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