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

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

Issue 131743009: Land Recent QUIC Changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use size_t instead of int to fix win_x64 compile error Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « net/quic/quic_connection_helper.h ('k') | net/quic/quic_crypto_stream.h » ('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 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 MockRandom* random_generator_; 267 MockRandom* random_generator_;
268 268
269 DISALLOW_COPY_AND_ASSIGN(TestConnectionHelper); 269 DISALLOW_COPY_AND_ASSIGN(TestConnectionHelper);
270 }; 270 };
271 271
272 class TestPacketWriter : public QuicPacketWriter { 272 class TestPacketWriter : public QuicPacketWriter {
273 public: 273 public:
274 TestPacketWriter() 274 TestPacketWriter()
275 : last_packet_size_(0), 275 : last_packet_size_(0),
276 write_blocked_(false), 276 write_blocked_(false),
277 block_next_write_(false),
277 is_write_blocked_data_buffered_(false), 278 is_write_blocked_data_buffered_(false),
278 is_server_(true), 279 is_server_(true),
279 final_bytes_of_last_packet_(0), 280 final_bytes_of_last_packet_(0),
280 final_bytes_of_previous_packet_(0), 281 final_bytes_of_previous_packet_(0),
281 use_tagging_decrypter_(false), 282 use_tagging_decrypter_(false),
282 packets_write_attempts_(0) { 283 packets_write_attempts_(0) {
283 } 284 }
284 285
285 // QuicPacketWriter 286 // QuicPacketWriter interface
286 virtual WriteResult WritePacket( 287 virtual WriteResult WritePacket(
287 const char* buffer, size_t buf_len, 288 const char* buffer, size_t buf_len,
288 const IPAddressNumber& self_address, 289 const IPAddressNumber& self_address,
289 const IPEndPoint& peer_address, 290 const IPEndPoint& peer_address,
290 QuicBlockedWriterInterface* blocked_writer) OVERRIDE { 291 QuicBlockedWriterInterface* blocked_writer) OVERRIDE {
291 QuicEncryptedPacket packet(buffer, buf_len); 292 QuicEncryptedPacket packet(buffer, buf_len);
292 ++packets_write_attempts_; 293 ++packets_write_attempts_;
293 294
294 if (packet.length() >= sizeof(final_bytes_of_last_packet_)) { 295 if (packet.length() >= sizeof(final_bytes_of_last_packet_)) {
295 final_bytes_of_previous_packet_ = final_bytes_of_last_packet_; 296 final_bytes_of_previous_packet_ = final_bytes_of_last_packet_;
296 memcpy(&final_bytes_of_last_packet_, packet.data() + packet.length() - 4, 297 memcpy(&final_bytes_of_last_packet_, packet.data() + packet.length() - 4,
297 sizeof(final_bytes_of_last_packet_)); 298 sizeof(final_bytes_of_last_packet_));
298 } 299 }
299 300
300 QuicFramer framer(QuicSupportedVersions(), QuicTime::Zero(), !is_server_); 301 QuicFramer framer(QuicSupportedVersions(), QuicTime::Zero(), !is_server_);
301 if (use_tagging_decrypter_) { 302 if (use_tagging_decrypter_) {
302 framer.SetDecrypter(new TaggingDecrypter); 303 framer.SetDecrypter(new TaggingDecrypter);
303 } 304 }
304 visitor_.Reset(); 305 visitor_.Reset();
305 framer.set_visitor(&visitor_); 306 framer.set_visitor(&visitor_);
306 EXPECT_TRUE(framer.ProcessPacket(packet)); 307 EXPECT_TRUE(framer.ProcessPacket(packet));
308 if (block_next_write_) {
309 write_blocked_ = true;
310 block_next_write_ = false;
311 }
307 if (IsWriteBlocked()) { 312 if (IsWriteBlocked()) {
308 return WriteResult(WRITE_STATUS_BLOCKED, -1); 313 return WriteResult(WRITE_STATUS_BLOCKED, -1);
309 } 314 }
310 last_packet_size_ = packet.length(); 315 last_packet_size_ = packet.length();
311 return WriteResult(WRITE_STATUS_OK, last_packet_size_); 316 return WriteResult(WRITE_STATUS_OK, last_packet_size_);
312 } 317 }
313 318
314 virtual bool IsWriteBlockedDataBuffered() const OVERRIDE { 319 virtual bool IsWriteBlockedDataBuffered() const OVERRIDE {
315 return is_write_blocked_data_buffered_; 320 return is_write_blocked_data_buffered_;
316 } 321 }
317 322
318 virtual bool IsWriteBlocked() const OVERRIDE { return write_blocked_; } 323 virtual bool IsWriteBlocked() const OVERRIDE { return write_blocked_; }
319 324
320 virtual void SetWritable() OVERRIDE { write_blocked_ = false; } 325 virtual void SetWritable() OVERRIDE { write_blocked_ = false; }
321 326
322 void SetWriteBlocked() { write_blocked_ = true; } 327 void BlockNextWrite() { block_next_write_ = true; }
323 328
324 // Resets the visitor's state by clearing out the headers and frames. 329 // Resets the visitor's state by clearing out the headers and frames.
325 void Reset() { 330 void Reset() {
326 visitor_.Reset(); 331 visitor_.Reset();
327 } 332 }
328 333
329 QuicPacketHeader* header() { return visitor_.header(); } 334 QuicPacketHeader* header() { return visitor_.header(); }
330 335
331 size_t frame_count() const { return visitor_.frame_count(); } 336 size_t frame_count() const { return visitor_.frame_count(); }
332 337
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 void use_tagging_decrypter() { 373 void use_tagging_decrypter() {
369 use_tagging_decrypter_ = true; 374 use_tagging_decrypter_ = true;
370 } 375 }
371 376
372 uint32 packets_write_attempts() { return packets_write_attempts_; } 377 uint32 packets_write_attempts() { return packets_write_attempts_; }
373 378
374 private: 379 private:
375 FramerVisitorCapturingFrames visitor_; 380 FramerVisitorCapturingFrames visitor_;
376 size_t last_packet_size_; 381 size_t last_packet_size_;
377 bool write_blocked_; 382 bool write_blocked_;
383 bool block_next_write_;
378 bool is_write_blocked_data_buffered_; 384 bool is_write_blocked_data_buffered_;
379 bool is_server_; 385 bool is_server_;
380 uint32 final_bytes_of_last_packet_; 386 uint32 final_bytes_of_last_packet_;
381 uint32 final_bytes_of_previous_packet_; 387 uint32 final_bytes_of_previous_packet_;
382 bool use_tagging_decrypter_; 388 bool use_tagging_decrypter_;
383 uint32 packets_write_attempts_; 389 uint32 packets_write_attempts_;
384 390
385 DISALLOW_COPY_AND_ASSIGN(TestPacketWriter); 391 DISALLOW_COPY_AND_ASSIGN(TestPacketWriter);
386 }; 392 };
387 393
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 EXPECT_THAT(frame->received_info.missing_packets, Contains(arrived)); 823 EXPECT_THAT(frame->received_info.missing_packets, Contains(arrived));
818 frame->received_info.missing_packets.erase(arrived); 824 frame->received_info.missing_packets.erase(arrived);
819 frame->received_info.entropy_hash ^= 825 frame->received_info.entropy_hash ^=
820 QuicConnectionPeer::GetSentEntropyHash(&connection_, arrived); 826 QuicConnectionPeer::GetSentEntropyHash(&connection_, arrived);
821 if (arrived > 1) { 827 if (arrived > 1) {
822 frame->received_info.entropy_hash ^= 828 frame->received_info.entropy_hash ^=
823 QuicConnectionPeer::GetSentEntropyHash(&connection_, arrived - 1); 829 QuicConnectionPeer::GetSentEntropyHash(&connection_, arrived - 1);
824 } 830 }
825 } 831 }
826 832
833 void TriggerConnectionClose() {
834 // Send an erroneous packet to close the connection.
835 EXPECT_CALL(visitor_,
836 OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false));
837 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a
838 // packet call to the visitor.
839 ProcessDataPacket(6000, 0, !kEntropyFlag);
840 EXPECT_FALSE(
841 QuicConnectionPeer::GetConnectionClosePacket(&connection_) == NULL);
842 }
843
827 QuicGuid guid_; 844 QuicGuid guid_;
828 QuicFramer framer_; 845 QuicFramer framer_;
829 QuicPacketCreator creator_; 846 QuicPacketCreator creator_;
830 MockEntropyCalculator entropy_calculator_; 847 MockEntropyCalculator entropy_calculator_;
831 848
832 MockSendAlgorithm* send_algorithm_; 849 MockSendAlgorithm* send_algorithm_;
833 TestReceiveAlgorithm* receive_algorithm_; 850 TestReceiveAlgorithm* receive_algorithm_;
834 MockClock clock_; 851 MockClock clock_;
835 MockRandom random_generator_; 852 MockRandom random_generator_;
836 scoped_ptr<TestConnectionHelper> helper_; 853 scoped_ptr<TestConnectionHelper> helper_;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
937 creator_.set_sequence_number(5); 954 creator_.set_sequence_number(5);
938 QuicAckFrame frame = InitAckFrame(0, 4); 955 QuicAckFrame frame = InitAckFrame(0, 4);
939 ProcessAckPacket(&frame); 956 ProcessAckPacket(&frame);
940 957
941 // Force an ack to be sent. 958 // Force an ack to be sent.
942 SendAckPacketToPeer(); 959 SendAckPacketToPeer();
943 EXPECT_TRUE(IsMissing(4)); 960 EXPECT_TRUE(IsMissing(4));
944 } 961 }
945 962
946 TEST_F(QuicConnectionTest, RejectPacketTooFarOut) { 963 TEST_F(QuicConnectionTest, RejectPacketTooFarOut) {
964 EXPECT_CALL(visitor_,
965 OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false));
947 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a 966 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a
948 // packet call to the visitor. 967 // packet call to the visitor.
949 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false));
950 ProcessDataPacket(6000, 0, !kEntropyFlag); 968 ProcessDataPacket(6000, 0, !kEntropyFlag);
969 EXPECT_FALSE(
970 QuicConnectionPeer::GetConnectionClosePacket(&connection_) == NULL);
951 } 971 }
952 972
953 TEST_F(QuicConnectionTest, TruncatedAck) { 973 TEST_F(QuicConnectionTest, TruncatedAck) {
954 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 974 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
955 QuicPacketSequenceNumber num_packets = 256 * 2 + 1; 975 QuicPacketSequenceNumber num_packets = 256 * 2 + 1;
956 for (QuicPacketSequenceNumber i = 0; i < num_packets; ++i) { 976 for (QuicPacketSequenceNumber i = 0; i < num_packets; ++i) {
957 SendStreamDataToPeer(1, "foo", i * 3, !kFin, NULL); 977 SendStreamDataToPeer(1, "foo", i * 3, !kFin, NULL);
958 } 978 }
959 979
960 QuicAckFrame frame = InitAckFrame(num_packets, 1); 980 QuicAckFrame frame = InitAckFrame(num_packets, 1);
961 // Create an ack with 256 nacks, none adjacent to one another. 981 // Create an ack with 256 nacks, none adjacent to one another.
962 for (QuicPacketSequenceNumber i = 1; i <= 256; ++i) { 982 for (QuicPacketSequenceNumber i = 1; i <= 256; ++i) {
963 NackPacket(i * 2, &frame); 983 NackPacket(i * 2, &frame);
964 } 984 }
965 EXPECT_CALL(entropy_calculator_, 985 EXPECT_CALL(entropy_calculator_,
966 EntropyHash(511)).WillOnce(testing::Return(0)); 986 EntropyHash(511)).WillOnce(testing::Return(0));
967 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(256); 987 EXPECT_CALL(*send_algorithm_, UpdateRtt(_));
988 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(256);
968 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(2); 989 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(2);
969 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(2); 990 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(2);
970 ProcessAckPacket(&frame); 991 ProcessAckPacket(&frame);
971 992
972 QuicReceivedPacketManager* received_packet_manager = 993 QuicReceivedPacketManager* received_packet_manager =
973 QuicConnectionPeer::GetReceivedPacketManager(&connection_); 994 QuicConnectionPeer::GetReceivedPacketManager(&connection_);
974 // A truncated ack will not have the true largest observed. 995 // A truncated ack will not have the true largest observed.
975 EXPECT_GT(num_packets, 996 EXPECT_GT(num_packets,
976 received_packet_manager->peer_largest_observed_packet()); 997 received_packet_manager->peer_largest_observed_packet());
977 998
978 AckPacket(192, &frame); 999 AckPacket(192, &frame);
979 1000
980 // Removing one missing packet allows us to ack 192 and one more range. 1001 // Removing one missing packet allows us to ack 192 and one more range.
981 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(2); 1002 EXPECT_CALL(*send_algorithm_, UpdateRtt(_));
1003 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(2);
982 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(2); 1004 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(2);
983 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(2); 1005 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(2);
984 ProcessAckPacket(&frame); 1006 ProcessAckPacket(&frame);
985 EXPECT_EQ(num_packets, 1007 EXPECT_EQ(num_packets,
986 received_packet_manager->peer_largest_observed_packet()); 1008 received_packet_manager->peer_largest_observed_packet());
987 } 1009 }
988 1010
989 TEST_F(QuicConnectionTest, AckReceiptCausesAckSendBadEntropy) { 1011 TEST_F(QuicConnectionTest, AckReceiptCausesAckSendBadEntropy) {
990 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1012 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
991 1013
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 QuicPacketSequenceNumber original; 1055 QuicPacketSequenceNumber original;
1034 QuicByteCount packet_size; 1056 QuicByteCount packet_size;
1035 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)) 1057 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _))
1036 .WillOnce(DoAll(SaveArg<1>(&original), SaveArg<2>(&packet_size), 1058 .WillOnce(DoAll(SaveArg<1>(&original), SaveArg<2>(&packet_size),
1037 Return(true))); 1059 Return(true)));
1038 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(1, _)).Times(1); 1060 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(1, _)).Times(1);
1039 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); 1061 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL);
1040 QuicAckFrame frame = InitAckFrame(original, 1); 1062 QuicAckFrame frame = InitAckFrame(original, 1);
1041 NackPacket(original, &frame); 1063 NackPacket(original, &frame);
1042 // First nack triggers early retransmit. 1064 // First nack triggers early retransmit.
1065 EXPECT_CALL(*send_algorithm_, UpdateRtt(_));
1043 QuicPacketSequenceNumber retransmission; 1066 QuicPacketSequenceNumber retransmission;
1044 EXPECT_CALL(*send_algorithm_, 1067 EXPECT_CALL(*send_algorithm_,
1045 OnPacketSent(_, _, packet_size - kQuicVersionSize, 1068 OnPacketSent(_, _, packet_size - kQuicVersionSize,
1046 NACK_RETRANSMISSION, _)) 1069 NACK_RETRANSMISSION, _))
1047 .WillOnce(DoAll(SaveArg<1>(&retransmission), Return(true))); 1070 .WillOnce(DoAll(SaveArg<1>(&retransmission), Return(true)));
1048 1071
1049 ProcessAckPacket(&frame); 1072 ProcessAckPacket(&frame);
1050 1073
1051 QuicAckFrame frame2 = InitAckFrame(retransmission, 1); 1074 QuicAckFrame frame2 = InitAckFrame(retransmission, 1);
1052 NackPacket(original, &frame2); 1075 NackPacket(original, &frame2);
1053 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)); 1076 EXPECT_CALL(*send_algorithm_, UpdateRtt(_));
1077 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _));
1054 1078
1055 ProcessAckPacket(&frame2); 1079 ProcessAckPacket(&frame2);
1056 // Now if the peer sends an ack which still reports the retransmitted packet 1080 // Now if the peer sends an ack which still reports the retransmitted packet
1057 // as missing, then that will count as a packet which instigates an ack. 1081 // as missing, then that will count as a packet which instigates an ack.
1058 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)); 1082 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _));
1059 ProcessAckPacket(&frame2); 1083 ProcessAckPacket(&frame2);
1060 ProcessAckPacket(&frame2); 1084 ProcessAckPacket(&frame2);
1061 1085
1062 // But an ack with no missing packets will not send an ack. 1086 // But an ack with no missing packets will not send an ack.
1063 AckPacket(original, &frame2); 1087 AckPacket(original, &frame2);
(...skipping 28 matching lines...) Expand all
1092 creator_.set_sequence_number(7); 1116 creator_.set_sequence_number(7);
1093 ProcessAckPacket(&frame2); 1117 ProcessAckPacket(&frame2);
1094 } 1118 }
1095 1119
1096 TEST_F(QuicConnectionTest, LargestObservedLower) { 1120 TEST_F(QuicConnectionTest, LargestObservedLower) {
1097 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1121 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1098 1122
1099 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); 1123 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL);
1100 SendStreamDataToPeer(1, "bar", 3, !kFin, NULL); 1124 SendStreamDataToPeer(1, "bar", 3, !kFin, NULL);
1101 SendStreamDataToPeer(1, "eep", 6, !kFin, NULL); 1125 SendStreamDataToPeer(1, "eep", 6, !kFin, NULL);
1102 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(2); 1126 EXPECT_CALL(*send_algorithm_, UpdateRtt(_));
1127 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(2);
1103 1128
1104 // Start out saying the largest observed is 2. 1129 // Start out saying the largest observed is 2.
1105 QuicAckFrame frame1 = InitAckFrame(1, 0); 1130 QuicAckFrame frame1 = InitAckFrame(1, 0);
1106 QuicAckFrame frame2 = InitAckFrame(2, 0); 1131 QuicAckFrame frame2 = InitAckFrame(2, 0);
1107 ProcessAckPacket(&frame2); 1132 ProcessAckPacket(&frame2);
1108 1133
1109 // Now change it to 1, and it should cause a connection error. 1134 // Now change it to 1, and it should cause a connection error.
1110 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_ACK_DATA, false)); 1135 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_ACK_DATA, false));
1111 EXPECT_CALL(visitor_, OnCanWrite()).Times(0); 1136 EXPECT_CALL(visitor_, OnCanWrite()).Times(0);
1112 ProcessAckPacket(&frame1); 1137 ProcessAckPacket(&frame1);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1226 1251
1227 SendStreamDataToPeer(1, "foo", 12, !kFin, &last_packet); 1252 SendStreamDataToPeer(1, "foo", 12, !kFin, &last_packet);
1228 EXPECT_EQ(PACKET_6BYTE_SEQUENCE_NUMBER, 1253 EXPECT_EQ(PACKET_6BYTE_SEQUENCE_NUMBER,
1229 connection_.options()->send_sequence_number_length); 1254 connection_.options()->send_sequence_number_length);
1230 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, 1255 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER,
1231 last_header()->public_header.sequence_number_length); 1256 last_header()->public_header.sequence_number_length);
1232 } 1257 }
1233 1258
1234 TEST_F(QuicConnectionTest, BasicSending) { 1259 TEST_F(QuicConnectionTest, BasicSending) {
1235 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1260 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1236 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(6); 1261 // EXPECT_CALL(*send_algorithm_, UpdateRtt(_));
1262 // EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(6);
1237 QuicPacketSequenceNumber last_packet; 1263 QuicPacketSequenceNumber last_packet;
1238 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 1264 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1
1239 EXPECT_EQ(1u, last_packet); 1265 EXPECT_EQ(1u, last_packet);
1240 SendAckPacketToPeer(); // Packet 2 1266 SendAckPacketToPeer(); // Packet 2
1241 1267
1242 EXPECT_EQ(1u, last_ack()->sent_info.least_unacked); 1268 EXPECT_EQ(1u, last_ack()->sent_info.least_unacked);
1243 1269
1244 SendAckPacketToPeer(); // Packet 3 1270 SendAckPacketToPeer(); // Packet 3
1245 EXPECT_EQ(1u, last_ack()->sent_info.least_unacked); 1271 EXPECT_EQ(1u, last_ack()->sent_info.least_unacked);
1246 1272
1247 SendStreamDataToPeer(1, "bar", 3, !kFin, &last_packet); // Packet 4 1273 SendStreamDataToPeer(1, "bar", 3, !kFin, &last_packet); // Packet 4
1248 EXPECT_EQ(4u, last_packet); 1274 EXPECT_EQ(4u, last_packet);
1249 SendAckPacketToPeer(); // Packet 5 1275 SendAckPacketToPeer(); // Packet 5
1250 EXPECT_EQ(1u, last_ack()->sent_info.least_unacked); 1276 EXPECT_EQ(1u, last_ack()->sent_info.least_unacked);
1251 1277
1278 EXPECT_CALL(*send_algorithm_, UpdateRtt(_));
1279 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(3);
1280
1252 // Peer acks up to packet 3. 1281 // Peer acks up to packet 3.
1253 QuicAckFrame frame = InitAckFrame(3, 0); 1282 QuicAckFrame frame = InitAckFrame(3, 0);
1254 ProcessAckPacket(&frame); 1283 ProcessAckPacket(&frame);
1255 SendAckPacketToPeer(); // Packet 6 1284 SendAckPacketToPeer(); // Packet 6
1256 1285
1257 // As soon as we've acked one, we skip ack packets 2 and 3 and note lack of 1286 // As soon as we've acked one, we skip ack packets 2 and 3 and note lack of
1258 // ack for 4. 1287 // ack for 4.
1259 EXPECT_EQ(4u, last_ack()->sent_info.least_unacked); 1288 EXPECT_EQ(4u, last_ack()->sent_info.least_unacked);
1260 1289
1290 EXPECT_CALL(*send_algorithm_, UpdateRtt(_));
1291 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(3);
1292
1261 // Peer acks up to packet 4, the last packet. 1293 // Peer acks up to packet 4, the last packet.
1262 QuicAckFrame frame2 = InitAckFrame(6, 0); 1294 QuicAckFrame frame2 = InitAckFrame(6, 0);
1263 ProcessAckPacket(&frame2); // Acks don't instigate acks. 1295 ProcessAckPacket(&frame2); // Acks don't instigate acks.
1264 1296
1265 // Verify that we did not send an ack. 1297 // Verify that we did not send an ack.
1266 EXPECT_EQ(6u, last_header()->packet_sequence_number); 1298 EXPECT_EQ(6u, last_header()->packet_sequence_number);
1267 1299
1268 // So the last ack has not changed. 1300 // So the last ack has not changed.
1269 EXPECT_EQ(4u, last_ack()->sent_info.least_unacked); 1301 EXPECT_EQ(4u, last_ack()->sent_info.least_unacked);
1270 1302
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1302 // All packets carry version info till version is negotiated. 1334 // All packets carry version info till version is negotiated.
1303 size_t payload_length; 1335 size_t payload_length;
1304 connection_.options()->max_packet_length = 1336 connection_.options()->max_packet_length =
1305 GetPacketLengthForOneStream( 1337 GetPacketLengthForOneStream(
1306 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, 1338 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER,
1307 IN_FEC_GROUP, &payload_length); 1339 IN_FEC_GROUP, &payload_length);
1308 // And send FEC every two packets. 1340 // And send FEC every two packets.
1309 connection_.options()->max_packets_per_fec_group = 2; 1341 connection_.options()->max_packets_per_fec_group = 2;
1310 1342
1311 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1343 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1312 writer_->SetWriteBlocked(); 1344 writer_->BlockNextWrite();
1313 const string payload(payload_length, 'a'); 1345 const string payload(payload_length, 'a');
1314 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL); 1346 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL);
1315 EXPECT_FALSE(creator_.ShouldSendFec(true)); 1347 EXPECT_FALSE(creator_.ShouldSendFec(true));
1316 // Expect the first data packet and the fec packet to be queued. 1348 // Expect the first data packet and the fec packet to be queued.
1317 EXPECT_EQ(2u, connection_.NumQueuedPackets()); 1349 EXPECT_EQ(2u, connection_.NumQueuedPackets());
1318 } 1350 }
1319 1351
1320 TEST_F(QuicConnectionTest, AbandonFECFromCongestionWindow) { 1352 TEST_F(QuicConnectionTest, AbandonFECFromCongestionWindow) {
1321 connection_.options()->max_packets_per_fec_group = 1; 1353 connection_.options()->max_packets_per_fec_group = 1;
1322 // 1 Data and 1 FEC packet. 1354 // 1 Data and 1 FEC packet.
(...skipping 21 matching lines...) Expand all
1344 // Send some more data afterwards to ensure early retransmit doesn't trigger. 1376 // Send some more data afterwards to ensure early retransmit doesn't trigger.
1345 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL); 1377 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL);
1346 connection_.SendStreamDataWithString(3, "foo", 6, !kFin, NULL); 1378 connection_.SendStreamDataWithString(3, "foo", 6, !kFin, NULL);
1347 1379
1348 QuicAckFrame ack_fec = InitAckFrame(2, 1); 1380 QuicAckFrame ack_fec = InitAckFrame(2, 1);
1349 // Data packet missing. 1381 // Data packet missing.
1350 // TODO(ianswett): Note that this is not a sensible ack, since if the FEC was 1382 // TODO(ianswett): Note that this is not a sensible ack, since if the FEC was
1351 // received, it would cause the covered packet to be acked as well. 1383 // received, it would cause the covered packet to be acked as well.
1352 NackPacket(1, &ack_fec); 1384 NackPacket(1, &ack_fec);
1353 1385
1354 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(1); 1386 EXPECT_CALL(*send_algorithm_, UpdateRtt(_));
1387 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(1);
1355 ProcessAckPacket(&ack_fec); 1388 ProcessAckPacket(&ack_fec);
1356 clock_.AdvanceTime(DefaultRetransmissionTime()); 1389 clock_.AdvanceTime(DefaultRetransmissionTime());
1357 1390
1358 // Don't abandon the acked FEC packet, but it will abandon 2 the subsequent 1391 // Don't abandon the acked FEC packet, but it will abandon 2 the subsequent
1359 // FEC packets. 1392 // FEC packets.
1360 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 1393 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
1361 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3); 1394 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3);
1362 connection_.GetRetransmissionAlarm()->Fire(); 1395 connection_.GetRetransmissionAlarm()->Fire();
1363 } 1396 }
1364 1397
1365 TEST_F(QuicConnectionTest, AbandonAllFEC) { 1398 TEST_F(QuicConnectionTest, AbandonAllFEC) {
1366 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1399 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1367 connection_.options()->max_packets_per_fec_group = 1; 1400 connection_.options()->max_packets_per_fec_group = 1;
1368 1401
1369 // 1 Data and 1 FEC packet. 1402 // 1 Data and 1 FEC packet.
1370 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); 1403 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6);
1371 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); 1404 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL);
1372 // Send some more data afterwards to ensure early retransmit doesn't trigger. 1405 // Send some more data afterwards to ensure early retransmit doesn't trigger.
1373 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL); 1406 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL);
1374 // Advance the time so not all the FEC packets are abandoned. 1407 // Advance the time so not all the FEC packets are abandoned.
1375 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); 1408 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1));
1376 connection_.SendStreamDataWithString(3, "foo", 6, !kFin, NULL); 1409 connection_.SendStreamDataWithString(3, "foo", 6, !kFin, NULL);
1377 1410
1378 QuicAckFrame ack_fec = InitAckFrame(5, 1); 1411 QuicAckFrame ack_fec = InitAckFrame(5, 1);
1379 // Ack all data packets, but no fec packets. 1412 // Ack all data packets, but no fec packets.
1380 NackPacket(2, &ack_fec); 1413 NackPacket(2, &ack_fec);
1381 NackPacket(4, &ack_fec); 1414 NackPacket(4, &ack_fec);
1382 1415
1383 // Lose the first FEC packet and ack the three data packets. 1416 // Lose the first FEC packet and ack the three data packets.
1384 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(3); 1417 EXPECT_CALL(*send_algorithm_, UpdateRtt(_));
1418 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(3);
1385 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(2, _)); 1419 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(2, _));
1386 EXPECT_CALL(*send_algorithm_, OnPacketLost(2, _)); 1420 EXPECT_CALL(*send_algorithm_, OnPacketLost(2, _));
1387 ProcessAckPacket(&ack_fec); 1421 ProcessAckPacket(&ack_fec);
1388 1422
1389 clock_.AdvanceTime(DefaultRetransmissionTime().Subtract( 1423 clock_.AdvanceTime(DefaultRetransmissionTime().Subtract(
1390 QuicTime::Delta::FromMilliseconds(1))); 1424 QuicTime::Delta::FromMilliseconds(1)));
1391 1425
1392 // Abandon all packets 1426 // Abandon all packets
1393 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(false)); 1427 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(false));
1394 connection_.GetRetransmissionAlarm()->Fire(); 1428 connection_.GetRetransmissionAlarm()->Fire();
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
1570 EXPECT_EQ(1u, frame.stream_id); 1604 EXPECT_EQ(1u, frame.stream_id);
1571 EXPECT_EQ("ABCD", string(static_cast<char*> 1605 EXPECT_EQ("ABCD", string(static_cast<char*>
1572 (frame.data.iovec()[0].iov_base), 1606 (frame.data.iovec()[0].iov_base),
1573 (frame.data.iovec()[0].iov_len))); 1607 (frame.data.iovec()[0].iov_len)));
1574 } 1608 }
1575 1609
1576 TEST_F(QuicConnectionTest, FramePackingSendvQueued) { 1610 TEST_F(QuicConnectionTest, FramePackingSendvQueued) {
1577 // Try to send two stream frames in 1 packet by using writev. 1611 // Try to send two stream frames in 1 packet by using writev.
1578 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)); 1612 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _));
1579 1613
1580 writer_->SetWriteBlocked(); 1614 writer_->BlockNextWrite();
1581 char data[] = "ABCD"; 1615 char data[] = "ABCD";
1582 IOVector data_iov; 1616 IOVector data_iov;
1583 data_iov.AppendNoCoalesce(data, 2); 1617 data_iov.AppendNoCoalesce(data, 2);
1584 data_iov.AppendNoCoalesce(data + 2, 2); 1618 data_iov.AppendNoCoalesce(data + 2, 2);
1585 connection_.SendStreamData(1, data_iov, 0, !kFin, NULL); 1619 connection_.SendStreamData(1, data_iov, 0, !kFin, NULL);
1586 1620
1587 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 1621 EXPECT_EQ(1u, connection_.NumQueuedPackets());
1588 EXPECT_TRUE(connection_.HasQueuedData()); 1622 EXPECT_TRUE(connection_.HasQueuedData());
1589 1623
1590 // Attempt to send all packets, but since we're actually still
1591 // blocked, they should all remain queued.
1592 EXPECT_FALSE(connection_.OnCanWrite());
1593 EXPECT_EQ(1u, connection_.NumQueuedPackets());
1594
1595 // Unblock the writes and actually send. 1624 // Unblock the writes and actually send.
1596 writer_->SetWritable(); 1625 writer_->SetWritable();
1597 EXPECT_TRUE(connection_.OnCanWrite()); 1626 EXPECT_TRUE(connection_.OnCanWrite());
1598 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1627 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1599 1628
1600 // Parse the last packet and ensure it's one stream frame from one stream. 1629 // Parse the last packet and ensure it's one stream frame from one stream.
1601 EXPECT_EQ(1u, writer_->frame_count()); 1630 EXPECT_EQ(1u, writer_->frame_count());
1602 EXPECT_EQ(1u, writer_->stream_frames()->size()); 1631 EXPECT_EQ(1u, writer_->stream_frames()->size());
1603 EXPECT_EQ(1u, (*writer_->stream_frames())[0].stream_id); 1632 EXPECT_EQ(1u, (*writer_->stream_frames())[0].stream_id);
1604 } 1633 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1636 connection_.OnCanWrite(); 1665 connection_.OnCanWrite();
1637 // Parse the last packet and ensure it's the two stream frames from 1666 // Parse the last packet and ensure it's the two stream frames from
1638 // two different streams. 1667 // two different streams.
1639 EXPECT_EQ(2u, writer_->frame_count()); 1668 EXPECT_EQ(2u, writer_->frame_count());
1640 EXPECT_EQ(2u, writer_->stream_frames()->size()); 1669 EXPECT_EQ(2u, writer_->stream_frames()->size());
1641 EXPECT_EQ(kStreamId3, (*writer_->stream_frames())[0].stream_id); 1670 EXPECT_EQ(kStreamId3, (*writer_->stream_frames())[0].stream_id);
1642 EXPECT_EQ(kStreamId5, (*writer_->stream_frames())[1].stream_id); 1671 EXPECT_EQ(kStreamId5, (*writer_->stream_frames())[1].stream_id);
1643 } 1672 }
1644 1673
1645 TEST_F(QuicConnectionTest, RetransmitOnNack) { 1674 TEST_F(QuicConnectionTest, RetransmitOnNack) {
1646 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(2); 1675 EXPECT_CALL(*send_algorithm_, UpdateRtt(_));
1676 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _));
1647 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(1); 1677 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(1);
1648 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(2, _)).Times(1); 1678 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(2, _)).Times(1);
1649 QuicPacketSequenceNumber last_packet; 1679 QuicPacketSequenceNumber last_packet;
1650 QuicByteCount second_packet_size; 1680 QuicByteCount second_packet_size;
1651 SendStreamDataToPeer(3, "foo", 0, !kFin, &last_packet); // Packet 1 1681 SendStreamDataToPeer(3, "foo", 0, !kFin, &last_packet); // Packet 1
1652 second_packet_size = 1682 second_packet_size =
1653 SendStreamDataToPeer(3, "foos", 3, !kFin, &last_packet); // Packet 2 1683 SendStreamDataToPeer(3, "foos", 3, !kFin, &last_packet); // Packet 2
1654 SendStreamDataToPeer(3, "fooos", 7, !kFin, &last_packet); // Packet 3 1684 SendStreamDataToPeer(3, "fooos", 7, !kFin, &last_packet); // Packet 3
1655 1685
1656 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1686 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1657 1687
1658 // Peer acks one but not two or three. Right now we only retransmit on 1688 // Peer acks one but not two or three. Right now we only retransmit on
1659 // explicit nack, so it should not trigger a retransmission. 1689 // explicit nack, so it should not trigger a retransmission.
1660 QuicAckFrame ack_one = InitAckFrame(1, 0); 1690 QuicAckFrame ack_one = InitAckFrame(1, 0);
1661 ProcessAckPacket(&ack_one); 1691 ProcessAckPacket(&ack_one);
1662 ProcessAckPacket(&ack_one); 1692 ProcessAckPacket(&ack_one);
1663 ProcessAckPacket(&ack_one); 1693 ProcessAckPacket(&ack_one);
1664 1694
1665 // Peer acks up to 3 with two explicitly missing. 1695 // Peer acks up to 3 with two explicitly missing.
1666 // Early retransmit causes 2 to be retransmitted on the first ack. 1696 // Early retransmit causes 2 to be retransmitted on the first ack.
1667 QuicAckFrame nack_two = InitAckFrame(3, 0); 1697 QuicAckFrame nack_two = InitAckFrame(3, 0);
1668 NackPacket(2, &nack_two); 1698 NackPacket(2, &nack_two);
1669 // The third nack should trigger a retransmission. 1699 // The third nack should trigger a retransmission.
1700 EXPECT_CALL(*send_algorithm_, UpdateRtt(_));
1701 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _));
1670 EXPECT_CALL(*send_algorithm_, 1702 EXPECT_CALL(*send_algorithm_,
1671 OnPacketSent(_, _, second_packet_size - kQuicVersionSize, 1703 OnPacketSent(_, _, second_packet_size - kQuicVersionSize,
1672 NACK_RETRANSMISSION, _)).Times(1); 1704 NACK_RETRANSMISSION, _)).Times(1);
1673 ProcessAckPacket(&nack_two); 1705 ProcessAckPacket(&nack_two);
1674 } 1706 }
1675 1707
1676 TEST_F(QuicConnectionTest, DiscardRetransmit) { 1708 TEST_F(QuicConnectionTest, DiscardRetransmit) {
1677 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(2); 1709 EXPECT_CALL(*send_algorithm_, UpdateRtt(_));
1710 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _));
1678 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(1); 1711 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(1);
1679 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(2, _)).Times(1); 1712 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(2, _)).Times(1);
1680 QuicPacketSequenceNumber last_packet; 1713 QuicPacketSequenceNumber last_packet;
1681 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 1714 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1
1682 SendStreamDataToPeer(1, "foos", 3, !kFin, &last_packet); // Packet 2 1715 SendStreamDataToPeer(1, "foos", 3, !kFin, &last_packet); // Packet 2
1683 SendStreamDataToPeer(1, "fooos", 7, !kFin, &last_packet); // Packet 3 1716 SendStreamDataToPeer(1, "fooos", 7, !kFin, &last_packet); // Packet 3
1684 1717
1685 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1718 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1686 1719
1687 // Peer acks one but not two or three. Right now we only retransmit on 1720 // Peer acks one but not two or three. Right now we only retransmit on
1688 // explicit nack, so it should not trigger a retransmission. 1721 // explicit nack, so it should not trigger a retransmission.
1689 QuicAckFrame ack_one = InitAckFrame(1, 0); 1722 QuicAckFrame ack_one = InitAckFrame(1, 0);
1690 ProcessAckPacket(&ack_one); 1723 ProcessAckPacket(&ack_one);
1691 ProcessAckPacket(&ack_one); 1724 ProcessAckPacket(&ack_one);
1692 ProcessAckPacket(&ack_one); 1725 ProcessAckPacket(&ack_one);
1693 1726
1694 // Peer acks up to 3 with two explicitly missing. Two nacks should cause no 1727 // Peer acks up to 3 with two explicitly missing. Two nacks should cause no
1695 // change. 1728 // change.
1696 QuicAckFrame nack_two = InitAckFrame(3, 0); 1729 QuicAckFrame nack_two = InitAckFrame(3, 0);
1697 NackPacket(2, &nack_two); 1730 NackPacket(2, &nack_two);
1698 // The first nack should trigger a fast retransmission, but we'll be 1731 // The first nack should trigger a fast retransmission, but we'll be
1699 // write blocked, so the packet will be queued. 1732 // write blocked, so the packet will be queued.
1700 writer_->SetWriteBlocked(); 1733 writer_->BlockNextWrite();
1734 EXPECT_CALL(*send_algorithm_, UpdateRtt(_));
1735 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _));
1701 1736
1702 ProcessAckPacket(&nack_two); 1737 ProcessAckPacket(&nack_two);
1703 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 1738 EXPECT_EQ(1u, connection_.NumQueuedPackets());
1704 1739
1705 // Now, ack the previous transmission. 1740 // Now, ack the previous transmission.
1706 QuicAckFrame ack_all = InitAckFrame(3, 0); 1741 QuicAckFrame ack_all = InitAckFrame(3, 0);
1707 ProcessAckPacket(&ack_all); 1742 ProcessAckPacket(&ack_all);
1708 1743
1709 // Unblock the socket and attempt to send the queued packets. However, 1744 // Unblock the socket and attempt to send the queued packets. However,
1710 // since the previous transmission has been acked, we will not 1745 // since the previous transmission has been acked, we will not
(...skipping 13 matching lines...) Expand all
1724 QuicPacketSequenceNumber largest_observed; 1759 QuicPacketSequenceNumber largest_observed;
1725 QuicByteCount packet_size; 1760 QuicByteCount packet_size;
1726 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)) 1761 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _))
1727 .WillOnce(DoAll(SaveArg<1>(&largest_observed), SaveArg<2>(&packet_size), 1762 .WillOnce(DoAll(SaveArg<1>(&largest_observed), SaveArg<2>(&packet_size),
1728 Return(true))); 1763 Return(true)));
1729 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(1, _)).Times(1); 1764 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(1, _)).Times(1);
1730 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); 1765 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL);
1731 QuicAckFrame frame = InitAckFrame(1, largest_observed); 1766 QuicAckFrame frame = InitAckFrame(1, largest_observed);
1732 NackPacket(largest_observed, &frame); 1767 NackPacket(largest_observed, &frame);
1733 // The first nack should retransmit the largest observed packet. 1768 // The first nack should retransmit the largest observed packet.
1769 EXPECT_CALL(*send_algorithm_, UpdateRtt(_));
1734 EXPECT_CALL(*send_algorithm_, 1770 EXPECT_CALL(*send_algorithm_,
1735 OnPacketSent(_, _, packet_size - kQuicVersionSize, 1771 OnPacketSent(_, _, packet_size - kQuicVersionSize,
1736 NACK_RETRANSMISSION, _)); 1772 NACK_RETRANSMISSION, _));
1737 ProcessAckPacket(&frame); 1773 ProcessAckPacket(&frame);
1738 } 1774 }
1739 1775
1740 TEST_F(QuicConnectionTest, QueueAfterTwoRTOs) { 1776 TEST_F(QuicConnectionTest, QueueAfterTwoRTOs) {
1741 for (int i = 0; i < 10; ++i) { 1777 for (int i = 0; i < 10; ++i) {
1742 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 1778 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
1743 connection_.SendStreamDataWithString(3, "foo", i * 3, !kFin, NULL); 1779 connection_.SendStreamDataWithString(3, "foo", i * 3, !kFin, NULL);
1744 } 1780 }
1745 1781
1746 // Block the congestion window and ensure they're queued. 1782 // Block the congestion window and ensure they're queued.
1747 writer_->SetWriteBlocked(); 1783 writer_->BlockNextWrite();
1748 clock_.AdvanceTime(DefaultRetransmissionTime()); 1784 clock_.AdvanceTime(DefaultRetransmissionTime());
1749 // Only one packet should be retransmitted. 1785 // Only one packet should be retransmitted.
1750 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 1786 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
1751 connection_.GetRetransmissionAlarm()->Fire(); 1787 connection_.GetRetransmissionAlarm()->Fire();
1752 EXPECT_TRUE(connection_.HasQueuedData()); 1788 EXPECT_TRUE(connection_.HasQueuedData());
1753 1789
1754 // Unblock the congestion window. 1790 // Unblock the congestion window.
1755 writer_->SetWritable(); 1791 writer_->SetWritable();
1756 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds( 1792 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(
1757 2 * DefaultRetransmissionTime().ToMicroseconds())); 1793 2 * DefaultRetransmissionTime().ToMicroseconds()));
1758 // Retransmit already retransmitted packets event though the sequence number 1794 // Retransmit already retransmitted packets event though the sequence number
1759 // greater than the largest observed. 1795 // greater than the largest observed.
1760 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(10); 1796 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(10);
1761 connection_.GetRetransmissionAlarm()->Fire(); 1797 connection_.GetRetransmissionAlarm()->Fire();
1762 connection_.OnCanWrite(); 1798 connection_.OnCanWrite();
1763 } 1799 }
1764 1800
1765 TEST_F(QuicConnectionTest, WriteBlockedThenSent) { 1801 TEST_F(QuicConnectionTest, WriteBlockedThenSent) {
1766 writer_->SetWriteBlocked(); 1802 writer_->BlockNextWrite();
1803 writer_->set_is_write_blocked_data_buffered(true);
1767 1804
1768 writer_->set_is_write_blocked_data_buffered(true);
1769 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); 1805 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL);
1770 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 1806 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
1771 1807
1772 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 1808 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
1773 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0)); 1809 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0));
1774 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 1810 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
1775 } 1811 }
1776 1812
1777 TEST_F(QuicConnectionTest, ResumptionAlarmThenWriteBlocked) { 1813 TEST_F(QuicConnectionTest, WriteBlockedAckedThenSent) {
1778 // Set the send and resumption alarm, then block the connection. 1814 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1815 writer_->BlockNextWrite();
1816
1817 writer_->set_is_write_blocked_data_buffered(true);
1818 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL);
1819 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
1820
1821 // Ack the sent packet before the callback returns, which happens in
1822 // rare circumstances with write blocked sockets.
1823 QuicAckFrame ack = InitAckFrame(1, 0);
1824 ProcessAckPacket(&ack);
1825
1826 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0);
1827 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0));
1828 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
1829 }
1830
1831 TEST_F(QuicConnectionTest, RetransmitWriteBlockedAckedOriginalThenSent) {
1832 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1833 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL);
1834 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
1835
1836 writer_->BlockNextWrite();
1837 writer_->set_is_write_blocked_data_buffered(true);
1838
1839 // Simulate the retransmission alarm firing.
1840 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(1, _));
1841 clock_.AdvanceTime(DefaultRetransmissionTime());
1842 connection_.GetRetransmissionAlarm()->Fire();
1843
1844 // Ack the sent packet before the callback returns, which happens in
1845 // rare circumstances with write blocked sockets.
1846 EXPECT_CALL(*send_algorithm_, UpdateRtt(_));
1847 QuicAckFrame ack = InitAckFrame(1, 0);
1848 ProcessAckPacket(&ack);
1849
1850 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0));
1851 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
1852 }
1853
1854 TEST_F(QuicConnectionTest, ResumptionAlarmWhenWriteBlocked) {
1855 // Block the connection.
1856 writer_->BlockNextWrite();
1857 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL);
1858 EXPECT_EQ(1u, writer_->packets_write_attempts());
1859 EXPECT_TRUE(writer_->IsWriteBlocked());
1860
1861 // Set the send and resumption alarms. Fire the alarms and ensure they don't
1862 // attempt to write.
1779 connection_.GetResumeWritesAlarm()->Set(clock_.ApproximateNow()); 1863 connection_.GetResumeWritesAlarm()->Set(clock_.ApproximateNow());
1780 connection_.GetSendAlarm()->Set(clock_.ApproximateNow()); 1864 connection_.GetSendAlarm()->Set(clock_.ApproximateNow());
1781 QuicConnectionPeer::SetIsWriteBlocked(&connection_, true);
1782
1783 // Fire the alarms and ensure the connection is still write blocked.
1784 connection_.GetResumeWritesAlarm()->Fire(); 1865 connection_.GetResumeWritesAlarm()->Fire();
1785 connection_.GetSendAlarm()->Fire(); 1866 connection_.GetSendAlarm()->Fire();
1786 EXPECT_TRUE(QuicConnectionPeer::IsWriteBlocked(&connection_)); 1867 EXPECT_TRUE(writer_->IsWriteBlocked());
1868 EXPECT_EQ(1u, writer_->packets_write_attempts());
1787 } 1869 }
1788 1870
1789 TEST_F(QuicConnectionTest, LimitPacketsPerNack) { 1871 TEST_F(QuicConnectionTest, LimitPacketsPerNack) {
1790 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1872 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1791 EXPECT_CALL(*send_algorithm_, OnPacketAcked(15, _, _)).Times(1); 1873 EXPECT_CALL(*send_algorithm_, UpdateRtt(_));
1874 EXPECT_CALL(*send_algorithm_, OnPacketAcked(15, _)).Times(1);
1792 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(4); 1875 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(4);
1793 int offset = 0; 1876 int offset = 0;
1794 // Send packets 1 to 15. 1877 // Send packets 1 to 15.
1795 for (int i = 0; i < 15; ++i) { 1878 for (int i = 0; i < 15; ++i) {
1796 SendStreamDataToPeer(1, "foo", offset, !kFin, NULL); 1879 SendStreamDataToPeer(1, "foo", offset, !kFin, NULL);
1797 offset += 3; 1880 offset += 3;
1798 } 1881 }
1799 1882
1800 // Ack 15, nack 1-14. 1883 // Ack 15, nack 1-14.
1801 QuicAckFrame nack = InitAckFrame(15, 0); 1884 QuicAckFrame nack = InitAckFrame(15, 0);
1802 for (int i = 1; i < 15; ++i) { 1885 for (int i = 1; i < 15; ++i) {
1803 NackPacket(i, &nack); 1886 NackPacket(i, &nack);
1804 } 1887 }
1805 1888
1806 // 13 packets have been NACK'd 3 times, but we limit retransmissions to 2. 1889 // 13 packets have been NACK'd 3 times, but we limit retransmissions to 2.
1807 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(2); 1890 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(2);
1808 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); 1891 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
1809 ProcessAckPacket(&nack); 1892 ProcessAckPacket(&nack);
1810 1893
1811 // The next call should trigger retransmitting 2 more packets. 1894 // The next call should trigger retransmitting 2 more packets.
1812 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(2); 1895 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(2);
1813 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); 1896 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
1814 ProcessAckPacket(&nack); 1897 ProcessAckPacket(&nack);
1815 } 1898 }
1816 1899
1817 // Test sending multiple acks from the connection to the session. 1900 // Test sending multiple acks from the connection to the session.
1818 TEST_F(QuicConnectionTest, MultipleAcks) { 1901 TEST_F(QuicConnectionTest, MultipleAcks) {
1819 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(6);
1820 QuicPacketSequenceNumber last_packet; 1902 QuicPacketSequenceNumber last_packet;
1821 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 1903 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1
1822 EXPECT_EQ(1u, last_packet); 1904 EXPECT_EQ(1u, last_packet);
1823 SendStreamDataToPeer(3, "foo", 0, !kFin, &last_packet); // Packet 2 1905 SendStreamDataToPeer(3, "foo", 0, !kFin, &last_packet); // Packet 2
1824 EXPECT_EQ(2u, last_packet); 1906 EXPECT_EQ(2u, last_packet);
1825 SendAckPacketToPeer(); // Packet 3 1907 SendAckPacketToPeer(); // Packet 3
1826 SendStreamDataToPeer(5, "foo", 0, !kFin, &last_packet); // Packet 4 1908 SendStreamDataToPeer(5, "foo", 0, !kFin, &last_packet); // Packet 4
1827 EXPECT_EQ(4u, last_packet); 1909 EXPECT_EQ(4u, last_packet);
1828 SendStreamDataToPeer(1, "foo", 3, !kFin, &last_packet); // Packet 5 1910 SendStreamDataToPeer(1, "foo", 3, !kFin, &last_packet); // Packet 5
1829 EXPECT_EQ(5u, last_packet); 1911 EXPECT_EQ(5u, last_packet);
1830 SendStreamDataToPeer(3, "foo", 3, !kFin, &last_packet); // Packet 6 1912 SendStreamDataToPeer(3, "foo", 3, !kFin, &last_packet); // Packet 6
1831 EXPECT_EQ(6u, last_packet); 1913 EXPECT_EQ(6u, last_packet);
1832 1914
1833 // Client will ack packets 1, 2, [!3], 4, 5. 1915 // Client will ack packets 1, 2, [!3], 4, 5.
1916 EXPECT_CALL(*send_algorithm_, UpdateRtt(_));
1917 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(4);
1834 QuicAckFrame frame1 = InitAckFrame(5, 0); 1918 QuicAckFrame frame1 = InitAckFrame(5, 0);
1835 NackPacket(3, &frame1); 1919 NackPacket(3, &frame1);
1836 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1920 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1837 ProcessAckPacket(&frame1); 1921 ProcessAckPacket(&frame1);
1838 1922
1839 // Now the client implicitly acks 3, and explicitly acks 6. 1923 // Now the client implicitly acks 3, and explicitly acks 6.
1924 EXPECT_CALL(*send_algorithm_, UpdateRtt(_));
1925 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(2);
1840 QuicAckFrame frame2 = InitAckFrame(6, 0); 1926 QuicAckFrame frame2 = InitAckFrame(6, 0);
1841 ProcessAckPacket(&frame2); 1927 ProcessAckPacket(&frame2);
1842 } 1928 }
1843 1929
1844 TEST_F(QuicConnectionTest, DontLatchUnackedPacket) { 1930 TEST_F(QuicConnectionTest, DontLatchUnackedPacket) {
1845 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(1); 1931 EXPECT_CALL(*send_algorithm_, UpdateRtt(_));
1932 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(1);
1846 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); // Packet 1; 1933 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); // Packet 1;
1847 // From now on, we send acks, so the send algorithm won't save them. 1934 // From now on, we send acks, so the send algorithm won't save them.
1848 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 1935 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
1849 .WillByDefault(Return(false)); 1936 .WillByDefault(Return(false));
1850 SendAckPacketToPeer(); // Packet 2 1937 SendAckPacketToPeer(); // Packet 2
1851 1938
1852 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1939 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1853 QuicAckFrame frame = InitAckFrame(1, 0); 1940 QuicAckFrame frame = InitAckFrame(1, 0);
1854 ProcessAckPacket(&frame); 1941 ProcessAckPacket(&frame);
1855 1942
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
2138 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, RTO_RETRANSMISSION, _)) 2225 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, RTO_RETRANSMISSION, _))
2139 .WillOnce(DoAll(SaveArg<1>(&rto_sequence_number), Return(true))); 2226 .WillOnce(DoAll(SaveArg<1>(&rto_sequence_number), Return(true)));
2140 connection_.GetRetransmissionAlarm()->Fire(); 2227 connection_.GetRetransmissionAlarm()->Fire();
2141 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission( 2228 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission(
2142 &connection_, original_sequence_number)); 2229 &connection_, original_sequence_number));
2143 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission( 2230 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission(
2144 &connection_, rto_sequence_number)); 2231 &connection_, rto_sequence_number));
2145 EXPECT_TRUE(QuicConnectionPeer::IsRetransmission( 2232 EXPECT_TRUE(QuicConnectionPeer::IsRetransmission(
2146 &connection_, rto_sequence_number)); 2233 &connection_, rto_sequence_number));
2147 // Once by explicit nack. 2234 // Once by explicit nack.
2235 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)).Times(3);
2148 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(1); 2236 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(1);
2149 EXPECT_CALL(*send_algorithm_, 2237 EXPECT_CALL(*send_algorithm_,
2150 OnPacketAbandoned(rto_sequence_number, _)).Times(1); 2238 OnPacketAbandoned(rto_sequence_number, _)).Times(1);
2151 QuicPacketSequenceNumber nack_sequence_number = 0; 2239 QuicPacketSequenceNumber nack_sequence_number = 0;
2152 // Ack packets might generate some other packets, which are not 2240 // Ack packets might generate some other packets, which are not
2153 // retransmissions. (More ack packets). 2241 // retransmissions. (More ack packets).
2154 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)) 2242 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _))
2155 .Times(AnyNumber()); 2243 .Times(AnyNumber());
2156 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NACK_RETRANSMISSION, _)) 2244 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NACK_RETRANSMISSION, _))
2157 .WillOnce(DoAll(SaveArg<1>(&nack_sequence_number), Return(true))); 2245 .WillOnce(DoAll(SaveArg<1>(&nack_sequence_number), Return(true)));
2158 QuicAckFrame ack = InitAckFrame(rto_sequence_number, 0); 2246 QuicAckFrame ack = InitAckFrame(rto_sequence_number, 0);
2159 // Ack the retransmitted packet. 2247 // Ack the retransmitted packet.
2160 NackPacket(original_sequence_number, &ack); 2248 NackPacket(original_sequence_number, &ack);
2161 NackPacket(rto_sequence_number, &ack); 2249 NackPacket(rto_sequence_number, &ack);
2162 for (int i = 0; i < 3; i++) { 2250 for (int i = 0; i < 3; i++) {
2163 ProcessAckPacket(&ack); 2251 ProcessAckPacket(&ack);
2164 } 2252 }
2165 ASSERT_NE(0u, nack_sequence_number); 2253 ASSERT_NE(0u, nack_sequence_number);
2166 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission( 2254 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission(
2167 &connection_, rto_sequence_number)); 2255 &connection_, rto_sequence_number));
2168 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission( 2256 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission(
2169 &connection_, nack_sequence_number)); 2257 &connection_, nack_sequence_number));
2170 EXPECT_TRUE(QuicConnectionPeer::IsRetransmission( 2258 EXPECT_TRUE(QuicConnectionPeer::IsRetransmission(
2171 &connection_, nack_sequence_number)); 2259 &connection_, nack_sequence_number));
2172 } 2260 }
2173 2261
2174 TEST_F(QuicConnectionTest, SetRTOAfterWritingToSocket) { 2262 TEST_F(QuicConnectionTest, SetRTOAfterWritingToSocket) {
2175 writer_->SetWriteBlocked(); 2263 writer_->BlockNextWrite();
2176 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); 2264 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL);
2177 // Make sure that RTO is not started when the packet is queued. 2265 // Make sure that RTO is not started when the packet is queued.
2178 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 2266 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2179 2267
2180 // Test that RTO is started once we write to the socket. 2268 // Test that RTO is started once we write to the socket.
2181 writer_->SetWritable(); 2269 writer_->SetWritable();
2182 connection_.OnCanWrite(); 2270 connection_.OnCanWrite();
2183 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 2271 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
2184 } 2272 }
2185 2273
2186 TEST_F(QuicConnectionTest, DelayRTOWithAckReceipt) { 2274 TEST_F(QuicConnectionTest, DelayRTOWithAckReceipt) {
2187 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2275 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2188 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)) 2276 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _))
2189 .Times(2); 2277 .Times(2);
2190 connection_.SendStreamDataWithString(2, "foo", 0, !kFin, NULL); 2278 connection_.SendStreamDataWithString(2, "foo", 0, !kFin, NULL);
2191 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, NULL); 2279 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, NULL);
2192 QuicAlarm* retransmission_alarm = connection_.GetRetransmissionAlarm(); 2280 QuicAlarm* retransmission_alarm = connection_.GetRetransmissionAlarm();
2193 EXPECT_TRUE(retransmission_alarm->IsSet()); 2281 EXPECT_TRUE(retransmission_alarm->IsSet());
2194 2282
2195 // Advance the time right before the RTO, then receive an ack for the first 2283 // Advance the time right before the RTO, then receive an ack for the first
2196 // packet to delay the RTO. 2284 // packet to delay the RTO.
2197 clock_.AdvanceTime(DefaultRetransmissionTime()); 2285 clock_.AdvanceTime(DefaultRetransmissionTime());
2198 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(1); 2286 EXPECT_CALL(*send_algorithm_, UpdateRtt(_));
2287 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(1);
2199 QuicAckFrame ack = InitAckFrame(1, 0); 2288 QuicAckFrame ack = InitAckFrame(1, 0);
2200 ProcessAckPacket(&ack); 2289 ProcessAckPacket(&ack);
2201 EXPECT_TRUE(retransmission_alarm->IsSet()); 2290 EXPECT_TRUE(retransmission_alarm->IsSet());
2202 2291
2203 // Move forward past the original RTO and ensure the RTO is still pending. 2292 // Move forward past the original RTO and ensure the RTO is still pending.
2204 clock_.AdvanceTime(DefaultRetransmissionTime()); 2293 clock_.AdvanceTime(DefaultRetransmissionTime());
2205 2294
2206 // Ensure the second packet gets retransmitted when it finally fires. 2295 // Ensure the second packet gets retransmitted when it finally fires.
2207 EXPECT_TRUE(retransmission_alarm->IsSet()); 2296 EXPECT_TRUE(retransmission_alarm->IsSet());
2208 EXPECT_LT(retransmission_alarm->deadline(), clock_.ApproximateNow()); 2297 EXPECT_LT(retransmission_alarm->deadline(), clock_.ApproximateNow());
2209 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 2298 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
2210 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, RTO_RETRANSMISSION, _)); 2299 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, RTO_RETRANSMISSION, _));
2211 // Manually cancel the alarm to simulate a real test. 2300 // Manually cancel the alarm to simulate a real test.
2212 connection_.GetRetransmissionAlarm()->Fire(); 2301 connection_.GetRetransmissionAlarm()->Fire();
2213 2302
2214 // The new retransmitted sequence number should set the RTO to a larger value 2303 // The new retransmitted sequence number should set the RTO to a larger value
2215 // than previously. 2304 // than previously.
2216 EXPECT_TRUE(retransmission_alarm->IsSet()); 2305 EXPECT_TRUE(retransmission_alarm->IsSet());
2217 QuicTime next_rto_time = retransmission_alarm->deadline(); 2306 QuicTime next_rto_time = retransmission_alarm->deadline();
2218 QuicTime expected_rto_time = 2307 QuicTime expected_rto_time =
2219 connection_.sent_packet_manager().GetRetransmissionTime(); 2308 connection_.sent_packet_manager().GetRetransmissionTime();
2220 EXPECT_EQ(next_rto_time, expected_rto_time); 2309 EXPECT_EQ(next_rto_time, expected_rto_time);
2221 } 2310 }
2222 2311
2223 TEST_F(QuicConnectionTest, TestQueued) { 2312 TEST_F(QuicConnectionTest, TestQueued) {
2224 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2313 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2225 writer_->SetWriteBlocked(); 2314 writer_->BlockNextWrite();
2226 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); 2315 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL);
2227 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2316 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2228 2317
2229 // Attempt to send all packets, but since we're actually still
2230 // blocked, they should all remain queued.
2231 EXPECT_FALSE(connection_.OnCanWrite());
2232 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2233
2234 // Unblock the writes and actually send. 2318 // Unblock the writes and actually send.
2235 writer_->SetWritable(); 2319 writer_->SetWritable();
2236 EXPECT_TRUE(connection_.OnCanWrite()); 2320 EXPECT_TRUE(connection_.OnCanWrite());
2237 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2321 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2238 } 2322 }
2239 2323
2240 TEST_F(QuicConnectionTest, CloseFecGroup) { 2324 TEST_F(QuicConnectionTest, CloseFecGroup) {
2241 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2325 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2242 // Don't send missing packet 1. 2326 // Don't send missing packet 1.
2243 // Don't send missing packet 2. 2327 // Don't send missing packet 2.
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
2375 TimeUntilSend(_, NACK_RETRANSMISSION, _, _)).Times(0); 2459 TimeUntilSend(_, NACK_RETRANSMISSION, _, _)).Times(0);
2376 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 2460 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
2377 connection_.SendPacket( 2461 connection_.SendPacket(
2378 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); 2462 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA);
2379 // XXX: fixme. was: connection_.SendPacket(1, packet, kForce); 2463 // XXX: fixme. was: connection_.SendPacket(1, packet, kForce);
2380 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2464 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2381 } 2465 }
2382 2466
2383 TEST_F(QuicConnectionTest, SendSchedulerEAGAIN) { 2467 TEST_F(QuicConnectionTest, SendSchedulerEAGAIN) {
2384 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); 2468 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag);
2385 writer_->SetWriteBlocked(); 2469 writer_->BlockNextWrite();
2386 EXPECT_CALL(*send_algorithm_, 2470 EXPECT_CALL(*send_algorithm_,
2387 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( 2471 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce(
2388 testing::Return(QuicTime::Delta::Zero())); 2472 testing::Return(QuicTime::Delta::Zero()));
2389 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 1, _, _, _)).Times(0); 2473 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 1, _, _, _)).Times(0);
2390 connection_.SendPacket( 2474 connection_.SendPacket(
2391 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); 2475 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA);
2392 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2476 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2393 } 2477 }
2394 2478
2395 TEST_F(QuicConnectionTest, SendSchedulerDelayThenSend) { 2479 TEST_F(QuicConnectionTest, SendSchedulerDelayThenSend) {
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
2626 connection_.SendStreamDataWithString(kCryptoStreamId, "foo", 0, !kFin, NULL); 2710 connection_.SendStreamDataWithString(kCryptoStreamId, "foo", 0, !kFin, NULL);
2627 // Check that ack is not bundled with outgoing data. 2711 // Check that ack is not bundled with outgoing data.
2628 EXPECT_EQ(1u, writer_->frame_count()); 2712 EXPECT_EQ(1u, writer_->frame_count());
2629 EXPECT_FALSE(writer_->ack()); 2713 EXPECT_FALSE(writer_->ack());
2630 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); 2714 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
2631 } 2715 }
2632 2716
2633 TEST_F(QuicConnectionTest, NoAckForClose) { 2717 TEST_F(QuicConnectionTest, NoAckForClose) {
2634 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2718 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2635 ProcessPacket(1); 2719 ProcessPacket(1);
2636 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(0); 2720 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(0);
2637 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PEER_GOING_AWAY, true)); 2721 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PEER_GOING_AWAY, true));
2638 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); 2722 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0);
2639 ProcessClosePacket(2, 0); 2723 ProcessClosePacket(2, 0);
2640 } 2724 }
2641 2725
2642 TEST_F(QuicConnectionTest, SendWhenDisconnected) { 2726 TEST_F(QuicConnectionTest, SendWhenDisconnected) {
2643 EXPECT_TRUE(connection_.connected()); 2727 EXPECT_TRUE(connection_.connected());
2644 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PEER_GOING_AWAY, false)); 2728 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PEER_GOING_AWAY, false));
2645 connection_.CloseConnection(QUIC_PEER_GOING_AWAY, false); 2729 connection_.CloseConnection(QUIC_PEER_GOING_AWAY, false);
2646 EXPECT_FALSE(connection_.connected()); 2730 EXPECT_FALSE(connection_.connected());
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
2850 QuicFrames frames; 2934 QuicFrames frames;
2851 QuicFrame frame(&frame1_); 2935 QuicFrame frame(&frame1_);
2852 frames.push_back(frame); 2936 frames.push_back(frame);
2853 scoped_ptr<QuicPacket> packet( 2937 scoped_ptr<QuicPacket> packet(
2854 framer_.BuildUnsizedDataPacket(header, frames).packet); 2938 framer_.BuildUnsizedDataPacket(header, frames).packet);
2855 scoped_ptr<QuicEncryptedPacket> encrypted( 2939 scoped_ptr<QuicEncryptedPacket> encrypted(
2856 framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); 2940 framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet));
2857 2941
2858 framer_.set_version(QuicVersionMax()); 2942 framer_.set_version(QuicVersionMax());
2859 connection_.set_is_server(true); 2943 connection_.set_is_server(true);
2860 writer_->SetWriteBlocked(); 2944 writer_->BlockNextWrite();
2861 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); 2945 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted);
2862 EXPECT_EQ(0u, writer_->last_packet_size()); 2946 EXPECT_EQ(0u, writer_->last_packet_size());
2863 EXPECT_TRUE(connection_.HasQueuedData()); 2947 EXPECT_TRUE(connection_.HasQueuedData());
2864 EXPECT_TRUE(QuicConnectionPeer::IsWriteBlocked(&connection_));
2865 2948
2866 writer_->SetWritable(); 2949 writer_->SetWritable();
2867 connection_.OnCanWrite(); 2950 connection_.OnCanWrite();
2868 EXPECT_TRUE(writer_->version_negotiation_packet() != NULL); 2951 EXPECT_TRUE(writer_->version_negotiation_packet() != NULL);
2869 2952
2870 size_t num_versions = arraysize(kSupportedQuicVersions); 2953 size_t num_versions = arraysize(kSupportedQuicVersions);
2871 EXPECT_EQ(num_versions, 2954 EXPECT_EQ(num_versions,
2872 writer_->version_negotiation_packet()->versions.size()); 2955 writer_->version_negotiation_packet()->versions.size());
2873 2956
2874 // We expect all versions in kSupportedQuicVersions to be 2957 // We expect all versions in kSupportedQuicVersions to be
(...skipping 20 matching lines...) Expand all
2895 QuicFrames frames; 2978 QuicFrames frames;
2896 QuicFrame frame(&frame1_); 2979 QuicFrame frame(&frame1_);
2897 frames.push_back(frame); 2980 frames.push_back(frame);
2898 scoped_ptr<QuicPacket> packet( 2981 scoped_ptr<QuicPacket> packet(
2899 framer_.BuildUnsizedDataPacket(header, frames).packet); 2982 framer_.BuildUnsizedDataPacket(header, frames).packet);
2900 scoped_ptr<QuicEncryptedPacket> encrypted( 2983 scoped_ptr<QuicEncryptedPacket> encrypted(
2901 framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); 2984 framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet));
2902 2985
2903 framer_.set_version(QuicVersionMax()); 2986 framer_.set_version(QuicVersionMax());
2904 connection_.set_is_server(true); 2987 connection_.set_is_server(true);
2905 writer_->SetWriteBlocked(); 2988 writer_->BlockNextWrite();
2906 writer_->set_is_write_blocked_data_buffered(true); 2989 writer_->set_is_write_blocked_data_buffered(true);
2907 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); 2990 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted);
2908 EXPECT_EQ(0u, writer_->last_packet_size()); 2991 EXPECT_EQ(0u, writer_->last_packet_size());
2909 EXPECT_FALSE(connection_.HasQueuedData()); 2992 EXPECT_FALSE(connection_.HasQueuedData());
2910 EXPECT_TRUE(QuicConnectionPeer::IsWriteBlocked(&connection_));
2911 } 2993 }
2912 2994
2913 TEST_F(QuicConnectionTest, ClientHandlesVersionNegotiation) { 2995 TEST_F(QuicConnectionTest, ClientHandlesVersionNegotiation) {
2914 // Start out with some unsupported version. 2996 // Start out with some unsupported version.
2915 QuicConnectionPeer::GetFramer(&connection_)->set_version_for_tests( 2997 QuicConnectionPeer::GetFramer(&connection_)->set_version_for_tests(
2916 QUIC_VERSION_UNSUPPORTED); 2998 QUIC_VERSION_UNSUPPORTED);
2917 2999
2918 QuicPacketHeader header; 3000 QuicPacketHeader header;
2919 header.public_header.guid = guid_; 3001 header.public_header.guid = guid_;
2920 header.public_header.reset_flag = false; 3002 header.public_header.reset_flag = false;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
3000 3082
3001 // Retransmit due to RTO. 3083 // Retransmit due to RTO.
3002 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10)); 3084 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10));
3003 connection_.GetRetransmissionAlarm()->Fire(); 3085 connection_.GetRetransmissionAlarm()->Fire();
3004 3086
3005 // Retransmit due to explicit nacks. 3087 // Retransmit due to explicit nacks.
3006 QuicAckFrame nack_three = InitAckFrame(4, 0); 3088 QuicAckFrame nack_three = InitAckFrame(4, 0);
3007 NackPacket(3, &nack_three); 3089 NackPacket(3, &nack_three);
3008 NackPacket(1, &nack_three); 3090 NackPacket(1, &nack_three);
3009 QuicFrame frame(&nack_three); 3091 QuicFrame frame(&nack_three);
3010 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(1); 3092 EXPECT_CALL(*send_algorithm_, UpdateRtt(_));
3093 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(1);
3011 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(1); 3094 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(1);
3012 EXPECT_CALL(visitor_, OnCanWrite()).Times(4).WillRepeatedly(Return(true)); 3095 EXPECT_CALL(visitor_, OnCanWrite()).Times(4).WillRepeatedly(Return(true));
3013 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3096 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3014 3097
3015 ProcessFramePacket(frame); 3098 ProcessFramePacket(frame);
3016 ProcessFramePacket(frame); 3099 ProcessFramePacket(frame);
3017 ProcessFramePacket(frame); 3100 ProcessFramePacket(frame);
3018 3101
3019 EXPECT_CALL(*send_algorithm_, SmoothedRtt()).WillOnce( 3102 EXPECT_CALL(*send_algorithm_, SmoothedRtt()).WillOnce(
3020 Return(QuicTime::Delta::Zero())); 3103 Return(QuicTime::Delta::Zero()));
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
3129 lowest_version_vector.push_back(QuicVersionMin()); 3212 lowest_version_vector.push_back(QuicVersionMin());
3130 EXPECT_TRUE(connection_.SelectMutualVersion(lowest_version_vector)); 3213 EXPECT_TRUE(connection_.SelectMutualVersion(lowest_version_vector));
3131 EXPECT_EQ(QuicVersionMin(), connection_.version()); 3214 EXPECT_EQ(QuicVersionMin(), connection_.version());
3132 3215
3133 // Shouldn't be able to find a mutually supported version. 3216 // Shouldn't be able to find a mutually supported version.
3134 QuicVersionVector unsupported_version; 3217 QuicVersionVector unsupported_version;
3135 unsupported_version.push_back(QUIC_VERSION_UNSUPPORTED); 3218 unsupported_version.push_back(QUIC_VERSION_UNSUPPORTED);
3136 EXPECT_FALSE(connection_.SelectMutualVersion(unsupported_version)); 3219 EXPECT_FALSE(connection_.SelectMutualVersion(unsupported_version));
3137 } 3220 }
3138 3221
3139 TEST_F(QuicConnectionTest, ConnectionCloseWhenNotWriteBlocked) { 3222 TEST_F(QuicConnectionTest, ConnectionCloseWhenWritable) {
3140 writer_->SetWritable(); // Already default. 3223 EXPECT_FALSE(writer_->IsWriteBlocked());
3141 3224
3142 // Send a packet (but write will not block). 3225 // Send a packet.
3143 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); 3226 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL);
3144 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 3227 EXPECT_EQ(0u, connection_.NumQueuedPackets());
3145 EXPECT_EQ(1u, writer_->packets_write_attempts()); 3228 EXPECT_EQ(1u, writer_->packets_write_attempts());
3146 3229
3147 // Send an erroneous packet to close the connection. 3230 TriggerConnectionClose();
3148 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false));
3149 ProcessDataPacket(6000, 0, !kEntropyFlag);
3150 EXPECT_EQ(2u, writer_->packets_write_attempts()); 3231 EXPECT_EQ(2u, writer_->packets_write_attempts());
3151 } 3232 }
3152 3233
3234 TEST_F(QuicConnectionTest, ConnectionCloseGettingWriteBlocked) {
3235 writer_->BlockNextWrite();
3236 TriggerConnectionClose();
3237 EXPECT_EQ(1u, writer_->packets_write_attempts());
3238 EXPECT_TRUE(writer_->IsWriteBlocked());
3239 }
3240
3153 TEST_F(QuicConnectionTest, ConnectionCloseWhenWriteBlocked) { 3241 TEST_F(QuicConnectionTest, ConnectionCloseWhenWriteBlocked) {
3154 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 3242 writer_->BlockNextWrite();
3155 writer_->SetWriteBlocked();
3156
3157 // Send a packet to so that write will really block.
3158 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); 3243 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL);
3159 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 3244 EXPECT_EQ(1u, connection_.NumQueuedPackets());
3160 EXPECT_EQ(1u, writer_->packets_write_attempts()); 3245 EXPECT_EQ(1u, writer_->packets_write_attempts());
3161 3246 EXPECT_TRUE(writer_->IsWriteBlocked());
3162 // Send an erroneous packet to close the connection. 3247 TriggerConnectionClose();
3163 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false));
3164 ProcessDataPacket(6000, 0, !kEntropyFlag);
3165 EXPECT_EQ(1u, writer_->packets_write_attempts()); 3248 EXPECT_EQ(1u, writer_->packets_write_attempts());
3166 } 3249 }
3167 3250
3168 TEST_F(QuicConnectionTest, ConnectionCloseWhenNothingPending) {
3169 writer_->SetWriteBlocked();
3170
3171 // Send an erroneous packet to close the connection.
3172 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false));
3173 ProcessDataPacket(6000, 0, !kEntropyFlag);
3174 EXPECT_EQ(1u, writer_->packets_write_attempts());
3175 }
3176
3177 TEST_F(QuicConnectionTest, AckNotifierTriggerCallback) { 3251 TEST_F(QuicConnectionTest, AckNotifierTriggerCallback) {
3178 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3252 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3179 3253
3180 // Create a delegate which we expect to be called. 3254 // Create a delegate which we expect to be called.
3181 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); 3255 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate);
3182 EXPECT_CALL(*delegate, OnAckNotification()).Times(1);; 3256 EXPECT_CALL(*delegate, OnAckNotification()).Times(1);
3183 3257
3184 // Send some data, which will register the delegate to be notified. 3258 // Send some data, which will register the delegate to be notified.
3185 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); 3259 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get());
3186 3260
3187 // Process an ACK from the server which should trigger the callback. 3261 // Process an ACK from the server which should trigger the callback.
3188 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(1); 3262 EXPECT_CALL(*send_algorithm_, UpdateRtt(_));
3263 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(1);
3189 QuicAckFrame frame = InitAckFrame(1, 0); 3264 QuicAckFrame frame = InitAckFrame(1, 0);
3190 ProcessAckPacket(&frame); 3265 ProcessAckPacket(&frame);
3191 } 3266 }
3192 3267
3193 TEST_F(QuicConnectionTest, AckNotifierFailToTriggerCallback) { 3268 TEST_F(QuicConnectionTest, AckNotifierFailToTriggerCallback) {
3194 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3269 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3195 3270
3196 // Create a delegate which we don't expect to be called. 3271 // Create a delegate which we don't expect to be called.
3197 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); 3272 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate);
3198 EXPECT_CALL(*delegate, OnAckNotification()).Times(0);; 3273 EXPECT_CALL(*delegate, OnAckNotification()).Times(0);
3199 3274
3200 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(2); 3275 EXPECT_CALL(*send_algorithm_, UpdateRtt(_));
3276 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(2);
3201 3277
3202 // Send some data, which will register the delegate to be notified. This will 3278 // Send some data, which will register the delegate to be notified. This will
3203 // not be ACKed and so the delegate should never be called. 3279 // not be ACKed and so the delegate should never be called.
3204 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); 3280 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get());
3205 3281
3206 // Send some other data which we will ACK. 3282 // Send some other data which we will ACK.
3207 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); 3283 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL);
3208 connection_.SendStreamDataWithString(1, "bar", 0, !kFin, NULL); 3284 connection_.SendStreamDataWithString(1, "bar", 0, !kFin, NULL);
3209 3285
3210 // Now we receive ACK for packets 2 and 3, but importantly missing packet 1 3286 // Now we receive ACK for packets 2 and 3, but importantly missing packet 1
3211 // which we registered to be notified about. 3287 // which we registered to be notified about.
3212 QuicAckFrame frame = InitAckFrame(3, 0); 3288 QuicAckFrame frame = InitAckFrame(3, 0);
3213 NackPacket(1, &frame); 3289 NackPacket(1, &frame);
3214 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)); 3290 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _));
3215 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)); 3291 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _));
3216 ProcessAckPacket(&frame); 3292 ProcessAckPacket(&frame);
3217 } 3293 }
3218 3294
3219 TEST_F(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) { 3295 TEST_F(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) {
3220 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3296 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3221 3297
3222 // Create a delegate which we expect to be called. 3298 // Create a delegate which we expect to be called.
3223 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); 3299 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate);
3224 EXPECT_CALL(*delegate, OnAckNotification()).Times(1);; 3300 EXPECT_CALL(*delegate, OnAckNotification()).Times(1);
3225 3301
3226 // In total expect ACKs for all 4 packets. 3302 // In total expect ACKs for all 4 packets.
3227 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(4); 3303 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)).Times(2);
3304 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(4);
3228 3305
3229 // Send four packets, and register to be notified on ACK of packet 2. 3306 // Send four packets, and register to be notified on ACK of packet 2.
3230 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); 3307 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL);
3231 connection_.SendStreamDataWithString(1, "bar", 0, !kFin, delegate.get()); 3308 connection_.SendStreamDataWithString(1, "bar", 0, !kFin, delegate.get());
3232 connection_.SendStreamDataWithString(1, "baz", 0, !kFin, NULL); 3309 connection_.SendStreamDataWithString(1, "baz", 0, !kFin, NULL);
3233 connection_.SendStreamDataWithString(1, "qux", 0, !kFin, NULL); 3310 connection_.SendStreamDataWithString(1, "qux", 0, !kFin, NULL);
3234 3311
3235 // Now we receive ACK for packets 1, 3, and 4, which invokes fast retransmit. 3312 // Now we receive ACK for packets 1, 3, and 4, which invokes fast retransmit.
3236 QuicAckFrame frame = InitAckFrame(4, 0); 3313 QuicAckFrame frame = InitAckFrame(4, 0);
3237 NackPacket(2, &frame); 3314 NackPacket(2, &frame);
3238 EXPECT_CALL(*send_algorithm_, OnPacketLost(2, _)); 3315 EXPECT_CALL(*send_algorithm_, OnPacketLost(2, _));
3239 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(2, _)); 3316 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(2, _));
3240 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 3317 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
3241 ProcessAckPacket(&frame); 3318 ProcessAckPacket(&frame);
3242 3319
3243 // Now we get an ACK for packet 5 (retransmitted packet 2), which should 3320 // Now we get an ACK for packet 5 (retransmitted packet 2), which should
3244 // trigger the callback. 3321 // trigger the callback.
3245 QuicAckFrame second_ack_frame = InitAckFrame(5, 0); 3322 QuicAckFrame second_ack_frame = InitAckFrame(5, 0);
3246 ProcessAckPacket(&second_ack_frame); 3323 ProcessAckPacket(&second_ack_frame);
3247 } 3324 }
3248 3325
3249 // TODO(rjshade): Add a similar test that FEC recovery on peer (and resulting 3326 // TODO(rjshade): Add a similar test that FEC recovery on peer (and resulting
3250 // ACK) triggers notification on our end. 3327 // ACK) triggers notification on our end.
3251 TEST_F(QuicConnectionTest, AckNotifierCallbackAfterFECRecovery) { 3328 TEST_F(QuicConnectionTest, AckNotifierCallbackAfterFECRecovery) {
3252 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3329 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3253 EXPECT_CALL(visitor_, OnCanWrite()).Times(1).WillOnce(Return(true)); 3330 EXPECT_CALL(visitor_, OnCanWrite()).Times(1).WillOnce(Return(true));
3254 3331
3255 // Create a delegate which we expect to be called. 3332 // Create a delegate which we expect to be called.
3256 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); 3333 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate);
3257 EXPECT_CALL(*delegate, OnAckNotification()).Times(1);; 3334 EXPECT_CALL(*delegate, OnAckNotification()).Times(1);
3258 3335
3259 // Expect ACKs for 1 packet. 3336 // Expect ACKs for 1 packet.
3260 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(1); 3337 EXPECT_CALL(*send_algorithm_, UpdateRtt(_));
3338 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(1);
3261 3339
3262 // Send one packet, and register to be notified on ACK. 3340 // Send one packet, and register to be notified on ACK.
3263 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); 3341 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get());
3264 3342
3265 // Ack packet gets dropped, but we receive an FEC packet that covers it. 3343 // Ack packet gets dropped, but we receive an FEC packet that covers it.
3266 // Should recover the Ack packet and trigger the notification callback. 3344 // Should recover the Ack packet and trigger the notification callback.
3267 QuicFrames frames; 3345 QuicFrames frames;
3268 3346
3269 QuicAckFrame ack_frame = InitAckFrame(1, 0); 3347 QuicAckFrame ack_frame = InitAckFrame(1, 0);
3270 frames.push_back(QuicFrame(&ack_frame)); 3348 frames.push_back(QuicFrame(&ack_frame));
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
3359 true); 3437 true);
3360 TestConnection client(guid_, IPEndPoint(), helper_.get(), writer_.get(), 3438 TestConnection client(guid_, IPEndPoint(), helper_.get(), writer_.get(),
3361 false); 3439 false);
3362 EXPECT_TRUE(client.sent_packet_manager().using_pacing()); 3440 EXPECT_TRUE(client.sent_packet_manager().using_pacing());
3363 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); 3441 EXPECT_FALSE(server.sent_packet_manager().using_pacing());
3364 } 3442 }
3365 3443
3366 } // namespace 3444 } // namespace
3367 } // namespace test 3445 } // namespace test
3368 } // namespace net 3446 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection_helper.h ('k') | net/quic/quic_crypto_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698