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_connection.h" | 5 #include "net/quic/quic_connection.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" | 24 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" |
25 #include "net/quic/test_tools/quic_test_utils.h" | 25 #include "net/quic/test_tools/quic_test_utils.h" |
26 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
28 | 28 |
29 using base::StringPiece; | 29 using base::StringPiece; |
30 using std::map; | 30 using std::map; |
31 using std::vector; | 31 using std::vector; |
32 using testing::_; | 32 using testing::_; |
33 using testing::AnyNumber; | 33 using testing::AnyNumber; |
| 34 using testing::AtLeast; |
34 using testing::ContainerEq; | 35 using testing::ContainerEq; |
35 using testing::Contains; | 36 using testing::Contains; |
36 using testing::DoAll; | 37 using testing::DoAll; |
37 using testing::InSequence; | 38 using testing::InSequence; |
38 using testing::InvokeWithoutArgs; | 39 using testing::InvokeWithoutArgs; |
39 using testing::Ref; | 40 using testing::Ref; |
40 using testing::Return; | 41 using testing::Return; |
41 using testing::SaveArg; | 42 using testing::SaveArg; |
42 using testing::StrictMock; | 43 using testing::StrictMock; |
43 | 44 |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 MockRandom* random_generator_; | 268 MockRandom* random_generator_; |
268 | 269 |
269 DISALLOW_COPY_AND_ASSIGN(TestConnectionHelper); | 270 DISALLOW_COPY_AND_ASSIGN(TestConnectionHelper); |
270 }; | 271 }; |
271 | 272 |
272 class TestPacketWriter : public QuicPacketWriter { | 273 class TestPacketWriter : public QuicPacketWriter { |
273 public: | 274 public: |
274 TestPacketWriter() | 275 TestPacketWriter() |
275 : last_packet_size_(0), | 276 : last_packet_size_(0), |
276 write_blocked_(false), | 277 write_blocked_(false), |
277 block_next_write_(false), | 278 block_on_next_write_(false), |
278 is_write_blocked_data_buffered_(false), | 279 is_write_blocked_data_buffered_(false), |
279 is_server_(true), | 280 is_server_(true), |
280 final_bytes_of_last_packet_(0), | 281 final_bytes_of_last_packet_(0), |
281 final_bytes_of_previous_packet_(0), | 282 final_bytes_of_previous_packet_(0), |
282 use_tagging_decrypter_(false), | 283 use_tagging_decrypter_(false), |
283 packets_write_attempts_(0) { | 284 packets_write_attempts_(0) { |
284 } | 285 } |
285 | 286 |
286 // QuicPacketWriter interface | 287 // QuicPacketWriter interface |
287 virtual WriteResult WritePacket( | 288 virtual WriteResult WritePacket( |
(...skipping 10 matching lines...) Expand all Loading... |
298 sizeof(final_bytes_of_last_packet_)); | 299 sizeof(final_bytes_of_last_packet_)); |
299 } | 300 } |
300 | 301 |
301 QuicFramer framer(QuicSupportedVersions(), QuicTime::Zero(), !is_server_); | 302 QuicFramer framer(QuicSupportedVersions(), QuicTime::Zero(), !is_server_); |
302 if (use_tagging_decrypter_) { | 303 if (use_tagging_decrypter_) { |
303 framer.SetDecrypter(new TaggingDecrypter); | 304 framer.SetDecrypter(new TaggingDecrypter); |
304 } | 305 } |
305 visitor_.Reset(); | 306 visitor_.Reset(); |
306 framer.set_visitor(&visitor_); | 307 framer.set_visitor(&visitor_); |
307 EXPECT_TRUE(framer.ProcessPacket(packet)); | 308 EXPECT_TRUE(framer.ProcessPacket(packet)); |
308 if (block_next_write_) { | 309 if (block_on_next_write_) { |
309 write_blocked_ = true; | 310 write_blocked_ = true; |
310 block_next_write_ = false; | 311 block_on_next_write_ = false; |
311 } | 312 } |
312 if (IsWriteBlocked()) { | 313 if (IsWriteBlocked()) { |
313 return WriteResult(WRITE_STATUS_BLOCKED, -1); | 314 return WriteResult(WRITE_STATUS_BLOCKED, -1); |
314 } | 315 } |
315 last_packet_size_ = packet.length(); | 316 last_packet_size_ = packet.length(); |
316 return WriteResult(WRITE_STATUS_OK, last_packet_size_); | 317 return WriteResult(WRITE_STATUS_OK, last_packet_size_); |
317 } | 318 } |
318 | 319 |
319 virtual bool IsWriteBlockedDataBuffered() const OVERRIDE { | 320 virtual bool IsWriteBlockedDataBuffered() const OVERRIDE { |
320 return is_write_blocked_data_buffered_; | 321 return is_write_blocked_data_buffered_; |
321 } | 322 } |
322 | 323 |
323 virtual bool IsWriteBlocked() const OVERRIDE { return write_blocked_; } | 324 virtual bool IsWriteBlocked() const OVERRIDE { return write_blocked_; } |
324 | 325 |
325 virtual void SetWritable() OVERRIDE { write_blocked_ = false; } | 326 virtual void SetWritable() OVERRIDE { write_blocked_ = false; } |
326 | 327 |
327 void BlockNextWrite() { block_next_write_ = true; } | 328 void BlockOnNextWrite() { block_on_next_write_ = true; } |
328 | 329 |
329 // Resets the visitor's state by clearing out the headers and frames. | 330 // Resets the visitor's state by clearing out the headers and frames. |
330 void Reset() { | 331 void Reset() { |
331 visitor_.Reset(); | 332 visitor_.Reset(); |
332 } | 333 } |
333 | 334 |
334 QuicPacketHeader* header() { return visitor_.header(); } | 335 QuicPacketHeader* header() { return visitor_.header(); } |
335 | 336 |
336 size_t frame_count() const { return visitor_.frame_count(); } | 337 size_t frame_count() const { return visitor_.frame_count(); } |
337 | 338 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 void use_tagging_decrypter() { | 374 void use_tagging_decrypter() { |
374 use_tagging_decrypter_ = true; | 375 use_tagging_decrypter_ = true; |
375 } | 376 } |
376 | 377 |
377 uint32 packets_write_attempts() { return packets_write_attempts_; } | 378 uint32 packets_write_attempts() { return packets_write_attempts_; } |
378 | 379 |
379 private: | 380 private: |
380 FramerVisitorCapturingFrames visitor_; | 381 FramerVisitorCapturingFrames visitor_; |
381 size_t last_packet_size_; | 382 size_t last_packet_size_; |
382 bool write_blocked_; | 383 bool write_blocked_; |
383 bool block_next_write_; | 384 bool block_on_next_write_; |
384 bool is_write_blocked_data_buffered_; | 385 bool is_write_blocked_data_buffered_; |
385 bool is_server_; | 386 bool is_server_; |
386 uint32 final_bytes_of_last_packet_; | 387 uint32 final_bytes_of_last_packet_; |
387 uint32 final_bytes_of_previous_packet_; | 388 uint32 final_bytes_of_previous_packet_; |
388 bool use_tagging_decrypter_; | 389 bool use_tagging_decrypter_; |
389 uint32 packets_write_attempts_; | 390 uint32 packets_write_attempts_; |
390 | 391 |
391 DISALLOW_COPY_AND_ASSIGN(TestPacketWriter); | 392 DISALLOW_COPY_AND_ASSIGN(TestPacketWriter); |
392 }; | 393 }; |
393 | 394 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 SendStreamDataWithString(kCryptoStreamId, "chlo", 0, !kFin, NULL); | 466 SendStreamDataWithString(kCryptoStreamId, "chlo", 0, !kFin, NULL); |
466 this->Flush(); | 467 this->Flush(); |
467 return consumed; | 468 return consumed; |
468 } | 469 } |
469 | 470 |
470 bool is_server() { | 471 bool is_server() { |
471 return QuicConnectionPeer::IsServer(this); | 472 return QuicConnectionPeer::IsServer(this); |
472 } | 473 } |
473 | 474 |
474 void set_version(QuicVersion version) { | 475 void set_version(QuicVersion version) { |
475 framer_.set_version(version); | 476 QuicConnectionPeer::GetFramer(this)->set_version(version); |
476 } | 477 } |
477 | 478 |
478 void set_is_server(bool is_server) { | 479 void set_is_server(bool is_server) { |
479 writer_->set_is_server(is_server); | 480 writer_->set_is_server(is_server); |
480 QuicPacketCreatorPeer::SetIsServer( | 481 QuicPacketCreatorPeer::SetIsServer( |
481 QuicConnectionPeer::GetPacketCreator(this), is_server); | 482 QuicConnectionPeer::GetPacketCreator(this), is_server); |
482 QuicConnectionPeer::SetIsServer(this, is_server); | 483 QuicConnectionPeer::SetIsServer(this, is_server); |
483 } | 484 } |
484 | 485 |
485 TestConnectionHelper::TestAlarm* GetAckAlarm() { | 486 TestConnectionHelper::TestAlarm* GetAckAlarm() { |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 // Send an erroneous packet to close the connection. | 835 // Send an erroneous packet to close the connection. |
835 EXPECT_CALL(visitor_, | 836 EXPECT_CALL(visitor_, |
836 OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false)); | 837 OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false)); |
837 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a | 838 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a |
838 // packet call to the visitor. | 839 // packet call to the visitor. |
839 ProcessDataPacket(6000, 0, !kEntropyFlag); | 840 ProcessDataPacket(6000, 0, !kEntropyFlag); |
840 EXPECT_FALSE( | 841 EXPECT_FALSE( |
841 QuicConnectionPeer::GetConnectionClosePacket(&connection_) == NULL); | 842 QuicConnectionPeer::GetConnectionClosePacket(&connection_) == NULL); |
842 } | 843 } |
843 | 844 |
| 845 void BlockOnNextWrite() { |
| 846 writer_->BlockOnNextWrite(); |
| 847 EXPECT_CALL(visitor_, OnWriteBlocked()).Times(AtLeast(1)); |
| 848 } |
| 849 |
844 QuicGuid guid_; | 850 QuicGuid guid_; |
845 QuicFramer framer_; | 851 QuicFramer framer_; |
846 QuicPacketCreator creator_; | 852 QuicPacketCreator creator_; |
847 MockEntropyCalculator entropy_calculator_; | 853 MockEntropyCalculator entropy_calculator_; |
848 | 854 |
849 MockSendAlgorithm* send_algorithm_; | 855 MockSendAlgorithm* send_algorithm_; |
850 TestReceiveAlgorithm* receive_algorithm_; | 856 TestReceiveAlgorithm* receive_algorithm_; |
851 MockClock clock_; | 857 MockClock clock_; |
852 MockRandom random_generator_; | 858 MockRandom random_generator_; |
853 scoped_ptr<TestConnectionHelper> helper_; | 859 scoped_ptr<TestConnectionHelper> helper_; |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1332 // All packets carry version info till version is negotiated. | 1338 // All packets carry version info till version is negotiated. |
1333 size_t payload_length; | 1339 size_t payload_length; |
1334 connection_.options()->max_packet_length = | 1340 connection_.options()->max_packet_length = |
1335 GetPacketLengthForOneStream( | 1341 GetPacketLengthForOneStream( |
1336 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, | 1342 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, |
1337 IN_FEC_GROUP, &payload_length); | 1343 IN_FEC_GROUP, &payload_length); |
1338 // And send FEC every two packets. | 1344 // And send FEC every two packets. |
1339 connection_.options()->max_packets_per_fec_group = 2; | 1345 connection_.options()->max_packets_per_fec_group = 2; |
1340 | 1346 |
1341 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1347 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
1342 writer_->BlockNextWrite(); | 1348 BlockOnNextWrite(); |
1343 const string payload(payload_length, 'a'); | 1349 const string payload(payload_length, 'a'); |
1344 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL); | 1350 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL); |
1345 EXPECT_FALSE(creator_.ShouldSendFec(true)); | 1351 EXPECT_FALSE(creator_.ShouldSendFec(true)); |
1346 // Expect the first data packet and the fec packet to be queued. | 1352 // Expect the first data packet and the fec packet to be queued. |
1347 EXPECT_EQ(2u, connection_.NumQueuedPackets()); | 1353 EXPECT_EQ(2u, connection_.NumQueuedPackets()); |
1348 } | 1354 } |
1349 | 1355 |
1350 TEST_F(QuicConnectionTest, AbandonFECFromCongestionWindow) { | 1356 TEST_F(QuicConnectionTest, AbandonFECFromCongestionWindow) { |
1351 connection_.options()->max_packets_per_fec_group = 1; | 1357 connection_.options()->max_packets_per_fec_group = 1; |
1352 // 1 Data and 1 FEC packet. | 1358 // 1 Data and 1 FEC packet. |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1602 EXPECT_EQ(1u, frame.stream_id); | 1608 EXPECT_EQ(1u, frame.stream_id); |
1603 EXPECT_EQ("ABCD", string(static_cast<char*> | 1609 EXPECT_EQ("ABCD", string(static_cast<char*> |
1604 (frame.data.iovec()[0].iov_base), | 1610 (frame.data.iovec()[0].iov_base), |
1605 (frame.data.iovec()[0].iov_len))); | 1611 (frame.data.iovec()[0].iov_len))); |
1606 } | 1612 } |
1607 | 1613 |
1608 TEST_F(QuicConnectionTest, FramePackingSendvQueued) { | 1614 TEST_F(QuicConnectionTest, FramePackingSendvQueued) { |
1609 // Try to send two stream frames in 1 packet by using writev. | 1615 // Try to send two stream frames in 1 packet by using writev. |
1610 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)); | 1616 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)); |
1611 | 1617 |
1612 writer_->BlockNextWrite(); | 1618 BlockOnNextWrite(); |
1613 char data[] = "ABCD"; | 1619 char data[] = "ABCD"; |
1614 IOVector data_iov; | 1620 IOVector data_iov; |
1615 data_iov.AppendNoCoalesce(data, 2); | 1621 data_iov.AppendNoCoalesce(data, 2); |
1616 data_iov.AppendNoCoalesce(data + 2, 2); | 1622 data_iov.AppendNoCoalesce(data + 2, 2); |
1617 connection_.SendStreamData(1, data_iov, 0, !kFin, NULL); | 1623 connection_.SendStreamData(1, data_iov, 0, !kFin, NULL); |
1618 | 1624 |
1619 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 1625 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
1620 EXPECT_TRUE(connection_.HasQueuedData()); | 1626 EXPECT_TRUE(connection_.HasQueuedData()); |
1621 | 1627 |
1622 // Unblock the writes and actually send. | 1628 // Unblock the writes and actually send. |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1721 ProcessAckPacket(&ack_one); | 1727 ProcessAckPacket(&ack_one); |
1722 ProcessAckPacket(&ack_one); | 1728 ProcessAckPacket(&ack_one); |
1723 ProcessAckPacket(&ack_one); | 1729 ProcessAckPacket(&ack_one); |
1724 | 1730 |
1725 // Peer acks up to 3 with two explicitly missing. Two nacks should cause no | 1731 // Peer acks up to 3 with two explicitly missing. Two nacks should cause no |
1726 // change. | 1732 // change. |
1727 QuicAckFrame nack_two = InitAckFrame(3, 0); | 1733 QuicAckFrame nack_two = InitAckFrame(3, 0); |
1728 NackPacket(2, &nack_two); | 1734 NackPacket(2, &nack_two); |
1729 // The first nack should trigger a fast retransmission, but we'll be | 1735 // The first nack should trigger a fast retransmission, but we'll be |
1730 // write blocked, so the packet will be queued. | 1736 // write blocked, so the packet will be queued. |
1731 writer_->BlockNextWrite(); | 1737 BlockOnNextWrite(); |
1732 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); | 1738 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); |
1733 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)); | 1739 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)); |
1734 | |
1735 ProcessAckPacket(&nack_two); | 1740 ProcessAckPacket(&nack_two); |
1736 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 1741 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
1737 | 1742 |
1738 // Now, ack the previous transmission. | 1743 // Now, ack the previous transmission. |
1739 QuicAckFrame ack_all = InitAckFrame(3, 0); | 1744 QuicAckFrame ack_all = InitAckFrame(3, 0); |
1740 ProcessAckPacket(&ack_all); | 1745 ProcessAckPacket(&ack_all); |
1741 | 1746 |
1742 // Unblock the socket and attempt to send the queued packets. However, | 1747 // Unblock the socket and attempt to send the queued packets. However, |
1743 // since the previous transmission has been acked, we will not | 1748 // since the previous transmission has been acked, we will not |
1744 // send the retransmission. | 1749 // send the retransmission. |
(...skipping 26 matching lines...) Expand all Loading... |
1771 ProcessAckPacket(&frame); | 1776 ProcessAckPacket(&frame); |
1772 } | 1777 } |
1773 | 1778 |
1774 TEST_F(QuicConnectionTest, QueueAfterTwoRTOs) { | 1779 TEST_F(QuicConnectionTest, QueueAfterTwoRTOs) { |
1775 for (int i = 0; i < 10; ++i) { | 1780 for (int i = 0; i < 10; ++i) { |
1776 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 1781 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
1777 connection_.SendStreamDataWithString(3, "foo", i * 3, !kFin, NULL); | 1782 connection_.SendStreamDataWithString(3, "foo", i * 3, !kFin, NULL); |
1778 } | 1783 } |
1779 | 1784 |
1780 // Block the congestion window and ensure they're queued. | 1785 // Block the congestion window and ensure they're queued. |
1781 writer_->BlockNextWrite(); | 1786 BlockOnNextWrite(); |
1782 clock_.AdvanceTime(DefaultRetransmissionTime()); | 1787 clock_.AdvanceTime(DefaultRetransmissionTime()); |
1783 // Only one packet should be retransmitted. | 1788 // Only one packet should be retransmitted. |
1784 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); | 1789 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
1785 connection_.GetRetransmissionAlarm()->Fire(); | 1790 connection_.GetRetransmissionAlarm()->Fire(); |
1786 EXPECT_TRUE(connection_.HasQueuedData()); | 1791 EXPECT_TRUE(connection_.HasQueuedData()); |
1787 | 1792 |
1788 // Unblock the congestion window. | 1793 // Unblock the congestion window. |
1789 writer_->SetWritable(); | 1794 writer_->SetWritable(); |
1790 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds( | 1795 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds( |
1791 2 * DefaultRetransmissionTime().ToMicroseconds())); | 1796 2 * DefaultRetransmissionTime().ToMicroseconds())); |
1792 // Retransmit already retransmitted packets event though the sequence number | 1797 // Retransmit already retransmitted packets event though the sequence number |
1793 // greater than the largest observed. | 1798 // greater than the largest observed. |
1794 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(10); | 1799 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(10); |
1795 connection_.GetRetransmissionAlarm()->Fire(); | 1800 connection_.GetRetransmissionAlarm()->Fire(); |
1796 connection_.OnCanWrite(); | 1801 connection_.OnCanWrite(); |
1797 } | 1802 } |
1798 | 1803 |
1799 TEST_F(QuicConnectionTest, WriteBlockedThenSent) { | 1804 TEST_F(QuicConnectionTest, WriteBlockedThenSent) { |
1800 writer_->BlockNextWrite(); | 1805 BlockOnNextWrite(); |
1801 writer_->set_is_write_blocked_data_buffered(true); | 1806 writer_->set_is_write_blocked_data_buffered(true); |
1802 | |
1803 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); | 1807 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); |
1804 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); | 1808 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); |
1805 | 1809 |
1806 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 1810 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
1807 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0)); | 1811 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0)); |
1808 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); | 1812 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); |
1809 } | 1813 } |
1810 | 1814 |
1811 TEST_F(QuicConnectionTest, WriteBlockedAckedThenSent) { | 1815 TEST_F(QuicConnectionTest, WriteBlockedAckedThenSent) { |
1812 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1816 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
1813 writer_->BlockNextWrite(); | 1817 BlockOnNextWrite(); |
1814 | |
1815 writer_->set_is_write_blocked_data_buffered(true); | 1818 writer_->set_is_write_blocked_data_buffered(true); |
1816 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); | 1819 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); |
1817 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); | 1820 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); |
1818 | 1821 |
1819 // Ack the sent packet before the callback returns, which happens in | 1822 // Ack the sent packet before the callback returns, which happens in |
1820 // rare circumstances with write blocked sockets. | 1823 // rare circumstances with write blocked sockets. |
1821 QuicAckFrame ack = InitAckFrame(1, 0); | 1824 QuicAckFrame ack = InitAckFrame(1, 0); |
1822 ProcessAckPacket(&ack); | 1825 ProcessAckPacket(&ack); |
1823 | 1826 |
1824 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); | 1827 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); |
1825 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0)); | 1828 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0)); |
1826 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); | 1829 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); |
1827 } | 1830 } |
1828 | 1831 |
1829 TEST_F(QuicConnectionTest, RetransmitWriteBlockedAckedOriginalThenSent) { | 1832 TEST_F(QuicConnectionTest, RetransmitWriteBlockedAckedOriginalThenSent) { |
1830 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1833 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
1831 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); | 1834 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); |
1832 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); | 1835 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); |
1833 | 1836 |
1834 writer_->BlockNextWrite(); | 1837 BlockOnNextWrite(); |
1835 writer_->set_is_write_blocked_data_buffered(true); | 1838 writer_->set_is_write_blocked_data_buffered(true); |
1836 | |
1837 // Simulate the retransmission alarm firing. | 1839 // Simulate the retransmission alarm firing. |
1838 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(_)); | 1840 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(_)); |
1839 clock_.AdvanceTime(DefaultRetransmissionTime()); | 1841 clock_.AdvanceTime(DefaultRetransmissionTime()); |
1840 connection_.GetRetransmissionAlarm()->Fire(); | 1842 connection_.GetRetransmissionAlarm()->Fire(); |
1841 | 1843 |
1842 // Ack the sent packet before the callback returns, which happens in | 1844 // Ack the sent packet before the callback returns, which happens in |
1843 // rare circumstances with write blocked sockets. | 1845 // rare circumstances with write blocked sockets. |
1844 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); | 1846 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); |
1845 QuicAckFrame ack = InitAckFrame(1, 0); | 1847 QuicAckFrame ack = InitAckFrame(1, 0); |
1846 ProcessAckPacket(&ack); | 1848 ProcessAckPacket(&ack); |
1847 | 1849 |
1848 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0)); | 1850 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0)); |
1849 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); | 1851 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); |
1850 } | 1852 } |
1851 | 1853 |
1852 TEST_F(QuicConnectionTest, ResumptionAlarmWhenWriteBlocked) { | 1854 TEST_F(QuicConnectionTest, ResumptionAlarmWhenWriteBlocked) { |
1853 // Block the connection. | 1855 // Block the connection. |
1854 writer_->BlockNextWrite(); | 1856 BlockOnNextWrite(); |
1855 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); | 1857 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); |
1856 EXPECT_EQ(1u, writer_->packets_write_attempts()); | 1858 EXPECT_EQ(1u, writer_->packets_write_attempts()); |
1857 EXPECT_TRUE(writer_->IsWriteBlocked()); | 1859 EXPECT_TRUE(writer_->IsWriteBlocked()); |
1858 | 1860 |
1859 // Set the send and resumption alarms. Fire the alarms and ensure they don't | 1861 // Set the send and resumption alarms. Fire the alarms and ensure they don't |
1860 // attempt to write. | 1862 // attempt to write. |
1861 connection_.GetResumeWritesAlarm()->Set(clock_.ApproximateNow()); | 1863 connection_.GetResumeWritesAlarm()->Set(clock_.ApproximateNow()); |
1862 connection_.GetSendAlarm()->Set(clock_.ApproximateNow()); | 1864 connection_.GetSendAlarm()->Set(clock_.ApproximateNow()); |
1863 connection_.GetResumeWritesAlarm()->Fire(); | 1865 connection_.GetResumeWritesAlarm()->Fire(); |
1864 connection_.GetSendAlarm()->Fire(); | 1866 connection_.GetSendAlarm()->Fire(); |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2247 ASSERT_NE(0u, nack_sequence_number); | 2249 ASSERT_NE(0u, nack_sequence_number); |
2248 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission( | 2250 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission( |
2249 &connection_, rto_sequence_number)); | 2251 &connection_, rto_sequence_number)); |
2250 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission( | 2252 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission( |
2251 &connection_, nack_sequence_number)); | 2253 &connection_, nack_sequence_number)); |
2252 EXPECT_TRUE(QuicConnectionPeer::IsRetransmission( | 2254 EXPECT_TRUE(QuicConnectionPeer::IsRetransmission( |
2253 &connection_, nack_sequence_number)); | 2255 &connection_, nack_sequence_number)); |
2254 } | 2256 } |
2255 | 2257 |
2256 TEST_F(QuicConnectionTest, SetRTOAfterWritingToSocket) { | 2258 TEST_F(QuicConnectionTest, SetRTOAfterWritingToSocket) { |
2257 writer_->BlockNextWrite(); | 2259 BlockOnNextWrite(); |
2258 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); | 2260 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); |
2259 // Make sure that RTO is not started when the packet is queued. | 2261 // Make sure that RTO is not started when the packet is queued. |
2260 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); | 2262 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); |
2261 | 2263 |
2262 // Test that RTO is started once we write to the socket. | 2264 // Test that RTO is started once we write to the socket. |
2263 writer_->SetWritable(); | 2265 writer_->SetWritable(); |
2264 connection_.OnCanWrite(); | 2266 connection_.OnCanWrite(); |
2265 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); | 2267 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); |
2266 } | 2268 } |
2267 | 2269 |
(...skipping 30 matching lines...) Expand all Loading... |
2298 // than previously. | 2300 // than previously. |
2299 EXPECT_TRUE(retransmission_alarm->IsSet()); | 2301 EXPECT_TRUE(retransmission_alarm->IsSet()); |
2300 QuicTime next_rto_time = retransmission_alarm->deadline(); | 2302 QuicTime next_rto_time = retransmission_alarm->deadline(); |
2301 QuicTime expected_rto_time = | 2303 QuicTime expected_rto_time = |
2302 connection_.sent_packet_manager().GetRetransmissionTime(); | 2304 connection_.sent_packet_manager().GetRetransmissionTime(); |
2303 EXPECT_EQ(next_rto_time, expected_rto_time); | 2305 EXPECT_EQ(next_rto_time, expected_rto_time); |
2304 } | 2306 } |
2305 | 2307 |
2306 TEST_F(QuicConnectionTest, TestQueued) { | 2308 TEST_F(QuicConnectionTest, TestQueued) { |
2307 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 2309 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
2308 writer_->BlockNextWrite(); | 2310 BlockOnNextWrite(); |
2309 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); | 2311 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); |
2310 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 2312 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
2311 | 2313 |
2312 // Unblock the writes and actually send. | 2314 // Unblock the writes and actually send. |
2313 writer_->SetWritable(); | 2315 writer_->SetWritable(); |
2314 EXPECT_TRUE(connection_.OnCanWrite()); | 2316 EXPECT_TRUE(connection_.OnCanWrite()); |
2315 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 2317 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
2316 } | 2318 } |
2317 | 2319 |
2318 TEST_F(QuicConnectionTest, CloseFecGroup) { | 2320 TEST_F(QuicConnectionTest, CloseFecGroup) { |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2453 TimeUntilSend(_, NACK_RETRANSMISSION, _, _)).Times(0); | 2455 TimeUntilSend(_, NACK_RETRANSMISSION, _, _)).Times(0); |
2454 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 2456 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
2455 connection_.SendPacket( | 2457 connection_.SendPacket( |
2456 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); | 2458 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); |
2457 // XXX: fixme. was: connection_.SendPacket(1, packet, kForce); | 2459 // XXX: fixme. was: connection_.SendPacket(1, packet, kForce); |
2458 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 2460 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
2459 } | 2461 } |
2460 | 2462 |
2461 TEST_F(QuicConnectionTest, SendSchedulerEAGAIN) { | 2463 TEST_F(QuicConnectionTest, SendSchedulerEAGAIN) { |
2462 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); | 2464 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); |
2463 writer_->BlockNextWrite(); | 2465 BlockOnNextWrite(); |
2464 EXPECT_CALL(*send_algorithm_, | 2466 EXPECT_CALL(*send_algorithm_, |
2465 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( | 2467 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( |
2466 testing::Return(QuicTime::Delta::Zero())); | 2468 testing::Return(QuicTime::Delta::Zero())); |
2467 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 1, _, _, _)).Times(0); | 2469 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 1, _, _, _)).Times(0); |
2468 connection_.SendPacket( | 2470 connection_.SendPacket( |
2469 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); | 2471 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); |
2470 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 2472 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
2471 } | 2473 } |
2472 | 2474 |
2473 TEST_F(QuicConnectionTest, SendSchedulerDelayThenSend) { | 2475 TEST_F(QuicConnectionTest, SendSchedulerDelayThenSend) { |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2928 QuicFrames frames; | 2930 QuicFrames frames; |
2929 QuicFrame frame(&frame1_); | 2931 QuicFrame frame(&frame1_); |
2930 frames.push_back(frame); | 2932 frames.push_back(frame); |
2931 scoped_ptr<QuicPacket> packet( | 2933 scoped_ptr<QuicPacket> packet( |
2932 framer_.BuildUnsizedDataPacket(header, frames).packet); | 2934 framer_.BuildUnsizedDataPacket(header, frames).packet); |
2933 scoped_ptr<QuicEncryptedPacket> encrypted( | 2935 scoped_ptr<QuicEncryptedPacket> encrypted( |
2934 framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); | 2936 framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); |
2935 | 2937 |
2936 framer_.set_version(QuicVersionMax()); | 2938 framer_.set_version(QuicVersionMax()); |
2937 connection_.set_is_server(true); | 2939 connection_.set_is_server(true); |
2938 writer_->BlockNextWrite(); | 2940 BlockOnNextWrite(); |
2939 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 2941 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); |
2940 EXPECT_EQ(0u, writer_->last_packet_size()); | 2942 EXPECT_EQ(0u, writer_->last_packet_size()); |
2941 EXPECT_TRUE(connection_.HasQueuedData()); | 2943 EXPECT_TRUE(connection_.HasQueuedData()); |
2942 | 2944 |
2943 writer_->SetWritable(); | 2945 writer_->SetWritable(); |
2944 connection_.OnCanWrite(); | 2946 connection_.OnCanWrite(); |
2945 EXPECT_TRUE(writer_->version_negotiation_packet() != NULL); | 2947 EXPECT_TRUE(writer_->version_negotiation_packet() != NULL); |
2946 | 2948 |
2947 size_t num_versions = arraysize(kSupportedQuicVersions); | 2949 size_t num_versions = arraysize(kSupportedQuicVersions); |
2948 EXPECT_EQ(num_versions, | 2950 EXPECT_EQ(num_versions, |
(...skipping 23 matching lines...) Expand all Loading... |
2972 QuicFrames frames; | 2974 QuicFrames frames; |
2973 QuicFrame frame(&frame1_); | 2975 QuicFrame frame(&frame1_); |
2974 frames.push_back(frame); | 2976 frames.push_back(frame); |
2975 scoped_ptr<QuicPacket> packet( | 2977 scoped_ptr<QuicPacket> packet( |
2976 framer_.BuildUnsizedDataPacket(header, frames).packet); | 2978 framer_.BuildUnsizedDataPacket(header, frames).packet); |
2977 scoped_ptr<QuicEncryptedPacket> encrypted( | 2979 scoped_ptr<QuicEncryptedPacket> encrypted( |
2978 framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); | 2980 framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); |
2979 | 2981 |
2980 framer_.set_version(QuicVersionMax()); | 2982 framer_.set_version(QuicVersionMax()); |
2981 connection_.set_is_server(true); | 2983 connection_.set_is_server(true); |
2982 writer_->BlockNextWrite(); | 2984 BlockOnNextWrite(); |
2983 writer_->set_is_write_blocked_data_buffered(true); | 2985 writer_->set_is_write_blocked_data_buffered(true); |
2984 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 2986 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); |
2985 EXPECT_EQ(0u, writer_->last_packet_size()); | 2987 EXPECT_EQ(0u, writer_->last_packet_size()); |
2986 EXPECT_FALSE(connection_.HasQueuedData()); | 2988 EXPECT_FALSE(connection_.HasQueuedData()); |
2987 } | 2989 } |
2988 | 2990 |
2989 TEST_F(QuicConnectionTest, ClientHandlesVersionNegotiation) { | 2991 TEST_F(QuicConnectionTest, ClientHandlesVersionNegotiation) { |
2990 // Start out with some unsupported version. | 2992 // Start out with some unsupported version. |
2991 QuicConnectionPeer::GetFramer(&connection_)->set_version_for_tests( | 2993 QuicConnectionPeer::GetFramer(&connection_)->set_version_for_tests( |
2992 QUIC_VERSION_UNSUPPORTED); | 2994 QUIC_VERSION_UNSUPPORTED); |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3250 // Send a packet. | 3252 // Send a packet. |
3251 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); | 3253 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); |
3252 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 3254 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
3253 EXPECT_EQ(1u, writer_->packets_write_attempts()); | 3255 EXPECT_EQ(1u, writer_->packets_write_attempts()); |
3254 | 3256 |
3255 TriggerConnectionClose(); | 3257 TriggerConnectionClose(); |
3256 EXPECT_EQ(2u, writer_->packets_write_attempts()); | 3258 EXPECT_EQ(2u, writer_->packets_write_attempts()); |
3257 } | 3259 } |
3258 | 3260 |
3259 TEST_F(QuicConnectionTest, ConnectionCloseGettingWriteBlocked) { | 3261 TEST_F(QuicConnectionTest, ConnectionCloseGettingWriteBlocked) { |
3260 writer_->BlockNextWrite(); | 3262 BlockOnNextWrite(); |
3261 TriggerConnectionClose(); | 3263 TriggerConnectionClose(); |
3262 EXPECT_EQ(1u, writer_->packets_write_attempts()); | 3264 EXPECT_EQ(1u, writer_->packets_write_attempts()); |
3263 EXPECT_TRUE(writer_->IsWriteBlocked()); | 3265 EXPECT_TRUE(writer_->IsWriteBlocked()); |
3264 } | 3266 } |
3265 | 3267 |
3266 TEST_F(QuicConnectionTest, ConnectionCloseWhenWriteBlocked) { | 3268 TEST_F(QuicConnectionTest, ConnectionCloseWhenWriteBlocked) { |
3267 writer_->BlockNextWrite(); | 3269 BlockOnNextWrite(); |
3268 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); | 3270 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); |
3269 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 3271 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
3270 EXPECT_EQ(1u, writer_->packets_write_attempts()); | 3272 EXPECT_EQ(1u, writer_->packets_write_attempts()); |
3271 EXPECT_TRUE(writer_->IsWriteBlocked()); | 3273 EXPECT_TRUE(writer_->IsWriteBlocked()); |
3272 TriggerConnectionClose(); | 3274 TriggerConnectionClose(); |
3273 EXPECT_EQ(1u, writer_->packets_write_attempts()); | 3275 EXPECT_EQ(1u, writer_->packets_write_attempts()); |
3274 } | 3276 } |
3275 | 3277 |
3276 TEST_F(QuicConnectionTest, AckNotifierTriggerCallback) { | 3278 TEST_F(QuicConnectionTest, AckNotifierTriggerCallback) { |
3277 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3279 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3462 true); | 3464 true); |
3463 TestConnection client(guid_, IPEndPoint(), helper_.get(), writer_.get(), | 3465 TestConnection client(guid_, IPEndPoint(), helper_.get(), writer_.get(), |
3464 false); | 3466 false); |
3465 EXPECT_TRUE(client.sent_packet_manager().using_pacing()); | 3467 EXPECT_TRUE(client.sent_packet_manager().using_pacing()); |
3466 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); | 3468 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); |
3467 } | 3469 } |
3468 | 3470 |
3469 } // namespace | 3471 } // namespace |
3470 } // namespace test | 3472 } // namespace test |
3471 } // namespace net | 3473 } // namespace net |
OLD | NEW |