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 <sys/epoll.h> | 6 #include <sys/epoll.h> |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
(...skipping 30 matching lines...) Expand all Loading... |
41 #include "net/tools/epoll_server/epoll_server.h" | 41 #include "net/tools/epoll_server/epoll_server.h" |
42 #include "net/tools/quic/quic_epoll_connection_helper.h" | 42 #include "net/tools/quic/quic_epoll_connection_helper.h" |
43 #include "net/tools/quic/quic_in_memory_cache.h" | 43 #include "net/tools/quic/quic_in_memory_cache.h" |
44 #include "net/tools/quic/quic_packet_writer_wrapper.h" | 44 #include "net/tools/quic/quic_packet_writer_wrapper.h" |
45 #include "net/tools/quic/quic_server.h" | 45 #include "net/tools/quic/quic_server.h" |
46 #include "net/tools/quic/quic_simple_server_stream.h" | 46 #include "net/tools/quic/quic_simple_server_stream.h" |
47 #include "net/tools/quic/quic_socket_utils.h" | 47 #include "net/tools/quic/quic_socket_utils.h" |
48 #include "net/tools/quic/quic_spdy_client_stream.h" | 48 #include "net/tools/quic/quic_spdy_client_stream.h" |
49 #include "net/tools/quic/test_tools/http_message.h" | 49 #include "net/tools/quic/test_tools/http_message.h" |
50 #include "net/tools/quic/test_tools/packet_dropping_test_writer.h" | 50 #include "net/tools/quic/test_tools/packet_dropping_test_writer.h" |
| 51 #include "net/tools/quic/test_tools/packet_reordering_writer.h" |
51 #include "net/tools/quic/test_tools/quic_client_peer.h" | 52 #include "net/tools/quic/test_tools/quic_client_peer.h" |
52 #include "net/tools/quic/test_tools/quic_dispatcher_peer.h" | 53 #include "net/tools/quic/test_tools/quic_dispatcher_peer.h" |
53 #include "net/tools/quic/test_tools/quic_in_memory_cache_peer.h" | 54 #include "net/tools/quic/test_tools/quic_in_memory_cache_peer.h" |
54 #include "net/tools/quic/test_tools/quic_server_peer.h" | 55 #include "net/tools/quic/test_tools/quic_server_peer.h" |
55 #include "net/tools/quic/test_tools/quic_test_client.h" | 56 #include "net/tools/quic/test_tools/quic_test_client.h" |
56 #include "net/tools/quic/test_tools/quic_test_server.h" | 57 #include "net/tools/quic/test_tools/quic_test_server.h" |
57 #include "net/tools/quic/test_tools/server_thread.h" | 58 #include "net/tools/quic/test_tools/server_thread.h" |
58 #include "testing/gtest/include/gtest/gtest.h" | 59 #include "testing/gtest/include/gtest/gtest.h" |
59 | 60 |
60 using base::IntToString; | 61 using base::IntToString; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 94 |
94 // Run all tests with the cross products of all versions. | 95 // Run all tests with the cross products of all versions. |
95 struct TestParams { | 96 struct TestParams { |
96 TestParams(const QuicVersionVector& client_supported_versions, | 97 TestParams(const QuicVersionVector& client_supported_versions, |
97 const QuicVersionVector& server_supported_versions, | 98 const QuicVersionVector& server_supported_versions, |
98 QuicVersion negotiated_version, | 99 QuicVersion negotiated_version, |
99 bool client_supports_stateless_rejects, | 100 bool client_supports_stateless_rejects, |
100 bool server_uses_stateless_rejects_if_peer_supported, | 101 bool server_uses_stateless_rejects_if_peer_supported, |
101 QuicTag congestion_control_tag, | 102 QuicTag congestion_control_tag, |
102 bool disable_hpack_dynamic_table, | 103 bool disable_hpack_dynamic_table, |
103 bool force_hol_blocking) | 104 bool force_hol_blocking, |
| 105 bool use_cheap_stateless_reject, |
| 106 bool buffer_packet_till_chlo) |
104 : client_supported_versions(client_supported_versions), | 107 : client_supported_versions(client_supported_versions), |
105 server_supported_versions(server_supported_versions), | 108 server_supported_versions(server_supported_versions), |
106 negotiated_version(negotiated_version), | 109 negotiated_version(negotiated_version), |
107 client_supports_stateless_rejects(client_supports_stateless_rejects), | 110 client_supports_stateless_rejects(client_supports_stateless_rejects), |
108 server_uses_stateless_rejects_if_peer_supported( | 111 server_uses_stateless_rejects_if_peer_supported( |
109 server_uses_stateless_rejects_if_peer_supported), | 112 server_uses_stateless_rejects_if_peer_supported), |
110 congestion_control_tag(congestion_control_tag), | 113 congestion_control_tag(congestion_control_tag), |
111 disable_hpack_dynamic_table(disable_hpack_dynamic_table), | 114 disable_hpack_dynamic_table(disable_hpack_dynamic_table), |
112 force_hol_blocking(force_hol_blocking) {} | 115 force_hol_blocking(force_hol_blocking), |
| 116 use_cheap_stateless_reject(use_cheap_stateless_reject), |
| 117 buffer_packet_till_chlo(buffer_packet_till_chlo) {} |
113 | 118 |
114 friend ostream& operator<<(ostream& os, const TestParams& p) { | 119 friend ostream& operator<<(ostream& os, const TestParams& p) { |
115 os << "{ server_supported_versions: " | 120 os << "{ server_supported_versions: " |
116 << QuicVersionVectorToString(p.server_supported_versions); | 121 << QuicVersionVectorToString(p.server_supported_versions); |
117 os << " client_supported_versions: " | 122 os << " client_supported_versions: " |
118 << QuicVersionVectorToString(p.client_supported_versions); | 123 << QuicVersionVectorToString(p.client_supported_versions); |
119 os << " negotiated_version: " << QuicVersionToString(p.negotiated_version); | 124 os << " negotiated_version: " << QuicVersionToString(p.negotiated_version); |
120 os << " client_supports_stateless_rejects: " | 125 os << " client_supports_stateless_rejects: " |
121 << p.client_supports_stateless_rejects; | 126 << p.client_supports_stateless_rejects; |
122 os << " server_uses_stateless_rejects_if_peer_supported: " | 127 os << " server_uses_stateless_rejects_if_peer_supported: " |
123 << p.server_uses_stateless_rejects_if_peer_supported; | 128 << p.server_uses_stateless_rejects_if_peer_supported; |
124 os << " congestion_control_tag: " | 129 os << " congestion_control_tag: " |
125 << QuicUtils::TagToString(p.congestion_control_tag); | 130 << QuicUtils::TagToString(p.congestion_control_tag); |
126 os << " disable_hpack_dynamic_table: " << p.disable_hpack_dynamic_table; | 131 os << " disable_hpack_dynamic_table: " << p.disable_hpack_dynamic_table; |
127 os << " force_hol_blocking: " << p.force_hol_blocking << " }"; | 132 os << " force_hol_blocking: " << p.force_hol_blocking; |
| 133 os << " use_cheap_stateless_reject: " << p.use_cheap_stateless_reject; |
| 134 os << " buffer_packet_till_chlo: " << p.buffer_packet_till_chlo << " }"; |
128 return os; | 135 return os; |
129 } | 136 } |
130 | 137 |
131 QuicVersionVector client_supported_versions; | 138 QuicVersionVector client_supported_versions; |
132 QuicVersionVector server_supported_versions; | 139 QuicVersionVector server_supported_versions; |
133 QuicVersion negotiated_version; | 140 QuicVersion negotiated_version; |
134 bool client_supports_stateless_rejects; | 141 bool client_supports_stateless_rejects; |
135 bool server_uses_stateless_rejects_if_peer_supported; | 142 bool server_uses_stateless_rejects_if_peer_supported; |
136 QuicTag congestion_control_tag; | 143 QuicTag congestion_control_tag; |
137 bool disable_hpack_dynamic_table; | 144 bool disable_hpack_dynamic_table; |
138 bool force_hol_blocking; | 145 bool force_hol_blocking; |
| 146 bool use_cheap_stateless_reject; |
| 147 bool buffer_packet_till_chlo; |
139 }; | 148 }; |
140 | 149 |
141 // Constructs various test permutations. | 150 // Constructs various test permutations. |
142 vector<TestParams> GetTestParams() { | 151 vector<TestParams> GetTestParams() { |
143 // Divide the versions into buckets in which the intra-frame format | 152 // Divide the versions into buckets in which the intra-frame format |
144 // is compatible. When clients encounter QUIC version negotiation | 153 // is compatible. When clients encounter QUIC version negotiation |
145 // they simply retransmit all packets using the new version's | 154 // they simply retransmit all packets using the new version's |
146 // QUIC framing. However, they are unable to change the intra-frame | 155 // QUIC framing. However, they are unable to change the intra-frame |
147 // layout (for example to change SPDY/4 headers to SPDY/3). So | 156 // layout (for example to change SPDY/4 headers to SPDY/3). So |
148 // these tests need to ensure that clients are never attempting | 157 // these tests need to ensure that clients are never attempting |
149 // to do 0-RTT across incompatible versions. Chromium only supports | 158 // to do 0-RTT across incompatible versions. Chromium only supports |
150 // a single version at a time anyway. :) | 159 // a single version at a time anyway. :) |
151 QuicVersionVector all_supported_versions = QuicSupportedVersions(); | 160 QuicVersionVector all_supported_versions = AllSupportedVersions(); |
152 QuicVersionVector version_buckets[4]; | 161 QuicVersionVector version_buckets[4]; |
153 | 162 |
154 for (const QuicVersion version : all_supported_versions) { | 163 for (const QuicVersion version : all_supported_versions) { |
155 if (version <= QUIC_VERSION_30) { | 164 if (version <= QUIC_VERSION_30) { |
156 // Versions: 30 | 165 // Versions: 30 |
157 // v26 adds a hash of the expected leaf cert in the XLCT tag. | 166 // v26 adds a hash of the expected leaf cert in the XLCT tag. |
158 version_buckets[0].push_back(version); | 167 version_buckets[0].push_back(version); |
159 } else if (version <= QUIC_VERSION_32) { | 168 } else if (version <= QUIC_VERSION_32) { |
160 // Versions: 31-32 | 169 // Versions: 31-32 |
161 // v31 adds a hash of the CHLO into the proof signature. | 170 // v31 adds a hash of the CHLO into the proof signature. |
162 version_buckets[1].push_back(version); | 171 version_buckets[1].push_back(version); |
163 } else if (version <= QUIC_VERSION_33) { | 172 } else if (version <= QUIC_VERSION_33) { |
164 // Versions: 33 | 173 // Versions: 33 |
165 // v33 adds a diversification nonce into the hkdf. | 174 // v33 adds a diversification nonce into the hkdf. |
166 version_buckets[2].push_back(version); | 175 version_buckets[2].push_back(version); |
167 } else { | 176 } else { |
168 // Versions: 34+ | 177 // Versions: 34+ |
169 // QUIC_VERSION_34 deprecates entropy and uses new ack and stop waiting | 178 // QUIC_VERSION_34 deprecates entropy and uses new ack and stop waiting |
170 // wire formats. | 179 // wire formats. |
171 version_buckets[3].push_back(version); | 180 version_buckets[3].push_back(version); |
172 } | 181 } |
173 } | 182 } |
174 | 183 |
175 // This must be kept in sync with the number of nested for-loops below as it | 184 // This must be kept in sync with the number of nested for-loops below as it |
176 // is used to prune the number of tests that are run. | 185 // is used to prune the number of tests that are run. |
177 const int kMaxEnabledOptions = 4; | 186 const int kMaxEnabledOptions = 6; |
178 int max_enabled_options = 0; | 187 int max_enabled_options = 0; |
179 vector<TestParams> params; | 188 vector<TestParams> params; |
180 for (bool server_uses_stateless_rejects_if_peer_supported : {true, false}) { | 189 for (bool server_uses_stateless_rejects_if_peer_supported : {true, false}) { |
181 for (bool client_supports_stateless_rejects : {true, false}) { | 190 for (bool client_supports_stateless_rejects : {true, false}) { |
182 for (const QuicTag congestion_control_tag : {kRENO, kQBIC}) { | 191 for (const QuicTag congestion_control_tag : {kRENO, kQBIC}) { |
183 for (bool disable_hpack_dynamic_table : {false}) { | 192 for (bool disable_hpack_dynamic_table : {false}) { |
184 for (bool force_hol_blocking : {true, false}) { | 193 for (bool force_hol_blocking : {true, false}) { |
185 int enabled_options = 0; | 194 for (bool use_cheap_stateless_reject : {true, false}) { |
186 if (force_hol_blocking) { | 195 for (bool buffer_packet_till_chlo : {true, false}) { |
187 ++enabled_options; | 196 if (!buffer_packet_till_chlo && use_cheap_stateless_reject) { |
188 } | 197 // Doing stateless reject while not buffering packet |
189 if (congestion_control_tag != kQBIC) { | 198 // before CHLO is not allowed. |
190 ++enabled_options; | 199 break; |
191 } | 200 } |
192 if (disable_hpack_dynamic_table) { | 201 int enabled_options = 0; |
193 ++enabled_options; | 202 if (force_hol_blocking) { |
194 } | 203 ++enabled_options; |
195 if (client_supports_stateless_rejects) { | 204 } |
196 ++enabled_options; | 205 if (congestion_control_tag != kQBIC) { |
197 } | 206 ++enabled_options; |
198 if (server_uses_stateless_rejects_if_peer_supported) { | 207 } |
199 ++enabled_options; | 208 if (disable_hpack_dynamic_table) { |
200 } | 209 ++enabled_options; |
201 CHECK_GE(kMaxEnabledOptions, enabled_options); | 210 } |
202 if (enabled_options > max_enabled_options) { | 211 if (client_supports_stateless_rejects) { |
203 max_enabled_options = enabled_options; | 212 ++enabled_options; |
204 } | 213 } |
| 214 if (server_uses_stateless_rejects_if_peer_supported) { |
| 215 ++enabled_options; |
| 216 } |
| 217 if (buffer_packet_till_chlo) { |
| 218 ++enabled_options; |
| 219 } |
| 220 if (use_cheap_stateless_reject) { |
| 221 ++enabled_options; |
| 222 } |
| 223 CHECK_GE(kMaxEnabledOptions, enabled_options); |
| 224 if (enabled_options > max_enabled_options) { |
| 225 max_enabled_options = enabled_options; |
| 226 } |
205 | 227 |
206 // Run tests with no options, a single option, or all the options | 228 // Run tests with no options, a single option, or all the |
207 // enabled to avoid a combinatorial explosion. | 229 // options enabled to avoid a combinatorial explosion. |
208 if (enabled_options > 1 && enabled_options < kMaxEnabledOptions) { | 230 if (enabled_options > 1 && |
209 continue; | 231 enabled_options < kMaxEnabledOptions) { |
210 } | 232 continue; |
| 233 } |
211 | 234 |
212 for (const QuicVersionVector& client_versions : version_buckets) { | 235 for (const QuicVersionVector& client_versions : |
213 CHECK(!client_versions.empty()); | 236 version_buckets) { |
214 // Add an entry for server and client supporting all versions. | 237 CHECK(!client_versions.empty()); |
215 params.push_back(TestParams( | 238 // Add an entry for server and client supporting all versions. |
216 client_versions, all_supported_versions, | 239 params.push_back(TestParams( |
217 client_versions.front(), client_supports_stateless_rejects, | 240 client_versions, all_supported_versions, |
218 server_uses_stateless_rejects_if_peer_supported, | 241 client_versions.front(), |
219 congestion_control_tag, disable_hpack_dynamic_table, | 242 client_supports_stateless_rejects, |
220 force_hol_blocking)); | 243 server_uses_stateless_rejects_if_peer_supported, |
| 244 congestion_control_tag, disable_hpack_dynamic_table, |
| 245 force_hol_blocking, use_cheap_stateless_reject, |
| 246 buffer_packet_till_chlo)); |
221 | 247 |
222 // Run version negotiation tests tests with no options, or all | 248 // Run version negotiation tests tests with no options, or all |
223 // the options enabled to avoid a combinatorial explosion. | 249 // the options enabled to avoid a combinatorial explosion. |
224 if (enabled_options > 0 && enabled_options < kMaxEnabledOptions) { | 250 if (enabled_options > 0 && |
225 continue; | 251 enabled_options < kMaxEnabledOptions) { |
226 } | 252 continue; |
| 253 } |
227 | 254 |
228 // Test client supporting all versions and server | 255 // Test client supporting all versions and server supporting 1 |
229 // supporting 1 version. Simulate an old server and | 256 // version. Simulate an old server and exercise version |
230 // exercise version downgrade in the client. Protocol | 257 // downgrade in the client. Protocol negotiation should occur. |
231 // negotiation should occur. Skip the i = 0 case | 258 // Skip the i = 0 case because it is essentially the same as |
232 // because it is essentially the same as the default | 259 // the default case. |
233 // case. | 260 for (size_t i = 1; i < client_versions.size(); ++i) { |
234 for (size_t i = 1; i < client_versions.size(); ++i) { | 261 QuicVersionVector server_supported_versions; |
235 QuicVersionVector server_supported_versions; | 262 server_supported_versions.push_back(client_versions[i]); |
236 server_supported_versions.push_back(client_versions[i]); | 263 params.push_back(TestParams( |
237 params.push_back(TestParams( | 264 client_versions, server_supported_versions, |
238 client_versions, server_supported_versions, | 265 server_supported_versions.front(), |
239 server_supported_versions.front(), | 266 client_supports_stateless_rejects, |
240 client_supports_stateless_rejects, | 267 server_uses_stateless_rejects_if_peer_supported, |
241 server_uses_stateless_rejects_if_peer_supported, | 268 congestion_control_tag, disable_hpack_dynamic_table, |
242 congestion_control_tag, disable_hpack_dynamic_table, | 269 force_hol_blocking, use_cheap_stateless_reject, |
243 force_hol_blocking)); | 270 buffer_packet_till_chlo)); |
244 } | 271 } // End of version for loop. |
245 } | 272 } // End of 2nd version for loop. |
246 } | 273 } // End of buffer_packet_till_chlo loop. |
247 } | 274 } // End of use_cheap_stateless_reject for loop. |
248 } | 275 } // End of force_hol_blocking loop. |
249 } | 276 } // End of disable_hpack_dynamic_table for loop. |
| 277 } // End of congestion_control_tag for loop. |
| 278 } // End of client_supports_stateless_rejects for loop. |
250 CHECK_EQ(kMaxEnabledOptions, max_enabled_options); | 279 CHECK_EQ(kMaxEnabledOptions, max_enabled_options); |
251 } | 280 } // End of server_uses_stateless_rejects_if_peer_supported for loop. |
252 return params; | 281 return params; |
253 } | 282 } |
254 | 283 |
255 class ServerDelegate : public PacketDroppingTestWriter::Delegate { | 284 class ServerDelegate : public PacketDroppingTestWriter::Delegate { |
256 public: | 285 public: |
257 explicit ServerDelegate(QuicDispatcher* dispatcher) | 286 explicit ServerDelegate(QuicDispatcher* dispatcher) |
258 : dispatcher_(dispatcher) {} | 287 : dispatcher_(dispatcher) {} |
259 ~ServerDelegate() override {} | 288 ~ServerDelegate() override {} |
260 void OnCanWrite() override { dispatcher_->OnCanWrite(); } | 289 void OnCanWrite() override { dispatcher_->OnCanWrite(); } |
261 | 290 |
(...skipping 13 matching lines...) Expand all Loading... |
275 private: | 304 private: |
276 QuicClient* client_; | 305 QuicClient* client_; |
277 }; | 306 }; |
278 | 307 |
279 class EndToEndTest : public ::testing::TestWithParam<TestParams> { | 308 class EndToEndTest : public ::testing::TestWithParam<TestParams> { |
280 protected: | 309 protected: |
281 EndToEndTest() | 310 EndToEndTest() |
282 : initialized_(false), | 311 : initialized_(false), |
283 server_address_(IPEndPoint(Loopback4(), 0)), | 312 server_address_(IPEndPoint(Loopback4(), 0)), |
284 server_hostname_("test.example.com"), | 313 server_hostname_("test.example.com"), |
| 314 client_writer_(nullptr), |
| 315 server_writer_(nullptr), |
285 server_started_(false), | 316 server_started_(false), |
286 strike_register_no_startup_period_(false), | 317 strike_register_no_startup_period_(false), |
287 chlo_multiplier_(0), | 318 chlo_multiplier_(0), |
288 stream_factory_(nullptr), | 319 stream_factory_(nullptr), |
289 support_server_push_(false) { | 320 support_server_push_(false) { |
290 client_supported_versions_ = GetParam().client_supported_versions; | 321 client_supported_versions_ = GetParam().client_supported_versions; |
291 server_supported_versions_ = GetParam().server_supported_versions; | 322 server_supported_versions_ = GetParam().server_supported_versions; |
292 negotiated_version_ = GetParam().negotiated_version; | 323 negotiated_version_ = GetParam().negotiated_version; |
293 | 324 |
294 VLOG(1) << "Using Configuration: " << GetParam(); | 325 VLOG(1) << "Using Configuration: " << GetParam(); |
(...skipping 20 matching lines...) Expand all Loading... |
315 AddToCache("/foo", 200, kFooResponseBody); | 346 AddToCache("/foo", 200, kFooResponseBody); |
316 AddToCache("/bar", 200, kBarResponseBody); | 347 AddToCache("/bar", 200, kBarResponseBody); |
317 } | 348 } |
318 | 349 |
319 ~EndToEndTest() override { | 350 ~EndToEndTest() override { |
320 // TODO(rtenneti): port RecycleUnusedPort if needed. | 351 // TODO(rtenneti): port RecycleUnusedPort if needed. |
321 // RecycleUnusedPort(server_address_.port()); | 352 // RecycleUnusedPort(server_address_.port()); |
322 QuicInMemoryCachePeer::ResetForTests(); | 353 QuicInMemoryCachePeer::ResetForTests(); |
323 } | 354 } |
324 | 355 |
| 356 virtual void CreateClientWithWriter() { |
| 357 client_.reset(CreateQuicClient(client_writer_)); |
| 358 } |
| 359 |
325 QuicTestClient* CreateQuicClient(QuicPacketWriterWrapper* writer) { | 360 QuicTestClient* CreateQuicClient(QuicPacketWriterWrapper* writer) { |
326 QuicTestClient* client = new QuicTestClient( | 361 QuicTestClient* client = new QuicTestClient( |
327 server_address_, server_hostname_, client_config_, | 362 server_address_, server_hostname_, client_config_, |
328 client_supported_versions_, CryptoTestUtils::ProofVerifierForTesting()); | 363 client_supported_versions_, CryptoTestUtils::ProofVerifierForTesting()); |
329 client->UseWriter(writer); | 364 client->UseWriter(writer); |
330 client->Connect(); | 365 client->Connect(); |
331 return client; | 366 return client; |
332 } | 367 } |
333 | 368 |
334 void set_smaller_flow_control_receive_window() { | 369 void set_smaller_flow_control_receive_window() { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 copt.push_back(kSPSH); | 422 copt.push_back(kSPSH); |
388 } | 423 } |
389 if (GetParam().client_supports_stateless_rejects) { | 424 if (GetParam().client_supports_stateless_rejects) { |
390 copt.push_back(kSREJ); | 425 copt.push_back(kSREJ); |
391 } | 426 } |
392 if (GetParam().disable_hpack_dynamic_table) { | 427 if (GetParam().disable_hpack_dynamic_table) { |
393 copt.push_back(kDHDT); | 428 copt.push_back(kDHDT); |
394 } | 429 } |
395 if (GetParam().force_hol_blocking) { | 430 if (GetParam().force_hol_blocking) { |
396 client_config_.SetForceHolBlocking(); | 431 client_config_.SetForceHolBlocking(); |
397 QuicConfigPeer::SetReceivedForceHolBlocking(&server_config_); | |
398 } | 432 } |
399 client_config_.SetConnectionOptionsToSend(copt); | 433 client_config_.SetConnectionOptionsToSend(copt); |
400 | 434 |
401 // Start the server first, because CreateQuicClient() attempts | 435 // Start the server first, because CreateQuicClient() attempts |
402 // to connect to the server. | 436 // to connect to the server. |
403 StartServer(); | 437 StartServer(); |
404 | 438 |
405 client_.reset(CreateQuicClient(client_writer_)); | 439 CreateClientWithWriter(); |
406 static EpollEvent event(EPOLLOUT, false); | 440 static EpollEvent event(EPOLLOUT, false); |
407 client_writer_->Initialize( | 441 if (client_writer_ != nullptr) { |
408 reinterpret_cast<QuicEpollConnectionHelper*>( | 442 client_writer_->Initialize( |
409 QuicConnectionPeer::GetHelper( | 443 reinterpret_cast<QuicEpollConnectionHelper*>( |
410 client_->client()->session()->connection())), | 444 QuicConnectionPeer::GetHelper( |
411 QuicConnectionPeer::GetAlarmFactory( | 445 client_->client()->session()->connection())), |
412 client_->client()->session()->connection()), | 446 QuicConnectionPeer::GetAlarmFactory( |
413 new ClientDelegate(client_->client())); | 447 client_->client()->session()->connection()), |
414 | 448 new ClientDelegate(client_->client())); |
| 449 } |
415 initialized_ = true; | 450 initialized_ = true; |
416 return client_->client()->connected(); | 451 return client_->client()->connected(); |
417 } | 452 } |
418 | 453 |
419 void SetUp() override { | 454 void SetUp() override { |
420 // The ownership of these gets transferred to the QuicPacketWriterWrapper | 455 // The ownership of these gets transferred to the QuicPacketWriterWrapper |
421 // when Initialize() is executed. | 456 // when Initialize() is executed. |
422 client_writer_ = new PacketDroppingTestWriter(); | 457 client_writer_ = new PacketDroppingTestWriter(); |
423 server_writer_ = new PacketDroppingTestWriter(); | 458 server_writer_ = new PacketDroppingTestWriter(); |
424 } | 459 } |
425 | 460 |
426 void TearDown() override { | 461 void TearDown() override { |
427 ASSERT_TRUE(initialized_) << "You must call Initialize() in every test " | 462 ASSERT_TRUE(initialized_) << "You must call Initialize() in every test " |
428 << "case. Otherwise, your test will leak memory."; | 463 << "case. Otherwise, your test will leak memory."; |
429 StopServer(); | 464 StopServer(); |
430 } | 465 } |
431 | 466 |
432 void StartServer() { | 467 void StartServer() { |
| 468 FLAGS_quic_buffer_packet_till_chlo = GetParam().buffer_packet_till_chlo; |
| 469 FLAGS_quic_use_cheap_stateless_rejects = |
| 470 GetParam().use_cheap_stateless_reject; |
433 server_thread_.reset(new ServerThread( | 471 server_thread_.reset(new ServerThread( |
434 new QuicTestServer(CryptoTestUtils::ProofSourceForTesting(), | 472 new QuicTestServer(CryptoTestUtils::ProofSourceForTesting(), |
435 server_config_, server_supported_versions_), | 473 server_config_, server_supported_versions_), |
436 server_address_, strike_register_no_startup_period_)); | 474 server_address_, strike_register_no_startup_period_)); |
437 if (chlo_multiplier_ != 0) { | 475 if (chlo_multiplier_ != 0) { |
438 server_thread_->server()->SetChloMultiplier(chlo_multiplier_); | 476 server_thread_->server()->SetChloMultiplier(chlo_multiplier_); |
439 } | 477 } |
440 server_thread_->Initialize(); | 478 server_thread_->Initialize(); |
441 server_address_ = | 479 server_address_ = |
442 IPEndPoint(server_address_.address(), server_thread_->GetPort()); | 480 IPEndPoint(server_address_.address(), server_thread_->GetPort()); |
(...skipping 2337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2780 client_->client()->WaitForCryptoHandshakeConfirmed(); | 2818 client_->client()->WaitForCryptoHandshakeConfirmed(); |
2781 SetPacketLossPercentage(1); | 2819 SetPacketLossPercentage(1); |
2782 client_->SendRequest("/huge_response"); | 2820 client_->SendRequest("/huge_response"); |
2783 client_->WaitForResponse(); | 2821 client_->WaitForResponse(); |
2784 // TODO(fayang): Fix this test to work with stateless rejects. | 2822 // TODO(fayang): Fix this test to work with stateless rejects. |
2785 if (!BothSidesSupportStatelessRejects()) { | 2823 if (!BothSidesSupportStatelessRejects()) { |
2786 VerifyCleanConnection(true); | 2824 VerifyCleanConnection(true); |
2787 } | 2825 } |
2788 } | 2826 } |
2789 | 2827 |
| 2828 class EndToEndBufferedPacketsTest : public EndToEndTest { |
| 2829 public: |
| 2830 EndToEndBufferedPacketsTest() : EndToEndTest() { |
| 2831 FLAGS_quic_buffer_packet_till_chlo = true; |
| 2832 } |
| 2833 |
| 2834 void CreateClientWithWriter() override { |
| 2835 LOG(ERROR) << "create client with reorder_writer_ "; |
| 2836 reorder_writer_ = new PacketReorderingWriter(); |
| 2837 client_.reset(EndToEndTest::CreateQuicClient(reorder_writer_)); |
| 2838 } |
| 2839 |
| 2840 void SetUp() override { |
| 2841 // Don't initialize client writer in base class. |
| 2842 server_writer_ = new PacketDroppingTestWriter(); |
| 2843 } |
| 2844 |
| 2845 protected: |
| 2846 PacketReorderingWriter* reorder_writer_; |
| 2847 }; |
| 2848 |
| 2849 INSTANTIATE_TEST_CASE_P(EndToEndBufferedPacketsTests, |
| 2850 EndToEndBufferedPacketsTest, |
| 2851 testing::ValuesIn(GetTestParams())); |
| 2852 |
| 2853 TEST_P(EndToEndBufferedPacketsTest, Buffer0RttRequest) { |
| 2854 ASSERT_TRUE(Initialize()); |
| 2855 if (negotiated_version_ <= QUIC_VERSION_32) { |
| 2856 // Since no 0-rtt for v32 and under, and this test relies on 0-rtt, skip |
| 2857 // this test if QUIC doesn't do 0-rtt. |
| 2858 return; |
| 2859 } |
| 2860 // Finish one request to make sure handshake established. |
| 2861 client_->SendSynchronousRequest("/foo"); |
| 2862 // Disconnect for next 0-rtt request. |
| 2863 client_->Disconnect(); |
| 2864 |
| 2865 // Client get valid STK now. Do a 0-rtt request. |
| 2866 // Buffer a CHLO till another packets sent out. |
| 2867 reorder_writer_->SetDelay(1); |
| 2868 // Only send out a CHLO. |
| 2869 client_->client()->Initialize(); |
| 2870 client_->client()->StartConnect(); |
| 2871 ASSERT_TRUE(client_->client()->connected()); |
| 2872 // Send a request before handshake finishes. |
| 2873 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::GET, "/bar"); |
| 2874 client_->SendMessage(request); |
| 2875 client_->WaitForResponse(); |
| 2876 EXPECT_EQ(kBarResponseBody, client_->response_body()); |
| 2877 QuicConnectionStats client_stats = |
| 2878 client_->client()->session()->connection()->GetStats(); |
| 2879 EXPECT_EQ(0u, client_stats.packets_lost); |
| 2880 EXPECT_EQ(1, client_->client()->GetNumSentClientHellos()); |
| 2881 } |
| 2882 |
2790 } // namespace | 2883 } // namespace |
2791 } // namespace test | 2884 } // namespace test |
2792 } // namespace net | 2885 } // namespace net |
OLD | NEW |