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

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, 5 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 2519 matching lines...) Expand 10 before | Expand all | Expand 10 after
2530 int port, 2530 int port,
2531 int priority, 2531 int priority,
2532 bool writable) { 2532 bool writable) {
2533 channel.AddRemoteCandidate( 2533 channel.AddRemoteCandidate(
2534 CreateUdpCandidate(LOCAL_PORT_TYPE, ip_addr, port, priority)); 2534 CreateUdpCandidate(LOCAL_PORT_TYPE, ip_addr, port, priority));
2535 EXPECT_TRUE_SIMULATED_WAIT( 2535 EXPECT_TRUE_SIMULATED_WAIT(
2536 GetConnectionTo(&channel, ip_addr, port) != nullptr, 3000, clock); 2536 GetConnectionTo(&channel, ip_addr, port) != nullptr, 3000, clock);
2537 Connection* conn = GetConnectionTo(&channel, ip_addr, port); 2537 Connection* conn = GetConnectionTo(&channel, ip_addr, port);
2538 2538
2539 if (conn && writable) { 2539 if (conn && writable) {
2540 conn->ReceivedPingResponse(LOW_RTT); // make it writable 2540 conn->ReceivedPingResponse(LOW_RTT, "id"); // make it writable
2541 } 2541 }
2542 return conn; 2542 return conn;
2543 } 2543 }
2544 2544
2545 void NominateConnection(Connection* conn) { 2545 void NominateConnection(Connection* conn) {
2546 conn->set_nominated(true); 2546 conn->set_nominated_value(1);
2547 conn->SignalNominated(conn); 2547 conn->SignalNominated(conn);
2548 } 2548 }
2549 2549
2550 void OnSelectedCandidatePairChanged( 2550 void OnSelectedCandidatePairChanged(
2551 TransportChannel* transport_channel, 2551 TransportChannel* transport_channel,
2552 CandidatePairInterface* selected_candidate_pair, 2552 CandidatePairInterface* selected_candidate_pair,
2553 int last_sent_packet_id, 2553 int last_sent_packet_id,
2554 bool ready_to_send) { 2554 bool ready_to_send) {
2555 last_selected_candidate_pair_ = selected_candidate_pair; 2555 last_selected_candidate_pair_ = selected_candidate_pair;
2556 last_sent_packet_id_ = last_sent_packet_id; 2556 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)); 2637 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)); 2638 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
2639 2639
2640 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2640 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2641 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 2641 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2642 ASSERT_TRUE(conn1 != nullptr); 2642 ASSERT_TRUE(conn1 != nullptr);
2643 ASSERT_TRUE(conn2 != nullptr); 2643 ASSERT_TRUE(conn2 != nullptr);
2644 2644
2645 // Low-priority connection becomes writable so that the other connection 2645 // Low-priority connection becomes writable so that the other connection
2646 // is not pruned. 2646 // is not pruned.
2647 conn1->ReceivedPingResponse(LOW_RTT); 2647 conn1->ReceivedPingResponse(LOW_RTT, "id");
2648 EXPECT_TRUE_WAIT( 2648 EXPECT_TRUE_WAIT(
2649 conn1->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL && 2649 conn1->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL &&
2650 conn2->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL, 2650 conn2->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL,
2651 kDefaultTimeout); 2651 kDefaultTimeout);
2652 } 2652 }
2653 2653
2654 // Verify that the connections are pinged at the right time. 2654 // Verify that the connections are pinged at the right time.
2655 TEST_F(P2PTransportChannelPingTest, TestStunPingIntervals) { 2655 TEST_F(P2PTransportChannelPingTest, TestStunPingIntervals) {
2656 rtc::ScopedFakeClock clock; 2656 rtc::ScopedFakeClock clock;
2657 int RTT_RATIO = 4; 2657 int RTT_RATIO = 4;
(...skipping 15 matching lines...) Expand all
2673 int64_t start = clock.TimeNanos(); 2673 int64_t start = clock.TimeNanos();
2674 SIMULATED_WAIT(conn->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL, 2674 SIMULATED_WAIT(conn->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL,
2675 kDefaultTimeout, clock); 2675 kDefaultTimeout, clock);
2676 int64_t ping_interval_ms = (clock.TimeNanos() - start) / 2676 int64_t ping_interval_ms = (clock.TimeNanos() - start) /
2677 rtc::kNumNanosecsPerMillisec / 2677 rtc::kNumNanosecsPerMillisec /
2678 (MIN_PINGS_AT_WEAK_PING_INTERVAL - 1); 2678 (MIN_PINGS_AT_WEAK_PING_INTERVAL - 1);
2679 EXPECT_EQ(ping_interval_ms, WEAK_PING_INTERVAL); 2679 EXPECT_EQ(ping_interval_ms, WEAK_PING_INTERVAL);
2680 2680
2681 // Stabilizing. 2681 // Stabilizing.
2682 2682
2683 conn->ReceivedPingResponse(LOW_RTT); 2683 conn->ReceivedPingResponse(LOW_RTT, "id");
2684 int ping_sent_before = conn->num_pings_sent(); 2684 int ping_sent_before = conn->num_pings_sent();
2685 start = clock.TimeNanos(); 2685 start = clock.TimeNanos();
2686 // The connection becomes strong but not stable because we haven't been able 2686 // The connection becomes strong but not stable because we haven't been able
2687 // to converge the RTT. 2687 // to converge the RTT.
2688 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock); 2688 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock);
2689 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; 2689 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec;
2690 EXPECT_GE(ping_interval_ms, STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL); 2690 EXPECT_GE(ping_interval_ms, STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL);
2691 EXPECT_LE(ping_interval_ms, 2691 EXPECT_LE(ping_interval_ms,
2692 STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE); 2692 STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE);
2693 2693
2694 // Stabilized. 2694 // Stabilized.
2695 2695
2696 // The connection becomes stable after receiving more than RTT_RATIO rtt 2696 // The connection becomes stable after receiving more than RTT_RATIO rtt
2697 // samples. 2697 // samples.
2698 for (int i = 0; i < RTT_RATIO; i++) { 2698 for (int i = 0; i < RTT_RATIO; i++) {
2699 conn->ReceivedPingResponse(LOW_RTT); 2699 conn->ReceivedPingResponse(LOW_RTT, "id");
2700 } 2700 }
2701 ping_sent_before = conn->num_pings_sent(); 2701 ping_sent_before = conn->num_pings_sent();
2702 start = clock.TimeNanos(); 2702 start = clock.TimeNanos();
2703 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock); 2703 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock);
2704 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; 2704 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec;
2705 EXPECT_GE(ping_interval_ms, STABLE_WRITABLE_CONNECTION_PING_INTERVAL); 2705 EXPECT_GE(ping_interval_ms, STABLE_WRITABLE_CONNECTION_PING_INTERVAL);
2706 EXPECT_LE(ping_interval_ms, 2706 EXPECT_LE(ping_interval_ms,
2707 STABLE_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE); 2707 STABLE_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE);
2708 2708
2709 // Destabilized. 2709 // Destabilized.
2710 2710
2711 conn->ReceivedPingResponse(LOW_RTT); 2711 conn->ReceivedPingResponse(LOW_RTT, "id");
2712 // Create a in-flight ping. 2712 // Create a in-flight ping.
2713 conn->Ping(clock.TimeNanos() / rtc::kNumNanosecsPerMillisec); 2713 conn->Ping(clock.TimeNanos() / rtc::kNumNanosecsPerMillisec);
2714 start = clock.TimeNanos(); 2714 start = clock.TimeNanos();
2715 // In-flight ping timeout and the connection will be unstable. 2715 // In-flight ping timeout and the connection will be unstable.
2716 SIMULATED_WAIT( 2716 SIMULATED_WAIT(
2717 !conn->stable(clock.TimeNanos() / rtc::kNumNanosecsPerMillisec), 3000, 2717 !conn->stable(clock.TimeNanos() / rtc::kNumNanosecsPerMillisec), 3000,
2718 clock); 2718 clock);
2719 int64_t duration_ms = 2719 int64_t duration_ms =
2720 (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; 2720 (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec;
2721 EXPECT_GE(duration_ms, 2 * conn->rtt() - RTT_RANGE); 2721 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)); 2783 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)); 2784 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
2785 2785
2786 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2786 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2787 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 2787 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2788 ASSERT_TRUE(conn1 != nullptr); 2788 ASSERT_TRUE(conn1 != nullptr);
2789 ASSERT_TRUE(conn2 != nullptr); 2789 ASSERT_TRUE(conn2 != nullptr);
2790 2790
2791 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); 2791 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch));
2792 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch)); 2792 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch));
2793 conn1->ReceivedPingResponse(LOW_RTT); 2793 conn1->ReceivedPingResponse(LOW_RTT, "id");
2794 ASSERT_TRUE(conn1->writable()); 2794 ASSERT_TRUE(conn1->writable());
2795 conn1->ReceivedPing(); 2795 conn1->ReceivedPing();
2796 2796
2797 // Ping received, but the connection is already writable, so no 2797 // Ping received, but the connection is already writable, so no
2798 // "triggered check" and conn2 is pinged before conn1 because it has 2798 // "triggered check" and conn2 is pinged before conn1 because it has
2799 // a higher priority. 2799 // a higher priority.
2800 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); 2800 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch));
2801 } 2801 }
2802 2802
2803 TEST_F(P2PTransportChannelPingTest, TestFailedConnectionNotPingable) { 2803 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); 2900 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2901 ASSERT_TRUE(conn1 != nullptr); 2901 ASSERT_TRUE(conn1 != nullptr);
2902 uint32_t remote_priority = conn1->remote_candidate().priority(); 2902 uint32_t remote_priority = conn1->remote_candidate().priority();
2903 2903
2904 // Create a higher priority candidate and make the connection 2904 // Create a higher priority candidate and make the connection
2905 // receiving/writable. This will prune conn1. 2905 // receiving/writable. This will prune conn1.
2906 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); 2906 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
2907 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 2907 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2908 ASSERT_TRUE(conn2 != nullptr); 2908 ASSERT_TRUE(conn2 != nullptr);
2909 conn2->ReceivedPing(); 2909 conn2->ReceivedPing();
2910 conn2->ReceivedPingResponse(LOW_RTT); 2910 conn2->ReceivedPingResponse(LOW_RTT, "id");
2911 2911
2912 // Wait for conn1 to be pruned. 2912 // Wait for conn1 to be pruned.
2913 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); 2913 EXPECT_TRUE_WAIT(conn1->pruned(), 3000);
2914 // Destroy the connection to test SignalUnknownAddress. 2914 // Destroy the connection to test SignalUnknownAddress.
2915 conn1->Destroy(); 2915 conn1->Destroy();
2916 EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 1000); 2916 EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 1000);
2917 2917
2918 // Create a minimal STUN message with prflx priority. 2918 // Create a minimal STUN message with prflx priority.
2919 IceMessage request; 2919 IceMessage request;
2920 request.SetType(STUN_BINDING_REQUEST); 2920 request.SetType(STUN_BINDING_REQUEST);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
3001 3001
3002 // If a stun request with use-candidate attribute arrives, the receiving 3002 // If a stun request with use-candidate attribute arrives, the receiving
3003 // connection will be set as the selected connection, even though 3003 // connection will be set as the selected connection, even though
3004 // its priority is lower. 3004 // its priority is lower.
3005 EXPECT_EQ(-1, SendData(ch, data, len, ++last_packet_id)); 3005 EXPECT_EQ(-1, SendData(ch, data, len, ++last_packet_id));
3006 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1)); 3006 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1));
3007 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); 3007 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
3008 ASSERT_TRUE(conn3 != nullptr); 3008 ASSERT_TRUE(conn3 != nullptr);
3009 // Because it has a lower priority, the selected connection is still conn2. 3009 // Because it has a lower priority, the selected connection is still conn2.
3010 EXPECT_EQ(conn2, ch.selected_connection()); 3010 EXPECT_EQ(conn2, ch.selected_connection());
3011 conn3->ReceivedPingResponse(LOW_RTT); // Become writable. 3011 conn3->ReceivedPingResponse(LOW_RTT, "id"); // Become writable.
3012 // But if it is nominated via use_candidate, it is chosen as the selected 3012 // But if it is nominated via use_candidate, it is chosen as the selected
3013 // connection. 3013 // connection.
3014 conn3->set_nominated(true); 3014 conn3->set_nominated_value(1);
3015 conn3->SignalNominated(conn3); 3015 conn3->SignalNominated(conn3);
3016 EXPECT_EQ(conn3, ch.selected_connection()); 3016 EXPECT_EQ(conn3, ch.selected_connection());
3017 EXPECT_EQ(conn3, last_selected_candidate_pair()); 3017 EXPECT_EQ(conn3, last_selected_candidate_pair());
3018 EXPECT_EQ(-1, last_sent_packet_id()); 3018 EXPECT_EQ(-1, last_sent_packet_id());
3019 EXPECT_TRUE(channel_ready_to_send()); 3019 EXPECT_TRUE(channel_ready_to_send());
3020 3020
3021 // Even if another higher priority candidate arrives, it will not be set as 3021 // Even if another higher priority candidate arrives, it will not be set as
3022 // the selected connection because the selected connection is nominated by 3022 // the selected connection because the selected connection is nominated by
3023 // the controlling side. 3023 // the controlling side.
3024 EXPECT_EQ(len, SendData(ch, data, len, ++last_packet_id)); 3024 EXPECT_EQ(len, SendData(ch, data, len, ++last_packet_id));
3025 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "4.4.4.4", 4, 100)); 3025 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "4.4.4.4", 4, 100));
3026 Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); 3026 Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4);
3027 ASSERT_TRUE(conn4 != nullptr); 3027 ASSERT_TRUE(conn4 != nullptr);
3028 EXPECT_EQ(conn3, ch.selected_connection()); 3028 EXPECT_EQ(conn3, ch.selected_connection());
3029 // But if it is nominated via use_candidate and writable, it will be set as 3029 // But if it is nominated via use_candidate and writable, it will be set as
3030 // the selected connection. 3030 // the selected connection.
3031 conn4->set_nominated(true); 3031 conn4->set_nominated_value(1);
3032 conn4->SignalNominated(conn4); 3032 conn4->SignalNominated(conn4);
3033 // Not switched yet because conn4 is not writable. 3033 // Not switched yet because conn4 is not writable.
3034 EXPECT_EQ(conn3, ch.selected_connection()); 3034 EXPECT_EQ(conn3, ch.selected_connection());
3035 reset_channel_ready_to_send(); 3035 reset_channel_ready_to_send();
3036 // The selected connection switches after conn4 becomes writable. 3036 // The selected connection switches after conn4 becomes writable.
3037 conn4->ReceivedPingResponse(LOW_RTT); 3037 conn4->ReceivedPingResponse(LOW_RTT, "id");
3038 EXPECT_EQ_WAIT(conn4, ch.selected_connection(), kDefaultTimeout); 3038 EXPECT_EQ_WAIT(conn4, ch.selected_connection(), kDefaultTimeout);
3039 EXPECT_EQ(conn4, last_selected_candidate_pair()); 3039 EXPECT_EQ(conn4, last_selected_candidate_pair());
3040 EXPECT_EQ(last_packet_id, last_sent_packet_id()); 3040 EXPECT_EQ(last_packet_id, last_sent_packet_id());
3041 // SignalReadyToSend is fired again because conn4 is writable. 3041 // SignalReadyToSend is fired again because conn4 is writable.
3042 EXPECT_TRUE(channel_ready_to_send()); 3042 EXPECT_TRUE(channel_ready_to_send());
3043 } 3043 }
3044 3044
3045 // The controlled side will select a connection as the "selected connection" 3045 // The controlled side will select a connection as the "selected connection"
3046 // based on requests from an unknown address before the controlling side 3046 // based on requests from an unknown address before the controlling side
3047 // nominates a connection, and will nominate a connection from an unknown 3047 // 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; 3062 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24;
3063 request.AddAttribute( 3063 request.AddAttribute(
3064 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); 3064 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority));
3065 TestUDPPort* port = static_cast<TestUDPPort*>(GetPort(&ch)); 3065 TestUDPPort* port = static_cast<TestUDPPort*>(GetPort(&ch));
3066 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP, 3066 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP,
3067 &request, kIceUfrag[1], false); 3067 &request, kIceUfrag[1], false);
3068 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3068 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3069 ASSERT_TRUE(conn1 != nullptr); 3069 ASSERT_TRUE(conn1 != nullptr);
3070 EXPECT_TRUE(port->sent_binding_response()); 3070 EXPECT_TRUE(port->sent_binding_response());
3071 EXPECT_EQ(conn1, ch.selected_connection()); 3071 EXPECT_EQ(conn1, ch.selected_connection());
3072 conn1->ReceivedPingResponse(LOW_RTT); 3072 conn1->ReceivedPingResponse(LOW_RTT, "id");
3073 EXPECT_EQ(conn1, ch.selected_connection()); 3073 EXPECT_EQ(conn1, ch.selected_connection());
3074 port->set_sent_binding_response(false); 3074 port->set_sent_binding_response(false);
3075 3075
3076 // Another connection is nominated via use_candidate. 3076 // Another connection is nominated via use_candidate.
3077 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); 3077 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1));
3078 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3078 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
3079 ASSERT_TRUE(conn2 != nullptr); 3079 ASSERT_TRUE(conn2 != nullptr);
3080 // Because it has a lower priority, the selected connection is still conn1. 3080 // Because it has a lower priority, the selected connection is still conn1.
3081 EXPECT_EQ(conn1, ch.selected_connection()); 3081 EXPECT_EQ(conn1, ch.selected_connection());
3082 // When it is nominated via use_candidate and writable, it is chosen as the 3082 // When it is nominated via use_candidate and writable, it is chosen as the
3083 // selected connection. 3083 // selected connection.
3084 conn2->ReceivedPingResponse(LOW_RTT); // Become writable. 3084 conn2->ReceivedPingResponse(LOW_RTT, "id"); // Become writable.
3085 conn2->set_nominated(true); 3085 conn2->set_nominated_value(1);
3086 conn2->SignalNominated(conn2); 3086 conn2->SignalNominated(conn2);
3087 EXPECT_EQ(conn2, ch.selected_connection()); 3087 EXPECT_EQ(conn2, ch.selected_connection());
3088 3088
3089 // Another request with unknown address, it will not be set as the selected 3089 // Another request with unknown address, it will not be set as the selected
3090 // connection because the selected connection was nominated by the controlling 3090 // connection because the selected connection was nominated by the controlling
3091 // side. 3091 // side.
3092 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), PROTO_UDP, 3092 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), PROTO_UDP,
3093 &request, kIceUfrag[1], false); 3093 &request, kIceUfrag[1], false);
3094 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); 3094 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
3095 ASSERT_TRUE(conn3 != nullptr); 3095 ASSERT_TRUE(conn3 != nullptr);
3096 EXPECT_TRUE(port->sent_binding_response()); 3096 EXPECT_TRUE(port->sent_binding_response());
3097 conn3->ReceivedPingResponse(LOW_RTT); // Become writable. 3097 conn3->ReceivedPingResponse(LOW_RTT, "id"); // Become writable.
3098 EXPECT_EQ(conn2, ch.selected_connection()); 3098 EXPECT_EQ(conn2, ch.selected_connection());
3099 port->set_sent_binding_response(false); 3099 port->set_sent_binding_response(false);
3100 3100
3101 // However if the request contains use_candidate attribute, it will be 3101 // However if the request contains use_candidate attribute, it will be
3102 // selected as the selected connection. 3102 // selected as the selected connection.
3103 request.AddAttribute(new StunByteStringAttribute(STUN_ATTR_USE_CANDIDATE)); 3103 request.AddAttribute(new StunByteStringAttribute(STUN_ATTR_USE_CANDIDATE));
3104 port->SignalUnknownAddress(port, rtc::SocketAddress("4.4.4.4", 4), PROTO_UDP, 3104 port->SignalUnknownAddress(port, rtc::SocketAddress("4.4.4.4", 4), PROTO_UDP,
3105 &request, kIceUfrag[1], false); 3105 &request, kIceUfrag[1], false);
3106 Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); 3106 Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4);
3107 ASSERT_TRUE(conn4 != nullptr); 3107 ASSERT_TRUE(conn4 != nullptr);
3108 EXPECT_TRUE(port->sent_binding_response()); 3108 EXPECT_TRUE(port->sent_binding_response());
3109 // conn4 is not the selected connection yet because it is not writable. 3109 // conn4 is not the selected connection yet because it is not writable.
3110 EXPECT_EQ(conn2, ch.selected_connection()); 3110 EXPECT_EQ(conn2, ch.selected_connection());
3111 conn4->ReceivedPingResponse(LOW_RTT); // Become writable. 3111 conn4->ReceivedPingResponse(LOW_RTT, "id"); // Become writable.
3112 EXPECT_EQ_WAIT(conn4, ch.selected_connection(), kDefaultTimeout); 3112 EXPECT_EQ_WAIT(conn4, ch.selected_connection(), kDefaultTimeout);
3113 3113
3114 // Test that the request from an unknown address contains a ufrag from an old 3114 // Test that the request from an unknown address contains a ufrag from an old
3115 // generation. 3115 // generation.
3116 port->set_sent_binding_response(false); 3116 port->set_sent_binding_response(false);
3117 ch.SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); 3117 ch.SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]);
3118 ch.SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); 3118 ch.SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]);
3119 port->SignalUnknownAddress(port, rtc::SocketAddress("5.5.5.5", 5), PROTO_UDP, 3119 port->SignalUnknownAddress(port, rtc::SocketAddress("5.5.5.5", 5), PROTO_UDP,
3120 &request, kIceUfrag[2], false); 3120 &request, kIceUfrag[2], false);
3121 Connection* conn5 = WaitForConnectionTo(&ch, "5.5.5.5", 5); 3121 Connection* conn5 = WaitForConnectionTo(&ch, "5.5.5.5", 5);
(...skipping 19 matching lines...) Expand all
3141 3141
3142 // If a data packet is received on conn2, the selected connection should 3142 // 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 3143 // switch to conn2 because the controlled side must mirror the media path
3144 // chosen by the controlling side. 3144 // chosen by the controlling side.
3145 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); 3145 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1));
3146 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3146 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
3147 ASSERT_TRUE(conn2 != nullptr); 3147 ASSERT_TRUE(conn2 != nullptr);
3148 conn2->ReceivedPing(); // Start receiving. 3148 conn2->ReceivedPing(); // Start receiving.
3149 conn2->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); 3149 conn2->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0));
3150 EXPECT_EQ(conn2, ch.selected_connection()); 3150 EXPECT_EQ(conn2, ch.selected_connection());
3151 conn2->ReceivedPingResponse(LOW_RTT); // Become writable. 3151 conn2->ReceivedPingResponse(LOW_RTT, "id"); // Become writable.
3152 3152
3153 // Now another STUN message with an unknown address and use_candidate will 3153 // Now another STUN message with an unknown address and use_candidate will
3154 // nominate the selected connection. 3154 // nominate the selected connection.
3155 IceMessage request; 3155 IceMessage request;
3156 request.SetType(STUN_BINDING_REQUEST); 3156 request.SetType(STUN_BINDING_REQUEST);
3157 request.AddAttribute( 3157 request.AddAttribute(
3158 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); 3158 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1]));
3159 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; 3159 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24;
3160 request.AddAttribute( 3160 request.AddAttribute(
3161 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); 3161 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority));
3162 request.AddAttribute(new StunByteStringAttribute(STUN_ATTR_USE_CANDIDATE)); 3162 request.AddAttribute(new StunByteStringAttribute(STUN_ATTR_USE_CANDIDATE));
3163 Port* port = GetPort(&ch); 3163 Port* port = GetPort(&ch);
3164 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), PROTO_UDP, 3164 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), PROTO_UDP,
3165 &request, kIceUfrag[1], false); 3165 &request, kIceUfrag[1], false);
3166 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); 3166 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
3167 ASSERT_TRUE(conn3 != nullptr); 3167 ASSERT_TRUE(conn3 != nullptr);
3168 EXPECT_EQ(conn2, ch.selected_connection()); // Not writable yet. 3168 EXPECT_EQ(conn2, ch.selected_connection()); // Not writable yet.
3169 conn3->ReceivedPingResponse(LOW_RTT); // Become writable. 3169 conn3->ReceivedPingResponse(LOW_RTT, "id"); // Become writable.
3170 EXPECT_EQ_WAIT(conn3, ch.selected_connection(), kDefaultTimeout); 3170 EXPECT_EQ_WAIT(conn3, ch.selected_connection(), kDefaultTimeout);
3171 3171
3172 // Now another data packet will not switch the selected connection because the 3172 // Now another data packet will not switch the selected connection because the
3173 // selected connection was nominated by the controlling side. 3173 // selected connection was nominated by the controlling side.
3174 conn2->ReceivedPing(); 3174 conn2->ReceivedPing();
3175 conn2->ReceivedPingResponse(LOW_RTT); 3175 conn2->ReceivedPingResponse(LOW_RTT, "id");
3176 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); 3176 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0));
3177 EXPECT_EQ_WAIT(conn3, ch.selected_connection(), kDefaultTimeout); 3177 EXPECT_EQ_WAIT(conn3, ch.selected_connection(), kDefaultTimeout);
3178 } 3178 }
3179 3179
3180 TEST_F(P2PTransportChannelPingTest, 3180 TEST_F(P2PTransportChannelPingTest,
3181 TestControlledAgentDataReceivingTakesHigherPrecedenceThanPriority) { 3181 TestControlledAgentDataReceivingTakesHigherPrecedenceThanPriority) {
3182 rtc::ScopedFakeClock clock; 3182 rtc::ScopedFakeClock clock;
3183 3183
3184 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3184 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3185 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa); 3185 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
3275 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, false); 3275 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, false);
3276 ASSERT_TRUE(conn1 != nullptr); 3276 ASSERT_TRUE(conn1 != nullptr);
3277 Connection* conn2 = 3277 Connection* conn2 =
3278 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, false); 3278 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, false);
3279 ASSERT_TRUE(conn2 != nullptr); 3279 ASSERT_TRUE(conn2 != nullptr);
3280 3280
3281 NominateConnection(conn1); 3281 NominateConnection(conn1);
3282 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); 3282 EXPECT_EQ(1, reset_selected_candidate_pair_switches());
3283 3283
3284 // conn2 becomes writable; it is selected even though it is not nominated. 3284 // conn2 becomes writable; it is selected even though it is not nominated.
3285 conn2->ReceivedPingResponse(LOW_RTT); 3285 conn2->ReceivedPingResponse(LOW_RTT, "id");
3286 3286
3287 EXPECT_EQ_SIMULATED_WAIT(1, reset_selected_candidate_pair_switches(), 3287 EXPECT_EQ_SIMULATED_WAIT(1, reset_selected_candidate_pair_switches(),
3288 kDefaultTimeout, clock); 3288 kDefaultTimeout, clock);
3289 EXPECT_EQ_SIMULATED_WAIT(conn2, last_selected_candidate_pair(), 3289 EXPECT_EQ_SIMULATED_WAIT(conn2, last_selected_candidate_pair(),
3290 kDefaultTimeout, clock); 3290 kDefaultTimeout, clock);
3291 3291
3292 // If conn1 is also writable, it will become selected. 3292 // If conn1 is also writable, it will become selected.
3293 conn1->ReceivedPingResponse(LOW_RTT); 3293 conn1->ReceivedPingResponse(LOW_RTT, "id");
3294 EXPECT_EQ_SIMULATED_WAIT(1, reset_selected_candidate_pair_switches(), 3294 EXPECT_EQ_SIMULATED_WAIT(1, reset_selected_candidate_pair_switches(),
3295 kDefaultTimeout, clock); 3295 kDefaultTimeout, clock);
3296 EXPECT_EQ_SIMULATED_WAIT(conn1, last_selected_candidate_pair(), 3296 EXPECT_EQ_SIMULATED_WAIT(conn1, last_selected_candidate_pair(),
3297 kDefaultTimeout, clock); 3297 kDefaultTimeout, clock);
3298 3298
3299 // Make sure sorting won't reselect candidate pair. 3299 // Make sure sorting won't reselect candidate pair.
3300 SIMULATED_WAIT(false, 10, clock); 3300 SIMULATED_WAIT(false, 10, clock);
3301 EXPECT_EQ(0, reset_selected_candidate_pair_switches()); 3301 EXPECT_EQ(0, reset_selected_candidate_pair_switches());
3302 } 3302 }
3303 3303
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
3344 TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) { 3344 TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) {
3345 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3345 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3346 P2PTransportChannel ch("test channel", 1, &pa); 3346 P2PTransportChannel ch("test channel", 1, &pa);
3347 PrepareChannel(&ch); 3347 PrepareChannel(&ch);
3348 ch.SetIceRole(ICEROLE_CONTROLLED); 3348 ch.SetIceRole(ICEROLE_CONTROLLED);
3349 ch.MaybeStartGathering(); 3349 ch.MaybeStartGathering();
3350 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 3350 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
3351 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3351 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3352 ASSERT_TRUE(conn1 != nullptr); 3352 ASSERT_TRUE(conn1 != nullptr);
3353 EXPECT_EQ(conn1, ch.selected_connection()); 3353 EXPECT_EQ(conn1, ch.selected_connection());
3354 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving 3354 conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving
3355 3355
3356 // When a higher-priority, nominated candidate comes in, the connections with 3356 // When a higher-priority, nominated candidate comes in, the connections with
3357 // lower-priority are pruned. 3357 // lower-priority are pruned.
3358 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10)); 3358 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10));
3359 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3359 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
3360 ASSERT_TRUE(conn2 != nullptr); 3360 ASSERT_TRUE(conn2 != nullptr);
3361 conn2->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving 3361 conn2->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving
3362 conn2->set_nominated(true); 3362 conn2->set_nominated_value(1);
3363 conn2->SignalNominated(conn2); 3363 conn2->SignalNominated(conn2);
3364 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); 3364 EXPECT_TRUE_WAIT(conn1->pruned(), 3000);
3365 3365
3366 ch.SetIceConfig(CreateIceConfig(500, GATHER_ONCE)); 3366 ch.SetIceConfig(CreateIceConfig(500, GATHER_ONCE));
3367 // Wait until conn2 becomes not receiving. 3367 // Wait until conn2 becomes not receiving.
3368 EXPECT_TRUE_WAIT(!conn2->receiving(), 3000); 3368 EXPECT_TRUE_WAIT(!conn2->receiving(), 3000);
3369 3369
3370 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1)); 3370 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1));
3371 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); 3371 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
3372 ASSERT_TRUE(conn3 != nullptr); 3372 ASSERT_TRUE(conn3 != nullptr);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3408 EXPECT_EQ(TransportChannelState::STATE_INIT, ch.GetState()); 3408 EXPECT_EQ(TransportChannelState::STATE_INIT, ch.GetState());
3409 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); 3409 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)); 3410 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1));
3411 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3411 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3412 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3412 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
3413 ASSERT_TRUE(conn1 != nullptr); 3413 ASSERT_TRUE(conn1 != nullptr);
3414 ASSERT_TRUE(conn2 != nullptr); 3414 ASSERT_TRUE(conn2 != nullptr);
3415 // Now there are two connections, so the transport channel is connecting. 3415 // Now there are two connections, so the transport channel is connecting.
3416 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState()); 3416 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState());
3417 // |conn1| becomes writable and receiving; it then should prune |conn2|. 3417 // |conn1| becomes writable and receiving; it then should prune |conn2|.
3418 conn1->ReceivedPingResponse(LOW_RTT); 3418 conn1->ReceivedPingResponse(LOW_RTT, "id");
3419 EXPECT_TRUE_WAIT(conn2->pruned(), 1000); 3419 EXPECT_TRUE_WAIT(conn2->pruned(), 1000);
3420 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); 3420 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState());
3421 conn1->Prune(); // All connections are pruned. 3421 conn1->Prune(); // All connections are pruned.
3422 // Need to wait until the channel state is updated. 3422 // Need to wait until the channel state is updated.
3423 EXPECT_EQ_WAIT(TransportChannelState::STATE_FAILED, ch.GetState(), 1000); 3423 EXPECT_EQ_WAIT(TransportChannelState::STATE_FAILED, ch.GetState(), 1000);
3424 } 3424 }
3425 3425
3426 // Test that when a low-priority connection is pruned, it is not deleted 3426 // 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. 3427 // right away, and it can become active and be pruned again.
3428 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { 3428 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) {
3429 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3429 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3430 P2PTransportChannel ch("test channel", 1, &pa); 3430 P2PTransportChannel ch("test channel", 1, &pa);
3431 PrepareChannel(&ch); 3431 PrepareChannel(&ch);
3432 IceConfig config = CreateIceConfig(1000, GATHER_ONCE); 3432 IceConfig config = CreateIceConfig(1000, GATHER_ONCE);
3433 config.receiving_switching_delay = rtc::Optional<int>(800); 3433 config.receiving_switching_delay = rtc::Optional<int>(800);
3434 ch.SetIceConfig(config); 3434 ch.SetIceConfig(config);
3435 ch.MaybeStartGathering(); 3435 ch.MaybeStartGathering();
3436 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); 3436 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
3437 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3437 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3438 ASSERT_TRUE(conn1 != nullptr); 3438 ASSERT_TRUE(conn1 != nullptr);
3439 EXPECT_EQ(conn1, ch.selected_connection()); 3439 EXPECT_EQ(conn1, ch.selected_connection());
3440 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving 3440 conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving
3441 3441
3442 // Add a low-priority connection |conn2|, which will be pruned, but it will 3442 // 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 3443 // 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, 3444 // receiving, |conn2| will start to ping and upon receiving the ping response,
3445 // it will become the selected connection. 3445 // it will become the selected connection.
3446 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); 3446 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1));
3447 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3447 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
3448 ASSERT_TRUE(conn2 != nullptr); 3448 ASSERT_TRUE(conn2 != nullptr);
3449 EXPECT_TRUE_WAIT(!conn2->active(), 1000); 3449 EXPECT_TRUE_WAIT(!conn2->active(), 1000);
3450 // |conn2| should not send a ping yet. 3450 // |conn2| should not send a ping yet.
3451 EXPECT_EQ(Connection::STATE_WAITING, conn2->state()); 3451 EXPECT_EQ(Connection::STATE_WAITING, conn2->state());
3452 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); 3452 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState());
3453 // Wait for |conn1| becoming not receiving. 3453 // Wait for |conn1| becoming not receiving.
3454 EXPECT_TRUE_WAIT(!conn1->receiving(), 3000); 3454 EXPECT_TRUE_WAIT(!conn1->receiving(), 3000);
3455 // Make sure conn2 is not deleted. 3455 // Make sure conn2 is not deleted.
3456 conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3456 conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
3457 ASSERT_TRUE(conn2 != nullptr); 3457 ASSERT_TRUE(conn2 != nullptr);
3458 EXPECT_EQ_WAIT(Connection::STATE_INPROGRESS, conn2->state(), 1000); 3458 EXPECT_EQ_WAIT(Connection::STATE_INPROGRESS, conn2->state(), 1000);
3459 conn2->ReceivedPingResponse(LOW_RTT); 3459 conn2->ReceivedPingResponse(LOW_RTT, "id");
3460 EXPECT_EQ_WAIT(conn2, ch.selected_connection(), 1000); 3460 EXPECT_EQ_WAIT(conn2, ch.selected_connection(), 1000);
3461 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState()); 3461 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState());
3462 3462
3463 // When |conn1| comes back again, |conn2| will be pruned again. 3463 // When |conn1| comes back again, |conn2| will be pruned again.
3464 conn1->ReceivedPingResponse(LOW_RTT); 3464 conn1->ReceivedPingResponse(LOW_RTT, "id");
3465 EXPECT_EQ_WAIT(conn1, ch.selected_connection(), 1000); 3465 EXPECT_EQ_WAIT(conn1, ch.selected_connection(), 1000);
3466 EXPECT_TRUE_WAIT(!conn2->active(), 1000); 3466 EXPECT_TRUE_WAIT(!conn2->active(), 1000);
3467 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); 3467 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState());
3468 } 3468 }
3469 3469
3470 // Test that if all connections in a channel has timed out on writing, they 3470 // 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. 3471 // will all be deleted. We use Prune to simulate write_time_out.
3472 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) { 3472 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) {
3473 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3473 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3474 P2PTransportChannel ch("test channel", 1, &pa); 3474 P2PTransportChannel ch("test channel", 1, &pa);
(...skipping 28 matching lines...) Expand all
3503 // the current port allocator session. 3503 // the current port allocator session.
3504 TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) { 3504 TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) {
3505 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3505 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3506 P2PTransportChannel ch("test channel", 1, &pa); 3506 P2PTransportChannel ch("test channel", 1, &pa);
3507 PrepareChannel(&ch); 3507 PrepareChannel(&ch);
3508 ch.SetIceConfig(CreateIceConfig(2000, GATHER_ONCE)); 3508 ch.SetIceConfig(CreateIceConfig(2000, GATHER_ONCE));
3509 ch.MaybeStartGathering(); 3509 ch.MaybeStartGathering();
3510 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); 3510 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
3511 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3511 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3512 ASSERT_TRUE(conn1 != nullptr); 3512 ASSERT_TRUE(conn1 != nullptr);
3513 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving 3513 conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving
3514 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); 3514 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts());
3515 3515
3516 // Start a new session. Even though conn1, which belongs to an older 3516 // Start a new session. Even though conn1, which belongs to an older
3517 // session, becomes unwritable and writable again, it should not stop the 3517 // session, becomes unwritable and writable again, it should not stop the
3518 // current session. 3518 // current session.
3519 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); 3519 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]);
3520 ch.MaybeStartGathering(); 3520 ch.MaybeStartGathering();
3521 conn1->Prune(); 3521 conn1->Prune();
3522 conn1->ReceivedPingResponse(LOW_RTT); 3522 conn1->ReceivedPingResponse(LOW_RTT, "id");
3523 EXPECT_TRUE(ch.allocator_session()->IsGettingPorts()); 3523 EXPECT_TRUE(ch.allocator_session()->IsGettingPorts());
3524 3524
3525 // But if a new connection created from the new session becomes writable, 3525 // But if a new connection created from the new session becomes writable,
3526 // it will stop the current session. 3526 // it will stop the current session.
3527 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 100)); 3527 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 100));
3528 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3528 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
3529 ASSERT_TRUE(conn2 != nullptr); 3529 ASSERT_TRUE(conn2 != nullptr);
3530 conn2->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving 3530 conn2->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving
3531 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); 3531 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts());
3532 } 3532 }
3533 3533
3534 // Test that the ICE role is updated even on ports that has been removed. 3534 // 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 3535 // These ports may still have connections that need a correct role, in case that
3536 // the connections on it may still receive stun pings. 3536 // the connections on it may still receive stun pings.
3537 TEST_F(P2PTransportChannelPingTest, TestIceRoleUpdatedOnRemovedPort) { 3537 TEST_F(P2PTransportChannelPingTest, TestIceRoleUpdatedOnRemovedPort) {
3538 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3538 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3539 P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa); 3539 P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa);
3540 // Starts with ICEROLE_CONTROLLING. 3540 // 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); 3686 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
3687 EXPECT_EQ(conn2->local_candidate().type(), LOCAL_PORT_TYPE); 3687 EXPECT_EQ(conn2->local_candidate().type(), LOCAL_PORT_TYPE);
3688 EXPECT_EQ(conn2->remote_candidate().type(), LOCAL_PORT_TYPE); 3688 EXPECT_EQ(conn2->remote_candidate().type(), LOCAL_PORT_TYPE);
3689 conn2->ReceivedPing(); 3689 conn2->ReceivedPing();
3690 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); 3690 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch));
3691 3691
3692 // Make conn3 the selected connection. 3692 // Make conn3 the selected connection.
3693 Connection* conn3 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3693 Connection* conn3 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3694 EXPECT_EQ(conn3->local_candidate().type(), LOCAL_PORT_TYPE); 3694 EXPECT_EQ(conn3->local_candidate().type(), LOCAL_PORT_TYPE);
3695 EXPECT_EQ(conn3->remote_candidate().type(), RELAY_PORT_TYPE); 3695 EXPECT_EQ(conn3->remote_candidate().type(), RELAY_PORT_TYPE);
3696 conn3->ReceivedPingResponse(LOW_RTT); 3696 conn3->ReceivedPingResponse(LOW_RTT, "id");
3697 ASSERT_TRUE(conn3->writable()); 3697 ASSERT_TRUE(conn3->writable());
3698 conn3->ReceivedPing(); 3698 conn3->ReceivedPing();
3699 3699
3700 /* 3700 /*
3701 3701
3702 TODO(honghaiz): Re-enable this once we use fake clock for this test to fix 3702 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 3703 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 3704 connections with fast rates until every connection is pinged at least three
3705 times. The selected connection may have been pinged before 3705 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 3706 |max_strong_interval|, so it may not be the next connection to be pinged as
3707 expected in the test. 3707 expected in the test.
3708 3708
3709 // Verify that conn3 will be the "selected connection" since it is readable 3709 // 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 3710 // and writable. After |MAX_CURRENT_STRONG_INTERVAL|, it should be the next
3711 // pingable connection. 3711 // pingable connection.
3712 EXPECT_TRUE_WAIT(conn3 == ch.selected_connection(), 5000); 3712 EXPECT_TRUE_WAIT(conn3 == ch.selected_connection(), 5000);
3713 WAIT(false, max_strong_interval + 100); 3713 WAIT(false, max_strong_interval + 100);
3714 conn3->ReceivedPingResponse(LOW_RTT); 3714 conn3->ReceivedPingResponse(LOW_RTT, "id");
3715 ASSERT_TRUE(conn3->writable()); 3715 ASSERT_TRUE(conn3->writable());
3716 EXPECT_EQ(conn3, FindNextPingableConnectionAndPingIt(&ch)); 3716 EXPECT_EQ(conn3, FindNextPingableConnectionAndPingIt(&ch));
3717 3717
3718 */ 3718 */
3719 } 3719 }
3720 3720
3721 // Test that Relay/Relay connections will be pinged first when everything has 3721 // 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 3722 // been pinged even if the Relay/Relay connection wasn't the first to be pinged
3723 // in the first round. 3723 // in the first round.
3724 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, 3724 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest,
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
3808 3808
3809 // TCP Relay/Relay is the next. 3809 // TCP Relay/Relay is the next.
3810 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, 3810 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE,
3811 TCP_PROTOCOL_NAME); 3811 TCP_PROTOCOL_NAME);
3812 3812
3813 // Finally, Local/Relay will be pinged. 3813 // Finally, Local/Relay will be pinged.
3814 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); 3814 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE);
3815 } 3815 }
3816 3816
3817 } // namespace cricket { 3817 } // namespace cricket {
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698