Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: net/quic/quic_connection_test.cc

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

Powered by Google App Engine
This is Rietveld 408576698