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

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

Issue 1782143003: Remove FEC code from receive path. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@115997404
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/quic_connection_logger.cc ('k') | net/quic/quic_framer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/quic/quic_connection.h" 5 #include "net/quic/quic_connection.h"
6 6
7 #include <ostream> 7 #include <ostream>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 using QuicConnection::set_defer_send_in_response_to_packets; 584 using QuicConnection::set_defer_send_in_response_to_packets;
585 585
586 private: 586 private:
587 TestPacketWriter* writer() { 587 TestPacketWriter* writer() {
588 return static_cast<TestPacketWriter*>(QuicConnection::writer()); 588 return static_cast<TestPacketWriter*>(QuicConnection::writer());
589 } 589 }
590 590
591 DISALLOW_COPY_AND_ASSIGN(TestConnection); 591 DISALLOW_COPY_AND_ASSIGN(TestConnection);
592 }; 592 };
593 593
594 // Used for testing packets revived from FEC packets.
595 class FecQuicConnectionDebugVisitor : public QuicConnectionDebugVisitor {
596 public:
597 void OnRevivedPacket(const QuicPacketHeader& header,
598 StringPiece data) override {
599 revived_header_ = header;
600 }
601
602 // Public accessor method.
603 QuicPacketHeader revived_header() const { return revived_header_; }
604
605 private:
606 QuicPacketHeader revived_header_;
607 };
608
609 enum class AckResponse { kDefer, kImmediate }; 594 enum class AckResponse { kDefer, kImmediate };
610 595
611 // Run tests with combinations of {QuicVersion, AckResponse}. 596 // Run tests with combinations of {QuicVersion, AckResponse}.
612 struct TestParams { 597 struct TestParams {
613 TestParams(QuicVersion version, 598 TestParams(QuicVersion version,
614 AckResponse ack_response) 599 AckResponse ack_response)
615 : version(version), 600 : version(version),
616 ack_response(ack_response) {} 601 ack_response(ack_response) {}
617 602
618 friend ostream& operator<<(ostream& os, const TestParams& p) { 603 friend ostream& operator<<(ostream& os, const TestParams& p) {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 if (writer_->stop_waiting_frames().empty()) { 713 if (writer_->stop_waiting_frames().empty()) {
729 return 0; 714 return 0;
730 } 715 }
731 return writer_->stop_waiting_frames()[0].least_unacked; 716 return writer_->stop_waiting_frames()[0].least_unacked;
732 } 717 }
733 718
734 void use_tagging_decrypter() { writer_->use_tagging_decrypter(); } 719 void use_tagging_decrypter() { writer_->use_tagging_decrypter(); }
735 720
736 void ProcessPacket(QuicPathId path_id, QuicPacketNumber number) { 721 void ProcessPacket(QuicPathId path_id, QuicPacketNumber number) {
737 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); 722 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
738 ProcessDataPacket(path_id, number, 0, !kEntropyFlag); 723 ProcessDataPacket(path_id, number, !kEntropyFlag);
739 if (connection_.GetSendAlarm()->IsSet()) { 724 if (connection_.GetSendAlarm()->IsSet()) {
740 connection_.GetSendAlarm()->Fire(); 725 connection_.GetSendAlarm()->Fire();
741 } 726 }
742 } 727 }
743 728
744 QuicPacketEntropyHash ProcessFramePacket(QuicFrame frame) { 729 QuicPacketEntropyHash ProcessFramePacket(QuicFrame frame) {
745 return ProcessFramePacketWithAddresses(frame, kSelfAddress, kPeerAddress); 730 return ProcessFramePacketWithAddresses(frame, kSelfAddress, kPeerAddress);
746 } 731 }
747 732
748 QuicPacketEntropyHash ProcessFramePacketWithAddresses( 733 QuicPacketEntropyHash ProcessFramePacketWithAddresses(
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 size_t encrypted_length = framer_.EncryptPayload( 772 size_t encrypted_length = framer_.EncryptPayload(
788 level, path_id, number, *packet, buffer, kMaxPacketSize); 773 level, path_id, number, *packet, buffer, kMaxPacketSize);
789 connection_.ProcessUdpPacket( 774 connection_.ProcessUdpPacket(
790 kSelfAddress, kPeerAddress, 775 kSelfAddress, kPeerAddress,
791 QuicEncryptedPacket(buffer, encrypted_length, false)); 776 QuicEncryptedPacket(buffer, encrypted_length, false));
792 return base::checked_cast<QuicPacketEntropyHash>(encrypted_length); 777 return base::checked_cast<QuicPacketEntropyHash>(encrypted_length);
793 } 778 }
794 779
795 size_t ProcessDataPacket(QuicPathId path_id, 780 size_t ProcessDataPacket(QuicPathId path_id,
796 QuicPacketNumber number, 781 QuicPacketNumber number,
797 QuicFecGroupNumber fec_group,
798 bool entropy_flag) { 782 bool entropy_flag) {
799 return ProcessDataPacketAtLevel(path_id, number, fec_group, entropy_flag, 783 return ProcessDataPacketAtLevel(path_id, number, entropy_flag, false,
800 false, ENCRYPTION_NONE); 784 ENCRYPTION_NONE);
801 } 785 }
802 786
803 size_t ProcessDataPacketAtLevel(QuicPathId path_id, 787 size_t ProcessDataPacketAtLevel(QuicPathId path_id,
804 QuicPacketNumber number, 788 QuicPacketNumber number,
805 QuicFecGroupNumber fec_group,
806 bool entropy_flag, 789 bool entropy_flag,
807 bool has_stop_waiting, 790 bool has_stop_waiting,
808 EncryptionLevel level) { 791 EncryptionLevel level) {
809 scoped_ptr<QuicPacket> packet(ConstructDataPacket( 792 scoped_ptr<QuicPacket> packet(
810 path_id, number, fec_group, entropy_flag, has_stop_waiting)); 793 ConstructDataPacket(path_id, number, entropy_flag, has_stop_waiting));
811 char buffer[kMaxPacketSize]; 794 char buffer[kMaxPacketSize];
812 size_t encrypted_length = framer_.EncryptPayload( 795 size_t encrypted_length = framer_.EncryptPayload(
813 level, path_id, number, *packet, buffer, kMaxPacketSize); 796 level, path_id, number, *packet, buffer, kMaxPacketSize);
814 connection_.ProcessUdpPacket( 797 connection_.ProcessUdpPacket(
815 kSelfAddress, kPeerAddress, 798 kSelfAddress, kPeerAddress,
816 QuicEncryptedPacket(buffer, encrypted_length, false)); 799 QuicEncryptedPacket(buffer, encrypted_length, false));
817 if (connection_.GetSendAlarm()->IsSet()) { 800 if (connection_.GetSendAlarm()->IsSet()) {
818 connection_.GetSendAlarm()->Fire(); 801 connection_.GetSendAlarm()->Fire();
819 } 802 }
820 return encrypted_length; 803 return encrypted_length;
821 } 804 }
822 805
823 void ProcessClosePacket(QuicPathId path_id, 806 void ProcessClosePacket(QuicPathId path_id, QuicPacketNumber number) {
824 QuicPacketNumber number, 807 scoped_ptr<QuicPacket> packet(ConstructClosePacket(number));
825 QuicFecGroupNumber fec_group) {
826 scoped_ptr<QuicPacket> packet(ConstructClosePacket(number, fec_group));
827 char buffer[kMaxPacketSize]; 808 char buffer[kMaxPacketSize];
828 size_t encrypted_length = framer_.EncryptPayload( 809 size_t encrypted_length = framer_.EncryptPayload(
829 ENCRYPTION_NONE, path_id, number, *packet, buffer, kMaxPacketSize); 810 ENCRYPTION_NONE, path_id, number, *packet, buffer, kMaxPacketSize);
830 connection_.ProcessUdpPacket( 811 connection_.ProcessUdpPacket(
831 kSelfAddress, kPeerAddress, 812 kSelfAddress, kPeerAddress,
832 QuicEncryptedPacket(buffer, encrypted_length, false)); 813 QuicEncryptedPacket(buffer, encrypted_length, false));
833 } 814 }
834 815
835 size_t ProcessFecProtectedPacket(QuicPathId path_id,
836 QuicPacketNumber number,
837 bool expect_revival,
838 bool entropy_flag,
839 bool has_stop_waiting) {
840 return ProcessFecProtectedPacketAtLevel(path_id, number, 1, expect_revival,
841 entropy_flag, has_stop_waiting,
842 ENCRYPTION_NONE);
843 }
844
845 size_t ProcessFecProtectedPacketAtLevel(QuicPathId path_id,
846 QuicPacketNumber number,
847 QuicFecGroupNumber fec_group,
848 bool expect_revival,
849 bool entropy_flag,
850 bool has_stop_waiting,
851 EncryptionLevel level) {
852 if (expect_revival) {
853 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
854 }
855 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1).RetiresOnSaturation();
856 return ProcessDataPacketAtLevel(path_id, number, fec_group, entropy_flag,
857 has_stop_waiting, level);
858 }
859
860 // Processes an FEC packet that covers the packets that would have been
861 // received.
862 size_t ProcessFecPacket(QuicPathId path_id,
863 QuicPacketNumber number,
864 QuicPacketNumber min_protected_packet,
865 bool expect_revival,
866 bool entropy_flag,
867 QuicPacket* packet) {
868 return ProcessFecPacketAtLevel(path_id, number, min_protected_packet,
869 expect_revival, entropy_flag, packet,
870 ENCRYPTION_NONE);
871 }
872
873 // Processes an FEC packet that covers the packets that would have been
874 // received.
875 size_t ProcessFecPacketAtLevel(QuicPathId path_id,
876 QuicPacketNumber number,
877 QuicPacketNumber min_protected_packet,
878 bool expect_revival,
879 bool entropy_flag,
880 QuicPacket* packet,
881 EncryptionLevel level) {
882 if (expect_revival) {
883 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
884 }
885
886 // Construct the decrypted data packet so we can compute the correct
887 // redundancy. If |packet| has been provided then use that, otherwise
888 // construct a default data packet.
889 scoped_ptr<QuicPacket> data_packet;
890 if (packet) {
891 data_packet.reset(packet);
892 } else {
893 data_packet.reset(ConstructDataPacket(path_id, number, 1, !kEntropyFlag,
894 !kHasStopWaiting));
895 }
896
897 QuicPacketHeader header;
898 header.public_header.connection_id = connection_id_;
899 header.public_header.packet_number_length = packet_number_length_;
900 header.public_header.connection_id_length = connection_id_length_;
901 header.public_header.multipath_flag = path_id != kDefaultPathId;
902 header.path_id = path_id;
903 header.packet_number = number;
904 header.entropy_flag = entropy_flag;
905 header.fec_flag = true;
906 header.is_in_fec_group = IN_FEC_GROUP;
907 header.fec_group = min_protected_packet;
908
909 // Since all data packets in this test have the same payload, the
910 // redundancy is either equal to that payload or the xor of that payload
911 // with itself, depending on the number of packets.
912 if (((number - min_protected_packet) % 2) == 0) {
913 for (size_t i = GetStartOfFecProtectedData(
914 header.public_header.connection_id_length,
915 header.public_header.version_flag,
916 header.public_header.multipath_flag,
917 header.public_header.packet_number_length);
918 i < data_packet->length(); ++i) {
919 data_packet->mutable_data()[i] ^= data_packet->data()[i];
920 }
921 }
922
923 scoped_ptr<QuicPacket> fec_packet(
924 framer_.BuildFecPacket(header, data_packet->FecProtectedData()));
925 char buffer[kMaxPacketSize];
926 size_t encrypted_length = framer_.EncryptPayload(
927 level, path_id, number, *fec_packet, buffer, kMaxPacketSize);
928
929 connection_.ProcessUdpPacket(
930 kSelfAddress, kPeerAddress,
931 QuicEncryptedPacket(buffer, encrypted_length, false));
932 if (connection_.GetSendAlarm()->IsSet()) {
933 connection_.GetSendAlarm()->Fire();
934 }
935 return encrypted_length;
936 }
937
938 QuicByteCount SendStreamDataToPeer(QuicStreamId id, 816 QuicByteCount SendStreamDataToPeer(QuicStreamId id,
939 StringPiece data, 817 StringPiece data,
940 QuicStreamOffset offset, 818 QuicStreamOffset offset,
941 bool fin, 819 bool fin,
942 QuicPacketNumber* last_packet) { 820 QuicPacketNumber* last_packet) {
943 QuicByteCount packet_size; 821 QuicByteCount packet_size;
944 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 822 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
945 .WillOnce(DoAll(SaveArg<3>(&packet_size), Return(true))); 823 .WillOnce(DoAll(SaveArg<3>(&packet_size), Return(true)));
946 connection_.SendStreamDataWithString(id, data, offset, fin, nullptr); 824 connection_.SendStreamDataWithString(id, data, offset, fin, nullptr);
947 if (last_packet != nullptr) { 825 if (last_packet != nullptr) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 } 872 }
995 873
996 QuicPacket* ConstructPacket(QuicPacketHeader header, QuicFrames frames) { 874 QuicPacket* ConstructPacket(QuicPacketHeader header, QuicFrames frames) {
997 QuicPacket* packet = BuildUnsizedDataPacket(&framer_, header, frames); 875 QuicPacket* packet = BuildUnsizedDataPacket(&framer_, header, frames);
998 EXPECT_NE(nullptr, packet); 876 EXPECT_NE(nullptr, packet);
999 return packet; 877 return packet;
1000 } 878 }
1001 879
1002 QuicPacket* ConstructDataPacket(QuicPathId path_id, 880 QuicPacket* ConstructDataPacket(QuicPathId path_id,
1003 QuicPacketNumber number, 881 QuicPacketNumber number,
1004 QuicFecGroupNumber fec_group,
1005 bool entropy_flag, 882 bool entropy_flag,
1006 bool has_stop_waiting) { 883 bool has_stop_waiting) {
1007 QuicPacketHeader header; 884 QuicPacketHeader header;
1008 header.public_header.connection_id = connection_id_; 885 header.public_header.connection_id = connection_id_;
1009 header.public_header.packet_number_length = packet_number_length_; 886 header.public_header.packet_number_length = packet_number_length_;
1010 header.public_header.connection_id_length = connection_id_length_; 887 header.public_header.connection_id_length = connection_id_length_;
1011 header.public_header.multipath_flag = path_id != kDefaultPathId; 888 header.public_header.multipath_flag = path_id != kDefaultPathId;
1012 header.entropy_flag = entropy_flag; 889 header.entropy_flag = entropy_flag;
1013 header.path_id = path_id; 890 header.path_id = path_id;
1014 header.packet_number = number; 891 header.packet_number = number;
1015 header.is_in_fec_group = fec_group == 0u ? NOT_IN_FEC_GROUP : IN_FEC_GROUP; 892 header.is_in_fec_group = NOT_IN_FEC_GROUP;
1016 header.fec_group = fec_group; 893 header.fec_group = 0;
1017 894
1018 QuicFrames frames; 895 QuicFrames frames;
1019 frames.push_back(QuicFrame(&frame1_)); 896 frames.push_back(QuicFrame(&frame1_));
1020 if (has_stop_waiting) { 897 if (has_stop_waiting) {
1021 frames.push_back(QuicFrame(&stop_waiting_)); 898 frames.push_back(QuicFrame(&stop_waiting_));
1022 } 899 }
1023 return ConstructPacket(header, frames); 900 return ConstructPacket(header, frames);
1024 } 901 }
1025 902
1026 QuicPacket* ConstructClosePacket(QuicPacketNumber number, 903 QuicPacket* ConstructClosePacket(QuicPacketNumber number) {
1027 QuicFecGroupNumber fec_group) {
1028 QuicPacketHeader header; 904 QuicPacketHeader header;
1029 header.public_header.connection_id = connection_id_; 905 header.public_header.connection_id = connection_id_;
1030 header.packet_number = number; 906 header.packet_number = number;
1031 header.is_in_fec_group = fec_group == 0u ? NOT_IN_FEC_GROUP : IN_FEC_GROUP; 907 header.is_in_fec_group = NOT_IN_FEC_GROUP;
1032 header.fec_group = fec_group; 908 header.fec_group = 0;
1033 909
1034 QuicConnectionCloseFrame qccf; 910 QuicConnectionCloseFrame qccf;
1035 qccf.error_code = QUIC_PEER_GOING_AWAY; 911 qccf.error_code = QUIC_PEER_GOING_AWAY;
1036 912
1037 QuicFrames frames; 913 QuicFrames frames;
1038 frames.push_back(QuicFrame(&qccf)); 914 frames.push_back(QuicFrame(&qccf));
1039 return ConstructPacket(header, frames); 915 return ConstructPacket(header, frames);
1040 } 916 }
1041 917
1042 QuicTime::Delta DefaultRetransmissionTime() { 918 QuicTime::Delta DefaultRetransmissionTime() {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 frame->entropy_hash ^= 954 frame->entropy_hash ^=
1079 QuicConnectionPeer::PacketEntropy(&connection_, arrived); 955 QuicConnectionPeer::PacketEntropy(&connection_, arrived);
1080 } 956 }
1081 957
1082 void TriggerConnectionClose() { 958 void TriggerConnectionClose() {
1083 // Send an erroneous packet to close the connection. 959 // Send an erroneous packet to close the connection.
1084 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, 960 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_PACKET_HEADER,
1085 ConnectionCloseSource::FROM_SELF)); 961 ConnectionCloseSource::FROM_SELF));
1086 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a 962 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a
1087 // packet call to the visitor. 963 // packet call to the visitor.
1088 ProcessDataPacket(kDefaultPathId, 6000, 0, !kEntropyFlag); 964 ProcessDataPacket(kDefaultPathId, 6000, !kEntropyFlag);
1089 EXPECT_FALSE(QuicConnectionPeer::GetConnectionClosePacket(&connection_) == 965 EXPECT_FALSE(QuicConnectionPeer::GetConnectionClosePacket(&connection_) ==
1090 nullptr); 966 nullptr);
1091 } 967 }
1092 968
1093 void BlockOnNextWrite() { 969 void BlockOnNextWrite() {
1094 writer_->BlockOnNextWrite(); 970 writer_->BlockOnNextWrite();
1095 EXPECT_CALL(visitor_, OnWriteBlocked()).Times(AtLeast(1)); 971 EXPECT_CALL(visitor_, OnWriteBlocked()).Times(AtLeast(1));
1096 } 972 }
1097 973
1098 void SetWritePauseTimeDelta(QuicTime::Delta delta) { 974 void SetWritePauseTimeDelta(QuicTime::Delta delta) {
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
1325 TEST_P(QuicConnectionTest, DuplicatePacket) { 1201 TEST_P(QuicConnectionTest, DuplicatePacket) {
1326 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1202 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1327 1203
1328 ProcessPacket(kDefaultPathId, 3); 1204 ProcessPacket(kDefaultPathId, 3);
1329 EXPECT_EQ(3u, outgoing_ack()->largest_observed); 1205 EXPECT_EQ(3u, outgoing_ack()->largest_observed);
1330 EXPECT_TRUE(IsMissing(2)); 1206 EXPECT_TRUE(IsMissing(2));
1331 EXPECT_TRUE(IsMissing(1)); 1207 EXPECT_TRUE(IsMissing(1));
1332 1208
1333 // Send packet 3 again, but do not set the expectation that 1209 // Send packet 3 again, but do not set the expectation that
1334 // the visitor OnStreamFrame() will be called. 1210 // the visitor OnStreamFrame() will be called.
1335 ProcessDataPacket(kDefaultPathId, 3, 0, !kEntropyFlag); 1211 ProcessDataPacket(kDefaultPathId, 3, !kEntropyFlag);
1336 EXPECT_EQ(3u, outgoing_ack()->largest_observed); 1212 EXPECT_EQ(3u, outgoing_ack()->largest_observed);
1337 EXPECT_TRUE(IsMissing(2)); 1213 EXPECT_TRUE(IsMissing(2));
1338 EXPECT_TRUE(IsMissing(1)); 1214 EXPECT_TRUE(IsMissing(1));
1339 } 1215 }
1340 1216
1341 TEST_P(QuicConnectionTest, PacketsOutOfOrderWithAdditionsAndLeastAwaiting) { 1217 TEST_P(QuicConnectionTest, PacketsOutOfOrderWithAdditionsAndLeastAwaiting) {
1342 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1218 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1343 1219
1344 ProcessPacket(kDefaultPathId, 3); 1220 ProcessPacket(kDefaultPathId, 3);
1345 EXPECT_EQ(3u, outgoing_ack()->largest_observed); 1221 EXPECT_EQ(3u, outgoing_ack()->largest_observed);
(...skipping 20 matching lines...) Expand all
1366 // Force an ack to be sent. 1242 // Force an ack to be sent.
1367 SendAckPacketToPeer(); 1243 SendAckPacketToPeer();
1368 EXPECT_TRUE(IsMissing(4)); 1244 EXPECT_TRUE(IsMissing(4));
1369 } 1245 }
1370 1246
1371 TEST_P(QuicConnectionTest, RejectPacketTooFarOut) { 1247 TEST_P(QuicConnectionTest, RejectPacketTooFarOut) {
1372 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, 1248 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_PACKET_HEADER,
1373 ConnectionCloseSource::FROM_SELF)); 1249 ConnectionCloseSource::FROM_SELF));
1374 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a 1250 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a
1375 // packet call to the visitor. 1251 // packet call to the visitor.
1376 ProcessDataPacket(kDefaultPathId, 6000, 0, !kEntropyFlag); 1252 ProcessDataPacket(kDefaultPathId, 6000, !kEntropyFlag);
1377 EXPECT_FALSE(QuicConnectionPeer::GetConnectionClosePacket(&connection_) == 1253 EXPECT_FALSE(QuicConnectionPeer::GetConnectionClosePacket(&connection_) ==
1378 nullptr); 1254 nullptr);
1379 } 1255 }
1380 1256
1381 TEST_P(QuicConnectionTest, RejectUnencryptedStreamData) { 1257 TEST_P(QuicConnectionTest, RejectUnencryptedStreamData) {
1382 // Process an unencrypted packet from the non-crypto stream. 1258 // Process an unencrypted packet from the non-crypto stream.
1383 frame1_.stream_id = 3; 1259 frame1_.stream_id = 3;
1384 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1260 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1385 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_UNENCRYPTED_STREAM_DATA, 1261 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_UNENCRYPTED_STREAM_DATA,
1386 ConnectionCloseSource::FROM_SELF)); 1262 ConnectionCloseSource::FROM_SELF));
1387 EXPECT_DFATAL(ProcessDataPacket(kDefaultPathId, 1, 0, !kEntropyFlag), ""); 1263 EXPECT_DFATAL(ProcessDataPacket(kDefaultPathId, 1, !kEntropyFlag), "");
1388 EXPECT_FALSE(QuicConnectionPeer::GetConnectionClosePacket(&connection_) == 1264 EXPECT_FALSE(QuicConnectionPeer::GetConnectionClosePacket(&connection_) ==
1389 nullptr); 1265 nullptr);
1390 const vector<QuicConnectionCloseFrame>& connection_close_frames = 1266 const vector<QuicConnectionCloseFrame>& connection_close_frames =
1391 writer_->connection_close_frames(); 1267 writer_->connection_close_frames();
1392 EXPECT_EQ(1u, connection_close_frames.size()); 1268 EXPECT_EQ(1u, connection_close_frames.size());
1393 EXPECT_EQ(QUIC_UNENCRYPTED_STREAM_DATA, 1269 EXPECT_EQ(QUIC_UNENCRYPTED_STREAM_DATA,
1394 connection_close_frames[0].error_code); 1270 connection_close_frames[0].error_code);
1395 } 1271 }
1396 1272
1397 TEST_P(QuicConnectionTest, TruncatedAck) { 1273 TEST_P(QuicConnectionTest, TruncatedAck) {
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
1910 // Parse the last packet and ensure it's the stream frame from stream 3. 1786 // Parse the last packet and ensure it's the stream frame from stream 3.
1911 EXPECT_EQ(1u, writer_->frame_count()); 1787 EXPECT_EQ(1u, writer_->frame_count());
1912 ASSERT_EQ(1u, writer_->stream_frames().size()); 1788 ASSERT_EQ(1u, writer_->stream_frames().size());
1913 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0]->stream_id); 1789 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0]->stream_id);
1914 } 1790 }
1915 1791
1916 TEST_P(QuicConnectionTest, FramePackingAckResponse) { 1792 TEST_P(QuicConnectionTest, FramePackingAckResponse) {
1917 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1793 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1918 // Process a data packet to queue up a pending ack. 1794 // Process a data packet to queue up a pending ack.
1919 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); 1795 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
1920 ProcessDataPacket(kDefaultPathId, 1, 1, kEntropyFlag); 1796 ProcessDataPacket(kDefaultPathId, 1, kEntropyFlag);
1921 1797
1922 EXPECT_CALL(visitor_, OnCanWrite()) 1798 EXPECT_CALL(visitor_, OnCanWrite())
1923 .WillOnce(DoAll(IgnoreResult(InvokeWithoutArgs( 1799 .WillOnce(DoAll(IgnoreResult(InvokeWithoutArgs(
1924 &connection_, &TestConnection::SendStreamData3)), 1800 &connection_, &TestConnection::SendStreamData3)),
1925 IgnoreResult(InvokeWithoutArgs( 1801 IgnoreResult(InvokeWithoutArgs(
1926 &connection_, &TestConnection::SendStreamData5)))); 1802 &connection_, &TestConnection::SendStreamData5))));
1927 1803
1928 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 1804 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
1929 1805
1930 // Process an ack to cause the visitor's OnCanWrite to be invoked. 1806 // Process an ack to cause the visitor's OnCanWrite to be invoked.
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
2533 2409
2534 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 2410 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
2535 frame = InitAckFrame(7); 2411 frame = InitAckFrame(7);
2536 NackPacket(5, &frame); 2412 NackPacket(5, &frame);
2537 NackPacket(6, &frame); 2413 NackPacket(6, &frame);
2538 ProcessAckPacket(&frame); 2414 ProcessAckPacket(&frame);
2539 2415
2540 EXPECT_EQ(6u, stop_waiting()->least_unacked); 2416 EXPECT_EQ(6u, stop_waiting()->least_unacked);
2541 } 2417 }
2542 2418
2543 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterFecPacket) {
2544 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2545
2546 // Don't send missing packet 1.
2547 ProcessFecPacket(kDefaultPathId, 2, 1, true, !kEntropyFlag, nullptr);
2548 // Entropy flag should be false, so entropy should be 0.
2549 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2));
2550 }
2551
2552 TEST_P(QuicConnectionTest, ReviveMissingPacketWithVaryingSeqNumLengths) {
2553 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2554
2555 // Set up a debug visitor to the connection.
2556 scoped_ptr<FecQuicConnectionDebugVisitor> fec_visitor(
2557 new FecQuicConnectionDebugVisitor());
2558 connection_.set_debug_visitor(fec_visitor.get());
2559
2560 QuicPacketNumber fec_packet = 0;
2561 // clang-format off
2562 QuicPacketNumberLength lengths[] = {
2563 PACKET_6BYTE_PACKET_NUMBER, PACKET_4BYTE_PACKET_NUMBER,
2564 PACKET_2BYTE_PACKET_NUMBER, PACKET_1BYTE_PACKET_NUMBER};
2565 // clang-format on
2566 // For each packet number length size, revive a packet and check sequence
2567 // number length in the revived packet.
2568 for (size_t i = 0; i < arraysize(lengths); ++i) {
2569 // Set packet_number_length_ (for data and FEC packets).
2570 packet_number_length_ = lengths[i];
2571 fec_packet += 2;
2572 // Don't send missing packet, but send fec packet right after it.
2573 ProcessFecPacket(kDefaultPathId, fec_packet, fec_packet - 1, true,
2574 !kEntropyFlag, nullptr);
2575 // packet number length in the revived header should be the same as
2576 // in the original data/fec packet headers.
2577 EXPECT_EQ(packet_number_length_,
2578 fec_visitor->revived_header().public_header.packet_number_length);
2579 }
2580 }
2581
2582 TEST_P(QuicConnectionTest, ReviveMissingPacketWithVaryingConnectionIdLengths) {
2583 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2584
2585 // Set up a debug visitor to the connection.
2586 scoped_ptr<FecQuicConnectionDebugVisitor> fec_visitor(
2587 new FecQuicConnectionDebugVisitor());
2588 connection_.set_debug_visitor(fec_visitor.get());
2589
2590 QuicPacketNumber fec_packet = 0;
2591 QuicConnectionIdLength lengths[] = {
2592 PACKET_8BYTE_CONNECTION_ID, PACKET_4BYTE_CONNECTION_ID,
2593 PACKET_1BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID};
2594 // For each connection id length size, revive a packet and check connection
2595 // id length in the revived packet.
2596 for (size_t i = 0; i < arraysize(lengths); ++i) {
2597 // Set connection id length (for data and FEC packets).
2598 connection_id_length_ = lengths[i];
2599 fec_packet += 2;
2600 // Don't send missing packet, but send fec packet right after it.
2601 ProcessFecPacket(kDefaultPathId, fec_packet, fec_packet - 1, true,
2602 !kEntropyFlag, nullptr);
2603 // Connection id length in the revived header should be the same as
2604 // in the original data/fec packet headers.
2605 EXPECT_EQ(connection_id_length_,
2606 fec_visitor->revived_header().public_header.connection_id_length);
2607 }
2608 }
2609
2610 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPacketThenFecPacket) {
2611 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2612
2613 ProcessFecProtectedPacket(kDefaultPathId, 1, false, kEntropyFlag,
2614 !kHasStopWaiting);
2615 // Don't send missing packet 2.
2616 ProcessFecPacket(kDefaultPathId, 3, 1, true, !kEntropyFlag, nullptr);
2617 // Entropy flag should be true, so entropy should not be 0.
2618 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2));
2619 }
2620
2621 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPacketsThenFecPacket) {
2622 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2623
2624 ProcessFecProtectedPacket(kDefaultPathId, 1, false, !kEntropyFlag,
2625 !kHasStopWaiting);
2626 // Don't send missing packet 2.
2627 ProcessFecProtectedPacket(kDefaultPathId, 3, false, !kEntropyFlag,
2628 !kHasStopWaiting);
2629 ProcessFecPacket(kDefaultPathId, 4, 1, true, kEntropyFlag, nullptr);
2630 // Ensure QUIC no longer revives entropy for lost packets.
2631 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2));
2632 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 4));
2633 }
2634
2635 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPacket) {
2636 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2637
2638 // Don't send missing packet 1.
2639 ProcessFecPacket(kDefaultPathId, 3, 1, false, !kEntropyFlag, nullptr);
2640 // Out of order.
2641 ProcessFecProtectedPacket(kDefaultPathId, 2, true, !kEntropyFlag,
2642 !kHasStopWaiting);
2643 // Entropy flag should be false, so entropy should be 0.
2644 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2));
2645 }
2646
2647 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPackets) {
2648 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2649
2650 ProcessFecProtectedPacket(kDefaultPathId, 1, false, !kEntropyFlag,
2651 !kHasStopWaiting);
2652 // Don't send missing packet 2.
2653 ProcessFecPacket(kDefaultPathId, 6, 1, false, kEntropyFlag, nullptr);
2654 ProcessFecProtectedPacket(kDefaultPathId, 3, false, kEntropyFlag,
2655 !kHasStopWaiting);
2656 ProcessFecProtectedPacket(kDefaultPathId, 4, false, kEntropyFlag,
2657 !kHasStopWaiting);
2658 ProcessFecProtectedPacket(kDefaultPathId, 5, true, !kEntropyFlag,
2659 !kHasStopWaiting);
2660 // Ensure entropy is not revived for the missing packet.
2661 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2));
2662 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 3));
2663 }
2664
2665 TEST_P(QuicConnectionTest, TLP) { 2419 TEST_P(QuicConnectionTest, TLP) {
2666 QuicSentPacketManagerPeer::SetMaxTailLossProbes(manager_, 1); 2420 QuicSentPacketManagerPeer::SetMaxTailLossProbes(manager_, 1);
2667 2421
2668 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr); 2422 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr);
2669 EXPECT_EQ(1u, stop_waiting()->least_unacked); 2423 EXPECT_EQ(1u, stop_waiting()->least_unacked);
2670 QuicTime retransmission_time = 2424 QuicTime retransmission_time =
2671 connection_.GetRetransmissionAlarm()->deadline(); 2425 connection_.GetRetransmissionAlarm()->deadline();
2672 EXPECT_NE(QuicTime::Zero(), retransmission_time); 2426 EXPECT_NE(QuicTime::Zero(), retransmission_time);
2673 2427
2674 EXPECT_EQ(1u, writer_->header().packet_number); 2428 EXPECT_EQ(1u, writer_->header().packet_number);
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
2863 QuicConfig config; 2617 QuicConfig config;
2864 connection_.SetFromConfig(config); 2618 connection_.SetFromConfig(config);
2865 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2619 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2866 use_tagging_decrypter(); 2620 use_tagging_decrypter();
2867 2621
2868 const uint8_t tag = 0x07; 2622 const uint8_t tag = 0x07;
2869 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); 2623 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
2870 2624
2871 // Process an encrypted packet which can not yet be decrypted which should 2625 // Process an encrypted packet which can not yet be decrypted which should
2872 // result in the packet being buffered. 2626 // result in the packet being buffered.
2873 ProcessDataPacketAtLevel(kDefaultPathId, 1, 0, kEntropyFlag, !kHasStopWaiting, 2627 ProcessDataPacketAtLevel(kDefaultPathId, 1, kEntropyFlag, !kHasStopWaiting,
2874 ENCRYPTION_INITIAL); 2628 ENCRYPTION_INITIAL);
2875 2629
2876 // Transition to the new encryption state and process another encrypted packet 2630 // Transition to the new encryption state and process another encrypted packet
2877 // which should result in the original packet being processed. 2631 // which should result in the original packet being processed.
2878 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); 2632 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag));
2879 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); 2633 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
2880 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); 2634 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
2881 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(2); 2635 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(2);
2882 ProcessDataPacketAtLevel(kDefaultPathId, 2, 0, kEntropyFlag, !kHasStopWaiting, 2636 ProcessDataPacketAtLevel(kDefaultPathId, 2, kEntropyFlag, !kHasStopWaiting,
2883 ENCRYPTION_INITIAL); 2637 ENCRYPTION_INITIAL);
2884 2638
2885 // Finally, process a third packet and note that we do not reprocess the 2639 // Finally, process a third packet and note that we do not reprocess the
2886 // buffered packet. 2640 // buffered packet.
2887 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); 2641 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
2888 ProcessDataPacketAtLevel(kDefaultPathId, 3, 0, kEntropyFlag, !kHasStopWaiting, 2642 ProcessDataPacketAtLevel(kDefaultPathId, 3, kEntropyFlag, !kHasStopWaiting,
2889 ENCRYPTION_INITIAL); 2643 ENCRYPTION_INITIAL);
2890 } 2644 }
2891 2645
2892 TEST_P(QuicConnectionTest, ProcessBufferedFECGroup) {
2893 // SetFromConfig is always called after construction from InitializeSession.
2894 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _));
2895 QuicConfig config;
2896 config.set_max_undecryptable_packets(100);
2897 connection_.SetFromConfig(config);
2898 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2899 use_tagging_decrypter();
2900
2901 const uint8_t tag = 0x07;
2902 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
2903
2904 // Don't send packet 1 and buffer initially encrypted packets.
2905 ProcessFecProtectedPacketAtLevel(kDefaultPathId, 2, 1, false, !kEntropyFlag,
2906 !kHasStopWaiting, ENCRYPTION_INITIAL);
2907 ProcessFecPacketAtLevel(kDefaultPathId, 3, 1, false, kEntropyFlag, nullptr,
2908 ENCRYPTION_INITIAL);
2909 // Since the packets were buffered, no FEC group should be open.
2910 ASSERT_EQ(0u, connection_.NumFecGroups());
2911
2912 // Now send non-fec protected ack packet and close the group.
2913 QuicStopWaitingFrame frame = InitStopWaitingFrame(4);
2914 ProcessStopWaitingPacketAtLevel(kDefaultPathId, 4, &frame,
2915 ENCRYPTION_INITIAL);
2916
2917 // Transition to the new encryption state and process another encrypted packet
2918 // which should result in the original packets being processed. The missing
2919 // packet should be revived before the STOP_WAITING packet is processed.
2920 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag));
2921 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
2922 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
2923
2924 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(2).RetiresOnSaturation();
2925 ProcessDataPacketAtLevel(kDefaultPathId, 5, 0, kEntropyFlag, !kHasStopWaiting,
2926 ENCRYPTION_INITIAL);
2927 const QuicConnectionStats& stats = connection_.GetStats();
2928 EXPECT_EQ(1u, stats.packets_revived);
2929 }
2930
2931 TEST_P(QuicConnectionTest, Buffer100NonDecryptablePackets) { 2646 TEST_P(QuicConnectionTest, Buffer100NonDecryptablePackets) {
2932 // SetFromConfig is always called after construction from InitializeSession. 2647 // SetFromConfig is always called after construction from InitializeSession.
2933 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); 2648 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _));
2934 QuicConfig config; 2649 QuicConfig config;
2935 config.set_max_undecryptable_packets(100); 2650 config.set_max_undecryptable_packets(100);
2936 connection_.SetFromConfig(config); 2651 connection_.SetFromConfig(config);
2937 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2652 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2938 use_tagging_decrypter(); 2653 use_tagging_decrypter();
2939 2654
2940 const uint8_t tag = 0x07; 2655 const uint8_t tag = 0x07;
2941 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); 2656 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
2942 2657
2943 // Process an encrypted packet which can not yet be decrypted which should 2658 // Process an encrypted packet which can not yet be decrypted which should
2944 // result in the packet being buffered. 2659 // result in the packet being buffered.
2945 for (QuicPacketNumber i = 1; i <= 100; ++i) { 2660 for (QuicPacketNumber i = 1; i <= 100; ++i) {
2946 ProcessDataPacketAtLevel(kDefaultPathId, i, 0, kEntropyFlag, 2661 ProcessDataPacketAtLevel(kDefaultPathId, i, kEntropyFlag, !kHasStopWaiting,
2947 !kHasStopWaiting, ENCRYPTION_INITIAL); 2662 ENCRYPTION_INITIAL);
2948 } 2663 }
2949 2664
2950 // Transition to the new encryption state and process another encrypted packet 2665 // Transition to the new encryption state and process another encrypted packet
2951 // which should result in the original packets being processed. 2666 // which should result in the original packets being processed.
2952 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); 2667 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag));
2953 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); 2668 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
2954 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); 2669 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
2955 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(101); 2670 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(101);
2956 ProcessDataPacketAtLevel(kDefaultPathId, 101, 0, kEntropyFlag, 2671 ProcessDataPacketAtLevel(kDefaultPathId, 101, kEntropyFlag, !kHasStopWaiting,
2957 !kHasStopWaiting, ENCRYPTION_INITIAL); 2672 ENCRYPTION_INITIAL);
2958 2673
2959 // Finally, process a third packet and note that we do not reprocess the 2674 // Finally, process a third packet and note that we do not reprocess the
2960 // buffered packet. 2675 // buffered packet.
2961 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); 2676 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
2962 ProcessDataPacketAtLevel(kDefaultPathId, 102, 0, kEntropyFlag, 2677 ProcessDataPacketAtLevel(kDefaultPathId, 102, kEntropyFlag, !kHasStopWaiting,
2963 !kHasStopWaiting, ENCRYPTION_INITIAL); 2678 ENCRYPTION_INITIAL);
2964 } 2679 }
2965 2680
2966 TEST_P(QuicConnectionTest, TestRetransmitOrder) { 2681 TEST_P(QuicConnectionTest, TestRetransmitOrder) {
2967 QuicByteCount first_packet_size; 2682 QuicByteCount first_packet_size;
2968 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 2683 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
2969 .WillOnce(DoAll(SaveArg<3>(&first_packet_size), Return(true))); 2684 .WillOnce(DoAll(SaveArg<3>(&first_packet_size), Return(true)));
2970 2685
2971 connection_.SendStreamDataWithString(3, "first_packet", 0, !kFin, nullptr); 2686 connection_.SendStreamDataWithString(3, "first_packet", 0, !kFin, nullptr);
2972 QuicByteCount second_packet_size; 2687 QuicByteCount second_packet_size;
2973 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 2688 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
3049 BlockOnNextWrite(); 2764 BlockOnNextWrite();
3050 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); 2765 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr);
3051 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2766 EXPECT_EQ(1u, connection_.NumQueuedPackets());
3052 2767
3053 // Unblock the writes and actually send. 2768 // Unblock the writes and actually send.
3054 writer_->SetWritable(); 2769 writer_->SetWritable();
3055 connection_.OnCanWrite(); 2770 connection_.OnCanWrite();
3056 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2771 EXPECT_EQ(0u, connection_.NumQueuedPackets());
3057 } 2772 }
3058 2773
3059 TEST_P(QuicConnectionTest, CloseFecGroup) {
3060 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3061 // Don't send missing packet 1.
3062 // Don't send missing packet 2.
3063 ProcessFecProtectedPacket(kDefaultPathId, 3, false, !kEntropyFlag,
3064 !kHasStopWaiting);
3065 // Don't send missing FEC packet 3.
3066 ASSERT_EQ(1u, connection_.NumFecGroups());
3067
3068 // Now send non-fec protected ack packet and close the group.
3069 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 4);
3070 QuicStopWaitingFrame frame = InitStopWaitingFrame(5);
3071 ProcessStopWaitingPacket(&frame);
3072 ASSERT_EQ(0u, connection_.NumFecGroups());
3073 }
3074
3075 TEST_P(QuicConnectionTest,
3076 CloseFecGroupUnderStopWaitingAndWaitingForPacketsBelowStopWaiting) {
3077 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3078 // Don't send missing packet 1.
3079 ProcessFecProtectedPacket(kDefaultPathId, 2, false, !kEntropyFlag,
3080 !kHasStopWaiting);
3081 EXPECT_EQ(1u, connection_.NumFecGroups());
3082 stop_waiting_ = InitStopWaitingFrame(2);
3083 ProcessFecProtectedPacket(kDefaultPathId, 3, false, !kEntropyFlag,
3084 kHasStopWaiting);
3085 // This Fec group would be closed.
3086 EXPECT_EQ(0u, connection_.NumFecGroups());
3087 }
3088
3089 TEST_P(QuicConnectionTest,
3090 DoNotCloseFecGroupUnderStopWaitingButNotWaitingForPacketsBelow) {
3091 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3092 ProcessFecProtectedPacket(kDefaultPathId, 1, false, !kEntropyFlag,
3093 !kHasStopWaiting);
3094 ProcessFecProtectedPacket(kDefaultPathId, 2, false, !kEntropyFlag,
3095 !kHasStopWaiting);
3096 // Don't send missing packet 3.
3097 EXPECT_EQ(1u, connection_.NumFecGroups());
3098 stop_waiting_ = InitStopWaitingFrame(2);
3099 ProcessFecProtectedPacket(kDefaultPathId, 3, false, !kEntropyFlag,
3100 kHasStopWaiting);
3101 // This group will not be closed because this group is not waiting for packets
3102 // below stop waiting.
3103 EXPECT_EQ(1u, connection_.NumFecGroups());
3104 }
3105
3106 TEST_P(QuicConnectionTest, InitialTimeout) { 2774 TEST_P(QuicConnectionTest, InitialTimeout) {
3107 EXPECT_TRUE(connection_.connected()); 2775 EXPECT_TRUE(connection_.connected());
3108 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber()); 2776 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber());
3109 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); 2777 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
3110 2778
3111 // SetFromConfig sets the initial timeouts before negotiation. 2779 // SetFromConfig sets the initial timeouts before negotiation.
3112 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); 2780 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _));
3113 QuicConfig config; 2781 QuicConfig config;
3114 connection_.SetFromConfig(config); 2782 connection_.SetFromConfig(config);
3115 // Subtract a second from the idle timeout on the client side. 2783 // Subtract a second from the idle timeout on the client side.
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
3661 nullptr); 3329 nullptr);
3662 connection_.GetTimeoutAlarm()->Fire(); 3330 connection_.GetTimeoutAlarm()->Fire();
3663 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(1)); 3331 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(1));
3664 } 3332 }
3665 EXPECT_FALSE(connection_.connected()); 3333 EXPECT_FALSE(connection_.connected());
3666 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); 3334 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
3667 } 3335 }
3668 3336
3669 TEST_P(QuicConnectionTest, SendScheduler) { 3337 TEST_P(QuicConnectionTest, SendScheduler) {
3670 // Test that if we send a packet without delay, it is not queued. 3338 // Test that if we send a packet without delay, it is not queued.
3671 QuicPacket* packet = ConstructDataPacket(kDefaultPathId, 1, 0, !kEntropyFlag, 3339 QuicPacket* packet =
3672 !kHasStopWaiting); 3340 ConstructDataPacket(kDefaultPathId, 1, !kEntropyFlag, !kHasStopWaiting);
3673 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 3341 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
3674 connection_.SendPacket(ENCRYPTION_NONE, kDefaultPathId, 1, packet, 3342 connection_.SendPacket(ENCRYPTION_NONE, kDefaultPathId, 1, packet,
3675 kTestEntropyHash, HAS_RETRANSMITTABLE_DATA, false, 3343 kTestEntropyHash, HAS_RETRANSMITTABLE_DATA, false,
3676 false); 3344 false);
3677 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 3345 EXPECT_EQ(0u, connection_.NumQueuedPackets());
3678 } 3346 }
3679 3347
3680 TEST_P(QuicConnectionTest, FailToSendFirstPacket) { 3348 TEST_P(QuicConnectionTest, FailToSendFirstPacket) {
3681 // Test that the connection does not crash when it fails to send the first 3349 // Test that the connection does not crash when it fails to send the first
3682 // packet at which point self_address_ might be uninitialized. 3350 // packet at which point self_address_ might be uninitialized.
3683 EXPECT_CALL(visitor_, OnConnectionClosed(_, _)).Times(1); 3351 EXPECT_CALL(visitor_, OnConnectionClosed(_, _)).Times(1);
3684 QuicPacket* packet = ConstructDataPacket(kDefaultPathId, 1, 0, !kEntropyFlag, 3352 QuicPacket* packet =
3685 !kHasStopWaiting); 3353 ConstructDataPacket(kDefaultPathId, 1, !kEntropyFlag, !kHasStopWaiting);
3686 writer_->SetShouldWriteFail(); 3354 writer_->SetShouldWriteFail();
3687 connection_.SendPacket(ENCRYPTION_NONE, kDefaultPathId, 1, packet, 3355 connection_.SendPacket(ENCRYPTION_NONE, kDefaultPathId, 1, packet,
3688 kTestEntropyHash, HAS_RETRANSMITTABLE_DATA, false, 3356 kTestEntropyHash, HAS_RETRANSMITTABLE_DATA, false,
3689 false); 3357 false);
3690 } 3358 }
3691 3359
3692 TEST_P(QuicConnectionTest, SendSchedulerEAGAIN) { 3360 TEST_P(QuicConnectionTest, SendSchedulerEAGAIN) {
3693 QuicPacket* packet = ConstructDataPacket(kDefaultPathId, 1, 0, !kEntropyFlag, 3361 QuicPacket* packet =
3694 !kHasStopWaiting); 3362 ConstructDataPacket(kDefaultPathId, 1, !kEntropyFlag, !kHasStopWaiting);
3695 BlockOnNextWrite(); 3363 BlockOnNextWrite();
3696 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 1, _, _)).Times(0); 3364 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 1, _, _)).Times(0);
3697 connection_.SendPacket(ENCRYPTION_NONE, kDefaultPathId, 1, packet, 3365 connection_.SendPacket(ENCRYPTION_NONE, kDefaultPathId, 1, packet,
3698 kTestEntropyHash, HAS_RETRANSMITTABLE_DATA, false, 3366 kTestEntropyHash, HAS_RETRANSMITTABLE_DATA, false,
3699 false); 3367 false);
3700 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 3368 EXPECT_EQ(1u, connection_.NumQueuedPackets());
3701 } 3369 }
3702 3370
3703 TEST_P(QuicConnectionTest, TestQueueLimitsOnSendStreamData) { 3371 TEST_P(QuicConnectionTest, TestQueueLimitsOnSendStreamData) {
3704 // All packets carry version info till version is negotiated. 3372 // All packets carry version info till version is negotiated.
3705 size_t payload_length; 3373 size_t payload_length;
3706 size_t length = GetPacketLengthForOneStream( 3374 size_t length = GetPacketLengthForOneStream(
3707 connection_.version(), kIncludeVersion, !kIncludePathId, 3375 connection_.version(), kIncludeVersion, !kIncludePathId,
3708 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_PACKET_NUMBER, NOT_IN_FEC_GROUP, 3376 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_PACKET_NUMBER, &payload_length);
3709 &payload_length);
3710 connection_.SetMaxPacketLength(length); 3377 connection_.SetMaxPacketLength(length);
3711 3378
3712 // Queue the first packet. 3379 // Queue the first packet.
3713 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _)) 3380 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _))
3714 .WillOnce(testing::Return(QuicTime::Delta::FromMicroseconds(10))); 3381 .WillOnce(testing::Return(QuicTime::Delta::FromMicroseconds(10)));
3715 const string payload(payload_length, 'a'); 3382 const string payload(payload_length, 'a');
3716 EXPECT_EQ(0u, 3383 EXPECT_EQ(0u,
3717 connection_.SendStreamDataWithString(3, payload, 0, !kFin, nullptr) 3384 connection_.SendStreamDataWithString(3, payload, 0, !kFin, nullptr)
3718 .bytes_consumed); 3385 .bytes_consumed);
3719 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 3386 EXPECT_EQ(0u, connection_.NumQueuedPackets());
3720 } 3387 }
3721 3388
3722 TEST_P(QuicConnectionTest, LoopThroughSendingPackets) { 3389 TEST_P(QuicConnectionTest, LoopThroughSendingPackets) {
3723 // All packets carry version info till version is negotiated. 3390 // All packets carry version info till version is negotiated.
3724 size_t payload_length; 3391 size_t payload_length;
3725 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining 3392 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining
3726 // packet length. The size of the offset field in a stream frame is 0 for 3393 // packet length. The size of the offset field in a stream frame is 0 for
3727 // offset 0, and 2 for non-zero offsets up through 16K. Increase 3394 // offset 0, and 2 for non-zero offsets up through 16K. Increase
3728 // max_packet_length by 2 so that subsequent packets containing subsequent 3395 // max_packet_length by 2 so that subsequent packets containing subsequent
3729 // stream frames with non-zero offets will fit within the packet length. 3396 // stream frames with non-zero offets will fit within the packet length.
3730 size_t length = 3397 size_t length = 2 + GetPacketLengthForOneStream(
3731 2 + GetPacketLengthForOneStream( 3398 connection_.version(), kIncludeVersion,
3732 connection_.version(), kIncludeVersion, !kIncludePathId, 3399 !kIncludePathId, PACKET_8BYTE_CONNECTION_ID,
3733 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_PACKET_NUMBER, 3400 PACKET_1BYTE_PACKET_NUMBER, &payload_length);
3734 NOT_IN_FEC_GROUP, &payload_length);
3735 connection_.SetMaxPacketLength(length); 3401 connection_.SetMaxPacketLength(length);
3736 3402
3737 // Queue the first packet. 3403 // Queue the first packet.
3738 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(7); 3404 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(7);
3739 // The first stream frame will have 2 fewer overhead bytes than the other six. 3405 // The first stream frame will have 2 fewer overhead bytes than the other six.
3740 const string payload(payload_length * 7 + 2, 'a'); 3406 const string payload(payload_length * 7 + 2, 'a');
3741 EXPECT_EQ(payload.size(), 3407 EXPECT_EQ(payload.size(),
3742 connection_.SendStreamDataWithString(1, payload, 0, !kFin, nullptr) 3408 connection_.SendStreamDataWithString(1, payload, 0, !kFin, nullptr)
3743 .bytes_consumed); 3409 .bytes_consumed);
3744 } 3410 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
3797 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 3463 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
3798 const uint8_t tag = 0x07; 3464 const uint8_t tag = 0x07;
3799 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); 3465 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag));
3800 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); 3466 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
3801 // Process a packet from the non-crypto stream. 3467 // Process a packet from the non-crypto stream.
3802 frame1_.stream_id = 3; 3468 frame1_.stream_id = 3;
3803 3469
3804 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used 3470 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used
3805 // instead of ENCRYPTION_NONE. 3471 // instead of ENCRYPTION_NONE.
3806 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); 3472 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
3807 ProcessDataPacketAtLevel(kDefaultPathId, 1, 0, !kEntropyFlag, 3473 ProcessDataPacketAtLevel(kDefaultPathId, 1, !kEntropyFlag, !kHasStopWaiting,
3808 !kHasStopWaiting, ENCRYPTION_INITIAL); 3474 ENCRYPTION_INITIAL);
3809 3475
3810 // Check if delayed ack timer is running for the expected interval. 3476 // Check if delayed ack timer is running for the expected interval.
3811 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); 3477 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
3812 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); 3478 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline());
3813 // Simulate delayed ack alarm firing. 3479 // Simulate delayed ack alarm firing.
3814 connection_.GetAckAlarm()->Fire(); 3480 connection_.GetAckAlarm()->Fire();
3815 // Check that ack is sent and that delayed ack alarm is reset. 3481 // Check that ack is sent and that delayed ack alarm is reset.
3816 EXPECT_EQ(2u, writer_->frame_count()); 3482 EXPECT_EQ(2u, writer_->frame_count());
3817 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); 3483 EXPECT_FALSE(writer_->stop_waiting_frames().empty());
3818 EXPECT_FALSE(writer_->ack_frames().empty()); 3484 EXPECT_FALSE(writer_->ack_frames().empty());
(...skipping 16 matching lines...) Expand all
3835 const uint8_t tag = 0x07; 3501 const uint8_t tag = 0x07;
3836 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); 3502 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag));
3837 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); 3503 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
3838 // Process a packet from the non-crypto stream. 3504 // Process a packet from the non-crypto stream.
3839 frame1_.stream_id = 3; 3505 frame1_.stream_id = 3;
3840 3506
3841 // Process all the initial packets in order so there aren't missing packets. 3507 // Process all the initial packets in order so there aren't missing packets.
3842 QuicPacketNumber kFirstDecimatedPacket = 101; 3508 QuicPacketNumber kFirstDecimatedPacket = 101;
3843 for (unsigned int i = 0; i < kFirstDecimatedPacket - 1; ++i) { 3509 for (unsigned int i = 0; i < kFirstDecimatedPacket - 1; ++i) {
3844 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); 3510 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
3845 ProcessDataPacketAtLevel(kDefaultPathId, 1 + i, 0, !kEntropyFlag, 3511 ProcessDataPacketAtLevel(kDefaultPathId, 1 + i, !kEntropyFlag,
3846 !kHasStopWaiting, ENCRYPTION_INITIAL); 3512 !kHasStopWaiting, ENCRYPTION_INITIAL);
3847 } 3513 }
3848 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 3514 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
3849 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used 3515 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used
3850 // instead of ENCRYPTION_NONE. 3516 // instead of ENCRYPTION_NONE.
3851 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); 3517 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
3852 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket, 0, 3518 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket, !kEntropyFlag,
3853 !kEntropyFlag, !kHasStopWaiting, ENCRYPTION_INITIAL); 3519 !kHasStopWaiting, ENCRYPTION_INITIAL);
3854 3520
3855 // Check if delayed ack timer is running for the expected interval. 3521 // Check if delayed ack timer is running for the expected interval.
3856 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); 3522 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
3857 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); 3523 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline());
3858 3524
3859 // The 10th received packet causes an ack to be sent. 3525 // The 10th received packet causes an ack to be sent.
3860 for (int i = 0; i < 9; ++i) { 3526 for (int i = 0; i < 9; ++i) {
3861 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); 3527 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
3862 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); 3528 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
3863 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 1 + i, 0, 3529 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 1 + i,
3864 !kEntropyFlag, !kHasStopWaiting, 3530 !kEntropyFlag, !kHasStopWaiting,
3865 ENCRYPTION_INITIAL); 3531 ENCRYPTION_INITIAL);
3866 } 3532 }
3867 // Check that ack is sent and that delayed ack alarm is reset. 3533 // Check that ack is sent and that delayed ack alarm is reset.
3868 EXPECT_EQ(2u, writer_->frame_count()); 3534 EXPECT_EQ(2u, writer_->frame_count());
3869 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); 3535 EXPECT_FALSE(writer_->stop_waiting_frames().empty());
3870 EXPECT_FALSE(writer_->ack_frames().empty()); 3536 EXPECT_FALSE(writer_->ack_frames().empty());
3871 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 3537 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
3872 } 3538 }
3873 3539
(...skipping 15 matching lines...) Expand all
3889 const uint8_t tag = 0x07; 3555 const uint8_t tag = 0x07;
3890 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); 3556 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag));
3891 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); 3557 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
3892 // Process a packet from the non-crypto stream. 3558 // Process a packet from the non-crypto stream.
3893 frame1_.stream_id = 3; 3559 frame1_.stream_id = 3;
3894 3560
3895 // Process all the initial packets in order so there aren't missing packets. 3561 // Process all the initial packets in order so there aren't missing packets.
3896 QuicPacketNumber kFirstDecimatedPacket = 101; 3562 QuicPacketNumber kFirstDecimatedPacket = 101;
3897 for (unsigned int i = 0; i < kFirstDecimatedPacket - 1; ++i) { 3563 for (unsigned int i = 0; i < kFirstDecimatedPacket - 1; ++i) {
3898 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); 3564 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
3899 ProcessDataPacketAtLevel(kDefaultPathId, 1 + i, 0, !kEntropyFlag, 3565 ProcessDataPacketAtLevel(kDefaultPathId, 1 + i, !kEntropyFlag,
3900 !kHasStopWaiting, ENCRYPTION_INITIAL); 3566 !kHasStopWaiting, ENCRYPTION_INITIAL);
3901 } 3567 }
3902 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 3568 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
3903 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used 3569 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used
3904 // instead of ENCRYPTION_NONE. 3570 // instead of ENCRYPTION_NONE.
3905 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); 3571 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
3906 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket, 0, 3572 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket, !kEntropyFlag,
3907 !kEntropyFlag, !kHasStopWaiting, ENCRYPTION_INITIAL); 3573 !kHasStopWaiting, ENCRYPTION_INITIAL);
3908 3574
3909 // Check if delayed ack timer is running for the expected interval. 3575 // Check if delayed ack timer is running for the expected interval.
3910 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); 3576 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
3911 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); 3577 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline());
3912 3578
3913 // Process packet 10 first and ensure the alarm is one eighth min_rtt. 3579 // Process packet 10 first and ensure the alarm is one eighth min_rtt.
3914 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); 3580 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
3915 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 9, 0, 3581 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 9,
3916 !kEntropyFlag, !kHasStopWaiting, ENCRYPTION_INITIAL); 3582 !kEntropyFlag, !kHasStopWaiting, ENCRYPTION_INITIAL);
3917 ack_time = clock_.ApproximateNow().Add(QuicTime::Delta::FromMilliseconds(5)); 3583 ack_time = clock_.ApproximateNow().Add(QuicTime::Delta::FromMilliseconds(5));
3918 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); 3584 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
3919 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); 3585 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline());
3920 3586
3921 // The 10th received packet causes an ack to be sent. 3587 // The 10th received packet causes an ack to be sent.
3922 for (int i = 0; i < 8; ++i) { 3588 for (int i = 0; i < 8; ++i) {
3923 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); 3589 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
3924 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); 3590 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
3925 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 1 + i, 0, 3591 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 1 + i,
3926 !kEntropyFlag, !kHasStopWaiting, 3592 !kEntropyFlag, !kHasStopWaiting,
3927 ENCRYPTION_INITIAL); 3593 ENCRYPTION_INITIAL);
3928 } 3594 }
3929 // Check that ack is sent and that delayed ack alarm is reset. 3595 // Check that ack is sent and that delayed ack alarm is reset.
3930 EXPECT_EQ(2u, writer_->frame_count()); 3596 EXPECT_EQ(2u, writer_->frame_count());
3931 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); 3597 EXPECT_FALSE(writer_->stop_waiting_frames().empty());
3932 EXPECT_FALSE(writer_->ack_frames().empty()); 3598 EXPECT_FALSE(writer_->ack_frames().empty());
3933 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 3599 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
3934 } 3600 }
3935 3601
(...skipping 15 matching lines...) Expand all
3951 const uint8_t tag = 0x07; 3617 const uint8_t tag = 0x07;
3952 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); 3618 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag));
3953 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); 3619 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
3954 // Process a packet from the non-crypto stream. 3620 // Process a packet from the non-crypto stream.
3955 frame1_.stream_id = 3; 3621 frame1_.stream_id = 3;
3956 3622
3957 // Process all the initial packets in order so there aren't missing packets. 3623 // Process all the initial packets in order so there aren't missing packets.
3958 QuicPacketNumber kFirstDecimatedPacket = 101; 3624 QuicPacketNumber kFirstDecimatedPacket = 101;
3959 for (unsigned int i = 0; i < kFirstDecimatedPacket - 1; ++i) { 3625 for (unsigned int i = 0; i < kFirstDecimatedPacket - 1; ++i) {
3960 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); 3626 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
3961 ProcessDataPacketAtLevel(kDefaultPathId, 1 + i, 0, !kEntropyFlag, 3627 ProcessDataPacketAtLevel(kDefaultPathId, 1 + i, !kEntropyFlag,
3962 !kHasStopWaiting, ENCRYPTION_INITIAL); 3628 !kHasStopWaiting, ENCRYPTION_INITIAL);
3963 } 3629 }
3964 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 3630 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
3965 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used 3631 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used
3966 // instead of ENCRYPTION_NONE. 3632 // instead of ENCRYPTION_NONE.
3967 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); 3633 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
3968 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket, 0, 3634 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket, !kEntropyFlag,
3969 !kEntropyFlag, !kHasStopWaiting, ENCRYPTION_INITIAL); 3635 !kHasStopWaiting, ENCRYPTION_INITIAL);
3970 3636
3971 // Check if delayed ack timer is running for the expected interval. 3637 // Check if delayed ack timer is running for the expected interval.
3972 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); 3638 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
3973 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); 3639 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline());
3974 3640
3975 // Process packet 10 first and ensure the alarm is one eighth min_rtt. 3641 // Process packet 10 first and ensure the alarm is one eighth min_rtt.
3976 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); 3642 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
3977 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 19, 0, 3643 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 19,
3978 !kEntropyFlag, !kHasStopWaiting, ENCRYPTION_INITIAL); 3644 !kEntropyFlag, !kHasStopWaiting, ENCRYPTION_INITIAL);
3979 ack_time = clock_.ApproximateNow().Add(QuicTime::Delta::FromMilliseconds(5)); 3645 ack_time = clock_.ApproximateNow().Add(QuicTime::Delta::FromMilliseconds(5));
3980 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); 3646 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
3981 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); 3647 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline());
3982 3648
3983 // The 10th received packet causes an ack to be sent. 3649 // The 10th received packet causes an ack to be sent.
3984 for (int i = 0; i < 8; ++i) { 3650 for (int i = 0; i < 8; ++i) {
3985 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); 3651 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
3986 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); 3652 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
3987 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 1 + i, 0, 3653 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 1 + i,
3988 !kEntropyFlag, !kHasStopWaiting, 3654 !kEntropyFlag, !kHasStopWaiting,
3989 ENCRYPTION_INITIAL); 3655 ENCRYPTION_INITIAL);
3990 } 3656 }
3991 // Check that ack is sent and that delayed ack alarm is reset. 3657 // Check that ack is sent and that delayed ack alarm is reset.
3992 EXPECT_EQ(2u, writer_->frame_count()); 3658 EXPECT_EQ(2u, writer_->frame_count());
3993 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); 3659 EXPECT_FALSE(writer_->stop_waiting_frames().empty());
3994 EXPECT_FALSE(writer_->ack_frames().empty()); 3660 EXPECT_FALSE(writer_->ack_frames().empty());
3995 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 3661 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
3996 3662
3997 // The next packet received in order will cause an immediate ack, 3663 // The next packet received in order will cause an immediate ack,
3998 // because it fills a hole. 3664 // because it fills a hole.
3999 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 3665 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
4000 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); 3666 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
4001 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 10, 0, 3667 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 10,
4002 !kEntropyFlag, !kHasStopWaiting, ENCRYPTION_INITIAL); 3668 !kEntropyFlag, !kHasStopWaiting, ENCRYPTION_INITIAL);
4003 // Check that ack is sent and that delayed ack alarm is reset. 3669 // Check that ack is sent and that delayed ack alarm is reset.
4004 EXPECT_EQ(2u, writer_->frame_count()); 3670 EXPECT_EQ(2u, writer_->frame_count());
4005 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); 3671 EXPECT_FALSE(writer_->stop_waiting_frames().empty());
4006 EXPECT_FALSE(writer_->ack_frames().empty()); 3672 EXPECT_FALSE(writer_->ack_frames().empty());
4007 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 3673 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
4008 } 3674 }
4009 3675
4010 TEST_P(QuicConnectionTest, SendDelayedAckOnHandshakeConfirmed) { 3676 TEST_P(QuicConnectionTest, SendDelayedAckOnHandshakeConfirmed) {
4011 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3677 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
4171 EXPECT_EQ(1u, writer_->stream_frames().size()); 3837 EXPECT_EQ(1u, writer_->stream_frames().size());
4172 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 3838 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
4173 } 3839 }
4174 3840
4175 TEST_P(QuicConnectionTest, NoAckSentForClose) { 3841 TEST_P(QuicConnectionTest, NoAckSentForClose) {
4176 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3842 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4177 ProcessPacket(kDefaultPathId, 1); 3843 ProcessPacket(kDefaultPathId, 1);
4178 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PEER_GOING_AWAY, 3844 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PEER_GOING_AWAY,
4179 ConnectionCloseSource::FROM_PEER)); 3845 ConnectionCloseSource::FROM_PEER));
4180 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); 3846 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0);
4181 ProcessClosePacket(kDefaultPathId, 2, 0); 3847 ProcessClosePacket(kDefaultPathId, 2);
4182 } 3848 }
4183 3849
4184 TEST_P(QuicConnectionTest, SendWhenDisconnected) { 3850 TEST_P(QuicConnectionTest, SendWhenDisconnected) {
4185 EXPECT_TRUE(connection_.connected()); 3851 EXPECT_TRUE(connection_.connected());
4186 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PEER_GOING_AWAY, 3852 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PEER_GOING_AWAY,
4187 ConnectionCloseSource::FROM_SELF)); 3853 ConnectionCloseSource::FROM_SELF));
4188 connection_.CloseConnection(QUIC_PEER_GOING_AWAY, 3854 connection_.CloseConnection(QUIC_PEER_GOING_AWAY,
4189 ConnectionCloseSource::FROM_SELF); 3855 ConnectionCloseSource::FROM_SELF);
4190 EXPECT_FALSE(connection_.connected()); 3856 EXPECT_FALSE(connection_.connected());
4191 EXPECT_FALSE(connection_.CanWriteStreamData()); 3857 EXPECT_FALSE(connection_.CanWriteStreamData());
4192 QuicPacket* packet = ConstructDataPacket(kDefaultPathId, 1, 0, !kEntropyFlag, 3858 QuicPacket* packet =
4193 !kHasStopWaiting); 3859 ConstructDataPacket(kDefaultPathId, 1, !kEntropyFlag, !kHasStopWaiting);
4194 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 1, _, _)).Times(0); 3860 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 1, _, _)).Times(0);
4195 connection_.SendPacket(ENCRYPTION_NONE, kDefaultPathId, 1, packet, 3861 connection_.SendPacket(ENCRYPTION_NONE, kDefaultPathId, 1, packet,
4196 kTestEntropyHash, HAS_RETRANSMITTABLE_DATA, false, 3862 kTestEntropyHash, HAS_RETRANSMITTABLE_DATA, false,
4197 false); 3863 false);
4198 } 3864 }
4199 3865
4200 TEST_P(QuicConnectionTest, PublicReset) { 3866 TEST_P(QuicConnectionTest, PublicReset) {
4201 QuicPublicResetPacket header; 3867 QuicPublicResetPacket header;
4202 header.public_header.connection_id = connection_id_; 3868 header.public_header.connection_id = connection_id_;
4203 header.public_header.reset_flag = true; 3869 header.public_header.reset_flag = true;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
4261 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 3); 3927 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 3);
4262 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3928 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4263 QuicStopWaitingFrame frame = InitStopWaitingFrame(4); 3929 QuicStopWaitingFrame frame = InitStopWaitingFrame(4);
4264 ProcessStopWaitingPacket(&frame); 3930 ProcessStopWaitingPacket(&frame);
4265 EXPECT_TRUE(outgoing_ack()->missing_packets.Empty()); 3931 EXPECT_TRUE(outgoing_ack()->missing_packets.Empty());
4266 } 3932 }
4267 3933
4268 TEST_P(QuicConnectionTest, ReceivedEntropyHashCalculation) { 3934 TEST_P(QuicConnectionTest, ReceivedEntropyHashCalculation) {
4269 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(AtLeast(1)); 3935 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(AtLeast(1));
4270 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3936 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4271 ProcessDataPacket(kDefaultPathId, 1, 1, kEntropyFlag); 3937 ProcessDataPacket(kDefaultPathId, 1, kEntropyFlag);
4272 ProcessDataPacket(kDefaultPathId, 4, 1, kEntropyFlag); 3938 ProcessDataPacket(kDefaultPathId, 4, kEntropyFlag);
4273 ProcessDataPacket(kDefaultPathId, 3, 1, !kEntropyFlag); 3939 ProcessDataPacket(kDefaultPathId, 3, !kEntropyFlag);
4274 ProcessDataPacket(kDefaultPathId, 7, 1, kEntropyFlag); 3940 ProcessDataPacket(kDefaultPathId, 7, kEntropyFlag);
4275 EXPECT_EQ(146u, outgoing_ack()->entropy_hash);
4276 }
4277
4278 TEST_P(QuicConnectionTest, ReceivedEntropyHashCalculationHalfFEC) {
4279 // FEC packets should not change the entropy hash calculation.
4280 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(AtLeast(1));
4281 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4282 ProcessDataPacket(kDefaultPathId, 1, 1, kEntropyFlag);
4283 ProcessFecPacket(kDefaultPathId, 4, 1, false, kEntropyFlag, nullptr);
4284 ProcessDataPacket(kDefaultPathId, 3, 3, !kEntropyFlag);
4285 ProcessFecPacket(kDefaultPathId, 7, 3, false, kEntropyFlag, nullptr);
4286 EXPECT_EQ(146u, outgoing_ack()->entropy_hash); 3941 EXPECT_EQ(146u, outgoing_ack()->entropy_hash);
4287 } 3942 }
4288 3943
4289 TEST_P(QuicConnectionTest, UpdateEntropyForReceivedPackets) { 3944 TEST_P(QuicConnectionTest, UpdateEntropyForReceivedPackets) {
4290 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(AtLeast(1)); 3945 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(AtLeast(1));
4291 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3946 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4292 ProcessDataPacket(kDefaultPathId, 1, 1, kEntropyFlag); 3947 ProcessDataPacket(kDefaultPathId, 1, kEntropyFlag);
4293 ProcessDataPacket(kDefaultPathId, 5, 1, kEntropyFlag); 3948 ProcessDataPacket(kDefaultPathId, 5, kEntropyFlag);
4294 ProcessDataPacket(kDefaultPathId, 4, 1, !kEntropyFlag); 3949 ProcessDataPacket(kDefaultPathId, 4, !kEntropyFlag);
4295 EXPECT_EQ(34u, outgoing_ack()->entropy_hash); 3950 EXPECT_EQ(34u, outgoing_ack()->entropy_hash);
4296 // Make 4th packet my least unacked, and update entropy for 2, 3 packets. 3951 // Make 4th packet my least unacked, and update entropy for 2, 3 packets.
4297 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 5); 3952 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 5);
4298 QuicPacketEntropyHash six_packet_entropy_hash = 0; 3953 QuicPacketEntropyHash six_packet_entropy_hash = 0;
4299 QuicPacketEntropyHash random_entropy_hash = 129u; 3954 QuicPacketEntropyHash random_entropy_hash = 129u;
4300 QuicStopWaitingFrame frame = InitStopWaitingFrame(4); 3955 QuicStopWaitingFrame frame = InitStopWaitingFrame(4);
4301 frame.entropy_hash = random_entropy_hash; 3956 frame.entropy_hash = random_entropy_hash;
4302 if (ProcessStopWaitingPacket(&frame)) { 3957 if (ProcessStopWaitingPacket(&frame)) {
4303 six_packet_entropy_hash = 1 << 6; 3958 six_packet_entropy_hash = 1 << 6;
4304 } 3959 }
4305 3960
4306 EXPECT_EQ((random_entropy_hash + (1 << 5) + six_packet_entropy_hash), 3961 EXPECT_EQ((random_entropy_hash + (1 << 5) + six_packet_entropy_hash),
4307 outgoing_ack()->entropy_hash); 3962 outgoing_ack()->entropy_hash);
4308 } 3963 }
4309 3964
4310 TEST_P(QuicConnectionTest, UpdateEntropyHashUptoCurrentPacket) { 3965 TEST_P(QuicConnectionTest, UpdateEntropyHashUptoCurrentPacket) {
4311 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(AtLeast(1)); 3966 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(AtLeast(1));
4312 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3967 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4313 ProcessDataPacket(kDefaultPathId, 1, 1, kEntropyFlag); 3968 ProcessDataPacket(kDefaultPathId, 1, kEntropyFlag);
4314 ProcessDataPacket(kDefaultPathId, 5, 1, !kEntropyFlag); 3969 ProcessDataPacket(kDefaultPathId, 5, !kEntropyFlag);
4315 ProcessDataPacket(kDefaultPathId, 22, 1, kEntropyFlag); 3970 ProcessDataPacket(kDefaultPathId, 22, kEntropyFlag);
4316 EXPECT_EQ(66u, outgoing_ack()->entropy_hash); 3971 EXPECT_EQ(66u, outgoing_ack()->entropy_hash);
4317 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 22); 3972 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 22);
4318 QuicPacketEntropyHash random_entropy_hash = 85u; 3973 QuicPacketEntropyHash random_entropy_hash = 85u;
4319 // Current packet is the least unacked packet. 3974 // Current packet is the least unacked packet.
4320 QuicPacketEntropyHash ack_entropy_hash; 3975 QuicPacketEntropyHash ack_entropy_hash;
4321 QuicStopWaitingFrame frame = InitStopWaitingFrame(23); 3976 QuicStopWaitingFrame frame = InitStopWaitingFrame(23);
4322 frame.entropy_hash = random_entropy_hash; 3977 frame.entropy_hash = random_entropy_hash;
4323 ack_entropy_hash = ProcessStopWaitingPacket(&frame); 3978 ack_entropy_hash = ProcessStopWaitingPacket(&frame);
4324 EXPECT_EQ((random_entropy_hash + ack_entropy_hash), 3979 EXPECT_EQ((random_entropy_hash + ack_entropy_hash),
4325 outgoing_ack()->entropy_hash); 3980 outgoing_ack()->entropy_hash);
4326 ProcessDataPacket(kDefaultPathId, 25, 1, kEntropyFlag); 3981 ProcessDataPacket(kDefaultPathId, 25, kEntropyFlag);
4327 EXPECT_EQ((random_entropy_hash + ack_entropy_hash + (1 << (25 % 8))), 3982 EXPECT_EQ((random_entropy_hash + ack_entropy_hash + (1 << (25 % 8))),
4328 outgoing_ack()->entropy_hash); 3983 outgoing_ack()->entropy_hash);
4329 } 3984 }
4330 3985
4331 TEST_P(QuicConnectionTest, EntropyCalculationForTruncatedAck) { 3986 TEST_P(QuicConnectionTest, EntropyCalculationForTruncatedAck) {
4332 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(AtLeast(1)); 3987 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(AtLeast(1));
4333 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3988 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4334 QuicPacketEntropyHash entropy[51]; 3989 QuicPacketEntropyHash entropy[51];
4335 entropy[0] = 0; 3990 entropy[0] = 0;
4336 for (int i = 1; i < 51; ++i) { 3991 for (int i = 1; i < 51; ++i) {
4337 bool should_send = i % 10 != 1; 3992 bool should_send = i % 10 != 1;
4338 bool entropy_flag = (i & (i - 1)) != 0; 3993 bool entropy_flag = (i & (i - 1)) != 0;
4339 if (!should_send) { 3994 if (!should_send) {
4340 entropy[i] = entropy[i - 1]; 3995 entropy[i] = entropy[i - 1];
4341 continue; 3996 continue;
4342 } 3997 }
4343 if (entropy_flag) { 3998 if (entropy_flag) {
4344 entropy[i] = entropy[i - 1] ^ (1 << (i % 8)); 3999 entropy[i] = entropy[i - 1] ^ (1 << (i % 8));
4345 } else { 4000 } else {
4346 entropy[i] = entropy[i - 1]; 4001 entropy[i] = entropy[i - 1];
4347 } 4002 }
4348 ProcessDataPacket(kDefaultPathId, i, 1, entropy_flag); 4003 ProcessDataPacket(kDefaultPathId, i, entropy_flag);
4349 } 4004 }
4350 for (int i = 1; i < 50; ++i) { 4005 for (int i = 1; i < 50; ++i) {
4351 EXPECT_EQ(entropy[i], 4006 EXPECT_EQ(entropy[i],
4352 QuicConnectionPeer::ReceivedEntropyHash(&connection_, i)); 4007 QuicConnectionPeer::ReceivedEntropyHash(&connection_, i));
4353 } 4008 }
4354 } 4009 }
4355 4010
4356 TEST_P(QuicConnectionTest, ServerSendsVersionNegotiationPacket) { 4011 TEST_P(QuicConnectionTest, ServerSendsVersionNegotiationPacket) {
4357 connection_.SetSupportedVersions(QuicSupportedVersions()); 4012 connection_.SetSupportedVersions(QuicSupportedVersions());
4358 framer_.set_version_for_tests(QUIC_VERSION_UNSUPPORTED); 4013 framer_.set_version_for_tests(QUIC_VERSION_UNSUPPORTED);
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
4542 EXPECT_EQ(3 * first_packet_size + 2 * second_packet_size - kQuicVersionSize, 4197 EXPECT_EQ(3 * first_packet_size + 2 * second_packet_size - kQuicVersionSize,
4543 stats.bytes_sent); 4198 stats.bytes_sent);
4544 EXPECT_EQ(5u, stats.packets_sent); 4199 EXPECT_EQ(5u, stats.packets_sent);
4545 EXPECT_EQ(2 * first_packet_size + second_packet_size - kQuicVersionSize, 4200 EXPECT_EQ(2 * first_packet_size + second_packet_size - kQuicVersionSize,
4546 stats.bytes_retransmitted); 4201 stats.bytes_retransmitted);
4547 EXPECT_EQ(3u, stats.packets_retransmitted); 4202 EXPECT_EQ(3u, stats.packets_retransmitted);
4548 EXPECT_EQ(1u, stats.rto_count); 4203 EXPECT_EQ(1u, stats.rto_count);
4549 EXPECT_EQ(kDefaultMaxPacketSize, stats.max_packet_size); 4204 EXPECT_EQ(kDefaultMaxPacketSize, stats.max_packet_size);
4550 } 4205 }
4551 4206
4552 TEST_P(QuicConnectionTest, CheckReceiveStats) {
4553 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4554
4555 size_t received_bytes = 0;
4556 received_bytes += ProcessFecProtectedPacket(kDefaultPathId, 1, false,
4557 !kEntropyFlag, !kHasStopWaiting);
4558 received_bytes += ProcessFecProtectedPacket(kDefaultPathId, 3, false,
4559 !kEntropyFlag, !kHasStopWaiting);
4560 // Should be counted against dropped packets.
4561 received_bytes += ProcessDataPacket(kDefaultPathId, 3, 1, !kEntropyFlag);
4562 received_bytes +=
4563 ProcessFecPacket(kDefaultPathId, 4, 1, true, !kEntropyFlag, nullptr);
4564
4565 EXPECT_CALL(*send_algorithm_, BandwidthEstimate())
4566 .WillOnce(Return(QuicBandwidth::Zero()));
4567
4568 const QuicConnectionStats& stats = connection_.GetStats();
4569 EXPECT_EQ(received_bytes, stats.bytes_received);
4570 EXPECT_EQ(4u, stats.packets_received);
4571
4572 EXPECT_EQ(1u, stats.packets_revived);
4573 EXPECT_EQ(1u, stats.packets_dropped);
4574 }
4575
4576 TEST_P(QuicConnectionTest, TestFecGroupLimits) {
4577 // Create and return a group for 1.
4578 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 1) != nullptr);
4579
4580 // Create and return a group for 2.
4581 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 2) != nullptr);
4582
4583 // Create and return a group for 4. This should remove 1 but not 2.
4584 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 4) != nullptr);
4585 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 1) == nullptr);
4586 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 2) != nullptr);
4587
4588 // Create and return a group for 3. This will kill off 2.
4589 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 3) != nullptr);
4590 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 2) == nullptr);
4591
4592 // Verify that adding 5 kills off 3, despite 4 being created before 3.
4593 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 5) != nullptr);
4594 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 4) != nullptr);
4595 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 3) == nullptr);
4596 }
4597
4598 TEST_P(QuicConnectionTest, ProcessFramesIfPacketClosedConnection) { 4207 TEST_P(QuicConnectionTest, ProcessFramesIfPacketClosedConnection) {
4599 // Construct a packet with stream frame and connection close frame. 4208 // Construct a packet with stream frame and connection close frame.
4600 QuicPacketHeader header; 4209 QuicPacketHeader header;
4601 header.public_header.connection_id = connection_id_; 4210 header.public_header.connection_id = connection_id_;
4602 header.packet_number = 1; 4211 header.packet_number = 1;
4603 header.public_header.version_flag = false; 4212 header.public_header.version_flag = false;
4604 4213
4605 QuicConnectionCloseFrame qccf; 4214 QuicConnectionCloseFrame qccf;
4606 qccf.error_code = QUIC_PEER_GOING_AWAY; 4215 qccf.error_code = QUIC_PEER_GOING_AWAY;
4607 4216
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
4850 // the callback. 4459 // the callback.
4851 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 4460 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
4852 QuicAckFrame frame = InitAckFrame(2); 4461 QuicAckFrame frame = InitAckFrame(2);
4853 NackPacket(1, &frame); 4462 NackPacket(1, &frame);
4854 frame.latest_revived_packet = 1; 4463 frame.latest_revived_packet = 1;
4855 ProcessAckPacket(&frame); 4464 ProcessAckPacket(&frame);
4856 // If the ack is processed again, the notifier should not be called again. 4465 // If the ack is processed again, the notifier should not be called again.
4857 ProcessAckPacket(&frame); 4466 ProcessAckPacket(&frame);
4858 } 4467 }
4859 4468
4860 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterFECRecovery) {
4861 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4862 EXPECT_CALL(visitor_, OnCanWrite());
4863
4864 // Create a listener which we expect to be called.
4865 scoped_refptr<MockAckListener> listener(new MockAckListener);
4866 EXPECT_CALL(*listener, OnPacketAcked(_, _)).Times(1);
4867
4868 // Expect ACKs for 1 packet.
4869 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
4870
4871 // Send one packet, and register to be notified on ACK.
4872 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, listener.get());
4873
4874 // Ack packet gets dropped, but we receive an FEC packet that covers it.
4875 // Should recover the Ack packet and trigger the notification callback.
4876 QuicFrames frames;
4877
4878 QuicAckFrame ack_frame = InitAckFrame(1);
4879 frames.push_back(QuicFrame(&ack_frame));
4880
4881 // Dummy stream frame to satisfy expectations set elsewhere.
4882 frames.push_back(QuicFrame(&frame1_));
4883
4884 QuicPacketHeader ack_header;
4885 ack_header.public_header.connection_id = connection_id_;
4886 ack_header.public_header.reset_flag = false;
4887 ack_header.public_header.version_flag = false;
4888 ack_header.entropy_flag = !kEntropyFlag;
4889 ack_header.fec_flag = true;
4890 ack_header.packet_number = 1;
4891 ack_header.is_in_fec_group = IN_FEC_GROUP;
4892 ack_header.fec_group = 1;
4893
4894 QuicPacket* packet = BuildUnsizedDataPacket(&framer_, ack_header, frames);
4895
4896 // Take the packet which contains the ACK frame, and construct and deliver an
4897 // FEC packet which allows the ACK packet to be recovered.
4898 ProcessFecPacket(kDefaultPathId, 2, 1, true, !kEntropyFlag, packet);
4899 }
4900
4901 TEST_P(QuicConnectionTest, OnPacketHeaderDebugVisitor) { 4469 TEST_P(QuicConnectionTest, OnPacketHeaderDebugVisitor) {
4902 QuicPacketHeader header; 4470 QuicPacketHeader header;
4903 4471
4904 scoped_ptr<MockQuicConnectionDebugVisitor> debug_visitor( 4472 scoped_ptr<MockQuicConnectionDebugVisitor> debug_visitor(
4905 new MockQuicConnectionDebugVisitor()); 4473 new MockQuicConnectionDebugVisitor());
4906 connection_.set_debug_visitor(debug_visitor.get()); 4474 connection_.set_debug_visitor(debug_visitor.get());
4907 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1); 4475 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1);
4908 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)).Times(1); 4476 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)).Times(1);
4909 EXPECT_CALL(*debug_visitor, OnSuccessfulVersionNegotiation(_)).Times(1); 4477 EXPECT_CALL(*debug_visitor, OnSuccessfulVersionNegotiation(_)).Times(1);
4910 connection_.OnPacketHeader(header); 4478 connection_.OnPacketHeader(header);
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
5095 // result in multiple attempts to close the connection - it will be marked as 4663 // result in multiple attempts to close the connection - it will be marked as
5096 // disconnected after the first call. 4664 // disconnected after the first call.
5097 EXPECT_CALL(visitor_, OnConnectionClosed(_, _)).Times(1); 4665 EXPECT_CALL(visitor_, OnConnectionClosed(_, _)).Times(1);
5098 connection_.SendConnectionCloseWithDetails(QUIC_NO_ERROR, "no reason"); 4666 connection_.SendConnectionCloseWithDetails(QUIC_NO_ERROR, "no reason");
5099 connection_.SendConnectionCloseWithDetails(QUIC_NO_ERROR, "no reason"); 4667 connection_.SendConnectionCloseWithDetails(QUIC_NO_ERROR, "no reason");
5100 } 4668 }
5101 4669
5102 } // namespace 4670 } // namespace
5103 } // namespace test 4671 } // namespace test
5104 } // namespace net 4672 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection_logger.cc ('k') | net/quic/quic_framer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698