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 1163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1174 client_->client()->WaitForEvents(); | 1174 client_->client()->WaitForEvents(); |
1175 } | 1175 } |
1176 } | 1176 } |
1177 | 1177 |
1178 TEST_P(EndToEndTest, NegotiateMaxOpenStreams) { | 1178 TEST_P(EndToEndTest, NegotiateMaxOpenStreams) { |
1179 // Negotiate 1 max open stream. | 1179 // Negotiate 1 max open stream. |
1180 client_config_.SetMaxStreamsPerConnection(1, 1); | 1180 client_config_.SetMaxStreamsPerConnection(1, 1); |
1181 ASSERT_TRUE(Initialize()); | 1181 ASSERT_TRUE(Initialize()); |
1182 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1182 client_->client()->WaitForCryptoHandshakeConfirmed(); |
1183 | 1183 |
| 1184 if (negotiated_version_ > QUIC_VERSION_34) { |
| 1185 // Newer versions use max incoming dynamic streams. |
| 1186 return; |
| 1187 } |
| 1188 |
1184 // Make the client misbehave after negotiation. | 1189 // Make the client misbehave after negotiation. |
1185 const int kServerMaxStreams = kMaxStreamsMinimumIncrement + 1; | 1190 const int kServerMaxStreams = kMaxStreamsMinimumIncrement + 1; |
1186 QuicSessionPeer::SetMaxOpenOutgoingStreams(client_->client()->session(), | 1191 QuicSessionPeer::SetMaxOpenOutgoingStreams(client_->client()->session(), |
1187 kServerMaxStreams + 1); | 1192 kServerMaxStreams + 1); |
1188 | 1193 |
1189 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); | 1194 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); |
1190 request.AddHeader("content-length", "3"); | 1195 request.AddHeader("content-length", "3"); |
1191 request.set_has_complete_message(false); | 1196 request.set_has_complete_message(false); |
1192 | 1197 |
1193 // The server supports a small number of additional streams beyond the | 1198 // The server supports a small number of additional streams beyond the |
1194 // negotiated limit. Open enough streams to go beyond that limit. | 1199 // negotiated limit. Open enough streams to go beyond that limit. |
1195 for (int i = 0; i < kServerMaxStreams + 1; ++i) { | 1200 for (int i = 0; i < kServerMaxStreams + 1; ++i) { |
1196 client_->SendMessage(request); | 1201 client_->SendMessage(request); |
1197 } | 1202 } |
1198 client_->WaitForResponse(); | 1203 client_->WaitForResponse(); |
1199 | 1204 |
1200 if (negotiated_version_ <= QUIC_VERSION_27) { | 1205 if (negotiated_version_ <= QUIC_VERSION_27) { |
1201 EXPECT_FALSE(client_->connected()); | 1206 EXPECT_FALSE(client_->connected()); |
1202 EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR, client_->stream_error()); | 1207 EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR, client_->stream_error()); |
1203 EXPECT_EQ(QUIC_TOO_MANY_OPEN_STREAMS, client_->connection_error()); | 1208 EXPECT_EQ(QUIC_TOO_MANY_OPEN_STREAMS, client_->connection_error()); |
1204 } else { | 1209 } else { |
1205 EXPECT_TRUE(client_->connected()); | 1210 EXPECT_TRUE(client_->connected()); |
1206 EXPECT_EQ(QUIC_REFUSED_STREAM, client_->stream_error()); | 1211 EXPECT_EQ(QUIC_REFUSED_STREAM, client_->stream_error()); |
1207 EXPECT_EQ(QUIC_NO_ERROR, client_->connection_error()); | 1212 EXPECT_EQ(QUIC_NO_ERROR, client_->connection_error()); |
1208 } | 1213 } |
1209 } | 1214 } |
1210 | 1215 |
| 1216 TEST_P(EndToEndTest, MaxIncomingDynamicStreamsLimitRespected) { |
| 1217 // Set a limit on maximum number of incoming dynamic streams. |
| 1218 // Make sure the limit is respected. |
| 1219 const uint32_t kServerMaxIncomingDynamicStreams = 1; |
| 1220 server_config_.SetMaxIncomingDynamicStreamsToSend( |
| 1221 kServerMaxIncomingDynamicStreams); |
| 1222 ASSERT_TRUE(Initialize()); |
| 1223 client_->client()->WaitForCryptoHandshakeConfirmed(); |
| 1224 |
| 1225 if (negotiated_version_ <= QUIC_VERSION_34) { |
| 1226 // Earlier versions negotiated max open streams. |
| 1227 return; |
| 1228 } |
| 1229 |
| 1230 // Make the client misbehave after negotiation. |
| 1231 const int kServerMaxStreams = |
| 1232 kMaxStreamsMinimumIncrement + kServerMaxIncomingDynamicStreams; |
| 1233 QuicSessionPeer::SetMaxOpenOutgoingStreams(client_->client()->session(), |
| 1234 kServerMaxStreams + 1); |
| 1235 |
| 1236 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); |
| 1237 request.AddHeader("content-length", "3"); |
| 1238 request.set_has_complete_message(false); |
| 1239 |
| 1240 // The server supports a small number of additional streams beyond the |
| 1241 // negotiated limit. Open enough streams to go beyond that limit. |
| 1242 for (int i = 0; i < kServerMaxStreams + 1; ++i) { |
| 1243 client_->SendMessage(request); |
| 1244 } |
| 1245 client_->WaitForResponse(); |
| 1246 |
| 1247 EXPECT_TRUE(client_->connected()); |
| 1248 EXPECT_EQ(QUIC_REFUSED_STREAM, client_->stream_error()); |
| 1249 EXPECT_EQ(QUIC_NO_ERROR, client_->connection_error()); |
| 1250 } |
| 1251 |
| 1252 TEST_P(EndToEndTest, SetIndependentMaxIncomingDynamicStreamsLimits) { |
| 1253 // Each endpoint can set max incoming dynamic streams independently. |
| 1254 const uint32_t kClientMaxIncomingDynamicStreams = 2; |
| 1255 const uint32_t kServerMaxIncomingDynamicStreams = 1; |
| 1256 client_config_.SetMaxIncomingDynamicStreamsToSend( |
| 1257 kClientMaxIncomingDynamicStreams); |
| 1258 server_config_.SetMaxIncomingDynamicStreamsToSend( |
| 1259 kServerMaxIncomingDynamicStreams); |
| 1260 ASSERT_TRUE(Initialize()); |
| 1261 client_->client()->WaitForCryptoHandshakeConfirmed(); |
| 1262 |
| 1263 if (negotiated_version_ <= QUIC_VERSION_34) { |
| 1264 // Earlier versions negotiated max open streams. |
| 1265 return; |
| 1266 } |
| 1267 |
| 1268 // The client has received the server's limit and vice versa. |
| 1269 EXPECT_EQ(kServerMaxIncomingDynamicStreams, |
| 1270 client_->client()->session()->max_open_outgoing_streams()); |
| 1271 server_thread_->Pause(); |
| 1272 QuicDispatcher* dispatcher = |
| 1273 QuicServerPeer::GetDispatcher(server_thread_->server()); |
| 1274 QuicSession* server_session = dispatcher->session_map().begin()->second; |
| 1275 EXPECT_EQ(kClientMaxIncomingDynamicStreams, |
| 1276 server_session->max_open_outgoing_streams()); |
| 1277 server_thread_->Resume(); |
| 1278 } |
| 1279 |
1211 TEST_P(EndToEndTest, NegotiateCongestionControl) { | 1280 TEST_P(EndToEndTest, NegotiateCongestionControl) { |
1212 ValueRestore<bool> old_flag(&FLAGS_quic_allow_bbr, true); | 1281 ValueRestore<bool> old_flag(&FLAGS_quic_allow_bbr, true); |
1213 // Disable this flag because if connection uses multipath sent packet manager, | 1282 // Disable this flag because if connection uses multipath sent packet manager, |
1214 // static_cast here does not work. | 1283 // static_cast here does not work. |
1215 FLAGS_quic_enable_multipath = false; | 1284 FLAGS_quic_enable_multipath = false; |
1216 ASSERT_TRUE(Initialize()); | 1285 ASSERT_TRUE(Initialize()); |
1217 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1286 client_->client()->WaitForCryptoHandshakeConfirmed(); |
1218 | 1287 |
1219 CongestionControlType expected_congestion_control_type = kReno; | 1288 CongestionControlType expected_congestion_control_type = kReno; |
1220 switch (GetParam().congestion_control_tag) { | 1289 switch (GetParam().congestion_control_tag) { |
(...skipping 18 matching lines...) Expand all Loading... |
1239 } | 1308 } |
1240 | 1309 |
1241 TEST_P(EndToEndTest, LimitMaxOpenStreams) { | 1310 TEST_P(EndToEndTest, LimitMaxOpenStreams) { |
1242 // Server limits the number of max streams to 2. | 1311 // Server limits the number of max streams to 2. |
1243 server_config_.SetMaxStreamsPerConnection(2, 2); | 1312 server_config_.SetMaxStreamsPerConnection(2, 2); |
1244 // Client tries to negotiate for 10. | 1313 // Client tries to negotiate for 10. |
1245 client_config_.SetMaxStreamsPerConnection(10, 5); | 1314 client_config_.SetMaxStreamsPerConnection(10, 5); |
1246 | 1315 |
1247 ASSERT_TRUE(Initialize()); | 1316 ASSERT_TRUE(Initialize()); |
1248 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1317 client_->client()->WaitForCryptoHandshakeConfirmed(); |
| 1318 if (negotiated_version_ > QUIC_VERSION_34) { |
| 1319 // No negotiated max streams beyond version 34. |
| 1320 return; |
| 1321 } |
1249 QuicConfig* client_negotiated_config = client_->client()->session()->config(); | 1322 QuicConfig* client_negotiated_config = client_->client()->session()->config(); |
1250 EXPECT_EQ(2u, client_negotiated_config->MaxStreamsPerConnection()); | 1323 EXPECT_EQ(2u, client_negotiated_config->MaxStreamsPerConnection()); |
1251 } | 1324 } |
1252 | 1325 |
1253 TEST_P(EndToEndTest, ClientSuggestsRTT) { | 1326 TEST_P(EndToEndTest, ClientSuggestsRTT) { |
1254 // Client suggests initial RTT, verify it is used. | 1327 // Client suggests initial RTT, verify it is used. |
1255 const uint32_t kInitialRTT = 20000; | 1328 const uint32_t kInitialRTT = 20000; |
1256 client_config_.SetInitialRoundTripTimeUsToSend(kInitialRTT); | 1329 client_config_.SetInitialRoundTripTimeUsToSend(kInitialRTT); |
1257 | 1330 |
1258 ASSERT_TRUE(Initialize()); | 1331 ASSERT_TRUE(Initialize()); |
(...skipping 1123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2382 EXPECT_EQ(trailers, client_->response_trailers()); | 2455 EXPECT_EQ(trailers, client_->response_trailers()); |
2383 } | 2456 } |
2384 | 2457 |
2385 class EndToEndTestServerPush : public EndToEndTest { | 2458 class EndToEndTestServerPush : public EndToEndTest { |
2386 protected: | 2459 protected: |
2387 const size_t kNumMaxStreams = 10; | 2460 const size_t kNumMaxStreams = 10; |
2388 | 2461 |
2389 EndToEndTestServerPush() : EndToEndTest() { | 2462 EndToEndTestServerPush() : EndToEndTest() { |
2390 FLAGS_quic_supports_push_promise = true; | 2463 FLAGS_quic_supports_push_promise = true; |
2391 client_config_.SetMaxStreamsPerConnection(kNumMaxStreams, kNumMaxStreams); | 2464 client_config_.SetMaxStreamsPerConnection(kNumMaxStreams, kNumMaxStreams); |
| 2465 client_config_.SetMaxIncomingDynamicStreamsToSend(kNumMaxStreams); |
| 2466 server_config_.SetMaxStreamsPerConnection(kNumMaxStreams, kNumMaxStreams); |
| 2467 server_config_.SetMaxIncomingDynamicStreamsToSend(kNumMaxStreams); |
2392 support_server_push_ = true; | 2468 support_server_push_ = true; |
2393 } | 2469 } |
2394 | 2470 |
2395 // Add a request with its response and |num_resources| push resources into | 2471 // Add a request with its response and |num_resources| push resources into |
2396 // cache. | 2472 // cache. |
2397 // If |resource_size| == 0, response body of push resources use default string | 2473 // If |resource_size| == 0, response body of push resources use default string |
2398 // concatenating with resource url. Otherwise, generate a string of | 2474 // concatenating with resource url. Otherwise, generate a string of |
2399 // |resource_size| as body. | 2475 // |resource_size| as body. |
2400 void AddRequestAndResponseWithServerPush(string host, | 2476 void AddRequestAndResponseWithServerPush(string host, |
2401 string path, | 2477 string path, |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2739 client_->WaitForResponse(); | 2815 client_->WaitForResponse(); |
2740 // TODO(fayang): Fix this test to work with stateless rejects. | 2816 // TODO(fayang): Fix this test to work with stateless rejects. |
2741 if (!BothSidesSupportStatelessRejects()) { | 2817 if (!BothSidesSupportStatelessRejects()) { |
2742 VerifyCleanConnection(true); | 2818 VerifyCleanConnection(true); |
2743 } | 2819 } |
2744 } | 2820 } |
2745 | 2821 |
2746 } // namespace | 2822 } // namespace |
2747 } // namespace test | 2823 } // namespace test |
2748 } // namespace net | 2824 } // namespace net |
OLD | NEW |