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

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

Powered by Google App Engine
This is Rietveld 408576698