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 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 } | 475 } |
476 OnSerializedPacket(&serialized_packet); | 476 OnSerializedPacket(&serialized_packet); |
477 } | 477 } |
478 | 478 |
479 QuicConsumedData SendStreamDataWithString( | 479 QuicConsumedData SendStreamDataWithString( |
480 QuicStreamId id, | 480 QuicStreamId id, |
481 StringPiece data, | 481 StringPiece data, |
482 QuicStreamOffset offset, | 482 QuicStreamOffset offset, |
483 bool fin, | 483 bool fin, |
484 QuicAckListenerInterface* listener) { | 484 QuicAckListenerInterface* listener) { |
485 return SendStreamDataWithStringHelper(id, data, offset, fin, | |
486 MAY_FEC_PROTECT, listener); | |
487 } | |
488 | |
489 QuicConsumedData SendStreamDataWithStringWithFec( | |
490 QuicStreamId id, | |
491 StringPiece data, | |
492 QuicStreamOffset offset, | |
493 bool fin, | |
494 QuicAckListenerInterface* listener) { | |
495 return SendStreamDataWithStringHelper(id, data, offset, fin, | |
496 MUST_FEC_PROTECT, listener); | |
497 } | |
498 | |
499 QuicConsumedData SendStreamDataWithStringHelper( | |
500 QuicStreamId id, | |
501 StringPiece data, | |
502 QuicStreamOffset offset, | |
503 bool fin, | |
504 FecProtection fec_protection, | |
505 QuicAckListenerInterface* listener) { | |
506 struct iovec iov; | 485 struct iovec iov; |
507 QuicIOVector data_iov(MakeIOVector(data, &iov)); | 486 QuicIOVector data_iov(MakeIOVector(data, &iov)); |
508 return QuicConnection::SendStreamData(id, data_iov, offset, fin, | 487 return QuicConnection::SendStreamData(id, data_iov, offset, fin, listener); |
509 fec_protection, listener); | |
510 } | 488 } |
511 | 489 |
512 QuicConsumedData SendStreamData3() { | 490 QuicConsumedData SendStreamData3() { |
513 return SendStreamDataWithString(kClientDataStreamId1, "food", 0, !kFin, | 491 return SendStreamDataWithString(kClientDataStreamId1, "food", 0, !kFin, |
514 nullptr); | 492 nullptr); |
515 } | 493 } |
516 | 494 |
517 QuicConsumedData SendStreamData3WithFec() { | |
518 return SendStreamDataWithStringWithFec(kClientDataStreamId1, "food", 0, | |
519 !kFin, nullptr); | |
520 } | |
521 | |
522 QuicConsumedData SendStreamData5() { | 495 QuicConsumedData SendStreamData5() { |
523 return SendStreamDataWithString(kClientDataStreamId2, "food2", 0, !kFin, | 496 return SendStreamDataWithString(kClientDataStreamId2, "food2", 0, !kFin, |
524 nullptr); | 497 nullptr); |
525 } | 498 } |
526 | 499 |
527 QuicConsumedData SendStreamData5WithFec() { | |
528 return SendStreamDataWithStringWithFec(kClientDataStreamId2, "food2", 0, | |
529 !kFin, nullptr); | |
530 } | |
531 // Ensures the connection can write stream data before writing. | 500 // Ensures the connection can write stream data before writing. |
532 QuicConsumedData EnsureWritableAndSendStreamData5() { | 501 QuicConsumedData EnsureWritableAndSendStreamData5() { |
533 EXPECT_TRUE(CanWriteStreamData()); | 502 EXPECT_TRUE(CanWriteStreamData()); |
534 return SendStreamData5(); | 503 return SendStreamData5(); |
535 } | 504 } |
536 | 505 |
537 // The crypto stream has special semantics so that it is not blocked by a | 506 // The crypto stream has special semantics so that it is not blocked by a |
538 // congestion window limitation, and also so that it gets put into a separate | 507 // congestion window limitation, and also so that it gets put into a separate |
539 // packet (so that it is easier to reason about a crypto frame not being | 508 // packet (so that it is easier to reason about a crypto frame not being |
540 // split needlessly across packet boundaries). As a result, we have separate | 509 // split needlessly across packet boundaries). As a result, we have separate |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 TestConnectionHelper::TestAlarm* GetAckAlarm() { | 548 TestConnectionHelper::TestAlarm* GetAckAlarm() { |
580 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( | 549 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( |
581 QuicConnectionPeer::GetAckAlarm(this)); | 550 QuicConnectionPeer::GetAckAlarm(this)); |
582 } | 551 } |
583 | 552 |
584 TestConnectionHelper::TestAlarm* GetPingAlarm() { | 553 TestConnectionHelper::TestAlarm* GetPingAlarm() { |
585 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( | 554 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( |
586 QuicConnectionPeer::GetPingAlarm(this)); | 555 QuicConnectionPeer::GetPingAlarm(this)); |
587 } | 556 } |
588 | 557 |
589 TestConnectionHelper::TestAlarm* GetFecAlarm() { | |
590 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( | |
591 QuicConnectionPeer::GetFecAlarm(this)); | |
592 } | |
593 | |
594 TestConnectionHelper::TestAlarm* GetResumeWritesAlarm() { | 558 TestConnectionHelper::TestAlarm* GetResumeWritesAlarm() { |
595 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( | 559 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( |
596 QuicConnectionPeer::GetResumeWritesAlarm(this)); | 560 QuicConnectionPeer::GetResumeWritesAlarm(this)); |
597 } | 561 } |
598 | 562 |
599 TestConnectionHelper::TestAlarm* GetRetransmissionAlarm() { | 563 TestConnectionHelper::TestAlarm* GetRetransmissionAlarm() { |
600 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( | 564 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( |
601 QuicConnectionPeer::GetRetransmissionAlarm(this)); | 565 QuicConnectionPeer::GetRetransmissionAlarm(this)); |
602 } | 566 } |
603 | 567 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 | 601 |
638 // Public accessor method. | 602 // Public accessor method. |
639 QuicPacketHeader revived_header() const { return revived_header_; } | 603 QuicPacketHeader revived_header() const { return revived_header_; } |
640 | 604 |
641 private: | 605 private: |
642 QuicPacketHeader revived_header_; | 606 QuicPacketHeader revived_header_; |
643 }; | 607 }; |
644 | 608 |
645 enum class AckResponse { kDefer, kImmediate }; | 609 enum class AckResponse { kDefer, kImmediate }; |
646 | 610 |
647 // Run tests with combinations of {QuicVersion, fec_send_policy, | 611 // Run tests with combinations of {QuicVersion, AckResponse}. |
648 // AckResponse}. | |
649 struct TestParams { | 612 struct TestParams { |
650 TestParams(QuicVersion version, | 613 TestParams(QuicVersion version, |
651 FecSendPolicy fec_send_policy, | |
652 AckResponse ack_response) | 614 AckResponse ack_response) |
653 : version(version), | 615 : version(version), |
654 fec_send_policy(fec_send_policy), | |
655 ack_response(ack_response) {} | 616 ack_response(ack_response) {} |
656 | 617 |
657 friend ostream& operator<<(ostream& os, const TestParams& p) { | 618 friend ostream& operator<<(ostream& os, const TestParams& p) { |
658 os << "{ client_version: " << QuicVersionToString(p.version) | 619 os << "{ client_version: " << QuicVersionToString(p.version) |
659 << " fec_send_policy: " << p.fec_send_policy << " ack_response: " | 620 << " ack_response: " |
660 << (p.ack_response == AckResponse::kDefer ? "defer" : "immediate") | 621 << (p.ack_response == AckResponse::kDefer ? "defer" : "immediate") |
661 << " }"; | 622 << " }"; |
662 return os; | 623 return os; |
663 } | 624 } |
664 | 625 |
665 QuicVersion version; | 626 QuicVersion version; |
666 FecSendPolicy fec_send_policy; | |
667 AckResponse ack_response; | 627 AckResponse ack_response; |
668 }; | 628 }; |
669 | 629 |
670 // Constructs various test permutations. | 630 // Constructs various test permutations. |
671 vector<TestParams> GetTestParams() { | 631 vector<TestParams> GetTestParams() { |
672 vector<TestParams> params; | 632 vector<TestParams> params; |
673 QuicVersionVector all_supported_versions = QuicSupportedVersions(); | 633 QuicVersionVector all_supported_versions = QuicSupportedVersions(); |
674 for (size_t i = 0; i < all_supported_versions.size(); ++i) { | 634 for (size_t i = 0; i < all_supported_versions.size(); ++i) { |
675 for (FecSendPolicy fec_send_policy : {FEC_ANY_TRIGGER, FEC_ALARM_TRIGGER}) { | 635 for (AckResponse ack_response : |
676 for (AckResponse ack_response : | 636 {AckResponse::kDefer, AckResponse::kImmediate}) { |
677 {AckResponse::kDefer, AckResponse::kImmediate}) { | 637 params.push_back(TestParams(all_supported_versions[i], ack_response)); |
678 params.push_back(TestParams(all_supported_versions[i], fec_send_policy, | |
679 ack_response)); | |
680 } | |
681 } | 638 } |
682 } | 639 } |
683 return params; | 640 return params; |
684 } | 641 } |
685 | 642 |
686 class QuicConnectionTest : public ::testing::TestWithParam<TestParams> { | 643 class QuicConnectionTest : public ::testing::TestWithParam<TestParams> { |
687 protected: | 644 protected: |
688 QuicConnectionTest() | 645 QuicConnectionTest() |
689 : connection_id_(42), | 646 : connection_id_(42), |
690 framer_(SupportedVersions(version()), | 647 framer_(SupportedVersions(version()), |
(...skipping 21 matching lines...) Expand all Loading... |
712 frame2_(1, false, 3, StringPiece(data2)), | 669 frame2_(1, false, 3, StringPiece(data2)), |
713 packet_number_length_(PACKET_6BYTE_PACKET_NUMBER), | 670 packet_number_length_(PACKET_6BYTE_PACKET_NUMBER), |
714 connection_id_length_(PACKET_8BYTE_CONNECTION_ID) { | 671 connection_id_length_(PACKET_8BYTE_CONNECTION_ID) { |
715 connection_.set_defer_send_in_response_to_packets(GetParam().ack_response == | 672 connection_.set_defer_send_in_response_to_packets(GetParam().ack_response == |
716 AckResponse::kDefer); | 673 AckResponse::kDefer); |
717 FLAGS_quic_always_log_bugs_for_tests = true; | 674 FLAGS_quic_always_log_bugs_for_tests = true; |
718 connection_.set_visitor(&visitor_); | 675 connection_.set_visitor(&visitor_); |
719 connection_.SetSendAlgorithm(send_algorithm_); | 676 connection_.SetSendAlgorithm(send_algorithm_); |
720 connection_.SetLossAlgorithm(loss_algorithm_); | 677 connection_.SetLossAlgorithm(loss_algorithm_); |
721 framer_.set_received_entropy_calculator(&entropy_calculator_); | 678 framer_.set_received_entropy_calculator(&entropy_calculator_); |
722 generator_->set_fec_send_policy(GetParam().fec_send_policy); | |
723 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _)) | 679 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _)) |
724 .WillRepeatedly(Return(QuicTime::Delta::Zero())); | 680 .WillRepeatedly(Return(QuicTime::Delta::Zero())); |
725 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 681 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
726 .Times(AnyNumber()); | 682 .Times(AnyNumber()); |
727 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) | 683 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) |
728 .WillRepeatedly(Return(QuicTime::Delta::Zero())); | 684 .WillRepeatedly(Return(QuicTime::Delta::Zero())); |
729 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) | 685 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) |
730 .WillRepeatedly(Return(kDefaultTCPMSS)); | 686 .WillRepeatedly(Return(kDefaultTCPMSS)); |
731 EXPECT_CALL(*send_algorithm_, PacingRate()) | 687 EXPECT_CALL(*send_algorithm_, PacingRate()) |
732 .WillRepeatedly(Return(QuicBandwidth::Zero())); | 688 .WillRepeatedly(Return(QuicBandwidth::Zero())); |
(...skipping 1157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1890 expected_recorded_send_time = clock_.Now(); | 1846 expected_recorded_send_time = clock_.Now(); |
1891 | 1847 |
1892 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 1848 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
1893 .WillOnce(DoAll(SaveArg<0>(&actual_recorded_send_time), Return(true))); | 1849 .WillOnce(DoAll(SaveArg<0>(&actual_recorded_send_time), Return(true))); |
1894 connection_.SendStreamDataWithString(2, "baz", 0, !kFin, nullptr); | 1850 connection_.SendStreamDataWithString(2, "baz", 0, !kFin, nullptr); |
1895 EXPECT_EQ(expected_recorded_send_time, actual_recorded_send_time) | 1851 EXPECT_EQ(expected_recorded_send_time, actual_recorded_send_time) |
1896 << "Expected time = " << expected_recorded_send_time.ToDebuggingValue() | 1852 << "Expected time = " << expected_recorded_send_time.ToDebuggingValue() |
1897 << ". Actual time = " << actual_recorded_send_time.ToDebuggingValue(); | 1853 << ". Actual time = " << actual_recorded_send_time.ToDebuggingValue(); |
1898 } | 1854 } |
1899 | 1855 |
1900 TEST_P(QuicConnectionTest, FECSending) { | |
1901 // All packets carry version info till version is negotiated. | |
1902 size_t payload_length; | |
1903 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining | |
1904 // packet length. The size of the offset field in a stream frame is 0 for | |
1905 // offset 0, and 2 for non-zero offsets up through 64K. Increase | |
1906 // max_packet_length by 2 so that subsequent packets containing subsequent | |
1907 // stream frames with non-zero offets will fit within the packet length. | |
1908 size_t length = | |
1909 2 + GetPacketLengthForOneStream( | |
1910 connection_.version(), kIncludeVersion, !kIncludePathId, | |
1911 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_PACKET_NUMBER, | |
1912 IN_FEC_GROUP, &payload_length); | |
1913 connection_.SetMaxPacketLength(length); | |
1914 | |
1915 if (generator_->fec_send_policy() == FEC_ALARM_TRIGGER) { | |
1916 // Send 4 protected data packets. FEC packet is not sent. | |
1917 EXPECT_CALL(*send_algorithm_, | |
1918 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)) | |
1919 .Times(4); | |
1920 } else { | |
1921 // Send 4 protected data packets, which should also trigger 1 FEC packet. | |
1922 EXPECT_CALL(*send_algorithm_, | |
1923 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)) | |
1924 .Times(5); | |
1925 } | |
1926 // The first stream frame will have 2 fewer overhead bytes than the other 3. | |
1927 const string payload(payload_length * 4 + 2, 'a'); | |
1928 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, nullptr); | |
1929 // Expect the FEC group to be closed after SendStreamDataWithString. | |
1930 EXPECT_FALSE(creator_->IsFecGroupOpen()); | |
1931 EXPECT_FALSE(QuicPacketCreatorPeer::IsFecProtected(creator_)); | |
1932 } | |
1933 | |
1934 TEST_P(QuicConnectionTest, FECQueueing) { | |
1935 // All packets carry version info till version is negotiated. | |
1936 size_t payload_length; | |
1937 size_t length = GetPacketLengthForOneStream( | |
1938 connection_.version(), kIncludeVersion, !kIncludePathId, | |
1939 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_PACKET_NUMBER, IN_FEC_GROUP, | |
1940 &payload_length); | |
1941 connection_.SetMaxPacketLength(length); | |
1942 EXPECT_TRUE(QuicPacketCreatorPeer::IsFecEnabled(creator_)); | |
1943 | |
1944 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | |
1945 BlockOnNextWrite(); | |
1946 const string payload(payload_length, 'a'); | |
1947 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, nullptr); | |
1948 EXPECT_FALSE(creator_->IsFecGroupOpen()); | |
1949 EXPECT_FALSE(QuicPacketCreatorPeer::IsFecProtected(creator_)); | |
1950 if (generator_->fec_send_policy() == FEC_ALARM_TRIGGER) { | |
1951 // Expect the first data packet to be queued and not the FEC packet. | |
1952 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | |
1953 } else { | |
1954 // Expect the first data packet and the fec packet to be queued. | |
1955 EXPECT_EQ(2u, connection_.NumQueuedPackets()); | |
1956 } | |
1957 } | |
1958 | |
1959 TEST_P(QuicConnectionTest, FECAlarmStoppedWhenFECPacketSent) { | |
1960 EXPECT_TRUE(QuicPacketCreatorPeer::IsFecEnabled(creator_)); | |
1961 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_)); | |
1962 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet()); | |
1963 | |
1964 creator_->set_max_packets_per_fec_group(2); | |
1965 | |
1966 // 1 Data packet. FEC alarm should be set. | |
1967 EXPECT_CALL(*send_algorithm_, | |
1968 OnPacketSent(_, _, 1u, _, HAS_RETRANSMITTABLE_DATA)) | |
1969 .Times(1); | |
1970 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, true, nullptr); | |
1971 EXPECT_TRUE(connection_.GetFecAlarm()->IsSet()); | |
1972 | |
1973 if (generator_->fec_send_policy() == FEC_ALARM_TRIGGER) { | |
1974 // If FEC send policy is FEC_ALARM_TRIGGER, FEC packet is not sent. | |
1975 // FEC alarm should not be set. | |
1976 EXPECT_CALL(*send_algorithm_, | |
1977 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)) | |
1978 .Times(1); | |
1979 } else { | |
1980 // Second data packet triggers FEC packet out. FEC alarm should not be set. | |
1981 EXPECT_CALL(*send_algorithm_, | |
1982 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)) | |
1983 .Times(2); | |
1984 } | |
1985 connection_.SendStreamDataWithStringWithFec(5, "foo", 0, true, nullptr); | |
1986 if (generator_->fec_send_policy() == FEC_ANY_TRIGGER) { | |
1987 EXPECT_TRUE(writer_->header().fec_flag); | |
1988 } | |
1989 EXPECT_FALSE(creator_->IsFecGroupOpen()); | |
1990 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet()); | |
1991 } | |
1992 | |
1993 TEST_P(QuicConnectionTest, FECAlarmStoppedOnConnectionClose) { | |
1994 EXPECT_TRUE(QuicPacketCreatorPeer::IsFecEnabled(creator_)); | |
1995 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet()); | |
1996 creator_->set_max_packets_per_fec_group(100); | |
1997 | |
1998 // 1 Data packet. FEC alarm should be set. | |
1999 EXPECT_CALL(*send_algorithm_, | |
2000 OnPacketSent(_, _, 1u, _, HAS_RETRANSMITTABLE_DATA)) | |
2001 .Times(1); | |
2002 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, kFin, nullptr); | |
2003 EXPECT_TRUE(connection_.GetFecAlarm()->IsSet()); | |
2004 | |
2005 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_NO_ERROR, | |
2006 ConnectionCloseSource::FROM_SELF)); | |
2007 // Closing connection should stop the FEC alarm. | |
2008 connection_.CloseConnection(QUIC_NO_ERROR, ConnectionCloseSource::FROM_SELF); | |
2009 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet()); | |
2010 } | |
2011 | |
2012 TEST_P(QuicConnectionTest, RemoveFECFromInflightOnRetransmissionTimeout) { | |
2013 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | |
2014 EXPECT_TRUE(QuicPacketCreatorPeer::IsFecEnabled(creator_)); | |
2015 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_)); | |
2016 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet()); | |
2017 | |
2018 // 1 Data packet. FEC alarm should be set. | |
2019 EXPECT_CALL(*send_algorithm_, | |
2020 OnPacketSent(_, _, 1u, _, HAS_RETRANSMITTABLE_DATA)) | |
2021 .Times(1); | |
2022 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, nullptr); | |
2023 EXPECT_TRUE(connection_.GetFecAlarm()->IsSet()); | |
2024 size_t protected_packet = | |
2025 QuicSentPacketManagerPeer::GetBytesInFlight(manager_); | |
2026 | |
2027 // Force FEC timeout to send FEC packet out. | |
2028 EXPECT_CALL(*send_algorithm_, | |
2029 OnPacketSent(_, _, 2u, _, HAS_RETRANSMITTABLE_DATA)) | |
2030 .Times(1); | |
2031 connection_.GetFecAlarm()->Fire(); | |
2032 EXPECT_TRUE(writer_->header().fec_flag); | |
2033 | |
2034 size_t fec_packet = protected_packet; | |
2035 EXPECT_EQ(protected_packet + fec_packet, | |
2036 QuicSentPacketManagerPeer::GetBytesInFlight(manager_)); | |
2037 clock_.AdvanceTime(DefaultRetransmissionTime()); | |
2038 | |
2039 // On RTO, both data and FEC packets are removed from inflight, only the data | |
2040 // packet is retransmitted, and this retransmission (but not FEC) gets added | |
2041 // back into the inflight. | |
2042 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); | |
2043 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | |
2044 connection_.GetRetransmissionAlarm()->Fire(); | |
2045 | |
2046 // The retransmission of packet 1 will be 3 bytes smaller than packet 1, since | |
2047 // the first transmission will have 1 byte for FEC group number and 2 bytes of | |
2048 // stream frame size, which are absent in the retransmission. | |
2049 size_t retransmitted_packet = protected_packet - 3; | |
2050 EXPECT_EQ(protected_packet + retransmitted_packet, | |
2051 QuicSentPacketManagerPeer::GetBytesInFlight(manager_)); | |
2052 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet()); | |
2053 | |
2054 // Receive ack for the retransmission. No data should be outstanding. | |
2055 QuicAckFrame ack = InitAckFrame(3); | |
2056 NackPacket(1, &ack); | |
2057 NackPacket(2, &ack); | |
2058 SendAlgorithmInterface::CongestionVector lost_packets; | |
2059 lost_packets.push_back(std::make_pair(1, kMaxPacketSize)); | |
2060 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _)) | |
2061 .WillOnce(SetArgPointee<3>(lost_packets)); | |
2062 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | |
2063 ProcessAckPacket(&ack); | |
2064 | |
2065 // Ensure the alarm is not set since all packets have been acked or abandoned. | |
2066 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); | |
2067 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_)); | |
2068 } | |
2069 | |
2070 TEST_P(QuicConnectionTest, RemoveFECFromInflightOnLossRetransmission) { | |
2071 EXPECT_TRUE(QuicPacketCreatorPeer::IsFecEnabled(creator_)); | |
2072 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet()); | |
2073 | |
2074 // 1 FEC-protected data packet. FEC alarm should be set. | |
2075 EXPECT_CALL(*send_algorithm_, | |
2076 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)) | |
2077 .Times(1); | |
2078 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, kFin, nullptr); | |
2079 EXPECT_TRUE(connection_.GetFecAlarm()->IsSet()); | |
2080 size_t protected_packet = | |
2081 QuicSentPacketManagerPeer::GetBytesInFlight(manager_); | |
2082 | |
2083 // Force FEC timeout to send FEC packet out. | |
2084 EXPECT_CALL(*send_algorithm_, | |
2085 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)) | |
2086 .Times(1); | |
2087 connection_.GetFecAlarm()->Fire(); | |
2088 EXPECT_TRUE(writer_->header().fec_flag); | |
2089 size_t fec_packet = protected_packet; | |
2090 EXPECT_EQ(protected_packet + fec_packet, | |
2091 QuicSentPacketManagerPeer::GetBytesInFlight(manager_)); | |
2092 | |
2093 // Send more data to trigger NACKs. Note that all data starts at stream offset | |
2094 // 0 to ensure the same packet size, for ease of testing. | |
2095 EXPECT_CALL(*send_algorithm_, | |
2096 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)) | |
2097 .Times(4); | |
2098 connection_.SendStreamDataWithString(5, "foo", 0, kFin, nullptr); | |
2099 connection_.SendStreamDataWithString(7, "foo", 0, kFin, nullptr); | |
2100 connection_.SendStreamDataWithString(9, "foo", 0, kFin, nullptr); | |
2101 connection_.SendStreamDataWithString(11, "foo", 0, kFin, nullptr); | |
2102 | |
2103 // An unprotected packet will be 3 bytes smaller than an FEC-protected packet, | |
2104 // since the protected packet will have 1 byte for FEC group number and | |
2105 // 2 bytes of stream frame size, which are absent in the unprotected packet. | |
2106 size_t unprotected_packet = protected_packet - 3; | |
2107 EXPECT_EQ(protected_packet + fec_packet + 4 * unprotected_packet, | |
2108 QuicSentPacketManagerPeer::GetBytesInFlight(manager_)); | |
2109 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet()); | |
2110 | |
2111 // Ack data packets, and NACK FEC packet and one data packet. Triggers | |
2112 // NACK-based loss detection of both packets, but only data packet is | |
2113 // retransmitted and considered outstanding. | |
2114 QuicAckFrame ack = InitAckFrame(6); | |
2115 NackPacket(2, &ack); | |
2116 NackPacket(3, &ack); | |
2117 SendAlgorithmInterface::CongestionVector lost_packets; | |
2118 lost_packets.push_back(std::make_pair(2, kMaxPacketSize)); | |
2119 lost_packets.push_back(std::make_pair(3, kMaxPacketSize)); | |
2120 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _)) | |
2121 .WillOnce(SetArgPointee<3>(lost_packets)); | |
2122 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | |
2123 EXPECT_CALL(*send_algorithm_, | |
2124 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)) | |
2125 .Times(1); | |
2126 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | |
2127 ProcessAckPacket(&ack); | |
2128 // On receiving this ack from the server, the client will no longer send | |
2129 // version number in subsequent packets, including in this retransmission. | |
2130 size_t unprotected_packet_no_version = unprotected_packet - 4; | |
2131 EXPECT_EQ(unprotected_packet_no_version, | |
2132 QuicSentPacketManagerPeer::GetBytesInFlight(manager_)); | |
2133 | |
2134 // Receive ack for the retransmission. No data should be outstanding. | |
2135 QuicAckFrame ack2 = InitAckFrame(7); | |
2136 NackPacket(2, &ack2); | |
2137 NackPacket(3, &ack2); | |
2138 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _)); | |
2139 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | |
2140 ProcessAckPacket(&ack2); | |
2141 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_)); | |
2142 } | |
2143 | |
2144 TEST_P(QuicConnectionTest, FECRemainsInflightOnTLPOfEarlierData) { | |
2145 // This test checks if TLP is sent correctly when a data and an FEC packet | |
2146 // are outstanding. TLP should be sent for the data packet when the | |
2147 // retransmission alarm fires. | |
2148 // Turn on TLP for this test. | |
2149 QuicSentPacketManagerPeer::SetMaxTailLossProbes(manager_, 1); | |
2150 EXPECT_TRUE(QuicPacketCreatorPeer::IsFecEnabled(creator_)); | |
2151 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_)); | |
2152 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet()); | |
2153 | |
2154 // 1 Data packet. FEC alarm should be set. | |
2155 EXPECT_CALL(*send_algorithm_, | |
2156 OnPacketSent(_, _, 1u, _, HAS_RETRANSMITTABLE_DATA)) | |
2157 .Times(1); | |
2158 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, kFin, nullptr); | |
2159 EXPECT_TRUE(connection_.GetFecAlarm()->IsSet()); | |
2160 size_t protected_packet = | |
2161 QuicSentPacketManagerPeer::GetBytesInFlight(manager_); | |
2162 EXPECT_LT(0u, protected_packet); | |
2163 | |
2164 // Force FEC timeout to send FEC packet out. | |
2165 EXPECT_CALL(*send_algorithm_, | |
2166 OnPacketSent(_, _, 2u, _, HAS_RETRANSMITTABLE_DATA)) | |
2167 .Times(1); | |
2168 connection_.GetFecAlarm()->Fire(); | |
2169 EXPECT_TRUE(writer_->header().fec_flag); | |
2170 size_t fec_packet = protected_packet; | |
2171 EXPECT_EQ(protected_packet + fec_packet, | |
2172 QuicSentPacketManagerPeer::GetBytesInFlight(manager_)); | |
2173 | |
2174 // TLP alarm should be set. | |
2175 QuicTime retransmission_time = | |
2176 connection_.GetRetransmissionAlarm()->deadline(); | |
2177 EXPECT_NE(QuicTime::Zero(), retransmission_time); | |
2178 // Simulate the retransmission alarm firing and sending a TLP, so send | |
2179 // algorithm's OnRetransmissionTimeout is not called. | |
2180 clock_.AdvanceTime(retransmission_time.Subtract(clock_.Now())); | |
2181 EXPECT_CALL(*send_algorithm_, | |
2182 OnPacketSent(_, _, 3u, _, HAS_RETRANSMITTABLE_DATA)) | |
2183 .Times(1); | |
2184 connection_.GetRetransmissionAlarm()->Fire(); | |
2185 // The TLP retransmission of packet 1 will be 3 bytes smaller than packet 1, | |
2186 // since packet 1 will have 1 byte for FEC group number and 2 bytes of stream | |
2187 // frame size, which are absent in the the TLP retransmission. | |
2188 size_t tlp_packet = protected_packet - 3; | |
2189 EXPECT_EQ(protected_packet + fec_packet + tlp_packet, | |
2190 QuicSentPacketManagerPeer::GetBytesInFlight(manager_)); | |
2191 } | |
2192 | |
2193 TEST_P(QuicConnectionTest, FECRemainsInflightOnTLPOfLaterData) { | |
2194 // Tests if TLP is sent correctly when data packet 1 and an FEC packet are | |
2195 // sent followed by data packet 2, and data packet 1 is acked. TLP should be | |
2196 // sent for data packet 2 when the retransmission alarm fires. Turn on TLP for | |
2197 // this test. | |
2198 QuicSentPacketManagerPeer::SetMaxTailLossProbes(manager_, 1); | |
2199 EXPECT_TRUE(QuicPacketCreatorPeer::IsFecEnabled(creator_)); | |
2200 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_)); | |
2201 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet()); | |
2202 | |
2203 // 1 Data packet. FEC alarm should be set. | |
2204 EXPECT_CALL(*send_algorithm_, | |
2205 OnPacketSent(_, _, 1u, _, HAS_RETRANSMITTABLE_DATA)) | |
2206 .Times(1); | |
2207 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, kFin, nullptr); | |
2208 EXPECT_TRUE(connection_.GetFecAlarm()->IsSet()); | |
2209 size_t protected_packet = | |
2210 QuicSentPacketManagerPeer::GetBytesInFlight(manager_); | |
2211 EXPECT_LT(0u, protected_packet); | |
2212 | |
2213 // Force FEC timeout to send FEC packet out. | |
2214 EXPECT_CALL(*send_algorithm_, | |
2215 OnPacketSent(_, _, 2u, _, HAS_RETRANSMITTABLE_DATA)) | |
2216 .Times(1); | |
2217 connection_.GetFecAlarm()->Fire(); | |
2218 EXPECT_TRUE(writer_->header().fec_flag); | |
2219 // Protected data packet and FEC packet oustanding. | |
2220 size_t fec_packet = protected_packet; | |
2221 EXPECT_EQ(protected_packet + fec_packet, | |
2222 QuicSentPacketManagerPeer::GetBytesInFlight(manager_)); | |
2223 | |
2224 // Send 1 unprotected data packet. No FEC alarm should be set. | |
2225 EXPECT_CALL(*send_algorithm_, | |
2226 OnPacketSent(_, _, 3u, _, HAS_RETRANSMITTABLE_DATA)) | |
2227 .Times(1); | |
2228 connection_.SendStreamDataWithString(5, "foo", 0, kFin, nullptr); | |
2229 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet()); | |
2230 // Protected data packet, FEC packet, and unprotected data packet oustanding. | |
2231 // An unprotected packet will be 3 bytes smaller than an FEC-protected packet, | |
2232 // since the protected packet will have 1 byte for FEC group number and | |
2233 // 2 bytes of stream frame size, which are absent in the unprotected packet. | |
2234 size_t unprotected_packet = protected_packet - 3; | |
2235 EXPECT_EQ(protected_packet + fec_packet + unprotected_packet, | |
2236 QuicSentPacketManagerPeer::GetBytesInFlight(manager_)); | |
2237 | |
2238 // Receive ack for first data packet. FEC and second data packet are still | |
2239 // outstanding. | |
2240 QuicAckFrame ack = InitAckFrame(1); | |
2241 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | |
2242 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | |
2243 ProcessAckPacket(&ack); | |
2244 // FEC packet and unprotected data packet oustanding. | |
2245 EXPECT_EQ(fec_packet + unprotected_packet, | |
2246 QuicSentPacketManagerPeer::GetBytesInFlight(manager_)); | |
2247 | |
2248 // TLP alarm should be set. | |
2249 QuicTime retransmission_time = | |
2250 connection_.GetRetransmissionAlarm()->deadline(); | |
2251 EXPECT_NE(QuicTime::Zero(), retransmission_time); | |
2252 // Simulate the retransmission alarm firing and sending a TLP, so send | |
2253 // algorithm's OnRetransmissionTimeout is not called. | |
2254 clock_.AdvanceTime(retransmission_time.Subtract(clock_.Now())); | |
2255 EXPECT_CALL(*send_algorithm_, | |
2256 OnPacketSent(_, _, 4u, _, HAS_RETRANSMITTABLE_DATA)) | |
2257 .Times(1); | |
2258 connection_.GetRetransmissionAlarm()->Fire(); | |
2259 | |
2260 // Having received an ack from the server, the client will no longer send | |
2261 // version number in subsequent packets, including in this retransmission. | |
2262 size_t tlp_packet_no_version = unprotected_packet - 4; | |
2263 EXPECT_EQ(fec_packet + unprotected_packet + tlp_packet_no_version, | |
2264 QuicSentPacketManagerPeer::GetBytesInFlight(manager_)); | |
2265 } | |
2266 | |
2267 TEST_P(QuicConnectionTest, NoTLPForFECPacket) { | |
2268 // Turn on TLP for this test. | |
2269 QuicSentPacketManagerPeer::SetMaxTailLossProbes(manager_, 1); | |
2270 EXPECT_TRUE(QuicPacketCreatorPeer::IsFecEnabled(creator_)); | |
2271 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | |
2272 | |
2273 // Send 1 FEC-protected data packet. FEC alarm should be set. | |
2274 EXPECT_CALL(*send_algorithm_, | |
2275 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)) | |
2276 .Times(1); | |
2277 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, nullptr); | |
2278 EXPECT_TRUE(connection_.GetFecAlarm()->IsSet()); | |
2279 // Force FEC timeout to send FEC packet out. | |
2280 EXPECT_CALL(*send_algorithm_, | |
2281 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)) | |
2282 .Times(1); | |
2283 connection_.GetFecAlarm()->Fire(); | |
2284 EXPECT_TRUE(writer_->header().fec_flag); | |
2285 | |
2286 // Ack data packet, but not FEC packet. | |
2287 QuicAckFrame ack = InitAckFrame(1); | |
2288 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | |
2289 ProcessAckPacket(&ack); | |
2290 | |
2291 // No TLP alarm for FEC, but retransmission alarm should be set for an RTO. | |
2292 EXPECT_LT(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_)); | |
2293 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); | |
2294 QuicTime rto_time = connection_.GetRetransmissionAlarm()->deadline(); | |
2295 EXPECT_NE(QuicTime::Zero(), rto_time); | |
2296 | |
2297 // Simulate the retransmission alarm firing. FEC packet is no longer | |
2298 // outstanding. | |
2299 clock_.AdvanceTime(rto_time.Subtract(clock_.Now())); | |
2300 connection_.GetRetransmissionAlarm()->Fire(); | |
2301 | |
2302 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); | |
2303 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_)); | |
2304 } | |
2305 | |
2306 TEST_P(QuicConnectionTest, FramePacking) { | 1856 TEST_P(QuicConnectionTest, FramePacking) { |
2307 // Send an ack and two stream frames in 1 packet by queueing them. | 1857 // Send an ack and two stream frames in 1 packet by queueing them. |
2308 { | 1858 { |
2309 QuicConnection::ScopedPacketBundler bundler(&connection_, | 1859 QuicConnection::ScopedPacketBundler bundler(&connection_, |
2310 QuicConnection::SEND_ACK); | 1860 QuicConnection::SEND_ACK); |
2311 connection_.SendStreamData3(); | 1861 connection_.SendStreamData3(); |
2312 connection_.SendStreamData5(); | 1862 connection_.SendStreamData5(); |
2313 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 1863 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
2314 } | 1864 } |
2315 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1865 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2356 } | 1906 } |
2357 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1907 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
2358 EXPECT_FALSE(connection_.HasQueuedData()); | 1908 EXPECT_FALSE(connection_.HasQueuedData()); |
2359 | 1909 |
2360 // Parse the last packet and ensure it's the stream frame from stream 3. | 1910 // Parse the last packet and ensure it's the stream frame from stream 3. |
2361 EXPECT_EQ(1u, writer_->frame_count()); | 1911 EXPECT_EQ(1u, writer_->frame_count()); |
2362 ASSERT_EQ(1u, writer_->stream_frames().size()); | 1912 ASSERT_EQ(1u, writer_->stream_frames().size()); |
2363 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0]->stream_id); | 1913 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0]->stream_id); |
2364 } | 1914 } |
2365 | 1915 |
2366 TEST_P(QuicConnectionTest, FramePackingFEC) { | |
2367 EXPECT_TRUE(QuicPacketCreatorPeer::IsFecEnabled(creator_)); | |
2368 | |
2369 // Queue an ack and two stream frames. Ack gets flushed when FEC is turned on | |
2370 // for sending protected data; two stream frames are packed in 1 packet. | |
2371 { | |
2372 QuicConnection::ScopedPacketBundler bundler(&connection_, | |
2373 QuicConnection::SEND_ACK); | |
2374 connection_.SendStreamData3WithFec(); | |
2375 connection_.SendStreamData5WithFec(); | |
2376 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | |
2377 } | |
2378 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | |
2379 EXPECT_FALSE(connection_.HasQueuedData()); | |
2380 | |
2381 // Parse the last packet and ensure it's in an fec group. | |
2382 EXPECT_EQ(2u, writer_->header().fec_group); | |
2383 EXPECT_EQ(2u, writer_->frame_count()); | |
2384 | |
2385 // FEC alarm should be set. | |
2386 EXPECT_TRUE(connection_.GetFecAlarm()->IsSet()); | |
2387 } | |
2388 | |
2389 TEST_P(QuicConnectionTest, FramePackingAckResponse) { | 1916 TEST_P(QuicConnectionTest, FramePackingAckResponse) { |
2390 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1917 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
2391 // Process a data packet to queue up a pending ack. | 1918 // Process a data packet to queue up a pending ack. |
2392 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 1919 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
2393 ProcessDataPacket(kDefaultPathId, 1, 1, kEntropyFlag); | 1920 ProcessDataPacket(kDefaultPathId, 1, 1, kEntropyFlag); |
2394 | 1921 |
2395 EXPECT_CALL(visitor_, OnCanWrite()) | 1922 EXPECT_CALL(visitor_, OnCanWrite()) |
2396 .WillOnce(DoAll(IgnoreResult(InvokeWithoutArgs( | 1923 .WillOnce(DoAll(IgnoreResult(InvokeWithoutArgs( |
2397 &connection_, &TestConnection::SendStreamData3)), | 1924 &connection_, &TestConnection::SendStreamData3)), |
2398 IgnoreResult(InvokeWithoutArgs( | 1925 IgnoreResult(InvokeWithoutArgs( |
(...skipping 22 matching lines...) Expand all Loading... |
2421 // Send data in 1 packet by writing multiple blocks in a single iovector | 1948 // Send data in 1 packet by writing multiple blocks in a single iovector |
2422 // using writev. | 1949 // using writev. |
2423 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 1950 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
2424 | 1951 |
2425 char data[] = "ABCD"; | 1952 char data[] = "ABCD"; |
2426 struct iovec iov[2]; | 1953 struct iovec iov[2]; |
2427 iov[0].iov_base = data; | 1954 iov[0].iov_base = data; |
2428 iov[0].iov_len = 2; | 1955 iov[0].iov_len = 2; |
2429 iov[1].iov_base = data + 2; | 1956 iov[1].iov_base = data + 2; |
2430 iov[1].iov_len = 2; | 1957 iov[1].iov_len = 2; |
2431 connection_.SendStreamData(1, QuicIOVector(iov, 2, 4), 0, !kFin, | 1958 connection_.SendStreamData(1, QuicIOVector(iov, 2, 4), 0, !kFin, nullptr); |
2432 MAY_FEC_PROTECT, nullptr); | |
2433 | 1959 |
2434 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1960 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
2435 EXPECT_FALSE(connection_.HasQueuedData()); | 1961 EXPECT_FALSE(connection_.HasQueuedData()); |
2436 | 1962 |
2437 // Parse the last packet and ensure multiple iovector blocks have | 1963 // Parse the last packet and ensure multiple iovector blocks have |
2438 // been packed into a single stream frame from one stream. | 1964 // been packed into a single stream frame from one stream. |
2439 EXPECT_EQ(1u, writer_->frame_count()); | 1965 EXPECT_EQ(1u, writer_->frame_count()); |
2440 EXPECT_EQ(1u, writer_->stream_frames().size()); | 1966 EXPECT_EQ(1u, writer_->stream_frames().size()); |
2441 QuicStreamFrame* frame = writer_->stream_frames()[0]; | 1967 QuicStreamFrame* frame = writer_->stream_frames()[0]; |
2442 EXPECT_EQ(1u, frame->stream_id); | 1968 EXPECT_EQ(1u, frame->stream_id); |
2443 EXPECT_EQ("ABCD", StringPiece(frame->frame_buffer, frame->frame_length)); | 1969 EXPECT_EQ("ABCD", StringPiece(frame->frame_buffer, frame->frame_length)); |
2444 } | 1970 } |
2445 | 1971 |
2446 TEST_P(QuicConnectionTest, FramePackingSendvQueued) { | 1972 TEST_P(QuicConnectionTest, FramePackingSendvQueued) { |
2447 // Try to send two stream frames in 1 packet by using writev. | 1973 // Try to send two stream frames in 1 packet by using writev. |
2448 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 1974 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
2449 | 1975 |
2450 BlockOnNextWrite(); | 1976 BlockOnNextWrite(); |
2451 char data[] = "ABCD"; | 1977 char data[] = "ABCD"; |
2452 struct iovec iov[2]; | 1978 struct iovec iov[2]; |
2453 iov[0].iov_base = data; | 1979 iov[0].iov_base = data; |
2454 iov[0].iov_len = 2; | 1980 iov[0].iov_len = 2; |
2455 iov[1].iov_base = data + 2; | 1981 iov[1].iov_base = data + 2; |
2456 iov[1].iov_len = 2; | 1982 iov[1].iov_len = 2; |
2457 connection_.SendStreamData(1, QuicIOVector(iov, 2, 4), 0, !kFin, | 1983 connection_.SendStreamData(1, QuicIOVector(iov, 2, 4), 0, !kFin, nullptr); |
2458 MAY_FEC_PROTECT, nullptr); | |
2459 | 1984 |
2460 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 1985 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
2461 EXPECT_TRUE(connection_.HasQueuedData()); | 1986 EXPECT_TRUE(connection_.HasQueuedData()); |
2462 | 1987 |
2463 // Unblock the writes and actually send. | 1988 // Unblock the writes and actually send. |
2464 writer_->SetWritable(); | 1989 writer_->SetWritable(); |
2465 connection_.OnCanWrite(); | 1990 connection_.OnCanWrite(); |
2466 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1991 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
2467 | 1992 |
2468 // Parse the last packet and ensure it's one stream frame from one stream. | 1993 // Parse the last packet and ensure it's one stream frame from one stream. |
2469 EXPECT_EQ(1u, writer_->frame_count()); | 1994 EXPECT_EQ(1u, writer_->frame_count()); |
2470 EXPECT_EQ(1u, writer_->stream_frames().size()); | 1995 EXPECT_EQ(1u, writer_->stream_frames().size()); |
2471 EXPECT_EQ(1u, writer_->stream_frames()[0]->stream_id); | 1996 EXPECT_EQ(1u, writer_->stream_frames()[0]->stream_id); |
2472 } | 1997 } |
2473 | 1998 |
2474 TEST_P(QuicConnectionTest, SendingZeroBytes) { | 1999 TEST_P(QuicConnectionTest, SendingZeroBytes) { |
2475 // Send a zero byte write with a fin using writev. | 2000 // Send a zero byte write with a fin using writev. |
2476 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 2001 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
2477 QuicIOVector empty_iov(nullptr, 0, 0); | 2002 QuicIOVector empty_iov(nullptr, 0, 0); |
2478 connection_.SendStreamData(1, empty_iov, 0, kFin, MAY_FEC_PROTECT, nullptr); | 2003 connection_.SendStreamData(1, empty_iov, 0, kFin, nullptr); |
2479 | 2004 |
2480 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 2005 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
2481 EXPECT_FALSE(connection_.HasQueuedData()); | 2006 EXPECT_FALSE(connection_.HasQueuedData()); |
2482 | 2007 |
2483 // Parse the last packet and ensure it's one stream frame from one stream. | 2008 // Parse the last packet and ensure it's one stream frame from one stream. |
2484 EXPECT_EQ(1u, writer_->frame_count()); | 2009 EXPECT_EQ(1u, writer_->frame_count()); |
2485 EXPECT_EQ(1u, writer_->stream_frames().size()); | 2010 EXPECT_EQ(1u, writer_->stream_frames().size()); |
2486 EXPECT_EQ(1u, writer_->stream_frames()[0]->stream_id); | 2011 EXPECT_EQ(1u, writer_->stream_frames()[0]->stream_id); |
2487 EXPECT_TRUE(writer_->stream_frames()[0]->fin); | 2012 EXPECT_TRUE(writer_->stream_frames()[0]->fin); |
2488 } | 2013 } |
(...skipping 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3596 ConnectionCloseSource::FROM_SELF)); | 3121 ConnectionCloseSource::FROM_SELF)); |
3597 // Simulate the timeout alarm firing. | 3122 // Simulate the timeout alarm firing. |
3598 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1)); | 3123 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1)); |
3599 connection_.GetTimeoutAlarm()->Fire(); | 3124 connection_.GetTimeoutAlarm()->Fire(); |
3600 | 3125 |
3601 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); | 3126 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); |
3602 EXPECT_FALSE(connection_.connected()); | 3127 EXPECT_FALSE(connection_.connected()); |
3603 | 3128 |
3604 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 3129 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
3605 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); | 3130 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); |
3606 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet()); | |
3607 EXPECT_FALSE(connection_.GetResumeWritesAlarm()->IsSet()); | 3131 EXPECT_FALSE(connection_.GetResumeWritesAlarm()->IsSet()); |
3608 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); | 3132 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); |
3609 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet()); | 3133 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet()); |
3610 EXPECT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet()); | 3134 EXPECT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet()); |
3611 } | 3135 } |
3612 | 3136 |
3613 TEST_P(QuicConnectionTest, HandshakeTimeout) { | 3137 TEST_P(QuicConnectionTest, HandshakeTimeout) { |
3614 // Use a shorter handshake timeout than idle timeout for this test. | 3138 // Use a shorter handshake timeout than idle timeout for this test. |
3615 const QuicTime::Delta timeout = QuicTime::Delta::FromSeconds(5); | 3139 const QuicTime::Delta timeout = QuicTime::Delta::FromSeconds(5); |
3616 connection_.SetNetworkTimeouts(timeout, timeout); | 3140 connection_.SetNetworkTimeouts(timeout, timeout); |
(...skipping 23 matching lines...) Expand all Loading... |
3640 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_HANDSHAKE_TIMEOUT, | 3164 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_HANDSHAKE_TIMEOUT, |
3641 ConnectionCloseSource::FROM_SELF)); | 3165 ConnectionCloseSource::FROM_SELF)); |
3642 // Simulate the timeout alarm firing. | 3166 // Simulate the timeout alarm firing. |
3643 connection_.GetTimeoutAlarm()->Fire(); | 3167 connection_.GetTimeoutAlarm()->Fire(); |
3644 | 3168 |
3645 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); | 3169 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); |
3646 EXPECT_FALSE(connection_.connected()); | 3170 EXPECT_FALSE(connection_.connected()); |
3647 | 3171 |
3648 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 3172 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
3649 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); | 3173 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); |
3650 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet()); | |
3651 EXPECT_FALSE(connection_.GetResumeWritesAlarm()->IsSet()); | 3174 EXPECT_FALSE(connection_.GetResumeWritesAlarm()->IsSet()); |
3652 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); | 3175 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); |
3653 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet()); | 3176 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet()); |
3654 } | 3177 } |
3655 | 3178 |
3656 TEST_P(QuicConnectionTest, PingAfterSend) { | 3179 TEST_P(QuicConnectionTest, PingAfterSend) { |
3657 EXPECT_TRUE(connection_.connected()); | 3180 EXPECT_TRUE(connection_.connected()); |
3658 EXPECT_CALL(visitor_, HasOpenDynamicStreams()).WillRepeatedly(Return(true)); | 3181 EXPECT_CALL(visitor_, HasOpenDynamicStreams()).WillRepeatedly(Return(true)); |
3659 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); | 3182 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); |
3660 | 3183 |
(...skipping 1707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5368 ack_header.is_in_fec_group = IN_FEC_GROUP; | 4891 ack_header.is_in_fec_group = IN_FEC_GROUP; |
5369 ack_header.fec_group = 1; | 4892 ack_header.fec_group = 1; |
5370 | 4893 |
5371 QuicPacket* packet = BuildUnsizedDataPacket(&framer_, ack_header, frames); | 4894 QuicPacket* packet = BuildUnsizedDataPacket(&framer_, ack_header, frames); |
5372 | 4895 |
5373 // Take the packet which contains the ACK frame, and construct and deliver an | 4896 // Take the packet which contains the ACK frame, and construct and deliver an |
5374 // FEC packet which allows the ACK packet to be recovered. | 4897 // FEC packet which allows the ACK packet to be recovered. |
5375 ProcessFecPacket(kDefaultPathId, 2, 1, true, !kEntropyFlag, packet); | 4898 ProcessFecPacket(kDefaultPathId, 2, 1, true, !kEntropyFlag, packet); |
5376 } | 4899 } |
5377 | 4900 |
5378 TEST_P(QuicConnectionTest, NetworkChangeVisitorCwndCallbackChangesFecState) { | |
5379 size_t max_packets_per_fec_group = creator_->max_packets_per_fec_group(); | |
5380 | |
5381 QuicSentPacketManager::NetworkChangeVisitor* visitor = | |
5382 QuicSentPacketManagerPeer::GetNetworkChangeVisitor(manager_); | |
5383 EXPECT_TRUE(visitor); | |
5384 | |
5385 // Increase FEC group size by increasing congestion window to a large number. | |
5386 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) | |
5387 .WillRepeatedly(Return(1000 * kDefaultTCPMSS)); | |
5388 visitor->OnCongestionWindowChange(); | |
5389 EXPECT_LT(max_packets_per_fec_group, creator_->max_packets_per_fec_group()); | |
5390 } | |
5391 | |
5392 TEST_P(QuicConnectionTest, NetworkChangeVisitorConfigCallbackChangesFecState) { | |
5393 QuicSentPacketManager::NetworkChangeVisitor* visitor = | |
5394 QuicSentPacketManagerPeer::GetNetworkChangeVisitor(manager_); | |
5395 EXPECT_TRUE(visitor); | |
5396 EXPECT_EQ(QuicTime::Delta::Zero(), | |
5397 QuicPacketCreatorPeer::GetFecTimeout(creator_)); | |
5398 | |
5399 // Verify that sending a config with a new initial rtt changes fec timeout. | |
5400 // Create and process a config with a non-zero initial RTT. | |
5401 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); | |
5402 QuicConfig config; | |
5403 config.SetInitialRoundTripTimeUsToSend(300000); | |
5404 connection_.SetFromConfig(config); | |
5405 EXPECT_LT(QuicTime::Delta::Zero(), | |
5406 QuicPacketCreatorPeer::GetFecTimeout(creator_)); | |
5407 } | |
5408 | |
5409 TEST_P(QuicConnectionTest, NetworkChangeVisitorRttCallbackChangesFecState) { | |
5410 // Verify that sending a config with a new initial rtt changes fec timeout. | |
5411 QuicSentPacketManager::NetworkChangeVisitor* visitor = | |
5412 QuicSentPacketManagerPeer::GetNetworkChangeVisitor(manager_); | |
5413 EXPECT_TRUE(visitor); | |
5414 EXPECT_EQ(QuicTime::Delta::Zero(), | |
5415 QuicPacketCreatorPeer::GetFecTimeout(creator_)); | |
5416 | |
5417 // Increase FEC timeout by increasing RTT. | |
5418 RttStats* rtt_stats = QuicSentPacketManagerPeer::GetRttStats(manager_); | |
5419 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(300), | |
5420 QuicTime::Delta::Zero(), QuicTime::Zero()); | |
5421 visitor->OnRttChange(); | |
5422 EXPECT_LT(QuicTime::Delta::Zero(), | |
5423 QuicPacketCreatorPeer::GetFecTimeout(creator_)); | |
5424 } | |
5425 | |
5426 TEST_P(QuicConnectionTest, OnPacketHeaderDebugVisitor) { | 4901 TEST_P(QuicConnectionTest, OnPacketHeaderDebugVisitor) { |
5427 QuicPacketHeader header; | 4902 QuicPacketHeader header; |
5428 | 4903 |
5429 scoped_ptr<MockQuicConnectionDebugVisitor> debug_visitor( | 4904 scoped_ptr<MockQuicConnectionDebugVisitor> debug_visitor( |
5430 new MockQuicConnectionDebugVisitor()); | 4905 new MockQuicConnectionDebugVisitor()); |
5431 connection_.set_debug_visitor(debug_visitor.get()); | 4906 connection_.set_debug_visitor(debug_visitor.get()); |
5432 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1); | 4907 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1); |
5433 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)).Times(1); | 4908 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)).Times(1); |
5434 EXPECT_CALL(*debug_visitor, OnSuccessfulVersionNegotiation(_)).Times(1); | 4909 EXPECT_CALL(*debug_visitor, OnSuccessfulVersionNegotiation(_)).Times(1); |
5435 connection_.OnPacketHeader(header); | 4910 connection_.OnPacketHeader(header); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5476 TEST_P(QuicConnectionTest, NoDataNoFin) { | 4951 TEST_P(QuicConnectionTest, NoDataNoFin) { |
5477 // Make sure that a call to SendStreamWithData, with no data and no FIN, does | 4952 // Make sure that a call to SendStreamWithData, with no data and no FIN, does |
5478 // not result in a QuicAckNotifier being used-after-free (fail under ASAN). | 4953 // not result in a QuicAckNotifier being used-after-free (fail under ASAN). |
5479 // Regression test for b/18594622 | 4954 // Regression test for b/18594622 |
5480 scoped_refptr<MockAckListener> listener(new MockAckListener); | 4955 scoped_refptr<MockAckListener> listener(new MockAckListener); |
5481 EXPECT_DFATAL( | 4956 EXPECT_DFATAL( |
5482 connection_.SendStreamDataWithString(3, "", 0, !kFin, listener.get()), | 4957 connection_.SendStreamDataWithString(3, "", 0, !kFin, listener.get()), |
5483 "Attempt to send empty stream frame"); | 4958 "Attempt to send empty stream frame"); |
5484 } | 4959 } |
5485 | 4960 |
5486 TEST_P(QuicConnectionTest, FecSendPolicyReceivedConnectionOption) { | |
5487 // Test sending SetReceivedConnectionOptions when FEC send policy is | |
5488 // FEC_ANY_TRIGGER. | |
5489 if (GetParam().fec_send_policy == FEC_ALARM_TRIGGER) { | |
5490 return; | |
5491 } | |
5492 connection_.set_perspective(Perspective::IS_SERVER); | |
5493 | |
5494 // Test ReceivedConnectionOptions. | |
5495 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); | |
5496 QuicConfig config; | |
5497 QuicTagVector copt; | |
5498 copt.push_back(kFSPA); | |
5499 QuicConfigPeer::SetReceivedConnectionOptions(&config, copt); | |
5500 EXPECT_EQ(FEC_ANY_TRIGGER, generator_->fec_send_policy()); | |
5501 connection_.SetFromConfig(config); | |
5502 EXPECT_EQ(FEC_ALARM_TRIGGER, generator_->fec_send_policy()); | |
5503 } | |
5504 | |
5505 // TODO(rtenneti): Delete this code after the 0.25 RTT FEC experiment. | |
5506 TEST_P(QuicConnectionTest, FecRTTMultiplierReceivedConnectionOption) { | |
5507 connection_.set_perspective(Perspective::IS_SERVER); | |
5508 | |
5509 // Test ReceivedConnectionOptions. | |
5510 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); | |
5511 QuicConfig config; | |
5512 QuicTagVector copt; | |
5513 copt.push_back(kFRTT); | |
5514 QuicConfigPeer::SetReceivedConnectionOptions(&config, copt); | |
5515 float rtt_multiplier_for_fec_timeout = | |
5516 QuicPacketCreatorPeer::GetRttMultiplierForFecTimeout(creator_); | |
5517 connection_.SetFromConfig(config); | |
5518 // New RTT multiplier is half of the old RTT multiplier. | |
5519 EXPECT_EQ(rtt_multiplier_for_fec_timeout, | |
5520 QuicPacketCreatorPeer::GetRttMultiplierForFecTimeout(creator_) * 2); | |
5521 } | |
5522 | |
5523 TEST_P(QuicConnectionTest, DoNotSendGoAwayTwice) { | 4961 TEST_P(QuicConnectionTest, DoNotSendGoAwayTwice) { |
5524 EXPECT_FALSE(connection_.goaway_sent()); | 4962 EXPECT_FALSE(connection_.goaway_sent()); |
5525 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 4963 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
5526 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away."); | 4964 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away."); |
5527 EXPECT_TRUE(connection_.goaway_sent()); | 4965 EXPECT_TRUE(connection_.goaway_sent()); |
5528 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); | 4966 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); |
5529 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away."); | 4967 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away."); |
5530 } | 4968 } |
5531 | 4969 |
5532 TEST_P(QuicConnectionTest, ReevaluateTimeUntilSendOnAck) { | 4970 TEST_P(QuicConnectionTest, ReevaluateTimeUntilSendOnAck) { |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5657 // result in multiple attempts to close the connection - it will be marked as | 5095 // result in multiple attempts to close the connection - it will be marked as |
5658 // disconnected after the first call. | 5096 // disconnected after the first call. |
5659 EXPECT_CALL(visitor_, OnConnectionClosed(_, _)).Times(1); | 5097 EXPECT_CALL(visitor_, OnConnectionClosed(_, _)).Times(1); |
5660 connection_.SendConnectionCloseWithDetails(QUIC_NO_ERROR, "no reason"); | 5098 connection_.SendConnectionCloseWithDetails(QUIC_NO_ERROR, "no reason"); |
5661 connection_.SendConnectionCloseWithDetails(QUIC_NO_ERROR, "no reason"); | 5099 connection_.SendConnectionCloseWithDetails(QUIC_NO_ERROR, "no reason"); |
5662 } | 5100 } |
5663 | 5101 |
5664 } // namespace | 5102 } // namespace |
5665 } // namespace test | 5103 } // namespace test |
5666 } // namespace net | 5104 } // namespace net |
OLD | NEW |