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 <cstdint> | 8 #include <cstdint> |
9 #include <list> | 9 #include <list> |
10 #include <memory> | 10 #include <memory> |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 // layout (for example to change HTTP/2 headers to SPDY/3). So | 146 // layout (for example to change HTTP/2 headers to SPDY/3). So |
147 // these tests need to ensure that clients are never attempting | 147 // these tests need to ensure that clients are never attempting |
148 // to do 0-RTT across incompatible versions. Chromium only supports | 148 // to do 0-RTT across incompatible versions. Chromium only supports |
149 // a single version at a time anyway. :) | 149 // a single version at a time anyway. :) |
150 QuicVersionVector all_supported_versions = AllSupportedVersions(); | 150 QuicVersionVector all_supported_versions = AllSupportedVersions(); |
151 // Even though this currently has one element, it may well get another | 151 // Even though this currently has one element, it may well get another |
152 // with future versions of QUIC, so don't remove it. | 152 // with future versions of QUIC, so don't remove it. |
153 QuicVersionVector version_buckets[1]; | 153 QuicVersionVector version_buckets[1]; |
154 | 154 |
155 for (const QuicVersion version : all_supported_versions) { | 155 for (const QuicVersion version : all_supported_versions) { |
156 // Versions: 34+ | 156 // Versions: 35+ |
157 // QUIC_VERSION_34 deprecates entropy and uses new ack and stop waiting | 157 // QUIC_VERSION_35 allows endpoints to independently set stream limit. |
158 // wire formats. | |
159 version_buckets[0].push_back(version); | 158 version_buckets[0].push_back(version); |
160 } | 159 } |
161 | 160 |
162 // This must be kept in sync with the number of nested for-loops below as it | 161 // This must be kept in sync with the number of nested for-loops below as it |
163 // is used to prune the number of tests that are run. | 162 // is used to prune the number of tests that are run. |
164 const int kMaxEnabledOptions = 7; | 163 const int kMaxEnabledOptions = 7; |
165 int max_enabled_options = 0; | 164 int max_enabled_options = 0; |
166 std::vector<TestParams> params; | 165 std::vector<TestParams> params; |
167 for (bool server_uses_stateless_rejects_if_peer_supported : {true, false}) { | 166 for (bool server_uses_stateless_rejects_if_peer_supported : {true, false}) { |
168 for (bool client_supports_stateless_rejects : {true, false}) { | 167 for (bool client_supports_stateless_rejects : {true, false}) { |
(...skipping 1103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1272 client_config_.SetIdleNetworkTimeout(QuicTime::Delta::FromMicroseconds(500), | 1271 client_config_.SetIdleNetworkTimeout(QuicTime::Delta::FromMicroseconds(500), |
1273 QuicTime::Delta::FromMicroseconds(500)); | 1272 QuicTime::Delta::FromMicroseconds(500)); |
1274 // Note: we do NOT ASSERT_TRUE: we may time out during initial handshake: | 1273 // Note: we do NOT ASSERT_TRUE: we may time out during initial handshake: |
1275 // that's enough to validate timeout in this case. | 1274 // that's enough to validate timeout in this case. |
1276 Initialize(); | 1275 Initialize(); |
1277 while (client_->client()->connected()) { | 1276 while (client_->client()->connected()) { |
1278 client_->client()->WaitForEvents(); | 1277 client_->client()->WaitForEvents(); |
1279 } | 1278 } |
1280 } | 1279 } |
1281 | 1280 |
1282 TEST_P(EndToEndTest, NegotiateMaxOpenStreams) { | |
1283 // Negotiate 1 max open stream. | |
1284 client_config_.SetMaxStreamsPerConnection(1, 1); | |
1285 ASSERT_TRUE(Initialize()); | |
1286 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); | |
1287 | |
1288 if (negotiated_version_ > QUIC_VERSION_34) { | |
1289 // Newer versions use max incoming dynamic streams. | |
1290 return; | |
1291 } | |
1292 | |
1293 // Make the client misbehave after negotiation. | |
1294 const int kServerMaxStreams = kMaxStreamsMinimumIncrement + 1; | |
1295 QuicSessionPeer::SetMaxOpenOutgoingStreams(client_->client()->session(), | |
1296 kServerMaxStreams + 1); | |
1297 | |
1298 SpdyHeaderBlock headers; | |
1299 headers[":method"] = "POST"; | |
1300 headers[":path"] = "/foo"; | |
1301 headers[":scheme"] = "https"; | |
1302 headers[":authority"] = server_hostname_; | |
1303 headers["content-length"] = "3"; | |
1304 | |
1305 // The server supports a small number of additional streams beyond the | |
1306 // negotiated limit. Open enough streams to go beyond that limit. | |
1307 for (int i = 0; i < kServerMaxStreams + 1; ++i) { | |
1308 client_->SendMessage(headers, "", /*fin=*/false); | |
1309 } | |
1310 client_->WaitForResponse(); | |
1311 | |
1312 EXPECT_TRUE(client_->connected()); | |
1313 EXPECT_EQ(QUIC_REFUSED_STREAM, client_->stream_error()); | |
1314 EXPECT_EQ(QUIC_NO_ERROR, client_->connection_error()); | |
1315 } | |
1316 | |
1317 TEST_P(EndToEndTest, MaxIncomingDynamicStreamsLimitRespected) { | 1281 TEST_P(EndToEndTest, MaxIncomingDynamicStreamsLimitRespected) { |
1318 // Set a limit on maximum number of incoming dynamic streams. | 1282 // Set a limit on maximum number of incoming dynamic streams. |
1319 // Make sure the limit is respected. | 1283 // Make sure the limit is respected. |
1320 const uint32_t kServerMaxIncomingDynamicStreams = 1; | 1284 const uint32_t kServerMaxIncomingDynamicStreams = 1; |
1321 server_config_.SetMaxIncomingDynamicStreamsToSend( | 1285 server_config_.SetMaxIncomingDynamicStreamsToSend( |
1322 kServerMaxIncomingDynamicStreams); | 1286 kServerMaxIncomingDynamicStreams); |
1323 ASSERT_TRUE(Initialize()); | 1287 ASSERT_TRUE(Initialize()); |
1324 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); | 1288 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
1325 | 1289 |
1326 if (negotiated_version_ <= QUIC_VERSION_34) { | |
1327 // Earlier versions negotiated max open streams. | |
1328 return; | |
1329 } | |
1330 | |
1331 // Make the client misbehave after negotiation. | 1290 // Make the client misbehave after negotiation. |
1332 const int kServerMaxStreams = | 1291 const int kServerMaxStreams = |
1333 kMaxStreamsMinimumIncrement + kServerMaxIncomingDynamicStreams; | 1292 kMaxStreamsMinimumIncrement + kServerMaxIncomingDynamicStreams; |
1334 QuicSessionPeer::SetMaxOpenOutgoingStreams(client_->client()->session(), | 1293 QuicSessionPeer::SetMaxOpenOutgoingStreams(client_->client()->session(), |
1335 kServerMaxStreams + 1); | 1294 kServerMaxStreams + 1); |
1336 | 1295 |
1337 SpdyHeaderBlock headers; | 1296 SpdyHeaderBlock headers; |
1338 headers[":method"] = "POST"; | 1297 headers[":method"] = "POST"; |
1339 headers[":path"] = "/foo"; | 1298 headers[":path"] = "/foo"; |
1340 headers[":scheme"] = "https"; | 1299 headers[":scheme"] = "https"; |
(...skipping 16 matching lines...) Expand all Loading... |
1357 // Each endpoint can set max incoming dynamic streams independently. | 1316 // Each endpoint can set max incoming dynamic streams independently. |
1358 const uint32_t kClientMaxIncomingDynamicStreams = 2; | 1317 const uint32_t kClientMaxIncomingDynamicStreams = 2; |
1359 const uint32_t kServerMaxIncomingDynamicStreams = 1; | 1318 const uint32_t kServerMaxIncomingDynamicStreams = 1; |
1360 client_config_.SetMaxIncomingDynamicStreamsToSend( | 1319 client_config_.SetMaxIncomingDynamicStreamsToSend( |
1361 kClientMaxIncomingDynamicStreams); | 1320 kClientMaxIncomingDynamicStreams); |
1362 server_config_.SetMaxIncomingDynamicStreamsToSend( | 1321 server_config_.SetMaxIncomingDynamicStreamsToSend( |
1363 kServerMaxIncomingDynamicStreams); | 1322 kServerMaxIncomingDynamicStreams); |
1364 ASSERT_TRUE(Initialize()); | 1323 ASSERT_TRUE(Initialize()); |
1365 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); | 1324 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
1366 | 1325 |
1367 if (negotiated_version_ <= QUIC_VERSION_34) { | |
1368 // Earlier versions negotiated max open streams. | |
1369 return; | |
1370 } | |
1371 | |
1372 // The client has received the server's limit and vice versa. | 1326 // The client has received the server's limit and vice versa. |
1373 EXPECT_EQ(kServerMaxIncomingDynamicStreams, | 1327 EXPECT_EQ(kServerMaxIncomingDynamicStreams, |
1374 client_->client()->session()->max_open_outgoing_streams()); | 1328 client_->client()->session()->max_open_outgoing_streams()); |
1375 server_thread_->Pause(); | 1329 server_thread_->Pause(); |
1376 QuicDispatcher* dispatcher = | 1330 QuicDispatcher* dispatcher = |
1377 QuicServerPeer::GetDispatcher(server_thread_->server()); | 1331 QuicServerPeer::GetDispatcher(server_thread_->server()); |
1378 QuicSession* server_session = dispatcher->session_map().begin()->second.get(); | 1332 QuicSession* server_session = dispatcher->session_map().begin()->second.get(); |
1379 EXPECT_EQ(kClientMaxIncomingDynamicStreams, | 1333 EXPECT_EQ(kClientMaxIncomingDynamicStreams, |
1380 server_session->max_open_outgoing_streams()); | 1334 server_session->max_open_outgoing_streams()); |
1381 server_thread_->Resume(); | 1335 server_thread_->Resume(); |
(...skipping 20 matching lines...) Expand all Loading... |
1402 } | 1356 } |
1403 | 1357 |
1404 server_thread_->Pause(); | 1358 server_thread_->Pause(); |
1405 EXPECT_EQ(expected_congestion_control_type, | 1359 EXPECT_EQ(expected_congestion_control_type, |
1406 QuicSentPacketManagerPeer::GetSendAlgorithm( | 1360 QuicSentPacketManagerPeer::GetSendAlgorithm( |
1407 *GetSentPacketManagerFromFirstServerSession()) | 1361 *GetSentPacketManagerFromFirstServerSession()) |
1408 ->GetCongestionControlType()); | 1362 ->GetCongestionControlType()); |
1409 server_thread_->Resume(); | 1363 server_thread_->Resume(); |
1410 } | 1364 } |
1411 | 1365 |
1412 TEST_P(EndToEndTest, LimitMaxOpenStreams) { | |
1413 // Server limits the number of max streams to 2. | |
1414 server_config_.SetMaxStreamsPerConnection(2, 2); | |
1415 // Client tries to negotiate for 10. | |
1416 client_config_.SetMaxStreamsPerConnection(10, 5); | |
1417 | |
1418 ASSERT_TRUE(Initialize()); | |
1419 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); | |
1420 if (negotiated_version_ > QUIC_VERSION_34) { | |
1421 // No negotiated max streams beyond version 34. | |
1422 return; | |
1423 } | |
1424 QuicConfig* client_negotiated_config = client_->client()->session()->config(); | |
1425 EXPECT_EQ(2u, client_negotiated_config->MaxStreamsPerConnection()); | |
1426 } | |
1427 | |
1428 TEST_P(EndToEndTest, ClientSuggestsRTT) { | 1366 TEST_P(EndToEndTest, ClientSuggestsRTT) { |
1429 // Client suggests initial RTT, verify it is used. | 1367 // Client suggests initial RTT, verify it is used. |
1430 const uint32_t kInitialRTT = 20000; | 1368 const uint32_t kInitialRTT = 20000; |
1431 client_config_.SetInitialRoundTripTimeUsToSend(kInitialRTT); | 1369 client_config_.SetInitialRoundTripTimeUsToSend(kInitialRTT); |
1432 | 1370 |
1433 ASSERT_TRUE(Initialize()); | 1371 ASSERT_TRUE(Initialize()); |
1434 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); | 1372 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
1435 server_thread_->WaitForCryptoHandshakeConfirmed(); | 1373 server_thread_->WaitForCryptoHandshakeConfirmed(); |
1436 | 1374 |
1437 // Pause the server so we can access the server's internals without races. | 1375 // Pause the server so we can access the server's internals without races. |
(...skipping 1692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3130 client_->WaitForResponse(); | 3068 client_->WaitForResponse(); |
3131 EXPECT_EQ(kBarResponseBody, client_->response_body()); | 3069 EXPECT_EQ(kBarResponseBody, client_->response_body()); |
3132 QuicConnectionStats client_stats = | 3070 QuicConnectionStats client_stats = |
3133 client_->client()->session()->connection()->GetStats(); | 3071 client_->client()->session()->connection()->GetStats(); |
3134 EXPECT_EQ(0u, client_stats.packets_lost); | 3072 EXPECT_EQ(0u, client_stats.packets_lost); |
3135 EXPECT_EQ(1, client_->client()->GetNumSentClientHellos()); | 3073 EXPECT_EQ(1, client_->client()->GetNumSentClientHellos()); |
3136 } | 3074 } |
3137 } // namespace | 3075 } // namespace |
3138 } // namespace test | 3076 } // namespace test |
3139 } // namespace net | 3077 } // namespace net |
OLD | NEW |