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

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

Issue 478153003: Change the wire format of the ack frame to include a compressed version (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase TOT and pass clock to QuicTestPacketMaker and use it in AckPacket Created 6 years, 4 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_framer.cc ('k') | net/quic/quic_http_stream_test.cc » ('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_framer.h" 5 #include "net/quic/quic_framer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 453
454 // Checks if the supplied string matches data in the supplied StreamFrame. 454 // Checks if the supplied string matches data in the supplied StreamFrame.
455 void CheckStreamFrameData(string str, QuicStreamFrame* frame) { 455 void CheckStreamFrameData(string str, QuicStreamFrame* frame) {
456 scoped_ptr<string> frame_data(frame->GetDataAsString()); 456 scoped_ptr<string> frame_data(frame->GetDataAsString());
457 EXPECT_EQ(str, *frame_data); 457 EXPECT_EQ(str, *frame_data);
458 } 458 }
459 459
460 void CheckStreamFrameBoundaries(unsigned char* packet, 460 void CheckStreamFrameBoundaries(unsigned char* packet,
461 size_t stream_id_size, 461 size_t stream_id_size,
462 bool include_version) { 462 bool include_version) {
463 // Now test framing boundaries 463 // Now test framing boundaries.
464 for (size_t i = kQuicFrameTypeSize; i < GetMinStreamFrameSize(); ++i) { 464 for (size_t i = kQuicFrameTypeSize; i < GetMinStreamFrameSize(); ++i) {
465 string expected_error; 465 string expected_error;
466 if (i < kQuicFrameTypeSize + stream_id_size) { 466 if (i < kQuicFrameTypeSize + stream_id_size) {
467 expected_error = "Unable to read stream_id."; 467 expected_error = "Unable to read stream_id.";
468 } else if (i < kQuicFrameTypeSize + stream_id_size + 468 } else if (i < kQuicFrameTypeSize + stream_id_size +
469 kQuicMaxStreamOffsetSize) { 469 kQuicMaxStreamOffsetSize) {
470 expected_error = "Unable to read offset."; 470 expected_error = "Unable to read offset.";
471 } else { 471 } else {
472 expected_error = "Unable to read frame data."; 472 expected_error = "Unable to read frame data.";
473 } 473 }
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); 675 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
676 EXPECT_FALSE(visitor_.header_->public_header.version_flag); 676 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
677 EXPECT_FALSE(visitor_.header_->fec_flag); 677 EXPECT_FALSE(visitor_.header_->fec_flag);
678 EXPECT_FALSE(visitor_.header_->entropy_flag); 678 EXPECT_FALSE(visitor_.header_->entropy_flag);
679 EXPECT_EQ(0, visitor_.header_->entropy_hash); 679 EXPECT_EQ(0, visitor_.header_->entropy_hash);
680 EXPECT_EQ(GG_UINT64_C(0x123456789ABC), 680 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
681 visitor_.header_->packet_sequence_number); 681 visitor_.header_->packet_sequence_number);
682 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); 682 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
683 EXPECT_EQ(0x00u, visitor_.header_->fec_group); 683 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
684 684
685 // Now test framing boundaries 685 // Now test framing boundaries.
686 for (size_t i = 0; 686 for (size_t i = 0;
687 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 687 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
688 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); 688 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP);
689 ++i) { 689 ++i) {
690 string expected_error; 690 string expected_error;
691 if (i < kConnectionIdOffset) { 691 if (i < kConnectionIdOffset) {
692 expected_error = "Unable to read public flags."; 692 expected_error = "Unable to read public flags.";
693 } else if (i < GetSequenceNumberOffset(!kIncludeVersion)) { 693 } else if (i < GetSequenceNumberOffset(!kIncludeVersion)) {
694 expected_error = "Unable to read ConnectionId."; 694 expected_error = "Unable to read ConnectionId.";
695 } else if (i < GetPrivateFlagsOffset(!kIncludeVersion)) { 695 } else if (i < GetPrivateFlagsOffset(!kIncludeVersion)) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); 728 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
729 EXPECT_FALSE(visitor_.header_->public_header.version_flag); 729 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
730 EXPECT_FALSE(visitor_.header_->fec_flag); 730 EXPECT_FALSE(visitor_.header_->fec_flag);
731 EXPECT_FALSE(visitor_.header_->entropy_flag); 731 EXPECT_FALSE(visitor_.header_->entropy_flag);
732 EXPECT_EQ(0, visitor_.header_->entropy_hash); 732 EXPECT_EQ(0, visitor_.header_->entropy_hash);
733 EXPECT_EQ(GG_UINT64_C(0x123456789ABC), 733 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
734 visitor_.header_->packet_sequence_number); 734 visitor_.header_->packet_sequence_number);
735 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); 735 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
736 EXPECT_EQ(0x00u, visitor_.header_->fec_group); 736 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
737 737
738 // Now test framing boundaries 738 // Now test framing boundaries.
739 for (size_t i = 0; 739 for (size_t i = 0;
740 i < GetPacketHeaderSize(PACKET_4BYTE_CONNECTION_ID, !kIncludeVersion, 740 i < GetPacketHeaderSize(PACKET_4BYTE_CONNECTION_ID, !kIncludeVersion,
741 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); 741 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP);
742 ++i) { 742 ++i) {
743 string expected_error; 743 string expected_error;
744 if (i < kConnectionIdOffset) { 744 if (i < kConnectionIdOffset) {
745 expected_error = "Unable to read public flags."; 745 expected_error = "Unable to read public flags.";
746 } else if (i < GetSequenceNumberOffset(PACKET_4BYTE_CONNECTION_ID, 746 } else if (i < GetSequenceNumberOffset(PACKET_4BYTE_CONNECTION_ID,
747 !kIncludeVersion)) { 747 !kIncludeVersion)) {
748 expected_error = "Unable to read ConnectionId."; 748 expected_error = "Unable to read ConnectionId.";
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); 784 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
785 EXPECT_FALSE(visitor_.header_->public_header.version_flag); 785 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
786 EXPECT_FALSE(visitor_.header_->fec_flag); 786 EXPECT_FALSE(visitor_.header_->fec_flag);
787 EXPECT_FALSE(visitor_.header_->entropy_flag); 787 EXPECT_FALSE(visitor_.header_->entropy_flag);
788 EXPECT_EQ(0, visitor_.header_->entropy_hash); 788 EXPECT_EQ(0, visitor_.header_->entropy_hash);
789 EXPECT_EQ(GG_UINT64_C(0x123456789ABC), 789 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
790 visitor_.header_->packet_sequence_number); 790 visitor_.header_->packet_sequence_number);
791 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); 791 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
792 EXPECT_EQ(0x00u, visitor_.header_->fec_group); 792 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
793 793
794 // Now test framing boundaries 794 // Now test framing boundaries.
795 for (size_t i = 0; 795 for (size_t i = 0;
796 i < GetPacketHeaderSize(PACKET_1BYTE_CONNECTION_ID, !kIncludeVersion, 796 i < GetPacketHeaderSize(PACKET_1BYTE_CONNECTION_ID, !kIncludeVersion,
797 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); 797 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP);
798 ++i) { 798 ++i) {
799 string expected_error; 799 string expected_error;
800 if (i < kConnectionIdOffset) { 800 if (i < kConnectionIdOffset) {
801 expected_error = "Unable to read public flags."; 801 expected_error = "Unable to read public flags.";
802 } else if (i < GetSequenceNumberOffset(PACKET_1BYTE_CONNECTION_ID, 802 } else if (i < GetSequenceNumberOffset(PACKET_1BYTE_CONNECTION_ID,
803 !kIncludeVersion)) { 803 !kIncludeVersion)) {
804 expected_error = "Unable to read ConnectionId."; 804 expected_error = "Unable to read ConnectionId.";
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); 839 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
840 EXPECT_FALSE(visitor_.header_->public_header.version_flag); 840 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
841 EXPECT_FALSE(visitor_.header_->fec_flag); 841 EXPECT_FALSE(visitor_.header_->fec_flag);
842 EXPECT_FALSE(visitor_.header_->entropy_flag); 842 EXPECT_FALSE(visitor_.header_->entropy_flag);
843 EXPECT_EQ(0, visitor_.header_->entropy_hash); 843 EXPECT_EQ(0, visitor_.header_->entropy_hash);
844 EXPECT_EQ(GG_UINT64_C(0x123456789ABC), 844 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
845 visitor_.header_->packet_sequence_number); 845 visitor_.header_->packet_sequence_number);
846 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); 846 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
847 EXPECT_EQ(0x00u, visitor_.header_->fec_group); 847 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
848 848
849 // Now test framing boundaries 849 // Now test framing boundaries.
850 for (size_t i = 0; 850 for (size_t i = 0;
851 i < GetPacketHeaderSize(PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, 851 i < GetPacketHeaderSize(PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion,
852 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); 852 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP);
853 ++i) { 853 ++i) {
854 string expected_error; 854 string expected_error;
855 if (i < kConnectionIdOffset) { 855 if (i < kConnectionIdOffset) {
856 expected_error = "Unable to read public flags."; 856 expected_error = "Unable to read public flags.";
857 } else if (i < GetSequenceNumberOffset(PACKET_0BYTE_CONNECTION_ID, 857 } else if (i < GetSequenceNumberOffset(PACKET_0BYTE_CONNECTION_ID,
858 !kIncludeVersion)) { 858 !kIncludeVersion)) {
859 expected_error = "Unable to read ConnectionId."; 859 expected_error = "Unable to read ConnectionId.";
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 EXPECT_TRUE(visitor_.header_->public_header.version_flag); 896 EXPECT_TRUE(visitor_.header_->public_header.version_flag);
897 EXPECT_EQ(GetParam(), visitor_.header_->public_header.versions[0]); 897 EXPECT_EQ(GetParam(), visitor_.header_->public_header.versions[0]);
898 EXPECT_FALSE(visitor_.header_->fec_flag); 898 EXPECT_FALSE(visitor_.header_->fec_flag);
899 EXPECT_FALSE(visitor_.header_->entropy_flag); 899 EXPECT_FALSE(visitor_.header_->entropy_flag);
900 EXPECT_EQ(0, visitor_.header_->entropy_hash); 900 EXPECT_EQ(0, visitor_.header_->entropy_hash);
901 EXPECT_EQ(GG_UINT64_C(0x123456789ABC), 901 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
902 visitor_.header_->packet_sequence_number); 902 visitor_.header_->packet_sequence_number);
903 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); 903 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
904 EXPECT_EQ(0x00u, visitor_.header_->fec_group); 904 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
905 905
906 // Now test framing boundaries 906 // Now test framing boundaries.
907 for (size_t i = 0; 907 for (size_t i = 0;
908 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, kIncludeVersion, 908 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, kIncludeVersion,
909 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); 909 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP);
910 ++i) { 910 ++i) {
911 string expected_error; 911 string expected_error;
912 if (i < kConnectionIdOffset) { 912 if (i < kConnectionIdOffset) {
913 expected_error = "Unable to read public flags."; 913 expected_error = "Unable to read public flags.";
914 } else if (i < kVersionOffset) { 914 } else if (i < kVersionOffset) {
915 expected_error = "Unable to read ConnectionId."; 915 expected_error = "Unable to read ConnectionId.";
916 } else if (i < GetSequenceNumberOffset(kIncludeVersion)) { 916 } else if (i < GetSequenceNumberOffset(kIncludeVersion)) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); 951 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
952 EXPECT_FALSE(visitor_.header_->public_header.version_flag); 952 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
953 EXPECT_FALSE(visitor_.header_->fec_flag); 953 EXPECT_FALSE(visitor_.header_->fec_flag);
954 EXPECT_FALSE(visitor_.header_->entropy_flag); 954 EXPECT_FALSE(visitor_.header_->entropy_flag);
955 EXPECT_EQ(0, visitor_.header_->entropy_hash); 955 EXPECT_EQ(0, visitor_.header_->entropy_hash);
956 EXPECT_EQ(GG_UINT64_C(0x123456789ABC), 956 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
957 visitor_.header_->packet_sequence_number); 957 visitor_.header_->packet_sequence_number);
958 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); 958 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
959 EXPECT_EQ(0x00u, visitor_.header_->fec_group); 959 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
960 960
961 // Now test framing boundaries 961 // Now test framing boundaries.
962 for (size_t i = 0; 962 for (size_t i = 0;
963 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 963 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
964 PACKET_4BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); 964 PACKET_4BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP);
965 ++i) { 965 ++i) {
966 string expected_error; 966 string expected_error;
967 if (i < kConnectionIdOffset) { 967 if (i < kConnectionIdOffset) {
968 expected_error = "Unable to read public flags."; 968 expected_error = "Unable to read public flags.";
969 } else if (i < GetSequenceNumberOffset(!kIncludeVersion)) { 969 } else if (i < GetSequenceNumberOffset(!kIncludeVersion)) {
970 expected_error = "Unable to read ConnectionId."; 970 expected_error = "Unable to read ConnectionId.";
971 } else if (i < GetPrivateFlagsOffset(!kIncludeVersion, 971 } else if (i < GetPrivateFlagsOffset(!kIncludeVersion,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); 1006 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
1007 EXPECT_FALSE(visitor_.header_->public_header.version_flag); 1007 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
1008 EXPECT_FALSE(visitor_.header_->fec_flag); 1008 EXPECT_FALSE(visitor_.header_->fec_flag);
1009 EXPECT_FALSE(visitor_.header_->entropy_flag); 1009 EXPECT_FALSE(visitor_.header_->entropy_flag);
1010 EXPECT_EQ(0, visitor_.header_->entropy_hash); 1010 EXPECT_EQ(0, visitor_.header_->entropy_hash);
1011 EXPECT_EQ(GG_UINT64_C(0x123456789ABC), 1011 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
1012 visitor_.header_->packet_sequence_number); 1012 visitor_.header_->packet_sequence_number);
1013 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); 1013 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
1014 EXPECT_EQ(0x00u, visitor_.header_->fec_group); 1014 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
1015 1015
1016 // Now test framing boundaries 1016 // Now test framing boundaries.
1017 for (size_t i = 0; 1017 for (size_t i = 0;
1018 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 1018 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
1019 PACKET_2BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); 1019 PACKET_2BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP);
1020 ++i) { 1020 ++i) {
1021 string expected_error; 1021 string expected_error;
1022 if (i < kConnectionIdOffset) { 1022 if (i < kConnectionIdOffset) {
1023 expected_error = "Unable to read public flags."; 1023 expected_error = "Unable to read public flags.";
1024 } else if (i < GetSequenceNumberOffset(!kIncludeVersion)) { 1024 } else if (i < GetSequenceNumberOffset(!kIncludeVersion)) {
1025 expected_error = "Unable to read ConnectionId."; 1025 expected_error = "Unable to read ConnectionId.";
1026 } else if (i < GetPrivateFlagsOffset(!kIncludeVersion, 1026 } else if (i < GetPrivateFlagsOffset(!kIncludeVersion,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); 1061 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
1062 EXPECT_FALSE(visitor_.header_->public_header.version_flag); 1062 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
1063 EXPECT_FALSE(visitor_.header_->fec_flag); 1063 EXPECT_FALSE(visitor_.header_->fec_flag);
1064 EXPECT_FALSE(visitor_.header_->entropy_flag); 1064 EXPECT_FALSE(visitor_.header_->entropy_flag);
1065 EXPECT_EQ(0, visitor_.header_->entropy_hash); 1065 EXPECT_EQ(0, visitor_.header_->entropy_hash);
1066 EXPECT_EQ(GG_UINT64_C(0x123456789ABC), 1066 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
1067 visitor_.header_->packet_sequence_number); 1067 visitor_.header_->packet_sequence_number);
1068 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); 1068 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
1069 EXPECT_EQ(0x00u, visitor_.header_->fec_group); 1069 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
1070 1070
1071 // Now test framing boundaries 1071 // Now test framing boundaries.
1072 for (size_t i = 0; 1072 for (size_t i = 0;
1073 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 1073 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
1074 PACKET_1BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); 1074 PACKET_1BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP);
1075 ++i) { 1075 ++i) {
1076 string expected_error; 1076 string expected_error;
1077 if (i < kConnectionIdOffset) { 1077 if (i < kConnectionIdOffset) {
1078 expected_error = "Unable to read public flags."; 1078 expected_error = "Unable to read public flags.";
1079 } else if (i < GetSequenceNumberOffset(!kIncludeVersion)) { 1079 } else if (i < GetSequenceNumberOffset(!kIncludeVersion)) {
1080 expected_error = "Unable to read ConnectionId."; 1080 expected_error = "Unable to read ConnectionId.";
1081 } else if (i < GetPrivateFlagsOffset(!kIncludeVersion, 1081 } else if (i < GetPrivateFlagsOffset(!kIncludeVersion,
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
1300 1300
1301 ASSERT_EQ(1u, visitor_.stream_frames_.size()); 1301 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1302 EXPECT_EQ(0u, visitor_.ack_frames_.size()); 1302 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1303 EXPECT_EQ(static_cast<uint64>(0x01020304), 1303 EXPECT_EQ(static_cast<uint64>(0x01020304),
1304 visitor_.stream_frames_[0]->stream_id); 1304 visitor_.stream_frames_[0]->stream_id);
1305 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); 1305 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1306 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654), 1306 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1307 visitor_.stream_frames_[0]->offset); 1307 visitor_.stream_frames_[0]->offset);
1308 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); 1308 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]);
1309 1309
1310 // Now test framing boundaries 1310 // Now test framing boundaries.
1311 CheckStreamFrameBoundaries(packet, kQuicMaxStreamIdSize, !kIncludeVersion); 1311 CheckStreamFrameBoundaries(packet, kQuicMaxStreamIdSize, !kIncludeVersion);
1312 } 1312 }
1313 1313
1314 TEST_P(QuicFramerTest, StreamFrame3ByteStreamId) { 1314 TEST_P(QuicFramerTest, StreamFrame3ByteStreamId) {
1315 unsigned char packet[] = { 1315 unsigned char packet[] = {
1316 // public flags (8 byte connection_id) 1316 // public flags (8 byte connection_id)
1317 0x3C, 1317 0x3C,
1318 // connection_id 1318 // connection_id
1319 0x10, 0x32, 0x54, 0x76, 1319 0x10, 0x32, 0x54, 0x76,
1320 0x98, 0xBA, 0xDC, 0xFE, 1320 0x98, 0xBA, 0xDC, 0xFE,
(...skipping 27 matching lines...) Expand all
1348 1348
1349 ASSERT_EQ(1u, visitor_.stream_frames_.size()); 1349 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1350 EXPECT_EQ(0u, visitor_.ack_frames_.size()); 1350 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1351 EXPECT_EQ(GG_UINT64_C(0x00020304), 1351 EXPECT_EQ(GG_UINT64_C(0x00020304),
1352 visitor_.stream_frames_[0]->stream_id); 1352 visitor_.stream_frames_[0]->stream_id);
1353 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); 1353 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1354 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654), 1354 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1355 visitor_.stream_frames_[0]->offset); 1355 visitor_.stream_frames_[0]->offset);
1356 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); 1356 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]);
1357 1357
1358 // Now test framing boundaries 1358 // Now test framing boundaries.
1359 const size_t stream_id_size = 3; 1359 const size_t stream_id_size = 3;
1360 CheckStreamFrameBoundaries(packet, stream_id_size, !kIncludeVersion); 1360 CheckStreamFrameBoundaries(packet, stream_id_size, !kIncludeVersion);
1361 } 1361 }
1362 1362
1363 TEST_P(QuicFramerTest, StreamFrame2ByteStreamId) { 1363 TEST_P(QuicFramerTest, StreamFrame2ByteStreamId) {
1364 unsigned char packet[] = { 1364 unsigned char packet[] = {
1365 // public flags (8 byte connection_id) 1365 // public flags (8 byte connection_id)
1366 0x3C, 1366 0x3C,
1367 // connection_id 1367 // connection_id
1368 0x10, 0x32, 0x54, 0x76, 1368 0x10, 0x32, 0x54, 0x76,
(...skipping 28 matching lines...) Expand all
1397 1397
1398 ASSERT_EQ(1u, visitor_.stream_frames_.size()); 1398 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1399 EXPECT_EQ(0u, visitor_.ack_frames_.size()); 1399 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1400 EXPECT_EQ(static_cast<uint64>(0x00000304), 1400 EXPECT_EQ(static_cast<uint64>(0x00000304),
1401 visitor_.stream_frames_[0]->stream_id); 1401 visitor_.stream_frames_[0]->stream_id);
1402 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); 1402 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1403 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654), 1403 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1404 visitor_.stream_frames_[0]->offset); 1404 visitor_.stream_frames_[0]->offset);
1405 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); 1405 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]);
1406 1406
1407 // Now test framing boundaries 1407 // Now test framing boundaries.
1408 const size_t stream_id_size = 2; 1408 const size_t stream_id_size = 2;
1409 CheckStreamFrameBoundaries(packet, stream_id_size, !kIncludeVersion); 1409 CheckStreamFrameBoundaries(packet, stream_id_size, !kIncludeVersion);
1410 } 1410 }
1411 1411
1412 TEST_P(QuicFramerTest, StreamFrame1ByteStreamId) { 1412 TEST_P(QuicFramerTest, StreamFrame1ByteStreamId) {
1413 unsigned char packet[] = { 1413 unsigned char packet[] = {
1414 // public flags (8 byte connection_id) 1414 // public flags (8 byte connection_id)
1415 0x3C, 1415 0x3C,
1416 // connection_id 1416 // connection_id
1417 0x10, 0x32, 0x54, 0x76, 1417 0x10, 0x32, 0x54, 0x76,
(...skipping 28 matching lines...) Expand all
1446 1446
1447 ASSERT_EQ(1u, visitor_.stream_frames_.size()); 1447 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1448 EXPECT_EQ(0u, visitor_.ack_frames_.size()); 1448 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1449 EXPECT_EQ(static_cast<uint64>(0x00000004), 1449 EXPECT_EQ(static_cast<uint64>(0x00000004),
1450 visitor_.stream_frames_[0]->stream_id); 1450 visitor_.stream_frames_[0]->stream_id);
1451 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); 1451 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1452 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654), 1452 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1453 visitor_.stream_frames_[0]->offset); 1453 visitor_.stream_frames_[0]->offset);
1454 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); 1454 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]);
1455 1455
1456 // Now test framing boundaries 1456 // Now test framing boundaries.
1457 const size_t stream_id_size = 1; 1457 const size_t stream_id_size = 1;
1458 CheckStreamFrameBoundaries(packet, stream_id_size, !kIncludeVersion); 1458 CheckStreamFrameBoundaries(packet, stream_id_size, !kIncludeVersion);
1459 } 1459 }
1460 1460
1461 TEST_P(QuicFramerTest, StreamFrameWithVersion) { 1461 TEST_P(QuicFramerTest, StreamFrameWithVersion) {
1462 unsigned char packet[] = { 1462 unsigned char packet[] = {
1463 // public flags (version, 8 byte connection_id) 1463 // public flags (version, 8 byte connection_id)
1464 0x3D, 1464 0x3D,
1465 // connection_id 1465 // connection_id
1466 0x10, 0x32, 0x54, 0x76, 1466 0x10, 0x32, 0x54, 0x76,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1499 1499
1500 ASSERT_EQ(1u, visitor_.stream_frames_.size()); 1500 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1501 EXPECT_EQ(0u, visitor_.ack_frames_.size()); 1501 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1502 EXPECT_EQ(static_cast<uint64>(0x01020304), 1502 EXPECT_EQ(static_cast<uint64>(0x01020304),
1503 visitor_.stream_frames_[0]->stream_id); 1503 visitor_.stream_frames_[0]->stream_id);
1504 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); 1504 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1505 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654), 1505 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1506 visitor_.stream_frames_[0]->offset); 1506 visitor_.stream_frames_[0]->offset);
1507 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); 1507 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]);
1508 1508
1509 // Now test framing boundaries 1509 // Now test framing boundaries.
1510 CheckStreamFrameBoundaries(packet, kQuicMaxStreamIdSize, kIncludeVersion); 1510 CheckStreamFrameBoundaries(packet, kQuicMaxStreamIdSize, kIncludeVersion);
1511 } 1511 }
1512 1512
1513 TEST_P(QuicFramerTest, RejectPacket) { 1513 TEST_P(QuicFramerTest, RejectPacket) {
1514 visitor_.accept_packet_ = false; 1514 visitor_.accept_packet_ = false;
1515 1515
1516 unsigned char packet[] = { 1516 unsigned char packet[] = {
1517 // public flags (8 byte connection_id) 1517 // public flags (8 byte connection_id)
1518 0x3C, 1518 0x3C,
1519 // connection_id 1519 // connection_id
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
1675 1675
1676 ASSERT_EQ(1u, visitor_.stream_frames_.size()); 1676 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1677 EXPECT_EQ(0u, visitor_.ack_frames_.size()); 1677 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1678 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_.stream_frames_[0]->stream_id); 1678 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_.stream_frames_[0]->stream_id);
1679 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); 1679 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1680 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654), 1680 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1681 visitor_.stream_frames_[0]->offset); 1681 visitor_.stream_frames_[0]->offset);
1682 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); 1682 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]);
1683 } 1683 }
1684 1684
1685 TEST_P(QuicFramerTest, AckFrame) { 1685 TEST_P(QuicFramerTest, AckFramev22) {
1686 if (version_ > QUIC_VERSION_22) {
1687 return;
1688 }
1686 unsigned char packet[] = { 1689 unsigned char packet[] = {
1687 // public flags (8 byte connection_id) 1690 // public flags (8 byte connection_id)
1688 0x3C, 1691 0x3C,
1692 // connection_id
1693 0x10, 0x32, 0x54, 0x76,
1694 0x98, 0xBA, 0xDC, 0xFE,
1695 // packet sequence number
1696 0xA8, 0x9A, 0x78, 0x56,
1697 0x34, 0x12,
1698 // private flags (entropy)
1699 0x01,
1700
1701 // frame type (ack frame)
1702 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
1703 0x6C,
1704 // entropy hash of all received packets.
1705 0xBA,
1706 // largest observed packet sequence number
1707 0xBF, 0x9A, 0x78, 0x56,
1708 0x34, 0x12,
1709 // Zero delta time.
1710 0x0, 0x0,
1711 // num missing packets
1712 0x01,
1713 // missing packet delta
1714 0x01,
1715 // 0 more missing packets in range.
1716 0x00,
1717 // Number of revived packets.
1718 0x00,
1719 };
1720
1721 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1722 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1723
1724 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1725 ASSERT_TRUE(visitor_.header_.get());
1726 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1727
1728 EXPECT_EQ(0u, visitor_.stream_frames_.size());
1729 ASSERT_EQ(1u, visitor_.ack_frames_.size());
1730 const QuicAckFrame& frame = *visitor_.ack_frames_[0];
1731 EXPECT_EQ(0xBA, frame.entropy_hash);
1732 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame.largest_observed);
1733 ASSERT_EQ(1u, frame.missing_packets.size());
1734 SequenceNumberSet::const_iterator missing_iter =
1735 frame.missing_packets.begin();
1736 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter);
1737
1738 const size_t kReceivedEntropyOffset = kQuicFrameTypeSize;
1739 const size_t kLargestObservedOffset = kReceivedEntropyOffset +
1740 kQuicEntropyHashSize;
1741 const size_t kMissingDeltaTimeOffset = kLargestObservedOffset +
1742 PACKET_6BYTE_SEQUENCE_NUMBER;
1743 const size_t kNumMissingPacketOffset = kMissingDeltaTimeOffset +
1744 kQuicDeltaTimeLargestObservedSize;
1745 const size_t kMissingPacketsOffset = kNumMissingPacketOffset +
1746 kNumberOfNackRangesSize;
1747 const size_t kMissingPacketsRange = kMissingPacketsOffset +
1748 PACKET_1BYTE_SEQUENCE_NUMBER;
1749 const size_t kRevivedPacketsLength = kMissingPacketsRange +
1750 PACKET_1BYTE_SEQUENCE_NUMBER;
1751 // Now test framing boundaries.
1752 const size_t ack_frame_size = kRevivedPacketsLength +
1753 PACKET_1BYTE_SEQUENCE_NUMBER;
1754 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) {
1755 string expected_error;
1756 if (i < kLargestObservedOffset) {
1757 expected_error = "Unable to read entropy hash for received packets.";
1758 } else if (i < kMissingDeltaTimeOffset) {
1759 expected_error = "Unable to read largest observed.";
1760 } else if (i < kNumMissingPacketOffset) {
1761 expected_error = "Unable to read delta time largest observed.";
1762 } else if (i < kMissingPacketsOffset) {
1763 expected_error = "Unable to read num missing packet ranges.";
1764 } else if (i < kMissingPacketsRange) {
1765 expected_error = "Unable to read missing sequence number delta.";
1766 } else if (i < kRevivedPacketsLength) {
1767 expected_error = "Unable to read missing sequence number range.";
1768 } else {
1769 expected_error = "Unable to read num revived packets.";
1770 }
1771 CheckProcessingFails(
1772 packet,
1773 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
1774 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP),
1775 expected_error, QUIC_INVALID_ACK_DATA);
1776 }
1777 }
1778
1779
1780 TEST_P(QuicFramerTest, AckFrameTwoTimestamp) {
1781 if (version_ <= QUIC_VERSION_22) {
1782 return;
1783 }
1784 unsigned char packet[] = {
1785 // public flags (8 byte connection_id)
1786 0x3C,
1787 // connection_id
1788 0x10, 0x32, 0x54, 0x76,
1789 0x98, 0xBA, 0xDC, 0xFE,
1790 // packet sequence number
1791 0xA8, 0x9A, 0x78, 0x56,
1792 0x34, 0x12,
1793 // private flags (entropy)
1794 0x01,
1795
1796 // frame type (ack frame)
1797 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
1798 0x6C,
1799 // entropy hash of all received packets.
1800 0xBA,
1801 // largest observed packet sequence number
1802 0xBF, 0x9A, 0x78, 0x56,
1803 0x34, 0x12,
1804 // Zero delta time.
1805 0x0, 0x0,
1806 // Number of timestamps.
1807 0x02,
1808 // Delta from largest observed.
1809 0x01,
1810 // Delta time.
1811 0x10, 0x32, 0x54, 0x76,
1812 // Delta from largest observed.
1813 0x02,
1814 // Delta time.
1815 0x10, 0x32,
1816 // num missing packets
1817 0x01,
1818 // missing packet delta
1819 0x01,
1820 // 0 more missing packets in range.
1821 0x00,
1822 // Number of revived packets.
1823 0x00,
1824 };
1825
1826 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1827 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1828
1829 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1830 ASSERT_TRUE(visitor_.header_.get());
1831 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1832
1833 EXPECT_EQ(0u, visitor_.stream_frames_.size());
1834 ASSERT_EQ(1u, visitor_.ack_frames_.size());
1835 const QuicAckFrame& frame = *visitor_.ack_frames_[0];
1836 EXPECT_EQ(0xBA, frame.entropy_hash);
1837 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame.largest_observed);
1838 ASSERT_EQ(1u, frame.missing_packets.size());
1839 ASSERT_EQ(2u, frame.received_packet_times.size());
1840 SequenceNumberSet::const_iterator missing_iter =
1841 frame.missing_packets.begin();
1842 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter);
1843
1844 const size_t kReceivedEntropyOffset = kQuicFrameTypeSize;
1845 const size_t kLargestObservedOffset = kReceivedEntropyOffset +
1846 kQuicEntropyHashSize;
1847 const size_t kMissingDeltaTimeOffset = kLargestObservedOffset +
1848 PACKET_6BYTE_SEQUENCE_NUMBER;
1849 const size_t kNumTimestampsOffset = kMissingDeltaTimeOffset +
1850 kQuicDeltaTimeLargestObservedSize;
1851 const size_t kTimestampDeltaLargestObserved1 = kNumTimestampsOffset +
1852 kQuicNumTimestampsSize;
1853 const size_t kTimestampTimeDeltaLargestObserved1 =
1854 kTimestampDeltaLargestObserved1 + 1;
1855 const size_t kTimestampDeltaLargestObserved2 =
1856 kTimestampTimeDeltaLargestObserved1 + 4;
1857 const size_t kTimestampTimeDeltaLargestObserved2 =
1858 kTimestampDeltaLargestObserved2 + 1;
1859 const size_t kNumMissingPacketOffset =
1860 kTimestampTimeDeltaLargestObserved2 + 2;
1861 const size_t kMissingPacketsOffset = kNumMissingPacketOffset +
1862 kNumberOfNackRangesSize;
1863 const size_t kMissingPacketsRange = kMissingPacketsOffset +
1864 PACKET_1BYTE_SEQUENCE_NUMBER;
1865 const size_t kRevivedPacketsLength = kMissingPacketsRange +
1866 PACKET_1BYTE_SEQUENCE_NUMBER;
1867 // Now test framing boundaries.
1868 const size_t ack_frame_size = kRevivedPacketsLength +
1869 PACKET_1BYTE_SEQUENCE_NUMBER;
1870 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) {
1871 string expected_error;
1872 if (i < kLargestObservedOffset) {
1873 expected_error = "Unable to read entropy hash for received packets.";
1874 } else if (i < kMissingDeltaTimeOffset) {
1875 expected_error = "Unable to read largest observed.";
1876 } else if (i < kNumTimestampsOffset) {
1877 expected_error = "Unable to read delta time largest observed.";
1878 } else if (i < kTimestampDeltaLargestObserved1) {
1879 expected_error = "Unable to read num received packets.";
1880 } else if (i < kTimestampTimeDeltaLargestObserved1) {
1881 expected_error = "Unable to read sequence delta in received packets.";
1882 } else if (i < kTimestampDeltaLargestObserved2) {
1883 expected_error = "Unable to read time delta in received packets.";
1884 } else if (i < kTimestampTimeDeltaLargestObserved2) {
1885 expected_error = "Unable to read sequence delta in received packets.";
1886 } else if (i < kNumMissingPacketOffset) {
1887 expected_error =
1888 "Unable to read incremental time delta in received packets.";
1889 } else if (i < kMissingPacketsOffset) {
1890 expected_error = "Unable to read num missing packet ranges.";
1891 } else if (i < kMissingPacketsRange) {
1892 expected_error = "Unable to read missing sequence number delta.";
1893 } else if (i < kRevivedPacketsLength) {
1894 expected_error = "Unable to read missing sequence number range.";
1895 } else {
1896 expected_error = "Unable to read num revived packets.";
1897 }
1898 CheckProcessingFails(
1899 packet,
1900 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
1901 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP),
1902 expected_error, QUIC_INVALID_ACK_DATA);
1903 }
1904 }
1905
1906
1907 TEST_P(QuicFramerTest, AckFrameOneTimestamp) {
1908 if (version_ <= QUIC_VERSION_22) {
1909 return;
1910 }
1911 unsigned char packet[] = {
1912 // public flags (8 byte connection_id)
1913 0x3C,
1914 // connection_id
1915 0x10, 0x32, 0x54, 0x76,
1916 0x98, 0xBA, 0xDC, 0xFE,
1917 // packet sequence number
1918 0xA8, 0x9A, 0x78, 0x56,
1919 0x34, 0x12,
1920 // private flags (entropy)
1921 0x01,
1922
1923 // frame type (ack frame)
1924 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
1925 0x6C,
1926 // entropy hash of all received packets.
1927 0xBA,
1928 // largest observed packet sequence number
1929 0xBF, 0x9A, 0x78, 0x56,
1930 0x34, 0x12,
1931 // Zero delta time.
1932 0x0, 0x0,
1933 // Number of timestamps.
1934 0x01,
1935 // Delta from largest observed.
1936 0x01,
1937 // Delta time.
1938 0x10, 0x32, 0x54, 0x76,
1939 // num missing packets
1940 0x01,
1941 // missing packet delta
1942 0x01,
1943 // 0 more missing packets in range.
1944 0x00,
1945 // Number of revived packets.
1946 0x00,
1947 };
1948
1949 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1950 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1951
1952 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1953 ASSERT_TRUE(visitor_.header_.get());
1954 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1955
1956 EXPECT_EQ(0u, visitor_.stream_frames_.size());
1957 ASSERT_EQ(1u, visitor_.ack_frames_.size());
1958 const QuicAckFrame& frame = *visitor_.ack_frames_[0];
1959 EXPECT_EQ(0xBA, frame.entropy_hash);
1960 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame.largest_observed);
1961 ASSERT_EQ(1u, frame.missing_packets.size());
1962 ASSERT_EQ(1u, frame.received_packet_times.size());
1963 SequenceNumberSet::const_iterator missing_iter =
1964 frame.missing_packets.begin();
1965 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter);
1966
1967 const size_t kReceivedEntropyOffset = kQuicFrameTypeSize;
1968 const size_t kLargestObservedOffset = kReceivedEntropyOffset +
1969 kQuicEntropyHashSize;
1970 const size_t kMissingDeltaTimeOffset = kLargestObservedOffset +
1971 PACKET_6BYTE_SEQUENCE_NUMBER;
1972 const size_t kNumTimestampsOffset = kMissingDeltaTimeOffset +
1973 kQuicDeltaTimeLargestObservedSize;
1974 const size_t kTimestampDeltaLargestObserved = kNumTimestampsOffset +
1975 kQuicNumTimestampsSize;
1976 const size_t kTimestampTimeDeltaLargestObserved =
1977 kTimestampDeltaLargestObserved + 1;
1978 const size_t kNumMissingPacketOffset = kTimestampTimeDeltaLargestObserved + 4;
1979 const size_t kMissingPacketsOffset = kNumMissingPacketOffset +
1980 kNumberOfNackRangesSize;
1981 const size_t kMissingPacketsRange = kMissingPacketsOffset +
1982 PACKET_1BYTE_SEQUENCE_NUMBER;
1983 const size_t kRevivedPacketsLength = kMissingPacketsRange +
1984 PACKET_1BYTE_SEQUENCE_NUMBER;
1985 // Now test framing boundaries.
1986 const size_t ack_frame_size = kRevivedPacketsLength +
1987 PACKET_1BYTE_SEQUENCE_NUMBER;
1988 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) {
1989 string expected_error;
1990 if (i < kLargestObservedOffset) {
1991 expected_error = "Unable to read entropy hash for received packets.";
1992 } else if (i < kMissingDeltaTimeOffset) {
1993 expected_error = "Unable to read largest observed.";
1994 } else if (i < kNumTimestampsOffset) {
1995 expected_error = "Unable to read delta time largest observed.";
1996 } else if (i < kTimestampDeltaLargestObserved) {
1997 expected_error = "Unable to read num received packets.";
1998 } else if (i < kTimestampTimeDeltaLargestObserved) {
1999 expected_error = "Unable to read sequence delta in received packets.";
2000 } else if (i < kNumMissingPacketOffset) {
2001 expected_error = "Unable to read time delta in received packets.";
2002 } else if (i < kMissingPacketsOffset) {
2003 expected_error = "Unable to read num missing packet ranges.";
2004 } else if (i < kMissingPacketsRange) {
2005 expected_error = "Unable to read missing sequence number delta.";
2006 } else if (i < kRevivedPacketsLength) {
2007 expected_error = "Unable to read missing sequence number range.";
2008 } else {
2009 expected_error = "Unable to read num revived packets.";
2010 }
2011 CheckProcessingFails(
2012 packet,
2013 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
2014 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP),
2015 expected_error, QUIC_INVALID_ACK_DATA);
2016 }
2017 }
2018
2019
2020 TEST_P(QuicFramerTest, AckFrame) {
2021 if (version_ <= QUIC_VERSION_22) {
2022 return;
2023 }
2024 unsigned char packet[] = {
2025 // public flags (8 byte connection_id)
2026 0x3C,
2027 // connection_id
2028 0x10, 0x32, 0x54, 0x76,
2029 0x98, 0xBA, 0xDC, 0xFE,
2030 // packet sequence number
2031 0xA8, 0x9A, 0x78, 0x56,
2032 0x34, 0x12,
2033 // private flags (entropy)
2034 0x01,
2035
2036 // frame type (ack frame)
2037 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
2038 0x6C,
2039 // entropy hash of all received packets.
2040 0xBA,
2041 // largest observed packet sequence number
2042 0xBF, 0x9A, 0x78, 0x56,
2043 0x34, 0x12,
2044 // Zero delta time.
2045 0x0, 0x0,
2046 // Number of timestamps.
2047 0x00,
2048 // num missing packets
2049 0x01,
2050 // missing packet delta
2051 0x01,
2052 // 0 more missing packets in range.
2053 0x00,
2054 // Number of revived packets.
2055 0x00,
2056 };
2057
2058 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2059 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2060
2061 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2062 ASSERT_TRUE(visitor_.header_.get());
2063 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2064
2065 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2066 ASSERT_EQ(1u, visitor_.ack_frames_.size());
2067 const QuicAckFrame& frame = *visitor_.ack_frames_[0];
2068 EXPECT_EQ(0xBA, frame.entropy_hash);
2069 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame.largest_observed);
2070 ASSERT_EQ(1u, frame.missing_packets.size());
2071 SequenceNumberSet::const_iterator missing_iter =
2072 frame.missing_packets.begin();
2073 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter);
2074
2075 const size_t kReceivedEntropyOffset = kQuicFrameTypeSize;
2076 const size_t kLargestObservedOffset = kReceivedEntropyOffset +
2077 kQuicEntropyHashSize;
2078 const size_t kMissingDeltaTimeOffset = kLargestObservedOffset +
2079 PACKET_6BYTE_SEQUENCE_NUMBER;
2080 const size_t kNumTimestampsOffset = kMissingDeltaTimeOffset +
2081 kQuicDeltaTimeLargestObservedSize;
2082 const size_t kNumMissingPacketOffset = kNumTimestampsOffset +
2083 kQuicNumTimestampsSize;
2084 const size_t kMissingPacketsOffset = kNumMissingPacketOffset +
2085 kNumberOfNackRangesSize;
2086 const size_t kMissingPacketsRange = kMissingPacketsOffset +
2087 PACKET_1BYTE_SEQUENCE_NUMBER;
2088 const size_t kRevivedPacketsLength = kMissingPacketsRange +
2089 PACKET_1BYTE_SEQUENCE_NUMBER;
2090 // Now test framing boundaries.
2091 const size_t ack_frame_size = kRevivedPacketsLength +
2092 PACKET_1BYTE_SEQUENCE_NUMBER;
2093 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) {
2094 string expected_error;
2095 if (i < kLargestObservedOffset) {
2096 expected_error = "Unable to read entropy hash for received packets.";
2097 } else if (i < kMissingDeltaTimeOffset) {
2098 expected_error = "Unable to read largest observed.";
2099 } else if (i < kNumTimestampsOffset) {
2100 expected_error = "Unable to read delta time largest observed.";
2101 } else if (i < kNumMissingPacketOffset) {
2102 expected_error = "Unable to read num received packets.";
2103 } else if (i < kMissingPacketsOffset) {
2104 expected_error = "Unable to read num missing packet ranges.";
2105 } else if (i < kMissingPacketsRange) {
2106 expected_error = "Unable to read missing sequence number delta.";
2107 } else if (i < kRevivedPacketsLength) {
2108 expected_error = "Unable to read missing sequence number range.";
2109 } else {
2110 expected_error = "Unable to read num revived packets.";
2111 }
2112 CheckProcessingFails(
2113 packet,
2114 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
2115 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP),
2116 expected_error, QUIC_INVALID_ACK_DATA);
2117 }
2118 }
2119
2120 TEST_P(QuicFramerTest, AckFrameRevivedPackets) {
2121 if (version_ <= QUIC_VERSION_22) {
2122 return;
2123 }
2124 unsigned char packet[] = {
2125 // public flags (8 byte connection_id)
2126 0x3C,
1689 // connection_id 2127 // connection_id
1690 0x10, 0x32, 0x54, 0x76, 2128 0x10, 0x32, 0x54, 0x76,
1691 0x98, 0xBA, 0xDC, 0xFE, 2129 0x98, 0xBA, 0xDC, 0xFE,
1692 // packet sequence number 2130 // packet sequence number
1693 0xA8, 0x9A, 0x78, 0x56, 2131 0xA8, 0x9A, 0x78, 0x56,
1694 0x34, 0x12, 2132 0x34, 0x12,
1695 // private flags (entropy) 2133 // private flags (entropy)
1696 0x01, 2134 0x01,
1697 2135
1698 // frame type (ack frame) 2136 // frame type (ack frame)
1699 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) 2137 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
1700 0x6C, 2138 0x6C,
1701 // entropy hash of all received packets. 2139 // entropy hash of all received packets.
1702 0xBA, 2140 0xBA,
1703 // largest observed packet sequence number 2141 // largest observed packet sequence number
1704 0xBF, 0x9A, 0x78, 0x56, 2142 0xBF, 0x9A, 0x78, 0x56,
1705 0x34, 0x12, 2143 0x34, 0x12,
1706 // Zero delta time. 2144 // Zero delta time.
1707 0x0, 0x0, 2145 0x0, 0x0,
2146 // num received packets.
2147 0x00,
1708 // num missing packets 2148 // num missing packets
1709 0x01, 2149 0x01,
1710 // missing packet delta 2150 // missing packet delta
1711 0x01, 2151 0x01,
1712 // 0 more missing packets in range. 2152 // 0 more missing packets in range.
1713 0x00, 2153 0x00,
1714 // Number of revived packets. 2154 // Number of revived packets.
2155 0x01,
2156 // Revived packet sequence number.
2157 0xBE, 0x9A, 0x78, 0x56,
2158 0x34, 0x12,
2159 // Number of revived packets.
1715 0x00, 2160 0x00,
1716 }; 2161 };
1717 2162
1718 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 2163 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1719 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2164 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1720 2165
1721 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2166 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1722 ASSERT_TRUE(visitor_.header_.get()); 2167 ASSERT_TRUE(visitor_.header_.get());
1723 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 2168 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1724 2169
1725 EXPECT_EQ(0u, visitor_.stream_frames_.size()); 2170 EXPECT_EQ(0u, visitor_.stream_frames_.size());
1726 ASSERT_EQ(1u, visitor_.ack_frames_.size()); 2171 ASSERT_EQ(1u, visitor_.ack_frames_.size());
1727 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; 2172 const QuicAckFrame& frame = *visitor_.ack_frames_[0];
1728 EXPECT_EQ(0xBA, frame.entropy_hash); 2173 EXPECT_EQ(0xBA, frame.entropy_hash);
1729 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame.largest_observed); 2174 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame.largest_observed);
1730 ASSERT_EQ(1u, frame.missing_packets.size()); 2175 ASSERT_EQ(1u, frame.missing_packets.size());
1731 SequenceNumberSet::const_iterator missing_iter = 2176 SequenceNumberSet::const_iterator missing_iter =
1732 frame.missing_packets.begin(); 2177 frame.missing_packets.begin();
1733 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter); 2178 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter);
1734 2179
1735 const size_t kReceivedEntropyOffset = kQuicFrameTypeSize; 2180 const size_t kReceivedEntropyOffset = kQuicFrameTypeSize;
1736 const size_t kLargestObservedOffset = kReceivedEntropyOffset + 2181 const size_t kLargestObservedOffset = kReceivedEntropyOffset +
1737 kQuicEntropyHashSize; 2182 kQuicEntropyHashSize;
1738 const size_t kMissingDeltaTimeOffset = kLargestObservedOffset + 2183 const size_t kMissingDeltaTimeOffset = kLargestObservedOffset +
1739 PACKET_6BYTE_SEQUENCE_NUMBER; 2184 PACKET_6BYTE_SEQUENCE_NUMBER;
1740 const size_t kNumMissingPacketOffset = kMissingDeltaTimeOffset + 2185 const size_t kNumTimestampsOffset = kMissingDeltaTimeOffset +
1741 kQuicDeltaTimeLargestObservedSize; 2186 kQuicDeltaTimeLargestObservedSize;
2187 const size_t kNumMissingPacketOffset = kNumTimestampsOffset +
2188 kQuicNumTimestampsSize;
1742 const size_t kMissingPacketsOffset = kNumMissingPacketOffset + 2189 const size_t kMissingPacketsOffset = kNumMissingPacketOffset +
1743 kNumberOfNackRangesSize; 2190 kNumberOfNackRangesSize;
1744 const size_t kMissingPacketsRange = kMissingPacketsOffset + 2191 const size_t kMissingPacketsRange = kMissingPacketsOffset +
1745 PACKET_1BYTE_SEQUENCE_NUMBER; 2192 PACKET_1BYTE_SEQUENCE_NUMBER;
1746 const size_t kRevivedPacketsLength = kMissingPacketsRange + 2193 const size_t kRevivedPacketsLength = kMissingPacketsRange +
1747 PACKET_1BYTE_SEQUENCE_NUMBER; 2194 PACKET_1BYTE_SEQUENCE_NUMBER;
1748 // Now test framing boundaries 2195 const size_t kRevivedPacketSequenceNumberLength = kRevivedPacketsLength +
1749 const size_t ack_frame_size = kRevivedPacketsLength +
1750 PACKET_1BYTE_SEQUENCE_NUMBER; 2196 PACKET_1BYTE_SEQUENCE_NUMBER;
2197 // Now test framing boundaries.
2198 const size_t ack_frame_size = kRevivedPacketSequenceNumberLength +
2199 PACKET_6BYTE_SEQUENCE_NUMBER;
1751 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) { 2200 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) {
1752 string expected_error; 2201 string expected_error;
1753 if (i < kLargestObservedOffset) { 2202 if (i < kReceivedEntropyOffset) {
2203 expected_error = "Unable to read least unacked delta.";
2204 } else if (i < kLargestObservedOffset) {
1754 expected_error = "Unable to read entropy hash for received packets."; 2205 expected_error = "Unable to read entropy hash for received packets.";
1755 } else if (i < kMissingDeltaTimeOffset) { 2206 } else if (i < kMissingDeltaTimeOffset) {
1756 expected_error = "Unable to read largest observed."; 2207 expected_error = "Unable to read largest observed.";
2208 } else if (i < kNumTimestampsOffset) {
2209 expected_error = "Unable to read delta time largest observed.";
1757 } else if (i < kNumMissingPacketOffset) { 2210 } else if (i < kNumMissingPacketOffset) {
1758 expected_error = "Unable to read delta time largest observed."; 2211 expected_error = "Unable to read num received packets.";
1759 } else if (i < kMissingPacketsOffset) { 2212 } else if (i < kMissingPacketsOffset) {
1760 expected_error = "Unable to read num missing packet ranges."; 2213 expected_error = "Unable to read num missing packet ranges.";
1761 } else if (i < kMissingPacketsRange) { 2214 } else if (i < kMissingPacketsRange) {
1762 expected_error = "Unable to read missing sequence number delta."; 2215 expected_error = "Unable to read missing sequence number delta.";
1763 } else if (i < kRevivedPacketsLength) { 2216 } else if (i < kRevivedPacketsLength) {
1764 expected_error = "Unable to read missing sequence number range."; 2217 expected_error = "Unable to read missing sequence number range.";
2218 } else if (i < kRevivedPacketSequenceNumberLength) {
2219 expected_error = "Unable to read num revived packets.";
1765 } else { 2220 } else {
1766 expected_error = "Unable to read num revived packets."; 2221 expected_error = "Unable to read revived packet.";
1767 } 2222 }
1768 CheckProcessingFails( 2223 CheckProcessingFails(
1769 packet, 2224 packet,
1770 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 2225 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
1771 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), 2226 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP),
1772 expected_error, QUIC_INVALID_ACK_DATA); 2227 expected_error, QUIC_INVALID_ACK_DATA);
1773 } 2228 }
1774 } 2229 }
1775 2230
1776 TEST_P(QuicFramerTest, AckFrameRevivedPackets) { 2231 TEST_P(QuicFramerTest, AckFrameRevivedPacketsv22) {
2232 if (version_ > QUIC_VERSION_22) {
2233 return;
2234 }
1777 unsigned char packet[] = { 2235 unsigned char packet[] = {
1778 // public flags (8 byte connection_id) 2236 // public flags (8 byte connection_id)
1779 0x3C, 2237 0x3C,
1780 // connection_id 2238 // connection_id
1781 0x10, 0x32, 0x54, 0x76, 2239 0x10, 0x32, 0x54, 0x76,
1782 0x98, 0xBA, 0xDC, 0xFE, 2240 0x98, 0xBA, 0xDC, 0xFE,
1783 // packet sequence number 2241 // packet sequence number
1784 0xA8, 0x9A, 0x78, 0x56, 2242 0xA8, 0x9A, 0x78, 0x56,
1785 0x34, 0x12, 2243 0x34, 0x12,
1786 // private flags (entropy) 2244 // private flags (entropy)
(...skipping 13 matching lines...) Expand all
1800 0x01, 2258 0x01,
1801 // missing packet delta 2259 // missing packet delta
1802 0x01, 2260 0x01,
1803 // 0 more missing packets in range. 2261 // 0 more missing packets in range.
1804 0x00, 2262 0x00,
1805 // Number of revived packets. 2263 // Number of revived packets.
1806 0x01, 2264 0x01,
1807 // Revived packet sequence number. 2265 // Revived packet sequence number.
1808 0xBE, 0x9A, 0x78, 0x56, 2266 0xBE, 0x9A, 0x78, 0x56,
1809 0x34, 0x12, 2267 0x34, 0x12,
2268 // Number of revived packets.
2269 0x00,
1810 }; 2270 };
1811 2271
1812 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 2272 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1813 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2273 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1814 2274
1815 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2275 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1816 ASSERT_TRUE(visitor_.header_.get()); 2276 ASSERT_TRUE(visitor_.header_.get());
1817 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 2277 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1818 2278
1819 EXPECT_EQ(0u, visitor_.stream_frames_.size()); 2279 EXPECT_EQ(0u, visitor_.stream_frames_.size());
(...skipping 14 matching lines...) Expand all
1834 const size_t kNumMissingPacketOffset = kMissingDeltaTimeOffset + 2294 const size_t kNumMissingPacketOffset = kMissingDeltaTimeOffset +
1835 kQuicDeltaTimeLargestObservedSize; 2295 kQuicDeltaTimeLargestObservedSize;
1836 const size_t kMissingPacketsOffset = kNumMissingPacketOffset + 2296 const size_t kMissingPacketsOffset = kNumMissingPacketOffset +
1837 kNumberOfNackRangesSize; 2297 kNumberOfNackRangesSize;
1838 const size_t kMissingPacketsRange = kMissingPacketsOffset + 2298 const size_t kMissingPacketsRange = kMissingPacketsOffset +
1839 PACKET_1BYTE_SEQUENCE_NUMBER; 2299 PACKET_1BYTE_SEQUENCE_NUMBER;
1840 const size_t kRevivedPacketsLength = kMissingPacketsRange + 2300 const size_t kRevivedPacketsLength = kMissingPacketsRange +
1841 PACKET_1BYTE_SEQUENCE_NUMBER; 2301 PACKET_1BYTE_SEQUENCE_NUMBER;
1842 const size_t kRevivedPacketSequenceNumberLength = kRevivedPacketsLength + 2302 const size_t kRevivedPacketSequenceNumberLength = kRevivedPacketsLength +
1843 PACKET_1BYTE_SEQUENCE_NUMBER; 2303 PACKET_1BYTE_SEQUENCE_NUMBER;
1844 // Now test framing boundaries 2304 // Now test framing boundaries.
1845 const size_t ack_frame_size = kRevivedPacketSequenceNumberLength + 2305 const size_t ack_frame_size = kRevivedPacketSequenceNumberLength +
1846 PACKET_6BYTE_SEQUENCE_NUMBER; 2306 PACKET_6BYTE_SEQUENCE_NUMBER;
1847 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) { 2307 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) {
1848 string expected_error; 2308 string expected_error;
1849 if (i < kReceivedEntropyOffset) { 2309 if (i < kReceivedEntropyOffset) {
1850 expected_error = "Unable to read least unacked delta."; 2310 expected_error = "Unable to read least unacked delta.";
1851 } else if (i < kLargestObservedOffset) { 2311 } else if (i < kLargestObservedOffset) {
1852 expected_error = "Unable to read entropy hash for received packets."; 2312 expected_error = "Unable to read entropy hash for received packets.";
1853 } else if (i < kMissingDeltaTimeOffset) { 2313 } else if (i < kMissingDeltaTimeOffset) {
1854 expected_error = "Unable to read largest observed."; 2314 expected_error = "Unable to read largest observed.";
(...skipping 11 matching lines...) Expand all
1866 expected_error = "Unable to read revived packet."; 2326 expected_error = "Unable to read revived packet.";
1867 } 2327 }
1868 CheckProcessingFails( 2328 CheckProcessingFails(
1869 packet, 2329 packet,
1870 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 2330 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
1871 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), 2331 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP),
1872 expected_error, QUIC_INVALID_ACK_DATA); 2332 expected_error, QUIC_INVALID_ACK_DATA);
1873 } 2333 }
1874 } 2334 }
1875 2335
1876 TEST_P(QuicFramerTest, AckFrameNoNacks) { 2336 TEST_P(QuicFramerTest, AckFrameNoNacksv22) {
2337 if (version_ > QUIC_VERSION_22) {
2338 return;
2339 }
1877 unsigned char packet[] = { 2340 unsigned char packet[] = {
1878 // public flags (8 byte connection_id) 2341 // public flags (8 byte connection_id)
1879 0x3C, 2342 0x3C,
2343 // connection_id
2344 0x10, 0x32, 0x54, 0x76,
2345 0x98, 0xBA, 0xDC, 0xFE,
2346 // packet sequence number
2347 0xA8, 0x9A, 0x78, 0x56,
2348 0x34, 0x12,
2349 // private flags (entropy)
2350 0x01,
2351
2352 // frame type (ack frame)
2353 // (no nacks, not truncated, 6 byte largest observed, 1 byte delta)
2354 0x4C,
2355 // entropy hash of all received packets.
2356 0xBA,
2357 // largest observed packet sequence number
2358 0xBF, 0x9A, 0x78, 0x56,
2359 0x34, 0x12,
2360 // Zero delta time.
2361 0x0, 0x0,
2362 };
2363
2364 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2365 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2366
2367 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2368 ASSERT_TRUE(visitor_.header_.get());
2369 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2370
2371 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2372 ASSERT_EQ(1u, visitor_.ack_frames_.size());
2373 QuicAckFrame* frame = visitor_.ack_frames_[0];
2374 EXPECT_EQ(0xBA, frame->entropy_hash);
2375 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame->largest_observed);
2376 ASSERT_EQ(0u, frame->missing_packets.size());
2377
2378 // Verify that the packet re-serializes identically.
2379 QuicFrames frames;
2380 frames.push_back(QuicFrame(frame));
2381 scoped_ptr<QuicPacket> data(BuildDataPacket(*visitor_.header_, frames));
2382 ASSERT_TRUE(data != NULL);
2383
2384 test::CompareCharArraysWithHexError("constructed packet",
2385 data->data(), data->length(),
2386 AsChars(packet), arraysize(packet));
2387 }
2388
2389 TEST_P(QuicFramerTest, AckFrameNoNacks) {
2390 if (version_ <= QUIC_VERSION_22) {
2391 return;
2392 }
2393 unsigned char packet[] = {
2394 // public flags (8 byte connection_id)
2395 0x3C,
1880 // connection_id 2396 // connection_id
1881 0x10, 0x32, 0x54, 0x76, 2397 0x10, 0x32, 0x54, 0x76,
1882 0x98, 0xBA, 0xDC, 0xFE, 2398 0x98, 0xBA, 0xDC, 0xFE,
1883 // packet sequence number 2399 // packet sequence number
1884 0xA8, 0x9A, 0x78, 0x56, 2400 0xA8, 0x9A, 0x78, 0x56,
1885 0x34, 0x12, 2401 0x34, 0x12,
1886 // private flags (entropy) 2402 // private flags (entropy)
1887 0x01, 2403 0x01,
1888 2404
1889 // frame type (ack frame) 2405 // frame type (ack frame)
1890 // (no nacks, not truncated, 6 byte largest observed, 1 byte delta) 2406 // (no nacks, not truncated, 6 byte largest observed, 1 byte delta)
1891 0x4C, 2407 0x4C,
1892 // entropy hash of all received packets. 2408 // entropy hash of all received packets.
1893 0xBA, 2409 0xBA,
1894 // largest observed packet sequence number 2410 // largest observed packet sequence number
1895 0xBF, 0x9A, 0x78, 0x56, 2411 0xBF, 0x9A, 0x78, 0x56,
1896 0x34, 0x12, 2412 0x34, 0x12,
1897 // Zero delta time. 2413 // Zero delta time.
1898 0x0, 0x0, 2414 0x0, 0x0,
2415 // Number of received packets.
2416 0x00,
1899 }; 2417 };
1900 2418
1901 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 2419 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1902 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2420 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1903 2421
1904 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2422 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1905 ASSERT_TRUE(visitor_.header_.get()); 2423 ASSERT_TRUE(visitor_.header_.get());
1906 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 2424 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1907 2425
1908 EXPECT_EQ(0u, visitor_.stream_frames_.size()); 2426 EXPECT_EQ(0u, visitor_.stream_frames_.size());
1909 ASSERT_EQ(1u, visitor_.ack_frames_.size()); 2427 ASSERT_EQ(1u, visitor_.ack_frames_.size());
1910 QuicAckFrame* frame = visitor_.ack_frames_[0]; 2428 QuicAckFrame* frame = visitor_.ack_frames_[0];
1911 EXPECT_EQ(0xBA, frame->entropy_hash); 2429 EXPECT_EQ(0xBA, frame->entropy_hash);
1912 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame->largest_observed); 2430 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame->largest_observed);
1913 ASSERT_EQ(0u, frame->missing_packets.size()); 2431 ASSERT_EQ(0u, frame->missing_packets.size());
1914 2432
1915 // Verify that the packet re-serializes identically. 2433 // Verify that the packet re-serializes identically.
1916 QuicFrames frames; 2434 QuicFrames frames;
1917 frames.push_back(QuicFrame(frame)); 2435 frames.push_back(QuicFrame(frame));
1918 scoped_ptr<QuicPacket> data(BuildDataPacket(*visitor_.header_, frames)); 2436 scoped_ptr<QuicPacket> data(BuildDataPacket(*visitor_.header_, frames));
1919 ASSERT_TRUE(data != NULL); 2437 ASSERT_TRUE(data != NULL);
1920 2438
1921 test::CompareCharArraysWithHexError("constructed packet", 2439 test::CompareCharArraysWithHexError("constructed packet",
1922 data->data(), data->length(), 2440 data->data(), data->length(),
1923 AsChars(packet), arraysize(packet)); 2441 AsChars(packet), arraysize(packet));
1924 } 2442 }
1925 2443
2444 TEST_P(QuicFramerTest, AckFrame500Nacksv22) {
2445 if (version_ > QUIC_VERSION_22) {
2446 return;
2447 }
2448 unsigned char packet[] = {
2449 // public flags (8 byte connection_id)
2450 0x3C,
2451 // connection_id
2452 0x10, 0x32, 0x54, 0x76,
2453 0x98, 0xBA, 0xDC, 0xFE,
2454 // packet sequence number
2455 0xA8, 0x9A, 0x78, 0x56,
2456 0x34, 0x12,
2457 // private flags (entropy)
2458 0x01,
2459
2460 // frame type (ack frame)
2461 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
2462 0x6C,
2463 // entropy hash of all received packets.
2464 0xBA,
2465 // largest observed packet sequence number
2466 0xBF, 0x9A, 0x78, 0x56,
2467 0x34, 0x12,
2468 // Zero delta time.
2469 0x0, 0x0,
2470 // num missing packet ranges
2471 0x02,
2472 // missing packet delta
2473 0x01,
2474 // 243 more missing packets in range.
2475 // The ranges are listed in this order so the re-constructed packet matches.
2476 0xF3,
2477 // No gap between ranges
2478 0x00,
2479 // 255 more missing packets in range.
2480 0xFF,
2481 // No revived packets.
2482 0x00,
2483 };
2484
2485 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2486 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2487
2488 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2489 ASSERT_TRUE(visitor_.header_.get());
2490 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2491
2492 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2493 ASSERT_EQ(1u, visitor_.ack_frames_.size());
2494 QuicAckFrame* frame = visitor_.ack_frames_[0];
2495 EXPECT_EQ(0xBA, frame->entropy_hash);
2496 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame->largest_observed);
2497 EXPECT_EQ(0u, frame->revived_packets.size());
2498 ASSERT_EQ(500u, frame->missing_packets.size());
2499 SequenceNumberSet::const_iterator first_missing_iter =
2500 frame->missing_packets.begin();
2501 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE) - 499, *first_missing_iter);
2502 SequenceNumberSet::const_reverse_iterator last_missing_iter =
2503 frame->missing_packets.rbegin();
2504 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *last_missing_iter);
2505
2506 // Verify that the packet re-serializes identically.
2507 QuicFrames frames;
2508 frames.push_back(QuicFrame(frame));
2509 scoped_ptr<QuicPacket> data(BuildDataPacket(*visitor_.header_, frames));
2510 ASSERT_TRUE(data != NULL);
2511
2512 test::CompareCharArraysWithHexError("constructed packet",
2513 data->data(), data->length(),
2514 AsChars(packet), arraysize(packet));
2515 }
2516
1926 TEST_P(QuicFramerTest, AckFrame500Nacks) { 2517 TEST_P(QuicFramerTest, AckFrame500Nacks) {
2518 if (version_ <= QUIC_VERSION_22) {
2519 return;
2520 }
1927 unsigned char packet[] = { 2521 unsigned char packet[] = {
1928 // public flags (8 byte connection_id) 2522 // public flags (8 byte connection_id)
1929 0x3C, 2523 0x3C,
1930 // connection_id 2524 // connection_id
1931 0x10, 0x32, 0x54, 0x76, 2525 0x10, 0x32, 0x54, 0x76,
1932 0x98, 0xBA, 0xDC, 0xFE, 2526 0x98, 0xBA, 0xDC, 0xFE,
1933 // packet sequence number 2527 // packet sequence number
1934 0xA8, 0x9A, 0x78, 0x56, 2528 0xA8, 0x9A, 0x78, 0x56,
1935 0x34, 0x12, 2529 0x34, 0x12,
1936 // private flags (entropy) 2530 // private flags (entropy)
1937 0x01, 2531 0x01,
1938 2532
1939 // frame type (ack frame) 2533 // frame type (ack frame)
1940 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) 2534 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
1941 0x6C, 2535 0x6C,
1942 // entropy hash of all received packets. 2536 // entropy hash of all received packets.
1943 0xBA, 2537 0xBA,
1944 // largest observed packet sequence number 2538 // largest observed packet sequence number
1945 0xBF, 0x9A, 0x78, 0x56, 2539 0xBF, 0x9A, 0x78, 0x56,
1946 0x34, 0x12, 2540 0x34, 0x12,
1947 // Zero delta time. 2541 // Zero delta time.
1948 0x0, 0x0, 2542 0x0, 0x0,
2543 // No received packets.
2544 0x00,
1949 // num missing packet ranges 2545 // num missing packet ranges
1950 0x02, 2546 0x02,
1951 // missing packet delta 2547 // missing packet delta
1952 0x01, 2548 0x01,
1953 // 243 more missing packets in range. 2549 // 243 more missing packets in range.
1954 // The ranges are listed in this order so the re-constructed packet matches. 2550 // The ranges are listed in this order so the re-constructed packet matches.
1955 0xF3, 2551 0xF3,
1956 // No gap between ranges 2552 // No gap between ranges
1957 0x00, 2553 0x00,
1958 // 255 more missing packets in range. 2554 // 255 more missing packets in range.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
2021 ASSERT_TRUE(visitor_.header_.get()); 2617 ASSERT_TRUE(visitor_.header_.get());
2022 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 2618 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2023 2619
2024 EXPECT_EQ(0u, visitor_.stream_frames_.size()); 2620 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2025 ASSERT_EQ(1u, visitor_.congestion_feedback_frames_.size()); 2621 ASSERT_EQ(1u, visitor_.congestion_feedback_frames_.size());
2026 const QuicCongestionFeedbackFrame& frame = 2622 const QuicCongestionFeedbackFrame& frame =
2027 *visitor_.congestion_feedback_frames_[0]; 2623 *visitor_.congestion_feedback_frames_[0];
2028 ASSERT_EQ(kTCP, frame.type); 2624 ASSERT_EQ(kTCP, frame.type);
2029 EXPECT_EQ(0x4030u, frame.tcp.receive_window); 2625 EXPECT_EQ(0x4030u, frame.tcp.receive_window);
2030 2626
2031 // Now test framing boundaries 2627 // Now test framing boundaries.
2032 for (size_t i = kQuicFrameTypeSize; i < 4; ++i) { 2628 for (size_t i = kQuicFrameTypeSize; i < 4; ++i) {
2033 string expected_error; 2629 string expected_error;
2034 if (i < 2) { 2630 if (i < 2) {
2035 expected_error = "Unable to read congestion feedback type."; 2631 expected_error = "Unable to read congestion feedback type.";
2036 } else if (i < 4) { 2632 } else if (i < 4) {
2037 expected_error = "Unable to read receive window."; 2633 expected_error = "Unable to read receive window.";
2038 } 2634 }
2039 CheckProcessingFails( 2635 CheckProcessingFails(
2040 packet, 2636 packet,
2041 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 2637 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
2163 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2759 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2164 ASSERT_TRUE(visitor_.header_.get()); 2760 ASSERT_TRUE(visitor_.header_.get());
2165 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 2761 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2166 2762
2167 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_.rst_stream_frame_.stream_id); 2763 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_.rst_stream_frame_.stream_id);
2168 EXPECT_EQ(0x01, visitor_.rst_stream_frame_.error_code); 2764 EXPECT_EQ(0x01, visitor_.rst_stream_frame_.error_code);
2169 EXPECT_EQ("because I can", visitor_.rst_stream_frame_.error_details); 2765 EXPECT_EQ("because I can", visitor_.rst_stream_frame_.error_details);
2170 EXPECT_EQ(GG_UINT64_C(0x0807060504030201), 2766 EXPECT_EQ(GG_UINT64_C(0x0807060504030201),
2171 visitor_.rst_stream_frame_.byte_offset); 2767 visitor_.rst_stream_frame_.byte_offset);
2172 2768
2173 // Now test framing boundaries 2769 // Now test framing boundaries.
2174 for (size_t i = kQuicFrameTypeSize; 2770 for (size_t i = kQuicFrameTypeSize;
2175 i < QuicFramer::GetMinRstStreamFrameSize(); ++i) { 2771 i < QuicFramer::GetMinRstStreamFrameSize(); ++i) {
2176 string expected_error; 2772 string expected_error;
2177 if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize) { 2773 if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize) {
2178 expected_error = "Unable to read stream_id."; 2774 expected_error = "Unable to read stream_id.";
2179 } else if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize + 2775 } else if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize +
2180 + kQuicMaxStreamOffsetSize) { 2776 + kQuicMaxStreamOffsetSize) {
2181 expected_error = "Unable to read rst stream sent byte offset."; 2777 expected_error = "Unable to read rst stream sent byte offset.";
2182 } else if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize + 2778 } else if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize +
2183 + kQuicMaxStreamOffsetSize + kQuicErrorCodeSize) { 2779 + kQuicMaxStreamOffsetSize + kQuicErrorCodeSize) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2227 ASSERT_TRUE(visitor_.header_.get()); 2823 ASSERT_TRUE(visitor_.header_.get());
2228 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 2824 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2229 2825
2230 EXPECT_EQ(0u, visitor_.stream_frames_.size()); 2826 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2231 2827
2232 EXPECT_EQ(0x11, visitor_.connection_close_frame_.error_code); 2828 EXPECT_EQ(0x11, visitor_.connection_close_frame_.error_code);
2233 EXPECT_EQ("because I can", visitor_.connection_close_frame_.error_details); 2829 EXPECT_EQ("because I can", visitor_.connection_close_frame_.error_details);
2234 2830
2235 ASSERT_EQ(0u, visitor_.ack_frames_.size()); 2831 ASSERT_EQ(0u, visitor_.ack_frames_.size());
2236 2832
2237 // Now test framing boundaries 2833 // Now test framing boundaries.
2238 for (size_t i = kQuicFrameTypeSize; 2834 for (size_t i = kQuicFrameTypeSize;
2239 i < QuicFramer::GetMinConnectionCloseFrameSize(); ++i) { 2835 i < QuicFramer::GetMinConnectionCloseFrameSize(); ++i) {
2240 string expected_error; 2836 string expected_error;
2241 if (i < kQuicFrameTypeSize + kQuicErrorCodeSize) { 2837 if (i < kQuicFrameTypeSize + kQuicErrorCodeSize) {
2242 expected_error = "Unable to read connection close error code."; 2838 expected_error = "Unable to read connection close error code.";
2243 } else { 2839 } else {
2244 expected_error = "Unable to read connection close error details."; 2840 expected_error = "Unable to read connection close error details.";
2245 } 2841 }
2246 CheckProcessingFails( 2842 CheckProcessingFails(
2247 packet, 2843 packet,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2285 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2881 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2286 ASSERT_TRUE(visitor_.header_.get()); 2882 ASSERT_TRUE(visitor_.header_.get());
2287 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 2883 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2288 2884
2289 EXPECT_EQ(GG_UINT64_C(0x01020304), 2885 EXPECT_EQ(GG_UINT64_C(0x01020304),
2290 visitor_.goaway_frame_.last_good_stream_id); 2886 visitor_.goaway_frame_.last_good_stream_id);
2291 EXPECT_EQ(0x9, visitor_.goaway_frame_.error_code); 2887 EXPECT_EQ(0x9, visitor_.goaway_frame_.error_code);
2292 EXPECT_EQ("because I can", visitor_.goaway_frame_.reason_phrase); 2888 EXPECT_EQ("because I can", visitor_.goaway_frame_.reason_phrase);
2293 2889
2294 const size_t reason_size = arraysize("because I can") - 1; 2890 const size_t reason_size = arraysize("because I can") - 1;
2295 // Now test framing boundaries 2891 // Now test framing boundaries.
2296 for (size_t i = kQuicFrameTypeSize; 2892 for (size_t i = kQuicFrameTypeSize;
2297 i < QuicFramer::GetMinGoAwayFrameSize() + reason_size; ++i) { 2893 i < QuicFramer::GetMinGoAwayFrameSize() + reason_size; ++i) {
2298 string expected_error; 2894 string expected_error;
2299 if (i < kQuicFrameTypeSize + kQuicErrorCodeSize) { 2895 if (i < kQuicFrameTypeSize + kQuicErrorCodeSize) {
2300 expected_error = "Unable to read go away error code."; 2896 expected_error = "Unable to read go away error code.";
2301 } else if (i < kQuicFrameTypeSize + kQuicErrorCodeSize + 2897 } else if (i < kQuicFrameTypeSize + kQuicErrorCodeSize +
2302 kQuicMaxStreamIdSize) { 2898 kQuicMaxStreamIdSize) {
2303 expected_error = "Unable to read last good stream id."; 2899 expected_error = "Unable to read last good stream id.";
2304 } else { 2900 } else {
2305 expected_error = "Unable to read goaway reason."; 2901 expected_error = "Unable to read goaway reason.";
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2340 2936
2341 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2937 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2342 ASSERT_TRUE(visitor_.header_.get()); 2938 ASSERT_TRUE(visitor_.header_.get());
2343 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 2939 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2344 2940
2345 EXPECT_EQ(GG_UINT64_C(0x01020304), 2941 EXPECT_EQ(GG_UINT64_C(0x01020304),
2346 visitor_.window_update_frame_.stream_id); 2942 visitor_.window_update_frame_.stream_id);
2347 EXPECT_EQ(GG_UINT64_C(0x0c0b0a0908070605), 2943 EXPECT_EQ(GG_UINT64_C(0x0c0b0a0908070605),
2348 visitor_.window_update_frame_.byte_offset); 2944 visitor_.window_update_frame_.byte_offset);
2349 2945
2350 // Now test framing boundaries 2946 // Now test framing boundaries.
2351 for (size_t i = kQuicFrameTypeSize; 2947 for (size_t i = kQuicFrameTypeSize;
2352 i < QuicFramer::GetWindowUpdateFrameSize(); ++i) { 2948 i < QuicFramer::GetWindowUpdateFrameSize(); ++i) {
2353 string expected_error; 2949 string expected_error;
2354 if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize) { 2950 if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize) {
2355 expected_error = "Unable to read stream_id."; 2951 expected_error = "Unable to read stream_id.";
2356 } else { 2952 } else {
2357 expected_error = "Unable to read window byte_offset."; 2953 expected_error = "Unable to read window byte_offset.";
2358 } 2954 }
2359 CheckProcessingFails( 2955 CheckProcessingFails(
2360 packet, 2956 packet,
(...skipping 26 matching lines...) Expand all
2387 2983
2388 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2984 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2389 2985
2390 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2986 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2391 ASSERT_TRUE(visitor_.header_.get()); 2987 ASSERT_TRUE(visitor_.header_.get());
2392 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 2988 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2393 2989
2394 EXPECT_EQ(GG_UINT64_C(0x01020304), 2990 EXPECT_EQ(GG_UINT64_C(0x01020304),
2395 visitor_.blocked_frame_.stream_id); 2991 visitor_.blocked_frame_.stream_id);
2396 2992
2397 // Now test framing boundaries 2993 // Now test framing boundaries.
2398 for (size_t i = kQuicFrameTypeSize; i < QuicFramer::GetBlockedFrameSize(); 2994 for (size_t i = kQuicFrameTypeSize; i < QuicFramer::GetBlockedFrameSize();
2399 ++i) { 2995 ++i) {
2400 string expected_error = "Unable to read stream_id."; 2996 string expected_error = "Unable to read stream_id.";
2401 CheckProcessingFails( 2997 CheckProcessingFails(
2402 packet, 2998 packet,
2403 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 2999 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
2404 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), 3000 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP),
2405 expected_error, QUIC_INVALID_BLOCKED_DATA); 3001 expected_error, QUIC_INVALID_BLOCKED_DATA);
2406 } 3002 }
2407 } 3003 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
2474 visitor_.public_reset_packet_->public_header.connection_id); 3070 visitor_.public_reset_packet_->public_header.connection_id);
2475 EXPECT_TRUE(visitor_.public_reset_packet_->public_header.reset_flag); 3071 EXPECT_TRUE(visitor_.public_reset_packet_->public_header.reset_flag);
2476 EXPECT_FALSE(visitor_.public_reset_packet_->public_header.version_flag); 3072 EXPECT_FALSE(visitor_.public_reset_packet_->public_header.version_flag);
2477 EXPECT_EQ(GG_UINT64_C(0xABCDEF0123456789), 3073 EXPECT_EQ(GG_UINT64_C(0xABCDEF0123456789),
2478 visitor_.public_reset_packet_->nonce_proof); 3074 visitor_.public_reset_packet_->nonce_proof);
2479 EXPECT_EQ(GG_UINT64_C(0x123456789ABC), 3075 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
2480 visitor_.public_reset_packet_->rejected_sequence_number); 3076 visitor_.public_reset_packet_->rejected_sequence_number);
2481 EXPECT_TRUE( 3077 EXPECT_TRUE(
2482 visitor_.public_reset_packet_->client_address.address().empty()); 3078 visitor_.public_reset_packet_->client_address.address().empty());
2483 3079
2484 // Now test framing boundaries 3080 // Now test framing boundaries.
2485 for (size_t i = 0; i < arraysize(packet); ++i) { 3081 for (size_t i = 0; i < arraysize(packet); ++i) {
2486 string expected_error; 3082 string expected_error;
2487 DVLOG(1) << "iteration: " << i; 3083 DVLOG(1) << "iteration: " << i;
2488 if (i < kConnectionIdOffset) { 3084 if (i < kConnectionIdOffset) {
2489 expected_error = "Unable to read public flags."; 3085 expected_error = "Unable to read public flags.";
2490 CheckProcessingFails(packet, i, expected_error, 3086 CheckProcessingFails(packet, i, expected_error,
2491 QUIC_INVALID_PACKET_HEADER); 3087 QUIC_INVALID_PACKET_HEADER);
2492 } else if (i < kPublicResetPacketMessageTagOffset) { 3088 } else if (i < kPublicResetPacketMessageTagOffset) {
2493 expected_error = "Unable to read ConnectionId."; 3089 expected_error = "Unable to read ConnectionId.";
2494 CheckProcessingFails(packet, i, expected_error, 3090 CheckProcessingFails(packet, i, expected_error,
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
2580 EXPECT_FALSE(visitor_.public_reset_packet_->public_header.version_flag); 3176 EXPECT_FALSE(visitor_.public_reset_packet_->public_header.version_flag);
2581 EXPECT_EQ(GG_UINT64_C(0xABCDEF0123456789), 3177 EXPECT_EQ(GG_UINT64_C(0xABCDEF0123456789),
2582 visitor_.public_reset_packet_->nonce_proof); 3178 visitor_.public_reset_packet_->nonce_proof);
2583 EXPECT_EQ(GG_UINT64_C(0x123456789ABC), 3179 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
2584 visitor_.public_reset_packet_->rejected_sequence_number); 3180 visitor_.public_reset_packet_->rejected_sequence_number);
2585 EXPECT_EQ("4.31.198.44", 3181 EXPECT_EQ("4.31.198.44",
2586 IPAddressToString(visitor_.public_reset_packet_-> 3182 IPAddressToString(visitor_.public_reset_packet_->
2587 client_address.address())); 3183 client_address.address()));
2588 EXPECT_EQ(443, visitor_.public_reset_packet_->client_address.port()); 3184 EXPECT_EQ(443, visitor_.public_reset_packet_->client_address.port());
2589 3185
2590 // Now test framing boundaries 3186 // Now test framing boundaries.
2591 for (size_t i = 0; i < arraysize(packet); ++i) { 3187 for (size_t i = 0; i < arraysize(packet); ++i) {
2592 string expected_error; 3188 string expected_error;
2593 DVLOG(1) << "iteration: " << i; 3189 DVLOG(1) << "iteration: " << i;
2594 if (i < kConnectionIdOffset) { 3190 if (i < kConnectionIdOffset) {
2595 expected_error = "Unable to read public flags."; 3191 expected_error = "Unable to read public flags.";
2596 CheckProcessingFails(packet, i, expected_error, 3192 CheckProcessingFails(packet, i, expected_error,
2597 QUIC_INVALID_PACKET_HEADER); 3193 QUIC_INVALID_PACKET_HEADER);
2598 } else if (i < kPublicResetPacketMessageTagOffset) { 3194 } else if (i < kPublicResetPacketMessageTagOffset) {
2599 expected_error = "Unable to read ConnectionId."; 3195 expected_error = "Unable to read ConnectionId.";
2600 CheckProcessingFails(packet, i, expected_error, 3196 CheckProcessingFails(packet, i, expected_error,
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
3042 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), 3638 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
3043 }; 3639 };
3044 3640
3045 QuicVersionVector versions; 3641 QuicVersionVector versions;
3046 versions.push_back(GetParam()); 3642 versions.push_back(GetParam());
3047 scoped_ptr<QuicEncryptedPacket> data( 3643 scoped_ptr<QuicEncryptedPacket> data(
3048 framer_.BuildVersionNegotiationPacket(header, versions)); 3644 framer_.BuildVersionNegotiationPacket(header, versions));
3049 3645
3050 test::CompareCharArraysWithHexError("constructed packet", 3646 test::CompareCharArraysWithHexError("constructed packet",
3051 data->data(), data->length(), 3647 data->data(), data->length(),
3648 AsChars(packet), arraysize(packet));
3649 }
3650
3651 TEST_P(QuicFramerTest, BuildAckFramePacketv22) {
3652 if (version_ > QUIC_VERSION_22) {
3653 return;
3654 }
3655 QuicPacketHeader header;
3656 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3657 header.public_header.reset_flag = false;
3658 header.public_header.version_flag = false;
3659 header.fec_flag = false;
3660 header.entropy_flag = true;
3661 header.packet_sequence_number = GG_UINT64_C(0x770123456789AA8);
3662 header.fec_group = 0;
3663
3664 QuicAckFrame ack_frame;
3665 ack_frame.entropy_hash = 0x43;
3666 ack_frame.largest_observed = GG_UINT64_C(0x770123456789ABF);
3667 ack_frame.delta_time_largest_observed = QuicTime::Delta::Zero();
3668 ack_frame.missing_packets.insert(
3669 GG_UINT64_C(0x770123456789ABE));
3670
3671 QuicFrames frames;
3672 frames.push_back(QuicFrame(&ack_frame));
3673
3674 unsigned char packet[] = {
3675 // public flags (8 byte connection_id)
3676 0x3C,
3677 // connection_id
3678 0x10, 0x32, 0x54, 0x76,
3679 0x98, 0xBA, 0xDC, 0xFE,
3680 // packet sequence number
3681 0xA8, 0x9A, 0x78, 0x56,
3682 0x34, 0x12,
3683 // private flags (entropy)
3684 0x01,
3685
3686 // frame type (ack frame)
3687 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
3688 0x6C,
3689 // entropy hash of all received packets.
3690 0x43,
3691 // largest observed packet sequence number
3692 0xBF, 0x9A, 0x78, 0x56,
3693 0x34, 0x12,
3694 // Zero delta time.
3695 0x0, 0x0,
3696 // num missing packet ranges
3697 0x01,
3698 // missing packet delta
3699 0x01,
3700 // 0 more missing packets in range.
3701 0x00,
3702 // 0 revived packets.
3703 0x00,
3704 };
3705
3706 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3707 ASSERT_TRUE(data != NULL);
3708
3709 test::CompareCharArraysWithHexError("constructed packet",
3710 data->data(), data->length(),
3052 AsChars(packet), arraysize(packet)); 3711 AsChars(packet), arraysize(packet));
3053 } 3712 }
3054 3713
3055 TEST_P(QuicFramerTest, BuildAckFramePacket) { 3714 TEST_P(QuicFramerTest, BuildAckFramePacket) {
3715 if (version_ <= QUIC_VERSION_22) {
3716 return;
3717 }
3056 QuicPacketHeader header; 3718 QuicPacketHeader header;
3057 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); 3719 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3058 header.public_header.reset_flag = false; 3720 header.public_header.reset_flag = false;
3059 header.public_header.version_flag = false; 3721 header.public_header.version_flag = false;
3060 header.fec_flag = false; 3722 header.fec_flag = false;
3061 header.entropy_flag = true; 3723 header.entropy_flag = true;
3062 header.packet_sequence_number = GG_UINT64_C(0x770123456789AA8); 3724 header.packet_sequence_number = GG_UINT64_C(0x770123456789AA8);
3063 header.fec_group = 0; 3725 header.fec_group = 0;
3064 3726
3065 QuicAckFrame ack_frame; 3727 QuicAckFrame ack_frame;
(...skipping 21 matching lines...) Expand all
3087 // frame type (ack frame) 3749 // frame type (ack frame)
3088 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) 3750 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
3089 0x6C, 3751 0x6C,
3090 // entropy hash of all received packets. 3752 // entropy hash of all received packets.
3091 0x43, 3753 0x43,
3092 // largest observed packet sequence number 3754 // largest observed packet sequence number
3093 0xBF, 0x9A, 0x78, 0x56, 3755 0xBF, 0x9A, 0x78, 0x56,
3094 0x34, 0x12, 3756 0x34, 0x12,
3095 // Zero delta time. 3757 // Zero delta time.
3096 0x0, 0x0, 3758 0x0, 0x0,
3759 // num received packets.
3760 0x00,
3097 // num missing packet ranges 3761 // num missing packet ranges
3098 0x01, 3762 0x01,
3099 // missing packet delta 3763 // missing packet delta
3100 0x01, 3764 0x01,
3101 // 0 more missing packets in range. 3765 // 0 more missing packets in range.
3102 0x00, 3766 0x00,
3103 // 0 revived packets. 3767 // 0 revived packets.
3104 0x00, 3768 0x00,
3105 }; 3769 };
3106 3770
3107 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 3771 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3108 ASSERT_TRUE(data != NULL); 3772 ASSERT_TRUE(data != NULL);
3109 3773
3110 test::CompareCharArraysWithHexError("constructed packet", 3774 test::CompareCharArraysWithHexError("constructed packet",
3111 data->data(), data->length(), 3775 data->data(), data->length(),
3112 AsChars(packet), arraysize(packet)); 3776 AsChars(packet), arraysize(packet));
3113 } 3777 }
3114 3778
3115 // TODO(jri): Add test for tuncated packets in which the original ack frame had 3779 // TODO(jri): Add test for tuncated packets in which the original ack frame had
3116 // revived packets. (In both the large and small packet cases below). 3780 // revived packets. (In both the large and small packet cases below).
3117 TEST_P(QuicFramerTest, BuildTruncatedAckFrameLargePacket) { 3781
3782 TEST_P(QuicFramerTest, BuildTruncatedAckFrameLargePacketv22) {
3783 if (version_ > QUIC_VERSION_22) {
3784 return;
3785 }
3118 QuicPacketHeader header; 3786 QuicPacketHeader header;
3119 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); 3787 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3120 header.public_header.reset_flag = false; 3788 header.public_header.reset_flag = false;
3789 header.public_header.version_flag = false;
3790 header.fec_flag = false;
3791 header.entropy_flag = true;
3792 header.packet_sequence_number = GG_UINT64_C(0x770123456789AA8);
3793 header.fec_group = 0;
3794
3795 QuicAckFrame ack_frame;
3796 // This entropy hash is different from what shows up in the packet below,
3797 // since entropy is recomputed by the framer on ack truncation (by
3798 // TestEntropyCalculator for this test.)
3799 ack_frame.entropy_hash = 0x43;
3800 ack_frame.largest_observed = 2 * 300;
3801 ack_frame.delta_time_largest_observed = QuicTime::Delta::Zero();
3802 for (size_t i = 1; i < 2 * 300; i += 2) {
3803 ack_frame.missing_packets.insert(i);
3804 }
3805
3806 QuicFrames frames;
3807 frames.push_back(QuicFrame(&ack_frame));
3808
3809 unsigned char packet[] = {
3810 // public flags (8 byte connection_id)
3811 0x3C,
3812 // connection_id
3813 0x10, 0x32, 0x54, 0x76,
3814 0x98, 0xBA, 0xDC, 0xFE,
3815 // packet sequence number
3816 0xA8, 0x9A, 0x78, 0x56,
3817 0x34, 0x12,
3818 // private flags (entropy)
3819 0x01,
3820
3821 // frame type (ack frame)
3822 // (has nacks, is truncated, 2 byte largest observed, 1 byte delta)
3823 0x74,
3824 // entropy hash of all received packets, set to 1 by TestEntropyCalculator
3825 // since ack is truncated.
3826 0x01,
3827 // 2-byte largest observed packet sequence number.
3828 // Expected to be 510 (0x1FE), since only 255 nack ranges can fit.
3829 0xFE, 0x01,
3830 // Zero delta time.
3831 0x0, 0x0,
3832 // num missing packet ranges (limited to 255 by size of this field).
3833 0xFF,
3834 // {missing packet delta, further missing packets in range}
3835 // 6 nack ranges x 42 + 3 nack ranges
3836 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3837 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3838 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3839 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3840 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3841 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3842 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3843 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3844 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3845 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3846
3847 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3848 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3849 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3850 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3851 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3852 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3853 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3854 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3855 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3856 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3857
3858 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3859 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3860 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3861 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3862 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3863 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3864 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3865 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3866 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3867 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3868
3869 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3870 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3871 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3872 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3873 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3874 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3875 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3876 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3877 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3878 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3879
3880 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3881 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3882 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3883
3884 // 0 revived packets.
3885 0x00,
3886 };
3887
3888 scoped_ptr<QuicPacket> data(
3889 framer_.BuildDataPacket(header, frames, kMaxPacketSize).packet);
3890 ASSERT_TRUE(data != NULL);
3891
3892 test::CompareCharArraysWithHexError("constructed packet",
3893 data->data(), data->length(),
3894 AsChars(packet), arraysize(packet));
3895 }
3896
3897 TEST_P(QuicFramerTest, BuildTruncatedAckFrameLargePacket) {
3898 if (version_ <= QUIC_VERSION_22) {
3899 return;
3900 }
3901 QuicPacketHeader header;
3902 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3903 header.public_header.reset_flag = false;
3121 header.public_header.version_flag = false; 3904 header.public_header.version_flag = false;
3122 header.fec_flag = false; 3905 header.fec_flag = false;
3123 header.entropy_flag = true; 3906 header.entropy_flag = true;
3124 header.packet_sequence_number = GG_UINT64_C(0x770123456789AA8); 3907 header.packet_sequence_number = GG_UINT64_C(0x770123456789AA8);
3125 header.fec_group = 0; 3908 header.fec_group = 0;
3126 3909
3127 QuicAckFrame ack_frame; 3910 QuicAckFrame ack_frame;
3128 // This entropy hash is different from what shows up in the packet below, 3911 // This entropy hash is different from what shows up in the packet below,
3129 // since entropy is recomputed by the framer on ack truncation (by 3912 // since entropy is recomputed by the framer on ack truncation (by
3130 // TestEntropyCalculator for this test.) 3913 // TestEntropyCalculator for this test.)
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
3220 scoped_ptr<QuicPacket> data( 4003 scoped_ptr<QuicPacket> data(
3221 framer_.BuildDataPacket(header, frames, kMaxPacketSize).packet); 4004 framer_.BuildDataPacket(header, frames, kMaxPacketSize).packet);
3222 ASSERT_TRUE(data != NULL); 4005 ASSERT_TRUE(data != NULL);
3223 4006
3224 test::CompareCharArraysWithHexError("constructed packet", 4007 test::CompareCharArraysWithHexError("constructed packet",
3225 data->data(), data->length(), 4008 data->data(), data->length(),
3226 AsChars(packet), arraysize(packet)); 4009 AsChars(packet), arraysize(packet));
3227 } 4010 }
3228 4011
3229 4012
3230 TEST_P(QuicFramerTest, BuildTruncatedAckFrameSmallPacket) { 4013 TEST_P(QuicFramerTest, BuildTruncatedAckFrameSmallPacketv22) {
4014 if (version_ > QUIC_VERSION_22) {
4015 return;
4016 }
3231 QuicPacketHeader header; 4017 QuicPacketHeader header;
3232 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); 4018 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3233 header.public_header.reset_flag = false; 4019 header.public_header.reset_flag = false;
4020 header.public_header.version_flag = false;
4021 header.fec_flag = false;
4022 header.entropy_flag = true;
4023 header.packet_sequence_number = GG_UINT64_C(0x770123456789AA8);
4024 header.fec_group = 0;
4025
4026 QuicAckFrame ack_frame;
4027 // This entropy hash is different from what shows up in the packet below,
4028 // since entropy is recomputed by the framer on ack truncation (by
4029 // TestEntropyCalculator for this test.)
4030 ack_frame.entropy_hash = 0x43;
4031 ack_frame.largest_observed = 2 * 300;
4032 ack_frame.delta_time_largest_observed = QuicTime::Delta::Zero();
4033 for (size_t i = 1; i < 2 * 300; i += 2) {
4034 ack_frame.missing_packets.insert(i);
4035 }
4036
4037 QuicFrames frames;
4038 frames.push_back(QuicFrame(&ack_frame));
4039
4040 unsigned char packet[] = {
4041 // public flags (8 byte connection_id)
4042 0x3C,
4043 // connection_id
4044 0x10, 0x32, 0x54, 0x76,
4045 0x98, 0xBA, 0xDC, 0xFE,
4046 // packet sequence number
4047 0xA8, 0x9A, 0x78, 0x56,
4048 0x34, 0x12,
4049 // private flags (entropy)
4050 0x01,
4051
4052 // frame type (ack frame)
4053 // (has nacks, is truncated, 2 byte largest observed, 1 byte delta)
4054 0x74,
4055 // entropy hash of all received packets, set to 1 by TestEntropyCalculator
4056 // since ack is truncated.
4057 0x01,
4058 // 2-byte largest observed packet sequence number.
4059 // Expected to be 12 (0x0C), since only 6 nack ranges can fit.
4060 0x0C, 0x00,
4061 // Zero delta time.
4062 0x0, 0x0,
4063 // num missing packet ranges (limited to 6 by packet size of 37).
4064 0x06,
4065 // {missing packet delta, further missing packets in range}
4066 // 6 nack ranges
4067 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
4068 // 0 revived packets.
4069 0x00,
4070 };
4071
4072 scoped_ptr<QuicPacket> data(
4073 framer_.BuildDataPacket(header, frames, 37u).packet);
4074 ASSERT_TRUE(data != NULL);
4075 // Expect 1 byte unused since at least 2 bytes are needed to fit more nacks.
4076 EXPECT_EQ(36u, data->length());
4077 test::CompareCharArraysWithHexError("constructed packet",
4078 data->data(), data->length(),
4079 AsChars(packet), arraysize(packet));
4080 }
4081
4082 TEST_P(QuicFramerTest, BuildTruncatedAckFrameSmallPacket) {
4083 if (version_ <= QUIC_VERSION_22) {
4084 return;
4085 }
4086 QuicPacketHeader header;
4087 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
4088 header.public_header.reset_flag = false;
3234 header.public_header.version_flag = false; 4089 header.public_header.version_flag = false;
3235 header.fec_flag = false; 4090 header.fec_flag = false;
3236 header.entropy_flag = true; 4091 header.entropy_flag = true;
3237 header.packet_sequence_number = GG_UINT64_C(0x770123456789AA8); 4092 header.packet_sequence_number = GG_UINT64_C(0x770123456789AA8);
3238 header.fec_group = 0; 4093 header.fec_group = 0;
3239 4094
3240 QuicAckFrame ack_frame; 4095 QuicAckFrame ack_frame;
3241 // This entropy hash is different from what shows up in the packet below, 4096 // This entropy hash is different from what shows up in the packet below,
3242 // since entropy is recomputed by the framer on ack truncation (by 4097 // since entropy is recomputed by the framer on ack truncation (by
3243 // TestEntropyCalculator for this test.) 4098 // TestEntropyCalculator for this test.)
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
3389 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); 4244 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3390 header.public_header.reset_flag = false; 4245 header.public_header.reset_flag = false;
3391 header.public_header.version_flag = false; 4246 header.public_header.version_flag = false;
3392 header.fec_flag = false; 4247 header.fec_flag = false;
3393 header.entropy_flag = false; 4248 header.entropy_flag = false;
3394 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); 4249 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
3395 header.fec_group = 0; 4250 header.fec_group = 0;
3396 4251
3397 QuicCongestionFeedbackFrame congestion_feedback_frame; 4252 QuicCongestionFeedbackFrame congestion_feedback_frame;
3398 congestion_feedback_frame.type = 4253 congestion_feedback_frame.type =
3399 static_cast<CongestionFeedbackType>(kTimestamp + 1); 4254 static_cast<CongestionFeedbackType>(kTCP + 1);
3400 4255
3401 QuicFrames frames; 4256 QuicFrames frames;
3402 frames.push_back(QuicFrame(&congestion_feedback_frame)); 4257 frames.push_back(QuicFrame(&congestion_feedback_frame));
3403 4258
3404 scoped_ptr<QuicPacket> data; 4259 scoped_ptr<QuicPacket> data;
3405 EXPECT_DFATAL( 4260 EXPECT_DFATAL(
3406 data.reset(BuildDataPacket(header, frames)), 4261 data.reset(BuildDataPacket(header, frames)),
3407 "AppendCongestionFeedbackFrame failed"); 4262 "AppendCongestionFeedbackFrame failed");
3408 ASSERT_TRUE(data == NULL); 4263 ASSERT_TRUE(data == NULL);
3409 } 4264 }
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
3946 EXPECT_EQ(510u, processed_ack_frame.largest_observed); 4801 EXPECT_EQ(510u, processed_ack_frame.largest_observed);
3947 ASSERT_EQ(255u, processed_ack_frame.missing_packets.size()); 4802 ASSERT_EQ(255u, processed_ack_frame.missing_packets.size());
3948 SequenceNumberSet::const_iterator missing_iter = 4803 SequenceNumberSet::const_iterator missing_iter =
3949 processed_ack_frame.missing_packets.begin(); 4804 processed_ack_frame.missing_packets.begin();
3950 EXPECT_EQ(1u, *missing_iter); 4805 EXPECT_EQ(1u, *missing_iter);
3951 SequenceNumberSet::const_reverse_iterator last_missing_iter = 4806 SequenceNumberSet::const_reverse_iterator last_missing_iter =
3952 processed_ack_frame.missing_packets.rbegin(); 4807 processed_ack_frame.missing_packets.rbegin();
3953 EXPECT_EQ(509u, *last_missing_iter); 4808 EXPECT_EQ(509u, *last_missing_iter);
3954 } 4809 }
3955 4810
3956 TEST_P(QuicFramerTest, AckTruncationSmallPacket) { 4811 TEST_P(QuicFramerTest, AckTruncationSmallPacketv22) {
4812 if (version_ > QUIC_VERSION_22) {
4813 return;
4814 }
3957 QuicPacketHeader header; 4815 QuicPacketHeader header;
3958 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); 4816 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3959 header.public_header.reset_flag = false; 4817 header.public_header.reset_flag = false;
4818 header.public_header.version_flag = false;
4819 header.fec_flag = false;
4820 header.entropy_flag = false;
4821 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
4822 header.fec_group = 0;
4823
4824 // Create a packet with just the ack.
4825 QuicAckFrame ack_frame = MakeAckFrameWithNackRanges(300, 0u);
4826 QuicFrame frame;
4827 frame.type = ACK_FRAME;
4828 frame.ack_frame = &ack_frame;
4829 QuicFrames frames;
4830 frames.push_back(frame);
4831
4832 // Build an ack packet with truncation due to limit in number of nack ranges.
4833 scoped_ptr<QuicPacket> raw_ack_packet(
4834 framer_.BuildDataPacket(header, frames, 500).packet);
4835 ASSERT_TRUE(raw_ack_packet != NULL);
4836 scoped_ptr<QuicEncryptedPacket> ack_packet(
4837 framer_.EncryptPacket(ENCRYPTION_NONE, header.packet_sequence_number,
4838 *raw_ack_packet));
4839 // Now make sure we can turn our ack packet back into an ack frame.
4840 ASSERT_TRUE(framer_.ProcessPacket(*ack_packet));
4841 ASSERT_EQ(1u, visitor_.ack_frames_.size());
4842 QuicAckFrame& processed_ack_frame = *visitor_.ack_frames_[0];
4843 EXPECT_TRUE(processed_ack_frame.is_truncated);
4844 EXPECT_EQ(476u, processed_ack_frame.largest_observed);
4845 ASSERT_EQ(238u, processed_ack_frame.missing_packets.size());
4846 SequenceNumberSet::const_iterator missing_iter =
4847 processed_ack_frame.missing_packets.begin();
4848 EXPECT_EQ(1u, *missing_iter);
4849 SequenceNumberSet::const_reverse_iterator last_missing_iter =
4850 processed_ack_frame.missing_packets.rbegin();
4851 EXPECT_EQ(475u, *last_missing_iter);
4852 }
4853
4854
4855 TEST_P(QuicFramerTest, AckTruncationSmallPacket) {
4856 if (version_ <= QUIC_VERSION_22) {
4857 return;
4858 }
4859 QuicPacketHeader header;
4860 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
4861 header.public_header.reset_flag = false;
3960 header.public_header.version_flag = false; 4862 header.public_header.version_flag = false;
3961 header.fec_flag = false; 4863 header.fec_flag = false;
3962 header.entropy_flag = false; 4864 header.entropy_flag = false;
3963 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); 4865 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
3964 header.fec_group = 0; 4866 header.fec_group = 0;
3965 4867
3966 // Create a packet with just the ack. 4868 // Create a packet with just the ack.
3967 QuicAckFrame ack_frame = MakeAckFrameWithNackRanges(300, 0u); 4869 QuicAckFrame ack_frame = MakeAckFrameWithNackRanges(300, 0u);
3968 QuicFrame frame; 4870 QuicFrame frame;
3969 frame.type = ACK_FRAME; 4871 frame.type = ACK_FRAME;
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
4167 EXPECT_CALL(visitor, OnPacketComplete()); 5069 EXPECT_CALL(visitor, OnPacketComplete());
4168 EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)).WillOnce(Return(true)); 5070 EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)).WillOnce(Return(true));
4169 5071
4170 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 5072 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
4171 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 5073 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
4172 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 5074 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
4173 } 5075 }
4174 5076
4175 } // namespace test 5077 } // namespace test
4176 } // namespace net 5078 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_framer.cc ('k') | net/quic/quic_http_stream_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698