| 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" |
| 11 #include "net/quic/congestion_control/receive_algorithm_interface.h" | 11 #include "net/quic/congestion_control/receive_algorithm_interface.h" |
| 12 #include "net/quic/congestion_control/send_algorithm_interface.h" | 12 #include "net/quic/congestion_control/send_algorithm_interface.h" |
| 13 #include "net/quic/crypto/null_encrypter.h" | 13 #include "net/quic/crypto/null_encrypter.h" |
| 14 #include "net/quic/crypto/quic_decrypter.h" | 14 #include "net/quic/crypto/quic_decrypter.h" |
| 15 #include "net/quic/crypto/quic_encrypter.h" | 15 #include "net/quic/crypto/quic_encrypter.h" |
| 16 #include "net/quic/crypto/quic_random.h" | |
| 17 #include "net/quic/quic_protocol.h" | 16 #include "net/quic/quic_protocol.h" |
| 18 #include "net/quic/quic_sent_packet_manager.h" | 17 #include "net/quic/quic_sent_packet_manager.h" |
| 19 #include "net/quic/quic_utils.h" | 18 #include "net/quic/quic_utils.h" |
| 20 #include "net/quic/test_tools/mock_clock.h" | 19 #include "net/quic/test_tools/mock_clock.h" |
| 21 #include "net/quic/test_tools/mock_random.h" | 20 #include "net/quic/test_tools/mock_random.h" |
| 22 #include "net/quic/test_tools/quic_connection_peer.h" | 21 #include "net/quic/test_tools/quic_connection_peer.h" |
| 23 #include "net/quic/test_tools/quic_framer_peer.h" | 22 #include "net/quic/test_tools/quic_framer_peer.h" |
| 24 #include "net/quic/test_tools/quic_packet_creator_peer.h" | 23 #include "net/quic/test_tools/quic_packet_creator_peer.h" |
| 25 #include "net/quic/test_tools/quic_test_utils.h" | 24 #include "net/quic/test_tools/quic_test_utils.h" |
| 26 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 TestPacketWriter* writer_; | 499 TestPacketWriter* writer_; |
| 501 | 500 |
| 502 DISALLOW_COPY_AND_ASSIGN(TestConnection); | 501 DISALLOW_COPY_AND_ASSIGN(TestConnection); |
| 503 }; | 502 }; |
| 504 | 503 |
| 505 class QuicConnectionTest : public ::testing::TestWithParam<bool> { | 504 class QuicConnectionTest : public ::testing::TestWithParam<bool> { |
| 506 protected: | 505 protected: |
| 507 QuicConnectionTest() | 506 QuicConnectionTest() |
| 508 : guid_(42), | 507 : guid_(42), |
| 509 framer_(QuicSupportedVersions(), QuicTime::Zero(), false), | 508 framer_(QuicSupportedVersions(), QuicTime::Zero(), false), |
| 510 creator_(guid_, &framer_, QuicRandom::GetInstance(), false), | 509 creator_(guid_, &framer_, &random_generator_, false), |
| 511 send_algorithm_(new StrictMock<MockSendAlgorithm>), | 510 send_algorithm_(new StrictMock<MockSendAlgorithm>), |
| 512 helper_(new TestConnectionHelper(&clock_, &random_generator_)), | 511 helper_(new TestConnectionHelper(&clock_, &random_generator_)), |
| 513 writer_(new TestPacketWriter()), | 512 writer_(new TestPacketWriter()), |
| 514 connection_(guid_, IPEndPoint(), helper_.get(), writer_.get(), false), | 513 connection_(guid_, IPEndPoint(), helper_.get(), writer_.get(), false), |
| 515 frame1_(1, false, 0, MakeIOVector(data1)), | 514 frame1_(1, false, 0, MakeIOVector(data1)), |
| 516 frame2_(1, false, 3, MakeIOVector(data2)), | 515 frame2_(1, false, 3, MakeIOVector(data2)), |
| 517 accept_packet_(true) { | 516 accept_packet_(true) { |
| 518 connection_.set_visitor(&visitor_); | 517 connection_.set_visitor(&visitor_); |
| 519 connection_.SetSendAlgorithm(send_algorithm_); | 518 connection_.SetSendAlgorithm(send_algorithm_); |
| 520 framer_.set_received_entropy_calculator(&entropy_calculator_); | 519 framer_.set_received_entropy_calculator(&entropy_calculator_); |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 913 QuicPacketSequenceNumber num_packets = 256 * 2 + 1; | 912 QuicPacketSequenceNumber num_packets = 256 * 2 + 1; |
| 914 for (QuicPacketSequenceNumber i = 0; i < num_packets; ++i) { | 913 for (QuicPacketSequenceNumber i = 0; i < num_packets; ++i) { |
| 915 SendStreamDataToPeer(1, "foo", i * 3, !kFin, NULL); | 914 SendStreamDataToPeer(1, "foo", i * 3, !kFin, NULL); |
| 916 } | 915 } |
| 917 | 916 |
| 918 QuicAckFrame frame(num_packets, QuicTime::Zero(), 1); | 917 QuicAckFrame frame(num_packets, QuicTime::Zero(), 1); |
| 919 // Create an ack with 256 nacks, none adjacent to one another. | 918 // Create an ack with 256 nacks, none adjacent to one another. |
| 920 for (QuicPacketSequenceNumber i = 1; i <= 256; ++i) { | 919 for (QuicPacketSequenceNumber i = 1; i <= 256; ++i) { |
| 921 frame.received_info.missing_packets.insert(i * 2); | 920 frame.received_info.missing_packets.insert(i * 2); |
| 922 } | 921 } |
| 922 frame.received_info.entropy_hash = 0; |
| 923 EXPECT_CALL(entropy_calculator_, | 923 EXPECT_CALL(entropy_calculator_, |
| 924 EntropyHash(511)).WillOnce(testing::Return(0)); | 924 EntropyHash(511)).WillOnce(testing::Return(0)); |
| 925 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(256); | 925 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(256); |
| 926 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(10); | 926 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(10); |
| 927 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(10); | 927 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(10); |
| 928 ProcessAckPacket(&frame); | 928 ProcessAckPacket(&frame); |
| 929 | 929 |
| 930 QuicReceivedPacketManager* received_packet_manager = | 930 QuicReceivedPacketManager* received_packet_manager = |
| 931 QuicConnectionPeer::GetReceivedPacketManager(&connection_); | 931 QuicConnectionPeer::GetReceivedPacketManager(&connection_); |
| 932 // A truncated ack will not have the true largest observed. | 932 // A truncated ack will not have the true largest observed. |
| 933 EXPECT_GT(num_packets, | 933 EXPECT_GT(num_packets, |
| 934 received_packet_manager->peer_largest_observed_packet()); | 934 received_packet_manager->peer_largest_observed_packet()); |
| 935 | 935 |
| 936 frame.received_info.missing_packets.erase(192); | 936 frame.received_info.missing_packets.erase(192); |
| 937 frame.received_info.entropy_hash = 2; |
| 937 | 938 |
| 938 // Removing one missing packet allows us to ack 192 and one more range. | 939 // Removing one missing packet allows us to ack 192 and one more range. |
| 939 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(2); | 940 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(2); |
| 940 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(10); | 941 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(10); |
| 941 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(10); | 942 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(10); |
| 942 ProcessAckPacket(&frame); | 943 ProcessAckPacket(&frame); |
| 943 EXPECT_EQ(num_packets, | 944 EXPECT_EQ(num_packets, |
| 944 received_packet_manager->peer_largest_observed_packet()); | 945 received_packet_manager->peer_largest_observed_packet()); |
| 945 } | 946 } |
| 946 | 947 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1017 | 1018 |
| 1018 ProcessAckPacket(&frame2); | 1019 ProcessAckPacket(&frame2); |
| 1019 // Now if the peer sends an ack which still reports the retransmitted packet | 1020 // Now if the peer sends an ack which still reports the retransmitted packet |
| 1020 // as missing, then that will count as a packet which instigates an ack. | 1021 // as missing, then that will count as a packet which instigates an ack. |
| 1021 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)); | 1022 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)); |
| 1022 ProcessAckPacket(&frame2); | 1023 ProcessAckPacket(&frame2); |
| 1023 ProcessAckPacket(&frame2); | 1024 ProcessAckPacket(&frame2); |
| 1024 | 1025 |
| 1025 // But an ack with no missing packets will not send an ack. | 1026 // But an ack with no missing packets will not send an ack. |
| 1026 frame2.received_info.missing_packets.clear(); | 1027 frame2.received_info.missing_packets.clear(); |
| 1028 frame2.received_info.entropy_hash = |
| 1029 QuicConnectionPeer::GetSentEntropyHash(&connection_, retransmission); |
| 1027 ProcessAckPacket(&frame2); | 1030 ProcessAckPacket(&frame2); |
| 1028 ProcessAckPacket(&frame2); | 1031 ProcessAckPacket(&frame2); |
| 1029 } | 1032 } |
| 1030 | 1033 |
| 1031 TEST_F(QuicConnectionTest, LeastUnackedLower) { | 1034 TEST_F(QuicConnectionTest, LeastUnackedLower) { |
| 1032 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1035 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1033 | 1036 |
| 1034 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); | 1037 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); |
| 1035 SendStreamDataToPeer(1, "bar", 3, !kFin, NULL); | 1038 SendStreamDataToPeer(1, "bar", 3, !kFin, NULL); |
| 1036 SendStreamDataToPeer(1, "eep", 6, !kFin, NULL); | 1039 SendStreamDataToPeer(1, "eep", 6, !kFin, NULL); |
| (...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1646 QuicConnectionPeer::GetSentEntropyHash(&connection_, 1); | 1649 QuicConnectionPeer::GetSentEntropyHash(&connection_, 1); |
| 1647 // The first nack should trigger a fast retransmission, but we'll be | 1650 // The first nack should trigger a fast retransmission, but we'll be |
| 1648 // write blocked, so the packet will be queued. | 1651 // write blocked, so the packet will be queued. |
| 1649 writer_->set_blocked(true); | 1652 writer_->set_blocked(true); |
| 1650 | 1653 |
| 1651 ProcessAckPacket(&nack_two); | 1654 ProcessAckPacket(&nack_two); |
| 1652 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 1655 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 1653 | 1656 |
| 1654 // Now, ack the previous transmission. | 1657 // Now, ack the previous transmission. |
| 1655 QuicAckFrame ack_all(3, QuicTime::Zero(), 0); | 1658 QuicAckFrame ack_all(3, QuicTime::Zero(), 0); |
| 1656 nack_two.received_info.entropy_hash = | 1659 ack_all.received_info.entropy_hash = |
| 1657 QuicConnectionPeer::GetSentEntropyHash(&connection_, 3); | 1660 QuicConnectionPeer::GetSentEntropyHash(&connection_, 3); |
| 1658 ProcessAckPacket(&ack_all); | 1661 ProcessAckPacket(&ack_all); |
| 1659 | 1662 |
| 1660 // Unblock the socket and attempt to send the queued packets. However, | 1663 // Unblock the socket and attempt to send the queued packets. However, |
| 1661 // since the previous transmission has been acked, we will not | 1664 // since the previous transmission has been acked, we will not |
| 1662 // send the retransmission. | 1665 // send the retransmission. |
| 1663 EXPECT_CALL(*send_algorithm_, | 1666 EXPECT_CALL(*send_algorithm_, |
| 1664 OnPacketSent(_, _, _, _, _)).Times(0); | 1667 OnPacketSent(_, _, _, _, _)).Times(0); |
| 1665 | 1668 |
| 1666 writer_->set_blocked(false); | 1669 writer_->set_blocked(false); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1788 EXPECT_EQ(5u, last_packet); | 1791 EXPECT_EQ(5u, last_packet); |
| 1789 SendStreamDataToPeer(3, "foo", 3, !kFin, &last_packet); // Packet 6 | 1792 SendStreamDataToPeer(3, "foo", 3, !kFin, &last_packet); // Packet 6 |
| 1790 EXPECT_EQ(6u, last_packet); | 1793 EXPECT_EQ(6u, last_packet); |
| 1791 | 1794 |
| 1792 // Client will ack packets 1, 2, [!3], 4, 5. | 1795 // Client will ack packets 1, 2, [!3], 4, 5. |
| 1793 QuicAckFrame frame1(5, QuicTime::Zero(), 0); | 1796 QuicAckFrame frame1(5, QuicTime::Zero(), 0); |
| 1794 frame1.received_info.missing_packets.insert(3); | 1797 frame1.received_info.missing_packets.insert(3); |
| 1795 frame1.received_info.entropy_hash = | 1798 frame1.received_info.entropy_hash = |
| 1796 QuicConnectionPeer::GetSentEntropyHash(&connection_, 5) ^ | 1799 QuicConnectionPeer::GetSentEntropyHash(&connection_, 5) ^ |
| 1797 QuicConnectionPeer::GetSentEntropyHash(&connection_, 3) ^ | 1800 QuicConnectionPeer::GetSentEntropyHash(&connection_, 3) ^ |
| 1798 QuicConnectionPeer::GetSentEntropyHash(&connection_, 1); | 1801 QuicConnectionPeer::GetSentEntropyHash(&connection_, 2); |
| 1799 | 1802 |
| 1800 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1803 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1801 | 1804 |
| 1802 ProcessAckPacket(&frame1); | 1805 ProcessAckPacket(&frame1); |
| 1803 | 1806 |
| 1804 // Now the client implicitly acks 3, and explicitly acks 6. | 1807 // Now the client implicitly acks 3, and explicitly acks 6. |
| 1805 QuicAckFrame frame2(6, QuicTime::Zero(), 0); | 1808 QuicAckFrame frame2(6, QuicTime::Zero(), 0); |
| 1806 frame2.received_info.entropy_hash = | 1809 frame2.received_info.entropy_hash = |
| 1807 QuicConnectionPeer::GetSentEntropyHash(&connection_, 6); | 1810 QuicConnectionPeer::GetSentEntropyHash(&connection_, 6); |
| 1808 | 1811 |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2123 // Ack packets might generate some other packets, which are not | 2126 // Ack packets might generate some other packets, which are not |
| 2124 // retransmissions. (More ack packets). | 2127 // retransmissions. (More ack packets). |
| 2125 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)) | 2128 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)) |
| 2126 .Times(AnyNumber()); | 2129 .Times(AnyNumber()); |
| 2127 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NACK_RETRANSMISSION, _)) | 2130 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NACK_RETRANSMISSION, _)) |
| 2128 .WillOnce(DoAll(SaveArg<1>(&nack_sequence_number), Return(true))); | 2131 .WillOnce(DoAll(SaveArg<1>(&nack_sequence_number), Return(true))); |
| 2129 QuicAckFrame ack(rto_sequence_number, QuicTime::Zero(), 0); | 2132 QuicAckFrame ack(rto_sequence_number, QuicTime::Zero(), 0); |
| 2130 // Ack the retransmitted packet. | 2133 // Ack the retransmitted packet. |
| 2131 ack.received_info.missing_packets.insert(original_sequence_number); | 2134 ack.received_info.missing_packets.insert(original_sequence_number); |
| 2132 ack.received_info.missing_packets.insert(rto_sequence_number); | 2135 ack.received_info.missing_packets.insert(rto_sequence_number); |
| 2133 ack.received_info.entropy_hash = QuicConnectionPeer::GetSentEntropyHash( | 2136 ack.received_info.entropy_hash = |
| 2134 &connection_, rto_sequence_number - 1); | 2137 QuicConnectionPeer::GetSentEntropyHash(&connection_, |
| 2138 rto_sequence_number - 1) ^ |
| 2139 QuicConnectionPeer::GetSentEntropyHash(&connection_, |
| 2140 original_sequence_number); |
| 2135 for (int i = 0; i < 3; i++) { | 2141 for (int i = 0; i < 3; i++) { |
| 2136 ProcessAckPacket(&ack); | 2142 ProcessAckPacket(&ack); |
| 2137 } | 2143 } |
| 2138 ASSERT_NE(0u, nack_sequence_number); | 2144 ASSERT_NE(0u, nack_sequence_number); |
| 2139 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission( | 2145 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission( |
| 2140 &connection_, rto_sequence_number)); | 2146 &connection_, rto_sequence_number)); |
| 2141 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission( | 2147 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission( |
| 2142 &connection_, nack_sequence_number)); | 2148 &connection_, nack_sequence_number)); |
| 2143 EXPECT_TRUE(QuicConnectionPeer::IsRetransmission( | 2149 EXPECT_TRUE(QuicConnectionPeer::IsRetransmission( |
| 2144 &connection_, nack_sequence_number)); | 2150 &connection_, nack_sequence_number)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2163 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); | 2169 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); |
| 2164 connection_.SendStreamDataWithString(2, "bar", 0, !kFin, NULL); | 2170 connection_.SendStreamDataWithString(2, "bar", 0, !kFin, NULL); |
| 2165 QuicAlarm* retransmission_alarm = connection_.GetRetransmissionAlarm(); | 2171 QuicAlarm* retransmission_alarm = connection_.GetRetransmissionAlarm(); |
| 2166 EXPECT_TRUE(retransmission_alarm->IsSet()); | 2172 EXPECT_TRUE(retransmission_alarm->IsSet()); |
| 2167 | 2173 |
| 2168 // Advance the time right before the RTO, then receive an ack for the first | 2174 // Advance the time right before the RTO, then receive an ack for the first |
| 2169 // packet to delay the RTO. | 2175 // packet to delay the RTO. |
| 2170 clock_.AdvanceTime(DefaultRetransmissionTime()); | 2176 clock_.AdvanceTime(DefaultRetransmissionTime()); |
| 2171 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(1); | 2177 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(1); |
| 2172 QuicAckFrame ack(1, QuicTime::Zero(), 0); | 2178 QuicAckFrame ack(1, QuicTime::Zero(), 0); |
| 2179 ack.received_info.entropy_hash = |
| 2180 QuicConnectionPeer::GetSentEntropyHash(&connection_, 1); |
| 2173 ProcessAckPacket(&ack); | 2181 ProcessAckPacket(&ack); |
| 2174 EXPECT_TRUE(retransmission_alarm->IsSet()); | 2182 EXPECT_TRUE(retransmission_alarm->IsSet()); |
| 2175 | 2183 |
| 2176 // Move forward past the original RTO and ensure the RTO is still pending. | 2184 // Move forward past the original RTO and ensure the RTO is still pending. |
| 2177 clock_.AdvanceTime(DefaultRetransmissionTime()); | 2185 clock_.AdvanceTime(DefaultRetransmissionTime()); |
| 2178 | 2186 |
| 2179 // Ensure the second packet gets retransmitted when it finally fires. | 2187 // Ensure the second packet gets retransmitted when it finally fires. |
| 2180 EXPECT_TRUE(retransmission_alarm->IsSet()); | 2188 EXPECT_TRUE(retransmission_alarm->IsSet()); |
| 2181 EXPECT_GE(retransmission_alarm->deadline(), clock_.ApproximateNow()); | 2189 EXPECT_GE(retransmission_alarm->deadline(), clock_.ApproximateNow()); |
| 2182 clock_.AdvanceTime(DefaultRetransmissionTime()); | 2190 clock_.AdvanceTime(DefaultRetransmissionTime()); |
| (...skipping 954 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3137 // Create a delegate which we expect to be called. | 3145 // Create a delegate which we expect to be called. |
| 3138 MockAckNotifierDelegate delegate; | 3146 MockAckNotifierDelegate delegate; |
| 3139 EXPECT_CALL(delegate, OnAckNotification()).Times(1);; | 3147 EXPECT_CALL(delegate, OnAckNotification()).Times(1);; |
| 3140 | 3148 |
| 3141 // Send some data, which will register the delegate to be notified. | 3149 // Send some data, which will register the delegate to be notified. |
| 3142 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, &delegate); | 3150 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, &delegate); |
| 3143 | 3151 |
| 3144 // Process an ACK from the server which should trigger the callback. | 3152 // Process an ACK from the server which should trigger the callback. |
| 3145 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(1); | 3153 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(1); |
| 3146 QuicAckFrame frame(1, QuicTime::Zero(), 0); | 3154 QuicAckFrame frame(1, QuicTime::Zero(), 0); |
| 3155 frame.received_info.entropy_hash = |
| 3156 QuicConnectionPeer::GetSentEntropyHash(&connection_, 1); |
| 3147 ProcessAckPacket(&frame); | 3157 ProcessAckPacket(&frame); |
| 3148 } | 3158 } |
| 3149 | 3159 |
| 3150 TEST_F(QuicConnectionTest, AckNotifierFailToTriggerCallback) { | 3160 TEST_F(QuicConnectionTest, AckNotifierFailToTriggerCallback) { |
| 3151 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3161 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3152 | 3162 |
| 3153 // Create a delegate which we don't expect to be called. | 3163 // Create a delegate which we don't expect to be called. |
| 3154 MockAckNotifierDelegate delegate; | 3164 MockAckNotifierDelegate delegate; |
| 3155 EXPECT_CALL(delegate, OnAckNotification()).Times(0);; | 3165 EXPECT_CALL(delegate, OnAckNotification()).Times(0);; |
| 3156 | 3166 |
| 3157 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(2); | 3167 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(2); |
| 3158 | 3168 |
| 3159 // Send some data, which will register the delegate to be notified. This will | 3169 // Send some data, which will register the delegate to be notified. This will |
| 3160 // not be ACKed and so the delegate should never be called. | 3170 // not be ACKed and so the delegate should never be called. |
| 3161 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, &delegate); | 3171 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, &delegate); |
| 3162 | 3172 |
| 3163 // Send some other data which we will ACK. | 3173 // Send some other data which we will ACK. |
| 3164 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); | 3174 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); |
| 3165 connection_.SendStreamDataWithString(1, "bar", 0, !kFin, NULL); | 3175 connection_.SendStreamDataWithString(1, "bar", 0, !kFin, NULL); |
| 3166 | 3176 |
| 3167 // Now we receive ACK for packets 2 and 3, but importantly missing packet 1 | 3177 // Now we receive ACK for packets 2 and 3, but importantly missing packet 1 |
| 3168 // which we registered to be notified about. | 3178 // which we registered to be notified about. |
| 3169 QuicAckFrame frame(3, QuicTime::Zero(), 0); | 3179 QuicAckFrame frame(3, QuicTime::Zero(), 0); |
| 3170 frame.received_info.missing_packets.insert(1); | 3180 frame.received_info.missing_packets.insert(1); |
| 3181 frame.received_info.entropy_hash = |
| 3182 QuicConnectionPeer::GetSentEntropyHash(&connection_, 3) ^ |
| 3183 QuicConnectionPeer::GetSentEntropyHash(&connection_, 1); |
| 3171 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)); | 3184 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)); |
| 3172 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)); | 3185 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)); |
| 3173 ProcessAckPacket(&frame); | 3186 ProcessAckPacket(&frame); |
| 3174 } | 3187 } |
| 3175 | 3188 |
| 3176 TEST_F(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) { | 3189 TEST_F(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) { |
| 3177 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3190 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3178 | 3191 |
| 3179 // Create a delegate which we expect to be called. | 3192 // Create a delegate which we expect to be called. |
| 3180 MockAckNotifierDelegate delegate; | 3193 MockAckNotifierDelegate delegate; |
| 3181 EXPECT_CALL(delegate, OnAckNotification()).Times(1);; | 3194 EXPECT_CALL(delegate, OnAckNotification()).Times(1);; |
| 3182 | 3195 |
| 3183 // In total expect ACKs for all 4 packets. | 3196 // In total expect ACKs for all 4 packets. |
| 3184 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(4); | 3197 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(4); |
| 3185 | 3198 |
| 3186 // Send four packets, and register to be notified on ACK of packet 2. | 3199 // Send four packets, and register to be notified on ACK of packet 2. |
| 3187 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); | 3200 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); |
| 3188 connection_.SendStreamDataWithString(1, "bar", 0, !kFin, &delegate); | 3201 connection_.SendStreamDataWithString(1, "bar", 0, !kFin, &delegate); |
| 3189 connection_.SendStreamDataWithString(1, "baz", 0, !kFin, NULL); | 3202 connection_.SendStreamDataWithString(1, "baz", 0, !kFin, NULL); |
| 3190 connection_.SendStreamDataWithString(1, "qux", 0, !kFin, NULL); | 3203 connection_.SendStreamDataWithString(1, "qux", 0, !kFin, NULL); |
| 3191 | 3204 |
| 3192 // Now we receive ACK for packets 1, 3, and 4, which invokes fast retransmit. | 3205 // Now we receive ACK for packets 1, 3, and 4, which invokes fast retransmit. |
| 3193 QuicAckFrame frame(4, QuicTime::Zero(), 0); | 3206 QuicAckFrame frame(4, QuicTime::Zero(), 0); |
| 3194 frame.received_info.missing_packets.insert(2); | 3207 frame.received_info.missing_packets.insert(2); |
| 3208 frame.received_info.entropy_hash = |
| 3209 QuicConnectionPeer::GetSentEntropyHash(&connection_, 4) ^ |
| 3210 QuicConnectionPeer::GetSentEntropyHash(&connection_, 2) ^ |
| 3211 QuicConnectionPeer::GetSentEntropyHash(&connection_, 1); |
| 3195 EXPECT_CALL(*send_algorithm_, OnPacketLost(2, _)); | 3212 EXPECT_CALL(*send_algorithm_, OnPacketLost(2, _)); |
| 3196 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(2, _)); | 3213 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(2, _)); |
| 3197 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 3214 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| 3198 ProcessAckPacket(&frame); | 3215 ProcessAckPacket(&frame); |
| 3199 | 3216 |
| 3200 // Now we get an ACK for packet 5 (retransmitted packet 2), which should | 3217 // Now we get an ACK for packet 5 (retransmitted packet 2), which should |
| 3201 // trigger the callback. | 3218 // trigger the callback. |
| 3202 QuicAckFrame second_ack_frame(5, QuicTime::Zero(), 0); | 3219 QuicAckFrame second_ack_frame(5, QuicTime::Zero(), 0); |
| 3220 second_ack_frame.received_info.entropy_hash = |
| 3221 QuicConnectionPeer::GetSentEntropyHash(&connection_, 5); |
| 3203 ProcessAckPacket(&second_ack_frame); | 3222 ProcessAckPacket(&second_ack_frame); |
| 3204 } | 3223 } |
| 3205 | 3224 |
| 3206 // TODO(rjshade): Add a similar test that FEC recovery on peer (and resulting | 3225 // TODO(rjshade): Add a similar test that FEC recovery on peer (and resulting |
| 3207 // ACK) triggers notification on our end. | 3226 // ACK) triggers notification on our end. |
| 3208 TEST_F(QuicConnectionTest, AckNotifierCallbackAfterFECRecovery) { | 3227 TEST_F(QuicConnectionTest, AckNotifierCallbackAfterFECRecovery) { |
| 3209 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3228 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3210 EXPECT_CALL(visitor_, OnCanWrite()).Times(1).WillOnce(Return(true)); | 3229 EXPECT_CALL(visitor_, OnCanWrite()).Times(1).WillOnce(Return(true)); |
| 3211 | 3230 |
| 3212 // Create a delegate which we expect to be called. | 3231 // Create a delegate which we expect to be called. |
| 3213 MockAckNotifierDelegate delegate; | 3232 MockAckNotifierDelegate delegate; |
| 3214 EXPECT_CALL(delegate, OnAckNotification()).Times(1);; | 3233 EXPECT_CALL(delegate, OnAckNotification()).Times(1);; |
| 3215 | 3234 |
| 3216 // Expect ACKs for 1 packet. | 3235 // Expect ACKs for 1 packet. |
| 3217 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(1); | 3236 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(1); |
| 3218 | 3237 |
| 3219 // Send one packet, and register to be notified on ACK. | 3238 // Send one packet, and register to be notified on ACK. |
| 3220 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, &delegate); | 3239 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, &delegate); |
| 3221 | 3240 |
| 3222 // Ack packet gets dropped, but we receive an FEC packet that covers it. | 3241 // Ack packet gets dropped, but we receive an FEC packet that covers it. |
| 3223 // Should recover the Ack packet and trigger the notification callback. | 3242 // Should recover the Ack packet and trigger the notification callback. |
| 3224 QuicFrames frames; | 3243 QuicFrames frames; |
| 3225 | 3244 |
| 3226 QuicAckFrame ack_frame(1, QuicTime::Zero(), 0); | 3245 QuicAckFrame ack_frame(1, QuicTime::Zero(), 0); |
| 3246 ack_frame.received_info.entropy_hash = |
| 3247 QuicConnectionPeer::GetSentEntropyHash(&connection_, 1); |
| 3227 frames.push_back(QuicFrame(&ack_frame)); | 3248 frames.push_back(QuicFrame(&ack_frame)); |
| 3228 | 3249 |
| 3229 // Dummy stream frame to satisfy expectations set elsewhere. | 3250 // Dummy stream frame to satisfy expectations set elsewhere. |
| 3230 frames.push_back(QuicFrame(&frame1_)); | 3251 frames.push_back(QuicFrame(&frame1_)); |
| 3231 | 3252 |
| 3232 QuicPacketHeader ack_header; | 3253 QuicPacketHeader ack_header; |
| 3233 ack_header.public_header.guid = guid_; | 3254 ack_header.public_header.guid = guid_; |
| 3234 ack_header.public_header.reset_flag = false; | 3255 ack_header.public_header.reset_flag = false; |
| 3235 ack_header.public_header.version_flag = false; | 3256 ack_header.public_header.version_flag = false; |
| 3236 ack_header.entropy_flag = !kEntropyFlag; | 3257 ack_header.entropy_flag = !kEntropyFlag; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3316 true); | 3337 true); |
| 3317 TestConnection client(guid_, IPEndPoint(), helper_.get(), writer_.get(), | 3338 TestConnection client(guid_, IPEndPoint(), helper_.get(), writer_.get(), |
| 3318 false); | 3339 false); |
| 3319 EXPECT_TRUE(client.sent_packet_manager().using_pacing()); | 3340 EXPECT_TRUE(client.sent_packet_manager().using_pacing()); |
| 3320 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); | 3341 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); |
| 3321 } | 3342 } |
| 3322 | 3343 |
| 3323 } // namespace | 3344 } // namespace |
| 3324 } // namespace test | 3345 } // namespace test |
| 3325 } // namespace net | 3346 } // namespace net |
| OLD | NEW |