| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "net/tools/quic/quic_server_session.h" | 5 #include "net/tools/quic/quic_server_session.h" |
| 6 | 6 |
| 7 #include "net/quic/crypto/quic_crypto_server_config.h" | 7 #include "net/quic/crypto/quic_crypto_server_config.h" |
| 8 #include "net/quic/crypto/quic_random.h" | 8 #include "net/quic/crypto/quic_random.h" |
| 9 #include "net/quic/proto/cached_network_parameters.pb.h" | 9 #include "net/quic/proto/cached_network_parameters.pb.h" |
| 10 #include "net/quic/quic_connection.h" | 10 #include "net/quic/quic_connection.h" |
| 11 #include "net/quic/quic_crypto_server_stream.h" | 11 #include "net/quic/quic_crypto_server_stream.h" |
| 12 #include "net/quic/quic_flags.h" | 12 #include "net/quic/quic_flags.h" |
| 13 #include "net/quic/quic_utils.h" | 13 #include "net/quic/quic_utils.h" |
| 14 #include "net/quic/test_tools/quic_config_peer.h" | 14 #include "net/quic/test_tools/quic_config_peer.h" |
| 15 #include "net/quic/test_tools/quic_connection_peer.h" | 15 #include "net/quic/test_tools/quic_connection_peer.h" |
| 16 #include "net/quic/test_tools/quic_data_stream_peer.h" | 16 #include "net/quic/test_tools/quic_data_stream_peer.h" |
| 17 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" | 17 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" |
| 18 #include "net/quic/test_tools/quic_session_peer.h" | 18 #include "net/quic/test_tools/quic_session_peer.h" |
| 19 #include "net/quic/test_tools/quic_spdy_session_peer.h" |
| 19 #include "net/quic/test_tools/quic_sustained_bandwidth_recorder_peer.h" | 20 #include "net/quic/test_tools/quic_sustained_bandwidth_recorder_peer.h" |
| 20 #include "net/quic/test_tools/quic_test_utils.h" | 21 #include "net/quic/test_tools/quic_test_utils.h" |
| 21 #include "net/test/gtest_util.h" | 22 #include "net/test/gtest_util.h" |
| 22 #include "net/tools/quic/quic_spdy_server_stream.h" | 23 #include "net/tools/quic/quic_spdy_server_stream.h" |
| 23 #include "net/tools/quic/test_tools/quic_test_utils.h" | 24 #include "net/tools/quic/test_tools/quic_test_utils.h" |
| 24 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 26 | 27 |
| 27 using __gnu_cxx::vector; | 28 using __gnu_cxx::vector; |
| 28 using net::test::MockConnection; | 29 using net::test::MockConnection; |
| 29 using net::test::QuicConfigPeer; | 30 using net::test::QuicConfigPeer; |
| 30 using net::test::QuicConnectionPeer; | 31 using net::test::QuicConnectionPeer; |
| 31 using net::test::QuicDataStreamPeer; | 32 using net::test::QuicDataStreamPeer; |
| 32 using net::test::QuicSentPacketManagerPeer; | 33 using net::test::QuicSentPacketManagerPeer; |
| 33 using net::test::QuicSessionPeer; | 34 using net::test::QuicSessionPeer; |
| 35 using net::test::QuicSpdySessionPeer; |
| 34 using net::test::QuicSustainedBandwidthRecorderPeer; | 36 using net::test::QuicSustainedBandwidthRecorderPeer; |
| 35 using net::test::SupportedVersions; | 37 using net::test::SupportedVersions; |
| 36 using net::test::ValueRestore; | 38 using net::test::ValueRestore; |
| 37 using net::test::kClientDataStreamId1; | 39 using net::test::kClientDataStreamId1; |
| 38 using net::test::kClientDataStreamId2; | 40 using net::test::kClientDataStreamId2; |
| 39 using net::test::kClientDataStreamId3; | 41 using net::test::kClientDataStreamId3; |
| 40 using std::string; | 42 using std::string; |
| 41 using testing::StrictMock; | 43 using testing::StrictMock; |
| 42 using testing::_; | 44 using testing::_; |
| 43 | 45 |
| 44 namespace net { | 46 namespace net { |
| 45 namespace tools { | 47 namespace tools { |
| 46 namespace test { | 48 namespace test { |
| 47 | 49 |
| 48 class QuicServerSessionPeer { | 50 class QuicServerSessionPeer { |
| 49 public: | 51 public: |
| 50 static QuicDataStream* GetIncomingDataStream( | 52 static ReliableQuicStream* GetIncomingDynamicStream(QuicServerSession* s, |
| 51 QuicServerSession* s, QuicStreamId id) { | 53 QuicStreamId id) { |
| 52 return s->GetIncomingDataStream(id); | 54 return s->GetIncomingDynamicStream(id); |
| 53 } | 55 } |
| 54 static void SetCryptoStream(QuicServerSession* s, | 56 static void SetCryptoStream(QuicServerSession* s, |
| 55 QuicCryptoServerStream* crypto_stream) { | 57 QuicCryptoServerStream* crypto_stream) { |
| 56 s->crypto_stream_.reset(crypto_stream); | 58 s->crypto_stream_.reset(crypto_stream); |
| 59 s->static_streams()[kCryptoStreamId] = crypto_stream; |
| 57 } | 60 } |
| 58 static bool IsBandwidthResumptionEnabled(QuicServerSession* s) { | 61 static bool IsBandwidthResumptionEnabled(QuicServerSession* s) { |
| 59 return s->bandwidth_resumption_enabled_; | 62 return s->bandwidth_resumption_enabled_; |
| 60 } | 63 } |
| 61 }; | 64 }; |
| 62 | 65 |
| 63 namespace { | 66 namespace { |
| 64 | 67 |
| 65 const size_t kMaxStreamsForTest = 10; | 68 const size_t kMaxStreamsForTest = 10; |
| 66 | 69 |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 EXPECT_EQ(kMaxStreamsForTest, session_->get_max_open_streams()); | 203 EXPECT_EQ(kMaxStreamsForTest, session_->get_max_open_streams()); |
| 201 session_->OnConfigNegotiated(); | 204 session_->OnConfigNegotiated(); |
| 202 EXPECT_LT(kMaxStreamsMultiplier * kMaxStreamsForTest, | 205 EXPECT_LT(kMaxStreamsMultiplier * kMaxStreamsForTest, |
| 203 kMaxStreamsForTest + kMaxStreamsMinimumIncrement); | 206 kMaxStreamsForTest + kMaxStreamsMinimumIncrement); |
| 204 EXPECT_EQ(kMaxStreamsForTest + kMaxStreamsMinimumIncrement, | 207 EXPECT_EQ(kMaxStreamsForTest + kMaxStreamsMinimumIncrement, |
| 205 session_->get_max_open_streams()); | 208 session_->get_max_open_streams()); |
| 206 EXPECT_EQ(0u, session_->GetNumOpenStreams()); | 209 EXPECT_EQ(0u, session_->GetNumOpenStreams()); |
| 207 QuicStreamId stream_id = kClientDataStreamId1; | 210 QuicStreamId stream_id = kClientDataStreamId1; |
| 208 // Open the max configured number of streams, should be no problem. | 211 // Open the max configured number of streams, should be no problem. |
| 209 for (size_t i = 0; i < kMaxStreamsForTest; ++i) { | 212 for (size_t i = 0; i < kMaxStreamsForTest; ++i) { |
| 210 EXPECT_TRUE(QuicServerSessionPeer::GetIncomingDataStream(session_.get(), | 213 EXPECT_TRUE(QuicServerSessionPeer::GetIncomingDynamicStream(session_.get(), |
| 211 stream_id)); | 214 stream_id)); |
| 212 stream_id += 2; | 215 stream_id += 2; |
| 213 } | 216 } |
| 214 | 217 |
| 215 // Open more streams: server should accept slightly more than the limit. | 218 // Open more streams: server should accept slightly more than the limit. |
| 216 for (size_t i = 0; i < kMaxStreamsMinimumIncrement; ++i) { | 219 for (size_t i = 0; i < kMaxStreamsMinimumIncrement; ++i) { |
| 217 EXPECT_TRUE(QuicServerSessionPeer::GetIncomingDataStream(session_.get(), | 220 EXPECT_TRUE(QuicServerSessionPeer::GetIncomingDynamicStream(session_.get(), |
| 218 stream_id)); | 221 stream_id)); |
| 219 stream_id += 2; | 222 stream_id += 2; |
| 220 } | 223 } |
| 221 | 224 |
| 222 // Now violate the server's internal stream limit. | 225 // Now violate the server's internal stream limit. |
| 223 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_TOO_MANY_OPEN_STREAMS)); | 226 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_TOO_MANY_OPEN_STREAMS)); |
| 224 stream_id += 2; | 227 stream_id += 2; |
| 225 EXPECT_FALSE( | 228 EXPECT_FALSE(QuicServerSessionPeer::GetIncomingDynamicStream(session_.get(), |
| 226 QuicServerSessionPeer::GetIncomingDataStream(session_.get(), stream_id)); | 229 stream_id)); |
| 227 } | 230 } |
| 228 | 231 |
| 229 TEST_P(QuicServerSessionTest, MaxOpenStreamsImplicit) { | 232 TEST_P(QuicServerSessionTest, MaxOpenStreamsImplicit) { |
| 230 // Test that the server closes the connection if a client attempts to open too | 233 // Test that the server closes the connection if a client attempts to open too |
| 231 // many data streams implicitly. The server accepts slightly more than the | 234 // many data streams implicitly. The server accepts slightly more than the |
| 232 // negotiated stream limit to deal with rare cases where a client FIN/RST is | 235 // negotiated stream limit to deal with rare cases where a client FIN/RST is |
| 233 // lost. | 236 // lost. |
| 234 | 237 |
| 235 // The slightly increased stream limit is set during config negotiation. | 238 // The slightly increased stream limit is set during config negotiation. |
| 236 EXPECT_EQ(kMaxStreamsForTest, session_->get_max_open_streams()); | 239 EXPECT_EQ(kMaxStreamsForTest, session_->get_max_open_streams()); |
| 237 session_->OnConfigNegotiated(); | 240 session_->OnConfigNegotiated(); |
| 238 EXPECT_LT(kMaxStreamsMultiplier * kMaxStreamsForTest, | 241 EXPECT_LT(kMaxStreamsMultiplier * kMaxStreamsForTest, |
| 239 kMaxStreamsForTest + kMaxStreamsMinimumIncrement); | 242 kMaxStreamsForTest + kMaxStreamsMinimumIncrement); |
| 240 EXPECT_EQ(kMaxStreamsForTest + kMaxStreamsMinimumIncrement, | 243 EXPECT_EQ(kMaxStreamsForTest + kMaxStreamsMinimumIncrement, |
| 241 session_->get_max_open_streams()); | 244 session_->get_max_open_streams()); |
| 242 | 245 |
| 243 EXPECT_EQ(0u, session_->GetNumOpenStreams()); | 246 EXPECT_EQ(0u, session_->GetNumOpenStreams()); |
| 244 EXPECT_TRUE(QuicServerSessionPeer::GetIncomingDataStream( | 247 EXPECT_TRUE(QuicServerSessionPeer::GetIncomingDynamicStream( |
| 245 session_.get(), kClientDataStreamId1)); | 248 session_.get(), kClientDataStreamId1)); |
| 246 // Implicitly open streams up to the server's limit. | 249 // Implicitly open streams up to the server's limit. |
| 247 const int kActualMaxStreams = | 250 const int kActualMaxStreams = |
| 248 kMaxStreamsForTest + kMaxStreamsMinimumIncrement; | 251 kMaxStreamsForTest + kMaxStreamsMinimumIncrement; |
| 249 const int kMaxValidStreamId = | 252 const int kMaxValidStreamId = |
| 250 kClientDataStreamId1 + (kActualMaxStreams - 1) * 2; | 253 kClientDataStreamId1 + (kActualMaxStreams - 1) * 2; |
| 251 EXPECT_TRUE(QuicServerSessionPeer::GetIncomingDataStream( | 254 EXPECT_TRUE(QuicServerSessionPeer::GetIncomingDynamicStream( |
| 252 session_.get(), kMaxValidStreamId)); | 255 session_.get(), kMaxValidStreamId)); |
| 253 | 256 |
| 254 // Opening a further stream will result in connection close. | 257 // Opening a further stream will result in connection close. |
| 255 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_TOO_MANY_OPEN_STREAMS)); | 258 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_TOO_MANY_OPEN_STREAMS)); |
| 256 EXPECT_FALSE(QuicServerSessionPeer::GetIncomingDataStream( | 259 EXPECT_FALSE(QuicServerSessionPeer::GetIncomingDynamicStream( |
| 257 session_.get(), kMaxValidStreamId + 2)); | 260 session_.get(), kMaxValidStreamId + 2)); |
| 258 } | 261 } |
| 259 | 262 |
| 260 TEST_P(QuicServerSessionTest, GetEvenIncomingError) { | 263 TEST_P(QuicServerSessionTest, GetEvenIncomingError) { |
| 261 // Incoming streams on the server session must be odd. | 264 // Incoming streams on the server session must be odd. |
| 262 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_INVALID_STREAM_ID)); | 265 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_INVALID_STREAM_ID)); |
| 263 EXPECT_EQ(nullptr, | 266 EXPECT_EQ(nullptr, |
| 264 QuicServerSessionPeer::GetIncomingDataStream(session_.get(), 4)); | 267 QuicServerSessionPeer::GetIncomingDynamicStream(session_.get(), 4)); |
| 265 } | 268 } |
| 266 | 269 |
| 267 TEST_P(QuicServerSessionTest, GetStreamDisconnected) { | 270 TEST_P(QuicServerSessionTest, GetStreamDisconnected) { |
| 268 // Don't create new streams if the connection is disconnected. | 271 // Don't create new streams if the connection is disconnected. |
| 269 QuicConnectionPeer::CloseConnection(connection_); | 272 QuicConnectionPeer::CloseConnection(connection_); |
| 270 EXPECT_DFATAL(QuicServerSessionPeer::GetIncomingDataStream(session_.get(), 5), | 273 EXPECT_DFATAL( |
| 271 "ShouldCreateIncomingDataStream called when disconnected"); | 274 QuicServerSessionPeer::GetIncomingDynamicStream(session_.get(), 5), |
| 275 "ShouldCreateIncomingDynamicStream called when disconnected"); |
| 272 } | 276 } |
| 273 | 277 |
| 274 TEST_P(QuicServerSessionTest, SetFecProtectionFromConfig) { | 278 TEST_P(QuicServerSessionTest, SetFecProtectionFromConfig) { |
| 275 ValueRestore<bool> old_flag(&FLAGS_enable_quic_fec, true); | 279 ValueRestore<bool> old_flag(&FLAGS_enable_quic_fec, true); |
| 276 | 280 |
| 277 // Set received config to have FEC connection option. | 281 // Set received config to have FEC connection option. |
| 278 QuicTagVector copt; | 282 QuicTagVector copt; |
| 279 copt.push_back(kFHDR); | 283 copt.push_back(kFHDR); |
| 280 QuicConfigPeer::SetReceivedConnectionOptions(session_->config(), copt); | 284 QuicConfigPeer::SetReceivedConnectionOptions(session_->config(), copt); |
| 281 session_->OnConfigNegotiated(); | 285 session_->OnConfigNegotiated(); |
| 282 | 286 |
| 283 // Verify that headers stream is always protected and data streams are | 287 // Verify that headers stream is always protected and data streams are |
| 284 // optionally protected. | 288 // optionally protected. |
| 285 EXPECT_EQ(FEC_PROTECT_ALWAYS, | 289 EXPECT_EQ(FEC_PROTECT_ALWAYS, QuicSpdySessionPeer::GetHeadersStream( |
| 286 QuicSessionPeer::GetHeadersStream(session_.get())->fec_policy()); | 290 session_.get())->fec_policy()); |
| 287 QuicDataStream* stream = QuicServerSessionPeer::GetIncomingDataStream( | 291 ReliableQuicStream* stream = QuicServerSessionPeer::GetIncomingDynamicStream( |
| 288 session_.get(), kClientDataStreamId1); | 292 session_.get(), kClientDataStreamId1); |
| 289 ASSERT_TRUE(stream); | 293 ASSERT_TRUE(stream); |
| 290 EXPECT_EQ(FEC_PROTECT_OPTIONAL, stream->fec_policy()); | 294 EXPECT_EQ(FEC_PROTECT_OPTIONAL, stream->fec_policy()); |
| 291 } | 295 } |
| 292 | 296 |
| 293 class MockQuicCryptoServerStream : public QuicCryptoServerStream { | 297 class MockQuicCryptoServerStream : public QuicCryptoServerStream { |
| 294 public: | 298 public: |
| 295 explicit MockQuicCryptoServerStream( | 299 explicit MockQuicCryptoServerStream( |
| 296 const QuicCryptoServerConfig* crypto_config, QuicSession* session) | 300 const QuicCryptoServerConfig* crypto_config, QuicSession* session) |
| 297 : QuicCryptoServerStream(crypto_config, session) {} | 301 : QuicCryptoServerStream(crypto_config, session) {} |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 QuicServerSessionPeer::IsBandwidthResumptionEnabled(session_.get())); | 461 QuicServerSessionPeer::IsBandwidthResumptionEnabled(session_.get())); |
| 458 session_->OnConfigNegotiated(); | 462 session_->OnConfigNegotiated(); |
| 459 EXPECT_FALSE( | 463 EXPECT_FALSE( |
| 460 QuicServerSessionPeer::IsBandwidthResumptionEnabled(session_.get())); | 464 QuicServerSessionPeer::IsBandwidthResumptionEnabled(session_.get())); |
| 461 } | 465 } |
| 462 | 466 |
| 463 } // namespace | 467 } // namespace |
| 464 } // namespace test | 468 } // namespace test |
| 465 } // namespace tools | 469 } // namespace tools |
| 466 } // namespace net | 470 } // namespace net |
| OLD | NEW |