blob: c7362979af61b7ff631ea5e83f6acce66efe25e7 [file] [log] [blame]
Hugo Benichi25bf8f52016-04-19 09:52:39 +09001/*
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
17package android.net.metrics;
18
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090019import android.annotation.SystemApi;
20import android.annotation.TestApi;
Hugo Benichi25bf8f52016-04-19 09:52:39 +090021import android.os.Parcel;
22import android.os.Parcelable;
Hugo Benichi5df9d722016-04-25 17:16:35 +090023import android.util.SparseArray;
24
25import com.android.internal.util.MessageUtils;
Hugo Benichi25bf8f52016-04-19 09:52:39 +090026
27/**
Hugo Benichi0d1c65b2016-06-22 17:01:43 +090028 * An event recorded when IpReachabilityMonitor sends a neighbor probe or receives
29 * a neighbor probe result.
Hugo Benichi25bf8f52016-04-19 09:52:39 +090030 * {@hide}
31 */
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090032@SystemApi
33@TestApi
34public final class IpReachabilityEvent implements IpConnectivityLog.Event {
Hugo Benichi25bf8f52016-04-19 09:52:39 +090035
Hugo Benichi0d1c65b2016-06-22 17:01:43 +090036 // 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 Benichi95cb2262017-01-11 10:11:26 +090043 /** Neighbor unreachable notification from kernel. */
Hugo Benichi0d1c65b2016-06-22 17:01:43 +090044 public static final int NUD_FAILED_ORGANIC = 4 << 8;
Hugo Benichi95cb2262017-01-11 10:11:26 +090045 /** Neighbor unreachable notification from kernel, IP provisioning is also lost. */
Hugo Benichi0d1c65b2016-06-22 17:01:43 +090046 public static final int PROVISIONING_LOST_ORGANIC = 5 << 8;
Hugo Benichi25bf8f52016-04-19 09:52:39 +090047
Hugo Benichi25bf8f52016-04-19 09:52:39 +090048 // 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 Benichi0d1c65b2016-06-22 17:01:43 +090052 // byte 3: when byte 2 == PROBE, errno code from RTNetlink or IpReachabilityMonitor.
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090053 /** @hide */
Hugo Benichi25bf8f52016-04-19 09:52:39 +090054 public final int eventType;
55
Hugo Benichi948a8592017-03-16 16:33:47 +090056 public IpReachabilityEvent(int eventType) {
Hugo Benichi25bf8f52016-04-19 09:52:39 +090057 this.eventType = eventType;
58 }
59
60 private IpReachabilityEvent(Parcel in) {
Hugo Benichi25bf8f52016-04-19 09:52:39 +090061 this.eventType = in.readInt();
62 }
63
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090064 /** @hide */
Hugo Benichi0d1c65b2016-06-22 17:01:43 +090065 @Override
Hugo Benichi25bf8f52016-04-19 09:52:39 +090066 public void writeToParcel(Parcel out, int flags) {
Hugo Benichi25bf8f52016-04-19 09:52:39 +090067 out.writeInt(eventType);
68 }
69
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090070 /** @hide */
Hugo Benichi0d1c65b2016-06-22 17:01:43 +090071 @Override
Hugo Benichi25bf8f52016-04-19 09:52:39 +090072 public int describeContents() {
73 return 0;
74 }
75
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090076 /** @hide */
Hugo Benichi25bf8f52016-04-19 09:52:39 +090077 public static final Parcelable.Creator<IpReachabilityEvent> CREATOR
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 Benichi5df9d722016-04-25 17:16:35 +090088 @Override
89 public String toString() {
Hugo Benichi0d1c65b2016-06-22 17:01:43 +090090 int hi = eventType & 0xff00;
91 int lo = eventType & 0x00ff;
92 String eventName = Decoder.constants.get(hi);
Hugo Benichi948a8592017-03-16 16:33:47 +090093 return String.format("IpReachabilityEvent(%s:%02x)", eventName, lo);
Hugo Benichi5df9d722016-04-25 17:16:35 +090094 }
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 Benichicfddd682016-05-31 16:28:06 +0900101}