OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/quic/quic_connection.h" | 5 #include "net/quic/quic_connection.h" |
6 | 6 |
7 #include <ostream> | 7 #include <ostream> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 TestPacketWriter* writer, | 428 TestPacketWriter* writer, |
429 Perspective perspective, | 429 Perspective perspective, |
430 QuicVersion version) | 430 QuicVersion version) |
431 : QuicConnection(connection_id, | 431 : QuicConnection(connection_id, |
432 address, | 432 address, |
433 helper, | 433 helper, |
434 writer, | 434 writer, |
435 /* owns_writer= */ false, | 435 /* owns_writer= */ false, |
436 perspective, | 436 perspective, |
437 SupportedVersions(version)) { | 437 SupportedVersions(version)) { |
438 // Disable tail loss probes for most tests. | |
439 QuicSentPacketManagerPeer::SetMaxTailLossProbes( | |
440 QuicConnectionPeer::GetSentPacketManager(this), 0); | |
441 writer->set_perspective(perspective); | 438 writer->set_perspective(perspective); |
442 } | 439 } |
443 | 440 |
444 void SendAck() { QuicConnectionPeer::SendAck(this); } | 441 void SendAck() { QuicConnectionPeer::SendAck(this); } |
445 | 442 |
446 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) { | 443 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) { |
447 QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm); | 444 QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm); |
448 } | 445 } |
449 | 446 |
450 void SetLossAlgorithm(LossDetectionInterface* loss_algorithm) { | 447 void SetLossAlgorithm(LossDetectionInterface* loss_algorithm) { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 TestConnectionHelper::TestAlarm* GetTimeoutAlarm() { | 570 TestConnectionHelper::TestAlarm* GetTimeoutAlarm() { |
574 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( | 571 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( |
575 QuicConnectionPeer::GetTimeoutAlarm(this)); | 572 QuicConnectionPeer::GetTimeoutAlarm(this)); |
576 } | 573 } |
577 | 574 |
578 TestConnectionHelper::TestAlarm* GetMtuDiscoveryAlarm() { | 575 TestConnectionHelper::TestAlarm* GetMtuDiscoveryAlarm() { |
579 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( | 576 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( |
580 QuicConnectionPeer::GetMtuDiscoveryAlarm(this)); | 577 QuicConnectionPeer::GetMtuDiscoveryAlarm(this)); |
581 } | 578 } |
582 | 579 |
| 580 void DisableTailLossProbe() { |
| 581 QuicSentPacketManagerPeer::SetMaxTailLossProbes( |
| 582 QuicConnectionPeer::GetSentPacketManager(this), 0); |
| 583 } |
| 584 |
583 using QuicConnection::SelectMutualVersion; | 585 using QuicConnection::SelectMutualVersion; |
584 using QuicConnection::set_defer_send_in_response_to_packets; | 586 using QuicConnection::set_defer_send_in_response_to_packets; |
585 | 587 |
586 private: | 588 private: |
587 TestPacketWriter* writer() { | 589 TestPacketWriter* writer() { |
588 return static_cast<TestPacketWriter*>(QuicConnection::writer()); | 590 return static_cast<TestPacketWriter*>(QuicConnection::writer()); |
589 } | 591 } |
590 | 592 |
591 DISALLOW_COPY_AND_ASSIGN(TestConnection); | 593 DISALLOW_COPY_AND_ASSIGN(TestConnection); |
592 }; | 594 }; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 frame2_(1, false, 3, StringPiece(data2)), | 654 frame2_(1, false, 3, StringPiece(data2)), |
653 packet_number_length_(PACKET_6BYTE_PACKET_NUMBER), | 655 packet_number_length_(PACKET_6BYTE_PACKET_NUMBER), |
654 connection_id_length_(PACKET_8BYTE_CONNECTION_ID) { | 656 connection_id_length_(PACKET_8BYTE_CONNECTION_ID) { |
655 connection_.set_defer_send_in_response_to_packets(GetParam().ack_response == | 657 connection_.set_defer_send_in_response_to_packets(GetParam().ack_response == |
656 AckResponse::kDefer); | 658 AckResponse::kDefer); |
657 FLAGS_quic_always_log_bugs_for_tests = true; | 659 FLAGS_quic_always_log_bugs_for_tests = true; |
658 connection_.set_visitor(&visitor_); | 660 connection_.set_visitor(&visitor_); |
659 connection_.SetSendAlgorithm(send_algorithm_); | 661 connection_.SetSendAlgorithm(send_algorithm_); |
660 connection_.SetLossAlgorithm(loss_algorithm_); | 662 connection_.SetLossAlgorithm(loss_algorithm_); |
661 framer_.set_received_entropy_calculator(&entropy_calculator_); | 663 framer_.set_received_entropy_calculator(&entropy_calculator_); |
662 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _)) | 664 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _)) |
663 .WillRepeatedly(Return(QuicTime::Delta::Zero())); | 665 .WillRepeatedly(Return(QuicTime::Delta::Zero())); |
664 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 666 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
665 .Times(AnyNumber()); | 667 .Times(AnyNumber()); |
666 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) | 668 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) |
667 .WillRepeatedly(Return(QuicTime::Delta::Zero())); | 669 .WillRepeatedly(Return(QuicTime::Delta::Zero())); |
668 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) | 670 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) |
669 .WillRepeatedly(Return(kDefaultTCPMSS)); | 671 .WillRepeatedly(Return(kDefaultTCPMSS)); |
670 EXPECT_CALL(*send_algorithm_, PacingRate()) | 672 EXPECT_CALL(*send_algorithm_, PacingRate()) |
671 .WillRepeatedly(Return(QuicBandwidth::Zero())); | 673 .WillRepeatedly(Return(QuicBandwidth::Zero())); |
672 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 674 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
(...skipping 17 matching lines...) Expand all Loading... |
690 .WillRepeatedly(Return(QuicTime::Zero())); | 692 .WillRepeatedly(Return(QuicTime::Zero())); |
691 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _)).Times(AnyNumber()); | 693 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _)).Times(AnyNumber()); |
692 // TODO(ianswett): Fix QuicConnectionTests so they don't attempt to write | 694 // TODO(ianswett): Fix QuicConnectionTests so they don't attempt to write |
693 // non-crypto stream data at ENCRYPTION_NONE. | 695 // non-crypto stream data at ENCRYPTION_NONE. |
694 FLAGS_quic_never_write_unencrypted_data = false; | 696 FLAGS_quic_never_write_unencrypted_data = false; |
695 } | 697 } |
696 | 698 |
697 QuicVersion version() { return GetParam().version; } | 699 QuicVersion version() { return GetParam().version; } |
698 | 700 |
699 QuicAckFrame* outgoing_ack() { | 701 QuicAckFrame* outgoing_ack() { |
700 QuicConnectionPeer::PopulateAckFrame(&connection_, &ack_); | 702 if (FLAGS_quic_dont_copy_acks) { |
| 703 QuicFrame ack_frame = |
| 704 QuicConnectionPeer::GetUpdatedAckFrame(&connection_); |
| 705 ack_ = *ack_frame.ack_frame; |
| 706 } else { |
| 707 QuicConnectionPeer::PopulateAckFrame(&connection_, &ack_); |
| 708 } |
701 return &ack_; | 709 return &ack_; |
702 } | 710 } |
703 | 711 |
704 QuicStopWaitingFrame* stop_waiting() { | 712 QuicStopWaitingFrame* stop_waiting() { |
705 QuicConnectionPeer::PopulateStopWaitingFrame(&connection_, &stop_waiting_); | 713 QuicConnectionPeer::PopulateStopWaitingFrame(&connection_, &stop_waiting_); |
706 return &stop_waiting_; | 714 return &stop_waiting_; |
707 } | 715 } |
708 | 716 |
709 QuicPacketNumber least_unacked() { | 717 QuicPacketNumber least_unacked() { |
710 if (writer_->stop_waiting_frames().empty()) { | 718 if (writer_->stop_waiting_frames().empty()) { |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
966 void BlockOnNextWrite() { | 974 void BlockOnNextWrite() { |
967 writer_->BlockOnNextWrite(); | 975 writer_->BlockOnNextWrite(); |
968 EXPECT_CALL(visitor_, OnWriteBlocked()).Times(AtLeast(1)); | 976 EXPECT_CALL(visitor_, OnWriteBlocked()).Times(AtLeast(1)); |
969 } | 977 } |
970 | 978 |
971 void SetWritePauseTimeDelta(QuicTime::Delta delta) { | 979 void SetWritePauseTimeDelta(QuicTime::Delta delta) { |
972 writer_->SetWritePauseTimeDelta(delta); | 980 writer_->SetWritePauseTimeDelta(delta); |
973 } | 981 } |
974 | 982 |
975 void CongestionBlockWrites() { | 983 void CongestionBlockWrites() { |
976 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _)) | 984 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _)) |
977 .WillRepeatedly(testing::Return(QuicTime::Delta::FromSeconds(1))); | 985 .WillRepeatedly(testing::Return(QuicTime::Delta::FromSeconds(1))); |
978 } | 986 } |
979 | 987 |
980 void CongestionUnblockWrites() { | 988 void CongestionUnblockWrites() { |
981 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _)) | 989 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _)) |
982 .WillRepeatedly(testing::Return(QuicTime::Delta::Zero())); | 990 .WillRepeatedly(testing::Return(QuicTime::Delta::Zero())); |
983 } | 991 } |
984 | 992 |
985 QuicConnectionId connection_id_; | 993 QuicConnectionId connection_id_; |
986 QuicFramer framer_; | 994 QuicFramer framer_; |
987 MockEntropyCalculator entropy_calculator_; | 995 MockEntropyCalculator entropy_calculator_; |
988 | 996 |
989 MockSendAlgorithm* send_algorithm_; | 997 MockSendAlgorithm* send_algorithm_; |
990 MockLossAlgorithm* loss_algorithm_; | 998 MockLossAlgorithm* loss_algorithm_; |
991 MockClock clock_; | 999 MockClock clock_; |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1296 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 1304 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
1297 ProcessAckPacket(&frame); | 1305 ProcessAckPacket(&frame); |
1298 EXPECT_EQ(num_packets, manager_->largest_observed()); | 1306 EXPECT_EQ(num_packets, manager_->largest_observed()); |
1299 } | 1307 } |
1300 | 1308 |
1301 TEST_P(QuicConnectionTest, AckReceiptCausesAckSendBadEntropy) { | 1309 TEST_P(QuicConnectionTest, AckReceiptCausesAckSendBadEntropy) { |
1302 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1310 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
1303 | 1311 |
1304 ProcessPacket(kDefaultPathId, 1); | 1312 ProcessPacket(kDefaultPathId, 1); |
1305 // Delay sending, then queue up an ack. | 1313 // Delay sending, then queue up an ack. |
1306 if (!FLAGS_quic_respect_send_alarm2) { | |
1307 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _)) | |
1308 .WillOnce(testing::Return(QuicTime::Delta::FromMicroseconds(1))); | |
1309 } | |
1310 QuicConnectionPeer::SendAck(&connection_); | 1314 QuicConnectionPeer::SendAck(&connection_); |
1311 | 1315 |
1312 // Process an ack with a least unacked of the received ack. | 1316 // Process an ack with a least unacked of the received ack. |
1313 // This causes an ack to be sent when TimeUntilSend returns 0. | 1317 // This causes an ack to be sent when TimeUntilSend returns 0. |
1314 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _)) | 1318 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _)) |
1315 .WillRepeatedly(testing::Return(QuicTime::Delta::Zero())); | 1319 .WillRepeatedly(testing::Return(QuicTime::Delta::Zero())); |
1316 // Skip a packet and then record an ack. | 1320 // Skip a packet and then record an ack. |
1317 QuicAckFrame frame = InitAckFrame(0); | 1321 QuicAckFrame frame = InitAckFrame(0); |
1318 ProcessAckPacket(3, &frame); | 1322 ProcessAckPacket(3, &frame); |
1319 } | 1323 } |
1320 | 1324 |
1321 TEST_P(QuicConnectionTest, OutOfOrderReceiptCausesAckSend) { | 1325 TEST_P(QuicConnectionTest, OutOfOrderReceiptCausesAckSend) { |
1322 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1326 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
1323 | 1327 |
1324 ProcessPacket(kDefaultPathId, 3); | 1328 ProcessPacket(kDefaultPathId, 3); |
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1882 } | 1886 } |
1883 | 1887 |
1884 TEST_P(QuicConnectionTest, OnCanWrite) { | 1888 TEST_P(QuicConnectionTest, OnCanWrite) { |
1885 // Visitor's OnCanWrite will send data, but will have more pending writes. | 1889 // Visitor's OnCanWrite will send data, but will have more pending writes. |
1886 EXPECT_CALL(visitor_, OnCanWrite()) | 1890 EXPECT_CALL(visitor_, OnCanWrite()) |
1887 .WillOnce(DoAll(IgnoreResult(InvokeWithoutArgs( | 1891 .WillOnce(DoAll(IgnoreResult(InvokeWithoutArgs( |
1888 &connection_, &TestConnection::SendStreamData3)), | 1892 &connection_, &TestConnection::SendStreamData3)), |
1889 IgnoreResult(InvokeWithoutArgs( | 1893 IgnoreResult(InvokeWithoutArgs( |
1890 &connection_, &TestConnection::SendStreamData5)))); | 1894 &connection_, &TestConnection::SendStreamData5)))); |
1891 EXPECT_CALL(visitor_, WillingAndAbleToWrite()).WillOnce(Return(true)); | 1895 EXPECT_CALL(visitor_, WillingAndAbleToWrite()).WillOnce(Return(true)); |
1892 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _)) | 1896 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _)) |
1893 .WillRepeatedly(testing::Return(QuicTime::Delta::Zero())); | 1897 .WillRepeatedly(testing::Return(QuicTime::Delta::Zero())); |
1894 | 1898 |
1895 connection_.OnCanWrite(); | 1899 connection_.OnCanWrite(); |
1896 | 1900 |
1897 // Parse the last packet and ensure it's the two stream frames from | 1901 // Parse the last packet and ensure it's the two stream frames from |
1898 // two different streams. | 1902 // two different streams. |
1899 EXPECT_EQ(2u, writer_->frame_count()); | 1903 EXPECT_EQ(2u, writer_->frame_count()); |
1900 EXPECT_EQ(2u, writer_->stream_frames().size()); | 1904 EXPECT_EQ(2u, writer_->stream_frames().size()); |
1901 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0]->stream_id); | 1905 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0]->stream_id); |
1902 EXPECT_EQ(kClientDataStreamId2, writer_->stream_frames()[1]->stream_id); | 1906 EXPECT_EQ(kClientDataStreamId2, writer_->stream_frames()[1]->stream_id); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2033 // Fire the RTO and verify that the RST_STREAM is resent, not stream data. | 2037 // Fire the RTO and verify that the RST_STREAM is resent, not stream data. |
2034 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 2038 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
2035 clock_.AdvanceTime(DefaultRetransmissionTime()); | 2039 clock_.AdvanceTime(DefaultRetransmissionTime()); |
2036 connection_.GetRetransmissionAlarm()->Fire(); | 2040 connection_.GetRetransmissionAlarm()->Fire(); |
2037 EXPECT_EQ(1u, writer_->frame_count()); | 2041 EXPECT_EQ(1u, writer_->frame_count()); |
2038 EXPECT_EQ(1u, writer_->rst_stream_frames().size()); | 2042 EXPECT_EQ(1u, writer_->rst_stream_frames().size()); |
2039 EXPECT_EQ(stream_id, writer_->rst_stream_frames().front().stream_id); | 2043 EXPECT_EQ(stream_id, writer_->rst_stream_frames().front().stream_id); |
2040 } | 2044 } |
2041 | 2045 |
2042 TEST_P(QuicConnectionTest, RetransmitForQuicRstStreamNoErrorOnRTO) { | 2046 TEST_P(QuicConnectionTest, RetransmitForQuicRstStreamNoErrorOnRTO) { |
| 2047 connection_.DisableTailLossProbe(); |
| 2048 |
2043 QuicStreamId stream_id = 2; | 2049 QuicStreamId stream_id = 2; |
2044 QuicPacketNumber last_packet; | 2050 QuicPacketNumber last_packet; |
2045 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet); | 2051 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet); |
2046 | 2052 |
2047 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 2053 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
2048 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14); | 2054 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14); |
2049 | 2055 |
2050 // Fire the RTO and verify that the RST_STREAM is resent, the stream data | 2056 // Fire the RTO and verify that the RST_STREAM is resent, the stream data |
2051 // is only sent on QUIC_VERSION_29 or later versions. | 2057 // is only sent on QUIC_VERSION_29 or later versions. |
2052 if (version() > QUIC_VERSION_28) { | 2058 if (version() > QUIC_VERSION_28) { |
2053 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 2059 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
2054 .Times(AtLeast(2)); | 2060 .Times(AtLeast(2)); |
2055 } else { | 2061 } else { |
2056 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 2062 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
2057 } | 2063 } |
2058 clock_.AdvanceTime(DefaultRetransmissionTime()); | 2064 clock_.AdvanceTime(DefaultRetransmissionTime()); |
2059 connection_.GetRetransmissionAlarm()->Fire(); | 2065 connection_.GetRetransmissionAlarm()->Fire(); |
2060 EXPECT_EQ(1u, writer_->frame_count()); | 2066 EXPECT_EQ(1u, writer_->frame_count()); |
2061 EXPECT_EQ(1u, writer_->rst_stream_frames().size()); | 2067 ASSERT_EQ(1u, writer_->rst_stream_frames().size()); |
2062 EXPECT_EQ(stream_id, writer_->rst_stream_frames().front().stream_id); | 2068 EXPECT_EQ(stream_id, writer_->rst_stream_frames().front().stream_id); |
2063 } | 2069 } |
2064 | 2070 |
2065 TEST_P(QuicConnectionTest, DoNotSendPendingRetransmissionForResetStream) { | 2071 TEST_P(QuicConnectionTest, DoNotSendPendingRetransmissionForResetStream) { |
2066 QuicStreamId stream_id = 2; | 2072 QuicStreamId stream_id = 2; |
2067 QuicPacketNumber last_packet; | 2073 QuicPacketNumber last_packet; |
2068 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet); | 2074 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet); |
2069 SendStreamDataToPeer(stream_id, "foos", 3, !kFin, &last_packet); | 2075 SendStreamDataToPeer(stream_id, "foos", 3, !kFin, &last_packet); |
2070 BlockOnNextWrite(); | 2076 BlockOnNextWrite(); |
2071 connection_.SendStreamDataWithString(stream_id, "fooos", 7, !kFin, nullptr); | 2077 connection_.SendStreamDataWithString(stream_id, "fooos", 7, !kFin, nullptr); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2190 lost_packets.push_back(std::make_pair(1, kMaxPacketSize)); | 2196 lost_packets.push_back(std::make_pair(1, kMaxPacketSize)); |
2191 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _)) | 2197 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _)) |
2192 .WillOnce(SetArgPointee<3>(lost_packets)); | 2198 .WillOnce(SetArgPointee<3>(lost_packets)); |
2193 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 2199 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
2194 EXPECT_CALL(*send_algorithm_, | 2200 EXPECT_CALL(*send_algorithm_, |
2195 OnPacketSent(_, _, _, packet_size - kQuicVersionSize, _)); | 2201 OnPacketSent(_, _, _, packet_size - kQuicVersionSize, _)); |
2196 ProcessAckPacket(&frame); | 2202 ProcessAckPacket(&frame); |
2197 } | 2203 } |
2198 | 2204 |
2199 TEST_P(QuicConnectionTest, QueueAfterTwoRTOs) { | 2205 TEST_P(QuicConnectionTest, QueueAfterTwoRTOs) { |
| 2206 connection_.DisableTailLossProbe(); |
| 2207 |
2200 for (int i = 0; i < 10; ++i) { | 2208 for (int i = 0; i < 10; ++i) { |
2201 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 2209 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
2202 connection_.SendStreamDataWithString(3, "foo", i * 3, !kFin, nullptr); | 2210 connection_.SendStreamDataWithString(3, "foo", i * 3, !kFin, nullptr); |
2203 } | 2211 } |
2204 | 2212 |
2205 // Block the writer and ensure they're queued. | 2213 // Block the writer and ensure they're queued. |
2206 BlockOnNextWrite(); | 2214 BlockOnNextWrite(); |
2207 clock_.AdvanceTime(DefaultRetransmissionTime()); | 2215 clock_.AdvanceTime(DefaultRetransmissionTime()); |
2208 // Only one packet should be retransmitted. | 2216 // Only one packet should be retransmitted. |
2209 connection_.GetRetransmissionAlarm()->Fire(); | 2217 connection_.GetRetransmissionAlarm()->Fire(); |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2423 // so send algorithm's OnRetransmissionTimeout is not called. | 2431 // so send algorithm's OnRetransmissionTimeout is not called. |
2424 clock_.AdvanceTime(retransmission_time.Subtract(clock_.Now())); | 2432 clock_.AdvanceTime(retransmission_time.Subtract(clock_.Now())); |
2425 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _)); | 2433 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _)); |
2426 connection_.GetRetransmissionAlarm()->Fire(); | 2434 connection_.GetRetransmissionAlarm()->Fire(); |
2427 EXPECT_EQ(2u, writer_->header().packet_number); | 2435 EXPECT_EQ(2u, writer_->header().packet_number); |
2428 // We do not raise the high water mark yet. | 2436 // We do not raise the high water mark yet. |
2429 EXPECT_EQ(1u, stop_waiting()->least_unacked); | 2437 EXPECT_EQ(1u, stop_waiting()->least_unacked); |
2430 } | 2438 } |
2431 | 2439 |
2432 TEST_P(QuicConnectionTest, RTO) { | 2440 TEST_P(QuicConnectionTest, RTO) { |
| 2441 connection_.DisableTailLossProbe(); |
| 2442 |
2433 QuicTime default_retransmission_time = | 2443 QuicTime default_retransmission_time = |
2434 clock_.ApproximateNow().Add(DefaultRetransmissionTime()); | 2444 clock_.ApproximateNow().Add(DefaultRetransmissionTime()); |
2435 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr); | 2445 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr); |
2436 EXPECT_EQ(1u, stop_waiting()->least_unacked); | 2446 EXPECT_EQ(1u, stop_waiting()->least_unacked); |
2437 | 2447 |
2438 EXPECT_EQ(1u, writer_->header().packet_number); | 2448 EXPECT_EQ(1u, writer_->header().packet_number); |
2439 EXPECT_EQ(default_retransmission_time, | 2449 EXPECT_EQ(default_retransmission_time, |
2440 connection_.GetRetransmissionAlarm()->deadline()); | 2450 connection_.GetRetransmissionAlarm()->deadline()); |
2441 // Simulate the retransmission alarm firing. | 2451 // Simulate the retransmission alarm firing. |
2442 clock_.AdvanceTime(DefaultRetransmissionTime()); | 2452 clock_.AdvanceTime(DefaultRetransmissionTime()); |
2443 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _)); | 2453 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _)); |
2444 connection_.GetRetransmissionAlarm()->Fire(); | 2454 connection_.GetRetransmissionAlarm()->Fire(); |
2445 EXPECT_EQ(2u, writer_->header().packet_number); | 2455 EXPECT_EQ(2u, writer_->header().packet_number); |
2446 // We do not raise the high water mark yet. | 2456 // We do not raise the high water mark yet. |
2447 EXPECT_EQ(1u, stop_waiting()->least_unacked); | 2457 EXPECT_EQ(1u, stop_waiting()->least_unacked); |
2448 } | 2458 } |
2449 | 2459 |
2450 TEST_P(QuicConnectionTest, RTOWithSameEncryptionLevel) { | 2460 TEST_P(QuicConnectionTest, RTOWithSameEncryptionLevel) { |
| 2461 connection_.DisableTailLossProbe(); |
| 2462 |
2451 QuicTime default_retransmission_time = | 2463 QuicTime default_retransmission_time = |
2452 clock_.ApproximateNow().Add(DefaultRetransmissionTime()); | 2464 clock_.ApproximateNow().Add(DefaultRetransmissionTime()); |
2453 use_tagging_decrypter(); | 2465 use_tagging_decrypter(); |
2454 | 2466 |
2455 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at | 2467 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at |
2456 // the end of the packet. We can test this to check which encrypter was used. | 2468 // the end of the packet. We can test this to check which encrypter was used. |
2457 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); | 2469 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); |
2458 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr); | 2470 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr); |
2459 EXPECT_EQ(0x01010101u, writer_->final_bytes_of_last_packet()); | 2471 EXPECT_EQ(0x01010101u, writer_->final_bytes_of_last_packet()); |
2460 | 2472 |
(...skipping 21 matching lines...) Expand all Loading... |
2482 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet()); | 2494 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet()); |
2483 } | 2495 } |
2484 | 2496 |
2485 TEST_P(QuicConnectionTest, SendHandshakeMessages) { | 2497 TEST_P(QuicConnectionTest, SendHandshakeMessages) { |
2486 use_tagging_decrypter(); | 2498 use_tagging_decrypter(); |
2487 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at | 2499 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at |
2488 // the end of the packet. We can test this to check which encrypter was used. | 2500 // the end of the packet. We can test this to check which encrypter was used. |
2489 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); | 2501 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); |
2490 | 2502 |
2491 // Attempt to send a handshake message and have the socket block. | 2503 // Attempt to send a handshake message and have the socket block. |
2492 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _)) | 2504 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _)) |
2493 .WillRepeatedly(testing::Return(QuicTime::Delta::Zero())); | 2505 .WillRepeatedly(testing::Return(QuicTime::Delta::Zero())); |
2494 BlockOnNextWrite(); | 2506 BlockOnNextWrite(); |
2495 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); | 2507 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); |
2496 // The packet should be serialized, but not queued. | 2508 // The packet should be serialized, but not queued. |
2497 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 2509 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
2498 | 2510 |
2499 // Switch to the new encrypter. | 2511 // Switch to the new encrypter. |
2500 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); | 2512 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); |
2501 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); | 2513 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); |
2502 | 2514 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2665 ENCRYPTION_INITIAL); | 2677 ENCRYPTION_INITIAL); |
2666 | 2678 |
2667 // Finally, process a third packet and note that we do not reprocess the | 2679 // Finally, process a third packet and note that we do not reprocess the |
2668 // buffered packet. | 2680 // buffered packet. |
2669 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 2681 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
2670 ProcessDataPacketAtLevel(kDefaultPathId, 102, kEntropyFlag, !kHasStopWaiting, | 2682 ProcessDataPacketAtLevel(kDefaultPathId, 102, kEntropyFlag, !kHasStopWaiting, |
2671 ENCRYPTION_INITIAL); | 2683 ENCRYPTION_INITIAL); |
2672 } | 2684 } |
2673 | 2685 |
2674 TEST_P(QuicConnectionTest, TestRetransmitOrder) { | 2686 TEST_P(QuicConnectionTest, TestRetransmitOrder) { |
| 2687 connection_.DisableTailLossProbe(); |
| 2688 |
2675 QuicByteCount first_packet_size; | 2689 QuicByteCount first_packet_size; |
2676 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 2690 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
2677 .WillOnce(DoAll(SaveArg<3>(&first_packet_size), Return(true))); | 2691 .WillOnce(DoAll(SaveArg<3>(&first_packet_size), Return(true))); |
2678 | 2692 |
2679 connection_.SendStreamDataWithString(3, "first_packet", 0, !kFin, nullptr); | 2693 connection_.SendStreamDataWithString(3, "first_packet", 0, !kFin, nullptr); |
2680 QuicByteCount second_packet_size; | 2694 QuicByteCount second_packet_size; |
2681 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 2695 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
2682 .WillOnce(DoAll(SaveArg<3>(&second_packet_size), Return(true))); | 2696 .WillOnce(DoAll(SaveArg<3>(&second_packet_size), Return(true))); |
2683 connection_.SendStreamDataWithString(3, "second_packet", 12, !kFin, nullptr); | 2697 connection_.SendStreamDataWithString(3, "second_packet", 12, !kFin, nullptr); |
2684 EXPECT_NE(first_packet_size, second_packet_size); | 2698 EXPECT_NE(first_packet_size, second_packet_size); |
(...skipping 23 matching lines...) Expand all Loading... |
2708 // Make sure that RTO is not started when the packet is queued. | 2722 // Make sure that RTO is not started when the packet is queued. |
2709 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); | 2723 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); |
2710 | 2724 |
2711 // Test that RTO is started once we write to the socket. | 2725 // Test that RTO is started once we write to the socket. |
2712 writer_->SetWritable(); | 2726 writer_->SetWritable(); |
2713 connection_.OnCanWrite(); | 2727 connection_.OnCanWrite(); |
2714 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); | 2728 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); |
2715 } | 2729 } |
2716 | 2730 |
2717 TEST_P(QuicConnectionTest, DelayRTOWithAckReceipt) { | 2731 TEST_P(QuicConnectionTest, DelayRTOWithAckReceipt) { |
| 2732 connection_.DisableTailLossProbe(); |
| 2733 |
2718 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2734 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
2719 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); | 2735 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); |
2720 connection_.SendStreamDataWithString(2, "foo", 0, !kFin, nullptr); | 2736 connection_.SendStreamDataWithString(2, "foo", 0, !kFin, nullptr); |
2721 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, nullptr); | 2737 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, nullptr); |
2722 QuicAlarm* retransmission_alarm = connection_.GetRetransmissionAlarm(); | 2738 QuicAlarm* retransmission_alarm = connection_.GetRetransmissionAlarm(); |
2723 EXPECT_TRUE(retransmission_alarm->IsSet()); | 2739 EXPECT_TRUE(retransmission_alarm->IsSet()); |
2724 EXPECT_EQ(clock_.Now().Add(DefaultRetransmissionTime()), | 2740 EXPECT_EQ(clock_.Now().Add(DefaultRetransmissionTime()), |
2725 retransmission_alarm->deadline()); | 2741 retransmission_alarm->deadline()); |
2726 | 2742 |
2727 // Advance the time right before the RTO, then receive an ack for the first | 2743 // Advance the time right before the RTO, then receive an ack for the first |
(...skipping 18 matching lines...) Expand all Loading... |
2746 // The new retransmitted packet number should set the RTO to a larger value | 2762 // The new retransmitted packet number should set the RTO to a larger value |
2747 // than previously. | 2763 // than previously. |
2748 EXPECT_TRUE(retransmission_alarm->IsSet()); | 2764 EXPECT_TRUE(retransmission_alarm->IsSet()); |
2749 QuicTime next_rto_time = retransmission_alarm->deadline(); | 2765 QuicTime next_rto_time = retransmission_alarm->deadline(); |
2750 QuicTime expected_rto_time = | 2766 QuicTime expected_rto_time = |
2751 connection_.sent_packet_manager().GetRetransmissionTime(); | 2767 connection_.sent_packet_manager().GetRetransmissionTime(); |
2752 EXPECT_EQ(next_rto_time, expected_rto_time); | 2768 EXPECT_EQ(next_rto_time, expected_rto_time); |
2753 } | 2769 } |
2754 | 2770 |
2755 TEST_P(QuicConnectionTest, TestQueued) { | 2771 TEST_P(QuicConnectionTest, TestQueued) { |
| 2772 connection_.DisableTailLossProbe(); |
| 2773 |
2756 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 2774 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
2757 BlockOnNextWrite(); | 2775 BlockOnNextWrite(); |
2758 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); | 2776 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); |
2759 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 2777 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
2760 | 2778 |
2761 // Unblock the writes and actually send. | 2779 // Unblock the writes and actually send. |
2762 writer_->SetWritable(); | 2780 writer_->SetWritable(); |
2763 connection_.OnCanWrite(); | 2781 connection_.OnCanWrite(); |
2764 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 2782 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
2765 } | 2783 } |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3320 VLOG(1) << "sending data packet"; | 3338 VLOG(1) << "sending data packet"; |
3321 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, !kFin, | 3339 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, !kFin, |
3322 nullptr); | 3340 nullptr); |
3323 connection_.GetTimeoutAlarm()->Fire(); | 3341 connection_.GetTimeoutAlarm()->Fire(); |
3324 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(1)); | 3342 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(1)); |
3325 } | 3343 } |
3326 EXPECT_FALSE(connection_.connected()); | 3344 EXPECT_FALSE(connection_.connected()); |
3327 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); | 3345 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); |
3328 } | 3346 } |
3329 | 3347 |
| 3348 TEST_P(QuicConnectionTest, TimeoutAfter5RTOs) { |
| 3349 FLAGS_quic_enable_rto_timeout = true; |
| 3350 QuicSentPacketManagerPeer::SetMaxTailLossProbes(manager_, 2); |
| 3351 EXPECT_TRUE(connection_.connected()); |
| 3352 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 3353 QuicConfig config; |
| 3354 QuicTagVector connection_options; |
| 3355 connection_options.push_back(k5RTO); |
| 3356 config.SetConnectionOptionsToSend(connection_options); |
| 3357 connection_.SetFromConfig(config); |
| 3358 |
| 3359 // Send stream data. |
| 3360 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, kFin, nullptr); |
| 3361 |
| 3362 EXPECT_CALL(visitor_, OnPathDegrading()); |
| 3363 // Fire the retransmission alarm 6 times, twice for TLP and 4 times for RTO. |
| 3364 for (int i = 0; i < 6; ++i) { |
| 3365 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| 3366 connection_.GetRetransmissionAlarm()->Fire(); |
| 3367 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet()); |
| 3368 EXPECT_TRUE(connection_.connected()); |
| 3369 } |
| 3370 |
| 3371 EXPECT_EQ(2u, connection_.sent_packet_manager().consecutive_tlp_count()); |
| 3372 EXPECT_EQ(4u, connection_.sent_packet_manager().consecutive_rto_count()); |
| 3373 // This time, we should time out. |
| 3374 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_TOO_MANY_RTOS, |
| 3375 ConnectionCloseSource::FROM_SELF)); |
| 3376 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| 3377 connection_.GetRetransmissionAlarm()->Fire(); |
| 3378 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); |
| 3379 EXPECT_FALSE(connection_.connected()); |
| 3380 } |
| 3381 |
3330 TEST_P(QuicConnectionTest, SendScheduler) { | 3382 TEST_P(QuicConnectionTest, SendScheduler) { |
3331 // Test that if we send a packet without delay, it is not queued. | 3383 // Test that if we send a packet without delay, it is not queued. |
3332 QuicPacket* packet = | 3384 QuicPacket* packet = |
3333 ConstructDataPacket(kDefaultPathId, 1, !kEntropyFlag, !kHasStopWaiting); | 3385 ConstructDataPacket(kDefaultPathId, 1, !kEntropyFlag, !kHasStopWaiting); |
3334 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 3386 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
3335 connection_.SendPacket(ENCRYPTION_NONE, kDefaultPathId, 1, packet, | 3387 connection_.SendPacket(ENCRYPTION_NONE, kDefaultPathId, 1, packet, |
3336 kTestEntropyHash, HAS_RETRANSMITTABLE_DATA, false, | 3388 kTestEntropyHash, HAS_RETRANSMITTABLE_DATA, false, |
3337 false); | 3389 false); |
3338 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 3390 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
3339 } | 3391 } |
(...skipping 23 matching lines...) Expand all Loading... |
3363 | 3415 |
3364 TEST_P(QuicConnectionTest, TestQueueLimitsOnSendStreamData) { | 3416 TEST_P(QuicConnectionTest, TestQueueLimitsOnSendStreamData) { |
3365 // All packets carry version info till version is negotiated. | 3417 // All packets carry version info till version is negotiated. |
3366 size_t payload_length; | 3418 size_t payload_length; |
3367 size_t length = GetPacketLengthForOneStream( | 3419 size_t length = GetPacketLengthForOneStream( |
3368 connection_.version(), kIncludeVersion, !kIncludePathId, | 3420 connection_.version(), kIncludeVersion, !kIncludePathId, |
3369 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_PACKET_NUMBER, &payload_length); | 3421 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_PACKET_NUMBER, &payload_length); |
3370 connection_.SetMaxPacketLength(length); | 3422 connection_.SetMaxPacketLength(length); |
3371 | 3423 |
3372 // Queue the first packet. | 3424 // Queue the first packet. |
3373 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _)) | 3425 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _)) |
3374 .WillOnce(testing::Return(QuicTime::Delta::FromMicroseconds(10))); | 3426 .WillOnce(testing::Return(QuicTime::Delta::FromMicroseconds(10))); |
3375 const string payload(payload_length, 'a'); | 3427 const string payload(payload_length, 'a'); |
3376 EXPECT_EQ(0u, | 3428 EXPECT_EQ(0u, |
3377 connection_.SendStreamDataWithString(3, payload, 0, !kFin, nullptr) | 3429 connection_.SendStreamDataWithString(3, payload, 0, !kFin, nullptr) |
3378 .bytes_consumed); | 3430 .bytes_consumed); |
3379 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 3431 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
3380 } | 3432 } |
3381 | 3433 |
3382 TEST_P(QuicConnectionTest, LoopThroughSendingPackets) { | 3434 TEST_P(QuicConnectionTest, LoopThroughSendingPackets) { |
3383 // All packets carry version info till version is negotiated. | 3435 // All packets carry version info till version is negotiated. |
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4146 EXPECT_CALL(visitor_, | 4198 EXPECT_CALL(visitor_, |
4147 OnConnectionClosed(QUIC_INVALID_VERSION_NEGOTIATION_PACKET, | 4199 OnConnectionClosed(QUIC_INVALID_VERSION_NEGOTIATION_PACKET, |
4148 ConnectionCloseSource::FROM_SELF)); | 4200 ConnectionCloseSource::FROM_SELF)); |
4149 scoped_ptr<QuicEncryptedPacket> encrypted( | 4201 scoped_ptr<QuicEncryptedPacket> encrypted( |
4150 framer_.BuildVersionNegotiationPacket(connection_id_, | 4202 framer_.BuildVersionNegotiationPacket(connection_id_, |
4151 QuicSupportedVersions())); | 4203 QuicSupportedVersions())); |
4152 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted); | 4204 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted); |
4153 } | 4205 } |
4154 | 4206 |
4155 TEST_P(QuicConnectionTest, CheckSendStats) { | 4207 TEST_P(QuicConnectionTest, CheckSendStats) { |
| 4208 connection_.DisableTailLossProbe(); |
| 4209 |
4156 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 4210 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
4157 connection_.SendStreamDataWithString(3, "first", 0, !kFin, nullptr); | 4211 connection_.SendStreamDataWithString(3, "first", 0, !kFin, nullptr); |
4158 size_t first_packet_size = writer_->last_packet_size(); | 4212 size_t first_packet_size = writer_->last_packet_size(); |
4159 | 4213 |
4160 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 4214 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
4161 connection_.SendStreamDataWithString(5, "second", 0, !kFin, nullptr); | 4215 connection_.SendStreamDataWithString(5, "second", 0, !kFin, nullptr); |
4162 size_t second_packet_size = writer_->last_packet_size(); | 4216 size_t second_packet_size = writer_->last_packet_size(); |
4163 | 4217 |
4164 // 2 retransmissions due to rto, 1 due to explicit nack. | 4218 // 2 retransmissions due to rto, 1 due to explicit nack. |
4165 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); | 4219 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4358 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _)); | 4412 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _)); |
4359 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 4413 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
4360 QuicAckFrame second_ack_frame = InitAckFrame(5); | 4414 QuicAckFrame second_ack_frame = InitAckFrame(5); |
4361 ProcessAckPacket(&second_ack_frame); | 4415 ProcessAckPacket(&second_ack_frame); |
4362 } | 4416 } |
4363 | 4417 |
4364 // AckNotifierCallback is triggered by the ack of a packet that timed | 4418 // AckNotifierCallback is triggered by the ack of a packet that timed |
4365 // out and was retransmitted, even though the retransmission has a | 4419 // out and was retransmitted, even though the retransmission has a |
4366 // different packet number. | 4420 // different packet number. |
4367 TEST_P(QuicConnectionTest, AckNotifierCallbackForAckAfterRTO) { | 4421 TEST_P(QuicConnectionTest, AckNotifierCallbackForAckAfterRTO) { |
| 4422 connection_.DisableTailLossProbe(); |
| 4423 |
4368 // Create a listener which we expect to be called. | 4424 // Create a listener which we expect to be called. |
4369 scoped_refptr<MockAckListener> listener(new StrictMock<MockAckListener>); | 4425 scoped_refptr<MockAckListener> listener(new StrictMock<MockAckListener>); |
4370 | 4426 |
4371 QuicTime default_retransmission_time = | 4427 QuicTime default_retransmission_time = |
4372 clock_.ApproximateNow().Add(DefaultRetransmissionTime()); | 4428 clock_.ApproximateNow().Add(DefaultRetransmissionTime()); |
4373 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, listener.get()); | 4429 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, listener.get()); |
4374 EXPECT_EQ(1u, stop_waiting()->least_unacked); | 4430 EXPECT_EQ(1u, stop_waiting()->least_unacked); |
4375 | 4431 |
4376 EXPECT_EQ(1u, writer_->header().packet_number); | 4432 EXPECT_EQ(1u, writer_->header().packet_number); |
4377 EXPECT_EQ(default_retransmission_time, | 4433 EXPECT_EQ(default_retransmission_time, |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4501 TEST_P(QuicConnectionTest, DoNotSendGoAwayTwice) { | 4557 TEST_P(QuicConnectionTest, DoNotSendGoAwayTwice) { |
4502 EXPECT_FALSE(connection_.goaway_sent()); | 4558 EXPECT_FALSE(connection_.goaway_sent()); |
4503 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 4559 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
4504 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away."); | 4560 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away."); |
4505 EXPECT_TRUE(connection_.goaway_sent()); | 4561 EXPECT_TRUE(connection_.goaway_sent()); |
4506 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); | 4562 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); |
4507 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away."); | 4563 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away."); |
4508 } | 4564 } |
4509 | 4565 |
4510 TEST_P(QuicConnectionTest, ReevaluateTimeUntilSendOnAck) { | 4566 TEST_P(QuicConnectionTest, ReevaluateTimeUntilSendOnAck) { |
4511 ValueRestore<bool> old_flag(&FLAGS_quic_respect_send_alarm2, true); | |
4512 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 4567 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
4513 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, !kFin, | 4568 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, !kFin, |
4514 nullptr); | 4569 nullptr); |
4515 | 4570 |
4516 // Evaluate CanWrite, and have it return a non-Zero value. | 4571 // Evaluate CanWrite, and have it return a non-Zero value. |
4517 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _)) | 4572 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _)) |
4518 .WillRepeatedly(Return(QuicTime::Delta::FromMilliseconds(1))); | 4573 .WillRepeatedly(Return(QuicTime::Delta::FromMilliseconds(1))); |
4519 connection_.OnCanWrite(); | 4574 connection_.OnCanWrite(); |
4520 EXPECT_TRUE(connection_.GetSendAlarm()->IsSet()); | 4575 EXPECT_TRUE(connection_.GetSendAlarm()->IsSet()); |
4521 EXPECT_EQ(clock_.Now().Add(QuicTime::Delta::FromMilliseconds(1)), | 4576 EXPECT_EQ(clock_.Now().Add(QuicTime::Delta::FromMilliseconds(1)), |
4522 connection_.GetSendAlarm()->deadline()); | 4577 connection_.GetSendAlarm()->deadline()); |
4523 | 4578 |
4524 // Process an ack and the send alarm will be set to the new 2ms delay. | 4579 // Process an ack and the send alarm will be set to the new 2ms delay. |
4525 QuicAckFrame ack = InitAckFrame(1); | 4580 QuicAckFrame ack = InitAckFrame(1); |
4526 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _)); | 4581 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _)); |
4527 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 4582 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
4528 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _)) | 4583 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _)) |
4529 .WillRepeatedly(Return(QuicTime::Delta::FromMilliseconds(2))); | 4584 .WillRepeatedly(Return(QuicTime::Delta::FromMilliseconds(2))); |
4530 ProcessAckPacket(&ack); | 4585 ProcessAckPacket(&ack); |
4531 EXPECT_EQ(1u, writer_->frame_count()); | 4586 EXPECT_EQ(1u, writer_->frame_count()); |
4532 EXPECT_EQ(1u, writer_->stream_frames().size()); | 4587 EXPECT_EQ(1u, writer_->stream_frames().size()); |
4533 EXPECT_TRUE(connection_.GetSendAlarm()->IsSet()); | 4588 EXPECT_TRUE(connection_.GetSendAlarm()->IsSet()); |
4534 EXPECT_EQ(clock_.Now().Add(QuicTime::Delta::FromMilliseconds(2)), | 4589 EXPECT_EQ(clock_.Now().Add(QuicTime::Delta::FromMilliseconds(2)), |
4535 connection_.GetSendAlarm()->deadline()); | 4590 connection_.GetSendAlarm()->deadline()); |
4536 writer_->Reset(); | 4591 writer_->Reset(); |
4537 } | 4592 } |
4538 | 4593 |
4539 TEST_P(QuicConnectionTest, SendAcksImmediately) { | 4594 TEST_P(QuicConnectionTest, SendAcksImmediately) { |
4540 FLAGS_quic_respect_send_alarm2 = true; | |
4541 CongestionBlockWrites(); | 4595 CongestionBlockWrites(); |
4542 SendAckPacketToPeer(); | 4596 SendAckPacketToPeer(); |
4543 } | 4597 } |
4544 | 4598 |
4545 TEST_P(QuicConnectionTest, SendPingImmediately) { | 4599 TEST_P(QuicConnectionTest, SendPingImmediately) { |
4546 CongestionBlockWrites(); | 4600 CongestionBlockWrites(); |
4547 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 4601 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
4548 connection_.SendPing(); | 4602 connection_.SendPing(); |
4549 EXPECT_FALSE(connection_.HasQueuedData()); | 4603 EXPECT_FALSE(connection_.HasQueuedData()); |
4550 } | 4604 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4606 EXPECT_FALSE(connection_.connected()); | 4660 EXPECT_FALSE(connection_.connected()); |
4607 } | 4661 } |
4608 | 4662 |
4609 TEST_P(QuicConnectionTest, OnPathDegrading) { | 4663 TEST_P(QuicConnectionTest, OnPathDegrading) { |
4610 QuicByteCount packet_size; | 4664 QuicByteCount packet_size; |
4611 const size_t kMinTimeoutsBeforePathDegrading = 2; | 4665 const size_t kMinTimeoutsBeforePathDegrading = 2; |
4612 | 4666 |
4613 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 4667 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
4614 .WillOnce(DoAll(SaveArg<3>(&packet_size), Return(true))); | 4668 .WillOnce(DoAll(SaveArg<3>(&packet_size), Return(true))); |
4615 connection_.SendStreamDataWithString(3, "packet", 0, !kFin, nullptr); | 4669 connection_.SendStreamDataWithString(3, "packet", 0, !kFin, nullptr); |
4616 for (size_t i = 1; i < kMinTimeoutsBeforePathDegrading; ++i) { | 4670 size_t num_timeouts = |
| 4671 kMinTimeoutsBeforePathDegrading + |
| 4672 QuicSentPacketManagerPeer::GetMaxTailLossProbes( |
| 4673 QuicConnectionPeer::GetSentPacketManager(&connection_)); |
| 4674 for (size_t i = 1; i < num_timeouts; ++i) { |
4617 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10 * i)); | 4675 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10 * i)); |
4618 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, packet_size, _)); | 4676 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, packet_size, _)); |
4619 connection_.GetRetransmissionAlarm()->Fire(); | 4677 connection_.GetRetransmissionAlarm()->Fire(); |
4620 } | 4678 } |
4621 // Next RTO should cause OnPathDegrading to be called before the | 4679 // Next RTO should cause OnPathDegrading to be called before the |
4622 // retransmission is sent out. | 4680 // retransmission is sent out. |
4623 clock_.AdvanceTime( | 4681 clock_.AdvanceTime( |
4624 QuicTime::Delta::FromSeconds(kMinTimeoutsBeforePathDegrading * 10)); | 4682 QuicTime::Delta::FromSeconds(kMinTimeoutsBeforePathDegrading * 10)); |
4625 { | 4683 { |
4626 InSequence s; | 4684 InSequence s; |
4627 EXPECT_CALL(visitor_, OnPathDegrading()); | 4685 EXPECT_CALL(visitor_, OnPathDegrading()); |
4628 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, packet_size, _)); | 4686 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, packet_size, _)); |
4629 } | 4687 } |
4630 connection_.GetRetransmissionAlarm()->Fire(); | 4688 connection_.GetRetransmissionAlarm()->Fire(); |
4631 } | 4689 } |
4632 | 4690 |
4633 TEST_P(QuicConnectionTest, MultipleCallsToSendConnectionCloseWithDetails) { | 4691 TEST_P(QuicConnectionTest, MultipleCallsToSendConnectionCloseWithDetails) { |
4634 // Verifies that multiple calls to SendConnectionCloseWithDetails do not | 4692 // Verifies that multiple calls to SendConnectionCloseWithDetails do not |
4635 // result in multiple attempts to close the connection - it will be marked as | 4693 // result in multiple attempts to close the connection - it will be marked as |
4636 // disconnected after the first call. | 4694 // disconnected after the first call. |
4637 EXPECT_CALL(visitor_, OnConnectionClosed(_, _)).Times(1); | 4695 EXPECT_CALL(visitor_, OnConnectionClosed(_, _)).Times(1); |
4638 connection_.SendConnectionCloseWithDetails(QUIC_NO_ERROR, "no reason"); | 4696 connection_.SendConnectionCloseWithDetails(QUIC_NO_ERROR, "no reason"); |
4639 connection_.SendConnectionCloseWithDetails(QUIC_NO_ERROR, "no reason"); | 4697 connection_.SendConnectionCloseWithDetails(QUIC_NO_ERROR, "no reason"); |
4640 } | 4698 } |
4641 | 4699 |
4642 } // namespace | 4700 } // namespace |
4643 } // namespace test | 4701 } // namespace test |
4644 } // namespace net | 4702 } // namespace net |
OLD | NEW |