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" |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 QuicStreamFrame frame3(kClientDataStreamId1, false, 2, StringPiece("TP")); | 182 QuicStreamFrame frame3(kClientDataStreamId1, false, 2, StringPiece("TP")); |
183 QuicStreamFrame frame4(kClientDataStreamId2, false, 2, StringPiece("TP")); | 183 QuicStreamFrame frame4(kClientDataStreamId2, false, 2, StringPiece("TP")); |
184 visitor_->OnStreamFrame(frame3); | 184 visitor_->OnStreamFrame(frame3); |
185 visitor_->OnStreamFrame(frame4); | 185 visitor_->OnStreamFrame(frame4); |
186 // The stream should never be opened, now that the reset is received. | 186 // The stream should never be opened, now that the reset is received. |
187 EXPECT_EQ(1u, session_->GetNumOpenStreams()); | 187 EXPECT_EQ(1u, session_->GetNumOpenStreams()); |
188 EXPECT_TRUE(connection_->connected()); | 188 EXPECT_TRUE(connection_->connected()); |
189 } | 189 } |
190 | 190 |
191 TEST_P(QuicServerSessionTest, MaxOpenStreams) { | 191 TEST_P(QuicServerSessionTest, MaxOpenStreams) { |
192 // Test that the server closes the connection if a client attempts to open too | 192 // Test that the server refuses if a client attempts to open too many data |
193 // many data streams. The server accepts slightly more than the negotiated | 193 // streams. The server accepts slightly more than the negotiated stream limit |
194 // stream limit to deal with rare cases where a client FIN/RST is lost. | 194 // to deal with rare cases where a client FIN/RST is lost. |
195 | 195 |
196 // The slightly increased stream limit is set during config negotiation. It | 196 // The slightly increased stream limit is set during config negotiation. It |
197 // is either an increase of 10 over negotiated limit, or a fixed percentage | 197 // is either an increase of 10 over negotiated limit, or a fixed percentage |
198 // scaling, whichever is larger. Test both before continuing. | 198 // scaling, whichever is larger. Test both before continuing. |
199 EXPECT_EQ(kMaxStreamsForTest, session_->get_max_open_streams()); | 199 EXPECT_EQ(kMaxStreamsForTest, session_->get_max_open_streams()); |
200 session_->OnConfigNegotiated(); | 200 session_->OnConfigNegotiated(); |
201 EXPECT_LT(kMaxStreamsMultiplier * kMaxStreamsForTest, | 201 EXPECT_LT(kMaxStreamsMultiplier * kMaxStreamsForTest, |
202 kMaxStreamsForTest + kMaxStreamsMinimumIncrement); | 202 kMaxStreamsForTest + kMaxStreamsMinimumIncrement); |
203 EXPECT_EQ(kMaxStreamsForTest + kMaxStreamsMinimumIncrement, | 203 EXPECT_EQ(kMaxStreamsForTest + kMaxStreamsMinimumIncrement, |
204 session_->get_max_open_streams()); | 204 session_->get_max_open_streams()); |
205 EXPECT_EQ(0u, session_->GetNumOpenStreams()); | 205 EXPECT_EQ(0u, session_->GetNumOpenStreams()); |
206 QuicStreamId stream_id = kClientDataStreamId1; | 206 QuicStreamId stream_id = kClientDataStreamId1; |
207 // Open the max configured number of streams, should be no problem. | 207 // Open the max configured number of streams, should be no problem. |
208 for (size_t i = 0; i < kMaxStreamsForTest; ++i) { | 208 for (size_t i = 0; i < kMaxStreamsForTest; ++i) { |
209 EXPECT_TRUE(QuicServerSessionPeer::GetIncomingDynamicStream(session_.get(), | 209 EXPECT_TRUE(QuicServerSessionPeer::GetIncomingDynamicStream(session_.get(), |
210 stream_id)); | 210 stream_id)); |
211 stream_id += 2; | 211 stream_id += 2; |
212 } | 212 } |
213 | 213 |
214 // Open more streams: server should accept slightly more than the limit. | 214 // Open more streams: server should accept slightly more than the limit. |
215 for (size_t i = 0; i < kMaxStreamsMinimumIncrement; ++i) { | 215 for (size_t i = 0; i < kMaxStreamsMinimumIncrement; ++i) { |
216 EXPECT_TRUE(QuicServerSessionPeer::GetIncomingDynamicStream(session_.get(), | 216 EXPECT_TRUE(QuicServerSessionPeer::GetIncomingDynamicStream(session_.get(), |
217 stream_id)); | 217 stream_id)); |
218 stream_id += 2; | 218 stream_id += 2; |
219 } | 219 } |
220 | 220 |
221 // Now violate the server's internal stream limit. | 221 // Now violate the server's internal stream limit. |
222 stream_id += 2; | 222 stream_id += 2; |
223 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_TOO_MANY_OPEN_STREAMS)); | 223 if (connection_->version() <= QUIC_VERSION_27) { |
224 EXPECT_CALL(*connection_, SendRstStream(_, _, _)).Times(0); | 224 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_TOO_MANY_OPEN_STREAMS)); |
| 225 EXPECT_CALL(*connection_, SendRstStream(_, _, _)).Times(0); |
| 226 } else { |
| 227 EXPECT_CALL(*connection_, SendConnectionClose(_)).Times(0); |
| 228 EXPECT_CALL(*connection_, SendRstStream(stream_id, QUIC_REFUSED_STREAM, 0)); |
| 229 } |
| 230 // Even if the connection remains open, the stream creation should fail. |
225 EXPECT_FALSE(QuicServerSessionPeer::GetIncomingDynamicStream(session_.get(), | 231 EXPECT_FALSE(QuicServerSessionPeer::GetIncomingDynamicStream(session_.get(), |
226 stream_id)); | 232 stream_id)); |
227 } | 233 } |
228 | 234 |
229 TEST_P(QuicServerSessionTest, MaxAvailableStreams) { | 235 TEST_P(QuicServerSessionTest, MaxAvailableStreams) { |
230 // Test that the server closes the connection if a client makes too many data | 236 // Test that the server closes the connection if a client makes too many data |
231 // streams available. The server accepts slightly more than the negotiated | 237 // streams available. The server accepts slightly more than the negotiated |
232 // stream limit to deal with rare cases where a client FIN/RST is lost. | 238 // stream limit to deal with rare cases where a client FIN/RST is lost. |
233 | 239 |
234 // The slightly increased stream limit is set during config negotiation. | 240 // The slightly increased stream limit is set during config negotiation. |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 QuicServerSessionPeer::IsBandwidthResumptionEnabled(session_.get())); | 485 QuicServerSessionPeer::IsBandwidthResumptionEnabled(session_.get())); |
480 session_->OnConfigNegotiated(); | 486 session_->OnConfigNegotiated(); |
481 EXPECT_FALSE( | 487 EXPECT_FALSE( |
482 QuicServerSessionPeer::IsBandwidthResumptionEnabled(session_.get())); | 488 QuicServerSessionPeer::IsBandwidthResumptionEnabled(session_.get())); |
483 } | 489 } |
484 | 490 |
485 } // namespace | 491 } // namespace |
486 } // namespace test | 492 } // namespace test |
487 } // namespace tools | 493 } // namespace tools |
488 } // namespace net | 494 } // namespace net |
OLD | NEW |