Chromium Code Reviews

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: Minor fix in the test Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
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 1844 matching lines...)
1855 const SocketAddress& address) { 1855 const SocketAddress& address) {
1856 for (cricket::Connection* conn : channel->connections()) { 1856 for (cricket::Connection* conn : channel->connections()) {
1857 if (conn->local_candidate().address().EqualIPs(address)) { 1857 if (conn->local_candidate().address().EqualIPs(address)) {
1858 return conn; 1858 return conn;
1859 } 1859 }
1860 } 1860 }
1861 return nullptr; 1861 return nullptr;
1862 } 1862 }
1863 1863
1864 void DestroyAllButBestConnection(cricket::P2PTransportChannel* channel) { 1864 void DestroyAllButBestConnection(cricket::P2PTransportChannel* channel) {
1865 const cricket::Connection* best_connection = channel->best_connection(); 1865 const cricket::Connection* selected_connection =
1866 channel->selected_connection();
1866 for (cricket::Connection* conn : channel->connections()) { 1867 for (cricket::Connection* conn : channel->connections()) {
1867 if (conn != best_connection) { 1868 if (conn != selected_connection) {
1868 conn->Destroy(); 1869 conn->Destroy();
1869 } 1870 }
1870 } 1871 }
1871 } 1872 }
1872 }; 1873 };
1873 1874
1874 // Test that we can establish connectivity when both peers are multihomed. 1875 // Test that we can establish connectivity when both peers are multihomed.
1875 TEST_F(P2PTransportChannelMultihomedTest, DISABLED_TestBasic) { 1876 TEST_F(P2PTransportChannelMultihomedTest, DISABLED_TestBasic) {
1876 AddAddress(0, kPublicAddrs[0]); 1877 AddAddress(0, kPublicAddrs[0]);
1877 AddAddress(0, kAlternateAddrs[0]); 1878 AddAddress(0, kAlternateAddrs[0]);
(...skipping 106 matching lines...)
1984 3000, clock); 1985 3000, clock);
1985 EXPECT_TRUE( 1986 EXPECT_TRUE(
1986 LocalCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0])); 1987 LocalCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0]));
1987 EXPECT_TRUE(RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); 1988 EXPECT_TRUE(RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1]));
1988 EXPECT_TRUE( 1989 EXPECT_TRUE(
1989 RemoteCandidate(ep2_ch1())->address().EqualIPs(kAlternateAddrs[0])); 1990 RemoteCandidate(ep2_ch1())->address().EqualIPs(kAlternateAddrs[0]));
1990 1991
1991 DestroyChannels(); 1992 DestroyChannels();
1992 } 1993 }
1993 1994
1995 // Test that when the controlling side switches the selected connection,
1996 // the nominated value of the selected connection on the controlled side will
1997 // increase.
1998 TEST_F(P2PTransportChannelMultihomedTest, TestIceRenomination) {
1999 rtc::ScopedFakeClock clock;
2000 // Adding alternate address will make sure |kPublicAddrs| has the higher
2001 // priority than others. This is due to FakeNetwork::AddInterface method.
2002 AddAddress(0, kAlternateAddrs[0]);
2003 AddAddress(0, kPublicAddrs[0]);
2004 AddAddress(1, kPublicAddrs[1]);
2005
2006 // Use only local ports for simplicity.
2007 SetAllocatorFlags(0, kOnlyLocalPorts);
2008 SetAllocatorFlags(1, kOnlyLocalPorts);
2009
2010 // Create channels and let them go writable, as usual.
2011 CreateChannels(1);
2012 ep1_ch1()->set_peer_supports_renomination(true);
2013 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
2014 ep2_ch1()->receiving() &&
2015 ep2_ch1()->writable(),
2016 3000, clock);
2017 EXPECT_TRUE_SIMULATED_WAIT(
2018 ep2_ch1()->selected_connection()->nominated_value() > 0, kDefaultTimeout,
2019 clock);
2020 int nominated_value = ep2_ch1()->selected_connection()->nominated_value();
2021
2022 // Make the receiving timeout shorter for testing.
2023 IceConfig config = CreateIceConfig(1000, GATHER_ONCE);
2024 ep1_ch1()->SetIceConfig(config);
2025 ep2_ch1()->SetIceConfig(config);
2026
2027 // Blackhole any traffic to or from the public addrs.
2028 LOG(LS_INFO) << "Failing over...";
2029 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]);
2030
2031 // We should detect loss of receiving within 1 second or so.
2032 EXPECT_TRUE_SIMULATED_WAIT(!ep1_ch1()->selected_connection()->receiving() &&
2033 !ep2_ch1()->selected_connection()->receiving(),
2034 3000, clock);
Taylor Brandstetter 2016/07/27 22:20:55 This test relies on both channels becoming "not re
honghaiz3 2016/07/28 04:19:14 Revised. I think we need to make sure that the con
Taylor Brandstetter 2016/07/28 16:30:45 This looks good.
2035 // We should switch over to use the alternate addr on both sides
2036 // when we are not receiving.
2037 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection()->receiving() &&
2038 ep2_ch1()->selected_connection()->receiving(),
2039 3000, clock);
2040 // The connection must have switched on the controlling side and the nominated
2041 // value should increase.
2042 EXPECT_TRUE_SIMULATED_WAIT(
2043 ep2_ch1()->selected_connection()->nominated_value() > nominated_value,
2044 kDefaultTimeout, clock);
2045
2046 DestroyChannels();
2047 }
2048
1994 // Test that if an interface fails temporarily and then recovers quickly, 2049 // Test that if an interface fails temporarily and then recovers quickly,
1995 // the selected connection will not switch. 2050 // the selected connection will not switch.
1996 // The case that it will switch over to the backup connection if the selected 2051 // 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 2052 // connection does not recover after enough time is covered in
1998 // TestFailoverControlledSide and TestFailoverControllingSide. 2053 // TestFailoverControlledSide and TestFailoverControllingSide.
1999 TEST_F(P2PTransportChannelMultihomedTest, 2054 TEST_F(P2PTransportChannelMultihomedTest,
2000 TestConnectionSwitchDampeningControlledSide) { 2055 TestConnectionSwitchDampeningControlledSide) {
2001 rtc::ScopedFakeClock clock; 2056 rtc::ScopedFakeClock clock;
2002 AddAddress(0, kPublicAddrs[0]); 2057 AddAddress(0, kPublicAddrs[0]);
2003 // Adding alternate address will make sure |kPublicAddrs| has the higher 2058 // Adding alternate address will make sure |kPublicAddrs| has the higher
(...skipping 284 matching lines...)
2288 SetAllocatorFlags(0, kOnlyLocalPorts); 2343 SetAllocatorFlags(0, kOnlyLocalPorts);
2289 SetAllocatorFlags(1, kOnlyLocalPorts); 2344 SetAllocatorFlags(1, kOnlyLocalPorts);
2290 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && 2345 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
2291 ep2_ch1()->receiving() && ep2_ch1()->writable(), 2346 ep2_ch1()->receiving() && ep2_ch1()->writable(),
2292 kDefaultTimeout, kDefaultTimeout); 2347 kDefaultTimeout, kDefaultTimeout);
2293 2348
2294 // Add a new wifi interface on end point 2. We should expect a new connection 2349 // 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. 2350 // to be created and the new one will be the best connection.
2296 AddAddress(1, wifi[1], "test_wifi1", rtc::ADAPTER_TYPE_WIFI); 2351 AddAddress(1, wifi[1], "test_wifi1", rtc::ADAPTER_TYPE_WIFI);
2297 const cricket::Connection* conn; 2352 const cricket::Connection* conn;
2298 EXPECT_TRUE_WAIT((conn = ep1_ch1()->best_connection()) != nullptr && 2353 EXPECT_TRUE_WAIT((conn = ep1_ch1()->selected_connection()) != nullptr &&
2299 conn->remote_candidate().address().EqualIPs(wifi[1]), 2354 conn->remote_candidate().address().EqualIPs(wifi[1]),
2300 kDefaultTimeout); 2355 kDefaultTimeout);
2301 EXPECT_TRUE_WAIT((conn = ep2_ch1()->best_connection()) != nullptr && 2356 EXPECT_TRUE_WAIT((conn = ep2_ch1()->selected_connection()) != nullptr &&
2302 conn->local_candidate().address().EqualIPs(wifi[1]), 2357 conn->local_candidate().address().EqualIPs(wifi[1]),
2303 kDefaultTimeout); 2358 kDefaultTimeout);
2304 2359
2305 // Add a new cellular interface on end point 1, we should expect a new 2360 // Add a new cellular interface on end point 1, we should expect a new
2306 // backup connection created using this new interface. 2361 // backup connection created using this new interface.
2307 AddAddress(0, cellular[0], "test_cellular0", rtc::ADAPTER_TYPE_CELLULAR); 2362 AddAddress(0, cellular[0], "test_cellular0", rtc::ADAPTER_TYPE_CELLULAR);
2308 EXPECT_TRUE_WAIT(ep1_ch1()->GetState() == cricket::STATE_COMPLETED && 2363 EXPECT_TRUE_WAIT(
2309 (conn = GetConnectionWithLocalAddress( 2364 ep1_ch1()->GetState() == cricket::STATE_COMPLETED &&
2310 ep1_ch1(), cellular[0])) != nullptr && 2365 (conn = GetConnectionWithLocalAddress(ep1_ch1(), cellular[0])) !=
2311 conn != ep1_ch1()->best_connection() && conn->writable(), 2366 nullptr &&
2312 kDefaultTimeout); 2367 conn != ep1_ch1()->selected_connection() && conn->writable(),
2368 kDefaultTimeout);
2313 EXPECT_TRUE_WAIT( 2369 EXPECT_TRUE_WAIT(
2314 ep2_ch1()->GetState() == cricket::STATE_COMPLETED && 2370 ep2_ch1()->GetState() == cricket::STATE_COMPLETED &&
2315 (conn = GetConnectionWithRemoteAddress(ep2_ch1(), cellular[0])) != 2371 (conn = GetConnectionWithRemoteAddress(ep2_ch1(), cellular[0])) !=
2316 nullptr && 2372 nullptr &&
2317 conn != ep2_ch1()->best_connection() && conn->receiving(), 2373 conn != ep2_ch1()->selected_connection() && conn->receiving(),
2318 kDefaultTimeout); 2374 kDefaultTimeout);
2319 2375
2320 DestroyChannels(); 2376 DestroyChannels();
2321 } 2377 }
2322 2378
2323 // Tests that we can switch links via continual gathering. 2379 // Tests that we can switch links via continual gathering.
2324 TEST_F(P2PTransportChannelMultihomedTest, 2380 TEST_F(P2PTransportChannelMultihomedTest,
2325 TestSwitchLinksViaContinualGathering) { 2381 TestSwitchLinksViaContinualGathering) {
2326 rtc::ScopedFakeClock clock; 2382 rtc::ScopedFakeClock clock;
2327 AddAddress(0, kPublicAddrs[0]); 2383 AddAddress(0, kPublicAddrs[0]);
(...skipping 25 matching lines...)
2353 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() && 2409 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() &&
2354 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && 2410 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) &&
2355 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]), 2411 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]),
2356 3000, clock); 2412 3000, clock);
2357 2413
2358 // Remove one address first and then add another address. 2414 // Remove one address first and then add another address.
2359 LOG(LS_INFO) << "Draining again..."; 2415 LOG(LS_INFO) << "Draining again...";
2360 RemoveAddress(1, kAlternateAddrs[1]); 2416 RemoveAddress(1, kAlternateAddrs[1]);
2361 AddAddress(1, kAlternateAddrs[0]); 2417 AddAddress(1, kAlternateAddrs[0]);
2362 EXPECT_TRUE_SIMULATED_WAIT( 2418 EXPECT_TRUE_SIMULATED_WAIT(
2363 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && 2419 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() &&
2364 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && 2420 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) &&
2365 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0]), 2421 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0]),
2366 3000, clock); 2422 3000, clock);
2367 2423
2368 DestroyChannels(); 2424 DestroyChannels();
2369 } 2425 }
2370 2426
2371 /* 2427 /*
2372 TODO(honghaiz) Once continual gathering fully supports 2428 TODO(honghaiz) Once continual gathering fully supports
2373 GATHER_CONTINUALLY_AND_RECOVER, put this test back. 2429 GATHER_CONTINUALLY_AND_RECOVER, put this test back.
(...skipping 16 matching lines...)
2390 2446
2391 // Create channels and let them go writable, as usual. 2447 // Create channels and let them go writable, as usual.
2392 CreateChannels(1); 2448 CreateChannels(1);
2393 // Set continual gathering policy. 2449 // Set continual gathering policy.
2394 IceConfig config = CreateIceConfig(1000, GATHER_CONTINUALLY_AND_RECOVER); 2450 IceConfig config = CreateIceConfig(1000, GATHER_CONTINUALLY_AND_RECOVER);
2395 ep1_ch1()->SetIceConfig(config); 2451 ep1_ch1()->SetIceConfig(config);
2396 ep2_ch1()->SetIceConfig(config); 2452 ep2_ch1()->SetIceConfig(config);
2397 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && 2453 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
2398 ep2_ch1()->receiving() && ep2_ch1()->writable(), 2454 ep2_ch1()->receiving() && ep2_ch1()->writable(),
2399 3000, clock); 2455 3000, clock);
2400 EXPECT_TRUE(ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && 2456 EXPECT_TRUE(ep1_ch1()->selected_connection() &&
2457 ep2_ch1()->selected_connection() &&
2401 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) && 2458 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) &&
2402 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1])); 2459 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]));
2403 2460
2404 // First destroy all backup connection. 2461 // First destroy all backup connection.
2405 DestroyAllButBestConnection(ep1_ch1()); 2462 DestroyAllButBestConnection(ep1_ch1());
2406 2463
2407 SIMULATED_WAIT(false, 10, clock); 2464 SIMULATED_WAIT(false, 10, clock);
2408 // Then the interface of the best connection goes away. 2465 // Then the interface of the best connection goes away.
2409 RemoveAddress(0, wifi[0]); 2466 RemoveAddress(0, wifi[0]);
2410 EXPECT_TRUE_SIMULATED_WAIT( 2467 EXPECT_TRUE_SIMULATED_WAIT(
2411 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && 2468 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() &&
2412 LocalCandidate(ep1_ch1())->address().EqualIPs(cellular[0]) && 2469 LocalCandidate(ep1_ch1())->address().EqualIPs(cellular[0]) &&
2413 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]), 2470 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]),
2414 3000, clock); 2471 3000, clock);
2415 2472
2416 DestroyChannels(); 2473 DestroyChannels();
2417 } 2474 }
2418 */ 2475 */
2419 2476
2420 // Tests that the backup connection will be restored after it is destroyed. 2477 // Tests that the backup connection will be restored after it is destroyed.
2421 TEST_F(P2PTransportChannelMultihomedTest, TestRestoreBackupConnection) { 2478 TEST_F(P2PTransportChannelMultihomedTest, TestRestoreBackupConnection) {
(...skipping 11 matching lines...)
2433 // Create channels and let them go writable, as usual. 2490 // Create channels and let them go writable, as usual.
2434 CreateChannels(1); 2491 CreateChannels(1);
2435 IceConfig config = CreateIceConfig(1000, GATHER_CONTINUALLY); 2492 IceConfig config = CreateIceConfig(1000, GATHER_CONTINUALLY);
2436 config.regather_on_failed_networks_interval = rtc::Optional<int>(2000); 2493 config.regather_on_failed_networks_interval = rtc::Optional<int>(2000);
2437 ep1_ch1()->SetIceConfig(config); 2494 ep1_ch1()->SetIceConfig(config);
2438 ep2_ch1()->SetIceConfig(config); 2495 ep2_ch1()->SetIceConfig(config);
2439 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && 2496 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
2440 ep2_ch1()->receiving() && 2497 ep2_ch1()->receiving() &&
2441 ep2_ch1()->writable(), 2498 ep2_ch1()->writable(),
2442 3000, clock); 2499 3000, clock);
2443 EXPECT_TRUE(ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && 2500 EXPECT_TRUE(ep1_ch1()->selected_connection() &&
2501 ep2_ch1()->selected_connection() &&
2444 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) && 2502 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) &&
2445 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1])); 2503 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]));
2446 2504
2447 // Destroy all backup connections. 2505 // Destroy all backup connections.
2448 DestroyAllButBestConnection(ep1_ch1()); 2506 DestroyAllButBestConnection(ep1_ch1());
2449 // Ensure the backup connection is removed first. 2507 // Ensure the backup connection is removed first.
2450 EXPECT_TRUE_SIMULATED_WAIT( 2508 EXPECT_TRUE_SIMULATED_WAIT(
2451 GetConnectionWithLocalAddress(ep1_ch1(), cellular[0]) == nullptr, 2509 GetConnectionWithLocalAddress(ep1_ch1(), cellular[0]) == nullptr,
2452 kDefaultTimeout, clock); 2510 kDefaultTimeout, clock);
2453 const cricket::Connection* conn; 2511 const cricket::Connection* conn;
2454 EXPECT_TRUE_SIMULATED_WAIT( 2512 EXPECT_TRUE_SIMULATED_WAIT(
2455 (conn = GetConnectionWithLocalAddress(ep1_ch1(), cellular[0])) != 2513 (conn = GetConnectionWithLocalAddress(ep1_ch1(), cellular[0])) !=
2456 nullptr && 2514 nullptr &&
2457 conn != ep1_ch1()->best_connection() && conn->writable(), 2515 conn != ep1_ch1()->selected_connection() && conn->writable(),
2458 5000, clock); 2516 5000, clock);
2459 2517
2460 DestroyChannels(); 2518 DestroyChannels();
2461 } 2519 }
2462 2520
2463 // A collection of tests which tests a single P2PTransportChannel by sending 2521 // A collection of tests which tests a single P2PTransportChannel by sending
2464 // pings. 2522 // pings.
2465 class P2PTransportChannelPingTest : public testing::Test, 2523 class P2PTransportChannelPingTest : public testing::Test,
2466 public sigslot::has_slots<> { 2524 public sigslot::has_slots<> {
2467 public: 2525 public:
(...skipping 62 matching lines...)
2530 int port, 2588 int port,
2531 int priority, 2589 int priority,
2532 bool writable) { 2590 bool writable) {
2533 channel.AddRemoteCandidate( 2591 channel.AddRemoteCandidate(
2534 CreateUdpCandidate(LOCAL_PORT_TYPE, ip_addr, port, priority)); 2592 CreateUdpCandidate(LOCAL_PORT_TYPE, ip_addr, port, priority));
2535 EXPECT_TRUE_SIMULATED_WAIT( 2593 EXPECT_TRUE_SIMULATED_WAIT(
2536 GetConnectionTo(&channel, ip_addr, port) != nullptr, 3000, clock); 2594 GetConnectionTo(&channel, ip_addr, port) != nullptr, 3000, clock);
2537 Connection* conn = GetConnectionTo(&channel, ip_addr, port); 2595 Connection* conn = GetConnectionTo(&channel, ip_addr, port);
2538 2596
2539 if (conn && writable) { 2597 if (conn && writable) {
2540 conn->ReceivedPingResponse(LOW_RTT); // make it writable 2598 conn->ReceivedPingResponse(LOW_RTT, "id"); // make it writable
2541 } 2599 }
2542 return conn; 2600 return conn;
2543 } 2601 }
2544 2602
2545 void NominateConnection(Connection* conn) { 2603 void NominateConnection(Connection* conn, int nominated_value = 1) {
2546 conn->set_nominated(true); 2604 conn->set_nominated_value(nominated_value);
2547 conn->SignalNominated(conn); 2605 conn->SignalNominated(conn);
2548 } 2606 }
2549 2607
2550 void OnSelectedCandidatePairChanged( 2608 void OnSelectedCandidatePairChanged(
2551 TransportChannel* transport_channel, 2609 TransportChannel* transport_channel,
2552 CandidatePairInterface* selected_candidate_pair, 2610 CandidatePairInterface* selected_candidate_pair,
2553 int last_sent_packet_id, 2611 int last_sent_packet_id,
2554 bool ready_to_send) { 2612 bool ready_to_send) {
2555 last_selected_candidate_pair_ = selected_candidate_pair; 2613 last_selected_candidate_pair_ = selected_candidate_pair;
2556 last_sent_packet_id_ = last_sent_packet_id; 2614 last_sent_packet_id_ = last_sent_packet_id;
(...skipping 80 matching lines...)
2637 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 2695 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
2638 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); 2696 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
2639 2697
2640 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2698 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2641 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 2699 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2642 ASSERT_TRUE(conn1 != nullptr); 2700 ASSERT_TRUE(conn1 != nullptr);
2643 ASSERT_TRUE(conn2 != nullptr); 2701 ASSERT_TRUE(conn2 != nullptr);
2644 2702
2645 // Low-priority connection becomes writable so that the other connection 2703 // Low-priority connection becomes writable so that the other connection
2646 // is not pruned. 2704 // is not pruned.
2647 conn1->ReceivedPingResponse(LOW_RTT); 2705 conn1->ReceivedPingResponse(LOW_RTT, "id");
2648 EXPECT_TRUE_WAIT( 2706 EXPECT_TRUE_WAIT(
2649 conn1->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL && 2707 conn1->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL &&
2650 conn2->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL, 2708 conn2->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL,
2651 kDefaultTimeout); 2709 kDefaultTimeout);
2652 } 2710 }
2653 2711
2654 // Verify that the connections are pinged at the right time. 2712 // Verify that the connections are pinged at the right time.
2655 TEST_F(P2PTransportChannelPingTest, TestStunPingIntervals) { 2713 TEST_F(P2PTransportChannelPingTest, TestStunPingIntervals) {
2656 rtc::ScopedFakeClock clock; 2714 rtc::ScopedFakeClock clock;
2657 int RTT_RATIO = 4; 2715 int RTT_RATIO = 4;
(...skipping 15 matching lines...)
2673 int64_t start = clock.TimeNanos(); 2731 int64_t start = clock.TimeNanos();
2674 SIMULATED_WAIT(conn->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL, 2732 SIMULATED_WAIT(conn->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL,
2675 kDefaultTimeout, clock); 2733 kDefaultTimeout, clock);
2676 int64_t ping_interval_ms = (clock.TimeNanos() - start) / 2734 int64_t ping_interval_ms = (clock.TimeNanos() - start) /
2677 rtc::kNumNanosecsPerMillisec / 2735 rtc::kNumNanosecsPerMillisec /
2678 (MIN_PINGS_AT_WEAK_PING_INTERVAL - 1); 2736 (MIN_PINGS_AT_WEAK_PING_INTERVAL - 1);
2679 EXPECT_EQ(ping_interval_ms, WEAK_PING_INTERVAL); 2737 EXPECT_EQ(ping_interval_ms, WEAK_PING_INTERVAL);
2680 2738
2681 // Stabilizing. 2739 // Stabilizing.
2682 2740
2683 conn->ReceivedPingResponse(LOW_RTT); 2741 conn->ReceivedPingResponse(LOW_RTT, "id");
2684 int ping_sent_before = conn->num_pings_sent(); 2742 int ping_sent_before = conn->num_pings_sent();
2685 start = clock.TimeNanos(); 2743 start = clock.TimeNanos();
2686 // The connection becomes strong but not stable because we haven't been able 2744 // The connection becomes strong but not stable because we haven't been able
2687 // to converge the RTT. 2745 // to converge the RTT.
2688 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock); 2746 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock);
2689 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; 2747 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec;
2690 EXPECT_GE(ping_interval_ms, STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL); 2748 EXPECT_GE(ping_interval_ms, STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL);
2691 EXPECT_LE(ping_interval_ms, 2749 EXPECT_LE(ping_interval_ms,
2692 STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE); 2750 STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE);
2693 2751
2694 // Stabilized. 2752 // Stabilized.
2695 2753
2696 // The connection becomes stable after receiving more than RTT_RATIO rtt 2754 // The connection becomes stable after receiving more than RTT_RATIO rtt
2697 // samples. 2755 // samples.
2698 for (int i = 0; i < RTT_RATIO; i++) { 2756 for (int i = 0; i < RTT_RATIO; i++) {
2699 conn->ReceivedPingResponse(LOW_RTT); 2757 conn->ReceivedPingResponse(LOW_RTT, "id");
2700 } 2758 }
2701 ping_sent_before = conn->num_pings_sent(); 2759 ping_sent_before = conn->num_pings_sent();
2702 start = clock.TimeNanos(); 2760 start = clock.TimeNanos();
2703 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock); 2761 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock);
2704 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; 2762 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec;
2705 EXPECT_GE(ping_interval_ms, STABLE_WRITABLE_CONNECTION_PING_INTERVAL); 2763 EXPECT_GE(ping_interval_ms, STABLE_WRITABLE_CONNECTION_PING_INTERVAL);
2706 EXPECT_LE(ping_interval_ms, 2764 EXPECT_LE(ping_interval_ms,
2707 STABLE_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE); 2765 STABLE_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE);
2708 2766
2709 // Destabilized. 2767 // Destabilized.
2710 2768
2711 conn->ReceivedPingResponse(LOW_RTT); 2769 conn->ReceivedPingResponse(LOW_RTT, "id");
2712 // Create a in-flight ping. 2770 // Create a in-flight ping.
2713 conn->Ping(clock.TimeNanos() / rtc::kNumNanosecsPerMillisec); 2771 conn->Ping(clock.TimeNanos() / rtc::kNumNanosecsPerMillisec);
2714 start = clock.TimeNanos(); 2772 start = clock.TimeNanos();
2715 // In-flight ping timeout and the connection will be unstable. 2773 // In-flight ping timeout and the connection will be unstable.
2716 SIMULATED_WAIT( 2774 SIMULATED_WAIT(
2717 !conn->stable(clock.TimeNanos() / rtc::kNumNanosecsPerMillisec), 3000, 2775 !conn->stable(clock.TimeNanos() / rtc::kNumNanosecsPerMillisec), 3000,
2718 clock); 2776 clock);
2719 int64_t duration_ms = 2777 int64_t duration_ms =
2720 (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; 2778 (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec;
2721 EXPECT_GE(duration_ms, 2 * conn->rtt() - RTT_RANGE); 2779 EXPECT_GE(duration_ms, 2 * conn->rtt() - RTT_RANGE);
(...skipping 61 matching lines...)
2783 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 2841 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
2784 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); 2842 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
2785 2843
2786 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2844 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2787 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 2845 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2788 ASSERT_TRUE(conn1 != nullptr); 2846 ASSERT_TRUE(conn1 != nullptr);
2789 ASSERT_TRUE(conn2 != nullptr); 2847 ASSERT_TRUE(conn2 != nullptr);
2790 2848
2791 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); 2849 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch));
2792 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch)); 2850 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch));
2793 conn1->ReceivedPingResponse(LOW_RTT); 2851 conn1->ReceivedPingResponse(LOW_RTT, "id");
2794 ASSERT_TRUE(conn1->writable()); 2852 ASSERT_TRUE(conn1->writable());
2795 conn1->ReceivedPing(); 2853 conn1->ReceivedPing();
2796 2854
2797 // Ping received, but the connection is already writable, so no 2855 // Ping received, but the connection is already writable, so no
2798 // "triggered check" and conn2 is pinged before conn1 because it has 2856 // "triggered check" and conn2 is pinged before conn1 because it has
2799 // a higher priority. 2857 // a higher priority.
2800 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); 2858 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch));
2801 } 2859 }
2802 2860
2803 TEST_F(P2PTransportChannelPingTest, TestFailedConnectionNotPingable) { 2861 TEST_F(P2PTransportChannelPingTest, TestFailedConnectionNotPingable) {
(...skipping 96 matching lines...)
2900 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2958 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2901 ASSERT_TRUE(conn1 != nullptr); 2959 ASSERT_TRUE(conn1 != nullptr);
2902 uint32_t remote_priority = conn1->remote_candidate().priority(); 2960 uint32_t remote_priority = conn1->remote_candidate().priority();
2903 2961
2904 // Create a higher priority candidate and make the connection 2962 // Create a higher priority candidate and make the connection
2905 // receiving/writable. This will prune conn1. 2963 // receiving/writable. This will prune conn1.
2906 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); 2964 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
2907 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 2965 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2908 ASSERT_TRUE(conn2 != nullptr); 2966 ASSERT_TRUE(conn2 != nullptr);
2909 conn2->ReceivedPing(); 2967 conn2->ReceivedPing();
2910 conn2->ReceivedPingResponse(LOW_RTT); 2968 conn2->ReceivedPingResponse(LOW_RTT, "id");
2911 2969
2912 // Wait for conn1 to be pruned. 2970 // Wait for conn1 to be pruned.
2913 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); 2971 EXPECT_TRUE_WAIT(conn1->pruned(), 3000);
2914 // Destroy the connection to test SignalUnknownAddress. 2972 // Destroy the connection to test SignalUnknownAddress.
2915 conn1->Destroy(); 2973 conn1->Destroy();
2916 EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 1000); 2974 EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 1000);
2917 2975
2918 // Create a minimal STUN message with prflx priority. 2976 // Create a minimal STUN message with prflx priority.
2919 IceMessage request; 2977 IceMessage request;
2920 request.SetType(STUN_BINDING_REQUEST); 2978 request.SetType(STUN_BINDING_REQUEST);
(...skipping 80 matching lines...)
3001 3059
3002 // If a stun request with use-candidate attribute arrives, the receiving 3060 // If a stun request with use-candidate attribute arrives, the receiving
3003 // connection will be set as the selected connection, even though 3061 // connection will be set as the selected connection, even though
3004 // its priority is lower. 3062 // its priority is lower.
3005 EXPECT_EQ(-1, SendData(ch, data, len, ++last_packet_id)); 3063 EXPECT_EQ(-1, SendData(ch, data, len, ++last_packet_id));
3006 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1)); 3064 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1));
3007 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); 3065 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
3008 ASSERT_TRUE(conn3 != nullptr); 3066 ASSERT_TRUE(conn3 != nullptr);
3009 // Because it has a lower priority, the selected connection is still conn2. 3067 // Because it has a lower priority, the selected connection is still conn2.
3010 EXPECT_EQ(conn2, ch.selected_connection()); 3068 EXPECT_EQ(conn2, ch.selected_connection());
3011 conn3->ReceivedPingResponse(LOW_RTT); // Become writable. 3069 conn3->ReceivedPingResponse(LOW_RTT, "id"); // Become writable.
3012 // But if it is nominated via use_candidate, it is chosen as the selected 3070 // But if it is nominated via use_candidate, it is chosen as the selected
3013 // connection. 3071 // connection.
3014 conn3->set_nominated(true); 3072 NominateConnection(conn3);
3015 conn3->SignalNominated(conn3);
3016 EXPECT_EQ(conn3, ch.selected_connection()); 3073 EXPECT_EQ(conn3, ch.selected_connection());
3017 EXPECT_EQ(conn3, last_selected_candidate_pair()); 3074 EXPECT_EQ(conn3, last_selected_candidate_pair());
3018 EXPECT_EQ(-1, last_sent_packet_id()); 3075 EXPECT_EQ(-1, last_sent_packet_id());
3019 EXPECT_TRUE(channel_ready_to_send()); 3076 EXPECT_TRUE(channel_ready_to_send());
3020 3077
3021 // Even if another higher priority candidate arrives, it will not be set as 3078 // Even if another higher priority candidate arrives, it will not be set as
3022 // the selected connection because the selected connection is nominated by 3079 // the selected connection because the selected connection is nominated by
3023 // the controlling side. 3080 // the controlling side.
3024 EXPECT_EQ(len, SendData(ch, data, len, ++last_packet_id)); 3081 EXPECT_EQ(len, SendData(ch, data, len, ++last_packet_id));
3025 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "4.4.4.4", 4, 100)); 3082 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "4.4.4.4", 4, 100));
3026 Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); 3083 Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4);
3027 ASSERT_TRUE(conn4 != nullptr); 3084 ASSERT_TRUE(conn4 != nullptr);
3028 EXPECT_EQ(conn3, ch.selected_connection()); 3085 EXPECT_EQ(conn3, ch.selected_connection());
3029 // But if it is nominated via use_candidate and writable, it will be set as 3086 // But if it is nominated via use_candidate and writable, it will be set as
3030 // the selected connection. 3087 // the selected connection.
3031 conn4->set_nominated(true); 3088 NominateConnection(conn4);
3032 conn4->SignalNominated(conn4);
3033 // Not switched yet because conn4 is not writable. 3089 // Not switched yet because conn4 is not writable.
3034 EXPECT_EQ(conn3, ch.selected_connection()); 3090 EXPECT_EQ(conn3, ch.selected_connection());
3035 reset_channel_ready_to_send(); 3091 reset_channel_ready_to_send();
3036 // The selected connection switches after conn4 becomes writable. 3092 // The selected connection switches after conn4 becomes writable.
3037 conn4->ReceivedPingResponse(LOW_RTT); 3093 conn4->ReceivedPingResponse(LOW_RTT, "id");
3038 EXPECT_EQ_WAIT(conn4, ch.selected_connection(), kDefaultTimeout); 3094 EXPECT_EQ_WAIT(conn4, ch.selected_connection(), kDefaultTimeout);
3039 EXPECT_EQ(conn4, last_selected_candidate_pair()); 3095 EXPECT_EQ(conn4, last_selected_candidate_pair());
3040 EXPECT_EQ(last_packet_id, last_sent_packet_id()); 3096 EXPECT_EQ(last_packet_id, last_sent_packet_id());
3041 // SignalReadyToSend is fired again because conn4 is writable. 3097 // SignalReadyToSend is fired again because conn4 is writable.
3042 EXPECT_TRUE(channel_ready_to_send()); 3098 EXPECT_TRUE(channel_ready_to_send());
3043 } 3099 }
3044 3100
3045 // The controlled side will select a connection as the "selected connection" 3101 // The controlled side will select a connection as the "selected connection"
3046 // based on requests from an unknown address before the controlling side 3102 // based on requests from an unknown address before the controlling side
3047 // nominates a connection, and will nominate a connection from an unknown 3103 // nominates a connection, and will nominate a connection from an unknown
(...skipping 14 matching lines...)
3062 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; 3118 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24;
3063 request.AddAttribute( 3119 request.AddAttribute(
3064 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); 3120 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority));
3065 TestUDPPort* port = static_cast<TestUDPPort*>(GetPort(&ch)); 3121 TestUDPPort* port = static_cast<TestUDPPort*>(GetPort(&ch));
3066 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP, 3122 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP,
3067 &request, kIceUfrag[1], false); 3123 &request, kIceUfrag[1], false);
3068 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3124 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3069 ASSERT_TRUE(conn1 != nullptr); 3125 ASSERT_TRUE(conn1 != nullptr);
3070 EXPECT_TRUE(port->sent_binding_response()); 3126 EXPECT_TRUE(port->sent_binding_response());
3071 EXPECT_EQ(conn1, ch.selected_connection()); 3127 EXPECT_EQ(conn1, ch.selected_connection());
3072 conn1->ReceivedPingResponse(LOW_RTT); 3128 conn1->ReceivedPingResponse(LOW_RTT, "id");
3073 EXPECT_EQ(conn1, ch.selected_connection()); 3129 EXPECT_EQ(conn1, ch.selected_connection());
3074 port->set_sent_binding_response(false); 3130 port->set_sent_binding_response(false);
3075 3131
3076 // Another connection is nominated via use_candidate. 3132 // Another connection is nominated via use_candidate.
3077 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); 3133 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1));
3078 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3134 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
3079 ASSERT_TRUE(conn2 != nullptr); 3135 ASSERT_TRUE(conn2 != nullptr);
3080 // Because it has a lower priority, the selected connection is still conn1. 3136 // Because it has a lower priority, the selected connection is still conn1.
3081 EXPECT_EQ(conn1, ch.selected_connection()); 3137 EXPECT_EQ(conn1, ch.selected_connection());
3082 // When it is nominated via use_candidate and writable, it is chosen as the 3138 // When it is nominated via use_candidate and writable, it is chosen as the
3083 // selected connection. 3139 // selected connection.
3084 conn2->ReceivedPingResponse(LOW_RTT); // Become writable. 3140 conn2->ReceivedPingResponse(LOW_RTT, "id"); // Become writable.
3085 conn2->set_nominated(true); 3141 NominateConnection(conn2);
3086 conn2->SignalNominated(conn2);
3087 EXPECT_EQ(conn2, ch.selected_connection()); 3142 EXPECT_EQ(conn2, ch.selected_connection());
3088 3143
3089 // Another request with unknown address, it will not be set as the selected 3144 // Another request with unknown address, it will not be set as the selected
3090 // connection because the selected connection was nominated by the controlling 3145 // connection because the selected connection was nominated by the controlling
3091 // side. 3146 // side.
3092 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), PROTO_UDP, 3147 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), PROTO_UDP,
3093 &request, kIceUfrag[1], false); 3148 &request, kIceUfrag[1], false);
3094 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); 3149 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
3095 ASSERT_TRUE(conn3 != nullptr); 3150 ASSERT_TRUE(conn3 != nullptr);
3096 EXPECT_TRUE(port->sent_binding_response()); 3151 EXPECT_TRUE(port->sent_binding_response());
3097 conn3->ReceivedPingResponse(LOW_RTT); // Become writable. 3152 conn3->ReceivedPingResponse(LOW_RTT, "id"); // Become writable.
3098 EXPECT_EQ(conn2, ch.selected_connection()); 3153 EXPECT_EQ(conn2, ch.selected_connection());
3099 port->set_sent_binding_response(false); 3154 port->set_sent_binding_response(false);
3100 3155
3101 // However if the request contains use_candidate attribute, it will be 3156 // However if the request contains use_candidate attribute, it will be
3102 // selected as the selected connection. 3157 // selected as the selected connection.
3103 request.AddAttribute(new StunByteStringAttribute(STUN_ATTR_USE_CANDIDATE)); 3158 request.AddAttribute(new StunByteStringAttribute(STUN_ATTR_USE_CANDIDATE));
3104 port->SignalUnknownAddress(port, rtc::SocketAddress("4.4.4.4", 4), PROTO_UDP, 3159 port->SignalUnknownAddress(port, rtc::SocketAddress("4.4.4.4", 4), PROTO_UDP,
3105 &request, kIceUfrag[1], false); 3160 &request, kIceUfrag[1], false);
3106 Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); 3161 Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4);
3107 ASSERT_TRUE(conn4 != nullptr); 3162 ASSERT_TRUE(conn4 != nullptr);
3108 EXPECT_TRUE(port->sent_binding_response()); 3163 EXPECT_TRUE(port->sent_binding_response());
3109 // conn4 is not the selected connection yet because it is not writable. 3164 // conn4 is not the selected connection yet because it is not writable.
3110 EXPECT_EQ(conn2, ch.selected_connection()); 3165 EXPECT_EQ(conn2, ch.selected_connection());
3111 conn4->ReceivedPingResponse(LOW_RTT); // Become writable. 3166 conn4->ReceivedPingResponse(LOW_RTT, "id"); // Become writable.
3112 EXPECT_EQ_WAIT(conn4, ch.selected_connection(), kDefaultTimeout); 3167 EXPECT_EQ_WAIT(conn4, ch.selected_connection(), kDefaultTimeout);
3113 3168
3114 // Test that the request from an unknown address contains a ufrag from an old 3169 // Test that the request from an unknown address contains a ufrag from an old
3115 // generation. 3170 // generation.
3116 port->set_sent_binding_response(false); 3171 port->set_sent_binding_response(false);
3117 ch.SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); 3172 ch.SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]);
3118 ch.SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); 3173 ch.SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]);
3119 port->SignalUnknownAddress(port, rtc::SocketAddress("5.5.5.5", 5), PROTO_UDP, 3174 port->SignalUnknownAddress(port, rtc::SocketAddress("5.5.5.5", 5), PROTO_UDP,
3120 &request, kIceUfrag[2], false); 3175 &request, kIceUfrag[2], false);
3121 Connection* conn5 = WaitForConnectionTo(&ch, "5.5.5.5", 5); 3176 Connection* conn5 = WaitForConnectionTo(&ch, "5.5.5.5", 5);
(...skipping 19 matching lines...)
3141 3196
3142 // If a data packet is received on conn2, the selected connection should 3197 // If a data packet is received on conn2, the selected connection should
3143 // switch to conn2 because the controlled side must mirror the media path 3198 // switch to conn2 because the controlled side must mirror the media path
3144 // chosen by the controlling side. 3199 // chosen by the controlling side.
3145 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); 3200 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1));
3146 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3201 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
3147 ASSERT_TRUE(conn2 != nullptr); 3202 ASSERT_TRUE(conn2 != nullptr);
3148 conn2->ReceivedPing(); // Start receiving. 3203 conn2->ReceivedPing(); // Start receiving.
3149 conn2->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); 3204 conn2->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0));
3150 EXPECT_EQ(conn2, ch.selected_connection()); 3205 EXPECT_EQ(conn2, ch.selected_connection());
3151 conn2->ReceivedPingResponse(LOW_RTT); // Become writable. 3206 conn2->ReceivedPingResponse(LOW_RTT, "id"); // Become writable.
3152 3207
3153 // Now another STUN message with an unknown address and use_candidate will 3208 // Now another STUN message with an unknown address and use_candidate will
3154 // nominate the selected connection. 3209 // nominate the selected connection.
3155 IceMessage request; 3210 IceMessage request;
3156 request.SetType(STUN_BINDING_REQUEST); 3211 request.SetType(STUN_BINDING_REQUEST);
3157 request.AddAttribute( 3212 request.AddAttribute(
3158 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); 3213 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1]));
3159 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; 3214 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24;
3160 request.AddAttribute( 3215 request.AddAttribute(
3161 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); 3216 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority));
3162 request.AddAttribute(new StunByteStringAttribute(STUN_ATTR_USE_CANDIDATE)); 3217 request.AddAttribute(new StunByteStringAttribute(STUN_ATTR_USE_CANDIDATE));
3163 Port* port = GetPort(&ch); 3218 Port* port = GetPort(&ch);
3164 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), PROTO_UDP, 3219 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), PROTO_UDP,
3165 &request, kIceUfrag[1], false); 3220 &request, kIceUfrag[1], false);
3166 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); 3221 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
3167 ASSERT_TRUE(conn3 != nullptr); 3222 ASSERT_TRUE(conn3 != nullptr);
3168 EXPECT_EQ(conn2, ch.selected_connection()); // Not writable yet. 3223 EXPECT_EQ(conn2, ch.selected_connection()); // Not writable yet.
3169 conn3->ReceivedPingResponse(LOW_RTT); // Become writable. 3224 conn3->ReceivedPingResponse(LOW_RTT, "id"); // Become writable.
3170 EXPECT_EQ_WAIT(conn3, ch.selected_connection(), kDefaultTimeout); 3225 EXPECT_EQ_WAIT(conn3, ch.selected_connection(), kDefaultTimeout);
3171 3226
3172 // Now another data packet will not switch the selected connection because the 3227 // Now another data packet will not switch the selected connection because the
3173 // selected connection was nominated by the controlling side. 3228 // selected connection was nominated by the controlling side.
3174 conn2->ReceivedPing(); 3229 conn2->ReceivedPing();
3175 conn2->ReceivedPingResponse(LOW_RTT); 3230 conn2->ReceivedPingResponse(LOW_RTT, "id");
3176 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); 3231 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0));
3177 EXPECT_EQ_WAIT(conn3, ch.selected_connection(), kDefaultTimeout); 3232 EXPECT_EQ_WAIT(conn3, ch.selected_connection(), kDefaultTimeout);
3178 } 3233 }
3179 3234
3180 TEST_F(P2PTransportChannelPingTest, 3235 TEST_F(P2PTransportChannelPingTest,
3181 TestControlledAgentDataReceivingTakesHigherPrecedenceThanPriority) { 3236 TestControlledAgentDataReceivingTakesHigherPrecedenceThanPriority) {
3182 rtc::ScopedFakeClock clock; 3237 rtc::ScopedFakeClock clock;
3183 3238
3184 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3239 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3185 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa); 3240 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa);
(...skipping 69 matching lines...)
3255 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); 3310 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0));
3256 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); 3311 EXPECT_EQ(1, reset_selected_candidate_pair_switches());
3257 EXPECT_EQ(conn2, last_selected_candidate_pair()); 3312 EXPECT_EQ(conn2, last_selected_candidate_pair());
3258 3313
3259 // Make sure sorting won't reselect candidate pair. 3314 // Make sure sorting won't reselect candidate pair.
3260 SIMULATED_WAIT(false, 10, clock); 3315 SIMULATED_WAIT(false, 10, clock);
3261 EXPECT_EQ(0, reset_selected_candidate_pair_switches()); 3316 EXPECT_EQ(0, reset_selected_candidate_pair_switches());
3262 } 3317 }
3263 3318
3264 TEST_F(P2PTransportChannelPingTest, 3319 TEST_F(P2PTransportChannelPingTest,
3320 TestControlledAgentSelectsConnectionWithHigherNominatedValue) {
3321 rtc::ScopedFakeClock clock;
3322
3323 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3324 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa);
3325 PrepareChannel(&ch);
3326 ch.SetIceRole(ICEROLE_CONTROLLED);
3327 ch.MaybeStartGathering();
3328 // The connections have decreasing priority.
3329 Connection* conn1 =
3330 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, false);
3331 ASSERT_TRUE(conn1 != nullptr);
3332 Connection* conn2 =
3333 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, false);
3334 ASSERT_TRUE(conn2 != nullptr);
3335
3336 // conn1 is the selected connection because it has a higher priority,
3337 EXPECT_EQ_SIMULATED_WAIT(conn1, last_selected_candidate_pair(),
3338 kDefaultTimeout, clock);
3339 reset_selected_candidate_pair_switches();
3340
3341 // conn2 is nominated; it becomes selected.
3342 NominateConnection(conn2);
3343 EXPECT_EQ(1, reset_selected_candidate_pair_switches());
3344 EXPECT_EQ(conn2, last_selected_candidate_pair());
3345
3346 // conn1 is selected because of its priority.
3347 NominateConnection(conn1);
3348 EXPECT_EQ(1, reset_selected_candidate_pair_switches());
3349 EXPECT_EQ(conn1, last_selected_candidate_pair());
3350
3351 // conn2 gets higher nominated value; it is selected again.
3352 NominateConnection(conn2, 2);
3353 EXPECT_EQ(1, reset_selected_candidate_pair_switches());
3354 EXPECT_EQ(conn2, last_selected_candidate_pair());
3355
3356 // Make sure sorting won't reselect candidate pair.
3357 SIMULATED_WAIT(false, 100, clock);
3358 EXPECT_EQ(0, reset_selected_candidate_pair_switches());
3359 }
3360
3361 TEST_F(P2PTransportChannelPingTest,
3265 TestControlledAgentWriteStateTakesHigherPrecedenceThanNomination) { 3362 TestControlledAgentWriteStateTakesHigherPrecedenceThanNomination) {
3266 rtc::ScopedFakeClock clock; 3363 rtc::ScopedFakeClock clock;
3267 3364
3268 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3365 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3269 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa); 3366 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa);
3270 PrepareChannel(&ch); 3367 PrepareChannel(&ch);
3271 ch.SetIceRole(ICEROLE_CONTROLLED); 3368 ch.SetIceRole(ICEROLE_CONTROLLED);
3272 ch.MaybeStartGathering(); 3369 ch.MaybeStartGathering();
3273 // The connections have decreasing priority. 3370 // The connections have decreasing priority.
3274 Connection* conn1 = 3371 Connection* conn1 =
3275 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, false); 3372 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, false);
3276 ASSERT_TRUE(conn1 != nullptr); 3373 ASSERT_TRUE(conn1 != nullptr);
3277 Connection* conn2 = 3374 Connection* conn2 =
3278 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, false); 3375 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, false);
3279 ASSERT_TRUE(conn2 != nullptr); 3376 ASSERT_TRUE(conn2 != nullptr);
3280 3377
3281 NominateConnection(conn1); 3378 NominateConnection(conn1);
3282 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); 3379 EXPECT_EQ(1, reset_selected_candidate_pair_switches());
3283 3380
3284 // conn2 becomes writable; it is selected even though it is not nominated. 3381 // conn2 becomes writable; it is selected even though it is not nominated.
3285 conn2->ReceivedPingResponse(LOW_RTT); 3382 conn2->ReceivedPingResponse(LOW_RTT, "id");
3286 3383
3287 EXPECT_EQ_SIMULATED_WAIT(1, reset_selected_candidate_pair_switches(), 3384 EXPECT_EQ_SIMULATED_WAIT(1, reset_selected_candidate_pair_switches(),
3288 kDefaultTimeout, clock); 3385 kDefaultTimeout, clock);
3289 EXPECT_EQ_SIMULATED_WAIT(conn2, last_selected_candidate_pair(), 3386 EXPECT_EQ_SIMULATED_WAIT(conn2, last_selected_candidate_pair(),
3290 kDefaultTimeout, clock); 3387 kDefaultTimeout, clock);
3291 3388
3292 // If conn1 is also writable, it will become selected. 3389 // If conn1 is also writable, it will become selected.
3293 conn1->ReceivedPingResponse(LOW_RTT); 3390 conn1->ReceivedPingResponse(LOW_RTT, "id");
3294 EXPECT_EQ_SIMULATED_WAIT(1, reset_selected_candidate_pair_switches(), 3391 EXPECT_EQ_SIMULATED_WAIT(1, reset_selected_candidate_pair_switches(),
3295 kDefaultTimeout, clock); 3392 kDefaultTimeout, clock);
3296 EXPECT_EQ_SIMULATED_WAIT(conn1, last_selected_candidate_pair(), 3393 EXPECT_EQ_SIMULATED_WAIT(conn1, last_selected_candidate_pair(),
3297 kDefaultTimeout, clock); 3394 kDefaultTimeout, clock);
3298 3395
3299 // Make sure sorting won't reselect candidate pair. 3396 // Make sure sorting won't reselect candidate pair.
3300 SIMULATED_WAIT(false, 10, clock); 3397 SIMULATED_WAIT(false, 10, clock);
3301 EXPECT_EQ(0, reset_selected_candidate_pair_switches()); 3398 EXPECT_EQ(0, reset_selected_candidate_pair_switches());
3302 } 3399 }
3303 3400
(...skipping 40 matching lines...)
3344 TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) { 3441 TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) {
3345 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3442 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3346 P2PTransportChannel ch("test channel", 1, &pa); 3443 P2PTransportChannel ch("test channel", 1, &pa);
3347 PrepareChannel(&ch); 3444 PrepareChannel(&ch);
3348 ch.SetIceRole(ICEROLE_CONTROLLED); 3445 ch.SetIceRole(ICEROLE_CONTROLLED);
3349 ch.MaybeStartGathering(); 3446 ch.MaybeStartGathering();
3350 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 3447 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
3351 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3448 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3352 ASSERT_TRUE(conn1 != nullptr); 3449 ASSERT_TRUE(conn1 != nullptr);
3353 EXPECT_EQ(conn1, ch.selected_connection()); 3450 EXPECT_EQ(conn1, ch.selected_connection());
3354 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving 3451 conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving
3355 3452
3356 // When a higher-priority, nominated candidate comes in, the connections with 3453 // When a higher-priority, nominated candidate comes in, the connections with
3357 // lower-priority are pruned. 3454 // lower-priority are pruned.
3358 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10)); 3455 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10));
3359 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3456 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
3360 ASSERT_TRUE(conn2 != nullptr); 3457 ASSERT_TRUE(conn2 != nullptr);
3361 conn2->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving 3458 conn2->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving
3362 conn2->set_nominated(true); 3459 NominateConnection(conn2);
3363 conn2->SignalNominated(conn2);
3364 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); 3460 EXPECT_TRUE_WAIT(conn1->pruned(), 3000);
3365 3461
3366 ch.SetIceConfig(CreateIceConfig(500, GATHER_ONCE)); 3462 ch.SetIceConfig(CreateIceConfig(500, GATHER_ONCE));
3367 // Wait until conn2 becomes not receiving. 3463 // Wait until conn2 becomes not receiving.
3368 EXPECT_TRUE_WAIT(!conn2->receiving(), 3000); 3464 EXPECT_TRUE_WAIT(!conn2->receiving(), 3000);
3369 3465
3370 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1)); 3466 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1));
3371 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); 3467 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
3372 ASSERT_TRUE(conn3 != nullptr); 3468 ASSERT_TRUE(conn3 != nullptr);
3373 // The selected connection should still be conn2. Even through conn3 has lower 3469 // The selected connection should still be conn2. Even through conn3 has lower
(...skipping 34 matching lines...)
3408 EXPECT_EQ(TransportChannelState::STATE_INIT, ch.GetState()); 3504 EXPECT_EQ(TransportChannelState::STATE_INIT, ch.GetState());
3409 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); 3505 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
3410 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); 3506 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1));
3411 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3507 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3412 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3508 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
3413 ASSERT_TRUE(conn1 != nullptr); 3509 ASSERT_TRUE(conn1 != nullptr);
3414 ASSERT_TRUE(conn2 != nullptr); 3510 ASSERT_TRUE(conn2 != nullptr);
3415 // Now there are two connections, so the transport channel is connecting. 3511 // Now there are two connections, so the transport channel is connecting.
3416 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState()); 3512 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState());
3417 // |conn1| becomes writable and receiving; it then should prune |conn2|. 3513 // |conn1| becomes writable and receiving; it then should prune |conn2|.
3418 conn1->ReceivedPingResponse(LOW_RTT); 3514 conn1->ReceivedPingResponse(LOW_RTT, "id");
3419 EXPECT_TRUE_WAIT(conn2->pruned(), 1000); 3515 EXPECT_TRUE_WAIT(conn2->pruned(), 1000);
3420 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); 3516 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState());
3421 conn1->Prune(); // All connections are pruned. 3517 conn1->Prune(); // All connections are pruned.
3422 // Need to wait until the channel state is updated. 3518 // Need to wait until the channel state is updated.
3423 EXPECT_EQ_WAIT(TransportChannelState::STATE_FAILED, ch.GetState(), 1000); 3519 EXPECT_EQ_WAIT(TransportChannelState::STATE_FAILED, ch.GetState(), 1000);
3424 } 3520 }
3425 3521
3426 // Test that when a low-priority connection is pruned, it is not deleted 3522 // Test that when a low-priority connection is pruned, it is not deleted
3427 // right away, and it can become active and be pruned again. 3523 // right away, and it can become active and be pruned again.
3428 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { 3524 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) {
3429 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3525 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3430 P2PTransportChannel ch("test channel", 1, &pa); 3526 P2PTransportChannel ch("test channel", 1, &pa);
3431 PrepareChannel(&ch); 3527 PrepareChannel(&ch);
3432 IceConfig config = CreateIceConfig(1000, GATHER_ONCE); 3528 IceConfig config = CreateIceConfig(1000, GATHER_ONCE);
3433 config.receiving_switching_delay = rtc::Optional<int>(800); 3529 config.receiving_switching_delay = rtc::Optional<int>(800);
3434 ch.SetIceConfig(config); 3530 ch.SetIceConfig(config);
3435 ch.MaybeStartGathering(); 3531 ch.MaybeStartGathering();
3436 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); 3532 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
3437 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3533 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3438 ASSERT_TRUE(conn1 != nullptr); 3534 ASSERT_TRUE(conn1 != nullptr);
3439 EXPECT_EQ(conn1, ch.selected_connection()); 3535 EXPECT_EQ(conn1, ch.selected_connection());
3440 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving 3536 conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving
3441 3537
3442 // Add a low-priority connection |conn2|, which will be pruned, but it will 3538 // Add a low-priority connection |conn2|, which will be pruned, but it will
3443 // not be deleted right away. Once the current selected connection becomes not 3539 // not be deleted right away. Once the current selected connection becomes not
3444 // receiving, |conn2| will start to ping and upon receiving the ping response, 3540 // receiving, |conn2| will start to ping and upon receiving the ping response,
3445 // it will become the selected connection. 3541 // it will become the selected connection.
3446 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); 3542 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1));
3447 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3543 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
3448 ASSERT_TRUE(conn2 != nullptr); 3544 ASSERT_TRUE(conn2 != nullptr);
3449 EXPECT_TRUE_WAIT(!conn2->active(), 1000); 3545 EXPECT_TRUE_WAIT(!conn2->active(), 1000);
3450 // |conn2| should not send a ping yet. 3546 // |conn2| should not send a ping yet.
3451 EXPECT_EQ(Connection::STATE_WAITING, conn2->state()); 3547 EXPECT_EQ(Connection::STATE_WAITING, conn2->state());
3452 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); 3548 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState());
3453 // Wait for |conn1| becoming not receiving. 3549 // Wait for |conn1| becoming not receiving.
3454 EXPECT_TRUE_WAIT(!conn1->receiving(), 3000); 3550 EXPECT_TRUE_WAIT(!conn1->receiving(), 3000);
3455 // Make sure conn2 is not deleted. 3551 // Make sure conn2 is not deleted.
3456 conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3552 conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
3457 ASSERT_TRUE(conn2 != nullptr); 3553 ASSERT_TRUE(conn2 != nullptr);
3458 EXPECT_EQ_WAIT(Connection::STATE_INPROGRESS, conn2->state(), 1000); 3554 EXPECT_EQ_WAIT(Connection::STATE_INPROGRESS, conn2->state(), 1000);
3459 conn2->ReceivedPingResponse(LOW_RTT); 3555 conn2->ReceivedPingResponse(LOW_RTT, "id");
3460 EXPECT_EQ_WAIT(conn2, ch.selected_connection(), 1000); 3556 EXPECT_EQ_WAIT(conn2, ch.selected_connection(), 1000);
3461 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState()); 3557 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState());
3462 3558
3463 // When |conn1| comes back again, |conn2| will be pruned again. 3559 // When |conn1| comes back again, |conn2| will be pruned again.
3464 conn1->ReceivedPingResponse(LOW_RTT); 3560 conn1->ReceivedPingResponse(LOW_RTT, "id");
3465 EXPECT_EQ_WAIT(conn1, ch.selected_connection(), 1000); 3561 EXPECT_EQ_WAIT(conn1, ch.selected_connection(), 1000);
3466 EXPECT_TRUE_WAIT(!conn2->active(), 1000); 3562 EXPECT_TRUE_WAIT(!conn2->active(), 1000);
3467 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); 3563 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState());
3468 } 3564 }
3469 3565
3470 // Test that if all connections in a channel has timed out on writing, they 3566 // Test that if all connections in a channel has timed out on writing, they
3471 // will all be deleted. We use Prune to simulate write_time_out. 3567 // will all be deleted. We use Prune to simulate write_time_out.
3472 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) { 3568 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) {
3473 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3569 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3474 P2PTransportChannel ch("test channel", 1, &pa); 3570 P2PTransportChannel ch("test channel", 1, &pa);
(...skipping 28 matching lines...)
3503 // the current port allocator session. 3599 // the current port allocator session.
3504 TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) { 3600 TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) {
3505 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3601 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3506 P2PTransportChannel ch("test channel", 1, &pa); 3602 P2PTransportChannel ch("test channel", 1, &pa);
3507 PrepareChannel(&ch); 3603 PrepareChannel(&ch);
3508 ch.SetIceConfig(CreateIceConfig(2000, GATHER_ONCE)); 3604 ch.SetIceConfig(CreateIceConfig(2000, GATHER_ONCE));
3509 ch.MaybeStartGathering(); 3605 ch.MaybeStartGathering();
3510 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); 3606 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
3511 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3607 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3512 ASSERT_TRUE(conn1 != nullptr); 3608 ASSERT_TRUE(conn1 != nullptr);
3513 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving 3609 conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving
3514 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); 3610 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts());
3515 3611
3516 // Start a new session. Even though conn1, which belongs to an older 3612 // Start a new session. Even though conn1, which belongs to an older
3517 // session, becomes unwritable and writable again, it should not stop the 3613 // session, becomes unwritable and writable again, it should not stop the
3518 // current session. 3614 // current session.
3519 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); 3615 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]);
3520 ch.MaybeStartGathering(); 3616 ch.MaybeStartGathering();
3521 conn1->Prune(); 3617 conn1->Prune();
3522 conn1->ReceivedPingResponse(LOW_RTT); 3618 conn1->ReceivedPingResponse(LOW_RTT, "id");
3523 EXPECT_TRUE(ch.allocator_session()->IsGettingPorts()); 3619 EXPECT_TRUE(ch.allocator_session()->IsGettingPorts());
3524 3620
3525 // But if a new connection created from the new session becomes writable, 3621 // But if a new connection created from the new session becomes writable,
3526 // it will stop the current session. 3622 // it will stop the current session.
3527 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 100)); 3623 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 100));
3528 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3624 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
3529 ASSERT_TRUE(conn2 != nullptr); 3625 ASSERT_TRUE(conn2 != nullptr);
3530 conn2->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving 3626 conn2->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving
3531 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); 3627 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts());
3532 } 3628 }
3533 3629
3534 // Test that the ICE role is updated even on ports that has been removed. 3630 // Test that the ICE role is updated even on ports that has been removed.
3535 // These ports may still have connections that need a correct role, in case that 3631 // These ports may still have connections that need a correct role, in case that
3536 // the connections on it may still receive stun pings. 3632 // the connections on it may still receive stun pings.
3537 TEST_F(P2PTransportChannelPingTest, TestIceRoleUpdatedOnRemovedPort) { 3633 TEST_F(P2PTransportChannelPingTest, TestIceRoleUpdatedOnRemovedPort) {
3538 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3634 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3539 P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa); 3635 P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa);
3540 // Starts with ICEROLE_CONTROLLING. 3636 // Starts with ICEROLE_CONTROLLING.
(...skipping 145 matching lines...)
3686 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3782 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
3687 EXPECT_EQ(conn2->local_candidate().type(), LOCAL_PORT_TYPE); 3783 EXPECT_EQ(conn2->local_candidate().type(), LOCAL_PORT_TYPE);
3688 EXPECT_EQ(conn2->remote_candidate().type(), LOCAL_PORT_TYPE); 3784 EXPECT_EQ(conn2->remote_candidate().type(), LOCAL_PORT_TYPE);
3689 conn2->ReceivedPing(); 3785 conn2->ReceivedPing();
3690 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); 3786 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch));
3691 3787
3692 // Make conn3 the selected connection. 3788 // Make conn3 the selected connection.
3693 Connection* conn3 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3789 Connection* conn3 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3694 EXPECT_EQ(conn3->local_candidate().type(), LOCAL_PORT_TYPE); 3790 EXPECT_EQ(conn3->local_candidate().type(), LOCAL_PORT_TYPE);
3695 EXPECT_EQ(conn3->remote_candidate().type(), RELAY_PORT_TYPE); 3791 EXPECT_EQ(conn3->remote_candidate().type(), RELAY_PORT_TYPE);
3696 conn3->ReceivedPingResponse(LOW_RTT); 3792 conn3->ReceivedPingResponse(LOW_RTT, "id");
3697 ASSERT_TRUE(conn3->writable()); 3793 ASSERT_TRUE(conn3->writable());
3698 conn3->ReceivedPing(); 3794 conn3->ReceivedPing();
3699 3795
3700 /* 3796 /*
3701 3797
3702 TODO(honghaiz): Re-enable this once we use fake clock for this test to fix 3798 TODO(honghaiz): Re-enable this once we use fake clock for this test to fix
3703 the flakiness. The following test becomes flaky because we now ping the 3799 the flakiness. The following test becomes flaky because we now ping the
3704 connections with fast rates until every connection is pinged at least three 3800 connections with fast rates until every connection is pinged at least three
3705 times. The selected connection may have been pinged before 3801 times. The selected connection may have been pinged before
3706 |max_strong_interval|, so it may not be the next connection to be pinged as 3802 |max_strong_interval|, so it may not be the next connection to be pinged as
3707 expected in the test. 3803 expected in the test.
3708 3804
3709 // Verify that conn3 will be the "selected connection" since it is readable 3805 // Verify that conn3 will be the "selected connection" since it is readable
3710 // and writable. After |MAX_CURRENT_STRONG_INTERVAL|, it should be the next 3806 // and writable. After |MAX_CURRENT_STRONG_INTERVAL|, it should be the next
3711 // pingable connection. 3807 // pingable connection.
3712 EXPECT_TRUE_WAIT(conn3 == ch.selected_connection(), 5000); 3808 EXPECT_TRUE_WAIT(conn3 == ch.selected_connection(), 5000);
3713 WAIT(false, max_strong_interval + 100); 3809 WAIT(false, max_strong_interval + 100);
3714 conn3->ReceivedPingResponse(LOW_RTT); 3810 conn3->ReceivedPingResponse(LOW_RTT, "id");
3715 ASSERT_TRUE(conn3->writable()); 3811 ASSERT_TRUE(conn3->writable());
3716 EXPECT_EQ(conn3, FindNextPingableConnectionAndPingIt(&ch)); 3812 EXPECT_EQ(conn3, FindNextPingableConnectionAndPingIt(&ch));
3717 3813
3718 */ 3814 */
3719 } 3815 }
3720 3816
3721 // Test that Relay/Relay connections will be pinged first when everything has 3817 // Test that Relay/Relay connections will be pinged first when everything has
3722 // been pinged even if the Relay/Relay connection wasn't the first to be pinged 3818 // been pinged even if the Relay/Relay connection wasn't the first to be pinged
3723 // in the first round. 3819 // in the first round.
3724 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, 3820 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest,
(...skipping 83 matching lines...)
3808 3904
3809 // TCP Relay/Relay is the next. 3905 // TCP Relay/Relay is the next.
3810 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, 3906 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE,
3811 TCP_PROTOCOL_NAME); 3907 TCP_PROTOCOL_NAME);
3812 3908
3813 // Finally, Local/Relay will be pinged. 3909 // Finally, Local/Relay will be pinged.
3814 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); 3910 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE);
3815 } 3911 }
3816 3912
3817 } // namespace cricket { 3913 } // namespace cricket {
OLDNEW

Powered by Google App Engine