| 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 900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 911 | 911 |
| 912 QuicAckFrame frame(num_packets, QuicTime::Zero(), 1); | 912 QuicAckFrame frame(num_packets, QuicTime::Zero(), 1); |
| 913 // Create an ack with 256 nacks, none adjacent to one another. | 913 // Create an ack with 256 nacks, none adjacent to one another. |
| 914 for (QuicPacketSequenceNumber i = 1; i <= 256; ++i) { | 914 for (QuicPacketSequenceNumber i = 1; i <= 256; ++i) { |
| 915 frame.received_info.missing_packets.insert(i * 2); | 915 frame.received_info.missing_packets.insert(i * 2); |
| 916 } | 916 } |
| 917 frame.received_info.entropy_hash = 0; | 917 frame.received_info.entropy_hash = 0; |
| 918 EXPECT_CALL(entropy_calculator_, | 918 EXPECT_CALL(entropy_calculator_, |
| 919 EntropyHash(511)).WillOnce(testing::Return(0)); | 919 EntropyHash(511)).WillOnce(testing::Return(0)); |
| 920 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(256); | 920 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(256); |
| 921 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(10); | 921 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(2); |
| 922 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(10); | 922 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(2); |
| 923 ProcessAckPacket(&frame); | 923 ProcessAckPacket(&frame); |
| 924 | 924 |
| 925 QuicReceivedPacketManager* received_packet_manager = | 925 QuicReceivedPacketManager* received_packet_manager = |
| 926 QuicConnectionPeer::GetReceivedPacketManager(&connection_); | 926 QuicConnectionPeer::GetReceivedPacketManager(&connection_); |
| 927 // A truncated ack will not have the true largest observed. | 927 // A truncated ack will not have the true largest observed. |
| 928 EXPECT_GT(num_packets, | 928 EXPECT_GT(num_packets, |
| 929 received_packet_manager->peer_largest_observed_packet()); | 929 received_packet_manager->peer_largest_observed_packet()); |
| 930 | 930 |
| 931 frame.received_info.missing_packets.erase(192); | 931 frame.received_info.missing_packets.erase(192); |
| 932 frame.received_info.entropy_hash = 2; | 932 frame.received_info.entropy_hash = 2; |
| 933 | 933 |
| 934 // Removing one missing packet allows us to ack 192 and one more range. | 934 // Removing one missing packet allows us to ack 192 and one more range. |
| 935 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(2); | 935 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(2); |
| 936 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(10); | 936 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(2); |
| 937 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(10); | 937 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(2); |
| 938 ProcessAckPacket(&frame); | 938 ProcessAckPacket(&frame); |
| 939 EXPECT_EQ(num_packets, | 939 EXPECT_EQ(num_packets, |
| 940 received_packet_manager->peer_largest_observed_packet()); | 940 received_packet_manager->peer_largest_observed_packet()); |
| 941 } | 941 } |
| 942 | 942 |
| 943 TEST_F(QuicConnectionTest, AckReceiptCausesAckSendBadEntropy) { | 943 TEST_F(QuicConnectionTest, AckReceiptCausesAckSendBadEntropy) { |
| 944 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 944 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 945 | 945 |
| 946 ProcessPacket(1); | 946 ProcessPacket(1); |
| 947 // Delay sending, then queue up an ack. | 947 // Delay sending, then queue up an ack. |
| (...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1781 | 1781 |
| 1782 // Fire the alarms and ensure the connection is still write blocked. | 1782 // Fire the alarms and ensure the connection is still write blocked. |
| 1783 connection_.GetResumeWritesAlarm()->Fire(); | 1783 connection_.GetResumeWritesAlarm()->Fire(); |
| 1784 connection_.GetSendAlarm()->Fire(); | 1784 connection_.GetSendAlarm()->Fire(); |
| 1785 EXPECT_TRUE(QuicConnectionPeer::IsWriteBlocked(&connection_)); | 1785 EXPECT_TRUE(QuicConnectionPeer::IsWriteBlocked(&connection_)); |
| 1786 } | 1786 } |
| 1787 | 1787 |
| 1788 TEST_F(QuicConnectionTest, LimitPacketsPerNack) { | 1788 TEST_F(QuicConnectionTest, LimitPacketsPerNack) { |
| 1789 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1789 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1790 EXPECT_CALL(*send_algorithm_, OnPacketAcked(15, _, _)).Times(1); | 1790 EXPECT_CALL(*send_algorithm_, OnPacketAcked(15, _, _)).Times(1); |
| 1791 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(13); | 1791 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(4); |
| 1792 int offset = 0; | 1792 int offset = 0; |
| 1793 // Send packets 1 to 15. | 1793 // Send packets 1 to 15. |
| 1794 for (int i = 0; i < 15; ++i) { | 1794 for (int i = 0; i < 15; ++i) { |
| 1795 SendStreamDataToPeer(1, "foo", offset, !kFin, NULL); | 1795 SendStreamDataToPeer(1, "foo", offset, !kFin, NULL); |
| 1796 offset += 3; | 1796 offset += 3; |
| 1797 } | 1797 } |
| 1798 | 1798 |
| 1799 // Ack 15, nack 1-14. | 1799 // Ack 15, nack 1-14. |
| 1800 QuicAckFrame nack(15, QuicTime::Zero(), 0); | 1800 QuicAckFrame nack(15, QuicTime::Zero(), 0); |
| 1801 for (int i = 1; i < 15; ++i) { | 1801 for (int i = 1; i < 15; ++i) { |
| 1802 nack.received_info.missing_packets.insert(i); | 1802 nack.received_info.missing_packets.insert(i); |
| 1803 } | 1803 } |
| 1804 | 1804 |
| 1805 nack.received_info.entropy_hash = | 1805 nack.received_info.entropy_hash = |
| 1806 QuicConnectionPeer::GetSentEntropyHash(&connection_, 15) ^ | 1806 QuicConnectionPeer::GetSentEntropyHash(&connection_, 15) ^ |
| 1807 QuicConnectionPeer::GetSentEntropyHash(&connection_, 14); | 1807 QuicConnectionPeer::GetSentEntropyHash(&connection_, 14); |
| 1808 | 1808 |
| 1809 // 13 packets have been NACK'd 3 times, but we limit retransmissions to 10. | 1809 // 13 packets have been NACK'd 3 times, but we limit retransmissions to 2. |
| 1810 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(10); | 1810 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(2); |
| 1811 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(10); | 1811 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); |
| 1812 ProcessAckPacket(&nack); | 1812 ProcessAckPacket(&nack); |
| 1813 | 1813 |
| 1814 // The next call should trigger retransmitting 3 more packets, because 14 | 1814 // The next call should trigger retransmitting 2 more packets. |
| 1815 // only has 2 nacks so far. | 1815 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(2); |
| 1816 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(3); | 1816 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); |
| 1817 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3); | |
| 1818 ProcessAckPacket(&nack); | 1817 ProcessAckPacket(&nack); |
| 1819 } | 1818 } |
| 1820 | 1819 |
| 1821 // Test sending multiple acks from the connection to the session. | 1820 // Test sending multiple acks from the connection to the session. |
| 1822 TEST_F(QuicConnectionTest, MultipleAcks) { | 1821 TEST_F(QuicConnectionTest, MultipleAcks) { |
| 1823 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(6); | 1822 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(6); |
| 1824 QuicPacketSequenceNumber last_packet; | 1823 QuicPacketSequenceNumber last_packet; |
| 1825 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 | 1824 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 |
| 1826 EXPECT_EQ(1u, last_packet); | 1825 EXPECT_EQ(1u, last_packet); |
| 1827 SendStreamDataToPeer(3, "foo", 0, !kFin, &last_packet); // Packet 2 | 1826 SendStreamDataToPeer(3, "foo", 0, !kFin, &last_packet); // Packet 2 |
| (...skipping 1551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3379 true); | 3378 true); |
| 3380 TestConnection client(guid_, IPEndPoint(), helper_.get(), writer_.get(), | 3379 TestConnection client(guid_, IPEndPoint(), helper_.get(), writer_.get(), |
| 3381 false); | 3380 false); |
| 3382 EXPECT_TRUE(client.sent_packet_manager().using_pacing()); | 3381 EXPECT_TRUE(client.sent_packet_manager().using_pacing()); |
| 3383 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); | 3382 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); |
| 3384 } | 3383 } |
| 3385 | 3384 |
| 3386 } // namespace | 3385 } // namespace |
| 3387 } // namespace test | 3386 } // namespace test |
| 3388 } // namespace net | 3387 } // namespace net |
| OLD | NEW |