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

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

Issue 862133002: Update from https://crrev.com/312398 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: 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
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 21 matching lines...) Expand all
58 59
59 const bool kFin = true; 60 const bool kFin = true;
60 const bool kEntropyFlag = true; 61 const bool kEntropyFlag = true;
61 62
62 const QuicPacketEntropyHash kTestEntropyHash = 76; 63 const QuicPacketEntropyHash kTestEntropyHash = 76;
63 64
64 const int kDefaultRetransmissionTimeMs = 500; 65 const int kDefaultRetransmissionTimeMs = 500;
65 66
66 class TestReceiveAlgorithm : public ReceiveAlgorithmInterface { 67 class TestReceiveAlgorithm : public ReceiveAlgorithmInterface {
67 public: 68 public:
68 explicit TestReceiveAlgorithm(QuicCongestionFeedbackFrame* feedback) 69 TestReceiveAlgorithm() {}
69 : feedback_(feedback) {
70 }
71
72 bool GenerateCongestionFeedback(
73 QuicCongestionFeedbackFrame* congestion_feedback) override {
74 if (feedback_ == nullptr) {
75 return false;
76 }
77 *congestion_feedback = *feedback_;
78 return true;
79 }
80 70
81 MOCK_METHOD3(RecordIncomingPacket, 71 MOCK_METHOD3(RecordIncomingPacket,
82 void(QuicByteCount, QuicPacketSequenceNumber, QuicTime)); 72 void(QuicByteCount, QuicPacketSequenceNumber, QuicTime));
83 73
84 private: 74 private:
85 QuicCongestionFeedbackFrame* feedback_;
86
87 DISALLOW_COPY_AND_ASSIGN(TestReceiveAlgorithm); 75 DISALLOW_COPY_AND_ASSIGN(TestReceiveAlgorithm);
88 }; 76 };
89 77
90 // TaggingEncrypter appends kTagSize bytes of |tag| to the end of each message. 78 // TaggingEncrypter appends kTagSize bytes of |tag| to the end of each message.
91 class TaggingEncrypter : public QuicEncrypter { 79 class TaggingEncrypter : public QuicEncrypter {
92 public: 80 public:
93 explicit TaggingEncrypter(uint8 tag) 81 explicit TaggingEncrypter(uint8 tag)
94 : tag_(tag) { 82 : tag_(tag) {
95 } 83 }
96 84
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 } 315 }
328 316
329 const QuicPacketHeader& header() { return framer_.header(); } 317 const QuicPacketHeader& header() { return framer_.header(); }
330 318
331 size_t frame_count() const { return framer_.num_frames(); } 319 size_t frame_count() const { return framer_.num_frames(); }
332 320
333 const vector<QuicAckFrame>& ack_frames() const { 321 const vector<QuicAckFrame>& ack_frames() const {
334 return framer_.ack_frames(); 322 return framer_.ack_frames();
335 } 323 }
336 324
337 const vector<QuicCongestionFeedbackFrame>& feedback_frames() const {
338 return framer_.feedback_frames();
339 }
340
341 const vector<QuicStopWaitingFrame>& stop_waiting_frames() const { 325 const vector<QuicStopWaitingFrame>& stop_waiting_frames() const {
342 return framer_.stop_waiting_frames(); 326 return framer_.stop_waiting_frames();
343 } 327 }
344 328
345 const vector<QuicConnectionCloseFrame>& connection_close_frames() const { 329 const vector<QuicConnectionCloseFrame>& connection_close_frames() const {
346 return framer_.connection_close_frames(); 330 return framer_.connection_close_frames();
347 } 331 }
348 332
349 const vector<QuicStreamFrame>& stream_frames() const { 333 const vector<QuicStreamFrame>& stream_frames() const {
350 return framer_.stream_frames(); 334 return framer_.stream_frames();
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 TestConnectionHelper::TestAlarm* GetAckAlarm() { 541 TestConnectionHelper::TestAlarm* GetAckAlarm() {
558 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( 542 return reinterpret_cast<TestConnectionHelper::TestAlarm*>(
559 QuicConnectionPeer::GetAckAlarm(this)); 543 QuicConnectionPeer::GetAckAlarm(this));
560 } 544 }
561 545
562 TestConnectionHelper::TestAlarm* GetPingAlarm() { 546 TestConnectionHelper::TestAlarm* GetPingAlarm() {
563 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( 547 return reinterpret_cast<TestConnectionHelper::TestAlarm*>(
564 QuicConnectionPeer::GetPingAlarm(this)); 548 QuicConnectionPeer::GetPingAlarm(this));
565 } 549 }
566 550
551 TestConnectionHelper::TestAlarm* GetFecAlarm() {
552 return reinterpret_cast<TestConnectionHelper::TestAlarm*>(
553 QuicConnectionPeer::GetFecAlarm(this));
554 }
555
567 TestConnectionHelper::TestAlarm* GetResumeWritesAlarm() { 556 TestConnectionHelper::TestAlarm* GetResumeWritesAlarm() {
568 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( 557 return reinterpret_cast<TestConnectionHelper::TestAlarm*>(
569 QuicConnectionPeer::GetResumeWritesAlarm(this)); 558 QuicConnectionPeer::GetResumeWritesAlarm(this));
570 } 559 }
571 560
572 TestConnectionHelper::TestAlarm* GetRetransmissionAlarm() { 561 TestConnectionHelper::TestAlarm* GetRetransmissionAlarm() {
573 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( 562 return reinterpret_cast<TestConnectionHelper::TestAlarm*>(
574 QuicConnectionPeer::GetRetransmissionAlarm(this)); 563 QuicConnectionPeer::GetRetransmissionAlarm(this));
575 } 564 }
576 565
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 }; 612 };
624 613
625 class QuicConnectionTest : public ::testing::TestWithParam<QuicVersion> { 614 class QuicConnectionTest : public ::testing::TestWithParam<QuicVersion> {
626 protected: 615 protected:
627 QuicConnectionTest() 616 QuicConnectionTest()
628 : connection_id_(42), 617 : connection_id_(42),
629 framer_(SupportedVersions(version()), QuicTime::Zero(), false), 618 framer_(SupportedVersions(version()), QuicTime::Zero(), false),
630 peer_creator_(connection_id_, &framer_, &random_generator_), 619 peer_creator_(connection_id_, &framer_, &random_generator_),
631 send_algorithm_(new StrictMock<MockSendAlgorithm>), 620 send_algorithm_(new StrictMock<MockSendAlgorithm>),
632 loss_algorithm_(new MockLossAlgorithm()), 621 loss_algorithm_(new MockLossAlgorithm()),
622 receive_algorithm_(new TestReceiveAlgorithm),
633 helper_(new TestConnectionHelper(&clock_, &random_generator_)), 623 helper_(new TestConnectionHelper(&clock_, &random_generator_)),
634 writer_(new TestPacketWriter(version(), &clock_)), 624 writer_(new TestPacketWriter(version(), &clock_)),
635 factory_(writer_.get()), 625 factory_(writer_.get()),
636 connection_(connection_id_, IPEndPoint(), helper_.get(), 626 connection_(connection_id_,
637 factory_, false, version()), 627 IPEndPoint(),
628 helper_.get(),
629 factory_,
630 false,
631 version()),
632 creator_(QuicConnectionPeer::GetPacketCreator(&connection_)),
633 generator_(QuicConnectionPeer::GetPacketGenerator(&connection_)),
634 manager_(QuicConnectionPeer::GetSentPacketManager(&connection_)),
638 frame1_(1, false, 0, MakeIOVector(data1)), 635 frame1_(1, false, 0, MakeIOVector(data1)),
639 frame2_(1, false, 3, MakeIOVector(data2)), 636 frame2_(1, false, 3, MakeIOVector(data2)),
640 sequence_number_length_(PACKET_6BYTE_SEQUENCE_NUMBER), 637 sequence_number_length_(PACKET_6BYTE_SEQUENCE_NUMBER),
641 connection_id_length_(PACKET_8BYTE_CONNECTION_ID) { 638 connection_id_length_(PACKET_8BYTE_CONNECTION_ID) {
642 connection_.set_visitor(&visitor_); 639 connection_.set_visitor(&visitor_);
643 connection_.SetSendAlgorithm(send_algorithm_); 640 connection_.SetSendAlgorithm(send_algorithm_);
644 connection_.SetLossAlgorithm(loss_algorithm_); 641 connection_.SetLossAlgorithm(loss_algorithm_);
645 framer_.set_received_entropy_calculator(&entropy_calculator_); 642 framer_.set_received_entropy_calculator(&entropy_calculator_);
646 // Simplify tests by not sending feedback unless specifically configured. 643 connection_.SetReceiveAlgorithm(receive_algorithm_);
647 SetFeedback(nullptr);
648 EXPECT_CALL( 644 EXPECT_CALL(
649 *send_algorithm_, TimeUntilSend(_, _, _)).WillRepeatedly(Return( 645 *send_algorithm_, TimeUntilSend(_, _, _)).WillRepeatedly(Return(
650 QuicTime::Delta::Zero())); 646 QuicTime::Delta::Zero()));
651 EXPECT_CALL(*receive_algorithm_, 647 EXPECT_CALL(*receive_algorithm_,
652 RecordIncomingPacket(_, _, _)).Times(AnyNumber()); 648 RecordIncomingPacket(_, _, _)).Times(AnyNumber());
653 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 649 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
654 .Times(AnyNumber()); 650 .Times(AnyNumber());
655 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly( 651 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly(
656 Return(QuicTime::Delta::Zero())); 652 Return(QuicTime::Delta::Zero()));
657 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( 653 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly(
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 QuicByteCount SendStreamDataToPeer(QuicStreamId id, 823 QuicByteCount SendStreamDataToPeer(QuicStreamId id,
828 StringPiece data, 824 StringPiece data,
829 QuicStreamOffset offset, 825 QuicStreamOffset offset,
830 bool fin, 826 bool fin,
831 QuicPacketSequenceNumber* last_packet) { 827 QuicPacketSequenceNumber* last_packet) {
832 QuicByteCount packet_size; 828 QuicByteCount packet_size;
833 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 829 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
834 .WillOnce(DoAll(SaveArg<3>(&packet_size), Return(true))); 830 .WillOnce(DoAll(SaveArg<3>(&packet_size), Return(true)));
835 connection_.SendStreamDataWithString(id, data, offset, fin, nullptr); 831 connection_.SendStreamDataWithString(id, data, offset, fin, nullptr);
836 if (last_packet != nullptr) { 832 if (last_packet != nullptr) {
837 *last_packet = 833 *last_packet = creator_->sequence_number();
838 QuicConnectionPeer::GetPacketCreator(&connection_)->sequence_number();
839 } 834 }
840 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 835 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
841 .Times(AnyNumber()); 836 .Times(AnyNumber());
842 return packet_size; 837 return packet_size;
843 } 838 }
844 839
845 void SendAckPacketToPeer() { 840 void SendAckPacketToPeer() {
846 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 841 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
847 connection_.SendAck(); 842 connection_.SendAck();
848 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 843 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 920
926 QuicFrames frames; 921 QuicFrames frames;
927 QuicFrame frame(&qccf); 922 QuicFrame frame(&qccf);
928 frames.push_back(frame); 923 frames.push_back(frame);
929 QuicPacket* packet = 924 QuicPacket* packet =
930 BuildUnsizedDataPacket(&framer_, header_, frames).packet; 925 BuildUnsizedDataPacket(&framer_, header_, frames).packet;
931 EXPECT_TRUE(packet != nullptr); 926 EXPECT_TRUE(packet != nullptr);
932 return packet; 927 return packet;
933 } 928 }
934 929
935 void SetFeedback(QuicCongestionFeedbackFrame* feedback) {
936 receive_algorithm_ = new TestReceiveAlgorithm(feedback);
937 connection_.SetReceiveAlgorithm(receive_algorithm_);
938 }
939
940 QuicTime::Delta DefaultRetransmissionTime() { 930 QuicTime::Delta DefaultRetransmissionTime() {
941 return QuicTime::Delta::FromMilliseconds(kDefaultRetransmissionTimeMs); 931 return QuicTime::Delta::FromMilliseconds(kDefaultRetransmissionTimeMs);
942 } 932 }
943 933
944 QuicTime::Delta DefaultDelayedAckTime() { 934 QuicTime::Delta DefaultDelayedAckTime() {
945 return QuicTime::Delta::FromMilliseconds(kMaxDelayedAckTimeMs); 935 return QuicTime::Delta::FromMilliseconds(kMaxDelayedAckTimeMs);
946 } 936 }
947 937
948 // Initialize a frame acknowledging all packets up to largest_observed. 938 // Initialize a frame acknowledging all packets up to largest_observed.
949 const QuicAckFrame InitAckFrame(QuicPacketSequenceNumber largest_observed) { 939 const QuicAckFrame InitAckFrame(QuicPacketSequenceNumber largest_observed) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1017 1007
1018 MockSendAlgorithm* send_algorithm_; 1008 MockSendAlgorithm* send_algorithm_;
1019 MockLossAlgorithm* loss_algorithm_; 1009 MockLossAlgorithm* loss_algorithm_;
1020 TestReceiveAlgorithm* receive_algorithm_; 1010 TestReceiveAlgorithm* receive_algorithm_;
1021 MockClock clock_; 1011 MockClock clock_;
1022 MockRandom random_generator_; 1012 MockRandom random_generator_;
1023 scoped_ptr<TestConnectionHelper> helper_; 1013 scoped_ptr<TestConnectionHelper> helper_;
1024 scoped_ptr<TestPacketWriter> writer_; 1014 scoped_ptr<TestPacketWriter> writer_;
1025 NiceMock<MockPacketWriterFactory> factory_; 1015 NiceMock<MockPacketWriterFactory> factory_;
1026 TestConnection connection_; 1016 TestConnection connection_;
1017 QuicPacketCreator* creator_;
1018 QuicPacketGenerator* generator_;
1019 QuicSentPacketManager* manager_;
1027 StrictMock<MockConnectionVisitor> visitor_; 1020 StrictMock<MockConnectionVisitor> visitor_;
1028 1021
1029 QuicPacketHeader header_; 1022 QuicPacketHeader header_;
1030 QuicStreamFrame frame1_; 1023 QuicStreamFrame frame1_;
1031 QuicStreamFrame frame2_; 1024 QuicStreamFrame frame2_;
1032 scoped_ptr<QuicAckFrame> outgoing_ack_; 1025 scoped_ptr<QuicAckFrame> outgoing_ack_;
1033 scoped_ptr<QuicStopWaitingFrame> stop_waiting_; 1026 scoped_ptr<QuicStopWaitingFrame> stop_waiting_;
1034 QuicSequenceNumberLength sequence_number_length_; 1027 QuicSequenceNumberLength sequence_number_length_;
1035 QuicConnectionIdLength connection_id_length_; 1028 QuicConnectionIdLength connection_id_length_;
1036 1029
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 lost_packets.insert(i * 2); 1160 lost_packets.insert(i * 2);
1168 } 1161 }
1169 } 1162 }
1170 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 1163 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
1171 .WillOnce(Return(lost_packets)); 1164 .WillOnce(Return(lost_packets));
1172 EXPECT_CALL(entropy_calculator_, EntropyHash(511)) 1165 EXPECT_CALL(entropy_calculator_, EntropyHash(511))
1173 .WillOnce(Return(static_cast<QuicPacketEntropyHash>(0))); 1166 .WillOnce(Return(static_cast<QuicPacketEntropyHash>(0)));
1174 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 1167 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
1175 ProcessAckPacket(&frame); 1168 ProcessAckPacket(&frame);
1176 1169
1177 const QuicSentPacketManager& sent_packet_manager =
1178 connection_.sent_packet_manager();
1179 // A truncated ack will not have the true largest observed. 1170 // A truncated ack will not have the true largest observed.
1180 EXPECT_GT(num_packets, sent_packet_manager.largest_observed()); 1171 EXPECT_GT(num_packets, manager_->largest_observed());
1181 1172
1182 AckPacket(192, &frame); 1173 AckPacket(192, &frame);
1183 1174
1184 // Removing one missing packet allows us to ack 192 and one more range, but 1175 // 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. 1176 // 192 has already been declared lost, so it doesn't register as an ack.
1186 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 1177 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
1187 .WillOnce(Return(SequenceNumberSet())); 1178 .WillOnce(Return(SequenceNumberSet()));
1188 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 1179 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
1189 ProcessAckPacket(&frame); 1180 ProcessAckPacket(&frame);
1190 EXPECT_EQ(num_packets, sent_packet_manager.largest_observed()); 1181 EXPECT_EQ(num_packets, manager_->largest_observed());
1191 } 1182 }
1192 1183
1193 TEST_P(QuicConnectionTest, AckReceiptCausesAckSendBadEntropy) { 1184 TEST_P(QuicConnectionTest, AckReceiptCausesAckSendBadEntropy) {
1194 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1185 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1195 1186
1196 ProcessPacket(1); 1187 ProcessPacket(1);
1197 // Delay sending, then queue up an ack. 1188 // Delay sending, then queue up an ack.
1198 EXPECT_CALL(*send_algorithm_, 1189 EXPECT_CALL(*send_algorithm_,
1199 TimeUntilSend(_, _, _)).WillOnce( 1190 TimeUntilSend(_, _, _)).WillOnce(
1200 testing::Return(QuicTime::Delta::FromMicroseconds(1))); 1191 testing::Return(QuicTime::Delta::FromMicroseconds(1)));
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1399 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1409 ProcessPacket(1); 1400 ProcessPacket(1);
1410 1401
1411 peer_creator_.set_sequence_number(1); 1402 peer_creator_.set_sequence_number(1);
1412 QuicAckFrame frame1 = InitAckFrame(0); 1403 QuicAckFrame frame1 = InitAckFrame(0);
1413 ProcessAckPacket(&frame1); 1404 ProcessAckPacket(&frame1);
1414 } 1405 }
1415 1406
1416 TEST_P(QuicConnectionTest, SendingDifferentSequenceNumberLengthsBandwidth) { 1407 TEST_P(QuicConnectionTest, SendingDifferentSequenceNumberLengthsBandwidth) {
1417 QuicPacketSequenceNumber last_packet; 1408 QuicPacketSequenceNumber last_packet;
1418 QuicPacketCreator* creator =
1419 QuicConnectionPeer::GetPacketCreator(&connection_);
1420 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); 1409 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet);
1421 EXPECT_EQ(1u, last_packet); 1410 EXPECT_EQ(1u, last_packet);
1422 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, 1411 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER,
1423 creator->next_sequence_number_length()); 1412 creator_->next_sequence_number_length());
1424 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, 1413 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER,
1425 writer_->header().public_header.sequence_number_length); 1414 writer_->header().public_header.sequence_number_length);
1426 1415
1427 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( 1416 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly(
1428 Return(kMaxPacketSize * 256)); 1417 Return(kMaxPacketSize * 256));
1429 1418
1430 SendStreamDataToPeer(1, "bar", 3, !kFin, &last_packet); 1419 SendStreamDataToPeer(1, "bar", 3, !kFin, &last_packet);
1431 EXPECT_EQ(2u, last_packet); 1420 EXPECT_EQ(2u, last_packet);
1432 EXPECT_EQ(PACKET_2BYTE_SEQUENCE_NUMBER, 1421 EXPECT_EQ(PACKET_2BYTE_SEQUENCE_NUMBER,
1433 creator->next_sequence_number_length()); 1422 creator_->next_sequence_number_length());
1434 // The 1 packet lag is due to the sequence number length being recalculated in 1423 // The 1 packet lag is due to the sequence number length being recalculated in
1435 // QuicConnection after a packet is sent. 1424 // QuicConnection after a packet is sent.
1436 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, 1425 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER,
1437 writer_->header().public_header.sequence_number_length); 1426 writer_->header().public_header.sequence_number_length);
1438 1427
1439 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( 1428 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly(
1440 Return(kMaxPacketSize * 256 * 256)); 1429 Return(kMaxPacketSize * 256 * 256));
1441 1430
1442 SendStreamDataToPeer(1, "foo", 6, !kFin, &last_packet); 1431 SendStreamDataToPeer(1, "foo", 6, !kFin, &last_packet);
1443 EXPECT_EQ(3u, last_packet); 1432 EXPECT_EQ(3u, last_packet);
1444 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, 1433 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER,
1445 creator->next_sequence_number_length()); 1434 creator_->next_sequence_number_length());
1446 EXPECT_EQ(PACKET_2BYTE_SEQUENCE_NUMBER, 1435 EXPECT_EQ(PACKET_2BYTE_SEQUENCE_NUMBER,
1447 writer_->header().public_header.sequence_number_length); 1436 writer_->header().public_header.sequence_number_length);
1448 1437
1449 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( 1438 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly(
1450 Return(kMaxPacketSize * 256 * 256 * 256)); 1439 Return(kMaxPacketSize * 256 * 256 * 256));
1451 1440
1452 SendStreamDataToPeer(1, "bar", 9, !kFin, &last_packet); 1441 SendStreamDataToPeer(1, "bar", 9, !kFin, &last_packet);
1453 EXPECT_EQ(4u, last_packet); 1442 EXPECT_EQ(4u, last_packet);
1454 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, 1443 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER,
1455 creator->next_sequence_number_length()); 1444 creator_->next_sequence_number_length());
1456 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, 1445 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER,
1457 writer_->header().public_header.sequence_number_length); 1446 writer_->header().public_header.sequence_number_length);
1458 1447
1459 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( 1448 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly(
1460 Return(kMaxPacketSize * 256 * 256 * 256 * 256)); 1449 Return(kMaxPacketSize * 256 * 256 * 256 * 256));
1461 1450
1462 SendStreamDataToPeer(1, "foo", 12, !kFin, &last_packet); 1451 SendStreamDataToPeer(1, "foo", 12, !kFin, &last_packet);
1463 EXPECT_EQ(5u, last_packet); 1452 EXPECT_EQ(5u, last_packet);
1464 EXPECT_EQ(PACKET_6BYTE_SEQUENCE_NUMBER, 1453 EXPECT_EQ(PACKET_6BYTE_SEQUENCE_NUMBER,
1465 creator->next_sequence_number_length()); 1454 creator_->next_sequence_number_length());
1466 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, 1455 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER,
1467 writer_->header().public_header.sequence_number_length); 1456 writer_->header().public_header.sequence_number_length);
1468 } 1457 }
1469 1458
1470 // TODO(ianswett): Re-enable this test by finding a good way to test different 1459 // TODO(ianswett): Re-enable this test by finding a good way to test different
1471 // sequence number lengths without sending packets with giant gaps. 1460 // sequence number lengths without sending packets with giant gaps.
1472 TEST_P(QuicConnectionTest, 1461 TEST_P(QuicConnectionTest,
1473 DISABLED_SendingDifferentSequenceNumberLengthsUnackedDelta) { 1462 DISABLED_SendingDifferentSequenceNumberLengthsUnackedDelta) {
1474 QuicPacketSequenceNumber last_packet; 1463 QuicPacketSequenceNumber last_packet;
1475 QuicPacketCreator* creator =
1476 QuicConnectionPeer::GetPacketCreator(&connection_);
1477 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); 1464 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet);
1478 EXPECT_EQ(1u, last_packet); 1465 EXPECT_EQ(1u, last_packet);
1479 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, 1466 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER,
1480 creator->next_sequence_number_length()); 1467 creator_->next_sequence_number_length());
1481 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, 1468 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER,
1482 writer_->header().public_header.sequence_number_length); 1469 writer_->header().public_header.sequence_number_length);
1483 1470
1484 creator->set_sequence_number(100); 1471 creator_->set_sequence_number(100);
1485 1472
1486 SendStreamDataToPeer(1, "bar", 3, !kFin, &last_packet); 1473 SendStreamDataToPeer(1, "bar", 3, !kFin, &last_packet);
1487 EXPECT_EQ(PACKET_2BYTE_SEQUENCE_NUMBER, 1474 EXPECT_EQ(PACKET_2BYTE_SEQUENCE_NUMBER,
1488 creator->next_sequence_number_length()); 1475 creator_->next_sequence_number_length());
1489 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, 1476 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER,
1490 writer_->header().public_header.sequence_number_length); 1477 writer_->header().public_header.sequence_number_length);
1491 1478
1492 creator->set_sequence_number(100 * 256); 1479 creator_->set_sequence_number(100 * 256);
1493 1480
1494 SendStreamDataToPeer(1, "foo", 6, !kFin, &last_packet); 1481 SendStreamDataToPeer(1, "foo", 6, !kFin, &last_packet);
1495 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, 1482 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER,
1496 creator->next_sequence_number_length()); 1483 creator_->next_sequence_number_length());
1497 EXPECT_EQ(PACKET_2BYTE_SEQUENCE_NUMBER, 1484 EXPECT_EQ(PACKET_2BYTE_SEQUENCE_NUMBER,
1498 writer_->header().public_header.sequence_number_length); 1485 writer_->header().public_header.sequence_number_length);
1499 1486
1500 creator->set_sequence_number(100 * 256 * 256); 1487 creator_->set_sequence_number(100 * 256 * 256);
1501 1488
1502 SendStreamDataToPeer(1, "bar", 9, !kFin, &last_packet); 1489 SendStreamDataToPeer(1, "bar", 9, !kFin, &last_packet);
1503 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, 1490 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER,
1504 creator->next_sequence_number_length()); 1491 creator_->next_sequence_number_length());
1505 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, 1492 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER,
1506 writer_->header().public_header.sequence_number_length); 1493 writer_->header().public_header.sequence_number_length);
1507 1494
1508 creator->set_sequence_number(100 * 256 * 256 * 256); 1495 creator_->set_sequence_number(100 * 256 * 256 * 256);
1509 1496
1510 SendStreamDataToPeer(1, "foo", 12, !kFin, &last_packet); 1497 SendStreamDataToPeer(1, "foo", 12, !kFin, &last_packet);
1511 EXPECT_EQ(PACKET_6BYTE_SEQUENCE_NUMBER, 1498 EXPECT_EQ(PACKET_6BYTE_SEQUENCE_NUMBER,
1512 creator->next_sequence_number_length()); 1499 creator_->next_sequence_number_length());
1513 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, 1500 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER,
1514 writer_->header().public_header.sequence_number_length); 1501 writer_->header().public_header.sequence_number_length);
1515 } 1502 }
1516 1503
1517 TEST_P(QuicConnectionTest, BasicSending) { 1504 TEST_P(QuicConnectionTest, BasicSending) {
1518 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1505 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1519 QuicPacketSequenceNumber last_packet; 1506 QuicPacketSequenceNumber last_packet;
1520 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 1507 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1
1521 EXPECT_EQ(1u, last_packet); 1508 EXPECT_EQ(1u, last_packet);
1522 SendAckPacketToPeer(); // Packet 2 1509 SendAckPacketToPeer(); // Packet 2
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1628 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 1615 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
1629 .WillOnce(DoAll(SaveArg<0>(&actual_recorded_send_time), Return(true))); 1616 .WillOnce(DoAll(SaveArg<0>(&actual_recorded_send_time), Return(true)));
1630 connection_.SendStreamDataWithString(2, "baz", 0, !kFin, nullptr); 1617 connection_.SendStreamDataWithString(2, "baz", 0, !kFin, nullptr);
1631 EXPECT_EQ(expected_recorded_send_time, actual_recorded_send_time) 1618 EXPECT_EQ(expected_recorded_send_time, actual_recorded_send_time)
1632 << "Expected time = " << expected_recorded_send_time.ToDebuggingValue() 1619 << "Expected time = " << expected_recorded_send_time.ToDebuggingValue()
1633 << ". Actual time = " << actual_recorded_send_time.ToDebuggingValue(); 1620 << ". Actual time = " << actual_recorded_send_time.ToDebuggingValue();
1634 } 1621 }
1635 1622
1636 TEST_P(QuicConnectionTest, FECSending) { 1623 TEST_P(QuicConnectionTest, FECSending) {
1637 // All packets carry version info till version is negotiated. 1624 // All packets carry version info till version is negotiated.
1638 QuicPacketCreator* creator =
1639 QuicConnectionPeer::GetPacketCreator(&connection_);
1640 size_t payload_length; 1625 size_t payload_length;
1641 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining 1626 // 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 1627 // 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 1628 // offset 0, and 2 for non-zero offsets up through 64K. Increase
1644 // max_packet_length by 2 so that subsequent packets containing subsequent 1629 // max_packet_length by 2 so that subsequent packets containing subsequent
1645 // stream frames with non-zero offets will fit within the packet length. 1630 // stream frames with non-zero offets will fit within the packet length.
1646 size_t length = 2 + GetPacketLengthForOneStream( 1631 size_t length = 2 + GetPacketLengthForOneStream(
1647 connection_.version(), kIncludeVersion, 1632 connection_.version(), kIncludeVersion,
1648 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, 1633 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER,
1649 IN_FEC_GROUP, &payload_length); 1634 IN_FEC_GROUP, &payload_length);
1650 creator->set_max_packet_length(length); 1635 creator_->set_max_packet_length(length);
1651 1636
1652 // Send 4 protected data packets, which should also trigger 1 FEC packet. 1637 // Send 4 protected data packets, which should also trigger 1 FEC packet.
1653 EXPECT_CALL(*send_algorithm_, 1638 EXPECT_CALL(*send_algorithm_,
1654 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(5); 1639 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(5);
1655 // The first stream frame will have 2 fewer overhead bytes than the other 3. 1640 // The first stream frame will have 2 fewer overhead bytes than the other 3.
1656 const string payload(payload_length * 4 + 2, 'a'); 1641 const string payload(payload_length * 4 + 2, 'a');
1657 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, nullptr); 1642 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, nullptr);
1658 // Expect the FEC group to be closed after SendStreamDataWithString. 1643 // Expect the FEC group to be closed after SendStreamDataWithString.
1659 EXPECT_FALSE(creator->IsFecGroupOpen()); 1644 EXPECT_FALSE(creator_->IsFecGroupOpen());
1660 EXPECT_FALSE(creator->IsFecProtected()); 1645 EXPECT_FALSE(creator_->IsFecProtected());
1661 } 1646 }
1662 1647
1663 TEST_P(QuicConnectionTest, FECQueueing) { 1648 TEST_P(QuicConnectionTest, FECQueueing) {
1664 // All packets carry version info till version is negotiated. 1649 // All packets carry version info till version is negotiated.
1665 size_t payload_length; 1650 size_t payload_length;
1666 QuicPacketCreator* creator =
1667 QuicConnectionPeer::GetPacketCreator(&connection_);
1668 size_t length = GetPacketLengthForOneStream( 1651 size_t length = GetPacketLengthForOneStream(
1669 connection_.version(), kIncludeVersion, 1652 connection_.version(), kIncludeVersion,
1670 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, 1653 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER,
1671 IN_FEC_GROUP, &payload_length); 1654 IN_FEC_GROUP, &payload_length);
1672 creator->set_max_packet_length(length); 1655 creator_->set_max_packet_length(length);
1673 EXPECT_TRUE(creator->IsFecEnabled()); 1656 EXPECT_TRUE(creator_->IsFecEnabled());
1674 1657
1675 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1658 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1676 BlockOnNextWrite(); 1659 BlockOnNextWrite();
1677 const string payload(payload_length, 'a'); 1660 const string payload(payload_length, 'a');
1678 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, nullptr); 1661 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, nullptr);
1679 EXPECT_FALSE(creator->IsFecGroupOpen()); 1662 EXPECT_FALSE(creator_->IsFecGroupOpen());
1680 EXPECT_FALSE(creator->IsFecProtected()); 1663 EXPECT_FALSE(creator_->IsFecProtected());
1681 // Expect the first data packet and the fec packet to be queued. 1664 // Expect the first data packet and the fec packet to be queued.
1682 EXPECT_EQ(2u, connection_.NumQueuedPackets()); 1665 EXPECT_EQ(2u, connection_.NumQueuedPackets());
1683 } 1666 }
1684 1667
1668 TEST_P(QuicConnectionTest, FECAlarmStoppedWhenFECPacketSent) {
1669 EXPECT_TRUE(creator_->IsFecEnabled());
1670 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1671 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet());
1672
1673 creator_->set_max_packets_per_fec_group(2);
1674
1675 // 1 Data packet. FEC alarm should be set.
1676 EXPECT_CALL(*send_algorithm_,
1677 OnPacketSent(_, _, 1u, _, HAS_RETRANSMITTABLE_DATA)).Times(1);
1678 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, true, nullptr);
1679 EXPECT_TRUE(connection_.GetFecAlarm()->IsSet());
1680
1681 // Second data packet triggers FEC packet out. FEC alarm should not be set.
1682 EXPECT_CALL(*send_algorithm_,
1683 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(2);
1684 connection_.SendStreamDataWithStringWithFec(5, "foo", 0, true, nullptr);
1685 EXPECT_TRUE(writer_->header().fec_flag);
1686 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet());
1687 }
1688
1689 TEST_P(QuicConnectionTest, FECAlarmStoppedOnConnectionClose) {
1690 EXPECT_TRUE(creator_->IsFecEnabled());
1691 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet());
1692 creator_->set_max_packets_per_fec_group(100);
1693
1694 // 1 Data packet. FEC alarm should be set.
1695 EXPECT_CALL(*send_algorithm_,
1696 OnPacketSent(_, _, 1u, _, HAS_RETRANSMITTABLE_DATA)).Times(1);
1697 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, kFin, nullptr);
1698 EXPECT_TRUE(connection_.GetFecAlarm()->IsSet());
1699
1700 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_NO_ERROR, false));
1701 // Closing connection should stop the FEC alarm.
1702 connection_.CloseConnection(QUIC_NO_ERROR, /*from_peer=*/false);
1703 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet());
1704 }
1705
1685 TEST_P(QuicConnectionTest, RemoveFECFromInflightOnRetransmissionTimeout) { 1706 TEST_P(QuicConnectionTest, RemoveFECFromInflightOnRetransmissionTimeout) {
1686 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1707 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1687 EXPECT_TRUE(QuicConnectionPeer::GetPacketCreator( 1708 EXPECT_TRUE(creator_->IsFecEnabled());
1688 &connection_)->IsFecEnabled()); 1709 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1689 QuicSentPacketManager* manager = 1710 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet());
1690 QuicConnectionPeer::GetSentPacketManager(&connection_);
1691 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager));
1692 1711
1693 // 1 Data and 1 FEC packet. 1712 // 1 Data packet. FEC alarm should be set.
1694 EXPECT_CALL(*send_algorithm_, 1713 EXPECT_CALL(*send_algorithm_,
1695 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(2); 1714 OnPacketSent(_, _, 1u, _, HAS_RETRANSMITTABLE_DATA)).Times(1);
1696 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, nullptr); 1715 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, nullptr);
1697 size_t data_and_fec = QuicSentPacketManagerPeer::GetBytesInFlight(manager); 1716 EXPECT_TRUE(connection_.GetFecAlarm()->IsSet());
1698 EXPECT_LT(0u, data_and_fec); 1717 size_t protected_packet =
1718 QuicSentPacketManagerPeer::GetBytesInFlight(manager_);
1699 1719
1720 // Force FEC timeout to send FEC packet out.
1721 EXPECT_CALL(*send_algorithm_,
1722 OnPacketSent(_, _, 2u, _, HAS_RETRANSMITTABLE_DATA)).Times(1);
1723 connection_.GetFecAlarm()->Fire();
1724 EXPECT_TRUE(writer_->header().fec_flag);
1725
1726 size_t fec_packet = protected_packet;
1727 EXPECT_EQ(protected_packet + fec_packet,
1728 QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1700 clock_.AdvanceTime(DefaultRetransmissionTime()); 1729 clock_.AdvanceTime(DefaultRetransmissionTime());
1701 1730
1702 // On RTO, both data and FEC packets are removed from inflight, 1731 // 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. 1732 // packet is retransmitted, and this retransmission (but not FEC) gets added
1733 // back into the inflight.
1704 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 1734 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
1705 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 1735 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
1706 connection_.GetRetransmissionAlarm()->Fire(); 1736 connection_.GetRetransmissionAlarm()->Fire();
1707 1737
1708 size_t data_only = QuicSentPacketManagerPeer::GetBytesInFlight(manager); 1738 // The retransmission of packet 1 will be 3 bytes smaller than packet 1, since
1709 EXPECT_LT(0u, data_only); 1739 // the first transmission will have 1 byte for FEC group number and 2 bytes of
1710 EXPECT_GE(data_and_fec, 2 * data_only); 1740 // stream frame size, which are absent in the retransmission.
1741 size_t retransmitted_packet = protected_packet - 3;
1742 if (FLAGS_quic_use_new_rto) {
1743 EXPECT_EQ(protected_packet + retransmitted_packet,
1744 QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1745 } else {
1746 EXPECT_EQ(retransmitted_packet,
1747 QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1748 }
1749 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet());
1711 1750
1712 // Receive ack for the retransmission. No data should be outstanding. 1751 // Receive ack for the retransmission. No data should be outstanding.
1713 QuicAckFrame ack = InitAckFrame(3); 1752 QuicAckFrame ack = InitAckFrame(3);
1714 NackPacket(1, &ack); 1753 NackPacket(1, &ack);
1715 NackPacket(2, &ack); 1754 NackPacket(2, &ack);
1716 SequenceNumberSet lost_packets; 1755 SequenceNumberSet lost_packets;
1756 if (FLAGS_quic_use_new_rto) {
1757 lost_packets.insert(1);
1758 }
1717 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 1759 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
1718 .WillOnce(Return(lost_packets)); 1760 .WillOnce(Return(lost_packets));
1719 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 1761 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
1720 ProcessAckPacket(&ack); 1762 ProcessAckPacket(&ack);
1721 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager));
1722 1763
1723 // Ensure the alarm is not set since all packets have been acked or abandoned. 1764 // Ensure the alarm is not set since all packets have been acked or abandoned.
1724 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 1765 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
1725 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager)); 1766 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1726 } 1767 }
1727 1768
1728 TEST_P(QuicConnectionTest, RemoveFECFromInflightOnLossRetransmission) { 1769 TEST_P(QuicConnectionTest, RemoveFECFromInflightOnLossRetransmission) {
1729 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1770 EXPECT_TRUE(creator_->IsFecEnabled());
1730 EXPECT_TRUE(QuicConnectionPeer::GetPacketCreator( 1771 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet());
1731 &connection_)->IsFecEnabled());
1732 QuicSentPacketManager* manager =
1733 QuicConnectionPeer::GetSentPacketManager(&connection_);
1734 1772
1735 // 1 Data packet and 1 FEC packet, followed by more data to trigger NACKs. 1773 // 1 FEC-protected data packet. FEC alarm should be set.
1736 EXPECT_CALL(*send_algorithm_, 1774 EXPECT_CALL(*send_algorithm_,
1737 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(6); 1775 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(1);
1738 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, nullptr); 1776 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, kFin, nullptr);
1739 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, nullptr); 1777 EXPECT_TRUE(connection_.GetFecAlarm()->IsSet());
1740 connection_.SendStreamDataWithString(3, "foo", 6, !kFin, nullptr); 1778 size_t protected_packet =
1741 connection_.SendStreamDataWithString(3, "foo", 9, !kFin, nullptr); 1779 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 1780
1747 // Ack data packets, and NACK 1 data packet and FEC packet. Triggers 1781 // Force FEC timeout to send FEC packet out.
1748 // NACK-based loss detection of data and FEC packet, but only data is 1782 EXPECT_CALL(*send_algorithm_,
1783 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(1);
1784 connection_.GetFecAlarm()->Fire();
1785 EXPECT_TRUE(writer_->header().fec_flag);
1786 size_t fec_packet = protected_packet;
1787 EXPECT_EQ(protected_packet + fec_packet,
1788 QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1789
1790 // Send more data to trigger NACKs. Note that all data starts at stream offset
1791 // 0 to ensure the same packet size, for ease of testing.
1792 EXPECT_CALL(*send_algorithm_,
1793 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(4);
1794 connection_.SendStreamDataWithString(5, "foo", 0, kFin, nullptr);
1795 connection_.SendStreamDataWithString(7, "foo", 0, kFin, nullptr);
1796 connection_.SendStreamDataWithString(9, "foo", 0, kFin, nullptr);
1797 connection_.SendStreamDataWithString(11, "foo", 0, kFin, nullptr);
1798
1799 // An unprotected packet will be 3 bytes smaller than an FEC-protected packet,
1800 // since the protected packet will have 1 byte for FEC group number and
1801 // 2 bytes of stream frame size, which are absent in the unprotected packet.
1802 size_t unprotected_packet = protected_packet - 3;
1803 EXPECT_EQ(protected_packet + fec_packet + 4 * unprotected_packet,
1804 QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1805 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet());
1806
1807 // Ack data packets, and NACK FEC packet and one data packet. Triggers
1808 // NACK-based loss detection of both packets, but only data packet is
1749 // retransmitted and considered oustanding. 1809 // retransmitted and considered oustanding.
1750 QuicAckFrame ack = InitAckFrame(6); 1810 QuicAckFrame ack = InitAckFrame(6);
1751 NackPacket(2, &ack); 1811 NackPacket(2, &ack);
1752 NackPacket(3, &ack); 1812 NackPacket(3, &ack);
1753 SequenceNumberSet lost_packets; 1813 SequenceNumberSet lost_packets;
1754 lost_packets.insert(2); 1814 lost_packets.insert(2);
1755 lost_packets.insert(3); 1815 lost_packets.insert(3);
1756 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 1816 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
1757 .WillOnce(Return(lost_packets)); 1817 .WillOnce(Return(lost_packets));
1758 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 1818 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
1759 EXPECT_CALL(*send_algorithm_, 1819 EXPECT_CALL(*send_algorithm_,
1760 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(1); 1820 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(1);
1821 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1761 ProcessAckPacket(&ack); 1822 ProcessAckPacket(&ack);
1762 size_t data_only = QuicSentPacketManagerPeer::GetBytesInFlight(manager); 1823 // On receiving this ack from the server, the client will no longer send
1763 EXPECT_GT(multiple_data_and_fec, data_only); 1824 // version number in subsequent packets, including in this retransmission.
1764 EXPECT_LT(0u, data_only); 1825 size_t unprotected_packet_no_version = unprotected_packet - 4;
1826 EXPECT_EQ(unprotected_packet_no_version,
1827 QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1765 1828
1766 // Receive ack for the retransmission. No data should be outstanding. 1829 // Receive ack for the retransmission. No data should be outstanding.
1767 QuicAckFrame ack2 = InitAckFrame(7); 1830 QuicAckFrame ack2 = InitAckFrame(7);
1768 NackPacket(2, &ack2); 1831 NackPacket(2, &ack2);
1769 NackPacket(3, &ack2); 1832 NackPacket(3, &ack2);
1770 SequenceNumberSet lost_packets2; 1833 SequenceNumberSet lost_packets2;
1771 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 1834 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
1772 .WillOnce(Return(lost_packets2)); 1835 .WillOnce(Return(lost_packets2));
1773 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 1836 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
1774 ProcessAckPacket(&ack2); 1837 ProcessAckPacket(&ack2);
1775 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager)); 1838 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1839 }
1840
1841 TEST_P(QuicConnectionTest, FECRemainsInflightOnTLPOfEarlierData) {
1842 // This test checks if TLP is sent correctly when a data and an FEC packet
1843 // are outstanding. TLP should be sent for the data packet when the
1844 // retransmission alarm fires.
1845 // Turn on TLP for this test.
1846 QuicSentPacketManagerPeer::SetMaxTailLossProbes(manager_, 1);
1847 EXPECT_TRUE(creator_->IsFecEnabled());
1848 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1849 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet());
1850
1851 // 1 Data packet. FEC alarm should be set.
1852 EXPECT_CALL(*send_algorithm_,
1853 OnPacketSent(_, _, 1u, _, HAS_RETRANSMITTABLE_DATA)).Times(1);
1854 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, kFin, nullptr);
1855 EXPECT_TRUE(connection_.GetFecAlarm()->IsSet());
1856 size_t protected_packet =
1857 QuicSentPacketManagerPeer::GetBytesInFlight(manager_);
1858 EXPECT_LT(0u, protected_packet);
1859
1860 // Force FEC timeout to send FEC packet out.
1861 EXPECT_CALL(*send_algorithm_,
1862 OnPacketSent(_, _, 2u, _, HAS_RETRANSMITTABLE_DATA)).Times(1);
1863 connection_.GetFecAlarm()->Fire();
1864 EXPECT_TRUE(writer_->header().fec_flag);
1865 size_t fec_packet = protected_packet;
1866 EXPECT_EQ(protected_packet + fec_packet,
1867 QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1868
1869 // TLP alarm should be set.
1870 QuicTime retransmission_time =
1871 connection_.GetRetransmissionAlarm()->deadline();
1872 EXPECT_NE(QuicTime::Zero(), retransmission_time);
1873 // Simulate the retransmission alarm firing and sending a TLP, so send
1874 // algorithm's OnRetransmissionTimeout is not called.
1875 clock_.AdvanceTime(retransmission_time.Subtract(clock_.Now()));
1876 EXPECT_CALL(*send_algorithm_,
1877 OnPacketSent(_, _, 3u, _, HAS_RETRANSMITTABLE_DATA)).Times(1);
1878 connection_.GetRetransmissionAlarm()->Fire();
1879 // The TLP retransmission of packet 1 will be 3 bytes smaller than packet 1,
1880 // since packet 1 will have 1 byte for FEC group number and 2 bytes of stream
1881 // frame size, which are absent in the the TLP retransmission.
1882 size_t tlp_packet = protected_packet - 3;
1883 EXPECT_EQ(protected_packet + fec_packet + tlp_packet,
1884 QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1885 }
1886
1887 TEST_P(QuicConnectionTest, FECRemainsInflightOnTLPOfLaterData) {
1888 // Tests if TLP is sent correctly when data packet 1 and an FEC packet are
1889 // sent followed by data packet 2, and data packet 1 is acked. TLP should be
1890 // sent for data packet 2 when the retransmission alarm fires. Turn on TLP for
1891 // this test.
1892 QuicSentPacketManagerPeer::SetMaxTailLossProbes(manager_, 1);
1893 EXPECT_TRUE(creator_->IsFecEnabled());
1894 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1895 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet());
1896
1897 // 1 Data packet. FEC alarm should be set.
1898 EXPECT_CALL(*send_algorithm_,
1899 OnPacketSent(_, _, 1u, _, HAS_RETRANSMITTABLE_DATA)).Times(1);
1900 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, kFin, nullptr);
1901 EXPECT_TRUE(connection_.GetFecAlarm()->IsSet());
1902 size_t protected_packet =
1903 QuicSentPacketManagerPeer::GetBytesInFlight(manager_);
1904 EXPECT_LT(0u, protected_packet);
1905
1906 // Force FEC timeout to send FEC packet out.
1907 EXPECT_CALL(*send_algorithm_,
1908 OnPacketSent(_, _, 2u, _, HAS_RETRANSMITTABLE_DATA)).Times(1);
1909 connection_.GetFecAlarm()->Fire();
1910 EXPECT_TRUE(writer_->header().fec_flag);
1911 // Protected data packet and FEC packet oustanding.
1912 size_t fec_packet = protected_packet;
1913 EXPECT_EQ(protected_packet + fec_packet,
1914 QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1915
1916 // Send 1 unprotected data packet. No FEC alarm should be set.
1917 EXPECT_CALL(*send_algorithm_,
1918 OnPacketSent(_, _, 3u, _, HAS_RETRANSMITTABLE_DATA)).Times(1);
1919 connection_.SendStreamDataWithString(5, "foo", 0, kFin, nullptr);
1920 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet());
1921 // Protected data packet, FEC packet, and unprotected data packet oustanding.
1922 // An unprotected packet will be 3 bytes smaller than an FEC-protected packet,
1923 // since the protected packet will have 1 byte for FEC group number and
1924 // 2 bytes of stream frame size, which are absent in the unprotected packet.
1925 size_t unprotected_packet = protected_packet - 3;
1926 EXPECT_EQ(protected_packet + fec_packet + unprotected_packet,
1927 QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1928
1929 // Receive ack for first data packet. FEC and second data packet are still
1930 // outstanding.
1931 QuicAckFrame ack = InitAckFrame(1);
1932 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
1933 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1934 ProcessAckPacket(&ack);
1935 // FEC packet and unprotected data packet oustanding.
1936 EXPECT_EQ(fec_packet + unprotected_packet,
1937 QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1938
1939 // TLP alarm should be set.
1940 QuicTime retransmission_time =
1941 connection_.GetRetransmissionAlarm()->deadline();
1942 EXPECT_NE(QuicTime::Zero(), retransmission_time);
1943 // Simulate the retransmission alarm firing and sending a TLP, so send
1944 // algorithm's OnRetransmissionTimeout is not called.
1945 clock_.AdvanceTime(retransmission_time.Subtract(clock_.Now()));
1946 EXPECT_CALL(*send_algorithm_,
1947 OnPacketSent(_, _, 4u, _, HAS_RETRANSMITTABLE_DATA)).Times(1);
1948 connection_.GetRetransmissionAlarm()->Fire();
1949
1950 // Having received an ack from the server, the client will no longer send
1951 // version number in subsequent packets, including in this retransmission.
1952 size_t tlp_packet_no_version = unprotected_packet - 4;
1953 EXPECT_EQ(fec_packet + unprotected_packet + tlp_packet_no_version,
1954 QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1776 } 1955 }
1777 1956
1778 TEST_P(QuicConnectionTest, NoTLPForFECPacket) { 1957 TEST_P(QuicConnectionTest, NoTLPForFECPacket) {
1779 // Turn on TLP for this test. 1958 // Turn on TLP for this test.
1780 QuicSentPacketManagerPeer::SetMaxTailLossProbes( 1959 QuicSentPacketManagerPeer::SetMaxTailLossProbes(manager_, 1);
1781 QuicConnectionPeer::GetSentPacketManager(&connection_), 1); 1960 EXPECT_TRUE(creator_->IsFecEnabled());
1961 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1782 1962
1783 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1963 // 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_, 1964 EXPECT_CALL(*send_algorithm_,
1791 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(2); 1965 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(1);
1792 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, nullptr); 1966 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, nullptr);
1967 EXPECT_TRUE(connection_.GetFecAlarm()->IsSet());
1968 // Force FEC timeout to send FEC packet out.
1969 EXPECT_CALL(*send_algorithm_,
1970 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(1);
1971 connection_.GetFecAlarm()->Fire();
1972 EXPECT_TRUE(writer_->header().fec_flag);
1793 1973
1794 // Ack data packet, but not FEC packet. 1974 // Ack data packet, but not FEC packet.
1795 QuicAckFrame ack = InitAckFrame(1); 1975 QuicAckFrame ack = InitAckFrame(1);
1796 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 1976 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
1797 ProcessAckPacket(&ack); 1977 ProcessAckPacket(&ack);
1798 1978
1799 // No TLP alarm for FEC, so when retransmission alarm fires, it is an RTO. 1979 // No TLP alarm for FEC, but retransmission alarm should be set for an RTO.
1980 EXPECT_LT(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1800 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 1981 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
1801 EXPECT_LT(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager));
1802 QuicTime rto_time = connection_.GetRetransmissionAlarm()->deadline(); 1982 QuicTime rto_time = connection_.GetRetransmissionAlarm()->deadline();
1803 EXPECT_NE(QuicTime::Zero(), rto_time); 1983 EXPECT_NE(QuicTime::Zero(), rto_time);
1804 1984
1805 // Simulate the retransmission alarm firing. FEC packet is no longer 1985 // Simulate the retransmission alarm firing. FEC packet is no longer
1806 // outstanding. 1986 // outstanding.
1807 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(false)); 1987 if (!FLAGS_quic_use_new_rto) {
1988 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(false));
1989 }
1808 clock_.AdvanceTime(rto_time.Subtract(clock_.Now())); 1990 clock_.AdvanceTime(rto_time.Subtract(clock_.Now()));
1809 connection_.GetRetransmissionAlarm()->Fire(); 1991 connection_.GetRetransmissionAlarm()->Fire();
1992
1810 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 1993 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
1811 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager)); 1994 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1812 } 1995 }
1813 1996
1814 TEST_P(QuicConnectionTest, FramePacking) { 1997 TEST_P(QuicConnectionTest, FramePacking) {
1815 CongestionBlockWrites(); 1998 CongestionBlockWrites();
1816 1999
1817 // Send an ack and two stream frames in 1 packet by queueing them. 2000 // Send an ack and two stream frames in 1 packet by queueing them.
1818 connection_.SendAck(); 2001 connection_.SendAck();
1819 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( 2002 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll(
1820 IgnoreResult(InvokeWithoutArgs(&connection_, 2003 IgnoreResult(InvokeWithoutArgs(&connection_,
1821 &TestConnection::SendStreamData3)), 2004 &TestConnection::SendStreamData3)),
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1880 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2063 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1881 EXPECT_FALSE(connection_.HasQueuedData()); 2064 EXPECT_FALSE(connection_.HasQueuedData());
1882 2065
1883 // Parse the last packet and ensure it's the stream frame from stream 3. 2066 // Parse the last packet and ensure it's the stream frame from stream 3.
1884 EXPECT_EQ(1u, writer_->frame_count()); 2067 EXPECT_EQ(1u, writer_->frame_count());
1885 ASSERT_EQ(1u, writer_->stream_frames().size()); 2068 ASSERT_EQ(1u, writer_->stream_frames().size());
1886 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0].stream_id); 2069 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0].stream_id);
1887 } 2070 }
1888 2071
1889 TEST_P(QuicConnectionTest, FramePackingFEC) { 2072 TEST_P(QuicConnectionTest, FramePackingFEC) {
1890 EXPECT_TRUE(QuicConnectionPeer::GetPacketCreator( 2073 EXPECT_TRUE(creator_->IsFecEnabled());
1891 &connection_)->IsFecEnabled());
1892 2074
1893 CongestionBlockWrites(); 2075 CongestionBlockWrites();
1894 2076
1895 // Queue an ack and two stream frames. Ack gets flushed when FEC is turned on 2077 // 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. 2078 // for sending protected data; two stream frames are packed in 1 packet.
1897 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( 2079 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll(
1898 IgnoreResult(InvokeWithoutArgs( 2080 IgnoreResult(InvokeWithoutArgs(
1899 &connection_, &TestConnection::SendStreamData3WithFec)), 2081 &connection_, &TestConnection::SendStreamData3WithFec)),
1900 IgnoreResult(InvokeWithoutArgs( 2082 IgnoreResult(InvokeWithoutArgs(
1901 &connection_, &TestConnection::SendStreamData5WithFec)))); 2083 &connection_, &TestConnection::SendStreamData5WithFec))));
1902 connection_.SendAck(); 2084 connection_.SendAck();
1903 2085
1904 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3); 2086 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
1905 CongestionUnblockWrites(); 2087 CongestionUnblockWrites();
1906 connection_.GetSendAlarm()->Fire(); 2088 connection_.GetSendAlarm()->Fire();
1907 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2089 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1908 EXPECT_FALSE(connection_.HasQueuedData()); 2090 EXPECT_FALSE(connection_.HasQueuedData());
1909 2091
1910 // Parse the last packet and ensure it's in an fec group. 2092 // Parse the last packet and ensure it's in an fec group.
1911 EXPECT_EQ(2u, writer_->header().fec_group); 2093 EXPECT_EQ(2u, writer_->header().fec_group);
1912 EXPECT_EQ(0u, writer_->frame_count()); 2094 EXPECT_EQ(2u, writer_->frame_count());
2095
2096 // FEC alarm should be set.
2097 EXPECT_TRUE(connection_.GetFecAlarm()->IsSet());
1913 } 2098 }
1914 2099
1915 TEST_P(QuicConnectionTest, FramePackingAckResponse) { 2100 TEST_P(QuicConnectionTest, FramePackingAckResponse) {
1916 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2101 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1917 // Process a data packet to queue up a pending ack. 2102 // Process a data packet to queue up a pending ack.
1918 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); 2103 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1);
1919 ProcessDataPacket(1, 1, kEntropyFlag); 2104 ProcessDataPacket(1, 1, kEntropyFlag);
1920 2105
1921 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( 2106 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll(
1922 IgnoreResult(InvokeWithoutArgs(&connection_, 2107 IgnoreResult(InvokeWithoutArgs(&connection_,
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
2122 OnPacketSent(_, _, _, packet_size - kQuicVersionSize, _)); 2307 OnPacketSent(_, _, _, packet_size - kQuicVersionSize, _));
2123 ProcessAckPacket(&frame); 2308 ProcessAckPacket(&frame);
2124 } 2309 }
2125 2310
2126 TEST_P(QuicConnectionTest, QueueAfterTwoRTOs) { 2311 TEST_P(QuicConnectionTest, QueueAfterTwoRTOs) {
2127 for (int i = 0; i < 10; ++i) { 2312 for (int i = 0; i < 10; ++i) {
2128 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2313 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2129 connection_.SendStreamDataWithString(3, "foo", i * 3, !kFin, nullptr); 2314 connection_.SendStreamDataWithString(3, "foo", i * 3, !kFin, nullptr);
2130 } 2315 }
2131 2316
2132 // Block the congestion window and ensure they're queued. 2317 // Block the writer and ensure they're queued.
2133 BlockOnNextWrite(); 2318 BlockOnNextWrite();
2134 clock_.AdvanceTime(DefaultRetransmissionTime()); 2319 clock_.AdvanceTime(DefaultRetransmissionTime());
2135 // Only one packet should be retransmitted. 2320 // Only one packet should be retransmitted.
2136 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 2321 if (!FLAGS_quic_use_new_rto) {
2322 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
2323 }
2137 connection_.GetRetransmissionAlarm()->Fire(); 2324 connection_.GetRetransmissionAlarm()->Fire();
2138 EXPECT_TRUE(connection_.HasQueuedData()); 2325 EXPECT_TRUE(connection_.HasQueuedData());
2139 2326
2140 // Unblock the congestion window. 2327 // Unblock the writer.
2141 writer_->SetWritable(); 2328 writer_->SetWritable();
2142 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds( 2329 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(
2143 2 * DefaultRetransmissionTime().ToMicroseconds())); 2330 2 * DefaultRetransmissionTime().ToMicroseconds()));
2144 // Retransmit already retransmitted packets event though the sequence number 2331 // Retransmit already retransmitted packets event though the sequence number
2145 // greater than the largest observed. 2332 // greater than the largest observed.
2146 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(10); 2333 if (FLAGS_quic_use_new_rto) {
2334 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
2335 } else {
2336 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(10);
2337 }
2147 connection_.GetRetransmissionAlarm()->Fire(); 2338 connection_.GetRetransmissionAlarm()->Fire();
2148 connection_.OnCanWrite(); 2339 connection_.OnCanWrite();
2149 } 2340 }
2150 2341
2151 TEST_P(QuicConnectionTest, WriteBlockedThenSent) { 2342 TEST_P(QuicConnectionTest, WriteBlockedThenSent) {
2152 BlockOnNextWrite(); 2343 BlockOnNextWrite();
2153 writer_->set_is_write_blocked_data_buffered(true); 2344 writer_->set_is_write_blocked_data_buffered(true);
2154 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2345 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2155 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); 2346 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr);
2156 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 2347 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
2157 2348
2158 writer_->SetWritable(); 2349 writer_->SetWritable();
2159 connection_.OnCanWrite(); 2350 connection_.OnCanWrite();
2160 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 2351 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
2161 } 2352 }
2162 2353
2163 TEST_P(QuicConnectionTest, RetransmitWriteBlockedAckedOriginalThenSent) { 2354 TEST_P(QuicConnectionTest, RetransmitWriteBlockedAckedOriginalThenSent) {
2164 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2355 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2165 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); 2356 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr);
2166 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 2357 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
2167 2358
2168 BlockOnNextWrite(); 2359 BlockOnNextWrite();
2169 writer_->set_is_write_blocked_data_buffered(true); 2360 writer_->set_is_write_blocked_data_buffered(true);
2170 // Simulate the retransmission alarm firing. 2361 // Simulate the retransmission alarm firing.
2171 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(_)); 2362 if (!FLAGS_quic_use_new_rto) {
2363 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(_));
2364 }
2172 clock_.AdvanceTime(DefaultRetransmissionTime()); 2365 clock_.AdvanceTime(DefaultRetransmissionTime());
2173 connection_.GetRetransmissionAlarm()->Fire(); 2366 connection_.GetRetransmissionAlarm()->Fire();
2174 2367
2175 // Ack the sent packet before the callback returns, which happens in 2368 // Ack the sent packet before the callback returns, which happens in
2176 // rare circumstances with write blocked sockets. 2369 // rare circumstances with write blocked sockets.
2177 QuicAckFrame ack = InitAckFrame(1); 2370 QuicAckFrame ack = InitAckFrame(1);
2178 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 2371 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
2179 EXPECT_CALL(*send_algorithm_, RevertRetransmissionTimeout()); 2372 if (!FLAGS_quic_use_new_rto) {
2373 EXPECT_CALL(*send_algorithm_, RevertRetransmissionTimeout());
2374 }
2180 ProcessAckPacket(&ack); 2375 ProcessAckPacket(&ack);
2181 2376
2182 writer_->SetWritable(); 2377 writer_->SetWritable();
2183 connection_.OnCanWrite(); 2378 connection_.OnCanWrite();
2184 // There is now a pending packet, but with no retransmittable frames. 2379 // There is now a pending packet, but with no retransmittable frames.
2185 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 2380 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
2186 EXPECT_FALSE(connection_.sent_packet_manager().HasRetransmittableFrames(2)); 2381 EXPECT_FALSE(connection_.sent_packet_manager().HasRetransmittableFrames(2));
2187 } 2382 }
2188 2383
2189 TEST_P(QuicConnectionTest, AlarmsWhenWriteBlocked) { 2384 TEST_P(QuicConnectionTest, AlarmsWhenWriteBlocked) {
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
2424 ProcessFecPacket(6, 1, false, kEntropyFlag, nullptr); 2619 ProcessFecPacket(6, 1, false, kEntropyFlag, nullptr);
2425 ProcessFecProtectedPacket(3, false, kEntropyFlag); 2620 ProcessFecProtectedPacket(3, false, kEntropyFlag);
2426 ProcessFecProtectedPacket(4, false, kEntropyFlag); 2621 ProcessFecProtectedPacket(4, false, kEntropyFlag);
2427 ProcessFecProtectedPacket(5, true, !kEntropyFlag); 2622 ProcessFecProtectedPacket(5, true, !kEntropyFlag);
2428 // Ensure entropy is not revived for the missing packet. 2623 // Ensure entropy is not revived for the missing packet.
2429 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); 2624 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2));
2430 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 3)); 2625 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 3));
2431 } 2626 }
2432 2627
2433 TEST_P(QuicConnectionTest, TLP) { 2628 TEST_P(QuicConnectionTest, TLP) {
2434 QuicSentPacketManagerPeer::SetMaxTailLossProbes( 2629 QuicSentPacketManagerPeer::SetMaxTailLossProbes(manager_, 1);
2435 QuicConnectionPeer::GetSentPacketManager(&connection_), 1);
2436 2630
2437 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr); 2631 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr);
2438 EXPECT_EQ(1u, stop_waiting()->least_unacked); 2632 EXPECT_EQ(1u, stop_waiting()->least_unacked);
2439 QuicTime retransmission_time = 2633 QuicTime retransmission_time =
2440 connection_.GetRetransmissionAlarm()->deadline(); 2634 connection_.GetRetransmissionAlarm()->deadline();
2441 EXPECT_NE(QuicTime::Zero(), retransmission_time); 2635 EXPECT_NE(QuicTime::Zero(), retransmission_time);
2442 2636
2443 EXPECT_EQ(1u, writer_->header().packet_sequence_number); 2637 EXPECT_EQ(1u, writer_->header().packet_sequence_number);
2444 // Simulate the retransmission alarm firing and sending a tlp, 2638 // Simulate the retransmission alarm firing and sending a tlp,
2445 // so send algorithm's OnRetransmissionTimeout is not called. 2639 // so send algorithm's OnRetransmissionTimeout is not called.
2446 clock_.AdvanceTime(retransmission_time.Subtract(clock_.Now())); 2640 clock_.AdvanceTime(retransmission_time.Subtract(clock_.Now()));
2447 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _)); 2641 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _));
2448 connection_.GetRetransmissionAlarm()->Fire(); 2642 connection_.GetRetransmissionAlarm()->Fire();
2449 EXPECT_EQ(2u, writer_->header().packet_sequence_number); 2643 EXPECT_EQ(2u, writer_->header().packet_sequence_number);
2450 // We do not raise the high water mark yet. 2644 // We do not raise the high water mark yet.
2451 EXPECT_EQ(1u, stop_waiting()->least_unacked); 2645 EXPECT_EQ(1u, stop_waiting()->least_unacked);
2452 } 2646 }
2453 2647
2454 TEST_P(QuicConnectionTest, RTO) { 2648 TEST_P(QuicConnectionTest, RTO) {
2455 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( 2649 QuicTime default_retransmission_time = clock_.ApproximateNow().Add(
2456 DefaultRetransmissionTime()); 2650 DefaultRetransmissionTime());
2457 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr); 2651 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr);
2458 EXPECT_EQ(1u, stop_waiting()->least_unacked); 2652 EXPECT_EQ(1u, stop_waiting()->least_unacked);
2459 2653
2460 EXPECT_EQ(1u, writer_->header().packet_sequence_number); 2654 EXPECT_EQ(1u, writer_->header().packet_sequence_number);
2461 EXPECT_EQ(default_retransmission_time, 2655 EXPECT_EQ(default_retransmission_time,
2462 connection_.GetRetransmissionAlarm()->deadline()); 2656 connection_.GetRetransmissionAlarm()->deadline());
2463 // Simulate the retransmission alarm firing. 2657 // Simulate the retransmission alarm firing.
2464 clock_.AdvanceTime(DefaultRetransmissionTime()); 2658 clock_.AdvanceTime(DefaultRetransmissionTime());
2465 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 2659 if (!FLAGS_quic_use_new_rto) {
2660 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
2661 }
2466 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _)); 2662 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _));
2467 connection_.GetRetransmissionAlarm()->Fire(); 2663 connection_.GetRetransmissionAlarm()->Fire();
2468 EXPECT_EQ(2u, writer_->header().packet_sequence_number); 2664 EXPECT_EQ(2u, writer_->header().packet_sequence_number);
2469 // We do not raise the high water mark yet. 2665 // We do not raise the high water mark yet.
2470 EXPECT_EQ(1u, stop_waiting()->least_unacked); 2666 EXPECT_EQ(1u, stop_waiting()->least_unacked);
2471 } 2667 }
2472 2668
2473 TEST_P(QuicConnectionTest, RTOWithSameEncryptionLevel) { 2669 TEST_P(QuicConnectionTest, RTOWithSameEncryptionLevel) {
2474 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( 2670 QuicTime default_retransmission_time = clock_.ApproximateNow().Add(
2475 DefaultRetransmissionTime()); 2671 DefaultRetransmissionTime());
2476 use_tagging_decrypter(); 2672 use_tagging_decrypter();
2477 2673
2478 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at 2674 // 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. 2675 // the end of the packet. We can test this to check which encrypter was used.
2480 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); 2676 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01));
2481 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr); 2677 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr);
2482 EXPECT_EQ(0x01010101u, writer_->final_bytes_of_last_packet()); 2678 EXPECT_EQ(0x01010101u, writer_->final_bytes_of_last_packet());
2483 2679
2484 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); 2680 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02));
2485 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); 2681 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
2486 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr); 2682 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr);
2487 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet()); 2683 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet());
2488 2684
2489 EXPECT_EQ(default_retransmission_time, 2685 EXPECT_EQ(default_retransmission_time,
2490 connection_.GetRetransmissionAlarm()->deadline()); 2686 connection_.GetRetransmissionAlarm()->deadline());
2491 { 2687 {
2492 InSequence s; 2688 InSequence s;
2493 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 2689 if (!FLAGS_quic_use_new_rto) {
2690 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
2691 }
2494 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 3, _, _)); 2692 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 3, _, _));
2495 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 4, _, _)); 2693 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 4, _, _));
2496 } 2694 }
2497 2695
2498 // Simulate the retransmission alarm firing. 2696 // Simulate the retransmission alarm firing.
2499 clock_.AdvanceTime(DefaultRetransmissionTime()); 2697 clock_.AdvanceTime(DefaultRetransmissionTime());
2500 connection_.GetRetransmissionAlarm()->Fire(); 2698 connection_.GetRetransmissionAlarm()->Fire();
2501 2699
2502 // Packet should have been sent with ENCRYPTION_NONE. 2700 // Packet should have been sent with ENCRYPTION_NONE.
2503 EXPECT_EQ(0x01010101u, writer_->final_bytes_of_previous_packet()); 2701 EXPECT_EQ(0x01010101u, writer_->final_bytes_of_previous_packet());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2537 2735
2538 TEST_P(QuicConnectionTest, 2736 TEST_P(QuicConnectionTest,
2539 DropRetransmitsForNullEncryptedPacketAfterForwardSecure) { 2737 DropRetransmitsForNullEncryptedPacketAfterForwardSecure) {
2540 use_tagging_decrypter(); 2738 use_tagging_decrypter();
2541 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); 2739 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01));
2542 QuicPacketSequenceNumber sequence_number; 2740 QuicPacketSequenceNumber sequence_number;
2543 SendStreamDataToPeer(3, "foo", 0, !kFin, &sequence_number); 2741 SendStreamDataToPeer(3, "foo", 0, !kFin, &sequence_number);
2544 2742
2545 // Simulate the retransmission alarm firing and the socket blocking. 2743 // Simulate the retransmission alarm firing and the socket blocking.
2546 BlockOnNextWrite(); 2744 BlockOnNextWrite();
2547 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 2745 if (!FLAGS_quic_use_new_rto) {
2746 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
2747 }
2548 clock_.AdvanceTime(DefaultRetransmissionTime()); 2748 clock_.AdvanceTime(DefaultRetransmissionTime());
2549 connection_.GetRetransmissionAlarm()->Fire(); 2749 connection_.GetRetransmissionAlarm()->Fire();
2550 2750
2551 // Go forward secure. 2751 // Go forward secure.
2552 connection_.SetEncrypter(ENCRYPTION_FORWARD_SECURE, 2752 connection_.SetEncrypter(ENCRYPTION_FORWARD_SECURE,
2553 new TaggingEncrypter(0x02)); 2753 new TaggingEncrypter(0x02));
2554 connection_.SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); 2754 connection_.SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE);
2555 connection_.NeuterUnencryptedPackets(); 2755 connection_.NeuterUnencryptedPackets();
2556 2756
2557 EXPECT_EQ(QuicTime::Zero(), 2757 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))); 2899 DoAll(SaveArg<3>(&first_packet_size), Return(true)));
2700 2900
2701 connection_.SendStreamDataWithString(3, "first_packet", 0, !kFin, nullptr); 2901 connection_.SendStreamDataWithString(3, "first_packet", 0, !kFin, nullptr);
2702 QuicByteCount second_packet_size; 2902 QuicByteCount second_packet_size;
2703 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).WillOnce( 2903 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).WillOnce(
2704 DoAll(SaveArg<3>(&second_packet_size), Return(true))); 2904 DoAll(SaveArg<3>(&second_packet_size), Return(true)));
2705 connection_.SendStreamDataWithString(3, "second_packet", 12, !kFin, nullptr); 2905 connection_.SendStreamDataWithString(3, "second_packet", 12, !kFin, nullptr);
2706 EXPECT_NE(first_packet_size, second_packet_size); 2906 EXPECT_NE(first_packet_size, second_packet_size);
2707 // Advance the clock by huge time to make sure packets will be retransmitted. 2907 // Advance the clock by huge time to make sure packets will be retransmitted.
2708 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10)); 2908 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10));
2709 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 2909 if (!FLAGS_quic_use_new_rto) {
2910 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
2911 }
2710 { 2912 {
2711 InSequence s; 2913 InSequence s;
2712 EXPECT_CALL(*send_algorithm_, 2914 EXPECT_CALL(*send_algorithm_,
2713 OnPacketSent(_, _, _, first_packet_size, _)); 2915 OnPacketSent(_, _, _, first_packet_size, _));
2714 EXPECT_CALL(*send_algorithm_, 2916 EXPECT_CALL(*send_algorithm_,
2715 OnPacketSent(_, _, _, second_packet_size, _)); 2917 OnPacketSent(_, _, _, second_packet_size, _));
2716 } 2918 }
2717 connection_.GetRetransmissionAlarm()->Fire(); 2919 connection_.GetRetransmissionAlarm()->Fire();
2718 2920
2719 // Advance again and expect the packets to be sent again in the same order. 2921 // Advance again and expect the packets to be sent again in the same order.
2720 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(20)); 2922 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(20));
2721 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 2923 if (!FLAGS_quic_use_new_rto) {
2924 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
2925 }
2722 { 2926 {
2723 InSequence s; 2927 InSequence s;
2724 EXPECT_CALL(*send_algorithm_, 2928 EXPECT_CALL(*send_algorithm_,
2725 OnPacketSent(_, _, _, first_packet_size, _)); 2929 OnPacketSent(_, _, _, first_packet_size, _));
2726 EXPECT_CALL(*send_algorithm_, 2930 EXPECT_CALL(*send_algorithm_,
2727 OnPacketSent(_, _, _, second_packet_size, _)); 2931 OnPacketSent(_, _, _, second_packet_size, _));
2728 } 2932 }
2729 connection_.GetRetransmissionAlarm()->Fire(); 2933 connection_.GetRetransmissionAlarm()->Fire();
2730 } 2934 }
2731 2935
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) { 2936 TEST_P(QuicConnectionTest, SetRTOAfterWritingToSocket) {
2785 BlockOnNextWrite(); 2937 BlockOnNextWrite();
2786 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); 2938 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr);
2787 // Make sure that RTO is not started when the packet is queued. 2939 // Make sure that RTO is not started when the packet is queued.
2788 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 2940 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2789 2941
2790 // Test that RTO is started once we write to the socket. 2942 // Test that RTO is started once we write to the socket.
2791 writer_->SetWritable(); 2943 writer_->SetWritable();
2792 connection_.OnCanWrite(); 2944 connection_.OnCanWrite();
2793 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 2945 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
(...skipping 18 matching lines...) Expand all
2812 ProcessAckPacket(&ack); 2964 ProcessAckPacket(&ack);
2813 EXPECT_TRUE(retransmission_alarm->IsSet()); 2965 EXPECT_TRUE(retransmission_alarm->IsSet());
2814 EXPECT_GT(retransmission_alarm->deadline(), clock_.Now()); 2966 EXPECT_GT(retransmission_alarm->deadline(), clock_.Now());
2815 2967
2816 // Move forward past the original RTO and ensure the RTO is still pending. 2968 // Move forward past the original RTO and ensure the RTO is still pending.
2817 clock_.AdvanceTime(DefaultRetransmissionTime().Multiply(2)); 2969 clock_.AdvanceTime(DefaultRetransmissionTime().Multiply(2));
2818 2970
2819 // Ensure the second packet gets retransmitted when it finally fires. 2971 // Ensure the second packet gets retransmitted when it finally fires.
2820 EXPECT_TRUE(retransmission_alarm->IsSet()); 2972 EXPECT_TRUE(retransmission_alarm->IsSet());
2821 EXPECT_LT(retransmission_alarm->deadline(), clock_.ApproximateNow()); 2973 EXPECT_LT(retransmission_alarm->deadline(), clock_.ApproximateNow());
2822 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 2974 if (!FLAGS_quic_use_new_rto) {
2975 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
2976 }
2823 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 2977 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
2824 // Manually cancel the alarm to simulate a real test. 2978 // Manually cancel the alarm to simulate a real test.
2825 connection_.GetRetransmissionAlarm()->Fire(); 2979 connection_.GetRetransmissionAlarm()->Fire();
2826 2980
2827 // The new retransmitted sequence number should set the RTO to a larger value 2981 // The new retransmitted sequence number should set the RTO to a larger value
2828 // than previously. 2982 // than previously.
2829 EXPECT_TRUE(retransmission_alarm->IsSet()); 2983 EXPECT_TRUE(retransmission_alarm->IsSet());
2830 QuicTime next_rto_time = retransmission_alarm->deadline(); 2984 QuicTime next_rto_time = retransmission_alarm->deadline();
2831 QuicTime expected_rto_time = 2985 QuicTime expected_rto_time =
2832 connection_.sent_packet_manager().GetRetransmissionTime(); 2986 connection_.sent_packet_manager().GetRetransmissionTime();
(...skipping 20 matching lines...) Expand all
2853 // Don't send missing FEC packet 3. 3007 // Don't send missing FEC packet 3.
2854 ASSERT_EQ(1u, connection_.NumFecGroups()); 3008 ASSERT_EQ(1u, connection_.NumFecGroups());
2855 3009
2856 // Now send non-fec protected ack packet and close the group. 3010 // Now send non-fec protected ack packet and close the group.
2857 peer_creator_.set_sequence_number(4); 3011 peer_creator_.set_sequence_number(4);
2858 QuicStopWaitingFrame frame = InitStopWaitingFrame(5); 3012 QuicStopWaitingFrame frame = InitStopWaitingFrame(5);
2859 ProcessStopWaitingPacket(&frame); 3013 ProcessStopWaitingPacket(&frame);
2860 ASSERT_EQ(0u, connection_.NumFecGroups()); 3014 ASSERT_EQ(0u, connection_.NumFecGroups());
2861 } 3015 }
2862 3016
2863 TEST_P(QuicConnectionTest, NoQuicCongestionFeedbackFrame) {
2864 SendAckPacketToPeer();
2865 EXPECT_TRUE(writer_->feedback_frames().empty());
2866 }
2867
2868 TEST_P(QuicConnectionTest, WithQuicCongestionFeedbackFrame) {
2869 QuicCongestionFeedbackFrame info;
2870 info.type = kTCP;
2871 info.tcp.receive_window = 0x4030;
2872
2873 // After QUIC_VERSION_22, do not send TCP Congestion Feedback Frames anymore.
2874 if (version() > QUIC_VERSION_22) {
2875 SendAckPacketToPeer();
2876 ASSERT_TRUE(writer_->feedback_frames().empty());
2877 } else {
2878 // Only SetFeedback in this case because SetFeedback will create a receive
2879 // algorithm which is how the received_packet_manager checks if it should be
2880 // creating TCP Congestion Feedback Frames.
2881 SetFeedback(&info);
2882 SendAckPacketToPeer();
2883 ASSERT_FALSE(writer_->feedback_frames().empty());
2884 ASSERT_EQ(kTCP, writer_->feedback_frames()[0].type);
2885 }
2886 }
2887
2888 TEST_P(QuicConnectionTest, UpdateQuicCongestionFeedbackFrame) {
2889 SendAckPacketToPeer();
2890 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _));
2891 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2892 ProcessPacket(1);
2893 }
2894
2895 TEST_P(QuicConnectionTest, DontUpdateQuicCongestionFeedbackFrameForRevived) {
2896 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2897 SendAckPacketToPeer();
2898 // Process an FEC packet, and revive the missing data packet
2899 // but only contact the receive_algorithm once.
2900 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _));
2901 ProcessFecPacket(2, 1, true, !kEntropyFlag, nullptr);
2902 }
2903
2904 TEST_P(QuicConnectionTest, InitialTimeout) { 3017 TEST_P(QuicConnectionTest, InitialTimeout) {
2905 EXPECT_TRUE(connection_.connected()); 3018 EXPECT_TRUE(connection_.connected());
2906 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber()); 3019 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber());
2907 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); 3020 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
2908 3021
2909 // SetFromConfig sets the initial timeouts before negotiation. 3022 // SetFromConfig sets the initial timeouts before negotiation.
2910 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _, _)); 3023 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _, _));
2911 QuicConfig config; 3024 QuicConfig config;
2912 connection_.SetFromConfig(config); 3025 connection_.SetFromConfig(config);
2913 // Subtract a second from the idle timeout on the client side. 3026 // Subtract a second from the idle timeout on the client side.
2914 QuicTime default_timeout = clock_.ApproximateNow().Add( 3027 QuicTime default_timeout = clock_.ApproximateNow().Add(
2915 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1)); 3028 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1));
2916 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); 3029 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
2917 3030
2918 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_CONNECTION_TIMED_OUT, false)); 3031 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_CONNECTION_TIMED_OUT, false));
2919 // Simulate the timeout alarm firing. 3032 // Simulate the timeout alarm firing.
2920 clock_.AdvanceTime( 3033 clock_.AdvanceTime(
2921 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1)); 3034 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1));
2922 connection_.GetTimeoutAlarm()->Fire(); 3035 connection_.GetTimeoutAlarm()->Fire();
2923 3036
2924 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); 3037 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
2925 EXPECT_FALSE(connection_.connected()); 3038 EXPECT_FALSE(connection_.connected());
2926 3039
2927 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 3040 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
2928 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); 3041 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet());
3042 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet());
2929 EXPECT_FALSE(connection_.GetResumeWritesAlarm()->IsSet()); 3043 EXPECT_FALSE(connection_.GetResumeWritesAlarm()->IsSet());
2930 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 3044 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2931 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet()); 3045 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet());
2932 } 3046 }
2933 3047
2934 TEST_P(QuicConnectionTest, OverallTimeout) { 3048 TEST_P(QuicConnectionTest, OverallTimeout) {
2935 // Use a shorter overall connection timeout than idle timeout for this test. 3049 // Use a shorter overall connection timeout than idle timeout for this test.
2936 const QuicTime::Delta timeout = QuicTime::Delta::FromSeconds(5); 3050 const QuicTime::Delta timeout = QuicTime::Delta::FromSeconds(5);
2937 connection_.SetNetworkTimeouts(timeout, timeout); 3051 connection_.SetNetworkTimeouts(timeout, timeout);
2938 EXPECT_TRUE(connection_.connected()); 3052 EXPECT_TRUE(connection_.connected());
(...skipping 22 matching lines...) Expand all
2961 EXPECT_CALL(visitor_, 3075 EXPECT_CALL(visitor_,
2962 OnConnectionClosed(QUIC_CONNECTION_OVERALL_TIMED_OUT, false)); 3076 OnConnectionClosed(QUIC_CONNECTION_OVERALL_TIMED_OUT, false));
2963 // Simulate the timeout alarm firing. 3077 // Simulate the timeout alarm firing.
2964 connection_.GetTimeoutAlarm()->Fire(); 3078 connection_.GetTimeoutAlarm()->Fire();
2965 3079
2966 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); 3080 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
2967 EXPECT_FALSE(connection_.connected()); 3081 EXPECT_FALSE(connection_.connected());
2968 3082
2969 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 3083 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
2970 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); 3084 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet());
3085 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet());
2971 EXPECT_FALSE(connection_.GetResumeWritesAlarm()->IsSet()); 3086 EXPECT_FALSE(connection_.GetResumeWritesAlarm()->IsSet());
2972 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 3087 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2973 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet()); 3088 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet());
2974 } 3089 }
2975 3090
2976 TEST_P(QuicConnectionTest, PingAfterSend) { 3091 TEST_P(QuicConnectionTest, PingAfterSend) {
2977 EXPECT_TRUE(connection_.connected()); 3092 EXPECT_TRUE(connection_.connected());
2978 EXPECT_CALL(visitor_, HasOpenDataStreams()).WillRepeatedly(Return(true)); 3093 EXPECT_CALL(visitor_, HasOpenDataStreams()).WillRepeatedly(Return(true));
2979 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); 3094 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet());
2980 3095
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
3132 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 3247 EXPECT_EQ(1u, connection_.NumQueuedPackets());
3133 } 3248 }
3134 3249
3135 TEST_P(QuicConnectionTest, TestQueueLimitsOnSendStreamData) { 3250 TEST_P(QuicConnectionTest, TestQueueLimitsOnSendStreamData) {
3136 // All packets carry version info till version is negotiated. 3251 // All packets carry version info till version is negotiated.
3137 size_t payload_length; 3252 size_t payload_length;
3138 size_t length = GetPacketLengthForOneStream( 3253 size_t length = GetPacketLengthForOneStream(
3139 connection_.version(), kIncludeVersion, 3254 connection_.version(), kIncludeVersion,
3140 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, 3255 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER,
3141 NOT_IN_FEC_GROUP, &payload_length); 3256 NOT_IN_FEC_GROUP, &payload_length);
3142 QuicConnectionPeer::GetPacketCreator(&connection_)->set_max_packet_length( 3257 creator_->set_max_packet_length(length);
3143 length);
3144 3258
3145 // Queue the first packet. 3259 // Queue the first packet.
3146 EXPECT_CALL(*send_algorithm_, 3260 EXPECT_CALL(*send_algorithm_,
3147 TimeUntilSend(_, _, _)).WillOnce( 3261 TimeUntilSend(_, _, _)).WillOnce(
3148 testing::Return(QuicTime::Delta::FromMicroseconds(10))); 3262 testing::Return(QuicTime::Delta::FromMicroseconds(10)));
3149 const string payload(payload_length, 'a'); 3263 const string payload(payload_length, 'a');
3150 EXPECT_EQ(0u, connection_.SendStreamDataWithString(3, payload, 0, !kFin, 3264 EXPECT_EQ(0u, connection_.SendStreamDataWithString(3, payload, 0, !kFin,
3151 nullptr).bytes_consumed); 3265 nullptr).bytes_consumed);
3152 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 3266 EXPECT_EQ(0u, connection_.NumQueuedPackets());
3153 } 3267 }
3154 3268
3155 TEST_P(QuicConnectionTest, LoopThroughSendingPackets) { 3269 TEST_P(QuicConnectionTest, LoopThroughSendingPackets) {
3156 // All packets carry version info till version is negotiated. 3270 // All packets carry version info till version is negotiated.
3157 size_t payload_length; 3271 size_t payload_length;
3158 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining 3272 // 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 3273 // 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 3274 // offset 0, and 2 for non-zero offsets up through 16K. Increase
3161 // max_packet_length by 2 so that subsequent packets containing subsequent 3275 // max_packet_length by 2 so that subsequent packets containing subsequent
3162 // stream frames with non-zero offets will fit within the packet length. 3276 // stream frames with non-zero offets will fit within the packet length.
3163 size_t length = 2 + GetPacketLengthForOneStream( 3277 size_t length = 2 + GetPacketLengthForOneStream(
3164 connection_.version(), kIncludeVersion, 3278 connection_.version(), kIncludeVersion,
3165 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, 3279 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER,
3166 NOT_IN_FEC_GROUP, &payload_length); 3280 NOT_IN_FEC_GROUP, &payload_length);
3167 QuicConnectionPeer::GetPacketCreator(&connection_)->set_max_packet_length( 3281 creator_->set_max_packet_length(length);
3168 length);
3169 3282
3170 // Queue the first packet. 3283 // Queue the first packet.
3171 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(7); 3284 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(7);
3172 // The first stream frame will have 2 fewer overhead bytes than the other six. 3285 // The first stream frame will have 2 fewer overhead bytes than the other six.
3173 const string payload(payload_length * 7 + 2, 'a'); 3286 const string payload(payload_length * 7 + 2, 'a');
3174 EXPECT_EQ(payload.size(), 3287 EXPECT_EQ(payload.size(),
3175 connection_.SendStreamDataWithString(1, payload, 0, !kFin, nullptr) 3288 connection_.SendStreamDataWithString(1, payload, 0, !kFin, nullptr)
3176 .bytes_consumed); 3289 .bytes_consumed);
3177 } 3290 }
3178 3291
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
3731 QuicFrames frames; 3844 QuicFrames frames;
3732 QuicFrame frame(&frame1_); 3845 QuicFrame frame(&frame1_);
3733 frames.push_back(frame); 3846 frames.push_back(frame);
3734 scoped_ptr<QuicPacket> packet( 3847 scoped_ptr<QuicPacket> packet(
3735 BuildUnsizedDataPacket(&framer_, header, frames).packet); 3848 BuildUnsizedDataPacket(&framer_, header, frames).packet);
3736 encrypted.reset(framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); 3849 encrypted.reset(framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet));
3737 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); 3850 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1);
3738 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3851 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3739 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); 3852 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted);
3740 3853
3741 ASSERT_FALSE(QuicPacketCreatorPeer::SendVersionInPacket( 3854 ASSERT_FALSE(QuicPacketCreatorPeer::SendVersionInPacket(creator_));
3742 QuicConnectionPeer::GetPacketCreator(&connection_)));
3743 } 3855 }
3744 3856
3745 TEST_P(QuicConnectionTest, BadVersionNegotiation) { 3857 TEST_P(QuicConnectionTest, BadVersionNegotiation) {
3746 QuicPacketHeader header; 3858 QuicPacketHeader header;
3747 header.public_header.connection_id = connection_id_; 3859 header.public_header.connection_id = connection_id_;
3748 header.public_header.reset_flag = false; 3860 header.public_header.reset_flag = false;
3749 header.public_header.version_flag = true; 3861 header.public_header.version_flag = true;
3750 header.entropy_flag = false; 3862 header.entropy_flag = false;
3751 header.fec_flag = false; 3863 header.fec_flag = false;
3752 header.packet_sequence_number = 12; 3864 header.packet_sequence_number = 12;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
3790 NackPacket(3, &nack_three); 3902 NackPacket(3, &nack_three);
3791 NackPacket(1, &nack_three); 3903 NackPacket(1, &nack_three);
3792 SequenceNumberSet lost_packets; 3904 SequenceNumberSet lost_packets;
3793 lost_packets.insert(1); 3905 lost_packets.insert(1);
3794 lost_packets.insert(3); 3906 lost_packets.insert(3);
3795 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 3907 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
3796 .WillOnce(Return(lost_packets)); 3908 .WillOnce(Return(lost_packets));
3797 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 3909 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
3798 EXPECT_CALL(visitor_, OnCanWrite()).Times(2); 3910 EXPECT_CALL(visitor_, OnCanWrite()).Times(2);
3799 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3911 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3800 EXPECT_CALL(*send_algorithm_, RevertRetransmissionTimeout()); 3912 if (!FLAGS_quic_use_new_rto) {
3913 EXPECT_CALL(*send_algorithm_, RevertRetransmissionTimeout());
3914 }
3801 ProcessAckPacket(&nack_three); 3915 ProcessAckPacket(&nack_three);
3802 3916
3803 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillOnce( 3917 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillOnce(
3804 Return(QuicBandwidth::Zero())); 3918 Return(QuicBandwidth::Zero()));
3805 3919
3806 const QuicConnectionStats& stats = connection_.GetStats(); 3920 const QuicConnectionStats& stats = connection_.GetStats();
3807 EXPECT_EQ(3 * first_packet_size + 2 * second_packet_size - kQuicVersionSize, 3921 EXPECT_EQ(3 * first_packet_size + 2 * second_packet_size - kQuicVersionSize,
3808 stats.bytes_sent); 3922 stats.bytes_sent);
3809 EXPECT_EQ(5u, stats.packets_sent); 3923 EXPECT_EQ(5u, stats.packets_sent);
3810 EXPECT_EQ(2 * first_packet_size + second_packet_size - kQuicVersionSize, 3924 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()); 4059 EXPECT_TRUE(writer_->IsWriteBlocked());
3946 TriggerConnectionClose(); 4060 TriggerConnectionClose();
3947 EXPECT_EQ(1u, writer_->packets_write_attempts()); 4061 EXPECT_EQ(1u, writer_->packets_write_attempts());
3948 } 4062 }
3949 4063
3950 TEST_P(QuicConnectionTest, AckNotifierTriggerCallback) { 4064 TEST_P(QuicConnectionTest, AckNotifierTriggerCallback) {
3951 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4065 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3952 4066
3953 // Create a delegate which we expect to be called. 4067 // Create a delegate which we expect to be called.
3954 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); 4068 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate);
3955 EXPECT_CALL(*delegate.get(), OnAckNotification(_, _, _, _, _)).Times(1); 4069 EXPECT_CALL(*delegate.get(), OnAckNotification(_, _, _)).Times(1);
3956 4070
3957 // Send some data, which will register the delegate to be notified. 4071 // Send some data, which will register the delegate to be notified.
3958 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); 4072 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get());
3959 4073
3960 // Process an ACK from the server which should trigger the callback. 4074 // Process an ACK from the server which should trigger the callback.
3961 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 4075 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
3962 QuicAckFrame frame = InitAckFrame(1); 4076 QuicAckFrame frame = InitAckFrame(1);
3963 ProcessAckPacket(&frame); 4077 ProcessAckPacket(&frame);
3964 } 4078 }
3965 4079
3966 TEST_P(QuicConnectionTest, AckNotifierFailToTriggerCallback) { 4080 TEST_P(QuicConnectionTest, AckNotifierFailToTriggerCallback) {
3967 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4081 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3968 4082
3969 // Create a delegate which we don't expect to be called. 4083 // Create a delegate which we don't expect to be called.
3970 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); 4084 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate);
3971 EXPECT_CALL(*delegate.get(), OnAckNotification(_, _, _, _, _)).Times(0); 4085 EXPECT_CALL(*delegate.get(), OnAckNotification(_, _, _)).Times(0);
3972 4086
3973 // Send some data, which will register the delegate to be notified. This will 4087 // 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. 4088 // not be ACKed and so the delegate should never be called.
3975 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); 4089 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get());
3976 4090
3977 // Send some other data which we will ACK. 4091 // Send some other data which we will ACK.
3978 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); 4092 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr);
3979 connection_.SendStreamDataWithString(1, "bar", 0, !kFin, nullptr); 4093 connection_.SendStreamDataWithString(1, "bar", 0, !kFin, nullptr);
3980 4094
3981 // Now we receive ACK for packets 2 and 3, but importantly missing packet 1 4095 // Now we receive ACK for packets 2 and 3, but importantly missing packet 1
3982 // which we registered to be notified about. 4096 // which we registered to be notified about.
3983 QuicAckFrame frame = InitAckFrame(3); 4097 QuicAckFrame frame = InitAckFrame(3);
3984 NackPacket(1, &frame); 4098 NackPacket(1, &frame);
3985 SequenceNumberSet lost_packets; 4099 SequenceNumberSet lost_packets;
3986 lost_packets.insert(1); 4100 lost_packets.insert(1);
3987 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 4101 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
3988 .WillOnce(Return(lost_packets)); 4102 .WillOnce(Return(lost_packets));
3989 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 4103 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
3990 ProcessAckPacket(&frame); 4104 ProcessAckPacket(&frame);
3991 } 4105 }
3992 4106
3993 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) { 4107 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) {
3994 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4108 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3995 4109
3996 // Create a delegate which we expect to be called. 4110 // Create a delegate which we expect to be called.
3997 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); 4111 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate);
3998 EXPECT_CALL(*delegate.get(), OnAckNotification(_, _, _, _, _)).Times(1); 4112 EXPECT_CALL(*delegate.get(), OnAckNotification(_, _, _)).Times(1);
3999 4113
4000 // Send four packets, and register to be notified on ACK of packet 2. 4114 // Send four packets, and register to be notified on ACK of packet 2.
4001 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); 4115 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr);
4002 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, delegate.get()); 4116 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, delegate.get());
4003 connection_.SendStreamDataWithString(3, "baz", 0, !kFin, nullptr); 4117 connection_.SendStreamDataWithString(3, "baz", 0, !kFin, nullptr);
4004 connection_.SendStreamDataWithString(3, "qux", 0, !kFin, nullptr); 4118 connection_.SendStreamDataWithString(3, "qux", 0, !kFin, nullptr);
4005 4119
4006 // Now we receive ACK for packets 1, 3, and 4 and lose 2. 4120 // Now we receive ACK for packets 1, 3, and 4 and lose 2.
4007 QuicAckFrame frame = InitAckFrame(4); 4121 QuicAckFrame frame = InitAckFrame(4);
4008 NackPacket(2, &frame); 4122 NackPacket(2, &frame);
(...skipping 27 matching lines...) Expand all
4036 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( 4150 QuicTime default_retransmission_time = clock_.ApproximateNow().Add(
4037 DefaultRetransmissionTime()); 4151 DefaultRetransmissionTime());
4038 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, delegate.get()); 4152 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, delegate.get());
4039 EXPECT_EQ(1u, stop_waiting()->least_unacked); 4153 EXPECT_EQ(1u, stop_waiting()->least_unacked);
4040 4154
4041 EXPECT_EQ(1u, writer_->header().packet_sequence_number); 4155 EXPECT_EQ(1u, writer_->header().packet_sequence_number);
4042 EXPECT_EQ(default_retransmission_time, 4156 EXPECT_EQ(default_retransmission_time,
4043 connection_.GetRetransmissionAlarm()->deadline()); 4157 connection_.GetRetransmissionAlarm()->deadline());
4044 // Simulate the retransmission alarm firing. 4158 // Simulate the retransmission alarm firing.
4045 clock_.AdvanceTime(DefaultRetransmissionTime()); 4159 clock_.AdvanceTime(DefaultRetransmissionTime());
4046 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 4160 if (!FLAGS_quic_use_new_rto) {
4161 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
4162 }
4047 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _)); 4163 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _));
4048 connection_.GetRetransmissionAlarm()->Fire(); 4164 connection_.GetRetransmissionAlarm()->Fire();
4049 EXPECT_EQ(2u, writer_->header().packet_sequence_number); 4165 EXPECT_EQ(2u, writer_->header().packet_sequence_number);
4050 // We do not raise the high water mark yet. 4166 // We do not raise the high water mark yet.
4051 EXPECT_EQ(1u, stop_waiting()->least_unacked); 4167 EXPECT_EQ(1u, stop_waiting()->least_unacked);
4052 4168
4053 // Ack the original packet, which will revert the RTO. 4169 // Ack the original packet, which will revert the RTO.
4054 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4170 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4055 EXPECT_CALL(*delegate.get(), OnAckNotification(1, _, 1, _, _)); 4171 EXPECT_CALL(*delegate.get(), OnAckNotification(1, _, _));
4056 EXPECT_CALL(*send_algorithm_, RevertRetransmissionTimeout()); 4172 if (!FLAGS_quic_use_new_rto) {
4173 EXPECT_CALL(*send_algorithm_, RevertRetransmissionTimeout());
4174 }
4057 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 4175 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
4058 QuicAckFrame ack_frame = InitAckFrame(1); 4176 QuicAckFrame ack_frame = InitAckFrame(1);
4059 ProcessAckPacket(&ack_frame); 4177 ProcessAckPacket(&ack_frame);
4060 4178
4061 // Delegate is not notified again when the retransmit is acked. 4179 // Delegate is not notified again when the retransmit is acked.
4062 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 4180 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
4063 QuicAckFrame second_ack_frame = InitAckFrame(2); 4181 QuicAckFrame second_ack_frame = InitAckFrame(2);
4064 ProcessAckPacket(&second_ack_frame); 4182 ProcessAckPacket(&second_ack_frame);
4065 } 4183 }
4066 4184
(...skipping 20 matching lines...) Expand all
4087 lost_packets.insert(2); 4205 lost_packets.insert(2);
4088 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4206 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4089 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 4207 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
4090 .WillOnce(Return(lost_packets)); 4208 .WillOnce(Return(lost_packets));
4091 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 4209 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
4092 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 4210 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
4093 ProcessAckPacket(&frame); 4211 ProcessAckPacket(&frame);
4094 4212
4095 // Now we get an ACK for packet 2, which was previously nacked. 4213 // Now we get an ACK for packet 2, which was previously nacked.
4096 SequenceNumberSet no_lost_packets; 4214 SequenceNumberSet no_lost_packets;
4097 EXPECT_CALL(*delegate.get(), OnAckNotification(1, _, 1, _, _)); 4215 EXPECT_CALL(*delegate.get(), OnAckNotification(1, _, _));
4098 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 4216 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
4099 .WillOnce(Return(no_lost_packets)); 4217 .WillOnce(Return(no_lost_packets));
4100 QuicAckFrame second_ack_frame = InitAckFrame(4); 4218 QuicAckFrame second_ack_frame = InitAckFrame(4);
4101 ProcessAckPacket(&second_ack_frame); 4219 ProcessAckPacket(&second_ack_frame);
4102 4220
4103 // Verify that the delegate is not notified again when the 4221 // Verify that the delegate is not notified again when the
4104 // retransmit is acked. 4222 // retransmit is acked.
4105 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 4223 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
4106 .WillOnce(Return(no_lost_packets)); 4224 .WillOnce(Return(no_lost_packets));
4107 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 4225 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
4108 QuicAckFrame third_ack_frame = InitAckFrame(5); 4226 QuicAckFrame third_ack_frame = InitAckFrame(5);
4109 ProcessAckPacket(&third_ack_frame); 4227 ProcessAckPacket(&third_ack_frame);
4110 } 4228 }
4111 4229
4112 TEST_P(QuicConnectionTest, AckNotifierFECTriggerCallback) { 4230 TEST_P(QuicConnectionTest, AckNotifierFECTriggerCallback) {
4113 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4231 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4114 4232
4115 // Create a delegate which we expect to be called. 4233 // Create a delegate which we expect to be called.
4116 scoped_refptr<MockAckNotifierDelegate> delegate( 4234 scoped_refptr<MockAckNotifierDelegate> delegate(
4117 new MockAckNotifierDelegate); 4235 new MockAckNotifierDelegate);
4118 EXPECT_CALL(*delegate.get(), OnAckNotification(_, _, _, _, _)).Times(1); 4236 EXPECT_CALL(*delegate.get(), OnAckNotification(_, _, _)).Times(1);
4119 4237
4120 // Send some data, which will register the delegate to be notified. 4238 // Send some data, which will register the delegate to be notified.
4121 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); 4239 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get());
4122 connection_.SendStreamDataWithString(2, "bar", 0, !kFin, nullptr); 4240 connection_.SendStreamDataWithString(2, "bar", 0, !kFin, nullptr);
4123 4241
4124 // Process an ACK from the server with a revived packet, which should trigger 4242 // Process an ACK from the server with a revived packet, which should trigger
4125 // the callback. 4243 // the callback.
4126 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 4244 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
4127 QuicAckFrame frame = InitAckFrame(2); 4245 QuicAckFrame frame = InitAckFrame(2);
4128 NackPacket(1, &frame); 4246 NackPacket(1, &frame);
4129 frame.revived_packets.insert(1); 4247 frame.revived_packets.insert(1);
4130 ProcessAckPacket(&frame); 4248 ProcessAckPacket(&frame);
4131 // If the ack is processed again, the notifier should not be called again. 4249 // If the ack is processed again, the notifier should not be called again.
4132 ProcessAckPacket(&frame); 4250 ProcessAckPacket(&frame);
4133 } 4251 }
4134 4252
4135 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterFECRecovery) { 4253 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterFECRecovery) {
4136 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4254 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4137 EXPECT_CALL(visitor_, OnCanWrite()); 4255 EXPECT_CALL(visitor_, OnCanWrite());
4138 4256
4139 // Create a delegate which we expect to be called. 4257 // Create a delegate which we expect to be called.
4140 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); 4258 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate);
4141 EXPECT_CALL(*delegate.get(), OnAckNotification(_, _, _, _, _)).Times(1); 4259 EXPECT_CALL(*delegate.get(), OnAckNotification(_, _, _)).Times(1);
4142 4260
4143 // Expect ACKs for 1 packet. 4261 // Expect ACKs for 1 packet.
4144 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 4262 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
4145 4263
4146 // Send one packet, and register to be notified on ACK. 4264 // Send one packet, and register to be notified on ACK.
4147 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); 4265 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get());
4148 4266
4149 // Ack packet gets dropped, but we receive an FEC packet that covers it. 4267 // Ack packet gets dropped, but we receive an FEC packet that covers it.
4150 // Should recover the Ack packet and trigger the notification callback. 4268 // Should recover the Ack packet and trigger the notification callback.
4151 QuicFrames frames; 4269 QuicFrames frames;
(...skipping 16 matching lines...) Expand all
4168 4286
4169 QuicPacket* packet = 4287 QuicPacket* packet =
4170 BuildUnsizedDataPacket(&framer_, ack_header, frames).packet; 4288 BuildUnsizedDataPacket(&framer_, ack_header, frames).packet;
4171 4289
4172 // Take the packet which contains the ACK frame, and construct and deliver an 4290 // Take the packet which contains the ACK frame, and construct and deliver an
4173 // FEC packet which allows the ACK packet to be recovered. 4291 // FEC packet which allows the ACK packet to be recovered.
4174 ProcessFecPacket(2, 1, true, !kEntropyFlag, packet); 4292 ProcessFecPacket(2, 1, true, !kEntropyFlag, packet);
4175 } 4293 }
4176 4294
4177 TEST_P(QuicConnectionTest, NetworkChangeVisitorCwndCallbackChangesFecState) { 4295 TEST_P(QuicConnectionTest, NetworkChangeVisitorCwndCallbackChangesFecState) {
4178 QuicPacketCreator* creator = 4296 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 4297
4182 QuicSentPacketManager::NetworkChangeVisitor* visitor = 4298 QuicSentPacketManager::NetworkChangeVisitor* visitor =
4183 QuicSentPacketManagerPeer::GetNetworkChangeVisitor( 4299 QuicSentPacketManagerPeer::GetNetworkChangeVisitor(manager_);
4184 QuicConnectionPeer::GetSentPacketManager(&connection_));
4185 EXPECT_TRUE(visitor); 4300 EXPECT_TRUE(visitor);
4186 4301
4187 // Increase FEC group size by increasing congestion window to a large number. 4302 // Increase FEC group size by increasing congestion window to a large number.
4188 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( 4303 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly(
4189 Return(1000 * kDefaultTCPMSS)); 4304 Return(1000 * kDefaultTCPMSS));
4190 visitor->OnCongestionWindowChange(); 4305 visitor->OnCongestionWindowChange();
4191 EXPECT_LT(max_packets_per_fec_group, creator->max_packets_per_fec_group()); 4306 EXPECT_LT(max_packets_per_fec_group, creator_->max_packets_per_fec_group());
4192 } 4307 }
4193 4308
4194 TEST_P(QuicConnectionTest, NetworkChangeVisitorConfigCallbackChangesFecState) { 4309 TEST_P(QuicConnectionTest, NetworkChangeVisitorConfigCallbackChangesFecState) {
4195 QuicSentPacketManager* sent_packet_manager =
4196 QuicConnectionPeer::GetSentPacketManager(&connection_);
4197 QuicSentPacketManager::NetworkChangeVisitor* visitor = 4310 QuicSentPacketManager::NetworkChangeVisitor* visitor =
4198 QuicSentPacketManagerPeer::GetNetworkChangeVisitor(sent_packet_manager); 4311 QuicSentPacketManagerPeer::GetNetworkChangeVisitor(manager_);
4199 EXPECT_TRUE(visitor); 4312 EXPECT_TRUE(visitor);
4200 4313 EXPECT_EQ(QuicTime::Delta::Zero(),
4201 QuicPacketGenerator* generator = 4314 QuicPacketGeneratorPeer::GetFecTimeout(generator_));
4202 QuicConnectionPeer::GetPacketGenerator(&connection_);
4203 EXPECT_EQ(QuicTime::Delta::Zero(), generator->fec_timeout());
4204 4315
4205 // Verify that sending a config with a new initial rtt changes fec timeout. 4316 // 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. 4317 // Create and process a config with a non-zero initial RTT.
4207 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _, _)); 4318 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _, _));
4208 QuicConfig config; 4319 QuicConfig config;
4209 config.SetInitialRoundTripTimeUsToSend(300000); 4320 config.SetInitialRoundTripTimeUsToSend(300000);
4210 connection_.SetFromConfig(config); 4321 connection_.SetFromConfig(config);
4211 EXPECT_LT(QuicTime::Delta::Zero(), generator->fec_timeout()); 4322 EXPECT_LT(QuicTime::Delta::Zero(),
4323 QuicPacketGeneratorPeer::GetFecTimeout(generator_));
4212 } 4324 }
4213 4325
4214 TEST_P(QuicConnectionTest, NetworkChangeVisitorRttCallbackChangesFecState) { 4326 TEST_P(QuicConnectionTest, NetworkChangeVisitorRttCallbackChangesFecState) {
4215 // Verify that sending a config with a new initial rtt changes fec timeout. 4327 // 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 = 4328 QuicSentPacketManager::NetworkChangeVisitor* visitor =
4219 QuicSentPacketManagerPeer::GetNetworkChangeVisitor(sent_packet_manager); 4329 QuicSentPacketManagerPeer::GetNetworkChangeVisitor(manager_);
4220 EXPECT_TRUE(visitor); 4330 EXPECT_TRUE(visitor);
4221 4331 EXPECT_EQ(QuicTime::Delta::Zero(),
4222 QuicPacketGenerator* generator = 4332 QuicPacketGeneratorPeer::GetFecTimeout(generator_));
4223 QuicConnectionPeer::GetPacketGenerator(&connection_);
4224 EXPECT_EQ(QuicTime::Delta::Zero(), generator->fec_timeout());
4225 4333
4226 // Increase FEC timeout by increasing RTT. 4334 // Increase FEC timeout by increasing RTT.
4227 RttStats* rtt_stats = 4335 RttStats* rtt_stats = QuicSentPacketManagerPeer::GetRttStats(manager_);
4228 QuicSentPacketManagerPeer::GetRttStats(sent_packet_manager);
4229 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(300), 4336 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(300),
4230 QuicTime::Delta::Zero(), QuicTime::Zero()); 4337 QuicTime::Delta::Zero(), QuicTime::Zero());
4231 visitor->OnRttChange(); 4338 visitor->OnRttChange();
4232 EXPECT_LT(QuicTime::Delta::Zero(), generator->fec_timeout()); 4339 EXPECT_LT(QuicTime::Delta::Zero(),
4340 QuicPacketGeneratorPeer::GetFecTimeout(generator_));
4233 } 4341 }
4234 4342
4235 class MockQuicConnectionDebugVisitor 4343 class MockQuicConnectionDebugVisitor
4236 : public QuicConnectionDebugVisitor { 4344 : public QuicConnectionDebugVisitor {
4237 public: 4345 public:
4238 MOCK_METHOD1(OnFrameAddedToPacket, 4346 MOCK_METHOD1(OnFrameAddedToPacket,
4239 void(const QuicFrame&)); 4347 void(const QuicFrame&));
4240 4348
4241 MOCK_METHOD6(OnPacketSent, 4349 MOCK_METHOD6(OnPacketSent,
4242 void(const SerializedPacket&, 4350 void(const SerializedPacket&,
(...skipping 13 matching lines...) Expand all
4256 4364
4257 MOCK_METHOD1(OnPacketHeader, 4365 MOCK_METHOD1(OnPacketHeader,
4258 void(const QuicPacketHeader& header)); 4366 void(const QuicPacketHeader& header));
4259 4367
4260 MOCK_METHOD1(OnStreamFrame, 4368 MOCK_METHOD1(OnStreamFrame,
4261 void(const QuicStreamFrame&)); 4369 void(const QuicStreamFrame&));
4262 4370
4263 MOCK_METHOD1(OnAckFrame, 4371 MOCK_METHOD1(OnAckFrame,
4264 void(const QuicAckFrame& frame)); 4372 void(const QuicAckFrame& frame));
4265 4373
4266 MOCK_METHOD1(OnCongestionFeedbackFrame,
4267 void(const QuicCongestionFeedbackFrame&));
4268
4269 MOCK_METHOD1(OnStopWaitingFrame, 4374 MOCK_METHOD1(OnStopWaitingFrame,
4270 void(const QuicStopWaitingFrame&)); 4375 void(const QuicStopWaitingFrame&));
4271 4376
4272 MOCK_METHOD1(OnRstStreamFrame, 4377 MOCK_METHOD1(OnRstStreamFrame,
4273 void(const QuicRstStreamFrame&)); 4378 void(const QuicRstStreamFrame&));
4274 4379
4275 MOCK_METHOD1(OnConnectionCloseFrame, 4380 MOCK_METHOD1(OnConnectionCloseFrame,
4276 void(const QuicConnectionCloseFrame&)); 4381 void(const QuicConnectionCloseFrame&));
4277 4382
4278 MOCK_METHOD1(OnPublicResetPacket, 4383 MOCK_METHOD1(OnPublicResetPacket,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
4321 // Cancel alarm, and try again with BLOCKED frame. 4426 // Cancel alarm, and try again with BLOCKED frame.
4322 ack_alarm->Cancel(); 4427 ack_alarm->Cancel();
4323 QuicBlockedFrame blocked; 4428 QuicBlockedFrame blocked;
4324 blocked.stream_id = 3; 4429 blocked.stream_id = 3;
4325 EXPECT_CALL(visitor_, OnBlockedFrames(_)); 4430 EXPECT_CALL(visitor_, OnBlockedFrames(_));
4326 ProcessFramePacket(QuicFrame(&blocked)); 4431 ProcessFramePacket(QuicFrame(&blocked));
4327 EXPECT_TRUE(ack_alarm->IsSet()); 4432 EXPECT_TRUE(ack_alarm->IsSet());
4328 } 4433 }
4329 4434
4330 TEST_P(QuicConnectionTest, NoDataNoFin) { 4435 TEST_P(QuicConnectionTest, NoDataNoFin) {
4331 ValueRestore<bool> old_flag(&FLAGS_quic_empty_data_no_fin_early_return, true);
4332 // Make sure that a call to SendStreamWithData, with no data and no FIN, does 4436 // Make sure that a call to SendStreamWithData, with no data and no FIN, does
4333 // not result in a QuicAckNotifier being used-after-free (fail under ASAN). 4437 // not result in a QuicAckNotifier being used-after-free (fail under ASAN).
4334 // Regression test for b/18594622 4438 // Regression test for b/18594622
4335 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); 4439 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate);
4336 EXPECT_DFATAL( 4440 EXPECT_DFATAL(
4337 connection_.SendStreamDataWithString(3, "", 0, !kFin, delegate.get()), 4441 connection_.SendStreamDataWithString(3, "", 0, !kFin, delegate.get()),
4338 "Attempt to send empty stream frame"); 4442 "Attempt to send empty stream frame");
4339 } 4443 }
4340 4444
4341 } // namespace 4445 } // namespace
4342 } // namespace test 4446 } // namespace test
4343 } // namespace net 4447 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698