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 1664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1675 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1675 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
1676 BlockOnNextWrite(); | 1676 BlockOnNextWrite(); |
1677 const string payload(payload_length, 'a'); | 1677 const string payload(payload_length, 'a'); |
1678 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, nullptr); | 1678 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, nullptr); |
1679 EXPECT_FALSE(creator->IsFecGroupOpen()); | 1679 EXPECT_FALSE(creator->IsFecGroupOpen()); |
1680 EXPECT_FALSE(creator->IsFecProtected()); | 1680 EXPECT_FALSE(creator->IsFecProtected()); |
1681 // Expect the first data packet and the fec packet to be queued. | 1681 // Expect the first data packet and the fec packet to be queued. |
1682 EXPECT_EQ(2u, connection_.NumQueuedPackets()); | 1682 EXPECT_EQ(2u, connection_.NumQueuedPackets()); |
1683 } | 1683 } |
1684 | 1684 |
1685 TEST_P(QuicConnectionTest, AbandonFECFromCongestionWindow) { | 1685 TEST_P(QuicConnectionTest, RemoveFECFromInflightOnRetransmissionTimeout) { |
| 1686 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
1686 EXPECT_TRUE(QuicConnectionPeer::GetPacketCreator( | 1687 EXPECT_TRUE(QuicConnectionPeer::GetPacketCreator( |
1687 &connection_)->IsFecEnabled()); | 1688 &connection_)->IsFecEnabled()); |
| 1689 QuicSentPacketManager* manager = |
| 1690 QuicConnectionPeer::GetSentPacketManager(&connection_); |
| 1691 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager)); |
1688 | 1692 |
1689 // 1 Data and 1 FEC packet. | 1693 // 1 Data and 1 FEC packet. |
1690 EXPECT_CALL(*send_algorithm_, | 1694 EXPECT_CALL(*send_algorithm_, |
1691 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(2); | 1695 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(2); |
1692 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, nullptr); | 1696 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, nullptr); |
| 1697 size_t data_and_fec = QuicSentPacketManagerPeer::GetBytesInFlight(manager); |
| 1698 EXPECT_LT(0u, data_and_fec); |
1693 | 1699 |
1694 const QuicTime::Delta retransmission_time = | 1700 clock_.AdvanceTime(DefaultRetransmissionTime()); |
1695 QuicTime::Delta::FromMilliseconds(5000); | |
1696 clock_.AdvanceTime(retransmission_time); | |
1697 | 1701 |
1698 // Abandon FEC packet and data packet. | 1702 // On RTO, both data and FEC packets are removed from inflight, |
| 1703 // and retransmission of the data (but not FEC) gets added into the inflight. |
1699 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); | 1704 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
1700 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 1705 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
1701 EXPECT_CALL(visitor_, OnCanWrite()); | 1706 connection_.GetRetransmissionAlarm()->Fire(); |
1702 connection_.OnRetransmissionTimeout(); | 1707 ; |
| 1708 |
| 1709 size_t data_only = QuicSentPacketManagerPeer::GetBytesInFlight(manager); |
| 1710 EXPECT_LT(0u, data_only); |
| 1711 EXPECT_GE(data_and_fec, 2 * data_only); |
| 1712 |
| 1713 // Receive ack for the retransmission. No data should be outstanding. |
| 1714 QuicAckFrame ack = InitAckFrame(3); |
| 1715 NackPacket(1, &ack); |
| 1716 NackPacket(2, &ack); |
| 1717 SequenceNumberSet lost_packets; |
| 1718 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
| 1719 .WillOnce(Return(lost_packets)); |
| 1720 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 1721 ProcessAckPacket(&ack); |
| 1722 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager)); |
| 1723 |
| 1724 // Ensure the alarm is not set since all packets have been acked or abandoned. |
| 1725 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); |
| 1726 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager)); |
1703 } | 1727 } |
1704 | 1728 |
1705 TEST_P(QuicConnectionTest, DontAbandonAckedFEC) { | 1729 TEST_P(QuicConnectionTest, RemoveFECFromInflightOnLossRetransmission) { |
1706 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1730 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
1707 EXPECT_TRUE(QuicConnectionPeer::GetPacketCreator( | 1731 EXPECT_TRUE(QuicConnectionPeer::GetPacketCreator( |
1708 &connection_)->IsFecEnabled()); | 1732 &connection_)->IsFecEnabled()); |
| 1733 QuicSentPacketManager* manager = |
| 1734 QuicConnectionPeer::GetSentPacketManager(&connection_); |
1709 | 1735 |
1710 // 3 Data and 3 FEC packets. | 1736 // 1 Data packet and 1 FEC packet, followed by more data to trigger NACKs. |
1711 EXPECT_CALL(*send_algorithm_, | 1737 EXPECT_CALL(*send_algorithm_, |
1712 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(6); | 1738 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(6); |
1713 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, nullptr); | 1739 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, nullptr); |
1714 // Send some more data afterwards to ensure early retransmit doesn't trigger. | 1740 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, nullptr); |
1715 connection_.SendStreamDataWithStringWithFec(3, "foo", 3, !kFin, nullptr); | 1741 connection_.SendStreamDataWithString(3, "foo", 6, !kFin, nullptr); |
1716 connection_.SendStreamDataWithStringWithFec(3, "foo", 6, !kFin, nullptr); | 1742 connection_.SendStreamDataWithString(3, "foo", 9, !kFin, nullptr); |
| 1743 connection_.SendStreamDataWithString(3, "foo", 12, !kFin, nullptr); |
| 1744 size_t multiple_data_and_fec = |
| 1745 QuicSentPacketManagerPeer::GetBytesInFlight(manager); |
| 1746 EXPECT_LT(0u, multiple_data_and_fec); |
1717 | 1747 |
1718 QuicAckFrame ack_fec = InitAckFrame(2); | 1748 // Ack data packets, and NACK 1 data packet and FEC packet. Triggers |
1719 // Data packet missing. | 1749 // NACK-based loss detection of data and FEC packet, but only data is |
1720 // TODO(ianswett): Note that this is not a sensible ack, since if the FEC was | 1750 // retransmitted and considered oustanding. |
1721 // received, it would cause the covered packet to be acked as well. | 1751 QuicAckFrame ack = InitAckFrame(6); |
1722 NackPacket(1, &ack_fec); | 1752 NackPacket(2, &ack); |
| 1753 NackPacket(3, &ack); |
| 1754 SequenceNumberSet lost_packets; |
| 1755 lost_packets.insert(2); |
| 1756 lost_packets.insert(3); |
| 1757 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
| 1758 .WillOnce(Return(lost_packets)); |
1723 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 1759 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
1724 ProcessAckPacket(&ack_fec); | 1760 EXPECT_CALL(*send_algorithm_, |
1725 clock_.AdvanceTime(DefaultRetransmissionTime()); | 1761 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(1); |
| 1762 ProcessAckPacket(&ack); |
| 1763 size_t data_only = QuicSentPacketManagerPeer::GetBytesInFlight(manager); |
| 1764 EXPECT_GT(multiple_data_and_fec, data_only); |
| 1765 EXPECT_LT(0u, data_only); |
1726 | 1766 |
1727 // Don't abandon the acked FEC packet, but it will abandon 2 the subsequent | 1767 // Receive ack for the retransmission. No data should be outstanding. |
1728 // FEC packets. | 1768 QuicAckFrame ack2 = InitAckFrame(7); |
1729 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); | 1769 NackPacket(2, &ack2); |
1730 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3); | 1770 NackPacket(3, &ack2); |
1731 connection_.GetRetransmissionAlarm()->Fire(); | 1771 SequenceNumberSet lost_packets2; |
| 1772 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
| 1773 .WillOnce(Return(lost_packets2)); |
| 1774 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 1775 ProcessAckPacket(&ack2); |
| 1776 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager)); |
1732 } | 1777 } |
1733 | 1778 |
1734 TEST_P(QuicConnectionTest, AbandonAllFEC) { | 1779 TEST_P(QuicConnectionTest, NoTLPForFECPacket) { |
| 1780 // Turn on TLP for this test. |
| 1781 QuicSentPacketManagerPeer::SetMaxTailLossProbes( |
| 1782 QuicConnectionPeer::GetSentPacketManager(&connection_), 1); |
| 1783 |
1735 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1784 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
1736 EXPECT_TRUE(QuicConnectionPeer::GetPacketCreator( | 1785 EXPECT_TRUE(QuicConnectionPeer::GetPacketCreator( |
1737 &connection_)->IsFecEnabled()); | 1786 &connection_)->IsFecEnabled()); |
| 1787 QuicSentPacketManager* manager = |
| 1788 QuicConnectionPeer::GetSentPacketManager(&connection_); |
1738 | 1789 |
1739 // 3 Data and 3 FEC packet. | 1790 // 1 Data packet and 1 FEC packet. |
1740 EXPECT_CALL(*send_algorithm_, | 1791 EXPECT_CALL(*send_algorithm_, |
1741 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(6); | 1792 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(2); |
1742 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, nullptr); | 1793 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, nullptr); |
1743 // Send some more data afterwards to ensure early retransmit doesn't trigger. | |
1744 connection_.SendStreamDataWithStringWithFec(3, "foo", 3, !kFin, nullptr); | |
1745 // Advance the time so not all the FEC packets are abandoned. | |
1746 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); | |
1747 connection_.SendStreamDataWithStringWithFec(3, "foo", 6, !kFin, nullptr); | |
1748 | 1794 |
1749 QuicAckFrame ack_fec = InitAckFrame(5); | 1795 // Ack data packet, but not FEC packet. |
1750 // Ack all data packets, but no fec packets. | 1796 QuicAckFrame ack = InitAckFrame(1); |
1751 NackPacket(2, &ack_fec); | 1797 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
1752 NackPacket(4, &ack_fec); | 1798 ProcessAckPacket(&ack); |
1753 | 1799 |
1754 // Lose the first FEC packet and ack the three data packets. | 1800 // No TLP alarm for FEC, so when retransmission alarm fires, it is an RTO. |
1755 SequenceNumberSet lost_packets; | 1801 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); |
1756 lost_packets.insert(2); | 1802 EXPECT_LT(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager)); |
1757 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) | 1803 QuicTime rto_time = connection_.GetRetransmissionAlarm()->deadline(); |
1758 .WillOnce(Return(lost_packets)); | 1804 EXPECT_NE(QuicTime::Zero(), rto_time); |
1759 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | |
1760 ProcessAckPacket(&ack_fec); | |
1761 | 1805 |
1762 clock_.AdvanceTime(DefaultRetransmissionTime().Subtract( | 1806 // Simulate the retransmission alarm firing. FEC packet is no longer |
1763 QuicTime::Delta::FromMilliseconds(1))); | 1807 // outstanding. |
1764 | |
1765 // Abandon all packets | |
1766 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(false)); | 1808 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(false)); |
| 1809 clock_.AdvanceTime(rto_time.Subtract(clock_.Now())); |
1767 connection_.GetRetransmissionAlarm()->Fire(); | 1810 connection_.GetRetransmissionAlarm()->Fire(); |
1768 | |
1769 // Ensure the alarm is not set since all packets have been abandoned. | |
1770 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); | 1811 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); |
| 1812 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager)); |
1771 } | 1813 } |
1772 | 1814 |
1773 TEST_P(QuicConnectionTest, FramePacking) { | 1815 TEST_P(QuicConnectionTest, FramePacking) { |
1774 CongestionBlockWrites(); | 1816 CongestionBlockWrites(); |
1775 | 1817 |
1776 // Send an ack and two stream frames in 1 packet by queueing them. | 1818 // Send an ack and two stream frames in 1 packet by queueing them. |
1777 connection_.SendAck(); | 1819 connection_.SendAck(); |
1778 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( | 1820 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( |
1779 IgnoreResult(InvokeWithoutArgs(&connection_, | 1821 IgnoreResult(InvokeWithoutArgs(&connection_, |
1780 &TestConnection::SendStreamData3)), | 1822 &TestConnection::SendStreamData3)), |
(...skipping 1238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3019 // causing no connection close packet to be sent. | 3061 // causing no connection close packet to be sent. |
3020 ValueRestore<bool> old_flag(&FLAGS_quic_allow_silent_close, true); | 3062 ValueRestore<bool> old_flag(&FLAGS_quic_allow_silent_close, true); |
3021 EXPECT_TRUE(connection_.connected()); | 3063 EXPECT_TRUE(connection_.connected()); |
3022 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _, _)); | 3064 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _, _)); |
3023 QuicConfig config; | 3065 QuicConfig config; |
3024 | 3066 |
3025 // Create a handshake message that also enables silent close. | 3067 // Create a handshake message that also enables silent close. |
3026 CryptoHandshakeMessage msg; | 3068 CryptoHandshakeMessage msg; |
3027 string error_details; | 3069 string error_details; |
3028 QuicConfig client_config; | 3070 QuicConfig client_config; |
3029 client_config.SetInitialFlowControlWindowToSend( | |
3030 kInitialSessionFlowControlWindowForTest); | |
3031 client_config.SetInitialStreamFlowControlWindowToSend( | 3071 client_config.SetInitialStreamFlowControlWindowToSend( |
3032 kInitialStreamFlowControlWindowForTest); | 3072 kInitialStreamFlowControlWindowForTest); |
3033 client_config.SetInitialSessionFlowControlWindowToSend( | 3073 client_config.SetInitialSessionFlowControlWindowToSend( |
3034 kInitialSessionFlowControlWindowForTest); | 3074 kInitialSessionFlowControlWindowForTest); |
3035 client_config.SetIdleConnectionStateLifetime( | 3075 client_config.SetIdleConnectionStateLifetime( |
3036 QuicTime::Delta::FromSeconds(kDefaultIdleTimeoutSecs), | 3076 QuicTime::Delta::FromSeconds(kDefaultIdleTimeoutSecs), |
3037 QuicTime::Delta::FromSeconds(kDefaultIdleTimeoutSecs)); | 3077 QuicTime::Delta::FromSeconds(kDefaultIdleTimeoutSecs)); |
3038 client_config.ToHandshakeMessage(&msg); | 3078 client_config.ToHandshakeMessage(&msg); |
3039 const QuicErrorCode error = | 3079 const QuicErrorCode error = |
3040 config.ProcessPeerHello(msg, CLIENT, &error_details); | 3080 config.ProcessPeerHello(msg, CLIENT, &error_details); |
(...skipping 1257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4298 // Regression test for b/18594622 | 4338 // Regression test for b/18594622 |
4299 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); | 4339 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); |
4300 EXPECT_DFATAL( | 4340 EXPECT_DFATAL( |
4301 connection_.SendStreamDataWithString(3, "", 0, !kFin, delegate.get()), | 4341 connection_.SendStreamDataWithString(3, "", 0, !kFin, delegate.get()), |
4302 "Attempt to send empty stream frame"); | 4342 "Attempt to send empty stream frame"); |
4303 } | 4343 } |
4304 | 4344 |
4305 } // namespace | 4345 } // namespace |
4306 } // namespace test | 4346 } // namespace test |
4307 } // namespace net | 4347 } // namespace net |
OLD | NEW |