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

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

Issue 1944003002: Increase the stun ping interval. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Add unit test with fake clock. Created 4 years, 6 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
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.cc ('k') | webrtc/p2p/base/port.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 20 matching lines...) Expand all
31 #include "webrtc/base/ssladapter.h" 31 #include "webrtc/base/ssladapter.h"
32 #include "webrtc/base/thread.h" 32 #include "webrtc/base/thread.h"
33 #include "webrtc/base/virtualsocketserver.h" 33 #include "webrtc/base/virtualsocketserver.h"
34 34
35 using cricket::kDefaultPortAllocatorFlags; 35 using cricket::kDefaultPortAllocatorFlags;
36 using cricket::kMinimumStepDelay; 36 using cricket::kMinimumStepDelay;
37 using cricket::kDefaultStepDelay; 37 using cricket::kDefaultStepDelay;
38 using cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET; 38 using cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET;
39 using cricket::ServerAddresses; 39 using cricket::ServerAddresses;
40 using cricket::MIN_PINGS_AT_WEAK_PING_INTERVAL; 40 using cricket::MIN_PINGS_AT_WEAK_PING_INTERVAL;
41 using cricket::MIN_PINGS_TO_STABILIZE;
41 using rtc::SocketAddress; 42 using rtc::SocketAddress;
42 43
43 static const int kDefaultTimeout = 1000; 44 static const int kDefaultTimeout = 1000;
44 static const int kOnlyLocalPorts = cricket::PORTALLOCATOR_DISABLE_STUN | 45 static const int kOnlyLocalPorts = cricket::PORTALLOCATOR_DISABLE_STUN |
45 cricket::PORTALLOCATOR_DISABLE_RELAY | 46 cricket::PORTALLOCATOR_DISABLE_RELAY |
46 cricket::PORTALLOCATOR_DISABLE_TCP; 47 cricket::PORTALLOCATOR_DISABLE_TCP;
47 // Addresses on the public internet. 48 // Addresses on the public internet.
48 static const SocketAddress kPublicAddrs[2] = 49 static const SocketAddress kPublicAddrs[2] =
49 { SocketAddress("11.11.11.11", 0), SocketAddress("22.22.22.22", 0) }; 50 { SocketAddress("11.11.11.11", 0), SocketAddress("22.22.22.22", 0) };
50 // IPv6 Addresses on the public internet. 51 // IPv6 Addresses on the public internet.
(...skipping 2018 matching lines...) Expand 10 before | Expand all | Expand 10 after
2069 2070
2070 // Low-priority connection becomes writable so that the other connection 2071 // Low-priority connection becomes writable so that the other connection
2071 // is not pruned. 2072 // is not pruned.
2072 conn1->ReceivedPingResponse(); 2073 conn1->ReceivedPingResponse();
2073 EXPECT_TRUE_WAIT( 2074 EXPECT_TRUE_WAIT(
2074 conn1->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL && 2075 conn1->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL &&
2075 conn2->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL, 2076 conn2->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL,
2076 kDefaultTimeout); 2077 kDefaultTimeout);
2077 } 2078 }
2078 2079
2080 TEST_F(P2PTransportChannelPingTest, TestInitialPingInterval) {
2081 rtc::ScopedFakeClock clock;
2082
2083 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2084 cricket::P2PTransportChannel ch("TestChannel", 1, &pa);
2085 PrepareChannel(&ch);
2086 ch.Connect();
2087 ch.MaybeStartGathering();
2088 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
2089 cricket::Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2090 ASSERT_TRUE(conn != nullptr);
2091
2092 int64_t start = clock.TimeNanos() / 1000000;
2093 // Wait for the connection to send MIN_PINGS_AT_WEAK_PING_INTERVAL pings.
2094 SIMULATED_WAIT(conn->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL,
2095 kDefaultTimeout, clock);
2096 int64_t duration = clock.TimeNanos() / 1000000 - start;
2097 EXPECT_TRUE(duration >= 100 && duration <= 200);
Zhi Huang 2016/06/10 20:39:02 The duration is not expected to be exactly the sam
Zhi Huang 2016/06/20 17:18:17 We can get the exact ping interval for initial pin
2098 }
2099
2100 TEST_F(P2PTransportChannelPingTest, TestStabilizingPingInterval) {
2101 rtc::ScopedFakeClock clock;
2102 int stablilizing_timeout = 2000;
2103
2104 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2105 cricket::P2PTransportChannel ch("TestChannel", 1, &pa);
2106 PrepareChannel(&ch);
2107 ch.Connect();
2108 ch.MaybeStartGathering();
2109 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
2110 cricket::Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2111
2112 ASSERT_TRUE(conn != nullptr);
2113 // Wait for the connection to send MIN_PINGS_AT_WEAK_PING_INTERVAL pings.
2114 SIMULATED_WAIT(conn->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL,
2115 kDefaultTimeout, clock);
2116 // The connection become strong but not stabilized. The ping interval is
2117 // expected to be STABLIZING_WRITABLE_CONNECTION_PING_INTERVAL.
2118 conn->ReceivedPingResponse();
2119 int ping_sent_before = conn->num_pings_sent();
2120 int64_t start = clock.TimeNanos() / 1000000;
2121 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1,
2122 stablilizing_timeout, clock);
2123 int64_t duration = clock.TimeNanos() / 1000000 - start;
2124 EXPECT_TRUE(duration >= 900 && duration <= 1100);
2125 }
2126
2127 TEST_F(P2PTransportChannelPingTest, TestStabilizedPingInterval) {
2128 rtc::ScopedFakeClock clock;
2129 int stabilized_timeout = 3000;
2130
2131 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2132 cricket::P2PTransportChannel ch("TestChannel", 1, &pa);
2133 PrepareChannel(&ch);
2134 ch.Connect();
2135 ch.MaybeStartGathering();
2136 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
2137 cricket::Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2138 ASSERT_TRUE(conn != nullptr);
2139
2140 // Wait for the connection to send MIN_PINGS_TO_STABILIZE pings to stablize.
2141 SIMULATED_WAIT(conn->num_pings_sent() > MIN_PINGS_TO_STABILIZE,
2142 kDefaultTimeout, clock);
2143 // The connection become writable and receiving.
2144 conn->ReceivedPingResponse();
2145 int ping_sent_before = conn->num_pings_sent();
2146 int64_t start = clock.TimeNanos() / 1000000;
2147 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1,
2148 stabilized_timeout, clock);
2149 int64_t duration = clock.TimeNanos() / 1000000 - start;
2150 EXPECT_TRUE(duration >= 2500 && duration <= 2600);
2151 }
2152
2153 // Verify that a stabilized connection will ping faster if a in-flight ping time
2154 // out.
2155 TEST_F(P2PTransportChannelPingTest, TestTimeoutPingInterval) {
2156 rtc::ScopedFakeClock clock;
2157 int stablilizing_timeout = 2000;
2158
2159 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2160 cricket::P2PTransportChannel ch("TestChannel", 1, &pa);
2161 PrepareChannel(&ch);
2162 ch.Connect();
2163 ch.MaybeStartGathering();
2164 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
2165 cricket::Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2166 ASSERT_TRUE(conn != nullptr);
2167
2168 // Wait for the connection to send MIN_PINGS_TO_STABILIZE pings to stablize.
2169 SIMULATED_WAIT(conn->num_pings_sent() >= MIN_PINGS_TO_STABILIZE,
2170 kDefaultTimeout, clock);
2171 // The connection become writable and receiving.
2172 conn->ReceivedPingResponse();
2173
2174 // Create a in-flight ping.
2175 conn->Ping(clock.TimeNanos() / 1000000);
2176 int ping_sent_before = conn->num_pings_sent();
2177 int64_t start = clock.TimeNanos() / 1000000;
2178 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1,
2179 stablilizing_timeout, clock);
2180 int64_t duration = clock.TimeNanos() / 1000000 - start;
2181 EXPECT_TRUE(duration >= 900 && duration <= 1100);
2182 }
2183
2079 TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) { 2184 TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) {
2080 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2185 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2081 cricket::P2PTransportChannel ch("trigger checks", 1, &pa); 2186 cricket::P2PTransportChannel ch("trigger checks", 1, &pa);
2082 PrepareChannel(&ch); 2187 PrepareChannel(&ch);
2083 ch.Connect(); 2188 ch.Connect();
2084 ch.MaybeStartGathering(); 2189 ch.MaybeStartGathering();
2085 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); 2190 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
2086 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2)); 2191 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2));
2087 2192
2088 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2193 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
2700 cricket::RelayServerConfig config(cricket::RELAY_TURN); 2805 cricket::RelayServerConfig config(cricket::RELAY_TURN);
2701 config.credentials = kRelayCredentials; 2806 config.credentials = kRelayCredentials;
2702 config.ports.push_back( 2807 config.ports.push_back(
2703 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false)); 2808 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
2704 allocator_->AddTurnServer(config); 2809 allocator_->AddTurnServer(config);
2705 allocator_->set_step_delay(kMinimumStepDelay); 2810 allocator_->set_step_delay(kMinimumStepDelay);
2706 } 2811 }
2707 2812
2708 cricket::P2PTransportChannel& StartTransportChannel( 2813 cricket::P2PTransportChannel& StartTransportChannel(
2709 bool prioritize_most_likely_to_work, 2814 bool prioritize_most_likely_to_work,
2710 int max_strong_interval) { 2815 int stable_writable_connection_ping_interval) {
2711 channel_.reset( 2816 channel_.reset(
2712 new cricket::P2PTransportChannel("checks", 1, nullptr, allocator())); 2817 new cricket::P2PTransportChannel("checks", 1, nullptr, allocator()));
2713 cricket::IceConfig config = channel_->config(); 2818 cricket::IceConfig config = channel_->config();
2714 config.prioritize_most_likely_candidate_pairs = 2819 config.prioritize_most_likely_candidate_pairs =
2715 prioritize_most_likely_to_work; 2820 prioritize_most_likely_to_work;
2716 config.max_strong_interval = max_strong_interval; 2821 config.stable_writable_connection_ping_interval =
2822 stable_writable_connection_ping_interval;
2717 channel_->SetIceConfig(config); 2823 channel_->SetIceConfig(config);
2718 PrepareChannel(channel_.get()); 2824 PrepareChannel(channel_.get());
2719 channel_->Connect(); 2825 channel_->Connect();
2720 channel_->MaybeStartGathering(); 2826 channel_->MaybeStartGathering();
2721 return *channel_.get(); 2827 return *channel_.get();
2722 } 2828 }
2723 2829
2724 cricket::BasicPortAllocator* allocator() { return allocator_.get(); } 2830 cricket::BasicPortAllocator* allocator() { return allocator_.get(); }
2725 cricket::TestTurnServer* turn_server() { return &turn_server_; } 2831 cricket::TestTurnServer* turn_server() { return &turn_server_; }
2726 2832
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
2915 3021
2916 // TCP Relay/Relay is the next. 3022 // TCP Relay/Relay is the next.
2917 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, 3023 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
2918 cricket::RELAY_PORT_TYPE, 3024 cricket::RELAY_PORT_TYPE,
2919 cricket::TCP_PROTOCOL_NAME); 3025 cricket::TCP_PROTOCOL_NAME);
2920 3026
2921 // Finally, Local/Relay will be pinged. 3027 // Finally, Local/Relay will be pinged.
2922 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, 3028 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE,
2923 cricket::RELAY_PORT_TYPE); 3029 cricket::RELAY_PORT_TYPE);
2924 } 3030 }
OLDNEW
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.cc ('k') | webrtc/p2p/base/port.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698