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

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

Issue 2163403002: Prepare for ICE-renomination (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: . Created 4 years, 4 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
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 // On the candidate itself, or through SetIceCredentials? 842 // On the candidate itself, or through SetIceCredentials?
843 // Goes through the candidate itself by default. 843 // Goes through the candidate itself by default.
844 void set_remote_ice_credential_source(RemoteIceCredentialSource source) { 844 void set_remote_ice_credential_source(RemoteIceCredentialSource source) {
845 remote_ice_credential_source_ = source; 845 remote_ice_credential_source_ = source;
846 } 846 }
847 847
848 void set_force_relay(bool relay) { 848 void set_force_relay(bool relay) {
849 force_relay_ = relay; 849 force_relay_ = relay;
850 } 850 }
851 851
852 void ConnectSignalNominated(Connection* conn) {
853 conn->SignalNominated.connect(this,
854 &P2PTransportChannelTestBase::OnNominated);
855 }
856
857 void OnNominated(Connection* conn) { nominated_ = true; }
858 bool nominated() { return nominated_; }
859
852 private: 860 private:
853 rtc::Thread* main_; 861 rtc::Thread* main_;
854 std::unique_ptr<rtc::PhysicalSocketServer> pss_; 862 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
855 std::unique_ptr<rtc::VirtualSocketServer> vss_; 863 std::unique_ptr<rtc::VirtualSocketServer> vss_;
856 std::unique_ptr<rtc::NATSocketServer> nss_; 864 std::unique_ptr<rtc::NATSocketServer> nss_;
857 std::unique_ptr<rtc::FirewallSocketServer> ss_; 865 std::unique_ptr<rtc::FirewallSocketServer> ss_;
858 rtc::SocketServerScope ss_scope_; 866 rtc::SocketServerScope ss_scope_;
859 std::unique_ptr<TestStunServer> stun_server_; 867 std::unique_ptr<TestStunServer> stun_server_;
860 TestTurnServer turn_server_; 868 TestTurnServer turn_server_;
861 TestRelayServer relay_server_; 869 TestRelayServer relay_server_;
862 rtc::SocksProxyServer socks_server1_; 870 rtc::SocksProxyServer socks_server1_;
863 rtc::SocksProxyServer socks_server2_; 871 rtc::SocksProxyServer socks_server2_;
864 Endpoint ep1_; 872 Endpoint ep1_;
865 Endpoint ep2_; 873 Endpoint ep2_;
866 RemoteIceCredentialSource remote_ice_credential_source_ = FROM_CANDIDATE; 874 RemoteIceCredentialSource remote_ice_credential_source_ = FROM_CANDIDATE;
867 bool force_relay_; 875 bool force_relay_;
868 int selected_candidate_pair_switches_ = 0; 876 int selected_candidate_pair_switches_ = 0;
877
878 bool nominated_ = false;
869 }; 879 };
870 880
871 // The tests have only a few outcomes, which we predefine. 881 // The tests have only a few outcomes, which we predefine.
872 const P2PTransportChannelTestBase::Result P2PTransportChannelTestBase:: 882 const P2PTransportChannelTestBase::Result P2PTransportChannelTestBase::
873 kLocalUdpToLocalUdp("local", "udp", "local", "udp", 883 kLocalUdpToLocalUdp("local", "udp", "local", "udp",
874 "local", "udp", "local", "udp", 1000); 884 "local", "udp", "local", "udp", 1000);
875 const P2PTransportChannelTestBase::Result P2PTransportChannelTestBase:: 885 const P2PTransportChannelTestBase::Result P2PTransportChannelTestBase::
876 kLocalUdpToStunUdp("local", "udp", "stun", "udp", 886 kLocalUdpToStunUdp("local", "udp", "stun", "udp",
877 "local", "udp", "stun", "udp", 1000); 887 "local", "udp", "stun", "udp", 1000);
878 const P2PTransportChannelTestBase::Result P2PTransportChannelTestBase:: 888 const P2PTransportChannelTestBase::Result P2PTransportChannelTestBase::
(...skipping 976 matching lines...) Expand 10 before | Expand all | Expand 10 after
1855 const SocketAddress& address) { 1865 const SocketAddress& address) {
1856 for (cricket::Connection* conn : channel->connections()) { 1866 for (cricket::Connection* conn : channel->connections()) {
1857 if (conn->local_candidate().address().EqualIPs(address)) { 1867 if (conn->local_candidate().address().EqualIPs(address)) {
1858 return conn; 1868 return conn;
1859 } 1869 }
1860 } 1870 }
1861 return nullptr; 1871 return nullptr;
1862 } 1872 }
1863 1873
1864 void DestroyAllButBestConnection(cricket::P2PTransportChannel* channel) { 1874 void DestroyAllButBestConnection(cricket::P2PTransportChannel* channel) {
1865 const cricket::Connection* best_connection = channel->best_connection(); 1875 const cricket::Connection* selected_connection =
1876 channel->selected_connection();
1866 for (cricket::Connection* conn : channel->connections()) { 1877 for (cricket::Connection* conn : channel->connections()) {
1867 if (conn != best_connection) { 1878 if (conn != selected_connection) {
1868 conn->Destroy(); 1879 conn->Destroy();
1869 } 1880 }
1870 } 1881 }
1871 } 1882 }
1872 }; 1883 };
1873 1884
1874 // Test that we can establish connectivity when both peers are multihomed. 1885 // Test that we can establish connectivity when both peers are multihomed.
1875 TEST_F(P2PTransportChannelMultihomedTest, DISABLED_TestBasic) { 1886 TEST_F(P2PTransportChannelMultihomedTest, DISABLED_TestBasic) {
1876 AddAddress(0, kPublicAddrs[0]); 1887 AddAddress(0, kPublicAddrs[0]);
1877 AddAddress(0, kAlternateAddrs[0]); 1888 AddAddress(0, kAlternateAddrs[0]);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1984 3000, clock); 1995 3000, clock);
1985 EXPECT_TRUE( 1996 EXPECT_TRUE(
1986 LocalCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0])); 1997 LocalCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0]));
1987 EXPECT_TRUE(RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); 1998 EXPECT_TRUE(RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1]));
1988 EXPECT_TRUE( 1999 EXPECT_TRUE(
1989 RemoteCandidate(ep2_ch1())->address().EqualIPs(kAlternateAddrs[0])); 2000 RemoteCandidate(ep2_ch1())->address().EqualIPs(kAlternateAddrs[0]));
1990 2001
1991 DestroyChannels(); 2002 DestroyChannels();
1992 } 2003 }
1993 2004
2005 // Test that when the controlling side switches the selected connection,
2006 // the nomination of the selected connection on the controlled side will
2007 // increase.
2008 TEST_F(P2PTransportChannelMultihomedTest, TestIceRenomination) {
2009 rtc::ScopedFakeClock clock;
2010 // Adding alternate address will make sure |kPublicAddrs| has the higher
2011 // priority than others. This is due to FakeNetwork::AddInterface method.
2012 AddAddress(0, kAlternateAddrs[0]);
2013 AddAddress(0, kPublicAddrs[0]);
2014 AddAddress(1, kPublicAddrs[1]);
2015
2016 // Use only local ports for simplicity.
2017 SetAllocatorFlags(0, kOnlyLocalPorts);
2018 SetAllocatorFlags(1, kOnlyLocalPorts);
2019
2020 // Create channels and let them go writable, as usual.
2021 CreateChannels(1);
2022 ep1_ch1()->set_remote_supports_renomination(true);
2023 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
2024 ep2_ch1()->receiving() &&
2025 ep2_ch1()->writable(),
2026 3000, clock);
2027 EXPECT_TRUE_SIMULATED_WAIT(
2028 ep2_ch1()->selected_connection()->remote_nomination() > 0 &&
2029 ep1_ch1()->selected_connection()->acked_nomination() > 0,
2030 kDefaultTimeout, clock);
2031 const Connection* selected_connection1 = ep1_ch1()->selected_connection();
2032 Connection* selected_connection2 =
2033 const_cast<Connection*>(ep2_ch1()->selected_connection());
2034 int remote_nomination2 = selected_connection2->remote_nomination();
2035 // |selected_connection2| should not be nominated any more since the previous
2036 // nomination has been acknowledged.
2037 ConnectSignalNominated(selected_connection2);
2038 SIMULATED_WAIT(nominated(), 3000, clock);
2039 EXPECT_FALSE(nominated());
2040
2041 // Make the receiving timeout shorter for testing.
2042 IceConfig config = CreateIceConfig(1000, GATHER_ONCE);
2043 ep1_ch1()->SetIceConfig(config);
2044 ep2_ch1()->SetIceConfig(config);
2045
2046 // Blackhole any traffic to or from the public addrs.
2047 LOG(LS_INFO) << "Failing over...";
2048 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]);
2049
2050 // The selected connection on the controlling side should switch.
2051 EXPECT_TRUE_SIMULATED_WAIT(
2052 ep1_ch1()->selected_connection() != selected_connection1, 3000, clock);
2053 // The connection on the controlled side should be nominated again
2054 // and have an increased nomination.
2055 EXPECT_TRUE_SIMULATED_WAIT(
2056 ep2_ch1()->selected_connection()->remote_nomination() >
2057 remote_nomination2,
2058 kDefaultTimeout, clock);
2059
2060 DestroyChannels();
2061 }
2062
1994 // Test that if an interface fails temporarily and then recovers quickly, 2063 // Test that if an interface fails temporarily and then recovers quickly,
1995 // the selected connection will not switch. 2064 // the selected connection will not switch.
1996 // The case that it will switch over to the backup connection if the selected 2065 // The case that it will switch over to the backup connection if the selected
1997 // connection does not recover after enough time is covered in 2066 // connection does not recover after enough time is covered in
1998 // TestFailoverControlledSide and TestFailoverControllingSide. 2067 // TestFailoverControlledSide and TestFailoverControllingSide.
1999 TEST_F(P2PTransportChannelMultihomedTest, 2068 TEST_F(P2PTransportChannelMultihomedTest,
2000 TestConnectionSwitchDampeningControlledSide) { 2069 TestConnectionSwitchDampeningControlledSide) {
2001 rtc::ScopedFakeClock clock; 2070 rtc::ScopedFakeClock clock;
2002 AddAddress(0, kPublicAddrs[0]); 2071 AddAddress(0, kPublicAddrs[0]);
2003 // Adding alternate address will make sure |kPublicAddrs| has the higher 2072 // Adding alternate address will make sure |kPublicAddrs| has the higher
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
2288 SetAllocatorFlags(0, kOnlyLocalPorts); 2357 SetAllocatorFlags(0, kOnlyLocalPorts);
2289 SetAllocatorFlags(1, kOnlyLocalPorts); 2358 SetAllocatorFlags(1, kOnlyLocalPorts);
2290 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && 2359 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
2291 ep2_ch1()->receiving() && ep2_ch1()->writable(), 2360 ep2_ch1()->receiving() && ep2_ch1()->writable(),
2292 kDefaultTimeout, kDefaultTimeout); 2361 kDefaultTimeout, kDefaultTimeout);
2293 2362
2294 // Add a new wifi interface on end point 2. We should expect a new connection 2363 // Add a new wifi interface on end point 2. We should expect a new connection
2295 // to be created and the new one will be the best connection. 2364 // to be created and the new one will be the best connection.
2296 AddAddress(1, wifi[1], "test_wifi1", rtc::ADAPTER_TYPE_WIFI); 2365 AddAddress(1, wifi[1], "test_wifi1", rtc::ADAPTER_TYPE_WIFI);
2297 const cricket::Connection* conn; 2366 const cricket::Connection* conn;
2298 EXPECT_TRUE_WAIT((conn = ep1_ch1()->best_connection()) != nullptr && 2367 EXPECT_TRUE_WAIT((conn = ep1_ch1()->selected_connection()) != nullptr &&
2299 conn->remote_candidate().address().EqualIPs(wifi[1]), 2368 conn->remote_candidate().address().EqualIPs(wifi[1]),
2300 kDefaultTimeout); 2369 kDefaultTimeout);
2301 EXPECT_TRUE_WAIT((conn = ep2_ch1()->best_connection()) != nullptr && 2370 EXPECT_TRUE_WAIT((conn = ep2_ch1()->selected_connection()) != nullptr &&
2302 conn->local_candidate().address().EqualIPs(wifi[1]), 2371 conn->local_candidate().address().EqualIPs(wifi[1]),
2303 kDefaultTimeout); 2372 kDefaultTimeout);
2304 2373
2305 // Add a new cellular interface on end point 1, we should expect a new 2374 // Add a new cellular interface on end point 1, we should expect a new
2306 // backup connection created using this new interface. 2375 // backup connection created using this new interface.
2307 AddAddress(0, cellular[0], "test_cellular0", rtc::ADAPTER_TYPE_CELLULAR); 2376 AddAddress(0, cellular[0], "test_cellular0", rtc::ADAPTER_TYPE_CELLULAR);
2308 EXPECT_TRUE_WAIT(ep1_ch1()->GetState() == cricket::STATE_COMPLETED && 2377 EXPECT_TRUE_WAIT(
2309 (conn = GetConnectionWithLocalAddress( 2378 ep1_ch1()->GetState() == cricket::STATE_COMPLETED &&
2310 ep1_ch1(), cellular[0])) != nullptr && 2379 (conn = GetConnectionWithLocalAddress(ep1_ch1(), cellular[0])) !=
2311 conn != ep1_ch1()->best_connection() && conn->writable(), 2380 nullptr &&
2312 kDefaultTimeout); 2381 conn != ep1_ch1()->selected_connection() && conn->writable(),
2382 kDefaultTimeout);
2313 EXPECT_TRUE_WAIT( 2383 EXPECT_TRUE_WAIT(
2314 ep2_ch1()->GetState() == cricket::STATE_COMPLETED && 2384 ep2_ch1()->GetState() == cricket::STATE_COMPLETED &&
2315 (conn = GetConnectionWithRemoteAddress(ep2_ch1(), cellular[0])) != 2385 (conn = GetConnectionWithRemoteAddress(ep2_ch1(), cellular[0])) !=
2316 nullptr && 2386 nullptr &&
2317 conn != ep2_ch1()->best_connection() && conn->receiving(), 2387 conn != ep2_ch1()->selected_connection() && conn->receiving(),
2318 kDefaultTimeout); 2388 kDefaultTimeout);
2319 2389
2320 DestroyChannels(); 2390 DestroyChannels();
2321 } 2391 }
2322 2392
2323 // Tests that we can switch links via continual gathering. 2393 // Tests that we can switch links via continual gathering.
2324 TEST_F(P2PTransportChannelMultihomedTest, 2394 TEST_F(P2PTransportChannelMultihomedTest,
2325 TestSwitchLinksViaContinualGathering) { 2395 TestSwitchLinksViaContinualGathering) {
2326 rtc::ScopedFakeClock clock; 2396 rtc::ScopedFakeClock clock;
2327 AddAddress(0, kPublicAddrs[0]); 2397 AddAddress(0, kPublicAddrs[0]);
(...skipping 25 matching lines...) Expand all
2353 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() && 2423 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() &&
2354 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && 2424 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) &&
2355 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]), 2425 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]),
2356 3000, clock); 2426 3000, clock);
2357 2427
2358 // Remove one address first and then add another address. 2428 // Remove one address first and then add another address.
2359 LOG(LS_INFO) << "Draining again..."; 2429 LOG(LS_INFO) << "Draining again...";
2360 RemoveAddress(1, kAlternateAddrs[1]); 2430 RemoveAddress(1, kAlternateAddrs[1]);
2361 AddAddress(1, kAlternateAddrs[0]); 2431 AddAddress(1, kAlternateAddrs[0]);
2362 EXPECT_TRUE_SIMULATED_WAIT( 2432 EXPECT_TRUE_SIMULATED_WAIT(
2363 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && 2433 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() &&
2364 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && 2434 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) &&
2365 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0]), 2435 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0]),
2366 3000, clock); 2436 3000, clock);
2367 2437
2368 DestroyChannels(); 2438 DestroyChannels();
2369 } 2439 }
2370 2440
2371 /* 2441 /*
2372 TODO(honghaiz) Once continual gathering fully supports 2442 TODO(honghaiz) Once continual gathering fully supports
2373 GATHER_CONTINUALLY_AND_RECOVER, put this test back. 2443 GATHER_CONTINUALLY_AND_RECOVER, put this test back.
(...skipping 16 matching lines...) Expand all
2390 2460
2391 // Create channels and let them go writable, as usual. 2461 // Create channels and let them go writable, as usual.
2392 CreateChannels(1); 2462 CreateChannels(1);
2393 // Set continual gathering policy. 2463 // Set continual gathering policy.
2394 IceConfig config = CreateIceConfig(1000, GATHER_CONTINUALLY_AND_RECOVER); 2464 IceConfig config = CreateIceConfig(1000, GATHER_CONTINUALLY_AND_RECOVER);
2395 ep1_ch1()->SetIceConfig(config); 2465 ep1_ch1()->SetIceConfig(config);
2396 ep2_ch1()->SetIceConfig(config); 2466 ep2_ch1()->SetIceConfig(config);
2397 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && 2467 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
2398 ep2_ch1()->receiving() && ep2_ch1()->writable(), 2468 ep2_ch1()->receiving() && ep2_ch1()->writable(),
2399 3000, clock); 2469 3000, clock);
2400 EXPECT_TRUE(ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && 2470 EXPECT_TRUE(ep1_ch1()->selected_connection() &&
2471 ep2_ch1()->selected_connection() &&
2401 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) && 2472 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) &&
2402 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1])); 2473 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]));
2403 2474
2404 // First destroy all backup connection. 2475 // First destroy all backup connection.
2405 DestroyAllButBestConnection(ep1_ch1()); 2476 DestroyAllButBestConnection(ep1_ch1());
2406 2477
2407 SIMULATED_WAIT(false, 10, clock); 2478 SIMULATED_WAIT(false, 10, clock);
2408 // Then the interface of the best connection goes away. 2479 // Then the interface of the best connection goes away.
2409 RemoveAddress(0, wifi[0]); 2480 RemoveAddress(0, wifi[0]);
2410 EXPECT_TRUE_SIMULATED_WAIT( 2481 EXPECT_TRUE_SIMULATED_WAIT(
2411 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && 2482 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() &&
2412 LocalCandidate(ep1_ch1())->address().EqualIPs(cellular[0]) && 2483 LocalCandidate(ep1_ch1())->address().EqualIPs(cellular[0]) &&
2413 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]), 2484 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]),
2414 3000, clock); 2485 3000, clock);
2415 2486
2416 DestroyChannels(); 2487 DestroyChannels();
2417 } 2488 }
2418 */ 2489 */
2419 2490
2420 // Tests that the backup connection will be restored after it is destroyed. 2491 // Tests that the backup connection will be restored after it is destroyed.
2421 TEST_F(P2PTransportChannelMultihomedTest, TestRestoreBackupConnection) { 2492 TEST_F(P2PTransportChannelMultihomedTest, TestRestoreBackupConnection) {
(...skipping 11 matching lines...) Expand all
2433 // Create channels and let them go writable, as usual. 2504 // Create channels and let them go writable, as usual.
2434 CreateChannels(1); 2505 CreateChannels(1);
2435 IceConfig config = CreateIceConfig(1000, GATHER_CONTINUALLY); 2506 IceConfig config = CreateIceConfig(1000, GATHER_CONTINUALLY);
2436 config.regather_on_failed_networks_interval = rtc::Optional<int>(2000); 2507 config.regather_on_failed_networks_interval = rtc::Optional<int>(2000);
2437 ep1_ch1()->SetIceConfig(config); 2508 ep1_ch1()->SetIceConfig(config);
2438 ep2_ch1()->SetIceConfig(config); 2509 ep2_ch1()->SetIceConfig(config);
2439 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && 2510 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
2440 ep2_ch1()->receiving() && 2511 ep2_ch1()->receiving() &&
2441 ep2_ch1()->writable(), 2512 ep2_ch1()->writable(),
2442 3000, clock); 2513 3000, clock);
2443 EXPECT_TRUE(ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && 2514 EXPECT_TRUE(ep1_ch1()->selected_connection() &&
2515 ep2_ch1()->selected_connection() &&
2444 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) && 2516 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) &&
2445 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1])); 2517 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]));
2446 2518
2447 // Destroy all backup connections. 2519 // Destroy all backup connections.
2448 DestroyAllButBestConnection(ep1_ch1()); 2520 DestroyAllButBestConnection(ep1_ch1());
2449 // Ensure the backup connection is removed first. 2521 // Ensure the backup connection is removed first.
2450 EXPECT_TRUE_SIMULATED_WAIT( 2522 EXPECT_TRUE_SIMULATED_WAIT(
2451 GetConnectionWithLocalAddress(ep1_ch1(), cellular[0]) == nullptr, 2523 GetConnectionWithLocalAddress(ep1_ch1(), cellular[0]) == nullptr,
2452 kDefaultTimeout, clock); 2524 kDefaultTimeout, clock);
2453 const cricket::Connection* conn; 2525 const cricket::Connection* conn;
2454 EXPECT_TRUE_SIMULATED_WAIT( 2526 EXPECT_TRUE_SIMULATED_WAIT(
2455 (conn = GetConnectionWithLocalAddress(ep1_ch1(), cellular[0])) != 2527 (conn = GetConnectionWithLocalAddress(ep1_ch1(), cellular[0])) !=
2456 nullptr && 2528 nullptr &&
2457 conn != ep1_ch1()->best_connection() && conn->writable(), 2529 conn != ep1_ch1()->selected_connection() && conn->writable(),
2458 5000, clock); 2530 5000, clock);
2459 2531
2460 DestroyChannels(); 2532 DestroyChannels();
2461 } 2533 }
2462 2534
2463 // A collection of tests which tests a single P2PTransportChannel by sending 2535 // A collection of tests which tests a single P2PTransportChannel by sending
2464 // pings. 2536 // pings.
2465 class P2PTransportChannelPingTest : public testing::Test, 2537 class P2PTransportChannelPingTest : public testing::Test,
2466 public sigslot::has_slots<> { 2538 public sigslot::has_slots<> {
2467 public: 2539 public:
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
2537 int port, 2609 int port,
2538 int priority, 2610 int priority,
2539 bool writable) { 2611 bool writable) {
2540 channel.AddRemoteCandidate( 2612 channel.AddRemoteCandidate(
2541 CreateUdpCandidate(LOCAL_PORT_TYPE, ip_addr, port, priority)); 2613 CreateUdpCandidate(LOCAL_PORT_TYPE, ip_addr, port, priority));
2542 EXPECT_TRUE_SIMULATED_WAIT( 2614 EXPECT_TRUE_SIMULATED_WAIT(
2543 GetConnectionTo(&channel, ip_addr, port) != nullptr, 3000, clock); 2615 GetConnectionTo(&channel, ip_addr, port) != nullptr, 3000, clock);
2544 Connection* conn = GetConnectionTo(&channel, ip_addr, port); 2616 Connection* conn = GetConnectionTo(&channel, ip_addr, port);
2545 2617
2546 if (conn && writable) { 2618 if (conn && writable) {
2547 conn->ReceivedPingResponse(LOW_RTT); // make it writable 2619 conn->ReceivedPingResponse(LOW_RTT, "id"); // make it writable
2548 } 2620 }
2549 return conn; 2621 return conn;
2550 } 2622 }
2551 2623
2552 void NominateConnection(Connection* conn) { 2624 void NominateConnection(Connection* conn, int remote_nomination = 1) {
2553 conn->set_nominated(true); 2625 conn->set_remote_nomination(remote_nomination);
2554 conn->SignalNominated(conn); 2626 conn->SignalNominated(conn);
2555 } 2627 }
2556 2628
2557 void OnSelectedCandidatePairChanged( 2629 void OnSelectedCandidatePairChanged(
2558 TransportChannel* transport_channel, 2630 TransportChannel* transport_channel,
2559 CandidatePairInterface* selected_candidate_pair, 2631 CandidatePairInterface* selected_candidate_pair,
2560 int last_sent_packet_id, 2632 int last_sent_packet_id,
2561 bool ready_to_send) { 2633 bool ready_to_send) {
2562 last_selected_candidate_pair_ = selected_candidate_pair; 2634 last_selected_candidate_pair_ = selected_candidate_pair;
2563 last_sent_packet_id_ = last_sent_packet_id; 2635 last_sent_packet_id_ = last_sent_packet_id;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
2644 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 2716 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
2645 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); 2717 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
2646 2718
2647 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2719 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2648 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 2720 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2649 ASSERT_TRUE(conn1 != nullptr); 2721 ASSERT_TRUE(conn1 != nullptr);
2650 ASSERT_TRUE(conn2 != nullptr); 2722 ASSERT_TRUE(conn2 != nullptr);
2651 2723
2652 // Low-priority connection becomes writable so that the other connection 2724 // Low-priority connection becomes writable so that the other connection
2653 // is not pruned. 2725 // is not pruned.
2654 conn1->ReceivedPingResponse(LOW_RTT); 2726 conn1->ReceivedPingResponse(LOW_RTT, "id");
2655 EXPECT_TRUE_WAIT( 2727 EXPECT_TRUE_WAIT(
2656 conn1->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL && 2728 conn1->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL &&
2657 conn2->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL, 2729 conn2->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL,
2658 kDefaultTimeout); 2730 kDefaultTimeout);
2659 } 2731 }
2660 2732
2661 // Verify that the connections are pinged at the right time. 2733 // Verify that the connections are pinged at the right time.
2662 TEST_F(P2PTransportChannelPingTest, TestStunPingIntervals) { 2734 TEST_F(P2PTransportChannelPingTest, TestStunPingIntervals) {
2663 rtc::ScopedFakeClock clock; 2735 rtc::ScopedFakeClock clock;
2664 int RTT_RATIO = 4; 2736 int RTT_RATIO = 4;
(...skipping 15 matching lines...) Expand all
2680 int64_t start = clock.TimeNanos(); 2752 int64_t start = clock.TimeNanos();
2681 SIMULATED_WAIT(conn->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL, 2753 SIMULATED_WAIT(conn->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL,
2682 kDefaultTimeout, clock); 2754 kDefaultTimeout, clock);
2683 int64_t ping_interval_ms = (clock.TimeNanos() - start) / 2755 int64_t ping_interval_ms = (clock.TimeNanos() - start) /
2684 rtc::kNumNanosecsPerMillisec / 2756 rtc::kNumNanosecsPerMillisec /
2685 (MIN_PINGS_AT_WEAK_PING_INTERVAL - 1); 2757 (MIN_PINGS_AT_WEAK_PING_INTERVAL - 1);
2686 EXPECT_EQ(ping_interval_ms, WEAK_PING_INTERVAL); 2758 EXPECT_EQ(ping_interval_ms, WEAK_PING_INTERVAL);
2687 2759
2688 // Stabilizing. 2760 // Stabilizing.
2689 2761
2690 conn->ReceivedPingResponse(LOW_RTT); 2762 conn->ReceivedPingResponse(LOW_RTT, "id");
2691 int ping_sent_before = conn->num_pings_sent(); 2763 int ping_sent_before = conn->num_pings_sent();
2692 start = clock.TimeNanos(); 2764 start = clock.TimeNanos();
2693 // The connection becomes strong but not stable because we haven't been able 2765 // The connection becomes strong but not stable because we haven't been able
2694 // to converge the RTT. 2766 // to converge the RTT.
2695 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock); 2767 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock);
2696 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; 2768 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec;
2697 EXPECT_GE(ping_interval_ms, STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL); 2769 EXPECT_GE(ping_interval_ms, STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL);
2698 EXPECT_LE(ping_interval_ms, 2770 EXPECT_LE(ping_interval_ms,
2699 STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE); 2771 STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE);
2700 2772
2701 // Stabilized. 2773 // Stabilized.
2702 2774
2703 // The connection becomes stable after receiving more than RTT_RATIO rtt 2775 // The connection becomes stable after receiving more than RTT_RATIO rtt
2704 // samples. 2776 // samples.
2705 for (int i = 0; i < RTT_RATIO; i++) { 2777 for (int i = 0; i < RTT_RATIO; i++) {
2706 conn->ReceivedPingResponse(LOW_RTT); 2778 conn->ReceivedPingResponse(LOW_RTT, "id");
2707 } 2779 }
2708 ping_sent_before = conn->num_pings_sent(); 2780 ping_sent_before = conn->num_pings_sent();
2709 start = clock.TimeNanos(); 2781 start = clock.TimeNanos();
2710 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock); 2782 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock);
2711 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; 2783 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec;
2712 EXPECT_GE(ping_interval_ms, STABLE_WRITABLE_CONNECTION_PING_INTERVAL); 2784 EXPECT_GE(ping_interval_ms, STABLE_WRITABLE_CONNECTION_PING_INTERVAL);
2713 EXPECT_LE(ping_interval_ms, 2785 EXPECT_LE(ping_interval_ms,
2714 STABLE_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE); 2786 STABLE_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE);
2715 2787
2716 // Destabilized. 2788 // Destabilized.
2717 2789
2718 conn->ReceivedPingResponse(LOW_RTT); 2790 conn->ReceivedPingResponse(LOW_RTT, "id");
2719 // Create a in-flight ping. 2791 // Create a in-flight ping.
2720 conn->Ping(clock.TimeNanos() / rtc::kNumNanosecsPerMillisec); 2792 conn->Ping(clock.TimeNanos() / rtc::kNumNanosecsPerMillisec);
2721 start = clock.TimeNanos(); 2793 start = clock.TimeNanos();
2722 // In-flight ping timeout and the connection will be unstable. 2794 // In-flight ping timeout and the connection will be unstable.
2723 SIMULATED_WAIT( 2795 SIMULATED_WAIT(
2724 !conn->stable(clock.TimeNanos() / rtc::kNumNanosecsPerMillisec), 3000, 2796 !conn->stable(clock.TimeNanos() / rtc::kNumNanosecsPerMillisec), 3000,
2725 clock); 2797 clock);
2726 int64_t duration_ms = 2798 int64_t duration_ms =
2727 (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; 2799 (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec;
2728 EXPECT_GE(duration_ms, 2 * conn->rtt() - RTT_RANGE); 2800 EXPECT_GE(duration_ms, 2 * conn->rtt() - RTT_RANGE);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
2790 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 2862 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
2791 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); 2863 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
2792 2864
2793 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2865 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2794 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 2866 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2795 ASSERT_TRUE(conn1 != nullptr); 2867 ASSERT_TRUE(conn1 != nullptr);
2796 ASSERT_TRUE(conn2 != nullptr); 2868 ASSERT_TRUE(conn2 != nullptr);
2797 2869
2798 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); 2870 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch));
2799 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch)); 2871 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch));
2800 conn1->ReceivedPingResponse(LOW_RTT); 2872 conn1->ReceivedPingResponse(LOW_RTT, "id");
2801 ASSERT_TRUE(conn1->writable()); 2873 ASSERT_TRUE(conn1->writable());
2802 conn1->ReceivedPing(); 2874 conn1->ReceivedPing();
2803 2875
2804 // Ping received, but the connection is already writable, so no 2876 // Ping received, but the connection is already writable, so no
2805 // "triggered check" and conn2 is pinged before conn1 because it has 2877 // "triggered check" and conn2 is pinged before conn1 because it has
2806 // a higher priority. 2878 // a higher priority.
2807 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); 2879 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch));
2808 } 2880 }
2809 2881
2810 TEST_F(P2PTransportChannelPingTest, TestFailedConnectionNotPingable) { 2882 TEST_F(P2PTransportChannelPingTest, TestFailedConnectionNotPingable) {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
2907 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2979 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2908 ASSERT_TRUE(conn1 != nullptr); 2980 ASSERT_TRUE(conn1 != nullptr);
2909 uint32_t remote_priority = conn1->remote_candidate().priority(); 2981 uint32_t remote_priority = conn1->remote_candidate().priority();
2910 2982
2911 // Create a higher priority candidate and make the connection 2983 // Create a higher priority candidate and make the connection
2912 // receiving/writable. This will prune conn1. 2984 // receiving/writable. This will prune conn1.
2913 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); 2985 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
2914 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 2986 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2915 ASSERT_TRUE(conn2 != nullptr); 2987 ASSERT_TRUE(conn2 != nullptr);
2916 conn2->ReceivedPing(); 2988 conn2->ReceivedPing();
2917 conn2->ReceivedPingResponse(LOW_RTT); 2989 conn2->ReceivedPingResponse(LOW_RTT, "id");
2918 2990
2919 // Wait for conn1 to be pruned. 2991 // Wait for conn1 to be pruned.
2920 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); 2992 EXPECT_TRUE_WAIT(conn1->pruned(), 3000);
2921 // Destroy the connection to test SignalUnknownAddress. 2993 // Destroy the connection to test SignalUnknownAddress.
2922 conn1->Destroy(); 2994 conn1->Destroy();
2923 EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 1000); 2995 EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 1000);
2924 2996
2925 // Create a minimal STUN message with prflx priority. 2997 // Create a minimal STUN message with prflx priority.
2926 IceMessage request; 2998 IceMessage request;
2927 request.SetType(STUN_BINDING_REQUEST); 2999 request.SetType(STUN_BINDING_REQUEST);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
3008 3080
3009 // If a stun request with use-candidate attribute arrives, the receiving 3081 // If a stun request with use-candidate attribute arrives, the receiving
3010 // connection will be set as the selected connection, even though 3082 // connection will be set as the selected connection, even though
3011 // its priority is lower. 3083 // its priority is lower.
3012 EXPECT_EQ(-1, SendData(ch, data, len, ++last_packet_id)); 3084 EXPECT_EQ(-1, SendData(ch, data, len, ++last_packet_id));
3013 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1)); 3085 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1));
3014 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); 3086 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
3015 ASSERT_TRUE(conn3 != nullptr); 3087 ASSERT_TRUE(conn3 != nullptr);
3016 // Because it has a lower priority, the selected connection is still conn2. 3088 // Because it has a lower priority, the selected connection is still conn2.
3017 EXPECT_EQ(conn2, ch.selected_connection()); 3089 EXPECT_EQ(conn2, ch.selected_connection());
3018 conn3->ReceivedPingResponse(LOW_RTT); // Become writable. 3090 conn3->ReceivedPingResponse(LOW_RTT, "id"); // Become writable.
3019 // But if it is nominated via use_candidate, it is chosen as the selected 3091 // But if it is nominated via use_candidate, it is chosen as the selected
3020 // connection. 3092 // connection.
3021 conn3->set_nominated(true); 3093 NominateConnection(conn3);
3022 conn3->SignalNominated(conn3);
3023 EXPECT_EQ(conn3, ch.selected_connection()); 3094 EXPECT_EQ(conn3, ch.selected_connection());
3024 EXPECT_EQ(conn3, last_selected_candidate_pair()); 3095 EXPECT_EQ(conn3, last_selected_candidate_pair());
3025 EXPECT_EQ(-1, last_sent_packet_id()); 3096 EXPECT_EQ(-1, last_sent_packet_id());
3026 EXPECT_TRUE(channel_ready_to_send()); 3097 EXPECT_TRUE(channel_ready_to_send());
3027 3098
3028 // Even if another higher priority candidate arrives, it will not be set as 3099 // Even if another higher priority candidate arrives, it will not be set as
3029 // the selected connection because the selected connection is nominated by 3100 // the selected connection because the selected connection is nominated by
3030 // the controlling side. 3101 // the controlling side.
3031 EXPECT_EQ(len, SendData(ch, data, len, ++last_packet_id)); 3102 EXPECT_EQ(len, SendData(ch, data, len, ++last_packet_id));
3032 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "4.4.4.4", 4, 100)); 3103 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "4.4.4.4", 4, 100));
3033 Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); 3104 Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4);
3034 ASSERT_TRUE(conn4 != nullptr); 3105 ASSERT_TRUE(conn4 != nullptr);
3035 EXPECT_EQ(conn3, ch.selected_connection()); 3106 EXPECT_EQ(conn3, ch.selected_connection());
3036 // But if it is nominated via use_candidate and writable, it will be set as 3107 // But if it is nominated via use_candidate and writable, it will be set as
3037 // the selected connection. 3108 // the selected connection.
3038 conn4->set_nominated(true); 3109 NominateConnection(conn4);
3039 conn4->SignalNominated(conn4);
3040 // Not switched yet because conn4 is not writable. 3110 // Not switched yet because conn4 is not writable.
3041 EXPECT_EQ(conn3, ch.selected_connection()); 3111 EXPECT_EQ(conn3, ch.selected_connection());
3042 reset_channel_ready_to_send(); 3112 reset_channel_ready_to_send();
3043 // The selected connection switches after conn4 becomes writable. 3113 // The selected connection switches after conn4 becomes writable.
3044 conn4->ReceivedPingResponse(LOW_RTT); 3114 conn4->ReceivedPingResponse(LOW_RTT, "id");
3045 EXPECT_EQ_WAIT(conn4, ch.selected_connection(), kDefaultTimeout); 3115 EXPECT_EQ_WAIT(conn4, ch.selected_connection(), kDefaultTimeout);
3046 EXPECT_EQ(conn4, last_selected_candidate_pair()); 3116 EXPECT_EQ(conn4, last_selected_candidate_pair());
3047 EXPECT_EQ(last_packet_id, last_sent_packet_id()); 3117 EXPECT_EQ(last_packet_id, last_sent_packet_id());
3048 // SignalReadyToSend is fired again because conn4 is writable. 3118 // SignalReadyToSend is fired again because conn4 is writable.
3049 EXPECT_TRUE(channel_ready_to_send()); 3119 EXPECT_TRUE(channel_ready_to_send());
3050 } 3120 }
3051 3121
3052 // The controlled side will select a connection as the "selected connection" 3122 // The controlled side will select a connection as the "selected connection"
3053 // based on requests from an unknown address before the controlling side 3123 // based on requests from an unknown address before the controlling side
3054 // nominates a connection, and will nominate a connection from an unknown 3124 // nominates a connection, and will nominate a connection from an unknown
(...skipping 14 matching lines...) Expand all
3069 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; 3139 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24;
3070 request.AddAttribute( 3140 request.AddAttribute(
3071 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); 3141 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority));
3072 TestUDPPort* port = static_cast<TestUDPPort*>(GetPort(&ch)); 3142 TestUDPPort* port = static_cast<TestUDPPort*>(GetPort(&ch));
3073 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP, 3143 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP,
3074 &request, kIceUfrag[1], false); 3144 &request, kIceUfrag[1], false);
3075 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3145 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3076 ASSERT_TRUE(conn1 != nullptr); 3146 ASSERT_TRUE(conn1 != nullptr);
3077 EXPECT_TRUE(port->sent_binding_response()); 3147 EXPECT_TRUE(port->sent_binding_response());
3078 EXPECT_EQ(conn1, ch.selected_connection()); 3148 EXPECT_EQ(conn1, ch.selected_connection());
3079 conn1->ReceivedPingResponse(LOW_RTT); 3149 conn1->ReceivedPingResponse(LOW_RTT, "id");
3080 EXPECT_EQ(conn1, ch.selected_connection()); 3150 EXPECT_EQ(conn1, ch.selected_connection());
3081 port->set_sent_binding_response(false); 3151 port->set_sent_binding_response(false);
3082 3152
3083 // Another connection is nominated via use_candidate. 3153 // Another connection is nominated via use_candidate.
3084 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); 3154 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1));
3085 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3155 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
3086 ASSERT_TRUE(conn2 != nullptr); 3156 ASSERT_TRUE(conn2 != nullptr);
3087 // Because it has a lower priority, the selected connection is still conn1. 3157 // Because it has a lower priority, the selected connection is still conn1.
3088 EXPECT_EQ(conn1, ch.selected_connection()); 3158 EXPECT_EQ(conn1, ch.selected_connection());
3089 // When it is nominated via use_candidate and writable, it is chosen as the 3159 // When it is nominated via use_candidate and writable, it is chosen as the
3090 // selected connection. 3160 // selected connection.
3091 conn2->ReceivedPingResponse(LOW_RTT); // Become writable. 3161 conn2->ReceivedPingResponse(LOW_RTT, "id"); // Become writable.
3092 conn2->set_nominated(true); 3162 NominateConnection(conn2);
3093 conn2->SignalNominated(conn2);
3094 EXPECT_EQ(conn2, ch.selected_connection()); 3163 EXPECT_EQ(conn2, ch.selected_connection());
3095 3164
3096 // Another request with unknown address, it will not be set as the selected 3165 // Another request with unknown address, it will not be set as the selected
3097 // connection because the selected connection was nominated by the controlling 3166 // connection because the selected connection was nominated by the controlling
3098 // side. 3167 // side.
3099 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), PROTO_UDP, 3168 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), PROTO_UDP,
3100 &request, kIceUfrag[1], false); 3169 &request, kIceUfrag[1], false);
3101 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); 3170 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
3102 ASSERT_TRUE(conn3 != nullptr); 3171 ASSERT_TRUE(conn3 != nullptr);
3103 EXPECT_TRUE(port->sent_binding_response()); 3172 EXPECT_TRUE(port->sent_binding_response());
3104 conn3->ReceivedPingResponse(LOW_RTT); // Become writable. 3173 conn3->ReceivedPingResponse(LOW_RTT, "id"); // Become writable.
3105 EXPECT_EQ(conn2, ch.selected_connection()); 3174 EXPECT_EQ(conn2, ch.selected_connection());
3106 port->set_sent_binding_response(false); 3175 port->set_sent_binding_response(false);
3107 3176
3108 // However if the request contains use_candidate attribute, it will be 3177 // However if the request contains use_candidate attribute, it will be
3109 // selected as the selected connection. 3178 // selected as the selected connection.
3110 request.AddAttribute(new StunByteStringAttribute(STUN_ATTR_USE_CANDIDATE)); 3179 request.AddAttribute(new StunByteStringAttribute(STUN_ATTR_USE_CANDIDATE));
3111 port->SignalUnknownAddress(port, rtc::SocketAddress("4.4.4.4", 4), PROTO_UDP, 3180 port->SignalUnknownAddress(port, rtc::SocketAddress("4.4.4.4", 4), PROTO_UDP,
3112 &request, kIceUfrag[1], false); 3181 &request, kIceUfrag[1], false);
3113 Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); 3182 Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4);
3114 ASSERT_TRUE(conn4 != nullptr); 3183 ASSERT_TRUE(conn4 != nullptr);
3115 EXPECT_TRUE(port->sent_binding_response()); 3184 EXPECT_TRUE(port->sent_binding_response());
3116 // conn4 is not the selected connection yet because it is not writable. 3185 // conn4 is not the selected connection yet because it is not writable.
3117 EXPECT_EQ(conn2, ch.selected_connection()); 3186 EXPECT_EQ(conn2, ch.selected_connection());
3118 conn4->ReceivedPingResponse(LOW_RTT); // Become writable. 3187 conn4->ReceivedPingResponse(LOW_RTT, "id"); // Become writable.
3119 EXPECT_EQ_WAIT(conn4, ch.selected_connection(), kDefaultTimeout); 3188 EXPECT_EQ_WAIT(conn4, ch.selected_connection(), kDefaultTimeout);
3120 3189
3121 // Test that the request from an unknown address contains a ufrag from an old 3190 // Test that the request from an unknown address contains a ufrag from an old
3122 // generation. 3191 // generation.
3123 port->set_sent_binding_response(false); 3192 port->set_sent_binding_response(false);
3124 ch.SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); 3193 ch.SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]);
3125 ch.SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); 3194 ch.SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]);
3126 port->SignalUnknownAddress(port, rtc::SocketAddress("5.5.5.5", 5), PROTO_UDP, 3195 port->SignalUnknownAddress(port, rtc::SocketAddress("5.5.5.5", 5), PROTO_UDP,
3127 &request, kIceUfrag[2], false); 3196 &request, kIceUfrag[2], false);
3128 Connection* conn5 = WaitForConnectionTo(&ch, "5.5.5.5", 5); 3197 Connection* conn5 = WaitForConnectionTo(&ch, "5.5.5.5", 5);
(...skipping 19 matching lines...) Expand all
3148 3217
3149 // If a data packet is received on conn2, the selected connection should 3218 // If a data packet is received on conn2, the selected connection should
3150 // switch to conn2 because the controlled side must mirror the media path 3219 // switch to conn2 because the controlled side must mirror the media path
3151 // chosen by the controlling side. 3220 // chosen by the controlling side.
3152 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); 3221 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1));
3153 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3222 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
3154 ASSERT_TRUE(conn2 != nullptr); 3223 ASSERT_TRUE(conn2 != nullptr);
3155 conn2->ReceivedPing(); // Start receiving. 3224 conn2->ReceivedPing(); // Start receiving.
3156 conn2->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); 3225 conn2->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0));
3157 EXPECT_EQ(conn2, ch.selected_connection()); 3226 EXPECT_EQ(conn2, ch.selected_connection());
3158 conn2->ReceivedPingResponse(LOW_RTT); // Become writable. 3227 conn2->ReceivedPingResponse(LOW_RTT, "id"); // Become writable.
3159 3228
3160 // Now another STUN message with an unknown address and use_candidate will 3229 // Now another STUN message with an unknown address and use_candidate will
3161 // nominate the selected connection. 3230 // nominate the selected connection.
3162 IceMessage request; 3231 IceMessage request;
3163 request.SetType(STUN_BINDING_REQUEST); 3232 request.SetType(STUN_BINDING_REQUEST);
3164 request.AddAttribute( 3233 request.AddAttribute(
3165 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); 3234 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1]));
3166 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; 3235 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24;
3167 request.AddAttribute( 3236 request.AddAttribute(
3168 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); 3237 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority));
3169 request.AddAttribute(new StunByteStringAttribute(STUN_ATTR_USE_CANDIDATE)); 3238 request.AddAttribute(new StunByteStringAttribute(STUN_ATTR_USE_CANDIDATE));
3170 Port* port = GetPort(&ch); 3239 Port* port = GetPort(&ch);
3171 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), PROTO_UDP, 3240 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), PROTO_UDP,
3172 &request, kIceUfrag[1], false); 3241 &request, kIceUfrag[1], false);
3173 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); 3242 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
3174 ASSERT_TRUE(conn3 != nullptr); 3243 ASSERT_TRUE(conn3 != nullptr);
3175 EXPECT_EQ(conn2, ch.selected_connection()); // Not writable yet. 3244 EXPECT_EQ(conn2, ch.selected_connection()); // Not writable yet.
3176 conn3->ReceivedPingResponse(LOW_RTT); // Become writable. 3245 conn3->ReceivedPingResponse(LOW_RTT, "id"); // Become writable.
3177 EXPECT_EQ_WAIT(conn3, ch.selected_connection(), kDefaultTimeout); 3246 EXPECT_EQ_WAIT(conn3, ch.selected_connection(), kDefaultTimeout);
3178 3247
3179 // Now another data packet will not switch the selected connection because the 3248 // Now another data packet will not switch the selected connection because the
3180 // selected connection was nominated by the controlling side. 3249 // selected connection was nominated by the controlling side.
3181 conn2->ReceivedPing(); 3250 conn2->ReceivedPing();
3182 conn2->ReceivedPingResponse(LOW_RTT); 3251 conn2->ReceivedPingResponse(LOW_RTT, "id");
3183 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); 3252 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0));
3184 EXPECT_EQ_WAIT(conn3, ch.selected_connection(), kDefaultTimeout); 3253 EXPECT_EQ_WAIT(conn3, ch.selected_connection(), kDefaultTimeout);
3185 } 3254 }
3186 3255
3187 TEST_F(P2PTransportChannelPingTest, 3256 TEST_F(P2PTransportChannelPingTest,
3188 TestControlledAgentDataReceivingTakesHigherPrecedenceThanPriority) { 3257 TestControlledAgentDataReceivingTakesHigherPrecedenceThanPriority) {
3189 rtc::ScopedFakeClock clock; 3258 rtc::ScopedFakeClock clock;
3190 3259
3191 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3260 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3192 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa); 3261 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
3262 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); 3331 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0));
3263 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); 3332 EXPECT_EQ(1, reset_selected_candidate_pair_switches());
3264 EXPECT_EQ(conn2, last_selected_candidate_pair()); 3333 EXPECT_EQ(conn2, last_selected_candidate_pair());
3265 3334
3266 // Make sure sorting won't reselect candidate pair. 3335 // Make sure sorting won't reselect candidate pair.
3267 SIMULATED_WAIT(false, 10, clock); 3336 SIMULATED_WAIT(false, 10, clock);
3268 EXPECT_EQ(0, reset_selected_candidate_pair_switches()); 3337 EXPECT_EQ(0, reset_selected_candidate_pair_switches());
3269 } 3338 }
3270 3339
3271 TEST_F(P2PTransportChannelPingTest, 3340 TEST_F(P2PTransportChannelPingTest,
3341 TestControlledAgentSelectsConnectionWithHigherNomination) {
3342 rtc::ScopedFakeClock clock;
3343
3344 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3345 P2PTransportChannel ch("test", 1, &pa);
3346 PrepareChannel(&ch);
3347 ch.SetIceRole(ICEROLE_CONTROLLED);
3348 ch.MaybeStartGathering();
3349 // The connections have decreasing priority.
3350 Connection* conn1 =
3351 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, false);
3352 ASSERT_TRUE(conn1 != nullptr);
3353 Connection* conn2 =
3354 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, false);
3355 ASSERT_TRUE(conn2 != nullptr);
3356
3357 // conn1 is the selected connection because it has a higher priority,
3358 EXPECT_EQ_SIMULATED_WAIT(conn1, last_selected_candidate_pair(),
3359 kDefaultTimeout, clock);
3360 reset_selected_candidate_pair_switches();
3361
3362 // conn2 is nominated; it becomes selected.
3363 NominateConnection(conn2);
3364 EXPECT_EQ(1, reset_selected_candidate_pair_switches());
3365 EXPECT_EQ(conn2, last_selected_candidate_pair());
3366
3367 // conn1 is selected because of its priority.
3368 NominateConnection(conn1);
3369 EXPECT_EQ(1, reset_selected_candidate_pair_switches());
3370 EXPECT_EQ(conn1, last_selected_candidate_pair());
3371
3372 // conn2 gets higher remote nomination; it is selected again.
3373 NominateConnection(conn2, 2);
3374 EXPECT_EQ(1, reset_selected_candidate_pair_switches());
3375 EXPECT_EQ(conn2, last_selected_candidate_pair());
3376
3377 // Make sure sorting won't reselect candidate pair.
3378 SIMULATED_WAIT(false, 100, clock);
3379 EXPECT_EQ(0, reset_selected_candidate_pair_switches());
3380 }
3381
3382 TEST_F(P2PTransportChannelPingTest,
3272 TestControlledAgentWriteStateTakesHigherPrecedenceThanNomination) { 3383 TestControlledAgentWriteStateTakesHigherPrecedenceThanNomination) {
3273 rtc::ScopedFakeClock clock; 3384 rtc::ScopedFakeClock clock;
3274 3385
3275 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3386 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3276 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa); 3387 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa);
3277 PrepareChannel(&ch); 3388 PrepareChannel(&ch);
3278 ch.SetIceRole(ICEROLE_CONTROLLED); 3389 ch.SetIceRole(ICEROLE_CONTROLLED);
3279 ch.MaybeStartGathering(); 3390 ch.MaybeStartGathering();
3280 // The connections have decreasing priority. 3391 // The connections have decreasing priority.
3281 Connection* conn1 = 3392 Connection* conn1 =
3282 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, false); 3393 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, false);
3283 ASSERT_TRUE(conn1 != nullptr); 3394 ASSERT_TRUE(conn1 != nullptr);
3284 Connection* conn2 = 3395 Connection* conn2 =
3285 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, false); 3396 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, false);
3286 ASSERT_TRUE(conn2 != nullptr); 3397 ASSERT_TRUE(conn2 != nullptr);
3287 3398
3288 NominateConnection(conn1); 3399 NominateConnection(conn1);
3289 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); 3400 EXPECT_EQ(1, reset_selected_candidate_pair_switches());
3290 3401
3291 // conn2 becomes writable; it is selected even though it is not nominated. 3402 // conn2 becomes writable; it is selected even though it is not nominated.
3292 conn2->ReceivedPingResponse(LOW_RTT); 3403 conn2->ReceivedPingResponse(LOW_RTT, "id");
3293 3404
3294 EXPECT_EQ_SIMULATED_WAIT(1, reset_selected_candidate_pair_switches(), 3405 EXPECT_EQ_SIMULATED_WAIT(1, reset_selected_candidate_pair_switches(),
3295 kDefaultTimeout, clock); 3406 kDefaultTimeout, clock);
3296 EXPECT_EQ_SIMULATED_WAIT(conn2, last_selected_candidate_pair(), 3407 EXPECT_EQ_SIMULATED_WAIT(conn2, last_selected_candidate_pair(),
3297 kDefaultTimeout, clock); 3408 kDefaultTimeout, clock);
3298 3409
3299 // If conn1 is also writable, it will become selected. 3410 // If conn1 is also writable, it will become selected.
3300 conn1->ReceivedPingResponse(LOW_RTT); 3411 conn1->ReceivedPingResponse(LOW_RTT, "id");
3301 EXPECT_EQ_SIMULATED_WAIT(1, reset_selected_candidate_pair_switches(), 3412 EXPECT_EQ_SIMULATED_WAIT(1, reset_selected_candidate_pair_switches(),
3302 kDefaultTimeout, clock); 3413 kDefaultTimeout, clock);
3303 EXPECT_EQ_SIMULATED_WAIT(conn1, last_selected_candidate_pair(), 3414 EXPECT_EQ_SIMULATED_WAIT(conn1, last_selected_candidate_pair(),
3304 kDefaultTimeout, clock); 3415 kDefaultTimeout, clock);
3305 3416
3306 // Make sure sorting won't reselect candidate pair. 3417 // Make sure sorting won't reselect candidate pair.
3307 SIMULATED_WAIT(false, 10, clock); 3418 SIMULATED_WAIT(false, 10, clock);
3308 EXPECT_EQ(0, reset_selected_candidate_pair_switches()); 3419 EXPECT_EQ(0, reset_selected_candidate_pair_switches());
3309 } 3420 }
3310 3421
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
3351 TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) { 3462 TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) {
3352 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3463 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3353 P2PTransportChannel ch("test channel", 1, &pa); 3464 P2PTransportChannel ch("test channel", 1, &pa);
3354 PrepareChannel(&ch); 3465 PrepareChannel(&ch);
3355 ch.SetIceRole(ICEROLE_CONTROLLED); 3466 ch.SetIceRole(ICEROLE_CONTROLLED);
3356 ch.MaybeStartGathering(); 3467 ch.MaybeStartGathering();
3357 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 3468 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
3358 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3469 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3359 ASSERT_TRUE(conn1 != nullptr); 3470 ASSERT_TRUE(conn1 != nullptr);
3360 EXPECT_EQ(conn1, ch.selected_connection()); 3471 EXPECT_EQ(conn1, ch.selected_connection());
3361 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving 3472 conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving
3362 3473
3363 // When a higher-priority, nominated candidate comes in, the connections with 3474 // When a higher-priority, nominated candidate comes in, the connections with
3364 // lower-priority are pruned. 3475 // lower-priority are pruned.
3365 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10)); 3476 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10));
3366 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3477 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
3367 ASSERT_TRUE(conn2 != nullptr); 3478 ASSERT_TRUE(conn2 != nullptr);
3368 conn2->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving 3479 conn2->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving
3369 conn2->set_nominated(true); 3480 NominateConnection(conn2);
3370 conn2->SignalNominated(conn2);
3371 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); 3481 EXPECT_TRUE_WAIT(conn1->pruned(), 3000);
3372 3482
3373 ch.SetIceConfig(CreateIceConfig(500, GATHER_ONCE)); 3483 ch.SetIceConfig(CreateIceConfig(500, GATHER_ONCE));
3374 // Wait until conn2 becomes not receiving. 3484 // Wait until conn2 becomes not receiving.
3375 EXPECT_TRUE_WAIT(!conn2->receiving(), 3000); 3485 EXPECT_TRUE_WAIT(!conn2->receiving(), 3000);
3376 3486
3377 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1)); 3487 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1));
3378 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); 3488 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
3379 ASSERT_TRUE(conn3 != nullptr); 3489 ASSERT_TRUE(conn3 != nullptr);
3380 // The selected connection should still be conn2. Even through conn3 has lower 3490 // The selected connection should still be conn2. Even through conn3 has lower
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
3415 EXPECT_EQ(TransportChannelState::STATE_INIT, ch.GetState()); 3525 EXPECT_EQ(TransportChannelState::STATE_INIT, ch.GetState());
3416 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); 3526 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
3417 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); 3527 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1));
3418 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3528 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3419 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3529 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
3420 ASSERT_TRUE(conn1 != nullptr); 3530 ASSERT_TRUE(conn1 != nullptr);
3421 ASSERT_TRUE(conn2 != nullptr); 3531 ASSERT_TRUE(conn2 != nullptr);
3422 // Now there are two connections, so the transport channel is connecting. 3532 // Now there are two connections, so the transport channel is connecting.
3423 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState()); 3533 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState());
3424 // |conn1| becomes writable and receiving; it then should prune |conn2|. 3534 // |conn1| becomes writable and receiving; it then should prune |conn2|.
3425 conn1->ReceivedPingResponse(LOW_RTT); 3535 conn1->ReceivedPingResponse(LOW_RTT, "id");
3426 EXPECT_TRUE_WAIT(conn2->pruned(), 1000); 3536 EXPECT_TRUE_WAIT(conn2->pruned(), 1000);
3427 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); 3537 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState());
3428 conn1->Prune(); // All connections are pruned. 3538 conn1->Prune(); // All connections are pruned.
3429 // Need to wait until the channel state is updated. 3539 // Need to wait until the channel state is updated.
3430 EXPECT_EQ_WAIT(TransportChannelState::STATE_FAILED, ch.GetState(), 1000); 3540 EXPECT_EQ_WAIT(TransportChannelState::STATE_FAILED, ch.GetState(), 1000);
3431 } 3541 }
3432 3542
3433 // Test that when a low-priority connection is pruned, it is not deleted 3543 // Test that when a low-priority connection is pruned, it is not deleted
3434 // right away, and it can become active and be pruned again. 3544 // right away, and it can become active and be pruned again.
3435 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { 3545 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) {
3436 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3546 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3437 P2PTransportChannel ch("test channel", 1, &pa); 3547 P2PTransportChannel ch("test channel", 1, &pa);
3438 PrepareChannel(&ch); 3548 PrepareChannel(&ch);
3439 IceConfig config = CreateIceConfig(1000, GATHER_ONCE); 3549 IceConfig config = CreateIceConfig(1000, GATHER_ONCE);
3440 config.receiving_switching_delay = rtc::Optional<int>(800); 3550 config.receiving_switching_delay = rtc::Optional<int>(800);
3441 ch.SetIceConfig(config); 3551 ch.SetIceConfig(config);
3442 ch.MaybeStartGathering(); 3552 ch.MaybeStartGathering();
3443 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); 3553 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
3444 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3554 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3445 ASSERT_TRUE(conn1 != nullptr); 3555 ASSERT_TRUE(conn1 != nullptr);
3446 EXPECT_EQ(conn1, ch.selected_connection()); 3556 EXPECT_EQ(conn1, ch.selected_connection());
3447 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving 3557 conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving
3448 3558
3449 // Add a low-priority connection |conn2|, which will be pruned, but it will 3559 // Add a low-priority connection |conn2|, which will be pruned, but it will
3450 // not be deleted right away. Once the current selected connection becomes not 3560 // not be deleted right away. Once the current selected connection becomes not
3451 // receiving, |conn2| will start to ping and upon receiving the ping response, 3561 // receiving, |conn2| will start to ping and upon receiving the ping response,
3452 // it will become the selected connection. 3562 // it will become the selected connection.
3453 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); 3563 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1));
3454 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3564 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
3455 ASSERT_TRUE(conn2 != nullptr); 3565 ASSERT_TRUE(conn2 != nullptr);
3456 EXPECT_TRUE_WAIT(!conn2->active(), 1000); 3566 EXPECT_TRUE_WAIT(!conn2->active(), 1000);
3457 // |conn2| should not send a ping yet. 3567 // |conn2| should not send a ping yet.
3458 EXPECT_EQ(Connection::STATE_WAITING, conn2->state()); 3568 EXPECT_EQ(Connection::STATE_WAITING, conn2->state());
3459 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); 3569 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState());
3460 // Wait for |conn1| becoming not receiving. 3570 // Wait for |conn1| becoming not receiving.
3461 EXPECT_TRUE_WAIT(!conn1->receiving(), 3000); 3571 EXPECT_TRUE_WAIT(!conn1->receiving(), 3000);
3462 // Make sure conn2 is not deleted. 3572 // Make sure conn2 is not deleted.
3463 conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3573 conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
3464 ASSERT_TRUE(conn2 != nullptr); 3574 ASSERT_TRUE(conn2 != nullptr);
3465 EXPECT_EQ_WAIT(Connection::STATE_INPROGRESS, conn2->state(), 1000); 3575 EXPECT_EQ_WAIT(Connection::STATE_INPROGRESS, conn2->state(), 1000);
3466 conn2->ReceivedPingResponse(LOW_RTT); 3576 conn2->ReceivedPingResponse(LOW_RTT, "id");
3467 EXPECT_EQ_WAIT(conn2, ch.selected_connection(), 1000); 3577 EXPECT_EQ_WAIT(conn2, ch.selected_connection(), 1000);
3468 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState()); 3578 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState());
3469 3579
3470 // When |conn1| comes back again, |conn2| will be pruned again. 3580 // When |conn1| comes back again, |conn2| will be pruned again.
3471 conn1->ReceivedPingResponse(LOW_RTT); 3581 conn1->ReceivedPingResponse(LOW_RTT, "id");
3472 EXPECT_EQ_WAIT(conn1, ch.selected_connection(), 1000); 3582 EXPECT_EQ_WAIT(conn1, ch.selected_connection(), 1000);
3473 EXPECT_TRUE_WAIT(!conn2->active(), 1000); 3583 EXPECT_TRUE_WAIT(!conn2->active(), 1000);
3474 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); 3584 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState());
3475 } 3585 }
3476 3586
3477 // Test that if all connections in a channel has timed out on writing, they 3587 // Test that if all connections in a channel has timed out on writing, they
3478 // will all be deleted. We use Prune to simulate write_time_out. 3588 // will all be deleted. We use Prune to simulate write_time_out.
3479 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) { 3589 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) {
3480 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3590 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3481 P2PTransportChannel ch("test channel", 1, &pa); 3591 P2PTransportChannel ch("test channel", 1, &pa);
(...skipping 28 matching lines...) Expand all
3510 // the current port allocator session. 3620 // the current port allocator session.
3511 TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) { 3621 TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) {
3512 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3622 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3513 P2PTransportChannel ch("test channel", 1, &pa); 3623 P2PTransportChannel ch("test channel", 1, &pa);
3514 PrepareChannel(&ch); 3624 PrepareChannel(&ch);
3515 ch.SetIceConfig(CreateIceConfig(2000, GATHER_ONCE)); 3625 ch.SetIceConfig(CreateIceConfig(2000, GATHER_ONCE));
3516 ch.MaybeStartGathering(); 3626 ch.MaybeStartGathering();
3517 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); 3627 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
3518 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3628 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3519 ASSERT_TRUE(conn1 != nullptr); 3629 ASSERT_TRUE(conn1 != nullptr);
3520 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving 3630 conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving
3521 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); 3631 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts());
3522 3632
3523 // Start a new session. Even though conn1, which belongs to an older 3633 // Start a new session. Even though conn1, which belongs to an older
3524 // session, becomes unwritable and writable again, it should not stop the 3634 // session, becomes unwritable and writable again, it should not stop the
3525 // current session. 3635 // current session.
3526 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); 3636 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]);
3527 ch.MaybeStartGathering(); 3637 ch.MaybeStartGathering();
3528 conn1->Prune(); 3638 conn1->Prune();
3529 conn1->ReceivedPingResponse(LOW_RTT); 3639 conn1->ReceivedPingResponse(LOW_RTT, "id");
3530 EXPECT_TRUE(ch.allocator_session()->IsGettingPorts()); 3640 EXPECT_TRUE(ch.allocator_session()->IsGettingPorts());
3531 3641
3532 // But if a new connection created from the new session becomes writable, 3642 // But if a new connection created from the new session becomes writable,
3533 // it will stop the current session. 3643 // it will stop the current session.
3534 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 100)); 3644 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 100));
3535 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3645 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
3536 ASSERT_TRUE(conn2 != nullptr); 3646 ASSERT_TRUE(conn2 != nullptr);
3537 conn2->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving 3647 conn2->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving
3538 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); 3648 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts());
3539 } 3649 }
3540 3650
3541 // Test that the ICE role is updated even on ports that has been removed. 3651 // Test that the ICE role is updated even on ports that has been removed.
3542 // These ports may still have connections that need a correct role, in case that 3652 // These ports may still have connections that need a correct role, in case that
3543 // the connections on it may still receive stun pings. 3653 // the connections on it may still receive stun pings.
3544 TEST_F(P2PTransportChannelPingTest, TestIceRoleUpdatedOnRemovedPort) { 3654 TEST_F(P2PTransportChannelPingTest, TestIceRoleUpdatedOnRemovedPort) {
3545 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3655 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3546 P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa); 3656 P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa);
3547 // Starts with ICEROLE_CONTROLLING. 3657 // Starts with ICEROLE_CONTROLLING.
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
3700 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3810 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
3701 EXPECT_EQ(conn2->local_candidate().type(), LOCAL_PORT_TYPE); 3811 EXPECT_EQ(conn2->local_candidate().type(), LOCAL_PORT_TYPE);
3702 EXPECT_EQ(conn2->remote_candidate().type(), LOCAL_PORT_TYPE); 3812 EXPECT_EQ(conn2->remote_candidate().type(), LOCAL_PORT_TYPE);
3703 conn2->ReceivedPing(); 3813 conn2->ReceivedPing();
3704 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); 3814 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch));
3705 3815
3706 // Make conn3 the selected connection. 3816 // Make conn3 the selected connection.
3707 Connection* conn3 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3817 Connection* conn3 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3708 EXPECT_EQ(conn3->local_candidate().type(), LOCAL_PORT_TYPE); 3818 EXPECT_EQ(conn3->local_candidate().type(), LOCAL_PORT_TYPE);
3709 EXPECT_EQ(conn3->remote_candidate().type(), RELAY_PORT_TYPE); 3819 EXPECT_EQ(conn3->remote_candidate().type(), RELAY_PORT_TYPE);
3710 conn3->ReceivedPingResponse(LOW_RTT); 3820 conn3->ReceivedPingResponse(LOW_RTT, "id");
3711 ASSERT_TRUE(conn3->writable()); 3821 ASSERT_TRUE(conn3->writable());
3712 conn3->ReceivedPing(); 3822 conn3->ReceivedPing();
3713 3823
3714 /* 3824 /*
3715 3825
3716 TODO(honghaiz): Re-enable this once we use fake clock for this test to fix 3826 TODO(honghaiz): Re-enable this once we use fake clock for this test to fix
3717 the flakiness. The following test becomes flaky because we now ping the 3827 the flakiness. The following test becomes flaky because we now ping the
3718 connections with fast rates until every connection is pinged at least three 3828 connections with fast rates until every connection is pinged at least three
3719 times. The selected connection may have been pinged before 3829 times. The selected connection may have been pinged before
3720 |max_strong_interval|, so it may not be the next connection to be pinged as 3830 |max_strong_interval|, so it may not be the next connection to be pinged as
3721 expected in the test. 3831 expected in the test.
3722 3832
3723 // Verify that conn3 will be the "selected connection" since it is readable 3833 // Verify that conn3 will be the "selected connection" since it is readable
3724 // and writable. After |MAX_CURRENT_STRONG_INTERVAL|, it should be the next 3834 // and writable. After |MAX_CURRENT_STRONG_INTERVAL|, it should be the next
3725 // pingable connection. 3835 // pingable connection.
3726 EXPECT_TRUE_WAIT(conn3 == ch.selected_connection(), 5000); 3836 EXPECT_TRUE_WAIT(conn3 == ch.selected_connection(), 5000);
3727 WAIT(false, max_strong_interval + 100); 3837 WAIT(false, max_strong_interval + 100);
3728 conn3->ReceivedPingResponse(LOW_RTT); 3838 conn3->ReceivedPingResponse(LOW_RTT, "id");
3729 ASSERT_TRUE(conn3->writable()); 3839 ASSERT_TRUE(conn3->writable());
3730 EXPECT_EQ(conn3, FindNextPingableConnectionAndPingIt(&ch)); 3840 EXPECT_EQ(conn3, FindNextPingableConnectionAndPingIt(&ch));
3731 3841
3732 */ 3842 */
3733 } 3843 }
3734 3844
3735 // Test that Relay/Relay connections will be pinged first when everything has 3845 // Test that Relay/Relay connections will be pinged first when everything has
3736 // been pinged even if the Relay/Relay connection wasn't the first to be pinged 3846 // been pinged even if the Relay/Relay connection wasn't the first to be pinged
3737 // in the first round. 3847 // in the first round.
3738 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, 3848 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest,
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
3822 3932
3823 // TCP Relay/Relay is the next. 3933 // TCP Relay/Relay is the next.
3824 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, 3934 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE,
3825 TCP_PROTOCOL_NAME); 3935 TCP_PROTOCOL_NAME);
3826 3936
3827 // Finally, Local/Relay will be pinged. 3937 // Finally, Local/Relay will be pinged.
3828 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); 3938 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE);
3829 } 3939 }
3830 3940
3831 } // namespace cricket { 3941 } // namespace cricket {
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698