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

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

Issue 2850573002: Landing Recent QUIC changes until 3:35 PM, Apr 26, 2017 UTC-4 (Closed)
Patch Set: Remove Disconnect from ~QuicTestClient Created 3 years, 7 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/core/quic_framer.cc ('k') | net/quic/core/quic_packet_creator.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/core/quic_framer.h" 5 #include "net/quic/core/quic_framer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cstdint> 8 #include <cstdint>
9 #include <map> 9 #include <map>
10 #include <memory> 10 #include <memory>
(...skipping 13 matching lines...) Expand all
24 #include "net/quic/test_tools/quic_test_utils.h" 24 #include "net/quic/test_tools/quic_test_utils.h"
25 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
26 26
27 using std::string; 27 using std::string;
28 using testing::Return; 28 using testing::Return;
29 using testing::Truly; 29 using testing::Truly;
30 using testing::_; 30 using testing::_;
31 31
32 namespace net { 32 namespace net {
33 namespace test { 33 namespace test {
34 namespace {
34 35
35 const QuicPacketNumber kEpoch = UINT64_C(1) << 48; 36 const QuicPacketNumber kEpoch = UINT64_C(1) << 48;
36 const QuicPacketNumber kMask = kEpoch - 1; 37 const QuicPacketNumber kMask = kEpoch - 1;
37 38
38 // Use fields in which each byte is distinct to ensure that every byte is 39 // Use fields in which each byte is distinct to ensure that every byte is
39 // framed correctly. The values are otherwise arbitrary. 40 // framed correctly. The values are otherwise arbitrary.
40 const QuicConnectionId kConnectionId = UINT64_C(0xFEDCBA9876543210); 41 const QuicConnectionId kConnectionId = UINT64_C(0xFEDCBA9876543210);
41 const QuicPacketNumber kPacketNumber = UINT64_C(0x123456789ABC); 42 const QuicPacketNumber kPacketNumber = UINT64_C(0x123456789ABC);
42 const QuicPacketNumber kSmallLargestObserved = UINT16_C(0x1234); 43 const QuicPacketNumber kSmallLargestObserved = UINT16_C(0x1234);
43 const QuicPacketNumber kSmallMissingPacket = UINT16_C(0x1233); 44 const QuicPacketNumber kSmallMissingPacket = UINT16_C(0x1233);
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 440
440 QuicFlagSaver flags_; // Save/restore all QUIC flag values. 441 QuicFlagSaver flags_; // Save/restore all QUIC flag values.
441 test::TestEncrypter* encrypter_; 442 test::TestEncrypter* encrypter_;
442 test::TestDecrypter* decrypter_; 443 test::TestDecrypter* decrypter_;
443 QuicVersion version_; 444 QuicVersion version_;
444 QuicTime start_; 445 QuicTime start_;
445 QuicFramer framer_; 446 QuicFramer framer_;
446 test::TestQuicVisitor visitor_; 447 test::TestQuicVisitor visitor_;
447 }; 448 };
448 449
450 // Helper function to get index of packets in hex format.
451 // For each packet in hex format, integers and floating numbers are in big
452 // endian for v38 and up, and connection ID is in big endian according to
453 // perspective and flags.
454 // There are 4 combinations:
455 // 0 : little endian connection ID, little endian integers/floating numbers.
456 // 1 : big endian connection ID, little endian integers/floating numbers.
457 // 2 : little endian connection ID, big endian integers/floating numbers.
458 // 3 : big endian connection ID, big endian integers/floating numbers.
459 size_t GetPacketIndex(QuicVersion version, Perspective perspective) {
460 size_t index = 0;
461 if (QuicUtils::IsConnectionIdWireFormatBigEndian(perspective)) {
462 index = 1;
463 }
464 if (version > QUIC_VERSION_38) {
465 index += 2;
466 }
467 return index;
468 }
469
449 // Run all framer tests with all supported versions of QUIC. 470 // Run all framer tests with all supported versions of QUIC.
450 INSTANTIATE_TEST_CASE_P(QuicFramerTests, 471 INSTANTIATE_TEST_CASE_P(QuicFramerTests,
451 QuicFramerTest, 472 QuicFramerTest,
452 ::testing::ValuesIn(kSupportedQuicVersions)); 473 ::testing::ValuesIn(kSupportedQuicVersions));
453 474
454 TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearEpochStart) { 475 TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearEpochStart) {
455 // A few quick manual sanity checks. 476 // A few quick manual sanity checks.
456 CheckCalculatePacketNumber(UINT64_C(1), UINT64_C(0)); 477 CheckCalculatePacketNumber(UINT64_C(1), UINT64_C(0));
457 CheckCalculatePacketNumber(kEpoch + 1, kMask); 478 CheckCalculatePacketNumber(kEpoch + 1, kMask);
458 CheckCalculatePacketNumber(kEpoch, kMask); 479 CheckCalculatePacketNumber(kEpoch, kMask);
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 }; 641 };
621 642
622 unsigned char packet_cid_be[] = { 643 unsigned char packet_cid_be[] = {
623 // public flags (8 byte connection_id) 644 // public flags (8 byte connection_id)
624 0x38, 645 0x38,
625 // connection_id 646 // connection_id
626 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 647 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
627 // packet number 648 // packet number
628 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, 649 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
629 }; 650 };
651
652 unsigned char packet39[] = {
653 // public flags (8 byte connection_id)
654 0x38,
655 // connection_id
656 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
657 // packet number
658 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC,
659 };
660
661 unsigned char packet_cid_be39[] = {
662 // public flags (8 byte connection_id)
663 0x38,
664 // connection_id
665 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
666 // packet number
667 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC,
668 };
630 // clang-format on 669 // clang-format on
631 670
632 QuicEncryptedPacket encrypted( 671 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
633 AsChars( 672 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
634 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 673
635 ? packet_cid_be 674 QuicEncryptedPacket encrypted(AsChars(packets[index]), arraysize(packet),
636 : packet), 675 false);
637 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
638 ? arraysize(packet_cid_be)
639 : arraysize(packet),
640 false);
641 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); 676 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
642 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); 677 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
643 ASSERT_TRUE(visitor_.header_.get()); 678 ASSERT_TRUE(visitor_.header_.get());
644 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); 679 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id);
645 EXPECT_FALSE(visitor_.header_->public_header.multipath_flag); 680 EXPECT_FALSE(visitor_.header_->public_header.multipath_flag);
646 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); 681 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
647 EXPECT_FALSE(visitor_.header_->public_header.version_flag); 682 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
648 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); 683 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number);
649 684
650 // Now test framing boundaries. 685 // Now test framing boundaries.
651 for (size_t i = 0; 686 for (size_t i = 0;
652 i < GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, 687 i < GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID,
653 !kIncludeVersion, !kIncludeDiversificationNonce, 688 !kIncludeVersion, !kIncludeDiversificationNonce,
654 PACKET_6BYTE_PACKET_NUMBER); 689 PACKET_6BYTE_PACKET_NUMBER);
655 ++i) { 690 ++i) {
656 string expected_error; 691 string expected_error;
657 if (i < kConnectionIdOffset) { 692 if (i < kConnectionIdOffset) {
658 expected_error = "Unable to read public flags."; 693 expected_error = "Unable to read public flags.";
659 } else if (i < GetPacketNumberOffset(!kIncludeVersion)) { 694 } else if (i < GetPacketNumberOffset(!kIncludeVersion)) {
660 expected_error = "Unable to read ConnectionId."; 695 expected_error = "Unable to read ConnectionId.";
661 } else { 696 } else {
662 expected_error = "Unable to read packet number."; 697 expected_error = "Unable to read packet number.";
663 } 698 }
664 CheckProcessingFails( 699 CheckProcessingFails(packets[index], i, expected_error,
665 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 700 QUIC_INVALID_PACKET_HEADER);
666 ? packet_cid_be
667 : packet,
668 i, expected_error, QUIC_INVALID_PACKET_HEADER);
669 } 701 }
670 } 702 }
671 703
672 TEST_P(QuicFramerTest, PacketHeaderWith0ByteConnectionId) { 704 TEST_P(QuicFramerTest, PacketHeaderWith0ByteConnectionId) {
673 QuicFramerPeer::SetLastSerializedConnectionId(&framer_, kConnectionId); 705 QuicFramerPeer::SetLastSerializedConnectionId(&framer_, kConnectionId);
674 706
675 // clang-format off 707 // clang-format off
676 unsigned char packet[] = { 708 unsigned char packet[] = {
677 // public flags (0 byte connection_id) 709 // public flags (0 byte connection_id)
678 0x30, 710 0x30,
679 // connection_id 711 // connection_id
680 // packet number 712 // packet number
681 0xBC, 0x9A, 0x78, 0x56, 713 0xBC, 0x9A, 0x78, 0x56,
682 0x34, 0x12, 714 0x34, 0x12,
683 }; 715 };
716
717 unsigned char packet39[] = {
718 // public flags (0 byte connection_id)
719 0x30,
720 // connection_id
721 // packet number
722 0x12, 0x34, 0x56, 0x78,
723 0x9A, 0xBC,
724 };
684 // clang-format on 725 // clang-format on
685 726
686 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 727 QuicEncryptedPacket encrypted(
728 AsChars(framer_.version() > QUIC_VERSION_38 ? packet39 : packet),
729 arraysize(packet), false);
687 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); 730 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
688 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); 731 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
689 ASSERT_TRUE(visitor_.header_.get()); 732 ASSERT_TRUE(visitor_.header_.get());
690 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); 733 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id);
691 EXPECT_FALSE(visitor_.header_->public_header.multipath_flag); 734 EXPECT_FALSE(visitor_.header_->public_header.multipath_flag);
692 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); 735 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
693 EXPECT_FALSE(visitor_.header_->public_header.version_flag); 736 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
694 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); 737 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number);
695 738
696 // Now test framing boundaries. 739 // Now test framing boundaries.
697 for (size_t i = 0; 740 for (size_t i = 0;
698 i < GetPacketHeaderSize(framer_.version(), PACKET_0BYTE_CONNECTION_ID, 741 i < GetPacketHeaderSize(framer_.version(), PACKET_0BYTE_CONNECTION_ID,
699 !kIncludeVersion, !kIncludeDiversificationNonce, 742 !kIncludeVersion, !kIncludeDiversificationNonce,
700 PACKET_6BYTE_PACKET_NUMBER); 743 PACKET_6BYTE_PACKET_NUMBER);
701 ++i) { 744 ++i) {
702 string expected_error; 745 string expected_error;
703 if (i < kConnectionIdOffset) { 746 if (i < kConnectionIdOffset) {
704 expected_error = "Unable to read public flags."; 747 expected_error = "Unable to read public flags.";
705 } else if (i < GetPacketNumberOffset(PACKET_0BYTE_CONNECTION_ID, 748 } else if (i < GetPacketNumberOffset(PACKET_0BYTE_CONNECTION_ID,
706 !kIncludeVersion)) { 749 !kIncludeVersion)) {
707 expected_error = "Unable to read ConnectionId."; 750 expected_error = "Unable to read ConnectionId.";
708 } else { 751 } else {
709 expected_error = "Unable to read packet number."; 752 expected_error = "Unable to read packet number.";
710 } 753 }
711 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER); 754 CheckProcessingFails(
755 framer_.version() > QUIC_VERSION_38 ? packet39 : packet, i,
756 expected_error, QUIC_INVALID_PACKET_HEADER);
712 } 757 }
713 } 758 }
714 759
715 TEST_P(QuicFramerTest, PacketHeaderWithVersionFlag) { 760 TEST_P(QuicFramerTest, PacketHeaderWithVersionFlag) {
716 // clang-format off 761 // clang-format off
717 unsigned char packet[] = { 762 unsigned char packet[] = {
718 // public flags (version) 763 // public flags (version)
719 0x39, 764 0x39,
720 // connection_id 765 // connection_id
721 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, 766 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
722 // version tag 767 // version tag
723 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), 768 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
724 // packet number 769 // packet number
725 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, 770 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
726 }; 771 };
727 772
728 unsigned char packet_cid_be[] = { 773 unsigned char packet_cid_be[] = {
729 // public flags (version) 774 // public flags (version)
730 0x39, 775 0x39,
731 // connection_id 776 // connection_id
732 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 777 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
733 // version tag 778 // version tag
734 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), 779 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
735 // packet number 780 // packet number
736 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, 781 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
737 }; 782 };
783
784 unsigned char packet39[] = {
785 // public flags (version)
786 0x39,
787 // connection_id
788 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
789 // version tag
790 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
791 // packet number
792 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC,
793 };
794
795 unsigned char packet_cid_be39[] = {
796 // public flags (version)
797 0x39,
798 // connection_id
799 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
800 // version tag
801 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
802 // packet number
803 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC,
804 };
738 // clang-format on 805 // clang-format on
739 806
740 QuicEncryptedPacket encrypted( 807 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
741 AsChars( 808 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
742 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 809
743 ? packet_cid_be 810 QuicEncryptedPacket encrypted(AsChars(packets[index]), arraysize(packet),
744 : packet), 811 false);
745 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
746 ? arraysize(packet_cid_be)
747 : arraysize(packet),
748 false);
749 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); 812 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
750 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); 813 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
751 ASSERT_TRUE(visitor_.header_.get()); 814 ASSERT_TRUE(visitor_.header_.get());
752 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); 815 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id);
753 EXPECT_FALSE(visitor_.header_->public_header.multipath_flag); 816 EXPECT_FALSE(visitor_.header_->public_header.multipath_flag);
754 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); 817 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
755 EXPECT_TRUE(visitor_.header_->public_header.version_flag); 818 EXPECT_TRUE(visitor_.header_->public_header.version_flag);
756 EXPECT_EQ(GetParam(), visitor_.header_->public_header.versions[0]); 819 EXPECT_EQ(GetParam(), visitor_.header_->public_header.versions[0]);
757 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); 820 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number);
758 821
759 // Now test framing boundaries. 822 // Now test framing boundaries.
760 for (size_t i = 0; 823 for (size_t i = 0;
761 i < GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, 824 i < GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID,
762 kIncludeVersion, !kIncludeDiversificationNonce, 825 kIncludeVersion, !kIncludeDiversificationNonce,
763 PACKET_6BYTE_PACKET_NUMBER); 826 PACKET_6BYTE_PACKET_NUMBER);
764 ++i) { 827 ++i) {
765 string expected_error; 828 string expected_error;
766 if (i < kConnectionIdOffset) { 829 if (i < kConnectionIdOffset) {
767 expected_error = "Unable to read public flags."; 830 expected_error = "Unable to read public flags.";
768 } else if (i < kVersionOffset) { 831 } else if (i < kVersionOffset) {
769 expected_error = "Unable to read ConnectionId."; 832 expected_error = "Unable to read ConnectionId.";
770 } else if (i < GetPacketNumberOffset(kIncludeVersion)) { 833 } else if (i < GetPacketNumberOffset(kIncludeVersion)) {
771 expected_error = "Unable to read protocol version."; 834 expected_error = "Unable to read protocol version.";
772 } else { 835 } else {
773 expected_error = "Unable to read packet number."; 836 expected_error = "Unable to read packet number.";
774 } 837 }
775 CheckProcessingFails( 838 CheckProcessingFails(packets[index], i, expected_error,
776 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 839 QUIC_INVALID_PACKET_HEADER);
777 ? packet_cid_be
778 : packet,
779 i, expected_error, QUIC_INVALID_PACKET_HEADER);
780 } 840 }
781 } 841 }
782 842
783 TEST_P(QuicFramerTest, PacketHeaderWith4BytePacketNumber) { 843 TEST_P(QuicFramerTest, PacketHeaderWith4BytePacketNumber) {
784 QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2); 844 QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2);
785 845
786 // clang-format off 846 // clang-format off
787 unsigned char packet[] = { 847 unsigned char packet[] = {
788 // public flags (8 byte connection_id and 4 byte packet number) 848 // public flags (8 byte connection_id and 4 byte packet number)
789 0x28, 849 0x28,
790 // connection_id 850 // connection_id
791 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, 851 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
792 // packet number 852 // packet number
793 0xBC, 0x9A, 0x78, 0x56, 853 0xBC, 0x9A, 0x78, 0x56,
794 }; 854 };
795 855
796 unsigned char packet_cid_be[] = { 856 unsigned char packet_cid_be[] = {
797 // public flags (8 byte connection_id and 4 byte packet number) 857 // public flags (8 byte connection_id and 4 byte packet number)
798 0x28, 858 0x28,
799 // connection_id 859 // connection_id
800 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 860 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
801 // packet number 861 // packet number
802 0xBC, 0x9A, 0x78, 0x56, 862 0xBC, 0x9A, 0x78, 0x56,
803 }; 863 };
864
865 unsigned char packet39[] = {
866 // public flags (8 byte connection_id and 4 byte packet number)
867 0x28,
868 // connection_id
869 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
870 // packet number
871 0x56, 0x78, 0x9A, 0xBC,
872 };
873
874 unsigned char packet_cid_be39[] = {
875 // public flags (8 byte connection_id and 4 byte packet number)
876 0x28,
877 // connection_id
878 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
879 // packet number
880 0x56, 0x78, 0x9A, 0xBC,
881 };
804 // clang-format on 882 // clang-format on
805 883
806 QuicEncryptedPacket encrypted( 884 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
807 AsChars( 885 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
808 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 886
809 ? packet_cid_be 887 QuicEncryptedPacket encrypted(AsChars(packets[index]), arraysize(packet),
810 : packet), 888 false);
811 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
812 ? arraysize(packet_cid_be)
813 : arraysize(packet),
814 false);
815 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); 889 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
816 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); 890 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
817 ASSERT_TRUE(visitor_.header_.get()); 891 ASSERT_TRUE(visitor_.header_.get());
818 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); 892 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id);
819 EXPECT_FALSE(visitor_.header_->public_header.multipath_flag); 893 EXPECT_FALSE(visitor_.header_->public_header.multipath_flag);
820 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); 894 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
821 EXPECT_FALSE(visitor_.header_->public_header.version_flag); 895 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
822 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); 896 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number);
823 897
824 // Now test framing boundaries. 898 // Now test framing boundaries.
825 for (size_t i = 0; 899 for (size_t i = 0;
826 i < GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, 900 i < GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID,
827 !kIncludeVersion, !kIncludeDiversificationNonce, 901 !kIncludeVersion, !kIncludeDiversificationNonce,
828 PACKET_4BYTE_PACKET_NUMBER); 902 PACKET_4BYTE_PACKET_NUMBER);
829 ++i) { 903 ++i) {
830 string expected_error; 904 string expected_error;
831 if (i < kConnectionIdOffset) { 905 if (i < kConnectionIdOffset) {
832 expected_error = "Unable to read public flags."; 906 expected_error = "Unable to read public flags.";
833 } else if (i < GetPacketNumberOffset(!kIncludeVersion)) { 907 } else if (i < GetPacketNumberOffset(!kIncludeVersion)) {
834 expected_error = "Unable to read ConnectionId."; 908 expected_error = "Unable to read ConnectionId.";
835 } else { 909 } else {
836 expected_error = "Unable to read packet number."; 910 expected_error = "Unable to read packet number.";
837 } 911 }
838 CheckProcessingFails( 912 CheckProcessingFails(packets[index], i, expected_error,
839 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 913 QUIC_INVALID_PACKET_HEADER);
840 ? packet_cid_be
841 : packet,
842 i, expected_error, QUIC_INVALID_PACKET_HEADER);
843 } 914 }
844 } 915 }
845 916
846 TEST_P(QuicFramerTest, PacketHeaderWith2BytePacketNumber) { 917 TEST_P(QuicFramerTest, PacketHeaderWith2BytePacketNumber) {
847 QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2); 918 QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2);
848 919
849 // clang-format off 920 // clang-format off
850 unsigned char packet[] = { 921 unsigned char packet[] = {
851 // public flags (8 byte connection_id and 2 byte packet number) 922 // public flags (8 byte connection_id and 2 byte packet number)
852 0x18, 923 0x18,
853 // connection_id 924 // connection_id
854 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, 925 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
855 // packet number 926 // packet number
856 0xBC, 0x9A, 927 0xBC, 0x9A,
857 }; 928 };
858 929
859 unsigned char packet_cid_be[] = { 930 unsigned char packet_cid_be[] = {
860 // public flags (8 byte connection_id and 2 byte packet number) 931 // public flags (8 byte connection_id and 2 byte packet number)
861 0x18, 932 0x18,
862 // connection_id 933 // connection_id
863 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 934 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
864 // packet number 935 // packet number
865 0xBC, 0x9A, 936 0xBC, 0x9A,
866 }; 937 };
938
939 unsigned char packet39[] = {
940 // public flags (8 byte connection_id and 2 byte packet number)
941 0x18,
942 // connection_id
943 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
944 // packet number
945 0x9A, 0xBC,
946 };
947
948 unsigned char packet_cid_be39[] = {
949 // public flags (8 byte connection_id and 2 byte packet number)
950 0x18,
951 // connection_id
952 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
953 // packet number
954 0x9A, 0xBC,
955 };
867 // clang-format on 956 // clang-format on
868 957
869 QuicEncryptedPacket encrypted( 958 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
870 AsChars( 959 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
871 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 960
872 ? packet_cid_be 961 QuicEncryptedPacket encrypted(AsChars(packets[index]), arraysize(packet),
873 : packet), 962 false);
874 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
875 ? arraysize(packet_cid_be)
876 : arraysize(packet),
877 false);
878 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); 963 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
879 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); 964 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
880 ASSERT_TRUE(visitor_.header_.get()); 965 ASSERT_TRUE(visitor_.header_.get());
881 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); 966 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id);
882 EXPECT_FALSE(visitor_.header_->public_header.multipath_flag); 967 EXPECT_FALSE(visitor_.header_->public_header.multipath_flag);
883 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); 968 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
884 EXPECT_FALSE(visitor_.header_->public_header.version_flag); 969 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
885 EXPECT_EQ(PACKET_2BYTE_PACKET_NUMBER, 970 EXPECT_EQ(PACKET_2BYTE_PACKET_NUMBER,
886 visitor_.header_->public_header.packet_number_length); 971 visitor_.header_->public_header.packet_number_length);
887 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); 972 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number);
888 973
889 // Now test framing boundaries. 974 // Now test framing boundaries.
890 for (size_t i = 0; 975 for (size_t i = 0;
891 i < GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, 976 i < GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID,
892 !kIncludeVersion, !kIncludeDiversificationNonce, 977 !kIncludeVersion, !kIncludeDiversificationNonce,
893 PACKET_2BYTE_PACKET_NUMBER); 978 PACKET_2BYTE_PACKET_NUMBER);
894 ++i) { 979 ++i) {
895 string expected_error; 980 string expected_error;
896 if (i < kConnectionIdOffset) { 981 if (i < kConnectionIdOffset) {
897 expected_error = "Unable to read public flags."; 982 expected_error = "Unable to read public flags.";
898 } else if (i < GetPacketNumberOffset(!kIncludeVersion)) { 983 } else if (i < GetPacketNumberOffset(!kIncludeVersion)) {
899 expected_error = "Unable to read ConnectionId."; 984 expected_error = "Unable to read ConnectionId.";
900 } else { 985 } else {
901 expected_error = "Unable to read packet number."; 986 expected_error = "Unable to read packet number.";
902 } 987 }
903 CheckProcessingFails( 988 CheckProcessingFails(packets[index], i, expected_error,
904 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 989 QUIC_INVALID_PACKET_HEADER);
905 ? packet_cid_be
906 : packet,
907 i, expected_error, QUIC_INVALID_PACKET_HEADER);
908 } 990 }
909 } 991 }
910 992
911 TEST_P(QuicFramerTest, PacketHeaderWith1BytePacketNumber) { 993 TEST_P(QuicFramerTest, PacketHeaderWith1BytePacketNumber) {
912 QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2); 994 QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2);
913 995
914 // clang-format off 996 // clang-format off
915 unsigned char packet[] = { 997 unsigned char packet[] = {
916 // public flags (8 byte connection_id and 1 byte packet number) 998 // public flags (8 byte connection_id and 1 byte packet number)
917 0x08, 999 0x08,
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 1145 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
1064 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 1146 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
1065 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 1147 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
1066 // packet number 1148 // packet number
1067 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, 1149 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
1068 1150
1069 // frame type (padding) 1151 // frame type (padding)
1070 0x00, 1152 0x00,
1071 0x00, 0x00, 0x00, 0x00 1153 0x00, 0x00, 0x00, 0x00
1072 }; 1154 };
1155
1156 unsigned char packet39[] = {
1157 // public flags: includes nonce flag
1158 static_cast<unsigned char>(
1159 FLAGS_quic_reloadable_flag_quic_remove_multipath_bit ? 0x3C : 0x7C),
1160 // connection_id
1161 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
1162 // nonce
1163 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1164 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
1165 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
1166 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
1167 // packet number
1168 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC,
1169
1170 // frame type (padding)
1171 0x00,
1172 0x00, 0x00, 0x00, 0x00
1173 };
1174
1175 unsigned char packet_cid_be39[] = {
1176 // public flags: includes nonce flag
1177 static_cast<unsigned char>(
1178 FLAGS_quic_reloadable_flag_quic_remove_multipath_bit ? 0x3C : 0x7C),
1179 // connection_id
1180 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
1181 // nonce
1182 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1183 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
1184 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
1185 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
1186 // packet number
1187 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC,
1188
1189 // frame type (padding)
1190 0x00,
1191 0x00, 0x00, 0x00, 0x00
1192 };
1073 // clang-format on 1193 // clang-format on
1194 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
1195 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
1074 1196
1075 QuicEncryptedPacket encrypted( 1197 QuicEncryptedPacket encrypted(AsChars(packets[index]), arraysize(packet),
1076 AsChars( 1198 false);
1077 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
1078 ? packet_cid_be
1079 : packet),
1080 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
1081 ? arraysize(packet_cid_be)
1082 : arraysize(packet),
1083 false);
1084 QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); 1199 QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT);
1085 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1200 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1086 ASSERT_TRUE(visitor_.public_header_->nonce != nullptr); 1201 ASSERT_TRUE(visitor_.public_header_->nonce != nullptr);
1087 for (char i = 0; i < 32; ++i) { 1202 for (char i = 0; i < 32; ++i) {
1088 EXPECT_EQ(i, (*visitor_.public_header_->nonce)[static_cast<size_t>(i)]); 1203 EXPECT_EQ(i, (*visitor_.public_header_->nonce)[static_cast<size_t>(i)]);
1089 } 1204 }
1090 EXPECT_EQ(1u, visitor_.padding_frames_.size()); 1205 EXPECT_EQ(1u, visitor_.padding_frames_.size());
1091 EXPECT_EQ(5, visitor_.padding_frames_[0]->num_padding_bytes); 1206 EXPECT_EQ(5, visitor_.padding_frames_[0]->num_padding_bytes);
1092 }; 1207 };
1093 1208
(...skipping 26 matching lines...) Expand all
1120 // version tag 1235 // version tag
1121 'Q', '0', '0', '0', 1236 'Q', '0', '0', '0',
1122 // packet number 1237 // packet number
1123 0xBC, 0x9A, 0x78, 0x56, 1238 0xBC, 0x9A, 0x78, 0x56,
1124 0x34, 0x12, 1239 0x34, 0x12,
1125 1240
1126 // frame type (padding frame) 1241 // frame type (padding frame)
1127 0x00, 1242 0x00,
1128 0x00, 0x00, 0x00, 0x00 1243 0x00, 0x00, 0x00, 0x00
1129 }; 1244 };
1245
1246 unsigned char packet39[] = {
1247 // public flags (8 byte connection_id, version flag and an unknown flag)
1248 static_cast<unsigned char>(
1249 FLAGS_quic_reloadable_flag_quic_remove_multipath_bit ? 0x39 : 0x79),
1250 // connection_id
1251 0x10, 0x32, 0x54, 0x76,
1252 0x98, 0xBA, 0xDC, 0xFE,
1253 // version tag
1254 'Q', '0', '0', '0',
1255 // packet number
1256 0x12, 0x34, 0x56, 0x78,
1257 0x9A, 0xBC,
1258
1259 // frame type (padding frame)
1260 0x00,
1261 0x00, 0x00, 0x00, 0x00
1262 };
1263
1264 unsigned char packet_cid_be39[] = {
1265 // public flags (8 byte connection_id, version flag and an unknown flag)
1266 static_cast<unsigned char>(
1267 FLAGS_quic_reloadable_flag_quic_remove_multipath_bit ? 0x39 : 0x79),
1268 // connection_id
1269 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
1270 // version tag
1271 'Q', '0', '0', '0',
1272 // packet number
1273 0x12, 0x34, 0x56, 0x78,
1274 0x9A, 0xBC,
1275
1276 // frame type (padding frame)
1277 0x00,
1278 0x00, 0x00, 0x00, 0x00
1279 };
1130 // clang-format on 1280 // clang-format on
1131 QuicEncryptedPacket encrypted( 1281 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
1132 AsChars( 1282 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
1133 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 1283
1134 ? packet_cid_be 1284 QuicEncryptedPacket encrypted(AsChars(packets[index]), arraysize(packet),
1135 : packet), 1285 false);
1136 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
1137 ? arraysize(packet_cid_be)
1138 : arraysize(packet),
1139 false);
1140 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1286 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1141 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1287 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1142 ASSERT_TRUE(visitor_.header_.get()); 1288 ASSERT_TRUE(visitor_.header_.get());
1143 EXPECT_EQ(0, visitor_.frame_count_); 1289 EXPECT_EQ(0, visitor_.frame_count_);
1144 EXPECT_EQ(1, visitor_.version_mismatch_); 1290 EXPECT_EQ(1, visitor_.version_mismatch_);
1145 EXPECT_EQ(1u, visitor_.padding_frames_.size()); 1291 EXPECT_EQ(1u, visitor_.padding_frames_.size());
1146 EXPECT_EQ(5, visitor_.padding_frames_[0]->num_padding_bytes); 1292 EXPECT_EQ(5, visitor_.padding_frames_[0]->num_padding_bytes);
1147 }; 1293 };
1148 1294
1149 TEST_P(QuicFramerTest, PaddingFrame) { 1295 TEST_P(QuicFramerTest, PaddingFrame) {
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1289 0xDC, 0xFE, 0x98, 0xBA, 1435 0xDC, 0xFE, 0x98, 0xBA,
1290 // data length 1436 // data length
1291 0x0c, 0x00, 1437 0x0c, 0x00,
1292 // data 1438 // data
1293 'h', 'e', 'l', 'l', 1439 'h', 'e', 'l', 'l',
1294 'o', ' ', 'w', 'o', 1440 'o', ' ', 'w', 'o',
1295 'r', 'l', 'd', '!', 1441 'r', 'l', 'd', '!',
1296 // paddings 1442 // paddings
1297 0x00, 0x00, 1443 0x00, 0x00,
1298 }; 1444 };
1445
1446 unsigned char packet39[] = {
1447 // public flags (8 byte connection_id)
1448 0x38,
1449 // connection_id
1450 0x10, 0x32, 0x54, 0x76,
1451 0x98, 0xBA, 0xDC, 0xFE,
1452 // packet number
1453 0x12, 0x34, 0x56, 0x78,
1454 0x9A, 0xBC,
1455
1456 // paddings
1457 0x00, 0x00,
1458 // frame type (stream frame with fin)
1459 0xFF,
1460 // stream id
1461 0x01, 0x02, 0x03, 0x04,
1462 // offset
1463 0xBA, 0x98, 0xFE, 0xDC,
1464 0x32, 0x10, 0x76, 0x54,
1465 // data length
1466 0x00, 0x0c,
1467 // data
1468 'h', 'e', 'l', 'l',
1469 'o', ' ', 'w', 'o',
1470 'r', 'l', 'd', '!',
1471 // paddings
1472 0x00, 0x00,
1473 };
1474
1475 unsigned char packet_cid_be39[] = {
1476 // public flags (8 byte connection_id)
1477 0x38,
1478 // connection_id
1479 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
1480 // packet number
1481 0x12, 0x34, 0x56, 0x78,
1482 0x9A, 0xBC,
1483
1484 // paddings
1485 0x00, 0x00,
1486 // frame type (stream frame with fin)
1487 0xFF,
1488 // stream id
1489 0x01, 0x02, 0x03, 0x04,
1490 // offset
1491 0xBA, 0x98, 0xFE, 0xDC,
1492 0x32, 0x10, 0x76, 0x54,
1493 // data length
1494 0x00, 0x0c,
1495 // data
1496 'h', 'e', 'l', 'l',
1497 'o', ' ', 'w', 'o',
1498 'r', 'l', 'd', '!',
1499 // paddings
1500 0x00, 0x00,
1501 };
1299 // clang-format on 1502 // clang-format on
1300 1503
1301 if (framer_.version() <= QUIC_VERSION_37) { 1504 if (framer_.version() <= QUIC_VERSION_37) {
1302 return; 1505 return;
1303 } 1506 }
1304 1507
1305 QuicEncryptedPacket encrypted( 1508 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
1306 AsChars( 1509 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
1307 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 1510
1308 ? packet_cid_be 1511 QuicEncryptedPacket encrypted(AsChars(packets[index]), arraysize(packet),
1309 : packet), 1512 false);
1310 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
1311 ? arraysize(packet_cid_be)
1312 : arraysize(packet),
1313 false);
1314 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1513 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1315 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1514 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1316 ASSERT_TRUE(visitor_.header_.get()); 1515 ASSERT_TRUE(visitor_.header_.get());
1317 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, 1516 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion,
1318 !kIncludeDiversificationNonce)); 1517 !kIncludeDiversificationNonce));
1319 1518
1320 ASSERT_EQ(1u, visitor_.stream_frames_.size()); 1519 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1321 EXPECT_EQ(0u, visitor_.ack_frames_.size()); 1520 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1322 EXPECT_EQ(2u, visitor_.padding_frames_.size()); 1521 EXPECT_EQ(2u, visitor_.padding_frames_.size());
1323 EXPECT_EQ(2, visitor_.padding_frames_[0]->num_padding_bytes); 1522 EXPECT_EQ(2, visitor_.padding_frames_[0]->num_padding_bytes);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1371 // offset 1570 // offset
1372 0x54, 0x76, 0x10, 0x32, 1571 0x54, 0x76, 0x10, 0x32,
1373 0xDC, 0xFE, 0x98, 0xBA, 1572 0xDC, 0xFE, 0x98, 0xBA,
1374 // data length 1573 // data length
1375 0x0c, 0x00, 1574 0x0c, 0x00,
1376 // data 1575 // data
1377 'h', 'e', 'l', 'l', 1576 'h', 'e', 'l', 'l',
1378 'o', ' ', 'w', 'o', 1577 'o', ' ', 'w', 'o',
1379 'r', 'l', 'd', '!', 1578 'r', 'l', 'd', '!',
1380 }; 1579 };
1580
1581 unsigned char packet39[] = {
1582 // public flags (8 byte connection_id)
1583 0x38,
1584 // connection_id
1585 0x10, 0x32, 0x54, 0x76,
1586 0x98, 0xBA, 0xDC, 0xFE,
1587 // packet number
1588 0x12, 0x34, 0x56, 0x78,
1589 0x9A, 0xBC,
1590
1591 // frame type (stream frame with fin)
1592 0xFF,
1593 // stream id
1594 0x01, 0x02, 0x03, 0x04,
1595 // offset
1596 0xBA, 0x98, 0xFE, 0xDC,
1597 0x32, 0x10, 0x76, 0x54,
1598 // data length
1599 0x00, 0x0c,
1600 // data
1601 'h', 'e', 'l', 'l',
1602 'o', ' ', 'w', 'o',
1603 'r', 'l', 'd', '!',
1604 };
1605
1606 unsigned char packet_cid_be39[] = {
1607 // public flags (8 byte connection_id)
1608 0x38,
1609 // connection_id
1610 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
1611 // packet number
1612 0x12, 0x34, 0x56, 0x78,
1613 0x9A, 0xBC,
1614
1615 // frame type (stream frame with fin)
1616 0xFF,
1617 // stream id
1618 0x01, 0x02, 0x03, 0x04,
1619 // offset
1620 0xBA, 0x98, 0xFE, 0xDC,
1621 0x32, 0x10, 0x76, 0x54,
1622 // data length
1623 0x00, 0x0c,
1624 // data
1625 'h', 'e', 'l', 'l',
1626 'o', ' ', 'w', 'o',
1627 'r', 'l', 'd', '!',
1628 };
1381 // clang-format on 1629 // clang-format on
1630 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
1631 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
1382 1632
1383 QuicEncryptedPacket encrypted( 1633 QuicEncryptedPacket encrypted(AsChars(packets[index]), arraysize(packet),
1384 AsChars( 1634 false);
1385 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
1386 ? packet_cid_be
1387 : packet),
1388 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
1389 ? arraysize(packet_cid_be)
1390 : arraysize(packet),
1391 false);
1392 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1635 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1393 1636
1394 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1637 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1395 ASSERT_TRUE(visitor_.header_.get()); 1638 ASSERT_TRUE(visitor_.header_.get());
1396 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, 1639 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion,
1397 !kIncludeDiversificationNonce)); 1640 !kIncludeDiversificationNonce));
1398 1641
1399 ASSERT_EQ(1u, visitor_.stream_frames_.size()); 1642 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1400 EXPECT_EQ(0u, visitor_.ack_frames_.size()); 1643 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1401 EXPECT_EQ(kStreamId, visitor_.stream_frames_[0]->stream_id); 1644 EXPECT_EQ(kStreamId, visitor_.stream_frames_[0]->stream_id);
1402 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); 1645 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1403 EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); 1646 EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset);
1404 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); 1647 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get());
1405 1648
1406 // Now test framing boundaries. 1649 // Now test framing boundaries.
1407 CheckStreamFrameBoundaries( 1650 CheckStreamFrameBoundaries(packets[index], kQuicMaxStreamIdSize,
1408 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 1651 !kIncludeVersion);
1409 ? packet_cid_be
1410 : packet,
1411 kQuicMaxStreamIdSize, !kIncludeVersion);
1412 } 1652 }
1413 1653
1414 TEST_P(QuicFramerTest, MissingDiversificationNonce) { 1654 TEST_P(QuicFramerTest, MissingDiversificationNonce) {
1415 QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); 1655 QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT);
1416 framer_.SetDecrypter(ENCRYPTION_NONE, 1656 framer_.SetDecrypter(ENCRYPTION_NONE,
1417 new NullDecrypter(Perspective::IS_CLIENT)); 1657 new NullDecrypter(Perspective::IS_CLIENT));
1418 decrypter_ = new test::TestDecrypter(); 1658 decrypter_ = new test::TestDecrypter();
1419 framer_.SetAlternativeDecrypter(ENCRYPTION_INITIAL, decrypter_, false); 1659 framer_.SetAlternativeDecrypter(ENCRYPTION_INITIAL, decrypter_, false);
1420 1660
1421 // clang-format off 1661 // clang-format off
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1460 // offset 1700 // offset
1461 0x54, 0x76, 0x10, 0x32, 1701 0x54, 0x76, 0x10, 0x32,
1462 0xDC, 0xFE, 0x98, 0xBA, 1702 0xDC, 0xFE, 0x98, 0xBA,
1463 // data length 1703 // data length
1464 0x0c, 0x00, 1704 0x0c, 0x00,
1465 // data 1705 // data
1466 'h', 'e', 'l', 'l', 1706 'h', 'e', 'l', 'l',
1467 'o', ' ', 'w', 'o', 1707 'o', ' ', 'w', 'o',
1468 'r', 'l', 'd', '!', 1708 'r', 'l', 'd', '!',
1469 }; 1709 };
1710
1711 unsigned char packet39[] = {
1712 // public flags (8 byte connection_id)
1713 0x38,
1714 // connection_id
1715 0x10, 0x32, 0x54, 0x76,
1716 0x98, 0xBA, 0xDC, 0xFE,
1717 // packet number
1718 0x12, 0x34, 0x56, 0x78,
1719 0x9A, 0xBC,
1720
1721 // frame type (stream frame with fin)
1722 0xFF,
1723 // stream id
1724 0x01, 0x02, 0x03, 0x04,
1725 // offset
1726 0xBA, 0x98, 0xFE, 0xDC,
1727 0x32, 0x10, 0x76, 0x54,
1728 // data length
1729 0x00, 0x0c,
1730 // data
1731 'h', 'e', 'l', 'l',
1732 'o', ' ', 'w', 'o',
1733 'r', 'l', 'd', '!',
1734 };
1735
1736 unsigned char packet_cid_be39[] = {
1737 // public flags (8 byte connection_id)
1738 0x38,
1739 // connection_id
1740 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
1741 // packet number
1742 0x12, 0x34, 0x56, 0x78,
1743 0x9A, 0xBC,
1744
1745 // frame type (stream frame with fin)
1746 0xFF,
1747 // stream id
1748 0x01, 0x02, 0x03, 0x04,
1749 // offset
1750 0xBA, 0x98, 0xFE, 0xDC,
1751 0x32, 0x10, 0x76, 0x54,
1752 // data length
1753 0x00, 0x0c,
1754 // data
1755 'h', 'e', 'l', 'l',
1756 'o', ' ', 'w', 'o',
1757 'r', 'l', 'd', '!',
1758 };
1470 // clang-format on 1759 // clang-format on
1471 1760
1472 QuicEncryptedPacket encrypted( 1761 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
1473 AsChars( 1762 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
1474 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 1763
1475 ? packet_cid_be 1764 QuicEncryptedPacket encrypted(AsChars(packets[index]), arraysize(packet),
1476 : packet), 1765 false);
1477 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
1478 ? arraysize(packet_cid_be)
1479 : arraysize(packet),
1480 false);
1481 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); 1766 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
1482 EXPECT_EQ(QUIC_DECRYPTION_FAILURE, framer_.error()); 1767 EXPECT_EQ(QUIC_DECRYPTION_FAILURE, framer_.error());
1483 } 1768 }
1484 1769
1485 TEST_P(QuicFramerTest, StreamFrame3ByteStreamId) { 1770 TEST_P(QuicFramerTest, StreamFrame3ByteStreamId) {
1486 // clang-format off 1771 // clang-format off
1487 unsigned char packet[] = { 1772 unsigned char packet[] = {
1488 // public flags (8 byte connection_id) 1773 // public flags (8 byte connection_id)
1489 0x38, 1774 0x38,
1490 // connection_id 1775 // connection_id
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1525 // offset 1810 // offset
1526 0x54, 0x76, 0x10, 0x32, 1811 0x54, 0x76, 0x10, 0x32,
1527 0xDC, 0xFE, 0x98, 0xBA, 1812 0xDC, 0xFE, 0x98, 0xBA,
1528 // data length 1813 // data length
1529 0x0c, 0x00, 1814 0x0c, 0x00,
1530 // data 1815 // data
1531 'h', 'e', 'l', 'l', 1816 'h', 'e', 'l', 'l',
1532 'o', ' ', 'w', 'o', 1817 'o', ' ', 'w', 'o',
1533 'r', 'l', 'd', '!', 1818 'r', 'l', 'd', '!',
1534 }; 1819 };
1820
1821 unsigned char packet39[] = {
1822 // public flags (8 byte connection_id)
1823 0x38,
1824 // connection_id
1825 0x10, 0x32, 0x54, 0x76,
1826 0x98, 0xBA, 0xDC, 0xFE,
1827 // packet number
1828 0x12, 0x34, 0x56, 0x78,
1829 0x9A, 0xBC,
1830
1831 // frame type (stream frame with fin)
1832 0xFE,
1833 // stream id
1834 0x02, 0x03, 0x04,
1835 // offset
1836 0xBA, 0x98, 0xFE, 0xDC,
1837 0x32, 0x10, 0x76, 0x54,
1838 // data length
1839 0x00, 0x0c,
1840 // data
1841 'h', 'e', 'l', 'l',
1842 'o', ' ', 'w', 'o',
1843 'r', 'l', 'd', '!',
1844 };
1845
1846 unsigned char packet_cid_be39[] = {
1847 // public flags (8 byte connection_id)
1848 0x38,
1849 // connection_id
1850 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
1851 // packet number
1852 0x12, 0x34, 0x56, 0x78,
1853 0x9A, 0xBC,
1854
1855 // frame type (stream frame with fin)
1856 0xFE,
1857 // stream id
1858 0x02, 0x03, 0x04,
1859 // offset
1860 0xBA, 0x98, 0xFE, 0xDC,
1861 0x32, 0x10, 0x76, 0x54,
1862 // data length
1863 0x00, 0x0c,
1864 // data
1865 'h', 'e', 'l', 'l',
1866 'o', ' ', 'w', 'o',
1867 'r', 'l', 'd', '!',
1868 };
1535 // clang-format on 1869 // clang-format on
1536 1870
1537 QuicEncryptedPacket encrypted( 1871 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
1538 AsChars( 1872 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
1539 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 1873
1540 ? packet_cid_be 1874 QuicEncryptedPacket encrypted(AsChars(packets[index]), arraysize(packet),
1541 : packet), 1875 false);
1542 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
1543 ? arraysize(packet_cid_be)
1544 : arraysize(packet),
1545 false);
1546 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1876 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1547 1877
1548 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1878 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1549 ASSERT_TRUE(visitor_.header_.get()); 1879 ASSERT_TRUE(visitor_.header_.get());
1550 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, 1880 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion,
1551 !kIncludeDiversificationNonce)); 1881 !kIncludeDiversificationNonce));
1552 1882
1553 ASSERT_EQ(1u, visitor_.stream_frames_.size()); 1883 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1554 EXPECT_EQ(0u, visitor_.ack_frames_.size()); 1884 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1555 // Stream ID should be the last 3 bytes of kStreamId. 1885 // Stream ID should be the last 3 bytes of kStreamId.
1556 EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); 1886 EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id);
1557 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); 1887 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1558 EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); 1888 EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset);
1559 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); 1889 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get());
1560 1890
1561 // Now test framing boundaries. 1891 // Now test framing boundaries.
1562 const size_t stream_id_size = 3; 1892 const size_t stream_id_size = 3;
1563 CheckStreamFrameBoundaries( 1893 CheckStreamFrameBoundaries(packets[index], stream_id_size, !kIncludeVersion);
1564 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
1565 ? packet_cid_be
1566 : packet,
1567 stream_id_size, !kIncludeVersion);
1568 } 1894 }
1569 1895
1570 TEST_P(QuicFramerTest, StreamFrame2ByteStreamId) { 1896 TEST_P(QuicFramerTest, StreamFrame2ByteStreamId) {
1571 // clang-format off 1897 // clang-format off
1572 unsigned char packet[] = { 1898 unsigned char packet[] = {
1573 // public flags (8 byte connection_id) 1899 // public flags (8 byte connection_id)
1574 0x38, 1900 0x38,
1575 // connection_id 1901 // connection_id
1576 0x10, 0x32, 0x54, 0x76, 1902 0x10, 0x32, 0x54, 0x76,
1577 0x98, 0xBA, 0xDC, 0xFE, 1903 0x98, 0xBA, 0xDC, 0xFE,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1610 // offset 1936 // offset
1611 0x54, 0x76, 0x10, 0x32, 1937 0x54, 0x76, 0x10, 0x32,
1612 0xDC, 0xFE, 0x98, 0xBA, 1938 0xDC, 0xFE, 0x98, 0xBA,
1613 // data length 1939 // data length
1614 0x0c, 0x00, 1940 0x0c, 0x00,
1615 // data 1941 // data
1616 'h', 'e', 'l', 'l', 1942 'h', 'e', 'l', 'l',
1617 'o', ' ', 'w', 'o', 1943 'o', ' ', 'w', 'o',
1618 'r', 'l', 'd', '!', 1944 'r', 'l', 'd', '!',
1619 }; 1945 };
1946
1947 unsigned char packet39[] = {
1948 // public flags (8 byte connection_id)
1949 0x38,
1950 // connection_id
1951 0x10, 0x32, 0x54, 0x76,
1952 0x98, 0xBA, 0xDC, 0xFE,
1953 // packet number
1954 0x12, 0x34, 0x56, 0x78,
1955 0x9A, 0xBC,
1956
1957 // frame type (stream frame with fin)
1958 0xFD,
1959 // stream id
1960 0x03, 0x04,
1961 // offset
1962 0xBA, 0x98, 0xFE, 0xDC,
1963 0x32, 0x10, 0x76, 0x54,
1964 // data length
1965 0x00, 0x0c,
1966 // data
1967 'h', 'e', 'l', 'l',
1968 'o', ' ', 'w', 'o',
1969 'r', 'l', 'd', '!',
1970 };
1971
1972 unsigned char packet_cid_be39[] = {
1973 // public flags (8 byte connection_id)
1974 0x38,
1975 // connection_id
1976 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
1977 // packet number
1978 0x12, 0x34, 0x56, 0x78,
1979 0x9A, 0xBC,
1980
1981 // frame type (stream frame with fin)
1982 0xFD,
1983 // stream id
1984 0x03, 0x04,
1985 // offset
1986 0xBA, 0x98, 0xFE, 0xDC,
1987 0x32, 0x10, 0x76, 0x54,
1988 // data length
1989 0x00, 0x0c,
1990 // data
1991 'h', 'e', 'l', 'l',
1992 'o', ' ', 'w', 'o',
1993 'r', 'l', 'd', '!',
1994 };
1620 // clang-format on 1995 // clang-format on
1621 1996
1622 QuicEncryptedPacket encrypted( 1997 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
1623 AsChars( 1998 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
1624 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 1999
1625 ? packet_cid_be 2000 QuicEncryptedPacket encrypted(AsChars(packets[index]), arraysize(packet),
1626 : packet), 2001 false);
1627 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
1628 ? arraysize(packet_cid_be)
1629 : arraysize(packet),
1630 false);
1631 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2002 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1632 2003
1633 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2004 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1634 ASSERT_TRUE(visitor_.header_.get()); 2005 ASSERT_TRUE(visitor_.header_.get());
1635 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, 2006 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion,
1636 !kIncludeDiversificationNonce)); 2007 !kIncludeDiversificationNonce));
1637 2008
1638 ASSERT_EQ(1u, visitor_.stream_frames_.size()); 2009 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1639 EXPECT_EQ(0u, visitor_.ack_frames_.size()); 2010 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1640 // Stream ID should be the last 2 bytes of kStreamId. 2011 // Stream ID should be the last 2 bytes of kStreamId.
1641 EXPECT_EQ(0x0000FFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); 2012 EXPECT_EQ(0x0000FFFF & kStreamId, visitor_.stream_frames_[0]->stream_id);
1642 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); 2013 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1643 EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); 2014 EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset);
1644 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); 2015 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get());
1645 2016
1646 // Now test framing boundaries. 2017 // Now test framing boundaries.
1647 const size_t stream_id_size = 2; 2018 const size_t stream_id_size = 2;
1648 CheckStreamFrameBoundaries( 2019 CheckStreamFrameBoundaries(packets[index], stream_id_size, !kIncludeVersion);
1649 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
1650 ? packet_cid_be
1651 : packet,
1652 stream_id_size, !kIncludeVersion);
1653 } 2020 }
1654 2021
1655 TEST_P(QuicFramerTest, StreamFrame1ByteStreamId) { 2022 TEST_P(QuicFramerTest, StreamFrame1ByteStreamId) {
1656 // clang-format off 2023 // clang-format off
1657 unsigned char packet[] = { 2024 unsigned char packet[] = {
1658 // public flags (8 byte connection_id) 2025 // public flags (8 byte connection_id)
1659 0x38, 2026 0x38,
1660 // connection_id 2027 // connection_id
1661 0x10, 0x32, 0x54, 0x76, 2028 0x10, 0x32, 0x54, 0x76,
1662 0x98, 0xBA, 0xDC, 0xFE, 2029 0x98, 0xBA, 0xDC, 0xFE,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1695 // offset 2062 // offset
1696 0x54, 0x76, 0x10, 0x32, 2063 0x54, 0x76, 0x10, 0x32,
1697 0xDC, 0xFE, 0x98, 0xBA, 2064 0xDC, 0xFE, 0x98, 0xBA,
1698 // data length 2065 // data length
1699 0x0c, 0x00, 2066 0x0c, 0x00,
1700 // data 2067 // data
1701 'h', 'e', 'l', 'l', 2068 'h', 'e', 'l', 'l',
1702 'o', ' ', 'w', 'o', 2069 'o', ' ', 'w', 'o',
1703 'r', 'l', 'd', '!', 2070 'r', 'l', 'd', '!',
1704 }; 2071 };
2072
2073 unsigned char packet39[] = {
2074 // public flags (8 byte connection_id)
2075 0x38,
2076 // connection_id
2077 0x10, 0x32, 0x54, 0x76,
2078 0x98, 0xBA, 0xDC, 0xFE,
2079 // packet number
2080 0x12, 0x34, 0x56, 0x78,
2081 0x9A, 0xBC,
2082
2083 // frame type (stream frame with fin)
2084 0xFC,
2085 // stream id
2086 0x04,
2087 // offset
2088 0xBA, 0x98, 0xFE, 0xDC,
2089 0x32, 0x10, 0x76, 0x54,
2090 // data length
2091 0x00, 0x0c,
2092 // data
2093 'h', 'e', 'l', 'l',
2094 'o', ' ', 'w', 'o',
2095 'r', 'l', 'd', '!',
2096 };
2097
2098 unsigned char packet_cid_be39[] = {
2099 // public flags (8 byte connection_id)
2100 0x38,
2101 // connection_id
2102 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
2103 // packet number
2104 0x12, 0x34, 0x56, 0x78,
2105 0x9A, 0xBC,
2106
2107 // frame type (stream frame with fin)
2108 0xFC,
2109 // stream id
2110 0x04,
2111 // offset
2112 0xBA, 0x98, 0xFE, 0xDC,
2113 0x32, 0x10, 0x76, 0x54,
2114 // data length
2115 0x00, 0x0c,
2116 // data
2117 'h', 'e', 'l', 'l',
2118 'o', ' ', 'w', 'o',
2119 'r', 'l', 'd', '!',
2120 };
1705 // clang-format on 2121 // clang-format on
1706 2122
1707 QuicEncryptedPacket encrypted( 2123 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
1708 AsChars( 2124 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
1709 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 2125
1710 ? packet_cid_be 2126 QuicEncryptedPacket encrypted(AsChars(packets[index]), arraysize(packet),
1711 : packet), 2127 false);
1712 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
1713 ? arraysize(packet_cid_be)
1714 : arraysize(packet),
1715 false);
1716 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2128 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1717 2129
1718 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2130 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1719 ASSERT_TRUE(visitor_.header_.get()); 2131 ASSERT_TRUE(visitor_.header_.get());
1720 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, 2132 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion,
1721 !kIncludeDiversificationNonce)); 2133 !kIncludeDiversificationNonce));
1722 2134
1723 ASSERT_EQ(1u, visitor_.stream_frames_.size()); 2135 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1724 EXPECT_EQ(0u, visitor_.ack_frames_.size()); 2136 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1725 // Stream ID should be the last byte of kStreamId. 2137 // Stream ID should be the last byte of kStreamId.
1726 EXPECT_EQ(0x000000FF & kStreamId, visitor_.stream_frames_[0]->stream_id); 2138 EXPECT_EQ(0x000000FF & kStreamId, visitor_.stream_frames_[0]->stream_id);
1727 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); 2139 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1728 EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); 2140 EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset);
1729 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); 2141 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get());
1730 2142
1731 // Now test framing boundaries. 2143 // Now test framing boundaries.
1732 const size_t stream_id_size = 1; 2144 const size_t stream_id_size = 1;
1733 CheckStreamFrameBoundaries( 2145 CheckStreamFrameBoundaries(packets[index], stream_id_size, !kIncludeVersion);
1734 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
1735 ? packet_cid_be
1736 : packet,
1737 stream_id_size, !kIncludeVersion);
1738 } 2146 }
1739 2147
1740 TEST_P(QuicFramerTest, StreamFrameWithVersion) { 2148 TEST_P(QuicFramerTest, StreamFrameWithVersion) {
1741 // clang-format off 2149 // clang-format off
1742 unsigned char packet[] = { 2150 unsigned char packet[] = {
1743 // public flags (version, 8 byte connection_id) 2151 // public flags (version, 8 byte connection_id)
1744 0x39, 2152 0x39,
1745 // connection_id 2153 // connection_id
1746 0x10, 0x32, 0x54, 0x76, 2154 0x10, 0x32, 0x54, 0x76,
1747 0x98, 0xBA, 0xDC, 0xFE, 2155 0x98, 0xBA, 0xDC, 0xFE,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1784 // offset 2192 // offset
1785 0x54, 0x76, 0x10, 0x32, 2193 0x54, 0x76, 0x10, 0x32,
1786 0xDC, 0xFE, 0x98, 0xBA, 2194 0xDC, 0xFE, 0x98, 0xBA,
1787 // data length 2195 // data length
1788 0x0c, 0x00, 2196 0x0c, 0x00,
1789 // data 2197 // data
1790 'h', 'e', 'l', 'l', 2198 'h', 'e', 'l', 'l',
1791 'o', ' ', 'w', 'o', 2199 'o', ' ', 'w', 'o',
1792 'r', 'l', 'd', '!', 2200 'r', 'l', 'd', '!',
1793 }; 2201 };
2202
2203 unsigned char packet39[] = {
2204 // public flags (version, 8 byte connection_id)
2205 0x39,
2206 // connection_id
2207 0x10, 0x32, 0x54, 0x76,
2208 0x98, 0xBA, 0xDC, 0xFE,
2209 // version tag
2210 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
2211 // packet number
2212 0x12, 0x34, 0x56, 0x78,
2213 0x9A, 0xBC,
2214
2215 // frame type (stream frame with fin)
2216 0xFF,
2217 // stream id
2218 0x01, 0x02, 0x03, 0x04,
2219 // offset
2220 0xBA, 0x98, 0xFE, 0xDC,
2221 0x32, 0x10, 0x76, 0x54,
2222 // data length
2223 0x00, 0x0c,
2224 // data
2225 'h', 'e', 'l', 'l',
2226 'o', ' ', 'w', 'o',
2227 'r', 'l', 'd', '!',
2228 };
2229
2230 unsigned char packet_cid_be39[] = {
2231 // public flags (version, 8 byte connection_id)
2232 0x39,
2233 // connection_id
2234 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
2235 // version tag
2236 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
2237 // packet number
2238 0x12, 0x34, 0x56, 0x78,
2239 0x9A, 0xBC,
2240
2241 // frame type (stream frame with fin)
2242 0xFF,
2243 // stream id
2244 0x01, 0x02, 0x03, 0x04,
2245 // offset
2246 0xBA, 0x98, 0xFE, 0xDC,
2247 0x32, 0x10, 0x76, 0x54,
2248 // data length
2249 0x00, 0x0c,
2250 // data
2251 'h', 'e', 'l', 'l',
2252 'o', ' ', 'w', 'o',
2253 'r', 'l', 'd', '!',
2254 };
1794 // clang-format on 2255 // clang-format on
1795 2256
1796 QuicEncryptedPacket encrypted( 2257 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
1797 AsChars( 2258 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
1798 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 2259
1799 ? packet_cid_be 2260 QuicEncryptedPacket encrypted(AsChars(packets[index]), arraysize(packet),
1800 : packet), 2261 false);
1801 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
1802 ? arraysize(packet_cid_be)
1803 : arraysize(packet),
1804 false);
1805 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2262 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1806 2263
1807 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2264 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1808 ASSERT_TRUE(visitor_.header_.get()); 2265 ASSERT_TRUE(visitor_.header_.get());
1809 EXPECT_TRUE(visitor_.header_->public_header.version_flag); 2266 EXPECT_TRUE(visitor_.header_->public_header.version_flag);
1810 EXPECT_EQ(GetParam(), visitor_.header_->public_header.versions[0]); 2267 EXPECT_EQ(GetParam(), visitor_.header_->public_header.versions[0]);
1811 EXPECT_TRUE(CheckDecryption(encrypted, kIncludeVersion, 2268 EXPECT_TRUE(CheckDecryption(encrypted, kIncludeVersion,
1812 !kIncludeDiversificationNonce)); 2269 !kIncludeDiversificationNonce));
1813 2270
1814 ASSERT_EQ(1u, visitor_.stream_frames_.size()); 2271 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1815 EXPECT_EQ(0u, visitor_.ack_frames_.size()); 2272 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1816 EXPECT_EQ(kStreamId, visitor_.stream_frames_[0]->stream_id); 2273 EXPECT_EQ(kStreamId, visitor_.stream_frames_[0]->stream_id);
1817 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); 2274 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1818 EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); 2275 EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset);
1819 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); 2276 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get());
1820 2277
1821 // Now test framing boundaries. 2278 // Now test framing boundaries.
1822 CheckStreamFrameBoundaries( 2279 CheckStreamFrameBoundaries(packets[index], kQuicMaxStreamIdSize,
1823 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 2280 kIncludeVersion);
1824 ? packet_cid_be
1825 : packet,
1826 kQuicMaxStreamIdSize, kIncludeVersion);
1827 } 2281 }
1828 2282
1829 TEST_P(QuicFramerTest, RejectPacket) { 2283 TEST_P(QuicFramerTest, RejectPacket) {
1830 visitor_.accept_packet_ = false; 2284 visitor_.accept_packet_ = false;
1831 2285
1832 // clang-format off 2286 // clang-format off
1833 unsigned char packet[] = { 2287 unsigned char packet[] = {
1834 // public flags (8 byte connection_id) 2288 // public flags (8 byte connection_id)
1835 0x38, 2289 0x38,
1836 // connection_id 2290 // connection_id
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1871 // offset 2325 // offset
1872 0x54, 0x76, 0x10, 0x32, 2326 0x54, 0x76, 0x10, 0x32,
1873 0xDC, 0xFE, 0x98, 0xBA, 2327 0xDC, 0xFE, 0x98, 0xBA,
1874 // data length 2328 // data length
1875 0x0c, 0x00, 2329 0x0c, 0x00,
1876 // data 2330 // data
1877 'h', 'e', 'l', 'l', 2331 'h', 'e', 'l', 'l',
1878 'o', ' ', 'w', 'o', 2332 'o', ' ', 'w', 'o',
1879 'r', 'l', 'd', '!', 2333 'r', 'l', 'd', '!',
1880 }; 2334 };
2335
2336 unsigned char packet39[] = {
2337 // public flags (8 byte connection_id)
2338 0x38,
2339 // connection_id
2340 0x10, 0x32, 0x54, 0x76,
2341 0x98, 0xBA, 0xDC, 0xFE,
2342 // packet number
2343 0x12, 0x34, 0x56, 0x78,
2344 0x9A, 0xBC,
2345
2346 // frame type (stream frame with fin)
2347 0xFF,
2348 // stream id
2349 0x01, 0x02, 0x03, 0x04,
2350 // offset
2351 0xBA, 0x98, 0xFE, 0xDC,
2352 0x32, 0x10, 0x76, 0x54,
2353 // data length
2354 0x00, 0x0c,
2355 // data
2356 'h', 'e', 'l', 'l',
2357 'o', ' ', 'w', 'o',
2358 'r', 'l', 'd', '!',
2359 };
2360
2361 unsigned char packet_cid_be39[] = {
2362 // public flags (8 byte connection_id)
2363 0x38,
2364 // connection_id
2365 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
2366 // packet number
2367 0x12, 0x34, 0x56, 0x78,
2368 0x9A, 0xBC,
2369
2370 // frame type (stream frame with fin)
2371 0xFF,
2372 // stream id
2373 0x01, 0x02, 0x03, 0x04,
2374 // offset
2375 0xBA, 0x98, 0xFE, 0xDC,
2376 0x32, 0x10, 0x76, 0x54,
2377 // data length
2378 0x00, 0x0c,
2379 // data
2380 'h', 'e', 'l', 'l',
2381 'o', ' ', 'w', 'o',
2382 'r', 'l', 'd', '!',
2383 };
1881 // clang-format on 2384 // clang-format on
1882 2385
1883 QuicEncryptedPacket encrypted( 2386 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
1884 AsChars( 2387 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
1885 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 2388
1886 ? packet_cid_be 2389 QuicEncryptedPacket encrypted(AsChars(packets[index]), arraysize(packet),
1887 : packet), 2390 false);
1888 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
1889 ? arraysize(packet_cid_be)
1890 : arraysize(packet),
1891 false);
1892 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2391 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1893 2392
1894 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2393 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1895 ASSERT_TRUE(visitor_.header_.get()); 2394 ASSERT_TRUE(visitor_.header_.get());
1896 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, 2395 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion,
1897 !kIncludeDiversificationNonce)); 2396 !kIncludeDiversificationNonce));
1898 2397
1899 ASSERT_EQ(0u, visitor_.stream_frames_.size()); 2398 ASSERT_EQ(0u, visitor_.stream_frames_.size());
1900 EXPECT_EQ(0u, visitor_.ack_frames_.size()); 2399 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1901 } 2400 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1971 0x45, 2470 0x45,
1972 // largest acked 2471 // largest acked
1973 0x34, 0x12, 2472 0x34, 0x12,
1974 // Zero delta time. 2473 // Zero delta time.
1975 0x00, 0x00, 2474 0x00, 0x00,
1976 // first ack block length. 2475 // first ack block length.
1977 0x34, 0x12, 2476 0x34, 0x12,
1978 // num timestamps. 2477 // num timestamps.
1979 0x00, 2478 0x00,
1980 }; 2479 };
2480
2481 unsigned char packet39[] = {
2482 // public flags (8 byte connection_id)
2483 0x3C,
2484 // connection_id
2485 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
2486 // packet number
2487 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC,
2488
2489 // frame type (ack frame)
2490 // (one ack block, 2 byte largest observed, 2 byte block length)
2491 0x45,
2492 // largest acked
2493 0x12, 0x34,
2494 // Zero delta time.
2495 0x00, 0x00,
2496 // first ack block length.
2497 0x12, 0x34,
2498 // num timestamps.
2499 0x00,
2500 };
2501
2502 unsigned char packet_cid_be39[] = {
2503 // public flags (8 byte connection_id)
2504 0x3C,
2505 // connection_id
2506 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
2507 // packet number
2508 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC,
2509
2510 // frame type (ack frame)
2511 // (one ack block, 2 byte largest observed, 2 byte block length)
2512 0x45,
2513 // largest acked
2514 0x12, 0x34,
2515 // Zero delta time.
2516 0x00, 0x00,
2517 // first ack block length.
2518 0x12, 0x34,
2519 // num timestamps.
2520 0x00,
2521 };
1981 // clang-format on 2522 // clang-format on
1982 2523
1983 QuicEncryptedPacket encrypted( 2524 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
1984 AsChars( 2525 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
1985 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 2526
1986 ? packet_cid_be 2527 QuicEncryptedPacket encrypted(AsChars(packets[index]), arraysize(packet),
1987 : packet), 2528 false);
1988 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
1989 ? arraysize(packet_cid_be)
1990 : arraysize(packet),
1991 false);
1992 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2529 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1993 2530
1994 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2531 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1995 ASSERT_TRUE(visitor_.header_.get()); 2532 ASSERT_TRUE(visitor_.header_.get());
1996 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, 2533 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion,
1997 !kIncludeDiversificationNonce)); 2534 !kIncludeDiversificationNonce));
1998 2535
1999 EXPECT_EQ(0u, visitor_.stream_frames_.size()); 2536 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2000 ASSERT_EQ(1u, visitor_.ack_frames_.size()); 2537 ASSERT_EQ(1u, visitor_.ack_frames_.size());
2001 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; 2538 const QuicAckFrame& frame = *visitor_.ack_frames_[0];
(...skipping 15 matching lines...) Expand all
2017 if (i < kLargestAckedDeltaTimeOffset) { 2554 if (i < kLargestAckedDeltaTimeOffset) {
2018 expected_error = "Unable to read largest acked."; 2555 expected_error = "Unable to read largest acked.";
2019 } else if (i < kFirstAckBlockLengthOffset) { 2556 } else if (i < kFirstAckBlockLengthOffset) {
2020 expected_error = "Unable to read ack delay time."; 2557 expected_error = "Unable to read ack delay time.";
2021 } else if (i < kNumTimestampsOffset) { 2558 } else if (i < kNumTimestampsOffset) {
2022 expected_error = "Unable to read first ack block length."; 2559 expected_error = "Unable to read first ack block length.";
2023 } else { 2560 } else {
2024 expected_error = "Unable to read num received packets."; 2561 expected_error = "Unable to read num received packets.";
2025 } 2562 }
2026 CheckProcessingFails( 2563 CheckProcessingFails(
2027 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 2564 packets[index],
2028 ? packet_cid_be
2029 : packet,
2030 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, 2565 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID,
2031 !kIncludeVersion, !kIncludeDiversificationNonce, 2566 !kIncludeVersion, !kIncludeDiversificationNonce,
2032 PACKET_6BYTE_PACKET_NUMBER), 2567 PACKET_6BYTE_PACKET_NUMBER),
2033 expected_error, QUIC_INVALID_ACK_DATA); 2568 expected_error, QUIC_INVALID_ACK_DATA);
2034 } 2569 }
2035 } 2570 }
2036 2571
2037 TEST_P(QuicFramerTest, AckFrameTwoTimeStampsMultipleAckBlocks) { 2572 TEST_P(QuicFramerTest, AckFrameTwoTimeStampsMultipleAckBlocks) {
2038 // clang-format off 2573 // clang-format off
2039 unsigned char packet[] = { 2574 unsigned char packet[] = {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
2122 0x02, 2657 0x02,
2123 // Delta from largest observed. 2658 // Delta from largest observed.
2124 0x01, 2659 0x01,
2125 // Delta time. 2660 // Delta time.
2126 0x10, 0x32, 0x54, 0x76, 2661 0x10, 0x32, 0x54, 0x76,
2127 // Delta from largest observed. 2662 // Delta from largest observed.
2128 0x02, 2663 0x02,
2129 // Delta time. 2664 // Delta time.
2130 0x10, 0x32, 2665 0x10, 0x32,
2131 }; 2666 };
2667
2668 unsigned char packet39[] = {
2669 // public flags (8 byte connection_id)
2670 0x3C,
2671 // connection_id
2672 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
2673 // packet number
2674 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC,
2675
2676 // frame type (ack frame)
2677 // (more than one ack block, 2 byte largest observed, 2 byte block length)
2678 0x65,
2679 // largest acked
2680 0x12, 0x34,
2681 // Zero delta time.
2682 0x00, 0x00,
2683 // num ack blocks ranges.
2684 0x04,
2685 // first ack block length.
2686 0x00, 0x01,
2687 // gap to next block.
2688 0x01,
2689 // ack block length.
2690 0x0e, 0xaf,
2691 // gap to next block.
2692 0xff,
2693 // ack block length.
2694 0x00, 0x00,
2695 // gap to next block.
2696 0x91,
2697 // ack block length.
2698 0x01, 0xea,
2699 // gap to next block.
2700 0x05,
2701 // ack block length.
2702 0x00, 0x04,
2703 // Number of timestamps.
2704 0x02,
2705 // Delta from largest observed.
2706 0x01,
2707 // Delta time.
2708 0x76, 0x54, 0x32, 0x10,
2709 // Delta from largest observed.
2710 0x02,
2711 // Delta time.
2712 0x32, 0x10,
2713 };
2714
2715 unsigned char packet_cid_be39[] = {
2716 // public flags (8 byte connection_id)
2717 0x3C,
2718 // connection_id
2719 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
2720 // packet number
2721 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC,
2722
2723 // frame type (ack frame)
2724 // (more than one ack block, 2 byte largest observed, 2 byte block length)
2725 0x65,
2726 // largest acked
2727 0x12, 0x34,
2728 // Zero delta time.
2729 0x00, 0x00,
2730 // num ack blocks ranges.
2731 0x04,
2732 // first ack block length.
2733 0x00, 0x01,
2734 // gap to next block.
2735 0x01,
2736 // ack block length.
2737 0x0e, 0xaf,
2738 // gap to next block.
2739 0xff,
2740 // ack block length.
2741 0x00, 0x00,
2742 // gap to next block.
2743 0x91,
2744 // ack block length.
2745 0x01, 0xea,
2746 // gap to next block.
2747 0x05,
2748 // ack block length.
2749 0x00, 0x04,
2750 // Number of timestamps.
2751 0x02,
2752 // Delta from largest observed.
2753 0x01,
2754 // Delta time.
2755 0x76, 0x54, 0x32, 0x10,
2756 // Delta from largest observed.
2757 0x02,
2758 // Delta time.
2759 0x32, 0x10,
2760 };
2132 // clang-format on 2761 // clang-format on
2133 2762
2134 QuicEncryptedPacket encrypted( 2763 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
2135 AsChars( 2764 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
2136 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 2765
2137 ? packet_cid_be 2766 QuicEncryptedPacket encrypted(AsChars(packets[index]), arraysize(packet),
2138 : packet), 2767 false);
2139 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
2140 ? arraysize(packet_cid_be)
2141 : arraysize(packet),
2142 false);
2143 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2768 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2144 2769
2145 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2770 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2146 ASSERT_TRUE(visitor_.header_.get()); 2771 ASSERT_TRUE(visitor_.header_.get());
2147 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, 2772 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion,
2148 !kIncludeDiversificationNonce)); 2773 !kIncludeDiversificationNonce));
2149 2774
2150 EXPECT_EQ(0u, visitor_.stream_frames_.size()); 2775 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2151 ASSERT_EQ(1u, visitor_.ack_frames_.size()); 2776 ASSERT_EQ(1u, visitor_.ack_frames_.size());
2152 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; 2777 const QuicAckFrame& frame = *visitor_.ack_frames_[0];
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
2219 } else if (i < kTimestampDeltaLargestObserved2) { 2844 } else if (i < kTimestampDeltaLargestObserved2) {
2220 expected_error = "Unable to read time delta in received packets."; 2845 expected_error = "Unable to read time delta in received packets.";
2221 } else if (i < kTimestampTimeDeltaLargestObserved2) { 2846 } else if (i < kTimestampTimeDeltaLargestObserved2) {
2222 expected_error = "Unable to read sequence delta in received packets."; 2847 expected_error = "Unable to read sequence delta in received packets.";
2223 } else { 2848 } else {
2224 expected_error = 2849 expected_error =
2225 "Unable to read incremental time delta in received packets."; 2850 "Unable to read incremental time delta in received packets.";
2226 } 2851 }
2227 2852
2228 CheckProcessingFails( 2853 CheckProcessingFails(
2229 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 2854 packets[index],
2230 ? packet_cid_be
2231 : packet,
2232 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, 2855 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID,
2233 !kIncludeVersion, !kIncludeDiversificationNonce, 2856 !kIncludeVersion, !kIncludeDiversificationNonce,
2234 PACKET_6BYTE_PACKET_NUMBER), 2857 PACKET_6BYTE_PACKET_NUMBER),
2235 expected_error, QUIC_INVALID_ACK_DATA); 2858 expected_error, QUIC_INVALID_ACK_DATA);
2236 } 2859 }
2237 } 2860 }
2238 2861
2239 TEST_P(QuicFramerTest, NewStopWaitingFrame) { 2862 TEST_P(QuicFramerTest, NewStopWaitingFrame) {
2240 // clang-format off 2863 // clang-format off
2241 unsigned char packet[] = { 2864 unsigned char packet[] = {
(...skipping 19 matching lines...) Expand all
2261 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 2884 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
2262 // packet number 2885 // packet number
2263 0xA8, 0x9A, 0x78, 0x56, 2886 0xA8, 0x9A, 0x78, 0x56,
2264 0x34, 0x12, 2887 0x34, 0x12,
2265 // frame type (stop waiting frame) 2888 // frame type (stop waiting frame)
2266 0x06, 2889 0x06,
2267 // least packet number awaiting an ack, delta from packet number. 2890 // least packet number awaiting an ack, delta from packet number.
2268 0x08, 0x00, 0x00, 0x00, 2891 0x08, 0x00, 0x00, 0x00,
2269 0x00, 0x00, 2892 0x00, 0x00,
2270 }; 2893 };
2894
2895 unsigned char packet39[] = {
2896 // public flags (8 byte connection_id)
2897 0x3C,
2898 // connection_id
2899 0x10, 0x32, 0x54, 0x76,
2900 0x98, 0xBA, 0xDC, 0xFE,
2901 // packet number
2902 0x12, 0x34, 0x56, 0x78,
2903 0x9A, 0xA8,
2904 // frame type (stop waiting frame)
2905 0x06,
2906 // least packet number awaiting an ack, delta from packet number.
2907 0x00, 0x00, 0x00, 0x00,
2908 0x00, 0x08,
2909 };
2910
2911 unsigned char packet_cid_be39[] = {
2912 // public flags (8 byte connection_id)
2913 0x3C,
2914 // connection_id
2915 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
2916 // packet number
2917 0x12, 0x34, 0x56, 0x78,
2918 0x9A, 0xA8,
2919 // frame type (stop waiting frame)
2920 0x06,
2921 // least packet number awaiting an ack, delta from packet number.
2922 0x00, 0x00, 0x00, 0x00,
2923 0x00, 0x08,
2924 };
2271 // clang-format on 2925 // clang-format on
2272 2926
2273 QuicEncryptedPacket encrypted( 2927 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
2274 AsChars( 2928 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
2275 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 2929
2276 ? packet_cid_be 2930 QuicEncryptedPacket encrypted(AsChars(packets[index]), arraysize(packet),
2277 : packet), 2931 false);
2278 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
2279 ? arraysize(packet_cid_be)
2280 : arraysize(packet),
2281 false);
2282 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2932 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2283 2933
2284 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2934 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2285 ASSERT_TRUE(visitor_.header_.get()); 2935 ASSERT_TRUE(visitor_.header_.get());
2286 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, 2936 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion,
2287 !kIncludeDiversificationNonce)); 2937 !kIncludeDiversificationNonce));
2288 2938
2289 EXPECT_EQ(0u, visitor_.stream_frames_.size()); 2939 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2290 ASSERT_EQ(1u, visitor_.stop_waiting_frames_.size()); 2940 ASSERT_EQ(1u, visitor_.stop_waiting_frames_.size());
2291 const QuicStopWaitingFrame& frame = *visitor_.stop_waiting_frames_[0]; 2941 const QuicStopWaitingFrame& frame = *visitor_.stop_waiting_frames_[0];
2292 EXPECT_EQ(kLeastUnacked, frame.least_unacked); 2942 EXPECT_EQ(kLeastUnacked, frame.least_unacked);
2293 2943
2294 const size_t frame_size = 7; 2944 const size_t frame_size = 7;
2295 for (size_t i = kQuicFrameTypeSize; i < frame_size; ++i) { 2945 for (size_t i = kQuicFrameTypeSize; i < frame_size; ++i) {
2296 string expected_error; 2946 string expected_error;
2297 expected_error = "Unable to read least unacked delta."; 2947 expected_error = "Unable to read least unacked delta.";
2298 CheckProcessingFails( 2948 CheckProcessingFails(
2299 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 2949 packets[index],
2300 ? packet_cid_be
2301 : packet,
2302 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, 2950 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID,
2303 !kIncludeVersion, !kIncludeDiversificationNonce, 2951 !kIncludeVersion, !kIncludeDiversificationNonce,
2304 PACKET_6BYTE_PACKET_NUMBER), 2952 PACKET_6BYTE_PACKET_NUMBER),
2305 expected_error, QUIC_INVALID_STOP_WAITING_DATA); 2953 expected_error, QUIC_INVALID_STOP_WAITING_DATA);
2306 } 2954 }
2307 } 2955 }
2308 2956
2309 TEST_P(QuicFramerTest, RstStreamFrameQuic) { 2957 TEST_P(QuicFramerTest, RstStreamFrameQuic) {
2310 // clang-format off 2958 // clang-format off
2311 unsigned char packet[] = { 2959 unsigned char packet[] = {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2345 // stream id 2993 // stream id
2346 0x04, 0x03, 0x02, 0x01, 2994 0x04, 0x03, 0x02, 0x01,
2347 2995
2348 // sent byte offset 2996 // sent byte offset
2349 0x54, 0x76, 0x10, 0x32, 2997 0x54, 0x76, 0x10, 0x32,
2350 0xDC, 0xFE, 0x98, 0xBA, 2998 0xDC, 0xFE, 0x98, 0xBA,
2351 2999
2352 // error code 3000 // error code
2353 0x01, 0x00, 0x00, 0x00, 3001 0x01, 0x00, 0x00, 0x00,
2354 }; 3002 };
3003
3004 unsigned char packet39[] = {
3005 // public flags (8 byte connection_id)
3006 0x38,
3007 // connection_id
3008 0x10, 0x32, 0x54, 0x76,
3009 0x98, 0xBA, 0xDC, 0xFE,
3010 // packet number
3011 0x12, 0x34, 0x56, 0x78,
3012 0x9A, 0xBC,
3013
3014 // frame type (rst stream frame)
3015 0x01,
3016 // stream id
3017 0x01, 0x02, 0x03, 0x04,
3018
3019 // sent byte offset
3020 0xBA, 0x98, 0xFE, 0xDC,
3021 0x32, 0x10, 0x76, 0x54,
3022
3023 // error code
3024 0x00, 0x00, 0x00, 0x01,
3025 };
3026
3027 unsigned char packet_cid_be39[] = {
3028 // public flags (8 byte connection_id)
3029 0x38,
3030 // connection_id
3031 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
3032 // packet number
3033 0x12, 0x34, 0x56, 0x78,
3034 0x9A, 0xBC,
3035
3036 // frame type (rst stream frame)
3037 0x01,
3038 // stream id
3039 0x01, 0x02, 0x03, 0x04,
3040
3041 // sent byte offset
3042 0xBA, 0x98, 0xFE, 0xDC,
3043 0x32, 0x10, 0x76, 0x54,
3044
3045 // error code
3046 0x00, 0x00, 0x00, 0x01,
3047 };
2355 // clang-format on 3048 // clang-format on
2356 3049
2357 QuicEncryptedPacket encrypted( 3050 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
2358 AsChars( 3051 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
2359 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 3052
2360 ? packet_cid_be 3053 QuicEncryptedPacket encrypted(AsChars(packets[index]), arraysize(packet),
2361 : packet), 3054 false);
2362 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
2363 ? arraysize(packet_cid_be)
2364 : arraysize(packet),
2365 false);
2366 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 3055 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2367 3056
2368 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 3057 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2369 ASSERT_TRUE(visitor_.header_.get()); 3058 ASSERT_TRUE(visitor_.header_.get());
2370 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, 3059 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion,
2371 !kIncludeDiversificationNonce)); 3060 !kIncludeDiversificationNonce));
2372 3061
2373 EXPECT_EQ(kStreamId, visitor_.rst_stream_frame_.stream_id); 3062 EXPECT_EQ(kStreamId, visitor_.rst_stream_frame_.stream_id);
2374 EXPECT_EQ(0x01, visitor_.rst_stream_frame_.error_code); 3063 EXPECT_EQ(0x01, visitor_.rst_stream_frame_.error_code);
2375 EXPECT_EQ(kStreamOffset, visitor_.rst_stream_frame_.byte_offset); 3064 EXPECT_EQ(kStreamOffset, visitor_.rst_stream_frame_.byte_offset);
2376 3065
2377 // Now test framing boundaries. 3066 // Now test framing boundaries.
2378 for (size_t i = kQuicFrameTypeSize; i < QuicFramer::GetRstStreamFrameSize(); 3067 for (size_t i = kQuicFrameTypeSize; i < QuicFramer::GetRstStreamFrameSize();
2379 ++i) { 3068 ++i) {
2380 string expected_error; 3069 string expected_error;
2381 if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize) { 3070 if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize) {
2382 expected_error = "Unable to read stream_id."; 3071 expected_error = "Unable to read stream_id.";
2383 } else if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize + 3072 } else if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize +
2384 kQuicMaxStreamOffsetSize) { 3073 kQuicMaxStreamOffsetSize) {
2385 expected_error = "Unable to read rst stream sent byte offset."; 3074 expected_error = "Unable to read rst stream sent byte offset.";
2386 } else if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize + 3075 } else if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize +
2387 kQuicMaxStreamOffsetSize + kQuicErrorCodeSize) { 3076 kQuicMaxStreamOffsetSize + kQuicErrorCodeSize) {
2388 expected_error = "Unable to read rst stream error code."; 3077 expected_error = "Unable to read rst stream error code.";
2389 } 3078 }
2390 CheckProcessingFails( 3079 CheckProcessingFails(
2391 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 3080 packets[index],
2392 ? packet_cid_be
2393 : packet,
2394 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, 3081 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID,
2395 !kIncludeVersion, !kIncludeDiversificationNonce, 3082 !kIncludeVersion, !kIncludeDiversificationNonce,
2396 PACKET_6BYTE_PACKET_NUMBER), 3083 PACKET_6BYTE_PACKET_NUMBER),
2397 expected_error, QUIC_INVALID_RST_STREAM_DATA); 3084 expected_error, QUIC_INVALID_RST_STREAM_DATA);
2398 } 3085 }
2399 } 3086 }
2400 3087
2401 TEST_P(QuicFramerTest, ConnectionCloseFrame) { 3088 TEST_P(QuicFramerTest, ConnectionCloseFrame) {
2402 // clang-format off 3089 // clang-format off
2403 unsigned char packet[] = { 3090 unsigned char packet[] = {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2439 0x11, 0x00, 0x00, 0x00, 3126 0x11, 0x00, 0x00, 0x00,
2440 3127
2441 // error details length 3128 // error details length
2442 0x0d, 0x00, 3129 0x0d, 0x00,
2443 // error details 3130 // error details
2444 'b', 'e', 'c', 'a', 3131 'b', 'e', 'c', 'a',
2445 'u', 's', 'e', ' ', 3132 'u', 's', 'e', ' ',
2446 'I', ' ', 'c', 'a', 3133 'I', ' ', 'c', 'a',
2447 'n', 3134 'n',
2448 }; 3135 };
3136
3137 unsigned char packet39[] = {
3138 // public flags (8 byte connection_id)
3139 0x38,
3140 // connection_id
3141 0x10, 0x32, 0x54, 0x76,
3142 0x98, 0xBA, 0xDC, 0xFE,
3143 // packet number
3144 0x12, 0x34, 0x56, 0x78,
3145 0x9A, 0xBC,
3146
3147 // frame type (connection close frame)
3148 0x02,
3149 // error code
3150 0x00, 0x00, 0x00, 0x11,
3151
3152 // error details length
3153 0x00, 0x0d,
3154 // error details
3155 'b', 'e', 'c', 'a',
3156 'u', 's', 'e', ' ',
3157 'I', ' ', 'c', 'a',
3158 'n',
3159 };
3160
3161 unsigned char packet_cid_be39[] = {
3162 // public flags (8 byte connection_id)
3163 0x38,
3164 // connection_id
3165 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
3166 // packet number
3167 0x12, 0x34, 0x56, 0x78,
3168 0x9A, 0xBC,
3169
3170 // frame type (connection close frame)
3171 0x02,
3172 // error code
3173 0x00, 0x00, 0x00, 0x11,
3174
3175 // error details length
3176 0x00, 0x0d,
3177 // error details
3178 'b', 'e', 'c', 'a',
3179 'u', 's', 'e', ' ',
3180 'I', ' ', 'c', 'a',
3181 'n',
3182 };
2449 // clang-format on 3183 // clang-format on
2450 3184
2451 QuicEncryptedPacket encrypted( 3185 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
2452 AsChars( 3186 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
2453 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 3187
2454 ? packet_cid_be 3188 QuicEncryptedPacket encrypted(AsChars(packets[index]), arraysize(packet),
2455 : packet), 3189 false);
2456 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
2457 ? arraysize(packet_cid_be)
2458 : arraysize(packet),
2459 false);
2460 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 3190 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2461 3191
2462 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 3192 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2463 ASSERT_TRUE(visitor_.header_.get()); 3193 ASSERT_TRUE(visitor_.header_.get());
2464 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, 3194 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion,
2465 !kIncludeDiversificationNonce)); 3195 !kIncludeDiversificationNonce));
2466 3196
2467 EXPECT_EQ(0u, visitor_.stream_frames_.size()); 3197 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2468 3198
2469 EXPECT_EQ(0x11, visitor_.connection_close_frame_.error_code); 3199 EXPECT_EQ(0x11, visitor_.connection_close_frame_.error_code);
2470 EXPECT_EQ("because I can", visitor_.connection_close_frame_.error_details); 3200 EXPECT_EQ("because I can", visitor_.connection_close_frame_.error_details);
2471 3201
2472 ASSERT_EQ(0u, visitor_.ack_frames_.size()); 3202 ASSERT_EQ(0u, visitor_.ack_frames_.size());
2473 3203
2474 // Now test framing boundaries. 3204 // Now test framing boundaries.
2475 for (size_t i = kQuicFrameTypeSize; 3205 for (size_t i = kQuicFrameTypeSize;
2476 i < QuicFramer::GetMinConnectionCloseFrameSize(); ++i) { 3206 i < QuicFramer::GetMinConnectionCloseFrameSize(); ++i) {
2477 string expected_error; 3207 string expected_error;
2478 if (i < kQuicFrameTypeSize + kQuicErrorCodeSize) { 3208 if (i < kQuicFrameTypeSize + kQuicErrorCodeSize) {
2479 expected_error = "Unable to read connection close error code."; 3209 expected_error = "Unable to read connection close error code.";
2480 } else { 3210 } else {
2481 expected_error = "Unable to read connection close error details."; 3211 expected_error = "Unable to read connection close error details.";
2482 } 3212 }
2483 CheckProcessingFails( 3213 CheckProcessingFails(
2484 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 3214 packets[index],
2485 ? packet_cid_be
2486 : packet,
2487 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, 3215 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID,
2488 !kIncludeVersion, !kIncludeDiversificationNonce, 3216 !kIncludeVersion, !kIncludeDiversificationNonce,
2489 PACKET_6BYTE_PACKET_NUMBER), 3217 PACKET_6BYTE_PACKET_NUMBER),
2490 expected_error, QUIC_INVALID_CONNECTION_CLOSE_DATA); 3218 expected_error, QUIC_INVALID_CONNECTION_CLOSE_DATA);
2491 } 3219 }
2492 } 3220 }
2493 3221
2494 TEST_P(QuicFramerTest, GoAwayFrame) { 3222 TEST_P(QuicFramerTest, GoAwayFrame) {
2495 // clang-format off 3223 // clang-format off
2496 unsigned char packet[] = { 3224 unsigned char packet[] = {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2534 // stream id 3262 // stream id
2535 0x04, 0x03, 0x02, 0x01, 3263 0x04, 0x03, 0x02, 0x01,
2536 // error details length 3264 // error details length
2537 0x0d, 0x00, 3265 0x0d, 0x00,
2538 // error details 3266 // error details
2539 'b', 'e', 'c', 'a', 3267 'b', 'e', 'c', 'a',
2540 'u', 's', 'e', ' ', 3268 'u', 's', 'e', ' ',
2541 'I', ' ', 'c', 'a', 3269 'I', ' ', 'c', 'a',
2542 'n', 3270 'n',
2543 }; 3271 };
3272
3273 unsigned char packet39[] = {
3274 // public flags (8 byte connection_id)
3275 0x38,
3276 // connection_id
3277 0x10, 0x32, 0x54, 0x76,
3278 0x98, 0xBA, 0xDC, 0xFE,
3279 // packet number
3280 0x12, 0x34, 0x56, 0x78,
3281 0x9A, 0xBC,
3282
3283 // frame type (go away frame)
3284 0x03,
3285 // error code
3286 0x00, 0x00, 0x00, 0x09,
3287 // stream id
3288 0x01, 0x02, 0x03, 0x04,
3289 // error details length
3290 0x00, 0x0d,
3291 // error details
3292 'b', 'e', 'c', 'a',
3293 'u', 's', 'e', ' ',
3294 'I', ' ', 'c', 'a',
3295 'n',
3296 };
3297
3298 unsigned char packet_cid_be39[] = {
3299 // public flags (8 byte connection_id)
3300 0x38,
3301 // connection_id
3302 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
3303 // packet number
3304 0x12, 0x34, 0x56, 0x78,
3305 0x9A, 0xBC,
3306
3307 // frame type (go away frame)
3308 0x03,
3309 // error code
3310 0x00, 0x00, 0x00, 0x09,
3311 // stream id
3312 0x01, 0x02, 0x03, 0x04,
3313 // error details length
3314 0x00, 0x0d,
3315 // error details
3316 'b', 'e', 'c', 'a',
3317 'u', 's', 'e', ' ',
3318 'I', ' ', 'c', 'a',
3319 'n',
3320 };
2544 // clang-format on 3321 // clang-format on
2545 3322
2546 QuicEncryptedPacket encrypted( 3323 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
2547 AsChars( 3324 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
2548 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 3325
2549 ? packet_cid_be 3326 QuicEncryptedPacket encrypted(AsChars(packets[index]), arraysize(packet),
2550 : packet), 3327 false);
2551 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
2552 ? arraysize(packet_cid_be)
2553 : arraysize(packet),
2554 false);
2555 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 3328 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2556 3329
2557 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 3330 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2558 ASSERT_TRUE(visitor_.header_.get()); 3331 ASSERT_TRUE(visitor_.header_.get());
2559 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, 3332 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion,
2560 !kIncludeDiversificationNonce)); 3333 !kIncludeDiversificationNonce));
2561 3334
2562 EXPECT_EQ(kStreamId, visitor_.goaway_frame_.last_good_stream_id); 3335 EXPECT_EQ(kStreamId, visitor_.goaway_frame_.last_good_stream_id);
2563 EXPECT_EQ(0x9, visitor_.goaway_frame_.error_code); 3336 EXPECT_EQ(0x9, visitor_.goaway_frame_.error_code);
2564 EXPECT_EQ("because I can", visitor_.goaway_frame_.reason_phrase); 3337 EXPECT_EQ("because I can", visitor_.goaway_frame_.reason_phrase);
2565 3338
2566 const size_t reason_size = arraysize("because I can") - 1; 3339 const size_t reason_size = arraysize("because I can") - 1;
2567 // Now test framing boundaries. 3340 // Now test framing boundaries.
2568 for (size_t i = kQuicFrameTypeSize; 3341 for (size_t i = kQuicFrameTypeSize;
2569 i < QuicFramer::GetMinGoAwayFrameSize() + reason_size; ++i) { 3342 i < QuicFramer::GetMinGoAwayFrameSize() + reason_size; ++i) {
2570 string expected_error; 3343 string expected_error;
2571 if (i < kQuicFrameTypeSize + kQuicErrorCodeSize) { 3344 if (i < kQuicFrameTypeSize + kQuicErrorCodeSize) {
2572 expected_error = "Unable to read go away error code."; 3345 expected_error = "Unable to read go away error code.";
2573 } else if (i < 3346 } else if (i <
2574 kQuicFrameTypeSize + kQuicErrorCodeSize + kQuicMaxStreamIdSize) { 3347 kQuicFrameTypeSize + kQuicErrorCodeSize + kQuicMaxStreamIdSize) {
2575 expected_error = "Unable to read last good stream id."; 3348 expected_error = "Unable to read last good stream id.";
2576 } else { 3349 } else {
2577 expected_error = "Unable to read goaway reason."; 3350 expected_error = "Unable to read goaway reason.";
2578 } 3351 }
2579 CheckProcessingFails( 3352 CheckProcessingFails(
2580 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 3353 packets[index],
2581 ? packet_cid_be
2582 : packet,
2583 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, 3354 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID,
2584 !kIncludeVersion, !kIncludeDiversificationNonce, 3355 !kIncludeVersion, !kIncludeDiversificationNonce,
2585 PACKET_6BYTE_PACKET_NUMBER), 3356 PACKET_6BYTE_PACKET_NUMBER),
2586 expected_error, QUIC_INVALID_GOAWAY_DATA); 3357 expected_error, QUIC_INVALID_GOAWAY_DATA);
2587 } 3358 }
2588 } 3359 }
2589 3360
2590 TEST_P(QuicFramerTest, WindowUpdateFrame) { 3361 TEST_P(QuicFramerTest, WindowUpdateFrame) {
2591 // clang-format off 3362 // clang-format off
2592 unsigned char packet[] = { 3363 unsigned char packet[] = {
(...skipping 25 matching lines...) Expand all
2618 0x34, 0x12, 3389 0x34, 0x12,
2619 3390
2620 // frame type (window update frame) 3391 // frame type (window update frame)
2621 0x04, 3392 0x04,
2622 // stream id 3393 // stream id
2623 0x04, 0x03, 0x02, 0x01, 3394 0x04, 0x03, 0x02, 0x01,
2624 // byte offset 3395 // byte offset
2625 0x54, 0x76, 0x10, 0x32, 3396 0x54, 0x76, 0x10, 0x32,
2626 0xDC, 0xFE, 0x98, 0xBA, 3397 0xDC, 0xFE, 0x98, 0xBA,
2627 }; 3398 };
3399
3400 unsigned char packet39[] = {
3401 // public flags (8 byte connection_id)
3402 0x38,
3403 // connection_id
3404 0x10, 0x32, 0x54, 0x76,
3405 0x98, 0xBA, 0xDC, 0xFE,
3406 // packet number
3407 0x12, 0x34, 0x56, 0x78,
3408 0x9A, 0xBC,
3409
3410 // frame type (window update frame)
3411 0x04,
3412 // stream id
3413 0x01, 0x02, 0x03, 0x04,
3414 // byte offset
3415 0xBA, 0x98, 0xFE, 0xDC,
3416 0x32, 0x10, 0x76, 0x54,
3417 };
3418
3419 unsigned char packet_cid_be39[] = {
3420 // public flags (8 byte connection_id)
3421 0x38,
3422 // connection_id
3423 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
3424 // packet number
3425 0x12, 0x34, 0x56, 0x78,
3426 0x9A, 0xBC,
3427
3428 // frame type (window update frame)
3429 0x04,
3430 // stream id
3431 0x01, 0x02, 0x03, 0x04,
3432 // byte offset
3433 0xBA, 0x98, 0xFE, 0xDC,
3434 0x32, 0x10, 0x76, 0x54,
3435 };
2628 // clang-format on 3436 // clang-format on
2629 3437
2630 QuicEncryptedPacket encrypted( 3438 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
2631 AsChars( 3439 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
2632 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 3440
2633 ? packet_cid_be 3441 QuicEncryptedPacket encrypted(AsChars(packets[index]), arraysize(packet),
2634 : packet), 3442 false);
2635 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
2636 ? arraysize(packet_cid_be)
2637 : arraysize(packet),
2638 false);
2639 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 3443 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2640 3444
2641 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 3445 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2642 ASSERT_TRUE(visitor_.header_.get()); 3446 ASSERT_TRUE(visitor_.header_.get());
2643 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, 3447 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion,
2644 !kIncludeDiversificationNonce)); 3448 !kIncludeDiversificationNonce));
2645 3449
2646 EXPECT_EQ(kStreamId, visitor_.window_update_frame_.stream_id); 3450 EXPECT_EQ(kStreamId, visitor_.window_update_frame_.stream_id);
2647 EXPECT_EQ(kStreamOffset, visitor_.window_update_frame_.byte_offset); 3451 EXPECT_EQ(kStreamOffset, visitor_.window_update_frame_.byte_offset);
2648 3452
2649 // Now test framing boundaries. 3453 // Now test framing boundaries.
2650 for (size_t i = kQuicFrameTypeSize; 3454 for (size_t i = kQuicFrameTypeSize;
2651 i < QuicFramer::GetWindowUpdateFrameSize(); ++i) { 3455 i < QuicFramer::GetWindowUpdateFrameSize(); ++i) {
2652 string expected_error; 3456 string expected_error;
2653 if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize) { 3457 if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize) {
2654 expected_error = "Unable to read stream_id."; 3458 expected_error = "Unable to read stream_id.";
2655 } else { 3459 } else {
2656 expected_error = "Unable to read window byte_offset."; 3460 expected_error = "Unable to read window byte_offset.";
2657 } 3461 }
2658 CheckProcessingFails( 3462 CheckProcessingFails(
2659 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 3463 packets[index],
2660 ? packet_cid_be
2661 : packet,
2662 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, 3464 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID,
2663 !kIncludeVersion, !kIncludeDiversificationNonce, 3465 !kIncludeVersion, !kIncludeDiversificationNonce,
2664 PACKET_6BYTE_PACKET_NUMBER), 3466 PACKET_6BYTE_PACKET_NUMBER),
2665 expected_error, QUIC_INVALID_WINDOW_UPDATE_DATA); 3467 expected_error, QUIC_INVALID_WINDOW_UPDATE_DATA);
2666 } 3468 }
2667 } 3469 }
2668 3470
2669 TEST_P(QuicFramerTest, BlockedFrame) { 3471 TEST_P(QuicFramerTest, BlockedFrame) {
2670 // clang-format off 3472 // clang-format off
2671 unsigned char packet[] = { 3473 unsigned char packet[] = {
(...skipping 19 matching lines...) Expand all
2691 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 3493 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
2692 // packet number 3494 // packet number
2693 0xBC, 0x9A, 0x78, 0x56, 3495 0xBC, 0x9A, 0x78, 0x56,
2694 0x34, 0x12, 3496 0x34, 0x12,
2695 3497
2696 // frame type (blocked frame) 3498 // frame type (blocked frame)
2697 0x05, 3499 0x05,
2698 // stream id 3500 // stream id
2699 0x04, 0x03, 0x02, 0x01, 3501 0x04, 0x03, 0x02, 0x01,
2700 }; 3502 };
3503
3504 unsigned char packet39[] = {
3505 // public flags (8 byte connection_id)
3506 0x38,
3507 // connection_id
3508 0x10, 0x32, 0x54, 0x76,
3509 0x98, 0xBA, 0xDC, 0xFE,
3510 // packet number
3511 0x12, 0x34, 0x56, 0x78,
3512 0x9A, 0xBC,
3513
3514 // frame type (blocked frame)
3515 0x05,
3516 // stream id
3517 0x01, 0x02, 0x03, 0x04,
3518 };
3519
3520 unsigned char packet_cid_be39[] = {
3521 // public flags (8 byte connection_id)
3522 0x38,
3523 // connection_id
3524 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
3525 // packet number
3526 0x12, 0x34, 0x56, 0x78,
3527 0x9A, 0xBC,
3528
3529 // frame type (blocked frame)
3530 0x05,
3531 // stream id
3532 0x01, 0x02, 0x03, 0x04,
3533 };
2701 // clang-format on 3534 // clang-format on
2702 3535
2703 QuicEncryptedPacket encrypted( 3536 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
2704 AsChars( 3537 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
2705 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 3538
2706 ? packet_cid_be 3539 QuicEncryptedPacket encrypted(AsChars(packets[index]), arraysize(packet),
2707 : packet), 3540 false);
2708 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
2709 ? arraysize(packet_cid_be)
2710 : arraysize(packet),
2711 false);
2712 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 3541 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2713 3542
2714 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 3543 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2715 ASSERT_TRUE(visitor_.header_.get()); 3544 ASSERT_TRUE(visitor_.header_.get());
2716 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, 3545 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion,
2717 !kIncludeDiversificationNonce)); 3546 !kIncludeDiversificationNonce));
2718 3547
2719 EXPECT_EQ(kStreamId, visitor_.blocked_frame_.stream_id); 3548 EXPECT_EQ(kStreamId, visitor_.blocked_frame_.stream_id);
2720 3549
2721 // Now test framing boundaries. 3550 // Now test framing boundaries.
2722 for (size_t i = kQuicFrameTypeSize; i < QuicFramer::GetBlockedFrameSize(); 3551 for (size_t i = kQuicFrameTypeSize; i < QuicFramer::GetBlockedFrameSize();
2723 ++i) { 3552 ++i) {
2724 string expected_error = "Unable to read stream_id."; 3553 string expected_error = "Unable to read stream_id.";
2725 CheckProcessingFails( 3554 CheckProcessingFails(
2726 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 3555 packets[index],
2727 ? packet_cid_be
2728 : packet,
2729 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, 3556 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID,
2730 !kIncludeVersion, !kIncludeDiversificationNonce, 3557 !kIncludeVersion, !kIncludeDiversificationNonce,
2731 PACKET_6BYTE_PACKET_NUMBER), 3558 PACKET_6BYTE_PACKET_NUMBER),
2732 expected_error, QUIC_INVALID_BLOCKED_DATA); 3559 expected_error, QUIC_INVALID_BLOCKED_DATA);
2733 } 3560 }
2734 } 3561 }
2735 3562
2736 TEST_P(QuicFramerTest, PingFrame) { 3563 TEST_P(QuicFramerTest, PingFrame) {
2737 // clang-format off 3564 // clang-format off
2738 unsigned char packet[] = { 3565 unsigned char packet[] = {
(...skipping 15 matching lines...) Expand all
2754 0x38, 3581 0x38,
2755 // connection_id 3582 // connection_id
2756 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 3583 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
2757 // packet number 3584 // packet number
2758 0xBC, 0x9A, 0x78, 0x56, 3585 0xBC, 0x9A, 0x78, 0x56,
2759 0x34, 0x12, 3586 0x34, 0x12,
2760 3587
2761 // frame type (ping frame) 3588 // frame type (ping frame)
2762 0x07, 3589 0x07,
2763 }; 3590 };
3591
3592 unsigned char packet39[] = {
3593 // public flags (8 byte connection_id)
3594 0x38,
3595 // connection_id
3596 0x10, 0x32, 0x54, 0x76,
3597 0x98, 0xBA, 0xDC, 0xFE,
3598 // packet number
3599 0x12, 0x34, 0x56, 0x78,
3600 0x9A, 0xBC,
3601
3602 // frame type (ping frame)
3603 0x07,
3604 };
3605
3606 unsigned char packet_cid_be39[] = {
3607 // public flags (8 byte connection_id)
3608 0x38,
3609 // connection_id
3610 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
3611 // packet number
3612 0x12, 0x34, 0x56, 0x78,
3613 0x9A, 0xBC,
3614
3615 // frame type (ping frame)
3616 0x07,
3617 };
2764 // clang-format on 3618 // clang-format on
2765 3619
2766 QuicEncryptedPacket encrypted( 3620 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
2767 AsChars( 3621 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
2768 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 3622
2769 ? packet_cid_be 3623 QuicEncryptedPacket encrypted(AsChars(packets[index]), arraysize(packet),
2770 : packet), 3624 false);
2771 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
2772 ? arraysize(packet_cid_be)
2773 : arraysize(packet),
2774 false);
2775 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 3625 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2776 3626
2777 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 3627 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2778 ASSERT_TRUE(visitor_.header_.get()); 3628 ASSERT_TRUE(visitor_.header_.get());
2779 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, 3629 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion,
2780 !kIncludeDiversificationNonce)); 3630 !kIncludeDiversificationNonce));
2781 3631
2782 EXPECT_EQ(1u, visitor_.ping_frames_.size()); 3632 EXPECT_EQ(1u, visitor_.ping_frames_.size());
2783 3633
2784 // No need to check the PING frame boundaries because it has no payload. 3634 // No need to check the PING frame boundaries because it has no payload.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
2848 : arraysize(packet), 3698 : arraysize(packet),
2849 false); 3699 false);
2850 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 3700 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2851 ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); 3701 ASSERT_EQ(QUIC_NO_ERROR, framer_.error());
2852 ASSERT_TRUE(visitor_.public_reset_packet_.get()); 3702 ASSERT_TRUE(visitor_.public_reset_packet_.get());
2853 EXPECT_EQ(kConnectionId, 3703 EXPECT_EQ(kConnectionId,
2854 visitor_.public_reset_packet_->public_header.connection_id); 3704 visitor_.public_reset_packet_->public_header.connection_id);
2855 EXPECT_TRUE(visitor_.public_reset_packet_->public_header.reset_flag); 3705 EXPECT_TRUE(visitor_.public_reset_packet_->public_header.reset_flag);
2856 EXPECT_FALSE(visitor_.public_reset_packet_->public_header.version_flag); 3706 EXPECT_FALSE(visitor_.public_reset_packet_->public_header.version_flag);
2857 EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof); 3707 EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof);
2858 EXPECT_EQ(0u, visitor_.public_reset_packet_->rejected_packet_number);
2859 EXPECT_EQ( 3708 EXPECT_EQ(
2860 IpAddressFamily::IP_UNSPEC, 3709 IpAddressFamily::IP_UNSPEC,
2861 visitor_.public_reset_packet_->client_address.host().address_family()); 3710 visitor_.public_reset_packet_->client_address.host().address_family());
2862 3711
2863 // Now test framing boundaries. 3712 // Now test framing boundaries.
2864 if (!QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())) { 3713 if (!QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())) {
2865 for (size_t i = 0; i < arraysize(packet); ++i) { 3714 for (size_t i = 0; i < arraysize(packet); ++i) {
2866 string expected_error; 3715 string expected_error;
2867 QUIC_DLOG(INFO) << "iteration: " << i; 3716 QUIC_DLOG(INFO) << "iteration: " << i;
2868 if (i < kConnectionIdOffset) { 3717 if (i < kConnectionIdOffset) {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
2967 : arraysize(packet), 3816 : arraysize(packet),
2968 false); 3817 false);
2969 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 3818 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2970 ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); 3819 ASSERT_EQ(QUIC_NO_ERROR, framer_.error());
2971 ASSERT_TRUE(visitor_.public_reset_packet_.get()); 3820 ASSERT_TRUE(visitor_.public_reset_packet_.get());
2972 EXPECT_EQ(kConnectionId, 3821 EXPECT_EQ(kConnectionId,
2973 visitor_.public_reset_packet_->public_header.connection_id); 3822 visitor_.public_reset_packet_->public_header.connection_id);
2974 EXPECT_TRUE(visitor_.public_reset_packet_->public_header.reset_flag); 3823 EXPECT_TRUE(visitor_.public_reset_packet_->public_header.reset_flag);
2975 EXPECT_FALSE(visitor_.public_reset_packet_->public_header.version_flag); 3824 EXPECT_FALSE(visitor_.public_reset_packet_->public_header.version_flag);
2976 EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof); 3825 EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof);
2977 EXPECT_EQ(0u, visitor_.public_reset_packet_->rejected_packet_number);
2978 EXPECT_EQ( 3826 EXPECT_EQ(
2979 IpAddressFamily::IP_UNSPEC, 3827 IpAddressFamily::IP_UNSPEC,
2980 visitor_.public_reset_packet_->client_address.host().address_family()); 3828 visitor_.public_reset_packet_->client_address.host().address_family());
2981 3829
2982 // Now test framing boundaries. 3830 // Now test framing boundaries.
2983 if (!QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())) { 3831 if (!QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())) {
2984 for (size_t i = 0; i < arraysize(packet); ++i) { 3832 for (size_t i = 0; i < arraysize(packet); ++i) {
2985 string expected_error; 3833 string expected_error;
2986 QUIC_DLOG(INFO) << "iteration: " << i; 3834 QUIC_DLOG(INFO) << "iteration: " << i;
2987 if (i < kConnectionIdOffset) { 3835 if (i < kConnectionIdOffset) {
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
3169 : arraysize(packet), 4017 : arraysize(packet),
3170 false); 4018 false);
3171 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 4019 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
3172 ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); 4020 ASSERT_EQ(QUIC_NO_ERROR, framer_.error());
3173 ASSERT_TRUE(visitor_.public_reset_packet_.get()); 4021 ASSERT_TRUE(visitor_.public_reset_packet_.get());
3174 EXPECT_EQ(kConnectionId, 4022 EXPECT_EQ(kConnectionId,
3175 visitor_.public_reset_packet_->public_header.connection_id); 4023 visitor_.public_reset_packet_->public_header.connection_id);
3176 EXPECT_TRUE(visitor_.public_reset_packet_->public_header.reset_flag); 4024 EXPECT_TRUE(visitor_.public_reset_packet_->public_header.reset_flag);
3177 EXPECT_FALSE(visitor_.public_reset_packet_->public_header.version_flag); 4025 EXPECT_FALSE(visitor_.public_reset_packet_->public_header.version_flag);
3178 EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof); 4026 EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof);
3179 EXPECT_EQ(0u, visitor_.public_reset_packet_->rejected_packet_number);
3180 EXPECT_EQ("4.31.198.44", 4027 EXPECT_EQ("4.31.198.44",
3181 visitor_.public_reset_packet_->client_address.host().ToString()); 4028 visitor_.public_reset_packet_->client_address.host().ToString());
3182 EXPECT_EQ(443, visitor_.public_reset_packet_->client_address.port()); 4029 EXPECT_EQ(443, visitor_.public_reset_packet_->client_address.port());
3183 4030
3184 // Now test framing boundaries. 4031 // Now test framing boundaries.
3185 if (!QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())) { 4032 if (!QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())) {
3186 for (size_t i = 0; i < arraysize(packet); ++i) { 4033 for (size_t i = 0; i < arraysize(packet); ++i) {
3187 string expected_error; 4034 string expected_error;
3188 QUIC_DLOG(INFO) << "iteration: " << i; 4035 QUIC_DLOG(INFO) << "iteration: " << i;
3189 if (i < kConnectionIdOffset) { 4036 if (i < kConnectionIdOffset) {
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
3373 // connection_id 4220 // connection_id
3374 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 4221 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
3375 // packet number 4222 // packet number
3376 0xBC, 0x9A, 0x78, 0x56, 4223 0xBC, 0x9A, 0x78, 0x56,
3377 0x34, 0x12, 4224 0x34, 0x12,
3378 4225
3379 // frame type (padding frame) 4226 // frame type (padding frame)
3380 0x00, 4227 0x00,
3381 0x00, 0x00, 0x00, 0x00 4228 0x00, 0x00, 0x00, 0x00
3382 }; 4229 };
4230
4231 unsigned char packet39[kMaxPacketSize] = {
4232 // public flags (8 byte connection_id)
4233 0x38,
4234 // connection_id
4235 0x10, 0x32, 0x54, 0x76,
4236 0x98, 0xBA, 0xDC, 0xFE,
4237 // packet number
4238 0x12, 0x34, 0x56, 0x78,
4239 0x9A, 0xBC,
4240
4241 // frame type (padding frame)
4242 0x00,
4243 0x00, 0x00, 0x00, 0x00
4244 };
4245
4246 unsigned char packet_cid_be39[kMaxPacketSize] = {
4247 // public flags (8 byte connection_id)
4248 0x38,
4249 // connection_id
4250 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
4251 // packet number
4252 0x12, 0x34, 0x56, 0x78,
4253 0x9A, 0xBC,
4254
4255 // frame type (padding frame)
4256 0x00,
4257 0x00, 0x00, 0x00, 0x00
4258 };
3383 // clang-format on 4259 // clang-format on
3384 4260
4261 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
4262 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
4263
3385 uint64_t header_size = GetPacketHeaderSize( 4264 uint64_t header_size = GetPacketHeaderSize(
3386 framer_.version(), PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 4265 framer_.version(), PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
3387 !kIncludeDiversificationNonce, PACKET_6BYTE_PACKET_NUMBER); 4266 !kIncludeDiversificationNonce, PACKET_6BYTE_PACKET_NUMBER);
3388 memset((QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 4267 memset((packets[index]) + header_size + 1, 0x00,
3389 ? packet_cid_be 4268 kMaxPacketSize - header_size - 1);
3390 : packet) +
3391 header_size + 1,
3392 0x00, kMaxPacketSize - header_size - 1);
3393 4269
3394 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 4270 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3395 ASSERT_TRUE(data != nullptr); 4271 ASSERT_TRUE(data != nullptr);
3396 4272
3397 test::CompareCharArraysWithHexError( 4273 test::CompareCharArraysWithHexError("constructed packet", data->data(),
3398 "constructed packet", data->data(), data->length(), 4274 data->length(), AsChars(packets[index]),
3399 AsChars( 4275 arraysize(packet));
3400 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
3401 ? packet_cid_be
3402 : packet),
3403 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
3404 ? arraysize(packet_cid_be)
3405 : arraysize(packet));
3406 } 4276 }
3407 4277
3408 TEST_P(QuicFramerTest, BuildStreamFramePacketWithNewPaddingFrame) { 4278 TEST_P(QuicFramerTest, BuildStreamFramePacketWithNewPaddingFrame) {
3409 if (framer_.version() <= QUIC_VERSION_37) { 4279 if (framer_.version() <= QUIC_VERSION_37) {
3410 return; 4280 return;
3411 } 4281 }
3412 QuicPacketHeader header; 4282 QuicPacketHeader header;
3413 header.public_header.connection_id = kConnectionId; 4283 header.public_header.connection_id = kConnectionId;
3414 header.public_header.reset_flag = false; 4284 header.public_header.reset_flag = false;
3415 header.public_header.version_flag = false; 4285 header.public_header.version_flag = false;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
3471 0xDC, 0xFE, 0x98, 0xBA, 4341 0xDC, 0xFE, 0x98, 0xBA,
3472 // data length 4342 // data length
3473 0x0c, 0x00, 4343 0x0c, 0x00,
3474 // data 4344 // data
3475 'h', 'e', 'l', 'l', 4345 'h', 'e', 'l', 'l',
3476 'o', ' ', 'w', 'o', 4346 'o', ' ', 'w', 'o',
3477 'r', 'l', 'd', '!', 4347 'r', 'l', 'd', '!',
3478 // paddings 4348 // paddings
3479 0x00, 0x00, 4349 0x00, 0x00,
3480 }; 4350 };
4351
4352 unsigned char packet39[] = {
4353 // public flags (8 byte connection_id)
4354 0x38,
4355 // connection_id
4356 0x10, 0x32, 0x54, 0x76,
4357 0x98, 0xBA, 0xDC, 0xFE,
4358 // packet number
4359 0x12, 0x34, 0x56, 0x78,
4360 0x9A, 0xBC,
4361
4362 // paddings
4363 0x00, 0x00,
4364 // frame type (stream frame with fin)
4365 0xFF,
4366 // stream id
4367 0x01, 0x02, 0x03, 0x04,
4368 // offset
4369 0xBA, 0x98, 0xFE, 0xDC,
4370 0x32, 0x10, 0x76, 0x54,
4371 // data length
4372 0x00, 0x0c,
4373 // data
4374 'h', 'e', 'l', 'l',
4375 'o', ' ', 'w', 'o',
4376 'r', 'l', 'd', '!',
4377 // paddings
4378 0x00, 0x00,
4379 };
4380
4381 unsigned char packet_cid_be39[] = {
4382 // public flags (8 byte connection_id)
4383 0x38,
4384 // connection_id
4385 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
4386 // packet number
4387 0x12, 0x34, 0x56, 0x78,
4388 0x9A, 0xBC,
4389
4390 // paddings
4391 0x00, 0x00,
4392 // frame type (stream frame with fin)
4393 0xFF,
4394 // stream id
4395 0x01, 0x02, 0x03, 0x04,
4396 // offset
4397 0xBA, 0x98, 0xFE, 0xDC,
4398 0x32, 0x10, 0x76, 0x54,
4399 // data length
4400 0x00, 0x0c,
4401 // data
4402 'h', 'e', 'l', 'l',
4403 'o', ' ', 'w', 'o',
4404 'r', 'l', 'd', '!',
4405 // paddings
4406 0x00, 0x00,
4407 };
3481 // clang-format on 4408 // clang-format on
3482 4409
4410 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
4411 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
4412
3483 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 4413 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3484 ASSERT_TRUE(data != nullptr); 4414 ASSERT_TRUE(data != nullptr);
3485 4415
3486 test::CompareCharArraysWithHexError( 4416 test::CompareCharArraysWithHexError("constructed packet", data->data(),
3487 "constructed packet", data->data(), data->length(), 4417 data->length(), AsChars(packets[index]),
3488 AsChars( 4418 arraysize(packet));
3489 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
3490 ? packet_cid_be
3491 : packet),
3492 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
3493 ? arraysize(packet_cid_be)
3494 : arraysize(packet));
3495 } 4419 }
3496 4420
3497 TEST_P(QuicFramerTest, Build4ByteSequenceNumberPaddingFramePacket) { 4421 TEST_P(QuicFramerTest, Build4ByteSequenceNumberPaddingFramePacket) {
3498 QuicPacketHeader header; 4422 QuicPacketHeader header;
3499 header.public_header.connection_id = kConnectionId; 4423 header.public_header.connection_id = kConnectionId;
3500 header.public_header.reset_flag = false; 4424 header.public_header.reset_flag = false;
3501 header.public_header.version_flag = false; 4425 header.public_header.version_flag = false;
3502 header.public_header.packet_number_length = PACKET_4BYTE_PACKET_NUMBER; 4426 header.public_header.packet_number_length = PACKET_4BYTE_PACKET_NUMBER;
3503 header.packet_number = kPacketNumber; 4427 header.packet_number = kPacketNumber;
3504 4428
(...skipping 19 matching lines...) Expand all
3524 0x28, 4448 0x28,
3525 // connection_id 4449 // connection_id
3526 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 4450 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
3527 // packet number 4451 // packet number
3528 0xBC, 0x9A, 0x78, 0x56, 4452 0xBC, 0x9A, 0x78, 0x56,
3529 4453
3530 // frame type (padding frame) 4454 // frame type (padding frame)
3531 0x00, 4455 0x00,
3532 0x00, 0x00, 0x00, 0x00 4456 0x00, 0x00, 0x00, 0x00
3533 }; 4457 };
4458
4459 unsigned char packet39[kMaxPacketSize] = {
4460 // public flags (8 byte connection_id and 4 byte packet number)
4461 0x28,
4462 // connection_id
4463 0x10, 0x32, 0x54, 0x76,
4464 0x98, 0xBA, 0xDC, 0xFE,
4465 // packet number
4466 0x56, 0x78, 0x9A, 0xBC,
4467
4468 // frame type (padding frame)
4469 0x00,
4470 0x00, 0x00, 0x00, 0x00
4471 };
4472
4473 unsigned char packet_cid_be39[kMaxPacketSize] = {
4474 // public flags (8 byte connection_id and 4 byte packet number)
4475 0x28,
4476 // connection_id
4477 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
4478 // packet number
4479 0x56, 0x78, 0x9A, 0xBC,
4480
4481 // frame type (padding frame)
4482 0x00,
4483 0x00, 0x00, 0x00, 0x00
4484 };
3534 // clang-format on 4485 // clang-format on
3535 4486
4487 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
4488 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
4489
3536 uint64_t header_size = GetPacketHeaderSize( 4490 uint64_t header_size = GetPacketHeaderSize(
3537 framer_.version(), PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 4491 framer_.version(), PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
3538 !kIncludeDiversificationNonce, PACKET_4BYTE_PACKET_NUMBER); 4492 !kIncludeDiversificationNonce, PACKET_4BYTE_PACKET_NUMBER);
3539 memset((QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 4493 memset((packets[index]) + header_size + 1, 0x00,
3540 ? packet_cid_be 4494 kMaxPacketSize - header_size - 1);
3541 : packet) +
3542 header_size + 1,
3543 0x00, kMaxPacketSize - header_size - 1);
3544 4495
3545 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 4496 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3546 ASSERT_TRUE(data != nullptr); 4497 ASSERT_TRUE(data != nullptr);
3547 4498
3548 test::CompareCharArraysWithHexError( 4499 test::CompareCharArraysWithHexError("constructed packet", data->data(),
3549 "constructed packet", data->data(), data->length(), 4500 data->length(), AsChars(packets[index]),
3550 AsChars( 4501 arraysize(packet));
3551 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
3552 ? packet_cid_be
3553 : packet),
3554 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
3555 ? arraysize(packet_cid_be)
3556 : arraysize(packet));
3557 } 4502 }
3558 4503
3559 TEST_P(QuicFramerTest, Build2ByteSequenceNumberPaddingFramePacket) { 4504 TEST_P(QuicFramerTest, Build2ByteSequenceNumberPaddingFramePacket) {
3560 QuicPacketHeader header; 4505 QuicPacketHeader header;
3561 header.public_header.connection_id = kConnectionId; 4506 header.public_header.connection_id = kConnectionId;
3562 header.public_header.reset_flag = false; 4507 header.public_header.reset_flag = false;
3563 header.public_header.version_flag = false; 4508 header.public_header.version_flag = false;
3564 header.public_header.packet_number_length = PACKET_2BYTE_PACKET_NUMBER; 4509 header.public_header.packet_number_length = PACKET_2BYTE_PACKET_NUMBER;
3565 header.packet_number = kPacketNumber; 4510 header.packet_number = kPacketNumber;
3566 4511
(...skipping 19 matching lines...) Expand all
3586 0x18, 4531 0x18,
3587 // connection_id 4532 // connection_id
3588 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 4533 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
3589 // packet number 4534 // packet number
3590 0xBC, 0x9A, 4535 0xBC, 0x9A,
3591 4536
3592 // frame type (padding frame) 4537 // frame type (padding frame)
3593 0x00, 4538 0x00,
3594 0x00, 0x00, 0x00, 0x00 4539 0x00, 0x00, 0x00, 0x00
3595 }; 4540 };
4541
4542 unsigned char packet39[kMaxPacketSize] = {
4543 // public flags (8 byte connection_id and 2 byte packet number)
4544 0x18,
4545 // connection_id
4546 0x10, 0x32, 0x54, 0x76,
4547 0x98, 0xBA, 0xDC, 0xFE,
4548 // packet number
4549 0x9A, 0xBC,
4550
4551 // frame type (padding frame)
4552 0x00,
4553 0x00, 0x00, 0x00, 0x00
4554 };
4555
4556 unsigned char packet_cid_be39[kMaxPacketSize] = {
4557 // public flags (8 byte connection_id and 2 byte packet number)
4558 0x18,
4559 // connection_id
4560 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
4561 // packet number
4562 0x9A, 0xBC,
4563
4564 // frame type (padding frame)
4565 0x00,
4566 0x00, 0x00, 0x00, 0x00
4567 };
3596 // clang-format on 4568 // clang-format on
3597 4569
4570 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
4571 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
4572
3598 uint64_t header_size = GetPacketHeaderSize( 4573 uint64_t header_size = GetPacketHeaderSize(
3599 framer_.version(), PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 4574 framer_.version(), PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
3600 !kIncludeDiversificationNonce, PACKET_2BYTE_PACKET_NUMBER); 4575 !kIncludeDiversificationNonce, PACKET_2BYTE_PACKET_NUMBER);
3601 memset((QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 4576 memset((packets[index]) + header_size + 1, 0x00,
3602 ? packet_cid_be 4577 kMaxPacketSize - header_size - 1);
3603 : packet) +
3604 header_size + 1,
3605 0x00, kMaxPacketSize - header_size - 1);
3606 4578
3607 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 4579 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3608 ASSERT_TRUE(data != nullptr); 4580 ASSERT_TRUE(data != nullptr);
3609 4581
3610 test::CompareCharArraysWithHexError( 4582 test::CompareCharArraysWithHexError("constructed packet", data->data(),
3611 "constructed packet", data->data(), data->length(), 4583 data->length(), AsChars(packets[index]),
3612 AsChars( 4584 arraysize(packet));
3613 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
3614 ? packet_cid_be
3615 : packet),
3616 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
3617 ? arraysize(packet_cid_be)
3618 : arraysize(packet));
3619 } 4585 }
3620 4586
3621 TEST_P(QuicFramerTest, Build1ByteSequenceNumberPaddingFramePacket) { 4587 TEST_P(QuicFramerTest, Build1ByteSequenceNumberPaddingFramePacket) {
3622 QuicPacketHeader header; 4588 QuicPacketHeader header;
3623 header.public_header.connection_id = kConnectionId; 4589 header.public_header.connection_id = kConnectionId;
3624 header.public_header.reset_flag = false; 4590 header.public_header.reset_flag = false;
3625 header.public_header.version_flag = false; 4591 header.public_header.version_flag = false;
3626 header.public_header.packet_number_length = PACKET_1BYTE_PACKET_NUMBER; 4592 header.public_header.packet_number_length = PACKET_1BYTE_PACKET_NUMBER;
3627 header.packet_number = kPacketNumber; 4593 header.packet_number = kPacketNumber;
3628 4594
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
3730 // stream id 4696 // stream id
3731 0x04, 0x03, 0x02, 0x01, 4697 0x04, 0x03, 0x02, 0x01,
3732 // offset 4698 // offset
3733 0x54, 0x76, 0x10, 0x32, 4699 0x54, 0x76, 0x10, 0x32,
3734 0xDC, 0xFE, 0x98, 0xBA, 4700 0xDC, 0xFE, 0x98, 0xBA,
3735 // data 4701 // data
3736 'h', 'e', 'l', 'l', 4702 'h', 'e', 'l', 'l',
3737 'o', ' ', 'w', 'o', 4703 'o', ' ', 'w', 'o',
3738 'r', 'l', 'd', '!', 4704 'r', 'l', 'd', '!',
3739 }; 4705 };
4706
4707 unsigned char packet39[] = {
4708 // public flags (8 byte connection_id)
4709 0x38,
4710 // connection_id
4711 0x10, 0x32, 0x54, 0x76,
4712 0x98, 0xBA, 0xDC, 0xFE,
4713 // packet number
4714 0x12, 0x34, 0x56, 0x78,
4715 0x9A, 0xBC,
4716
4717 // frame type (stream frame with fin and no length)
4718 0xDF,
4719 // stream id
4720 0x01, 0x02, 0x03, 0x04,
4721 // offset
4722 0xBA, 0x98, 0xFE, 0xDC,
4723 0x32, 0x10, 0x76, 0x54,
4724 // data
4725 'h', 'e', 'l', 'l',
4726 'o', ' ', 'w', 'o',
4727 'r', 'l', 'd', '!',
4728 };
4729
4730 unsigned char packet_cid_be39[] = {
4731 // public flags (8 byte connection_id)
4732 0x38,
4733 // connection_id
4734 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
4735 // packet number
4736 0x12, 0x34, 0x56, 0x78,
4737 0x9A, 0xBC,
4738
4739 // frame type (stream frame with fin and no length)
4740 0xDF,
4741 // stream id
4742 0x01, 0x02, 0x03, 0x04,
4743 // offset
4744 0xBA, 0x98, 0xFE, 0xDC,
4745 0x32, 0x10, 0x76, 0x54,
4746 // data
4747 'h', 'e', 'l', 'l',
4748 'o', ' ', 'w', 'o',
4749 'r', 'l', 'd', '!',
4750 };
3740 // clang-format on 4751 // clang-format on
3741 4752
4753 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
4754 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
4755
3742 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 4756 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3743 ASSERT_TRUE(data != nullptr); 4757 ASSERT_TRUE(data != nullptr);
3744 4758
3745 test::CompareCharArraysWithHexError( 4759 test::CompareCharArraysWithHexError("constructed packet", data->data(),
3746 "constructed packet", data->data(), data->length(), 4760 data->length(), AsChars(packets[index]),
3747 AsChars( 4761 arraysize(packet));
3748 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
3749 ? packet_cid_be
3750 : packet),
3751 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
3752 ? arraysize(packet_cid_be)
3753 : arraysize(packet));
3754 } 4762 }
3755 4763
3756 TEST_P(QuicFramerTest, BuildStreamFramePacketWithVersionFlag) { 4764 TEST_P(QuicFramerTest, BuildStreamFramePacketWithVersionFlag) {
3757 QuicPacketHeader header; 4765 QuicPacketHeader header;
3758 header.public_header.connection_id = kConnectionId; 4766 header.public_header.connection_id = kConnectionId;
3759 header.public_header.reset_flag = false; 4767 header.public_header.reset_flag = false;
3760 header.public_header.version_flag = true; 4768 header.public_header.version_flag = true;
3761 header.packet_number = kPacketNumber; 4769 header.packet_number = kPacketNumber;
3762 4770
3763 QuicStreamFrame stream_frame(kStreamId, true, kStreamOffset, 4771 QuicStreamFrame stream_frame(kStreamId, true, kStreamOffset,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3799 4807
3800 // frame type (stream frame with fin and no length) 4808 // frame type (stream frame with fin and no length)
3801 0xDF, 4809 0xDF,
3802 // stream id 4810 // stream id
3803 0x04, 0x03, 0x02, 0x01, 4811 0x04, 0x03, 0x02, 0x01,
3804 // offset 4812 // offset
3805 0x54, 0x76, 0x10, 0x32, 0xDC, 0xFE, 0x98, 0xBA, 4813 0x54, 0x76, 0x10, 0x32, 0xDC, 0xFE, 0x98, 0xBA,
3806 // data 4814 // data
3807 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!', 4815 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!',
3808 }; 4816 };
4817
4818 unsigned char packet39[] = {
4819 // public flags (version, 8 byte connection_id)
4820 static_cast<unsigned char>(
4821 FLAGS_quic_reloadable_flag_quic_remove_v33_hacks2 ? 0x39 : 0x3D),
4822 // connection_id
4823 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
4824 // version tag
4825 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
4826 // packet number
4827 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC,
4828
4829 // frame type (stream frame with fin and no length)
4830 0xDF,
4831 // stream id
4832 0x01, 0x02, 0x03, 0x04,
4833 // offset
4834 0xBA, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54,
4835 // data
4836 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!',
4837 };
4838
4839 unsigned char packet_cid_be39[] = {
4840 // public flags (version, 8 byte connection_id)
4841 static_cast<unsigned char>(
4842 FLAGS_quic_reloadable_flag_quic_remove_v33_hacks2 ? 0x39 : 0x3D),
4843 // connection_id
4844 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
4845 // version tag
4846 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
4847 // packet number
4848 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC,
4849
4850 // frame type (stream frame with fin and no length)
4851 0xDF,
4852 // stream id
4853 0x01, 0x02, 0x03, 0x04,
4854 // offset
4855 0xBA, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54,
4856 // data
4857 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!',
4858 };
3809 // clang-format on 4859 // clang-format on
3810 4860
4861 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
4862 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
4863
3811 QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); 4864 QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT);
3812 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 4865 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3813 ASSERT_TRUE(data != nullptr); 4866 ASSERT_TRUE(data != nullptr);
3814 4867
3815 test::CompareCharArraysWithHexError( 4868 test::CompareCharArraysWithHexError("constructed packet", data->data(),
3816 "constructed packet", data->data(), data->length(), 4869 data->length(), AsChars(packets[index]),
3817 AsChars( 4870 arraysize(packet));
3818 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
3819 ? packet_cid_be
3820 : packet),
3821 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
3822 ? arraysize(packet_cid_be)
3823 : arraysize(packet));
3824 } 4871 }
3825 4872
3826 TEST_P(QuicFramerTest, BuildVersionNegotiationPacket) { 4873 TEST_P(QuicFramerTest, BuildVersionNegotiationPacket) {
3827 // clang-format off 4874 // clang-format off
3828 unsigned char packet[] = { 4875 unsigned char packet[] = {
3829 // public flags (version, 8 byte connection_id) 4876 // public flags (version, 8 byte connection_id)
3830 0x0D, 4877 0x0D,
3831 // connection_id 4878 // connection_id
3832 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, 4879 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
3833 // version tag 4880 // version tag
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
3909 0x45, 4956 0x45,
3910 // largest acked 4957 // largest acked
3911 0x34, 0x12, 4958 0x34, 0x12,
3912 // Zero delta time. 4959 // Zero delta time.
3913 0x00, 0x00, 4960 0x00, 0x00,
3914 // first ack block length. 4961 // first ack block length.
3915 0x34, 0x12, 4962 0x34, 0x12,
3916 // num timestamps. 4963 // num timestamps.
3917 0x00, 4964 0x00,
3918 }; 4965 };
4966
4967 unsigned char packet39[] = {
4968 // public flags (8 byte connection_id)
4969 0x38,
4970 // connection_id
4971 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
4972 // packet number
4973 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC,
4974
4975 // frame type (ack frame)
4976 // (no ack blocks, 2 byte largest observed, 2 byte block length)
4977 0x45,
4978 // largest acked
4979 0x12, 0x34,
4980 // Zero delta time.
4981 0x00, 0x00,
4982 // first ack block length.
4983 0x12, 0x34,
4984 // num timestamps.
4985 0x00,
4986 };
4987
4988 unsigned char packet_cid_be39[] = {
4989 // public flags (8 byte connection_id)
4990 0x38,
4991 // connection_id
4992 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
4993 // packet number
4994 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC,
4995
4996 // frame type (ack frame)
4997 // (no ack blocks, 2 byte largest observed, 2 byte block length)
4998 0x45,
4999 // largest acked
5000 0x12, 0x34,
5001 // Zero delta time.
5002 0x00, 0x00,
5003 // first ack block length.
5004 0x12, 0x34,
5005 // num timestamps.
5006 0x00,
5007 };
3919 // clang-format on 5008 // clang-format on
3920 5009
5010 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
5011 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
5012
3921 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 5013 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3922 ASSERT_TRUE(data != nullptr); 5014 ASSERT_TRUE(data != nullptr);
3923 5015
3924 test::CompareCharArraysWithHexError( 5016 test::CompareCharArraysWithHexError("constructed packet", data->data(),
3925 "constructed packet", data->data(), data->length(), 5017 data->length(), AsChars(packets[index]),
3926 AsChars( 5018 arraysize(packet));
3927 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
3928 ? packet_cid_be
3929 : packet),
3930 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
3931 ? arraysize(packet_cid_be)
3932 : arraysize(packet));
3933 } 5019 }
3934 5020
3935 TEST_P(QuicFramerTest, BuildAckFramePacketMultipleAckBlocks) { 5021 TEST_P(QuicFramerTest, BuildAckFramePacketMultipleAckBlocks) {
3936 QuicPacketHeader header; 5022 QuicPacketHeader header;
3937 header.public_header.connection_id = kConnectionId; 5023 header.public_header.connection_id = kConnectionId;
3938 header.public_header.reset_flag = false; 5024 header.public_header.reset_flag = false;
3939 header.public_header.version_flag = false; 5025 header.public_header.version_flag = false;
3940 header.packet_number = kPacketNumber; 5026 header.packet_number = kPacketNumber;
3941 5027
3942 // Use kSmallLargestObserved to make this test finished in a short time. 5028 // Use kSmallLargestObserved to make this test finished in a short time.
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
4021 0x91, 5107 0x91,
4022 // ack block length. 5108 // ack block length.
4023 0xea, 0x01, 5109 0xea, 0x01,
4024 // gap to next block. 5110 // gap to next block.
4025 0x05, 5111 0x05,
4026 // ack block length. 5112 // ack block length.
4027 0x04, 0x00, 5113 0x04, 0x00,
4028 // num timestamps. 5114 // num timestamps.
4029 0x00, 5115 0x00,
4030 }; 5116 };
5117
5118 unsigned char packet39[] = {
5119 // public flags (8 byte connection_id)
5120 0x38,
5121 // connection_id
5122 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
5123 // packet number
5124 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC,
5125
5126 // frame type (ack frame)
5127 // (has ack blocks, 2 byte largest observed, 2 byte block length)
5128 0x65,
5129 // largest acked
5130 0x12, 0x34,
5131 // Zero delta time.
5132 0x00, 0x00,
5133 // num ack blocks ranges.
5134 0x04,
5135 // first ack block length.
5136 0x00, 0x01,
5137 // gap to next block.
5138 0x01,
5139 // ack block length.
5140 0x0e, 0xaf,
5141 // gap to next block.
5142 0xff,
5143 // ack block length.
5144 0x00, 0x00,
5145 // gap to next block.
5146 0x91,
5147 // ack block length.
5148 0x01, 0xea,
5149 // gap to next block.
5150 0x05,
5151 // ack block length.
5152 0x00, 0x04,
5153 // num timestamps.
5154 0x00,
5155 };
5156
5157 unsigned char packet_cid_be39[] = {
5158 // public flags (8 byte connection_id)
5159 0x38,
5160 // connection_id
5161 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
5162 // packet number
5163 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC,
5164
5165 // frame type (ack frame)
5166 // (has ack blocks, 2 byte largest observed, 2 byte block length)
5167 0x65,
5168 // largest acked
5169 0x12, 0x34,
5170 // Zero delta time.
5171 0x00, 0x00,
5172 // num ack blocks ranges.
5173 0x04,
5174 // first ack block length.
5175 0x00, 0x01,
5176 // gap to next block.
5177 0x01,
5178 // ack block length.
5179 0x0e, 0xaf,
5180 // gap to next block.
5181 0xff,
5182 // ack block length.
5183 0x00, 0x00,
5184 // gap to next block.
5185 0x91,
5186 // ack block length.
5187 0x01, 0xea,
5188 // gap to next block.
5189 0x05,
5190 // ack block length.
5191 0x00, 0x04,
5192 // num timestamps.
5193 0x00,
5194 };
4031 // clang-format on 5195 // clang-format on
4032 5196
5197 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
5198 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
5199
4033 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 5200 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames));
4034 ASSERT_TRUE(data != nullptr); 5201 ASSERT_TRUE(data != nullptr);
4035 5202
4036 test::CompareCharArraysWithHexError( 5203 test::CompareCharArraysWithHexError("constructed packet", data->data(),
4037 "constructed packet", data->data(), data->length(), 5204 data->length(), AsChars(packets[index]),
4038 AsChars( 5205 arraysize(packet));
4039 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
4040 ? packet_cid_be
4041 : packet),
4042 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
4043 ? arraysize(packet_cid_be)
4044 : arraysize(packet));
4045 } 5206 }
4046 5207
4047 TEST_P(QuicFramerTest, BuildAckFramePacketMaxAckBlocks) { 5208 TEST_P(QuicFramerTest, BuildAckFramePacketMaxAckBlocks) {
4048 QuicPacketHeader header; 5209 QuicPacketHeader header;
4049 header.public_header.connection_id = kConnectionId; 5210 header.public_header.connection_id = kConnectionId;
4050 header.public_header.reset_flag = false; 5211 header.public_header.reset_flag = false;
4051 header.public_header.version_flag = false; 5212 header.public_header.version_flag = false;
4052 header.packet_number = kPacketNumber; 5213 header.packet_number = kPacketNumber;
4053 5214
4054 // Use kSmallLargestObservedto make this test finished in a short time. 5215 // Use kSmallLargestObservedto make this test finished in a short time.
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
4242 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 5403 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
4243 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 5404 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
4244 5405
4245 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 5406 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
4246 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 5407 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
4247 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 5408 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
4248 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 5409 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
4249 // num timestamps. 5410 // num timestamps.
4250 0x00, 5411 0x00,
4251 }; 5412 };
5413
5414 unsigned char packet39[] = {
5415 // public flags (8 byte connection_id)
5416 0x38,
5417 // connection_id
5418 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
5419 // packet number
5420 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC,
5421 // frame type (ack frame)
5422 // (has ack blocks, 2 byte largest observed, 2 byte block length)
5423 0x65,
5424 // largest acked
5425 0x12, 0x34,
5426 // Zero delta time.
5427 0x00, 0x00,
5428 // num ack blocks ranges.
5429 0xff,
5430 // first ack block length.
5431 0x0f, 0xdd,
5432 // 255 = 4 * 63 + 3
5433 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5434 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5435 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5436 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5437 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5438 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5439 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5440 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5441 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5442 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5443
5444 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5445 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5446 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5447 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5448 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5449 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5450 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5451 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5452 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5453 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5454
5455 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5456 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5457 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5458 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5459 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5460 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5461 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5462 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5463 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5464 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5465
5466 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5467 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5468 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5469 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5470 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5471 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5472 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5473 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5474 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5475 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5476
5477 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5478 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5479 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5480 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5481 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5482 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5483 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5484 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5485 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5486 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5487
5488 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5489 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5490 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5491 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5492 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5493 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5494 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5495 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5496 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5497 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5498
5499 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5500 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5501 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5502 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5503 // num timestamps.
5504 0x00,
5505 };
5506
5507 unsigned char packet_cid_be39[] = {
5508 // public flags (8 byte connection_id)
5509 0x38,
5510 // connection_id
5511 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
5512 // packet number
5513 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC,
5514 // frame type (ack frame)
5515 // (has ack blocks, 2 byte largest observed, 2 byte block length)
5516 0x65,
5517 // largest acked
5518 0x12, 0x34,
5519 // Zero delta time.
5520 0x00, 0x00,
5521 // num ack blocks ranges.
5522 0xff,
5523 // first ack block length.
5524 0x0f, 0xdd,
5525 // 255 = 4 * 63 + 3
5526 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5527 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5528 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5529 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5530 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5531 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5532 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5533 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5534 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5535 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5536
5537 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5538 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5539 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5540 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5541 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5542 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5543 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5544 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5545 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5546 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5547
5548 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5549 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5550 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5551 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5552 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5553 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5554 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5555 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5556 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5557 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5558
5559 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5560 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5561 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5562 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5563 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5564 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5565 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5566 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5567 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5568 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5569
5570 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5571 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5572 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5573 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5574 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5575 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5576 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5577 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5578 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5579 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5580
5581 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5582 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5583 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5584 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5585 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5586 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5587 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5588 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5589 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5590 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5591
5592 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5593 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5594 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5595 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
5596 // num timestamps.
5597 0x00,
5598 };
4252 // clang-format on 5599 // clang-format on
4253 5600
5601 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
5602 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
5603
4254 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 5604 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames));
4255 ASSERT_TRUE(data != nullptr); 5605 ASSERT_TRUE(data != nullptr);
4256 5606
4257 test::CompareCharArraysWithHexError( 5607 test::CompareCharArraysWithHexError("constructed packet", data->data(),
4258 "constructed packet", data->data(), data->length(), 5608 data->length(), AsChars(packets[index]),
4259 AsChars( 5609 arraysize(packet));
4260 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
4261 ? packet_cid_be
4262 : packet),
4263 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
4264 ? arraysize(packet_cid_be)
4265 : arraysize(packet));
4266 } 5610 }
4267 5611
4268 TEST_P(QuicFramerTest, BuildNewStopWaitingPacket) { 5612 TEST_P(QuicFramerTest, BuildNewStopWaitingPacket) {
4269 QuicPacketHeader header; 5613 QuicPacketHeader header;
4270 header.public_header.connection_id = kConnectionId; 5614 header.public_header.connection_id = kConnectionId;
4271 header.public_header.reset_flag = false; 5615 header.public_header.reset_flag = false;
4272 header.public_header.version_flag = false; 5616 header.public_header.version_flag = false;
4273 header.packet_number = kPacketNumber; 5617 header.packet_number = kPacketNumber;
4274 5618
4275 QuicStopWaitingFrame stop_waiting_frame; 5619 QuicStopWaitingFrame stop_waiting_frame;
(...skipping 25 matching lines...) Expand all
4301 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 5645 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
4302 // packet number 5646 // packet number
4303 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, 5647 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
4304 5648
4305 // frame type (stop waiting frame) 5649 // frame type (stop waiting frame)
4306 0x06, 5650 0x06,
4307 // least packet number awaiting an ack, delta from packet number. 5651 // least packet number awaiting an ack, delta from packet number.
4308 0x1C, 0x00, 0x00, 0x00, 5652 0x1C, 0x00, 0x00, 0x00,
4309 0x00, 0x00, 5653 0x00, 0x00,
4310 }; 5654 };
5655
5656 unsigned char packet39[] = {
5657 // public flags (8 byte connection_id)
5658 0x38,
5659 // connection_id
5660 0x10, 0x32, 0x54, 0x76,
5661 0x98, 0xBA, 0xDC, 0xFE,
5662 // packet number
5663 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC,
5664
5665 // frame type (stop waiting frame)
5666 0x06,
5667 // least packet number awaiting an ack, delta from packet number.
5668 0x00, 0x00, 0x00, 0x00,
5669 0x00, 0x1C,
5670 };
5671
5672 unsigned char packet_cid_be39[] = {
5673 // public flags (8 byte connection_id)
5674 0x38,
5675 // connection_id
5676 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
5677 // packet number
5678 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC,
5679
5680 // frame type (stop waiting frame)
5681 0x06,
5682 // least packet number awaiting an ack, delta from packet number.
5683 0x00, 0x00, 0x00, 0x00,
5684 0x00, 0x1C,
5685 };
4311 // clang-format on 5686 // clang-format on
4312 5687
5688 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
5689 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
5690
4313 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 5691 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames));
4314 ASSERT_TRUE(data != nullptr); 5692 ASSERT_TRUE(data != nullptr);
4315 5693
4316 test::CompareCharArraysWithHexError( 5694 test::CompareCharArraysWithHexError("constructed packet", data->data(),
4317 "constructed packet", data->data(), data->length(), 5695 data->length(), AsChars(packets[index]),
4318 AsChars( 5696 arraysize(packet));
4319 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
4320 ? packet_cid_be
4321 : packet),
4322 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
4323 ? arraysize(packet_cid_be)
4324 : arraysize(packet));
4325 } 5697 }
4326 5698
4327 TEST_P(QuicFramerTest, BuildRstFramePacketQuic) { 5699 TEST_P(QuicFramerTest, BuildRstFramePacketQuic) {
4328 QuicPacketHeader header; 5700 QuicPacketHeader header;
4329 header.public_header.connection_id = kConnectionId; 5701 header.public_header.connection_id = kConnectionId;
4330 header.public_header.reset_flag = false; 5702 header.public_header.reset_flag = false;
4331 header.public_header.version_flag = false; 5703 header.public_header.version_flag = false;
4332 header.packet_number = kPacketNumber; 5704 header.packet_number = kPacketNumber;
4333 5705
4334 QuicRstStreamFrame rst_frame; 5706 QuicRstStreamFrame rst_frame;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
4370 // frame type (rst stream frame) 5742 // frame type (rst stream frame)
4371 0x01, 5743 0x01,
4372 // stream id 5744 // stream id
4373 0x04, 0x03, 0x02, 0x01, 5745 0x04, 0x03, 0x02, 0x01,
4374 // sent byte offset 5746 // sent byte offset
4375 0x01, 0x02, 0x03, 0x04, 5747 0x01, 0x02, 0x03, 0x04,
4376 0x05, 0x06, 0x07, 0x08, 5748 0x05, 0x06, 0x07, 0x08,
4377 // error code 5749 // error code
4378 0x08, 0x07, 0x06, 0x05, 5750 0x08, 0x07, 0x06, 0x05,
4379 }; 5751 };
5752
5753 unsigned char packet39[] = {
5754 // public flags (8 byte connection_id)
5755 0x38,
5756 // connection_id
5757 0x10, 0x32, 0x54, 0x76,
5758 0x98, 0xBA, 0xDC, 0xFE,
5759 // packet number
5760 0x12, 0x34, 0x56, 0x78,
5761 0x9A, 0xBC,
5762
5763 // frame type (rst stream frame)
5764 0x01,
5765 // stream id
5766 0x01, 0x02, 0x03, 0x04,
5767 // sent byte offset
5768 0x08, 0x07, 0x06, 0x05,
5769 0x04, 0x03, 0x02, 0x01,
5770 // error code
5771 0x05, 0x06, 0x07, 0x08,
5772 };
5773
5774 unsigned char packet_cid_be39[] = {
5775 // public flags (8 byte connection_id)
5776 0x38,
5777 // connection_id
5778 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
5779 // packet number
5780 0x12, 0x34, 0x56, 0x78,
5781 0x9A, 0xBC,
5782
5783 // frame type (rst stream frame)
5784 0x01,
5785 // stream id
5786 0x01, 0x02, 0x03, 0x04,
5787 // sent byte offset
5788 0x08, 0x07, 0x06, 0x05,
5789 0x04, 0x03, 0x02, 0x01,
5790 // error code
5791 0x05, 0x06, 0x07, 0x08,
5792 };
4380 // clang-format on 5793 // clang-format on
4381 5794
5795 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
5796 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
5797
4382 QuicFrames frames = {QuicFrame(&rst_frame)}; 5798 QuicFrames frames = {QuicFrame(&rst_frame)};
4383 5799
4384 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 5800 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames));
4385 ASSERT_TRUE(data != nullptr); 5801 ASSERT_TRUE(data != nullptr);
4386 5802
4387 test::CompareCharArraysWithHexError( 5803 test::CompareCharArraysWithHexError("constructed packet", data->data(),
4388 "constructed packet", data->data(), data->length(), 5804 data->length(), AsChars(packets[index]),
4389 AsChars( 5805 arraysize(packet));
4390 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
4391 ? packet_cid_be
4392 : packet),
4393 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
4394 ? arraysize(packet_cid_be)
4395 : arraysize(packet));
4396 } 5806 }
4397 5807
4398 TEST_P(QuicFramerTest, BuildCloseFramePacket) { 5808 TEST_P(QuicFramerTest, BuildCloseFramePacket) {
4399 QuicPacketHeader header; 5809 QuicPacketHeader header;
4400 header.public_header.connection_id = kConnectionId; 5810 header.public_header.connection_id = kConnectionId;
4401 header.public_header.reset_flag = false; 5811 header.public_header.reset_flag = false;
4402 header.public_header.version_flag = false; 5812 header.public_header.version_flag = false;
4403 header.packet_number = kPacketNumber; 5813 header.packet_number = kPacketNumber;
4404 5814
4405 QuicConnectionCloseFrame close_frame; 5815 QuicConnectionCloseFrame close_frame;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
4446 // error code 5856 // error code
4447 0x08, 0x07, 0x06, 0x05, 5857 0x08, 0x07, 0x06, 0x05,
4448 // error details length 5858 // error details length
4449 0x0d, 0x00, 5859 0x0d, 0x00,
4450 // error details 5860 // error details
4451 'b', 'e', 'c', 'a', 5861 'b', 'e', 'c', 'a',
4452 'u', 's', 'e', ' ', 5862 'u', 's', 'e', ' ',
4453 'I', ' ', 'c', 'a', 5863 'I', ' ', 'c', 'a',
4454 'n', 5864 'n',
4455 }; 5865 };
5866
5867 unsigned char packet39[] = {
5868 // public flags (8 byte connection_id)
5869 0x38,
5870 // connection_id
5871 0x10, 0x32, 0x54, 0x76,
5872 0x98, 0xBA, 0xDC, 0xFE,
5873 // packet number
5874 0x12, 0x34, 0x56, 0x78,
5875 0x9A, 0xBC,
5876
5877 // frame type (connection close frame)
5878 0x02,
5879 // error code
5880 0x05, 0x06, 0x07, 0x08,
5881 // error details length
5882 0x00, 0x0d,
5883 // error details
5884 'b', 'e', 'c', 'a',
5885 'u', 's', 'e', ' ',
5886 'I', ' ', 'c', 'a',
5887 'n',
5888 };
5889
5890 unsigned char packet_cid_be39[] = {
5891 // public flags (8 byte connection_id)
5892 0x38,
5893 // connection_id
5894 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
5895 // packet number
5896 0x12, 0x34, 0x56, 0x78,
5897 0x9A, 0xBC,
5898
5899 // frame type (connection close frame)
5900 0x02,
5901 // error code
5902 0x05, 0x06, 0x07, 0x08,
5903 // error details length
5904 0x00, 0x0d,
5905 // error details
5906 'b', 'e', 'c', 'a',
5907 'u', 's', 'e', ' ',
5908 'I', ' ', 'c', 'a',
5909 'n',
5910 };
4456 // clang-format on 5911 // clang-format on
4457 5912
5913 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
5914 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
5915
4458 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 5916 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames));
4459 ASSERT_TRUE(data != nullptr); 5917 ASSERT_TRUE(data != nullptr);
4460 5918
4461 test::CompareCharArraysWithHexError( 5919 test::CompareCharArraysWithHexError("constructed packet", data->data(),
4462 "constructed packet", data->data(), data->length(), 5920 data->length(), AsChars(packets[index]),
4463 AsChars( 5921 arraysize(packet));
4464 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
4465 ? packet_cid_be
4466 : packet),
4467 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
4468 ? arraysize(packet_cid_be)
4469 : arraysize(packet));
4470 } 5922 }
4471 5923
4472 TEST_P(QuicFramerTest, BuildGoAwayPacket) { 5924 TEST_P(QuicFramerTest, BuildGoAwayPacket) {
4473 QuicPacketHeader header; 5925 QuicPacketHeader header;
4474 header.public_header.connection_id = kConnectionId; 5926 header.public_header.connection_id = kConnectionId;
4475 header.public_header.reset_flag = false; 5927 header.public_header.reset_flag = false;
4476 header.public_header.version_flag = false; 5928 header.public_header.version_flag = false;
4477 header.packet_number = kPacketNumber; 5929 header.packet_number = kPacketNumber;
4478 5930
4479 QuicGoAwayFrame goaway_frame; 5931 QuicGoAwayFrame goaway_frame;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
4525 // stream id 5977 // stream id
4526 0x04, 0x03, 0x02, 0x01, 5978 0x04, 0x03, 0x02, 0x01,
4527 // error details length 5979 // error details length
4528 0x0d, 0x00, 5980 0x0d, 0x00,
4529 // error details 5981 // error details
4530 'b', 'e', 'c', 'a', 5982 'b', 'e', 'c', 'a',
4531 'u', 's', 'e', ' ', 5983 'u', 's', 'e', ' ',
4532 'I', ' ', 'c', 'a', 5984 'I', ' ', 'c', 'a',
4533 'n', 5985 'n',
4534 }; 5986 };
5987
5988 unsigned char packet39[] = {
5989 // public flags (8 byte connection_id)
5990 0x38,
5991 // connection_id
5992 0x10, 0x32, 0x54, 0x76,
5993 0x98, 0xBA, 0xDC, 0xFE,
5994 // packet number
5995 0x12, 0x34, 0x56, 0x78,
5996 0x9A, 0xBC,
5997
5998 // frame type (go away frame)
5999 0x03,
6000 // error code
6001 0x05, 0x06, 0x07, 0x08,
6002 // stream id
6003 0x01, 0x02, 0x03, 0x04,
6004 // error details length
6005 0x00, 0x0d,
6006 // error details
6007 'b', 'e', 'c', 'a',
6008 'u', 's', 'e', ' ',
6009 'I', ' ', 'c', 'a',
6010 'n',
6011 };
6012
6013 unsigned char packet_cid_be39[] = {
6014 // public flags (8 byte connection_id)
6015 0x38,
6016 // connection_id
6017 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
6018 // packet number
6019 0x12, 0x34, 0x56, 0x78,
6020 0x9A, 0xBC,
6021
6022 // frame type (go away frame)
6023 0x03,
6024 // error code
6025 0x05, 0x06, 0x07, 0x08,
6026 // stream id
6027 0x01, 0x02, 0x03, 0x04,
6028 // error details length
6029 0x00, 0x0d,
6030 // error details
6031 'b', 'e', 'c', 'a',
6032 'u', 's', 'e', ' ',
6033 'I', ' ', 'c', 'a',
6034 'n',
6035 };
4535 // clang-format on 6036 // clang-format on
4536 6037
6038 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
6039 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
6040
4537 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 6041 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames));
4538 ASSERT_TRUE(data != nullptr); 6042 ASSERT_TRUE(data != nullptr);
4539 6043
4540 test::CompareCharArraysWithHexError( 6044 test::CompareCharArraysWithHexError("constructed packet", data->data(),
4541 "constructed packet", data->data(), data->length(), 6045 data->length(), AsChars(packets[index]),
4542 AsChars( 6046 arraysize(packet));
4543 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
4544 ? packet_cid_be
4545 : packet),
4546 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
4547 ? arraysize(packet_cid_be)
4548 : arraysize(packet));
4549 } 6047 }
4550 6048
4551 TEST_P(QuicFramerTest, BuildWindowUpdatePacket) { 6049 TEST_P(QuicFramerTest, BuildWindowUpdatePacket) {
4552 QuicPacketHeader header; 6050 QuicPacketHeader header;
4553 header.public_header.connection_id = kConnectionId; 6051 header.public_header.connection_id = kConnectionId;
4554 header.public_header.reset_flag = false; 6052 header.public_header.reset_flag = false;
4555 header.public_header.version_flag = false; 6053 header.public_header.version_flag = false;
4556 header.packet_number = kPacketNumber; 6054 header.packet_number = kPacketNumber;
4557 6055
4558 QuicWindowUpdateFrame window_update_frame; 6056 QuicWindowUpdateFrame window_update_frame;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
4591 0x34, 0x12, 6089 0x34, 0x12,
4592 6090
4593 // frame type (window update frame) 6091 // frame type (window update frame)
4594 0x04, 6092 0x04,
4595 // stream id 6093 // stream id
4596 0x04, 0x03, 0x02, 0x01, 6094 0x04, 0x03, 0x02, 0x01,
4597 // byte offset 6095 // byte offset
4598 0x88, 0x77, 0x66, 0x55, 6096 0x88, 0x77, 0x66, 0x55,
4599 0x44, 0x33, 0x22, 0x11, 6097 0x44, 0x33, 0x22, 0x11,
4600 }; 6098 };
6099
6100 unsigned char packet39[] = {
6101 // public flags (8 byte connection_id)
6102 0x38,
6103 // connection_id
6104 0x10, 0x32, 0x54, 0x76,
6105 0x98, 0xBA, 0xDC, 0xFE,
6106 // packet number
6107 0x12, 0x34, 0x56, 0x78,
6108 0x9A, 0xBC,
6109
6110 // frame type (window update frame)
6111 0x04,
6112 // stream id
6113 0x01, 0x02, 0x03, 0x04,
6114 // byte offset
6115 0x11, 0x22, 0x33, 0x44,
6116 0x55, 0x66, 0x77, 0x88,
6117 };
6118
6119 unsigned char packet_cid_be39[] = {
6120 // public flags (8 byte connection_id)
6121 0x38,
6122 // connection_id
6123 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
6124 // packet number
6125 0x12, 0x34, 0x56, 0x78,
6126 0x9A, 0xBC,
6127
6128 // frame type (window update frame)
6129 0x04,
6130 // stream id
6131 0x01, 0x02, 0x03, 0x04,
6132 // byte offset
6133 0x11, 0x22, 0x33, 0x44,
6134 0x55, 0x66, 0x77, 0x88,
6135 };
4601 // clang-format on 6136 // clang-format on
4602 6137
6138 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
6139 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
6140
4603 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 6141 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames));
4604 ASSERT_TRUE(data != nullptr); 6142 ASSERT_TRUE(data != nullptr);
4605 6143
4606 test::CompareCharArraysWithHexError( 6144 test::CompareCharArraysWithHexError("constructed packet", data->data(),
4607 "constructed packet", data->data(), data->length(), 6145 data->length(), AsChars(packets[index]),
4608 AsChars( 6146 arraysize(packet));
4609 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
4610 ? packet_cid_be
4611 : packet),
4612 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
4613 ? arraysize(packet_cid_be)
4614 : arraysize(packet));
4615 } 6147 }
4616 6148
4617 TEST_P(QuicFramerTest, BuildBlockedPacket) { 6149 TEST_P(QuicFramerTest, BuildBlockedPacket) {
4618 QuicPacketHeader header; 6150 QuicPacketHeader header;
4619 header.public_header.connection_id = kConnectionId; 6151 header.public_header.connection_id = kConnectionId;
4620 header.public_header.reset_flag = false; 6152 header.public_header.reset_flag = false;
4621 header.public_header.version_flag = false; 6153 header.public_header.version_flag = false;
4622 header.packet_number = kPacketNumber; 6154 header.packet_number = kPacketNumber;
4623 6155
4624 QuicBlockedFrame blocked_frame; 6156 QuicBlockedFrame blocked_frame;
(...skipping 25 matching lines...) Expand all
4650 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 6182 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
4651 // packet number 6183 // packet number
4652 0xBC, 0x9A, 0x78, 0x56, 6184 0xBC, 0x9A, 0x78, 0x56,
4653 0x34, 0x12, 6185 0x34, 0x12,
4654 6186
4655 // frame type (blocked frame) 6187 // frame type (blocked frame)
4656 0x05, 6188 0x05,
4657 // stream id 6189 // stream id
4658 0x04, 0x03, 0x02, 0x01, 6190 0x04, 0x03, 0x02, 0x01,
4659 }; 6191 };
6192
6193 unsigned char packet39[] = {
6194 // public flags (8 byte connection_id)
6195 0x38,
6196 // connection_id
6197 0x10, 0x32, 0x54, 0x76,
6198 0x98, 0xBA, 0xDC, 0xFE,
6199 // packet number
6200 0x12, 0x34, 0x56, 0x78,
6201 0x9A, 0xBC,
6202
6203 // frame type (blocked frame)
6204 0x05,
6205 // stream id
6206 0x01, 0x02, 0x03, 0x04,
6207 };
6208
6209 unsigned char packet_cid_be39[] = {
6210 // public flags (8 byte connection_id)
6211 0x38,
6212 // connection_id
6213 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
6214 // packet number
6215 0x12, 0x34, 0x56, 0x78,
6216 0x9A, 0xBC,
6217
6218 // frame type (blocked frame)
6219 0x05,
6220 // stream id
6221 0x01, 0x02, 0x03, 0x04,
6222 };
4660 // clang-format on 6223 // clang-format on
4661 6224
6225 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
6226 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
6227
4662 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 6228 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames));
4663 ASSERT_TRUE(data != nullptr); 6229 ASSERT_TRUE(data != nullptr);
4664 6230
4665 test::CompareCharArraysWithHexError( 6231 test::CompareCharArraysWithHexError("constructed packet", data->data(),
4666 "constructed packet", data->data(), data->length(), 6232 data->length(), AsChars(packets[index]),
4667 AsChars( 6233 arraysize(packet));
4668 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
4669 ? packet_cid_be
4670 : packet),
4671 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
4672 ? arraysize(packet_cid_be)
4673 : arraysize(packet));
4674 } 6234 }
4675 6235
4676 TEST_P(QuicFramerTest, BuildPingPacket) { 6236 TEST_P(QuicFramerTest, BuildPingPacket) {
4677 QuicPacketHeader header; 6237 QuicPacketHeader header;
4678 header.public_header.connection_id = kConnectionId; 6238 header.public_header.connection_id = kConnectionId;
4679 header.public_header.reset_flag = false; 6239 header.public_header.reset_flag = false;
4680 header.public_header.version_flag = false; 6240 header.public_header.version_flag = false;
4681 header.packet_number = kPacketNumber; 6241 header.packet_number = kPacketNumber;
4682 6242
4683 QuicFrames frames = {QuicFrame(QuicPingFrame())}; 6243 QuicFrames frames = {QuicFrame(QuicPingFrame())};
(...skipping 18 matching lines...) Expand all
4702 0x38, 6262 0x38,
4703 // connection_id 6263 // connection_id
4704 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 6264 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
4705 // packet number 6265 // packet number
4706 0xBC, 0x9A, 0x78, 0x56, 6266 0xBC, 0x9A, 0x78, 0x56,
4707 0x34, 0x12, 6267 0x34, 0x12,
4708 6268
4709 // frame type (ping frame) 6269 // frame type (ping frame)
4710 0x07, 6270 0x07,
4711 }; 6271 };
6272
6273 unsigned char packet39[] = {
6274 // public flags (8 byte connection_id)
6275 0x38,
6276 // connection_id
6277 0x10, 0x32, 0x54, 0x76,
6278 0x98, 0xBA, 0xDC, 0xFE,
6279 // packet number
6280 0x12, 0x34, 0x56, 0x78,
6281 0x9A, 0xBC,
6282
6283 // frame type (ping frame)
6284 0x07,
6285 };
6286
6287 unsigned char packet_cid_be39[] = {
6288 // public flags (8 byte connection_id)
6289 0x38,
6290 // connection_id
6291 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
6292 // packet number
6293 0x12, 0x34, 0x56, 0x78,
6294 0x9A, 0xBC,
6295
6296 // frame type (ping frame)
6297 0x07,
6298 };
4712 // clang-format on 6299 // clang-format on
4713 6300
6301 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
6302 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
6303
4714 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 6304 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames));
4715 ASSERT_TRUE(data != nullptr); 6305 ASSERT_TRUE(data != nullptr);
4716 6306
4717 test::CompareCharArraysWithHexError( 6307 test::CompareCharArraysWithHexError("constructed packet", data->data(),
4718 "constructed packet", data->data(), data->length(), 6308 data->length(), AsChars(packets[index]),
4719 AsChars( 6309 arraysize(packet));
4720 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
4721 ? packet_cid_be
4722 : packet),
4723 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
4724 ? arraysize(packet_cid_be)
4725 : arraysize(packet));
4726 } 6310 }
4727 6311
4728 // Test that the MTU discovery packet is serialized correctly as a PING packet. 6312 // Test that the MTU discovery packet is serialized correctly as a PING packet.
4729 TEST_P(QuicFramerTest, BuildMtuDiscoveryPacket) { 6313 TEST_P(QuicFramerTest, BuildMtuDiscoveryPacket) {
4730 QuicPacketHeader header; 6314 QuicPacketHeader header;
4731 header.public_header.connection_id = kConnectionId; 6315 header.public_header.connection_id = kConnectionId;
4732 header.public_header.reset_flag = false; 6316 header.public_header.reset_flag = false;
4733 header.public_header.version_flag = false; 6317 header.public_header.version_flag = false;
4734 header.packet_number = kPacketNumber; 6318 header.packet_number = kPacketNumber;
4735 6319
(...skipping 19 matching lines...) Expand all
4755 0x38, 6339 0x38,
4756 // connection_id 6340 // connection_id
4757 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 6341 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
4758 // packet number 6342 // packet number
4759 0xBC, 0x9A, 0x78, 0x56, 6343 0xBC, 0x9A, 0x78, 0x56,
4760 0x34, 0x12, 6344 0x34, 0x12,
4761 6345
4762 // frame type (ping frame) 6346 // frame type (ping frame)
4763 0x07, 6347 0x07,
4764 }; 6348 };
6349
6350 unsigned char packet39[] = {
6351 // public flags (8 byte connection_id)
6352 0x38,
6353 // connection_id
6354 0x10, 0x32, 0x54, 0x76,
6355 0x98, 0xBA, 0xDC, 0xFE,
6356 // packet number
6357 0x12, 0x34, 0x56, 0x78,
6358 0x9A, 0xBC,
6359
6360 // frame type (ping frame)
6361 0x07,
6362 };
6363
6364 unsigned char packet_cid_be39[] = {
6365 // public flags (8 byte connection_id)
6366 0x38,
6367 // connection_id
6368 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
6369 // packet number
6370 0x12, 0x34, 0x56, 0x78,
6371 0x9A, 0xBC,
6372
6373 // frame type (ping frame)
6374 0x07,
6375 };
4765 // clang-format on 6376 // clang-format on
4766 6377
6378 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
6379 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
6380
4767 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 6381 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames));
4768 ASSERT_TRUE(data != nullptr); 6382 ASSERT_TRUE(data != nullptr);
4769 6383
4770 test::CompareCharArraysWithHexError( 6384 test::CompareCharArraysWithHexError("constructed packet", data->data(),
4771 "constructed packet", data->data(), data->length(), 6385 data->length(), AsChars(packets[index]),
4772 AsChars( 6386 arraysize(packet));
4773 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
4774 ? packet_cid_be
4775 : packet),
4776 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
4777 ? arraysize(packet_cid_be)
4778 : arraysize(packet));
4779 } 6387 }
4780 6388
4781 TEST_P(QuicFramerTest, BuildPublicResetPacketOld) { 6389 TEST_P(QuicFramerTest, BuildPublicResetPacketOld) {
4782 FLAGS_quic_reloadable_flag_quic_use_old_public_reset_packets = true; 6390 FLAGS_quic_reloadable_flag_quic_use_old_public_reset_packets = true;
4783 QuicPublicResetPacket reset_packet; 6391 QuicPublicResetPacket reset_packet;
4784 reset_packet.public_header.connection_id = kConnectionId; 6392 reset_packet.public_header.connection_id = kConnectionId;
4785 reset_packet.public_header.reset_flag = true; 6393 reset_packet.public_header.reset_flag = true;
4786 reset_packet.public_header.version_flag = false; 6394 reset_packet.public_header.version_flag = false;
4787 reset_packet.rejected_packet_number = kPacketNumber;
4788 reset_packet.nonce_proof = kNonceProof; 6395 reset_packet.nonce_proof = kNonceProof;
4789 6396
4790 // clang-format off 6397 // clang-format off
4791 unsigned char packet[] = { 6398 unsigned char packet[] = {
4792 // public flags (public reset, 8 byte ConnectionId) 6399 // public flags (public reset, 8 byte ConnectionId)
4793 0x0E, 6400 0x0E,
4794 // connection_id 6401 // connection_id
4795 0x10, 0x32, 0x54, 0x76, 6402 0x10, 0x32, 0x54, 0x76,
4796 0x98, 0xBA, 0xDC, 0xFE, 6403 0x98, 0xBA, 0xDC, 0xFE,
4797 // message tag (kPRST)
4798 'P', 'R', 'S', 'T',
4799 // num_entries (2) + padding
4800 0x02, 0x00, 0x00, 0x00,
4801 // tag kRNON
4802 'R', 'N', 'O', 'N',
4803 // end offset 8
4804 0x08, 0x00, 0x00, 0x00,
4805 // tag kRSEQ
4806 'R', 'S', 'E', 'Q',
4807 // end offset 16
4808 0x10, 0x00, 0x00, 0x00,
4809 // nonce proof
4810 0x89, 0x67, 0x45, 0x23,
4811 0x01, 0xEF, 0xCD, 0xAB,
4812 // rejected packet number
4813 0xBC, 0x9A, 0x78, 0x56,
4814 0x34, 0x12, 0x00, 0x00,
4815 };
4816
4817 unsigned char packet_cid_be[] = {
4818 // public flags (public reset, 8 byte ConnectionId)
4819 0x0E,
4820 // connection_id
4821 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
4822 // message tag (kPRST)
4823 'P', 'R', 'S', 'T',
4824 // num_entries (2) + padding
4825 0x02, 0x00, 0x00, 0x00,
4826 // tag kRNON
4827 'R', 'N', 'O', 'N',
4828 // end offset 8
4829 0x08, 0x00, 0x00, 0x00,
4830 // tag kRSEQ
4831 'R', 'S', 'E', 'Q',
4832 // end offset 16
4833 0x10, 0x00, 0x00, 0x00,
4834 // nonce proof
4835 0x89, 0x67, 0x45, 0x23,
4836 0x01, 0xEF, 0xCD, 0xAB,
4837 // rejected packet number
4838 0xBC, 0x9A, 0x78, 0x56,
4839 0x34, 0x12, 0x00, 0x00,
4840 };
4841
4842 unsigned char packet_no_rejected_packet_number[] = {
4843 // public flags (public reset, 8 byte ConnectionId)
4844 0x0E,
4845 // connection_id
4846 0x10, 0x32, 0x54, 0x76,
4847 0x98, 0xBA, 0xDC, 0xFE,
4848 // message tag (kPRST)
4849 'P', 'R', 'S', 'T',
4850 // num_entries (1) + padding
4851 0x01, 0x00, 0x00, 0x00,
4852 // tag kRNON
4853 'R', 'N', 'O', 'N',
4854 // end offset 8
4855 0x08, 0x00, 0x00, 0x00,
4856 // nonce proof
4857 0x89, 0x67, 0x45, 0x23,
4858 0x01, 0xEF, 0xCD, 0xAB,
4859 };
4860
4861 unsigned char packet_no_rejected_packet_number_cid_be[] = {
4862 // public flags (public reset, 8 byte ConnectionId)
4863 0x0E,
4864 // connection_id
4865 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
4866 // message tag (kPRST)
4867 'P', 'R', 'S', 'T',
4868 // num_entries (1) + padding
4869 0x01, 0x00, 0x00, 0x00,
4870 // tag kRNON
4871 'R', 'N', 'O', 'N',
4872 // end offset 8
4873 0x08, 0x00, 0x00, 0x00,
4874 // nonce proof
4875 0x89, 0x67, 0x45, 0x23,
4876 0x01, 0xEF, 0xCD, 0xAB,
4877 };
4878 // clang-format on
4879
4880 std::unique_ptr<QuicEncryptedPacket> data(
4881 framer_.BuildPublicResetPacket(reset_packet));
4882 ASSERT_TRUE(data != nullptr);
4883 if (FLAGS_quic_reloadable_flag_quic_remove_packet_number_from_public_reset) {
4884 test::CompareCharArraysWithHexError(
4885 "constructed packet", data->data(), data->length(),
4886 AsChars(
4887 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
4888 ? packet_no_rejected_packet_number_cid_be
4889 : packet_no_rejected_packet_number),
4890 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
4891 ? arraysize(packet_no_rejected_packet_number_cid_be)
4892 : arraysize(packet_no_rejected_packet_number));
4893 } else {
4894 test::CompareCharArraysWithHexError(
4895 "constructed packet", data->data(), data->length(),
4896 AsChars(
4897 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
4898 ? packet_cid_be
4899 : packet),
4900 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
4901 ? arraysize(packet_cid_be)
4902 : arraysize(packet));
4903 }
4904 }
4905
4906 TEST_P(QuicFramerTest, BuildPublicResetPacket) {
4907 FLAGS_quic_reloadable_flag_quic_use_old_public_reset_packets = false;
4908 QuicPublicResetPacket reset_packet;
4909 reset_packet.public_header.connection_id = kConnectionId;
4910 reset_packet.public_header.reset_flag = true;
4911 reset_packet.public_header.version_flag = false;
4912 reset_packet.rejected_packet_number = kPacketNumber;
4913 reset_packet.nonce_proof = kNonceProof;
4914
4915 // clang-format off
4916 unsigned char packet[] = {
4917 // public flags (public reset, 8 byte ConnectionId)
4918 0x0A,
4919 // connection_id
4920 0x10, 0x32, 0x54, 0x76,
4921 0x98, 0xBA, 0xDC, 0xFE,
4922 // message tag (kPRST)
4923 'P', 'R', 'S', 'T',
4924 // num_entries (2) + padding
4925 0x02, 0x00, 0x00, 0x00,
4926 // tag kRNON
4927 'R', 'N', 'O', 'N',
4928 // end offset 8
4929 0x08, 0x00, 0x00, 0x00,
4930 // tag kRSEQ
4931 'R', 'S', 'E', 'Q',
4932 // end offset 16
4933 0x10, 0x00, 0x00, 0x00,
4934 // nonce proof
4935 0x89, 0x67, 0x45, 0x23,
4936 0x01, 0xEF, 0xCD, 0xAB,
4937 // rejected packet number
4938 0xBC, 0x9A, 0x78, 0x56,
4939 0x34, 0x12, 0x00, 0x00,
4940 };
4941
4942 unsigned char packet_cid_be[] = {
4943 // public flags (public reset, 8 byte ConnectionId)
4944 0x0A,
4945 // connection_id
4946 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
4947 // message tag (kPRST)
4948 'P', 'R', 'S', 'T',
4949 // num_entries (2) + padding
4950 0x02, 0x00, 0x00, 0x00,
4951 // tag kRNON
4952 'R', 'N', 'O', 'N',
4953 // end offset 8
4954 0x08, 0x00, 0x00, 0x00,
4955 // tag kRSEQ
4956 'R', 'S', 'E', 'Q',
4957 // end offset 16
4958 0x10, 0x00, 0x00, 0x00,
4959 // nonce proof
4960 0x89, 0x67, 0x45, 0x23,
4961 0x01, 0xEF, 0xCD, 0xAB,
4962 // rejected packet number
4963 0xBC, 0x9A, 0x78, 0x56,
4964 0x34, 0x12, 0x00, 0x00,
4965 };
4966
4967 unsigned char packet_no_rejected_packet_number[] = {
4968 // public flags (public reset, 8 byte ConnectionId)
4969 0x0A,
4970 // connection_id
4971 0x10, 0x32, 0x54, 0x76,
4972 0x98, 0xBA, 0xDC, 0xFE,
4973 // message tag (kPRST) 6404 // message tag (kPRST)
4974 'P', 'R', 'S', 'T', 6405 'P', 'R', 'S', 'T',
4975 // num_entries (1) + padding 6406 // num_entries (1) + padding
4976 0x01, 0x00, 0x00, 0x00, 6407 0x01, 0x00, 0x00, 0x00,
4977 // tag kRNON 6408 // tag kRNON
4978 'R', 'N', 'O', 'N', 6409 'R', 'N', 'O', 'N',
4979 // end offset 8 6410 // end offset 8
4980 0x08, 0x00, 0x00, 0x00, 6411 0x08, 0x00, 0x00, 0x00,
4981 // nonce proof 6412 // nonce proof
4982 0x89, 0x67, 0x45, 0x23, 6413 0x89, 0x67, 0x45, 0x23,
4983 0x01, 0xEF, 0xCD, 0xAB, 6414 0x01, 0xEF, 0xCD, 0xAB,
4984 }; 6415 };
4985 6416
4986 unsigned char packet_no_rejected_packet_number_cid_be[] = { 6417 unsigned char packet_cid_be[] = {
4987 // public flags (public reset, 8 byte ConnectionId) 6418 // public flags (public reset, 8 byte ConnectionId)
4988 0x0A, 6419 0x0E,
4989 // connection_id 6420 // connection_id
4990 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 6421 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
4991 // message tag (kPRST) 6422 // message tag (kPRST)
4992 'P', 'R', 'S', 'T', 6423 'P', 'R', 'S', 'T',
4993 // num_entries (1) + padding 6424 // num_entries (1) + padding
4994 0x01, 0x00, 0x00, 0x00, 6425 0x01, 0x00, 0x00, 0x00,
4995 // tag kRNON 6426 // tag kRNON
4996 'R', 'N', 'O', 'N', 6427 'R', 'N', 'O', 'N',
4997 // end offset 8 6428 // end offset 8
4998 0x08, 0x00, 0x00, 0x00, 6429 0x08, 0x00, 0x00, 0x00,
4999 // nonce proof 6430 // nonce proof
5000 0x89, 0x67, 0x45, 0x23, 6431 0x89, 0x67, 0x45, 0x23,
5001 0x01, 0xEF, 0xCD, 0xAB, 6432 0x01, 0xEF, 0xCD, 0xAB,
5002 }; 6433 };
5003 // clang-format on 6434 // clang-format on
5004 6435
5005 std::unique_ptr<QuicEncryptedPacket> data( 6436 std::unique_ptr<QuicEncryptedPacket> data(
5006 framer_.BuildPublicResetPacket(reset_packet)); 6437 framer_.BuildPublicResetPacket(reset_packet));
5007 ASSERT_TRUE(data != nullptr); 6438 ASSERT_TRUE(data != nullptr);
6439 test::CompareCharArraysWithHexError(
6440 "constructed packet", data->data(), data->length(),
6441 AsChars(
6442 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
6443 ? packet_cid_be
6444 : packet),
6445 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
6446 ? arraysize(packet_cid_be)
6447 : arraysize(packet));
6448 }
6449
6450 TEST_P(QuicFramerTest, BuildPublicResetPacket) {
6451 FLAGS_quic_reloadable_flag_quic_use_old_public_reset_packets = false;
6452 QuicPublicResetPacket reset_packet;
6453 reset_packet.public_header.connection_id = kConnectionId;
6454 reset_packet.public_header.reset_flag = true;
6455 reset_packet.public_header.version_flag = false;
6456 reset_packet.nonce_proof = kNonceProof;
6457
6458 // clang-format off
6459 unsigned char packet[] = {
6460 // public flags (public reset, 8 byte ConnectionId)
6461 0x0A,
6462 // connection_id
6463 0x10, 0x32, 0x54, 0x76,
6464 0x98, 0xBA, 0xDC, 0xFE,
6465 // message tag (kPRST)
6466 'P', 'R', 'S', 'T',
6467 // num_entries (1) + padding
6468 0x01, 0x00, 0x00, 0x00,
6469 // tag kRNON
6470 'R', 'N', 'O', 'N',
6471 // end offset 8
6472 0x08, 0x00, 0x00, 0x00,
6473 // nonce proof
6474 0x89, 0x67, 0x45, 0x23,
6475 0x01, 0xEF, 0xCD, 0xAB,
6476 };
6477
6478 unsigned char packet_cid_be[] = {
6479 // public flags (public reset, 8 byte ConnectionId)
6480 0x0A,
6481 // connection_id
6482 0xFE, 0xDC, 0xBA, 0x98,
6483 0x76, 0x54, 0x32, 0x10,
6484 // message tag (kPRST)
6485 'P', 'R', 'S', 'T',
6486 // num_entries (1) + padding
6487 0x01, 0x00, 0x00, 0x00,
6488 // tag kRNON
6489 'R', 'N', 'O', 'N',
6490 // end offset 8
6491 0x08, 0x00, 0x00, 0x00,
6492 // nonce proof
6493 0x89, 0x67, 0x45, 0x23,
6494 0x01, 0xEF, 0xCD, 0xAB,
6495 };
6496 // clang-format on
6497
6498 std::unique_ptr<QuicEncryptedPacket> data(
6499 framer_.BuildPublicResetPacket(reset_packet));
6500 ASSERT_TRUE(data != nullptr);
5008 6501
5009 if (FLAGS_quic_reloadable_flag_quic_remove_packet_number_from_public_reset) { 6502 test::CompareCharArraysWithHexError(
5010 test::CompareCharArraysWithHexError( 6503 "constructed packet", data->data(), data->length(),
5011 "constructed packet", data->data(), data->length(), 6504 AsChars(
5012 AsChars( 6505 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
5013 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 6506 ? packet_cid_be
5014 ? packet_no_rejected_packet_number_cid_be 6507 : packet),
5015 : packet_no_rejected_packet_number), 6508 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
5016 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 6509 ? arraysize(packet_cid_be)
5017 ? arraysize(packet_no_rejected_packet_number_cid_be) 6510 : arraysize(packet));
5018 : arraysize(packet_no_rejected_packet_number));
5019 } else {
5020 test::CompareCharArraysWithHexError(
5021 "constructed packet", data->data(), data->length(),
5022 AsChars(
5023 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
5024 ? packet_cid_be
5025 : packet),
5026 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
5027 ? arraysize(packet_cid_be)
5028 : arraysize(packet));
5029 }
5030 } 6511 }
5031 6512
5032 TEST_P(QuicFramerTest, BuildPublicResetPacketWithClientAddress) { 6513 TEST_P(QuicFramerTest, BuildPublicResetPacketWithClientAddress) {
5033 FLAGS_quic_reloadable_flag_quic_use_old_public_reset_packets = false; 6514 FLAGS_quic_reloadable_flag_quic_use_old_public_reset_packets = false;
5034 QuicPublicResetPacket reset_packet; 6515 QuicPublicResetPacket reset_packet;
5035 reset_packet.public_header.connection_id = kConnectionId; 6516 reset_packet.public_header.connection_id = kConnectionId;
5036 reset_packet.public_header.reset_flag = true; 6517 reset_packet.public_header.reset_flag = true;
5037 reset_packet.public_header.version_flag = false; 6518 reset_packet.public_header.version_flag = false;
5038 reset_packet.rejected_packet_number = kPacketNumber;
5039 reset_packet.nonce_proof = kNonceProof; 6519 reset_packet.nonce_proof = kNonceProof;
5040 reset_packet.client_address = 6520 reset_packet.client_address =
5041 QuicSocketAddress(QuicIpAddress::Loopback4(), 0x1234); 6521 QuicSocketAddress(QuicIpAddress::Loopback4(), 0x1234);
5042 6522
5043 // clang-format off 6523 // clang-format off
5044 unsigned char packet[] = { 6524 unsigned char packet[] = {
5045 // public flags (public reset, 8 byte ConnectionId)
5046 0x0A,
5047 // connection_id
5048 0x10, 0x32, 0x54, 0x76,
5049 0x98, 0xBA, 0xDC, 0xFE,
5050 // message tag (kPRST)
5051 'P', 'R', 'S', 'T',
5052 // num_entries (3) + padding
5053 0x03, 0x00, 0x00, 0x00,
5054 // tag kRNON
5055 'R', 'N', 'O', 'N',
5056 // end offset 8
5057 0x08, 0x00, 0x00, 0x00,
5058 // tag kRSEQ
5059 'R', 'S', 'E', 'Q',
5060 // end offset 16
5061 0x10, 0x00, 0x00, 0x00,
5062 // tag kCADR
5063 'C', 'A', 'D', 'R',
5064 // end offset 24
5065 0x18, 0x00, 0x00, 0x00,
5066 // nonce proof
5067 0x89, 0x67, 0x45, 0x23,
5068 0x01, 0xEF, 0xCD, 0xAB,
5069 // rejected packet number
5070 0xBC, 0x9A, 0x78, 0x56,
5071 0x34, 0x12, 0x00, 0x00,
5072 // client address
5073 0x02, 0x00,
5074 0x7F, 0x00, 0x00, 0x01,
5075 0x34, 0x12,
5076 };
5077
5078 unsigned char packet_cid_be[] = {
5079 // public flags (public reset, 8 byte ConnectionId)
5080 0x0A,
5081 // connection_id
5082 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
5083 // message tag (kPRST)
5084 'P', 'R', 'S', 'T',
5085 // num_entries (3) + padding
5086 0x03, 0x00, 0x00, 0x00,
5087 // tag kRNON
5088 'R', 'N', 'O', 'N',
5089 // end offset 8
5090 0x08, 0x00, 0x00, 0x00,
5091 // tag kRSEQ
5092 'R', 'S', 'E', 'Q',
5093 // end offset 16
5094 0x10, 0x00, 0x00, 0x00,
5095 // tag kCADR
5096 'C', 'A', 'D', 'R',
5097 // end offset 24
5098 0x18, 0x00, 0x00, 0x00,
5099 // nonce proof
5100 0x89, 0x67, 0x45, 0x23,
5101 0x01, 0xEF, 0xCD, 0xAB,
5102 // rejected packet number
5103 0xBC, 0x9A, 0x78, 0x56,
5104 0x34, 0x12, 0x00, 0x00,
5105 // client address
5106 0x02, 0x00,
5107 0x7F, 0x00, 0x00, 0x01,
5108 0x34, 0x12,
5109 };
5110
5111 unsigned char packet_no_rejected_packet_number[] = {
5112 // public flags (public reset, 8 byte ConnectionId) 6525 // public flags (public reset, 8 byte ConnectionId)
5113 0x0A, 6526 0x0A,
5114 // connection_id 6527 // connection_id
5115 0x10, 0x32, 0x54, 0x76, 6528 0x10, 0x32, 0x54, 0x76,
5116 0x98, 0xBA, 0xDC, 0xFE, 6529 0x98, 0xBA, 0xDC, 0xFE,
5117 // message tag (kPRST) 6530 // message tag (kPRST)
5118 'P', 'R', 'S', 'T', 6531 'P', 'R', 'S', 'T',
5119 // num_entries (2) + padding 6532 // num_entries (2) + padding
5120 0x02, 0x00, 0x00, 0x00, 6533 0x02, 0x00, 0x00, 0x00,
5121 // tag kRNON 6534 // tag kRNON
5122 'R', 'N', 'O', 'N', 6535 'R', 'N', 'O', 'N',
5123 // end offset 8 6536 // end offset 8
5124 0x08, 0x00, 0x00, 0x00, 6537 0x08, 0x00, 0x00, 0x00,
5125 // tag kCADR 6538 // tag kCADR
5126 'C', 'A', 'D', 'R', 6539 'C', 'A', 'D', 'R',
5127 // end offset 16 6540 // end offset 16
5128 0x10, 0x00, 0x00, 0x00, 6541 0x10, 0x00, 0x00, 0x00,
5129 // nonce proof 6542 // nonce proof
5130 0x89, 0x67, 0x45, 0x23, 6543 0x89, 0x67, 0x45, 0x23,
5131 0x01, 0xEF, 0xCD, 0xAB, 6544 0x01, 0xEF, 0xCD, 0xAB,
5132 // client address 6545 // client address
5133 0x02, 0x00, 6546 0x02, 0x00,
5134 0x7F, 0x00, 0x00, 0x01, 6547 0x7F, 0x00, 0x00, 0x01,
5135 0x34, 0x12, 6548 0x34, 0x12,
5136 }; 6549 };
5137 6550
5138 unsigned char packet_no_rejected_packet_number_cid_be[] = { 6551 unsigned char packet_cid_be[] = {
5139 // public flags (public reset, 8 byte ConnectionId) 6552 // public flags (public reset, 8 byte ConnectionId)
5140 0x0A, 6553 0x0A,
5141 // connection_id 6554 // connection_id
5142 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 6555 0xFE, 0xDC, 0xBA, 0x98,
6556 0x76, 0x54, 0x32, 0x10,
5143 // message tag (kPRST) 6557 // message tag (kPRST)
5144 'P', 'R', 'S', 'T', 6558 'P', 'R', 'S', 'T',
5145 // num_entries (2) + padding 6559 // num_entries (2) + padding
5146 0x02, 0x00, 0x00, 0x00, 6560 0x02, 0x00, 0x00, 0x00,
5147 // tag kRNON 6561 // tag kRNON
5148 'R', 'N', 'O', 'N', 6562 'R', 'N', 'O', 'N',
5149 // end offset 8 6563 // end offset 8
5150 0x08, 0x00, 0x00, 0x00, 6564 0x08, 0x00, 0x00, 0x00,
5151 // tag kCADR 6565 // tag kCADR
5152 'C', 'A', 'D', 'R', 6566 'C', 'A', 'D', 'R',
5153 // end offset 16 6567 // end offset 16
5154 0x10, 0x00, 0x00, 0x00, 6568 0x10, 0x00, 0x00, 0x00,
5155 // nonce proof 6569 // nonce proof
5156 0x89, 0x67, 0x45, 0x23, 6570 0x89, 0x67, 0x45, 0x23,
5157 0x01, 0xEF, 0xCD, 0xAB, 6571 0x01, 0xEF, 0xCD, 0xAB,
5158 // client address 6572 // client address
5159 0x02, 0x00, 6573 0x02, 0x00,
5160 0x7F, 0x00, 0x00, 0x01, 6574 0x7F, 0x00, 0x00, 0x01,
5161 0x34, 0x12, 6575 0x34, 0x12,
5162 }; 6576 };
5163 // clang-format on 6577 // clang-format on
5164 6578
5165 std::unique_ptr<QuicEncryptedPacket> data( 6579 std::unique_ptr<QuicEncryptedPacket> data(
5166 framer_.BuildPublicResetPacket(reset_packet)); 6580 framer_.BuildPublicResetPacket(reset_packet));
5167 ASSERT_TRUE(data != nullptr); 6581 ASSERT_TRUE(data != nullptr);
5168 6582
5169 if (FLAGS_quic_reloadable_flag_quic_remove_packet_number_from_public_reset) { 6583 test::CompareCharArraysWithHexError(
5170 test::CompareCharArraysWithHexError( 6584 "constructed packet", data->data(), data->length(),
5171 "constructed packet", data->data(), data->length(), 6585 AsChars(
5172 AsChars( 6586 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
5173 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 6587 ? packet_cid_be
5174 ? packet_no_rejected_packet_number_cid_be 6588 : packet),
5175 : packet_no_rejected_packet_number),
5176 6589
5177 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 6590 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
5178 ? arraysize(packet_no_rejected_packet_number_cid_be) 6591 ? arraysize(packet_cid_be)
5179 : arraysize(packet_no_rejected_packet_number)); 6592 : arraysize(packet));
5180 } else {
5181 test::CompareCharArraysWithHexError(
5182 "constructed packet", data->data(), data->length(),
5183 AsChars(
5184 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
5185 ? packet_cid_be
5186 : packet),
5187
5188 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
5189 ? arraysize(packet_cid_be)
5190 : arraysize(packet));
5191 }
5192 } 6593 }
5193 6594
5194 TEST_P(QuicFramerTest, EncryptPacket) { 6595 TEST_P(QuicFramerTest, EncryptPacket) {
5195 QuicPacketNumber packet_number = kPacketNumber; 6596 QuicPacketNumber packet_number = kPacketNumber;
5196 // clang-format off 6597 // clang-format off
5197 unsigned char packet[] = { 6598 unsigned char packet[] = {
5198 // public flags (8 byte connection_id) 6599 // public flags (8 byte connection_id)
5199 0x38, 6600 0x38,
5200 // connection_id 6601 // connection_id
5201 0x10, 0x32, 0x54, 0x76, 6602 0x10, 0x32, 0x54, 0x76,
(...skipping 17 matching lines...) Expand all
5219 // packet number 6620 // packet number
5220 0xBC, 0x9A, 0x78, 0x56, 6621 0xBC, 0x9A, 0x78, 0x56,
5221 0x34, 0x12, 6622 0x34, 0x12,
5222 6623
5223 // redundancy 6624 // redundancy
5224 'a', 'b', 'c', 'd', 6625 'a', 'b', 'c', 'd',
5225 'e', 'f', 'g', 'h', 6626 'e', 'f', 'g', 'h',
5226 'i', 'j', 'k', 'l', 6627 'i', 'j', 'k', 'l',
5227 'm', 'n', 'o', 'p', 6628 'm', 'n', 'o', 'p',
5228 }; 6629 };
6630
6631 unsigned char packet39[] = {
6632 // public flags (8 byte connection_id)
6633 0x38,
6634 // connection_id
6635 0x10, 0x32, 0x54, 0x76,
6636 0x98, 0xBA, 0xDC, 0xFE,
6637 // packet number
6638 0x12, 0x34, 0x56, 0x78,
6639 0x9A, 0xBC,
6640
6641 // redundancy
6642 'a', 'b', 'c', 'd',
6643 'e', 'f', 'g', 'h',
6644 'i', 'j', 'k', 'l',
6645 'm', 'n', 'o', 'p',
6646 };
6647
6648 unsigned char packet_cid_be39[] = {
6649 // public flags (8 byte connection_id)
6650 0x38,
6651 // connection_id
6652 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
6653 // packet number
6654 0x12, 0x34, 0x56, 0x78,
6655 0x9A, 0xBC,
6656
6657 // redundancy
6658 'a', 'b', 'c', 'd',
6659 'e', 'f', 'g', 'h',
6660 'i', 'j', 'k', 'l',
6661 'm', 'n', 'o', 'p',
6662 };
5229 // clang-format on 6663 // clang-format on
6664 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
6665 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
5230 6666
5231 std::unique_ptr<QuicPacket> raw(new QuicPacket( 6667 std::unique_ptr<QuicPacket> raw(new QuicPacket(
5232 AsChars( 6668 AsChars(packets[index]), arraysize(packet), false,
5233 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 6669 PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
5234 ? packet_cid_be
5235 : packet),
5236 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
5237 ? arraysize(packet_cid_be)
5238 : arraysize(packet),
5239 false, PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
5240 !kIncludeDiversificationNonce, PACKET_6BYTE_PACKET_NUMBER)); 6670 !kIncludeDiversificationNonce, PACKET_6BYTE_PACKET_NUMBER));
5241 char buffer[kMaxPacketSize]; 6671 char buffer[kMaxPacketSize];
5242 size_t encrypted_length = framer_.EncryptPayload( 6672 size_t encrypted_length = framer_.EncryptPayload(
5243 ENCRYPTION_NONE, packet_number, *raw, buffer, kMaxPacketSize); 6673 ENCRYPTION_NONE, packet_number, *raw, buffer, kMaxPacketSize);
5244 6674
5245 ASSERT_NE(0u, encrypted_length); 6675 ASSERT_NE(0u, encrypted_length);
5246 EXPECT_TRUE(CheckEncryption(packet_number, raw.get())); 6676 EXPECT_TRUE(CheckEncryption(packet_number, raw.get()));
5247 } 6677 }
5248 6678
5249 TEST_P(QuicFramerTest, EncryptPacketWithVersionFlag) { 6679 TEST_P(QuicFramerTest, EncryptPacketWithVersionFlag) {
(...skipping 28 matching lines...) Expand all
5278 // packet number 6708 // packet number
5279 0xBC, 0x9A, 0x78, 0x56, 6709 0xBC, 0x9A, 0x78, 0x56,
5280 0x34, 0x12, 6710 0x34, 0x12,
5281 6711
5282 // redundancy 6712 // redundancy
5283 'a', 'b', 'c', 'd', 6713 'a', 'b', 'c', 'd',
5284 'e', 'f', 'g', 'h', 6714 'e', 'f', 'g', 'h',
5285 'i', 'j', 'k', 'l', 6715 'i', 'j', 'k', 'l',
5286 'm', 'n', 'o', 'p', 6716 'm', 'n', 'o', 'p',
5287 }; 6717 };
6718
6719 unsigned char packet39[] = {
6720 // public flags (version, 8 byte connection_id)
6721 0x39,
6722 // connection_id
6723 0x10, 0x32, 0x54, 0x76,
6724 0x98, 0xBA, 0xDC, 0xFE,
6725 // version tag
6726 'Q', '.', '1', '0',
6727 // packet number
6728 0x12, 0x34, 0x56, 0x78,
6729 0x9A, 0xBC,
6730
6731 // redundancy
6732 'a', 'b', 'c', 'd',
6733 'e', 'f', 'g', 'h',
6734 'i', 'j', 'k', 'l',
6735 'm', 'n', 'o', 'p',
6736 };
6737
6738 unsigned char packet_cid_be39[] = {
6739 // public flags (version, 8 byte connection_id)
6740 0x39,
6741 // connection_id
6742 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
6743 // version tag
6744 'Q', '.', '1', '0',
6745 // packet number
6746 0x12, 0x34, 0x56, 0x78,
6747 0x9A, 0xBC,
6748
6749 // redundancy
6750 'a', 'b', 'c', 'd',
6751 'e', 'f', 'g', 'h',
6752 'i', 'j', 'k', 'l',
6753 'm', 'n', 'o', 'p',
6754 };
5288 // clang-format on 6755 // clang-format on
5289 6756
6757 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
6758 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
6759
5290 std::unique_ptr<QuicPacket> raw(new QuicPacket( 6760 std::unique_ptr<QuicPacket> raw(new QuicPacket(
5291 AsChars( 6761 AsChars(packets[index]), arraysize(packet), false,
5292 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 6762 PACKET_8BYTE_CONNECTION_ID, kIncludeVersion,
5293 ? packet_cid_be
5294 : packet),
5295 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
5296 ? arraysize(packet_cid_be)
5297 : arraysize(packet),
5298 false, PACKET_8BYTE_CONNECTION_ID, kIncludeVersion,
5299 !kIncludeDiversificationNonce, PACKET_6BYTE_PACKET_NUMBER)); 6763 !kIncludeDiversificationNonce, PACKET_6BYTE_PACKET_NUMBER));
5300 char buffer[kMaxPacketSize]; 6764 char buffer[kMaxPacketSize];
5301 size_t encrypted_length = framer_.EncryptPayload( 6765 size_t encrypted_length = framer_.EncryptPayload(
5302 ENCRYPTION_NONE, packet_number, *raw, buffer, kMaxPacketSize); 6766 ENCRYPTION_NONE, packet_number, *raw, buffer, kMaxPacketSize);
5303 6767
5304 ASSERT_NE(0u, encrypted_length); 6768 ASSERT_NE(0u, encrypted_length);
5305 EXPECT_TRUE(CheckEncryption(packet_number, raw.get())); 6769 EXPECT_TRUE(CheckEncryption(packet_number, raw.get()));
5306 } 6770 }
5307 6771
5308 TEST_P(QuicFramerTest, AckTruncationLargePacket) { 6772 TEST_P(QuicFramerTest, AckTruncationLargePacket) {
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
5478 0x34, 0x12, 6942 0x34, 0x12,
5479 // largest observed packet number 6943 // largest observed packet number
5480 0xBF, 0x9A, 0x78, 0x56, 6944 0xBF, 0x9A, 0x78, 0x56,
5481 0x34, 0x12, 6945 0x34, 0x12,
5482 // num missing packets 6946 // num missing packets
5483 0x01, 6947 0x01,
5484 // missing packet 6948 // missing packet
5485 0xBE, 0x9A, 0x78, 0x56, 6949 0xBE, 0x9A, 0x78, 0x56,
5486 0x34, 0x12, 6950 0x34, 0x12,
5487 }; 6951 };
6952
6953 unsigned char packet39[] = {
6954 // public flags (8 byte connection_id)
6955 0x38,
6956 // connection_id
6957 0x10, 0x32, 0x54, 0x76,
6958 0x98, 0xBA, 0xDC, 0xFE,
6959 // packet number
6960 0x12, 0x34, 0x56, 0x78,
6961 0x9A, 0xBC,
6962
6963 // frame type (stream frame with fin)
6964 0xFF,
6965 // stream id
6966 0x01, 0x02, 0x03, 0x04,
6967 // offset
6968 0xBA, 0x98, 0xFE, 0xDC,
6969 0x32, 0x10, 0x76, 0x54,
6970 // data length
6971 0x00, 0x0c,
6972 // data
6973 'h', 'e', 'l', 'l',
6974 'o', ' ', 'w', 'o',
6975 'r', 'l', 'd', '!',
6976
6977 // frame type (ack frame)
6978 0x40,
6979 // least packet number awaiting an ack
6980 0x12, 0x34, 0x56, 0x78,
6981 0x9A, 0xA0,
6982 // largest observed packet number
6983 0x12, 0x34, 0x56, 0x78,
6984 0x9A, 0xBF,
6985 // num missing packets
6986 0x01,
6987 // missing packet
6988 0x12, 0x34, 0x56, 0x78,
6989 0x9A, 0xBE,
6990 };
6991
6992 unsigned char packet_cid_be39[] = {
6993 // public flags (8 byte connection_id)
6994 0x38,
6995 // connection_id
6996 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
6997 // packet number
6998 0x12, 0x34, 0x56, 0x78,
6999 0x9A, 0xBC,
7000
7001 // frame type (stream frame with fin)
7002 0xFF,
7003 // stream id
7004 0x01, 0x02, 0x03, 0x04,
7005 // offset
7006 0xBA, 0x98, 0xFE, 0xDC,
7007 0x32, 0x10, 0x76, 0x54,
7008 // data length
7009 0x00, 0x0c,
7010 // data
7011 'h', 'e', 'l', 'l',
7012 'o', ' ', 'w', 'o',
7013 'r', 'l', 'd', '!',
7014
7015 // frame type (ack frame)
7016 0x40,
7017 // least packet number awaiting an ack
7018 0x12, 0x34, 0x56, 0x78,
7019 0x9A, 0xA0,
7020 // largest observed packet number
7021 0x12, 0x34, 0x56, 0x78,
7022 0x9A, 0xBF,
7023 // num missing packets
7024 0x01,
7025 // missing packet
7026 0x12, 0x34, 0x56, 0x78,
7027 0x9A, 0xBE,
7028 };
5488 // clang-format on 7029 // clang-format on
5489 7030
7031 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
7032 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
7033
5490 MockFramerVisitor visitor; 7034 MockFramerVisitor visitor;
5491 framer_.set_visitor(&visitor); 7035 framer_.set_visitor(&visitor);
5492 EXPECT_CALL(visitor, OnPacket()); 7036 EXPECT_CALL(visitor, OnPacket());
5493 EXPECT_CALL(visitor, OnPacketHeader(_)); 7037 EXPECT_CALL(visitor, OnPacketHeader(_));
5494 EXPECT_CALL(visitor, OnStreamFrame(_)).WillOnce(Return(false)); 7038 EXPECT_CALL(visitor, OnStreamFrame(_)).WillOnce(Return(false));
5495 EXPECT_CALL(visitor, OnAckFrame(_)).Times(0); 7039 EXPECT_CALL(visitor, OnAckFrame(_)).Times(0);
5496 EXPECT_CALL(visitor, OnPacketComplete()); 7040 EXPECT_CALL(visitor, OnPacketComplete());
5497 EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)).WillOnce(Return(true)); 7041 EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)).WillOnce(Return(true));
5498 EXPECT_CALL(visitor, OnUnauthenticatedHeader(_)).WillOnce(Return(true)); 7042 EXPECT_CALL(visitor, OnUnauthenticatedHeader(_)).WillOnce(Return(true));
5499 EXPECT_CALL(visitor, OnDecryptedPacket(_)); 7043 EXPECT_CALL(visitor, OnDecryptedPacket(_));
5500 7044
5501 QuicEncryptedPacket encrypted( 7045 QuicEncryptedPacket encrypted(AsChars(packets[index]), arraysize(packet),
5502 AsChars( 7046 false);
5503 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
5504 ? packet_cid_be
5505 : packet),
5506 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
5507 ? arraysize(packet_cid_be)
5508 : arraysize(packet),
5509 false);
5510 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 7047 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
5511 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 7048 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
5512 } 7049 }
5513 7050
5514 static char kTestString[] = "At least 20 characters."; 7051 static char kTestString[] = "At least 20 characters.";
5515 static QuicStreamId kTestQuicStreamId = 1; 7052 static QuicStreamId kTestQuicStreamId = 1;
5516 static bool ExpectedStreamFrame(const QuicStreamFrame& frame) { 7053 static bool ExpectedStreamFrame(const QuicStreamFrame& frame) {
5517 return frame.stream_id == kTestQuicStreamId && !frame.fin && 7054 return frame.stream_id == kTestQuicStreamId && !frame.fin &&
5518 frame.offset == 0 && 7055 frame.offset == 0 &&
5519 string(frame.data_buffer, frame.data_length) == kTestString; 7056 string(frame.data_buffer, frame.data_length) == kTestString;
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
5668 // offset 7205 // offset
5669 0x54, 0x76, 0x10, 0x32, 7206 0x54, 0x76, 0x10, 0x32,
5670 0xDC, 0xFE, 0x98, 0xBA, 7207 0xDC, 0xFE, 0x98, 0xBA,
5671 // data length 7208 // data length
5672 0x0c, 0x00, 7209 0x0c, 0x00,
5673 // data 7210 // data
5674 'h', 'e', 'l', 'l', 7211 'h', 'e', 'l', 'l',
5675 'o', ' ', 'w', 'o', 7212 'o', ' ', 'w', 'o',
5676 'r', 'l', 'd', '!', 7213 'r', 'l', 'd', '!',
5677 }; 7214 };
7215
7216 unsigned char packet39[] = {
7217 // public flags (8 byte connection_id)
7218 0x3C,
7219 // connection_id
7220 0x10, 0x32, 0x54, 0x76,
7221 0x98, 0xBA, 0xDC, 0xFE,
7222 // packet number
7223 0x12, 0x34, 0x56, 0x78,
7224 0x9A, 0xBC,
7225 // private flags
7226 0x00,
7227
7228 // frame type (stream frame with fin)
7229 0xFF,
7230 // stream id
7231 0x01, 0x02, 0x03, 0x04,
7232 // offset
7233 0xBA, 0x98, 0xFE, 0xDC,
7234 0x32, 0x10, 0x76, 0x54,
7235 // data length
7236 0x00, 0x0c,
7237 // data
7238 'h', 'e', 'l', 'l',
7239 'o', ' ', 'w', 'o',
7240 'r', 'l', 'd', '!',
7241 };
7242
7243 unsigned char packet_cid_be39[] = {
7244 // public flags (8 byte connection_id)
7245 0x3C,
7246 // connection_id
7247 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
7248 // packet number
7249 0x12, 0x34, 0x56, 0x78,
7250 0x9A, 0xBC,
7251 // private flags
7252 0x00,
7253
7254 // frame type (stream frame with fin)
7255 0xFF,
7256 // stream id
7257 0x01, 0x02, 0x03, 0x04,
7258 // offset
7259 0xBA, 0x98, 0xFE, 0xDC,
7260 0x32, 0x10, 0x76, 0x54,
7261 // data length
7262 0x00, 0x0c,
7263 // data
7264 'h', 'e', 'l', 'l',
7265 'o', ' ', 'w', 'o',
7266 'r', 'l', 'd', '!',
7267 };
5678 // clang-format on 7268 // clang-format on
5679 7269
5680 QuicFramerFuzzFunc( 7270 unsigned char* packets[] = {packet, packet_cid_be, packet39, packet_cid_be39};
5681 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) 7271 size_t index = GetPacketIndex(framer_.version(), framer_.perspective());
5682 ? packet_cid_be 7272
5683 : packet, 7273 QuicFramerFuzzFunc(packets[index], arraysize(packet));
5684 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())
5685 ? arraysize(packet_cid_be)
5686 : arraysize(packet));
5687 } 7274 }
5688 7275
7276 } // namespace
5689 } // namespace test 7277 } // namespace test
5690 } // namespace net 7278 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/quic_framer.cc ('k') | net/quic/core/quic_packet_creator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698