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

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

Issue 1782053003: Optionally defer responding to a QUIC ACK until all ACK processing has completed for an EpollServer… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@115992556
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/quic_connection.cc ('k') | net/quic/quic_flags.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/quic/quic_connection.h" 5 #include "net/quic/quic_connection.h"
6 6
7 #include <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 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( 610 return reinterpret_cast<TestConnectionHelper::TestAlarm*>(
611 QuicConnectionPeer::GetTimeoutAlarm(this)); 611 QuicConnectionPeer::GetTimeoutAlarm(this));
612 } 612 }
613 613
614 TestConnectionHelper::TestAlarm* GetMtuDiscoveryAlarm() { 614 TestConnectionHelper::TestAlarm* GetMtuDiscoveryAlarm() {
615 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( 615 return reinterpret_cast<TestConnectionHelper::TestAlarm*>(
616 QuicConnectionPeer::GetMtuDiscoveryAlarm(this)); 616 QuicConnectionPeer::GetMtuDiscoveryAlarm(this));
617 } 617 }
618 618
619 using QuicConnection::SelectMutualVersion; 619 using QuicConnection::SelectMutualVersion;
620 using QuicConnection::set_defer_send_in_response_to_packets;
620 621
621 private: 622 private:
622 TestPacketWriter* writer() { 623 TestPacketWriter* writer() {
623 return static_cast<TestPacketWriter*>(QuicConnection::writer()); 624 return static_cast<TestPacketWriter*>(QuicConnection::writer());
624 } 625 }
625 626
626 DISALLOW_COPY_AND_ASSIGN(TestConnection); 627 DISALLOW_COPY_AND_ASSIGN(TestConnection);
627 }; 628 };
628 629
629 // Used for testing packets revived from FEC packets. 630 // Used for testing packets revived from FEC packets.
630 class FecQuicConnectionDebugVisitor : public QuicConnectionDebugVisitor { 631 class FecQuicConnectionDebugVisitor : public QuicConnectionDebugVisitor {
631 public: 632 public:
632 void OnRevivedPacket(const QuicPacketHeader& header, 633 void OnRevivedPacket(const QuicPacketHeader& header,
633 StringPiece data) override { 634 StringPiece data) override {
634 revived_header_ = header; 635 revived_header_ = header;
635 } 636 }
636 637
637 // Public accessor method. 638 // Public accessor method.
638 QuicPacketHeader revived_header() const { return revived_header_; } 639 QuicPacketHeader revived_header() const { return revived_header_; }
639 640
640 private: 641 private:
641 QuicPacketHeader revived_header_; 642 QuicPacketHeader revived_header_;
642 }; 643 };
643 644
644 // Run tests with combinations of {QuicVersion, fec_send_policy}. 645 enum class AckResponse { kDefer, kImmediate };
646
647 // Run tests with combinations of {QuicVersion, fec_send_policy,
648 // AckResponse}.
645 struct TestParams { 649 struct TestParams {
646 TestParams(QuicVersion version, FecSendPolicy fec_send_policy) 650 TestParams(QuicVersion version,
647 : version(version), fec_send_policy(fec_send_policy) {} 651 FecSendPolicy fec_send_policy,
652 AckResponse ack_response)
653 : version(version),
654 fec_send_policy(fec_send_policy),
655 ack_response(ack_response) {}
648 656
649 friend ostream& operator<<(ostream& os, const TestParams& p) { 657 friend ostream& operator<<(ostream& os, const TestParams& p) {
650 os << "{ client_version: " << QuicVersionToString(p.version) 658 os << "{ client_version: " << QuicVersionToString(p.version)
651 << " fec_send_policy: " << p.fec_send_policy << " }"; 659 << " fec_send_policy: " << p.fec_send_policy << " ack_response: "
660 << (p.ack_response == AckResponse::kDefer ? "defer" : "immediate")
661 << " }";
652 return os; 662 return os;
653 } 663 }
654 664
655 QuicVersion version; 665 QuicVersion version;
656 FecSendPolicy fec_send_policy; 666 FecSendPolicy fec_send_policy;
667 AckResponse ack_response;
657 }; 668 };
658 669
659 // Constructs various test permutations. 670 // Constructs various test permutations.
660 vector<TestParams> GetTestParams() { 671 vector<TestParams> GetTestParams() {
661 vector<TestParams> params; 672 vector<TestParams> params;
662 QuicVersionVector all_supported_versions = QuicSupportedVersions(); 673 QuicVersionVector all_supported_versions = QuicSupportedVersions();
663 for (size_t i = 0; i < all_supported_versions.size(); ++i) { 674 for (size_t i = 0; i < all_supported_versions.size(); ++i) {
664 params.push_back(TestParams(all_supported_versions[i], FEC_ANY_TRIGGER)); 675 for (FecSendPolicy fec_send_policy : {FEC_ANY_TRIGGER, FEC_ALARM_TRIGGER}) {
665 params.push_back(TestParams(all_supported_versions[i], FEC_ALARM_TRIGGER)); 676 for (AckResponse ack_response :
677 {AckResponse::kDefer, AckResponse::kImmediate}) {
678 params.push_back(TestParams(all_supported_versions[i], fec_send_policy,
679 ack_response));
680 }
681 }
666 } 682 }
667 return params; 683 return params;
668 } 684 }
669 685
670 class QuicConnectionTest : public ::testing::TestWithParam<TestParams> { 686 class QuicConnectionTest : public ::testing::TestWithParam<TestParams> {
671 protected: 687 protected:
672 QuicConnectionTest() 688 QuicConnectionTest()
673 : connection_id_(42), 689 : connection_id_(42),
674 framer_(SupportedVersions(version()), 690 framer_(SupportedVersions(version()),
675 QuicTime::Zero(), 691 QuicTime::Zero(),
(...skipping 13 matching lines...) Expand all
689 writer_.get(), 705 writer_.get(),
690 Perspective::IS_CLIENT, 706 Perspective::IS_CLIENT,
691 version()), 707 version()),
692 creator_(QuicConnectionPeer::GetPacketCreator(&connection_)), 708 creator_(QuicConnectionPeer::GetPacketCreator(&connection_)),
693 generator_(QuicConnectionPeer::GetPacketGenerator(&connection_)), 709 generator_(QuicConnectionPeer::GetPacketGenerator(&connection_)),
694 manager_(QuicConnectionPeer::GetSentPacketManager(&connection_)), 710 manager_(QuicConnectionPeer::GetSentPacketManager(&connection_)),
695 frame1_(1, false, 0, StringPiece(data1)), 711 frame1_(1, false, 0, StringPiece(data1)),
696 frame2_(1, false, 3, StringPiece(data2)), 712 frame2_(1, false, 3, StringPiece(data2)),
697 packet_number_length_(PACKET_6BYTE_PACKET_NUMBER), 713 packet_number_length_(PACKET_6BYTE_PACKET_NUMBER),
698 connection_id_length_(PACKET_8BYTE_CONNECTION_ID) { 714 connection_id_length_(PACKET_8BYTE_CONNECTION_ID) {
715 connection_.set_defer_send_in_response_to_packets(GetParam().ack_response ==
716 AckResponse::kDefer);
699 FLAGS_quic_always_log_bugs_for_tests = true; 717 FLAGS_quic_always_log_bugs_for_tests = true;
700 connection_.set_visitor(&visitor_); 718 connection_.set_visitor(&visitor_);
701 connection_.SetSendAlgorithm(send_algorithm_); 719 connection_.SetSendAlgorithm(send_algorithm_);
702 connection_.SetLossAlgorithm(loss_algorithm_); 720 connection_.SetLossAlgorithm(loss_algorithm_);
703 framer_.set_received_entropy_calculator(&entropy_calculator_); 721 framer_.set_received_entropy_calculator(&entropy_calculator_);
704 generator_->set_fec_send_policy(GetParam().fec_send_policy); 722 generator_->set_fec_send_policy(GetParam().fec_send_policy);
705 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _)) 723 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _))
706 .WillRepeatedly(Return(QuicTime::Delta::Zero())); 724 .WillRepeatedly(Return(QuicTime::Delta::Zero()));
707 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 725 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
708 .Times(AnyNumber()); 726 .Times(AnyNumber());
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 return 0; 773 return 0;
756 } 774 }
757 return writer_->stop_waiting_frames()[0].least_unacked; 775 return writer_->stop_waiting_frames()[0].least_unacked;
758 } 776 }
759 777
760 void use_tagging_decrypter() { writer_->use_tagging_decrypter(); } 778 void use_tagging_decrypter() { writer_->use_tagging_decrypter(); }
761 779
762 void ProcessPacket(QuicPathId path_id, QuicPacketNumber number) { 780 void ProcessPacket(QuicPathId path_id, QuicPacketNumber number) {
763 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); 781 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
764 ProcessDataPacket(path_id, number, 0, !kEntropyFlag); 782 ProcessDataPacket(path_id, number, 0, !kEntropyFlag);
783 if (connection_.GetSendAlarm()->IsSet()) {
784 connection_.GetSendAlarm()->Fire();
785 }
765 } 786 }
766 787
767 QuicPacketEntropyHash ProcessFramePacket(QuicFrame frame) { 788 QuicPacketEntropyHash ProcessFramePacket(QuicFrame frame) {
768 return ProcessFramePacketWithAddresses(frame, kSelfAddress, kPeerAddress); 789 return ProcessFramePacketWithAddresses(frame, kSelfAddress, kPeerAddress);
769 } 790 }
770 791
771 QuicPacketEntropyHash ProcessFramePacketWithAddresses( 792 QuicPacketEntropyHash ProcessFramePacketWithAddresses(
772 QuicFrame frame, 793 QuicFrame frame,
773 IPEndPoint self_address, 794 IPEndPoint self_address,
774 IPEndPoint peer_address) { 795 IPEndPoint peer_address) {
775 QuicFrames frames; 796 QuicFrames frames;
776 frames.push_back(QuicFrame(frame)); 797 frames.push_back(QuicFrame(frame));
777 QuicPacketCreatorPeer::SetSendVersionInPacket( 798 QuicPacketCreatorPeer::SetSendVersionInPacket(
778 &peer_creator_, connection_.perspective() == Perspective::IS_SERVER); 799 &peer_creator_, connection_.perspective() == Perspective::IS_SERVER);
779 800
780 char buffer[kMaxPacketSize]; 801 char buffer[kMaxPacketSize];
781 SerializedPacket serialized_packet = 802 SerializedPacket serialized_packet =
782 QuicPacketCreatorPeer::SerializeAllFrames(&peer_creator_, frames, 803 QuicPacketCreatorPeer::SerializeAllFrames(&peer_creator_, frames,
783 buffer, kMaxPacketSize); 804 buffer, kMaxPacketSize);
784 connection_.ProcessUdpPacket( 805 connection_.ProcessUdpPacket(
785 self_address, peer_address, 806 self_address, peer_address,
786 QuicEncryptedPacket(serialized_packet.encrypted_buffer, 807 QuicEncryptedPacket(serialized_packet.encrypted_buffer,
787 serialized_packet.encrypted_length)); 808 serialized_packet.encrypted_length));
809 if (connection_.GetSendAlarm()->IsSet()) {
810 connection_.GetSendAlarm()->Fire();
811 }
788 return serialized_packet.entropy_hash; 812 return serialized_packet.entropy_hash;
789 } 813 }
790 814
791 QuicPacketEntropyHash ProcessFramePacketAtLevel(QuicPathId path_id, 815 QuicPacketEntropyHash ProcessFramePacketAtLevel(QuicPathId path_id,
792 QuicPacketNumber number, 816 QuicPacketNumber number,
793 QuicFrame frame, 817 QuicFrame frame,
794 EncryptionLevel level) { 818 EncryptionLevel level) {
795 QuicPacketHeader header; 819 QuicPacketHeader header;
796 header.public_header.connection_id = connection_id_; 820 header.public_header.connection_id = connection_id_;
797 header.public_header.packet_number_length = packet_number_length_; 821 header.public_header.packet_number_length = packet_number_length_;
(...skipping 29 matching lines...) Expand all
827 bool has_stop_waiting, 851 bool has_stop_waiting,
828 EncryptionLevel level) { 852 EncryptionLevel level) {
829 scoped_ptr<QuicPacket> packet(ConstructDataPacket( 853 scoped_ptr<QuicPacket> packet(ConstructDataPacket(
830 path_id, number, fec_group, entropy_flag, has_stop_waiting)); 854 path_id, number, fec_group, entropy_flag, has_stop_waiting));
831 char buffer[kMaxPacketSize]; 855 char buffer[kMaxPacketSize];
832 size_t encrypted_length = framer_.EncryptPayload( 856 size_t encrypted_length = framer_.EncryptPayload(
833 level, path_id, number, *packet, buffer, kMaxPacketSize); 857 level, path_id, number, *packet, buffer, kMaxPacketSize);
834 connection_.ProcessUdpPacket( 858 connection_.ProcessUdpPacket(
835 kSelfAddress, kPeerAddress, 859 kSelfAddress, kPeerAddress,
836 QuicEncryptedPacket(buffer, encrypted_length, false)); 860 QuicEncryptedPacket(buffer, encrypted_length, false));
861 if (connection_.GetSendAlarm()->IsSet()) {
862 connection_.GetSendAlarm()->Fire();
863 }
837 return encrypted_length; 864 return encrypted_length;
838 } 865 }
839 866
840 void ProcessClosePacket(QuicPathId path_id, 867 void ProcessClosePacket(QuicPathId path_id,
841 QuicPacketNumber number, 868 QuicPacketNumber number,
842 QuicFecGroupNumber fec_group) { 869 QuicFecGroupNumber fec_group) {
843 scoped_ptr<QuicPacket> packet(ConstructClosePacket(number, fec_group)); 870 scoped_ptr<QuicPacket> packet(ConstructClosePacket(number, fec_group));
844 char buffer[kMaxPacketSize]; 871 char buffer[kMaxPacketSize];
845 size_t encrypted_length = framer_.EncryptPayload( 872 size_t encrypted_length = framer_.EncryptPayload(
846 ENCRYPTION_NONE, path_id, number, *packet, buffer, kMaxPacketSize); 873 ENCRYPTION_NONE, path_id, number, *packet, buffer, kMaxPacketSize);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 966
940 scoped_ptr<QuicPacket> fec_packet( 967 scoped_ptr<QuicPacket> fec_packet(
941 framer_.BuildFecPacket(header, data_packet->FecProtectedData())); 968 framer_.BuildFecPacket(header, data_packet->FecProtectedData()));
942 char buffer[kMaxPacketSize]; 969 char buffer[kMaxPacketSize];
943 size_t encrypted_length = framer_.EncryptPayload( 970 size_t encrypted_length = framer_.EncryptPayload(
944 level, path_id, number, *fec_packet, buffer, kMaxPacketSize); 971 level, path_id, number, *fec_packet, buffer, kMaxPacketSize);
945 972
946 connection_.ProcessUdpPacket( 973 connection_.ProcessUdpPacket(
947 kSelfAddress, kPeerAddress, 974 kSelfAddress, kPeerAddress,
948 QuicEncryptedPacket(buffer, encrypted_length, false)); 975 QuicEncryptedPacket(buffer, encrypted_length, false));
976 if (connection_.GetSendAlarm()->IsSet()) {
977 connection_.GetSendAlarm()->Fire();
978 }
949 return encrypted_length; 979 return encrypted_length;
950 } 980 }
951 981
952 QuicByteCount SendStreamDataToPeer(QuicStreamId id, 982 QuicByteCount SendStreamDataToPeer(QuicStreamId id,
953 StringPiece data, 983 StringPiece data,
954 QuicStreamOffset offset, 984 QuicStreamOffset offset,
955 bool fin, 985 bool fin,
956 QuicPacketNumber* last_packet) { 986 QuicPacketNumber* last_packet) {
957 QuicByteCount packet_size; 987 QuicByteCount packet_size;
958 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 988 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
(...skipping 4668 matching lines...) Expand 10 before | Expand all | Expand 10 after
5627 // result in multiple attempts to close the connection - it will be marked as 5657 // result in multiple attempts to close the connection - it will be marked as
5628 // disconnected after the first call. 5658 // disconnected after the first call.
5629 EXPECT_CALL(visitor_, OnConnectionClosed(_, _)).Times(1); 5659 EXPECT_CALL(visitor_, OnConnectionClosed(_, _)).Times(1);
5630 connection_.SendConnectionCloseWithDetails(QUIC_NO_ERROR, "no reason"); 5660 connection_.SendConnectionCloseWithDetails(QUIC_NO_ERROR, "no reason");
5631 connection_.SendConnectionCloseWithDetails(QUIC_NO_ERROR, "no reason"); 5661 connection_.SendConnectionCloseWithDetails(QUIC_NO_ERROR, "no reason");
5632 } 5662 }
5633 5663
5634 } // namespace 5664 } // namespace
5635 } // namespace test 5665 } // namespace test
5636 } // namespace net 5666 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection.cc ('k') | net/quic/quic_flags.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698