OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/quic/quic_connection.h" | 5 #include "net/quic/quic_connection.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 60 |
61 const int kDefaultRetransmissionTimeMs = 500; | 61 const int kDefaultRetransmissionTimeMs = 500; |
62 | 62 |
63 class TestReceiveAlgorithm : public ReceiveAlgorithmInterface { | 63 class TestReceiveAlgorithm : public ReceiveAlgorithmInterface { |
64 public: | 64 public: |
65 explicit TestReceiveAlgorithm(QuicCongestionFeedbackFrame* feedback) | 65 explicit TestReceiveAlgorithm(QuicCongestionFeedbackFrame* feedback) |
66 : feedback_(feedback) { | 66 : feedback_(feedback) { |
67 } | 67 } |
68 | 68 |
69 bool GenerateCongestionFeedback( | 69 bool GenerateCongestionFeedback( |
70 QuicCongestionFeedbackFrame* congestion_feedback) { | 70 QuicCongestionFeedbackFrame* congestion_feedback) override { |
71 if (feedback_ == nullptr) { | 71 if (feedback_ == nullptr) { |
72 return false; | 72 return false; |
73 } | 73 } |
74 *congestion_feedback = *feedback_; | 74 *congestion_feedback = *feedback_; |
75 return true; | 75 return true; |
76 } | 76 } |
77 | 77 |
78 MOCK_METHOD3(RecordIncomingPacket, | 78 MOCK_METHOD3(RecordIncomingPacket, |
79 void(QuicByteCount, QuicPacketSequenceNumber, QuicTime)); | 79 void(QuicByteCount, QuicPacketSequenceNumber, QuicTime)); |
80 | 80 |
81 private: | 81 private: |
82 QuicCongestionFeedbackFrame* feedback_; | 82 QuicCongestionFeedbackFrame* feedback_; |
83 | 83 |
84 DISALLOW_COPY_AND_ASSIGN(TestReceiveAlgorithm); | 84 DISALLOW_COPY_AND_ASSIGN(TestReceiveAlgorithm); |
85 }; | 85 }; |
86 | 86 |
87 // TaggingEncrypter appends kTagSize bytes of |tag| to the end of each message. | 87 // TaggingEncrypter appends kTagSize bytes of |tag| to the end of each message. |
88 class TaggingEncrypter : public QuicEncrypter { | 88 class TaggingEncrypter : public QuicEncrypter { |
89 public: | 89 public: |
90 explicit TaggingEncrypter(uint8 tag) | 90 explicit TaggingEncrypter(uint8 tag) |
91 : tag_(tag) { | 91 : tag_(tag) { |
92 } | 92 } |
93 | 93 |
94 ~TaggingEncrypter() override {} | 94 ~TaggingEncrypter() override {} |
95 | 95 |
96 // QuicEncrypter interface. | 96 // QuicEncrypter interface. |
97 bool SetKey(StringPiece key) override { return true; } | 97 bool SetKey(StringPiece key) override { return true; } |
| 98 |
98 bool SetNoncePrefix(StringPiece nonce_prefix) override { return true; } | 99 bool SetNoncePrefix(StringPiece nonce_prefix) override { return true; } |
99 | 100 |
100 bool Encrypt(StringPiece nonce, | 101 bool Encrypt(StringPiece nonce, |
101 StringPiece associated_data, | 102 StringPiece associated_data, |
102 StringPiece plaintext, | 103 StringPiece plaintext, |
103 unsigned char* output) override { | 104 unsigned char* output) override { |
104 memcpy(output, plaintext.data(), plaintext.size()); | 105 memcpy(output, plaintext.data(), plaintext.size()); |
105 output += plaintext.size(); | 106 output += plaintext.size(); |
106 memset(output, tag_, kTagSize); | 107 memset(output, tag_, kTagSize); |
107 return true; | 108 return true; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 }; | 143 }; |
143 | 144 |
144 // TaggingDecrypter ensures that the final kTagSize bytes of the message all | 145 // TaggingDecrypter ensures that the final kTagSize bytes of the message all |
145 // have the same value and then removes them. | 146 // have the same value and then removes them. |
146 class TaggingDecrypter : public QuicDecrypter { | 147 class TaggingDecrypter : public QuicDecrypter { |
147 public: | 148 public: |
148 ~TaggingDecrypter() override {} | 149 ~TaggingDecrypter() override {} |
149 | 150 |
150 // QuicDecrypter interface | 151 // QuicDecrypter interface |
151 bool SetKey(StringPiece key) override { return true; } | 152 bool SetKey(StringPiece key) override { return true; } |
| 153 |
152 bool SetNoncePrefix(StringPiece nonce_prefix) override { return true; } | 154 bool SetNoncePrefix(StringPiece nonce_prefix) override { return true; } |
153 | 155 |
154 bool Decrypt(StringPiece nonce, | 156 bool Decrypt(StringPiece nonce, |
155 StringPiece associated_data, | 157 StringPiece associated_data, |
156 StringPiece ciphertext, | 158 StringPiece ciphertext, |
157 unsigned char* output, | 159 unsigned char* output, |
158 size_t* output_length) override { | 160 size_t* output_length) override { |
159 if (ciphertext.size() < kTagSize) { | 161 if (ciphertext.size() < kTagSize) { |
160 return false; | 162 return false; |
161 } | 163 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 | 253 |
252 private: | 254 private: |
253 MockClock* clock_; | 255 MockClock* clock_; |
254 MockRandom* random_generator_; | 256 MockRandom* random_generator_; |
255 | 257 |
256 DISALLOW_COPY_AND_ASSIGN(TestConnectionHelper); | 258 DISALLOW_COPY_AND_ASSIGN(TestConnectionHelper); |
257 }; | 259 }; |
258 | 260 |
259 class TestPacketWriter : public QuicPacketWriter { | 261 class TestPacketWriter : public QuicPacketWriter { |
260 public: | 262 public: |
261 explicit TestPacketWriter(QuicVersion version) | 263 TestPacketWriter(QuicVersion version, MockClock *clock) |
262 : version_(version), | 264 : version_(version), |
263 framer_(SupportedVersions(version_)), | 265 framer_(SupportedVersions(version_)), |
264 last_packet_size_(0), | 266 last_packet_size_(0), |
265 write_blocked_(false), | 267 write_blocked_(false), |
266 block_on_next_write_(false), | 268 block_on_next_write_(false), |
267 is_write_blocked_data_buffered_(false), | 269 is_write_blocked_data_buffered_(false), |
268 final_bytes_of_last_packet_(0), | 270 final_bytes_of_last_packet_(0), |
269 final_bytes_of_previous_packet_(0), | 271 final_bytes_of_previous_packet_(0), |
270 use_tagging_decrypter_(false), | 272 use_tagging_decrypter_(false), |
271 packets_write_attempts_(0) { | 273 packets_write_attempts_(0), |
| 274 clock_(clock), |
| 275 write_pause_time_delta_(QuicTime::Delta::Zero()) { |
272 } | 276 } |
273 | 277 |
274 // QuicPacketWriter interface | 278 // QuicPacketWriter interface |
275 WriteResult WritePacket(const char* buffer, | 279 WriteResult WritePacket(const char* buffer, |
276 size_t buf_len, | 280 size_t buf_len, |
277 const IPAddressNumber& self_address, | 281 const IPAddressNumber& self_address, |
278 const IPEndPoint& peer_address) override { | 282 const IPEndPoint& peer_address) override { |
279 QuicEncryptedPacket packet(buffer, buf_len); | 283 QuicEncryptedPacket packet(buffer, buf_len); |
280 ++packets_write_attempts_; | 284 ++packets_write_attempts_; |
281 | 285 |
282 if (packet.length() >= sizeof(final_bytes_of_last_packet_)) { | 286 if (packet.length() >= sizeof(final_bytes_of_last_packet_)) { |
283 final_bytes_of_previous_packet_ = final_bytes_of_last_packet_; | 287 final_bytes_of_previous_packet_ = final_bytes_of_last_packet_; |
284 memcpy(&final_bytes_of_last_packet_, packet.data() + packet.length() - 4, | 288 memcpy(&final_bytes_of_last_packet_, packet.data() + packet.length() - 4, |
285 sizeof(final_bytes_of_last_packet_)); | 289 sizeof(final_bytes_of_last_packet_)); |
286 } | 290 } |
287 | 291 |
288 if (use_tagging_decrypter_) { | 292 if (use_tagging_decrypter_) { |
289 framer_.framer()->SetDecrypter(new TaggingDecrypter, ENCRYPTION_NONE); | 293 framer_.framer()->SetDecrypter(new TaggingDecrypter, ENCRYPTION_NONE); |
290 } | 294 } |
291 EXPECT_TRUE(framer_.ProcessPacket(packet)); | 295 EXPECT_TRUE(framer_.ProcessPacket(packet)); |
292 if (block_on_next_write_) { | 296 if (block_on_next_write_) { |
293 write_blocked_ = true; | 297 write_blocked_ = true; |
294 block_on_next_write_ = false; | 298 block_on_next_write_ = false; |
295 } | 299 } |
296 if (IsWriteBlocked()) { | 300 if (IsWriteBlocked()) { |
297 return WriteResult(WRITE_STATUS_BLOCKED, -1); | 301 return WriteResult(WRITE_STATUS_BLOCKED, -1); |
298 } | 302 } |
299 last_packet_size_ = packet.length(); | 303 last_packet_size_ = packet.length(); |
| 304 |
| 305 if (!write_pause_time_delta_.IsZero()) { |
| 306 clock_->AdvanceTime(write_pause_time_delta_); |
| 307 } |
300 return WriteResult(WRITE_STATUS_OK, last_packet_size_); | 308 return WriteResult(WRITE_STATUS_OK, last_packet_size_); |
301 } | 309 } |
302 | 310 |
303 bool IsWriteBlockedDataBuffered() const override { | 311 bool IsWriteBlockedDataBuffered() const override { |
304 return is_write_blocked_data_buffered_; | 312 return is_write_blocked_data_buffered_; |
305 } | 313 } |
306 | 314 |
307 bool IsWriteBlocked() const override { return write_blocked_; } | 315 bool IsWriteBlocked() const override { return write_blocked_; } |
308 | 316 |
309 void SetWritable() override { write_blocked_ = false; } | 317 void SetWritable() override { write_blocked_ = false; } |
310 | 318 |
311 void BlockOnNextWrite() { block_on_next_write_ = true; } | 319 void BlockOnNextWrite() { block_on_next_write_ = true; } |
312 | 320 |
| 321 // Sets the amount of time that the writer should before the actual write. |
| 322 void SetWritePauseTimeDelta(QuicTime::Delta delta) { |
| 323 write_pause_time_delta_ = delta; |
| 324 } |
| 325 |
313 const QuicPacketHeader& header() { return framer_.header(); } | 326 const QuicPacketHeader& header() { return framer_.header(); } |
314 | 327 |
315 size_t frame_count() const { return framer_.num_frames(); } | 328 size_t frame_count() const { return framer_.num_frames(); } |
316 | 329 |
317 const vector<QuicAckFrame>& ack_frames() const { | 330 const vector<QuicAckFrame>& ack_frames() const { |
318 return framer_.ack_frames(); | 331 return framer_.ack_frames(); |
319 } | 332 } |
320 | 333 |
321 const vector<QuicCongestionFeedbackFrame>& feedback_frames() const { | 334 const vector<QuicCongestionFeedbackFrame>& feedback_frames() const { |
322 return framer_.feedback_frames(); | 335 return framer_.feedback_frames(); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 QuicVersion version_; | 396 QuicVersion version_; |
384 SimpleQuicFramer framer_; | 397 SimpleQuicFramer framer_; |
385 size_t last_packet_size_; | 398 size_t last_packet_size_; |
386 bool write_blocked_; | 399 bool write_blocked_; |
387 bool block_on_next_write_; | 400 bool block_on_next_write_; |
388 bool is_write_blocked_data_buffered_; | 401 bool is_write_blocked_data_buffered_; |
389 uint32 final_bytes_of_last_packet_; | 402 uint32 final_bytes_of_last_packet_; |
390 uint32 final_bytes_of_previous_packet_; | 403 uint32 final_bytes_of_previous_packet_; |
391 bool use_tagging_decrypter_; | 404 bool use_tagging_decrypter_; |
392 uint32 packets_write_attempts_; | 405 uint32 packets_write_attempts_; |
| 406 MockClock *clock_; |
| 407 // If non-zero, the clock will pause during WritePacket for this amount of |
| 408 // time. |
| 409 QuicTime::Delta write_pause_time_delta_; |
393 | 410 |
394 DISALLOW_COPY_AND_ASSIGN(TestPacketWriter); | 411 DISALLOW_COPY_AND_ASSIGN(TestPacketWriter); |
395 }; | 412 }; |
396 | 413 |
397 class TestConnection : public QuicConnection { | 414 class TestConnection : public QuicConnection { |
398 public: | 415 public: |
399 TestConnection(QuicConnectionId connection_id, | 416 TestConnection(QuicConnectionId connection_id, |
400 IPEndPoint address, | 417 IPEndPoint address, |
401 TestConnectionHelper* helper, | 418 TestConnectionHelper* helper, |
402 const PacketWriterFactory& factory, | 419 const PacketWriterFactory& factory, |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 | 607 |
591 private: | 608 private: |
592 QuicPacketHeader revived_header_; | 609 QuicPacketHeader revived_header_; |
593 }; | 610 }; |
594 | 611 |
595 class MockPacketWriterFactory : public QuicConnection::PacketWriterFactory { | 612 class MockPacketWriterFactory : public QuicConnection::PacketWriterFactory { |
596 public: | 613 public: |
597 MockPacketWriterFactory(QuicPacketWriter* writer) { | 614 MockPacketWriterFactory(QuicPacketWriter* writer) { |
598 ON_CALL(*this, Create(_)).WillByDefault(Return(writer)); | 615 ON_CALL(*this, Create(_)).WillByDefault(Return(writer)); |
599 } | 616 } |
600 virtual ~MockPacketWriterFactory() {} | 617 ~MockPacketWriterFactory() override {} |
601 | 618 |
602 MOCK_CONST_METHOD1(Create, QuicPacketWriter*(QuicConnection* connection)); | 619 MOCK_CONST_METHOD1(Create, QuicPacketWriter*(QuicConnection* connection)); |
603 }; | 620 }; |
604 | 621 |
605 class QuicConnectionTest : public ::testing::TestWithParam<QuicVersion> { | 622 class QuicConnectionTest : public ::testing::TestWithParam<QuicVersion> { |
606 protected: | 623 protected: |
607 QuicConnectionTest() | 624 QuicConnectionTest() |
608 : connection_id_(42), | 625 : connection_id_(42), |
609 framer_(SupportedVersions(version()), QuicTime::Zero(), false), | 626 framer_(SupportedVersions(version()), QuicTime::Zero(), false), |
610 peer_creator_(connection_id_, &framer_, &random_generator_), | 627 peer_creator_(connection_id_, &framer_, &random_generator_), |
611 send_algorithm_(new StrictMock<MockSendAlgorithm>), | 628 send_algorithm_(new StrictMock<MockSendAlgorithm>), |
612 loss_algorithm_(new MockLossAlgorithm()), | 629 loss_algorithm_(new MockLossAlgorithm()), |
613 helper_(new TestConnectionHelper(&clock_, &random_generator_)), | 630 helper_(new TestConnectionHelper(&clock_, &random_generator_)), |
614 writer_(new TestPacketWriter(version())), | 631 writer_(new TestPacketWriter(version(), &clock_)), |
615 factory_(writer_.get()), | 632 factory_(writer_.get()), |
616 connection_(connection_id_, IPEndPoint(), helper_.get(), | 633 connection_(connection_id_, IPEndPoint(), helper_.get(), |
617 factory_, false, version()), | 634 factory_, false, version()), |
618 frame1_(1, false, 0, MakeIOVector(data1)), | 635 frame1_(1, false, 0, MakeIOVector(data1)), |
619 frame2_(1, false, 3, MakeIOVector(data2)), | 636 frame2_(1, false, 3, MakeIOVector(data2)), |
620 sequence_number_length_(PACKET_6BYTE_SEQUENCE_NUMBER), | 637 sequence_number_length_(PACKET_6BYTE_SEQUENCE_NUMBER), |
621 connection_id_length_(PACKET_8BYTE_CONNECTION_ID) { | 638 connection_id_length_(PACKET_8BYTE_CONNECTION_ID) { |
622 connection_.set_visitor(&visitor_); | 639 connection_.set_visitor(&visitor_); |
623 connection_.SetSendAlgorithm(send_algorithm_); | 640 connection_.SetSendAlgorithm(send_algorithm_); |
624 connection_.SetLossAlgorithm(loss_algorithm_); | 641 connection_.SetLossAlgorithm(loss_algorithm_); |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
967 ProcessDataPacket(6000, 0, !kEntropyFlag); | 984 ProcessDataPacket(6000, 0, !kEntropyFlag); |
968 EXPECT_FALSE(QuicConnectionPeer::GetConnectionClosePacket(&connection_) == | 985 EXPECT_FALSE(QuicConnectionPeer::GetConnectionClosePacket(&connection_) == |
969 nullptr); | 986 nullptr); |
970 } | 987 } |
971 | 988 |
972 void BlockOnNextWrite() { | 989 void BlockOnNextWrite() { |
973 writer_->BlockOnNextWrite(); | 990 writer_->BlockOnNextWrite(); |
974 EXPECT_CALL(visitor_, OnWriteBlocked()).Times(AtLeast(1)); | 991 EXPECT_CALL(visitor_, OnWriteBlocked()).Times(AtLeast(1)); |
975 } | 992 } |
976 | 993 |
| 994 void SetWritePauseTimeDelta(QuicTime::Delta delta) { |
| 995 writer_->SetWritePauseTimeDelta(delta); |
| 996 } |
| 997 |
977 void CongestionBlockWrites() { | 998 void CongestionBlockWrites() { |
978 EXPECT_CALL(*send_algorithm_, | 999 EXPECT_CALL(*send_algorithm_, |
979 TimeUntilSend(_, _, _)).WillRepeatedly( | 1000 TimeUntilSend(_, _, _)).WillRepeatedly( |
980 testing::Return(QuicTime::Delta::FromSeconds(1))); | 1001 testing::Return(QuicTime::Delta::FromSeconds(1))); |
981 } | 1002 } |
982 | 1003 |
983 void CongestionUnblockWrites() { | 1004 void CongestionUnblockWrites() { |
984 EXPECT_CALL(*send_algorithm_, | 1005 EXPECT_CALL(*send_algorithm_, |
985 TimeUntilSend(_, _, _)).WillRepeatedly( | 1006 TimeUntilSend(_, _, _)).WillRepeatedly( |
986 testing::Return(QuicTime::Delta::Zero())); | 1007 testing::Return(QuicTime::Delta::Zero())); |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1541 SendAckPacketToPeer(); // Packet 7 | 1562 SendAckPacketToPeer(); // Packet 7 |
1542 EXPECT_EQ(7u, least_unacked()); | 1563 EXPECT_EQ(7u, least_unacked()); |
1543 | 1564 |
1544 // But if we send more data it should. | 1565 // But if we send more data it should. |
1545 SendStreamDataToPeer(1, "eep", 6, !kFin, &last_packet); // Packet 8 | 1566 SendStreamDataToPeer(1, "eep", 6, !kFin, &last_packet); // Packet 8 |
1546 EXPECT_EQ(8u, last_packet); | 1567 EXPECT_EQ(8u, last_packet); |
1547 SendAckPacketToPeer(); // Packet 9 | 1568 SendAckPacketToPeer(); // Packet 9 |
1548 EXPECT_EQ(7u, least_unacked()); | 1569 EXPECT_EQ(7u, least_unacked()); |
1549 } | 1570 } |
1550 | 1571 |
| 1572 // If FLAGS_quic_record_send_time_before_write is disabled, QuicConnection |
| 1573 // should record the packet sen-tdime after the packet is sent. |
| 1574 TEST_P(QuicConnectionTest, RecordSentTimeAfterPacketSent) { |
| 1575 ValueRestore<bool> old_flag(&FLAGS_quic_record_send_time_before_write, false); |
| 1576 // We're using a MockClock for the tests, so we have complete control over the |
| 1577 // time. |
| 1578 // Our recorded timestamp for the last packet sent time will be passed in to |
| 1579 // the send_algorithm. Make sure that it is set to the correct value. |
| 1580 QuicTime actual_recorded_send_time = QuicTime::Zero(); |
| 1581 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
| 1582 .WillOnce(DoAll(SaveArg<0>(&actual_recorded_send_time), Return(true))); |
| 1583 |
| 1584 // First send without any pause and check the result. |
| 1585 QuicTime expected_recorded_send_time = clock_.Now(); |
| 1586 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); |
| 1587 EXPECT_EQ(expected_recorded_send_time, actual_recorded_send_time) |
| 1588 << "Expected time = " << expected_recorded_send_time.ToDebuggingValue() |
| 1589 << ". Actual time = " << actual_recorded_send_time.ToDebuggingValue(); |
| 1590 |
| 1591 // Now pause during the write, and check the results. |
| 1592 actual_recorded_send_time = QuicTime::Zero(); |
| 1593 const QuicTime::Delta kWritePauseTimeDelta = |
| 1594 QuicTime::Delta::FromMilliseconds(5000); |
| 1595 SetWritePauseTimeDelta(kWritePauseTimeDelta); |
| 1596 expected_recorded_send_time = clock_.Now().Add(kWritePauseTimeDelta); |
| 1597 |
| 1598 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
| 1599 .WillOnce(DoAll(SaveArg<0>(&actual_recorded_send_time), Return(true))); |
| 1600 connection_.SendStreamDataWithString(2, "baz", 0, !kFin, nullptr); |
| 1601 EXPECT_EQ(expected_recorded_send_time, actual_recorded_send_time) |
| 1602 << "Expected time = " << expected_recorded_send_time.ToDebuggingValue() |
| 1603 << ". Actual time = " << actual_recorded_send_time.ToDebuggingValue(); |
| 1604 } |
| 1605 |
| 1606 // If FLAGS_quic_record_send_time_before_write is enabled, QuicConnection should |
| 1607 // record the the packet sent-time prior to sending the packet. |
| 1608 TEST_P(QuicConnectionTest, RecordSentTimeBeforePacketSent) { |
| 1609 ValueRestore<bool> old_flag(&FLAGS_quic_record_send_time_before_write, true); |
| 1610 // We're using a MockClock for the tests, so we have complete control over the |
| 1611 // time. |
| 1612 // Our recorded timestamp for the last packet sent time will be passed in to |
| 1613 // the send_algorithm. Make sure that it is set to the correct value. |
| 1614 QuicTime actual_recorded_send_time = QuicTime::Zero(); |
| 1615 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
| 1616 .WillOnce(DoAll(SaveArg<0>(&actual_recorded_send_time), Return(true))); |
| 1617 |
| 1618 // First send without any pause and check the result. |
| 1619 QuicTime expected_recorded_send_time = clock_.Now(); |
| 1620 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); |
| 1621 EXPECT_EQ(expected_recorded_send_time, actual_recorded_send_time) |
| 1622 << "Expected time = " << expected_recorded_send_time.ToDebuggingValue() |
| 1623 << ". Actual time = " << actual_recorded_send_time.ToDebuggingValue(); |
| 1624 |
| 1625 // Now pause during the write, and check the results. |
| 1626 actual_recorded_send_time = QuicTime::Zero(); |
| 1627 const QuicTime::Delta kWritePauseTimeDelta = |
| 1628 QuicTime::Delta::FromMilliseconds(5000); |
| 1629 SetWritePauseTimeDelta(kWritePauseTimeDelta); |
| 1630 expected_recorded_send_time = clock_.Now(); |
| 1631 |
| 1632 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
| 1633 .WillOnce(DoAll(SaveArg<0>(&actual_recorded_send_time), Return(true))); |
| 1634 connection_.SendStreamDataWithString(2, "baz", 0, !kFin, nullptr); |
| 1635 EXPECT_EQ(expected_recorded_send_time, actual_recorded_send_time) |
| 1636 << "Expected time = " << expected_recorded_send_time.ToDebuggingValue() |
| 1637 << ". Actual time = " << actual_recorded_send_time.ToDebuggingValue(); |
| 1638 } |
| 1639 |
1551 TEST_P(QuicConnectionTest, FECSending) { | 1640 TEST_P(QuicConnectionTest, FECSending) { |
1552 // All packets carry version info till version is negotiated. | 1641 // All packets carry version info till version is negotiated. |
1553 QuicPacketCreator* creator = | 1642 QuicPacketCreator* creator = |
1554 QuicConnectionPeer::GetPacketCreator(&connection_); | 1643 QuicConnectionPeer::GetPacketCreator(&connection_); |
1555 size_t payload_length; | 1644 size_t payload_length; |
1556 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining | 1645 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining |
1557 // packet length. The size of the offset field in a stream frame is 0 for | 1646 // packet length. The size of the offset field in a stream frame is 0 for |
1558 // offset 0, and 2 for non-zero offsets up through 64K. Increase | 1647 // offset 0, and 2 for non-zero offsets up through 64K. Increase |
1559 // max_packet_length by 2 so that subsequent packets containing subsequent | 1648 // max_packet_length by 2 so that subsequent packets containing subsequent |
1560 // stream frames with non-zero offets will fit within the packet length. | 1649 // stream frames with non-zero offets will fit within the packet length. |
1561 size_t length = 2 + GetPacketLengthForOneStream( | 1650 size_t length = 2 + GetPacketLengthForOneStream( |
1562 connection_.version(), kIncludeVersion, | 1651 connection_.version(), kIncludeVersion, |
1563 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, | 1652 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, |
1564 IN_FEC_GROUP, &payload_length); | 1653 IN_FEC_GROUP, &payload_length); |
1565 creator->set_max_packet_length(length); | 1654 creator->set_max_packet_length(length); |
1566 | 1655 |
1567 // Send 4 protected data packets, which should also trigger 1 FEC packet. | 1656 // Send 4 protected data packets, which should also trigger 1 FEC packet. |
1568 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(5); | 1657 EXPECT_CALL(*send_algorithm_, |
| 1658 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(5); |
1569 // The first stream frame will have 2 fewer overhead bytes than the other 3. | 1659 // The first stream frame will have 2 fewer overhead bytes than the other 3. |
1570 const string payload(payload_length * 4 + 2, 'a'); | 1660 const string payload(payload_length * 4 + 2, 'a'); |
1571 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, nullptr); | 1661 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, nullptr); |
1572 // Expect the FEC group to be closed after SendStreamDataWithString. | 1662 // Expect the FEC group to be closed after SendStreamDataWithString. |
1573 EXPECT_FALSE(creator->IsFecGroupOpen()); | 1663 EXPECT_FALSE(creator->IsFecGroupOpen()); |
1574 EXPECT_FALSE(creator->IsFecProtected()); | 1664 EXPECT_FALSE(creator->IsFecProtected()); |
1575 } | 1665 } |
1576 | 1666 |
1577 TEST_P(QuicConnectionTest, FECQueueing) { | 1667 TEST_P(QuicConnectionTest, FECQueueing) { |
1578 // All packets carry version info till version is negotiated. | 1668 // All packets carry version info till version is negotiated. |
(...skipping 15 matching lines...) Expand all Loading... |
1594 EXPECT_FALSE(creator->IsFecProtected()); | 1684 EXPECT_FALSE(creator->IsFecProtected()); |
1595 // Expect the first data packet and the fec packet to be queued. | 1685 // Expect the first data packet and the fec packet to be queued. |
1596 EXPECT_EQ(2u, connection_.NumQueuedPackets()); | 1686 EXPECT_EQ(2u, connection_.NumQueuedPackets()); |
1597 } | 1687 } |
1598 | 1688 |
1599 TEST_P(QuicConnectionTest, AbandonFECFromCongestionWindow) { | 1689 TEST_P(QuicConnectionTest, AbandonFECFromCongestionWindow) { |
1600 EXPECT_TRUE(QuicConnectionPeer::GetPacketCreator( | 1690 EXPECT_TRUE(QuicConnectionPeer::GetPacketCreator( |
1601 &connection_)->IsFecEnabled()); | 1691 &connection_)->IsFecEnabled()); |
1602 | 1692 |
1603 // 1 Data and 1 FEC packet. | 1693 // 1 Data and 1 FEC packet. |
1604 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); | 1694 EXPECT_CALL(*send_algorithm_, |
| 1695 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(2); |
1605 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, nullptr); | 1696 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, nullptr); |
1606 | 1697 |
1607 const QuicTime::Delta retransmission_time = | 1698 const QuicTime::Delta retransmission_time = |
1608 QuicTime::Delta::FromMilliseconds(5000); | 1699 QuicTime::Delta::FromMilliseconds(5000); |
1609 clock_.AdvanceTime(retransmission_time); | 1700 clock_.AdvanceTime(retransmission_time); |
1610 | 1701 |
1611 // Abandon FEC packet and data packet. | 1702 // Abandon FEC packet and data packet. |
1612 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); | 1703 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
1613 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 1704 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
1614 EXPECT_CALL(visitor_, OnCanWrite()); | 1705 EXPECT_CALL(visitor_, OnCanWrite()); |
1615 connection_.OnRetransmissionTimeout(); | 1706 connection_.OnRetransmissionTimeout(); |
1616 } | 1707 } |
1617 | 1708 |
1618 TEST_P(QuicConnectionTest, DontAbandonAckedFEC) { | 1709 TEST_P(QuicConnectionTest, DontAbandonAckedFEC) { |
1619 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1710 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
1620 EXPECT_TRUE(QuicConnectionPeer::GetPacketCreator( | 1711 EXPECT_TRUE(QuicConnectionPeer::GetPacketCreator( |
1621 &connection_)->IsFecEnabled()); | 1712 &connection_)->IsFecEnabled()); |
1622 | 1713 |
1623 // 1 Data and 1 FEC packet. | 1714 // 3 Data and 3 FEC packets. |
1624 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); | 1715 EXPECT_CALL(*send_algorithm_, |
| 1716 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(6); |
1625 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, nullptr); | 1717 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, nullptr); |
1626 // Send some more data afterwards to ensure early retransmit doesn't trigger. | 1718 // Send some more data afterwards to ensure early retransmit doesn't trigger. |
1627 connection_.SendStreamDataWithStringWithFec(3, "foo", 3, !kFin, nullptr); | 1719 connection_.SendStreamDataWithStringWithFec(3, "foo", 3, !kFin, nullptr); |
1628 connection_.SendStreamDataWithStringWithFec(3, "foo", 6, !kFin, nullptr); | 1720 connection_.SendStreamDataWithStringWithFec(3, "foo", 6, !kFin, nullptr); |
1629 | 1721 |
1630 QuicAckFrame ack_fec = InitAckFrame(2); | 1722 QuicAckFrame ack_fec = InitAckFrame(2); |
1631 // Data packet missing. | 1723 // Data packet missing. |
1632 // TODO(ianswett): Note that this is not a sensible ack, since if the FEC was | 1724 // TODO(ianswett): Note that this is not a sensible ack, since if the FEC was |
1633 // received, it would cause the covered packet to be acked as well. | 1725 // received, it would cause the covered packet to be acked as well. |
1634 NackPacket(1, &ack_fec); | 1726 NackPacket(1, &ack_fec); |
1635 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 1727 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
1636 ProcessAckPacket(&ack_fec); | 1728 ProcessAckPacket(&ack_fec); |
1637 clock_.AdvanceTime(DefaultRetransmissionTime()); | 1729 clock_.AdvanceTime(DefaultRetransmissionTime()); |
1638 | 1730 |
1639 // Don't abandon the acked FEC packet, but it will abandon 2 the subsequent | 1731 // Don't abandon the acked FEC packet, but it will abandon 2 the subsequent |
1640 // FEC packets. | 1732 // FEC packets. |
1641 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); | 1733 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
1642 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3); | 1734 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3); |
1643 connection_.GetRetransmissionAlarm()->Fire(); | 1735 connection_.GetRetransmissionAlarm()->Fire(); |
1644 } | 1736 } |
1645 | 1737 |
1646 TEST_P(QuicConnectionTest, AbandonAllFEC) { | 1738 TEST_P(QuicConnectionTest, AbandonAllFEC) { |
1647 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1739 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
1648 EXPECT_TRUE(QuicConnectionPeer::GetPacketCreator( | 1740 EXPECT_TRUE(QuicConnectionPeer::GetPacketCreator( |
1649 &connection_)->IsFecEnabled()); | 1741 &connection_)->IsFecEnabled()); |
1650 | 1742 |
1651 // 1 Data and 1 FEC packet. | 1743 // 3 Data and 3 FEC packet. |
1652 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); | 1744 EXPECT_CALL(*send_algorithm_, |
| 1745 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(6); |
1653 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, nullptr); | 1746 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, nullptr); |
1654 // Send some more data afterwards to ensure early retransmit doesn't trigger. | 1747 // Send some more data afterwards to ensure early retransmit doesn't trigger. |
1655 connection_.SendStreamDataWithStringWithFec(3, "foo", 3, !kFin, nullptr); | 1748 connection_.SendStreamDataWithStringWithFec(3, "foo", 3, !kFin, nullptr); |
1656 // Advance the time so not all the FEC packets are abandoned. | 1749 // Advance the time so not all the FEC packets are abandoned. |
1657 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); | 1750 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); |
1658 connection_.SendStreamDataWithStringWithFec(3, "foo", 6, !kFin, nullptr); | 1751 connection_.SendStreamDataWithStringWithFec(3, "foo", 6, !kFin, nullptr); |
1659 | 1752 |
1660 QuicAckFrame ack_fec = InitAckFrame(5); | 1753 QuicAckFrame ack_fec = InitAckFrame(5); |
1661 // Ack all data packets, but no fec packets. | 1754 // Ack all data packets, but no fec packets. |
1662 NackPacket(2, &ack_fec); | 1755 NackPacket(2, &ack_fec); |
(...skipping 1400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3063 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); | 3156 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); |
3064 // Simulate delayed ack alarm firing. | 3157 // Simulate delayed ack alarm firing. |
3065 connection_.GetAckAlarm()->Fire(); | 3158 connection_.GetAckAlarm()->Fire(); |
3066 // Check that ack is sent and that delayed ack alarm is reset. | 3159 // Check that ack is sent and that delayed ack alarm is reset. |
3067 EXPECT_EQ(2u, writer_->frame_count()); | 3160 EXPECT_EQ(2u, writer_->frame_count()); |
3068 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); | 3161 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); |
3069 EXPECT_FALSE(writer_->ack_frames().empty()); | 3162 EXPECT_FALSE(writer_->ack_frames().empty()); |
3070 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 3163 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
3071 } | 3164 } |
3072 | 3165 |
3073 TEST_P(QuicConnectionTest, SendEarlyDelayedAckForCrypto) { | 3166 TEST_P(QuicConnectionTest, SendDelayedAckOnHandshakeConfirmed) { |
3074 QuicTime ack_time = clock_.ApproximateNow(); | |
3075 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3167 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
3076 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | |
3077 // Process a packet from the crypto stream, which is frame1_'s default. | |
3078 ProcessPacket(1); | 3168 ProcessPacket(1); |
3079 // Check if delayed ack timer is running for the expected interval. | 3169 // Check that ack is sent and that delayed ack alarm is set. |
| 3170 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); |
| 3171 QuicTime ack_time = clock_.ApproximateNow().Add(DefaultDelayedAckTime()); |
| 3172 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); |
| 3173 |
| 3174 // Completing the handshake as the server does nothing. |
| 3175 QuicConnectionPeer::SetIsServer(&connection_, true); |
| 3176 connection_.OnHandshakeComplete(); |
3080 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); | 3177 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); |
3081 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); | 3178 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); |
3082 // Simulate delayed ack alarm firing. | 3179 |
3083 connection_.GetAckAlarm()->Fire(); | 3180 // Complete the handshake as the client decreases the delayed ack time to 0ms. |
3084 // Check that ack is sent and that delayed ack alarm is reset. | 3181 QuicConnectionPeer::SetIsServer(&connection_, false); |
3085 EXPECT_EQ(2u, writer_->frame_count()); | 3182 connection_.OnHandshakeComplete(); |
3086 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); | 3183 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); |
3087 EXPECT_FALSE(writer_->ack_frames().empty()); | 3184 EXPECT_EQ(clock_.ApproximateNow(), connection_.GetAckAlarm()->deadline()); |
3088 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | |
3089 } | 3185 } |
3090 | 3186 |
3091 TEST_P(QuicConnectionTest, SendDelayedAckOnSecondPacket) { | 3187 TEST_P(QuicConnectionTest, SendDelayedAckOnSecondPacket) { |
3092 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3188 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
3093 ProcessPacket(1); | 3189 ProcessPacket(1); |
3094 ProcessPacket(2); | 3190 ProcessPacket(2); |
3095 // Check that ack is sent and that delayed ack alarm is reset. | 3191 // Check that ack is sent and that delayed ack alarm is reset. |
3096 EXPECT_EQ(2u, writer_->frame_count()); | 3192 EXPECT_EQ(2u, writer_->frame_count()); |
3097 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); | 3193 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); |
3098 EXPECT_FALSE(writer_->ack_frames().empty()); | 3194 EXPECT_FALSE(writer_->ack_frames().empty()); |
(...skipping 997 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4096 QuicBlockedFrame blocked; | 4192 QuicBlockedFrame blocked; |
4097 blocked.stream_id = 3; | 4193 blocked.stream_id = 3; |
4098 EXPECT_CALL(visitor_, OnBlockedFrames(_)); | 4194 EXPECT_CALL(visitor_, OnBlockedFrames(_)); |
4099 ProcessFramePacket(QuicFrame(&blocked)); | 4195 ProcessFramePacket(QuicFrame(&blocked)); |
4100 EXPECT_TRUE(ack_alarm->IsSet()); | 4196 EXPECT_TRUE(ack_alarm->IsSet()); |
4101 } | 4197 } |
4102 | 4198 |
4103 } // namespace | 4199 } // namespace |
4104 } // namespace test | 4200 } // namespace test |
4105 } // namespace net | 4201 } // namespace net |
OLD | NEW |