| 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 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 | 650 |
| 651 QuicVersion version() { | 651 QuicVersion version() { |
| 652 return GetParam(); | 652 return GetParam(); |
| 653 } | 653 } |
| 654 | 654 |
| 655 QuicAckFrame* outgoing_ack() { | 655 QuicAckFrame* outgoing_ack() { |
| 656 outgoing_ack_.reset(QuicConnectionPeer::CreateAckFrame(&connection_)); | 656 outgoing_ack_.reset(QuicConnectionPeer::CreateAckFrame(&connection_)); |
| 657 return outgoing_ack_.get(); | 657 return outgoing_ack_.get(); |
| 658 } | 658 } |
| 659 | 659 |
| 660 QuicStopWaitingFrame* stop_waiting() { |
| 661 stop_waiting_.reset( |
| 662 QuicConnectionPeer::CreateStopWaitingFrame(&connection_)); |
| 663 return stop_waiting_.get(); |
| 664 } |
| 665 |
| 660 QuicPacketSequenceNumber least_unacked() { | 666 QuicPacketSequenceNumber least_unacked() { |
| 661 if (version() <= QUIC_VERSION_15) { | |
| 662 if (writer_->ack_frames().empty()) { | |
| 663 return 0; | |
| 664 } | |
| 665 return writer_->ack_frames()[0].sent_info.least_unacked; | |
| 666 } | |
| 667 if (writer_->stop_waiting_frames().empty()) { | 667 if (writer_->stop_waiting_frames().empty()) { |
| 668 return 0; | 668 return 0; |
| 669 } | 669 } |
| 670 return writer_->stop_waiting_frames()[0].least_unacked; | 670 return writer_->stop_waiting_frames()[0].least_unacked; |
| 671 } | 671 } |
| 672 | 672 |
| 673 void use_tagging_decrypter() { | 673 void use_tagging_decrypter() { |
| 674 writer_->use_tagging_decrypter(); | 674 writer_->use_tagging_decrypter(); |
| 675 } | 675 } |
| 676 | 676 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 819 | 819 |
| 820 QuicPacketEntropyHash ProcessStopWaitingPacket(QuicStopWaitingFrame* frame) { | 820 QuicPacketEntropyHash ProcessStopWaitingPacket(QuicStopWaitingFrame* frame) { |
| 821 return ProcessFramePacket(QuicFrame(frame)); | 821 return ProcessFramePacket(QuicFrame(frame)); |
| 822 } | 822 } |
| 823 | 823 |
| 824 QuicPacketEntropyHash ProcessGoAwayPacket(QuicGoAwayFrame* frame) { | 824 QuicPacketEntropyHash ProcessGoAwayPacket(QuicGoAwayFrame* frame) { |
| 825 return ProcessFramePacket(QuicFrame(frame)); | 825 return ProcessFramePacket(QuicFrame(frame)); |
| 826 } | 826 } |
| 827 | 827 |
| 828 bool IsMissing(QuicPacketSequenceNumber number) { | 828 bool IsMissing(QuicPacketSequenceNumber number) { |
| 829 return IsAwaitingPacket(outgoing_ack()->received_info, number); | 829 return IsAwaitingPacket(*outgoing_ack(), number); |
| 830 } | 830 } |
| 831 | 831 |
| 832 QuicPacket* ConstructDataPacket(QuicPacketSequenceNumber number, | 832 QuicPacket* ConstructDataPacket(QuicPacketSequenceNumber number, |
| 833 QuicFecGroupNumber fec_group, | 833 QuicFecGroupNumber fec_group, |
| 834 bool entropy_flag) { | 834 bool entropy_flag) { |
| 835 header_.public_header.connection_id = connection_id_; | 835 header_.public_header.connection_id = connection_id_; |
| 836 header_.public_header.reset_flag = false; | 836 header_.public_header.reset_flag = false; |
| 837 header_.public_header.version_flag = false; | 837 header_.public_header.version_flag = false; |
| 838 header_.public_header.sequence_number_length = sequence_number_length_; | 838 header_.public_header.sequence_number_length = sequence_number_length_; |
| 839 header_.public_header.connection_id_length = connection_id_length_; | 839 header_.public_header.connection_id_length = connection_id_length_; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 | 882 |
| 883 QuicTime::Delta DefaultRetransmissionTime() { | 883 QuicTime::Delta DefaultRetransmissionTime() { |
| 884 return QuicTime::Delta::FromMilliseconds(kDefaultRetransmissionTimeMs); | 884 return QuicTime::Delta::FromMilliseconds(kDefaultRetransmissionTimeMs); |
| 885 } | 885 } |
| 886 | 886 |
| 887 QuicTime::Delta DefaultDelayedAckTime() { | 887 QuicTime::Delta DefaultDelayedAckTime() { |
| 888 return QuicTime::Delta::FromMilliseconds(kMinRetransmissionTimeMs/2); | 888 return QuicTime::Delta::FromMilliseconds(kMinRetransmissionTimeMs/2); |
| 889 } | 889 } |
| 890 | 890 |
| 891 // Initialize a frame acknowledging all packets up to largest_observed. | 891 // Initialize a frame acknowledging all packets up to largest_observed. |
| 892 const QuicAckFrame InitAckFrame(QuicPacketSequenceNumber largest_observed, | 892 const QuicAckFrame InitAckFrame(QuicPacketSequenceNumber largest_observed) { |
| 893 QuicPacketSequenceNumber least_unacked) { | 893 QuicAckFrame frame(MakeAckFrame(largest_observed)); |
| 894 QuicAckFrame frame(MakeAckFrame(largest_observed, least_unacked)); | |
| 895 if (largest_observed > 0) { | 894 if (largest_observed > 0) { |
| 896 frame.received_info.entropy_hash = | 895 frame.entropy_hash = |
| 897 QuicConnectionPeer::GetSentEntropyHash(&connection_, largest_observed); | 896 QuicConnectionPeer::GetSentEntropyHash(&connection_, |
| 897 largest_observed); |
| 898 } | 898 } |
| 899 return frame; | 899 return frame; |
| 900 } | 900 } |
| 901 | 901 |
| 902 const QuicStopWaitingFrame InitStopWaitingFrame( | 902 const QuicStopWaitingFrame InitStopWaitingFrame( |
| 903 QuicPacketSequenceNumber least_unacked) { | 903 QuicPacketSequenceNumber least_unacked) { |
| 904 QuicStopWaitingFrame frame; | 904 QuicStopWaitingFrame frame; |
| 905 frame.least_unacked = least_unacked; | 905 frame.least_unacked = least_unacked; |
| 906 return frame; | 906 return frame; |
| 907 } | 907 } |
| 908 // Explicitly nack a packet. | 908 // Explicitly nack a packet. |
| 909 void NackPacket(QuicPacketSequenceNumber missing, QuicAckFrame* frame) { | 909 void NackPacket(QuicPacketSequenceNumber missing, QuicAckFrame* frame) { |
| 910 frame->received_info.missing_packets.insert(missing); | 910 frame->missing_packets.insert(missing); |
| 911 frame->received_info.entropy_hash ^= | 911 frame->entropy_hash ^= |
| 912 QuicConnectionPeer::GetSentEntropyHash(&connection_, missing); | 912 QuicConnectionPeer::GetSentEntropyHash(&connection_, missing); |
| 913 if (missing > 1) { | 913 if (missing > 1) { |
| 914 frame->received_info.entropy_hash ^= | 914 frame->entropy_hash ^= |
| 915 QuicConnectionPeer::GetSentEntropyHash(&connection_, missing - 1); | 915 QuicConnectionPeer::GetSentEntropyHash(&connection_, missing - 1); |
| 916 } | 916 } |
| 917 } | 917 } |
| 918 | 918 |
| 919 // Undo nacking a packet within the frame. | 919 // Undo nacking a packet within the frame. |
| 920 void AckPacket(QuicPacketSequenceNumber arrived, QuicAckFrame* frame) { | 920 void AckPacket(QuicPacketSequenceNumber arrived, QuicAckFrame* frame) { |
| 921 EXPECT_THAT(frame->received_info.missing_packets, Contains(arrived)); | 921 EXPECT_THAT(frame->missing_packets, Contains(arrived)); |
| 922 frame->received_info.missing_packets.erase(arrived); | 922 frame->missing_packets.erase(arrived); |
| 923 frame->received_info.entropy_hash ^= | 923 frame->entropy_hash ^= |
| 924 QuicConnectionPeer::GetSentEntropyHash(&connection_, arrived); | 924 QuicConnectionPeer::GetSentEntropyHash(&connection_, arrived); |
| 925 if (arrived > 1) { | 925 if (arrived > 1) { |
| 926 frame->received_info.entropy_hash ^= | 926 frame->entropy_hash ^= |
| 927 QuicConnectionPeer::GetSentEntropyHash(&connection_, arrived - 1); | 927 QuicConnectionPeer::GetSentEntropyHash(&connection_, arrived - 1); |
| 928 } | 928 } |
| 929 } | 929 } |
| 930 | 930 |
| 931 void TriggerConnectionClose() { | 931 void TriggerConnectionClose() { |
| 932 // Send an erroneous packet to close the connection. | 932 // Send an erroneous packet to close the connection. |
| 933 EXPECT_CALL(visitor_, | 933 EXPECT_CALL(visitor_, |
| 934 OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false)); | 934 OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false)); |
| 935 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a | 935 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a |
| 936 // packet call to the visitor. | 936 // packet call to the visitor. |
| 937 ProcessDataPacket(6000, 0, !kEntropyFlag); | 937 ProcessDataPacket(6000, 0, !kEntropyFlag); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 968 MockRandom random_generator_; | 968 MockRandom random_generator_; |
| 969 scoped_ptr<TestConnectionHelper> helper_; | 969 scoped_ptr<TestConnectionHelper> helper_; |
| 970 scoped_ptr<TestPacketWriter> writer_; | 970 scoped_ptr<TestPacketWriter> writer_; |
| 971 TestConnection connection_; | 971 TestConnection connection_; |
| 972 StrictMock<MockConnectionVisitor> visitor_; | 972 StrictMock<MockConnectionVisitor> visitor_; |
| 973 | 973 |
| 974 QuicPacketHeader header_; | 974 QuicPacketHeader header_; |
| 975 QuicStreamFrame frame1_; | 975 QuicStreamFrame frame1_; |
| 976 QuicStreamFrame frame2_; | 976 QuicStreamFrame frame2_; |
| 977 scoped_ptr<QuicAckFrame> outgoing_ack_; | 977 scoped_ptr<QuicAckFrame> outgoing_ack_; |
| 978 scoped_ptr<QuicStopWaitingFrame> stop_waiting_; |
| 978 QuicSequenceNumberLength sequence_number_length_; | 979 QuicSequenceNumberLength sequence_number_length_; |
| 979 QuicConnectionIdLength connection_id_length_; | 980 QuicConnectionIdLength connection_id_length_; |
| 980 | 981 |
| 981 private: | 982 private: |
| 982 DISALLOW_COPY_AND_ASSIGN(QuicConnectionTest); | 983 DISALLOW_COPY_AND_ASSIGN(QuicConnectionTest); |
| 983 }; | 984 }; |
| 984 | 985 |
| 985 // Run all end to end tests with all supported versions. | 986 // Run all end to end tests with all supported versions. |
| 986 INSTANTIATE_TEST_CASE_P(SupportedVersion, | 987 INSTANTIATE_TEST_CASE_P(SupportedVersion, |
| 987 QuicConnectionTest, | 988 QuicConnectionTest, |
| 988 ::testing::ValuesIn(QuicSupportedVersions())); | 989 ::testing::ValuesIn(QuicSupportedVersions())); |
| 989 | 990 |
| 990 TEST_P(QuicConnectionTest, PacketsInOrder) { | 991 TEST_P(QuicConnectionTest, PacketsInOrder) { |
| 991 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 992 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 992 | 993 |
| 993 ProcessPacket(1); | 994 ProcessPacket(1); |
| 994 EXPECT_EQ(1u, outgoing_ack()->received_info.largest_observed); | 995 EXPECT_EQ(1u, outgoing_ack()->largest_observed); |
| 995 EXPECT_EQ(0u, outgoing_ack()->received_info.missing_packets.size()); | 996 EXPECT_EQ(0u, outgoing_ack()->missing_packets.size()); |
| 996 | 997 |
| 997 ProcessPacket(2); | 998 ProcessPacket(2); |
| 998 EXPECT_EQ(2u, outgoing_ack()->received_info.largest_observed); | 999 EXPECT_EQ(2u, outgoing_ack()->largest_observed); |
| 999 EXPECT_EQ(0u, outgoing_ack()->received_info.missing_packets.size()); | 1000 EXPECT_EQ(0u, outgoing_ack()->missing_packets.size()); |
| 1000 | 1001 |
| 1001 ProcessPacket(3); | 1002 ProcessPacket(3); |
| 1002 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); | 1003 EXPECT_EQ(3u, outgoing_ack()->largest_observed); |
| 1003 EXPECT_EQ(0u, outgoing_ack()->received_info.missing_packets.size()); | 1004 EXPECT_EQ(0u, outgoing_ack()->missing_packets.size()); |
| 1004 } | 1005 } |
| 1005 | 1006 |
| 1006 TEST_P(QuicConnectionTest, PacketsOutOfOrder) { | 1007 TEST_P(QuicConnectionTest, PacketsOutOfOrder) { |
| 1007 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1008 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1008 | 1009 |
| 1009 ProcessPacket(3); | 1010 ProcessPacket(3); |
| 1010 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); | 1011 EXPECT_EQ(3u, outgoing_ack()->largest_observed); |
| 1011 EXPECT_TRUE(IsMissing(2)); | 1012 EXPECT_TRUE(IsMissing(2)); |
| 1012 EXPECT_TRUE(IsMissing(1)); | 1013 EXPECT_TRUE(IsMissing(1)); |
| 1013 | 1014 |
| 1014 ProcessPacket(2); | 1015 ProcessPacket(2); |
| 1015 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); | 1016 EXPECT_EQ(3u, outgoing_ack()->largest_observed); |
| 1016 EXPECT_FALSE(IsMissing(2)); | 1017 EXPECT_FALSE(IsMissing(2)); |
| 1017 EXPECT_TRUE(IsMissing(1)); | 1018 EXPECT_TRUE(IsMissing(1)); |
| 1018 | 1019 |
| 1019 ProcessPacket(1); | 1020 ProcessPacket(1); |
| 1020 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); | 1021 EXPECT_EQ(3u, outgoing_ack()->largest_observed); |
| 1021 EXPECT_FALSE(IsMissing(2)); | 1022 EXPECT_FALSE(IsMissing(2)); |
| 1022 EXPECT_FALSE(IsMissing(1)); | 1023 EXPECT_FALSE(IsMissing(1)); |
| 1023 } | 1024 } |
| 1024 | 1025 |
| 1025 TEST_P(QuicConnectionTest, DuplicatePacket) { | 1026 TEST_P(QuicConnectionTest, DuplicatePacket) { |
| 1026 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1027 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1027 | 1028 |
| 1028 ProcessPacket(3); | 1029 ProcessPacket(3); |
| 1029 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); | 1030 EXPECT_EQ(3u, outgoing_ack()->largest_observed); |
| 1030 EXPECT_TRUE(IsMissing(2)); | 1031 EXPECT_TRUE(IsMissing(2)); |
| 1031 EXPECT_TRUE(IsMissing(1)); | 1032 EXPECT_TRUE(IsMissing(1)); |
| 1032 | 1033 |
| 1033 // Send packet 3 again, but do not set the expectation that | 1034 // Send packet 3 again, but do not set the expectation that |
| 1034 // the visitor OnStreamFrames() will be called. | 1035 // the visitor OnStreamFrames() will be called. |
| 1035 ProcessDataPacket(3, 0, !kEntropyFlag); | 1036 ProcessDataPacket(3, 0, !kEntropyFlag); |
| 1036 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); | 1037 EXPECT_EQ(3u, outgoing_ack()->largest_observed); |
| 1037 EXPECT_TRUE(IsMissing(2)); | 1038 EXPECT_TRUE(IsMissing(2)); |
| 1038 EXPECT_TRUE(IsMissing(1)); | 1039 EXPECT_TRUE(IsMissing(1)); |
| 1039 } | 1040 } |
| 1040 | 1041 |
| 1041 TEST_P(QuicConnectionTest, PacketsOutOfOrderWithAdditionsAndLeastAwaiting) { | 1042 TEST_P(QuicConnectionTest, PacketsOutOfOrderWithAdditionsAndLeastAwaiting) { |
| 1042 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1043 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1043 | 1044 |
| 1044 ProcessPacket(3); | 1045 ProcessPacket(3); |
| 1045 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); | 1046 EXPECT_EQ(3u, outgoing_ack()->largest_observed); |
| 1046 EXPECT_TRUE(IsMissing(2)); | 1047 EXPECT_TRUE(IsMissing(2)); |
| 1047 EXPECT_TRUE(IsMissing(1)); | 1048 EXPECT_TRUE(IsMissing(1)); |
| 1048 | 1049 |
| 1049 ProcessPacket(2); | 1050 ProcessPacket(2); |
| 1050 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); | 1051 EXPECT_EQ(3u, outgoing_ack()->largest_observed); |
| 1051 EXPECT_TRUE(IsMissing(1)); | 1052 EXPECT_TRUE(IsMissing(1)); |
| 1052 | 1053 |
| 1053 ProcessPacket(5); | 1054 ProcessPacket(5); |
| 1054 EXPECT_EQ(5u, outgoing_ack()->received_info.largest_observed); | 1055 EXPECT_EQ(5u, outgoing_ack()->largest_observed); |
| 1055 EXPECT_TRUE(IsMissing(1)); | 1056 EXPECT_TRUE(IsMissing(1)); |
| 1056 EXPECT_TRUE(IsMissing(4)); | 1057 EXPECT_TRUE(IsMissing(4)); |
| 1057 | 1058 |
| 1058 // Pretend at this point the client has gotten acks for 2 and 3 and 1 is a | 1059 // Pretend at this point the client has gotten acks for 2 and 3 and 1 is a |
| 1059 // packet the peer will not retransmit. It indicates this by sending 'least | 1060 // packet the peer will not retransmit. It indicates this by sending 'least |
| 1060 // awaiting' is 4. The connection should then realize 1 will not be | 1061 // awaiting' is 4. The connection should then realize 1 will not be |
| 1061 // retransmitted, and will remove it from the missing list. | 1062 // retransmitted, and will remove it from the missing list. |
| 1062 peer_creator_.set_sequence_number(5); | 1063 peer_creator_.set_sequence_number(5); |
| 1063 QuicAckFrame frame = InitAckFrame(1, 4); | 1064 QuicAckFrame frame = InitAckFrame(1); |
| 1064 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(_, _, _, _)); | 1065 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(_, _, _, _)); |
| 1065 ProcessAckPacket(&frame); | 1066 ProcessAckPacket(&frame); |
| 1066 | 1067 |
| 1067 // Force an ack to be sent. | 1068 // Force an ack to be sent. |
| 1068 SendAckPacketToPeer(); | 1069 SendAckPacketToPeer(); |
| 1069 EXPECT_TRUE(IsMissing(4)); | 1070 EXPECT_TRUE(IsMissing(4)); |
| 1070 } | 1071 } |
| 1071 | 1072 |
| 1072 TEST_P(QuicConnectionTest, RejectPacketTooFarOut) { | 1073 TEST_P(QuicConnectionTest, RejectPacketTooFarOut) { |
| 1073 EXPECT_CALL(visitor_, | 1074 EXPECT_CALL(visitor_, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1095 connection_close_frames[0].error_code); | 1096 connection_close_frames[0].error_code); |
| 1096 } | 1097 } |
| 1097 | 1098 |
| 1098 TEST_P(QuicConnectionTest, TruncatedAck) { | 1099 TEST_P(QuicConnectionTest, TruncatedAck) { |
| 1099 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1100 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1100 QuicPacketSequenceNumber num_packets = 256 * 2 + 1; | 1101 QuicPacketSequenceNumber num_packets = 256 * 2 + 1; |
| 1101 for (QuicPacketSequenceNumber i = 0; i < num_packets; ++i) { | 1102 for (QuicPacketSequenceNumber i = 0; i < num_packets; ++i) { |
| 1102 SendStreamDataToPeer(3, "foo", i * 3, !kFin, NULL); | 1103 SendStreamDataToPeer(3, "foo", i * 3, !kFin, NULL); |
| 1103 } | 1104 } |
| 1104 | 1105 |
| 1105 QuicAckFrame frame = InitAckFrame(num_packets, 1); | 1106 QuicAckFrame frame = InitAckFrame(num_packets); |
| 1106 SequenceNumberSet lost_packets; | 1107 SequenceNumberSet lost_packets; |
| 1107 // Create an ack with 256 nacks, none adjacent to one another. | 1108 // Create an ack with 256 nacks, none adjacent to one another. |
| 1108 for (QuicPacketSequenceNumber i = 1; i <= 256; ++i) { | 1109 for (QuicPacketSequenceNumber i = 1; i <= 256; ++i) { |
| 1109 NackPacket(i * 2, &frame); | 1110 NackPacket(i * 2, &frame); |
| 1110 if (i < 256) { // Last packet is nacked, but not lost. | 1111 if (i < 256) { // Last packet is nacked, but not lost. |
| 1111 lost_packets.insert(i * 2); | 1112 lost_packets.insert(i * 2); |
| 1112 } | 1113 } |
| 1113 } | 1114 } |
| 1114 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) | 1115 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
| 1115 .WillOnce(Return(lost_packets)); | 1116 .WillOnce(Return(lost_packets)); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1146 testing::Return(QuicTime::Delta::FromMicroseconds(1))); | 1147 testing::Return(QuicTime::Delta::FromMicroseconds(1))); |
| 1147 QuicConnectionPeer::SendAck(&connection_); | 1148 QuicConnectionPeer::SendAck(&connection_); |
| 1148 | 1149 |
| 1149 // Process an ack with a least unacked of the received ack. | 1150 // Process an ack with a least unacked of the received ack. |
| 1150 // This causes an ack to be sent when TimeUntilSend returns 0. | 1151 // This causes an ack to be sent when TimeUntilSend returns 0. |
| 1151 EXPECT_CALL(*send_algorithm_, | 1152 EXPECT_CALL(*send_algorithm_, |
| 1152 TimeUntilSend(_, _, _)).WillRepeatedly( | 1153 TimeUntilSend(_, _, _)).WillRepeatedly( |
| 1153 testing::Return(QuicTime::Delta::Zero())); | 1154 testing::Return(QuicTime::Delta::Zero())); |
| 1154 // Skip a packet and then record an ack. | 1155 // Skip a packet and then record an ack. |
| 1155 peer_creator_.set_sequence_number(2); | 1156 peer_creator_.set_sequence_number(2); |
| 1156 QuicAckFrame frame = InitAckFrame(0, 3); | 1157 QuicAckFrame frame = InitAckFrame(0); |
| 1157 ProcessAckPacket(&frame); | 1158 ProcessAckPacket(&frame); |
| 1158 } | 1159 } |
| 1159 | 1160 |
| 1160 TEST_P(QuicConnectionTest, OutOfOrderReceiptCausesAckSend) { | 1161 TEST_P(QuicConnectionTest, OutOfOrderReceiptCausesAckSend) { |
| 1161 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1162 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1162 | 1163 |
| 1163 ProcessPacket(3); | 1164 ProcessPacket(3); |
| 1164 // Should ack immediately since we have missing packets. | 1165 // Should ack immediately since we have missing packets. |
| 1165 EXPECT_EQ(1u, writer_->packets_write_attempts()); | 1166 EXPECT_EQ(1u, writer_->packets_write_attempts()); |
| 1166 | 1167 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1179 | 1180 |
| 1180 TEST_P(QuicConnectionTest, AckReceiptCausesAckSend) { | 1181 TEST_P(QuicConnectionTest, AckReceiptCausesAckSend) { |
| 1181 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1182 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1182 | 1183 |
| 1183 QuicPacketSequenceNumber original; | 1184 QuicPacketSequenceNumber original; |
| 1184 QuicByteCount packet_size; | 1185 QuicByteCount packet_size; |
| 1185 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 1186 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
| 1186 .WillOnce(DoAll(SaveArg<2>(&original), SaveArg<3>(&packet_size), | 1187 .WillOnce(DoAll(SaveArg<2>(&original), SaveArg<3>(&packet_size), |
| 1187 Return(true))); | 1188 Return(true))); |
| 1188 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); | 1189 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); |
| 1189 QuicAckFrame frame = InitAckFrame(original, 1); | 1190 QuicAckFrame frame = InitAckFrame(original); |
| 1190 NackPacket(original, &frame); | 1191 NackPacket(original, &frame); |
| 1191 // First nack triggers early retransmit. | 1192 // First nack triggers early retransmit. |
| 1192 SequenceNumberSet lost_packets; | 1193 SequenceNumberSet lost_packets; |
| 1193 lost_packets.insert(1); | 1194 lost_packets.insert(1); |
| 1194 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) | 1195 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
| 1195 .WillOnce(Return(lost_packets)); | 1196 .WillOnce(Return(lost_packets)); |
| 1196 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 1197 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 1197 QuicPacketSequenceNumber retransmission; | 1198 QuicPacketSequenceNumber retransmission; |
| 1198 EXPECT_CALL(*send_algorithm_, | 1199 EXPECT_CALL(*send_algorithm_, |
| 1199 OnPacketSent(_, _, _, packet_size - kQuicVersionSize, _)) | 1200 OnPacketSent(_, _, _, packet_size - kQuicVersionSize, _)) |
| 1200 .WillOnce(DoAll(SaveArg<2>(&retransmission), Return(true))); | 1201 .WillOnce(DoAll(SaveArg<2>(&retransmission), Return(true))); |
| 1201 | 1202 |
| 1202 ProcessAckPacket(&frame); | 1203 ProcessAckPacket(&frame); |
| 1203 | 1204 |
| 1204 QuicAckFrame frame2 = InitAckFrame(retransmission, 1); | 1205 QuicAckFrame frame2 = InitAckFrame(retransmission); |
| 1205 NackPacket(original, &frame2); | 1206 NackPacket(original, &frame2); |
| 1206 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 1207 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 1207 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) | 1208 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
| 1208 .WillOnce(Return(SequenceNumberSet())); | 1209 .WillOnce(Return(SequenceNumberSet())); |
| 1209 ProcessAckPacket(&frame2); | 1210 ProcessAckPacket(&frame2); |
| 1210 | 1211 |
| 1211 // Now if the peer sends an ack which still reports the retransmitted packet | 1212 // Now if the peer sends an ack which still reports the retransmitted packet |
| 1212 // as missing, that will bundle an ack with data after two acks in a row | 1213 // as missing, that will bundle an ack with data after two acks in a row |
| 1213 // indicate the high water mark needs to be raised. | 1214 // indicate the high water mark needs to be raised. |
| 1214 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, | 1215 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, |
| 1215 HAS_RETRANSMITTABLE_DATA)); | 1216 HAS_RETRANSMITTABLE_DATA)); |
| 1216 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL); | 1217 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL); |
| 1217 // No ack sent. | 1218 // No ack sent. |
| 1218 EXPECT_EQ(1u, writer_->frame_count()); | 1219 EXPECT_EQ(1u, writer_->frame_count()); |
| 1219 EXPECT_EQ(1u, writer_->stream_frames().size()); | 1220 EXPECT_EQ(1u, writer_->stream_frames().size()); |
| 1220 | 1221 |
| 1221 // No more packet loss for the rest of the test. | 1222 // No more packet loss for the rest of the test. |
| 1222 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) | 1223 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
| 1223 .WillRepeatedly(Return(SequenceNumberSet())); | 1224 .WillRepeatedly(Return(SequenceNumberSet())); |
| 1224 ProcessAckPacket(&frame2); | 1225 ProcessAckPacket(&frame2); |
| 1225 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, | 1226 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, |
| 1226 HAS_RETRANSMITTABLE_DATA)); | 1227 HAS_RETRANSMITTABLE_DATA)); |
| 1227 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL); | 1228 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL); |
| 1228 // Ack bundled. | 1229 // Ack bundled. |
| 1229 if (version() > QUIC_VERSION_15) { | 1230 EXPECT_EQ(3u, writer_->frame_count()); |
| 1230 EXPECT_EQ(3u, writer_->frame_count()); | |
| 1231 } else { | |
| 1232 EXPECT_EQ(2u, writer_->frame_count()); | |
| 1233 } | |
| 1234 EXPECT_EQ(1u, writer_->stream_frames().size()); | 1231 EXPECT_EQ(1u, writer_->stream_frames().size()); |
| 1235 EXPECT_FALSE(writer_->ack_frames().empty()); | 1232 EXPECT_FALSE(writer_->ack_frames().empty()); |
| 1236 | 1233 |
| 1237 // But an ack with no missing packets will not send an ack. | 1234 // But an ack with no missing packets will not send an ack. |
| 1238 AckPacket(original, &frame2); | 1235 AckPacket(original, &frame2); |
| 1239 ProcessAckPacket(&frame2); | 1236 ProcessAckPacket(&frame2); |
| 1240 ProcessAckPacket(&frame2); | 1237 ProcessAckPacket(&frame2); |
| 1241 } | 1238 } |
| 1242 | 1239 |
| 1243 TEST_P(QuicConnectionTest, LeastUnackedLower) { | 1240 TEST_P(QuicConnectionTest, LeastUnackedLower) { |
| 1244 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1241 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1245 | 1242 |
| 1246 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); | 1243 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); |
| 1247 SendStreamDataToPeer(1, "bar", 3, !kFin, NULL); | 1244 SendStreamDataToPeer(1, "bar", 3, !kFin, NULL); |
| 1248 SendStreamDataToPeer(1, "eep", 6, !kFin, NULL); | 1245 SendStreamDataToPeer(1, "eep", 6, !kFin, NULL); |
| 1249 | 1246 |
| 1250 // Start out saying the least unacked is 2. | 1247 // Start out saying the least unacked is 2. |
| 1251 peer_creator_.set_sequence_number(5); | 1248 peer_creator_.set_sequence_number(5); |
| 1252 if (version() > QUIC_VERSION_15) { | 1249 QuicStopWaitingFrame frame = InitStopWaitingFrame(2); |
| 1253 QuicStopWaitingFrame frame = InitStopWaitingFrame(2); | 1250 ProcessStopWaitingPacket(&frame); |
| 1254 ProcessStopWaitingPacket(&frame); | |
| 1255 } else { | |
| 1256 QuicAckFrame frame = InitAckFrame(0, 2); | |
| 1257 ProcessAckPacket(&frame); | |
| 1258 } | |
| 1259 | 1251 |
| 1260 // Change it to 1, but lower the sequence number to fake out-of-order packets. | 1252 // Change it to 1, but lower the sequence number to fake out-of-order packets. |
| 1261 // This should be fine. | 1253 // This should be fine. |
| 1262 peer_creator_.set_sequence_number(1); | 1254 peer_creator_.set_sequence_number(1); |
| 1263 // The scheduler will not process out of order acks, but all packet processing | 1255 // The scheduler will not process out of order acks, but all packet processing |
| 1264 // causes the connection to try to write. | 1256 // causes the connection to try to write. |
| 1265 EXPECT_CALL(visitor_, OnCanWrite()); | 1257 EXPECT_CALL(visitor_, OnCanWrite()); |
| 1266 if (version() > QUIC_VERSION_15) { | 1258 QuicStopWaitingFrame frame2 = InitStopWaitingFrame(1); |
| 1267 QuicStopWaitingFrame frame2 = InitStopWaitingFrame(1); | 1259 ProcessStopWaitingPacket(&frame2); |
| 1268 ProcessStopWaitingPacket(&frame2); | |
| 1269 } else { | |
| 1270 QuicAckFrame frame2 = InitAckFrame(0, 1); | |
| 1271 ProcessAckPacket(&frame2); | |
| 1272 } | |
| 1273 | 1260 |
| 1274 // Now claim it's one, but set the ordering so it was sent "after" the first | 1261 // Now claim it's one, but set the ordering so it was sent "after" the first |
| 1275 // one. This should cause a connection error. | 1262 // one. This should cause a connection error. |
| 1276 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 1263 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| 1277 peer_creator_.set_sequence_number(7); | 1264 peer_creator_.set_sequence_number(7); |
| 1278 if (version() > QUIC_VERSION_15) { | 1265 EXPECT_CALL(visitor_, |
| 1279 EXPECT_CALL(visitor_, | 1266 OnConnectionClosed(QUIC_INVALID_STOP_WAITING_DATA, false)); |
| 1280 OnConnectionClosed(QUIC_INVALID_STOP_WAITING_DATA, false)); | 1267 QuicStopWaitingFrame frame3 = InitStopWaitingFrame(1); |
| 1281 QuicStopWaitingFrame frame2 = InitStopWaitingFrame(1); | 1268 ProcessStopWaitingPacket(&frame3); |
| 1282 ProcessStopWaitingPacket(&frame2); | |
| 1283 } else { | |
| 1284 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_ACK_DATA, false)); | |
| 1285 QuicAckFrame frame2 = InitAckFrame(0, 1); | |
| 1286 ProcessAckPacket(&frame2); | |
| 1287 } | |
| 1288 } | 1269 } |
| 1289 | 1270 |
| 1290 TEST_P(QuicConnectionTest, LargestObservedLower) { | 1271 TEST_P(QuicConnectionTest, LargestObservedLower) { |
| 1291 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1272 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1292 | 1273 |
| 1293 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); | 1274 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); |
| 1294 SendStreamDataToPeer(1, "bar", 3, !kFin, NULL); | 1275 SendStreamDataToPeer(1, "bar", 3, !kFin, NULL); |
| 1295 SendStreamDataToPeer(1, "eep", 6, !kFin, NULL); | 1276 SendStreamDataToPeer(1, "eep", 6, !kFin, NULL); |
| 1296 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 1277 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 1297 | 1278 |
| 1298 // Start out saying the largest observed is 2. | 1279 // Start out saying the largest observed is 2. |
| 1299 QuicAckFrame frame1 = InitAckFrame(1, 0); | 1280 QuicAckFrame frame1 = InitAckFrame(1); |
| 1300 QuicAckFrame frame2 = InitAckFrame(2, 0); | 1281 QuicAckFrame frame2 = InitAckFrame(2); |
| 1301 ProcessAckPacket(&frame2); | 1282 ProcessAckPacket(&frame2); |
| 1302 | 1283 |
| 1303 // Now change it to 1, and it should cause a connection error. | 1284 // Now change it to 1, and it should cause a connection error. |
| 1304 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_ACK_DATA, false)); | 1285 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_ACK_DATA, false)); |
| 1305 EXPECT_CALL(visitor_, OnCanWrite()).Times(0); | 1286 EXPECT_CALL(visitor_, OnCanWrite()).Times(0); |
| 1306 ProcessAckPacket(&frame1); | 1287 ProcessAckPacket(&frame1); |
| 1307 } | 1288 } |
| 1308 | 1289 |
| 1309 TEST_P(QuicConnectionTest, AckUnsentData) { | 1290 TEST_P(QuicConnectionTest, AckUnsentData) { |
| 1310 // Ack a packet which has not been sent. | 1291 // Ack a packet which has not been sent. |
| 1311 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_ACK_DATA, false)); | 1292 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_ACK_DATA, false)); |
| 1312 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1293 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1313 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 1294 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| 1314 QuicAckFrame frame(MakeAckFrame(1, 0)); | 1295 QuicAckFrame frame(MakeAckFrame(1)); |
| 1315 EXPECT_CALL(visitor_, OnCanWrite()).Times(0); | 1296 EXPECT_CALL(visitor_, OnCanWrite()).Times(0); |
| 1316 ProcessAckPacket(&frame); | 1297 ProcessAckPacket(&frame); |
| 1317 } | 1298 } |
| 1318 | 1299 |
| 1319 TEST_P(QuicConnectionTest, AckAll) { | 1300 TEST_P(QuicConnectionTest, AckAll) { |
| 1320 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1301 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1321 ProcessPacket(1); | 1302 ProcessPacket(1); |
| 1322 | 1303 |
| 1323 peer_creator_.set_sequence_number(1); | 1304 peer_creator_.set_sequence_number(1); |
| 1324 QuicAckFrame frame1 = InitAckFrame(0, 1); | 1305 QuicAckFrame frame1 = InitAckFrame(0); |
| 1325 ProcessAckPacket(&frame1); | 1306 ProcessAckPacket(&frame1); |
| 1326 } | 1307 } |
| 1327 | 1308 |
| 1328 TEST_P(QuicConnectionTest, SendingDifferentSequenceNumberLengthsBandwidth) { | 1309 TEST_P(QuicConnectionTest, SendingDifferentSequenceNumberLengthsBandwidth) { |
| 1329 QuicPacketSequenceNumber last_packet; | 1310 QuicPacketSequenceNumber last_packet; |
| 1330 QuicPacketCreator* creator = | 1311 QuicPacketCreator* creator = |
| 1331 QuicConnectionPeer::GetPacketCreator(&connection_); | 1312 QuicConnectionPeer::GetPacketCreator(&connection_); |
| 1332 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); | 1313 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); |
| 1333 EXPECT_EQ(1u, last_packet); | 1314 EXPECT_EQ(1u, last_packet); |
| 1334 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, | 1315 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1436 EXPECT_EQ(1u, least_unacked()); | 1417 EXPECT_EQ(1u, least_unacked()); |
| 1437 | 1418 |
| 1438 SendStreamDataToPeer(1, "bar", 3, !kFin, &last_packet); // Packet 4 | 1419 SendStreamDataToPeer(1, "bar", 3, !kFin, &last_packet); // Packet 4 |
| 1439 EXPECT_EQ(4u, last_packet); | 1420 EXPECT_EQ(4u, last_packet); |
| 1440 SendAckPacketToPeer(); // Packet 5 | 1421 SendAckPacketToPeer(); // Packet 5 |
| 1441 EXPECT_EQ(1u, least_unacked()); | 1422 EXPECT_EQ(1u, least_unacked()); |
| 1442 | 1423 |
| 1443 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 1424 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 1444 | 1425 |
| 1445 // Peer acks up to packet 3. | 1426 // Peer acks up to packet 3. |
| 1446 QuicAckFrame frame = InitAckFrame(3, 0); | 1427 QuicAckFrame frame = InitAckFrame(3); |
| 1447 ProcessAckPacket(&frame); | 1428 ProcessAckPacket(&frame); |
| 1448 SendAckPacketToPeer(); // Packet 6 | 1429 SendAckPacketToPeer(); // Packet 6 |
| 1449 | 1430 |
| 1450 // As soon as we've acked one, we skip ack packets 2 and 3 and note lack of | 1431 // As soon as we've acked one, we skip ack packets 2 and 3 and note lack of |
| 1451 // ack for 4. | 1432 // ack for 4. |
| 1452 EXPECT_EQ(4u, least_unacked()); | 1433 EXPECT_EQ(4u, least_unacked()); |
| 1453 | 1434 |
| 1454 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 1435 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 1455 | 1436 |
| 1456 // Peer acks up to packet 4, the last packet. | 1437 // Peer acks up to packet 4, the last packet. |
| 1457 QuicAckFrame frame2 = InitAckFrame(6, 0); | 1438 QuicAckFrame frame2 = InitAckFrame(6); |
| 1458 ProcessAckPacket(&frame2); // Acks don't instigate acks. | 1439 ProcessAckPacket(&frame2); // Acks don't instigate acks. |
| 1459 | 1440 |
| 1460 // Verify that we did not send an ack. | 1441 // Verify that we did not send an ack. |
| 1461 EXPECT_EQ(6u, writer_->header().packet_sequence_number); | 1442 EXPECT_EQ(6u, writer_->header().packet_sequence_number); |
| 1462 | 1443 |
| 1463 // So the last ack has not changed. | 1444 // So the last ack has not changed. |
| 1464 EXPECT_EQ(4u, least_unacked()); | 1445 EXPECT_EQ(4u, least_unacked()); |
| 1465 | 1446 |
| 1466 // If we force an ack, we shouldn't change our retransmit state. | 1447 // If we force an ack, we shouldn't change our retransmit state. |
| 1467 SendAckPacketToPeer(); // Packet 7 | 1448 SendAckPacketToPeer(); // Packet 7 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1544 EXPECT_TRUE(QuicConnectionPeer::GetPacketCreator( | 1525 EXPECT_TRUE(QuicConnectionPeer::GetPacketCreator( |
| 1545 &connection_)->IsFecEnabled()); | 1526 &connection_)->IsFecEnabled()); |
| 1546 | 1527 |
| 1547 // 1 Data and 1 FEC packet. | 1528 // 1 Data and 1 FEC packet. |
| 1548 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); | 1529 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); |
| 1549 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, NULL); | 1530 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, NULL); |
| 1550 // Send some more data afterwards to ensure early retransmit doesn't trigger. | 1531 // Send some more data afterwards to ensure early retransmit doesn't trigger. |
| 1551 connection_.SendStreamDataWithStringWithFec(3, "foo", 3, !kFin, NULL); | 1532 connection_.SendStreamDataWithStringWithFec(3, "foo", 3, !kFin, NULL); |
| 1552 connection_.SendStreamDataWithStringWithFec(3, "foo", 6, !kFin, NULL); | 1533 connection_.SendStreamDataWithStringWithFec(3, "foo", 6, !kFin, NULL); |
| 1553 | 1534 |
| 1554 QuicAckFrame ack_fec = InitAckFrame(2, 1); | 1535 QuicAckFrame ack_fec = InitAckFrame(2); |
| 1555 // Data packet missing. | 1536 // Data packet missing. |
| 1556 // TODO(ianswett): Note that this is not a sensible ack, since if the FEC was | 1537 // TODO(ianswett): Note that this is not a sensible ack, since if the FEC was |
| 1557 // received, it would cause the covered packet to be acked as well. | 1538 // received, it would cause the covered packet to be acked as well. |
| 1558 NackPacket(1, &ack_fec); | 1539 NackPacket(1, &ack_fec); |
| 1559 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 1540 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 1560 ProcessAckPacket(&ack_fec); | 1541 ProcessAckPacket(&ack_fec); |
| 1561 clock_.AdvanceTime(DefaultRetransmissionTime()); | 1542 clock_.AdvanceTime(DefaultRetransmissionTime()); |
| 1562 | 1543 |
| 1563 // Don't abandon the acked FEC packet, but it will abandon 2 the subsequent | 1544 // Don't abandon the acked FEC packet, but it will abandon 2 the subsequent |
| 1564 // FEC packets. | 1545 // FEC packets. |
| 1565 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); | 1546 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
| 1566 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3); | 1547 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3); |
| 1567 connection_.GetRetransmissionAlarm()->Fire(); | 1548 connection_.GetRetransmissionAlarm()->Fire(); |
| 1568 } | 1549 } |
| 1569 | 1550 |
| 1570 TEST_P(QuicConnectionTest, AbandonAllFEC) { | 1551 TEST_P(QuicConnectionTest, AbandonAllFEC) { |
| 1571 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1552 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1572 EXPECT_TRUE(QuicConnectionPeer::GetPacketCreator( | 1553 EXPECT_TRUE(QuicConnectionPeer::GetPacketCreator( |
| 1573 &connection_)->IsFecEnabled()); | 1554 &connection_)->IsFecEnabled()); |
| 1574 | 1555 |
| 1575 // 1 Data and 1 FEC packet. | 1556 // 1 Data and 1 FEC packet. |
| 1576 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); | 1557 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); |
| 1577 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, NULL); | 1558 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, NULL); |
| 1578 // Send some more data afterwards to ensure early retransmit doesn't trigger. | 1559 // Send some more data afterwards to ensure early retransmit doesn't trigger. |
| 1579 connection_.SendStreamDataWithStringWithFec(3, "foo", 3, !kFin, NULL); | 1560 connection_.SendStreamDataWithStringWithFec(3, "foo", 3, !kFin, NULL); |
| 1580 // Advance the time so not all the FEC packets are abandoned. | 1561 // Advance the time so not all the FEC packets are abandoned. |
| 1581 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); | 1562 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); |
| 1582 connection_.SendStreamDataWithStringWithFec(3, "foo", 6, !kFin, NULL); | 1563 connection_.SendStreamDataWithStringWithFec(3, "foo", 6, !kFin, NULL); |
| 1583 | 1564 |
| 1584 QuicAckFrame ack_fec = InitAckFrame(5, 1); | 1565 QuicAckFrame ack_fec = InitAckFrame(5); |
| 1585 // Ack all data packets, but no fec packets. | 1566 // Ack all data packets, but no fec packets. |
| 1586 NackPacket(2, &ack_fec); | 1567 NackPacket(2, &ack_fec); |
| 1587 NackPacket(4, &ack_fec); | 1568 NackPacket(4, &ack_fec); |
| 1588 | 1569 |
| 1589 // Lose the first FEC packet and ack the three data packets. | 1570 // Lose the first FEC packet and ack the three data packets. |
| 1590 SequenceNumberSet lost_packets; | 1571 SequenceNumberSet lost_packets; |
| 1591 lost_packets.insert(2); | 1572 lost_packets.insert(2); |
| 1592 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) | 1573 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
| 1593 .WillOnce(Return(lost_packets)); | 1574 .WillOnce(Return(lost_packets)); |
| 1594 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 1575 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1617 &TestConnection::SendStreamData5)))); | 1598 &TestConnection::SendStreamData5)))); |
| 1618 | 1599 |
| 1619 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 1600 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
| 1620 CongestionUnblockWrites(); | 1601 CongestionUnblockWrites(); |
| 1621 connection_.GetSendAlarm()->Fire(); | 1602 connection_.GetSendAlarm()->Fire(); |
| 1622 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1603 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 1623 EXPECT_FALSE(connection_.HasQueuedData()); | 1604 EXPECT_FALSE(connection_.HasQueuedData()); |
| 1624 | 1605 |
| 1625 // Parse the last packet and ensure it's an ack and two stream frames from | 1606 // Parse the last packet and ensure it's an ack and two stream frames from |
| 1626 // two different streams. | 1607 // two different streams. |
| 1627 if (version() > QUIC_VERSION_15) { | 1608 EXPECT_EQ(4u, writer_->frame_count()); |
| 1628 EXPECT_EQ(4u, writer_->frame_count()); | 1609 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); |
| 1629 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); | |
| 1630 } else { | |
| 1631 EXPECT_EQ(3u, writer_->frame_count()); | |
| 1632 } | |
| 1633 EXPECT_FALSE(writer_->ack_frames().empty()); | 1610 EXPECT_FALSE(writer_->ack_frames().empty()); |
| 1634 ASSERT_EQ(2u, writer_->stream_frames().size()); | 1611 ASSERT_EQ(2u, writer_->stream_frames().size()); |
| 1635 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0].stream_id); | 1612 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0].stream_id); |
| 1636 EXPECT_EQ(kClientDataStreamId2, writer_->stream_frames()[1].stream_id); | 1613 EXPECT_EQ(kClientDataStreamId2, writer_->stream_frames()[1].stream_id); |
| 1637 } | 1614 } |
| 1638 | 1615 |
| 1639 TEST_P(QuicConnectionTest, FramePackingNonCryptoThenCrypto) { | 1616 TEST_P(QuicConnectionTest, FramePackingNonCryptoThenCrypto) { |
| 1640 CongestionBlockWrites(); | 1617 CongestionBlockWrites(); |
| 1641 | 1618 |
| 1642 // Send an ack and two stream frames (one non-crypto, then one crypto) in 2 | 1619 // Send an ack and two stream frames (one non-crypto, then one crypto) in 2 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1719 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( | 1696 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( |
| 1720 IgnoreResult(InvokeWithoutArgs(&connection_, | 1697 IgnoreResult(InvokeWithoutArgs(&connection_, |
| 1721 &TestConnection::SendStreamData3)), | 1698 &TestConnection::SendStreamData3)), |
| 1722 IgnoreResult(InvokeWithoutArgs(&connection_, | 1699 IgnoreResult(InvokeWithoutArgs(&connection_, |
| 1723 &TestConnection::SendStreamData5)))); | 1700 &TestConnection::SendStreamData5)))); |
| 1724 | 1701 |
| 1725 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 1702 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
| 1726 | 1703 |
| 1727 // Process an ack to cause the visitor's OnCanWrite to be invoked. | 1704 // Process an ack to cause the visitor's OnCanWrite to be invoked. |
| 1728 peer_creator_.set_sequence_number(2); | 1705 peer_creator_.set_sequence_number(2); |
| 1729 QuicAckFrame ack_one = InitAckFrame(0, 0); | 1706 QuicAckFrame ack_one = InitAckFrame(0); |
| 1730 ProcessAckPacket(&ack_one); | 1707 ProcessAckPacket(&ack_one); |
| 1731 | 1708 |
| 1732 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1709 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 1733 EXPECT_FALSE(connection_.HasQueuedData()); | 1710 EXPECT_FALSE(connection_.HasQueuedData()); |
| 1734 | 1711 |
| 1735 // Parse the last packet and ensure it's an ack and two stream frames from | 1712 // Parse the last packet and ensure it's an ack and two stream frames from |
| 1736 // two different streams. | 1713 // two different streams. |
| 1737 if (version() > QUIC_VERSION_15) { | 1714 EXPECT_EQ(4u, writer_->frame_count()); |
| 1738 EXPECT_EQ(4u, writer_->frame_count()); | 1715 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); |
| 1739 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); | |
| 1740 } else { | |
| 1741 EXPECT_EQ(3u, writer_->frame_count()); | |
| 1742 } | |
| 1743 EXPECT_FALSE(writer_->ack_frames().empty()); | 1716 EXPECT_FALSE(writer_->ack_frames().empty()); |
| 1744 ASSERT_EQ(2u, writer_->stream_frames().size()); | 1717 ASSERT_EQ(2u, writer_->stream_frames().size()); |
| 1745 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0].stream_id); | 1718 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0].stream_id); |
| 1746 EXPECT_EQ(kClientDataStreamId2, writer_->stream_frames()[1].stream_id); | 1719 EXPECT_EQ(kClientDataStreamId2, writer_->stream_frames()[1].stream_id); |
| 1747 } | 1720 } |
| 1748 | 1721 |
| 1749 TEST_P(QuicConnectionTest, FramePackingSendv) { | 1722 TEST_P(QuicConnectionTest, FramePackingSendv) { |
| 1750 // Send data in 1 packet by writing multiple blocks in a single iovector | 1723 // Send data in 1 packet by writing multiple blocks in a single iovector |
| 1751 // using writev. | 1724 // using writev. |
| 1752 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 1725 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1839 QuicByteCount second_packet_size; | 1812 QuicByteCount second_packet_size; |
| 1840 SendStreamDataToPeer(3, "foo", 0, !kFin, &last_packet); // Packet 1 | 1813 SendStreamDataToPeer(3, "foo", 0, !kFin, &last_packet); // Packet 1 |
| 1841 second_packet_size = | 1814 second_packet_size = |
| 1842 SendStreamDataToPeer(3, "foos", 3, !kFin, &last_packet); // Packet 2 | 1815 SendStreamDataToPeer(3, "foos", 3, !kFin, &last_packet); // Packet 2 |
| 1843 SendStreamDataToPeer(3, "fooos", 7, !kFin, &last_packet); // Packet 3 | 1816 SendStreamDataToPeer(3, "fooos", 7, !kFin, &last_packet); // Packet 3 |
| 1844 | 1817 |
| 1845 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1818 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1846 | 1819 |
| 1847 // Don't lose a packet on an ack, and nothing is retransmitted. | 1820 // Don't lose a packet on an ack, and nothing is retransmitted. |
| 1848 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 1821 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 1849 QuicAckFrame ack_one = InitAckFrame(1, 0); | 1822 QuicAckFrame ack_one = InitAckFrame(1); |
| 1850 ProcessAckPacket(&ack_one); | 1823 ProcessAckPacket(&ack_one); |
| 1851 | 1824 |
| 1852 // Lose a packet and ensure it triggers retransmission. | 1825 // Lose a packet and ensure it triggers retransmission. |
| 1853 QuicAckFrame nack_two = InitAckFrame(3, 0); | 1826 QuicAckFrame nack_two = InitAckFrame(3); |
| 1854 NackPacket(2, &nack_two); | 1827 NackPacket(2, &nack_two); |
| 1855 SequenceNumberSet lost_packets; | 1828 SequenceNumberSet lost_packets; |
| 1856 lost_packets.insert(2); | 1829 lost_packets.insert(2); |
| 1857 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) | 1830 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
| 1858 .WillOnce(Return(lost_packets)); | 1831 .WillOnce(Return(lost_packets)); |
| 1859 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 1832 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 1860 EXPECT_CALL(*send_algorithm_, | 1833 EXPECT_CALL(*send_algorithm_, |
| 1861 OnPacketSent(_, _, _, second_packet_size - kQuicVersionSize, _)). | 1834 OnPacketSent(_, _, _, second_packet_size - kQuicVersionSize, _)). |
| 1862 Times(1); | 1835 Times(1); |
| 1863 ProcessAckPacket(&nack_two); | 1836 ProcessAckPacket(&nack_two); |
| 1864 } | 1837 } |
| 1865 | 1838 |
| 1866 TEST_P(QuicConnectionTest, DiscardRetransmit) { | 1839 TEST_P(QuicConnectionTest, DiscardRetransmit) { |
| 1867 QuicPacketSequenceNumber last_packet; | 1840 QuicPacketSequenceNumber last_packet; |
| 1868 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 | 1841 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 |
| 1869 SendStreamDataToPeer(1, "foos", 3, !kFin, &last_packet); // Packet 2 | 1842 SendStreamDataToPeer(1, "foos", 3, !kFin, &last_packet); // Packet 2 |
| 1870 SendStreamDataToPeer(1, "fooos", 7, !kFin, &last_packet); // Packet 3 | 1843 SendStreamDataToPeer(1, "fooos", 7, !kFin, &last_packet); // Packet 3 |
| 1871 | 1844 |
| 1872 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1845 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1873 | 1846 |
| 1874 // Instigate a loss with an ack. | 1847 // Instigate a loss with an ack. |
| 1875 QuicAckFrame nack_two = InitAckFrame(3, 0); | 1848 QuicAckFrame nack_two = InitAckFrame(3); |
| 1876 NackPacket(2, &nack_two); | 1849 NackPacket(2, &nack_two); |
| 1877 // The first nack should trigger a fast retransmission, but we'll be | 1850 // The first nack should trigger a fast retransmission, but we'll be |
| 1878 // write blocked, so the packet will be queued. | 1851 // write blocked, so the packet will be queued. |
| 1879 BlockOnNextWrite(); | 1852 BlockOnNextWrite(); |
| 1880 SequenceNumberSet lost_packets; | 1853 SequenceNumberSet lost_packets; |
| 1881 lost_packets.insert(2); | 1854 lost_packets.insert(2); |
| 1882 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) | 1855 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
| 1883 .WillOnce(Return(lost_packets)); | 1856 .WillOnce(Return(lost_packets)); |
| 1884 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 1857 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 1885 ProcessAckPacket(&nack_two); | 1858 ProcessAckPacket(&nack_two); |
| 1886 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 1859 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 1887 | 1860 |
| 1888 // Now, ack the previous transmission. | 1861 // Now, ack the previous transmission. |
| 1889 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) | 1862 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
| 1890 .WillOnce(Return(SequenceNumberSet())); | 1863 .WillOnce(Return(SequenceNumberSet())); |
| 1891 QuicAckFrame ack_all = InitAckFrame(3, 0); | 1864 QuicAckFrame ack_all = InitAckFrame(3); |
| 1892 ProcessAckPacket(&ack_all); | 1865 ProcessAckPacket(&ack_all); |
| 1893 | 1866 |
| 1894 // Unblock the socket and attempt to send the queued packets. However, | 1867 // Unblock the socket and attempt to send the queued packets. However, |
| 1895 // since the previous transmission has been acked, we will not | 1868 // since the previous transmission has been acked, we will not |
| 1896 // send the retransmission. | 1869 // send the retransmission. |
| 1897 EXPECT_CALL(*send_algorithm_, | 1870 EXPECT_CALL(*send_algorithm_, |
| 1898 OnPacketSent(_, _, _, _, _)).Times(0); | 1871 OnPacketSent(_, _, _, _, _)).Times(0); |
| 1899 | 1872 |
| 1900 writer_->SetWritable(); | 1873 writer_->SetWritable(); |
| 1901 connection_.OnCanWrite(); | 1874 connection_.OnCanWrite(); |
| 1902 | 1875 |
| 1903 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1876 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 1904 } | 1877 } |
| 1905 | 1878 |
| 1906 TEST_P(QuicConnectionTest, RetransmitNackedLargestObserved) { | 1879 TEST_P(QuicConnectionTest, RetransmitNackedLargestObserved) { |
| 1907 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1880 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1908 QuicPacketSequenceNumber largest_observed; | 1881 QuicPacketSequenceNumber largest_observed; |
| 1909 QuicByteCount packet_size; | 1882 QuicByteCount packet_size; |
| 1910 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 1883 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
| 1911 .WillOnce(DoAll(SaveArg<2>(&largest_observed), SaveArg<3>(&packet_size), | 1884 .WillOnce(DoAll(SaveArg<2>(&largest_observed), SaveArg<3>(&packet_size), |
| 1912 Return(true))); | 1885 Return(true))); |
| 1913 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); | 1886 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); |
| 1914 | 1887 |
| 1915 QuicAckFrame frame = InitAckFrame(1, largest_observed); | 1888 QuicAckFrame frame = InitAckFrame(1); |
| 1916 NackPacket(largest_observed, &frame); | 1889 NackPacket(largest_observed, &frame); |
| 1917 // The first nack should retransmit the largest observed packet. | 1890 // The first nack should retransmit the largest observed packet. |
| 1918 SequenceNumberSet lost_packets; | 1891 SequenceNumberSet lost_packets; |
| 1919 lost_packets.insert(1); | 1892 lost_packets.insert(1); |
| 1920 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) | 1893 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
| 1921 .WillOnce(Return(lost_packets)); | 1894 .WillOnce(Return(lost_packets)); |
| 1922 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 1895 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 1923 EXPECT_CALL(*send_algorithm_, | 1896 EXPECT_CALL(*send_algorithm_, |
| 1924 OnPacketSent(_, _, _, packet_size - kQuicVersionSize, _)); | 1897 OnPacketSent(_, _, _, packet_size - kQuicVersionSize, _)); |
| 1925 ProcessAckPacket(&frame); | 1898 ProcessAckPacket(&frame); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1963 | 1936 |
| 1964 TEST_P(QuicConnectionTest, WriteBlockedAckedThenSent) { | 1937 TEST_P(QuicConnectionTest, WriteBlockedAckedThenSent) { |
| 1965 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1938 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1966 BlockOnNextWrite(); | 1939 BlockOnNextWrite(); |
| 1967 writer_->set_is_write_blocked_data_buffered(true); | 1940 writer_->set_is_write_blocked_data_buffered(true); |
| 1968 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); | 1941 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); |
| 1969 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); | 1942 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); |
| 1970 | 1943 |
| 1971 // Ack the sent packet before the callback returns, which happens in | 1944 // Ack the sent packet before the callback returns, which happens in |
| 1972 // rare circumstances with write blocked sockets. | 1945 // rare circumstances with write blocked sockets. |
| 1973 QuicAckFrame ack = InitAckFrame(1, 0); | 1946 QuicAckFrame ack = InitAckFrame(1); |
| 1974 ProcessAckPacket(&ack); | 1947 ProcessAckPacket(&ack); |
| 1975 | 1948 |
| 1976 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); | 1949 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); |
| 1977 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0)); | 1950 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0)); |
| 1978 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); | 1951 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); |
| 1979 } | 1952 } |
| 1980 | 1953 |
| 1981 TEST_P(QuicConnectionTest, RetransmitWriteBlockedAckedOriginalThenSent) { | 1954 TEST_P(QuicConnectionTest, RetransmitWriteBlockedAckedOriginalThenSent) { |
| 1982 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1955 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1983 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); | 1956 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); |
| 1984 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); | 1957 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); |
| 1985 | 1958 |
| 1986 BlockOnNextWrite(); | 1959 BlockOnNextWrite(); |
| 1987 writer_->set_is_write_blocked_data_buffered(true); | 1960 writer_->set_is_write_blocked_data_buffered(true); |
| 1988 // Simulate the retransmission alarm firing. | 1961 // Simulate the retransmission alarm firing. |
| 1989 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(_)); | 1962 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(_)); |
| 1990 clock_.AdvanceTime(DefaultRetransmissionTime()); | 1963 clock_.AdvanceTime(DefaultRetransmissionTime()); |
| 1991 connection_.GetRetransmissionAlarm()->Fire(); | 1964 connection_.GetRetransmissionAlarm()->Fire(); |
| 1992 | 1965 |
| 1993 // Ack the sent packet before the callback returns, which happens in | 1966 // Ack the sent packet before the callback returns, which happens in |
| 1994 // rare circumstances with write blocked sockets. | 1967 // rare circumstances with write blocked sockets. |
| 1995 QuicAckFrame ack = InitAckFrame(1, 0); | 1968 QuicAckFrame ack = InitAckFrame(1); |
| 1996 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 1969 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 1997 EXPECT_CALL(*send_algorithm_, RevertRetransmissionTimeout()); | 1970 EXPECT_CALL(*send_algorithm_, RevertRetransmissionTimeout()); |
| 1998 ProcessAckPacket(&ack); | 1971 ProcessAckPacket(&ack); |
| 1999 | 1972 |
| 2000 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0)); | 1973 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0)); |
| 2001 // There is now a pending packet, but with no retransmittable frames. | 1974 // There is now a pending packet, but with no retransmittable frames. |
| 2002 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); | 1975 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); |
| 2003 EXPECT_FALSE(connection_.sent_packet_manager().HasRetransmittableFrames(2)); | 1976 EXPECT_FALSE(connection_.sent_packet_manager().HasRetransmittableFrames(2)); |
| 2004 } | 1977 } |
| 2005 | 1978 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2024 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1997 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2025 int offset = 0; | 1998 int offset = 0; |
| 2026 // Send packets 1 to 15. | 1999 // Send packets 1 to 15. |
| 2027 for (int i = 0; i < 15; ++i) { | 2000 for (int i = 0; i < 15; ++i) { |
| 2028 SendStreamDataToPeer(1, "foo", offset, !kFin, NULL); | 2001 SendStreamDataToPeer(1, "foo", offset, !kFin, NULL); |
| 2029 offset += 3; | 2002 offset += 3; |
| 2030 } | 2003 } |
| 2031 | 2004 |
| 2032 // Ack 15, nack 1-14. | 2005 // Ack 15, nack 1-14. |
| 2033 SequenceNumberSet lost_packets; | 2006 SequenceNumberSet lost_packets; |
| 2034 QuicAckFrame nack = InitAckFrame(15, 0); | 2007 QuicAckFrame nack = InitAckFrame(15); |
| 2035 for (int i = 1; i < 15; ++i) { | 2008 for (int i = 1; i < 15; ++i) { |
| 2036 NackPacket(i, &nack); | 2009 NackPacket(i, &nack); |
| 2037 lost_packets.insert(i); | 2010 lost_packets.insert(i); |
| 2038 } | 2011 } |
| 2039 | 2012 |
| 2040 // 14 packets have been NACK'd and lost. In TCP cubic, PRR limits | 2013 // 14 packets have been NACK'd and lost. In TCP cubic, PRR limits |
| 2041 // the retransmission rate in the case of burst losses. | 2014 // the retransmission rate in the case of burst losses. |
| 2042 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) | 2015 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
| 2043 .WillOnce(Return(lost_packets)); | 2016 .WillOnce(Return(lost_packets)); |
| 2044 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 2017 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2056 SendAckPacketToPeer(); // Packet 3 | 2029 SendAckPacketToPeer(); // Packet 3 |
| 2057 SendStreamDataToPeer(5, "foo", 0, !kFin, &last_packet); // Packet 4 | 2030 SendStreamDataToPeer(5, "foo", 0, !kFin, &last_packet); // Packet 4 |
| 2058 EXPECT_EQ(4u, last_packet); | 2031 EXPECT_EQ(4u, last_packet); |
| 2059 SendStreamDataToPeer(1, "foo", 3, !kFin, &last_packet); // Packet 5 | 2032 SendStreamDataToPeer(1, "foo", 3, !kFin, &last_packet); // Packet 5 |
| 2060 EXPECT_EQ(5u, last_packet); | 2033 EXPECT_EQ(5u, last_packet); |
| 2061 SendStreamDataToPeer(3, "foo", 3, !kFin, &last_packet); // Packet 6 | 2034 SendStreamDataToPeer(3, "foo", 3, !kFin, &last_packet); // Packet 6 |
| 2062 EXPECT_EQ(6u, last_packet); | 2035 EXPECT_EQ(6u, last_packet); |
| 2063 | 2036 |
| 2064 // Client will ack packets 1, 2, [!3], 4, 5. | 2037 // Client will ack packets 1, 2, [!3], 4, 5. |
| 2065 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 2038 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 2066 QuicAckFrame frame1 = InitAckFrame(5, 0); | 2039 QuicAckFrame frame1 = InitAckFrame(5); |
| 2067 NackPacket(3, &frame1); | 2040 NackPacket(3, &frame1); |
| 2068 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2041 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2069 ProcessAckPacket(&frame1); | 2042 ProcessAckPacket(&frame1); |
| 2070 | 2043 |
| 2071 // Now the client implicitly acks 3, and explicitly acks 6. | 2044 // Now the client implicitly acks 3, and explicitly acks 6. |
| 2072 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 2045 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 2073 QuicAckFrame frame2 = InitAckFrame(6, 0); | 2046 QuicAckFrame frame2 = InitAckFrame(6); |
| 2074 ProcessAckPacket(&frame2); | 2047 ProcessAckPacket(&frame2); |
| 2075 } | 2048 } |
| 2076 | 2049 |
| 2077 TEST_P(QuicConnectionTest, DontLatchUnackedPacket) { | 2050 TEST_P(QuicConnectionTest, DontLatchUnackedPacket) { |
| 2078 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); // Packet 1; | 2051 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); // Packet 1; |
| 2079 // From now on, we send acks, so the send algorithm won't mark them pending. | 2052 // From now on, we send acks, so the send algorithm won't mark them pending. |
| 2080 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 2053 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
| 2081 .WillByDefault(Return(false)); | 2054 .WillByDefault(Return(false)); |
| 2082 SendAckPacketToPeer(); // Packet 2 | 2055 SendAckPacketToPeer(); // Packet 2 |
| 2083 | 2056 |
| 2084 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2057 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2085 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 2058 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 2086 QuicAckFrame frame = InitAckFrame(1, 0); | 2059 QuicAckFrame frame = InitAckFrame(1); |
| 2087 ProcessAckPacket(&frame); | 2060 ProcessAckPacket(&frame); |
| 2088 | 2061 |
| 2089 // Verify that our internal state has least-unacked as 2, because we're still | 2062 // Verify that our internal state has least-unacked as 2, because we're still |
| 2090 // waiting for a potential ack for 2. | 2063 // waiting for a potential ack for 2. |
| 2091 EXPECT_EQ(2u, outgoing_ack()->sent_info.least_unacked); | 2064 |
| 2065 EXPECT_EQ(2u, stop_waiting()->least_unacked); |
| 2092 | 2066 |
| 2093 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 2067 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 2094 frame = InitAckFrame(2, 0); | 2068 frame = InitAckFrame(2); |
| 2095 ProcessAckPacket(&frame); | 2069 ProcessAckPacket(&frame); |
| 2096 EXPECT_EQ(3u, outgoing_ack()->sent_info.least_unacked); | 2070 EXPECT_EQ(3u, stop_waiting()->least_unacked); |
| 2097 | 2071 |
| 2098 // When we send an ack, we make sure our least-unacked makes sense. In this | 2072 // When we send an ack, we make sure our least-unacked makes sense. In this |
| 2099 // case since we're not waiting on an ack for 2 and all packets are acked, we | 2073 // case since we're not waiting on an ack for 2 and all packets are acked, we |
| 2100 // set it to 3. | 2074 // set it to 3. |
| 2101 SendAckPacketToPeer(); // Packet 3 | 2075 SendAckPacketToPeer(); // Packet 3 |
| 2102 // Least_unacked remains at 3 until another ack is received. | 2076 // Least_unacked remains at 3 until another ack is received. |
| 2103 EXPECT_EQ(3u, outgoing_ack()->sent_info.least_unacked); | 2077 EXPECT_EQ(3u, stop_waiting()->least_unacked); |
| 2104 // Check that the outgoing ack had its sequence number as least_unacked. | 2078 // Check that the outgoing ack had its sequence number as least_unacked. |
| 2105 EXPECT_EQ(3u, least_unacked()); | 2079 EXPECT_EQ(3u, least_unacked()); |
| 2106 | 2080 |
| 2107 // Ack the ack, which updates the rtt and raises the least unacked. | 2081 // Ack the ack, which updates the rtt and raises the least unacked. |
| 2108 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 2082 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 2109 frame = InitAckFrame(3, 0); | 2083 frame = InitAckFrame(3); |
| 2110 ProcessAckPacket(&frame); | 2084 ProcessAckPacket(&frame); |
| 2111 | 2085 |
| 2112 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 2086 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
| 2113 .WillByDefault(Return(true)); | 2087 .WillByDefault(Return(true)); |
| 2114 SendStreamDataToPeer(1, "bar", 3, false, NULL); // Packet 4 | 2088 SendStreamDataToPeer(1, "bar", 3, false, NULL); // Packet 4 |
| 2115 EXPECT_EQ(4u, outgoing_ack()->sent_info.least_unacked); | 2089 EXPECT_EQ(4u, stop_waiting()->least_unacked); |
| 2116 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 2090 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
| 2117 .WillByDefault(Return(false)); | 2091 .WillByDefault(Return(false)); |
| 2118 SendAckPacketToPeer(); // Packet 5 | 2092 SendAckPacketToPeer(); // Packet 5 |
| 2119 EXPECT_EQ(4u, least_unacked()); | 2093 EXPECT_EQ(4u, least_unacked()); |
| 2120 | 2094 |
| 2121 // Send two data packets at the end, and ensure if the last one is acked, | 2095 // Send two data packets at the end, and ensure if the last one is acked, |
| 2122 // the least unacked is raised above the ack packets. | 2096 // the least unacked is raised above the ack packets. |
| 2123 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 2097 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
| 2124 .WillByDefault(Return(true)); | 2098 .WillByDefault(Return(true)); |
| 2125 SendStreamDataToPeer(1, "bar", 6, false, NULL); // Packet 6 | 2099 SendStreamDataToPeer(1, "bar", 6, false, NULL); // Packet 6 |
| 2126 SendStreamDataToPeer(1, "bar", 9, false, NULL); // Packet 7 | 2100 SendStreamDataToPeer(1, "bar", 9, false, NULL); // Packet 7 |
| 2127 | 2101 |
| 2128 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 2102 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 2129 frame = InitAckFrame(7, 0); | 2103 frame = InitAckFrame(7); |
| 2130 NackPacket(5, &frame); | 2104 NackPacket(5, &frame); |
| 2131 NackPacket(6, &frame); | 2105 NackPacket(6, &frame); |
| 2132 ProcessAckPacket(&frame); | 2106 ProcessAckPacket(&frame); |
| 2133 | 2107 |
| 2134 EXPECT_EQ(6u, outgoing_ack()->sent_info.least_unacked); | 2108 EXPECT_EQ(6u, stop_waiting()->least_unacked); |
| 2135 } | 2109 } |
| 2136 | 2110 |
| 2137 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterFecPacket) { | 2111 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterFecPacket) { |
| 2138 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2112 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2139 | 2113 |
| 2140 // Don't send missing packet 1. | 2114 // Don't send missing packet 1. |
| 2141 ProcessFecPacket(2, 1, true, !kEntropyFlag, NULL); | 2115 ProcessFecPacket(2, 1, true, !kEntropyFlag, NULL); |
| 2142 // Entropy flag should be false, so entropy should be 0. | 2116 // Entropy flag should be false, so entropy should be 0. |
| 2143 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); | 2117 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); |
| 2144 } | 2118 } |
| 2145 | 2119 |
| 2146 TEST_P(QuicConnectionTest, ReviveMissingPacketWithVaryingSeqNumLengths) { | 2120 TEST_P(QuicConnectionTest, ReviveMissingPacketWithVaryingSeqNumLengths) { |
| 2147 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2121 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2148 | 2122 |
| 2149 // Set up a debug visitor to the connection. | 2123 // Set up a debug visitor to the connection. |
| 2150 scoped_ptr<FecQuicConnectionDebugVisitor> | 2124 FecQuicConnectionDebugVisitor* fec_visitor = |
| 2151 fec_visitor(new FecQuicConnectionDebugVisitor); | 2125 new FecQuicConnectionDebugVisitor(); |
| 2152 connection_.set_debug_visitor(fec_visitor.get()); | 2126 connection_.set_debug_visitor(fec_visitor); |
| 2153 | 2127 |
| 2154 QuicPacketSequenceNumber fec_packet = 0; | 2128 QuicPacketSequenceNumber fec_packet = 0; |
| 2155 QuicSequenceNumberLength lengths[] = {PACKET_6BYTE_SEQUENCE_NUMBER, | 2129 QuicSequenceNumberLength lengths[] = {PACKET_6BYTE_SEQUENCE_NUMBER, |
| 2156 PACKET_4BYTE_SEQUENCE_NUMBER, | 2130 PACKET_4BYTE_SEQUENCE_NUMBER, |
| 2157 PACKET_2BYTE_SEQUENCE_NUMBER, | 2131 PACKET_2BYTE_SEQUENCE_NUMBER, |
| 2158 PACKET_1BYTE_SEQUENCE_NUMBER}; | 2132 PACKET_1BYTE_SEQUENCE_NUMBER}; |
| 2159 // For each sequence number length size, revive a packet and check sequence | 2133 // For each sequence number length size, revive a packet and check sequence |
| 2160 // number length in the revived packet. | 2134 // number length in the revived packet. |
| 2161 for (size_t i = 0; i < arraysize(lengths); ++i) { | 2135 for (size_t i = 0; i < arraysize(lengths); ++i) { |
| 2162 // Set sequence_number_length_ (for data and FEC packets). | 2136 // Set sequence_number_length_ (for data and FEC packets). |
| 2163 sequence_number_length_ = lengths[i]; | 2137 sequence_number_length_ = lengths[i]; |
| 2164 fec_packet += 2; | 2138 fec_packet += 2; |
| 2165 // Don't send missing packet, but send fec packet right after it. | 2139 // Don't send missing packet, but send fec packet right after it. |
| 2166 ProcessFecPacket(fec_packet, fec_packet - 1, true, !kEntropyFlag, NULL); | 2140 ProcessFecPacket(fec_packet, fec_packet - 1, true, !kEntropyFlag, NULL); |
| 2167 // Sequence number length in the revived header should be the same as | 2141 // Sequence number length in the revived header should be the same as |
| 2168 // in the original data/fec packet headers. | 2142 // in the original data/fec packet headers. |
| 2169 EXPECT_EQ(sequence_number_length_, fec_visitor->revived_header(). | 2143 EXPECT_EQ(sequence_number_length_, fec_visitor->revived_header(). |
| 2170 public_header.sequence_number_length); | 2144 public_header.sequence_number_length); |
| 2171 } | 2145 } |
| 2172 } | 2146 } |
| 2173 | 2147 |
| 2174 TEST_P(QuicConnectionTest, ReviveMissingPacketWithVaryingConnectionIdLengths) { | 2148 TEST_P(QuicConnectionTest, ReviveMissingPacketWithVaryingConnectionIdLengths) { |
| 2175 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2149 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2176 | 2150 |
| 2177 // Set up a debug visitor to the connection. | 2151 // Set up a debug visitor to the connection. |
| 2178 scoped_ptr<FecQuicConnectionDebugVisitor> | 2152 FecQuicConnectionDebugVisitor* fec_visitor = |
| 2179 fec_visitor(new FecQuicConnectionDebugVisitor); | 2153 new FecQuicConnectionDebugVisitor(); |
| 2180 connection_.set_debug_visitor(fec_visitor.get()); | 2154 connection_.set_debug_visitor(fec_visitor); |
| 2181 | 2155 |
| 2182 QuicPacketSequenceNumber fec_packet = 0; | 2156 QuicPacketSequenceNumber fec_packet = 0; |
| 2183 QuicConnectionIdLength lengths[] = {PACKET_8BYTE_CONNECTION_ID, | 2157 QuicConnectionIdLength lengths[] = {PACKET_8BYTE_CONNECTION_ID, |
| 2184 PACKET_4BYTE_CONNECTION_ID, | 2158 PACKET_4BYTE_CONNECTION_ID, |
| 2185 PACKET_1BYTE_CONNECTION_ID, | 2159 PACKET_1BYTE_CONNECTION_ID, |
| 2186 PACKET_0BYTE_CONNECTION_ID}; | 2160 PACKET_0BYTE_CONNECTION_ID}; |
| 2187 // For each connection id length size, revive a packet and check connection | 2161 // For each connection id length size, revive a packet and check connection |
| 2188 // id length in the revived packet. | 2162 // id length in the revived packet. |
| 2189 for (size_t i = 0; i < arraysize(lengths); ++i) { | 2163 for (size_t i = 0; i < arraysize(lengths); ++i) { |
| 2190 // Set connection id length (for data and FEC packets). | 2164 // Set connection id length (for data and FEC packets). |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2244 // Ensure entropy is not revived for the missing packet. | 2218 // Ensure entropy is not revived for the missing packet. |
| 2245 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); | 2219 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); |
| 2246 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 3)); | 2220 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 3)); |
| 2247 } | 2221 } |
| 2248 | 2222 |
| 2249 TEST_P(QuicConnectionTest, TLP) { | 2223 TEST_P(QuicConnectionTest, TLP) { |
| 2250 QuicSentPacketManagerPeer::SetMaxTailLossProbes( | 2224 QuicSentPacketManagerPeer::SetMaxTailLossProbes( |
| 2251 QuicConnectionPeer::GetSentPacketManager(&connection_), 1); | 2225 QuicConnectionPeer::GetSentPacketManager(&connection_), 1); |
| 2252 | 2226 |
| 2253 SendStreamDataToPeer(3, "foo", 0, !kFin, NULL); | 2227 SendStreamDataToPeer(3, "foo", 0, !kFin, NULL); |
| 2254 EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked); | 2228 EXPECT_EQ(1u, stop_waiting()->least_unacked); |
| 2255 QuicTime retransmission_time = | 2229 QuicTime retransmission_time = |
| 2256 connection_.GetRetransmissionAlarm()->deadline(); | 2230 connection_.GetRetransmissionAlarm()->deadline(); |
| 2257 EXPECT_NE(QuicTime::Zero(), retransmission_time); | 2231 EXPECT_NE(QuicTime::Zero(), retransmission_time); |
| 2258 | 2232 |
| 2259 EXPECT_EQ(1u, writer_->header().packet_sequence_number); | 2233 EXPECT_EQ(1u, writer_->header().packet_sequence_number); |
| 2260 // Simulate the retransmission alarm firing and sending a tlp, | 2234 // Simulate the retransmission alarm firing and sending a tlp, |
| 2261 // so send algorithm's OnRetransmissionTimeout is not called. | 2235 // so send algorithm's OnRetransmissionTimeout is not called. |
| 2262 clock_.AdvanceTime(retransmission_time.Subtract(clock_.Now())); | 2236 clock_.AdvanceTime(retransmission_time.Subtract(clock_.Now())); |
| 2263 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _)); | 2237 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _)); |
| 2264 connection_.GetRetransmissionAlarm()->Fire(); | 2238 connection_.GetRetransmissionAlarm()->Fire(); |
| 2265 EXPECT_EQ(2u, writer_->header().packet_sequence_number); | 2239 EXPECT_EQ(2u, writer_->header().packet_sequence_number); |
| 2266 // We do not raise the high water mark yet. | 2240 // We do not raise the high water mark yet. |
| 2267 EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked); | 2241 EXPECT_EQ(1u, stop_waiting()->least_unacked); |
| 2268 } | 2242 } |
| 2269 | 2243 |
| 2270 TEST_P(QuicConnectionTest, RTO) { | 2244 TEST_P(QuicConnectionTest, RTO) { |
| 2271 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( | 2245 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( |
| 2272 DefaultRetransmissionTime()); | 2246 DefaultRetransmissionTime()); |
| 2273 SendStreamDataToPeer(3, "foo", 0, !kFin, NULL); | 2247 SendStreamDataToPeer(3, "foo", 0, !kFin, NULL); |
| 2274 EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked); | 2248 EXPECT_EQ(1u, stop_waiting()->least_unacked); |
| 2275 | 2249 |
| 2276 EXPECT_EQ(1u, writer_->header().packet_sequence_number); | 2250 EXPECT_EQ(1u, writer_->header().packet_sequence_number); |
| 2277 EXPECT_EQ(default_retransmission_time, | 2251 EXPECT_EQ(default_retransmission_time, |
| 2278 connection_.GetRetransmissionAlarm()->deadline()); | 2252 connection_.GetRetransmissionAlarm()->deadline()); |
| 2279 // Simulate the retransmission alarm firing. | 2253 // Simulate the retransmission alarm firing. |
| 2280 clock_.AdvanceTime(DefaultRetransmissionTime()); | 2254 clock_.AdvanceTime(DefaultRetransmissionTime()); |
| 2281 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); | 2255 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
| 2282 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _)); | 2256 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _)); |
| 2283 connection_.GetRetransmissionAlarm()->Fire(); | 2257 connection_.GetRetransmissionAlarm()->Fire(); |
| 2284 EXPECT_EQ(2u, writer_->header().packet_sequence_number); | 2258 EXPECT_EQ(2u, writer_->header().packet_sequence_number); |
| 2285 // We do not raise the high water mark yet. | 2259 // We do not raise the high water mark yet. |
| 2286 EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked); | 2260 EXPECT_EQ(1u, stop_waiting()->least_unacked); |
| 2287 } | 2261 } |
| 2288 | 2262 |
| 2289 TEST_P(QuicConnectionTest, RTOWithSameEncryptionLevel) { | 2263 TEST_P(QuicConnectionTest, RTOWithSameEncryptionLevel) { |
| 2290 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( | 2264 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( |
| 2291 DefaultRetransmissionTime()); | 2265 DefaultRetransmissionTime()); |
| 2292 use_tagging_decrypter(); | 2266 use_tagging_decrypter(); |
| 2293 | 2267 |
| 2294 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at | 2268 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at |
| 2295 // the end of the packet. We can test this to check which encrypter was used. | 2269 // the end of the packet. We can test this to check which encrypter was used. |
| 2296 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); | 2270 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2487 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) | 2461 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
| 2488 .WillOnce(Return(lost_packets)); | 2462 .WillOnce(Return(lost_packets)); |
| 2489 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 2463 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 2490 QuicPacketSequenceNumber nack_sequence_number = 0; | 2464 QuicPacketSequenceNumber nack_sequence_number = 0; |
| 2491 // Ack packets might generate some other packets, which are not | 2465 // Ack packets might generate some other packets, which are not |
| 2492 // retransmissions. (More ack packets). | 2466 // retransmissions. (More ack packets). |
| 2493 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 2467 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
| 2494 .Times(AnyNumber()); | 2468 .Times(AnyNumber()); |
| 2495 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 2469 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
| 2496 .WillOnce(DoAll(SaveArg<2>(&nack_sequence_number), Return(true))); | 2470 .WillOnce(DoAll(SaveArg<2>(&nack_sequence_number), Return(true))); |
| 2497 QuicAckFrame ack = InitAckFrame(rto_sequence_number, 0); | 2471 QuicAckFrame ack = InitAckFrame(rto_sequence_number); |
| 2498 // Nack the retransmitted packet. | 2472 // Nack the retransmitted packet. |
| 2499 NackPacket(original_sequence_number, &ack); | 2473 NackPacket(original_sequence_number, &ack); |
| 2500 NackPacket(rto_sequence_number, &ack); | 2474 NackPacket(rto_sequence_number, &ack); |
| 2501 ProcessAckPacket(&ack); | 2475 ProcessAckPacket(&ack); |
| 2502 | 2476 |
| 2503 ASSERT_NE(0u, nack_sequence_number); | 2477 ASSERT_NE(0u, nack_sequence_number); |
| 2504 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission( | 2478 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission( |
| 2505 &connection_, rto_sequence_number)); | 2479 &connection_, rto_sequence_number)); |
| 2506 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission( | 2480 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission( |
| 2507 &connection_, nack_sequence_number)); | 2481 &connection_, nack_sequence_number)); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2529 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, NULL); | 2503 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, NULL); |
| 2530 QuicAlarm* retransmission_alarm = connection_.GetRetransmissionAlarm(); | 2504 QuicAlarm* retransmission_alarm = connection_.GetRetransmissionAlarm(); |
| 2531 EXPECT_TRUE(retransmission_alarm->IsSet()); | 2505 EXPECT_TRUE(retransmission_alarm->IsSet()); |
| 2532 EXPECT_EQ(clock_.Now().Add(DefaultRetransmissionTime()), | 2506 EXPECT_EQ(clock_.Now().Add(DefaultRetransmissionTime()), |
| 2533 retransmission_alarm->deadline()); | 2507 retransmission_alarm->deadline()); |
| 2534 | 2508 |
| 2535 // Advance the time right before the RTO, then receive an ack for the first | 2509 // Advance the time right before the RTO, then receive an ack for the first |
| 2536 // packet to delay the RTO. | 2510 // packet to delay the RTO. |
| 2537 clock_.AdvanceTime(DefaultRetransmissionTime()); | 2511 clock_.AdvanceTime(DefaultRetransmissionTime()); |
| 2538 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 2512 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 2539 QuicAckFrame ack = InitAckFrame(1, 0); | 2513 QuicAckFrame ack = InitAckFrame(1); |
| 2540 ProcessAckPacket(&ack); | 2514 ProcessAckPacket(&ack); |
| 2541 EXPECT_TRUE(retransmission_alarm->IsSet()); | 2515 EXPECT_TRUE(retransmission_alarm->IsSet()); |
| 2542 EXPECT_GT(retransmission_alarm->deadline(), clock_.Now()); | 2516 EXPECT_GT(retransmission_alarm->deadline(), clock_.Now()); |
| 2543 | 2517 |
| 2544 // Move forward past the original RTO and ensure the RTO is still pending. | 2518 // Move forward past the original RTO and ensure the RTO is still pending. |
| 2545 clock_.AdvanceTime(DefaultRetransmissionTime().Multiply(2)); | 2519 clock_.AdvanceTime(DefaultRetransmissionTime().Multiply(2)); |
| 2546 | 2520 |
| 2547 // Ensure the second packet gets retransmitted when it finally fires. | 2521 // Ensure the second packet gets retransmitted when it finally fires. |
| 2548 EXPECT_TRUE(retransmission_alarm->IsSet()); | 2522 EXPECT_TRUE(retransmission_alarm->IsSet()); |
| 2549 EXPECT_LT(retransmission_alarm->deadline(), clock_.ApproximateNow()); | 2523 EXPECT_LT(retransmission_alarm->deadline(), clock_.ApproximateNow()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 2576 TEST_P(QuicConnectionTest, CloseFecGroup) { | 2550 TEST_P(QuicConnectionTest, CloseFecGroup) { |
| 2577 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2551 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2578 // Don't send missing packet 1. | 2552 // Don't send missing packet 1. |
| 2579 // Don't send missing packet 2. | 2553 // Don't send missing packet 2. |
| 2580 ProcessFecProtectedPacket(3, false, !kEntropyFlag); | 2554 ProcessFecProtectedPacket(3, false, !kEntropyFlag); |
| 2581 // Don't send missing FEC packet 3. | 2555 // Don't send missing FEC packet 3. |
| 2582 ASSERT_EQ(1u, connection_.NumFecGroups()); | 2556 ASSERT_EQ(1u, connection_.NumFecGroups()); |
| 2583 | 2557 |
| 2584 // Now send non-fec protected ack packet and close the group. | 2558 // Now send non-fec protected ack packet and close the group. |
| 2585 peer_creator_.set_sequence_number(4); | 2559 peer_creator_.set_sequence_number(4); |
| 2586 if (version() > QUIC_VERSION_15) { | 2560 QuicStopWaitingFrame frame = InitStopWaitingFrame(5); |
| 2587 QuicStopWaitingFrame frame = InitStopWaitingFrame(5); | 2561 ProcessStopWaitingPacket(&frame); |
| 2588 ProcessStopWaitingPacket(&frame); | |
| 2589 } else { | |
| 2590 QuicAckFrame frame = InitAckFrame(0, 5); | |
| 2591 ProcessAckPacket(&frame); | |
| 2592 } | |
| 2593 ASSERT_EQ(0u, connection_.NumFecGroups()); | 2562 ASSERT_EQ(0u, connection_.NumFecGroups()); |
| 2594 } | 2563 } |
| 2595 | 2564 |
| 2596 TEST_P(QuicConnectionTest, NoQuicCongestionFeedbackFrame) { | 2565 TEST_P(QuicConnectionTest, NoQuicCongestionFeedbackFrame) { |
| 2597 SendAckPacketToPeer(); | 2566 SendAckPacketToPeer(); |
| 2598 EXPECT_TRUE(writer_->feedback_frames().empty()); | 2567 EXPECT_TRUE(writer_->feedback_frames().empty()); |
| 2599 } | 2568 } |
| 2600 | 2569 |
| 2601 TEST_P(QuicConnectionTest, WithQuicCongestionFeedbackFrame) { | 2570 TEST_P(QuicConnectionTest, WithQuicCongestionFeedbackFrame) { |
| 2602 QuicCongestionFeedbackFrame info; | 2571 QuicCongestionFeedbackFrame info; |
| 2603 info.type = kFixRate; | 2572 info.type = kTCP; |
| 2604 info.fix_rate.bitrate = QuicBandwidth::FromBytesPerSecond(123); | 2573 info.tcp.receive_window = 0x4030; |
| 2605 SetFeedback(&info); | 2574 SetFeedback(&info); |
| 2606 | 2575 |
| 2607 SendAckPacketToPeer(); | 2576 SendAckPacketToPeer(); |
| 2608 ASSERT_FALSE(writer_->feedback_frames().empty()); | 2577 ASSERT_FALSE(writer_->feedback_frames().empty()); |
| 2609 ASSERT_EQ(kFixRate, writer_->feedback_frames()[0].type); | 2578 ASSERT_EQ(kTCP, writer_->feedback_frames()[0].type); |
| 2610 ASSERT_EQ(info.fix_rate.bitrate, | |
| 2611 writer_->feedback_frames()[0].fix_rate.bitrate); | |
| 2612 } | 2579 } |
| 2613 | 2580 |
| 2614 TEST_P(QuicConnectionTest, UpdateQuicCongestionFeedbackFrame) { | 2581 TEST_P(QuicConnectionTest, UpdateQuicCongestionFeedbackFrame) { |
| 2615 SendAckPacketToPeer(); | 2582 SendAckPacketToPeer(); |
| 2616 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _)); | 2583 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _)); |
| 2617 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2584 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2618 ProcessPacket(1); | 2585 ProcessPacket(1); |
| 2619 } | 2586 } |
| 2620 | 2587 |
| 2621 TEST_P(QuicConnectionTest, DontUpdateQuicCongestionFeedbackFrameForRevived) { | 2588 TEST_P(QuicConnectionTest, DontUpdateQuicCongestionFeedbackFrameForRevived) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2661 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); | 2628 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); |
| 2662 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); | 2629 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); |
| 2663 SendStreamDataToPeer(1, "GET /", 0, kFin, NULL); | 2630 SendStreamDataToPeer(1, "GET /", 0, kFin, NULL); |
| 2664 EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); | 2631 EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); |
| 2665 EXPECT_EQ(clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(15)), | 2632 EXPECT_EQ(clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(15)), |
| 2666 connection_.GetPingAlarm()->deadline()); | 2633 connection_.GetPingAlarm()->deadline()); |
| 2667 | 2634 |
| 2668 // Now recevie and ACK of the previous packet, which will move the | 2635 // Now recevie and ACK of the previous packet, which will move the |
| 2669 // ping alarm forward. | 2636 // ping alarm forward. |
| 2670 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); | 2637 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); |
| 2671 QuicAckFrame frame = InitAckFrame(1, 0); | 2638 QuicAckFrame frame = InitAckFrame(1); |
| 2672 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2639 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2673 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 2640 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 2674 ProcessAckPacket(&frame); | 2641 ProcessAckPacket(&frame); |
| 2675 EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); | 2642 EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); |
| 2676 EXPECT_EQ(clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(15)), | 2643 EXPECT_EQ(clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(15)), |
| 2677 connection_.GetPingAlarm()->deadline()); | 2644 connection_.GetPingAlarm()->deadline()); |
| 2678 | 2645 |
| 2679 writer_->Reset(); | 2646 writer_->Reset(); |
| 2680 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(15)); | 2647 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(15)); |
| 2681 connection_.GetPingAlarm()->Fire(); | 2648 connection_.GetPingAlarm()->Fire(); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2835 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); | 2802 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); |
| 2836 EXPECT_CALL(*send_algorithm_, | 2803 EXPECT_CALL(*send_algorithm_, |
| 2837 TimeUntilSend(_, _, _)).WillOnce( | 2804 TimeUntilSend(_, _, _)).WillOnce( |
| 2838 testing::Return(QuicTime::Delta::FromMicroseconds(10))); | 2805 testing::Return(QuicTime::Delta::FromMicroseconds(10))); |
| 2839 connection_.SendPacket( | 2806 connection_.SendPacket( |
| 2840 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); | 2807 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); |
| 2841 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 2808 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 2842 | 2809 |
| 2843 // Now send non-retransmitting information, that we're not going to | 2810 // Now send non-retransmitting information, that we're not going to |
| 2844 // retransmit 3. The far end should stop waiting for it. | 2811 // retransmit 3. The far end should stop waiting for it. |
| 2845 QuicAckFrame frame = InitAckFrame(0, 1); | 2812 QuicAckFrame frame = InitAckFrame(0); |
| 2846 EXPECT_CALL(*send_algorithm_, | 2813 EXPECT_CALL(*send_algorithm_, |
| 2847 TimeUntilSend(_, _, _)).WillRepeatedly( | 2814 TimeUntilSend(_, _, _)).WillRepeatedly( |
| 2848 testing::Return(QuicTime::Delta::Zero())); | 2815 testing::Return(QuicTime::Delta::Zero())); |
| 2849 EXPECT_CALL(*send_algorithm_, | 2816 EXPECT_CALL(*send_algorithm_, |
| 2850 OnPacketSent(_, _, _, _, _)); | 2817 OnPacketSent(_, _, _, _, _)); |
| 2851 ProcessAckPacket(&frame); | 2818 ProcessAckPacket(&frame); |
| 2852 | 2819 |
| 2853 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 2820 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 2854 // Ensure alarm is not set | 2821 // Ensure alarm is not set |
| 2855 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet()); | 2822 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet()); |
| 2856 } | 2823 } |
| 2857 | 2824 |
| 2858 TEST_P(QuicConnectionTest, SendSchedulerDelayThenAckAndHold) { | 2825 TEST_P(QuicConnectionTest, SendSchedulerDelayThenAckAndHold) { |
| 2859 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2826 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2860 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); | 2827 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); |
| 2861 EXPECT_CALL(*send_algorithm_, | 2828 EXPECT_CALL(*send_algorithm_, |
| 2862 TimeUntilSend(_, _, _)).WillOnce( | 2829 TimeUntilSend(_, _, _)).WillOnce( |
| 2863 testing::Return(QuicTime::Delta::FromMicroseconds(10))); | 2830 testing::Return(QuicTime::Delta::FromMicroseconds(10))); |
| 2864 connection_.SendPacket( | 2831 connection_.SendPacket( |
| 2865 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); | 2832 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); |
| 2866 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 2833 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 2867 | 2834 |
| 2868 // Now send non-retransmitting information, that we're not going to | 2835 // Now send non-retransmitting information, that we're not going to |
| 2869 // retransmit 3. The far end should stop waiting for it. | 2836 // retransmit 3. The far end should stop waiting for it. |
| 2870 QuicAckFrame frame = InitAckFrame(0, 1); | 2837 QuicAckFrame frame = InitAckFrame(0); |
| 2871 EXPECT_CALL(*send_algorithm_, | 2838 EXPECT_CALL(*send_algorithm_, |
| 2872 TimeUntilSend(_, _, _)).WillOnce( | 2839 TimeUntilSend(_, _, _)).WillOnce( |
| 2873 testing::Return(QuicTime::Delta::FromMicroseconds(1))); | 2840 testing::Return(QuicTime::Delta::FromMicroseconds(1))); |
| 2874 ProcessAckPacket(&frame); | 2841 ProcessAckPacket(&frame); |
| 2875 | 2842 |
| 2876 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 2843 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 2877 } | 2844 } |
| 2878 | 2845 |
| 2879 TEST_P(QuicConnectionTest, SendSchedulerDelayThenOnCanWrite) { | 2846 TEST_P(QuicConnectionTest, SendSchedulerDelayThenOnCanWrite) { |
| 2880 // TODO(ianswett): This test is unrealistic, because we would not serialize | 2847 // TODO(ianswett): This test is unrealistic, because we would not serialize |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2949 // instead of ENCRYPTION_NONE. | 2916 // instead of ENCRYPTION_NONE. |
| 2950 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); | 2917 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); |
| 2951 ProcessDataPacketAtLevel(1, 0, !kEntropyFlag, ENCRYPTION_INITIAL); | 2918 ProcessDataPacketAtLevel(1, 0, !kEntropyFlag, ENCRYPTION_INITIAL); |
| 2952 | 2919 |
| 2953 // Check if delayed ack timer is running for the expected interval. | 2920 // Check if delayed ack timer is running for the expected interval. |
| 2954 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); | 2921 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); |
| 2955 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); | 2922 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); |
| 2956 // Simulate delayed ack alarm firing. | 2923 // Simulate delayed ack alarm firing. |
| 2957 connection_.GetAckAlarm()->Fire(); | 2924 connection_.GetAckAlarm()->Fire(); |
| 2958 // Check that ack is sent and that delayed ack alarm is reset. | 2925 // Check that ack is sent and that delayed ack alarm is reset. |
| 2959 if (version() > QUIC_VERSION_15) { | 2926 EXPECT_EQ(2u, writer_->frame_count()); |
| 2960 EXPECT_EQ(2u, writer_->frame_count()); | 2927 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); |
| 2961 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); | |
| 2962 } else { | |
| 2963 EXPECT_EQ(1u, writer_->frame_count()); | |
| 2964 } | |
| 2965 EXPECT_FALSE(writer_->ack_frames().empty()); | 2928 EXPECT_FALSE(writer_->ack_frames().empty()); |
| 2966 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 2929 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
| 2967 } | 2930 } |
| 2968 | 2931 |
| 2969 TEST_P(QuicConnectionTest, SendEarlyDelayedAckForCrypto) { | 2932 TEST_P(QuicConnectionTest, SendEarlyDelayedAckForCrypto) { |
| 2970 QuicTime ack_time = clock_.ApproximateNow(); | 2933 QuicTime ack_time = clock_.ApproximateNow(); |
| 2971 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2934 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2972 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 2935 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
| 2973 // Process a packet from the crypto stream, which is frame1_'s default. | 2936 // Process a packet from the crypto stream, which is frame1_'s default. |
| 2974 ProcessPacket(1); | 2937 ProcessPacket(1); |
| 2975 // Check if delayed ack timer is running for the expected interval. | 2938 // Check if delayed ack timer is running for the expected interval. |
| 2976 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); | 2939 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); |
| 2977 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); | 2940 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); |
| 2978 // Simulate delayed ack alarm firing. | 2941 // Simulate delayed ack alarm firing. |
| 2979 connection_.GetAckAlarm()->Fire(); | 2942 connection_.GetAckAlarm()->Fire(); |
| 2980 // Check that ack is sent and that delayed ack alarm is reset. | 2943 // Check that ack is sent and that delayed ack alarm is reset. |
| 2981 if (version() > QUIC_VERSION_15) { | 2944 EXPECT_EQ(2u, writer_->frame_count()); |
| 2982 EXPECT_EQ(2u, writer_->frame_count()); | 2945 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); |
| 2983 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); | |
| 2984 } else { | |
| 2985 EXPECT_EQ(1u, writer_->frame_count()); | |
| 2986 } | |
| 2987 EXPECT_FALSE(writer_->ack_frames().empty()); | 2946 EXPECT_FALSE(writer_->ack_frames().empty()); |
| 2988 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 2947 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
| 2989 } | 2948 } |
| 2990 | 2949 |
| 2991 TEST_P(QuicConnectionTest, SendDelayedAckOnSecondPacket) { | 2950 TEST_P(QuicConnectionTest, SendDelayedAckOnSecondPacket) { |
| 2992 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2951 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2993 ProcessPacket(1); | 2952 ProcessPacket(1); |
| 2994 ProcessPacket(2); | 2953 ProcessPacket(2); |
| 2995 // Check that ack is sent and that delayed ack alarm is reset. | 2954 // Check that ack is sent and that delayed ack alarm is reset. |
| 2996 if (version() > QUIC_VERSION_15) { | 2955 EXPECT_EQ(2u, writer_->frame_count()); |
| 2997 EXPECT_EQ(2u, writer_->frame_count()); | 2956 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); |
| 2998 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); | |
| 2999 } else { | |
| 3000 EXPECT_EQ(1u, writer_->frame_count()); | |
| 3001 } | |
| 3002 EXPECT_FALSE(writer_->ack_frames().empty()); | 2957 EXPECT_FALSE(writer_->ack_frames().empty()); |
| 3003 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 2958 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
| 3004 } | 2959 } |
| 3005 | 2960 |
| 3006 TEST_P(QuicConnectionTest, NoAckOnOldNacks) { | 2961 TEST_P(QuicConnectionTest, NoAckOnOldNacks) { |
| 3007 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2962 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3008 // Drop one packet, triggering a sequence of acks. | 2963 // Drop one packet, triggering a sequence of acks. |
| 3009 ProcessPacket(2); | 2964 ProcessPacket(2); |
| 3010 size_t frames_per_ack = version() > QUIC_VERSION_15 ? 2 : 1; | 2965 size_t frames_per_ack = 2; |
| 3011 EXPECT_EQ(frames_per_ack, writer_->frame_count()); | 2966 EXPECT_EQ(frames_per_ack, writer_->frame_count()); |
| 3012 EXPECT_FALSE(writer_->ack_frames().empty()); | 2967 EXPECT_FALSE(writer_->ack_frames().empty()); |
| 3013 writer_->Reset(); | 2968 writer_->Reset(); |
| 3014 ProcessPacket(3); | 2969 ProcessPacket(3); |
| 3015 EXPECT_EQ(frames_per_ack, writer_->frame_count()); | 2970 EXPECT_EQ(frames_per_ack, writer_->frame_count()); |
| 3016 EXPECT_FALSE(writer_->ack_frames().empty()); | 2971 EXPECT_FALSE(writer_->ack_frames().empty()); |
| 3017 writer_->Reset(); | 2972 writer_->Reset(); |
| 3018 ProcessPacket(4); | 2973 ProcessPacket(4); |
| 3019 EXPECT_EQ(frames_per_ack, writer_->frame_count()); | 2974 EXPECT_EQ(frames_per_ack, writer_->frame_count()); |
| 3020 EXPECT_FALSE(writer_->ack_frames().empty()); | 2975 EXPECT_FALSE(writer_->ack_frames().empty()); |
| 3021 writer_->Reset(); | 2976 writer_->Reset(); |
| 3022 ProcessPacket(5); | 2977 ProcessPacket(5); |
| 3023 EXPECT_EQ(frames_per_ack, writer_->frame_count()); | 2978 EXPECT_EQ(frames_per_ack, writer_->frame_count()); |
| 3024 EXPECT_FALSE(writer_->ack_frames().empty()); | 2979 EXPECT_FALSE(writer_->ack_frames().empty()); |
| 3025 writer_->Reset(); | 2980 writer_->Reset(); |
| 3026 // Now only set the timer on the 6th packet, instead of sending another ack. | 2981 // Now only set the timer on the 6th packet, instead of sending another ack. |
| 3027 ProcessPacket(6); | 2982 ProcessPacket(6); |
| 3028 EXPECT_EQ(0u, writer_->frame_count()); | 2983 EXPECT_EQ(0u, writer_->frame_count()); |
| 3029 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); | 2984 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); |
| 3030 } | 2985 } |
| 3031 | 2986 |
| 3032 TEST_P(QuicConnectionTest, SendDelayedAckOnOutgoingPacket) { | 2987 TEST_P(QuicConnectionTest, SendDelayedAckOnOutgoingPacket) { |
| 3033 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2988 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3034 ProcessPacket(1); | 2989 ProcessPacket(1); |
| 3035 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, | 2990 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, |
| 3036 !kFin, NULL); | 2991 !kFin, NULL); |
| 3037 // Check that ack is bundled with outgoing data and that delayed ack | 2992 // Check that ack is bundled with outgoing data and that delayed ack |
| 3038 // alarm is reset. | 2993 // alarm is reset. |
| 3039 if (version() > QUIC_VERSION_15) { | 2994 EXPECT_EQ(3u, writer_->frame_count()); |
| 3040 EXPECT_EQ(3u, writer_->frame_count()); | 2995 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); |
| 3041 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); | |
| 3042 } else { | |
| 3043 EXPECT_EQ(2u, writer_->frame_count()); | |
| 3044 } | |
| 3045 EXPECT_FALSE(writer_->ack_frames().empty()); | 2996 EXPECT_FALSE(writer_->ack_frames().empty()); |
| 3046 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 2997 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
| 3047 } | 2998 } |
| 3048 | 2999 |
| 3049 TEST_P(QuicConnectionTest, SendDelayedAckOnOutgoingCryptoPacket) { | 3000 TEST_P(QuicConnectionTest, SendDelayedAckOnOutgoingCryptoPacket) { |
| 3050 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3001 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3051 ProcessPacket(1); | 3002 ProcessPacket(1); |
| 3052 connection_.SendStreamDataWithString(kCryptoStreamId, "foo", 0, !kFin, NULL); | 3003 connection_.SendStreamDataWithString(kCryptoStreamId, "foo", 0, !kFin, NULL); |
| 3053 // Check that ack is bundled with outgoing crypto data. | 3004 // Check that ack is bundled with outgoing crypto data. |
| 3054 EXPECT_EQ(version() <= QUIC_VERSION_15 ? 2u : 3u, writer_->frame_count()); | 3005 EXPECT_EQ(3u, writer_->frame_count()); |
| 3055 EXPECT_FALSE(writer_->ack_frames().empty()); | 3006 EXPECT_FALSE(writer_->ack_frames().empty()); |
| 3056 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 3007 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
| 3057 } | 3008 } |
| 3058 | 3009 |
| 3059 TEST_P(QuicConnectionTest, BundleAckForSecondCHLO) { | 3010 TEST_P(QuicConnectionTest, BundleAckForSecondCHLO) { |
| 3060 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3011 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3061 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 3012 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
| 3062 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce( | 3013 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce( |
| 3063 IgnoreResult(InvokeWithoutArgs(&connection_, | 3014 IgnoreResult(InvokeWithoutArgs(&connection_, |
| 3064 &TestConnection::SendCryptoStreamData))); | 3015 &TestConnection::SendCryptoStreamData))); |
| 3065 // Process a packet from the crypto stream, which is frame1_'s default. | 3016 // Process a packet from the crypto stream, which is frame1_'s default. |
| 3066 // Receiving the CHLO as packet 2 first will cause the connection to | 3017 // Receiving the CHLO as packet 2 first will cause the connection to |
| 3067 // immediately send an ack, due to the packet gap. | 3018 // immediately send an ack, due to the packet gap. |
| 3068 ProcessPacket(2); | 3019 ProcessPacket(2); |
| 3069 // Check that ack is sent and that delayed ack alarm is reset. | 3020 // Check that ack is sent and that delayed ack alarm is reset. |
| 3070 if (version() > QUIC_VERSION_15) { | 3021 EXPECT_EQ(3u, writer_->frame_count()); |
| 3071 EXPECT_EQ(3u, writer_->frame_count()); | 3022 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); |
| 3072 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); | |
| 3073 } else { | |
| 3074 EXPECT_EQ(2u, writer_->frame_count()); | |
| 3075 } | |
| 3076 EXPECT_EQ(1u, writer_->stream_frames().size()); | 3023 EXPECT_EQ(1u, writer_->stream_frames().size()); |
| 3077 EXPECT_FALSE(writer_->ack_frames().empty()); | 3024 EXPECT_FALSE(writer_->ack_frames().empty()); |
| 3078 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 3025 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
| 3079 } | 3026 } |
| 3080 | 3027 |
| 3081 TEST_P(QuicConnectionTest, BundleAckWithDataOnIncomingAck) { | 3028 TEST_P(QuicConnectionTest, BundleAckWithDataOnIncomingAck) { |
| 3082 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3029 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3083 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, | 3030 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, |
| 3084 !kFin, NULL); | 3031 !kFin, NULL); |
| 3085 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 3, | 3032 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 3, |
| 3086 !kFin, NULL); | 3033 !kFin, NULL); |
| 3087 // Ack the second packet, which will retransmit the first packet. | 3034 // Ack the second packet, which will retransmit the first packet. |
| 3088 QuicAckFrame ack = InitAckFrame(2, 0); | 3035 QuicAckFrame ack = InitAckFrame(2); |
| 3089 NackPacket(1, &ack); | 3036 NackPacket(1, &ack); |
| 3090 SequenceNumberSet lost_packets; | 3037 SequenceNumberSet lost_packets; |
| 3091 lost_packets.insert(1); | 3038 lost_packets.insert(1); |
| 3092 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) | 3039 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
| 3093 .WillOnce(Return(lost_packets)); | 3040 .WillOnce(Return(lost_packets)); |
| 3094 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 3041 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 3095 ProcessAckPacket(&ack); | 3042 ProcessAckPacket(&ack); |
| 3096 EXPECT_EQ(1u, writer_->frame_count()); | 3043 EXPECT_EQ(1u, writer_->frame_count()); |
| 3097 EXPECT_EQ(1u, writer_->stream_frames().size()); | 3044 EXPECT_EQ(1u, writer_->stream_frames().size()); |
| 3098 writer_->Reset(); | 3045 writer_->Reset(); |
| 3099 | 3046 |
| 3100 // Now ack the retransmission, which will both raise the high water mark | 3047 // Now ack the retransmission, which will both raise the high water mark |
| 3101 // and see if there is more data to send. | 3048 // and see if there is more data to send. |
| 3102 ack = InitAckFrame(3, 0); | 3049 ack = InitAckFrame(3); |
| 3103 NackPacket(1, &ack); | 3050 NackPacket(1, &ack); |
| 3104 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) | 3051 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
| 3105 .WillOnce(Return(SequenceNumberSet())); | 3052 .WillOnce(Return(SequenceNumberSet())); |
| 3106 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 3053 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 3107 ProcessAckPacket(&ack); | 3054 ProcessAckPacket(&ack); |
| 3108 | 3055 |
| 3109 // Check that no packet is sent and the ack alarm isn't set. | 3056 // Check that no packet is sent and the ack alarm isn't set. |
| 3110 EXPECT_EQ(0u, writer_->frame_count()); | 3057 EXPECT_EQ(0u, writer_->frame_count()); |
| 3111 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 3058 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
| 3112 writer_->Reset(); | 3059 writer_->Reset(); |
| 3113 | 3060 |
| 3114 // Send the same ack, but send both data and an ack together. | 3061 // Send the same ack, but send both data and an ack together. |
| 3115 ack = InitAckFrame(3, 0); | 3062 ack = InitAckFrame(3); |
| 3116 NackPacket(1, &ack); | 3063 NackPacket(1, &ack); |
| 3117 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) | 3064 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
| 3118 .WillOnce(Return(SequenceNumberSet())); | 3065 .WillOnce(Return(SequenceNumberSet())); |
| 3119 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce( | 3066 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce( |
| 3120 IgnoreResult(InvokeWithoutArgs( | 3067 IgnoreResult(InvokeWithoutArgs( |
| 3121 &connection_, | 3068 &connection_, |
| 3122 &TestConnection::EnsureWritableAndSendStreamData5))); | 3069 &TestConnection::EnsureWritableAndSendStreamData5))); |
| 3123 ProcessAckPacket(&ack); | 3070 ProcessAckPacket(&ack); |
| 3124 | 3071 |
| 3125 // Check that ack is bundled with outgoing data and the delayed ack | 3072 // Check that ack is bundled with outgoing data and the delayed ack |
| 3126 // alarm is reset. | 3073 // alarm is reset. |
| 3127 if (version() > QUIC_VERSION_15) { | 3074 EXPECT_EQ(3u, writer_->frame_count()); |
| 3128 EXPECT_EQ(3u, writer_->frame_count()); | 3075 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); |
| 3129 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); | |
| 3130 } else { | |
| 3131 EXPECT_EQ(2u, writer_->frame_count()); | |
| 3132 } | |
| 3133 EXPECT_FALSE(writer_->ack_frames().empty()); | 3076 EXPECT_FALSE(writer_->ack_frames().empty()); |
| 3134 EXPECT_EQ(1u, writer_->stream_frames().size()); | 3077 EXPECT_EQ(1u, writer_->stream_frames().size()); |
| 3135 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 3078 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
| 3136 } | 3079 } |
| 3137 | 3080 |
| 3138 TEST_P(QuicConnectionTest, NoAckSentForClose) { | 3081 TEST_P(QuicConnectionTest, NoAckSentForClose) { |
| 3139 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3082 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3140 ProcessPacket(1); | 3083 ProcessPacket(1); |
| 3141 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PEER_GOING_AWAY, true)); | 3084 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PEER_GOING_AWAY, true)); |
| 3142 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); | 3085 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3204 // The connection close packet should have error details. | 3147 // The connection close packet should have error details. |
| 3205 ASSERT_FALSE(writer_->connection_close_frames().empty()); | 3148 ASSERT_FALSE(writer_->connection_close_frames().empty()); |
| 3206 EXPECT_EQ("Unable to read public flags.", | 3149 EXPECT_EQ("Unable to read public flags.", |
| 3207 writer_->connection_close_frames()[0].error_details); | 3150 writer_->connection_close_frames()[0].error_details); |
| 3208 } | 3151 } |
| 3209 | 3152 |
| 3210 TEST_P(QuicConnectionTest, MissingPacketsBeforeLeastUnacked) { | 3153 TEST_P(QuicConnectionTest, MissingPacketsBeforeLeastUnacked) { |
| 3211 // Set the sequence number of the ack packet to be least unacked (4). | 3154 // Set the sequence number of the ack packet to be least unacked (4). |
| 3212 peer_creator_.set_sequence_number(3); | 3155 peer_creator_.set_sequence_number(3); |
| 3213 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3156 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3214 if (version() > QUIC_VERSION_15) { | 3157 QuicStopWaitingFrame frame = InitStopWaitingFrame(4); |
| 3215 QuicStopWaitingFrame frame = InitStopWaitingFrame(4); | 3158 ProcessStopWaitingPacket(&frame); |
| 3216 ProcessStopWaitingPacket(&frame); | 3159 EXPECT_TRUE(outgoing_ack()->missing_packets.empty()); |
| 3217 } else { | |
| 3218 QuicAckFrame ack = InitAckFrame(0, 4); | |
| 3219 ProcessAckPacket(&ack); | |
| 3220 } | |
| 3221 EXPECT_TRUE(outgoing_ack()->received_info.missing_packets.empty()); | |
| 3222 } | 3160 } |
| 3223 | 3161 |
| 3224 TEST_P(QuicConnectionTest, ReceivedEntropyHashCalculation) { | 3162 TEST_P(QuicConnectionTest, ReceivedEntropyHashCalculation) { |
| 3225 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(AtLeast(1)); | 3163 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(AtLeast(1)); |
| 3226 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3164 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3227 ProcessDataPacket(1, 1, kEntropyFlag); | 3165 ProcessDataPacket(1, 1, kEntropyFlag); |
| 3228 ProcessDataPacket(4, 1, kEntropyFlag); | 3166 ProcessDataPacket(4, 1, kEntropyFlag); |
| 3229 ProcessDataPacket(3, 1, !kEntropyFlag); | 3167 ProcessDataPacket(3, 1, !kEntropyFlag); |
| 3230 ProcessDataPacket(7, 1, kEntropyFlag); | 3168 ProcessDataPacket(7, 1, kEntropyFlag); |
| 3231 EXPECT_EQ(146u, outgoing_ack()->received_info.entropy_hash); | 3169 EXPECT_EQ(146u, outgoing_ack()->entropy_hash); |
| 3232 } | 3170 } |
| 3233 | 3171 |
| 3234 TEST_P(QuicConnectionTest, ReceivedEntropyHashCalculationHalfFEC) { | 3172 TEST_P(QuicConnectionTest, ReceivedEntropyHashCalculationHalfFEC) { |
| 3235 // FEC packets should not change the entropy hash calculation. | 3173 // FEC packets should not change the entropy hash calculation. |
| 3236 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(AtLeast(1)); | 3174 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(AtLeast(1)); |
| 3237 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3175 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3238 ProcessDataPacket(1, 1, kEntropyFlag); | 3176 ProcessDataPacket(1, 1, kEntropyFlag); |
| 3239 ProcessFecPacket(4, 1, false, kEntropyFlag, NULL); | 3177 ProcessFecPacket(4, 1, false, kEntropyFlag, NULL); |
| 3240 ProcessDataPacket(3, 3, !kEntropyFlag); | 3178 ProcessDataPacket(3, 3, !kEntropyFlag); |
| 3241 ProcessFecPacket(7, 3, false, kEntropyFlag, NULL); | 3179 ProcessFecPacket(7, 3, false, kEntropyFlag, NULL); |
| 3242 EXPECT_EQ(146u, outgoing_ack()->received_info.entropy_hash); | 3180 EXPECT_EQ(146u, outgoing_ack()->entropy_hash); |
| 3243 } | 3181 } |
| 3244 | 3182 |
| 3245 TEST_P(QuicConnectionTest, UpdateEntropyForReceivedPackets) { | 3183 TEST_P(QuicConnectionTest, UpdateEntropyForReceivedPackets) { |
| 3246 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(AtLeast(1)); | 3184 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(AtLeast(1)); |
| 3247 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3185 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3248 ProcessDataPacket(1, 1, kEntropyFlag); | 3186 ProcessDataPacket(1, 1, kEntropyFlag); |
| 3249 ProcessDataPacket(5, 1, kEntropyFlag); | 3187 ProcessDataPacket(5, 1, kEntropyFlag); |
| 3250 ProcessDataPacket(4, 1, !kEntropyFlag); | 3188 ProcessDataPacket(4, 1, !kEntropyFlag); |
| 3251 EXPECT_EQ(34u, outgoing_ack()->received_info.entropy_hash); | 3189 EXPECT_EQ(34u, outgoing_ack()->entropy_hash); |
| 3252 // Make 4th packet my least unacked, and update entropy for 2, 3 packets. | 3190 // Make 4th packet my least unacked, and update entropy for 2, 3 packets. |
| 3253 peer_creator_.set_sequence_number(5); | 3191 peer_creator_.set_sequence_number(5); |
| 3254 QuicPacketEntropyHash six_packet_entropy_hash = 0; | 3192 QuicPacketEntropyHash six_packet_entropy_hash = 0; |
| 3255 QuicPacketEntropyHash kRandomEntropyHash = 129u; | 3193 QuicPacketEntropyHash kRandomEntropyHash = 129u; |
| 3256 if (version() > QUIC_VERSION_15) { | 3194 QuicStopWaitingFrame frame = InitStopWaitingFrame(4); |
| 3257 QuicStopWaitingFrame frame = InitStopWaitingFrame(4); | 3195 frame.entropy_hash = kRandomEntropyHash; |
| 3258 frame.entropy_hash = kRandomEntropyHash; | 3196 if (ProcessStopWaitingPacket(&frame)) { |
| 3259 if (ProcessStopWaitingPacket(&frame)) { | 3197 six_packet_entropy_hash = 1 << 6; |
| 3260 six_packet_entropy_hash = 1 << 6; | |
| 3261 } | |
| 3262 } else { | |
| 3263 QuicAckFrame ack = InitAckFrame(0, 4); | |
| 3264 ack.sent_info.entropy_hash = kRandomEntropyHash; | |
| 3265 if (ProcessAckPacket(&ack)) { | |
| 3266 six_packet_entropy_hash = 1 << 6; | |
| 3267 } | |
| 3268 } | 3198 } |
| 3269 | 3199 |
| 3270 EXPECT_EQ((kRandomEntropyHash + (1 << 5) + six_packet_entropy_hash), | 3200 EXPECT_EQ((kRandomEntropyHash + (1 << 5) + six_packet_entropy_hash), |
| 3271 outgoing_ack()->received_info.entropy_hash); | 3201 outgoing_ack()->entropy_hash); |
| 3272 } | 3202 } |
| 3273 | 3203 |
| 3274 TEST_P(QuicConnectionTest, UpdateEntropyHashUptoCurrentPacket) { | 3204 TEST_P(QuicConnectionTest, UpdateEntropyHashUptoCurrentPacket) { |
| 3275 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(AtLeast(1)); | 3205 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(AtLeast(1)); |
| 3276 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3206 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3277 ProcessDataPacket(1, 1, kEntropyFlag); | 3207 ProcessDataPacket(1, 1, kEntropyFlag); |
| 3278 ProcessDataPacket(5, 1, !kEntropyFlag); | 3208 ProcessDataPacket(5, 1, !kEntropyFlag); |
| 3279 ProcessDataPacket(22, 1, kEntropyFlag); | 3209 ProcessDataPacket(22, 1, kEntropyFlag); |
| 3280 EXPECT_EQ(66u, outgoing_ack()->received_info.entropy_hash); | 3210 EXPECT_EQ(66u, outgoing_ack()->entropy_hash); |
| 3281 peer_creator_.set_sequence_number(22); | 3211 peer_creator_.set_sequence_number(22); |
| 3282 QuicPacketEntropyHash kRandomEntropyHash = 85u; | 3212 QuicPacketEntropyHash kRandomEntropyHash = 85u; |
| 3283 // Current packet is the least unacked packet. | 3213 // Current packet is the least unacked packet. |
| 3284 QuicPacketEntropyHash ack_entropy_hash; | 3214 QuicPacketEntropyHash ack_entropy_hash; |
| 3285 if (version() > QUIC_VERSION_15) { | 3215 QuicStopWaitingFrame frame = InitStopWaitingFrame(23); |
| 3286 QuicStopWaitingFrame frame = InitStopWaitingFrame(23); | 3216 frame.entropy_hash = kRandomEntropyHash; |
| 3287 frame.entropy_hash = kRandomEntropyHash; | 3217 ack_entropy_hash = ProcessStopWaitingPacket(&frame); |
| 3288 ack_entropy_hash = ProcessStopWaitingPacket(&frame); | |
| 3289 } else { | |
| 3290 QuicAckFrame ack = InitAckFrame(0, 23); | |
| 3291 ack.sent_info.entropy_hash = kRandomEntropyHash; | |
| 3292 ack_entropy_hash = ProcessAckPacket(&ack); | |
| 3293 } | |
| 3294 EXPECT_EQ((kRandomEntropyHash + ack_entropy_hash), | 3218 EXPECT_EQ((kRandomEntropyHash + ack_entropy_hash), |
| 3295 outgoing_ack()->received_info.entropy_hash); | 3219 outgoing_ack()->entropy_hash); |
| 3296 ProcessDataPacket(25, 1, kEntropyFlag); | 3220 ProcessDataPacket(25, 1, kEntropyFlag); |
| 3297 EXPECT_EQ((kRandomEntropyHash + ack_entropy_hash + (1 << (25 % 8))), | 3221 EXPECT_EQ((kRandomEntropyHash + ack_entropy_hash + (1 << (25 % 8))), |
| 3298 outgoing_ack()->received_info.entropy_hash); | 3222 outgoing_ack()->entropy_hash); |
| 3299 } | 3223 } |
| 3300 | 3224 |
| 3301 TEST_P(QuicConnectionTest, EntropyCalculationForTruncatedAck) { | 3225 TEST_P(QuicConnectionTest, EntropyCalculationForTruncatedAck) { |
| 3302 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(AtLeast(1)); | 3226 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(AtLeast(1)); |
| 3303 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3227 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3304 QuicPacketEntropyHash entropy[51]; | 3228 QuicPacketEntropyHash entropy[51]; |
| 3305 entropy[0] = 0; | 3229 entropy[0] = 0; |
| 3306 for (int i = 1; i < 51; ++i) { | 3230 for (int i = 1; i < 51; ++i) { |
| 3307 bool should_send = i % 10 != 1; | 3231 bool should_send = i % 10 != 1; |
| 3308 bool entropy_flag = (i & (i - 1)) != 0; | 3232 bool entropy_flag = (i & (i - 1)) != 0; |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3544 | 3468 |
| 3545 // 2 retransmissions due to rto, 1 due to explicit nack. | 3469 // 2 retransmissions due to rto, 1 due to explicit nack. |
| 3546 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); | 3470 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
| 3547 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3); | 3471 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3); |
| 3548 | 3472 |
| 3549 // Retransmit due to RTO. | 3473 // Retransmit due to RTO. |
| 3550 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10)); | 3474 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10)); |
| 3551 connection_.GetRetransmissionAlarm()->Fire(); | 3475 connection_.GetRetransmissionAlarm()->Fire(); |
| 3552 | 3476 |
| 3553 // Retransmit due to explicit nacks. | 3477 // Retransmit due to explicit nacks. |
| 3554 QuicAckFrame nack_three = InitAckFrame(4, 0); | 3478 QuicAckFrame nack_three = InitAckFrame(4); |
| 3555 NackPacket(3, &nack_three); | 3479 NackPacket(3, &nack_three); |
| 3556 NackPacket(1, &nack_three); | 3480 NackPacket(1, &nack_three); |
| 3557 SequenceNumberSet lost_packets; | 3481 SequenceNumberSet lost_packets; |
| 3558 lost_packets.insert(1); | 3482 lost_packets.insert(1); |
| 3559 lost_packets.insert(3); | 3483 lost_packets.insert(3); |
| 3560 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) | 3484 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
| 3561 .WillOnce(Return(lost_packets)); | 3485 .WillOnce(Return(lost_packets)); |
| 3562 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 3486 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 3563 EXPECT_CALL(visitor_, OnCanWrite()).Times(2); | 3487 EXPECT_CALL(visitor_, OnCanWrite()).Times(2); |
| 3564 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3488 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3728 | 3652 |
| 3729 // Create a delegate which we expect to be called. | 3653 // Create a delegate which we expect to be called. |
| 3730 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); | 3654 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); |
| 3731 EXPECT_CALL(*delegate, OnAckNotification(_, _, _, _, _)).Times(1); | 3655 EXPECT_CALL(*delegate, OnAckNotification(_, _, _, _, _)).Times(1); |
| 3732 | 3656 |
| 3733 // Send some data, which will register the delegate to be notified. | 3657 // Send some data, which will register the delegate to be notified. |
| 3734 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); | 3658 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); |
| 3735 | 3659 |
| 3736 // Process an ACK from the server which should trigger the callback. | 3660 // Process an ACK from the server which should trigger the callback. |
| 3737 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 3661 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 3738 QuicAckFrame frame = InitAckFrame(1, 0); | 3662 QuicAckFrame frame = InitAckFrame(1); |
| 3739 ProcessAckPacket(&frame); | 3663 ProcessAckPacket(&frame); |
| 3740 } | 3664 } |
| 3741 | 3665 |
| 3742 TEST_P(QuicConnectionTest, AckNotifierFailToTriggerCallback) { | 3666 TEST_P(QuicConnectionTest, AckNotifierFailToTriggerCallback) { |
| 3743 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3667 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3744 | 3668 |
| 3745 // Create a delegate which we don't expect to be called. | 3669 // Create a delegate which we don't expect to be called. |
| 3746 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); | 3670 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); |
| 3747 EXPECT_CALL(*delegate, OnAckNotification(_, _, _, _, _)).Times(0); | 3671 EXPECT_CALL(*delegate, OnAckNotification(_, _, _, _, _)).Times(0); |
| 3748 | 3672 |
| 3749 // Send some data, which will register the delegate to be notified. This will | 3673 // Send some data, which will register the delegate to be notified. This will |
| 3750 // not be ACKed and so the delegate should never be called. | 3674 // not be ACKed and so the delegate should never be called. |
| 3751 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); | 3675 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); |
| 3752 | 3676 |
| 3753 // Send some other data which we will ACK. | 3677 // Send some other data which we will ACK. |
| 3754 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); | 3678 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); |
| 3755 connection_.SendStreamDataWithString(1, "bar", 0, !kFin, NULL); | 3679 connection_.SendStreamDataWithString(1, "bar", 0, !kFin, NULL); |
| 3756 | 3680 |
| 3757 // Now we receive ACK for packets 2 and 3, but importantly missing packet 1 | 3681 // Now we receive ACK for packets 2 and 3, but importantly missing packet 1 |
| 3758 // which we registered to be notified about. | 3682 // which we registered to be notified about. |
| 3759 QuicAckFrame frame = InitAckFrame(3, 0); | 3683 QuicAckFrame frame = InitAckFrame(3); |
| 3760 NackPacket(1, &frame); | 3684 NackPacket(1, &frame); |
| 3761 SequenceNumberSet lost_packets; | 3685 SequenceNumberSet lost_packets; |
| 3762 lost_packets.insert(1); | 3686 lost_packets.insert(1); |
| 3763 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) | 3687 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
| 3764 .WillOnce(Return(lost_packets)); | 3688 .WillOnce(Return(lost_packets)); |
| 3765 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 3689 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 3766 ProcessAckPacket(&frame); | 3690 ProcessAckPacket(&frame); |
| 3767 } | 3691 } |
| 3768 | 3692 |
| 3769 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) { | 3693 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) { |
| 3770 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3694 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3771 | 3695 |
| 3772 // Create a delegate which we expect to be called. | 3696 // Create a delegate which we expect to be called. |
| 3773 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); | 3697 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); |
| 3774 EXPECT_CALL(*delegate, OnAckNotification(_, _, _, _, _)).Times(1); | 3698 EXPECT_CALL(*delegate, OnAckNotification(_, _, _, _, _)).Times(1); |
| 3775 | 3699 |
| 3776 // Send four packets, and register to be notified on ACK of packet 2. | 3700 // Send four packets, and register to be notified on ACK of packet 2. |
| 3777 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); | 3701 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); |
| 3778 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, delegate.get()); | 3702 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, delegate.get()); |
| 3779 connection_.SendStreamDataWithString(3, "baz", 0, !kFin, NULL); | 3703 connection_.SendStreamDataWithString(3, "baz", 0, !kFin, NULL); |
| 3780 connection_.SendStreamDataWithString(3, "qux", 0, !kFin, NULL); | 3704 connection_.SendStreamDataWithString(3, "qux", 0, !kFin, NULL); |
| 3781 | 3705 |
| 3782 // Now we receive ACK for packets 1, 3, and 4 and lose 2. | 3706 // Now we receive ACK for packets 1, 3, and 4 and lose 2. |
| 3783 QuicAckFrame frame = InitAckFrame(4, 0); | 3707 QuicAckFrame frame = InitAckFrame(4); |
| 3784 NackPacket(2, &frame); | 3708 NackPacket(2, &frame); |
| 3785 SequenceNumberSet lost_packets; | 3709 SequenceNumberSet lost_packets; |
| 3786 lost_packets.insert(2); | 3710 lost_packets.insert(2); |
| 3787 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) | 3711 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
| 3788 .WillOnce(Return(lost_packets)); | 3712 .WillOnce(Return(lost_packets)); |
| 3789 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 3713 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 3790 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 3714 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| 3791 ProcessAckPacket(&frame); | 3715 ProcessAckPacket(&frame); |
| 3792 | 3716 |
| 3793 // Now we get an ACK for packet 5 (retransmitted packet 2), which should | 3717 // Now we get an ACK for packet 5 (retransmitted packet 2), which should |
| 3794 // trigger the callback. | 3718 // trigger the callback. |
| 3795 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) | 3719 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
| 3796 .WillRepeatedly(Return(SequenceNumberSet())); | 3720 .WillRepeatedly(Return(SequenceNumberSet())); |
| 3797 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 3721 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 3798 QuicAckFrame second_ack_frame = InitAckFrame(5, 0); | 3722 QuicAckFrame second_ack_frame = InitAckFrame(5); |
| 3799 ProcessAckPacket(&second_ack_frame); | 3723 ProcessAckPacket(&second_ack_frame); |
| 3800 } | 3724 } |
| 3801 | 3725 |
| 3802 // AckNotifierCallback is triggered by the ack of a packet that timed | 3726 // AckNotifierCallback is triggered by the ack of a packet that timed |
| 3803 // out and was retransmitted, even though the retransmission has a | 3727 // out and was retransmitted, even though the retransmission has a |
| 3804 // different sequence number. | 3728 // different sequence number. |
| 3805 TEST_P(QuicConnectionTest, AckNotifierCallbackForAckAfterRTO) { | 3729 TEST_P(QuicConnectionTest, AckNotifierCallbackForAckAfterRTO) { |
| 3806 InSequence s; | 3730 InSequence s; |
| 3807 | 3731 |
| 3808 // Create a delegate which we expect to be called. | 3732 // Create a delegate which we expect to be called. |
| 3809 scoped_refptr<MockAckNotifierDelegate> delegate( | 3733 scoped_refptr<MockAckNotifierDelegate> delegate( |
| 3810 new StrictMock<MockAckNotifierDelegate>); | 3734 new StrictMock<MockAckNotifierDelegate>); |
| 3811 | 3735 |
| 3812 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( | 3736 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( |
| 3813 DefaultRetransmissionTime()); | 3737 DefaultRetransmissionTime()); |
| 3814 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, delegate.get()); | 3738 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, delegate.get()); |
| 3815 EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked); | 3739 EXPECT_EQ(1u, stop_waiting()->least_unacked); |
| 3816 | 3740 |
| 3817 EXPECT_EQ(1u, writer_->header().packet_sequence_number); | 3741 EXPECT_EQ(1u, writer_->header().packet_sequence_number); |
| 3818 EXPECT_EQ(default_retransmission_time, | 3742 EXPECT_EQ(default_retransmission_time, |
| 3819 connection_.GetRetransmissionAlarm()->deadline()); | 3743 connection_.GetRetransmissionAlarm()->deadline()); |
| 3820 // Simulate the retransmission alarm firing. | 3744 // Simulate the retransmission alarm firing. |
| 3821 clock_.AdvanceTime(DefaultRetransmissionTime()); | 3745 clock_.AdvanceTime(DefaultRetransmissionTime()); |
| 3822 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); | 3746 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
| 3823 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _)); | 3747 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _)); |
| 3824 connection_.GetRetransmissionAlarm()->Fire(); | 3748 connection_.GetRetransmissionAlarm()->Fire(); |
| 3825 EXPECT_EQ(2u, writer_->header().packet_sequence_number); | 3749 EXPECT_EQ(2u, writer_->header().packet_sequence_number); |
| 3826 // We do not raise the high water mark yet. | 3750 // We do not raise the high water mark yet. |
| 3827 EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked); | 3751 EXPECT_EQ(1u, stop_waiting()->least_unacked); |
| 3828 | 3752 |
| 3829 // Ack the original packet, which will revert the RTO. | 3753 // Ack the original packet, which will revert the RTO. |
| 3830 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3754 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3831 EXPECT_CALL(*delegate, OnAckNotification(1, _, 1, _, _)); | 3755 EXPECT_CALL(*delegate, OnAckNotification(1, _, 1, _, _)); |
| 3832 EXPECT_CALL(*send_algorithm_, RevertRetransmissionTimeout()); | 3756 EXPECT_CALL(*send_algorithm_, RevertRetransmissionTimeout()); |
| 3833 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 3757 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 3834 QuicAckFrame ack_frame = InitAckFrame(1, 0); | 3758 QuicAckFrame ack_frame = InitAckFrame(1); |
| 3835 ProcessAckPacket(&ack_frame); | 3759 ProcessAckPacket(&ack_frame); |
| 3836 | 3760 |
| 3837 // Delegate is not notified again when the retransmit is acked. | 3761 // Delegate is not notified again when the retransmit is acked. |
| 3838 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 3762 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 3839 QuicAckFrame second_ack_frame = InitAckFrame(2, 0); | 3763 QuicAckFrame second_ack_frame = InitAckFrame(2); |
| 3840 ProcessAckPacket(&second_ack_frame); | 3764 ProcessAckPacket(&second_ack_frame); |
| 3841 } | 3765 } |
| 3842 | 3766 |
| 3843 // AckNotifierCallback is triggered by the ack of a packet that was | 3767 // AckNotifierCallback is triggered by the ack of a packet that was |
| 3844 // previously nacked, even though the retransmission has a different | 3768 // previously nacked, even though the retransmission has a different |
| 3845 // sequence number. | 3769 // sequence number. |
| 3846 TEST_P(QuicConnectionTest, AckNotifierCallbackForAckOfNackedPacket) { | 3770 TEST_P(QuicConnectionTest, AckNotifierCallbackForAckOfNackedPacket) { |
| 3847 InSequence s; | 3771 InSequence s; |
| 3848 | 3772 |
| 3849 // Create a delegate which we expect to be called. | 3773 // Create a delegate which we expect to be called. |
| 3850 scoped_refptr<MockAckNotifierDelegate> delegate( | 3774 scoped_refptr<MockAckNotifierDelegate> delegate( |
| 3851 new StrictMock<MockAckNotifierDelegate>); | 3775 new StrictMock<MockAckNotifierDelegate>); |
| 3852 | 3776 |
| 3853 // Send four packets, and register to be notified on ACK of packet 2. | 3777 // Send four packets, and register to be notified on ACK of packet 2. |
| 3854 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); | 3778 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); |
| 3855 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, delegate.get()); | 3779 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, delegate.get()); |
| 3856 connection_.SendStreamDataWithString(3, "baz", 0, !kFin, NULL); | 3780 connection_.SendStreamDataWithString(3, "baz", 0, !kFin, NULL); |
| 3857 connection_.SendStreamDataWithString(3, "qux", 0, !kFin, NULL); | 3781 connection_.SendStreamDataWithString(3, "qux", 0, !kFin, NULL); |
| 3858 | 3782 |
| 3859 // Now we receive ACK for packets 1, 3, and 4 and lose 2. | 3783 // Now we receive ACK for packets 1, 3, and 4 and lose 2. |
| 3860 QuicAckFrame frame = InitAckFrame(4, 0); | 3784 QuicAckFrame frame = InitAckFrame(4); |
| 3861 NackPacket(2, &frame); | 3785 NackPacket(2, &frame); |
| 3862 SequenceNumberSet lost_packets; | 3786 SequenceNumberSet lost_packets; |
| 3863 lost_packets.insert(2); | 3787 lost_packets.insert(2); |
| 3864 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3788 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3865 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) | 3789 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
| 3866 .WillOnce(Return(lost_packets)); | 3790 .WillOnce(Return(lost_packets)); |
| 3867 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 3791 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 3868 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 3792 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| 3869 ProcessAckPacket(&frame); | 3793 ProcessAckPacket(&frame); |
| 3870 | 3794 |
| 3871 // Now we get an ACK for packet 2, which was previously nacked. | 3795 // Now we get an ACK for packet 2, which was previously nacked. |
| 3872 SequenceNumberSet no_lost_packets; | 3796 SequenceNumberSet no_lost_packets; |
| 3873 EXPECT_CALL(*delegate, OnAckNotification(1, _, 1, _, _)); | 3797 EXPECT_CALL(*delegate, OnAckNotification(1, _, 1, _, _)); |
| 3874 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) | 3798 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
| 3875 .WillOnce(Return(no_lost_packets)); | 3799 .WillOnce(Return(no_lost_packets)); |
| 3876 QuicAckFrame second_ack_frame = InitAckFrame(4, 0); | 3800 QuicAckFrame second_ack_frame = InitAckFrame(4); |
| 3877 ProcessAckPacket(&second_ack_frame); | 3801 ProcessAckPacket(&second_ack_frame); |
| 3878 | 3802 |
| 3879 // Verify that the delegate is not notified again when the | 3803 // Verify that the delegate is not notified again when the |
| 3880 // retransmit is acked. | 3804 // retransmit is acked. |
| 3881 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) | 3805 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
| 3882 .WillOnce(Return(no_lost_packets)); | 3806 .WillOnce(Return(no_lost_packets)); |
| 3883 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 3807 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 3884 QuicAckFrame third_ack_frame = InitAckFrame(5, 0); | 3808 QuicAckFrame third_ack_frame = InitAckFrame(5); |
| 3885 ProcessAckPacket(&third_ack_frame); | 3809 ProcessAckPacket(&third_ack_frame); |
| 3886 } | 3810 } |
| 3887 | 3811 |
| 3888 TEST_P(QuicConnectionTest, AckNotifierFECTriggerCallback) { | 3812 TEST_P(QuicConnectionTest, AckNotifierFECTriggerCallback) { |
| 3889 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3813 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3890 | 3814 |
| 3891 // Create a delegate which we expect to be called. | 3815 // Create a delegate which we expect to be called. |
| 3892 scoped_refptr<MockAckNotifierDelegate> delegate( | 3816 scoped_refptr<MockAckNotifierDelegate> delegate( |
| 3893 new MockAckNotifierDelegate); | 3817 new MockAckNotifierDelegate); |
| 3894 EXPECT_CALL(*delegate, OnAckNotification(_, _, _, _, _)).Times(1); | 3818 EXPECT_CALL(*delegate, OnAckNotification(_, _, _, _, _)).Times(1); |
| 3895 | 3819 |
| 3896 // Send some data, which will register the delegate to be notified. | 3820 // Send some data, which will register the delegate to be notified. |
| 3897 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); | 3821 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); |
| 3898 connection_.SendStreamDataWithString(2, "bar", 0, !kFin, NULL); | 3822 connection_.SendStreamDataWithString(2, "bar", 0, !kFin, NULL); |
| 3899 | 3823 |
| 3900 // Process an ACK from the server with a revived packet, which should trigger | 3824 // Process an ACK from the server with a revived packet, which should trigger |
| 3901 // the callback. | 3825 // the callback. |
| 3902 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 3826 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 3903 QuicAckFrame frame = InitAckFrame(2, 0); | 3827 QuicAckFrame frame = InitAckFrame(2); |
| 3904 NackPacket(1, &frame); | 3828 NackPacket(1, &frame); |
| 3905 frame.received_info.revived_packets.insert(1); | 3829 frame.revived_packets.insert(1); |
| 3906 ProcessAckPacket(&frame); | 3830 ProcessAckPacket(&frame); |
| 3907 // If the ack is processed again, the notifier should not be called again. | 3831 // If the ack is processed again, the notifier should not be called again. |
| 3908 ProcessAckPacket(&frame); | 3832 ProcessAckPacket(&frame); |
| 3909 } | 3833 } |
| 3910 | 3834 |
| 3911 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterFECRecovery) { | 3835 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterFECRecovery) { |
| 3912 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3836 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3913 EXPECT_CALL(visitor_, OnCanWrite()); | 3837 EXPECT_CALL(visitor_, OnCanWrite()); |
| 3914 | 3838 |
| 3915 // Create a delegate which we expect to be called. | 3839 // Create a delegate which we expect to be called. |
| 3916 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); | 3840 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); |
| 3917 EXPECT_CALL(*delegate, OnAckNotification(_, _, _, _, _)).Times(1); | 3841 EXPECT_CALL(*delegate, OnAckNotification(_, _, _, _, _)).Times(1); |
| 3918 | 3842 |
| 3919 // Expect ACKs for 1 packet. | 3843 // Expect ACKs for 1 packet. |
| 3920 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 3844 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 3921 | 3845 |
| 3922 // Send one packet, and register to be notified on ACK. | 3846 // Send one packet, and register to be notified on ACK. |
| 3923 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); | 3847 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); |
| 3924 | 3848 |
| 3925 // Ack packet gets dropped, but we receive an FEC packet that covers it. | 3849 // Ack packet gets dropped, but we receive an FEC packet that covers it. |
| 3926 // Should recover the Ack packet and trigger the notification callback. | 3850 // Should recover the Ack packet and trigger the notification callback. |
| 3927 QuicFrames frames; | 3851 QuicFrames frames; |
| 3928 | 3852 |
| 3929 QuicAckFrame ack_frame = InitAckFrame(1, 0); | 3853 QuicAckFrame ack_frame = InitAckFrame(1); |
| 3930 frames.push_back(QuicFrame(&ack_frame)); | 3854 frames.push_back(QuicFrame(&ack_frame)); |
| 3931 | 3855 |
| 3932 // Dummy stream frame to satisfy expectations set elsewhere. | 3856 // Dummy stream frame to satisfy expectations set elsewhere. |
| 3933 frames.push_back(QuicFrame(&frame1_)); | 3857 frames.push_back(QuicFrame(&frame1_)); |
| 3934 | 3858 |
| 3935 QuicPacketHeader ack_header; | 3859 QuicPacketHeader ack_header; |
| 3936 ack_header.public_header.connection_id = connection_id_; | 3860 ack_header.public_header.connection_id = connection_id_; |
| 3937 ack_header.public_header.reset_flag = false; | 3861 ack_header.public_header.reset_flag = false; |
| 3938 ack_header.public_header.version_flag = false; | 3862 ack_header.public_header.version_flag = false; |
| 3939 ack_header.entropy_flag = !kEntropyFlag; | 3863 ack_header.entropy_flag = !kEntropyFlag; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4017 MOCK_METHOD1(OnVersionNegotiationPacket, | 3941 MOCK_METHOD1(OnVersionNegotiationPacket, |
| 4018 void(const QuicVersionNegotiationPacket&)); | 3942 void(const QuicVersionNegotiationPacket&)); |
| 4019 | 3943 |
| 4020 MOCK_METHOD2(OnRevivedPacket, | 3944 MOCK_METHOD2(OnRevivedPacket, |
| 4021 void(const QuicPacketHeader&, StringPiece payload)); | 3945 void(const QuicPacketHeader&, StringPiece payload)); |
| 4022 }; | 3946 }; |
| 4023 | 3947 |
| 4024 TEST_P(QuicConnectionTest, OnPacketHeaderDebugVisitor) { | 3948 TEST_P(QuicConnectionTest, OnPacketHeaderDebugVisitor) { |
| 4025 QuicPacketHeader header; | 3949 QuicPacketHeader header; |
| 4026 | 3950 |
| 4027 scoped_ptr<MockQuicConnectionDebugVisitor> | 3951 MockQuicConnectionDebugVisitor* debug_visitor = |
| 4028 debug_visitor(new StrictMock<MockQuicConnectionDebugVisitor>); | 3952 new MockQuicConnectionDebugVisitor(); |
| 4029 connection_.set_debug_visitor(debug_visitor.get()); | 3953 connection_.set_debug_visitor(debug_visitor); |
| 4030 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1); | 3954 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1); |
| 4031 connection_.OnPacketHeader(header); | 3955 connection_.OnPacketHeader(header); |
| 4032 } | 3956 } |
| 4033 | 3957 |
| 4034 TEST_P(QuicConnectionTest, Pacing) { | 3958 TEST_P(QuicConnectionTest, Pacing) { |
| 4035 ValueRestore<bool> old_flag(&FLAGS_enable_quic_pacing, true); | 3959 ValueRestore<bool> old_flag(&FLAGS_enable_quic_pacing, true); |
| 4036 | 3960 |
| 4037 TestConnection server(connection_id_, IPEndPoint(), helper_.get(), | 3961 TestConnection server(connection_id_, IPEndPoint(), helper_.get(), |
| 4038 writer_.get(), true, version()); | 3962 writer_.get(), true, version()); |
| 4039 TestConnection client(connection_id_, IPEndPoint(), helper_.get(), | 3963 TestConnection client(connection_id_, IPEndPoint(), helper_.get(), |
| (...skipping 21 matching lines...) Expand all Loading... |
| 4061 QuicBlockedFrame blocked; | 3985 QuicBlockedFrame blocked; |
| 4062 blocked.stream_id = 3; | 3986 blocked.stream_id = 3; |
| 4063 EXPECT_CALL(visitor_, OnBlockedFrames(_)); | 3987 EXPECT_CALL(visitor_, OnBlockedFrames(_)); |
| 4064 ProcessFramePacket(QuicFrame(&blocked)); | 3988 ProcessFramePacket(QuicFrame(&blocked)); |
| 4065 EXPECT_TRUE(ack_alarm->IsSet()); | 3989 EXPECT_TRUE(ack_alarm->IsSet()); |
| 4066 } | 3990 } |
| 4067 | 3991 |
| 4068 } // namespace | 3992 } // namespace |
| 4069 } // namespace test | 3993 } // namespace test |
| 4070 } // namespace net | 3994 } // namespace net |
| OLD | NEW |