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 "net/quic/quic_session.h" | 5 #include "net/quic/quic_session.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 | 145 |
146 bool IsClosedStream(QuicStreamId id) { | 146 bool IsClosedStream(QuicStreamId id) { |
147 return QuicSession::IsClosedStream(id); | 147 return QuicSession::IsClosedStream(id); |
148 } | 148 } |
149 | 149 |
150 ReliableQuicStream* GetOrCreateDynamicStream(QuicStreamId stream_id) { | 150 ReliableQuicStream* GetOrCreateDynamicStream(QuicStreamId stream_id) { |
151 return QuicSpdySession::GetOrCreateDynamicStream(stream_id); | 151 return QuicSpdySession::GetOrCreateDynamicStream(stream_id); |
152 } | 152 } |
153 | 153 |
154 QuicConsumedData WritevData( | 154 QuicConsumedData WritevData( |
| 155 ReliableQuicStream* stream, |
155 QuicStreamId id, | 156 QuicStreamId id, |
156 QuicIOVector data, | 157 QuicIOVector data, |
157 QuicStreamOffset offset, | 158 QuicStreamOffset offset, |
158 bool fin, | 159 bool fin, |
159 QuicAckListenerInterface* ack_notifier_delegate) override { | 160 QuicAckListenerInterface* ack_notifier_delegate) override { |
160 QuicConsumedData consumed(data.total_length, fin); | 161 QuicConsumedData consumed(data.total_length, fin); |
161 if (!writev_consumes_all_data_) { | 162 if (!writev_consumes_all_data_) { |
162 consumed = | 163 consumed = QuicSession::WritevData(stream, id, data, offset, fin, |
163 QuicSession::WritevData(id, data, offset, fin, ack_notifier_delegate); | 164 ack_notifier_delegate); |
164 } | 165 } |
165 QuicSessionPeer::GetWriteBlockedStreams(this)->UpdateBytesForStream( | 166 QuicSessionPeer::GetWriteBlockedStreams(this)->UpdateBytesForStream( |
166 id, consumed.bytes_consumed); | 167 id, consumed.bytes_consumed); |
167 return consumed; | 168 return consumed; |
168 } | 169 } |
169 | 170 |
170 void set_writev_consumes_all_data(bool val) { | 171 void set_writev_consumes_all_data(bool val) { |
171 writev_consumes_all_data_ = val; | 172 writev_consumes_all_data_ = val; |
172 } | 173 } |
173 | 174 |
174 QuicConsumedData SendStreamData(QuicStreamId id) { | 175 QuicConsumedData SendStreamData(ReliableQuicStream* stream) { |
175 struct iovec iov; | 176 struct iovec iov; |
176 return WritevData(id, MakeIOVector("not empty", &iov), 0, true, nullptr); | 177 return WritevData(stream, stream->id(), MakeIOVector("not empty", &iov), 0, |
| 178 true, nullptr); |
177 } | 179 } |
178 | 180 |
179 QuicConsumedData SendLargeFakeData(QuicStreamId id, int bytes) { | 181 QuicConsumedData SendLargeFakeData(ReliableQuicStream* stream, int bytes) { |
180 DCHECK(writev_consumes_all_data_); | 182 DCHECK(writev_consumes_all_data_); |
181 struct iovec iov; | 183 struct iovec iov; |
182 iov.iov_base = nullptr; // should not be read. | 184 iov.iov_base = nullptr; // should not be read. |
183 iov.iov_len = static_cast<size_t>(bytes); | 185 iov.iov_len = static_cast<size_t>(bytes); |
184 return WritevData(id, QuicIOVector(&iov, 1, bytes), 0, true, nullptr); | 186 return WritevData(stream, stream->id(), QuicIOVector(&iov, 1, bytes), 0, |
| 187 true, nullptr); |
185 } | 188 } |
186 | 189 |
187 using QuicSession::PostProcessAfterData; | 190 using QuicSession::PostProcessAfterData; |
188 | 191 |
189 private: | 192 private: |
190 StrictMock<TestCryptoStream> crypto_stream_; | 193 StrictMock<TestCryptoStream> crypto_stream_; |
191 | 194 |
192 bool writev_consumes_all_data_; | 195 bool writev_consumes_all_data_; |
193 }; | 196 }; |
194 | 197 |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 StreamBlocker stream2_blocker(&session_, stream2->id()); | 415 StreamBlocker stream2_blocker(&session_, stream2->id()); |
413 StreamBlocker stream4_blocker(&session_, stream4->id()); | 416 StreamBlocker stream4_blocker(&session_, stream4->id()); |
414 StreamBlocker stream6_blocker(&session_, stream6->id()); | 417 StreamBlocker stream6_blocker(&session_, stream6->id()); |
415 // With two sessions blocked, we should get two write calls. They should both | 418 // With two sessions blocked, we should get two write calls. They should both |
416 // go to the first stream as it will only write 6k and mark itself blocked | 419 // go to the first stream as it will only write 6k and mark itself blocked |
417 // again. | 420 // again. |
418 InSequence s; | 421 InSequence s; |
419 EXPECT_CALL(*stream2, OnCanWrite()) | 422 EXPECT_CALL(*stream2, OnCanWrite()) |
420 .WillOnce(DoAll(testing::IgnoreResult(Invoke(CreateFunctor( | 423 .WillOnce(DoAll(testing::IgnoreResult(Invoke(CreateFunctor( |
421 &TestSession::SendLargeFakeData, | 424 &TestSession::SendLargeFakeData, |
422 base::Unretained(&session_), | 425 base::Unretained(&session_), stream2, 6000))), |
423 stream2->id(), 6000))), | |
424 Invoke(&stream2_blocker, | 426 Invoke(&stream2_blocker, |
425 &StreamBlocker::MarkConnectionLevelWriteBlocked))); | 427 &StreamBlocker::MarkConnectionLevelWriteBlocked))); |
426 EXPECT_CALL(*stream2, OnCanWrite()) | 428 EXPECT_CALL(*stream2, OnCanWrite()) |
427 .WillOnce(DoAll(testing::IgnoreResult(Invoke(CreateFunctor( | 429 .WillOnce(DoAll(testing::IgnoreResult(Invoke(CreateFunctor( |
428 &TestSession::SendLargeFakeData, | 430 &TestSession::SendLargeFakeData, |
429 base::Unretained(&session_), | 431 base::Unretained(&session_), stream2, 6000))), |
430 stream2->id(), 6000))), | |
431 Invoke(&stream2_blocker, | 432 Invoke(&stream2_blocker, |
432 &StreamBlocker::MarkConnectionLevelWriteBlocked))); | 433 &StreamBlocker::MarkConnectionLevelWriteBlocked))); |
433 session_.OnCanWrite(); | 434 session_.OnCanWrite(); |
434 | 435 |
435 // We should get one more call for stream2, at which point it has used its | 436 // We should get one more call for stream2, at which point it has used its |
436 // write quota and we move over to stream 4. | 437 // write quota and we move over to stream 4. |
437 EXPECT_CALL(*stream2, OnCanWrite()) | 438 EXPECT_CALL(*stream2, OnCanWrite()) |
438 .WillOnce(DoAll(testing::IgnoreResult(Invoke(CreateFunctor( | 439 .WillOnce(DoAll(testing::IgnoreResult(Invoke(CreateFunctor( |
439 &TestSession::SendLargeFakeData, | 440 &TestSession::SendLargeFakeData, |
440 base::Unretained(&session_), | 441 base::Unretained(&session_), stream2, 6000))), |
441 stream2->id(), 6000))), | |
442 Invoke(&stream2_blocker, | 442 Invoke(&stream2_blocker, |
443 &StreamBlocker::MarkConnectionLevelWriteBlocked))); | 443 &StreamBlocker::MarkConnectionLevelWriteBlocked))); |
444 EXPECT_CALL(*stream4, OnCanWrite()) | 444 EXPECT_CALL(*stream4, OnCanWrite()) |
445 .WillOnce(DoAll(testing::IgnoreResult(Invoke(CreateFunctor( | 445 .WillOnce(DoAll(testing::IgnoreResult(Invoke(CreateFunctor( |
446 &TestSession::SendLargeFakeData, | 446 &TestSession::SendLargeFakeData, |
447 base::Unretained(&session_), | 447 base::Unretained(&session_), stream4, 6000))), |
448 stream4->id(), 6000))), | |
449 Invoke(&stream4_blocker, | 448 Invoke(&stream4_blocker, |
450 &StreamBlocker::MarkConnectionLevelWriteBlocked))); | 449 &StreamBlocker::MarkConnectionLevelWriteBlocked))); |
451 session_.OnCanWrite(); | 450 session_.OnCanWrite(); |
452 | 451 |
453 // Now let stream 4 do the 2nd of its 3 writes, but add a block for a high | 452 // Now let stream 4 do the 2nd of its 3 writes, but add a block for a high |
454 // priority stream 6. 4 should be preempted. 6 will write but *not* block so | 453 // priority stream 6. 4 should be preempted. 6 will write but *not* block so |
455 // will cede back to 4. | 454 // will cede back to 4. |
456 stream6->SetPriority(kHighestPriority); | 455 stream6->SetPriority(kHighestPriority); |
457 EXPECT_CALL(*stream4, OnCanWrite()) | 456 EXPECT_CALL(*stream4, OnCanWrite()) |
458 .WillOnce(DoAll(testing::IgnoreResult(Invoke(CreateFunctor( | 457 .WillOnce(DoAll(testing::IgnoreResult(Invoke(CreateFunctor( |
459 &TestSession::SendLargeFakeData, | 458 &TestSession::SendLargeFakeData, |
460 base::Unretained(&session_), stream4->id(), 6000))), | 459 base::Unretained(&session_), stream4, 6000))), |
461 Invoke(&stream4_blocker, | 460 Invoke(&stream4_blocker, |
462 &StreamBlocker::MarkConnectionLevelWriteBlocked), | 461 &StreamBlocker::MarkConnectionLevelWriteBlocked), |
463 Invoke(&stream6_blocker, | 462 Invoke(&stream6_blocker, |
464 &StreamBlocker::MarkConnectionLevelWriteBlocked))); | 463 &StreamBlocker::MarkConnectionLevelWriteBlocked))); |
465 EXPECT_CALL(*stream6, OnCanWrite()) | 464 EXPECT_CALL(*stream6, OnCanWrite()) |
466 .WillOnce(testing::IgnoreResult(Invoke(CreateFunctor( | 465 .WillOnce(testing::IgnoreResult( |
467 &TestSession::SendLargeFakeData, | 466 Invoke(CreateFunctor(&TestSession::SendLargeFakeData, |
468 base::Unretained(&session_), stream4->id(), 6000)))); | 467 base::Unretained(&session_), stream4, 6000)))); |
469 session_.OnCanWrite(); | 468 session_.OnCanWrite(); |
470 | 469 |
471 // Stream4 alread did 6k worth of writes, so after doing another 12k it should | 470 // Stream4 alread did 6k worth of writes, so after doing another 12k it should |
472 // cede and 2 should resume. | 471 // cede and 2 should resume. |
473 EXPECT_CALL(*stream4, OnCanWrite()) | 472 EXPECT_CALL(*stream4, OnCanWrite()) |
474 .WillOnce(DoAll(testing::IgnoreResult(Invoke(CreateFunctor( | 473 .WillOnce(DoAll(testing::IgnoreResult(Invoke(CreateFunctor( |
475 &TestSession::SendLargeFakeData, | 474 &TestSession::SendLargeFakeData, |
476 base::Unretained(&session_), | 475 base::Unretained(&session_), stream4, 12000))), |
477 stream4->id(), 12000))), | |
478 Invoke(&stream4_blocker, | 476 Invoke(&stream4_blocker, |
479 &StreamBlocker::MarkConnectionLevelWriteBlocked))); | 477 &StreamBlocker::MarkConnectionLevelWriteBlocked))); |
480 EXPECT_CALL(*stream2, OnCanWrite()) | 478 EXPECT_CALL(*stream2, OnCanWrite()) |
481 .WillOnce(DoAll(testing::IgnoreResult(Invoke(CreateFunctor( | 479 .WillOnce(DoAll(testing::IgnoreResult(Invoke(CreateFunctor( |
482 &TestSession::SendLargeFakeData, | 480 &TestSession::SendLargeFakeData, |
483 base::Unretained(&session_), | 481 base::Unretained(&session_), stream2, 6000))), |
484 stream2->id(), 6000))), | |
485 Invoke(&stream2_blocker, | 482 Invoke(&stream2_blocker, |
486 &StreamBlocker::MarkConnectionLevelWriteBlocked))); | 483 &StreamBlocker::MarkConnectionLevelWriteBlocked))); |
487 session_.OnCanWrite(); | 484 session_.OnCanWrite(); |
488 } | 485 } |
489 | 486 |
490 TEST_P(QuicSessionTestServer, OnCanWriteBundlesStreams) { | 487 TEST_P(QuicSessionTestServer, OnCanWriteBundlesStreams) { |
491 // Encryption needs to be established before data can be sent. | 488 // Encryption needs to be established before data can be sent. |
492 CryptoHandshakeMessage msg; | 489 CryptoHandshakeMessage msg; |
493 session_.GetCryptoStream()->OnHandshakeMessage(msg); | 490 session_.GetCryptoStream()->OnHandshakeMessage(msg); |
494 | 491 |
495 // Drive congestion control manually. | 492 // Drive congestion control manually. |
496 MockSendAlgorithm* send_algorithm = new StrictMock<MockSendAlgorithm>; | 493 MockSendAlgorithm* send_algorithm = new StrictMock<MockSendAlgorithm>; |
497 QuicConnectionPeer::SetSendAlgorithm(session_.connection(), send_algorithm); | 494 QuicConnectionPeer::SetSendAlgorithm(session_.connection(), send_algorithm); |
498 | 495 |
499 TestStream* stream2 = session_.CreateOutgoingDynamicStream(kDefaultPriority); | 496 TestStream* stream2 = session_.CreateOutgoingDynamicStream(kDefaultPriority); |
500 TestStream* stream4 = session_.CreateOutgoingDynamicStream(kDefaultPriority); | 497 TestStream* stream4 = session_.CreateOutgoingDynamicStream(kDefaultPriority); |
501 TestStream* stream6 = session_.CreateOutgoingDynamicStream(kDefaultPriority); | 498 TestStream* stream6 = session_.CreateOutgoingDynamicStream(kDefaultPriority); |
502 | 499 |
503 session_.MarkConnectionLevelWriteBlocked(stream2->id()); | 500 session_.MarkConnectionLevelWriteBlocked(stream2->id()); |
504 session_.MarkConnectionLevelWriteBlocked(stream6->id()); | 501 session_.MarkConnectionLevelWriteBlocked(stream6->id()); |
505 session_.MarkConnectionLevelWriteBlocked(stream4->id()); | 502 session_.MarkConnectionLevelWriteBlocked(stream4->id()); |
506 | 503 |
507 EXPECT_CALL(*send_algorithm, TimeUntilSend(_, _)) | 504 EXPECT_CALL(*send_algorithm, TimeUntilSend(_, _)) |
508 .WillRepeatedly(Return(QuicTime::Delta::Zero())); | 505 .WillRepeatedly(Return(QuicTime::Delta::Zero())); |
509 EXPECT_CALL(*send_algorithm, GetCongestionWindow()) | 506 EXPECT_CALL(*send_algorithm, GetCongestionWindow()) |
510 .WillRepeatedly(Return(kMaxPacketSize * 10)); | 507 .WillRepeatedly(Return(kMaxPacketSize * 10)); |
511 EXPECT_CALL(*stream2, OnCanWrite()) | 508 EXPECT_CALL(*stream2, OnCanWrite()) |
512 .WillOnce(testing::IgnoreResult(Invoke(CreateFunctor( | 509 .WillOnce(testing::IgnoreResult( |
513 &TestSession::SendStreamData, | 510 Invoke(CreateFunctor(&TestSession::SendStreamData, |
514 base::Unretained(&session_), stream2->id())))); | 511 base::Unretained(&session_), stream2)))); |
515 EXPECT_CALL(*stream4, OnCanWrite()) | 512 EXPECT_CALL(*stream4, OnCanWrite()) |
516 .WillOnce(testing::IgnoreResult(Invoke(CreateFunctor( | 513 .WillOnce(testing::IgnoreResult( |
517 &TestSession::SendStreamData, | 514 Invoke(CreateFunctor(&TestSession::SendStreamData, |
518 base::Unretained(&session_), | 515 base::Unretained(&session_), stream4)))); |
519 stream4->id())))); | |
520 EXPECT_CALL(*stream6, OnCanWrite()) | 516 EXPECT_CALL(*stream6, OnCanWrite()) |
521 .WillOnce(testing::IgnoreResult(Invoke(CreateFunctor( | 517 .WillOnce(testing::IgnoreResult( |
522 &TestSession::SendStreamData, | 518 Invoke(CreateFunctor(&TestSession::SendStreamData, |
523 base::Unretained(&session_), | 519 base::Unretained(&session_), stream6)))); |
524 stream6->id())))); | |
525 | 520 |
526 // Expect that we only send one packet, the writes from different streams | 521 // Expect that we only send one packet, the writes from different streams |
527 // should be bundled together. | 522 // should be bundled together. |
528 MockPacketWriter* writer = static_cast<MockPacketWriter*>( | 523 MockPacketWriter* writer = static_cast<MockPacketWriter*>( |
529 QuicConnectionPeer::GetWriter(session_.connection())); | 524 QuicConnectionPeer::GetWriter(session_.connection())); |
530 EXPECT_CALL(*writer, WritePacket(_, _, _, _, _)) | 525 EXPECT_CALL(*writer, WritePacket(_, _, _, _, _)) |
531 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 0))); | 526 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 0))); |
532 EXPECT_CALL(*send_algorithm, OnPacketSent(_, _, _, _, _)); | 527 EXPECT_CALL(*send_algorithm, OnPacketSent(_, _, _, _, _)); |
533 session_.OnCanWrite(); | 528 session_.OnCanWrite(); |
534 EXPECT_FALSE(session_.WillingAndAbleToWrite()); | 529 EXPECT_FALSE(session_.WillingAndAbleToWrite()); |
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1181 session_.OnConfigNegotiated(); | 1176 session_.OnConfigNegotiated(); |
1182 EXPECT_LT(session_.max_open_outgoing_streams(), | 1177 EXPECT_LT(session_.max_open_outgoing_streams(), |
1183 session_.max_open_incoming_streams()); | 1178 session_.max_open_incoming_streams()); |
1184 EXPECT_EQ(session_.max_open_outgoing_streams(), | 1179 EXPECT_EQ(session_.max_open_outgoing_streams(), |
1185 kDefaultMaxStreamsPerConnection); | 1180 kDefaultMaxStreamsPerConnection); |
1186 } | 1181 } |
1187 | 1182 |
1188 } // namespace | 1183 } // namespace |
1189 } // namespace test | 1184 } // namespace test |
1190 } // namespace net | 1185 } // namespace net |
OLD | NEW |