OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stddef.h> | 5 #include <stddef.h> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 namespace { | 70 namespace { |
71 | 71 |
72 const char kFooResponseBody[] = "Artichoke hearts make me happy."; | 72 const char kFooResponseBody[] = "Artichoke hearts make me happy."; |
73 const char kBarResponseBody[] = "Palm hearts are pretty delicious, also."; | 73 const char kBarResponseBody[] = "Palm hearts are pretty delicious, also."; |
74 | 74 |
75 // Run all tests with the cross products of all versions. | 75 // Run all tests with the cross products of all versions. |
76 struct TestParams { | 76 struct TestParams { |
77 TestParams(const QuicVersionVector& client_supported_versions, | 77 TestParams(const QuicVersionVector& client_supported_versions, |
78 const QuicVersionVector& server_supported_versions, | 78 const QuicVersionVector& server_supported_versions, |
79 QuicVersion negotiated_version, | 79 QuicVersion negotiated_version, |
80 bool use_pacing, | |
81 bool use_fec, | 80 bool use_fec, |
82 QuicTag congestion_control_tag) | 81 QuicTag congestion_control_tag) |
83 : client_supported_versions(client_supported_versions), | 82 : client_supported_versions(client_supported_versions), |
84 server_supported_versions(server_supported_versions), | 83 server_supported_versions(server_supported_versions), |
85 negotiated_version(negotiated_version), | 84 negotiated_version(negotiated_version), |
86 use_pacing(use_pacing), | |
87 use_fec(use_fec), | 85 use_fec(use_fec), |
88 congestion_control_tag(congestion_control_tag) { | 86 congestion_control_tag(congestion_control_tag) { |
89 } | 87 } |
90 | 88 |
91 friend ostream& operator<<(ostream& os, const TestParams& p) { | 89 friend ostream& operator<<(ostream& os, const TestParams& p) { |
92 os << "{ server_supported_versions: " | 90 os << "{ server_supported_versions: " |
93 << QuicVersionVectorToString(p.server_supported_versions); | 91 << QuicVersionVectorToString(p.server_supported_versions); |
94 os << " client_supported_versions: " | 92 os << " client_supported_versions: " |
95 << QuicVersionVectorToString(p.client_supported_versions); | 93 << QuicVersionVectorToString(p.client_supported_versions); |
96 os << " negotiated_version: " << QuicVersionToString(p.negotiated_version); | 94 os << " negotiated_version: " << QuicVersionToString(p.negotiated_version); |
97 os << " use_pacing: " << p.use_pacing; | |
98 os << " use_fec: " << p.use_fec; | 95 os << " use_fec: " << p.use_fec; |
99 os << " congestion_control_tag: " | 96 os << " congestion_control_tag: " |
100 << QuicUtils::TagToString(p.congestion_control_tag) << " }"; | 97 << QuicUtils::TagToString(p.congestion_control_tag) << " }"; |
101 return os; | 98 return os; |
102 } | 99 } |
103 | 100 |
104 QuicVersionVector client_supported_versions; | 101 QuicVersionVector client_supported_versions; |
105 QuicVersionVector server_supported_versions; | 102 QuicVersionVector server_supported_versions; |
106 QuicVersion negotiated_version; | 103 QuicVersion negotiated_version; |
107 bool use_pacing; | |
108 bool use_fec; | 104 bool use_fec; |
109 QuicTag congestion_control_tag; | 105 QuicTag congestion_control_tag; |
110 }; | 106 }; |
111 | 107 |
112 // Constructs various test permutations. | 108 // Constructs various test permutations. |
113 vector<TestParams> GetTestParams() { | 109 vector<TestParams> GetTestParams() { |
114 vector<TestParams> params; | 110 vector<TestParams> params; |
115 QuicVersionVector all_supported_versions = QuicSupportedVersions(); | 111 QuicVersionVector all_supported_versions = QuicSupportedVersions(); |
116 // TODO(rtenneti): Add kTBBR after BBR code is checked in. | 112 // TODO(rtenneti): Add kTBBR after BBR code is checked in. |
117 // QuicTag congestion_control_tags[] = {kRENO, kTBBR, kQBIC}; | 113 // QuicTag congestion_control_tags[] = {kRENO, kTBBR, kQBIC}; |
118 QuicTag congestion_control_tags[] = {kRENO, kQBIC}; | 114 QuicTag congestion_control_tags[] = {kRENO, kQBIC}; |
119 QuicVersionVector spdy3_versions; | 115 QuicVersionVector spdy3_versions; |
120 QuicVersionVector spdy4_versions; | 116 QuicVersionVector spdy4_versions; |
121 for (QuicVersion version : all_supported_versions) { | 117 for (QuicVersion version : all_supported_versions) { |
122 if (version > QUIC_VERSION_23) { | 118 if (version > QUIC_VERSION_23) { |
123 spdy4_versions.push_back(version); | 119 spdy4_versions.push_back(version); |
124 } else { | 120 } else { |
125 spdy3_versions.push_back(version); | 121 spdy3_versions.push_back(version); |
126 } | 122 } |
127 } | 123 } |
128 for (size_t congestion_control_index = 0; | 124 for (size_t congestion_control_index = 0; |
129 congestion_control_index < arraysize(congestion_control_tags); | 125 congestion_control_index < arraysize(congestion_control_tags); |
130 congestion_control_index++) { | 126 congestion_control_index++) { |
131 QuicTag congestion_control_tag = | 127 QuicTag congestion_control_tag = |
132 congestion_control_tags[congestion_control_index]; | 128 congestion_control_tags[congestion_control_index]; |
133 for (int use_fec = 0; use_fec < 2; ++use_fec) { | 129 for (int use_fec = 0; use_fec < 2; ++use_fec) { |
134 for (int use_pacing = 0; use_pacing < 2; ++use_pacing) { | 130 for (int spdy_version = 3; spdy_version <= 4; ++spdy_version) { |
135 for (int spdy_version = 3; spdy_version <= 4; ++spdy_version) { | 131 const QuicVersionVector* client_versions = |
136 const QuicVersionVector* client_versions = | 132 spdy_version == 3 ? &spdy3_versions : &spdy4_versions; |
137 spdy_version == 3 ? &spdy3_versions : &spdy4_versions; | 133 // Add an entry for server and client supporting all versions. |
138 // Add an entry for server and client supporting all versions. | 134 params.push_back(TestParams(*client_versions, all_supported_versions, |
139 params.push_back(TestParams(*client_versions, all_supported_versions, | 135 (*client_versions)[0], use_fec != 0, |
140 (*client_versions)[0], use_pacing != 0, | 136 congestion_control_tag)); |
| 137 |
| 138 // Test client supporting all versions and server supporting 1 |
| 139 // version. Simulate an old server and exercise version downgrade in |
| 140 // the client. Protocol negotiation should occur. Skip the i = 0 case |
| 141 // because it is essentially the same as the default case. |
| 142 for (QuicVersion version : *client_versions) { |
| 143 QuicVersionVector server_supported_versions; |
| 144 server_supported_versions.push_back(version); |
| 145 params.push_back(TestParams(*client_versions, |
| 146 server_supported_versions, |
| 147 server_supported_versions[0], |
141 use_fec != 0, congestion_control_tag)); | 148 use_fec != 0, congestion_control_tag)); |
142 | |
143 // Test client supporting all versions and server supporting 1 | |
144 // version. Simulate an old server and exercise version downgrade in | |
145 // the client. Protocol negotiation should occur. Skip the i = 0 case | |
146 // because it is essentially the same as the default case. | |
147 for (QuicVersion version : *client_versions) { | |
148 QuicVersionVector server_supported_versions; | |
149 server_supported_versions.push_back(version); | |
150 params.push_back( | |
151 TestParams(*client_versions, server_supported_versions, | |
152 server_supported_versions[0], use_pacing != 0, | |
153 use_fec != 0, congestion_control_tag)); | |
154 } | |
155 } | 149 } |
156 } | 150 } |
157 } | 151 } |
158 } | 152 } |
159 return params; | 153 return params; |
160 } | 154 } |
161 | 155 |
162 class ServerDelegate : public PacketDroppingTestWriter::Delegate { | 156 class ServerDelegate : public PacketDroppingTestWriter::Delegate { |
163 public: | 157 public: |
164 ServerDelegate(TestWriterFactory* writer_factory, | 158 ServerDelegate(TestWriterFactory* writer_factory, |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 const QuicSentPacketManager * | 266 const QuicSentPacketManager * |
273 GetSentPacketManagerFromFirstServerSession() const { | 267 GetSentPacketManagerFromFirstServerSession() const { |
274 QuicDispatcher* dispatcher = | 268 QuicDispatcher* dispatcher = |
275 QuicServerPeer::GetDispatcher(server_thread_->server()); | 269 QuicServerPeer::GetDispatcher(server_thread_->server()); |
276 QuicSession* session = dispatcher->session_map().begin()->second; | 270 QuicSession* session = dispatcher->session_map().begin()->second; |
277 return &session->connection()->sent_packet_manager(); | 271 return &session->connection()->sent_packet_manager(); |
278 } | 272 } |
279 | 273 |
280 bool Initialize() { | 274 bool Initialize() { |
281 QuicTagVector copt; | 275 QuicTagVector copt; |
282 | |
283 if (GetParam().use_pacing) { | |
284 copt.push_back(kPACE); | |
285 } | |
286 server_config_.SetConnectionOptionsToSend(copt); | 276 server_config_.SetConnectionOptionsToSend(copt); |
287 | 277 |
288 // TODO(nimia): Consider setting the congestion control algorithm for the | 278 // TODO(nimia): Consider setting the congestion control algorithm for the |
289 // client as well according to the test parameter. | 279 // client as well according to the test parameter. |
290 copt.push_back(GetParam().congestion_control_tag); | 280 copt.push_back(GetParam().congestion_control_tag); |
291 | 281 |
292 if (GetParam().use_fec) { | 282 if (GetParam().use_fec) { |
293 // Set FEC config in client's connection options and in client session. | 283 // Set FEC config in client's connection options and in client session. |
294 copt.push_back(kFHDR); | 284 copt.push_back(kFHDR); |
295 } | 285 } |
(...skipping 15 matching lines...) Expand all Loading... |
311 client_->client()->session()->connection())), | 301 client_->client()->session()->connection())), |
312 new ClientDelegate(client_->client())); | 302 new ClientDelegate(client_->client())); |
313 return client_->client()->connected(); | 303 return client_->client()->connected(); |
314 } | 304 } |
315 | 305 |
316 void SetUp() override { | 306 void SetUp() override { |
317 // The ownership of these gets transferred to the QuicPacketWriterWrapper | 307 // The ownership of these gets transferred to the QuicPacketWriterWrapper |
318 // and TestWriterFactory when Initialize() is executed. | 308 // and TestWriterFactory when Initialize() is executed. |
319 client_writer_ = new PacketDroppingTestWriter(); | 309 client_writer_ = new PacketDroppingTestWriter(); |
320 server_writer_ = new PacketDroppingTestWriter(); | 310 server_writer_ = new PacketDroppingTestWriter(); |
321 // TODO(ianswett): Remove this once it's fully rolled out. | |
322 FLAGS_quic_enable_pacing = false; | |
323 } | 311 } |
324 | 312 |
325 void TearDown() override { StopServer(); } | 313 void TearDown() override { StopServer(); } |
326 | 314 |
327 void StartServer() { | 315 void StartServer() { |
328 server_thread_.reset( | 316 server_thread_.reset( |
329 new ServerThread( | 317 new ServerThread( |
330 new QuicServer(server_config_, server_supported_versions_), | 318 new QuicServer(server_config_, server_supported_versions_), |
331 server_address_, | 319 server_address_, |
332 strike_register_no_startup_period_)); | 320 strike_register_no_startup_period_)); |
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
922 // Pause the server so we can access the server's internals without races. | 910 // Pause the server so we can access the server's internals without races. |
923 server_thread_->Pause(); | 911 server_thread_->Pause(); |
924 QuicDispatcher* dispatcher = | 912 QuicDispatcher* dispatcher = |
925 QuicServerPeer::GetDispatcher(server_thread_->server()); | 913 QuicServerPeer::GetDispatcher(server_thread_->server()); |
926 ASSERT_EQ(1u, dispatcher->session_map().size()); | 914 ASSERT_EQ(1u, dispatcher->session_map().size()); |
927 const QuicSentPacketManager& client_sent_packet_manager = | 915 const QuicSentPacketManager& client_sent_packet_manager = |
928 client_->client()->session()->connection()->sent_packet_manager(); | 916 client_->client()->session()->connection()->sent_packet_manager(); |
929 const QuicSentPacketManager& server_sent_packet_manager = | 917 const QuicSentPacketManager& server_sent_packet_manager = |
930 *GetSentPacketManagerFromFirstServerSession(); | 918 *GetSentPacketManagerFromFirstServerSession(); |
931 | 919 |
932 // BBR automatically enables pacing. | |
933 EXPECT_EQ(GetParam().use_pacing || | |
934 (FLAGS_quic_allow_bbr && | |
935 GetParam().congestion_control_tag == kTBBR), | |
936 server_sent_packet_manager.using_pacing()); | |
937 EXPECT_EQ(GetParam().use_pacing || | |
938 (FLAGS_quic_allow_bbr && | |
939 GetParam().congestion_control_tag == kTBBR), | |
940 client_sent_packet_manager.using_pacing()); | |
941 | |
942 EXPECT_EQ(kInitialRTT, | 920 EXPECT_EQ(kInitialRTT, |
943 client_sent_packet_manager.GetRttStats()->initial_rtt_us()); | 921 client_sent_packet_manager.GetRttStats()->initial_rtt_us()); |
944 EXPECT_EQ(kInitialRTT, | 922 EXPECT_EQ(kInitialRTT, |
945 server_sent_packet_manager.GetRttStats()->initial_rtt_us()); | 923 server_sent_packet_manager.GetRttStats()->initial_rtt_us()); |
946 server_thread_->Resume(); | 924 server_thread_->Resume(); |
947 } | 925 } |
948 | 926 |
949 TEST_P(EndToEndTest, MaxInitialRTT) { | 927 TEST_P(EndToEndTest, MaxInitialRTT) { |
950 // Client tries to suggest twice the server's max initial rtt and the server | 928 // Client tries to suggest twice the server's max initial rtt and the server |
951 // uses the max. | 929 // uses the max. |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1349 // Now verify that the server is not waiting for a final FIN or RST. | 1327 // Now verify that the server is not waiting for a final FIN or RST. |
1350 server_thread_->Pause(); | 1328 server_thread_->Pause(); |
1351 QuicDispatcher* dispatcher = | 1329 QuicDispatcher* dispatcher = |
1352 QuicServerPeer::GetDispatcher(server_thread_->server()); | 1330 QuicServerPeer::GetDispatcher(server_thread_->server()); |
1353 QuicSession* session = dispatcher->session_map().begin()->second; | 1331 QuicSession* session = dispatcher->session_map().begin()->second; |
1354 EXPECT_EQ(0u, QuicSessionPeer::GetLocallyClosedStreamsHighestOffset( | 1332 EXPECT_EQ(0u, QuicSessionPeer::GetLocallyClosedStreamsHighestOffset( |
1355 session).size()); | 1333 session).size()); |
1356 server_thread_->Resume(); | 1334 server_thread_->Resume(); |
1357 } | 1335 } |
1358 | 1336 |
1359 TEST_P(EndToEndTest, EnablePacingViaFlag) { | |
1360 // When pacing is enabled via command-line flag, it will always be enabled, | |
1361 // regardless of the config. or the specific congestion-control algorithm. | |
1362 ValueRestore<bool> old_flag(&FLAGS_quic_enable_pacing, true); | |
1363 ASSERT_TRUE(Initialize()); | |
1364 | |
1365 client_->client()->WaitForCryptoHandshakeConfirmed(); | |
1366 server_thread_->WaitForCryptoHandshakeConfirmed(); | |
1367 | |
1368 // Pause the server so we can access the server's internals without races. | |
1369 server_thread_->Pause(); | |
1370 QuicDispatcher* dispatcher = | |
1371 QuicServerPeer::GetDispatcher(server_thread_->server()); | |
1372 ASSERT_EQ(1u, dispatcher->session_map().size()); | |
1373 const QuicSentPacketManager& client_sent_packet_manager = | |
1374 client_->client()->session()->connection()->sent_packet_manager(); | |
1375 const QuicSentPacketManager& server_sent_packet_manager = | |
1376 *GetSentPacketManagerFromFirstServerSession(); | |
1377 EXPECT_TRUE(server_sent_packet_manager.using_pacing()); | |
1378 EXPECT_TRUE(client_sent_packet_manager.using_pacing()); | |
1379 } | |
1380 | |
1381 // A TestAckNotifierDelegate verifies that its OnAckNotification method has been | 1337 // A TestAckNotifierDelegate verifies that its OnAckNotification method has been |
1382 // called exactly once on destruction. | 1338 // called exactly once on destruction. |
1383 class TestAckNotifierDelegate : public QuicAckNotifier::DelegateInterface { | 1339 class TestAckNotifierDelegate : public QuicAckNotifier::DelegateInterface { |
1384 public: | 1340 public: |
1385 TestAckNotifierDelegate() {} | 1341 TestAckNotifierDelegate() {} |
1386 | 1342 |
1387 void OnAckNotification(int /*num_retransmitted_packets*/, | 1343 void OnAckNotification(int /*num_retransmitted_packets*/, |
1388 int /*num_retransmitted_bytes*/, | 1344 int /*num_retransmitted_bytes*/, |
1389 QuicTime::Delta /*delta_largest_observed*/) override { | 1345 QuicTime::Delta /*delta_largest_observed*/) override { |
1390 ASSERT_FALSE(has_been_notified_); | 1346 ASSERT_FALSE(has_been_notified_); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1443 // Waits for up to 50 ms. | 1399 // Waits for up to 50 ms. |
1444 client_->client()->WaitForEvents(); | 1400 client_->client()->WaitForEvents(); |
1445 } | 1401 } |
1446 server_thread_->Resume(); | 1402 server_thread_->Resume(); |
1447 } | 1403 } |
1448 | 1404 |
1449 } // namespace | 1405 } // namespace |
1450 } // namespace test | 1406 } // namespace test |
1451 } // namespace tools | 1407 } // namespace tools |
1452 } // namespace net | 1408 } // namespace net |
OLD | NEW |