OLD | NEW |
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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 kSocksProxyAddrs[1]), | 192 kSocksProxyAddrs[1]), |
192 force_relay_(false) { | 193 force_relay_(false) { |
193 ep1_.role_ = ICEROLE_CONTROLLING; | 194 ep1_.role_ = ICEROLE_CONTROLLING; |
194 ep2_.role_ = ICEROLE_CONTROLLED; | 195 ep2_.role_ = ICEROLE_CONTROLLED; |
195 | 196 |
196 ServerAddresses stun_servers; | 197 ServerAddresses stun_servers; |
197 stun_servers.insert(kStunAddr); | 198 stun_servers.insert(kStunAddr); |
198 ep1_.allocator_.reset( | 199 ep1_.allocator_.reset( |
199 CreateBasicPortAllocator(&ep1_.network_manager_, stun_servers, | 200 CreateBasicPortAllocator(&ep1_.network_manager_, stun_servers, |
200 kTurnUdpIntAddr, rtc::SocketAddress())); | 201 kTurnUdpIntAddr, rtc::SocketAddress())); |
| 202 ep1_.metrics_observer_ = |
| 203 new rtc::RefCountedObject<webrtc::FakeMetricsObserver>(); |
| 204 ep1_.allocator_->set_metrics_observer(ep1_.metrics_observer_); |
201 ep2_.allocator_.reset( | 205 ep2_.allocator_.reset( |
202 CreateBasicPortAllocator(&ep2_.network_manager_, stun_servers, | 206 CreateBasicPortAllocator(&ep2_.network_manager_, stun_servers, |
203 kTurnUdpIntAddr, rtc::SocketAddress())); | 207 kTurnUdpIntAddr, rtc::SocketAddress())); |
| 208 ep2_.metrics_observer_ = |
| 209 new rtc::RefCountedObject<webrtc::FakeMetricsObserver>(); |
| 210 ep2_.allocator_->set_metrics_observer(ep2_.metrics_observer_); |
204 } | 211 } |
205 | 212 |
206 protected: | 213 protected: |
207 enum Config { | 214 enum Config { |
208 OPEN, // Open to the Internet | 215 OPEN, // Open to the Internet |
209 NAT_FULL_CONE, // NAT, no filtering | 216 NAT_FULL_CONE, // NAT, no filtering |
210 NAT_ADDR_RESTRICTED, // NAT, must send to an addr to recv | 217 NAT_ADDR_RESTRICTED, // NAT, must send to an addr to recv |
211 NAT_PORT_RESTRICTED, // NAT, must send to an addr+port to recv | 218 NAT_PORT_RESTRICTED, // NAT, must send to an addr+port to recv |
212 NAT_SYMMETRIC, // NAT, endpoint-dependent bindings | 219 NAT_SYMMETRIC, // NAT, endpoint-dependent bindings |
213 NAT_DOUBLE_CONE, // Double NAT, both cone | 220 NAT_DOUBLE_CONE, // Double NAT, both cone |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 void OnRoleConflict(bool role_conflict) { role_conflict_ = role_conflict; } | 298 void OnRoleConflict(bool role_conflict) { role_conflict_ = role_conflict; } |
292 bool role_conflict() { return role_conflict_; } | 299 bool role_conflict() { return role_conflict_; } |
293 void SetAllocationStepDelay(uint32_t delay) { | 300 void SetAllocationStepDelay(uint32_t delay) { |
294 allocator_->set_step_delay(delay); | 301 allocator_->set_step_delay(delay); |
295 } | 302 } |
296 void SetAllowTcpListen(bool allow_tcp_listen) { | 303 void SetAllowTcpListen(bool allow_tcp_listen) { |
297 allocator_->set_allow_tcp_listen(allow_tcp_listen); | 304 allocator_->set_allow_tcp_listen(allow_tcp_listen); |
298 } | 305 } |
299 | 306 |
300 rtc::FakeNetworkManager network_manager_; | 307 rtc::FakeNetworkManager network_manager_; |
| 308 // |metrics_observer_| should outlive |allocator_| as the former may be |
| 309 // used by the latter. |
| 310 rtc::scoped_refptr<webrtc::FakeMetricsObserver> metrics_observer_; |
301 std::unique_ptr<BasicPortAllocator> allocator_; | 311 std::unique_ptr<BasicPortAllocator> allocator_; |
302 ChannelData cd1_; | 312 ChannelData cd1_; |
303 ChannelData cd2_; | 313 ChannelData cd2_; |
304 IceRole role_; | 314 IceRole role_; |
305 uint64_t tiebreaker_; | 315 uint64_t tiebreaker_; |
306 bool role_conflict_; | 316 bool role_conflict_; |
307 bool save_candidates_; | 317 bool save_candidates_; |
308 std::vector<std::unique_ptr<CandidatesData>> saved_candidates_; | 318 std::vector<std::unique_ptr<CandidatesData>> saved_candidates_; |
309 bool ready_to_send_ = false; | 319 bool ready_to_send_ = false; |
310 }; | 320 }; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 return &ep1_; | 419 return &ep1_; |
410 } else if (endpoint == 1) { | 420 } else if (endpoint == 1) { |
411 return &ep2_; | 421 return &ep2_; |
412 } else { | 422 } else { |
413 return NULL; | 423 return NULL; |
414 } | 424 } |
415 } | 425 } |
416 PortAllocator* GetAllocator(int endpoint) { | 426 PortAllocator* GetAllocator(int endpoint) { |
417 return GetEndpoint(endpoint)->allocator_.get(); | 427 return GetEndpoint(endpoint)->allocator_.get(); |
418 } | 428 } |
| 429 webrtc::FakeMetricsObserver* GetMetricsObserver(int endpoint) { |
| 430 return GetEndpoint(endpoint)->metrics_observer_; |
| 431 } |
419 void AddAddress(int endpoint, const SocketAddress& addr) { | 432 void AddAddress(int endpoint, const SocketAddress& addr) { |
420 GetEndpoint(endpoint)->network_manager_.AddInterface(addr); | 433 GetEndpoint(endpoint)->network_manager_.AddInterface(addr); |
421 } | 434 } |
422 void AddAddress(int endpoint, | 435 void AddAddress(int endpoint, |
423 const SocketAddress& addr, | 436 const SocketAddress& addr, |
424 const std::string& ifname, | 437 const std::string& ifname, |
425 rtc::AdapterType adapter_type) { | 438 rtc::AdapterType adapter_type) { |
426 GetEndpoint(endpoint)->network_manager_.AddInterface(addr, ifname, | 439 GetEndpoint(endpoint)->network_manager_.AddInterface(addr, ifname, |
427 adapter_type); | 440 adapter_type); |
428 } | 441 } |
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1165 EXPECT_TRUE(best_conn_info->writable); | 1178 EXPECT_TRUE(best_conn_info->writable); |
1166 EXPECT_FALSE(best_conn_info->timeout); | 1179 EXPECT_FALSE(best_conn_info->timeout); |
1167 EXPECT_EQ(10U, best_conn_info->sent_total_packets); | 1180 EXPECT_EQ(10U, best_conn_info->sent_total_packets); |
1168 EXPECT_EQ(0U, best_conn_info->sent_discarded_packets); | 1181 EXPECT_EQ(0U, best_conn_info->sent_discarded_packets); |
1169 EXPECT_EQ(10 * 36U, best_conn_info->sent_total_bytes); | 1182 EXPECT_EQ(10 * 36U, best_conn_info->sent_total_bytes); |
1170 EXPECT_EQ(10 * 36U, best_conn_info->recv_total_bytes); | 1183 EXPECT_EQ(10 * 36U, best_conn_info->recv_total_bytes); |
1171 EXPECT_GT(best_conn_info->rtt, 0U); | 1184 EXPECT_GT(best_conn_info->rtt, 0U); |
1172 DestroyChannels(); | 1185 DestroyChannels(); |
1173 } | 1186 } |
1174 | 1187 |
| 1188 TEST_F(P2PTransportChannelTest, |
| 1189 TestIceRegatheringReasonIceRestartWhenDisconnected) { |
| 1190 rtc::ScopedFakeClock clock; |
| 1191 ConfigureEndpoints(OPEN, OPEN, kOnlyLocalPorts, kOnlyLocalPorts); |
| 1192 |
| 1193 CreateChannels(); |
| 1194 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 1195 ep2_ch1()->receiving() && |
| 1196 ep2_ch1()->writable(), |
| 1197 kDefaultTimeout, clock); |
| 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 const int kWriteTimeoutDelay = 6000; |
| 1202 EXPECT_TRUE_SIMULATED_WAIT(!ep1_ch1()->writable() && !ep2_ch1()->writable(), |
| 1203 kWriteTimeoutDelay, clock); |
| 1204 |
| 1205 ep1_ch1()->SetIceParameters(kIceParams[2]); |
| 1206 ep1_ch1()->SetRemoteIceParameters(kIceParams[3]); |
| 1207 ep1_ch1()->MaybeStartGathering(); |
| 1208 EXPECT_EQ(1, GetMetricsObserver(0)->GetEnumCounter( |
| 1209 webrtc::kEnumCounterIceRegatheringReason, |
| 1210 static_cast<int>( |
| 1211 IceRegatheringReason::ICE_RESTART_WHEN_DISCONNECTED))); |
| 1212 |
| 1213 ep2_ch1()->SetIceParameters(kIceParams[3]); |
| 1214 ep2_ch1()->SetRemoteIceParameters(kIceParams[2]); |
| 1215 ep2_ch1()->MaybeStartGathering(); |
| 1216 EXPECT_EQ(1, GetMetricsObserver(1)->GetEnumCounter( |
| 1217 webrtc::kEnumCounterIceRegatheringReason, |
| 1218 static_cast<int>( |
| 1219 IceRegatheringReason::ICE_RESTART_WHEN_DISCONNECTED))); |
| 1220 |
| 1221 DestroyChannels(); |
| 1222 } |
| 1223 |
| 1224 TEST_F(P2PTransportChannelTest, |
| 1225 TestIceRegatheringReasonIceRestartWhenConnected) { |
| 1226 rtc::ScopedFakeClock clock; |
| 1227 ConfigureEndpoints(OPEN, OPEN, kOnlyLocalPorts, kOnlyLocalPorts); |
| 1228 |
| 1229 CreateChannels(); |
| 1230 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 1231 ep2_ch1()->receiving() && |
| 1232 ep2_ch1()->writable(), |
| 1233 kDefaultTimeout, clock); |
| 1234 |
| 1235 ep1_ch1()->SetIceParameters(kIceParams[2]); |
| 1236 ep1_ch1()->SetRemoteIceParameters(kIceParams[3]); |
| 1237 ep1_ch1()->MaybeStartGathering(); |
| 1238 EXPECT_EQ( |
| 1239 1, |
| 1240 GetMetricsObserver(0)->GetEnumCounter( |
| 1241 webrtc::kEnumCounterIceRegatheringReason, |
| 1242 static_cast<int>(IceRegatheringReason::ICE_RESTART_WHEN_CONNECTED))); |
| 1243 |
| 1244 ep2_ch1()->SetIceParameters(kIceParams[3]); |
| 1245 ep2_ch1()->SetRemoteIceParameters(kIceParams[2]); |
| 1246 ep2_ch1()->MaybeStartGathering(); |
| 1247 EXPECT_EQ( |
| 1248 1, |
| 1249 GetMetricsObserver(1)->GetEnumCounter( |
| 1250 webrtc::kEnumCounterIceRegatheringReason, |
| 1251 static_cast<int>(IceRegatheringReason::ICE_RESTART_WHEN_CONNECTED))); |
| 1252 |
| 1253 DestroyChannels(); |
| 1254 } |
| 1255 |
| 1256 TEST_F(P2PTransportChannelTest, |
| 1257 TestIceRegatheringReasonIceRestartWhenConnecting) { |
| 1258 rtc::ScopedFakeClock clock; |
| 1259 ConfigureEndpoints(OPEN, OPEN, kOnlyLocalPorts, kOnlyLocalPorts); |
| 1260 |
| 1261 // Create the channels without waiting for them to become connected. |
| 1262 CreateChannels(); |
| 1263 |
| 1264 ep1_ch1()->SetIceParameters(kIceParams[2]); |
| 1265 ep1_ch1()->SetRemoteIceParameters(kIceParams[3]); |
| 1266 ep1_ch1()->MaybeStartGathering(); |
| 1267 EXPECT_EQ( |
| 1268 1, |
| 1269 GetMetricsObserver(0)->GetEnumCounter( |
| 1270 webrtc::kEnumCounterIceRegatheringReason, |
| 1271 static_cast<int>(IceRegatheringReason::ICE_RESTART_WHEN_CONNECTING))); |
| 1272 |
| 1273 ep2_ch1()->SetIceParameters(kIceParams[3]); |
| 1274 ep2_ch1()->SetRemoteIceParameters(kIceParams[2]); |
| 1275 ep2_ch1()->MaybeStartGathering(); |
| 1276 EXPECT_EQ( |
| 1277 1, |
| 1278 GetMetricsObserver(1)->GetEnumCounter( |
| 1279 webrtc::kEnumCounterIceRegatheringReason, |
| 1280 static_cast<int>(IceRegatheringReason::ICE_RESTART_WHEN_CONNECTING))); |
| 1281 |
| 1282 DestroyChannels(); |
| 1283 } |
| 1284 |
| 1285 // Test the ICE regathering reason where there is a network change on |
| 1286 // both endpoints and one of them enables continual gathering but the other |
| 1287 // does not. |
| 1288 TEST_F(P2PTransportChannelTest, |
| 1289 TestIceRegatheringReasonContinualGatheringByNetworkChange) { |
| 1290 rtc::ScopedFakeClock clock; |
| 1291 ConfigureEndpoints(OPEN, OPEN, kOnlyLocalPorts, kOnlyLocalPorts); |
| 1292 |
| 1293 // ep1 gathers continually but ep2 does not. |
| 1294 IceConfig continual_gathering_config = |
| 1295 CreateIceConfig(1000, GATHER_CONTINUALLY); |
| 1296 IceConfig default_config; |
| 1297 CreateChannels(continual_gathering_config, default_config); |
| 1298 |
| 1299 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 1300 ep2_ch1()->receiving() && |
| 1301 ep2_ch1()->writable(), |
| 1302 kDefaultTimeout, clock); |
| 1303 |
| 1304 // Add address in ep1 will trigger continual gathering. |
| 1305 AddAddress(0, kAlternateAddrs[0]); |
| 1306 EXPECT_EQ_SIMULATED_WAIT( |
| 1307 1, GetMetricsObserver(0)->GetEnumCounter( |
| 1308 webrtc::kEnumCounterIceRegatheringReason, |
| 1309 static_cast<int>( |
| 1310 IceRegatheringReason::CONTINUAL_GATHERING_BY_NETWORK_CHANGE)), |
| 1311 kDefaultTimeout, clock); |
| 1312 |
| 1313 ep2_ch1()->SetIceParameters(kIceParams[3]); |
| 1314 ep2_ch1()->SetRemoteIceParameters(kIceParams[2]); |
| 1315 ep2_ch1()->MaybeStartGathering(); |
| 1316 |
| 1317 AddAddress(1, kAlternateAddrs[1]); |
| 1318 SIMULATED_WAIT(false, kDefaultTimeout, clock); |
| 1319 // ep2 has not enabled continual gathering. |
| 1320 EXPECT_EQ( |
| 1321 0, GetMetricsObserver(1)->GetEnumCounter( |
| 1322 webrtc::kEnumCounterIceRegatheringReason, |
| 1323 static_cast<int>( |
| 1324 IceRegatheringReason::CONTINUAL_GATHERING_BY_NETWORK_CHANGE))); |
| 1325 |
| 1326 DestroyChannels(); |
| 1327 } |
| 1328 |
| 1329 // Test the ICE regathering reason where there is a network failure on |
| 1330 // both endpoints and one of them enables continual gathering but the other |
| 1331 // does not. |
| 1332 TEST_F(P2PTransportChannelTest, |
| 1333 TestIceRegatheringReasonContinualGatheringByNetworkFailure) { |
| 1334 rtc::ScopedFakeClock clock; |
| 1335 ConfigureEndpoints(OPEN, OPEN, kOnlyLocalPorts, kOnlyLocalPorts); |
| 1336 |
| 1337 // ep1 gathers continually but ep2 does not. |
| 1338 IceConfig config1 = CreateIceConfig(1000, GATHER_CONTINUALLY); |
| 1339 config1.regather_on_failed_networks_interval = rtc::Optional<int>(2000); |
| 1340 IceConfig config2; |
| 1341 config2.regather_on_failed_networks_interval = rtc::Optional<int>(2000); |
| 1342 CreateChannels(config1, config2); |
| 1343 |
| 1344 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 1345 ep2_ch1()->receiving() && |
| 1346 ep2_ch1()->writable(), |
| 1347 kDefaultTimeout, clock); |
| 1348 |
| 1349 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]); |
| 1350 // Timeout value such that all connections are deleted. |
| 1351 const int kNetworkFailureTimeout = 35000; |
| 1352 SIMULATED_WAIT(false, kNetworkFailureTimeout, clock); |
| 1353 EXPECT_LE( |
| 1354 1, |
| 1355 GetMetricsObserver(0)->GetEnumCounter( |
| 1356 webrtc::kEnumCounterIceRegatheringReason, |
| 1357 static_cast<int>( |
| 1358 IceRegatheringReason::CONTINUAL_GATHERING_BY_NETWORK_FAILURE))); |
| 1359 EXPECT_EQ( |
| 1360 0, |
| 1361 GetMetricsObserver(1)->GetEnumCounter( |
| 1362 webrtc::kEnumCounterIceRegatheringReason, |
| 1363 static_cast<int>( |
| 1364 IceRegatheringReason::CONTINUAL_GATHERING_BY_NETWORK_FAILURE))); |
| 1365 |
| 1366 DestroyChannels(); |
| 1367 } |
| 1368 |
1175 // Test that we properly create a connection on a STUN ping from unknown address | 1369 // Test that we properly create a connection on a STUN ping from unknown address |
1176 // when the signaling is slow. | 1370 // when the signaling is slow. |
1177 TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignaling) { | 1371 TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignaling) { |
1178 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, | 1372 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, |
1179 kDefaultPortAllocatorFlags); | 1373 kDefaultPortAllocatorFlags); |
1180 // Emulate no remote parameters coming in. | 1374 // Emulate no remote parameters coming in. |
1181 set_remote_ice_parameter_source(FROM_CANDIDATE); | 1375 set_remote_ice_parameter_source(FROM_CANDIDATE); |
1182 CreateChannels(); | 1376 CreateChannels(); |
1183 // Only have remote parameters come in for ep2, not ep1. | 1377 // Only have remote parameters come in for ep2, not ep1. |
1184 ep2_ch1()->SetRemoteIceParameters(kIceParams[0]); | 1378 ep2_ch1()->SetRemoteIceParameters(kIceParams[0]); |
(...skipping 2815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4000 | 4194 |
4001 // TCP Relay/Relay is the next. | 4195 // TCP Relay/Relay is the next. |
4002 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, | 4196 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, |
4003 TCP_PROTOCOL_NAME); | 4197 TCP_PROTOCOL_NAME); |
4004 | 4198 |
4005 // Finally, Local/Relay will be pinged. | 4199 // Finally, Local/Relay will be pinged. |
4006 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); | 4200 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); |
4007 } | 4201 } |
4008 | 4202 |
4009 } // namespace cricket { | 4203 } // namespace cricket { |
OLD | NEW |