Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: webrtc/p2p/base/p2ptransportchannel_unittest.cc

Issue 2386783002: Add UMA metrics for ICE regathering reasons. (Closed)
Patch Set: . Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2009 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <algorithm> 11 #include <algorithm>
12 #include <memory> 12 #include <memory>
13 13
14 #include "webrtc/api/fakemetricsobserver.h"
14 #include "webrtc/p2p/base/fakeportallocator.h" 15 #include "webrtc/p2p/base/fakeportallocator.h"
15 #include "webrtc/p2p/base/p2ptransportchannel.h" 16 #include "webrtc/p2p/base/p2ptransportchannel.h"
16 #include "webrtc/p2p/base/testrelayserver.h" 17 #include "webrtc/p2p/base/testrelayserver.h"
17 #include "webrtc/p2p/base/teststunserver.h" 18 #include "webrtc/p2p/base/teststunserver.h"
18 #include "webrtc/p2p/base/testturnserver.h" 19 #include "webrtc/p2p/base/testturnserver.h"
19 #include "webrtc/p2p/client/basicportallocator.h" 20 #include "webrtc/p2p/client/basicportallocator.h"
20 #include "webrtc/base/dscp.h" 21 #include "webrtc/base/dscp.h"
21 #include "webrtc/base/fakeclock.h" 22 #include "webrtc/base/fakeclock.h"
22 #include "webrtc/base/fakenetwork.h" 23 #include "webrtc/base/fakenetwork.h"
23 #include "webrtc/base/firewallsocketserver.h" 24 #include "webrtc/base/firewallsocketserver.h"
(...skipping 923 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 "tcp", 948 "tcp",
948 "local", 949 "local",
949 "tcp", 950 "tcp",
950 3000); 951 3000);
951 952
952 // Test the matrix of all the connectivity types we expect to see in the wild. 953 // Test the matrix of all the connectivity types we expect to see in the wild.
953 // Just test every combination of the configs in the Config enum. 954 // Just test every combination of the configs in the Config enum.
954 class P2PTransportChannelTest : public P2PTransportChannelTestBase { 955 class P2PTransportChannelTest : public P2PTransportChannelTestBase {
955 protected: 956 protected:
956 static const Result* kMatrix[NUM_CONFIGS][NUM_CONFIGS]; 957 static const Result* kMatrix[NUM_CONFIGS][NUM_CONFIGS];
957 void ConfigureEndpoints(Config config1, 958 void ConfigureEndpoints(
958 Config config2, 959 Config config1,
959 int allocator_flags1, 960 Config config2,
960 int allocator_flags2) { 961 int allocator_flags1,
962 int allocator_flags2,
963 webrtc::MetricsObserverInterface* observer1 = nullptr,
964 webrtc::MetricsObserverInterface* observer2 = nullptr) {
Taylor Brandstetter 2016/10/03 20:33:35 I'd prefer if the Endpoint owned its own metric ob
honghaiz3 2016/10/04 01:03:55 Done.
961 int delay = kMinimumStepDelay; 965 int delay = kMinimumStepDelay;
962 ConfigureEndpoint(0, config1); 966 ConfigureEndpoint(0, config1);
963 SetAllocatorFlags(0, allocator_flags1); 967 SetAllocatorFlags(0, allocator_flags1);
964 SetAllocationStepDelay(0, delay); 968 SetAllocationStepDelay(0, delay);
965 ConfigureEndpoint(1, config2); 969 ConfigureEndpoint(1, config2);
966 SetAllocatorFlags(1, allocator_flags2); 970 SetAllocatorFlags(1, allocator_flags2);
967 SetAllocationStepDelay(1, delay); 971 SetAllocationStepDelay(1, delay);
968 972
969 set_remote_ice_parameter_source(FROM_SETICEPARAMETERS); 973 set_remote_ice_parameter_source(FROM_SETICEPARAMETERS);
974 if (observer1) {
975 GetAllocator(0)->set_metrics_observer(observer1);
976 }
977 if (observer2) {
978 GetAllocator(1)->set_metrics_observer(observer2);
979 }
970 } 980 }
971 void ConfigureEndpoint(int endpoint, Config config) { 981 void ConfigureEndpoint(int endpoint, Config config) {
972 switch (config) { 982 switch (config) {
973 case OPEN: 983 case OPEN:
974 AddAddress(endpoint, kPublicAddrs[endpoint]); 984 AddAddress(endpoint, kPublicAddrs[endpoint]);
975 break; 985 break;
976 case NAT_FULL_CONE: 986 case NAT_FULL_CONE:
977 case NAT_ADDR_RESTRICTED: 987 case NAT_ADDR_RESTRICTED:
978 case NAT_PORT_RESTRICTED: 988 case NAT_PORT_RESTRICTED:
979 case NAT_SYMMETRIC: 989 case NAT_SYMMETRIC:
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1165 EXPECT_TRUE(best_conn_info->writable); 1175 EXPECT_TRUE(best_conn_info->writable);
1166 EXPECT_FALSE(best_conn_info->timeout); 1176 EXPECT_FALSE(best_conn_info->timeout);
1167 EXPECT_EQ(10U, best_conn_info->sent_total_packets); 1177 EXPECT_EQ(10U, best_conn_info->sent_total_packets);
1168 EXPECT_EQ(0U, best_conn_info->sent_discarded_packets); 1178 EXPECT_EQ(0U, best_conn_info->sent_discarded_packets);
1169 EXPECT_EQ(10 * 36U, best_conn_info->sent_total_bytes); 1179 EXPECT_EQ(10 * 36U, best_conn_info->sent_total_bytes);
1170 EXPECT_EQ(10 * 36U, best_conn_info->recv_total_bytes); 1180 EXPECT_EQ(10 * 36U, best_conn_info->recv_total_bytes);
1171 EXPECT_GT(best_conn_info->rtt, 0U); 1181 EXPECT_GT(best_conn_info->rtt, 0U);
1172 DestroyChannels(); 1182 DestroyChannels();
1173 } 1183 }
1174 1184
1185 TEST_F(P2PTransportChannelTest,
1186 TestIceRegatheringReasonIceRestartWhenDisconnected) {
1187 rtc::ScopedFakeClock clock;
1188 rtc::scoped_refptr<webrtc::FakeMetricsObserver> observer(
1189 new rtc::RefCountedObject<webrtc::FakeMetricsObserver>());
1190 ConfigureEndpoints(OPEN, OPEN, kOnlyLocalPorts, kOnlyLocalPorts, observer,
1191 observer);
1192
1193 CreateChannels();
1194 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1195 ep2_ch1()->receiving() &&
1196 ep2_ch1()->writable(),
1197 3000, clock);
Taylor Brandstetter 2016/10/03 20:33:35 Could we use constants here instead of 3000 and 60
honghaiz3 2016/10/04 01:03:55 Done.
1198
1199 // Drop all packets so that both channels become not writable.
1200 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]);
1201 EXPECT_TRUE_SIMULATED_WAIT(!ep1_ch1()->writable() && !ep2_ch1()->writable(),
1202 6000, clock);
1203
1204 ep1_ch1()->SetIceParameters(kIceParams[2]);
1205 ep1_ch1()->SetRemoteIceParameters(kIceParams[3]);
1206 ep1_ch1()->MaybeStartGathering();
1207 EXPECT_EQ(1, observer->GetEnumCounter(
1208 webrtc::kEnumCounterIceRegatheringReason,
1209 static_cast<int>(
1210 IceRegatheringReason::ICE_RESTART_WHEN_DISCONNECTED)));
1211
1212 ep2_ch1()->SetIceParameters(kIceParams[3]);
1213 ep2_ch1()->SetRemoteIceParameters(kIceParams[2]);
1214 ep2_ch1()->MaybeStartGathering();
1215 EXPECT_EQ(2, observer->GetEnumCounter(
1216 webrtc::kEnumCounterIceRegatheringReason,
1217 static_cast<int>(
1218 IceRegatheringReason::ICE_RESTART_WHEN_DISCONNECTED)));
1219
1220 DestroyChannels();
1221 }
1222
1223 TEST_F(P2PTransportChannelTest,
1224 TestIceRegatheringReasonIceRestartWhenConnected) {
1225 rtc::ScopedFakeClock clock;
1226 rtc::scoped_refptr<webrtc::FakeMetricsObserver> observer(
1227 new rtc::RefCountedObject<webrtc::FakeMetricsObserver>());
1228 ConfigureEndpoints(OPEN, OPEN, kOnlyLocalPorts, kOnlyLocalPorts, observer,
1229 observer);
1230
1231 CreateChannels();
1232 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1233 ep2_ch1()->receiving() &&
1234 ep2_ch1()->writable(),
1235 3000, clock);
1236
1237 ep1_ch1()->SetIceParameters(kIceParams[2]);
1238 ep1_ch1()->SetRemoteIceParameters(kIceParams[3]);
1239 ep1_ch1()->MaybeStartGathering();
1240 EXPECT_EQ(
1241 1,
1242 observer->GetEnumCounter(
1243 webrtc::kEnumCounterIceRegatheringReason,
1244 static_cast<int>(IceRegatheringReason::ICE_RESTART_WHEN_CONNECTED)));
1245
1246 ep2_ch1()->SetIceParameters(kIceParams[3]);
1247 ep2_ch1()->SetRemoteIceParameters(kIceParams[2]);
1248 ep2_ch1()->MaybeStartGathering();
1249 EXPECT_EQ(
1250 2,
1251 observer->GetEnumCounter(
1252 webrtc::kEnumCounterIceRegatheringReason,
1253 static_cast<int>(IceRegatheringReason::ICE_RESTART_WHEN_CONNECTED)));
1254
1255 DestroyChannels();
1256 }
1257
1258 TEST_F(P2PTransportChannelTest,
1259 TestIceRegatheringReasonIceRestartWhenConnecting) {
1260 rtc::ScopedFakeClock clock;
1261 rtc::scoped_refptr<webrtc::FakeMetricsObserver> observer(
1262 new rtc::RefCountedObject<webrtc::FakeMetricsObserver>());
1263 ConfigureEndpoints(OPEN, OPEN, kOnlyLocalPorts, kOnlyLocalPorts, observer,
1264 observer);
1265
1266 // Create the channels without waiting for them to become connected.
1267 CreateChannels();
1268
1269 ep1_ch1()->SetIceParameters(kIceParams[2]);
1270 ep1_ch1()->SetRemoteIceParameters(kIceParams[3]);
1271 ep1_ch1()->MaybeStartGathering();
1272 EXPECT_EQ(
1273 1,
1274 observer->GetEnumCounter(
1275 webrtc::kEnumCounterIceRegatheringReason,
1276 static_cast<int>(IceRegatheringReason::ICE_RESTART_WHEN_CONNECTING)));
1277
1278 ep2_ch1()->SetIceParameters(kIceParams[3]);
1279 ep2_ch1()->SetRemoteIceParameters(kIceParams[2]);
1280 ep2_ch1()->MaybeStartGathering();
1281 EXPECT_EQ(
1282 2,
1283 observer->GetEnumCounter(
1284 webrtc::kEnumCounterIceRegatheringReason,
1285 static_cast<int>(IceRegatheringReason::ICE_RESTART_WHEN_CONNECTING)));
1286
1287 DestroyChannels();
1288 }
1289
Taylor Brandstetter 2016/10/03 20:33:35 I think it would be helpful to add a comment expla
honghaiz3 2016/10/04 01:03:54 Done.
1290 TEST_F(P2PTransportChannelTest,
1291 TestIceRegatheringReasonContinualGatheringByNetworkChange) {
1292 rtc::ScopedFakeClock clock;
1293 rtc::scoped_refptr<webrtc::FakeMetricsObserver> observer1(
1294 new rtc::RefCountedObject<webrtc::FakeMetricsObserver>());
1295 rtc::scoped_refptr<webrtc::FakeMetricsObserver> observer2(
1296 new rtc::RefCountedObject<webrtc::FakeMetricsObserver>());
1297 ConfigureEndpoints(OPEN, OPEN, kOnlyLocalPorts, kOnlyLocalPorts, observer1,
1298 observer2);
1299
1300 // ep1 gathers continually but ep2 does not.
1301 IceConfig continual_gathering_config =
1302 CreateIceConfig(1000, GATHER_CONTINUALLY);
1303 IceConfig default_config;
1304 CreateChannels(continual_gathering_config, default_config);
1305
1306 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1307 ep2_ch1()->receiving() &&
1308 ep2_ch1()->writable(),
1309 3000, clock);
1310
1311 // Add address in ep1 will trigger continual gathering.
1312 AddAddress(0, kAlternateAddrs[0]);
1313 EXPECT_EQ_SIMULATED_WAIT(
1314 1, observer1->GetEnumCounter(
1315 webrtc::kEnumCounterIceRegatheringReason,
1316 static_cast<int>(
1317 IceRegatheringReason::CONTINUAL_GATHERING_BY_NETWORK_CHANGE)),
1318 kDefaultTimeout, clock);
1319
1320 ep2_ch1()->SetIceParameters(kIceParams[3]);
1321 ep2_ch1()->SetRemoteIceParameters(kIceParams[2]);
1322 ep2_ch1()->MaybeStartGathering();
1323
1324 AddAddress(1, kAlternateAddrs[1]);
1325 SIMULATED_WAIT(false, kDefaultTimeout, clock);
1326 // ep2 has not enabled continual gathering.
1327 EXPECT_EQ(
1328 0, observer2->GetEnumCounter(
1329 webrtc::kEnumCounterIceRegatheringReason,
1330 static_cast<int>(
1331 IceRegatheringReason::CONTINUAL_GATHERING_BY_NETWORK_CHANGE)));
1332
1333 DestroyChannels();
1334 }
1335
1336 TEST_F(P2PTransportChannelTest,
1337 TestIceRegatheringReasonContinualGatheringByNetworkFailure) {
1338 rtc::ScopedFakeClock clock;
1339 rtc::scoped_refptr<webrtc::FakeMetricsObserver> observer1(
1340 new rtc::RefCountedObject<webrtc::FakeMetricsObserver>());
1341 rtc::scoped_refptr<webrtc::FakeMetricsObserver> observer2(
1342 new rtc::RefCountedObject<webrtc::FakeMetricsObserver>());
1343 ConfigureEndpoints(OPEN, OPEN, kOnlyLocalPorts, kOnlyLocalPorts, observer1,
1344 observer2);
1345
1346 // ep1 gathers continually but ep2 does not.
1347 IceConfig config1 = CreateIceConfig(1000, GATHER_CONTINUALLY);
1348 config1.regather_on_failed_networks_interval = rtc::Optional<int>(2000);
1349 IceConfig config2;
1350 config2.regather_on_failed_networks_interval = rtc::Optional<int>(2000);
1351 CreateChannels(config1, config2);
1352
1353 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1354 ep2_ch1()->receiving() &&
1355 ep2_ch1()->writable(),
1356 3000, clock);
1357
1358 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]);
1359
1360 SIMULATED_WAIT(false, 35000, clock);
Taylor Brandstetter 2016/10/03 20:33:35 Could you replace 35000 with a constant?
honghaiz3 2016/10/04 01:03:54 Done.
1361 EXPECT_LE(
1362 1,
1363 observer1->GetEnumCounter(
1364 webrtc::kEnumCounterIceRegatheringReason,
1365 static_cast<int>(
1366 IceRegatheringReason::CONTINUAL_GATHERING_BY_NETWORK_FAILURE)));
1367 LOG(LS_INFO) << "x1";
Taylor Brandstetter 2016/10/03 20:33:35 Remember to remove this log statement
honghaiz3 2016/10/04 01:03:54 Done.
1368 EXPECT_EQ(
1369 0,
1370 observer2->GetEnumCounter(
1371 webrtc::kEnumCounterIceRegatheringReason,
1372 static_cast<int>(
1373 IceRegatheringReason::CONTINUAL_GATHERING_BY_NETWORK_FAILURE)));
1374
1375 DestroyChannels();
1376 }
1377
1175 // Test that we properly create a connection on a STUN ping from unknown address 1378 // Test that we properly create a connection on a STUN ping from unknown address
1176 // when the signaling is slow. 1379 // when the signaling is slow.
1177 TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignaling) { 1380 TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignaling) {
1178 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, 1381 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
1179 kDefaultPortAllocatorFlags); 1382 kDefaultPortAllocatorFlags);
1180 // Emulate no remote parameters coming in. 1383 // Emulate no remote parameters coming in.
1181 set_remote_ice_parameter_source(FROM_CANDIDATE); 1384 set_remote_ice_parameter_source(FROM_CANDIDATE);
1182 CreateChannels(); 1385 CreateChannels();
1183 // Only have remote parameters come in for ep2, not ep1. 1386 // Only have remote parameters come in for ep2, not ep1.
1184 ep2_ch1()->SetRemoteIceParameters(kIceParams[0]); 1387 ep2_ch1()->SetRemoteIceParameters(kIceParams[0]);
(...skipping 2815 matching lines...) Expand 10 before | Expand all | Expand 10 after
4000 4203
4001 // TCP Relay/Relay is the next. 4204 // TCP Relay/Relay is the next.
4002 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, 4205 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE,
4003 TCP_PROTOCOL_NAME); 4206 TCP_PROTOCOL_NAME);
4004 4207
4005 // Finally, Local/Relay will be pinged. 4208 // Finally, Local/Relay will be pinged.
4006 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); 4209 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE);
4007 } 4210 }
4008 4211
4009 } // namespace cricket { 4212 } // namespace cricket {
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698