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 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 | 631 |
632 void ProcessClosePacket(QuicPacketSequenceNumber number, | 632 void ProcessClosePacket(QuicPacketSequenceNumber number, |
633 QuicFecGroupNumber fec_group) { | 633 QuicFecGroupNumber fec_group) { |
634 scoped_ptr<QuicPacket> packet(ConstructClosePacket(number, fec_group)); | 634 scoped_ptr<QuicPacket> packet(ConstructClosePacket(number, fec_group)); |
635 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPacket( | 635 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPacket( |
636 ENCRYPTION_NONE, number, *packet)); | 636 ENCRYPTION_NONE, number, *packet)); |
637 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 637 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); |
638 } | 638 } |
639 | 639 |
640 size_t ProcessFecProtectedPacket(QuicPacketSequenceNumber number, | 640 size_t ProcessFecProtectedPacket(QuicPacketSequenceNumber number, |
641 bool expect_revival, bool entropy_flag) { | 641 bool expect_revival, bool entropy_flag) { |
642 if (expect_revival) { | 642 if (expect_revival) { |
643 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillOnce(Return(accept_packet_)); | 643 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillOnce(Return(accept_packet_)); |
644 } | 644 } |
645 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillOnce(Return(accept_packet_)) | 645 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillOnce(Return(accept_packet_)) |
646 .RetiresOnSaturation(); | 646 .RetiresOnSaturation(); |
647 return ProcessDataPacket(number, 1, entropy_flag); | 647 return ProcessDataPacket(number, 1, entropy_flag); |
648 } | 648 } |
649 | 649 |
650 // Processes an FEC packet that covers the packets that would have been | 650 // Processes an FEC packet that covers the packets that would have been |
651 // received. | 651 // received. |
(...skipping 1188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1840 clock_.AdvanceTime(DefaultRetransmissionTime()); | 1840 clock_.AdvanceTime(DefaultRetransmissionTime()); |
1841 connection_.GetRetransmissionAlarm()->Fire(); | 1841 connection_.GetRetransmissionAlarm()->Fire(); |
1842 | 1842 |
1843 // Ack the sent packet before the callback returns, which happens in | 1843 // Ack the sent packet before the callback returns, which happens in |
1844 // rare circumstances with write blocked sockets. | 1844 // rare circumstances with write blocked sockets. |
1845 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); | 1845 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); |
1846 QuicAckFrame ack = InitAckFrame(1, 0); | 1846 QuicAckFrame ack = InitAckFrame(1, 0); |
1847 ProcessAckPacket(&ack); | 1847 ProcessAckPacket(&ack); |
1848 | 1848 |
1849 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0)); | 1849 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0)); |
1850 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); | 1850 // The retransmission alarm should not be set because there are |
| 1851 // no unacked packets. |
| 1852 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); |
1851 } | 1853 } |
1852 | 1854 |
1853 TEST_F(QuicConnectionTest, ResumptionAlarmWhenWriteBlocked) { | 1855 TEST_F(QuicConnectionTest, ResumptionAlarmWhenWriteBlocked) { |
1854 // Block the connection. | 1856 // Block the connection. |
1855 BlockOnNextWrite(); | 1857 BlockOnNextWrite(); |
1856 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); | 1858 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); |
1857 EXPECT_EQ(1u, writer_->packets_write_attempts()); | 1859 EXPECT_EQ(1u, writer_->packets_write_attempts()); |
1858 EXPECT_TRUE(writer_->IsWriteBlocked()); | 1860 EXPECT_TRUE(writer_->IsWriteBlocked()); |
1859 | 1861 |
1860 // Set the send and resumption alarms. Fire the alarms and ensure they don't | 1862 // Set the send and resumption alarms. Fire the alarms and ensure they don't |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1976 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); | 1978 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); |
1977 } | 1979 } |
1978 | 1980 |
1979 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPacketsThenFecPacket) { | 1981 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPacketsThenFecPacket) { |
1980 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1982 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
1981 | 1983 |
1982 ProcessFecProtectedPacket(1, false, !kEntropyFlag); | 1984 ProcessFecProtectedPacket(1, false, !kEntropyFlag); |
1983 // Don't send missing packet 2. | 1985 // Don't send missing packet 2. |
1984 ProcessFecProtectedPacket(3, false, !kEntropyFlag); | 1986 ProcessFecProtectedPacket(3, false, !kEntropyFlag); |
1985 ProcessFecPacket(4, 1, true, kEntropyFlag, NULL); | 1987 ProcessFecPacket(4, 1, true, kEntropyFlag, NULL); |
1986 // Entropy flag should be true, so entropy should not be 0. | 1988 // Ensure QUIC no longer revives entropy for lost packets. |
1987 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); | 1989 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); |
| 1990 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 4)); |
1988 } | 1991 } |
1989 | 1992 |
1990 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPacket) { | 1993 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPacket) { |
1991 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1994 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
1992 | 1995 |
1993 // Don't send missing packet 1. | 1996 // Don't send missing packet 1. |
1994 ProcessFecPacket(3, 1, false, !kEntropyFlag, NULL); | 1997 ProcessFecPacket(3, 1, false, !kEntropyFlag, NULL); |
1995 // Out of order. | 1998 // Out of order. |
1996 ProcessFecProtectedPacket(2, true, !kEntropyFlag); | 1999 ProcessFecProtectedPacket(2, true, !kEntropyFlag); |
1997 // Entropy flag should be false, so entropy should be 0. | 2000 // Entropy flag should be false, so entropy should be 0. |
1998 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); | 2001 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); |
1999 } | 2002 } |
2000 | 2003 |
2001 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPackets) { | 2004 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPackets) { |
2002 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2005 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
2003 | 2006 |
2004 ProcessFecProtectedPacket(1, false, !kEntropyFlag); | 2007 ProcessFecProtectedPacket(1, false, !kEntropyFlag); |
2005 // Don't send missing packet 2. | 2008 // Don't send missing packet 2. |
2006 ProcessFecPacket(6, 1, false, kEntropyFlag, NULL); | 2009 ProcessFecPacket(6, 1, false, kEntropyFlag, NULL); |
2007 ProcessFecProtectedPacket(3, false, kEntropyFlag); | 2010 ProcessFecProtectedPacket(3, false, kEntropyFlag); |
2008 ProcessFecProtectedPacket(4, false, kEntropyFlag); | 2011 ProcessFecProtectedPacket(4, false, kEntropyFlag); |
2009 ProcessFecProtectedPacket(5, true, !kEntropyFlag); | 2012 ProcessFecProtectedPacket(5, true, !kEntropyFlag); |
2010 // Entropy flag should be true, so entropy should be 0. | 2013 // Ensure entropy is not revived for the missing packet. |
2011 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); | 2014 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); |
| 2015 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 3)); |
2012 } | 2016 } |
2013 | 2017 |
2014 TEST_F(QuicConnectionTest, RTO) { | 2018 TEST_F(QuicConnectionTest, RTO) { |
2015 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( | 2019 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( |
2016 DefaultRetransmissionTime()); | 2020 DefaultRetransmissionTime()); |
2017 SendStreamDataToPeer(3, "foo", 0, !kFin, NULL); | 2021 SendStreamDataToPeer(3, "foo", 0, !kFin, NULL); |
2018 EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked); | 2022 EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked); |
2019 | 2023 |
2020 EXPECT_EQ(1u, last_header()->packet_sequence_number); | 2024 EXPECT_EQ(1u, last_header()->packet_sequence_number); |
2021 EXPECT_EQ(default_retransmission_time, | 2025 EXPECT_EQ(default_retransmission_time, |
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2774 TEST_F(QuicConnectionTest, ReceivedEntropyHashCalculation) { | 2778 TEST_F(QuicConnectionTest, ReceivedEntropyHashCalculation) { |
2775 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillRepeatedly(Return(true)); | 2779 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillRepeatedly(Return(true)); |
2776 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2780 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
2777 ProcessDataPacket(1, 1, kEntropyFlag); | 2781 ProcessDataPacket(1, 1, kEntropyFlag); |
2778 ProcessDataPacket(4, 1, kEntropyFlag); | 2782 ProcessDataPacket(4, 1, kEntropyFlag); |
2779 ProcessDataPacket(3, 1, !kEntropyFlag); | 2783 ProcessDataPacket(3, 1, !kEntropyFlag); |
2780 ProcessDataPacket(7, 1, kEntropyFlag); | 2784 ProcessDataPacket(7, 1, kEntropyFlag); |
2781 EXPECT_EQ(146u, outgoing_ack()->received_info.entropy_hash); | 2785 EXPECT_EQ(146u, outgoing_ack()->received_info.entropy_hash); |
2782 } | 2786 } |
2783 | 2787 |
| 2788 TEST_F(QuicConnectionTest, ReceivedEntropyHashCalculationHalfFEC) { |
| 2789 // FEC packets should not change the entropy hash calculation. |
| 2790 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillRepeatedly(Return(true)); |
| 2791 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2792 ProcessDataPacket(1, 1, kEntropyFlag); |
| 2793 ProcessFecPacket(4, 1, false, kEntropyFlag, NULL); |
| 2794 ProcessDataPacket(3, 3, !kEntropyFlag); |
| 2795 ProcessFecPacket(7, 3, false, kEntropyFlag, NULL); |
| 2796 EXPECT_EQ(146u, outgoing_ack()->received_info.entropy_hash); |
| 2797 } |
| 2798 |
2784 TEST_F(QuicConnectionTest, UpdateEntropyForReceivedPackets) { | 2799 TEST_F(QuicConnectionTest, UpdateEntropyForReceivedPackets) { |
2785 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillRepeatedly(Return(true)); | 2800 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillRepeatedly(Return(true)); |
2786 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2801 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
2787 ProcessDataPacket(1, 1, kEntropyFlag); | 2802 ProcessDataPacket(1, 1, kEntropyFlag); |
2788 ProcessDataPacket(5, 1, kEntropyFlag); | 2803 ProcessDataPacket(5, 1, kEntropyFlag); |
2789 ProcessDataPacket(4, 1, !kEntropyFlag); | 2804 ProcessDataPacket(4, 1, !kEntropyFlag); |
2790 EXPECT_EQ(34u, outgoing_ack()->received_info.entropy_hash); | 2805 EXPECT_EQ(34u, outgoing_ack()->received_info.entropy_hash); |
2791 // Make 4th packet my least unacked, and update entropy for 2, 3 packets. | 2806 // Make 4th packet my least unacked, and update entropy for 2, 3 packets. |
2792 QuicAckFrame ack = InitAckFrame(0, 4); | 2807 QuicAckFrame ack = InitAckFrame(0, 4); |
2793 QuicPacketEntropyHash kRandomEntropyHash = 129u; | 2808 QuicPacketEntropyHash kRandomEntropyHash = 129u; |
(...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3463 true); | 3478 true); |
3464 TestConnection client(guid_, IPEndPoint(), helper_.get(), writer_.get(), | 3479 TestConnection client(guid_, IPEndPoint(), helper_.get(), writer_.get(), |
3465 false); | 3480 false); |
3466 EXPECT_TRUE(client.sent_packet_manager().using_pacing()); | 3481 EXPECT_TRUE(client.sent_packet_manager().using_pacing()); |
3467 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); | 3482 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); |
3468 } | 3483 } |
3469 | 3484 |
3470 } // namespace | 3485 } // namespace |
3471 } // namespace test | 3486 } // namespace test |
3472 } // namespace net | 3487 } // namespace net |
OLD | NEW |