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

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

Issue 849123003: Land Recent QUIC Changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed extra blank line Created 5 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
« no previous file with comments | « net/quic/quic_connection.cc ('k') | net/quic/quic_crypto_server_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"
11 #include "net/quic/congestion_control/loss_detection_interface.h" 11 #include "net/quic/congestion_control/loss_detection_interface.h"
12 #include "net/quic/congestion_control/receive_algorithm_interface.h" 12 #include "net/quic/congestion_control/receive_algorithm_interface.h"
13 #include "net/quic/congestion_control/send_algorithm_interface.h" 13 #include "net/quic/congestion_control/send_algorithm_interface.h"
14 #include "net/quic/crypto/null_encrypter.h" 14 #include "net/quic/crypto/null_encrypter.h"
15 #include "net/quic/crypto/quic_decrypter.h" 15 #include "net/quic/crypto/quic_decrypter.h"
16 #include "net/quic/crypto/quic_encrypter.h" 16 #include "net/quic/crypto/quic_encrypter.h"
17 #include "net/quic/quic_ack_notifier.h" 17 #include "net/quic/quic_ack_notifier.h"
18 #include "net/quic/quic_flags.h" 18 #include "net/quic/quic_flags.h"
19 #include "net/quic/quic_protocol.h" 19 #include "net/quic/quic_protocol.h"
20 #include "net/quic/quic_utils.h" 20 #include "net/quic/quic_utils.h"
21 #include "net/quic/test_tools/mock_clock.h" 21 #include "net/quic/test_tools/mock_clock.h"
22 #include "net/quic/test_tools/mock_random.h" 22 #include "net/quic/test_tools/mock_random.h"
23 #include "net/quic/test_tools/quic_config_peer.h" 23 #include "net/quic/test_tools/quic_config_peer.h"
24 #include "net/quic/test_tools/quic_connection_peer.h" 24 #include "net/quic/test_tools/quic_connection_peer.h"
25 #include "net/quic/test_tools/quic_framer_peer.h" 25 #include "net/quic/test_tools/quic_framer_peer.h"
26 #include "net/quic/test_tools/quic_packet_creator_peer.h" 26 #include "net/quic/test_tools/quic_packet_creator_peer.h"
27 #include "net/quic/test_tools/quic_packet_generator_peer.h"
27 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" 28 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h"
28 #include "net/quic/test_tools/quic_test_utils.h" 29 #include "net/quic/test_tools/quic_test_utils.h"
29 #include "net/quic/test_tools/simple_quic_framer.h" 30 #include "net/quic/test_tools/simple_quic_framer.h"
30 #include "net/test/gtest_util.h" 31 #include "net/test/gtest_util.h"
31 #include "testing/gmock/include/gmock/gmock.h" 32 #include "testing/gmock/include/gmock/gmock.h"
32 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
33 34
34 using base::StringPiece; 35 using base::StringPiece;
35 using std::map; 36 using std::map;
36 using std::string; 37 using std::string;
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 TestConnectionHelper::TestAlarm* GetAckAlarm() { 558 TestConnectionHelper::TestAlarm* GetAckAlarm() {
558 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( 559 return reinterpret_cast<TestConnectionHelper::TestAlarm*>(
559 QuicConnectionPeer::GetAckAlarm(this)); 560 QuicConnectionPeer::GetAckAlarm(this));
560 } 561 }
561 562
562 TestConnectionHelper::TestAlarm* GetPingAlarm() { 563 TestConnectionHelper::TestAlarm* GetPingAlarm() {
563 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( 564 return reinterpret_cast<TestConnectionHelper::TestAlarm*>(
564 QuicConnectionPeer::GetPingAlarm(this)); 565 QuicConnectionPeer::GetPingAlarm(this));
565 } 566 }
566 567
568 TestConnectionHelper::TestAlarm* GetFecAlarm() {
569 return reinterpret_cast<TestConnectionHelper::TestAlarm*>(
570 QuicConnectionPeer::GetFecAlarm(this));
571 }
572
567 TestConnectionHelper::TestAlarm* GetResumeWritesAlarm() { 573 TestConnectionHelper::TestAlarm* GetResumeWritesAlarm() {
568 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( 574 return reinterpret_cast<TestConnectionHelper::TestAlarm*>(
569 QuicConnectionPeer::GetResumeWritesAlarm(this)); 575 QuicConnectionPeer::GetResumeWritesAlarm(this));
570 } 576 }
571 577
572 TestConnectionHelper::TestAlarm* GetRetransmissionAlarm() { 578 TestConnectionHelper::TestAlarm* GetRetransmissionAlarm() {
573 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( 579 return reinterpret_cast<TestConnectionHelper::TestAlarm*>(
574 QuicConnectionPeer::GetRetransmissionAlarm(this)); 580 QuicConnectionPeer::GetRetransmissionAlarm(this));
575 } 581 }
576 582
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 protected: 632 protected:
627 QuicConnectionTest() 633 QuicConnectionTest()
628 : connection_id_(42), 634 : connection_id_(42),
629 framer_(SupportedVersions(version()), QuicTime::Zero(), false), 635 framer_(SupportedVersions(version()), QuicTime::Zero(), false),
630 peer_creator_(connection_id_, &framer_, &random_generator_), 636 peer_creator_(connection_id_, &framer_, &random_generator_),
631 send_algorithm_(new StrictMock<MockSendAlgorithm>), 637 send_algorithm_(new StrictMock<MockSendAlgorithm>),
632 loss_algorithm_(new MockLossAlgorithm()), 638 loss_algorithm_(new MockLossAlgorithm()),
633 helper_(new TestConnectionHelper(&clock_, &random_generator_)), 639 helper_(new TestConnectionHelper(&clock_, &random_generator_)),
634 writer_(new TestPacketWriter(version(), &clock_)), 640 writer_(new TestPacketWriter(version(), &clock_)),
635 factory_(writer_.get()), 641 factory_(writer_.get()),
636 connection_(connection_id_, IPEndPoint(), helper_.get(), 642 connection_(connection_id_,
637 factory_, false, version()), 643 IPEndPoint(),
644 helper_.get(),
645 factory_,
646 false,
647 version()),
648 creator_(QuicConnectionPeer::GetPacketCreator(&connection_)),
649 generator_(QuicConnectionPeer::GetPacketGenerator(&connection_)),
650 manager_(QuicConnectionPeer::GetSentPacketManager(&connection_)),
638 frame1_(1, false, 0, MakeIOVector(data1)), 651 frame1_(1, false, 0, MakeIOVector(data1)),
639 frame2_(1, false, 3, MakeIOVector(data2)), 652 frame2_(1, false, 3, MakeIOVector(data2)),
640 sequence_number_length_(PACKET_6BYTE_SEQUENCE_NUMBER), 653 sequence_number_length_(PACKET_6BYTE_SEQUENCE_NUMBER),
641 connection_id_length_(PACKET_8BYTE_CONNECTION_ID) { 654 connection_id_length_(PACKET_8BYTE_CONNECTION_ID) {
642 connection_.set_visitor(&visitor_); 655 connection_.set_visitor(&visitor_);
643 connection_.SetSendAlgorithm(send_algorithm_); 656 connection_.SetSendAlgorithm(send_algorithm_);
644 connection_.SetLossAlgorithm(loss_algorithm_); 657 connection_.SetLossAlgorithm(loss_algorithm_);
645 framer_.set_received_entropy_calculator(&entropy_calculator_); 658 framer_.set_received_entropy_calculator(&entropy_calculator_);
646 // Simplify tests by not sending feedback unless specifically configured. 659 // Simplify tests by not sending feedback unless specifically configured.
647 SetFeedback(nullptr); 660 SetFeedback(nullptr);
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 QuicByteCount SendStreamDataToPeer(QuicStreamId id, 840 QuicByteCount SendStreamDataToPeer(QuicStreamId id,
828 StringPiece data, 841 StringPiece data,
829 QuicStreamOffset offset, 842 QuicStreamOffset offset,
830 bool fin, 843 bool fin,
831 QuicPacketSequenceNumber* last_packet) { 844 QuicPacketSequenceNumber* last_packet) {
832 QuicByteCount packet_size; 845 QuicByteCount packet_size;
833 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 846 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
834 .WillOnce(DoAll(SaveArg<3>(&packet_size), Return(true))); 847 .WillOnce(DoAll(SaveArg<3>(&packet_size), Return(true)));
835 connection_.SendStreamDataWithString(id, data, offset, fin, nullptr); 848 connection_.SendStreamDataWithString(id, data, offset, fin, nullptr);
836 if (last_packet != nullptr) { 849 if (last_packet != nullptr) {
837 *last_packet = 850 *last_packet = creator_->sequence_number();
838 QuicConnectionPeer::GetPacketCreator(&connection_)->sequence_number();
839 } 851 }
840 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 852 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
841 .Times(AnyNumber()); 853 .Times(AnyNumber());
842 return packet_size; 854 return packet_size;
843 } 855 }
844 856
845 void SendAckPacketToPeer() { 857 void SendAckPacketToPeer() {
846 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 858 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
847 connection_.SendAck(); 859 connection_.SendAck();
848 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 860 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1017 1029
1018 MockSendAlgorithm* send_algorithm_; 1030 MockSendAlgorithm* send_algorithm_;
1019 MockLossAlgorithm* loss_algorithm_; 1031 MockLossAlgorithm* loss_algorithm_;
1020 TestReceiveAlgorithm* receive_algorithm_; 1032 TestReceiveAlgorithm* receive_algorithm_;
1021 MockClock clock_; 1033 MockClock clock_;
1022 MockRandom random_generator_; 1034 MockRandom random_generator_;
1023 scoped_ptr<TestConnectionHelper> helper_; 1035 scoped_ptr<TestConnectionHelper> helper_;
1024 scoped_ptr<TestPacketWriter> writer_; 1036 scoped_ptr<TestPacketWriter> writer_;
1025 NiceMock<MockPacketWriterFactory> factory_; 1037 NiceMock<MockPacketWriterFactory> factory_;
1026 TestConnection connection_; 1038 TestConnection connection_;
1039 QuicPacketCreator* creator_;
1040 QuicPacketGenerator* generator_;
1041 QuicSentPacketManager* manager_;
1027 StrictMock<MockConnectionVisitor> visitor_; 1042 StrictMock<MockConnectionVisitor> visitor_;
1028 1043
1029 QuicPacketHeader header_; 1044 QuicPacketHeader header_;
1030 QuicStreamFrame frame1_; 1045 QuicStreamFrame frame1_;
1031 QuicStreamFrame frame2_; 1046 QuicStreamFrame frame2_;
1032 scoped_ptr<QuicAckFrame> outgoing_ack_; 1047 scoped_ptr<QuicAckFrame> outgoing_ack_;
1033 scoped_ptr<QuicStopWaitingFrame> stop_waiting_; 1048 scoped_ptr<QuicStopWaitingFrame> stop_waiting_;
1034 QuicSequenceNumberLength sequence_number_length_; 1049 QuicSequenceNumberLength sequence_number_length_;
1035 QuicConnectionIdLength connection_id_length_; 1050 QuicConnectionIdLength connection_id_length_;
1036 1051
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 lost_packets.insert(i * 2); 1182 lost_packets.insert(i * 2);
1168 } 1183 }
1169 } 1184 }
1170 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 1185 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
1171 .WillOnce(Return(lost_packets)); 1186 .WillOnce(Return(lost_packets));
1172 EXPECT_CALL(entropy_calculator_, EntropyHash(511)) 1187 EXPECT_CALL(entropy_calculator_, EntropyHash(511))
1173 .WillOnce(Return(static_cast<QuicPacketEntropyHash>(0))); 1188 .WillOnce(Return(static_cast<QuicPacketEntropyHash>(0)));
1174 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 1189 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
1175 ProcessAckPacket(&frame); 1190 ProcessAckPacket(&frame);
1176 1191
1177 const QuicSentPacketManager& sent_packet_manager =
1178 connection_.sent_packet_manager();
1179 // A truncated ack will not have the true largest observed. 1192 // A truncated ack will not have the true largest observed.
1180 EXPECT_GT(num_packets, sent_packet_manager.largest_observed()); 1193 EXPECT_GT(num_packets, manager_->largest_observed());
1181 1194
1182 AckPacket(192, &frame); 1195 AckPacket(192, &frame);
1183 1196
1184 // Removing one missing packet allows us to ack 192 and one more range, but 1197 // Removing one missing packet allows us to ack 192 and one more range, but
1185 // 192 has already been declared lost, so it doesn't register as an ack. 1198 // 192 has already been declared lost, so it doesn't register as an ack.
1186 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 1199 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
1187 .WillOnce(Return(SequenceNumberSet())); 1200 .WillOnce(Return(SequenceNumberSet()));
1188 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 1201 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
1189 ProcessAckPacket(&frame); 1202 ProcessAckPacket(&frame);
1190 EXPECT_EQ(num_packets, sent_packet_manager.largest_observed()); 1203 EXPECT_EQ(num_packets, manager_->largest_observed());
1191 } 1204 }
1192 1205
1193 TEST_P(QuicConnectionTest, AckReceiptCausesAckSendBadEntropy) { 1206 TEST_P(QuicConnectionTest, AckReceiptCausesAckSendBadEntropy) {
1194 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1207 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1195 1208
1196 ProcessPacket(1); 1209 ProcessPacket(1);
1197 // Delay sending, then queue up an ack. 1210 // Delay sending, then queue up an ack.
1198 EXPECT_CALL(*send_algorithm_, 1211 EXPECT_CALL(*send_algorithm_,
1199 TimeUntilSend(_, _, _)).WillOnce( 1212 TimeUntilSend(_, _, _)).WillOnce(
1200 testing::Return(QuicTime::Delta::FromMicroseconds(1))); 1213 testing::Return(QuicTime::Delta::FromMicroseconds(1)));
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1421 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1409 ProcessPacket(1); 1422 ProcessPacket(1);
1410 1423
1411 peer_creator_.set_sequence_number(1); 1424 peer_creator_.set_sequence_number(1);
1412 QuicAckFrame frame1 = InitAckFrame(0); 1425 QuicAckFrame frame1 = InitAckFrame(0);
1413 ProcessAckPacket(&frame1); 1426 ProcessAckPacket(&frame1);
1414 } 1427 }
1415 1428
1416 TEST_P(QuicConnectionTest, SendingDifferentSequenceNumberLengthsBandwidth) { 1429 TEST_P(QuicConnectionTest, SendingDifferentSequenceNumberLengthsBandwidth) {
1417 QuicPacketSequenceNumber last_packet; 1430 QuicPacketSequenceNumber last_packet;
1418 QuicPacketCreator* creator =
1419 QuicConnectionPeer::GetPacketCreator(&connection_);
1420 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); 1431 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet);
1421 EXPECT_EQ(1u, last_packet); 1432 EXPECT_EQ(1u, last_packet);
1422 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, 1433 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER,
1423 creator->next_sequence_number_length()); 1434 creator_->next_sequence_number_length());
1424 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, 1435 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER,
1425 writer_->header().public_header.sequence_number_length); 1436 writer_->header().public_header.sequence_number_length);
1426 1437
1427 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( 1438 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly(
1428 Return(kMaxPacketSize * 256)); 1439 Return(kMaxPacketSize * 256));
1429 1440
1430 SendStreamDataToPeer(1, "bar", 3, !kFin, &last_packet); 1441 SendStreamDataToPeer(1, "bar", 3, !kFin, &last_packet);
1431 EXPECT_EQ(2u, last_packet); 1442 EXPECT_EQ(2u, last_packet);
1432 EXPECT_EQ(PACKET_2BYTE_SEQUENCE_NUMBER, 1443 EXPECT_EQ(PACKET_2BYTE_SEQUENCE_NUMBER,
1433 creator->next_sequence_number_length()); 1444 creator_->next_sequence_number_length());
1434 // The 1 packet lag is due to the sequence number length being recalculated in 1445 // The 1 packet lag is due to the sequence number length being recalculated in
1435 // QuicConnection after a packet is sent. 1446 // QuicConnection after a packet is sent.
1436 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, 1447 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER,
1437 writer_->header().public_header.sequence_number_length); 1448 writer_->header().public_header.sequence_number_length);
1438 1449
1439 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( 1450 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly(
1440 Return(kMaxPacketSize * 256 * 256)); 1451 Return(kMaxPacketSize * 256 * 256));
1441 1452
1442 SendStreamDataToPeer(1, "foo", 6, !kFin, &last_packet); 1453 SendStreamDataToPeer(1, "foo", 6, !kFin, &last_packet);
1443 EXPECT_EQ(3u, last_packet); 1454 EXPECT_EQ(3u, last_packet);
1444 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, 1455 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER,
1445 creator->next_sequence_number_length()); 1456 creator_->next_sequence_number_length());
1446 EXPECT_EQ(PACKET_2BYTE_SEQUENCE_NUMBER, 1457 EXPECT_EQ(PACKET_2BYTE_SEQUENCE_NUMBER,
1447 writer_->header().public_header.sequence_number_length); 1458 writer_->header().public_header.sequence_number_length);
1448 1459
1449 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( 1460 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly(
1450 Return(kMaxPacketSize * 256 * 256 * 256)); 1461 Return(kMaxPacketSize * 256 * 256 * 256));
1451 1462
1452 SendStreamDataToPeer(1, "bar", 9, !kFin, &last_packet); 1463 SendStreamDataToPeer(1, "bar", 9, !kFin, &last_packet);
1453 EXPECT_EQ(4u, last_packet); 1464 EXPECT_EQ(4u, last_packet);
1454 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, 1465 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER,
1455 creator->next_sequence_number_length()); 1466 creator_->next_sequence_number_length());
1456 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, 1467 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER,
1457 writer_->header().public_header.sequence_number_length); 1468 writer_->header().public_header.sequence_number_length);
1458 1469
1459 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( 1470 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly(
1460 Return(kMaxPacketSize * 256 * 256 * 256 * 256)); 1471 Return(kMaxPacketSize * 256 * 256 * 256 * 256));
1461 1472
1462 SendStreamDataToPeer(1, "foo", 12, !kFin, &last_packet); 1473 SendStreamDataToPeer(1, "foo", 12, !kFin, &last_packet);
1463 EXPECT_EQ(5u, last_packet); 1474 EXPECT_EQ(5u, last_packet);
1464 EXPECT_EQ(PACKET_6BYTE_SEQUENCE_NUMBER, 1475 EXPECT_EQ(PACKET_6BYTE_SEQUENCE_NUMBER,
1465 creator->next_sequence_number_length()); 1476 creator_->next_sequence_number_length());
1466 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, 1477 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER,
1467 writer_->header().public_header.sequence_number_length); 1478 writer_->header().public_header.sequence_number_length);
1468 } 1479 }
1469 1480
1470 // TODO(ianswett): Re-enable this test by finding a good way to test different 1481 // TODO(ianswett): Re-enable this test by finding a good way to test different
1471 // sequence number lengths without sending packets with giant gaps. 1482 // sequence number lengths without sending packets with giant gaps.
1472 TEST_P(QuicConnectionTest, 1483 TEST_P(QuicConnectionTest,
1473 DISABLED_SendingDifferentSequenceNumberLengthsUnackedDelta) { 1484 DISABLED_SendingDifferentSequenceNumberLengthsUnackedDelta) {
1474 QuicPacketSequenceNumber last_packet; 1485 QuicPacketSequenceNumber last_packet;
1475 QuicPacketCreator* creator =
1476 QuicConnectionPeer::GetPacketCreator(&connection_);
1477 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); 1486 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet);
1478 EXPECT_EQ(1u, last_packet); 1487 EXPECT_EQ(1u, last_packet);
1479 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, 1488 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER,
1480 creator->next_sequence_number_length()); 1489 creator_->next_sequence_number_length());
1481 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, 1490 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER,
1482 writer_->header().public_header.sequence_number_length); 1491 writer_->header().public_header.sequence_number_length);
1483 1492
1484 creator->set_sequence_number(100); 1493 creator_->set_sequence_number(100);
1485 1494
1486 SendStreamDataToPeer(1, "bar", 3, !kFin, &last_packet); 1495 SendStreamDataToPeer(1, "bar", 3, !kFin, &last_packet);
1487 EXPECT_EQ(PACKET_2BYTE_SEQUENCE_NUMBER, 1496 EXPECT_EQ(PACKET_2BYTE_SEQUENCE_NUMBER,
1488 creator->next_sequence_number_length()); 1497 creator_->next_sequence_number_length());
1489 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, 1498 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER,
1490 writer_->header().public_header.sequence_number_length); 1499 writer_->header().public_header.sequence_number_length);
1491 1500
1492 creator->set_sequence_number(100 * 256); 1501 creator_->set_sequence_number(100 * 256);
1493 1502
1494 SendStreamDataToPeer(1, "foo", 6, !kFin, &last_packet); 1503 SendStreamDataToPeer(1, "foo", 6, !kFin, &last_packet);
1495 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, 1504 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER,
1496 creator->next_sequence_number_length()); 1505 creator_->next_sequence_number_length());
1497 EXPECT_EQ(PACKET_2BYTE_SEQUENCE_NUMBER, 1506 EXPECT_EQ(PACKET_2BYTE_SEQUENCE_NUMBER,
1498 writer_->header().public_header.sequence_number_length); 1507 writer_->header().public_header.sequence_number_length);
1499 1508
1500 creator->set_sequence_number(100 * 256 * 256); 1509 creator_->set_sequence_number(100 * 256 * 256);
1501 1510
1502 SendStreamDataToPeer(1, "bar", 9, !kFin, &last_packet); 1511 SendStreamDataToPeer(1, "bar", 9, !kFin, &last_packet);
1503 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, 1512 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER,
1504 creator->next_sequence_number_length()); 1513 creator_->next_sequence_number_length());
1505 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, 1514 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER,
1506 writer_->header().public_header.sequence_number_length); 1515 writer_->header().public_header.sequence_number_length);
1507 1516
1508 creator->set_sequence_number(100 * 256 * 256 * 256); 1517 creator_->set_sequence_number(100 * 256 * 256 * 256);
1509 1518
1510 SendStreamDataToPeer(1, "foo", 12, !kFin, &last_packet); 1519 SendStreamDataToPeer(1, "foo", 12, !kFin, &last_packet);
1511 EXPECT_EQ(PACKET_6BYTE_SEQUENCE_NUMBER, 1520 EXPECT_EQ(PACKET_6BYTE_SEQUENCE_NUMBER,
1512 creator->next_sequence_number_length()); 1521 creator_->next_sequence_number_length());
1513 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, 1522 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER,
1514 writer_->header().public_header.sequence_number_length); 1523 writer_->header().public_header.sequence_number_length);
1515 } 1524 }
1516 1525
1517 TEST_P(QuicConnectionTest, BasicSending) { 1526 TEST_P(QuicConnectionTest, BasicSending) {
1518 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1527 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1519 QuicPacketSequenceNumber last_packet; 1528 QuicPacketSequenceNumber last_packet;
1520 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 1529 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1
1521 EXPECT_EQ(1u, last_packet); 1530 EXPECT_EQ(1u, last_packet);
1522 SendAckPacketToPeer(); // Packet 2 1531 SendAckPacketToPeer(); // Packet 2
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1628 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 1637 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
1629 .WillOnce(DoAll(SaveArg<0>(&actual_recorded_send_time), Return(true))); 1638 .WillOnce(DoAll(SaveArg<0>(&actual_recorded_send_time), Return(true)));
1630 connection_.SendStreamDataWithString(2, "baz", 0, !kFin, nullptr); 1639 connection_.SendStreamDataWithString(2, "baz", 0, !kFin, nullptr);
1631 EXPECT_EQ(expected_recorded_send_time, actual_recorded_send_time) 1640 EXPECT_EQ(expected_recorded_send_time, actual_recorded_send_time)
1632 << "Expected time = " << expected_recorded_send_time.ToDebuggingValue() 1641 << "Expected time = " << expected_recorded_send_time.ToDebuggingValue()
1633 << ". Actual time = " << actual_recorded_send_time.ToDebuggingValue(); 1642 << ". Actual time = " << actual_recorded_send_time.ToDebuggingValue();
1634 } 1643 }
1635 1644
1636 TEST_P(QuicConnectionTest, FECSending) { 1645 TEST_P(QuicConnectionTest, FECSending) {
1637 // All packets carry version info till version is negotiated. 1646 // All packets carry version info till version is negotiated.
1638 QuicPacketCreator* creator =
1639 QuicConnectionPeer::GetPacketCreator(&connection_);
1640 size_t payload_length; 1647 size_t payload_length;
1641 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining 1648 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining
1642 // packet length. The size of the offset field in a stream frame is 0 for 1649 // packet length. The size of the offset field in a stream frame is 0 for
1643 // offset 0, and 2 for non-zero offsets up through 64K. Increase 1650 // offset 0, and 2 for non-zero offsets up through 64K. Increase
1644 // max_packet_length by 2 so that subsequent packets containing subsequent 1651 // max_packet_length by 2 so that subsequent packets containing subsequent
1645 // stream frames with non-zero offets will fit within the packet length. 1652 // stream frames with non-zero offets will fit within the packet length.
1646 size_t length = 2 + GetPacketLengthForOneStream( 1653 size_t length = 2 + GetPacketLengthForOneStream(
1647 connection_.version(), kIncludeVersion, 1654 connection_.version(), kIncludeVersion,
1648 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, 1655 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER,
1649 IN_FEC_GROUP, &payload_length); 1656 IN_FEC_GROUP, &payload_length);
1650 creator->set_max_packet_length(length); 1657 creator_->set_max_packet_length(length);
1651 1658
1652 // Send 4 protected data packets, which should also trigger 1 FEC packet. 1659 // Send 4 protected data packets, which should also trigger 1 FEC packet.
1653 EXPECT_CALL(*send_algorithm_, 1660 EXPECT_CALL(*send_algorithm_,
1654 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(5); 1661 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(5);
1655 // The first stream frame will have 2 fewer overhead bytes than the other 3. 1662 // The first stream frame will have 2 fewer overhead bytes than the other 3.
1656 const string payload(payload_length * 4 + 2, 'a'); 1663 const string payload(payload_length * 4 + 2, 'a');
1657 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, nullptr); 1664 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, nullptr);
1658 // Expect the FEC group to be closed after SendStreamDataWithString. 1665 // Expect the FEC group to be closed after SendStreamDataWithString.
1659 EXPECT_FALSE(creator->IsFecGroupOpen()); 1666 EXPECT_FALSE(creator_->IsFecGroupOpen());
1660 EXPECT_FALSE(creator->IsFecProtected()); 1667 EXPECT_FALSE(creator_->IsFecProtected());
1661 } 1668 }
1662 1669
1663 TEST_P(QuicConnectionTest, FECQueueing) { 1670 TEST_P(QuicConnectionTest, FECQueueing) {
1664 // All packets carry version info till version is negotiated. 1671 // All packets carry version info till version is negotiated.
1665 size_t payload_length; 1672 size_t payload_length;
1666 QuicPacketCreator* creator =
1667 QuicConnectionPeer::GetPacketCreator(&connection_);
1668 size_t length = GetPacketLengthForOneStream( 1673 size_t length = GetPacketLengthForOneStream(
1669 connection_.version(), kIncludeVersion, 1674 connection_.version(), kIncludeVersion,
1670 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, 1675 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER,
1671 IN_FEC_GROUP, &payload_length); 1676 IN_FEC_GROUP, &payload_length);
1672 creator->set_max_packet_length(length); 1677 creator_->set_max_packet_length(length);
1673 EXPECT_TRUE(creator->IsFecEnabled()); 1678 EXPECT_TRUE(creator_->IsFecEnabled());
1674 1679
1675 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1680 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1676 BlockOnNextWrite(); 1681 BlockOnNextWrite();
1677 const string payload(payload_length, 'a'); 1682 const string payload(payload_length, 'a');
1678 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, nullptr); 1683 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, nullptr);
1679 EXPECT_FALSE(creator->IsFecGroupOpen()); 1684 EXPECT_FALSE(creator_->IsFecGroupOpen());
1680 EXPECT_FALSE(creator->IsFecProtected()); 1685 EXPECT_FALSE(creator_->IsFecProtected());
1681 // Expect the first data packet and the fec packet to be queued. 1686 // Expect the first data packet and the fec packet to be queued.
1682 EXPECT_EQ(2u, connection_.NumQueuedPackets()); 1687 EXPECT_EQ(2u, connection_.NumQueuedPackets());
1683 } 1688 }
1684 1689
1690 TEST_P(QuicConnectionTest, FECAlarmStoppedWhenFECPacketSent) {
1691 EXPECT_TRUE(creator_->IsFecEnabled());
1692 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1693 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet());
1694
1695 creator_->set_max_packets_per_fec_group(2);
1696
1697 // 1 Data packet. FEC alarm should be set.
1698 EXPECT_CALL(*send_algorithm_,
1699 OnPacketSent(_, _, 1u, _, HAS_RETRANSMITTABLE_DATA)).Times(1);
1700 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, true, nullptr);
1701 EXPECT_TRUE(connection_.GetFecAlarm()->IsSet());
1702
1703 // Second data packet triggers FEC packet out. FEC alarm should not be set.
1704 EXPECT_CALL(*send_algorithm_,
1705 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(2);
1706 connection_.SendStreamDataWithStringWithFec(5, "foo", 0, true, nullptr);
1707 EXPECT_TRUE(writer_->header().fec_flag);
1708 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet());
1709 }
1710
1711 TEST_P(QuicConnectionTest, FECAlarmStoppedOnConnectionClose) {
1712 EXPECT_TRUE(creator_->IsFecEnabled());
1713 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet());
1714 creator_->set_max_packets_per_fec_group(100);
1715
1716 // 1 Data packet. FEC alarm should be set.
1717 EXPECT_CALL(*send_algorithm_,
1718 OnPacketSent(_, _, 1u, _, HAS_RETRANSMITTABLE_DATA)).Times(1);
1719 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, kFin, nullptr);
1720 EXPECT_TRUE(connection_.GetFecAlarm()->IsSet());
1721
1722 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_NO_ERROR, false));
1723 // Closing connection should stop the FEC alarm.
1724 connection_.CloseConnection(QUIC_NO_ERROR, /*from_peer=*/false);
1725 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet());
1726 }
1727
1685 TEST_P(QuicConnectionTest, RemoveFECFromInflightOnRetransmissionTimeout) { 1728 TEST_P(QuicConnectionTest, RemoveFECFromInflightOnRetransmissionTimeout) {
1686 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1729 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1687 EXPECT_TRUE(QuicConnectionPeer::GetPacketCreator( 1730 EXPECT_TRUE(creator_->IsFecEnabled());
1688 &connection_)->IsFecEnabled()); 1731 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1689 QuicSentPacketManager* manager = 1732 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet());
1690 QuicConnectionPeer::GetSentPacketManager(&connection_);
1691 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager));
1692 1733
1693 // 1 Data and 1 FEC packet. 1734 // 1 Data packet. FEC alarm should be set.
1694 EXPECT_CALL(*send_algorithm_, 1735 EXPECT_CALL(*send_algorithm_,
1695 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(2); 1736 OnPacketSent(_, _, 1u, _, HAS_RETRANSMITTABLE_DATA)).Times(1);
1696 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, nullptr); 1737 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, nullptr);
1697 size_t data_and_fec = QuicSentPacketManagerPeer::GetBytesInFlight(manager); 1738 EXPECT_TRUE(connection_.GetFecAlarm()->IsSet());
1698 EXPECT_LT(0u, data_and_fec); 1739 size_t protected_packet =
1740 QuicSentPacketManagerPeer::GetBytesInFlight(manager_);
1699 1741
1742 // Force FEC timeout to send FEC packet out.
1743 EXPECT_CALL(*send_algorithm_,
1744 OnPacketSent(_, _, 2u, _, HAS_RETRANSMITTABLE_DATA)).Times(1);
1745 connection_.GetFecAlarm()->Fire();
1746 EXPECT_TRUE(writer_->header().fec_flag);
1747
1748 size_t fec_packet = protected_packet;
1749 EXPECT_EQ(protected_packet + fec_packet,
1750 QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1700 clock_.AdvanceTime(DefaultRetransmissionTime()); 1751 clock_.AdvanceTime(DefaultRetransmissionTime());
1701 1752
1702 // On RTO, both data and FEC packets are removed from inflight, 1753 // On RTO, both data and FEC packets are removed from inflight, only the data
1703 // and retransmission of the data (but not FEC) gets added into the inflight. 1754 // packet is retransmitted, and this retransmission (but not FEC) gets added
1755 // back into the inflight.
1704 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 1756 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
1705 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 1757 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
1706 connection_.GetRetransmissionAlarm()->Fire(); 1758 connection_.GetRetransmissionAlarm()->Fire();
1707 1759
1708 size_t data_only = QuicSentPacketManagerPeer::GetBytesInFlight(manager); 1760 // The retransmission of packet 1 will be 3 bytes smaller than packet 1, since
1709 EXPECT_LT(0u, data_only); 1761 // the first transmission will have 1 byte for FEC group number and 2 bytes of
1710 EXPECT_GE(data_and_fec, 2 * data_only); 1762 // stream frame size, which are absent in the retransmission.
1763 size_t retransmitted_packet = protected_packet - 3;
1764 if (FLAGS_quic_use_new_rto) {
1765 EXPECT_EQ(protected_packet + retransmitted_packet,
1766 QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1767 } else {
1768 EXPECT_EQ(retransmitted_packet,
1769 QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1770 }
1771 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet());
1711 1772
1712 // Receive ack for the retransmission. No data should be outstanding. 1773 // Receive ack for the retransmission. No data should be outstanding.
1713 QuicAckFrame ack = InitAckFrame(3); 1774 QuicAckFrame ack = InitAckFrame(3);
1714 NackPacket(1, &ack); 1775 NackPacket(1, &ack);
1715 NackPacket(2, &ack); 1776 NackPacket(2, &ack);
1716 SequenceNumberSet lost_packets; 1777 SequenceNumberSet lost_packets;
1778 if (FLAGS_quic_use_new_rto) {
1779 lost_packets.insert(1);
1780 }
1717 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 1781 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
1718 .WillOnce(Return(lost_packets)); 1782 .WillOnce(Return(lost_packets));
1719 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 1783 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
1720 ProcessAckPacket(&ack); 1784 ProcessAckPacket(&ack);
1721 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager));
1722 1785
1723 // Ensure the alarm is not set since all packets have been acked or abandoned. 1786 // Ensure the alarm is not set since all packets have been acked or abandoned.
1724 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 1787 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
1725 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager)); 1788 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1726 } 1789 }
1727 1790
1728 TEST_P(QuicConnectionTest, RemoveFECFromInflightOnLossRetransmission) { 1791 TEST_P(QuicConnectionTest, RemoveFECFromInflightOnLossRetransmission) {
1729 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1792 EXPECT_TRUE(creator_->IsFecEnabled());
1730 EXPECT_TRUE(QuicConnectionPeer::GetPacketCreator( 1793 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet());
1731 &connection_)->IsFecEnabled());
1732 QuicSentPacketManager* manager =
1733 QuicConnectionPeer::GetSentPacketManager(&connection_);
1734 1794
1735 // 1 Data packet and 1 FEC packet, followed by more data to trigger NACKs. 1795 // 1 FEC-protected data packet. FEC alarm should be set.
1736 EXPECT_CALL(*send_algorithm_, 1796 EXPECT_CALL(*send_algorithm_,
1737 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(6); 1797 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(1);
1738 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, nullptr); 1798 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, kFin, nullptr);
1739 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, nullptr); 1799 EXPECT_TRUE(connection_.GetFecAlarm()->IsSet());
1740 connection_.SendStreamDataWithString(3, "foo", 6, !kFin, nullptr); 1800 size_t protected_packet =
1741 connection_.SendStreamDataWithString(3, "foo", 9, !kFin, nullptr); 1801 QuicSentPacketManagerPeer::GetBytesInFlight(manager_);
1742 connection_.SendStreamDataWithString(3, "foo", 12, !kFin, nullptr);
1743 size_t multiple_data_and_fec =
1744 QuicSentPacketManagerPeer::GetBytesInFlight(manager);
1745 EXPECT_LT(0u, multiple_data_and_fec);
1746 1802
1747 // Ack data packets, and NACK 1 data packet and FEC packet. Triggers 1803 // Force FEC timeout to send FEC packet out.
1748 // NACK-based loss detection of data and FEC packet, but only data is 1804 EXPECT_CALL(*send_algorithm_,
1805 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(1);
1806 connection_.GetFecAlarm()->Fire();
1807 EXPECT_TRUE(writer_->header().fec_flag);
1808 size_t fec_packet = protected_packet;
1809 EXPECT_EQ(protected_packet + fec_packet,
1810 QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1811
1812 // Send more data to trigger NACKs. Note that all data starts at stream offset
1813 // 0 to ensure the same packet size, for ease of testing.
1814 EXPECT_CALL(*send_algorithm_,
1815 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(4);
1816 connection_.SendStreamDataWithString(5, "foo", 0, kFin, nullptr);
1817 connection_.SendStreamDataWithString(7, "foo", 0, kFin, nullptr);
1818 connection_.SendStreamDataWithString(9, "foo", 0, kFin, nullptr);
1819 connection_.SendStreamDataWithString(11, "foo", 0, kFin, nullptr);
1820
1821 // An unprotected packet will be 3 bytes smaller than an FEC-protected packet,
1822 // since the protected packet will have 1 byte for FEC group number and
1823 // 2 bytes of stream frame size, which are absent in the unprotected packet.
1824 size_t unprotected_packet = protected_packet - 3;
1825 EXPECT_EQ(protected_packet + fec_packet + 4 * unprotected_packet,
1826 QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1827 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet());
1828
1829 // Ack data packets, and NACK FEC packet and one data packet. Triggers
1830 // NACK-based loss detection of both packets, but only data packet is
1749 // retransmitted and considered oustanding. 1831 // retransmitted and considered oustanding.
1750 QuicAckFrame ack = InitAckFrame(6); 1832 QuicAckFrame ack = InitAckFrame(6);
1751 NackPacket(2, &ack); 1833 NackPacket(2, &ack);
1752 NackPacket(3, &ack); 1834 NackPacket(3, &ack);
1753 SequenceNumberSet lost_packets; 1835 SequenceNumberSet lost_packets;
1754 lost_packets.insert(2); 1836 lost_packets.insert(2);
1755 lost_packets.insert(3); 1837 lost_packets.insert(3);
1756 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 1838 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
1757 .WillOnce(Return(lost_packets)); 1839 .WillOnce(Return(lost_packets));
1758 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 1840 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
1759 EXPECT_CALL(*send_algorithm_, 1841 EXPECT_CALL(*send_algorithm_,
1760 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(1); 1842 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(1);
1843 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1761 ProcessAckPacket(&ack); 1844 ProcessAckPacket(&ack);
1762 size_t data_only = QuicSentPacketManagerPeer::GetBytesInFlight(manager); 1845 // On receiving this ack from the server, the client will no longer send
1763 EXPECT_GT(multiple_data_and_fec, data_only); 1846 // version number in subsequent packets, including in this retransmission.
1764 EXPECT_LT(0u, data_only); 1847 size_t unprotected_packet_no_version = unprotected_packet - 4;
1848 EXPECT_EQ(unprotected_packet_no_version,
1849 QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1765 1850
1766 // Receive ack for the retransmission. No data should be outstanding. 1851 // Receive ack for the retransmission. No data should be outstanding.
1767 QuicAckFrame ack2 = InitAckFrame(7); 1852 QuicAckFrame ack2 = InitAckFrame(7);
1768 NackPacket(2, &ack2); 1853 NackPacket(2, &ack2);
1769 NackPacket(3, &ack2); 1854 NackPacket(3, &ack2);
1770 SequenceNumberSet lost_packets2; 1855 SequenceNumberSet lost_packets2;
1771 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 1856 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
1772 .WillOnce(Return(lost_packets2)); 1857 .WillOnce(Return(lost_packets2));
1773 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 1858 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
1774 ProcessAckPacket(&ack2); 1859 ProcessAckPacket(&ack2);
1775 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager)); 1860 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1861 }
1862
1863 TEST_P(QuicConnectionTest, FECRemainsInflightOnTLPOfEarlierData) {
1864 // This test checks if TLP is sent correctly when a data and an FEC packet
1865 // are outstanding. TLP should be sent for the data packet when the
1866 // retransmission alarm fires.
1867 // Turn on TLP for this test.
1868 QuicSentPacketManagerPeer::SetMaxTailLossProbes(manager_, 1);
1869 EXPECT_TRUE(creator_->IsFecEnabled());
1870 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1871 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet());
1872
1873 // 1 Data packet. FEC alarm should be set.
1874 EXPECT_CALL(*send_algorithm_,
1875 OnPacketSent(_, _, 1u, _, HAS_RETRANSMITTABLE_DATA)).Times(1);
1876 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, kFin, nullptr);
1877 EXPECT_TRUE(connection_.GetFecAlarm()->IsSet());
1878 size_t protected_packet =
1879 QuicSentPacketManagerPeer::GetBytesInFlight(manager_);
1880 EXPECT_LT(0u, protected_packet);
1881
1882 // Force FEC timeout to send FEC packet out.
1883 EXPECT_CALL(*send_algorithm_,
1884 OnPacketSent(_, _, 2u, _, HAS_RETRANSMITTABLE_DATA)).Times(1);
1885 connection_.GetFecAlarm()->Fire();
1886 EXPECT_TRUE(writer_->header().fec_flag);
1887 size_t fec_packet = protected_packet;
1888 EXPECT_EQ(protected_packet + fec_packet,
1889 QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1890
1891 // TLP alarm should be set.
1892 QuicTime retransmission_time =
1893 connection_.GetRetransmissionAlarm()->deadline();
1894 EXPECT_NE(QuicTime::Zero(), retransmission_time);
1895 // Simulate the retransmission alarm firing and sending a TLP, so send
1896 // algorithm's OnRetransmissionTimeout is not called.
1897 clock_.AdvanceTime(retransmission_time.Subtract(clock_.Now()));
1898 EXPECT_CALL(*send_algorithm_,
1899 OnPacketSent(_, _, 3u, _, HAS_RETRANSMITTABLE_DATA)).Times(1);
1900 connection_.GetRetransmissionAlarm()->Fire();
1901 // The TLP retransmission of packet 1 will be 3 bytes smaller than packet 1,
1902 // since packet 1 will have 1 byte for FEC group number and 2 bytes of stream
1903 // frame size, which are absent in the the TLP retransmission.
1904 size_t tlp_packet = protected_packet - 3;
1905 EXPECT_EQ(protected_packet + fec_packet + tlp_packet,
1906 QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1907 }
1908
1909 TEST_P(QuicConnectionTest, FECRemainsInflightOnTLPOfLaterData) {
1910 // Tests if TLP is sent correctly when data packet 1 and an FEC packet are
1911 // sent followed by data packet 2, and data packet 1 is acked. TLP should be
1912 // sent for data packet 2 when the retransmission alarm fires. Turn on TLP for
1913 // this test.
1914 QuicSentPacketManagerPeer::SetMaxTailLossProbes(manager_, 1);
1915 EXPECT_TRUE(creator_->IsFecEnabled());
1916 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1917 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet());
1918
1919 // 1 Data packet. FEC alarm should be set.
1920 EXPECT_CALL(*send_algorithm_,
1921 OnPacketSent(_, _, 1u, _, HAS_RETRANSMITTABLE_DATA)).Times(1);
1922 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, kFin, nullptr);
1923 EXPECT_TRUE(connection_.GetFecAlarm()->IsSet());
1924 size_t protected_packet =
1925 QuicSentPacketManagerPeer::GetBytesInFlight(manager_);
1926 EXPECT_LT(0u, protected_packet);
1927
1928 // Force FEC timeout to send FEC packet out.
1929 EXPECT_CALL(*send_algorithm_,
1930 OnPacketSent(_, _, 2u, _, HAS_RETRANSMITTABLE_DATA)).Times(1);
1931 connection_.GetFecAlarm()->Fire();
1932 EXPECT_TRUE(writer_->header().fec_flag);
1933 // Protected data packet and FEC packet oustanding.
1934 size_t fec_packet = protected_packet;
1935 EXPECT_EQ(protected_packet + fec_packet,
1936 QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1937
1938 // Send 1 unprotected data packet. No FEC alarm should be set.
1939 EXPECT_CALL(*send_algorithm_,
1940 OnPacketSent(_, _, 3u, _, HAS_RETRANSMITTABLE_DATA)).Times(1);
1941 connection_.SendStreamDataWithString(5, "foo", 0, kFin, nullptr);
1942 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet());
1943 // Protected data packet, FEC packet, and unprotected data packet oustanding.
1944 // An unprotected packet will be 3 bytes smaller than an FEC-protected packet,
1945 // since the protected packet will have 1 byte for FEC group number and
1946 // 2 bytes of stream frame size, which are absent in the unprotected packet.
1947 size_t unprotected_packet = protected_packet - 3;
1948 EXPECT_EQ(protected_packet + fec_packet + unprotected_packet,
1949 QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1950
1951 // Receive ack for first data packet. FEC and second data packet are still
1952 // outstanding.
1953 QuicAckFrame ack = InitAckFrame(1);
1954 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
1955 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1956 ProcessAckPacket(&ack);
1957 // FEC packet and unprotected data packet oustanding.
1958 EXPECT_EQ(fec_packet + unprotected_packet,
1959 QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1960
1961 // TLP alarm should be set.
1962 QuicTime retransmission_time =
1963 connection_.GetRetransmissionAlarm()->deadline();
1964 EXPECT_NE(QuicTime::Zero(), retransmission_time);
1965 // Simulate the retransmission alarm firing and sending a TLP, so send
1966 // algorithm's OnRetransmissionTimeout is not called.
1967 clock_.AdvanceTime(retransmission_time.Subtract(clock_.Now()));
1968 EXPECT_CALL(*send_algorithm_,
1969 OnPacketSent(_, _, 4u, _, HAS_RETRANSMITTABLE_DATA)).Times(1);
1970 connection_.GetRetransmissionAlarm()->Fire();
1971
1972 // Having received an ack from the server, the client will no longer send
1973 // version number in subsequent packets, including in this retransmission.
1974 size_t tlp_packet_no_version = unprotected_packet - 4;
1975 EXPECT_EQ(fec_packet + unprotected_packet + tlp_packet_no_version,
1976 QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1776 } 1977 }
1777 1978
1778 TEST_P(QuicConnectionTest, NoTLPForFECPacket) { 1979 TEST_P(QuicConnectionTest, NoTLPForFECPacket) {
1779 // Turn on TLP for this test. 1980 // Turn on TLP for this test.
1780 QuicSentPacketManagerPeer::SetMaxTailLossProbes( 1981 QuicSentPacketManagerPeer::SetMaxTailLossProbes(manager_, 1);
1781 QuicConnectionPeer::GetSentPacketManager(&connection_), 1); 1982 EXPECT_TRUE(creator_->IsFecEnabled());
1983 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1782 1984
1783 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1985 // Send 1 FEC-protected data packet. FEC alarm should be set.
1784 EXPECT_TRUE(QuicConnectionPeer::GetPacketCreator(
1785 &connection_)->IsFecEnabled());
1786 QuicSentPacketManager* manager =
1787 QuicConnectionPeer::GetSentPacketManager(&connection_);
1788
1789 // 1 Data packet and 1 FEC packet.
1790 EXPECT_CALL(*send_algorithm_, 1986 EXPECT_CALL(*send_algorithm_,
1791 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(2); 1987 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(1);
1792 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, nullptr); 1988 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, nullptr);
1989 EXPECT_TRUE(connection_.GetFecAlarm()->IsSet());
1990 // Force FEC timeout to send FEC packet out.
1991 EXPECT_CALL(*send_algorithm_,
1992 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(1);
1993 connection_.GetFecAlarm()->Fire();
1994 EXPECT_TRUE(writer_->header().fec_flag);
1793 1995
1794 // Ack data packet, but not FEC packet. 1996 // Ack data packet, but not FEC packet.
1795 QuicAckFrame ack = InitAckFrame(1); 1997 QuicAckFrame ack = InitAckFrame(1);
1796 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 1998 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
1797 ProcessAckPacket(&ack); 1999 ProcessAckPacket(&ack);
1798 2000
1799 // No TLP alarm for FEC, so when retransmission alarm fires, it is an RTO. 2001 // No TLP alarm for FEC, but retransmission alarm should be set for an RTO.
2002 EXPECT_LT(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1800 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 2003 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
1801 EXPECT_LT(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager));
1802 QuicTime rto_time = connection_.GetRetransmissionAlarm()->deadline(); 2004 QuicTime rto_time = connection_.GetRetransmissionAlarm()->deadline();
1803 EXPECT_NE(QuicTime::Zero(), rto_time); 2005 EXPECT_NE(QuicTime::Zero(), rto_time);
1804 2006
1805 // Simulate the retransmission alarm firing. FEC packet is no longer 2007 // Simulate the retransmission alarm firing. FEC packet is no longer
1806 // outstanding. 2008 // outstanding.
1807 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(false)); 2009 if (!FLAGS_quic_use_new_rto) {
2010 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(false));
2011 }
1808 clock_.AdvanceTime(rto_time.Subtract(clock_.Now())); 2012 clock_.AdvanceTime(rto_time.Subtract(clock_.Now()));
1809 connection_.GetRetransmissionAlarm()->Fire(); 2013 connection_.GetRetransmissionAlarm()->Fire();
2014
1810 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 2015 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
1811 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager)); 2016 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1812 } 2017 }
1813 2018
1814 TEST_P(QuicConnectionTest, FramePacking) { 2019 TEST_P(QuicConnectionTest, FramePacking) {
1815 CongestionBlockWrites(); 2020 CongestionBlockWrites();
1816 2021
1817 // Send an ack and two stream frames in 1 packet by queueing them. 2022 // Send an ack and two stream frames in 1 packet by queueing them.
1818 connection_.SendAck(); 2023 connection_.SendAck();
1819 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( 2024 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll(
1820 IgnoreResult(InvokeWithoutArgs(&connection_, 2025 IgnoreResult(InvokeWithoutArgs(&connection_,
1821 &TestConnection::SendStreamData3)), 2026 &TestConnection::SendStreamData3)),
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1880 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2085 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1881 EXPECT_FALSE(connection_.HasQueuedData()); 2086 EXPECT_FALSE(connection_.HasQueuedData());
1882 2087
1883 // Parse the last packet and ensure it's the stream frame from stream 3. 2088 // Parse the last packet and ensure it's the stream frame from stream 3.
1884 EXPECT_EQ(1u, writer_->frame_count()); 2089 EXPECT_EQ(1u, writer_->frame_count());
1885 ASSERT_EQ(1u, writer_->stream_frames().size()); 2090 ASSERT_EQ(1u, writer_->stream_frames().size());
1886 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0].stream_id); 2091 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0].stream_id);
1887 } 2092 }
1888 2093
1889 TEST_P(QuicConnectionTest, FramePackingFEC) { 2094 TEST_P(QuicConnectionTest, FramePackingFEC) {
1890 EXPECT_TRUE(QuicConnectionPeer::GetPacketCreator( 2095 EXPECT_TRUE(creator_->IsFecEnabled());
1891 &connection_)->IsFecEnabled());
1892 2096
1893 CongestionBlockWrites(); 2097 CongestionBlockWrites();
1894 2098
1895 // Queue an ack and two stream frames. Ack gets flushed when FEC is turned on 2099 // Queue an ack and two stream frames. Ack gets flushed when FEC is turned on
1896 // for sending protected data; two stream frames are packing in 1 packet. 2100 // for sending protected data; two stream frames are packed in 1 packet.
1897 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( 2101 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll(
1898 IgnoreResult(InvokeWithoutArgs( 2102 IgnoreResult(InvokeWithoutArgs(
1899 &connection_, &TestConnection::SendStreamData3WithFec)), 2103 &connection_, &TestConnection::SendStreamData3WithFec)),
1900 IgnoreResult(InvokeWithoutArgs( 2104 IgnoreResult(InvokeWithoutArgs(
1901 &connection_, &TestConnection::SendStreamData5WithFec)))); 2105 &connection_, &TestConnection::SendStreamData5WithFec))));
1902 connection_.SendAck(); 2106 connection_.SendAck();
1903 2107
1904 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3); 2108 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
1905 CongestionUnblockWrites(); 2109 CongestionUnblockWrites();
1906 connection_.GetSendAlarm()->Fire(); 2110 connection_.GetSendAlarm()->Fire();
1907 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2111 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1908 EXPECT_FALSE(connection_.HasQueuedData()); 2112 EXPECT_FALSE(connection_.HasQueuedData());
1909 2113
1910 // Parse the last packet and ensure it's in an fec group. 2114 // Parse the last packet and ensure it's in an fec group.
1911 EXPECT_EQ(2u, writer_->header().fec_group); 2115 EXPECT_EQ(2u, writer_->header().fec_group);
1912 EXPECT_EQ(0u, writer_->frame_count()); 2116 EXPECT_EQ(2u, writer_->frame_count());
2117
2118 // FEC alarm should be set.
2119 EXPECT_TRUE(connection_.GetFecAlarm()->IsSet());
1913 } 2120 }
1914 2121
1915 TEST_P(QuicConnectionTest, FramePackingAckResponse) { 2122 TEST_P(QuicConnectionTest, FramePackingAckResponse) {
1916 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2123 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1917 // Process a data packet to queue up a pending ack. 2124 // Process a data packet to queue up a pending ack.
1918 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); 2125 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1);
1919 ProcessDataPacket(1, 1, kEntropyFlag); 2126 ProcessDataPacket(1, 1, kEntropyFlag);
1920 2127
1921 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( 2128 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll(
1922 IgnoreResult(InvokeWithoutArgs(&connection_, 2129 IgnoreResult(InvokeWithoutArgs(&connection_,
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
2122 OnPacketSent(_, _, _, packet_size - kQuicVersionSize, _)); 2329 OnPacketSent(_, _, _, packet_size - kQuicVersionSize, _));
2123 ProcessAckPacket(&frame); 2330 ProcessAckPacket(&frame);
2124 } 2331 }
2125 2332
2126 TEST_P(QuicConnectionTest, QueueAfterTwoRTOs) { 2333 TEST_P(QuicConnectionTest, QueueAfterTwoRTOs) {
2127 for (int i = 0; i < 10; ++i) { 2334 for (int i = 0; i < 10; ++i) {
2128 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2335 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2129 connection_.SendStreamDataWithString(3, "foo", i * 3, !kFin, nullptr); 2336 connection_.SendStreamDataWithString(3, "foo", i * 3, !kFin, nullptr);
2130 } 2337 }
2131 2338
2132 // Block the congestion window and ensure they're queued. 2339 // Block the writer and ensure they're queued.
2133 BlockOnNextWrite(); 2340 BlockOnNextWrite();
2134 clock_.AdvanceTime(DefaultRetransmissionTime()); 2341 clock_.AdvanceTime(DefaultRetransmissionTime());
2135 // Only one packet should be retransmitted. 2342 // Only one packet should be retransmitted.
2136 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 2343 if (!FLAGS_quic_use_new_rto) {
2344 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
2345 }
2137 connection_.GetRetransmissionAlarm()->Fire(); 2346 connection_.GetRetransmissionAlarm()->Fire();
2138 EXPECT_TRUE(connection_.HasQueuedData()); 2347 EXPECT_TRUE(connection_.HasQueuedData());
2139 2348
2140 // Unblock the congestion window. 2349 // Unblock the writer.
2141 writer_->SetWritable(); 2350 writer_->SetWritable();
2142 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds( 2351 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(
2143 2 * DefaultRetransmissionTime().ToMicroseconds())); 2352 2 * DefaultRetransmissionTime().ToMicroseconds()));
2144 // Retransmit already retransmitted packets event though the sequence number 2353 // Retransmit already retransmitted packets event though the sequence number
2145 // greater than the largest observed. 2354 // greater than the largest observed.
2146 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(10); 2355 if (FLAGS_quic_use_new_rto) {
2356 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
2357 } else {
2358 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(10);
2359 }
2147 connection_.GetRetransmissionAlarm()->Fire(); 2360 connection_.GetRetransmissionAlarm()->Fire();
2148 connection_.OnCanWrite(); 2361 connection_.OnCanWrite();
2149 } 2362 }
2150 2363
2151 TEST_P(QuicConnectionTest, WriteBlockedThenSent) { 2364 TEST_P(QuicConnectionTest, WriteBlockedThenSent) {
2152 BlockOnNextWrite(); 2365 BlockOnNextWrite();
2153 writer_->set_is_write_blocked_data_buffered(true); 2366 writer_->set_is_write_blocked_data_buffered(true);
2154 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2367 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2155 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); 2368 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr);
2156 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 2369 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
2157 2370
2158 writer_->SetWritable(); 2371 writer_->SetWritable();
2159 connection_.OnCanWrite(); 2372 connection_.OnCanWrite();
2160 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 2373 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
2161 } 2374 }
2162 2375
2163 TEST_P(QuicConnectionTest, RetransmitWriteBlockedAckedOriginalThenSent) { 2376 TEST_P(QuicConnectionTest, RetransmitWriteBlockedAckedOriginalThenSent) {
2164 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2377 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2165 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); 2378 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr);
2166 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 2379 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
2167 2380
2168 BlockOnNextWrite(); 2381 BlockOnNextWrite();
2169 writer_->set_is_write_blocked_data_buffered(true); 2382 writer_->set_is_write_blocked_data_buffered(true);
2170 // Simulate the retransmission alarm firing. 2383 // Simulate the retransmission alarm firing.
2171 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(_)); 2384 if (!FLAGS_quic_use_new_rto) {
2385 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(_));
2386 }
2172 clock_.AdvanceTime(DefaultRetransmissionTime()); 2387 clock_.AdvanceTime(DefaultRetransmissionTime());
2173 connection_.GetRetransmissionAlarm()->Fire(); 2388 connection_.GetRetransmissionAlarm()->Fire();
2174 2389
2175 // Ack the sent packet before the callback returns, which happens in 2390 // Ack the sent packet before the callback returns, which happens in
2176 // rare circumstances with write blocked sockets. 2391 // rare circumstances with write blocked sockets.
2177 QuicAckFrame ack = InitAckFrame(1); 2392 QuicAckFrame ack = InitAckFrame(1);
2178 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 2393 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
2179 EXPECT_CALL(*send_algorithm_, RevertRetransmissionTimeout()); 2394 if (!FLAGS_quic_use_new_rto) {
2395 EXPECT_CALL(*send_algorithm_, RevertRetransmissionTimeout());
2396 }
2180 ProcessAckPacket(&ack); 2397 ProcessAckPacket(&ack);
2181 2398
2182 writer_->SetWritable(); 2399 writer_->SetWritable();
2183 connection_.OnCanWrite(); 2400 connection_.OnCanWrite();
2184 // There is now a pending packet, but with no retransmittable frames. 2401 // There is now a pending packet, but with no retransmittable frames.
2185 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 2402 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
2186 EXPECT_FALSE(connection_.sent_packet_manager().HasRetransmittableFrames(2)); 2403 EXPECT_FALSE(connection_.sent_packet_manager().HasRetransmittableFrames(2));
2187 } 2404 }
2188 2405
2189 TEST_P(QuicConnectionTest, AlarmsWhenWriteBlocked) { 2406 TEST_P(QuicConnectionTest, AlarmsWhenWriteBlocked) {
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
2424 ProcessFecPacket(6, 1, false, kEntropyFlag, nullptr); 2641 ProcessFecPacket(6, 1, false, kEntropyFlag, nullptr);
2425 ProcessFecProtectedPacket(3, false, kEntropyFlag); 2642 ProcessFecProtectedPacket(3, false, kEntropyFlag);
2426 ProcessFecProtectedPacket(4, false, kEntropyFlag); 2643 ProcessFecProtectedPacket(4, false, kEntropyFlag);
2427 ProcessFecProtectedPacket(5, true, !kEntropyFlag); 2644 ProcessFecProtectedPacket(5, true, !kEntropyFlag);
2428 // Ensure entropy is not revived for the missing packet. 2645 // Ensure entropy is not revived for the missing packet.
2429 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); 2646 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2));
2430 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 3)); 2647 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 3));
2431 } 2648 }
2432 2649
2433 TEST_P(QuicConnectionTest, TLP) { 2650 TEST_P(QuicConnectionTest, TLP) {
2434 QuicSentPacketManagerPeer::SetMaxTailLossProbes( 2651 QuicSentPacketManagerPeer::SetMaxTailLossProbes(manager_, 1);
2435 QuicConnectionPeer::GetSentPacketManager(&connection_), 1);
2436 2652
2437 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr); 2653 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr);
2438 EXPECT_EQ(1u, stop_waiting()->least_unacked); 2654 EXPECT_EQ(1u, stop_waiting()->least_unacked);
2439 QuicTime retransmission_time = 2655 QuicTime retransmission_time =
2440 connection_.GetRetransmissionAlarm()->deadline(); 2656 connection_.GetRetransmissionAlarm()->deadline();
2441 EXPECT_NE(QuicTime::Zero(), retransmission_time); 2657 EXPECT_NE(QuicTime::Zero(), retransmission_time);
2442 2658
2443 EXPECT_EQ(1u, writer_->header().packet_sequence_number); 2659 EXPECT_EQ(1u, writer_->header().packet_sequence_number);
2444 // Simulate the retransmission alarm firing and sending a tlp, 2660 // Simulate the retransmission alarm firing and sending a tlp,
2445 // so send algorithm's OnRetransmissionTimeout is not called. 2661 // so send algorithm's OnRetransmissionTimeout is not called.
2446 clock_.AdvanceTime(retransmission_time.Subtract(clock_.Now())); 2662 clock_.AdvanceTime(retransmission_time.Subtract(clock_.Now()));
2447 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _)); 2663 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _));
2448 connection_.GetRetransmissionAlarm()->Fire(); 2664 connection_.GetRetransmissionAlarm()->Fire();
2449 EXPECT_EQ(2u, writer_->header().packet_sequence_number); 2665 EXPECT_EQ(2u, writer_->header().packet_sequence_number);
2450 // We do not raise the high water mark yet. 2666 // We do not raise the high water mark yet.
2451 EXPECT_EQ(1u, stop_waiting()->least_unacked); 2667 EXPECT_EQ(1u, stop_waiting()->least_unacked);
2452 } 2668 }
2453 2669
2454 TEST_P(QuicConnectionTest, RTO) { 2670 TEST_P(QuicConnectionTest, RTO) {
2455 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( 2671 QuicTime default_retransmission_time = clock_.ApproximateNow().Add(
2456 DefaultRetransmissionTime()); 2672 DefaultRetransmissionTime());
2457 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr); 2673 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr);
2458 EXPECT_EQ(1u, stop_waiting()->least_unacked); 2674 EXPECT_EQ(1u, stop_waiting()->least_unacked);
2459 2675
2460 EXPECT_EQ(1u, writer_->header().packet_sequence_number); 2676 EXPECT_EQ(1u, writer_->header().packet_sequence_number);
2461 EXPECT_EQ(default_retransmission_time, 2677 EXPECT_EQ(default_retransmission_time,
2462 connection_.GetRetransmissionAlarm()->deadline()); 2678 connection_.GetRetransmissionAlarm()->deadline());
2463 // Simulate the retransmission alarm firing. 2679 // Simulate the retransmission alarm firing.
2464 clock_.AdvanceTime(DefaultRetransmissionTime()); 2680 clock_.AdvanceTime(DefaultRetransmissionTime());
2465 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 2681 if (!FLAGS_quic_use_new_rto) {
2682 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
2683 }
2466 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _)); 2684 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _));
2467 connection_.GetRetransmissionAlarm()->Fire(); 2685 connection_.GetRetransmissionAlarm()->Fire();
2468 EXPECT_EQ(2u, writer_->header().packet_sequence_number); 2686 EXPECT_EQ(2u, writer_->header().packet_sequence_number);
2469 // We do not raise the high water mark yet. 2687 // We do not raise the high water mark yet.
2470 EXPECT_EQ(1u, stop_waiting()->least_unacked); 2688 EXPECT_EQ(1u, stop_waiting()->least_unacked);
2471 } 2689 }
2472 2690
2473 TEST_P(QuicConnectionTest, RTOWithSameEncryptionLevel) { 2691 TEST_P(QuicConnectionTest, RTOWithSameEncryptionLevel) {
2474 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( 2692 QuicTime default_retransmission_time = clock_.ApproximateNow().Add(
2475 DefaultRetransmissionTime()); 2693 DefaultRetransmissionTime());
2476 use_tagging_decrypter(); 2694 use_tagging_decrypter();
2477 2695
2478 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at 2696 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at
2479 // the end of the packet. We can test this to check which encrypter was used. 2697 // the end of the packet. We can test this to check which encrypter was used.
2480 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); 2698 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01));
2481 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr); 2699 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr);
2482 EXPECT_EQ(0x01010101u, writer_->final_bytes_of_last_packet()); 2700 EXPECT_EQ(0x01010101u, writer_->final_bytes_of_last_packet());
2483 2701
2484 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); 2702 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02));
2485 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); 2703 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
2486 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr); 2704 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr);
2487 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet()); 2705 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet());
2488 2706
2489 EXPECT_EQ(default_retransmission_time, 2707 EXPECT_EQ(default_retransmission_time,
2490 connection_.GetRetransmissionAlarm()->deadline()); 2708 connection_.GetRetransmissionAlarm()->deadline());
2491 { 2709 {
2492 InSequence s; 2710 InSequence s;
2493 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 2711 if (!FLAGS_quic_use_new_rto) {
2712 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
2713 }
2494 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 3, _, _)); 2714 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 3, _, _));
2495 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 4, _, _)); 2715 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 4, _, _));
2496 } 2716 }
2497 2717
2498 // Simulate the retransmission alarm firing. 2718 // Simulate the retransmission alarm firing.
2499 clock_.AdvanceTime(DefaultRetransmissionTime()); 2719 clock_.AdvanceTime(DefaultRetransmissionTime());
2500 connection_.GetRetransmissionAlarm()->Fire(); 2720 connection_.GetRetransmissionAlarm()->Fire();
2501 2721
2502 // Packet should have been sent with ENCRYPTION_NONE. 2722 // Packet should have been sent with ENCRYPTION_NONE.
2503 EXPECT_EQ(0x01010101u, writer_->final_bytes_of_previous_packet()); 2723 EXPECT_EQ(0x01010101u, writer_->final_bytes_of_previous_packet());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2537 2757
2538 TEST_P(QuicConnectionTest, 2758 TEST_P(QuicConnectionTest,
2539 DropRetransmitsForNullEncryptedPacketAfterForwardSecure) { 2759 DropRetransmitsForNullEncryptedPacketAfterForwardSecure) {
2540 use_tagging_decrypter(); 2760 use_tagging_decrypter();
2541 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); 2761 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01));
2542 QuicPacketSequenceNumber sequence_number; 2762 QuicPacketSequenceNumber sequence_number;
2543 SendStreamDataToPeer(3, "foo", 0, !kFin, &sequence_number); 2763 SendStreamDataToPeer(3, "foo", 0, !kFin, &sequence_number);
2544 2764
2545 // Simulate the retransmission alarm firing and the socket blocking. 2765 // Simulate the retransmission alarm firing and the socket blocking.
2546 BlockOnNextWrite(); 2766 BlockOnNextWrite();
2547 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 2767 if (!FLAGS_quic_use_new_rto) {
2768 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
2769 }
2548 clock_.AdvanceTime(DefaultRetransmissionTime()); 2770 clock_.AdvanceTime(DefaultRetransmissionTime());
2549 connection_.GetRetransmissionAlarm()->Fire(); 2771 connection_.GetRetransmissionAlarm()->Fire();
2550 2772
2551 // Go forward secure. 2773 // Go forward secure.
2552 connection_.SetEncrypter(ENCRYPTION_FORWARD_SECURE, 2774 connection_.SetEncrypter(ENCRYPTION_FORWARD_SECURE,
2553 new TaggingEncrypter(0x02)); 2775 new TaggingEncrypter(0x02));
2554 connection_.SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); 2776 connection_.SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE);
2555 connection_.NeuterUnencryptedPackets(); 2777 connection_.NeuterUnencryptedPackets();
2556 2778
2557 EXPECT_EQ(QuicTime::Zero(), 2779 EXPECT_EQ(QuicTime::Zero(),
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
2699 DoAll(SaveArg<3>(&first_packet_size), Return(true))); 2921 DoAll(SaveArg<3>(&first_packet_size), Return(true)));
2700 2922
2701 connection_.SendStreamDataWithString(3, "first_packet", 0, !kFin, nullptr); 2923 connection_.SendStreamDataWithString(3, "first_packet", 0, !kFin, nullptr);
2702 QuicByteCount second_packet_size; 2924 QuicByteCount second_packet_size;
2703 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).WillOnce( 2925 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).WillOnce(
2704 DoAll(SaveArg<3>(&second_packet_size), Return(true))); 2926 DoAll(SaveArg<3>(&second_packet_size), Return(true)));
2705 connection_.SendStreamDataWithString(3, "second_packet", 12, !kFin, nullptr); 2927 connection_.SendStreamDataWithString(3, "second_packet", 12, !kFin, nullptr);
2706 EXPECT_NE(first_packet_size, second_packet_size); 2928 EXPECT_NE(first_packet_size, second_packet_size);
2707 // Advance the clock by huge time to make sure packets will be retransmitted. 2929 // Advance the clock by huge time to make sure packets will be retransmitted.
2708 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10)); 2930 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10));
2709 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 2931 if (!FLAGS_quic_use_new_rto) {
2932 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
2933 }
2710 { 2934 {
2711 InSequence s; 2935 InSequence s;
2712 EXPECT_CALL(*send_algorithm_, 2936 EXPECT_CALL(*send_algorithm_,
2713 OnPacketSent(_, _, _, first_packet_size, _)); 2937 OnPacketSent(_, _, _, first_packet_size, _));
2714 EXPECT_CALL(*send_algorithm_, 2938 EXPECT_CALL(*send_algorithm_,
2715 OnPacketSent(_, _, _, second_packet_size, _)); 2939 OnPacketSent(_, _, _, second_packet_size, _));
2716 } 2940 }
2717 connection_.GetRetransmissionAlarm()->Fire(); 2941 connection_.GetRetransmissionAlarm()->Fire();
2718 2942
2719 // Advance again and expect the packets to be sent again in the same order. 2943 // Advance again and expect the packets to be sent again in the same order.
2720 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(20)); 2944 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(20));
2721 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 2945 if (!FLAGS_quic_use_new_rto) {
2946 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
2947 }
2722 { 2948 {
2723 InSequence s; 2949 InSequence s;
2724 EXPECT_CALL(*send_algorithm_, 2950 EXPECT_CALL(*send_algorithm_,
2725 OnPacketSent(_, _, _, first_packet_size, _)); 2951 OnPacketSent(_, _, _, first_packet_size, _));
2726 EXPECT_CALL(*send_algorithm_, 2952 EXPECT_CALL(*send_algorithm_,
2727 OnPacketSent(_, _, _, second_packet_size, _)); 2953 OnPacketSent(_, _, _, second_packet_size, _));
2728 } 2954 }
2729 connection_.GetRetransmissionAlarm()->Fire(); 2955 connection_.GetRetransmissionAlarm()->Fire();
2730 } 2956 }
2731 2957
2732 TEST_P(QuicConnectionTest, RetransmissionCountCalculation) {
2733 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2734 QuicPacketSequenceNumber original_sequence_number;
2735 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
2736 .WillOnce(DoAll(SaveArg<2>(&original_sequence_number), Return(true)));
2737 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr);
2738
2739 EXPECT_TRUE(QuicConnectionPeer::IsSavedForRetransmission(
2740 &connection_, original_sequence_number));
2741 EXPECT_FALSE(QuicConnectionPeer::IsRetransmission(
2742 &connection_, original_sequence_number));
2743 // Force retransmission due to RTO.
2744 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10));
2745 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
2746 QuicPacketSequenceNumber rto_sequence_number;
2747 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
2748 .WillOnce(DoAll(SaveArg<2>(&rto_sequence_number), Return(true)));
2749 connection_.GetRetransmissionAlarm()->Fire();
2750 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission(
2751 &connection_, original_sequence_number));
2752 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission(
2753 &connection_, rto_sequence_number));
2754 EXPECT_TRUE(QuicConnectionPeer::IsRetransmission(
2755 &connection_, rto_sequence_number));
2756 // Once by explicit nack.
2757 SequenceNumberSet lost_packets;
2758 lost_packets.insert(rto_sequence_number);
2759 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
2760 .WillOnce(Return(lost_packets));
2761 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
2762 QuicPacketSequenceNumber nack_sequence_number = 0;
2763 // Ack packets might generate some other packets, which are not
2764 // retransmissions. (More ack packets).
2765 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
2766 .Times(AnyNumber());
2767 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
2768 .WillOnce(DoAll(SaveArg<2>(&nack_sequence_number), Return(true)));
2769 QuicAckFrame ack = InitAckFrame(rto_sequence_number);
2770 // Nack the retransmitted packet.
2771 NackPacket(original_sequence_number, &ack);
2772 NackPacket(rto_sequence_number, &ack);
2773 ProcessAckPacket(&ack);
2774
2775 ASSERT_NE(0u, nack_sequence_number);
2776 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission(
2777 &connection_, rto_sequence_number));
2778 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission(
2779 &connection_, nack_sequence_number));
2780 EXPECT_TRUE(QuicConnectionPeer::IsRetransmission(
2781 &connection_, nack_sequence_number));
2782 }
2783
2784 TEST_P(QuicConnectionTest, SetRTOAfterWritingToSocket) { 2958 TEST_P(QuicConnectionTest, SetRTOAfterWritingToSocket) {
2785 BlockOnNextWrite(); 2959 BlockOnNextWrite();
2786 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); 2960 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr);
2787 // Make sure that RTO is not started when the packet is queued. 2961 // Make sure that RTO is not started when the packet is queued.
2788 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 2962 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2789 2963
2790 // Test that RTO is started once we write to the socket. 2964 // Test that RTO is started once we write to the socket.
2791 writer_->SetWritable(); 2965 writer_->SetWritable();
2792 connection_.OnCanWrite(); 2966 connection_.OnCanWrite();
2793 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 2967 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
(...skipping 18 matching lines...) Expand all
2812 ProcessAckPacket(&ack); 2986 ProcessAckPacket(&ack);
2813 EXPECT_TRUE(retransmission_alarm->IsSet()); 2987 EXPECT_TRUE(retransmission_alarm->IsSet());
2814 EXPECT_GT(retransmission_alarm->deadline(), clock_.Now()); 2988 EXPECT_GT(retransmission_alarm->deadline(), clock_.Now());
2815 2989
2816 // Move forward past the original RTO and ensure the RTO is still pending. 2990 // Move forward past the original RTO and ensure the RTO is still pending.
2817 clock_.AdvanceTime(DefaultRetransmissionTime().Multiply(2)); 2991 clock_.AdvanceTime(DefaultRetransmissionTime().Multiply(2));
2818 2992
2819 // Ensure the second packet gets retransmitted when it finally fires. 2993 // Ensure the second packet gets retransmitted when it finally fires.
2820 EXPECT_TRUE(retransmission_alarm->IsSet()); 2994 EXPECT_TRUE(retransmission_alarm->IsSet());
2821 EXPECT_LT(retransmission_alarm->deadline(), clock_.ApproximateNow()); 2995 EXPECT_LT(retransmission_alarm->deadline(), clock_.ApproximateNow());
2822 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 2996 if (!FLAGS_quic_use_new_rto) {
2997 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
2998 }
2823 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 2999 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
2824 // Manually cancel the alarm to simulate a real test. 3000 // Manually cancel the alarm to simulate a real test.
2825 connection_.GetRetransmissionAlarm()->Fire(); 3001 connection_.GetRetransmissionAlarm()->Fire();
2826 3002
2827 // The new retransmitted sequence number should set the RTO to a larger value 3003 // The new retransmitted sequence number should set the RTO to a larger value
2828 // than previously. 3004 // than previously.
2829 EXPECT_TRUE(retransmission_alarm->IsSet()); 3005 EXPECT_TRUE(retransmission_alarm->IsSet());
2830 QuicTime next_rto_time = retransmission_alarm->deadline(); 3006 QuicTime next_rto_time = retransmission_alarm->deadline();
2831 QuicTime expected_rto_time = 3007 QuicTime expected_rto_time =
2832 connection_.sent_packet_manager().GetRetransmissionTime(); 3008 connection_.sent_packet_manager().GetRetransmissionTime();
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
2919 // Simulate the timeout alarm firing. 3095 // Simulate the timeout alarm firing.
2920 clock_.AdvanceTime( 3096 clock_.AdvanceTime(
2921 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1)); 3097 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1));
2922 connection_.GetTimeoutAlarm()->Fire(); 3098 connection_.GetTimeoutAlarm()->Fire();
2923 3099
2924 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); 3100 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
2925 EXPECT_FALSE(connection_.connected()); 3101 EXPECT_FALSE(connection_.connected());
2926 3102
2927 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 3103 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
2928 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); 3104 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet());
3105 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet());
2929 EXPECT_FALSE(connection_.GetResumeWritesAlarm()->IsSet()); 3106 EXPECT_FALSE(connection_.GetResumeWritesAlarm()->IsSet());
2930 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 3107 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2931 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet()); 3108 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet());
2932 } 3109 }
2933 3110
2934 TEST_P(QuicConnectionTest, OverallTimeout) { 3111 TEST_P(QuicConnectionTest, OverallTimeout) {
2935 // Use a shorter overall connection timeout than idle timeout for this test. 3112 // Use a shorter overall connection timeout than idle timeout for this test.
2936 const QuicTime::Delta timeout = QuicTime::Delta::FromSeconds(5); 3113 const QuicTime::Delta timeout = QuicTime::Delta::FromSeconds(5);
2937 connection_.SetNetworkTimeouts(timeout, timeout); 3114 connection_.SetNetworkTimeouts(timeout, timeout);
2938 EXPECT_TRUE(connection_.connected()); 3115 EXPECT_TRUE(connection_.connected());
(...skipping 22 matching lines...) Expand all
2961 EXPECT_CALL(visitor_, 3138 EXPECT_CALL(visitor_,
2962 OnConnectionClosed(QUIC_CONNECTION_OVERALL_TIMED_OUT, false)); 3139 OnConnectionClosed(QUIC_CONNECTION_OVERALL_TIMED_OUT, false));
2963 // Simulate the timeout alarm firing. 3140 // Simulate the timeout alarm firing.
2964 connection_.GetTimeoutAlarm()->Fire(); 3141 connection_.GetTimeoutAlarm()->Fire();
2965 3142
2966 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); 3143 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
2967 EXPECT_FALSE(connection_.connected()); 3144 EXPECT_FALSE(connection_.connected());
2968 3145
2969 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 3146 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
2970 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); 3147 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet());
3148 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet());
2971 EXPECT_FALSE(connection_.GetResumeWritesAlarm()->IsSet()); 3149 EXPECT_FALSE(connection_.GetResumeWritesAlarm()->IsSet());
2972 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 3150 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2973 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet()); 3151 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet());
2974 } 3152 }
2975 3153
2976 TEST_P(QuicConnectionTest, PingAfterSend) { 3154 TEST_P(QuicConnectionTest, PingAfterSend) {
2977 EXPECT_TRUE(connection_.connected()); 3155 EXPECT_TRUE(connection_.connected());
2978 EXPECT_CALL(visitor_, HasOpenDataStreams()).WillRepeatedly(Return(true)); 3156 EXPECT_CALL(visitor_, HasOpenDataStreams()).WillRepeatedly(Return(true));
2979 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); 3157 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet());
2980 3158
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
3132 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 3310 EXPECT_EQ(1u, connection_.NumQueuedPackets());
3133 } 3311 }
3134 3312
3135 TEST_P(QuicConnectionTest, TestQueueLimitsOnSendStreamData) { 3313 TEST_P(QuicConnectionTest, TestQueueLimitsOnSendStreamData) {
3136 // All packets carry version info till version is negotiated. 3314 // All packets carry version info till version is negotiated.
3137 size_t payload_length; 3315 size_t payload_length;
3138 size_t length = GetPacketLengthForOneStream( 3316 size_t length = GetPacketLengthForOneStream(
3139 connection_.version(), kIncludeVersion, 3317 connection_.version(), kIncludeVersion,
3140 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, 3318 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER,
3141 NOT_IN_FEC_GROUP, &payload_length); 3319 NOT_IN_FEC_GROUP, &payload_length);
3142 QuicConnectionPeer::GetPacketCreator(&connection_)->set_max_packet_length( 3320 creator_->set_max_packet_length(length);
3143 length);
3144 3321
3145 // Queue the first packet. 3322 // Queue the first packet.
3146 EXPECT_CALL(*send_algorithm_, 3323 EXPECT_CALL(*send_algorithm_,
3147 TimeUntilSend(_, _, _)).WillOnce( 3324 TimeUntilSend(_, _, _)).WillOnce(
3148 testing::Return(QuicTime::Delta::FromMicroseconds(10))); 3325 testing::Return(QuicTime::Delta::FromMicroseconds(10)));
3149 const string payload(payload_length, 'a'); 3326 const string payload(payload_length, 'a');
3150 EXPECT_EQ(0u, connection_.SendStreamDataWithString(3, payload, 0, !kFin, 3327 EXPECT_EQ(0u, connection_.SendStreamDataWithString(3, payload, 0, !kFin,
3151 nullptr).bytes_consumed); 3328 nullptr).bytes_consumed);
3152 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 3329 EXPECT_EQ(0u, connection_.NumQueuedPackets());
3153 } 3330 }
3154 3331
3155 TEST_P(QuicConnectionTest, LoopThroughSendingPackets) { 3332 TEST_P(QuicConnectionTest, LoopThroughSendingPackets) {
3156 // All packets carry version info till version is negotiated. 3333 // All packets carry version info till version is negotiated.
3157 size_t payload_length; 3334 size_t payload_length;
3158 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining 3335 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining
3159 // packet length. The size of the offset field in a stream frame is 0 for 3336 // packet length. The size of the offset field in a stream frame is 0 for
3160 // offset 0, and 2 for non-zero offsets up through 16K. Increase 3337 // offset 0, and 2 for non-zero offsets up through 16K. Increase
3161 // max_packet_length by 2 so that subsequent packets containing subsequent 3338 // max_packet_length by 2 so that subsequent packets containing subsequent
3162 // stream frames with non-zero offets will fit within the packet length. 3339 // stream frames with non-zero offets will fit within the packet length.
3163 size_t length = 2 + GetPacketLengthForOneStream( 3340 size_t length = 2 + GetPacketLengthForOneStream(
3164 connection_.version(), kIncludeVersion, 3341 connection_.version(), kIncludeVersion,
3165 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, 3342 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER,
3166 NOT_IN_FEC_GROUP, &payload_length); 3343 NOT_IN_FEC_GROUP, &payload_length);
3167 QuicConnectionPeer::GetPacketCreator(&connection_)->set_max_packet_length( 3344 creator_->set_max_packet_length(length);
3168 length);
3169 3345
3170 // Queue the first packet. 3346 // Queue the first packet.
3171 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(7); 3347 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(7);
3172 // The first stream frame will have 2 fewer overhead bytes than the other six. 3348 // The first stream frame will have 2 fewer overhead bytes than the other six.
3173 const string payload(payload_length * 7 + 2, 'a'); 3349 const string payload(payload_length * 7 + 2, 'a');
3174 EXPECT_EQ(payload.size(), 3350 EXPECT_EQ(payload.size(),
3175 connection_.SendStreamDataWithString(1, payload, 0, !kFin, nullptr) 3351 connection_.SendStreamDataWithString(1, payload, 0, !kFin, nullptr)
3176 .bytes_consumed); 3352 .bytes_consumed);
3177 } 3353 }
3178 3354
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
3731 QuicFrames frames; 3907 QuicFrames frames;
3732 QuicFrame frame(&frame1_); 3908 QuicFrame frame(&frame1_);
3733 frames.push_back(frame); 3909 frames.push_back(frame);
3734 scoped_ptr<QuicPacket> packet( 3910 scoped_ptr<QuicPacket> packet(
3735 BuildUnsizedDataPacket(&framer_, header, frames).packet); 3911 BuildUnsizedDataPacket(&framer_, header, frames).packet);
3736 encrypted.reset(framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); 3912 encrypted.reset(framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet));
3737 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); 3913 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1);
3738 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3914 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3739 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); 3915 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted);
3740 3916
3741 ASSERT_FALSE(QuicPacketCreatorPeer::SendVersionInPacket( 3917 ASSERT_FALSE(QuicPacketCreatorPeer::SendVersionInPacket(creator_));
3742 QuicConnectionPeer::GetPacketCreator(&connection_)));
3743 } 3918 }
3744 3919
3745 TEST_P(QuicConnectionTest, BadVersionNegotiation) { 3920 TEST_P(QuicConnectionTest, BadVersionNegotiation) {
3746 QuicPacketHeader header; 3921 QuicPacketHeader header;
3747 header.public_header.connection_id = connection_id_; 3922 header.public_header.connection_id = connection_id_;
3748 header.public_header.reset_flag = false; 3923 header.public_header.reset_flag = false;
3749 header.public_header.version_flag = true; 3924 header.public_header.version_flag = true;
3750 header.entropy_flag = false; 3925 header.entropy_flag = false;
3751 header.fec_flag = false; 3926 header.fec_flag = false;
3752 header.packet_sequence_number = 12; 3927 header.packet_sequence_number = 12;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
3790 NackPacket(3, &nack_three); 3965 NackPacket(3, &nack_three);
3791 NackPacket(1, &nack_three); 3966 NackPacket(1, &nack_three);
3792 SequenceNumberSet lost_packets; 3967 SequenceNumberSet lost_packets;
3793 lost_packets.insert(1); 3968 lost_packets.insert(1);
3794 lost_packets.insert(3); 3969 lost_packets.insert(3);
3795 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 3970 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
3796 .WillOnce(Return(lost_packets)); 3971 .WillOnce(Return(lost_packets));
3797 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 3972 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
3798 EXPECT_CALL(visitor_, OnCanWrite()).Times(2); 3973 EXPECT_CALL(visitor_, OnCanWrite()).Times(2);
3799 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3974 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3800 EXPECT_CALL(*send_algorithm_, RevertRetransmissionTimeout()); 3975 if (!FLAGS_quic_use_new_rto) {
3976 EXPECT_CALL(*send_algorithm_, RevertRetransmissionTimeout());
3977 }
3801 ProcessAckPacket(&nack_three); 3978 ProcessAckPacket(&nack_three);
3802 3979
3803 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillOnce( 3980 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillOnce(
3804 Return(QuicBandwidth::Zero())); 3981 Return(QuicBandwidth::Zero()));
3805 3982
3806 const QuicConnectionStats& stats = connection_.GetStats(); 3983 const QuicConnectionStats& stats = connection_.GetStats();
3807 EXPECT_EQ(3 * first_packet_size + 2 * second_packet_size - kQuicVersionSize, 3984 EXPECT_EQ(3 * first_packet_size + 2 * second_packet_size - kQuicVersionSize,
3808 stats.bytes_sent); 3985 stats.bytes_sent);
3809 EXPECT_EQ(5u, stats.packets_sent); 3986 EXPECT_EQ(5u, stats.packets_sent);
3810 EXPECT_EQ(2 * first_packet_size + second_packet_size - kQuicVersionSize, 3987 EXPECT_EQ(2 * first_packet_size + second_packet_size - kQuicVersionSize,
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
3945 EXPECT_TRUE(writer_->IsWriteBlocked()); 4122 EXPECT_TRUE(writer_->IsWriteBlocked());
3946 TriggerConnectionClose(); 4123 TriggerConnectionClose();
3947 EXPECT_EQ(1u, writer_->packets_write_attempts()); 4124 EXPECT_EQ(1u, writer_->packets_write_attempts());
3948 } 4125 }
3949 4126
3950 TEST_P(QuicConnectionTest, AckNotifierTriggerCallback) { 4127 TEST_P(QuicConnectionTest, AckNotifierTriggerCallback) {
3951 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4128 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3952 4129
3953 // Create a delegate which we expect to be called. 4130 // Create a delegate which we expect to be called.
3954 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); 4131 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate);
3955 EXPECT_CALL(*delegate.get(), OnAckNotification(_, _, _, _, _)).Times(1); 4132 EXPECT_CALL(*delegate.get(), OnAckNotification(_, _, _)).Times(1);
3956 4133
3957 // Send some data, which will register the delegate to be notified. 4134 // Send some data, which will register the delegate to be notified.
3958 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); 4135 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get());
3959 4136
3960 // Process an ACK from the server which should trigger the callback. 4137 // Process an ACK from the server which should trigger the callback.
3961 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 4138 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
3962 QuicAckFrame frame = InitAckFrame(1); 4139 QuicAckFrame frame = InitAckFrame(1);
3963 ProcessAckPacket(&frame); 4140 ProcessAckPacket(&frame);
3964 } 4141 }
3965 4142
3966 TEST_P(QuicConnectionTest, AckNotifierFailToTriggerCallback) { 4143 TEST_P(QuicConnectionTest, AckNotifierFailToTriggerCallback) {
3967 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4144 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3968 4145
3969 // Create a delegate which we don't expect to be called. 4146 // Create a delegate which we don't expect to be called.
3970 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); 4147 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate);
3971 EXPECT_CALL(*delegate.get(), OnAckNotification(_, _, _, _, _)).Times(0); 4148 EXPECT_CALL(*delegate.get(), OnAckNotification(_, _, _)).Times(0);
3972 4149
3973 // Send some data, which will register the delegate to be notified. This will 4150 // Send some data, which will register the delegate to be notified. This will
3974 // not be ACKed and so the delegate should never be called. 4151 // not be ACKed and so the delegate should never be called.
3975 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); 4152 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get());
3976 4153
3977 // Send some other data which we will ACK. 4154 // Send some other data which we will ACK.
3978 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); 4155 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr);
3979 connection_.SendStreamDataWithString(1, "bar", 0, !kFin, nullptr); 4156 connection_.SendStreamDataWithString(1, "bar", 0, !kFin, nullptr);
3980 4157
3981 // Now we receive ACK for packets 2 and 3, but importantly missing packet 1 4158 // Now we receive ACK for packets 2 and 3, but importantly missing packet 1
3982 // which we registered to be notified about. 4159 // which we registered to be notified about.
3983 QuicAckFrame frame = InitAckFrame(3); 4160 QuicAckFrame frame = InitAckFrame(3);
3984 NackPacket(1, &frame); 4161 NackPacket(1, &frame);
3985 SequenceNumberSet lost_packets; 4162 SequenceNumberSet lost_packets;
3986 lost_packets.insert(1); 4163 lost_packets.insert(1);
3987 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 4164 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
3988 .WillOnce(Return(lost_packets)); 4165 .WillOnce(Return(lost_packets));
3989 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 4166 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
3990 ProcessAckPacket(&frame); 4167 ProcessAckPacket(&frame);
3991 } 4168 }
3992 4169
3993 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) { 4170 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) {
3994 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4171 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3995 4172
3996 // Create a delegate which we expect to be called. 4173 // Create a delegate which we expect to be called.
3997 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); 4174 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate);
3998 EXPECT_CALL(*delegate.get(), OnAckNotification(_, _, _, _, _)).Times(1); 4175 EXPECT_CALL(*delegate.get(), OnAckNotification(_, _, _)).Times(1);
3999 4176
4000 // Send four packets, and register to be notified on ACK of packet 2. 4177 // Send four packets, and register to be notified on ACK of packet 2.
4001 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); 4178 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr);
4002 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, delegate.get()); 4179 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, delegate.get());
4003 connection_.SendStreamDataWithString(3, "baz", 0, !kFin, nullptr); 4180 connection_.SendStreamDataWithString(3, "baz", 0, !kFin, nullptr);
4004 connection_.SendStreamDataWithString(3, "qux", 0, !kFin, nullptr); 4181 connection_.SendStreamDataWithString(3, "qux", 0, !kFin, nullptr);
4005 4182
4006 // Now we receive ACK for packets 1, 3, and 4 and lose 2. 4183 // Now we receive ACK for packets 1, 3, and 4 and lose 2.
4007 QuicAckFrame frame = InitAckFrame(4); 4184 QuicAckFrame frame = InitAckFrame(4);
4008 NackPacket(2, &frame); 4185 NackPacket(2, &frame);
(...skipping 27 matching lines...) Expand all
4036 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( 4213 QuicTime default_retransmission_time = clock_.ApproximateNow().Add(
4037 DefaultRetransmissionTime()); 4214 DefaultRetransmissionTime());
4038 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, delegate.get()); 4215 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, delegate.get());
4039 EXPECT_EQ(1u, stop_waiting()->least_unacked); 4216 EXPECT_EQ(1u, stop_waiting()->least_unacked);
4040 4217
4041 EXPECT_EQ(1u, writer_->header().packet_sequence_number); 4218 EXPECT_EQ(1u, writer_->header().packet_sequence_number);
4042 EXPECT_EQ(default_retransmission_time, 4219 EXPECT_EQ(default_retransmission_time,
4043 connection_.GetRetransmissionAlarm()->deadline()); 4220 connection_.GetRetransmissionAlarm()->deadline());
4044 // Simulate the retransmission alarm firing. 4221 // Simulate the retransmission alarm firing.
4045 clock_.AdvanceTime(DefaultRetransmissionTime()); 4222 clock_.AdvanceTime(DefaultRetransmissionTime());
4046 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 4223 if (!FLAGS_quic_use_new_rto) {
4224 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
4225 }
4047 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _)); 4226 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _));
4048 connection_.GetRetransmissionAlarm()->Fire(); 4227 connection_.GetRetransmissionAlarm()->Fire();
4049 EXPECT_EQ(2u, writer_->header().packet_sequence_number); 4228 EXPECT_EQ(2u, writer_->header().packet_sequence_number);
4050 // We do not raise the high water mark yet. 4229 // We do not raise the high water mark yet.
4051 EXPECT_EQ(1u, stop_waiting()->least_unacked); 4230 EXPECT_EQ(1u, stop_waiting()->least_unacked);
4052 4231
4053 // Ack the original packet, which will revert the RTO. 4232 // Ack the original packet, which will revert the RTO.
4054 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4233 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4055 EXPECT_CALL(*delegate.get(), OnAckNotification(1, _, 1, _, _)); 4234 EXPECT_CALL(*delegate.get(), OnAckNotification(1, _, _));
4056 EXPECT_CALL(*send_algorithm_, RevertRetransmissionTimeout()); 4235 if (!FLAGS_quic_use_new_rto) {
4236 EXPECT_CALL(*send_algorithm_, RevertRetransmissionTimeout());
4237 }
4057 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 4238 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
4058 QuicAckFrame ack_frame = InitAckFrame(1); 4239 QuicAckFrame ack_frame = InitAckFrame(1);
4059 ProcessAckPacket(&ack_frame); 4240 ProcessAckPacket(&ack_frame);
4060 4241
4061 // Delegate is not notified again when the retransmit is acked. 4242 // Delegate is not notified again when the retransmit is acked.
4062 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 4243 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
4063 QuicAckFrame second_ack_frame = InitAckFrame(2); 4244 QuicAckFrame second_ack_frame = InitAckFrame(2);
4064 ProcessAckPacket(&second_ack_frame); 4245 ProcessAckPacket(&second_ack_frame);
4065 } 4246 }
4066 4247
(...skipping 20 matching lines...) Expand all
4087 lost_packets.insert(2); 4268 lost_packets.insert(2);
4088 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4269 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4089 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 4270 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
4090 .WillOnce(Return(lost_packets)); 4271 .WillOnce(Return(lost_packets));
4091 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 4272 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
4092 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 4273 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
4093 ProcessAckPacket(&frame); 4274 ProcessAckPacket(&frame);
4094 4275
4095 // Now we get an ACK for packet 2, which was previously nacked. 4276 // Now we get an ACK for packet 2, which was previously nacked.
4096 SequenceNumberSet no_lost_packets; 4277 SequenceNumberSet no_lost_packets;
4097 EXPECT_CALL(*delegate.get(), OnAckNotification(1, _, 1, _, _)); 4278 EXPECT_CALL(*delegate.get(), OnAckNotification(1, _, _));
4098 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 4279 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
4099 .WillOnce(Return(no_lost_packets)); 4280 .WillOnce(Return(no_lost_packets));
4100 QuicAckFrame second_ack_frame = InitAckFrame(4); 4281 QuicAckFrame second_ack_frame = InitAckFrame(4);
4101 ProcessAckPacket(&second_ack_frame); 4282 ProcessAckPacket(&second_ack_frame);
4102 4283
4103 // Verify that the delegate is not notified again when the 4284 // Verify that the delegate is not notified again when the
4104 // retransmit is acked. 4285 // retransmit is acked.
4105 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 4286 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
4106 .WillOnce(Return(no_lost_packets)); 4287 .WillOnce(Return(no_lost_packets));
4107 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 4288 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
4108 QuicAckFrame third_ack_frame = InitAckFrame(5); 4289 QuicAckFrame third_ack_frame = InitAckFrame(5);
4109 ProcessAckPacket(&third_ack_frame); 4290 ProcessAckPacket(&third_ack_frame);
4110 } 4291 }
4111 4292
4112 TEST_P(QuicConnectionTest, AckNotifierFECTriggerCallback) { 4293 TEST_P(QuicConnectionTest, AckNotifierFECTriggerCallback) {
4113 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4294 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4114 4295
4115 // Create a delegate which we expect to be called. 4296 // Create a delegate which we expect to be called.
4116 scoped_refptr<MockAckNotifierDelegate> delegate( 4297 scoped_refptr<MockAckNotifierDelegate> delegate(
4117 new MockAckNotifierDelegate); 4298 new MockAckNotifierDelegate);
4118 EXPECT_CALL(*delegate.get(), OnAckNotification(_, _, _, _, _)).Times(1); 4299 EXPECT_CALL(*delegate.get(), OnAckNotification(_, _, _)).Times(1);
4119 4300
4120 // Send some data, which will register the delegate to be notified. 4301 // Send some data, which will register the delegate to be notified.
4121 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); 4302 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get());
4122 connection_.SendStreamDataWithString(2, "bar", 0, !kFin, nullptr); 4303 connection_.SendStreamDataWithString(2, "bar", 0, !kFin, nullptr);
4123 4304
4124 // Process an ACK from the server with a revived packet, which should trigger 4305 // Process an ACK from the server with a revived packet, which should trigger
4125 // the callback. 4306 // the callback.
4126 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 4307 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
4127 QuicAckFrame frame = InitAckFrame(2); 4308 QuicAckFrame frame = InitAckFrame(2);
4128 NackPacket(1, &frame); 4309 NackPacket(1, &frame);
4129 frame.revived_packets.insert(1); 4310 frame.revived_packets.insert(1);
4130 ProcessAckPacket(&frame); 4311 ProcessAckPacket(&frame);
4131 // If the ack is processed again, the notifier should not be called again. 4312 // If the ack is processed again, the notifier should not be called again.
4132 ProcessAckPacket(&frame); 4313 ProcessAckPacket(&frame);
4133 } 4314 }
4134 4315
4135 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterFECRecovery) { 4316 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterFECRecovery) {
4136 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4317 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4137 EXPECT_CALL(visitor_, OnCanWrite()); 4318 EXPECT_CALL(visitor_, OnCanWrite());
4138 4319
4139 // Create a delegate which we expect to be called. 4320 // Create a delegate which we expect to be called.
4140 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); 4321 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate);
4141 EXPECT_CALL(*delegate.get(), OnAckNotification(_, _, _, _, _)).Times(1); 4322 EXPECT_CALL(*delegate.get(), OnAckNotification(_, _, _)).Times(1);
4142 4323
4143 // Expect ACKs for 1 packet. 4324 // Expect ACKs for 1 packet.
4144 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 4325 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
4145 4326
4146 // Send one packet, and register to be notified on ACK. 4327 // Send one packet, and register to be notified on ACK.
4147 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); 4328 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get());
4148 4329
4149 // Ack packet gets dropped, but we receive an FEC packet that covers it. 4330 // Ack packet gets dropped, but we receive an FEC packet that covers it.
4150 // Should recover the Ack packet and trigger the notification callback. 4331 // Should recover the Ack packet and trigger the notification callback.
4151 QuicFrames frames; 4332 QuicFrames frames;
(...skipping 16 matching lines...) Expand all
4168 4349
4169 QuicPacket* packet = 4350 QuicPacket* packet =
4170 BuildUnsizedDataPacket(&framer_, ack_header, frames).packet; 4351 BuildUnsizedDataPacket(&framer_, ack_header, frames).packet;
4171 4352
4172 // Take the packet which contains the ACK frame, and construct and deliver an 4353 // Take the packet which contains the ACK frame, and construct and deliver an
4173 // FEC packet which allows the ACK packet to be recovered. 4354 // FEC packet which allows the ACK packet to be recovered.
4174 ProcessFecPacket(2, 1, true, !kEntropyFlag, packet); 4355 ProcessFecPacket(2, 1, true, !kEntropyFlag, packet);
4175 } 4356 }
4176 4357
4177 TEST_P(QuicConnectionTest, NetworkChangeVisitorCwndCallbackChangesFecState) { 4358 TEST_P(QuicConnectionTest, NetworkChangeVisitorCwndCallbackChangesFecState) {
4178 QuicPacketCreator* creator = 4359 size_t max_packets_per_fec_group = creator_->max_packets_per_fec_group();
4179 QuicConnectionPeer::GetPacketCreator(&connection_);
4180 size_t max_packets_per_fec_group = creator->max_packets_per_fec_group();
4181 4360
4182 QuicSentPacketManager::NetworkChangeVisitor* visitor = 4361 QuicSentPacketManager::NetworkChangeVisitor* visitor =
4183 QuicSentPacketManagerPeer::GetNetworkChangeVisitor( 4362 QuicSentPacketManagerPeer::GetNetworkChangeVisitor(manager_);
4184 QuicConnectionPeer::GetSentPacketManager(&connection_));
4185 EXPECT_TRUE(visitor); 4363 EXPECT_TRUE(visitor);
4186 4364
4187 // Increase FEC group size by increasing congestion window to a large number. 4365 // Increase FEC group size by increasing congestion window to a large number.
4188 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( 4366 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly(
4189 Return(1000 * kDefaultTCPMSS)); 4367 Return(1000 * kDefaultTCPMSS));
4190 visitor->OnCongestionWindowChange(); 4368 visitor->OnCongestionWindowChange();
4191 EXPECT_LT(max_packets_per_fec_group, creator->max_packets_per_fec_group()); 4369 EXPECT_LT(max_packets_per_fec_group, creator_->max_packets_per_fec_group());
4192 } 4370 }
4193 4371
4194 TEST_P(QuicConnectionTest, NetworkChangeVisitorConfigCallbackChangesFecState) { 4372 TEST_P(QuicConnectionTest, NetworkChangeVisitorConfigCallbackChangesFecState) {
4195 QuicSentPacketManager* sent_packet_manager =
4196 QuicConnectionPeer::GetSentPacketManager(&connection_);
4197 QuicSentPacketManager::NetworkChangeVisitor* visitor = 4373 QuicSentPacketManager::NetworkChangeVisitor* visitor =
4198 QuicSentPacketManagerPeer::GetNetworkChangeVisitor(sent_packet_manager); 4374 QuicSentPacketManagerPeer::GetNetworkChangeVisitor(manager_);
4199 EXPECT_TRUE(visitor); 4375 EXPECT_TRUE(visitor);
4200 4376 EXPECT_EQ(QuicTime::Delta::Zero(),
4201 QuicPacketGenerator* generator = 4377 QuicPacketGeneratorPeer::GetFecTimeout(generator_));
4202 QuicConnectionPeer::GetPacketGenerator(&connection_);
4203 EXPECT_EQ(QuicTime::Delta::Zero(), generator->fec_timeout());
4204 4378
4205 // Verify that sending a config with a new initial rtt changes fec timeout. 4379 // Verify that sending a config with a new initial rtt changes fec timeout.
4206 // Create and process a config with a non-zero initial RTT. 4380 // Create and process a config with a non-zero initial RTT.
4207 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _, _)); 4381 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _, _));
4208 QuicConfig config; 4382 QuicConfig config;
4209 config.SetInitialRoundTripTimeUsToSend(300000); 4383 config.SetInitialRoundTripTimeUsToSend(300000);
4210 connection_.SetFromConfig(config); 4384 connection_.SetFromConfig(config);
4211 EXPECT_LT(QuicTime::Delta::Zero(), generator->fec_timeout()); 4385 EXPECT_LT(QuicTime::Delta::Zero(),
4386 QuicPacketGeneratorPeer::GetFecTimeout(generator_));
4212 } 4387 }
4213 4388
4214 TEST_P(QuicConnectionTest, NetworkChangeVisitorRttCallbackChangesFecState) { 4389 TEST_P(QuicConnectionTest, NetworkChangeVisitorRttCallbackChangesFecState) {
4215 // Verify that sending a config with a new initial rtt changes fec timeout. 4390 // Verify that sending a config with a new initial rtt changes fec timeout.
4216 QuicSentPacketManager* sent_packet_manager =
4217 QuicConnectionPeer::GetSentPacketManager(&connection_);
4218 QuicSentPacketManager::NetworkChangeVisitor* visitor = 4391 QuicSentPacketManager::NetworkChangeVisitor* visitor =
4219 QuicSentPacketManagerPeer::GetNetworkChangeVisitor(sent_packet_manager); 4392 QuicSentPacketManagerPeer::GetNetworkChangeVisitor(manager_);
4220 EXPECT_TRUE(visitor); 4393 EXPECT_TRUE(visitor);
4221 4394 EXPECT_EQ(QuicTime::Delta::Zero(),
4222 QuicPacketGenerator* generator = 4395 QuicPacketGeneratorPeer::GetFecTimeout(generator_));
4223 QuicConnectionPeer::GetPacketGenerator(&connection_);
4224 EXPECT_EQ(QuicTime::Delta::Zero(), generator->fec_timeout());
4225 4396
4226 // Increase FEC timeout by increasing RTT. 4397 // Increase FEC timeout by increasing RTT.
4227 RttStats* rtt_stats = 4398 RttStats* rtt_stats = QuicSentPacketManagerPeer::GetRttStats(manager_);
4228 QuicSentPacketManagerPeer::GetRttStats(sent_packet_manager);
4229 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(300), 4399 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(300),
4230 QuicTime::Delta::Zero(), QuicTime::Zero()); 4400 QuicTime::Delta::Zero(), QuicTime::Zero());
4231 visitor->OnRttChange(); 4401 visitor->OnRttChange();
4232 EXPECT_LT(QuicTime::Delta::Zero(), generator->fec_timeout()); 4402 EXPECT_LT(QuicTime::Delta::Zero(),
4403 QuicPacketGeneratorPeer::GetFecTimeout(generator_));
4233 } 4404 }
4234 4405
4235 class MockQuicConnectionDebugVisitor 4406 class MockQuicConnectionDebugVisitor
4236 : public QuicConnectionDebugVisitor { 4407 : public QuicConnectionDebugVisitor {
4237 public: 4408 public:
4238 MOCK_METHOD1(OnFrameAddedToPacket, 4409 MOCK_METHOD1(OnFrameAddedToPacket,
4239 void(const QuicFrame&)); 4410 void(const QuicFrame&));
4240 4411
4241 MOCK_METHOD6(OnPacketSent, 4412 MOCK_METHOD6(OnPacketSent,
4242 void(const SerializedPacket&, 4413 void(const SerializedPacket&,
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
4334 // Regression test for b/18594622 4505 // Regression test for b/18594622
4335 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); 4506 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate);
4336 EXPECT_DFATAL( 4507 EXPECT_DFATAL(
4337 connection_.SendStreamDataWithString(3, "", 0, !kFin, delegate.get()), 4508 connection_.SendStreamDataWithString(3, "", 0, !kFin, delegate.get()),
4338 "Attempt to send empty stream frame"); 4509 "Attempt to send empty stream frame");
4339 } 4510 }
4340 4511
4341 } // namespace 4512 } // namespace
4342 } // namespace test 4513 } // namespace test
4343 } // namespace net 4514 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection.cc ('k') | net/quic/quic_crypto_server_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698