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/core/quic_connection.h" | 5 #include "net/quic/core/quic_connection.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <memory> | 8 #include <memory> |
9 #include <ostream> | 9 #include <ostream> |
10 #include <utility> | 10 #include <utility> |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 using testing::_; | 57 using testing::_; |
58 | 58 |
59 namespace net { | 59 namespace net { |
60 namespace test { | 60 namespace test { |
61 namespace { | 61 namespace { |
62 | 62 |
63 const char data1[] = "foo"; | 63 const char data1[] = "foo"; |
64 const char data2[] = "bar"; | 64 const char data2[] = "bar"; |
65 | 65 |
66 const bool kFin = true; | 66 const bool kFin = true; |
67 const bool kEntropyFlag = true; | |
68 const bool kHasStopWaiting = true; | 67 const bool kHasStopWaiting = true; |
69 | 68 |
70 const QuicPacketEntropyHash kTestEntropyHash = 76; | |
71 | |
72 const int kDefaultRetransmissionTimeMs = 500; | 69 const int kDefaultRetransmissionTimeMs = 500; |
73 | 70 |
74 const IPEndPoint kPeerAddress = IPEndPoint(Loopback6(), /*port=*/12345); | 71 const IPEndPoint kPeerAddress = IPEndPoint(Loopback6(), /*port=*/12345); |
75 const IPEndPoint kSelfAddress = IPEndPoint(Loopback6(), /*port=*/443); | 72 const IPEndPoint kSelfAddress = IPEndPoint(Loopback6(), /*port=*/443); |
76 | 73 |
77 Perspective InvertPerspective(Perspective perspective) { | 74 Perspective InvertPerspective(Perspective perspective) { |
78 return perspective == Perspective::IS_CLIENT ? Perspective::IS_SERVER | 75 return perspective == Perspective::IS_CLIENT ? Perspective::IS_SERVER |
79 : Perspective::IS_CLIENT; | 76 : Perspective::IS_CLIENT; |
80 } | 77 } |
81 | 78 |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 | 485 |
489 void SetLossAlgorithm(QuicPathId path_id, | 486 void SetLossAlgorithm(QuicPathId path_id, |
490 LossDetectionInterface* loss_algorithm) { | 487 LossDetectionInterface* loss_algorithm) { |
491 QuicConnectionPeer::SetLossAlgorithm(this, path_id, loss_algorithm); | 488 QuicConnectionPeer::SetLossAlgorithm(this, path_id, loss_algorithm); |
492 } | 489 } |
493 | 490 |
494 void SendPacket(EncryptionLevel level, | 491 void SendPacket(EncryptionLevel level, |
495 QuicPathId path_id, | 492 QuicPathId path_id, |
496 QuicPacketNumber packet_number, | 493 QuicPacketNumber packet_number, |
497 QuicPacket* packet, | 494 QuicPacket* packet, |
498 QuicPacketEntropyHash entropy_hash, | |
499 HasRetransmittableData retransmittable, | 495 HasRetransmittableData retransmittable, |
500 bool has_ack, | 496 bool has_ack, |
501 bool has_pending_frames) { | 497 bool has_pending_frames) { |
502 char buffer[kMaxPacketSize]; | 498 char buffer[kMaxPacketSize]; |
503 size_t encrypted_length = | 499 size_t encrypted_length = |
504 QuicConnectionPeer::GetFramer(this)->EncryptPayload( | 500 QuicConnectionPeer::GetFramer(this)->EncryptPayload( |
505 ENCRYPTION_NONE, path_id, packet_number, *packet, buffer, | 501 ENCRYPTION_NONE, path_id, packet_number, *packet, buffer, |
506 kMaxPacketSize); | 502 kMaxPacketSize); |
507 delete packet; | 503 delete packet; |
508 SerializedPacket serialized_packet( | 504 SerializedPacket serialized_packet( |
509 kDefaultPathId, packet_number, PACKET_6BYTE_PACKET_NUMBER, buffer, | 505 kDefaultPathId, packet_number, PACKET_6BYTE_PACKET_NUMBER, buffer, |
510 encrypted_length, entropy_hash, has_ack, has_pending_frames); | 506 encrypted_length, has_ack, has_pending_frames); |
511 if (retransmittable == HAS_RETRANSMITTABLE_DATA) { | 507 if (retransmittable == HAS_RETRANSMITTABLE_DATA) { |
512 serialized_packet.retransmittable_frames.push_back( | 508 serialized_packet.retransmittable_frames.push_back( |
513 QuicFrame(new QuicStreamFrame())); | 509 QuicFrame(new QuicStreamFrame())); |
514 } | 510 } |
515 OnSerializedPacket(&serialized_packet); | 511 OnSerializedPacket(&serialized_packet); |
516 } | 512 } |
517 | 513 |
518 QuicConsumedData SendStreamDataWithString( | 514 QuicConsumedData SendStreamDataWithString( |
519 QuicStreamId id, | 515 QuicStreamId id, |
520 StringPiece data, | 516 StringPiece data, |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 Perspective::IS_CLIENT), | 681 Perspective::IS_CLIENT), |
686 send_algorithm_(new StrictMock<MockSendAlgorithm>), | 682 send_algorithm_(new StrictMock<MockSendAlgorithm>), |
687 loss_algorithm_(new MockLossAlgorithm()), | 683 loss_algorithm_(new MockLossAlgorithm()), |
688 helper_(new TestConnectionHelper(&clock_, &random_generator_)), | 684 helper_(new TestConnectionHelper(&clock_, &random_generator_)), |
689 alarm_factory_(new TestAlarmFactory()), | 685 alarm_factory_(new TestAlarmFactory()), |
690 peer_framer_(SupportedVersions(version()), | 686 peer_framer_(SupportedVersions(version()), |
691 QuicTime::Zero(), | 687 QuicTime::Zero(), |
692 Perspective::IS_SERVER), | 688 Perspective::IS_SERVER), |
693 peer_creator_(connection_id_, | 689 peer_creator_(connection_id_, |
694 &peer_framer_, | 690 &peer_framer_, |
695 &random_generator_, | |
696 &buffer_allocator_, | 691 &buffer_allocator_, |
697 /*delegate=*/nullptr), | 692 /*delegate=*/nullptr), |
698 writer_(new TestPacketWriter(version(), &clock_)), | 693 writer_(new TestPacketWriter(version(), &clock_)), |
699 connection_(connection_id_, | 694 connection_(connection_id_, |
700 kPeerAddress, | 695 kPeerAddress, |
701 helper_.get(), | 696 helper_.get(), |
702 alarm_factory_.get(), | 697 alarm_factory_.get(), |
703 writer_.get(), | 698 writer_.get(), |
704 Perspective::IS_CLIENT, | 699 Perspective::IS_CLIENT, |
705 version()), | 700 version()), |
706 creator_(QuicConnectionPeer::GetPacketCreator(&connection_)), | 701 creator_(QuicConnectionPeer::GetPacketCreator(&connection_)), |
707 generator_(QuicConnectionPeer::GetPacketGenerator(&connection_)), | 702 generator_(QuicConnectionPeer::GetPacketGenerator(&connection_)), |
708 manager_(QuicConnectionPeer::GetSentPacketManager(&connection_, | 703 manager_(QuicConnectionPeer::GetSentPacketManager(&connection_, |
709 kDefaultPathId)), | 704 kDefaultPathId)), |
710 frame1_(1, false, 0, StringPiece(data1)), | 705 frame1_(1, false, 0, StringPiece(data1)), |
711 frame2_(1, false, 3, StringPiece(data2)), | 706 frame2_(1, false, 3, StringPiece(data2)), |
712 packet_number_length_(PACKET_6BYTE_PACKET_NUMBER), | 707 packet_number_length_(PACKET_6BYTE_PACKET_NUMBER), |
713 connection_id_length_(PACKET_8BYTE_CONNECTION_ID) { | 708 connection_id_length_(PACKET_8BYTE_CONNECTION_ID) { |
714 connection_.set_defer_send_in_response_to_packets(GetParam().ack_response == | 709 connection_.set_defer_send_in_response_to_packets(GetParam().ack_response == |
715 AckResponse::kDefer); | 710 AckResponse::kDefer); |
716 connection_.set_visitor(&visitor_); | 711 connection_.set_visitor(&visitor_); |
717 connection_.SetSendAlgorithm(kDefaultPathId, send_algorithm_); | 712 connection_.SetSendAlgorithm(kDefaultPathId, send_algorithm_); |
718 connection_.SetLossAlgorithm(kDefaultPathId, loss_algorithm_.get()); | 713 connection_.SetLossAlgorithm(kDefaultPathId, loss_algorithm_.get()); |
719 framer_.set_received_entropy_calculator(&entropy_calculator_); | |
720 peer_framer_.set_received_entropy_calculator(&peer_entropy_calculator_); | |
721 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _)) | 714 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _)) |
722 .WillRepeatedly(Return(QuicTime::Delta::Zero())); | 715 .WillRepeatedly(Return(QuicTime::Delta::Zero())); |
723 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 716 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
724 .Times(AnyNumber()); | 717 .Times(AnyNumber()); |
725 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) | 718 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) |
726 .WillRepeatedly(Return(kDefaultTCPMSS)); | 719 .WillRepeatedly(Return(kDefaultTCPMSS)); |
727 EXPECT_CALL(*send_algorithm_, PacingRate(_)) | 720 EXPECT_CALL(*send_algorithm_, PacingRate(_)) |
728 .WillRepeatedly(Return(QuicBandwidth::Zero())); | 721 .WillRepeatedly(Return(QuicBandwidth::Zero())); |
729 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 722 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
730 .WillByDefault(Return(true)); | 723 .WillByDefault(Return(true)); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
767 if (writer_->stop_waiting_frames().empty()) { | 760 if (writer_->stop_waiting_frames().empty()) { |
768 return 0; | 761 return 0; |
769 } | 762 } |
770 return writer_->stop_waiting_frames()[0].least_unacked; | 763 return writer_->stop_waiting_frames()[0].least_unacked; |
771 } | 764 } |
772 | 765 |
773 void use_tagging_decrypter() { writer_->use_tagging_decrypter(); } | 766 void use_tagging_decrypter() { writer_->use_tagging_decrypter(); } |
774 | 767 |
775 void ProcessPacket(QuicPathId path_id, QuicPacketNumber number) { | 768 void ProcessPacket(QuicPathId path_id, QuicPacketNumber number) { |
776 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 769 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
777 ProcessDataPacket(path_id, number, !kEntropyFlag); | 770 ProcessDataPacket(path_id, number); |
778 if (connection_.GetSendAlarm()->IsSet()) { | 771 if (connection_.GetSendAlarm()->IsSet()) { |
779 connection_.GetSendAlarm()->Fire(); | 772 connection_.GetSendAlarm()->Fire(); |
780 } | 773 } |
781 } | 774 } |
782 | 775 |
783 QuicPacketEntropyHash ProcessFramePacket(QuicFrame frame) { | 776 void ProcessFramePacket(QuicFrame frame) { |
784 return ProcessFramePacketWithAddresses(frame, kSelfAddress, kPeerAddress); | 777 ProcessFramePacketWithAddresses(frame, kSelfAddress, kPeerAddress); |
785 } | 778 } |
786 | 779 |
787 QuicPacketEntropyHash ProcessFramePacketWithAddresses( | 780 void ProcessFramePacketWithAddresses(QuicFrame frame, |
788 QuicFrame frame, | 781 IPEndPoint self_address, |
789 IPEndPoint self_address, | 782 IPEndPoint peer_address) { |
790 IPEndPoint peer_address) { | |
791 QuicFrames frames; | 783 QuicFrames frames; |
792 frames.push_back(QuicFrame(frame)); | 784 frames.push_back(QuicFrame(frame)); |
793 QuicPacketCreatorPeer::SetSendVersionInPacket( | 785 QuicPacketCreatorPeer::SetSendVersionInPacket( |
794 &peer_creator_, connection_.perspective() == Perspective::IS_SERVER); | 786 &peer_creator_, connection_.perspective() == Perspective::IS_SERVER); |
795 | 787 |
796 char buffer[kMaxPacketSize]; | 788 char buffer[kMaxPacketSize]; |
797 SerializedPacket serialized_packet = | 789 SerializedPacket serialized_packet = |
798 QuicPacketCreatorPeer::SerializeAllFrames(&peer_creator_, frames, | 790 QuicPacketCreatorPeer::SerializeAllFrames(&peer_creator_, frames, |
799 buffer, kMaxPacketSize); | 791 buffer, kMaxPacketSize); |
800 connection_.ProcessUdpPacket( | 792 connection_.ProcessUdpPacket( |
801 self_address, peer_address, | 793 self_address, peer_address, |
802 QuicReceivedPacket(serialized_packet.encrypted_buffer, | 794 QuicReceivedPacket(serialized_packet.encrypted_buffer, |
803 serialized_packet.encrypted_length, clock_.Now())); | 795 serialized_packet.encrypted_length, clock_.Now())); |
804 if (connection_.GetSendAlarm()->IsSet()) { | 796 if (connection_.GetSendAlarm()->IsSet()) { |
805 connection_.GetSendAlarm()->Fire(); | 797 connection_.GetSendAlarm()->Fire(); |
806 } | 798 } |
807 return serialized_packet.entropy_hash; | |
808 } | 799 } |
809 | 800 |
810 // Bypassing the packet creator is unrealistic, but allows us to process | 801 // Bypassing the packet creator is unrealistic, but allows us to process |
811 // packets the QuicPacketCreator won't allow us to create. | 802 // packets the QuicPacketCreator won't allow us to create. |
812 void ForceProcessFramePacket(QuicFrame frame) { | 803 void ForceProcessFramePacket(QuicFrame frame) { |
813 QuicFrames frames; | 804 QuicFrames frames; |
814 frames.push_back(QuicFrame(frame)); | 805 frames.push_back(QuicFrame(frame)); |
815 QuicPacketCreatorPeer::SetSendVersionInPacket( | 806 QuicPacketCreatorPeer::SetSendVersionInPacket( |
816 &peer_creator_, connection_.perspective() == Perspective::IS_SERVER); | 807 &peer_creator_, connection_.perspective() == Perspective::IS_SERVER); |
817 QuicPacketHeader header; | 808 QuicPacketHeader header; |
818 QuicPacketCreatorPeer::FillPacketHeader(&peer_creator_, &header); | 809 QuicPacketCreatorPeer::FillPacketHeader(&peer_creator_, &header); |
819 char encrypted_buffer[kMaxPacketSize]; | 810 char encrypted_buffer[kMaxPacketSize]; |
820 size_t length = peer_framer_.BuildDataPacket( | 811 size_t length = peer_framer_.BuildDataPacket( |
821 header, frames, encrypted_buffer, kMaxPacketSize); | 812 header, frames, encrypted_buffer, kMaxPacketSize); |
822 DCHECK_GT(length, 0u); | 813 DCHECK_GT(length, 0u); |
823 | 814 |
824 const size_t encrypted_length = peer_framer_.EncryptInPlace( | 815 const size_t encrypted_length = peer_framer_.EncryptInPlace( |
825 ENCRYPTION_NONE, kDefaultPathId, header.packet_number, | 816 ENCRYPTION_NONE, kDefaultPathId, header.packet_number, |
826 GetStartOfEncryptedData(peer_framer_.version(), header), length, | 817 GetStartOfEncryptedData(peer_framer_.version(), header), length, |
827 kMaxPacketSize, encrypted_buffer); | 818 kMaxPacketSize, encrypted_buffer); |
828 DCHECK_GT(encrypted_length, 0u); | 819 DCHECK_GT(encrypted_length, 0u); |
829 | 820 |
830 connection_.ProcessUdpPacket( | 821 connection_.ProcessUdpPacket( |
831 kSelfAddress, kPeerAddress, | 822 kSelfAddress, kPeerAddress, |
832 QuicReceivedPacket(encrypted_buffer, encrypted_length, clock_.Now())); | 823 QuicReceivedPacket(encrypted_buffer, encrypted_length, clock_.Now())); |
833 } | 824 } |
834 | 825 |
835 QuicPacketEntropyHash ProcessFramePacketAtLevel(QuicPathId path_id, | 826 size_t ProcessFramePacketAtLevel(QuicPathId path_id, |
836 QuicPacketNumber number, | 827 QuicPacketNumber number, |
837 QuicFrame frame, | 828 QuicFrame frame, |
838 EncryptionLevel level) { | 829 EncryptionLevel level) { |
839 QuicPacketHeader header; | 830 QuicPacketHeader header; |
840 header.public_header.connection_id = connection_id_; | 831 header.public_header.connection_id = connection_id_; |
841 header.public_header.packet_number_length = packet_number_length_; | 832 header.public_header.packet_number_length = packet_number_length_; |
842 header.public_header.connection_id_length = connection_id_length_; | 833 header.public_header.connection_id_length = connection_id_length_; |
843 header.public_header.multipath_flag = path_id != kDefaultPathId; | 834 header.public_header.multipath_flag = path_id != kDefaultPathId; |
844 header.path_id = path_id; | 835 header.path_id = path_id; |
845 header.packet_number = number; | 836 header.packet_number = number; |
846 QuicFrames frames; | 837 QuicFrames frames; |
847 frames.push_back(frame); | 838 frames.push_back(frame); |
848 std::unique_ptr<QuicPacket> packet(ConstructPacket(header, frames)); | 839 std::unique_ptr<QuicPacket> packet(ConstructPacket(header, frames)); |
849 | 840 |
850 char buffer[kMaxPacketSize]; | 841 char buffer[kMaxPacketSize]; |
851 size_t encrypted_length = framer_.EncryptPayload( | 842 size_t encrypted_length = framer_.EncryptPayload( |
852 level, path_id, number, *packet, buffer, kMaxPacketSize); | 843 level, path_id, number, *packet, buffer, kMaxPacketSize); |
853 connection_.ProcessUdpPacket( | 844 connection_.ProcessUdpPacket( |
854 kSelfAddress, kPeerAddress, | 845 kSelfAddress, kPeerAddress, |
855 QuicReceivedPacket(buffer, encrypted_length, QuicTime::Zero(), false)); | 846 QuicReceivedPacket(buffer, encrypted_length, QuicTime::Zero(), false)); |
856 return base::checked_cast<QuicPacketEntropyHash>(encrypted_length); | 847 return encrypted_length; |
857 } | 848 } |
858 | 849 |
859 size_t ProcessDataPacket(QuicPathId path_id, | 850 size_t ProcessDataPacket(QuicPathId path_id, QuicPacketNumber number) { |
860 QuicPacketNumber number, | 851 return ProcessDataPacketAtLevel(path_id, number, false, ENCRYPTION_NONE); |
861 bool entropy_flag) { | |
862 return ProcessDataPacketAtLevel(path_id, number, entropy_flag, false, | |
863 ENCRYPTION_NONE); | |
864 } | 852 } |
865 | 853 |
866 size_t ProcessDataPacketAtLevel(QuicPathId path_id, | 854 size_t ProcessDataPacketAtLevel(QuicPathId path_id, |
867 QuicPacketNumber number, | 855 QuicPacketNumber number, |
868 bool entropy_flag, | |
869 bool has_stop_waiting, | 856 bool has_stop_waiting, |
870 EncryptionLevel level) { | 857 EncryptionLevel level) { |
871 std::unique_ptr<QuicPacket> packet( | 858 std::unique_ptr<QuicPacket> packet( |
872 ConstructDataPacket(path_id, number, entropy_flag, has_stop_waiting)); | 859 ConstructDataPacket(path_id, number, has_stop_waiting)); |
873 char buffer[kMaxPacketSize]; | 860 char buffer[kMaxPacketSize]; |
874 size_t encrypted_length = framer_.EncryptPayload( | 861 size_t encrypted_length = framer_.EncryptPayload( |
875 level, path_id, number, *packet, buffer, kMaxPacketSize); | 862 level, path_id, number, *packet, buffer, kMaxPacketSize); |
876 connection_.ProcessUdpPacket( | 863 connection_.ProcessUdpPacket( |
877 kSelfAddress, kPeerAddress, | 864 kSelfAddress, kPeerAddress, |
878 QuicReceivedPacket(buffer, encrypted_length, clock_.Now(), false)); | 865 QuicReceivedPacket(buffer, encrypted_length, clock_.Now(), false)); |
879 if (connection_.GetSendAlarm()->IsSet()) { | 866 if (connection_.GetSendAlarm()->IsSet()) { |
880 connection_.GetSendAlarm()->Fire(); | 867 connection_.GetSendAlarm()->Fire(); |
881 } | 868 } |
882 return encrypted_length; | 869 return encrypted_length; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
914 connection_.SendAck(); | 901 connection_.SendAck(); |
915 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 902 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
916 .Times(AnyNumber()); | 903 .Times(AnyNumber()); |
917 } | 904 } |
918 | 905 |
919 void ProcessAckPacket(QuicPacketNumber packet_number, QuicAckFrame* frame) { | 906 void ProcessAckPacket(QuicPacketNumber packet_number, QuicAckFrame* frame) { |
920 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, packet_number - 1); | 907 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, packet_number - 1); |
921 ProcessFramePacket(QuicFrame(frame)); | 908 ProcessFramePacket(QuicFrame(frame)); |
922 } | 909 } |
923 | 910 |
924 QuicPacketEntropyHash ProcessAckPacket(QuicAckFrame* frame) { | 911 void ProcessAckPacket(QuicAckFrame* frame) { |
925 return ProcessFramePacket(QuicFrame(frame)); | 912 ProcessFramePacket(QuicFrame(frame)); |
926 } | 913 } |
927 | 914 |
928 QuicPacketEntropyHash ProcessStopWaitingPacket(QuicStopWaitingFrame* frame) { | 915 void ProcessStopWaitingPacket(QuicStopWaitingFrame* frame) { |
929 return ProcessFramePacket(QuicFrame(frame)); | 916 ProcessFramePacket(QuicFrame(frame)); |
930 } | 917 } |
931 | 918 |
932 QuicPacketEntropyHash ProcessStopWaitingPacketAtLevel( | 919 size_t ProcessStopWaitingPacketAtLevel(QuicPathId path_id, |
933 QuicPathId path_id, | 920 QuicPacketNumber number, |
934 QuicPacketNumber number, | 921 QuicStopWaitingFrame* frame, |
935 QuicStopWaitingFrame* frame, | 922 EncryptionLevel level) { |
936 EncryptionLevel level) { | |
937 return ProcessFramePacketAtLevel(path_id, number, QuicFrame(frame), | 923 return ProcessFramePacketAtLevel(path_id, number, QuicFrame(frame), |
938 ENCRYPTION_INITIAL); | 924 ENCRYPTION_INITIAL); |
939 } | 925 } |
940 | 926 |
941 QuicPacketEntropyHash ProcessGoAwayPacket(QuicGoAwayFrame* frame) { | 927 void ProcessGoAwayPacket(QuicGoAwayFrame* frame) { |
942 return ProcessFramePacket(QuicFrame(frame)); | 928 ProcessFramePacket(QuicFrame(frame)); |
943 } | 929 } |
944 | 930 |
945 QuicPacketEntropyHash ProcessPathClosePacket(QuicPathCloseFrame* frame) { | 931 void ProcessPathClosePacket(QuicPathCloseFrame* frame) { |
946 return ProcessFramePacket(QuicFrame(frame)); | 932 ProcessFramePacket(QuicFrame(frame)); |
947 } | 933 } |
948 | 934 |
949 bool IsMissing(QuicPacketNumber number) { | 935 bool IsMissing(QuicPacketNumber number) { |
950 return IsAwaitingPacket(*outgoing_ack(), number, 0); | 936 return IsAwaitingPacket(*outgoing_ack(), number, 0); |
951 } | 937 } |
952 | 938 |
953 QuicPacket* ConstructPacket(QuicPacketHeader header, QuicFrames frames) { | 939 QuicPacket* ConstructPacket(QuicPacketHeader header, QuicFrames frames) { |
954 QuicPacket* packet = BuildUnsizedDataPacket(&peer_framer_, header, frames); | 940 QuicPacket* packet = BuildUnsizedDataPacket(&peer_framer_, header, frames); |
955 EXPECT_NE(nullptr, packet); | 941 EXPECT_NE(nullptr, packet); |
956 return packet; | 942 return packet; |
957 } | 943 } |
958 | 944 |
959 QuicPacket* ConstructDataPacket(QuicPathId path_id, | 945 QuicPacket* ConstructDataPacket(QuicPathId path_id, |
960 QuicPacketNumber number, | 946 QuicPacketNumber number, |
961 bool entropy_flag, | |
962 bool has_stop_waiting) { | 947 bool has_stop_waiting) { |
963 QuicPacketHeader header; | 948 QuicPacketHeader header; |
964 header.public_header.connection_id = connection_id_; | 949 header.public_header.connection_id = connection_id_; |
965 header.public_header.packet_number_length = packet_number_length_; | 950 header.public_header.packet_number_length = packet_number_length_; |
966 header.public_header.connection_id_length = connection_id_length_; | 951 header.public_header.connection_id_length = connection_id_length_; |
967 header.public_header.multipath_flag = path_id != kDefaultPathId; | 952 header.public_header.multipath_flag = path_id != kDefaultPathId; |
968 header.entropy_flag = entropy_flag; | |
969 header.path_id = path_id; | 953 header.path_id = path_id; |
970 header.packet_number = number; | 954 header.packet_number = number; |
971 | 955 |
972 QuicFrames frames; | 956 QuicFrames frames; |
973 frames.push_back(QuicFrame(&frame1_)); | 957 frames.push_back(QuicFrame(&frame1_)); |
974 if (has_stop_waiting) { | 958 if (has_stop_waiting) { |
975 frames.push_back(QuicFrame(&stop_waiting_)); | 959 frames.push_back(QuicFrame(&stop_waiting_)); |
976 } | 960 } |
977 return ConstructPacket(header, frames); | 961 return ConstructPacket(header, frames); |
978 } | 962 } |
(...skipping 15 matching lines...) Expand all Loading... |
994 return QuicTime::Delta::FromMilliseconds(kDefaultRetransmissionTimeMs); | 978 return QuicTime::Delta::FromMilliseconds(kDefaultRetransmissionTimeMs); |
995 } | 979 } |
996 | 980 |
997 QuicTime::Delta DefaultDelayedAckTime() { | 981 QuicTime::Delta DefaultDelayedAckTime() { |
998 return QuicTime::Delta::FromMilliseconds(kMaxDelayedAckTimeMs); | 982 return QuicTime::Delta::FromMilliseconds(kMaxDelayedAckTimeMs); |
999 } | 983 } |
1000 | 984 |
1001 // Initialize a frame acknowledging all packets up to largest_observed. | 985 // Initialize a frame acknowledging all packets up to largest_observed. |
1002 const QuicAckFrame InitAckFrame(QuicPacketNumber largest_observed) { | 986 const QuicAckFrame InitAckFrame(QuicPacketNumber largest_observed) { |
1003 QuicAckFrame frame(MakeAckFrame(largest_observed)); | 987 QuicAckFrame frame(MakeAckFrame(largest_observed)); |
1004 if (GetParam().version <= QUIC_VERSION_33) { | 988 if (largest_observed > 0) { |
1005 if (largest_observed > 0) { | 989 frame.packets.Add(1, largest_observed + 1); |
1006 frame.entropy_hash = QuicConnectionPeer::GetSentEntropyHash( | |
1007 &connection_, largest_observed); | |
1008 } | |
1009 } else { | |
1010 frame.missing = false; | |
1011 if (largest_observed > 0) { | |
1012 frame.packets.Add(1, largest_observed + 1); | |
1013 } | |
1014 } | 990 } |
1015 return frame; | 991 return frame; |
1016 } | 992 } |
1017 | 993 |
1018 const QuicStopWaitingFrame InitStopWaitingFrame( | 994 const QuicStopWaitingFrame InitStopWaitingFrame( |
1019 QuicPacketNumber least_unacked) { | 995 QuicPacketNumber least_unacked) { |
1020 QuicStopWaitingFrame frame; | 996 QuicStopWaitingFrame frame; |
1021 frame.least_unacked = least_unacked; | 997 frame.least_unacked = least_unacked; |
1022 return frame; | 998 return frame; |
1023 } | 999 } |
1024 | 1000 |
1025 // Explicitly nack a packet. | 1001 // Explicitly nack a packet. |
1026 void NackPacket(QuicPacketNumber missing, QuicAckFrame* frame) { | 1002 void NackPacket(QuicPacketNumber missing, QuicAckFrame* frame) { |
1027 if (frame->missing) { | 1003 frame->packets.Remove(missing); |
1028 frame->packets.Add(missing); | |
1029 frame->entropy_hash ^= | |
1030 QuicConnectionPeer::PacketEntropy(&connection_, missing); | |
1031 } else { | |
1032 frame->packets.Remove(missing); | |
1033 } | |
1034 } | 1004 } |
1035 | 1005 |
1036 // Undo nacking a packet within the frame. | 1006 // Undo nacking a packet within the frame. |
1037 void AckPacket(QuicPacketNumber arrived, QuicAckFrame* frame) { | 1007 void AckPacket(QuicPacketNumber arrived, QuicAckFrame* frame) { |
1038 if (frame->missing) { | 1008 EXPECT_FALSE(frame->packets.Contains(arrived)); |
1039 EXPECT_TRUE(frame->packets.Contains(arrived)); | 1009 frame->packets.Add(arrived); |
1040 frame->packets.Remove(arrived); | |
1041 frame->entropy_hash ^= | |
1042 QuicConnectionPeer::PacketEntropy(&connection_, arrived); | |
1043 } else { | |
1044 EXPECT_FALSE(frame->packets.Contains(arrived)); | |
1045 frame->packets.Add(arrived); | |
1046 } | |
1047 } | 1010 } |
1048 | 1011 |
1049 void TriggerConnectionClose() { | 1012 void TriggerConnectionClose() { |
1050 // Send an erroneous packet to close the connection. | 1013 // Send an erroneous packet to close the connection. |
1051 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, _, | 1014 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, _, |
1052 ConnectionCloseSource::FROM_SELF)); | 1015 ConnectionCloseSource::FROM_SELF)); |
1053 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a | 1016 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a |
1054 // packet call to the visitor. | 1017 // packet call to the visitor. |
1055 ProcessDataPacket(kDefaultPathId, 6000, !kEntropyFlag); | 1018 ProcessDataPacket(kDefaultPathId, 6000); |
1056 EXPECT_FALSE(QuicConnectionPeer::GetConnectionClosePacket(&connection_) == | 1019 EXPECT_FALSE(QuicConnectionPeer::GetConnectionClosePacket(&connection_) == |
1057 nullptr); | 1020 nullptr); |
1058 } | 1021 } |
1059 | 1022 |
1060 void BlockOnNextWrite() { | 1023 void BlockOnNextWrite() { |
1061 writer_->BlockOnNextWrite(); | 1024 writer_->BlockOnNextWrite(); |
1062 EXPECT_CALL(visitor_, OnWriteBlocked()).Times(AtLeast(1)); | 1025 EXPECT_CALL(visitor_, OnWriteBlocked()).Times(AtLeast(1)); |
1063 } | 1026 } |
1064 | 1027 |
1065 void SimulateNextPacketTooLarge() { writer_->SimulateNextPacketTooLarge(); } | 1028 void SimulateNextPacketTooLarge() { writer_->SimulateNextPacketTooLarge(); } |
(...skipping 17 matching lines...) Expand all Loading... |
1083 void set_perspective(Perspective perspective) { | 1046 void set_perspective(Perspective perspective) { |
1084 connection_.set_perspective(perspective); | 1047 connection_.set_perspective(perspective); |
1085 QuicFramerPeer::SetPerspective(&peer_framer_, | 1048 QuicFramerPeer::SetPerspective(&peer_framer_, |
1086 InvertPerspective(perspective)); | 1049 InvertPerspective(perspective)); |
1087 } | 1050 } |
1088 | 1051 |
1089 QuicFlagSaver flags_; // Save/restore all QUIC flag values. | 1052 QuicFlagSaver flags_; // Save/restore all QUIC flag values. |
1090 | 1053 |
1091 QuicConnectionId connection_id_; | 1054 QuicConnectionId connection_id_; |
1092 QuicFramer framer_; | 1055 QuicFramer framer_; |
1093 MockEntropyCalculator entropy_calculator_; | |
1094 MockEntropyCalculator peer_entropy_calculator_; | |
1095 | 1056 |
1096 MockSendAlgorithm* send_algorithm_; | 1057 MockSendAlgorithm* send_algorithm_; |
1097 std::unique_ptr<MockLossAlgorithm> loss_algorithm_; | 1058 std::unique_ptr<MockLossAlgorithm> loss_algorithm_; |
1098 MockClock clock_; | 1059 MockClock clock_; |
1099 MockRandom random_generator_; | 1060 MockRandom random_generator_; |
1100 SimpleBufferAllocator buffer_allocator_; | 1061 SimpleBufferAllocator buffer_allocator_; |
1101 std::unique_ptr<TestConnectionHelper> helper_; | 1062 std::unique_ptr<TestConnectionHelper> helper_; |
1102 std::unique_ptr<TestAlarmFactory> alarm_factory_; | 1063 std::unique_ptr<TestAlarmFactory> alarm_factory_; |
1103 QuicFramer peer_framer_; | 1064 QuicFramer peer_framer_; |
1104 QuicPacketCreator peer_creator_; | 1065 QuicPacketCreator peer_creator_; |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1314 Perspective::IS_CLIENT, version()); | 1275 Perspective::IS_CLIENT, version()); |
1315 EXPECT_EQ(Perspective::IS_CLIENT, connection.perspective()); | 1276 EXPECT_EQ(Perspective::IS_CLIENT, connection.perspective()); |
1316 EXPECT_EQ(lower_max_packet_size, connection.max_packet_length()); | 1277 EXPECT_EQ(lower_max_packet_size, connection.max_packet_length()); |
1317 } | 1278 } |
1318 | 1279 |
1319 TEST_P(QuicConnectionTest, PacketsInOrder) { | 1280 TEST_P(QuicConnectionTest, PacketsInOrder) { |
1320 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1281 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
1321 | 1282 |
1322 ProcessPacket(kDefaultPathId, 1); | 1283 ProcessPacket(kDefaultPathId, 1); |
1323 EXPECT_EQ(1u, outgoing_ack()->largest_observed); | 1284 EXPECT_EQ(1u, outgoing_ack()->largest_observed); |
1324 if (outgoing_ack()->missing) { | 1285 EXPECT_EQ(1u, outgoing_ack()->packets.NumIntervals()); |
1325 EXPECT_TRUE(outgoing_ack()->packets.Empty()); | |
1326 } else { | |
1327 EXPECT_EQ(1u, outgoing_ack()->packets.NumIntervals()); | |
1328 } | |
1329 | 1286 |
1330 ProcessPacket(kDefaultPathId, 2); | 1287 ProcessPacket(kDefaultPathId, 2); |
1331 EXPECT_EQ(2u, outgoing_ack()->largest_observed); | 1288 EXPECT_EQ(2u, outgoing_ack()->largest_observed); |
1332 if (outgoing_ack()->missing) { | 1289 EXPECT_EQ(1u, outgoing_ack()->packets.NumIntervals()); |
1333 EXPECT_TRUE(outgoing_ack()->packets.Empty()); | |
1334 } else { | |
1335 EXPECT_EQ(1u, outgoing_ack()->packets.NumIntervals()); | |
1336 } | |
1337 | 1290 |
1338 ProcessPacket(kDefaultPathId, 3); | 1291 ProcessPacket(kDefaultPathId, 3); |
1339 EXPECT_EQ(3u, outgoing_ack()->largest_observed); | 1292 EXPECT_EQ(3u, outgoing_ack()->largest_observed); |
1340 if (outgoing_ack()->missing) { | 1293 EXPECT_EQ(1u, outgoing_ack()->packets.NumIntervals()); |
1341 EXPECT_TRUE(outgoing_ack()->packets.Empty()); | |
1342 } else { | |
1343 EXPECT_EQ(1u, outgoing_ack()->packets.NumIntervals()); | |
1344 } | |
1345 } | 1294 } |
1346 | 1295 |
1347 TEST_P(QuicConnectionTest, PacketsOutOfOrder) { | 1296 TEST_P(QuicConnectionTest, PacketsOutOfOrder) { |
1348 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1297 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
1349 | 1298 |
1350 ProcessPacket(kDefaultPathId, 3); | 1299 ProcessPacket(kDefaultPathId, 3); |
1351 EXPECT_EQ(3u, outgoing_ack()->largest_observed); | 1300 EXPECT_EQ(3u, outgoing_ack()->largest_observed); |
1352 EXPECT_TRUE(IsMissing(2)); | 1301 EXPECT_TRUE(IsMissing(2)); |
1353 EXPECT_TRUE(IsMissing(1)); | 1302 EXPECT_TRUE(IsMissing(1)); |
1354 | 1303 |
(...skipping 11 matching lines...) Expand all Loading... |
1366 TEST_P(QuicConnectionTest, DuplicatePacket) { | 1315 TEST_P(QuicConnectionTest, DuplicatePacket) { |
1367 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1316 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
1368 | 1317 |
1369 ProcessPacket(kDefaultPathId, 3); | 1318 ProcessPacket(kDefaultPathId, 3); |
1370 EXPECT_EQ(3u, outgoing_ack()->largest_observed); | 1319 EXPECT_EQ(3u, outgoing_ack()->largest_observed); |
1371 EXPECT_TRUE(IsMissing(2)); | 1320 EXPECT_TRUE(IsMissing(2)); |
1372 EXPECT_TRUE(IsMissing(1)); | 1321 EXPECT_TRUE(IsMissing(1)); |
1373 | 1322 |
1374 // Send packet 3 again, but do not set the expectation that | 1323 // Send packet 3 again, but do not set the expectation that |
1375 // the visitor OnStreamFrame() will be called. | 1324 // the visitor OnStreamFrame() will be called. |
1376 ProcessDataPacket(kDefaultPathId, 3, !kEntropyFlag); | 1325 ProcessDataPacket(kDefaultPathId, 3); |
1377 EXPECT_EQ(3u, outgoing_ack()->largest_observed); | 1326 EXPECT_EQ(3u, outgoing_ack()->largest_observed); |
1378 EXPECT_TRUE(IsMissing(2)); | 1327 EXPECT_TRUE(IsMissing(2)); |
1379 EXPECT_TRUE(IsMissing(1)); | 1328 EXPECT_TRUE(IsMissing(1)); |
1380 } | 1329 } |
1381 | 1330 |
1382 TEST_P(QuicConnectionTest, PacketsOutOfOrderWithAdditionsAndLeastAwaiting) { | 1331 TEST_P(QuicConnectionTest, PacketsOutOfOrderWithAdditionsAndLeastAwaiting) { |
1383 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1332 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
1384 | 1333 |
1385 ProcessPacket(kDefaultPathId, 3); | 1334 ProcessPacket(kDefaultPathId, 3); |
1386 EXPECT_EQ(3u, outgoing_ack()->largest_observed); | 1335 EXPECT_EQ(3u, outgoing_ack()->largest_observed); |
(...skipping 20 matching lines...) Expand all Loading... |
1407 // Force an ack to be sent. | 1356 // Force an ack to be sent. |
1408 SendAckPacketToPeer(); | 1357 SendAckPacketToPeer(); |
1409 EXPECT_TRUE(IsMissing(4)); | 1358 EXPECT_TRUE(IsMissing(4)); |
1410 } | 1359 } |
1411 | 1360 |
1412 TEST_P(QuicConnectionTest, RejectPacketTooFarOut) { | 1361 TEST_P(QuicConnectionTest, RejectPacketTooFarOut) { |
1413 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, _, | 1362 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, _, |
1414 ConnectionCloseSource::FROM_SELF)); | 1363 ConnectionCloseSource::FROM_SELF)); |
1415 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a | 1364 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a |
1416 // packet call to the visitor. | 1365 // packet call to the visitor. |
1417 ProcessDataPacket(kDefaultPathId, 6000, !kEntropyFlag); | 1366 ProcessDataPacket(kDefaultPathId, 6000); |
1418 EXPECT_FALSE(QuicConnectionPeer::GetConnectionClosePacket(&connection_) == | 1367 EXPECT_FALSE(QuicConnectionPeer::GetConnectionClosePacket(&connection_) == |
1419 nullptr); | 1368 nullptr); |
1420 } | 1369 } |
1421 | 1370 |
1422 TEST_P(QuicConnectionTest, RejectUnencryptedStreamData) { | 1371 TEST_P(QuicConnectionTest, RejectUnencryptedStreamData) { |
1423 // Process an unencrypted packet from the non-crypto stream. | 1372 // Process an unencrypted packet from the non-crypto stream. |
1424 frame1_.stream_id = 3; | 1373 frame1_.stream_id = 3; |
1425 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1374 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
1426 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_UNENCRYPTED_STREAM_DATA, _, | 1375 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_UNENCRYPTED_STREAM_DATA, _, |
1427 ConnectionCloseSource::FROM_SELF)); | 1376 ConnectionCloseSource::FROM_SELF)); |
1428 EXPECT_QUIC_BUG(ProcessDataPacket(kDefaultPathId, 1, !kEntropyFlag), ""); | 1377 EXPECT_QUIC_BUG(ProcessDataPacket(kDefaultPathId, 1), ""); |
1429 EXPECT_FALSE(QuicConnectionPeer::GetConnectionClosePacket(&connection_) == | 1378 EXPECT_FALSE(QuicConnectionPeer::GetConnectionClosePacket(&connection_) == |
1430 nullptr); | 1379 nullptr); |
1431 const std::vector<QuicConnectionCloseFrame>& connection_close_frames = | 1380 const std::vector<QuicConnectionCloseFrame>& connection_close_frames = |
1432 writer_->connection_close_frames(); | 1381 writer_->connection_close_frames(); |
1433 EXPECT_EQ(1u, connection_close_frames.size()); | 1382 EXPECT_EQ(1u, connection_close_frames.size()); |
1434 EXPECT_EQ(QUIC_UNENCRYPTED_STREAM_DATA, | 1383 EXPECT_EQ(QUIC_UNENCRYPTED_STREAM_DATA, |
1435 connection_close_frames[0].error_code); | 1384 connection_close_frames[0].error_code); |
1436 } | 1385 } |
1437 | 1386 |
1438 TEST_P(QuicConnectionTest, TruncatedAck) { | |
1439 if (GetParam().version > QUIC_VERSION_33) { | |
1440 return; | |
1441 } | |
1442 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | |
1443 QuicPacketNumber num_packets = 256 * 2 + 1; | |
1444 for (QuicPacketNumber i = 0; i < num_packets; ++i) { | |
1445 SendStreamDataToPeer(3, "foo", i * 3, !kFin, nullptr); | |
1446 } | |
1447 | |
1448 QuicAckFrame frame = InitAckFrame(num_packets); | |
1449 // Create an ack with 256 nacks, none adjacent to one another. | |
1450 for (QuicPacketNumber i = 1; i <= 256; ++i) { | |
1451 NackPacket(i * 2, &frame); | |
1452 } | |
1453 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)); | |
1454 EXPECT_CALL(peer_entropy_calculator_, EntropyHash(511)) | |
1455 .WillOnce(Return(static_cast<QuicPacketEntropyHash>(0))); | |
1456 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); | |
1457 ProcessAckPacket(&frame); | |
1458 | |
1459 // A truncated ack will not have the true largest observed. | |
1460 EXPECT_GT(num_packets, manager_->GetLargestObserved(frame.path_id)); | |
1461 | |
1462 AckPacket(192, &frame); | |
1463 | |
1464 // Removing one missing packet allows us to ack 192 and one more range, but | |
1465 // 192 has already been declared lost, so it doesn't register as an ack. | |
1466 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)); | |
1467 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); | |
1468 ProcessAckPacket(&frame); | |
1469 EXPECT_EQ(num_packets, manager_->GetLargestObserved(frame.path_id)); | |
1470 } | |
1471 | |
1472 TEST_P(QuicConnectionTest, AckReceiptCausesAckSendBadEntropy) { | |
1473 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | |
1474 | |
1475 ProcessPacket(kDefaultPathId, 1); | |
1476 // Delay sending, then queue up an ack. | |
1477 QuicConnectionPeer::SendAck(&connection_); | |
1478 | |
1479 // Process an ack with a least unacked of the received ack. | |
1480 // This causes an ack to be sent when TimeUntilSend returns 0. | |
1481 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _)) | |
1482 .WillRepeatedly(testing::Return(QuicTime::Delta::Zero())); | |
1483 // Skip a packet and then record an ack. | |
1484 QuicAckFrame frame = InitAckFrame(0); | |
1485 ProcessAckPacket(3, &frame); | |
1486 } | |
1487 | |
1488 TEST_P(QuicConnectionTest, OutOfOrderReceiptCausesAckSend) { | 1387 TEST_P(QuicConnectionTest, OutOfOrderReceiptCausesAckSend) { |
1489 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1388 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
1490 | 1389 |
1491 ProcessPacket(kDefaultPathId, 3); | 1390 ProcessPacket(kDefaultPathId, 3); |
1492 // Should ack immediately since we have missing packets. | 1391 // Should ack immediately since we have missing packets. |
1493 EXPECT_EQ(1u, writer_->packets_write_attempts()); | 1392 EXPECT_EQ(1u, writer_->packets_write_attempts()); |
1494 | 1393 |
1495 ProcessPacket(kDefaultPathId, 2); | 1394 ProcessPacket(kDefaultPathId, 2); |
1496 // Should ack immediately since we have missing packets. | 1395 // Should ack immediately since we have missing packets. |
1497 EXPECT_EQ(2u, writer_->packets_write_attempts()); | 1396 EXPECT_EQ(2u, writer_->packets_write_attempts()); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1633 TEST_P(QuicConnectionTest, TooManySentPackets) { | 1532 TEST_P(QuicConnectionTest, TooManySentPackets) { |
1634 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1533 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
1635 | 1534 |
1636 const int num_packets = kMaxTrackedPackets + 100; | 1535 const int num_packets = kMaxTrackedPackets + 100; |
1637 for (int i = 0; i < num_packets; ++i) { | 1536 for (int i = 0; i < num_packets; ++i) { |
1638 SendStreamDataToPeer(1, "foo", 3 * i, !kFin, nullptr); | 1537 SendStreamDataToPeer(1, "foo", 3 * i, !kFin, nullptr); |
1639 } | 1538 } |
1640 | 1539 |
1641 // Ack packet 1, which leaves more than the limit outstanding. | 1540 // Ack packet 1, which leaves more than the limit outstanding. |
1642 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); | 1541 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); |
1643 if (GetParam().version <= QUIC_VERSION_33) { | |
1644 EXPECT_CALL(visitor_, | |
1645 OnConnectionClosed(QUIC_TOO_MANY_OUTSTANDING_SENT_PACKETS, _, | |
1646 ConnectionCloseSource::FROM_SELF)); | |
1647 // We're receive buffer limited, so the connection won't try to write more. | |
1648 EXPECT_CALL(visitor_, OnCanWrite()).Times(0); | |
1649 } | |
1650 | 1542 |
1651 // Nack the first packet and ack the rest, leaving a huge gap. | 1543 // Nack the first packet and ack the rest, leaving a huge gap. |
1652 QuicAckFrame frame1 = InitAckFrame(num_packets); | 1544 QuicAckFrame frame1 = InitAckFrame(num_packets); |
1653 NackPacket(1, &frame1); | 1545 NackPacket(1, &frame1); |
1654 ProcessAckPacket(&frame1); | 1546 ProcessAckPacket(&frame1); |
1655 } | 1547 } |
1656 | 1548 |
1657 TEST_P(QuicConnectionTest, TooManyReceivedPackets) { | 1549 TEST_P(QuicConnectionTest, TooManyReceivedPackets) { |
1658 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1550 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
1659 if (GetParam().version <= QUIC_VERSION_33) { | |
1660 EXPECT_CALL(visitor_, | |
1661 OnConnectionClosed(QUIC_TOO_MANY_OUTSTANDING_RECEIVED_PACKETS, | |
1662 _, ConnectionCloseSource::FROM_SELF)); | |
1663 } | |
1664 // Miss 99 of every 100 packets for 5500 packets. | 1551 // Miss 99 of every 100 packets for 5500 packets. |
1665 for (QuicPacketNumber i = 1; i < kMaxTrackedPackets + 500; i += 100) { | 1552 for (QuicPacketNumber i = 1; i < kMaxTrackedPackets + 500; i += 100) { |
1666 ProcessPacket(kDefaultPathId, i); | 1553 ProcessPacket(kDefaultPathId, i); |
1667 if (!connection_.connected()) { | 1554 if (!connection_.connected()) { |
1668 break; | 1555 break; |
1669 } | 1556 } |
1670 } | 1557 } |
1671 } | 1558 } |
1672 | 1559 |
1673 TEST_P(QuicConnectionTest, LargestObservedLower) { | 1560 TEST_P(QuicConnectionTest, LargestObservedLower) { |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1851 // Parse the last packet and ensure it's the stream frame from stream 3. | 1738 // Parse the last packet and ensure it's the stream frame from stream 3. |
1852 EXPECT_EQ(1u, writer_->frame_count()); | 1739 EXPECT_EQ(1u, writer_->frame_count()); |
1853 ASSERT_EQ(1u, writer_->stream_frames().size()); | 1740 ASSERT_EQ(1u, writer_->stream_frames().size()); |
1854 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0]->stream_id); | 1741 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0]->stream_id); |
1855 } | 1742 } |
1856 | 1743 |
1857 TEST_P(QuicConnectionTest, FramePackingAckResponse) { | 1744 TEST_P(QuicConnectionTest, FramePackingAckResponse) { |
1858 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1745 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
1859 // Process a data packet to queue up a pending ack. | 1746 // Process a data packet to queue up a pending ack. |
1860 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 1747 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
1861 ProcessDataPacket(kDefaultPathId, 1, kEntropyFlag); | 1748 ProcessDataPacket(kDefaultPathId, 1); |
1862 | 1749 |
1863 EXPECT_CALL(visitor_, OnCanWrite()) | 1750 EXPECT_CALL(visitor_, OnCanWrite()) |
1864 .WillOnce(DoAll(IgnoreResult(InvokeWithoutArgs( | 1751 .WillOnce(DoAll(IgnoreResult(InvokeWithoutArgs( |
1865 &connection_, &TestConnection::SendStreamData3)), | 1752 &connection_, &TestConnection::SendStreamData3)), |
1866 IgnoreResult(InvokeWithoutArgs( | 1753 IgnoreResult(InvokeWithoutArgs( |
1867 &connection_, &TestConnection::SendStreamData5)))); | 1754 &connection_, &TestConnection::SendStreamData5)))); |
1868 | 1755 |
1869 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 1756 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
1870 | 1757 |
1871 // Process an ack to cause the visitor's OnCanWrite to be invoked. | 1758 // Process an ack to cause the visitor's OnCanWrite to be invoked. |
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2676 QuicConfig config; | 2563 QuicConfig config; |
2677 connection_.SetFromConfig(config); | 2564 connection_.SetFromConfig(config); |
2678 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2565 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
2679 use_tagging_decrypter(); | 2566 use_tagging_decrypter(); |
2680 | 2567 |
2681 const uint8_t tag = 0x07; | 2568 const uint8_t tag = 0x07; |
2682 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 2569 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
2683 | 2570 |
2684 // Process an encrypted packet which can not yet be decrypted which should | 2571 // Process an encrypted packet which can not yet be decrypted which should |
2685 // result in the packet being buffered. | 2572 // result in the packet being buffered. |
2686 ProcessDataPacketAtLevel(kDefaultPathId, 1, kEntropyFlag, !kHasStopWaiting, | 2573 ProcessDataPacketAtLevel(kDefaultPathId, 1, !kHasStopWaiting, |
2687 ENCRYPTION_INITIAL); | 2574 ENCRYPTION_INITIAL); |
2688 | 2575 |
2689 // Transition to the new encryption state and process another encrypted packet | 2576 // Transition to the new encryption state and process another encrypted packet |
2690 // which should result in the original packet being processed. | 2577 // which should result in the original packet being processed. |
2691 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); | 2578 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); |
2692 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); | 2579 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); |
2693 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 2580 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
2694 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(2); | 2581 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(2); |
2695 ProcessDataPacketAtLevel(kDefaultPathId, 2, kEntropyFlag, !kHasStopWaiting, | 2582 ProcessDataPacketAtLevel(kDefaultPathId, 2, !kHasStopWaiting, |
2696 ENCRYPTION_INITIAL); | 2583 ENCRYPTION_INITIAL); |
2697 | 2584 |
2698 // Finally, process a third packet and note that we do not reprocess the | 2585 // Finally, process a third packet and note that we do not reprocess the |
2699 // buffered packet. | 2586 // buffered packet. |
2700 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 2587 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
2701 ProcessDataPacketAtLevel(kDefaultPathId, 3, kEntropyFlag, !kHasStopWaiting, | 2588 ProcessDataPacketAtLevel(kDefaultPathId, 3, !kHasStopWaiting, |
2702 ENCRYPTION_INITIAL); | 2589 ENCRYPTION_INITIAL); |
2703 } | 2590 } |
2704 | 2591 |
2705 TEST_P(QuicConnectionTest, Buffer100NonDecryptablePackets) { | 2592 TEST_P(QuicConnectionTest, Buffer100NonDecryptablePackets) { |
2706 // SetFromConfig is always called after construction from InitializeSession. | 2593 // SetFromConfig is always called after construction from InitializeSession. |
2707 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); | 2594 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
2708 QuicConfig config; | 2595 QuicConfig config; |
2709 config.set_max_undecryptable_packets(100); | 2596 config.set_max_undecryptable_packets(100); |
2710 connection_.SetFromConfig(config); | 2597 connection_.SetFromConfig(config); |
2711 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2598 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
2712 use_tagging_decrypter(); | 2599 use_tagging_decrypter(); |
2713 | 2600 |
2714 const uint8_t tag = 0x07; | 2601 const uint8_t tag = 0x07; |
2715 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 2602 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
2716 | 2603 |
2717 // Process an encrypted packet which can not yet be decrypted which should | 2604 // Process an encrypted packet which can not yet be decrypted which should |
2718 // result in the packet being buffered. | 2605 // result in the packet being buffered. |
2719 for (QuicPacketNumber i = 1; i <= 100; ++i) { | 2606 for (QuicPacketNumber i = 1; i <= 100; ++i) { |
2720 ProcessDataPacketAtLevel(kDefaultPathId, i, kEntropyFlag, !kHasStopWaiting, | 2607 ProcessDataPacketAtLevel(kDefaultPathId, i, !kHasStopWaiting, |
2721 ENCRYPTION_INITIAL); | 2608 ENCRYPTION_INITIAL); |
2722 } | 2609 } |
2723 | 2610 |
2724 // Transition to the new encryption state and process another encrypted packet | 2611 // Transition to the new encryption state and process another encrypted packet |
2725 // which should result in the original packets being processed. | 2612 // which should result in the original packets being processed. |
2726 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); | 2613 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); |
2727 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); | 2614 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); |
2728 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 2615 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
2729 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(101); | 2616 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(101); |
2730 ProcessDataPacketAtLevel(kDefaultPathId, 101, kEntropyFlag, !kHasStopWaiting, | 2617 ProcessDataPacketAtLevel(kDefaultPathId, 101, !kHasStopWaiting, |
2731 ENCRYPTION_INITIAL); | 2618 ENCRYPTION_INITIAL); |
2732 | 2619 |
2733 // Finally, process a third packet and note that we do not reprocess the | 2620 // Finally, process a third packet and note that we do not reprocess the |
2734 // buffered packet. | 2621 // buffered packet. |
2735 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 2622 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
2736 ProcessDataPacketAtLevel(kDefaultPathId, 102, kEntropyFlag, !kHasStopWaiting, | 2623 ProcessDataPacketAtLevel(kDefaultPathId, 102, !kHasStopWaiting, |
2737 ENCRYPTION_INITIAL); | 2624 ENCRYPTION_INITIAL); |
2738 } | 2625 } |
2739 | 2626 |
2740 TEST_P(QuicConnectionTest, TestRetransmitOrder) { | 2627 TEST_P(QuicConnectionTest, TestRetransmitOrder) { |
2741 connection_.SetMaxTailLossProbes(kDefaultPathId, 0); | 2628 connection_.SetMaxTailLossProbes(kDefaultPathId, 0); |
2742 | 2629 |
2743 QuicByteCount first_packet_size; | 2630 QuicByteCount first_packet_size; |
2744 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 2631 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
2745 .WillOnce(DoAll(SaveArg<3>(&first_packet_size), Return(true))); | 2632 .WillOnce(DoAll(SaveArg<3>(&first_packet_size), Return(true))); |
2746 | 2633 |
(...skipping 888 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3635 EXPECT_EQ(4u, connection_.sent_packet_manager().GetConsecutiveRtoCount()); | 3522 EXPECT_EQ(4u, connection_.sent_packet_manager().GetConsecutiveRtoCount()); |
3636 // The 5th RTO should not time out server side. | 3523 // The 5th RTO should not time out server side. |
3637 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 3524 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
3638 connection_.GetRetransmissionAlarm()->Fire(); | 3525 connection_.GetRetransmissionAlarm()->Fire(); |
3639 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet()); | 3526 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet()); |
3640 EXPECT_TRUE(connection_.connected()); | 3527 EXPECT_TRUE(connection_.connected()); |
3641 } | 3528 } |
3642 | 3529 |
3643 TEST_P(QuicConnectionTest, SendScheduler) { | 3530 TEST_P(QuicConnectionTest, SendScheduler) { |
3644 // Test that if we send a packet without delay, it is not queued. | 3531 // Test that if we send a packet without delay, it is not queued. |
3645 QuicPacket* packet = | 3532 QuicPacket* packet = ConstructDataPacket(kDefaultPathId, 1, !kHasStopWaiting); |
3646 ConstructDataPacket(kDefaultPathId, 1, !kEntropyFlag, !kHasStopWaiting); | |
3647 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 3533 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
3648 connection_.SendPacket(ENCRYPTION_NONE, kDefaultPathId, 1, packet, | 3534 connection_.SendPacket(ENCRYPTION_NONE, kDefaultPathId, 1, packet, |
3649 kTestEntropyHash, HAS_RETRANSMITTABLE_DATA, false, | 3535 HAS_RETRANSMITTABLE_DATA, false, false); |
3650 false); | |
3651 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 3536 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
3652 } | 3537 } |
3653 | 3538 |
3654 TEST_P(QuicConnectionTest, FailToSendFirstPacket) { | 3539 TEST_P(QuicConnectionTest, FailToSendFirstPacket) { |
3655 // Test that the connection does not crash when it fails to send the first | 3540 // Test that the connection does not crash when it fails to send the first |
3656 // packet at which point self_address_ might be uninitialized. | 3541 // packet at which point self_address_ might be uninitialized. |
3657 EXPECT_CALL(visitor_, OnConnectionClosed(_, _, _)).Times(1); | 3542 EXPECT_CALL(visitor_, OnConnectionClosed(_, _, _)).Times(1); |
3658 QuicPacket* packet = | 3543 QuicPacket* packet = ConstructDataPacket(kDefaultPathId, 1, !kHasStopWaiting); |
3659 ConstructDataPacket(kDefaultPathId, 1, !kEntropyFlag, !kHasStopWaiting); | |
3660 writer_->SetShouldWriteFail(); | 3544 writer_->SetShouldWriteFail(); |
3661 connection_.SendPacket(ENCRYPTION_NONE, kDefaultPathId, 1, packet, | 3545 connection_.SendPacket(ENCRYPTION_NONE, kDefaultPathId, 1, packet, |
3662 kTestEntropyHash, HAS_RETRANSMITTABLE_DATA, false, | 3546 HAS_RETRANSMITTABLE_DATA, false, false); |
3663 false); | |
3664 } | 3547 } |
3665 | 3548 |
3666 TEST_P(QuicConnectionTest, SendSchedulerEAGAIN) { | 3549 TEST_P(QuicConnectionTest, SendSchedulerEAGAIN) { |
3667 QuicPacket* packet = | 3550 QuicPacket* packet = ConstructDataPacket(kDefaultPathId, 1, !kHasStopWaiting); |
3668 ConstructDataPacket(kDefaultPathId, 1, !kEntropyFlag, !kHasStopWaiting); | |
3669 BlockOnNextWrite(); | 3551 BlockOnNextWrite(); |
3670 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 1, _, _)).Times(0); | 3552 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 1, _, _)).Times(0); |
3671 connection_.SendPacket(ENCRYPTION_NONE, kDefaultPathId, 1, packet, | 3553 connection_.SendPacket(ENCRYPTION_NONE, kDefaultPathId, 1, packet, |
3672 kTestEntropyHash, HAS_RETRANSMITTABLE_DATA, false, | 3554 HAS_RETRANSMITTABLE_DATA, false, false); |
3673 false); | |
3674 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 3555 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
3675 } | 3556 } |
3676 | 3557 |
3677 TEST_P(QuicConnectionTest, TestQueueLimitsOnSendStreamData) { | 3558 TEST_P(QuicConnectionTest, TestQueueLimitsOnSendStreamData) { |
3678 // All packets carry version info till version is negotiated. | 3559 // All packets carry version info till version is negotiated. |
3679 size_t payload_length; | 3560 size_t payload_length; |
3680 size_t length = GetPacketLengthForOneStream( | 3561 size_t length = GetPacketLengthForOneStream( |
3681 connection_.version(), kIncludeVersion, !kIncludePathId, | 3562 connection_.version(), kIncludeVersion, !kIncludePathId, |
3682 !kIncludeDiversificationNonce, PACKET_8BYTE_CONNECTION_ID, | 3563 !kIncludeDiversificationNonce, PACKET_8BYTE_CONNECTION_ID, |
3683 PACKET_1BYTE_PACKET_NUMBER, &payload_length); | 3564 PACKET_1BYTE_PACKET_NUMBER, &payload_length); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3749 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 3630 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
3750 const uint8_t tag = 0x07; | 3631 const uint8_t tag = 0x07; |
3751 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); | 3632 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); |
3752 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 3633 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
3753 // Process a packet from the non-crypto stream. | 3634 // Process a packet from the non-crypto stream. |
3754 frame1_.stream_id = 3; | 3635 frame1_.stream_id = 3; |
3755 | 3636 |
3756 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used | 3637 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used |
3757 // instead of ENCRYPTION_NONE. | 3638 // instead of ENCRYPTION_NONE. |
3758 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 3639 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
3759 ProcessDataPacketAtLevel(kDefaultPathId, 1, !kEntropyFlag, !kHasStopWaiting, | 3640 ProcessDataPacketAtLevel(kDefaultPathId, 1, !kHasStopWaiting, |
3760 ENCRYPTION_INITIAL); | 3641 ENCRYPTION_INITIAL); |
3761 | 3642 |
3762 // Check if delayed ack timer is running for the expected interval. | 3643 // Check if delayed ack timer is running for the expected interval. |
3763 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); | 3644 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); |
3764 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); | 3645 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); |
3765 // Simulate delayed ack alarm firing. | 3646 // Simulate delayed ack alarm firing. |
3766 connection_.GetAckAlarm()->Fire(); | 3647 connection_.GetAckAlarm()->Fire(); |
3767 // Check that ack is sent and that delayed ack alarm is reset. | 3648 // Check that ack is sent and that delayed ack alarm is reset. |
3768 EXPECT_EQ(2u, writer_->frame_count()); | 3649 EXPECT_EQ(2u, writer_->frame_count()); |
3769 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); | 3650 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); |
(...skipping 17 matching lines...) Expand all Loading... |
3787 const uint8_t tag = 0x07; | 3668 const uint8_t tag = 0x07; |
3788 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); | 3669 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); |
3789 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 3670 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
3790 // Process a packet from the non-crypto stream. | 3671 // Process a packet from the non-crypto stream. |
3791 frame1_.stream_id = 3; | 3672 frame1_.stream_id = 3; |
3792 | 3673 |
3793 // Process all the initial packets in order so there aren't missing packets. | 3674 // Process all the initial packets in order so there aren't missing packets. |
3794 QuicPacketNumber kFirstDecimatedPacket = 101; | 3675 QuicPacketNumber kFirstDecimatedPacket = 101; |
3795 for (unsigned int i = 0; i < kFirstDecimatedPacket - 1; ++i) { | 3676 for (unsigned int i = 0; i < kFirstDecimatedPacket - 1; ++i) { |
3796 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 3677 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
3797 ProcessDataPacketAtLevel(kDefaultPathId, 1 + i, !kEntropyFlag, | 3678 ProcessDataPacketAtLevel(kDefaultPathId, 1 + i, !kHasStopWaiting, |
3798 !kHasStopWaiting, ENCRYPTION_INITIAL); | 3679 ENCRYPTION_INITIAL); |
3799 } | 3680 } |
3800 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 3681 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
3801 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used | 3682 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used |
3802 // instead of ENCRYPTION_NONE. | 3683 // instead of ENCRYPTION_NONE. |
3803 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 3684 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
3804 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket, !kEntropyFlag, | 3685 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket, |
3805 !kHasStopWaiting, ENCRYPTION_INITIAL); | 3686 !kHasStopWaiting, ENCRYPTION_INITIAL); |
3806 | 3687 |
3807 // Check if delayed ack timer is running for the expected interval. | 3688 // Check if delayed ack timer is running for the expected interval. |
3808 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); | 3689 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); |
3809 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); | 3690 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); |
3810 | 3691 |
3811 // The 10th received packet causes an ack to be sent. | 3692 // The 10th received packet causes an ack to be sent. |
3812 for (int i = 0; i < 9; ++i) { | 3693 for (int i = 0; i < 9; ++i) { |
3813 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); | 3694 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); |
3814 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 3695 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
3815 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 1 + i, | 3696 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 1 + i, |
3816 !kEntropyFlag, !kHasStopWaiting, | 3697 !kHasStopWaiting, ENCRYPTION_INITIAL); |
3817 ENCRYPTION_INITIAL); | |
3818 } | 3698 } |
3819 // Check that ack is sent and that delayed ack alarm is reset. | 3699 // Check that ack is sent and that delayed ack alarm is reset. |
3820 EXPECT_EQ(2u, writer_->frame_count()); | 3700 EXPECT_EQ(2u, writer_->frame_count()); |
3821 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); | 3701 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); |
3822 EXPECT_FALSE(writer_->ack_frames().empty()); | 3702 EXPECT_FALSE(writer_->ack_frames().empty()); |
3823 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 3703 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
3824 } | 3704 } |
3825 | 3705 |
3826 TEST_P(QuicConnectionTest, SendDelayedAckDecimationEighthRtt) { | 3706 TEST_P(QuicConnectionTest, SendDelayedAckDecimationEighthRtt) { |
3827 QuicConnectionPeer::SetAckMode(&connection_, QuicConnection::ACK_DECIMATION); | 3707 QuicConnectionPeer::SetAckMode(&connection_, QuicConnection::ACK_DECIMATION); |
(...skipping 12 matching lines...) Expand all Loading... |
3840 const uint8_t tag = 0x07; | 3720 const uint8_t tag = 0x07; |
3841 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); | 3721 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); |
3842 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 3722 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
3843 // Process a packet from the non-crypto stream. | 3723 // Process a packet from the non-crypto stream. |
3844 frame1_.stream_id = 3; | 3724 frame1_.stream_id = 3; |
3845 | 3725 |
3846 // Process all the initial packets in order so there aren't missing packets. | 3726 // Process all the initial packets in order so there aren't missing packets. |
3847 QuicPacketNumber kFirstDecimatedPacket = 101; | 3727 QuicPacketNumber kFirstDecimatedPacket = 101; |
3848 for (unsigned int i = 0; i < kFirstDecimatedPacket - 1; ++i) { | 3728 for (unsigned int i = 0; i < kFirstDecimatedPacket - 1; ++i) { |
3849 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 3729 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
3850 ProcessDataPacketAtLevel(kDefaultPathId, 1 + i, !kEntropyFlag, | 3730 ProcessDataPacketAtLevel(kDefaultPathId, 1 + i, !kHasStopWaiting, |
3851 !kHasStopWaiting, ENCRYPTION_INITIAL); | 3731 ENCRYPTION_INITIAL); |
3852 } | 3732 } |
3853 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 3733 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
3854 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used | 3734 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used |
3855 // instead of ENCRYPTION_NONE. | 3735 // instead of ENCRYPTION_NONE. |
3856 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 3736 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
3857 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket, !kEntropyFlag, | 3737 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket, |
3858 !kHasStopWaiting, ENCRYPTION_INITIAL); | 3738 !kHasStopWaiting, ENCRYPTION_INITIAL); |
3859 | 3739 |
3860 // Check if delayed ack timer is running for the expected interval. | 3740 // Check if delayed ack timer is running for the expected interval. |
3861 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); | 3741 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); |
3862 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); | 3742 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); |
3863 | 3743 |
3864 // The 10th received packet causes an ack to be sent. | 3744 // The 10th received packet causes an ack to be sent. |
3865 for (int i = 0; i < 9; ++i) { | 3745 for (int i = 0; i < 9; ++i) { |
3866 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); | 3746 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); |
3867 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 3747 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
3868 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 1 + i, | 3748 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 1 + i, |
3869 !kEntropyFlag, !kHasStopWaiting, | 3749 !kHasStopWaiting, ENCRYPTION_INITIAL); |
3870 ENCRYPTION_INITIAL); | |
3871 } | 3750 } |
3872 // Check that ack is sent and that delayed ack alarm is reset. | 3751 // Check that ack is sent and that delayed ack alarm is reset. |
3873 EXPECT_EQ(2u, writer_->frame_count()); | 3752 EXPECT_EQ(2u, writer_->frame_count()); |
3874 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); | 3753 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); |
3875 EXPECT_FALSE(writer_->ack_frames().empty()); | 3754 EXPECT_FALSE(writer_->ack_frames().empty()); |
3876 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 3755 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
3877 } | 3756 } |
3878 | 3757 |
3879 TEST_P(QuicConnectionTest, SendDelayedAckDecimationWithReordering) { | 3758 TEST_P(QuicConnectionTest, SendDelayedAckDecimationWithReordering) { |
3880 QuicConnectionPeer::SetAckMode( | 3759 QuicConnectionPeer::SetAckMode( |
(...skipping 12 matching lines...) Expand all Loading... |
3893 const uint8_t tag = 0x07; | 3772 const uint8_t tag = 0x07; |
3894 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); | 3773 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); |
3895 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 3774 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
3896 // Process a packet from the non-crypto stream. | 3775 // Process a packet from the non-crypto stream. |
3897 frame1_.stream_id = 3; | 3776 frame1_.stream_id = 3; |
3898 | 3777 |
3899 // Process all the initial packets in order so there aren't missing packets. | 3778 // Process all the initial packets in order so there aren't missing packets. |
3900 QuicPacketNumber kFirstDecimatedPacket = 101; | 3779 QuicPacketNumber kFirstDecimatedPacket = 101; |
3901 for (unsigned int i = 0; i < kFirstDecimatedPacket - 1; ++i) { | 3780 for (unsigned int i = 0; i < kFirstDecimatedPacket - 1; ++i) { |
3902 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 3781 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
3903 ProcessDataPacketAtLevel(kDefaultPathId, 1 + i, !kEntropyFlag, | 3782 ProcessDataPacketAtLevel(kDefaultPathId, 1 + i, !kHasStopWaiting, |
3904 !kHasStopWaiting, ENCRYPTION_INITIAL); | 3783 ENCRYPTION_INITIAL); |
3905 } | 3784 } |
3906 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 3785 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
3907 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used | 3786 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used |
3908 // instead of ENCRYPTION_NONE. | 3787 // instead of ENCRYPTION_NONE. |
3909 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 3788 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
3910 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket, !kEntropyFlag, | 3789 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket, |
3911 !kHasStopWaiting, ENCRYPTION_INITIAL); | 3790 !kHasStopWaiting, ENCRYPTION_INITIAL); |
3912 | 3791 |
3913 // Check if delayed ack timer is running for the expected interval. | 3792 // Check if delayed ack timer is running for the expected interval. |
3914 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); | 3793 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); |
3915 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); | 3794 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); |
3916 | 3795 |
3917 // Process packet 10 first and ensure the alarm is one eighth min_rtt. | 3796 // Process packet 10 first and ensure the alarm is one eighth min_rtt. |
3918 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 3797 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
3919 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 9, | 3798 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 9, |
3920 !kEntropyFlag, !kHasStopWaiting, ENCRYPTION_INITIAL); | 3799 !kHasStopWaiting, ENCRYPTION_INITIAL); |
3921 ack_time = clock_.ApproximateNow() + QuicTime::Delta::FromMilliseconds(5); | 3800 ack_time = clock_.ApproximateNow() + QuicTime::Delta::FromMilliseconds(5); |
3922 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); | 3801 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); |
3923 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); | 3802 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); |
3924 | 3803 |
3925 // The 10th received packet causes an ack to be sent. | 3804 // The 10th received packet causes an ack to be sent. |
3926 for (int i = 0; i < 8; ++i) { | 3805 for (int i = 0; i < 8; ++i) { |
3927 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); | 3806 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); |
3928 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 3807 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
3929 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 1 + i, | 3808 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 1 + i, |
3930 !kEntropyFlag, !kHasStopWaiting, | 3809 !kHasStopWaiting, ENCRYPTION_INITIAL); |
3931 ENCRYPTION_INITIAL); | |
3932 } | 3810 } |
3933 // Check that ack is sent and that delayed ack alarm is reset. | 3811 // Check that ack is sent and that delayed ack alarm is reset. |
3934 EXPECT_EQ(2u, writer_->frame_count()); | 3812 EXPECT_EQ(2u, writer_->frame_count()); |
3935 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); | 3813 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); |
3936 EXPECT_FALSE(writer_->ack_frames().empty()); | 3814 EXPECT_FALSE(writer_->ack_frames().empty()); |
3937 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 3815 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
3938 } | 3816 } |
3939 | 3817 |
3940 TEST_P(QuicConnectionTest, SendDelayedAckDecimationWithLargeReordering) { | 3818 TEST_P(QuicConnectionTest, SendDelayedAckDecimationWithLargeReordering) { |
3941 QuicConnectionPeer::SetAckMode( | 3819 QuicConnectionPeer::SetAckMode( |
(...skipping 12 matching lines...) Expand all Loading... |
3954 const uint8_t tag = 0x07; | 3832 const uint8_t tag = 0x07; |
3955 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); | 3833 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); |
3956 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 3834 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
3957 // Process a packet from the non-crypto stream. | 3835 // Process a packet from the non-crypto stream. |
3958 frame1_.stream_id = 3; | 3836 frame1_.stream_id = 3; |
3959 | 3837 |
3960 // Process all the initial packets in order so there aren't missing packets. | 3838 // Process all the initial packets in order so there aren't missing packets. |
3961 QuicPacketNumber kFirstDecimatedPacket = 101; | 3839 QuicPacketNumber kFirstDecimatedPacket = 101; |
3962 for (unsigned int i = 0; i < kFirstDecimatedPacket - 1; ++i) { | 3840 for (unsigned int i = 0; i < kFirstDecimatedPacket - 1; ++i) { |
3963 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 3841 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
3964 ProcessDataPacketAtLevel(kDefaultPathId, 1 + i, !kEntropyFlag, | 3842 ProcessDataPacketAtLevel(kDefaultPathId, 1 + i, !kHasStopWaiting, |
3965 !kHasStopWaiting, ENCRYPTION_INITIAL); | 3843 ENCRYPTION_INITIAL); |
3966 } | 3844 } |
3967 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 3845 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
3968 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used | 3846 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used |
3969 // instead of ENCRYPTION_NONE. | 3847 // instead of ENCRYPTION_NONE. |
3970 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 3848 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
3971 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket, !kEntropyFlag, | 3849 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket, |
3972 !kHasStopWaiting, ENCRYPTION_INITIAL); | 3850 !kHasStopWaiting, ENCRYPTION_INITIAL); |
3973 | 3851 |
3974 // Check if delayed ack timer is running for the expected interval. | 3852 // Check if delayed ack timer is running for the expected interval. |
3975 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); | 3853 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); |
3976 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); | 3854 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); |
3977 | 3855 |
3978 // Process packet 10 first and ensure the alarm is one eighth min_rtt. | 3856 // Process packet 10 first and ensure the alarm is one eighth min_rtt. |
3979 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 3857 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
3980 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 19, | 3858 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 19, |
3981 !kEntropyFlag, !kHasStopWaiting, ENCRYPTION_INITIAL); | 3859 !kHasStopWaiting, ENCRYPTION_INITIAL); |
3982 ack_time = clock_.ApproximateNow() + QuicTime::Delta::FromMilliseconds(5); | 3860 ack_time = clock_.ApproximateNow() + QuicTime::Delta::FromMilliseconds(5); |
3983 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); | 3861 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); |
3984 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); | 3862 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); |
3985 | 3863 |
3986 // The 10th received packet causes an ack to be sent. | 3864 // The 10th received packet causes an ack to be sent. |
3987 for (int i = 0; i < 8; ++i) { | 3865 for (int i = 0; i < 8; ++i) { |
3988 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); | 3866 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); |
3989 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 3867 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
3990 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 1 + i, | 3868 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 1 + i, |
3991 !kEntropyFlag, !kHasStopWaiting, | 3869 !kHasStopWaiting, ENCRYPTION_INITIAL); |
3992 ENCRYPTION_INITIAL); | |
3993 } | 3870 } |
3994 // Check that ack is sent and that delayed ack alarm is reset. | 3871 // Check that ack is sent and that delayed ack alarm is reset. |
3995 EXPECT_EQ(2u, writer_->frame_count()); | 3872 EXPECT_EQ(2u, writer_->frame_count()); |
3996 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); | 3873 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); |
3997 EXPECT_FALSE(writer_->ack_frames().empty()); | 3874 EXPECT_FALSE(writer_->ack_frames().empty()); |
3998 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 3875 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
3999 | 3876 |
4000 // The next packet received in order will cause an immediate ack, | 3877 // The next packet received in order will cause an immediate ack, |
4001 // because it fills a hole. | 3878 // because it fills a hole. |
4002 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 3879 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
4003 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 3880 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
4004 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 10, | 3881 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 10, |
4005 !kEntropyFlag, !kHasStopWaiting, ENCRYPTION_INITIAL); | 3882 !kHasStopWaiting, ENCRYPTION_INITIAL); |
4006 // Check that ack is sent and that delayed ack alarm is reset. | 3883 // Check that ack is sent and that delayed ack alarm is reset. |
4007 EXPECT_EQ(2u, writer_->frame_count()); | 3884 EXPECT_EQ(2u, writer_->frame_count()); |
4008 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); | 3885 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); |
4009 EXPECT_FALSE(writer_->ack_frames().empty()); | 3886 EXPECT_FALSE(writer_->ack_frames().empty()); |
4010 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 3887 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
4011 } | 3888 } |
4012 | 3889 |
4013 TEST_P(QuicConnectionTest, SendDelayedAckDecimationWithReorderingEighthRtt) { | 3890 TEST_P(QuicConnectionTest, SendDelayedAckDecimationWithReorderingEighthRtt) { |
4014 QuicConnectionPeer::SetAckMode( | 3891 QuicConnectionPeer::SetAckMode( |
4015 &connection_, QuicConnection::ACK_DECIMATION_WITH_REORDERING); | 3892 &connection_, QuicConnection::ACK_DECIMATION_WITH_REORDERING); |
(...skipping 12 matching lines...) Expand all Loading... |
4028 const uint8_t tag = 0x07; | 3905 const uint8_t tag = 0x07; |
4029 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); | 3906 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); |
4030 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 3907 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
4031 // Process a packet from the non-crypto stream. | 3908 // Process a packet from the non-crypto stream. |
4032 frame1_.stream_id = 3; | 3909 frame1_.stream_id = 3; |
4033 | 3910 |
4034 // Process all the initial packets in order so there aren't missing packets. | 3911 // Process all the initial packets in order so there aren't missing packets. |
4035 QuicPacketNumber kFirstDecimatedPacket = 101; | 3912 QuicPacketNumber kFirstDecimatedPacket = 101; |
4036 for (unsigned int i = 0; i < kFirstDecimatedPacket - 1; ++i) { | 3913 for (unsigned int i = 0; i < kFirstDecimatedPacket - 1; ++i) { |
4037 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 3914 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
4038 ProcessDataPacketAtLevel(kDefaultPathId, 1 + i, !kEntropyFlag, | 3915 ProcessDataPacketAtLevel(kDefaultPathId, 1 + i, !kHasStopWaiting, |
4039 !kHasStopWaiting, ENCRYPTION_INITIAL); | 3916 ENCRYPTION_INITIAL); |
4040 } | 3917 } |
4041 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 3918 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
4042 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used | 3919 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used |
4043 // instead of ENCRYPTION_NONE. | 3920 // instead of ENCRYPTION_NONE. |
4044 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 3921 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
4045 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket, !kEntropyFlag, | 3922 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket, |
4046 !kHasStopWaiting, ENCRYPTION_INITIAL); | 3923 !kHasStopWaiting, ENCRYPTION_INITIAL); |
4047 | 3924 |
4048 // Check if delayed ack timer is running for the expected interval. | 3925 // Check if delayed ack timer is running for the expected interval. |
4049 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); | 3926 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); |
4050 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); | 3927 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); |
4051 | 3928 |
4052 // Process packet 10 first and ensure the alarm is one eighth min_rtt. | 3929 // Process packet 10 first and ensure the alarm is one eighth min_rtt. |
4053 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 3930 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
4054 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 9, | 3931 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 9, |
4055 !kEntropyFlag, !kHasStopWaiting, ENCRYPTION_INITIAL); | 3932 !kHasStopWaiting, ENCRYPTION_INITIAL); |
4056 ack_time = clock_.ApproximateNow() + QuicTime::Delta::FromMilliseconds(5); | 3933 ack_time = clock_.ApproximateNow() + QuicTime::Delta::FromMilliseconds(5); |
4057 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); | 3934 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); |
4058 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); | 3935 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); |
4059 | 3936 |
4060 // The 10th received packet causes an ack to be sent. | 3937 // The 10th received packet causes an ack to be sent. |
4061 for (int i = 0; i < 8; ++i) { | 3938 for (int i = 0; i < 8; ++i) { |
4062 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); | 3939 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); |
4063 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 3940 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
4064 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 1 + i, | 3941 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 1 + i, |
4065 !kEntropyFlag, !kHasStopWaiting, | 3942 !kHasStopWaiting, ENCRYPTION_INITIAL); |
4066 ENCRYPTION_INITIAL); | |
4067 } | 3943 } |
4068 // Check that ack is sent and that delayed ack alarm is reset. | 3944 // Check that ack is sent and that delayed ack alarm is reset. |
4069 EXPECT_EQ(2u, writer_->frame_count()); | 3945 EXPECT_EQ(2u, writer_->frame_count()); |
4070 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); | 3946 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); |
4071 EXPECT_FALSE(writer_->ack_frames().empty()); | 3947 EXPECT_FALSE(writer_->ack_frames().empty()); |
4072 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 3948 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
4073 } | 3949 } |
4074 | 3950 |
4075 TEST_P(QuicConnectionTest, | 3951 TEST_P(QuicConnectionTest, |
4076 SendDelayedAckDecimationWithLargeReorderingEighthRtt) { | 3952 SendDelayedAckDecimationWithLargeReorderingEighthRtt) { |
(...skipping 14 matching lines...) Expand all Loading... |
4091 const uint8_t tag = 0x07; | 3967 const uint8_t tag = 0x07; |
4092 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); | 3968 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); |
4093 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 3969 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
4094 // Process a packet from the non-crypto stream. | 3970 // Process a packet from the non-crypto stream. |
4095 frame1_.stream_id = 3; | 3971 frame1_.stream_id = 3; |
4096 | 3972 |
4097 // Process all the initial packets in order so there aren't missing packets. | 3973 // Process all the initial packets in order so there aren't missing packets. |
4098 QuicPacketNumber kFirstDecimatedPacket = 101; | 3974 QuicPacketNumber kFirstDecimatedPacket = 101; |
4099 for (unsigned int i = 0; i < kFirstDecimatedPacket - 1; ++i) { | 3975 for (unsigned int i = 0; i < kFirstDecimatedPacket - 1; ++i) { |
4100 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 3976 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
4101 ProcessDataPacketAtLevel(kDefaultPathId, 1 + i, !kEntropyFlag, | 3977 ProcessDataPacketAtLevel(kDefaultPathId, 1 + i, !kHasStopWaiting, |
4102 !kHasStopWaiting, ENCRYPTION_INITIAL); | 3978 ENCRYPTION_INITIAL); |
4103 } | 3979 } |
4104 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 3980 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
4105 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used | 3981 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used |
4106 // instead of ENCRYPTION_NONE. | 3982 // instead of ENCRYPTION_NONE. |
4107 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 3983 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
4108 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket, !kEntropyFlag, | 3984 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket, |
4109 !kHasStopWaiting, ENCRYPTION_INITIAL); | 3985 !kHasStopWaiting, ENCRYPTION_INITIAL); |
4110 | 3986 |
4111 // Check if delayed ack timer is running for the expected interval. | 3987 // Check if delayed ack timer is running for the expected interval. |
4112 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); | 3988 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); |
4113 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); | 3989 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); |
4114 | 3990 |
4115 // Process packet 10 first and ensure the alarm is one eighth min_rtt. | 3991 // Process packet 10 first and ensure the alarm is one eighth min_rtt. |
4116 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 3992 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
4117 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 19, | 3993 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 19, |
4118 !kEntropyFlag, !kHasStopWaiting, ENCRYPTION_INITIAL); | 3994 !kHasStopWaiting, ENCRYPTION_INITIAL); |
4119 ack_time = clock_.ApproximateNow() + QuicTime::Delta::FromMilliseconds(5); | 3995 ack_time = clock_.ApproximateNow() + QuicTime::Delta::FromMilliseconds(5); |
4120 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); | 3996 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); |
4121 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); | 3997 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); |
4122 | 3998 |
4123 // The 10th received packet causes an ack to be sent. | 3999 // The 10th received packet causes an ack to be sent. |
4124 for (int i = 0; i < 8; ++i) { | 4000 for (int i = 0; i < 8; ++i) { |
4125 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); | 4001 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); |
4126 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 4002 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
4127 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 1 + i, | 4003 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 1 + i, |
4128 !kEntropyFlag, !kHasStopWaiting, | 4004 !kHasStopWaiting, ENCRYPTION_INITIAL); |
4129 ENCRYPTION_INITIAL); | |
4130 } | 4005 } |
4131 // Check that ack is sent and that delayed ack alarm is reset. | 4006 // Check that ack is sent and that delayed ack alarm is reset. |
4132 EXPECT_EQ(2u, writer_->frame_count()); | 4007 EXPECT_EQ(2u, writer_->frame_count()); |
4133 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); | 4008 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); |
4134 EXPECT_FALSE(writer_->ack_frames().empty()); | 4009 EXPECT_FALSE(writer_->ack_frames().empty()); |
4135 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 4010 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
4136 | 4011 |
4137 // The next packet received in order will cause an immediate ack, | 4012 // The next packet received in order will cause an immediate ack, |
4138 // because it fills a hole. | 4013 // because it fills a hole. |
4139 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 4014 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
4140 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 4015 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
4141 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 10, | 4016 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 10, |
4142 !kEntropyFlag, !kHasStopWaiting, ENCRYPTION_INITIAL); | 4017 !kHasStopWaiting, ENCRYPTION_INITIAL); |
4143 // Check that ack is sent and that delayed ack alarm is reset. | 4018 // Check that ack is sent and that delayed ack alarm is reset. |
4144 EXPECT_EQ(2u, writer_->frame_count()); | 4019 EXPECT_EQ(2u, writer_->frame_count()); |
4145 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); | 4020 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); |
4146 EXPECT_FALSE(writer_->ack_frames().empty()); | 4021 EXPECT_FALSE(writer_->ack_frames().empty()); |
4147 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 4022 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
4148 } | 4023 } |
4149 | 4024 |
4150 TEST_P(QuicConnectionTest, SendDelayedAckOnHandshakeConfirmed) { | 4025 TEST_P(QuicConnectionTest, SendDelayedAckOnHandshakeConfirmed) { |
4151 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 4026 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
4152 ProcessPacket(kDefaultPathId, 1); | 4027 ProcessPacket(kDefaultPathId, 1); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4269 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 4144 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
4270 | 4145 |
4271 // Process two packets from the crypto stream, which is frame1_'s default, | 4146 // Process two packets from the crypto stream, which is frame1_'s default, |
4272 // simulating a 2 packet reject. | 4147 // simulating a 2 packet reject. |
4273 { | 4148 { |
4274 ProcessPacket(kDefaultPathId, 1); | 4149 ProcessPacket(kDefaultPathId, 1); |
4275 // Send the new CHLO when the REJ is processed. | 4150 // Send the new CHLO when the REJ is processed. |
4276 EXPECT_CALL(visitor_, OnStreamFrame(_)) | 4151 EXPECT_CALL(visitor_, OnStreamFrame(_)) |
4277 .WillOnce(IgnoreResult(InvokeWithoutArgs( | 4152 .WillOnce(IgnoreResult(InvokeWithoutArgs( |
4278 &connection_, &TestConnection::SendCryptoStreamData))); | 4153 &connection_, &TestConnection::SendCryptoStreamData))); |
4279 ProcessDataPacket(kDefaultPathId, 2, kEntropyFlag); | 4154 ProcessDataPacket(kDefaultPathId, 2); |
4280 } | 4155 } |
4281 // Check that ack is sent and that delayed ack alarm is reset. | 4156 // Check that ack is sent and that delayed ack alarm is reset. |
4282 EXPECT_EQ(3u, writer_->frame_count()); | 4157 EXPECT_EQ(3u, writer_->frame_count()); |
4283 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); | 4158 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); |
4284 EXPECT_EQ(1u, writer_->stream_frames().size()); | 4159 EXPECT_EQ(1u, writer_->stream_frames().size()); |
4285 EXPECT_FALSE(writer_->ack_frames().empty()); | 4160 EXPECT_FALSE(writer_->ack_frames().empty()); |
4286 EXPECT_EQ(2u, writer_->ack_frames().front().largest_observed); | 4161 EXPECT_EQ(2u, writer_->ack_frames().front().largest_observed); |
4287 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 4162 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
4288 } | 4163 } |
4289 | 4164 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4348 } | 4223 } |
4349 | 4224 |
4350 TEST_P(QuicConnectionTest, SendWhenDisconnected) { | 4225 TEST_P(QuicConnectionTest, SendWhenDisconnected) { |
4351 EXPECT_TRUE(connection_.connected()); | 4226 EXPECT_TRUE(connection_.connected()); |
4352 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PEER_GOING_AWAY, _, | 4227 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PEER_GOING_AWAY, _, |
4353 ConnectionCloseSource::FROM_SELF)); | 4228 ConnectionCloseSource::FROM_SELF)); |
4354 connection_.CloseConnection(QUIC_PEER_GOING_AWAY, "no reason", | 4229 connection_.CloseConnection(QUIC_PEER_GOING_AWAY, "no reason", |
4355 ConnectionCloseBehavior::SILENT_CLOSE); | 4230 ConnectionCloseBehavior::SILENT_CLOSE); |
4356 EXPECT_FALSE(connection_.connected()); | 4231 EXPECT_FALSE(connection_.connected()); |
4357 EXPECT_FALSE(connection_.CanWriteStreamData()); | 4232 EXPECT_FALSE(connection_.CanWriteStreamData()); |
4358 QuicPacket* packet = | 4233 QuicPacket* packet = ConstructDataPacket(kDefaultPathId, 1, !kHasStopWaiting); |
4359 ConstructDataPacket(kDefaultPathId, 1, !kEntropyFlag, !kHasStopWaiting); | |
4360 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 1, _, _)).Times(0); | 4234 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 1, _, _)).Times(0); |
4361 connection_.SendPacket(ENCRYPTION_NONE, kDefaultPathId, 1, packet, | 4235 connection_.SendPacket(ENCRYPTION_NONE, kDefaultPathId, 1, packet, |
4362 kTestEntropyHash, HAS_RETRANSMITTABLE_DATA, false, | 4236 HAS_RETRANSMITTABLE_DATA, false, false); |
4363 false); | |
4364 } | 4237 } |
4365 | 4238 |
4366 TEST_P(QuicConnectionTest, PublicReset) { | 4239 TEST_P(QuicConnectionTest, PublicReset) { |
4367 QuicPublicResetPacket header; | 4240 QuicPublicResetPacket header; |
4368 header.public_header.connection_id = connection_id_; | 4241 header.public_header.connection_id = connection_id_; |
4369 header.public_header.reset_flag = true; | 4242 header.public_header.reset_flag = true; |
4370 header.public_header.version_flag = false; | 4243 header.public_header.version_flag = false; |
4371 header.rejected_packet_number = 10101; | 4244 header.rejected_packet_number = 10101; |
4372 std::unique_ptr<QuicEncryptedPacket> packet( | 4245 std::unique_ptr<QuicEncryptedPacket> packet( |
4373 framer_.BuildPublicResetPacket(header)); | 4246 framer_.BuildPublicResetPacket(header)); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4425 QuicReceivedPacket encrypted(nullptr, 0, QuicTime::Zero()); | 4298 QuicReceivedPacket encrypted(nullptr, 0, QuicTime::Zero()); |
4426 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, encrypted); | 4299 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, encrypted); |
4427 } | 4300 } |
4428 | 4301 |
4429 TEST_P(QuicConnectionTest, MissingPacketsBeforeLeastUnacked) { | 4302 TEST_P(QuicConnectionTest, MissingPacketsBeforeLeastUnacked) { |
4430 // Set the packet number of the ack packet to be least unacked (4). | 4303 // Set the packet number of the ack packet to be least unacked (4). |
4431 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 3); | 4304 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 3); |
4432 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 4305 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
4433 QuicStopWaitingFrame frame = InitStopWaitingFrame(4); | 4306 QuicStopWaitingFrame frame = InitStopWaitingFrame(4); |
4434 ProcessStopWaitingPacket(&frame); | 4307 ProcessStopWaitingPacket(&frame); |
4435 if (outgoing_ack()->missing) { | 4308 EXPECT_FALSE(outgoing_ack()->packets.Empty()); |
4436 EXPECT_TRUE(outgoing_ack()->packets.Empty()); | |
4437 } else { | |
4438 EXPECT_FALSE(outgoing_ack()->packets.Empty()); | |
4439 } | |
4440 } | |
4441 | |
4442 TEST_P(QuicConnectionTest, ReceivedEntropyHashCalculation) { | |
4443 if (GetParam().version > QUIC_VERSION_33) { | |
4444 return; | |
4445 } | |
4446 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(AtLeast(1)); | |
4447 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | |
4448 ProcessDataPacket(kDefaultPathId, 1, kEntropyFlag); | |
4449 ProcessDataPacket(kDefaultPathId, 4, kEntropyFlag); | |
4450 ProcessDataPacket(kDefaultPathId, 3, !kEntropyFlag); | |
4451 ProcessDataPacket(kDefaultPathId, 7, kEntropyFlag); | |
4452 EXPECT_EQ(146u, outgoing_ack()->entropy_hash); | |
4453 } | |
4454 | |
4455 TEST_P(QuicConnectionTest, UpdateEntropyForReceivedPackets) { | |
4456 if (GetParam().version > QUIC_VERSION_33) { | |
4457 return; | |
4458 } | |
4459 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(AtLeast(1)); | |
4460 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | |
4461 ProcessDataPacket(kDefaultPathId, 1, kEntropyFlag); | |
4462 ProcessDataPacket(kDefaultPathId, 5, kEntropyFlag); | |
4463 ProcessDataPacket(kDefaultPathId, 4, !kEntropyFlag); | |
4464 EXPECT_EQ(34u, outgoing_ack()->entropy_hash); | |
4465 // Make 4th packet my least unacked, and update entropy for 2, 3 packets. | |
4466 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 5); | |
4467 QuicPacketEntropyHash six_packet_entropy_hash = 0; | |
4468 QuicPacketEntropyHash random_entropy_hash = 129u; | |
4469 QuicStopWaitingFrame frame = InitStopWaitingFrame(4); | |
4470 frame.entropy_hash = random_entropy_hash; | |
4471 if (ProcessStopWaitingPacket(&frame)) { | |
4472 six_packet_entropy_hash = 1 << 6; | |
4473 } | |
4474 | |
4475 EXPECT_EQ((random_entropy_hash + (1 << 5) + six_packet_entropy_hash), | |
4476 outgoing_ack()->entropy_hash); | |
4477 } | |
4478 | |
4479 TEST_P(QuicConnectionTest, UpdateEntropyHashUptoCurrentPacket) { | |
4480 if (GetParam().version > QUIC_VERSION_33) { | |
4481 return; | |
4482 } | |
4483 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(AtLeast(1)); | |
4484 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | |
4485 ProcessDataPacket(kDefaultPathId, 1, kEntropyFlag); | |
4486 ProcessDataPacket(kDefaultPathId, 5, !kEntropyFlag); | |
4487 ProcessDataPacket(kDefaultPathId, 22, kEntropyFlag); | |
4488 EXPECT_EQ(66u, outgoing_ack()->entropy_hash); | |
4489 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 22); | |
4490 QuicPacketEntropyHash random_entropy_hash = 85u; | |
4491 // Current packet is the least unacked packet. | |
4492 QuicPacketEntropyHash ack_entropy_hash; | |
4493 QuicStopWaitingFrame frame = InitStopWaitingFrame(23); | |
4494 frame.entropy_hash = random_entropy_hash; | |
4495 ack_entropy_hash = ProcessStopWaitingPacket(&frame); | |
4496 EXPECT_EQ((random_entropy_hash + ack_entropy_hash), | |
4497 outgoing_ack()->entropy_hash); | |
4498 ProcessDataPacket(kDefaultPathId, 25, kEntropyFlag); | |
4499 EXPECT_EQ((random_entropy_hash + ack_entropy_hash + (1 << (25 % 8))), | |
4500 outgoing_ack()->entropy_hash); | |
4501 } | |
4502 | |
4503 TEST_P(QuicConnectionTest, EntropyCalculationForTruncatedAck) { | |
4504 if (GetParam().version > QUIC_VERSION_33) { | |
4505 return; | |
4506 } | |
4507 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(AtLeast(1)); | |
4508 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | |
4509 QuicPacketEntropyHash entropy[51]; | |
4510 entropy[0] = 0; | |
4511 for (int i = 1; i < 51; ++i) { | |
4512 bool should_send = i % 10 != 1; | |
4513 bool entropy_flag = (i & (i - 1)) != 0; | |
4514 if (!should_send) { | |
4515 entropy[i] = entropy[i - 1]; | |
4516 continue; | |
4517 } | |
4518 if (entropy_flag) { | |
4519 entropy[i] = entropy[i - 1] ^ (1 << (i % 8)); | |
4520 } else { | |
4521 entropy[i] = entropy[i - 1]; | |
4522 } | |
4523 ProcessDataPacket(kDefaultPathId, i, entropy_flag); | |
4524 } | |
4525 for (int i = 1; i < 50; ++i) { | |
4526 EXPECT_EQ(entropy[i], | |
4527 QuicConnectionPeer::ReceivedEntropyHash(&connection_, i)); | |
4528 } | |
4529 } | 4309 } |
4530 | 4310 |
4531 TEST_P(QuicConnectionTest, ServerSendsVersionNegotiationPacket) { | 4311 TEST_P(QuicConnectionTest, ServerSendsVersionNegotiationPacket) { |
4532 connection_.SetSupportedVersions(AllSupportedVersions()); | 4312 connection_.SetSupportedVersions(AllSupportedVersions()); |
4533 set_perspective(Perspective::IS_SERVER); | 4313 set_perspective(Perspective::IS_SERVER); |
4534 peer_framer_.set_version_for_tests(QUIC_VERSION_UNSUPPORTED); | 4314 peer_framer_.set_version_for_tests(QUIC_VERSION_UNSUPPORTED); |
4535 | 4315 |
4536 QuicPacketHeader header; | 4316 QuicPacketHeader header; |
4537 header.public_header.connection_id = connection_id_; | 4317 header.public_header.connection_id = connection_id_; |
4538 header.public_header.version_flag = true; | 4318 header.public_header.version_flag = true; |
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5324 error_details, ConnectionCloseSource::FROM_PEER)); | 5104 error_details, ConnectionCloseSource::FROM_PEER)); |
5325 connection_.set_perspective(Perspective::IS_CLIENT); | 5105 connection_.set_perspective(Perspective::IS_CLIENT); |
5326 connection_.CloseConnection(QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT, | 5106 connection_.CloseConnection(QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT, |
5327 error_details, | 5107 error_details, |
5328 ConnectionCloseBehavior::SILENT_CLOSE); | 5108 ConnectionCloseBehavior::SILENT_CLOSE); |
5329 } | 5109 } |
5330 | 5110 |
5331 } // namespace | 5111 } // namespace |
5332 } // namespace test | 5112 } // namespace test |
5333 } // namespace net | 5113 } // namespace net |
OLD | NEW |