Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +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 com.android.server.connectivity; |
| 18 | |
Glen Kuhne | 0719940 | 2016-10-25 15:47:25 -0700 | [diff] [blame] | 19 | import static com.android.server.connectivity.MetricsTestUtil.aLong; |
| 20 | import static com.android.server.connectivity.MetricsTestUtil.aString; |
| 21 | import static com.android.server.connectivity.MetricsTestUtil.aType; |
| 22 | import static com.android.server.connectivity.MetricsTestUtil.anInt; |
Glen Kuhne | 0719940 | 2016-10-25 15:47:25 -0700 | [diff] [blame] | 23 | import static com.android.server.connectivity.MetricsTestUtil.describeIpEvent; |
Hugo Benichi | 73fd4d1 | 2017-03-15 23:05:01 +0900 | [diff] [blame] | 24 | import static com.android.server.connectivity.metrics.nano.IpConnectivityLogClass.BLUETOOTH; |
| 25 | import static com.android.server.connectivity.metrics.nano.IpConnectivityLogClass.CELLULAR; |
Brett Chabot | 1ae2aa6 | 2019-03-04 14:14:56 -0800 | [diff] [blame] | 26 | import static com.android.server.connectivity.metrics.nano.IpConnectivityLogClass.IpConnectivityLog; |
Hugo Benichi | 73fd4d1 | 2017-03-15 23:05:01 +0900 | [diff] [blame] | 27 | import static com.android.server.connectivity.metrics.nano.IpConnectivityLogClass.MULTIPLE; |
| 28 | import static com.android.server.connectivity.metrics.nano.IpConnectivityLogClass.WIFI; |
Brett Chabot | 1ae2aa6 | 2019-03-04 14:14:56 -0800 | [diff] [blame] | 29 | |
Hugo Benichi | 60c9f63 | 2017-09-05 13:34:48 +0900 | [diff] [blame] | 30 | import static org.junit.Assert.assertEquals; |
| 31 | import static org.junit.Assert.fail; |
Glen Kuhne | 0719940 | 2016-10-25 15:47:25 -0700 | [diff] [blame] | 32 | |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 33 | import android.net.ConnectivityMetricsEvent; |
| 34 | import android.net.metrics.ApfProgramEvent; |
| 35 | import android.net.metrics.ApfStats; |
| 36 | import android.net.metrics.DefaultNetworkEvent; |
| 37 | import android.net.metrics.DhcpClientEvent; |
| 38 | import android.net.metrics.DhcpErrorEvent; |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 39 | import android.net.metrics.IpManagerEvent; |
| 40 | import android.net.metrics.IpReachabilityEvent; |
| 41 | import android.net.metrics.NetworkEvent; |
| 42 | import android.net.metrics.RaEvent; |
| 43 | import android.net.metrics.ValidationProbeEvent; |
Hugo Benichi | 60c9f63 | 2017-09-05 13:34:48 +0900 | [diff] [blame] | 44 | import android.net.metrics.WakeupStats; |
Hugo Benichi | 80df43e | 2016-11-24 11:28:06 +0900 | [diff] [blame] | 45 | import android.test.suitebuilder.annotation.SmallTest; |
Hugo Benichi | 60c9f63 | 2017-09-05 13:34:48 +0900 | [diff] [blame] | 46 | |
Brett Chabot | 1ae2aa6 | 2019-03-04 14:14:56 -0800 | [diff] [blame] | 47 | import androidx.test.runner.AndroidJUnit4; |
| 48 | |
Hugo Benichi | 5eb9053 | 2017-03-23 18:38:22 +0900 | [diff] [blame] | 49 | import com.android.server.connectivity.metrics.nano.IpConnectivityLogClass.IpConnectivityEvent; |
Hugo Benichi | 60c9f63 | 2017-09-05 13:34:48 +0900 | [diff] [blame] | 50 | |
Brett Chabot | 1ae2aa6 | 2019-03-04 14:14:56 -0800 | [diff] [blame] | 51 | import org.junit.Test; |
| 52 | import org.junit.runner.RunWith; |
| 53 | |
Glen Kuhne | 0719940 | 2016-10-25 15:47:25 -0700 | [diff] [blame] | 54 | import java.util.Arrays; |
Hugo Benichi | 5eb9053 | 2017-03-23 18:38:22 +0900 | [diff] [blame] | 55 | import java.util.List; |
Hugo Benichi | 60c9f63 | 2017-09-05 13:34:48 +0900 | [diff] [blame] | 56 | |
Hugo Benichi | f684050 | 2017-03-08 11:59:36 +0900 | [diff] [blame] | 57 | // TODO: instead of comparing textpb to textpb, parse textpb and compare proto to proto. |
Hugo Benichi | 60c9f63 | 2017-09-05 13:34:48 +0900 | [diff] [blame] | 58 | @RunWith(AndroidJUnit4.class) |
| 59 | @SmallTest |
| 60 | public class IpConnectivityEventBuilderTest { |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 61 | |
Hugo Benichi | 60c9f63 | 2017-09-05 13:34:48 +0900 | [diff] [blame] | 62 | @Test |
Hugo Benichi | 73fd4d1 | 2017-03-15 23:05:01 +0900 | [diff] [blame] | 63 | public void testLinkLayerInferrence() { |
| 64 | ConnectivityMetricsEvent ev = describeIpEvent( |
| 65 | aType(IpReachabilityEvent.class), |
Hugo Benichi | 73fd4d1 | 2017-03-15 23:05:01 +0900 | [diff] [blame] | 66 | anInt(IpReachabilityEvent.NUD_FAILED)); |
| 67 | |
Hugo Benichi | 2a5cfb9 | 2017-03-22 22:21:44 +0900 | [diff] [blame] | 68 | String want = String.join("\n", |
Hugo Benichi | 73fd4d1 | 2017-03-15 23:05:01 +0900 | [diff] [blame] | 69 | "dropped_events: 0", |
| 70 | "events <", |
| 71 | " if_name: \"\"", |
| 72 | " link_layer: 0", |
| 73 | " network_id: 0", |
| 74 | " time_ms: 1", |
| 75 | " transports: 0", |
| 76 | " ip_reachability_event <", |
| 77 | " event_type: 512", |
Hugo Benichi | 948a859 | 2017-03-16 16:33:47 +0900 | [diff] [blame] | 78 | " if_name: \"\"", |
Hugo Benichi | 73fd4d1 | 2017-03-15 23:05:01 +0900 | [diff] [blame] | 79 | " >", |
| 80 | ">", |
Hugo Benichi | 2a5cfb9 | 2017-03-22 22:21:44 +0900 | [diff] [blame] | 81 | "version: 2\n"); |
Hugo Benichi | 73fd4d1 | 2017-03-15 23:05:01 +0900 | [diff] [blame] | 82 | verifySerialization(want, ev); |
| 83 | |
| 84 | ev.netId = 123; |
| 85 | ev.transports = 3; // transports have priority for inferrence of link layer |
| 86 | ev.ifname = "wlan0"; |
Hugo Benichi | 2a5cfb9 | 2017-03-22 22:21:44 +0900 | [diff] [blame] | 87 | want = String.join("\n", |
Hugo Benichi | 73fd4d1 | 2017-03-15 23:05:01 +0900 | [diff] [blame] | 88 | "dropped_events: 0", |
| 89 | "events <", |
| 90 | " if_name: \"\"", |
| 91 | String.format(" link_layer: %d", MULTIPLE), |
| 92 | " network_id: 123", |
| 93 | " time_ms: 1", |
| 94 | " transports: 3", |
| 95 | " ip_reachability_event <", |
| 96 | " event_type: 512", |
Hugo Benichi | 948a859 | 2017-03-16 16:33:47 +0900 | [diff] [blame] | 97 | " if_name: \"\"", |
Hugo Benichi | 73fd4d1 | 2017-03-15 23:05:01 +0900 | [diff] [blame] | 98 | " >", |
| 99 | ">", |
Hugo Benichi | 2a5cfb9 | 2017-03-22 22:21:44 +0900 | [diff] [blame] | 100 | "version: 2\n"); |
Hugo Benichi | 73fd4d1 | 2017-03-15 23:05:01 +0900 | [diff] [blame] | 101 | verifySerialization(want, ev); |
| 102 | |
| 103 | ev.transports = 1; |
| 104 | ev.ifname = null; |
Hugo Benichi | 2a5cfb9 | 2017-03-22 22:21:44 +0900 | [diff] [blame] | 105 | want = String.join("\n", |
Hugo Benichi | 73fd4d1 | 2017-03-15 23:05:01 +0900 | [diff] [blame] | 106 | "dropped_events: 0", |
| 107 | "events <", |
| 108 | " if_name: \"\"", |
| 109 | String.format(" link_layer: %d", CELLULAR), |
| 110 | " network_id: 123", |
| 111 | " time_ms: 1", |
| 112 | " transports: 1", |
| 113 | " ip_reachability_event <", |
| 114 | " event_type: 512", |
Hugo Benichi | 948a859 | 2017-03-16 16:33:47 +0900 | [diff] [blame] | 115 | " if_name: \"\"", |
Hugo Benichi | 73fd4d1 | 2017-03-15 23:05:01 +0900 | [diff] [blame] | 116 | " >", |
| 117 | ">", |
Hugo Benichi | 2a5cfb9 | 2017-03-22 22:21:44 +0900 | [diff] [blame] | 118 | "version: 2\n"); |
Hugo Benichi | 73fd4d1 | 2017-03-15 23:05:01 +0900 | [diff] [blame] | 119 | verifySerialization(want, ev); |
| 120 | |
| 121 | ev.transports = 0; |
| 122 | ev.ifname = "not_inferred"; |
Hugo Benichi | 2a5cfb9 | 2017-03-22 22:21:44 +0900 | [diff] [blame] | 123 | want = String.join("\n", |
Hugo Benichi | 73fd4d1 | 2017-03-15 23:05:01 +0900 | [diff] [blame] | 124 | "dropped_events: 0", |
| 125 | "events <", |
| 126 | " if_name: \"not_inferred\"", |
| 127 | " link_layer: 0", |
| 128 | " network_id: 123", |
| 129 | " time_ms: 1", |
| 130 | " transports: 0", |
| 131 | " ip_reachability_event <", |
| 132 | " event_type: 512", |
Hugo Benichi | 948a859 | 2017-03-16 16:33:47 +0900 | [diff] [blame] | 133 | " if_name: \"\"", |
Hugo Benichi | 73fd4d1 | 2017-03-15 23:05:01 +0900 | [diff] [blame] | 134 | " >", |
| 135 | ">", |
Hugo Benichi | 2a5cfb9 | 2017-03-22 22:21:44 +0900 | [diff] [blame] | 136 | "version: 2\n"); |
Hugo Benichi | 73fd4d1 | 2017-03-15 23:05:01 +0900 | [diff] [blame] | 137 | verifySerialization(want, ev); |
| 138 | |
| 139 | ev.ifname = "bt-pan"; |
Hugo Benichi | 2a5cfb9 | 2017-03-22 22:21:44 +0900 | [diff] [blame] | 140 | want = String.join("\n", |
Hugo Benichi | 73fd4d1 | 2017-03-15 23:05:01 +0900 | [diff] [blame] | 141 | "dropped_events: 0", |
| 142 | "events <", |
| 143 | " if_name: \"\"", |
| 144 | String.format(" link_layer: %d", BLUETOOTH), |
| 145 | " network_id: 123", |
| 146 | " time_ms: 1", |
| 147 | " transports: 0", |
| 148 | " ip_reachability_event <", |
| 149 | " event_type: 512", |
Hugo Benichi | 948a859 | 2017-03-16 16:33:47 +0900 | [diff] [blame] | 150 | " if_name: \"\"", |
Hugo Benichi | 73fd4d1 | 2017-03-15 23:05:01 +0900 | [diff] [blame] | 151 | " >", |
| 152 | ">", |
Hugo Benichi | 2a5cfb9 | 2017-03-22 22:21:44 +0900 | [diff] [blame] | 153 | "version: 2\n"); |
Hugo Benichi | 73fd4d1 | 2017-03-15 23:05:01 +0900 | [diff] [blame] | 154 | verifySerialization(want, ev); |
| 155 | |
| 156 | ev.ifname = "rmnet_ipa0"; |
Hugo Benichi | 2a5cfb9 | 2017-03-22 22:21:44 +0900 | [diff] [blame] | 157 | want = String.join("\n", |
Hugo Benichi | 73fd4d1 | 2017-03-15 23:05:01 +0900 | [diff] [blame] | 158 | "dropped_events: 0", |
| 159 | "events <", |
| 160 | " if_name: \"\"", |
| 161 | String.format(" link_layer: %d", CELLULAR), |
| 162 | " network_id: 123", |
| 163 | " time_ms: 1", |
| 164 | " transports: 0", |
| 165 | " ip_reachability_event <", |
| 166 | " event_type: 512", |
Hugo Benichi | 948a859 | 2017-03-16 16:33:47 +0900 | [diff] [blame] | 167 | " if_name: \"\"", |
Hugo Benichi | 73fd4d1 | 2017-03-15 23:05:01 +0900 | [diff] [blame] | 168 | " >", |
| 169 | ">", |
Hugo Benichi | 2a5cfb9 | 2017-03-22 22:21:44 +0900 | [diff] [blame] | 170 | "version: 2\n"); |
Hugo Benichi | 73fd4d1 | 2017-03-15 23:05:01 +0900 | [diff] [blame] | 171 | verifySerialization(want, ev); |
| 172 | |
| 173 | ev.ifname = "wlan0"; |
Hugo Benichi | 2a5cfb9 | 2017-03-22 22:21:44 +0900 | [diff] [blame] | 174 | want = String.join("\n", |
Hugo Benichi | 73fd4d1 | 2017-03-15 23:05:01 +0900 | [diff] [blame] | 175 | "dropped_events: 0", |
| 176 | "events <", |
| 177 | " if_name: \"\"", |
| 178 | String.format(" link_layer: %d", WIFI), |
| 179 | " network_id: 123", |
| 180 | " time_ms: 1", |
| 181 | " transports: 0", |
| 182 | " ip_reachability_event <", |
| 183 | " event_type: 512", |
Hugo Benichi | 948a859 | 2017-03-16 16:33:47 +0900 | [diff] [blame] | 184 | " if_name: \"\"", |
Hugo Benichi | 73fd4d1 | 2017-03-15 23:05:01 +0900 | [diff] [blame] | 185 | " >", |
| 186 | ">", |
Hugo Benichi | 2a5cfb9 | 2017-03-22 22:21:44 +0900 | [diff] [blame] | 187 | "version: 2\n"); |
Hugo Benichi | 73fd4d1 | 2017-03-15 23:05:01 +0900 | [diff] [blame] | 188 | verifySerialization(want, ev); |
| 189 | } |
| 190 | |
Hugo Benichi | 60c9f63 | 2017-09-05 13:34:48 +0900 | [diff] [blame] | 191 | @Test |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 192 | public void testDefaultNetworkEventSerialization() { |
Hugo Benichi | 380a063 | 2017-10-20 09:25:29 +0900 | [diff] [blame] | 193 | DefaultNetworkEvent ev = new DefaultNetworkEvent(1001); |
Hugo Benichi | 1193a9c | 2017-10-19 14:58:15 +0900 | [diff] [blame] | 194 | ev.netId = 102; |
Hugo Benichi | 380a063 | 2017-10-20 09:25:29 +0900 | [diff] [blame] | 195 | ev.transports = 2; |
| 196 | ev.previousTransports = 4; |
| 197 | ev.ipv4 = true; |
| 198 | ev.initialScore = 20; |
| 199 | ev.finalScore = 60; |
| 200 | ev.durationMs = 54; |
| 201 | ev.validatedMs = 27; |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 202 | |
Hugo Benichi | 2a5cfb9 | 2017-03-22 22:21:44 +0900 | [diff] [blame] | 203 | String want = String.join("\n", |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 204 | "dropped_events: 0", |
| 205 | "events <", |
Hugo Benichi | f684050 | 2017-03-08 11:59:36 +0900 | [diff] [blame] | 206 | " if_name: \"\"", |
Hugo Benichi | 380a063 | 2017-10-20 09:25:29 +0900 | [diff] [blame] | 207 | " link_layer: 4", |
Hugo Benichi | 1193a9c | 2017-10-19 14:58:15 +0900 | [diff] [blame] | 208 | " network_id: 102", |
| 209 | " time_ms: 0", |
Hugo Benichi | 380a063 | 2017-10-20 09:25:29 +0900 | [diff] [blame] | 210 | " transports: 2", |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 211 | " default_network_event <", |
Hugo Benichi | 380a063 | 2017-10-20 09:25:29 +0900 | [diff] [blame] | 212 | " default_network_duration_ms: 54", |
| 213 | " final_score: 60", |
| 214 | " initial_score: 20", |
| 215 | " ip_support: 1", |
Hugo Benichi | 4eccf78 | 2017-07-18 14:28:27 +0900 | [diff] [blame] | 216 | " no_default_network_duration_ms: 0", |
Hugo Benichi | 380a063 | 2017-10-20 09:25:29 +0900 | [diff] [blame] | 217 | " previous_default_network_link_layer: 1", |
| 218 | " previous_network_ip_support: 0", |
| 219 | " validation_duration_ms: 27", |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 220 | " >", |
Hugo Benichi | d680d4c | 2016-10-13 13:16:16 +0900 | [diff] [blame] | 221 | ">", |
Hugo Benichi | 2a5cfb9 | 2017-03-22 22:21:44 +0900 | [diff] [blame] | 222 | "version: 2\n"); |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 223 | |
Hugo Benichi | 1193a9c | 2017-10-19 14:58:15 +0900 | [diff] [blame] | 224 | verifySerialization(want, IpConnectivityEventBuilder.toProto(ev)); |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 225 | } |
| 226 | |
Hugo Benichi | 60c9f63 | 2017-09-05 13:34:48 +0900 | [diff] [blame] | 227 | @Test |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 228 | public void testDhcpClientEventSerialization() { |
| 229 | ConnectivityMetricsEvent ev = describeIpEvent( |
| 230 | aType(DhcpClientEvent.class), |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 231 | aString("SomeState"), |
| 232 | anInt(192)); |
| 233 | |
Hugo Benichi | 2a5cfb9 | 2017-03-22 22:21:44 +0900 | [diff] [blame] | 234 | String want = String.join("\n", |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 235 | "dropped_events: 0", |
| 236 | "events <", |
Hugo Benichi | f684050 | 2017-03-08 11:59:36 +0900 | [diff] [blame] | 237 | " if_name: \"\"", |
Hugo Benichi | 1af06a6 | 2017-01-16 14:42:56 +0900 | [diff] [blame] | 238 | " link_layer: 0", |
Hugo Benichi | f684050 | 2017-03-08 11:59:36 +0900 | [diff] [blame] | 239 | " network_id: 0", |
Hugo Benichi | 80df43e | 2016-11-24 11:28:06 +0900 | [diff] [blame] | 240 | " time_ms: 1", |
Hugo Benichi | f684050 | 2017-03-08 11:59:36 +0900 | [diff] [blame] | 241 | " transports: 0", |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 242 | " dhcp_event <", |
| 243 | " duration_ms: 192", |
Hugo Benichi | 948a859 | 2017-03-16 16:33:47 +0900 | [diff] [blame] | 244 | " if_name: \"\"", |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 245 | " state_transition: \"SomeState\"", |
| 246 | " >", |
Hugo Benichi | d680d4c | 2016-10-13 13:16:16 +0900 | [diff] [blame] | 247 | ">", |
Hugo Benichi | 2a5cfb9 | 2017-03-22 22:21:44 +0900 | [diff] [blame] | 248 | "version: 2\n"); |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 249 | |
| 250 | verifySerialization(want, ev); |
| 251 | } |
| 252 | |
Hugo Benichi | 60c9f63 | 2017-09-05 13:34:48 +0900 | [diff] [blame] | 253 | @Test |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 254 | public void testDhcpErrorEventSerialization() { |
| 255 | ConnectivityMetricsEvent ev = describeIpEvent( |
| 256 | aType(DhcpErrorEvent.class), |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 257 | anInt(DhcpErrorEvent.L4_NOT_UDP)); |
| 258 | |
Hugo Benichi | 2a5cfb9 | 2017-03-22 22:21:44 +0900 | [diff] [blame] | 259 | String want = String.join("\n", |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 260 | "dropped_events: 0", |
| 261 | "events <", |
Hugo Benichi | f684050 | 2017-03-08 11:59:36 +0900 | [diff] [blame] | 262 | " if_name: \"\"", |
Hugo Benichi | 1af06a6 | 2017-01-16 14:42:56 +0900 | [diff] [blame] | 263 | " link_layer: 0", |
Hugo Benichi | f684050 | 2017-03-08 11:59:36 +0900 | [diff] [blame] | 264 | " network_id: 0", |
Hugo Benichi | 80df43e | 2016-11-24 11:28:06 +0900 | [diff] [blame] | 265 | " time_ms: 1", |
Hugo Benichi | f684050 | 2017-03-08 11:59:36 +0900 | [diff] [blame] | 266 | " transports: 0", |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 267 | " dhcp_event <", |
| 268 | " duration_ms: 0", |
Hugo Benichi | 948a859 | 2017-03-16 16:33:47 +0900 | [diff] [blame] | 269 | " if_name: \"\"", |
Hugo Benichi | 80df43e | 2016-11-24 11:28:06 +0900 | [diff] [blame] | 270 | " error_code: 50397184", |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 271 | " >", |
Hugo Benichi | d680d4c | 2016-10-13 13:16:16 +0900 | [diff] [blame] | 272 | ">", |
Hugo Benichi | 2a5cfb9 | 2017-03-22 22:21:44 +0900 | [diff] [blame] | 273 | "version: 2\n"); |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 274 | |
| 275 | verifySerialization(want, ev); |
| 276 | } |
| 277 | |
Hugo Benichi | 60c9f63 | 2017-09-05 13:34:48 +0900 | [diff] [blame] | 278 | @Test |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 279 | public void testIpManagerEventSerialization() { |
| 280 | ConnectivityMetricsEvent ev = describeIpEvent( |
| 281 | aType(IpManagerEvent.class), |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 282 | anInt(IpManagerEvent.PROVISIONING_OK), |
| 283 | aLong(5678)); |
| 284 | |
Hugo Benichi | 2a5cfb9 | 2017-03-22 22:21:44 +0900 | [diff] [blame] | 285 | String want = String.join("\n", |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 286 | "dropped_events: 0", |
| 287 | "events <", |
Hugo Benichi | f684050 | 2017-03-08 11:59:36 +0900 | [diff] [blame] | 288 | " if_name: \"\"", |
Hugo Benichi | 1af06a6 | 2017-01-16 14:42:56 +0900 | [diff] [blame] | 289 | " link_layer: 0", |
Hugo Benichi | f684050 | 2017-03-08 11:59:36 +0900 | [diff] [blame] | 290 | " network_id: 0", |
Hugo Benichi | 80df43e | 2016-11-24 11:28:06 +0900 | [diff] [blame] | 291 | " time_ms: 1", |
Hugo Benichi | f684050 | 2017-03-08 11:59:36 +0900 | [diff] [blame] | 292 | " transports: 0", |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 293 | " ip_provisioning_event <", |
| 294 | " event_type: 1", |
Hugo Benichi | 948a859 | 2017-03-16 16:33:47 +0900 | [diff] [blame] | 295 | " if_name: \"\"", |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 296 | " latency_ms: 5678", |
| 297 | " >", |
Hugo Benichi | d680d4c | 2016-10-13 13:16:16 +0900 | [diff] [blame] | 298 | ">", |
Hugo Benichi | 2a5cfb9 | 2017-03-22 22:21:44 +0900 | [diff] [blame] | 299 | "version: 2\n"); |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 300 | |
| 301 | verifySerialization(want, ev); |
| 302 | } |
| 303 | |
Hugo Benichi | 60c9f63 | 2017-09-05 13:34:48 +0900 | [diff] [blame] | 304 | @Test |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 305 | public void testIpReachabilityEventSerialization() { |
| 306 | ConnectivityMetricsEvent ev = describeIpEvent( |
| 307 | aType(IpReachabilityEvent.class), |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 308 | anInt(IpReachabilityEvent.NUD_FAILED)); |
| 309 | |
Hugo Benichi | 2a5cfb9 | 2017-03-22 22:21:44 +0900 | [diff] [blame] | 310 | String want = String.join("\n", |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 311 | "dropped_events: 0", |
| 312 | "events <", |
Hugo Benichi | f684050 | 2017-03-08 11:59:36 +0900 | [diff] [blame] | 313 | " if_name: \"\"", |
Hugo Benichi | 1af06a6 | 2017-01-16 14:42:56 +0900 | [diff] [blame] | 314 | " link_layer: 0", |
Hugo Benichi | f684050 | 2017-03-08 11:59:36 +0900 | [diff] [blame] | 315 | " network_id: 0", |
Hugo Benichi | 80df43e | 2016-11-24 11:28:06 +0900 | [diff] [blame] | 316 | " time_ms: 1", |
Hugo Benichi | f684050 | 2017-03-08 11:59:36 +0900 | [diff] [blame] | 317 | " transports: 0", |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 318 | " ip_reachability_event <", |
| 319 | " event_type: 512", |
Hugo Benichi | 948a859 | 2017-03-16 16:33:47 +0900 | [diff] [blame] | 320 | " if_name: \"\"", |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 321 | " >", |
Hugo Benichi | d680d4c | 2016-10-13 13:16:16 +0900 | [diff] [blame] | 322 | ">", |
Hugo Benichi | 2a5cfb9 | 2017-03-22 22:21:44 +0900 | [diff] [blame] | 323 | "version: 2\n"); |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 324 | |
| 325 | verifySerialization(want, ev); |
| 326 | } |
| 327 | |
Hugo Benichi | 60c9f63 | 2017-09-05 13:34:48 +0900 | [diff] [blame] | 328 | @Test |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 329 | public void testNetworkEventSerialization() { |
| 330 | ConnectivityMetricsEvent ev = describeIpEvent( |
| 331 | aType(NetworkEvent.class), |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 332 | anInt(5), |
| 333 | aLong(20410)); |
| 334 | |
Hugo Benichi | 2a5cfb9 | 2017-03-22 22:21:44 +0900 | [diff] [blame] | 335 | String want = String.join("\n", |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 336 | "dropped_events: 0", |
| 337 | "events <", |
Hugo Benichi | f684050 | 2017-03-08 11:59:36 +0900 | [diff] [blame] | 338 | " if_name: \"\"", |
Hugo Benichi | 1af06a6 | 2017-01-16 14:42:56 +0900 | [diff] [blame] | 339 | " link_layer: 0", |
Hugo Benichi | f684050 | 2017-03-08 11:59:36 +0900 | [diff] [blame] | 340 | " network_id: 0", |
Hugo Benichi | 80df43e | 2016-11-24 11:28:06 +0900 | [diff] [blame] | 341 | " time_ms: 1", |
Hugo Benichi | f684050 | 2017-03-08 11:59:36 +0900 | [diff] [blame] | 342 | " transports: 0", |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 343 | " network_event <", |
| 344 | " event_type: 5", |
| 345 | " latency_ms: 20410", |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 346 | " >", |
Hugo Benichi | d680d4c | 2016-10-13 13:16:16 +0900 | [diff] [blame] | 347 | ">", |
Hugo Benichi | 2a5cfb9 | 2017-03-22 22:21:44 +0900 | [diff] [blame] | 348 | "version: 2\n"); |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 349 | |
| 350 | verifySerialization(want, ev); |
| 351 | } |
| 352 | |
Hugo Benichi | 60c9f63 | 2017-09-05 13:34:48 +0900 | [diff] [blame] | 353 | @Test |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 354 | public void testValidationProbeEventSerialization() { |
| 355 | ConnectivityMetricsEvent ev = describeIpEvent( |
| 356 | aType(ValidationProbeEvent.class), |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 357 | aLong(40730), |
| 358 | anInt(ValidationProbeEvent.PROBE_HTTP), |
| 359 | anInt(204)); |
| 360 | |
Hugo Benichi | 2a5cfb9 | 2017-03-22 22:21:44 +0900 | [diff] [blame] | 361 | String want = String.join("\n", |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 362 | "dropped_events: 0", |
| 363 | "events <", |
Hugo Benichi | f684050 | 2017-03-08 11:59:36 +0900 | [diff] [blame] | 364 | " if_name: \"\"", |
Hugo Benichi | 1af06a6 | 2017-01-16 14:42:56 +0900 | [diff] [blame] | 365 | " link_layer: 0", |
Hugo Benichi | f684050 | 2017-03-08 11:59:36 +0900 | [diff] [blame] | 366 | " network_id: 0", |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 367 | " time_ms: 1", |
Hugo Benichi | f684050 | 2017-03-08 11:59:36 +0900 | [diff] [blame] | 368 | " transports: 0", |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 369 | " validation_probe_event <", |
| 370 | " latency_ms: 40730", |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 371 | " probe_result: 204", |
| 372 | " probe_type: 1", |
| 373 | " >", |
Hugo Benichi | d680d4c | 2016-10-13 13:16:16 +0900 | [diff] [blame] | 374 | ">", |
Hugo Benichi | 2a5cfb9 | 2017-03-22 22:21:44 +0900 | [diff] [blame] | 375 | "version: 2\n"); |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 376 | |
| 377 | verifySerialization(want, ev); |
| 378 | } |
| 379 | |
Hugo Benichi | 60c9f63 | 2017-09-05 13:34:48 +0900 | [diff] [blame] | 380 | @Test |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 381 | public void testApfProgramEventSerialization() { |
| 382 | ConnectivityMetricsEvent ev = describeIpEvent( |
| 383 | aType(ApfProgramEvent.class), |
| 384 | aLong(200), |
Hugo Benichi | 22d9b2d | 2017-02-22 13:02:27 +0900 | [diff] [blame] | 385 | aLong(18), |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 386 | anInt(7), |
| 387 | anInt(9), |
| 388 | anInt(2048), |
| 389 | anInt(3)); |
| 390 | |
Hugo Benichi | 2a5cfb9 | 2017-03-22 22:21:44 +0900 | [diff] [blame] | 391 | String want = String.join("\n", |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 392 | "dropped_events: 0", |
| 393 | "events <", |
Hugo Benichi | f684050 | 2017-03-08 11:59:36 +0900 | [diff] [blame] | 394 | " if_name: \"\"", |
Hugo Benichi | 1af06a6 | 2017-01-16 14:42:56 +0900 | [diff] [blame] | 395 | " link_layer: 0", |
Hugo Benichi | f684050 | 2017-03-08 11:59:36 +0900 | [diff] [blame] | 396 | " network_id: 0", |
Hugo Benichi | 80df43e | 2016-11-24 11:28:06 +0900 | [diff] [blame] | 397 | " time_ms: 1", |
Hugo Benichi | f684050 | 2017-03-08 11:59:36 +0900 | [diff] [blame] | 398 | " transports: 0", |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 399 | " apf_program_event <", |
| 400 | " current_ras: 9", |
| 401 | " drop_multicast: true", |
Hugo Benichi | 22d9b2d | 2017-02-22 13:02:27 +0900 | [diff] [blame] | 402 | " effective_lifetime: 18", |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 403 | " filtered_ras: 7", |
| 404 | " has_ipv4_addr: true", |
| 405 | " lifetime: 200", |
| 406 | " program_length: 2048", |
| 407 | " >", |
Hugo Benichi | d680d4c | 2016-10-13 13:16:16 +0900 | [diff] [blame] | 408 | ">", |
Hugo Benichi | 2a5cfb9 | 2017-03-22 22:21:44 +0900 | [diff] [blame] | 409 | "version: 2\n"); |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 410 | |
| 411 | verifySerialization(want, ev); |
| 412 | } |
| 413 | |
Hugo Benichi | 60c9f63 | 2017-09-05 13:34:48 +0900 | [diff] [blame] | 414 | @Test |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 415 | public void testApfStatsSerialization() { |
| 416 | ConnectivityMetricsEvent ev = describeIpEvent( |
| 417 | aType(ApfStats.class), |
| 418 | aLong(45000), |
| 419 | anInt(10), |
| 420 | anInt(2), |
| 421 | anInt(2), |
| 422 | anInt(1), |
| 423 | anInt(2), |
| 424 | anInt(4), |
Hugo Benichi | 22d9b2d | 2017-02-22 13:02:27 +0900 | [diff] [blame] | 425 | anInt(7), |
| 426 | anInt(3), |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 427 | anInt(2048)); |
| 428 | |
Hugo Benichi | 2a5cfb9 | 2017-03-22 22:21:44 +0900 | [diff] [blame] | 429 | String want = String.join("\n", |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 430 | "dropped_events: 0", |
| 431 | "events <", |
Hugo Benichi | f684050 | 2017-03-08 11:59:36 +0900 | [diff] [blame] | 432 | " if_name: \"\"", |
Hugo Benichi | 1af06a6 | 2017-01-16 14:42:56 +0900 | [diff] [blame] | 433 | " link_layer: 0", |
Hugo Benichi | f684050 | 2017-03-08 11:59:36 +0900 | [diff] [blame] | 434 | " network_id: 0", |
Hugo Benichi | 80df43e | 2016-11-24 11:28:06 +0900 | [diff] [blame] | 435 | " time_ms: 1", |
Hugo Benichi | f684050 | 2017-03-08 11:59:36 +0900 | [diff] [blame] | 436 | " transports: 0", |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 437 | " apf_statistics <", |
| 438 | " dropped_ras: 2", |
| 439 | " duration_ms: 45000", |
| 440 | " matching_ras: 2", |
| 441 | " max_program_size: 2048", |
| 442 | " parse_errors: 2", |
| 443 | " program_updates: 4", |
Hugo Benichi | 22d9b2d | 2017-02-22 13:02:27 +0900 | [diff] [blame] | 444 | " program_updates_all: 7", |
| 445 | " program_updates_allowing_multicast: 3", |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 446 | " received_ras: 10", |
Hugo Benichi | 4eccf78 | 2017-07-18 14:28:27 +0900 | [diff] [blame] | 447 | " total_packet_dropped: 0", |
| 448 | " total_packet_processed: 0", |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 449 | " zero_lifetime_ras: 1", |
| 450 | " >", |
Hugo Benichi | d680d4c | 2016-10-13 13:16:16 +0900 | [diff] [blame] | 451 | ">", |
Hugo Benichi | 2a5cfb9 | 2017-03-22 22:21:44 +0900 | [diff] [blame] | 452 | "version: 2\n"); |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 453 | |
| 454 | verifySerialization(want, ev); |
| 455 | } |
| 456 | |
Hugo Benichi | 60c9f63 | 2017-09-05 13:34:48 +0900 | [diff] [blame] | 457 | @Test |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 458 | public void testRaEventSerialization() { |
| 459 | ConnectivityMetricsEvent ev = describeIpEvent( |
| 460 | aType(RaEvent.class), |
| 461 | aLong(2000), |
| 462 | aLong(400), |
| 463 | aLong(300), |
| 464 | aLong(-1), |
| 465 | aLong(1000), |
| 466 | aLong(-1)); |
| 467 | |
Hugo Benichi | 2a5cfb9 | 2017-03-22 22:21:44 +0900 | [diff] [blame] | 468 | String want = String.join("\n", |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 469 | "dropped_events: 0", |
| 470 | "events <", |
Hugo Benichi | f684050 | 2017-03-08 11:59:36 +0900 | [diff] [blame] | 471 | " if_name: \"\"", |
Hugo Benichi | 1af06a6 | 2017-01-16 14:42:56 +0900 | [diff] [blame] | 472 | " link_layer: 0", |
Hugo Benichi | f684050 | 2017-03-08 11:59:36 +0900 | [diff] [blame] | 473 | " network_id: 0", |
Hugo Benichi | 80df43e | 2016-11-24 11:28:06 +0900 | [diff] [blame] | 474 | " time_ms: 1", |
Hugo Benichi | f684050 | 2017-03-08 11:59:36 +0900 | [diff] [blame] | 475 | " transports: 0", |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 476 | " ra_event <", |
| 477 | " dnssl_lifetime: -1", |
| 478 | " prefix_preferred_lifetime: 300", |
| 479 | " prefix_valid_lifetime: 400", |
| 480 | " rdnss_lifetime: 1000", |
| 481 | " route_info_lifetime: -1", |
| 482 | " router_lifetime: 2000", |
| 483 | " >", |
Hugo Benichi | d680d4c | 2016-10-13 13:16:16 +0900 | [diff] [blame] | 484 | ">", |
Hugo Benichi | 2a5cfb9 | 2017-03-22 22:21:44 +0900 | [diff] [blame] | 485 | "version: 2\n"); |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 486 | |
| 487 | verifySerialization(want, ev); |
| 488 | } |
| 489 | |
Hugo Benichi | 60c9f63 | 2017-09-05 13:34:48 +0900 | [diff] [blame] | 490 | @Test |
| 491 | public void testWakeupStatsSerialization() { |
| 492 | WakeupStats stats = new WakeupStats("wlan0"); |
| 493 | stats.totalWakeups = 14; |
| 494 | stats.applicationWakeups = 5; |
| 495 | stats.nonApplicationWakeups = 1; |
| 496 | stats.rootWakeups = 2; |
| 497 | stats.systemWakeups = 3; |
Hugo Benichi | 175b574 | 2017-09-19 13:15:26 +0900 | [diff] [blame] | 498 | stats.noUidWakeups = 3; |
Hugo Benichi | d921bce | 2017-10-12 21:33:40 +0900 | [diff] [blame] | 499 | stats.l2UnicastCount = 5; |
| 500 | stats.l2MulticastCount = 1; |
| 501 | stats.l2BroadcastCount = 2; |
| 502 | stats.ethertypes.put(0x800, 3); |
| 503 | stats.ethertypes.put(0x86dd, 3); |
| 504 | stats.ipNextHeaders.put(6, 5); |
| 505 | |
Hugo Benichi | 60c9f63 | 2017-09-05 13:34:48 +0900 | [diff] [blame] | 506 | |
| 507 | IpConnectivityEvent got = IpConnectivityEventBuilder.toProto(stats); |
| 508 | String want = String.join("\n", |
| 509 | "dropped_events: 0", |
| 510 | "events <", |
| 511 | " if_name: \"\"", |
| 512 | " link_layer: 4", |
| 513 | " network_id: 0", |
| 514 | " time_ms: 0", |
| 515 | " transports: 0", |
| 516 | " wakeup_stats <", |
| 517 | " application_wakeups: 5", |
| 518 | " duration_sec: 0", |
Hugo Benichi | d921bce | 2017-10-12 21:33:40 +0900 | [diff] [blame] | 519 | " ethertype_counts <", |
| 520 | " key: 2048", |
| 521 | " value: 3", |
| 522 | " >", |
| 523 | " ethertype_counts <", |
| 524 | " key: 34525", |
| 525 | " value: 3", |
| 526 | " >", |
| 527 | " ip_next_header_counts <", |
| 528 | " key: 6", |
| 529 | " value: 5", |
| 530 | " >", |
| 531 | " l2_broadcast_count: 2", |
| 532 | " l2_multicast_count: 1", |
| 533 | " l2_unicast_count: 5", |
Hugo Benichi | 175b574 | 2017-09-19 13:15:26 +0900 | [diff] [blame] | 534 | " no_uid_wakeups: 3", |
Hugo Benichi | 60c9f63 | 2017-09-05 13:34:48 +0900 | [diff] [blame] | 535 | " non_application_wakeups: 1", |
| 536 | " root_wakeups: 2", |
| 537 | " system_wakeups: 3", |
| 538 | " total_wakeups: 14", |
Hugo Benichi | 60c9f63 | 2017-09-05 13:34:48 +0900 | [diff] [blame] | 539 | " >", |
| 540 | ">", |
| 541 | "version: 2\n"); |
| 542 | |
| 543 | verifySerialization(want, got); |
| 544 | } |
| 545 | |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 546 | static void verifySerialization(String want, ConnectivityMetricsEvent... input) { |
Hugo Benichi | 60c9f63 | 2017-09-05 13:34:48 +0900 | [diff] [blame] | 547 | List<IpConnectivityEvent> protoInput = |
| 548 | IpConnectivityEventBuilder.toProto(Arrays.asList(input)); |
| 549 | verifySerialization(want, protoInput.toArray(new IpConnectivityEvent[0])); |
| 550 | } |
| 551 | |
| 552 | static void verifySerialization(String want, IpConnectivityEvent... input) { |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 553 | try { |
Hugo Benichi | 60c9f63 | 2017-09-05 13:34:48 +0900 | [diff] [blame] | 554 | byte[] got = IpConnectivityEventBuilder.serialize(0, Arrays.asList(input)); |
Glen Kuhne | 0719940 | 2016-10-25 15:47:25 -0700 | [diff] [blame] | 555 | IpConnectivityLog log = IpConnectivityLog.parseFrom(got); |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 556 | assertEquals(want, log.toString()); |
| 557 | } catch (Exception e) { |
| 558 | fail(e.toString()); |
| 559 | } |
| 560 | } |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 561 | } |