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

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

Issue 2759203003: Landing Recent QUIC changes until Thu Mar 16 17:24:53 2017 +0000 (Closed)
Patch Set: float Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/core/quic_framer.cc ('k') | no next file » | 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 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 unsigned char packet[kMaxPacketSize + 1] = { 564 unsigned char packet[kMaxPacketSize + 1] = {
565 // public flags (8 byte connection_id) 565 // public flags (8 byte connection_id)
566 0x38, 566 0x38,
567 // connection_id 567 // connection_id
568 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, 568 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
569 // packet number 569 // packet number
570 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, 570 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
571 // private flags 571 // private flags
572 0x00, 572 0x00,
573 }; 573 };
574
575 unsigned char packet_cid_be[kMaxPacketSize + 1] = {
576 // public flags (8 byte connection_id)
577 0x38,
578 // connection_id
579 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
580 // packet number
581 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
582 // private flags
583 0x00,
584 };
574 // clang-format on 585 // clang-format on
575 586
576 const size_t header_size = GetPacketHeaderSize( 587 const size_t header_size = GetPacketHeaderSize(
577 framer_.version(), PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 588 framer_.version(), PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
578 !kIncludeDiversificationNonce, PACKET_6BYTE_PACKET_NUMBER); 589 !kIncludeDiversificationNonce, PACKET_6BYTE_PACKET_NUMBER);
579 590
580 memset(packet + header_size, 0, kMaxPacketSize - header_size); 591 memset(packet + header_size, 0, kMaxPacketSize - header_size);
581 592
582 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 593 QuicEncryptedPacket encrypted(
594 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
595 ? packet_cid_be
596 : packet),
597 FLAGS_quic_restart_flag_quic_big_endian_connection_id
598 ? arraysize(packet_cid_be)
599 : arraysize(packet),
600 false);
583 EXPECT_QUIC_BUG(framer_.ProcessPacket(encrypted), "Packet too large:1"); 601 EXPECT_QUIC_BUG(framer_.ProcessPacket(encrypted), "Packet too large:1");
584 602
585 ASSERT_TRUE(visitor_.header_.get()); 603 ASSERT_TRUE(visitor_.header_.get());
586 // Make sure we've parsed the packet header, so we can send an error. 604 // Make sure we've parsed the packet header, so we can send an error.
587 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); 605 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id);
588 // Make sure the correct error is propagated. 606 // Make sure the correct error is propagated.
589 EXPECT_EQ(QUIC_PACKET_TOO_LARGE, framer_.error()); 607 EXPECT_EQ(QUIC_PACKET_TOO_LARGE, framer_.error());
590 } 608 }
591 609
592 TEST_P(QuicFramerTest, PacketHeader) { 610 TEST_P(QuicFramerTest, PacketHeader) {
593 // clang-format off 611 // clang-format off
594 unsigned char packet[] = { 612 unsigned char packet[] = {
595 // public flags (8 byte connection_id) 613 // public flags (8 byte connection_id)
596 0x38, 614 0x38,
597 // connection_id 615 // connection_id
598 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, 616 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
599 // packet number 617 // packet number
600 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, 618 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
601 }; 619 };
620
621 unsigned char packet_cid_be[] = {
622 // public flags (8 byte connection_id)
623 0x38,
624 // connection_id
625 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
626 // packet number
627 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
628 };
602 // clang-format on 629 // clang-format on
603 630
604 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 631 QuicEncryptedPacket encrypted(
632 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
633 ? packet_cid_be
634 : packet),
635 FLAGS_quic_restart_flag_quic_big_endian_connection_id
636 ? arraysize(packet_cid_be)
637 : arraysize(packet),
638 false);
605 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); 639 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
606 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); 640 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
607 ASSERT_TRUE(visitor_.header_.get()); 641 ASSERT_TRUE(visitor_.header_.get());
608 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); 642 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id);
609 EXPECT_FALSE(visitor_.header_->public_header.multipath_flag); 643 EXPECT_FALSE(visitor_.header_->public_header.multipath_flag);
610 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); 644 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
611 EXPECT_FALSE(visitor_.header_->public_header.version_flag); 645 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
612 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); 646 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number);
613 647
614 // Now test framing boundaries. 648 // Now test framing boundaries.
615 for (size_t i = 0; 649 for (size_t i = 0;
616 i < GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, 650 i < GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID,
617 !kIncludeVersion, !kIncludeDiversificationNonce, 651 !kIncludeVersion, !kIncludeDiversificationNonce,
618 PACKET_6BYTE_PACKET_NUMBER); 652 PACKET_6BYTE_PACKET_NUMBER);
619 ++i) { 653 ++i) {
620 string expected_error; 654 string expected_error;
621 if (i < kConnectionIdOffset) { 655 if (i < kConnectionIdOffset) {
622 expected_error = "Unable to read public flags."; 656 expected_error = "Unable to read public flags.";
623 } else if (i < GetPacketNumberOffset(!kIncludeVersion)) { 657 } else if (i < GetPacketNumberOffset(!kIncludeVersion)) {
624 expected_error = "Unable to read ConnectionId."; 658 expected_error = "Unable to read ConnectionId.";
625 } else { 659 } else {
626 expected_error = "Unable to read packet number."; 660 expected_error = "Unable to read packet number.";
627 } 661 }
628 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER); 662 CheckProcessingFails(FLAGS_quic_restart_flag_quic_big_endian_connection_id
663 ? packet_cid_be
664 : packet,
665 i, expected_error, QUIC_INVALID_PACKET_HEADER);
629 } 666 }
630 } 667 }
631 668
632 TEST_P(QuicFramerTest, PacketHeaderWith0ByteConnectionId) { 669 TEST_P(QuicFramerTest, PacketHeaderWith0ByteConnectionId) {
633 QuicFramerPeer::SetLastSerializedConnectionId(&framer_, kConnectionId); 670 QuicFramerPeer::SetLastSerializedConnectionId(&framer_, kConnectionId);
634 671
635 // clang-format off 672 // clang-format off
636 unsigned char packet[] = { 673 unsigned char packet[] = {
637 // public flags (0 byte connection_id) 674 // public flags (0 byte connection_id)
638 0x30, 675 0x30,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 unsigned char packet[] = { 714 unsigned char packet[] = {
678 // public flags (version) 715 // public flags (version)
679 0x39, 716 0x39,
680 // connection_id 717 // connection_id
681 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, 718 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
682 // version tag 719 // version tag
683 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), 720 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
684 // packet number 721 // packet number
685 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, 722 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
686 }; 723 };
724
725 unsigned char packet_cid_be[] = {
726 // public flags (version)
727 0x39,
728 // connection_id
729 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
730 // version tag
731 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
732 // packet number
733 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
734 };
687 // clang-format on 735 // clang-format on
688 736
689 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 737 QuicEncryptedPacket encrypted(
738 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
739 ? packet_cid_be
740 : packet),
741 FLAGS_quic_restart_flag_quic_big_endian_connection_id
742 ? arraysize(packet_cid_be)
743 : arraysize(packet),
744 false);
690 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); 745 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
691 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); 746 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
692 ASSERT_TRUE(visitor_.header_.get()); 747 ASSERT_TRUE(visitor_.header_.get());
693 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); 748 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id);
694 EXPECT_FALSE(visitor_.header_->public_header.multipath_flag); 749 EXPECT_FALSE(visitor_.header_->public_header.multipath_flag);
695 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); 750 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
696 EXPECT_TRUE(visitor_.header_->public_header.version_flag); 751 EXPECT_TRUE(visitor_.header_->public_header.version_flag);
697 EXPECT_EQ(GetParam(), visitor_.header_->public_header.versions[0]); 752 EXPECT_EQ(GetParam(), visitor_.header_->public_header.versions[0]);
698 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); 753 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number);
699 754
700 // Now test framing boundaries. 755 // Now test framing boundaries.
701 for (size_t i = 0; 756 for (size_t i = 0;
702 i < GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, 757 i < GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID,
703 kIncludeVersion, !kIncludeDiversificationNonce, 758 kIncludeVersion, !kIncludeDiversificationNonce,
704 PACKET_6BYTE_PACKET_NUMBER); 759 PACKET_6BYTE_PACKET_NUMBER);
705 ++i) { 760 ++i) {
706 string expected_error; 761 string expected_error;
707 if (i < kConnectionIdOffset) { 762 if (i < kConnectionIdOffset) {
708 expected_error = "Unable to read public flags."; 763 expected_error = "Unable to read public flags.";
709 } else if (i < kVersionOffset) { 764 } else if (i < kVersionOffset) {
710 expected_error = "Unable to read ConnectionId."; 765 expected_error = "Unable to read ConnectionId.";
711 } else if (i < GetPacketNumberOffset(kIncludeVersion)) { 766 } else if (i < GetPacketNumberOffset(kIncludeVersion)) {
712 expected_error = "Unable to read protocol version."; 767 expected_error = "Unable to read protocol version.";
713 } else { 768 } else {
714 expected_error = "Unable to read packet number."; 769 expected_error = "Unable to read packet number.";
715 } 770 }
716 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER); 771 CheckProcessingFails(FLAGS_quic_restart_flag_quic_big_endian_connection_id
772 ? packet_cid_be
773 : packet,
774 i, expected_error, QUIC_INVALID_PACKET_HEADER);
717 } 775 }
718 } 776 }
719 777
720 TEST_P(QuicFramerTest, PacketHeaderWith4BytePacketNumber) { 778 TEST_P(QuicFramerTest, PacketHeaderWith4BytePacketNumber) {
721 QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2); 779 QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2);
722 780
723 // clang-format off 781 // clang-format off
724 unsigned char packet[] = { 782 unsigned char packet[] = {
725 // public flags (8 byte connection_id and 4 byte packet number) 783 // public flags (8 byte connection_id and 4 byte packet number)
726 0x28, 784 0x28,
727 // connection_id 785 // connection_id
728 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, 786 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
729 // packet number 787 // packet number
730 0xBC, 0x9A, 0x78, 0x56, 788 0xBC, 0x9A, 0x78, 0x56,
731 }; 789 };
790
791 unsigned char packet_cid_be[] = {
792 // public flags (8 byte connection_id and 4 byte packet number)
793 0x28,
794 // connection_id
795 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
796 // packet number
797 0xBC, 0x9A, 0x78, 0x56,
798 };
732 // clang-format on 799 // clang-format on
733 800
734 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 801 QuicEncryptedPacket encrypted(
802 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
803 ? packet_cid_be
804 : packet),
805 FLAGS_quic_restart_flag_quic_big_endian_connection_id
806 ? arraysize(packet_cid_be)
807 : arraysize(packet),
808 false);
735 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); 809 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
736 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); 810 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
737 ASSERT_TRUE(visitor_.header_.get()); 811 ASSERT_TRUE(visitor_.header_.get());
738 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); 812 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id);
739 EXPECT_FALSE(visitor_.header_->public_header.multipath_flag); 813 EXPECT_FALSE(visitor_.header_->public_header.multipath_flag);
740 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); 814 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
741 EXPECT_FALSE(visitor_.header_->public_header.version_flag); 815 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
742 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); 816 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number);
743 817
744 // Now test framing boundaries. 818 // Now test framing boundaries.
745 for (size_t i = 0; 819 for (size_t i = 0;
746 i < GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, 820 i < GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID,
747 !kIncludeVersion, !kIncludeDiversificationNonce, 821 !kIncludeVersion, !kIncludeDiversificationNonce,
748 PACKET_4BYTE_PACKET_NUMBER); 822 PACKET_4BYTE_PACKET_NUMBER);
749 ++i) { 823 ++i) {
750 string expected_error; 824 string expected_error;
751 if (i < kConnectionIdOffset) { 825 if (i < kConnectionIdOffset) {
752 expected_error = "Unable to read public flags."; 826 expected_error = "Unable to read public flags.";
753 } else if (i < GetPacketNumberOffset(!kIncludeVersion)) { 827 } else if (i < GetPacketNumberOffset(!kIncludeVersion)) {
754 expected_error = "Unable to read ConnectionId."; 828 expected_error = "Unable to read ConnectionId.";
755 } else { 829 } else {
756 expected_error = "Unable to read packet number."; 830 expected_error = "Unable to read packet number.";
757 } 831 }
758 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER); 832 CheckProcessingFails(FLAGS_quic_restart_flag_quic_big_endian_connection_id
833 ? packet_cid_be
834 : packet,
835 i, expected_error, QUIC_INVALID_PACKET_HEADER);
759 } 836 }
760 } 837 }
761 838
762 TEST_P(QuicFramerTest, PacketHeaderWith2BytePacketNumber) { 839 TEST_P(QuicFramerTest, PacketHeaderWith2BytePacketNumber) {
763 QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2); 840 QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2);
764 841
765 // clang-format off 842 // clang-format off
766 unsigned char packet[] = { 843 unsigned char packet[] = {
767 // public flags (8 byte connection_id and 2 byte packet number) 844 // public flags (8 byte connection_id and 2 byte packet number)
768 0x18, 845 0x18,
769 // connection_id 846 // connection_id
770 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, 847 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
771 // packet number 848 // packet number
772 0xBC, 0x9A, 849 0xBC, 0x9A,
773 }; 850 };
851
852 unsigned char packet_cid_be[] = {
853 // public flags (8 byte connection_id and 2 byte packet number)
854 0x18,
855 // connection_id
856 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
857 // packet number
858 0xBC, 0x9A,
859 };
774 // clang-format on 860 // clang-format on
775 861
776 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 862 QuicEncryptedPacket encrypted(
863 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
864 ? packet_cid_be
865 : packet),
866 FLAGS_quic_restart_flag_quic_big_endian_connection_id
867 ? arraysize(packet_cid_be)
868 : arraysize(packet),
869 false);
777 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); 870 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
778 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); 871 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
779 ASSERT_TRUE(visitor_.header_.get()); 872 ASSERT_TRUE(visitor_.header_.get());
780 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); 873 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id);
781 EXPECT_FALSE(visitor_.header_->public_header.multipath_flag); 874 EXPECT_FALSE(visitor_.header_->public_header.multipath_flag);
782 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); 875 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
783 EXPECT_FALSE(visitor_.header_->public_header.version_flag); 876 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
784 EXPECT_EQ(PACKET_2BYTE_PACKET_NUMBER, 877 EXPECT_EQ(PACKET_2BYTE_PACKET_NUMBER,
785 visitor_.header_->public_header.packet_number_length); 878 visitor_.header_->public_header.packet_number_length);
786 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); 879 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number);
787 880
788 // Now test framing boundaries. 881 // Now test framing boundaries.
789 for (size_t i = 0; 882 for (size_t i = 0;
790 i < GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, 883 i < GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID,
791 !kIncludeVersion, !kIncludeDiversificationNonce, 884 !kIncludeVersion, !kIncludeDiversificationNonce,
792 PACKET_2BYTE_PACKET_NUMBER); 885 PACKET_2BYTE_PACKET_NUMBER);
793 ++i) { 886 ++i) {
794 string expected_error; 887 string expected_error;
795 if (i < kConnectionIdOffset) { 888 if (i < kConnectionIdOffset) {
796 expected_error = "Unable to read public flags."; 889 expected_error = "Unable to read public flags.";
797 } else if (i < GetPacketNumberOffset(!kIncludeVersion)) { 890 } else if (i < GetPacketNumberOffset(!kIncludeVersion)) {
798 expected_error = "Unable to read ConnectionId."; 891 expected_error = "Unable to read ConnectionId.";
799 } else { 892 } else {
800 expected_error = "Unable to read packet number."; 893 expected_error = "Unable to read packet number.";
801 } 894 }
802 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER); 895 CheckProcessingFails(FLAGS_quic_restart_flag_quic_big_endian_connection_id
896 ? packet_cid_be
897 : packet,
898 i, expected_error, QUIC_INVALID_PACKET_HEADER);
803 } 899 }
804 } 900 }
805 901
806 TEST_P(QuicFramerTest, PacketHeaderWith1BytePacketNumber) { 902 TEST_P(QuicFramerTest, PacketHeaderWith1BytePacketNumber) {
807 QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2); 903 QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2);
808 904
809 // clang-format off 905 // clang-format off
810 unsigned char packet[] = { 906 unsigned char packet[] = {
811 // public flags (8 byte connection_id and 1 byte packet number) 907 // public flags (8 byte connection_id and 1 byte packet number)
812 0x08, 908 0x08,
813 // connection_id 909 // connection_id
814 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, 910 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
815 // packet number 911 // packet number
816 0xBC, 912 0xBC,
817 }; 913 };
914
915 unsigned char packet_cid_be[] = {
916 // public flags (8 byte connection_id and 1 byte packet number)
917 0x08,
918 // connection_id
919 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
920 // packet number
921 0xBC,
922 };
818 // clang-format on 923 // clang-format on
819 924
820 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 925 QuicEncryptedPacket encrypted(
926 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
927 ? packet_cid_be
928 : packet),
929 FLAGS_quic_restart_flag_quic_big_endian_connection_id
930 ? arraysize(packet_cid_be)
931 : arraysize(packet),
932 false);
821 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); 933 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
822 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); 934 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
823 ASSERT_TRUE(visitor_.header_.get()); 935 ASSERT_TRUE(visitor_.header_.get());
824 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); 936 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id);
825 EXPECT_FALSE(visitor_.header_->public_header.multipath_flag); 937 EXPECT_FALSE(visitor_.header_->public_header.multipath_flag);
826 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); 938 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
827 EXPECT_FALSE(visitor_.header_->public_header.version_flag); 939 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
828 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, 940 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER,
829 visitor_.header_->public_header.packet_number_length); 941 visitor_.header_->public_header.packet_number_length);
830 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); 942 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number);
831 943
832 // Now test framing boundaries. 944 // Now test framing boundaries.
833 for (size_t i = 0; 945 for (size_t i = 0;
834 i < GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, 946 i < GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID,
835 !kIncludeVersion, !kIncludeDiversificationNonce, 947 !kIncludeVersion, !kIncludeDiversificationNonce,
836 PACKET_1BYTE_PACKET_NUMBER); 948 PACKET_1BYTE_PACKET_NUMBER);
837 ++i) { 949 ++i) {
838 string expected_error; 950 string expected_error;
839 if (i < kConnectionIdOffset) { 951 if (i < kConnectionIdOffset) {
840 expected_error = "Unable to read public flags."; 952 expected_error = "Unable to read public flags.";
841 } else if (i < GetPacketNumberOffset(!kIncludeVersion)) { 953 } else if (i < GetPacketNumberOffset(!kIncludeVersion)) {
842 expected_error = "Unable to read ConnectionId."; 954 expected_error = "Unable to read ConnectionId.";
843 } else { 955 } else {
844 expected_error = "Unable to read packet number."; 956 expected_error = "Unable to read packet number.";
845 } 957 }
846 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER); 958 CheckProcessingFails(FLAGS_quic_restart_flag_quic_big_endian_connection_id
959 ? packet_cid_be
960 : packet,
961 i, expected_error, QUIC_INVALID_PACKET_HEADER);
847 } 962 }
848 } 963 }
849 964
850 TEST_P(QuicFramerTest, PacketNumberDecreasesThenIncreases) { 965 TEST_P(QuicFramerTest, PacketNumberDecreasesThenIncreases) {
851 // Test the case when a packet is received from the past and future packet 966 // Test the case when a packet is received from the past and future packet
852 // numbers are still calculated relative to the largest received packet. 967 // numbers are still calculated relative to the largest received packet.
853 QuicPacketHeader header; 968 QuicPacketHeader header;
854 header.public_header.connection_id = kConnectionId; 969 header.public_header.connection_id = kConnectionId;
855 header.public_header.reset_flag = false; 970 header.public_header.reset_flag = false;
856 header.public_header.version_flag = false; 971 header.public_header.version_flag = false;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 1033 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
919 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 1034 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
920 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 1035 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
921 // packet number 1036 // packet number
922 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, 1037 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
923 1038
924 // frame type (padding) 1039 // frame type (padding)
925 0x00, 1040 0x00,
926 0x00, 0x00, 0x00, 0x00 1041 0x00, 0x00, 0x00, 0x00
927 }; 1042 };
1043
1044 unsigned char packet_cid_be[] = {
1045 // public flags: includes nonce flag
1046 static_cast<unsigned char>(
1047 FLAGS_quic_reloadable_flag_quic_remove_multipath_bit ? 0x3C : 0x7C),
1048 // connection_id
1049 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
1050 // nonce
1051 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1052 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
1053 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
1054 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
1055 // packet number
1056 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
1057
1058 // frame type (padding)
1059 0x00,
1060 0x00, 0x00, 0x00, 0x00
1061 };
928 // clang-format on 1062 // clang-format on
929 1063
930 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1064 QuicEncryptedPacket encrypted(
1065 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
1066 ? packet_cid_be
1067 : packet),
1068 FLAGS_quic_restart_flag_quic_big_endian_connection_id
1069 ? arraysize(packet_cid_be)
1070 : arraysize(packet),
1071 false);
931 QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); 1072 QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT);
932 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1073 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
933 ASSERT_TRUE(visitor_.public_header_->nonce != nullptr); 1074 ASSERT_TRUE(visitor_.public_header_->nonce != nullptr);
934 for (char i = 0; i < 32; ++i) { 1075 for (char i = 0; i < 32; ++i) {
935 EXPECT_EQ(i, (*visitor_.public_header_->nonce)[static_cast<size_t>(i)]); 1076 EXPECT_EQ(i, (*visitor_.public_header_->nonce)[static_cast<size_t>(i)]);
936 } 1077 }
937 }; 1078 };
938 1079
939 TEST_P(QuicFramerTest, LargePublicFlagWithMismatchedVersions) { 1080 TEST_P(QuicFramerTest, LargePublicFlagWithMismatchedVersions) {
940 // clang-format off 1081 // clang-format off
941 unsigned char packet[] = { 1082 unsigned char packet[] = {
942 // public flags (8 byte connection_id, version flag and an unknown flag) 1083 // public flags (8 byte connection_id, version flag and an unknown flag)
943 static_cast<unsigned char>( 1084 static_cast<unsigned char>(
944 FLAGS_quic_reloadable_flag_quic_remove_multipath_bit ? 0x39 : 0x79), 1085 FLAGS_quic_reloadable_flag_quic_remove_multipath_bit ? 0x39 : 0x79),
945 // connection_id 1086 // connection_id
946 0x10, 0x32, 0x54, 0x76, 1087 0x10, 0x32, 0x54, 0x76,
947 0x98, 0xBA, 0xDC, 0xFE, 1088 0x98, 0xBA, 0xDC, 0xFE,
948 // version tag 1089 // version tag
949 'Q', '0', '0', '0', 1090 'Q', '0', '0', '0',
950 // packet number 1091 // packet number
951 0xBC, 0x9A, 0x78, 0x56, 1092 0xBC, 0x9A, 0x78, 0x56,
952 0x34, 0x12, 1093 0x34, 0x12,
953 1094
954 // frame type (padding frame) 1095 // frame type (padding frame)
955 0x00, 1096 0x00,
956 0x00, 0x00, 0x00, 0x00 1097 0x00, 0x00, 0x00, 0x00
957 }; 1098 };
1099
1100 unsigned char packet_cid_be[] = {
1101 // public flags (8 byte connection_id, version flag and an unknown flag)
1102 static_cast<unsigned char>(
1103 FLAGS_quic_reloadable_flag_quic_remove_multipath_bit ? 0x39 : 0x79),
1104 // connection_id
1105 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
1106 // version tag
1107 'Q', '0', '0', '0',
1108 // packet number
1109 0xBC, 0x9A, 0x78, 0x56,
1110 0x34, 0x12,
1111
1112 // frame type (padding frame)
1113 0x00,
1114 0x00, 0x00, 0x00, 0x00
1115 };
958 // clang-format on 1116 // clang-format on
959 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1117 QuicEncryptedPacket encrypted(
1118 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
1119 ? packet_cid_be
1120 : packet),
1121 FLAGS_quic_restart_flag_quic_big_endian_connection_id
1122 ? arraysize(packet_cid_be)
1123 : arraysize(packet),
1124 false);
960 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1125 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
961 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1126 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
962 ASSERT_TRUE(visitor_.header_.get()); 1127 ASSERT_TRUE(visitor_.header_.get());
963 EXPECT_EQ(0, visitor_.frame_count_); 1128 EXPECT_EQ(0, visitor_.frame_count_);
964 EXPECT_EQ(1, visitor_.version_mismatch_); 1129 EXPECT_EQ(1, visitor_.version_mismatch_);
965 }; 1130 };
966 1131
967 TEST_P(QuicFramerTest, PaddingFrame) { 1132 TEST_P(QuicFramerTest, PaddingFrame) {
968 // clang-format off 1133 // clang-format off
969 unsigned char packet[] = { 1134 unsigned char packet[] = {
(...skipping 16 matching lines...) Expand all
986 // offset 1151 // offset
987 0x54, 0x76, 0x10, 0x32, 1152 0x54, 0x76, 0x10, 0x32,
988 0xDC, 0xFE, 0x98, 0xBA, 1153 0xDC, 0xFE, 0x98, 0xBA,
989 // data length 1154 // data length
990 0x0c, 0x00, 1155 0x0c, 0x00,
991 // data 1156 // data
992 'h', 'e', 'l', 'l', 1157 'h', 'e', 'l', 'l',
993 'o', ' ', 'w', 'o', 1158 'o', ' ', 'w', 'o',
994 'r', 'l', 'd', '!', 1159 'r', 'l', 'd', '!',
995 }; 1160 };
1161
1162 unsigned char packet_cid_be[] = {
1163 // public flags (8 byte connection_id)
1164 0x38,
1165 // connection_id
1166 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
1167 // packet number
1168 0xBC, 0x9A, 0x78, 0x56,
1169 0x34, 0x12,
1170
1171 // frame type (padding frame)
1172 0x00,
1173 // Ignored data (which in this case is a stream frame)
1174 // frame type (stream frame with fin)
1175 0xFF,
1176 // stream id
1177 0x04, 0x03, 0x02, 0x01,
1178 // offset
1179 0x54, 0x76, 0x10, 0x32,
1180 0xDC, 0xFE, 0x98, 0xBA,
1181 // data length
1182 0x0c, 0x00,
1183 // data
1184 'h', 'e', 'l', 'l',
1185 'o', ' ', 'w', 'o',
1186 'r', 'l', 'd', '!',
1187 };
996 // clang-format on 1188 // clang-format on
997 1189
998 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1190 QuicEncryptedPacket encrypted(
1191 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
1192 ? packet_cid_be
1193 : packet),
1194 FLAGS_quic_restart_flag_quic_big_endian_connection_id
1195 ? arraysize(packet_cid_be)
1196 : arraysize(packet),
1197 false);
999 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1198 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1000 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1199 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1001 ASSERT_TRUE(visitor_.header_.get()); 1200 ASSERT_TRUE(visitor_.header_.get());
1002 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, 1201 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion,
1003 !kIncludeDiversificationNonce)); 1202 !kIncludeDiversificationNonce));
1004 1203
1005 ASSERT_EQ(0u, visitor_.stream_frames_.size()); 1204 ASSERT_EQ(0u, visitor_.stream_frames_.size());
1006 EXPECT_EQ(0u, visitor_.ack_frames_.size()); 1205 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1007 // A packet with no frames is not acceptable. 1206 // A packet with no frames is not acceptable.
1008 CheckProcessingFails( 1207 CheckProcessingFails(
1009 packet, 1208 FLAGS_quic_restart_flag_quic_big_endian_connection_id ? packet_cid_be
1209 : packet,
1010 GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, 1210 GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID,
1011 !kIncludeVersion, !kIncludeDiversificationNonce, 1211 !kIncludeVersion, !kIncludeDiversificationNonce,
1012 PACKET_6BYTE_PACKET_NUMBER), 1212 PACKET_6BYTE_PACKET_NUMBER),
1013 "Packet has no frames.", QUIC_MISSING_PAYLOAD); 1213 "Packet has no frames.", QUIC_MISSING_PAYLOAD);
1014 } 1214 }
1015 1215
1016 TEST_P(QuicFramerTest, StreamFrame) { 1216 TEST_P(QuicFramerTest, StreamFrame) {
1017 // clang-format off 1217 // clang-format off
1018 unsigned char packet[] = { 1218 unsigned char packet[] = {
1019 // public flags (8 byte connection_id) 1219 // public flags (8 byte connection_id)
(...skipping 12 matching lines...) Expand all
1032 // offset 1232 // offset
1033 0x54, 0x76, 0x10, 0x32, 1233 0x54, 0x76, 0x10, 0x32,
1034 0xDC, 0xFE, 0x98, 0xBA, 1234 0xDC, 0xFE, 0x98, 0xBA,
1035 // data length 1235 // data length
1036 0x0c, 0x00, 1236 0x0c, 0x00,
1037 // data 1237 // data
1038 'h', 'e', 'l', 'l', 1238 'h', 'e', 'l', 'l',
1039 'o', ' ', 'w', 'o', 1239 'o', ' ', 'w', 'o',
1040 'r', 'l', 'd', '!', 1240 'r', 'l', 'd', '!',
1041 }; 1241 };
1242
1243 unsigned char packet_cid_be[] = {
1244 // public flags (8 byte connection_id)
1245 0x38,
1246 // connection_id
1247 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
1248 // packet number
1249 0xBC, 0x9A, 0x78, 0x56,
1250 0x34, 0x12,
1251
1252 // frame type (stream frame with fin)
1253 0xFF,
1254 // stream id
1255 0x04, 0x03, 0x02, 0x01,
1256 // offset
1257 0x54, 0x76, 0x10, 0x32,
1258 0xDC, 0xFE, 0x98, 0xBA,
1259 // data length
1260 0x0c, 0x00,
1261 // data
1262 'h', 'e', 'l', 'l',
1263 'o', ' ', 'w', 'o',
1264 'r', 'l', 'd', '!',
1265 };
1042 // clang-format on 1266 // clang-format on
1043 1267
1044 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1268 QuicEncryptedPacket encrypted(
1269 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
1270 ? packet_cid_be
1271 : packet),
1272 FLAGS_quic_restart_flag_quic_big_endian_connection_id
1273 ? arraysize(packet_cid_be)
1274 : arraysize(packet),
1275 false);
1045 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1276 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1046 1277
1047 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1278 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1048 ASSERT_TRUE(visitor_.header_.get()); 1279 ASSERT_TRUE(visitor_.header_.get());
1049 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, 1280 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion,
1050 !kIncludeDiversificationNonce)); 1281 !kIncludeDiversificationNonce));
1051 1282
1052 ASSERT_EQ(1u, visitor_.stream_frames_.size()); 1283 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1053 EXPECT_EQ(0u, visitor_.ack_frames_.size()); 1284 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1054 EXPECT_EQ(kStreamId, visitor_.stream_frames_[0]->stream_id); 1285 EXPECT_EQ(kStreamId, visitor_.stream_frames_[0]->stream_id);
1055 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); 1286 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1056 EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); 1287 EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset);
1057 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); 1288 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get());
1058 1289
1059 // Now test framing boundaries. 1290 // Now test framing boundaries.
1060 CheckStreamFrameBoundaries(packet, kQuicMaxStreamIdSize, !kIncludeVersion); 1291 CheckStreamFrameBoundaries(
1292 FLAGS_quic_restart_flag_quic_big_endian_connection_id ? packet_cid_be
1293 : packet,
1294 kQuicMaxStreamIdSize, !kIncludeVersion);
1061 } 1295 }
1062 1296
1063 TEST_P(QuicFramerTest, MissingDiversificationNonce) { 1297 TEST_P(QuicFramerTest, MissingDiversificationNonce) {
1064 QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); 1298 QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT);
1065 framer_.SetDecrypter(ENCRYPTION_NONE, 1299 framer_.SetDecrypter(ENCRYPTION_NONE,
1066 new NullDecrypter(Perspective::IS_CLIENT)); 1300 new NullDecrypter(Perspective::IS_CLIENT));
1067 decrypter_ = new test::TestDecrypter(); 1301 decrypter_ = new test::TestDecrypter();
1068 framer_.SetAlternativeDecrypter(ENCRYPTION_INITIAL, decrypter_, false); 1302 framer_.SetAlternativeDecrypter(ENCRYPTION_INITIAL, decrypter_, false);
1069 1303
1070 // clang-format off 1304 // clang-format off
(...skipping 14 matching lines...) Expand all
1085 // offset 1319 // offset
1086 0x54, 0x76, 0x10, 0x32, 1320 0x54, 0x76, 0x10, 0x32,
1087 0xDC, 0xFE, 0x98, 0xBA, 1321 0xDC, 0xFE, 0x98, 0xBA,
1088 // data length 1322 // data length
1089 0x0c, 0x00, 1323 0x0c, 0x00,
1090 // data 1324 // data
1091 'h', 'e', 'l', 'l', 1325 'h', 'e', 'l', 'l',
1092 'o', ' ', 'w', 'o', 1326 'o', ' ', 'w', 'o',
1093 'r', 'l', 'd', '!', 1327 'r', 'l', 'd', '!',
1094 }; 1328 };
1329
1330 unsigned char packet_cid_be[] = {
1331 // public flags (8 byte connection_id)
1332 0x38,
1333 // connection_id
1334 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
1335 // packet number
1336 0xBC, 0x9A, 0x78, 0x56,
1337 0x34, 0x12,
1338
1339 // frame type (stream frame with fin)
1340 0xFF,
1341 // stream id
1342 0x04, 0x03, 0x02, 0x01,
1343 // offset
1344 0x54, 0x76, 0x10, 0x32,
1345 0xDC, 0xFE, 0x98, 0xBA,
1346 // data length
1347 0x0c, 0x00,
1348 // data
1349 'h', 'e', 'l', 'l',
1350 'o', ' ', 'w', 'o',
1351 'r', 'l', 'd', '!',
1352 };
1095 // clang-format on 1353 // clang-format on
1096 1354
1097 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1355 QuicEncryptedPacket encrypted(
1356 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
1357 ? packet_cid_be
1358 : packet),
1359 FLAGS_quic_restart_flag_quic_big_endian_connection_id
1360 ? arraysize(packet_cid_be)
1361 : arraysize(packet),
1362 false);
1098 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); 1363 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
1099 EXPECT_EQ(QUIC_DECRYPTION_FAILURE, framer_.error()); 1364 EXPECT_EQ(QUIC_DECRYPTION_FAILURE, framer_.error());
1100 } 1365 }
1101 1366
1102 TEST_P(QuicFramerTest, StreamFrame3ByteStreamId) { 1367 TEST_P(QuicFramerTest, StreamFrame3ByteStreamId) {
1103 // clang-format off 1368 // clang-format off
1104 unsigned char packet[] = { 1369 unsigned char packet[] = {
1105 // public flags (8 byte connection_id) 1370 // public flags (8 byte connection_id)
1106 0x38, 1371 0x38,
1107 // connection_id 1372 // connection_id
(...skipping 10 matching lines...) Expand all
1118 // offset 1383 // offset
1119 0x54, 0x76, 0x10, 0x32, 1384 0x54, 0x76, 0x10, 0x32,
1120 0xDC, 0xFE, 0x98, 0xBA, 1385 0xDC, 0xFE, 0x98, 0xBA,
1121 // data length 1386 // data length
1122 0x0c, 0x00, 1387 0x0c, 0x00,
1123 // data 1388 // data
1124 'h', 'e', 'l', 'l', 1389 'h', 'e', 'l', 'l',
1125 'o', ' ', 'w', 'o', 1390 'o', ' ', 'w', 'o',
1126 'r', 'l', 'd', '!', 1391 'r', 'l', 'd', '!',
1127 }; 1392 };
1393
1394 unsigned char packet_cid_be[] = {
1395 // public flags (8 byte connection_id)
1396 0x38,
1397 // connection_id
1398 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
1399 // packet number
1400 0xBC, 0x9A, 0x78, 0x56,
1401 0x34, 0x12,
1402
1403 // frame type (stream frame with fin)
1404 0xFE,
1405 // stream id
1406 0x04, 0x03, 0x02,
1407 // offset
1408 0x54, 0x76, 0x10, 0x32,
1409 0xDC, 0xFE, 0x98, 0xBA,
1410 // data length
1411 0x0c, 0x00,
1412 // data
1413 'h', 'e', 'l', 'l',
1414 'o', ' ', 'w', 'o',
1415 'r', 'l', 'd', '!',
1416 };
1128 // clang-format on 1417 // clang-format on
1129 1418
1130 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1419 QuicEncryptedPacket encrypted(
1420 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
1421 ? packet_cid_be
1422 : packet),
1423 FLAGS_quic_restart_flag_quic_big_endian_connection_id
1424 ? arraysize(packet_cid_be)
1425 : arraysize(packet),
1426 false);
1131 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1427 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1132 1428
1133 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1429 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1134 ASSERT_TRUE(visitor_.header_.get()); 1430 ASSERT_TRUE(visitor_.header_.get());
1135 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, 1431 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion,
1136 !kIncludeDiversificationNonce)); 1432 !kIncludeDiversificationNonce));
1137 1433
1138 ASSERT_EQ(1u, visitor_.stream_frames_.size()); 1434 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1139 EXPECT_EQ(0u, visitor_.ack_frames_.size()); 1435 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1140 // Stream ID should be the last 3 bytes of kStreamId. 1436 // Stream ID should be the last 3 bytes of kStreamId.
1141 EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); 1437 EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id);
1142 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); 1438 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1143 EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); 1439 EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset);
1144 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); 1440 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get());
1145 1441
1146 // Now test framing boundaries. 1442 // Now test framing boundaries.
1147 const size_t stream_id_size = 3; 1443 const size_t stream_id_size = 3;
1148 CheckStreamFrameBoundaries(packet, stream_id_size, !kIncludeVersion); 1444 CheckStreamFrameBoundaries(
1445 FLAGS_quic_restart_flag_quic_big_endian_connection_id ? packet_cid_be
1446 : packet,
1447 stream_id_size, !kIncludeVersion);
1149 } 1448 }
1150 1449
1151 TEST_P(QuicFramerTest, StreamFrame2ByteStreamId) { 1450 TEST_P(QuicFramerTest, StreamFrame2ByteStreamId) {
1152 // clang-format off 1451 // clang-format off
1153 unsigned char packet[] = { 1452 unsigned char packet[] = {
1154 // public flags (8 byte connection_id) 1453 // public flags (8 byte connection_id)
1155 0x38, 1454 0x38,
1156 // connection_id 1455 // connection_id
1157 0x10, 0x32, 0x54, 0x76, 1456 0x10, 0x32, 0x54, 0x76,
1158 0x98, 0xBA, 0xDC, 0xFE, 1457 0x98, 0xBA, 0xDC, 0xFE,
1159 // packet number 1458 // packet number
1160 0xBC, 0x9A, 0x78, 0x56, 1459 0xBC, 0x9A, 0x78, 0x56,
1161 0x34, 0x12, 1460 0x34, 0x12,
1162 1461
1163 // frame type (stream frame with fin) 1462 // frame type (stream frame with fin)
1164 0xFD, 1463 0xFD,
1165 // stream id 1464 // stream id
1166 0x04, 0x03, 1465 0x04, 0x03,
1167 // offset 1466 // offset
1168 0x54, 0x76, 0x10, 0x32, 1467 0x54, 0x76, 0x10, 0x32,
1169 0xDC, 0xFE, 0x98, 0xBA, 1468 0xDC, 0xFE, 0x98, 0xBA,
1170 // data length 1469 // data length
1171 0x0c, 0x00, 1470 0x0c, 0x00,
1172 // data 1471 // data
1173 'h', 'e', 'l', 'l', 1472 'h', 'e', 'l', 'l',
1174 'o', ' ', 'w', 'o', 1473 'o', ' ', 'w', 'o',
1175 'r', 'l', 'd', '!', 1474 'r', 'l', 'd', '!',
1176 }; 1475 };
1476
1477 unsigned char packet_cid_be[] = {
1478 // public flags (8 byte connection_id)
1479 0x38,
1480 // connection_id
1481 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
1482 // packet number
1483 0xBC, 0x9A, 0x78, 0x56,
1484 0x34, 0x12,
1485
1486 // frame type (stream frame with fin)
1487 0xFD,
1488 // stream id
1489 0x04, 0x03,
1490 // offset
1491 0x54, 0x76, 0x10, 0x32,
1492 0xDC, 0xFE, 0x98, 0xBA,
1493 // data length
1494 0x0c, 0x00,
1495 // data
1496 'h', 'e', 'l', 'l',
1497 'o', ' ', 'w', 'o',
1498 'r', 'l', 'd', '!',
1499 };
1177 // clang-format on 1500 // clang-format on
1178 1501
1179 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1502 QuicEncryptedPacket encrypted(
1503 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
1504 ? packet_cid_be
1505 : packet),
1506 FLAGS_quic_restart_flag_quic_big_endian_connection_id
1507 ? arraysize(packet_cid_be)
1508 : arraysize(packet),
1509 false);
1180 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1510 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1181 1511
1182 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1512 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1183 ASSERT_TRUE(visitor_.header_.get()); 1513 ASSERT_TRUE(visitor_.header_.get());
1184 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, 1514 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion,
1185 !kIncludeDiversificationNonce)); 1515 !kIncludeDiversificationNonce));
1186 1516
1187 ASSERT_EQ(1u, visitor_.stream_frames_.size()); 1517 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1188 EXPECT_EQ(0u, visitor_.ack_frames_.size()); 1518 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1189 // Stream ID should be the last 2 bytes of kStreamId. 1519 // Stream ID should be the last 2 bytes of kStreamId.
1190 EXPECT_EQ(0x0000FFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); 1520 EXPECT_EQ(0x0000FFFF & kStreamId, visitor_.stream_frames_[0]->stream_id);
1191 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); 1521 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1192 EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); 1522 EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset);
1193 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); 1523 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get());
1194 1524
1195 // Now test framing boundaries. 1525 // Now test framing boundaries.
1196 const size_t stream_id_size = 2; 1526 const size_t stream_id_size = 2;
1197 CheckStreamFrameBoundaries(packet, stream_id_size, !kIncludeVersion); 1527 CheckStreamFrameBoundaries(
1528 FLAGS_quic_restart_flag_quic_big_endian_connection_id ? packet_cid_be
1529 : packet,
1530 stream_id_size, !kIncludeVersion);
1198 } 1531 }
1199 1532
1200 TEST_P(QuicFramerTest, StreamFrame1ByteStreamId) { 1533 TEST_P(QuicFramerTest, StreamFrame1ByteStreamId) {
1201 // clang-format off 1534 // clang-format off
1202 unsigned char packet[] = { 1535 unsigned char packet[] = {
1203 // public flags (8 byte connection_id) 1536 // public flags (8 byte connection_id)
1204 0x38, 1537 0x38,
1205 // connection_id 1538 // connection_id
1206 0x10, 0x32, 0x54, 0x76, 1539 0x10, 0x32, 0x54, 0x76,
1207 0x98, 0xBA, 0xDC, 0xFE, 1540 0x98, 0xBA, 0xDC, 0xFE,
1208 // packet number 1541 // packet number
1209 0xBC, 0x9A, 0x78, 0x56, 1542 0xBC, 0x9A, 0x78, 0x56,
1210 0x34, 0x12, 1543 0x34, 0x12,
1211 1544
1212 // frame type (stream frame with fin) 1545 // frame type (stream frame with fin)
1213 0xFC, 1546 0xFC,
1214 // stream id 1547 // stream id
1215 0x04, 1548 0x04,
1216 // offset 1549 // offset
1217 0x54, 0x76, 0x10, 0x32, 1550 0x54, 0x76, 0x10, 0x32,
1218 0xDC, 0xFE, 0x98, 0xBA, 1551 0xDC, 0xFE, 0x98, 0xBA,
1219 // data length 1552 // data length
1220 0x0c, 0x00, 1553 0x0c, 0x00,
1221 // data 1554 // data
1222 'h', 'e', 'l', 'l', 1555 'h', 'e', 'l', 'l',
1223 'o', ' ', 'w', 'o', 1556 'o', ' ', 'w', 'o',
1224 'r', 'l', 'd', '!', 1557 'r', 'l', 'd', '!',
1225 }; 1558 };
1559
1560 unsigned char packet_cid_be[] = {
1561 // public flags (8 byte connection_id)
1562 0x38,
1563 // connection_id
1564 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
1565 // packet number
1566 0xBC, 0x9A, 0x78, 0x56,
1567 0x34, 0x12,
1568
1569 // frame type (stream frame with fin)
1570 0xFC,
1571 // stream id
1572 0x04,
1573 // offset
1574 0x54, 0x76, 0x10, 0x32,
1575 0xDC, 0xFE, 0x98, 0xBA,
1576 // data length
1577 0x0c, 0x00,
1578 // data
1579 'h', 'e', 'l', 'l',
1580 'o', ' ', 'w', 'o',
1581 'r', 'l', 'd', '!',
1582 };
1226 // clang-format on 1583 // clang-format on
1227 1584
1228 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1585 QuicEncryptedPacket encrypted(
1586 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
1587 ? packet_cid_be
1588 : packet),
1589 FLAGS_quic_restart_flag_quic_big_endian_connection_id
1590 ? arraysize(packet_cid_be)
1591 : arraysize(packet),
1592 false);
1229 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1593 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1230 1594
1231 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1595 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1232 ASSERT_TRUE(visitor_.header_.get()); 1596 ASSERT_TRUE(visitor_.header_.get());
1233 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, 1597 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion,
1234 !kIncludeDiversificationNonce)); 1598 !kIncludeDiversificationNonce));
1235 1599
1236 ASSERT_EQ(1u, visitor_.stream_frames_.size()); 1600 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1237 EXPECT_EQ(0u, visitor_.ack_frames_.size()); 1601 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1238 // Stream ID should be the last byte of kStreamId. 1602 // Stream ID should be the last byte of kStreamId.
1239 EXPECT_EQ(0x000000FF & kStreamId, visitor_.stream_frames_[0]->stream_id); 1603 EXPECT_EQ(0x000000FF & kStreamId, visitor_.stream_frames_[0]->stream_id);
1240 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); 1604 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1241 EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); 1605 EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset);
1242 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); 1606 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get());
1243 1607
1244 // Now test framing boundaries. 1608 // Now test framing boundaries.
1245 const size_t stream_id_size = 1; 1609 const size_t stream_id_size = 1;
1246 CheckStreamFrameBoundaries(packet, stream_id_size, !kIncludeVersion); 1610 CheckStreamFrameBoundaries(
1611 FLAGS_quic_restart_flag_quic_big_endian_connection_id ? packet_cid_be
1612 : packet,
1613 stream_id_size, !kIncludeVersion);
1247 } 1614 }
1248 1615
1249 TEST_P(QuicFramerTest, StreamFrameWithVersion) { 1616 TEST_P(QuicFramerTest, StreamFrameWithVersion) {
1250 // clang-format off 1617 // clang-format off
1251 unsigned char packet[] = { 1618 unsigned char packet[] = {
1252 // public flags (version, 8 byte connection_id) 1619 // public flags (version, 8 byte connection_id)
1253 0x39, 1620 0x39,
1254 // connection_id 1621 // connection_id
1255 0x10, 0x32, 0x54, 0x76, 1622 0x10, 0x32, 0x54, 0x76,
1256 0x98, 0xBA, 0xDC, 0xFE, 1623 0x98, 0xBA, 0xDC, 0xFE,
(...skipping 10 matching lines...) Expand all
1267 // offset 1634 // offset
1268 0x54, 0x76, 0x10, 0x32, 1635 0x54, 0x76, 0x10, 0x32,
1269 0xDC, 0xFE, 0x98, 0xBA, 1636 0xDC, 0xFE, 0x98, 0xBA,
1270 // data length 1637 // data length
1271 0x0c, 0x00, 1638 0x0c, 0x00,
1272 // data 1639 // data
1273 'h', 'e', 'l', 'l', 1640 'h', 'e', 'l', 'l',
1274 'o', ' ', 'w', 'o', 1641 'o', ' ', 'w', 'o',
1275 'r', 'l', 'd', '!', 1642 'r', 'l', 'd', '!',
1276 }; 1643 };
1644
1645 unsigned char packet_cid_be[] = {
1646 // public flags (version, 8 byte connection_id)
1647 0x39,
1648 // connection_id
1649 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
1650 // version tag
1651 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
1652 // packet number
1653 0xBC, 0x9A, 0x78, 0x56,
1654 0x34, 0x12,
1655
1656 // frame type (stream frame with fin)
1657 0xFF,
1658 // stream id
1659 0x04, 0x03, 0x02, 0x01,
1660 // offset
1661 0x54, 0x76, 0x10, 0x32,
1662 0xDC, 0xFE, 0x98, 0xBA,
1663 // data length
1664 0x0c, 0x00,
1665 // data
1666 'h', 'e', 'l', 'l',
1667 'o', ' ', 'w', 'o',
1668 'r', 'l', 'd', '!',
1669 };
1277 // clang-format on 1670 // clang-format on
1278 1671
1279 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1672 QuicEncryptedPacket encrypted(
1673 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
1674 ? packet_cid_be
1675 : packet),
1676 FLAGS_quic_restart_flag_quic_big_endian_connection_id
1677 ? arraysize(packet_cid_be)
1678 : arraysize(packet),
1679 false);
1280 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1680 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1281 1681
1282 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1682 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1283 ASSERT_TRUE(visitor_.header_.get()); 1683 ASSERT_TRUE(visitor_.header_.get());
1284 EXPECT_TRUE(visitor_.header_->public_header.version_flag); 1684 EXPECT_TRUE(visitor_.header_->public_header.version_flag);
1285 EXPECT_EQ(GetParam(), visitor_.header_->public_header.versions[0]); 1685 EXPECT_EQ(GetParam(), visitor_.header_->public_header.versions[0]);
1286 EXPECT_TRUE(CheckDecryption(encrypted, kIncludeVersion, 1686 EXPECT_TRUE(CheckDecryption(encrypted, kIncludeVersion,
1287 !kIncludeDiversificationNonce)); 1687 !kIncludeDiversificationNonce));
1288 1688
1289 ASSERT_EQ(1u, visitor_.stream_frames_.size()); 1689 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1290 EXPECT_EQ(0u, visitor_.ack_frames_.size()); 1690 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1291 EXPECT_EQ(kStreamId, visitor_.stream_frames_[0]->stream_id); 1691 EXPECT_EQ(kStreamId, visitor_.stream_frames_[0]->stream_id);
1292 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); 1692 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1293 EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); 1693 EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset);
1294 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); 1694 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get());
1295 1695
1296 // Now test framing boundaries. 1696 // Now test framing boundaries.
1297 CheckStreamFrameBoundaries(packet, kQuicMaxStreamIdSize, kIncludeVersion); 1697 CheckStreamFrameBoundaries(
1698 FLAGS_quic_restart_flag_quic_big_endian_connection_id ? packet_cid_be
1699 : packet,
1700 kQuicMaxStreamIdSize, kIncludeVersion);
1298 } 1701 }
1299 1702
1300 TEST_P(QuicFramerTest, RejectPacket) { 1703 TEST_P(QuicFramerTest, RejectPacket) {
1301 visitor_.accept_packet_ = false; 1704 visitor_.accept_packet_ = false;
1302 1705
1303 // clang-format off 1706 // clang-format off
1304 unsigned char packet[] = { 1707 unsigned char packet[] = {
1305 // public flags (8 byte connection_id) 1708 // public flags (8 byte connection_id)
1306 0x38, 1709 0x38,
1307 // connection_id 1710 // connection_id
(...skipping 10 matching lines...) Expand all
1318 // offset 1721 // offset
1319 0x54, 0x76, 0x10, 0x32, 1722 0x54, 0x76, 0x10, 0x32,
1320 0xDC, 0xFE, 0x98, 0xBA, 1723 0xDC, 0xFE, 0x98, 0xBA,
1321 // data length 1724 // data length
1322 0x0c, 0x00, 1725 0x0c, 0x00,
1323 // data 1726 // data
1324 'h', 'e', 'l', 'l', 1727 'h', 'e', 'l', 'l',
1325 'o', ' ', 'w', 'o', 1728 'o', ' ', 'w', 'o',
1326 'r', 'l', 'd', '!', 1729 'r', 'l', 'd', '!',
1327 }; 1730 };
1731
1732 unsigned char packet_cid_be[] = {
1733 // public flags (8 byte connection_id)
1734 0x38,
1735 // connection_id
1736 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
1737 // packet number
1738 0xBC, 0x9A, 0x78, 0x56,
1739 0x34, 0x12,
1740
1741 // frame type (stream frame with fin)
1742 0xFF,
1743 // stream id
1744 0x04, 0x03, 0x02, 0x01,
1745 // offset
1746 0x54, 0x76, 0x10, 0x32,
1747 0xDC, 0xFE, 0x98, 0xBA,
1748 // data length
1749 0x0c, 0x00,
1750 // data
1751 'h', 'e', 'l', 'l',
1752 'o', ' ', 'w', 'o',
1753 'r', 'l', 'd', '!',
1754 };
1328 // clang-format on 1755 // clang-format on
1329 1756
1330 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1757 QuicEncryptedPacket encrypted(
1758 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
1759 ? packet_cid_be
1760 : packet),
1761 FLAGS_quic_restart_flag_quic_big_endian_connection_id
1762 ? arraysize(packet_cid_be)
1763 : arraysize(packet),
1764 false);
1331 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1765 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1332 1766
1333 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1767 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1334 ASSERT_TRUE(visitor_.header_.get()); 1768 ASSERT_TRUE(visitor_.header_.get());
1335 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, 1769 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion,
1336 !kIncludeDiversificationNonce)); 1770 !kIncludeDiversificationNonce));
1337 1771
1338 ASSERT_EQ(0u, visitor_.stream_frames_.size()); 1772 ASSERT_EQ(0u, visitor_.stream_frames_.size());
1339 EXPECT_EQ(0u, visitor_.ack_frames_.size()); 1773 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1340 } 1774 }
1341 1775
1342 TEST_P(QuicFramerTest, RejectPublicHeader) { 1776 TEST_P(QuicFramerTest, RejectPublicHeader) {
1343 visitor_.accept_public_header_ = false; 1777 visitor_.accept_public_header_ = false;
1344 1778
1345 // clang-format off 1779 // clang-format off
1346 unsigned char packet[] = { 1780 unsigned char packet[] = {
1347 // public flags (8 byte connection_id) 1781 // public flags (8 byte connection_id)
1348 0x38, 1782 0x38,
1349 // connection_id 1783 // connection_id
1350 0x10, 0x32, 0x54, 0x76, 1784 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
1351 0x98, 0xBA, 0xDC, 0xFE, 1785 };
1786
1787 unsigned char packet_cid_be[] = {
1788 // public flags (8 byte connection_id)
1789 0x38,
1790 // connection_id
1791 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
1352 }; 1792 };
1353 // clang-format on 1793 // clang-format on
1354 1794
1355 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1795 QuicEncryptedPacket encrypted(
1796 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
1797 ? packet_cid_be
1798 : packet),
1799 FLAGS_quic_restart_flag_quic_big_endian_connection_id
1800 ? arraysize(packet_cid_be)
1801 : arraysize(packet),
1802 false);
1356 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1803 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1357 1804
1358 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1805 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1359 ASSERT_TRUE(visitor_.public_header_.get()); 1806 ASSERT_TRUE(visitor_.public_header_.get());
1360 ASSERT_FALSE(visitor_.header_.get()); 1807 ASSERT_FALSE(visitor_.header_.get());
1361 } 1808 }
1362 1809
1363 TEST_P(QuicFramerTest, AckFrameOneAckBlock) { 1810 TEST_P(QuicFramerTest, AckFrameOneAckBlock) {
1364 // clang-format off 1811 // clang-format off
1365 unsigned char packet[] = { 1812 unsigned char packet[] = {
1366 // public flags (8 byte connection_id) 1813 // public flags (8 byte connection_id)
1367 0x3C, 1814 0x3C,
1368 // connection_id 1815 // connection_id
1369 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, 1816 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
1370 // packet number 1817 // packet number
1371 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, 1818 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
1372 1819
1373 // frame type (ack frame) 1820 // frame type (ack frame)
1374 // (one ack block, 2 byte largest observed, 2 byte block length) 1821 // (one ack block, 2 byte largest observed, 2 byte block length)
1375 0x45, 1822 0x45,
1376 // largest acked 1823 // largest acked
1377 0x34, 0x12, 1824 0x34, 0x12,
1378 // Zero delta time. 1825 // Zero delta time.
1379 0x00, 0x00, 1826 0x00, 0x00,
1380 // first ack block length. 1827 // first ack block length.
1381 0x34, 0x12, 1828 0x34, 0x12,
1382 // num timestamps. 1829 // num timestamps.
1383 0x00, 1830 0x00,
1384 }; 1831 };
1832
1833 unsigned char packet_cid_be[] = {
1834 // public flags (8 byte connection_id)
1835 0x3C,
1836 // connection_id
1837 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
1838 // packet number
1839 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
1840
1841 // frame type (ack frame)
1842 // (one ack block, 2 byte largest observed, 2 byte block length)
1843 0x45,
1844 // largest acked
1845 0x34, 0x12,
1846 // Zero delta time.
1847 0x00, 0x00,
1848 // first ack block length.
1849 0x34, 0x12,
1850 // num timestamps.
1851 0x00,
1852 };
1385 // clang-format on 1853 // clang-format on
1386 1854
1387 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1855 QuicEncryptedPacket encrypted(
1856 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
1857 ? packet_cid_be
1858 : packet),
1859 FLAGS_quic_restart_flag_quic_big_endian_connection_id
1860 ? arraysize(packet_cid_be)
1861 : arraysize(packet),
1862 false);
1388 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1863 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1389 1864
1390 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1865 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1391 ASSERT_TRUE(visitor_.header_.get()); 1866 ASSERT_TRUE(visitor_.header_.get());
1392 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, 1867 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion,
1393 !kIncludeDiversificationNonce)); 1868 !kIncludeDiversificationNonce));
1394 1869
1395 EXPECT_EQ(0u, visitor_.stream_frames_.size()); 1870 EXPECT_EQ(0u, visitor_.stream_frames_.size());
1396 ASSERT_EQ(1u, visitor_.ack_frames_.size()); 1871 ASSERT_EQ(1u, visitor_.ack_frames_.size());
1397 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; 1872 const QuicAckFrame& frame = *visitor_.ack_frames_[0];
(...skipping 15 matching lines...) Expand all
1413 if (i < kLargestAckedDeltaTimeOffset) { 1888 if (i < kLargestAckedDeltaTimeOffset) {
1414 expected_error = "Unable to read largest acked."; 1889 expected_error = "Unable to read largest acked.";
1415 } else if (i < kFirstAckBlockLengthOffset) { 1890 } else if (i < kFirstAckBlockLengthOffset) {
1416 expected_error = "Unable to read ack delay time."; 1891 expected_error = "Unable to read ack delay time.";
1417 } else if (i < kNumTimestampsOffset) { 1892 } else if (i < kNumTimestampsOffset) {
1418 expected_error = "Unable to read first ack block length."; 1893 expected_error = "Unable to read first ack block length.";
1419 } else { 1894 } else {
1420 expected_error = "Unable to read num received packets."; 1895 expected_error = "Unable to read num received packets.";
1421 } 1896 }
1422 CheckProcessingFails( 1897 CheckProcessingFails(
1423 packet, 1898 FLAGS_quic_restart_flag_quic_big_endian_connection_id ? packet_cid_be
1899 : packet,
1424 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, 1900 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID,
1425 !kIncludeVersion, !kIncludeDiversificationNonce, 1901 !kIncludeVersion, !kIncludeDiversificationNonce,
1426 PACKET_6BYTE_PACKET_NUMBER), 1902 PACKET_6BYTE_PACKET_NUMBER),
1427 expected_error, QUIC_INVALID_ACK_DATA); 1903 expected_error, QUIC_INVALID_ACK_DATA);
1428 } 1904 }
1429 } 1905 }
1430 1906
1431 TEST_P(QuicFramerTest, AckFrameTwoTimeStampsMultipleAckBlocks) { 1907 TEST_P(QuicFramerTest, AckFrameTwoTimeStampsMultipleAckBlocks) {
1432 // clang-format off 1908 // clang-format off
1433 unsigned char packet[] = { 1909 unsigned char packet[] = {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1469 0x02, 1945 0x02,
1470 // Delta from largest observed. 1946 // Delta from largest observed.
1471 0x01, 1947 0x01,
1472 // Delta time. 1948 // Delta time.
1473 0x10, 0x32, 0x54, 0x76, 1949 0x10, 0x32, 0x54, 0x76,
1474 // Delta from largest observed. 1950 // Delta from largest observed.
1475 0x02, 1951 0x02,
1476 // Delta time. 1952 // Delta time.
1477 0x10, 0x32, 1953 0x10, 0x32,
1478 }; 1954 };
1955
1956 unsigned char packet_cid_be[] = {
1957 // public flags (8 byte connection_id)
1958 0x3C,
1959 // connection_id
1960 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
1961 // packet number
1962 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
1963
1964 // frame type (ack frame)
1965 // (more than one ack block, 2 byte largest observed, 2 byte block length)
1966 0x65,
1967 // largest acked
1968 0x34, 0x12,
1969 // Zero delta time.
1970 0x00, 0x00,
1971 // num ack blocks ranges.
1972 0x04,
1973 // first ack block length.
1974 0x01, 0x00,
1975 // gap to next block.
1976 0x01,
1977 // ack block length.
1978 0xaf, 0x0e,
1979 // gap to next block.
1980 0xff,
1981 // ack block length.
1982 0x00, 0x00,
1983 // gap to next block.
1984 0x91,
1985 // ack block length.
1986 0xea, 0x01,
1987 // gap to next block.
1988 0x05,
1989 // ack block length.
1990 0x04, 0x00,
1991 // Number of timestamps.
1992 0x02,
1993 // Delta from largest observed.
1994 0x01,
1995 // Delta time.
1996 0x10, 0x32, 0x54, 0x76,
1997 // Delta from largest observed.
1998 0x02,
1999 // Delta time.
2000 0x10, 0x32,
2001 };
1479 // clang-format on 2002 // clang-format on
1480 2003
1481 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 2004 QuicEncryptedPacket encrypted(
2005 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
2006 ? packet_cid_be
2007 : packet),
2008 FLAGS_quic_restart_flag_quic_big_endian_connection_id
2009 ? arraysize(packet_cid_be)
2010 : arraysize(packet),
2011 false);
1482 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2012 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1483 2013
1484 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2014 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1485 ASSERT_TRUE(visitor_.header_.get()); 2015 ASSERT_TRUE(visitor_.header_.get());
1486 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, 2016 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion,
1487 !kIncludeDiversificationNonce)); 2017 !kIncludeDiversificationNonce));
1488 2018
1489 EXPECT_EQ(0u, visitor_.stream_frames_.size()); 2019 EXPECT_EQ(0u, visitor_.stream_frames_.size());
1490 ASSERT_EQ(1u, visitor_.ack_frames_.size()); 2020 ASSERT_EQ(1u, visitor_.ack_frames_.size());
1491 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; 2021 const QuicAckFrame& frame = *visitor_.ack_frames_[0];
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1558 } else if (i < kTimestampDeltaLargestObserved2) { 2088 } else if (i < kTimestampDeltaLargestObserved2) {
1559 expected_error = "Unable to read time delta in received packets."; 2089 expected_error = "Unable to read time delta in received packets.";
1560 } else if (i < kTimestampTimeDeltaLargestObserved2) { 2090 } else if (i < kTimestampTimeDeltaLargestObserved2) {
1561 expected_error = "Unable to read sequence delta in received packets."; 2091 expected_error = "Unable to read sequence delta in received packets.";
1562 } else { 2092 } else {
1563 expected_error = 2093 expected_error =
1564 "Unable to read incremental time delta in received packets."; 2094 "Unable to read incremental time delta in received packets.";
1565 } 2095 }
1566 2096
1567 CheckProcessingFails( 2097 CheckProcessingFails(
1568 packet, 2098 FLAGS_quic_restart_flag_quic_big_endian_connection_id ? packet_cid_be
2099 : packet,
1569 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, 2100 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID,
1570 !kIncludeVersion, !kIncludeDiversificationNonce, 2101 !kIncludeVersion, !kIncludeDiversificationNonce,
1571 PACKET_6BYTE_PACKET_NUMBER), 2102 PACKET_6BYTE_PACKET_NUMBER),
1572 expected_error, QUIC_INVALID_ACK_DATA); 2103 expected_error, QUIC_INVALID_ACK_DATA);
1573 } 2104 }
1574 } 2105 }
1575 2106
1576 TEST_P(QuicFramerTest, NewStopWaitingFrame) { 2107 TEST_P(QuicFramerTest, NewStopWaitingFrame) {
1577 // clang-format off 2108 // clang-format off
1578 unsigned char packet[] = { 2109 unsigned char packet[] = {
1579 // public flags (8 byte connection_id) 2110 // public flags (8 byte connection_id)
1580 0x3C, 2111 0x3C,
1581 // connection_id 2112 // connection_id
1582 0x10, 0x32, 0x54, 0x76, 2113 0x10, 0x32, 0x54, 0x76,
1583 0x98, 0xBA, 0xDC, 0xFE, 2114 0x98, 0xBA, 0xDC, 0xFE,
1584 // packet number 2115 // packet number
1585 0xA8, 0x9A, 0x78, 0x56, 2116 0xA8, 0x9A, 0x78, 0x56,
1586 0x34, 0x12, 2117 0x34, 0x12,
1587 // frame type (stop waiting frame) 2118 // frame type (stop waiting frame)
1588 0x06, 2119 0x06,
1589 // least packet number awaiting an ack, delta from packet number. 2120 // least packet number awaiting an ack, delta from packet number.
1590 0x08, 0x00, 0x00, 0x00, 2121 0x08, 0x00, 0x00, 0x00,
1591 0x00, 0x00, 2122 0x00, 0x00,
1592 }; 2123 };
2124
2125 unsigned char packet_cid_be[] = {
2126 // public flags (8 byte connection_id)
2127 0x3C,
2128 // connection_id
2129 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
2130 // packet number
2131 0xA8, 0x9A, 0x78, 0x56,
2132 0x34, 0x12,
2133 // frame type (stop waiting frame)
2134 0x06,
2135 // least packet number awaiting an ack, delta from packet number.
2136 0x08, 0x00, 0x00, 0x00,
2137 0x00, 0x00,
2138 };
1593 // clang-format on 2139 // clang-format on
1594 2140
1595 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 2141 QuicEncryptedPacket encrypted(
2142 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
2143 ? packet_cid_be
2144 : packet),
2145 FLAGS_quic_restart_flag_quic_big_endian_connection_id
2146 ? arraysize(packet_cid_be)
2147 : arraysize(packet),
2148 false);
1596 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2149 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1597 2150
1598 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2151 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1599 ASSERT_TRUE(visitor_.header_.get()); 2152 ASSERT_TRUE(visitor_.header_.get());
1600 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, 2153 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion,
1601 !kIncludeDiversificationNonce)); 2154 !kIncludeDiversificationNonce));
1602 2155
1603 EXPECT_EQ(0u, visitor_.stream_frames_.size()); 2156 EXPECT_EQ(0u, visitor_.stream_frames_.size());
1604 ASSERT_EQ(1u, visitor_.stop_waiting_frames_.size()); 2157 ASSERT_EQ(1u, visitor_.stop_waiting_frames_.size());
1605 const QuicStopWaitingFrame& frame = *visitor_.stop_waiting_frames_[0]; 2158 const QuicStopWaitingFrame& frame = *visitor_.stop_waiting_frames_[0];
1606 EXPECT_EQ(kLeastUnacked, frame.least_unacked); 2159 EXPECT_EQ(kLeastUnacked, frame.least_unacked);
1607 2160
1608 const size_t frame_size = 7; 2161 const size_t frame_size = 7;
1609 for (size_t i = kQuicFrameTypeSize; i < frame_size; ++i) { 2162 for (size_t i = kQuicFrameTypeSize; i < frame_size; ++i) {
1610 string expected_error; 2163 string expected_error;
1611 expected_error = "Unable to read least unacked delta."; 2164 expected_error = "Unable to read least unacked delta.";
1612 CheckProcessingFails( 2165 CheckProcessingFails(
1613 packet, 2166 FLAGS_quic_restart_flag_quic_big_endian_connection_id ? packet_cid_be
2167 : packet,
1614 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, 2168 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID,
1615 !kIncludeVersion, !kIncludeDiversificationNonce, 2169 !kIncludeVersion, !kIncludeDiversificationNonce,
1616 PACKET_6BYTE_PACKET_NUMBER), 2170 PACKET_6BYTE_PACKET_NUMBER),
1617 expected_error, QUIC_INVALID_STOP_WAITING_DATA); 2171 expected_error, QUIC_INVALID_STOP_WAITING_DATA);
1618 } 2172 }
1619 } 2173 }
1620 2174
1621 TEST_P(QuicFramerTest, RstStreamFrameQuic) { 2175 TEST_P(QuicFramerTest, RstStreamFrameQuic) {
1622 // clang-format off 2176 // clang-format off
1623 unsigned char packet[] = { 2177 unsigned char packet[] = {
(...skipping 11 matching lines...) Expand all
1635 // stream id 2189 // stream id
1636 0x04, 0x03, 0x02, 0x01, 2190 0x04, 0x03, 0x02, 0x01,
1637 2191
1638 // sent byte offset 2192 // sent byte offset
1639 0x54, 0x76, 0x10, 0x32, 2193 0x54, 0x76, 0x10, 0x32,
1640 0xDC, 0xFE, 0x98, 0xBA, 2194 0xDC, 0xFE, 0x98, 0xBA,
1641 2195
1642 // error code 2196 // error code
1643 0x01, 0x00, 0x00, 0x00, 2197 0x01, 0x00, 0x00, 0x00,
1644 }; 2198 };
2199
2200 unsigned char packet_cid_be[] = {
2201 // public flags (8 byte connection_id)
2202 0x38,
2203 // connection_id
2204 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
2205 // packet number
2206 0xBC, 0x9A, 0x78, 0x56,
2207 0x34, 0x12,
2208
2209 // frame type (rst stream frame)
2210 0x01,
2211 // stream id
2212 0x04, 0x03, 0x02, 0x01,
2213
2214 // sent byte offset
2215 0x54, 0x76, 0x10, 0x32,
2216 0xDC, 0xFE, 0x98, 0xBA,
2217
2218 // error code
2219 0x01, 0x00, 0x00, 0x00,
2220 };
1645 // clang-format on 2221 // clang-format on
1646 2222
1647 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 2223 QuicEncryptedPacket encrypted(
2224 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
2225 ? packet_cid_be
2226 : packet),
2227 FLAGS_quic_restart_flag_quic_big_endian_connection_id
2228 ? arraysize(packet_cid_be)
2229 : arraysize(packet),
2230 false);
1648 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2231 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1649 2232
1650 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2233 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1651 ASSERT_TRUE(visitor_.header_.get()); 2234 ASSERT_TRUE(visitor_.header_.get());
1652 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, 2235 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion,
1653 !kIncludeDiversificationNonce)); 2236 !kIncludeDiversificationNonce));
1654 2237
1655 EXPECT_EQ(kStreamId, visitor_.rst_stream_frame_.stream_id); 2238 EXPECT_EQ(kStreamId, visitor_.rst_stream_frame_.stream_id);
1656 EXPECT_EQ(0x01, visitor_.rst_stream_frame_.error_code); 2239 EXPECT_EQ(0x01, visitor_.rst_stream_frame_.error_code);
1657 EXPECT_EQ(kStreamOffset, visitor_.rst_stream_frame_.byte_offset); 2240 EXPECT_EQ(kStreamOffset, visitor_.rst_stream_frame_.byte_offset);
1658 2241
1659 // Now test framing boundaries. 2242 // Now test framing boundaries.
1660 for (size_t i = kQuicFrameTypeSize; i < QuicFramer::GetRstStreamFrameSize(); 2243 for (size_t i = kQuicFrameTypeSize; i < QuicFramer::GetRstStreamFrameSize();
1661 ++i) { 2244 ++i) {
1662 string expected_error; 2245 string expected_error;
1663 if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize) { 2246 if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize) {
1664 expected_error = "Unable to read stream_id."; 2247 expected_error = "Unable to read stream_id.";
1665 } else if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize + 2248 } else if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize +
1666 kQuicMaxStreamOffsetSize) { 2249 kQuicMaxStreamOffsetSize) {
1667 expected_error = "Unable to read rst stream sent byte offset."; 2250 expected_error = "Unable to read rst stream sent byte offset.";
1668 } else if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize + 2251 } else if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize +
1669 kQuicMaxStreamOffsetSize + kQuicErrorCodeSize) { 2252 kQuicMaxStreamOffsetSize + kQuicErrorCodeSize) {
1670 expected_error = "Unable to read rst stream error code."; 2253 expected_error = "Unable to read rst stream error code.";
1671 } 2254 }
1672 CheckProcessingFails( 2255 CheckProcessingFails(
1673 packet, 2256 FLAGS_quic_restart_flag_quic_big_endian_connection_id ? packet_cid_be
2257 : packet,
1674 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, 2258 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID,
1675 !kIncludeVersion, !kIncludeDiversificationNonce, 2259 !kIncludeVersion, !kIncludeDiversificationNonce,
1676 PACKET_6BYTE_PACKET_NUMBER), 2260 PACKET_6BYTE_PACKET_NUMBER),
1677 expected_error, QUIC_INVALID_RST_STREAM_DATA); 2261 expected_error, QUIC_INVALID_RST_STREAM_DATA);
1678 } 2262 }
1679 } 2263 }
1680 2264
1681 TEST_P(QuicFramerTest, ConnectionCloseFrame) { 2265 TEST_P(QuicFramerTest, ConnectionCloseFrame) {
1682 // clang-format off 2266 // clang-format off
1683 unsigned char packet[] = { 2267 unsigned char packet[] = {
(...skipping 12 matching lines...) Expand all
1696 0x11, 0x00, 0x00, 0x00, 2280 0x11, 0x00, 0x00, 0x00,
1697 2281
1698 // error details length 2282 // error details length
1699 0x0d, 0x00, 2283 0x0d, 0x00,
1700 // error details 2284 // error details
1701 'b', 'e', 'c', 'a', 2285 'b', 'e', 'c', 'a',
1702 'u', 's', 'e', ' ', 2286 'u', 's', 'e', ' ',
1703 'I', ' ', 'c', 'a', 2287 'I', ' ', 'c', 'a',
1704 'n', 2288 'n',
1705 }; 2289 };
2290
2291 unsigned char packet_cid_be[] = {
2292 // public flags (8 byte connection_id)
2293 0x38,
2294 // connection_id
2295 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
2296 // packet number
2297 0xBC, 0x9A, 0x78, 0x56,
2298 0x34, 0x12,
2299
2300 // frame type (connection close frame)
2301 0x02,
2302 // error code
2303 0x11, 0x00, 0x00, 0x00,
2304
2305 // error details length
2306 0x0d, 0x00,
2307 // error details
2308 'b', 'e', 'c', 'a',
2309 'u', 's', 'e', ' ',
2310 'I', ' ', 'c', 'a',
2311 'n',
2312 };
1706 // clang-format on 2313 // clang-format on
1707 2314
1708 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 2315 QuicEncryptedPacket encrypted(
2316 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
2317 ? packet_cid_be
2318 : packet),
2319 FLAGS_quic_restart_flag_quic_big_endian_connection_id
2320 ? arraysize(packet_cid_be)
2321 : arraysize(packet),
2322 false);
1709 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2323 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1710 2324
1711 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2325 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1712 ASSERT_TRUE(visitor_.header_.get()); 2326 ASSERT_TRUE(visitor_.header_.get());
1713 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, 2327 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion,
1714 !kIncludeDiversificationNonce)); 2328 !kIncludeDiversificationNonce));
1715 2329
1716 EXPECT_EQ(0u, visitor_.stream_frames_.size()); 2330 EXPECT_EQ(0u, visitor_.stream_frames_.size());
1717 2331
1718 EXPECT_EQ(0x11, visitor_.connection_close_frame_.error_code); 2332 EXPECT_EQ(0x11, visitor_.connection_close_frame_.error_code);
1719 EXPECT_EQ("because I can", visitor_.connection_close_frame_.error_details); 2333 EXPECT_EQ("because I can", visitor_.connection_close_frame_.error_details);
1720 2334
1721 ASSERT_EQ(0u, visitor_.ack_frames_.size()); 2335 ASSERT_EQ(0u, visitor_.ack_frames_.size());
1722 2336
1723 // Now test framing boundaries. 2337 // Now test framing boundaries.
1724 for (size_t i = kQuicFrameTypeSize; 2338 for (size_t i = kQuicFrameTypeSize;
1725 i < QuicFramer::GetMinConnectionCloseFrameSize(); ++i) { 2339 i < QuicFramer::GetMinConnectionCloseFrameSize(); ++i) {
1726 string expected_error; 2340 string expected_error;
1727 if (i < kQuicFrameTypeSize + kQuicErrorCodeSize) { 2341 if (i < kQuicFrameTypeSize + kQuicErrorCodeSize) {
1728 expected_error = "Unable to read connection close error code."; 2342 expected_error = "Unable to read connection close error code.";
1729 } else { 2343 } else {
1730 expected_error = "Unable to read connection close error details."; 2344 expected_error = "Unable to read connection close error details.";
1731 } 2345 }
1732 CheckProcessingFails( 2346 CheckProcessingFails(
1733 packet, 2347 FLAGS_quic_restart_flag_quic_big_endian_connection_id ? packet_cid_be
2348 : packet,
1734 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, 2349 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID,
1735 !kIncludeVersion, !kIncludeDiversificationNonce, 2350 !kIncludeVersion, !kIncludeDiversificationNonce,
1736 PACKET_6BYTE_PACKET_NUMBER), 2351 PACKET_6BYTE_PACKET_NUMBER),
1737 expected_error, QUIC_INVALID_CONNECTION_CLOSE_DATA); 2352 expected_error, QUIC_INVALID_CONNECTION_CLOSE_DATA);
1738 } 2353 }
1739 } 2354 }
1740 2355
1741 TEST_P(QuicFramerTest, GoAwayFrame) { 2356 TEST_P(QuicFramerTest, GoAwayFrame) {
1742 // clang-format off 2357 // clang-format off
1743 unsigned char packet[] = { 2358 unsigned char packet[] = {
(...skipping 13 matching lines...) Expand all
1757 // stream id 2372 // stream id
1758 0x04, 0x03, 0x02, 0x01, 2373 0x04, 0x03, 0x02, 0x01,
1759 // error details length 2374 // error details length
1760 0x0d, 0x00, 2375 0x0d, 0x00,
1761 // error details 2376 // error details
1762 'b', 'e', 'c', 'a', 2377 'b', 'e', 'c', 'a',
1763 'u', 's', 'e', ' ', 2378 'u', 's', 'e', ' ',
1764 'I', ' ', 'c', 'a', 2379 'I', ' ', 'c', 'a',
1765 'n', 2380 'n',
1766 }; 2381 };
2382
2383 unsigned char packet_cid_be[] = {
2384 // public flags (8 byte connection_id)
2385 0x38,
2386 // connection_id
2387 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
2388 // packet number
2389 0xBC, 0x9A, 0x78, 0x56,
2390 0x34, 0x12,
2391
2392 // frame type (go away frame)
2393 0x03,
2394 // error code
2395 0x09, 0x00, 0x00, 0x00,
2396 // stream id
2397 0x04, 0x03, 0x02, 0x01,
2398 // error details length
2399 0x0d, 0x00,
2400 // error details
2401 'b', 'e', 'c', 'a',
2402 'u', 's', 'e', ' ',
2403 'I', ' ', 'c', 'a',
2404 'n',
2405 };
1767 // clang-format on 2406 // clang-format on
1768 2407
1769 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 2408 QuicEncryptedPacket encrypted(
2409 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
2410 ? packet_cid_be
2411 : packet),
2412 FLAGS_quic_restart_flag_quic_big_endian_connection_id
2413 ? arraysize(packet_cid_be)
2414 : arraysize(packet),
2415 false);
1770 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2416 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1771 2417
1772 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2418 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1773 ASSERT_TRUE(visitor_.header_.get()); 2419 ASSERT_TRUE(visitor_.header_.get());
1774 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, 2420 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion,
1775 !kIncludeDiversificationNonce)); 2421 !kIncludeDiversificationNonce));
1776 2422
1777 EXPECT_EQ(kStreamId, visitor_.goaway_frame_.last_good_stream_id); 2423 EXPECT_EQ(kStreamId, visitor_.goaway_frame_.last_good_stream_id);
1778 EXPECT_EQ(0x9, visitor_.goaway_frame_.error_code); 2424 EXPECT_EQ(0x9, visitor_.goaway_frame_.error_code);
1779 EXPECT_EQ("because I can", visitor_.goaway_frame_.reason_phrase); 2425 EXPECT_EQ("because I can", visitor_.goaway_frame_.reason_phrase);
1780 2426
1781 const size_t reason_size = arraysize("because I can") - 1; 2427 const size_t reason_size = arraysize("because I can") - 1;
1782 // Now test framing boundaries. 2428 // Now test framing boundaries.
1783 for (size_t i = kQuicFrameTypeSize; 2429 for (size_t i = kQuicFrameTypeSize;
1784 i < QuicFramer::GetMinGoAwayFrameSize() + reason_size; ++i) { 2430 i < QuicFramer::GetMinGoAwayFrameSize() + reason_size; ++i) {
1785 string expected_error; 2431 string expected_error;
1786 if (i < kQuicFrameTypeSize + kQuicErrorCodeSize) { 2432 if (i < kQuicFrameTypeSize + kQuicErrorCodeSize) {
1787 expected_error = "Unable to read go away error code."; 2433 expected_error = "Unable to read go away error code.";
1788 } else if (i < 2434 } else if (i <
1789 kQuicFrameTypeSize + kQuicErrorCodeSize + kQuicMaxStreamIdSize) { 2435 kQuicFrameTypeSize + kQuicErrorCodeSize + kQuicMaxStreamIdSize) {
1790 expected_error = "Unable to read last good stream id."; 2436 expected_error = "Unable to read last good stream id.";
1791 } else { 2437 } else {
1792 expected_error = "Unable to read goaway reason."; 2438 expected_error = "Unable to read goaway reason.";
1793 } 2439 }
1794 CheckProcessingFails( 2440 CheckProcessingFails(
1795 packet, 2441 FLAGS_quic_restart_flag_quic_big_endian_connection_id ? packet_cid_be
2442 : packet,
1796 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, 2443 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID,
1797 !kIncludeVersion, !kIncludeDiversificationNonce, 2444 !kIncludeVersion, !kIncludeDiversificationNonce,
1798 PACKET_6BYTE_PACKET_NUMBER), 2445 PACKET_6BYTE_PACKET_NUMBER),
1799 expected_error, QUIC_INVALID_GOAWAY_DATA); 2446 expected_error, QUIC_INVALID_GOAWAY_DATA);
1800 } 2447 }
1801 } 2448 }
1802 2449
1803 TEST_P(QuicFramerTest, WindowUpdateFrame) { 2450 TEST_P(QuicFramerTest, WindowUpdateFrame) {
1804 // clang-format off 2451 // clang-format off
1805 unsigned char packet[] = { 2452 unsigned char packet[] = {
1806 // public flags (8 byte connection_id) 2453 // public flags (8 byte connection_id)
1807 0x38, 2454 0x38,
1808 // connection_id 2455 // connection_id
1809 0x10, 0x32, 0x54, 0x76, 2456 0x10, 0x32, 0x54, 0x76,
1810 0x98, 0xBA, 0xDC, 0xFE, 2457 0x98, 0xBA, 0xDC, 0xFE,
1811 // packet number 2458 // packet number
1812 0xBC, 0x9A, 0x78, 0x56, 2459 0xBC, 0x9A, 0x78, 0x56,
1813 0x34, 0x12, 2460 0x34, 0x12,
1814 2461
1815 // frame type (window update frame) 2462 // frame type (window update frame)
1816 0x04, 2463 0x04,
1817 // stream id 2464 // stream id
1818 0x04, 0x03, 0x02, 0x01, 2465 0x04, 0x03, 0x02, 0x01,
1819 // byte offset 2466 // byte offset
1820 0x54, 0x76, 0x10, 0x32, 2467 0x54, 0x76, 0x10, 0x32,
1821 0xDC, 0xFE, 0x98, 0xBA, 2468 0xDC, 0xFE, 0x98, 0xBA,
1822 }; 2469 };
2470
2471 unsigned char packet_cid_be[] = {
2472 // public flags (8 byte connection_id)
2473 0x38,
2474 // connection_id
2475 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
2476 // packet number
2477 0xBC, 0x9A, 0x78, 0x56,
2478 0x34, 0x12,
2479
2480 // frame type (window update frame)
2481 0x04,
2482 // stream id
2483 0x04, 0x03, 0x02, 0x01,
2484 // byte offset
2485 0x54, 0x76, 0x10, 0x32,
2486 0xDC, 0xFE, 0x98, 0xBA,
2487 };
1823 // clang-format on 2488 // clang-format on
1824 2489
1825 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 2490 QuicEncryptedPacket encrypted(
2491 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
2492 ? packet_cid_be
2493 : packet),
2494 FLAGS_quic_restart_flag_quic_big_endian_connection_id
2495 ? arraysize(packet_cid_be)
2496 : arraysize(packet),
2497 false);
1826 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2498 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1827 2499
1828 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2500 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1829 ASSERT_TRUE(visitor_.header_.get()); 2501 ASSERT_TRUE(visitor_.header_.get());
1830 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, 2502 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion,
1831 !kIncludeDiversificationNonce)); 2503 !kIncludeDiversificationNonce));
1832 2504
1833 EXPECT_EQ(kStreamId, visitor_.window_update_frame_.stream_id); 2505 EXPECT_EQ(kStreamId, visitor_.window_update_frame_.stream_id);
1834 EXPECT_EQ(kStreamOffset, visitor_.window_update_frame_.byte_offset); 2506 EXPECT_EQ(kStreamOffset, visitor_.window_update_frame_.byte_offset);
1835 2507
1836 // Now test framing boundaries. 2508 // Now test framing boundaries.
1837 for (size_t i = kQuicFrameTypeSize; 2509 for (size_t i = kQuicFrameTypeSize;
1838 i < QuicFramer::GetWindowUpdateFrameSize(); ++i) { 2510 i < QuicFramer::GetWindowUpdateFrameSize(); ++i) {
1839 string expected_error; 2511 string expected_error;
1840 if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize) { 2512 if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize) {
1841 expected_error = "Unable to read stream_id."; 2513 expected_error = "Unable to read stream_id.";
1842 } else { 2514 } else {
1843 expected_error = "Unable to read window byte_offset."; 2515 expected_error = "Unable to read window byte_offset.";
1844 } 2516 }
1845 CheckProcessingFails( 2517 CheckProcessingFails(
1846 packet, 2518 FLAGS_quic_restart_flag_quic_big_endian_connection_id ? packet_cid_be
2519 : packet,
1847 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, 2520 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID,
1848 !kIncludeVersion, !kIncludeDiversificationNonce, 2521 !kIncludeVersion, !kIncludeDiversificationNonce,
1849 PACKET_6BYTE_PACKET_NUMBER), 2522 PACKET_6BYTE_PACKET_NUMBER),
1850 expected_error, QUIC_INVALID_WINDOW_UPDATE_DATA); 2523 expected_error, QUIC_INVALID_WINDOW_UPDATE_DATA);
1851 } 2524 }
1852 } 2525 }
1853 2526
1854 TEST_P(QuicFramerTest, BlockedFrame) { 2527 TEST_P(QuicFramerTest, BlockedFrame) {
1855 // clang-format off 2528 // clang-format off
1856 unsigned char packet[] = { 2529 unsigned char packet[] = {
1857 // public flags (8 byte connection_id) 2530 // public flags (8 byte connection_id)
1858 0x38, 2531 0x38,
1859 // connection_id 2532 // connection_id
1860 0x10, 0x32, 0x54, 0x76, 2533 0x10, 0x32, 0x54, 0x76,
1861 0x98, 0xBA, 0xDC, 0xFE, 2534 0x98, 0xBA, 0xDC, 0xFE,
1862 // packet number 2535 // packet number
1863 0xBC, 0x9A, 0x78, 0x56, 2536 0xBC, 0x9A, 0x78, 0x56,
1864 0x34, 0x12, 2537 0x34, 0x12,
1865 2538
1866 // frame type (blocked frame) 2539 // frame type (blocked frame)
1867 0x05, 2540 0x05,
1868 // stream id 2541 // stream id
1869 0x04, 0x03, 0x02, 0x01, 2542 0x04, 0x03, 0x02, 0x01,
1870 }; 2543 };
2544
2545 unsigned char packet_cid_be[] = {
2546 // public flags (8 byte connection_id)
2547 0x38,
2548 // connection_id
2549 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
2550 // packet number
2551 0xBC, 0x9A, 0x78, 0x56,
2552 0x34, 0x12,
2553
2554 // frame type (blocked frame)
2555 0x05,
2556 // stream id
2557 0x04, 0x03, 0x02, 0x01,
2558 };
1871 // clang-format on 2559 // clang-format on
1872 2560
1873 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 2561 QuicEncryptedPacket encrypted(
2562 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
2563 ? packet_cid_be
2564 : packet),
2565 FLAGS_quic_restart_flag_quic_big_endian_connection_id
2566 ? arraysize(packet_cid_be)
2567 : arraysize(packet),
2568 false);
1874 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2569 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1875 2570
1876 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2571 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1877 ASSERT_TRUE(visitor_.header_.get()); 2572 ASSERT_TRUE(visitor_.header_.get());
1878 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, 2573 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion,
1879 !kIncludeDiversificationNonce)); 2574 !kIncludeDiversificationNonce));
1880 2575
1881 EXPECT_EQ(kStreamId, visitor_.blocked_frame_.stream_id); 2576 EXPECT_EQ(kStreamId, visitor_.blocked_frame_.stream_id);
1882 2577
1883 // Now test framing boundaries. 2578 // Now test framing boundaries.
1884 for (size_t i = kQuicFrameTypeSize; i < QuicFramer::GetBlockedFrameSize(); 2579 for (size_t i = kQuicFrameTypeSize; i < QuicFramer::GetBlockedFrameSize();
1885 ++i) { 2580 ++i) {
1886 string expected_error = "Unable to read stream_id."; 2581 string expected_error = "Unable to read stream_id.";
1887 CheckProcessingFails( 2582 CheckProcessingFails(
1888 packet, 2583 FLAGS_quic_restart_flag_quic_big_endian_connection_id ? packet_cid_be
2584 : packet,
1889 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, 2585 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID,
1890 !kIncludeVersion, !kIncludeDiversificationNonce, 2586 !kIncludeVersion, !kIncludeDiversificationNonce,
1891 PACKET_6BYTE_PACKET_NUMBER), 2587 PACKET_6BYTE_PACKET_NUMBER),
1892 expected_error, QUIC_INVALID_BLOCKED_DATA); 2588 expected_error, QUIC_INVALID_BLOCKED_DATA);
1893 } 2589 }
1894 } 2590 }
1895 2591
1896 TEST_P(QuicFramerTest, PingFrame) { 2592 TEST_P(QuicFramerTest, PingFrame) {
1897 // clang-format off 2593 // clang-format off
1898 unsigned char packet[] = { 2594 unsigned char packet[] = {
1899 // public flags (8 byte connection_id) 2595 // public flags (8 byte connection_id)
1900 0x38, 2596 0x38,
1901 // connection_id 2597 // connection_id
1902 0x10, 0x32, 0x54, 0x76, 2598 0x10, 0x32, 0x54, 0x76,
1903 0x98, 0xBA, 0xDC, 0xFE, 2599 0x98, 0xBA, 0xDC, 0xFE,
1904 // packet number 2600 // packet number
1905 0xBC, 0x9A, 0x78, 0x56, 2601 0xBC, 0x9A, 0x78, 0x56,
1906 0x34, 0x12, 2602 0x34, 0x12,
1907 2603
1908 // frame type (ping frame) 2604 // frame type (ping frame)
1909 0x07, 2605 0x07,
1910 }; 2606 };
2607
2608 unsigned char packet_cid_be[] = {
2609 // public flags (8 byte connection_id)
2610 0x38,
2611 // connection_id
2612 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
2613 // packet number
2614 0xBC, 0x9A, 0x78, 0x56,
2615 0x34, 0x12,
2616
2617 // frame type (ping frame)
2618 0x07,
2619 };
1911 // clang-format on 2620 // clang-format on
1912 2621
1913 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 2622 QuicEncryptedPacket encrypted(
2623 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
2624 ? packet_cid_be
2625 : packet),
2626 FLAGS_quic_restart_flag_quic_big_endian_connection_id
2627 ? arraysize(packet_cid_be)
2628 : arraysize(packet),
2629 false);
1914 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2630 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1915 2631
1916 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2632 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1917 ASSERT_TRUE(visitor_.header_.get()); 2633 ASSERT_TRUE(visitor_.header_.get());
1918 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, 2634 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion,
1919 !kIncludeDiversificationNonce)); 2635 !kIncludeDiversificationNonce));
1920 2636
1921 EXPECT_EQ(1u, visitor_.ping_frames_.size()); 2637 EXPECT_EQ(1u, visitor_.ping_frames_.size());
1922 2638
1923 // No need to check the PING frame boundaries because it has no payload. 2639 // No need to check the PING frame boundaries because it has no payload.
(...skipping 19 matching lines...) Expand all
1943 'R', 'S', 'E', 'Q', 2659 'R', 'S', 'E', 'Q',
1944 // end offset 16 2660 // end offset 16
1945 0x10, 0x00, 0x00, 0x00, 2661 0x10, 0x00, 0x00, 0x00,
1946 // nonce proof 2662 // nonce proof
1947 0x89, 0x67, 0x45, 0x23, 2663 0x89, 0x67, 0x45, 0x23,
1948 0x01, 0xEF, 0xCD, 0xAB, 2664 0x01, 0xEF, 0xCD, 0xAB,
1949 // rejected packet number 2665 // rejected packet number
1950 0xBC, 0x9A, 0x78, 0x56, 2666 0xBC, 0x9A, 0x78, 0x56,
1951 0x34, 0x12, 0x00, 0x00, 2667 0x34, 0x12, 0x00, 0x00,
1952 }; 2668 };
2669
2670 unsigned char packet_cid_be[] = {
2671 // public flags (public reset, 8 byte connection_id)
2672 0x0A,
2673 // connection_id
2674 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
2675 // message tag (kPRST)
2676 'P', 'R', 'S', 'T',
2677 // num_entries (2) + padding
2678 0x02, 0x00, 0x00, 0x00,
2679 // tag kRNON
2680 'R', 'N', 'O', 'N',
2681 // end offset 8
2682 0x08, 0x00, 0x00, 0x00,
2683 // tag kRSEQ
2684 'R', 'S', 'E', 'Q',
2685 // end offset 16
2686 0x10, 0x00, 0x00, 0x00,
2687 // nonce proof
2688 0x89, 0x67, 0x45, 0x23,
2689 0x01, 0xEF, 0xCD, 0xAB,
2690 // rejected packet number
2691 0xBC, 0x9A, 0x78, 0x56,
2692 0x34, 0x12, 0x00, 0x00,
2693 };
1953 // clang-format on 2694 // clang-format on
1954 2695
1955 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 2696 QuicEncryptedPacket encrypted(
2697 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
2698 ? packet_cid_be
2699 : packet),
2700 FLAGS_quic_restart_flag_quic_big_endian_connection_id
2701 ? arraysize(packet_cid_be)
2702 : arraysize(packet),
2703 false);
1956 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2704 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1957 ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); 2705 ASSERT_EQ(QUIC_NO_ERROR, framer_.error());
1958 ASSERT_TRUE(visitor_.public_reset_packet_.get()); 2706 ASSERT_TRUE(visitor_.public_reset_packet_.get());
1959 EXPECT_EQ(kConnectionId, 2707 EXPECT_EQ(kConnectionId,
1960 visitor_.public_reset_packet_->public_header.connection_id); 2708 visitor_.public_reset_packet_->public_header.connection_id);
1961 EXPECT_TRUE(visitor_.public_reset_packet_->public_header.reset_flag); 2709 EXPECT_TRUE(visitor_.public_reset_packet_->public_header.reset_flag);
1962 EXPECT_FALSE(visitor_.public_reset_packet_->public_header.version_flag); 2710 EXPECT_FALSE(visitor_.public_reset_packet_->public_header.version_flag);
1963 EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof); 2711 EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof);
1964 EXPECT_EQ(0u, visitor_.public_reset_packet_->rejected_packet_number); 2712 EXPECT_EQ(0u, visitor_.public_reset_packet_->rejected_packet_number);
1965 EXPECT_EQ( 2713 EXPECT_EQ(
1966 IpAddressFamily::IP_UNSPEC, 2714 IpAddressFamily::IP_UNSPEC,
1967 visitor_.public_reset_packet_->client_address.host().address_family()); 2715 visitor_.public_reset_packet_->client_address.host().address_family());
1968 2716
1969 // Now test framing boundaries. 2717 // Now test framing boundaries.
1970 for (size_t i = 0; i < arraysize(packet); ++i) { 2718 if (!FLAGS_quic_restart_flag_quic_big_endian_connection_id) {
2719 for (size_t i = 0; i < arraysize(packet); ++i) {
2720 string expected_error;
2721 QUIC_DLOG(INFO) << "iteration: " << i;
2722 if (i < kConnectionIdOffset) {
2723 expected_error = "Unable to read public flags.";
2724 CheckProcessingFails(packet, i, expected_error,
2725 QUIC_INVALID_PACKET_HEADER);
2726 } else if (i < kPublicResetPacketMessageTagOffset) {
2727 expected_error = "Unable to read ConnectionId.";
2728 CheckProcessingFails(packet, i, expected_error,
2729 QUIC_INVALID_PACKET_HEADER);
2730 } else {
2731 expected_error = "Unable to read reset message.";
2732 CheckProcessingFails(packet, i, expected_error,
2733 QUIC_INVALID_PUBLIC_RST_PACKET);
2734 }
2735 }
2736 return;
2737 }
2738
2739 for (size_t i = 0; i < arraysize(packet_cid_be); ++i) {
1971 string expected_error; 2740 string expected_error;
1972 QUIC_DLOG(INFO) << "iteration: " << i; 2741 QUIC_DLOG(INFO) << "iteration: " << i;
1973 if (i < kConnectionIdOffset) { 2742 if (i < kConnectionIdOffset) {
1974 expected_error = "Unable to read public flags."; 2743 expected_error = "Unable to read public flags.";
1975 CheckProcessingFails(packet, i, expected_error, 2744 CheckProcessingFails(packet_cid_be, i, expected_error,
1976 QUIC_INVALID_PACKET_HEADER); 2745 QUIC_INVALID_PACKET_HEADER);
1977 } else if (i < kPublicResetPacketMessageTagOffset) { 2746 } else if (i < kPublicResetPacketMessageTagOffset) {
1978 expected_error = "Unable to read ConnectionId."; 2747 expected_error = "Unable to read ConnectionId.";
1979 CheckProcessingFails(packet, i, expected_error, 2748 CheckProcessingFails(packet_cid_be, i, expected_error,
1980 QUIC_INVALID_PACKET_HEADER); 2749 QUIC_INVALID_PACKET_HEADER);
1981 } else { 2750 } else {
1982 expected_error = "Unable to read reset message."; 2751 expected_error = "Unable to read reset message.";
1983 CheckProcessingFails(packet, i, expected_error, 2752 CheckProcessingFails(packet_cid_be, i, expected_error,
1984 QUIC_INVALID_PUBLIC_RST_PACKET); 2753 QUIC_INVALID_PUBLIC_RST_PACKET);
1985 } 2754 }
1986 } 2755 }
1987 } 2756 }
1988 2757
1989 TEST_P(QuicFramerTest, PublicResetPacket) { 2758 TEST_P(QuicFramerTest, PublicResetPacket) {
1990 QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); 2759 QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT);
1991 2760
1992 // clang-format off 2761 // clang-format off
1993 unsigned char packet[] = { 2762 unsigned char packet[] = {
(...skipping 14 matching lines...) Expand all
2008 'R', 'S', 'E', 'Q', 2777 'R', 'S', 'E', 'Q',
2009 // end offset 16 2778 // end offset 16
2010 0x10, 0x00, 0x00, 0x00, 2779 0x10, 0x00, 0x00, 0x00,
2011 // nonce proof 2780 // nonce proof
2012 0x89, 0x67, 0x45, 0x23, 2781 0x89, 0x67, 0x45, 0x23,
2013 0x01, 0xEF, 0xCD, 0xAB, 2782 0x01, 0xEF, 0xCD, 0xAB,
2014 // rejected packet number 2783 // rejected packet number
2015 0xBC, 0x9A, 0x78, 0x56, 2784 0xBC, 0x9A, 0x78, 0x56,
2016 0x34, 0x12, 0x00, 0x00, 2785 0x34, 0x12, 0x00, 0x00,
2017 }; 2786 };
2787
2788 unsigned char packet_cid_be[] = {
2789 // public flags (public reset, 8 byte connection_id)
2790 0x0E,
2791 // connection_id
2792 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
2793 // message tag (kPRST)
2794 'P', 'R', 'S', 'T',
2795 // num_entries (2) + padding
2796 0x02, 0x00, 0x00, 0x00,
2797 // tag kRNON
2798 'R', 'N', 'O', 'N',
2799 // end offset 8
2800 0x08, 0x00, 0x00, 0x00,
2801 // tag kRSEQ
2802 'R', 'S', 'E', 'Q',
2803 // end offset 16
2804 0x10, 0x00, 0x00, 0x00,
2805 // nonce proof
2806 0x89, 0x67, 0x45, 0x23,
2807 0x01, 0xEF, 0xCD, 0xAB,
2808 // rejected packet number
2809 0xBC, 0x9A, 0x78, 0x56,
2810 0x34, 0x12, 0x00, 0x00,
2811 };
2018 // clang-format on 2812 // clang-format on
2019 2813
2020 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 2814 QuicEncryptedPacket encrypted(
2815 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
2816 ? packet_cid_be
2817 : packet),
2818 FLAGS_quic_restart_flag_quic_big_endian_connection_id
2819 ? arraysize(packet_cid_be)
2820 : arraysize(packet),
2821 false);
2021 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2822 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2022 ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); 2823 ASSERT_EQ(QUIC_NO_ERROR, framer_.error());
2023 ASSERT_TRUE(visitor_.public_reset_packet_.get()); 2824 ASSERT_TRUE(visitor_.public_reset_packet_.get());
2024 EXPECT_EQ(kConnectionId, 2825 EXPECT_EQ(kConnectionId,
2025 visitor_.public_reset_packet_->public_header.connection_id); 2826 visitor_.public_reset_packet_->public_header.connection_id);
2026 EXPECT_TRUE(visitor_.public_reset_packet_->public_header.reset_flag); 2827 EXPECT_TRUE(visitor_.public_reset_packet_->public_header.reset_flag);
2027 EXPECT_FALSE(visitor_.public_reset_packet_->public_header.version_flag); 2828 EXPECT_FALSE(visitor_.public_reset_packet_->public_header.version_flag);
2028 EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof); 2829 EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof);
2029 EXPECT_EQ(0u, visitor_.public_reset_packet_->rejected_packet_number); 2830 EXPECT_EQ(0u, visitor_.public_reset_packet_->rejected_packet_number);
2030 EXPECT_EQ( 2831 EXPECT_EQ(
2031 IpAddressFamily::IP_UNSPEC, 2832 IpAddressFamily::IP_UNSPEC,
2032 visitor_.public_reset_packet_->client_address.host().address_family()); 2833 visitor_.public_reset_packet_->client_address.host().address_family());
2033 2834
2034 // Now test framing boundaries. 2835 // Now test framing boundaries.
2035 for (size_t i = 0; i < arraysize(packet); ++i) { 2836 if (!FLAGS_quic_restart_flag_quic_big_endian_connection_id) {
2837 for (size_t i = 0; i < arraysize(packet); ++i) {
2838 string expected_error;
2839 QUIC_DLOG(INFO) << "iteration: " << i;
2840 if (i < kConnectionIdOffset) {
2841 expected_error = "Unable to read public flags.";
2842 CheckProcessingFails(packet, i, expected_error,
2843 QUIC_INVALID_PACKET_HEADER);
2844 } else if (i < kPublicResetPacketMessageTagOffset) {
2845 expected_error = "Unable to read ConnectionId.";
2846 CheckProcessingFails(packet, i, expected_error,
2847 QUIC_INVALID_PACKET_HEADER);
2848 } else {
2849 expected_error = "Unable to read reset message.";
2850 CheckProcessingFails(packet, i, expected_error,
2851 QUIC_INVALID_PUBLIC_RST_PACKET);
2852 }
2853 }
2854 return;
2855 }
2856
2857 for (size_t i = 0; i < arraysize(packet_cid_be); ++i) {
2036 string expected_error; 2858 string expected_error;
2037 QUIC_DLOG(INFO) << "iteration: " << i; 2859 QUIC_DLOG(INFO) << "iteration: " << i;
2038 if (i < kConnectionIdOffset) { 2860 if (i < kConnectionIdOffset) {
2039 expected_error = "Unable to read public flags."; 2861 expected_error = "Unable to read public flags.";
2040 CheckProcessingFails(packet, i, expected_error, 2862 CheckProcessingFails(packet_cid_be, i, expected_error,
2041 QUIC_INVALID_PACKET_HEADER); 2863 QUIC_INVALID_PACKET_HEADER);
2042 } else if (i < kPublicResetPacketMessageTagOffset) { 2864 } else if (i < kPublicResetPacketMessageTagOffset) {
2043 expected_error = "Unable to read ConnectionId."; 2865 expected_error = "Unable to read ConnectionId.";
2044 CheckProcessingFails(packet, i, expected_error, 2866 CheckProcessingFails(packet_cid_be, i, expected_error,
2045 QUIC_INVALID_PACKET_HEADER); 2867 QUIC_INVALID_PACKET_HEADER);
2046 } else { 2868 } else {
2047 expected_error = "Unable to read reset message."; 2869 expected_error = "Unable to read reset message.";
2048 CheckProcessingFails(packet, i, expected_error, 2870 CheckProcessingFails(packet_cid_be, i, expected_error,
2049 QUIC_INVALID_PUBLIC_RST_PACKET); 2871 QUIC_INVALID_PUBLIC_RST_PACKET);
2050 } 2872 }
2051 } 2873 }
2052 } 2874 }
2053 2875
2054 TEST_P(QuicFramerTest, PublicResetPacketWithTrailingJunk) { 2876 TEST_P(QuicFramerTest, PublicResetPacketWithTrailingJunk) {
2055 // clang-format off 2877 // clang-format off
2056 unsigned char packet[] = { 2878 unsigned char packet[] = {
2057 // public flags (public reset, 8 byte connection_id) 2879 // public flags (public reset, 8 byte connection_id)
2058 0x0A, 2880 0x0A,
(...skipping 14 matching lines...) Expand all
2073 0x10, 0x00, 0x00, 0x00, 2895 0x10, 0x00, 0x00, 0x00,
2074 // nonce proof 2896 // nonce proof
2075 0x89, 0x67, 0x45, 0x23, 2897 0x89, 0x67, 0x45, 0x23,
2076 0x01, 0xEF, 0xCD, 0xAB, 2898 0x01, 0xEF, 0xCD, 0xAB,
2077 // rejected packet number 2899 // rejected packet number
2078 0xBC, 0x9A, 0x78, 0x56, 2900 0xBC, 0x9A, 0x78, 0x56,
2079 0x34, 0x12, 0x00, 0x00, 2901 0x34, 0x12, 0x00, 0x00,
2080 // trailing junk 2902 // trailing junk
2081 'j', 'u', 'n', 'k', 2903 'j', 'u', 'n', 'k',
2082 }; 2904 };
2905
2906 unsigned char packet_cid_be[] = {
2907 // public flags (public reset, 8 byte connection_id)
2908 0x0A,
2909 // connection_id
2910 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
2911 // message tag (kPRST)
2912 'P', 'R', 'S', 'T',
2913 // num_entries (2) + padding
2914 0x02, 0x00, 0x00, 0x00,
2915 // tag kRNON
2916 'R', 'N', 'O', 'N',
2917 // end offset 8
2918 0x08, 0x00, 0x00, 0x00,
2919 // tag kRSEQ
2920 'R', 'S', 'E', 'Q',
2921 // end offset 16
2922 0x10, 0x00, 0x00, 0x00,
2923 // nonce proof
2924 0x89, 0x67, 0x45, 0x23,
2925 0x01, 0xEF, 0xCD, 0xAB,
2926 // rejected packet number
2927 0xBC, 0x9A, 0x78, 0x56,
2928 0x34, 0x12, 0x00, 0x00,
2929 // trailing junk
2930 'j', 'u', 'n', 'k',
2931 };
2083 // clang-format on 2932 // clang-format on
2084 2933
2085 string expected_error = "Unable to read reset message."; 2934 string expected_error = "Unable to read reset message.";
2086 CheckProcessingFails(packet, arraysize(packet), expected_error, 2935 CheckProcessingFails(FLAGS_quic_restart_flag_quic_big_endian_connection_id
2087 QUIC_INVALID_PUBLIC_RST_PACKET); 2936 ? packet_cid_be
2937 : packet,
2938 FLAGS_quic_restart_flag_quic_big_endian_connection_id
2939 ? arraysize(packet_cid_be)
2940 : arraysize(packet),
2941 expected_error, QUIC_INVALID_PUBLIC_RST_PACKET);
2088 } 2942 }
2089 2943
2090 TEST_P(QuicFramerTest, PublicResetPacketWithClientAddress) { 2944 TEST_P(QuicFramerTest, PublicResetPacketWithClientAddress) {
2091 // clang-format off 2945 // clang-format off
2092 unsigned char packet[] = { 2946 unsigned char packet[] = {
2093 // public flags (public reset, 8 byte connection_id) 2947 // public flags (public reset, 8 byte connection_id)
2094 0x0A, 2948 0x0A,
2095 // connection_id 2949 // connection_id
2096 0x10, 0x32, 0x54, 0x76, 2950 0x10, 0x32, 0x54, 0x76,
2097 0x98, 0xBA, 0xDC, 0xFE, 2951 0x98, 0xBA, 0xDC, 0xFE,
(...skipping 17 matching lines...) Expand all
2115 0x89, 0x67, 0x45, 0x23, 2969 0x89, 0x67, 0x45, 0x23,
2116 0x01, 0xEF, 0xCD, 0xAB, 2970 0x01, 0xEF, 0xCD, 0xAB,
2117 // rejected packet number 2971 // rejected packet number
2118 0xBC, 0x9A, 0x78, 0x56, 2972 0xBC, 0x9A, 0x78, 0x56,
2119 0x34, 0x12, 0x00, 0x00, 2973 0x34, 0x12, 0x00, 0x00,
2120 // client address: 4.31.198.44:443 2974 // client address: 4.31.198.44:443
2121 0x02, 0x00, 2975 0x02, 0x00,
2122 0x04, 0x1F, 0xC6, 0x2C, 2976 0x04, 0x1F, 0xC6, 0x2C,
2123 0xBB, 0x01, 2977 0xBB, 0x01,
2124 }; 2978 };
2979
2980 unsigned char packet_cid_be[] = {
2981 // public flags (public reset, 8 byte connection_id)
2982 0x0A,
2983 // connection_id
2984 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
2985 // message tag (kPRST)
2986 'P', 'R', 'S', 'T',
2987 // num_entries (3) + padding
2988 0x03, 0x00, 0x00, 0x00,
2989 // tag kRNON
2990 'R', 'N', 'O', 'N',
2991 // end offset 8
2992 0x08, 0x00, 0x00, 0x00,
2993 // tag kRSEQ
2994 'R', 'S', 'E', 'Q',
2995 // end offset 16
2996 0x10, 0x00, 0x00, 0x00,
2997 // tag kCADR
2998 'C', 'A', 'D', 'R',
2999 // end offset 24
3000 0x18, 0x00, 0x00, 0x00,
3001 // nonce proof
3002 0x89, 0x67, 0x45, 0x23,
3003 0x01, 0xEF, 0xCD, 0xAB,
3004 // rejected packet number
3005 0xBC, 0x9A, 0x78, 0x56,
3006 0x34, 0x12, 0x00, 0x00,
3007 // client address: 4.31.198.44:443
3008 0x02, 0x00,
3009 0x04, 0x1F, 0xC6, 0x2C,
3010 0xBB, 0x01,
3011 };
2125 // clang-format on 3012 // clang-format on
2126 3013
2127 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 3014 QuicEncryptedPacket encrypted(
3015 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
3016 ? packet_cid_be
3017 : packet),
3018 FLAGS_quic_restart_flag_quic_big_endian_connection_id
3019 ? arraysize(packet_cid_be)
3020 : arraysize(packet),
3021 false);
2128 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 3022 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2129 ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); 3023 ASSERT_EQ(QUIC_NO_ERROR, framer_.error());
2130 ASSERT_TRUE(visitor_.public_reset_packet_.get()); 3024 ASSERT_TRUE(visitor_.public_reset_packet_.get());
2131 EXPECT_EQ(kConnectionId, 3025 EXPECT_EQ(kConnectionId,
2132 visitor_.public_reset_packet_->public_header.connection_id); 3026 visitor_.public_reset_packet_->public_header.connection_id);
2133 EXPECT_TRUE(visitor_.public_reset_packet_->public_header.reset_flag); 3027 EXPECT_TRUE(visitor_.public_reset_packet_->public_header.reset_flag);
2134 EXPECT_FALSE(visitor_.public_reset_packet_->public_header.version_flag); 3028 EXPECT_FALSE(visitor_.public_reset_packet_->public_header.version_flag);
2135 EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof); 3029 EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof);
2136 EXPECT_EQ(0u, visitor_.public_reset_packet_->rejected_packet_number); 3030 EXPECT_EQ(0u, visitor_.public_reset_packet_->rejected_packet_number);
2137 EXPECT_EQ("4.31.198.44", 3031 EXPECT_EQ("4.31.198.44",
2138 visitor_.public_reset_packet_->client_address.host().ToString()); 3032 visitor_.public_reset_packet_->client_address.host().ToString());
2139 EXPECT_EQ(443, visitor_.public_reset_packet_->client_address.port()); 3033 EXPECT_EQ(443, visitor_.public_reset_packet_->client_address.port());
2140 3034
2141 // Now test framing boundaries. 3035 // Now test framing boundaries.
2142 for (size_t i = 0; i < arraysize(packet); ++i) { 3036 if (!FLAGS_quic_restart_flag_quic_big_endian_connection_id) {
3037 for (size_t i = 0; i < arraysize(packet); ++i) {
3038 string expected_error;
3039 QUIC_DLOG(INFO) << "iteration: " << i;
3040 if (i < kConnectionIdOffset) {
3041 expected_error = "Unable to read public flags.";
3042 CheckProcessingFails(packet, i, expected_error,
3043 QUIC_INVALID_PACKET_HEADER);
3044 } else if (i < kPublicResetPacketMessageTagOffset) {
3045 expected_error = "Unable to read ConnectionId.";
3046 CheckProcessingFails(packet, i, expected_error,
3047 QUIC_INVALID_PACKET_HEADER);
3048 } else {
3049 expected_error = "Unable to read reset message.";
3050 CheckProcessingFails(packet, i, expected_error,
3051 QUIC_INVALID_PUBLIC_RST_PACKET);
3052 }
3053 }
3054 return;
3055 }
3056
3057 for (size_t i = 0; i < arraysize(packet_cid_be); ++i) {
2143 string expected_error; 3058 string expected_error;
2144 QUIC_DLOG(INFO) << "iteration: " << i; 3059 QUIC_DLOG(INFO) << "iteration: " << i;
2145 if (i < kConnectionIdOffset) { 3060 if (i < kConnectionIdOffset) {
2146 expected_error = "Unable to read public flags."; 3061 expected_error = "Unable to read public flags.";
2147 CheckProcessingFails(packet, i, expected_error, 3062 CheckProcessingFails(packet_cid_be, i, expected_error,
2148 QUIC_INVALID_PACKET_HEADER); 3063 QUIC_INVALID_PACKET_HEADER);
2149 } else if (i < kPublicResetPacketMessageTagOffset) { 3064 } else if (i < kPublicResetPacketMessageTagOffset) {
2150 expected_error = "Unable to read ConnectionId."; 3065 expected_error = "Unable to read ConnectionId.";
2151 CheckProcessingFails(packet, i, expected_error, 3066 CheckProcessingFails(packet_cid_be, i, expected_error,
2152 QUIC_INVALID_PACKET_HEADER); 3067 QUIC_INVALID_PACKET_HEADER);
2153 } else { 3068 } else {
2154 expected_error = "Unable to read reset message."; 3069 expected_error = "Unable to read reset message.";
2155 CheckProcessingFails(packet, i, expected_error, 3070 CheckProcessingFails(packet_cid_be, i, expected_error,
2156 QUIC_INVALID_PUBLIC_RST_PACKET); 3071 QUIC_INVALID_PUBLIC_RST_PACKET);
2157 } 3072 }
2158 } 3073 }
2159 } 3074 }
2160 3075
2161 TEST_P(QuicFramerTest, VersionNegotiationPacket) { 3076 TEST_P(QuicFramerTest, VersionNegotiationPacket) {
2162 // clang-format off 3077 // clang-format off
2163 unsigned char packet[] = { 3078 unsigned char packet[] = {
2164 // public flags (version, 8 byte connection_id) 3079 // public flags (version, 8 byte connection_id)
2165 0x39, 3080 0x39,
2166 // connection_id 3081 // connection_id
2167 0x10, 0x32, 0x54, 0x76, 3082 0x10, 0x32, 0x54, 0x76,
2168 0x98, 0xBA, 0xDC, 0xFE, 3083 0x98, 0xBA, 0xDC, 0xFE,
2169 // version tag 3084 // version tag
2170 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), 3085 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
2171 'Q', '2', '.', '0', 3086 'Q', '2', '.', '0',
2172 }; 3087 };
3088
3089 unsigned char packet_cid_be[] = {
3090 // public flags (version, 8 byte connection_id)
3091 0x39,
3092 // connection_id
3093 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
3094 // version tag
3095 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
3096 'Q', '2', '.', '0',
3097 };
2173 // clang-format on 3098 // clang-format on
2174 3099
2175 QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); 3100 QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT);
2176 3101
2177 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 3102 QuicEncryptedPacket encrypted(
3103 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
3104 ? packet_cid_be
3105 : packet),
3106 FLAGS_quic_restart_flag_quic_big_endian_connection_id
3107 ? arraysize(packet_cid_be)
3108 : arraysize(packet),
3109 false);
2178 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 3110 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2179 ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); 3111 ASSERT_EQ(QUIC_NO_ERROR, framer_.error());
2180 ASSERT_TRUE(visitor_.version_negotiation_packet_.get()); 3112 ASSERT_TRUE(visitor_.version_negotiation_packet_.get());
2181 EXPECT_EQ(2u, visitor_.version_negotiation_packet_->versions.size()); 3113 EXPECT_EQ(2u, visitor_.version_negotiation_packet_->versions.size());
2182 EXPECT_EQ(GetParam(), visitor_.version_negotiation_packet_->versions[0]); 3114 EXPECT_EQ(GetParam(), visitor_.version_negotiation_packet_->versions[0]);
2183 3115
2184 for (size_t i = 0; i <= kPublicFlagsSize + PACKET_8BYTE_CONNECTION_ID; ++i) { 3116 for (size_t i = 0; i <= kPublicFlagsSize + PACKET_8BYTE_CONNECTION_ID; ++i) {
2185 string expected_error; 3117 string expected_error;
2186 QuicErrorCode error_code = QUIC_INVALID_PACKET_HEADER; 3118 QuicErrorCode error_code = QUIC_INVALID_PACKET_HEADER;
2187 if (i < kConnectionIdOffset) { 3119 if (i < kConnectionIdOffset) {
2188 expected_error = "Unable to read public flags."; 3120 expected_error = "Unable to read public flags.";
2189 } else if (i < kVersionOffset) { 3121 } else if (i < kVersionOffset) {
2190 expected_error = "Unable to read ConnectionId."; 3122 expected_error = "Unable to read ConnectionId.";
2191 } else { 3123 } else {
2192 expected_error = "Unable to read supported version in negotiation."; 3124 expected_error = "Unable to read supported version in negotiation.";
2193 error_code = QUIC_INVALID_VERSION_NEGOTIATION_PACKET; 3125 error_code = QUIC_INVALID_VERSION_NEGOTIATION_PACKET;
2194 } 3126 }
2195 CheckProcessingFails(packet, i, expected_error, error_code); 3127 CheckProcessingFails(FLAGS_quic_restart_flag_quic_big_endian_connection_id
3128 ? packet_cid_be
3129 : packet,
3130 i, expected_error, error_code);
2196 } 3131 }
2197 } 3132 }
2198 3133
2199 TEST_P(QuicFramerTest, OldVersionNegotiationPacket) { 3134 TEST_P(QuicFramerTest, OldVersionNegotiationPacket) {
2200 // clang-format off 3135 // clang-format off
2201 unsigned char packet[] = { 3136 unsigned char packet[] = {
2202 // public flags (version, 8 byte connection_id) 3137 // public flags (version, 8 byte connection_id)
2203 0x3D, 3138 0x3D,
2204 // connection_id 3139 // connection_id
2205 0x10, 0x32, 0x54, 0x76, 3140 0x10, 0x32, 0x54, 0x76,
2206 0x98, 0xBA, 0xDC, 0xFE, 3141 0x98, 0xBA, 0xDC, 0xFE,
2207 // version tag 3142 // version tag
2208 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), 3143 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
2209 'Q', '2', '.', '0', 3144 'Q', '2', '.', '0',
2210 }; 3145 };
3146
3147 unsigned char packet_cid_be[] = {
3148 // public flags (version, 8 byte connection_id)
3149 0x3D,
3150 // connection_id
3151 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
3152 // version tag
3153 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
3154 'Q', '2', '.', '0',
3155 };
2211 // clang-format on 3156 // clang-format on
2212 3157
2213 QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); 3158 QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT);
2214 3159
2215 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 3160 QuicEncryptedPacket encrypted(
3161 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
3162 ? packet_cid_be
3163 : packet),
3164 FLAGS_quic_restart_flag_quic_big_endian_connection_id
3165 ? arraysize(packet_cid_be)
3166 : arraysize(packet),
3167 false);
2216 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 3168 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2217 ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); 3169 ASSERT_EQ(QUIC_NO_ERROR, framer_.error());
2218 ASSERT_TRUE(visitor_.version_negotiation_packet_.get()); 3170 ASSERT_TRUE(visitor_.version_negotiation_packet_.get());
2219 EXPECT_EQ(2u, visitor_.version_negotiation_packet_->versions.size()); 3171 EXPECT_EQ(2u, visitor_.version_negotiation_packet_->versions.size());
2220 EXPECT_EQ(GetParam(), visitor_.version_negotiation_packet_->versions[0]); 3172 EXPECT_EQ(GetParam(), visitor_.version_negotiation_packet_->versions[0]);
2221 3173
2222 for (size_t i = 0; i <= kPublicFlagsSize + PACKET_8BYTE_CONNECTION_ID; ++i) { 3174 for (size_t i = 0; i <= kPublicFlagsSize + PACKET_8BYTE_CONNECTION_ID; ++i) {
2223 string expected_error; 3175 string expected_error;
2224 QuicErrorCode error_code = QUIC_INVALID_PACKET_HEADER; 3176 QuicErrorCode error_code = QUIC_INVALID_PACKET_HEADER;
2225 if (i < kConnectionIdOffset) { 3177 if (i < kConnectionIdOffset) {
2226 expected_error = "Unable to read public flags."; 3178 expected_error = "Unable to read public flags.";
2227 } else if (i < kVersionOffset) { 3179 } else if (i < kVersionOffset) {
2228 expected_error = "Unable to read ConnectionId."; 3180 expected_error = "Unable to read ConnectionId.";
2229 } else { 3181 } else {
2230 expected_error = "Unable to read supported version in negotiation."; 3182 expected_error = "Unable to read supported version in negotiation.";
2231 error_code = QUIC_INVALID_VERSION_NEGOTIATION_PACKET; 3183 error_code = QUIC_INVALID_VERSION_NEGOTIATION_PACKET;
2232 } 3184 }
2233 CheckProcessingFails(packet, i, expected_error, error_code); 3185 CheckProcessingFails(FLAGS_quic_restart_flag_quic_big_endian_connection_id
3186 ? packet_cid_be
3187 : packet,
3188 i, expected_error, error_code);
2234 } 3189 }
2235 } 3190 }
2236 3191
2237 TEST_P(QuicFramerTest, BuildPaddingFramePacket) { 3192 TEST_P(QuicFramerTest, BuildPaddingFramePacket) {
2238 QuicPacketHeader header; 3193 QuicPacketHeader header;
2239 header.public_header.connection_id = kConnectionId; 3194 header.public_header.connection_id = kConnectionId;
2240 header.public_header.reset_flag = false; 3195 header.public_header.reset_flag = false;
2241 header.public_header.version_flag = false; 3196 header.public_header.version_flag = false;
2242 header.packet_number = kPacketNumber; 3197 header.packet_number = kPacketNumber;
2243 3198
2244 QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; 3199 QuicFrames frames = {QuicFrame(QuicPaddingFrame())};
2245 3200
2246 // clang-format off 3201 // clang-format off
2247 unsigned char packet[kMaxPacketSize] = { 3202 unsigned char packet[kMaxPacketSize] = {
2248 // public flags (8 byte connection_id) 3203 // public flags (8 byte connection_id)
2249 0x38, 3204 0x38,
2250 // connection_id 3205 // connection_id
2251 0x10, 0x32, 0x54, 0x76, 3206 0x10, 0x32, 0x54, 0x76,
2252 0x98, 0xBA, 0xDC, 0xFE, 3207 0x98, 0xBA, 0xDC, 0xFE,
2253 // packet number 3208 // packet number
2254 0xBC, 0x9A, 0x78, 0x56, 3209 0xBC, 0x9A, 0x78, 0x56,
2255 0x34, 0x12, 3210 0x34, 0x12,
2256 3211
2257 // frame type (padding frame) 3212 // frame type (padding frame)
2258 0x00, 3213 0x00,
2259 0x00, 0x00, 0x00, 0x00 3214 0x00, 0x00, 0x00, 0x00
2260 }; 3215 };
3216
3217 unsigned char packet_cid_be[kMaxPacketSize] = {
3218 // public flags (8 byte connection_id)
3219 0x38,
3220 // connection_id
3221 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
3222 // packet number
3223 0xBC, 0x9A, 0x78, 0x56,
3224 0x34, 0x12,
3225
3226 // frame type (padding frame)
3227 0x00,
3228 0x00, 0x00, 0x00, 0x00
3229 };
2261 // clang-format on 3230 // clang-format on
2262 3231
2263 uint64_t header_size = GetPacketHeaderSize( 3232 uint64_t header_size = GetPacketHeaderSize(
2264 framer_.version(), PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 3233 framer_.version(), PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
2265 !kIncludeDiversificationNonce, PACKET_6BYTE_PACKET_NUMBER); 3234 !kIncludeDiversificationNonce, PACKET_6BYTE_PACKET_NUMBER);
2266 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1); 3235 memset((FLAGS_quic_restart_flag_quic_big_endian_connection_id ? packet_cid_be
3236 : packet) +
3237 header_size + 1,
3238 0x00, kMaxPacketSize - header_size - 1);
2267 3239
2268 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 3240 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames));
2269 ASSERT_TRUE(data != nullptr); 3241 ASSERT_TRUE(data != nullptr);
2270 3242
2271 test::CompareCharArraysWithHexError("constructed packet", data->data(), 3243 test::CompareCharArraysWithHexError(
2272 data->length(), AsChars(packet), 3244 "constructed packet", data->data(), data->length(),
2273 arraysize(packet)); 3245 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
3246 ? packet_cid_be
3247 : packet),
3248 FLAGS_quic_restart_flag_quic_big_endian_connection_id
3249 ? arraysize(packet_cid_be)
3250 : arraysize(packet));
2274 } 3251 }
2275 3252
2276 TEST_P(QuicFramerTest, Build4ByteSequenceNumberPaddingFramePacket) { 3253 TEST_P(QuicFramerTest, Build4ByteSequenceNumberPaddingFramePacket) {
2277 QuicPacketHeader header; 3254 QuicPacketHeader header;
2278 header.public_header.connection_id = kConnectionId; 3255 header.public_header.connection_id = kConnectionId;
2279 header.public_header.reset_flag = false; 3256 header.public_header.reset_flag = false;
2280 header.public_header.version_flag = false; 3257 header.public_header.version_flag = false;
2281 header.public_header.packet_number_length = PACKET_4BYTE_PACKET_NUMBER; 3258 header.public_header.packet_number_length = PACKET_4BYTE_PACKET_NUMBER;
2282 header.packet_number = kPacketNumber; 3259 header.packet_number = kPacketNumber;
2283 3260
2284 QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; 3261 QuicFrames frames = {QuicFrame(QuicPaddingFrame())};
2285 3262
2286 // clang-format off 3263 // clang-format off
2287 unsigned char packet[kMaxPacketSize] = { 3264 unsigned char packet[kMaxPacketSize] = {
2288 // public flags (8 byte connection_id and 4 byte packet number) 3265 // public flags (8 byte connection_id and 4 byte packet number)
2289 0x28, 3266 0x28,
2290 // connection_id 3267 // connection_id
2291 0x10, 0x32, 0x54, 0x76, 3268 0x10, 0x32, 0x54, 0x76,
2292 0x98, 0xBA, 0xDC, 0xFE, 3269 0x98, 0xBA, 0xDC, 0xFE,
2293 // packet number 3270 // packet number
2294 0xBC, 0x9A, 0x78, 0x56, 3271 0xBC, 0x9A, 0x78, 0x56,
2295 3272
2296 // frame type (padding frame) 3273 // frame type (padding frame)
2297 0x00, 3274 0x00,
2298 0x00, 0x00, 0x00, 0x00 3275 0x00, 0x00, 0x00, 0x00
2299 }; 3276 };
3277
3278 unsigned char packet_cid_be[kMaxPacketSize] = {
3279 // public flags (8 byte connection_id and 4 byte packet number)
3280 0x28,
3281 // connection_id
3282 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
3283 // packet number
3284 0xBC, 0x9A, 0x78, 0x56,
3285
3286 // frame type (padding frame)
3287 0x00,
3288 0x00, 0x00, 0x00, 0x00
3289 };
2300 // clang-format on 3290 // clang-format on
2301 3291
2302 uint64_t header_size = GetPacketHeaderSize( 3292 uint64_t header_size = GetPacketHeaderSize(
2303 framer_.version(), PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 3293 framer_.version(), PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
2304 !kIncludeDiversificationNonce, PACKET_4BYTE_PACKET_NUMBER); 3294 !kIncludeDiversificationNonce, PACKET_4BYTE_PACKET_NUMBER);
2305 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1); 3295 memset((FLAGS_quic_restart_flag_quic_big_endian_connection_id ? packet_cid_be
3296 : packet) +
3297 header_size + 1,
3298 0x00, kMaxPacketSize - header_size - 1);
2306 3299
2307 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 3300 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames));
2308 ASSERT_TRUE(data != nullptr); 3301 ASSERT_TRUE(data != nullptr);
2309 3302
2310 test::CompareCharArraysWithHexError("constructed packet", data->data(), 3303 test::CompareCharArraysWithHexError(
2311 data->length(), AsChars(packet), 3304 "constructed packet", data->data(), data->length(),
2312 arraysize(packet)); 3305 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
3306 ? packet_cid_be
3307 : packet),
3308 FLAGS_quic_restart_flag_quic_big_endian_connection_id
3309 ? arraysize(packet_cid_be)
3310 : arraysize(packet));
2313 } 3311 }
2314 3312
2315 TEST_P(QuicFramerTest, Build2ByteSequenceNumberPaddingFramePacket) { 3313 TEST_P(QuicFramerTest, Build2ByteSequenceNumberPaddingFramePacket) {
2316 QuicPacketHeader header; 3314 QuicPacketHeader header;
2317 header.public_header.connection_id = kConnectionId; 3315 header.public_header.connection_id = kConnectionId;
2318 header.public_header.reset_flag = false; 3316 header.public_header.reset_flag = false;
2319 header.public_header.version_flag = false; 3317 header.public_header.version_flag = false;
2320 header.public_header.packet_number_length = PACKET_2BYTE_PACKET_NUMBER; 3318 header.public_header.packet_number_length = PACKET_2BYTE_PACKET_NUMBER;
2321 header.packet_number = kPacketNumber; 3319 header.packet_number = kPacketNumber;
2322 3320
2323 QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; 3321 QuicFrames frames = {QuicFrame(QuicPaddingFrame())};
2324 3322
2325 // clang-format off 3323 // clang-format off
2326 unsigned char packet[kMaxPacketSize] = { 3324 unsigned char packet[kMaxPacketSize] = {
2327 // public flags (8 byte connection_id and 2 byte packet number) 3325 // public flags (8 byte connection_id and 2 byte packet number)
2328 0x18, 3326 0x18,
2329 // connection_id 3327 // connection_id
2330 0x10, 0x32, 0x54, 0x76, 3328 0x10, 0x32, 0x54, 0x76,
2331 0x98, 0xBA, 0xDC, 0xFE, 3329 0x98, 0xBA, 0xDC, 0xFE,
2332 // packet number 3330 // packet number
2333 0xBC, 0x9A, 3331 0xBC, 0x9A,
2334 3332
2335 // frame type (padding frame) 3333 // frame type (padding frame)
2336 0x00, 3334 0x00,
2337 0x00, 0x00, 0x00, 0x00 3335 0x00, 0x00, 0x00, 0x00
2338 }; 3336 };
3337
3338 unsigned char packet_cid_be[kMaxPacketSize] = {
3339 // public flags (8 byte connection_id and 2 byte packet number)
3340 0x18,
3341 // connection_id
3342 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
3343 // packet number
3344 0xBC, 0x9A,
3345
3346 // frame type (padding frame)
3347 0x00,
3348 0x00, 0x00, 0x00, 0x00
3349 };
2339 // clang-format on 3350 // clang-format on
2340 3351
2341 uint64_t header_size = GetPacketHeaderSize( 3352 uint64_t header_size = GetPacketHeaderSize(
2342 framer_.version(), PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 3353 framer_.version(), PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
2343 !kIncludeDiversificationNonce, PACKET_2BYTE_PACKET_NUMBER); 3354 !kIncludeDiversificationNonce, PACKET_2BYTE_PACKET_NUMBER);
2344 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1); 3355 memset((FLAGS_quic_restart_flag_quic_big_endian_connection_id ? packet_cid_be
3356 : packet) +
3357 header_size + 1,
3358 0x00, kMaxPacketSize - header_size - 1);
2345 3359
2346 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 3360 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames));
2347 ASSERT_TRUE(data != nullptr); 3361 ASSERT_TRUE(data != nullptr);
2348 3362
2349 test::CompareCharArraysWithHexError("constructed packet", data->data(), 3363 test::CompareCharArraysWithHexError(
2350 data->length(), AsChars(packet), 3364 "constructed packet", data->data(), data->length(),
2351 arraysize(packet)); 3365 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
3366 ? packet_cid_be
3367 : packet),
3368 FLAGS_quic_restart_flag_quic_big_endian_connection_id
3369 ? arraysize(packet_cid_be)
3370 : arraysize(packet));
2352 } 3371 }
2353 3372
2354 TEST_P(QuicFramerTest, Build1ByteSequenceNumberPaddingFramePacket) { 3373 TEST_P(QuicFramerTest, Build1ByteSequenceNumberPaddingFramePacket) {
2355 QuicPacketHeader header; 3374 QuicPacketHeader header;
2356 header.public_header.connection_id = kConnectionId; 3375 header.public_header.connection_id = kConnectionId;
2357 header.public_header.reset_flag = false; 3376 header.public_header.reset_flag = false;
2358 header.public_header.version_flag = false; 3377 header.public_header.version_flag = false;
2359 header.public_header.packet_number_length = PACKET_1BYTE_PACKET_NUMBER; 3378 header.public_header.packet_number_length = PACKET_1BYTE_PACKET_NUMBER;
2360 header.packet_number = kPacketNumber; 3379 header.packet_number = kPacketNumber;
2361 3380
2362 QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; 3381 QuicFrames frames = {QuicFrame(QuicPaddingFrame())};
2363 3382
2364 // clang-format off 3383 // clang-format off
2365 unsigned char packet[kMaxPacketSize] = { 3384 unsigned char packet[kMaxPacketSize] = {
2366 // public flags (8 byte connection_id and 1 byte packet number) 3385 // public flags (8 byte connection_id and 1 byte packet number)
2367 0x08, 3386 0x08,
2368 // connection_id 3387 // connection_id
2369 0x10, 0x32, 0x54, 0x76, 3388 0x10, 0x32, 0x54, 0x76,
2370 0x98, 0xBA, 0xDC, 0xFE, 3389 0x98, 0xBA, 0xDC, 0xFE,
2371 // packet number 3390 // packet number
2372 0xBC, 3391 0xBC,
2373 3392
2374 // frame type (padding frame) 3393 // frame type (padding frame)
2375 0x00, 3394 0x00,
2376 0x00, 0x00, 0x00, 0x00 3395 0x00, 0x00, 0x00, 0x00
2377 }; 3396 };
3397
3398 unsigned char packet_cid_be[kMaxPacketSize] = {
3399 // public flags (8 byte connection_id and 1 byte packet number)
3400 0x08,
3401 // connection_id
3402 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
3403 // packet number
3404 0xBC,
3405
3406 // frame type (padding frame)
3407 0x00,
3408 0x00, 0x00, 0x00, 0x00
3409 };
2378 // clang-format on 3410 // clang-format on
2379 3411
2380 uint64_t header_size = GetPacketHeaderSize( 3412 uint64_t header_size = GetPacketHeaderSize(
2381 framer_.version(), PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 3413 framer_.version(), PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
2382 !kIncludeDiversificationNonce, PACKET_1BYTE_PACKET_NUMBER); 3414 !kIncludeDiversificationNonce, PACKET_1BYTE_PACKET_NUMBER);
2383 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1); 3415 memset((FLAGS_quic_restart_flag_quic_big_endian_connection_id ? packet_cid_be
3416 : packet) +
3417 header_size + 1,
3418 0x00, kMaxPacketSize - header_size - 1);
2384 3419
2385 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 3420 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames));
2386 ASSERT_TRUE(data != nullptr); 3421 ASSERT_TRUE(data != nullptr);
2387 3422
2388 test::CompareCharArraysWithHexError("constructed packet", data->data(), 3423 test::CompareCharArraysWithHexError(
2389 data->length(), AsChars(packet), 3424 "constructed packet", data->data(), data->length(),
2390 arraysize(packet)); 3425 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
3426 ? packet_cid_be
3427 : packet),
3428 FLAGS_quic_restart_flag_quic_big_endian_connection_id
3429 ? arraysize(packet_cid_be)
3430 : arraysize(packet));
2391 } 3431 }
2392 3432
2393 TEST_P(QuicFramerTest, BuildStreamFramePacket) { 3433 TEST_P(QuicFramerTest, BuildStreamFramePacket) {
2394 QuicPacketHeader header; 3434 QuicPacketHeader header;
2395 header.public_header.connection_id = kConnectionId; 3435 header.public_header.connection_id = kConnectionId;
2396 header.public_header.reset_flag = false; 3436 header.public_header.reset_flag = false;
2397 header.public_header.version_flag = false; 3437 header.public_header.version_flag = false;
2398 header.packet_number = kPacketNumber; 3438 header.packet_number = kPacketNumber;
2399 3439
2400 QuicStreamFrame stream_frame(kStreamId, true, kStreamOffset, 3440 QuicStreamFrame stream_frame(kStreamId, true, kStreamOffset,
(...skipping 17 matching lines...) Expand all
2418 // stream id 3458 // stream id
2419 0x04, 0x03, 0x02, 0x01, 3459 0x04, 0x03, 0x02, 0x01,
2420 // offset 3460 // offset
2421 0x54, 0x76, 0x10, 0x32, 3461 0x54, 0x76, 0x10, 0x32,
2422 0xDC, 0xFE, 0x98, 0xBA, 3462 0xDC, 0xFE, 0x98, 0xBA,
2423 // data 3463 // data
2424 'h', 'e', 'l', 'l', 3464 'h', 'e', 'l', 'l',
2425 'o', ' ', 'w', 'o', 3465 'o', ' ', 'w', 'o',
2426 'r', 'l', 'd', '!', 3466 'r', 'l', 'd', '!',
2427 }; 3467 };
3468
3469 unsigned char packet_cid_be[] = {
3470 // public flags (8 byte connection_id)
3471 0x38,
3472 // connection_id
3473 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
3474 // packet number
3475 0xBC, 0x9A, 0x78, 0x56,
3476 0x34, 0x12,
3477
3478 // frame type (stream frame with fin and no length)
3479 0xDF,
3480 // stream id
3481 0x04, 0x03, 0x02, 0x01,
3482 // offset
3483 0x54, 0x76, 0x10, 0x32,
3484 0xDC, 0xFE, 0x98, 0xBA,
3485 // data
3486 'h', 'e', 'l', 'l',
3487 'o', ' ', 'w', 'o',
3488 'r', 'l', 'd', '!',
3489 };
2428 // clang-format on 3490 // clang-format on
2429 3491
2430 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 3492 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames));
2431 ASSERT_TRUE(data != nullptr); 3493 ASSERT_TRUE(data != nullptr);
2432 3494
2433 test::CompareCharArraysWithHexError("constructed packet", data->data(), 3495 test::CompareCharArraysWithHexError(
2434 data->length(), AsChars(packet), 3496 "constructed packet", data->data(), data->length(),
2435 arraysize(packet)); 3497 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
3498 ? packet_cid_be
3499 : packet),
3500 FLAGS_quic_restart_flag_quic_big_endian_connection_id
3501 ? arraysize(packet_cid_be)
3502 : arraysize(packet));
2436 } 3503 }
2437 3504
2438 TEST_P(QuicFramerTest, BuildStreamFramePacketWithVersionFlag) { 3505 TEST_P(QuicFramerTest, BuildStreamFramePacketWithVersionFlag) {
2439 QuicPacketHeader header; 3506 QuicPacketHeader header;
2440 header.public_header.connection_id = kConnectionId; 3507 header.public_header.connection_id = kConnectionId;
2441 header.public_header.reset_flag = false; 3508 header.public_header.reset_flag = false;
2442 header.public_header.version_flag = true; 3509 header.public_header.version_flag = true;
2443 header.packet_number = kPacketNumber; 3510 header.packet_number = kPacketNumber;
2444 3511
2445 QuicStreamFrame stream_frame(kStreamId, true, kStreamOffset, 3512 QuicStreamFrame stream_frame(kStreamId, true, kStreamOffset,
2446 QuicStringPiece("hello world!")); 3513 QuicStringPiece("hello world!"));
2447 QuicFrames frames = {QuicFrame(&stream_frame)}; 3514 QuicFrames frames = {QuicFrame(&stream_frame)};
2448 3515
2449 // clang-format off 3516 // clang-format off
2450 unsigned char packet[] = { 3517 unsigned char packet[] = {
2451 // public flags (version, 8 byte connection_id) 3518 // public flags (version, 8 byte connection_id)
2452 static_cast<unsigned char>( 3519 static_cast<unsigned char>(
2453 FLAGS_quic_reloadable_flag_quic_remove_v33_hacks2 ? 0x39 : 0x3D), 3520 FLAGS_quic_reloadable_flag_quic_remove_v33_hacks2 ? 0x39 : 0x3D),
2454 // connection_id 3521 // connection_id
2455 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, 3522 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
2456 // version tag 3523 // version tag
2457 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), 3524 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
2458 // packet number 3525 // packet number
3526 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
3527
3528 // frame type (stream frame with fin and no length)
3529 0xDF,
3530 // stream id
3531 0x04, 0x03, 0x02, 0x01,
3532 // offset
3533 0x54, 0x76, 0x10, 0x32, 0xDC, 0xFE, 0x98, 0xBA,
3534 // data
3535 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!',
3536 };
3537
3538 unsigned char packet_cid_be[] = {
3539 // public flags (version, 8 byte connection_id)
3540 static_cast<unsigned char>(
3541 FLAGS_quic_reloadable_flag_quic_remove_v33_hacks2 ? 0x39 : 0x3D),
3542 // connection_id
3543 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
3544 // version tag
3545 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
3546 // packet number
2459 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, 3547 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
2460 3548
2461 // frame type (stream frame with fin and no length) 3549 // frame type (stream frame with fin and no length)
2462 0xDF, 3550 0xDF,
2463 // stream id 3551 // stream id
2464 0x04, 0x03, 0x02, 0x01, 3552 0x04, 0x03, 0x02, 0x01,
2465 // offset 3553 // offset
2466 0x54, 0x76, 0x10, 0x32, 0xDC, 0xFE, 0x98, 0xBA, 3554 0x54, 0x76, 0x10, 0x32, 0xDC, 0xFE, 0x98, 0xBA,
2467 // data 3555 // data
2468 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!', 3556 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!',
2469 }; 3557 };
2470 // clang-format on 3558 // clang-format on
2471 3559
2472 QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); 3560 QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT);
2473 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 3561 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames));
2474 ASSERT_TRUE(data != nullptr); 3562 ASSERT_TRUE(data != nullptr);
2475 3563
2476 test::CompareCharArraysWithHexError("constructed packet", data->data(), 3564 test::CompareCharArraysWithHexError(
2477 data->length(), AsChars(packet), 3565 "constructed packet", data->data(), data->length(),
2478 arraysize(packet)); 3566 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
3567 ? packet_cid_be
3568 : packet),
3569 FLAGS_quic_restart_flag_quic_big_endian_connection_id
3570 ? arraysize(packet_cid_be)
3571 : arraysize(packet));
2479 } 3572 }
2480 3573
2481 TEST_P(QuicFramerTest, BuildVersionNegotiationPacket) { 3574 TEST_P(QuicFramerTest, BuildVersionNegotiationPacket) {
2482 // clang-format off 3575 // clang-format off
2483 unsigned char packet[] = { 3576 unsigned char packet[] = {
2484 // public flags (version, 8 byte connection_id) 3577 // public flags (version, 8 byte connection_id)
2485 0x0D, 3578 0x0D,
2486 // connection_id 3579 // connection_id
2487 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, 3580 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
2488 // version tag 3581 // version tag
2489 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), 3582 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
2490 }; 3583 };
3584
3585 unsigned char packet_cid_be[] = {
3586 // public flags (version, 8 byte connection_id)
3587 0x0D,
3588 // connection_id
3589 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
3590 // version tag
3591 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
3592 };
2491 // clang-format on 3593 // clang-format on
2492 3594
2493 QuicConnectionId connection_id = kConnectionId; 3595 QuicConnectionId connection_id = kConnectionId;
2494 std::unique_ptr<QuicEncryptedPacket> data( 3596 std::unique_ptr<QuicEncryptedPacket> data(
2495 framer_.BuildVersionNegotiationPacket(connection_id, 3597 framer_.BuildVersionNegotiationPacket(connection_id,
2496 SupportedVersions(GetParam()))); 3598 SupportedVersions(GetParam())));
2497 test::CompareCharArraysWithHexError("constructed packet", data->data(), 3599 test::CompareCharArraysWithHexError(
2498 data->length(), AsChars(packet), 3600 "constructed packet", data->data(), data->length(),
2499 arraysize(packet)); 3601 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
3602 ? packet_cid_be
3603 : packet),
3604 FLAGS_quic_restart_flag_quic_big_endian_connection_id
3605 ? arraysize(packet_cid_be)
3606 : arraysize(packet));
2500 } 3607 }
2501 3608
2502 TEST_P(QuicFramerTest, BuildAckFramePacketOneAckBlock) { 3609 TEST_P(QuicFramerTest, BuildAckFramePacketOneAckBlock) {
2503 QuicPacketHeader header; 3610 QuicPacketHeader header;
2504 header.public_header.connection_id = kConnectionId; 3611 header.public_header.connection_id = kConnectionId;
2505 header.public_header.reset_flag = false; 3612 header.public_header.reset_flag = false;
2506 header.public_header.version_flag = false; 3613 header.public_header.version_flag = false;
2507 header.packet_number = kPacketNumber; 3614 header.packet_number = kPacketNumber;
2508 3615
2509 // Use kSmallLargestObserved to make this test finished in a short time. 3616 // Use kSmallLargestObserved to make this test finished in a short time.
(...skipping 18 matching lines...) Expand all
2528 0x45, 3635 0x45,
2529 // largest acked 3636 // largest acked
2530 0x34, 0x12, 3637 0x34, 0x12,
2531 // Zero delta time. 3638 // Zero delta time.
2532 0x00, 0x00, 3639 0x00, 0x00,
2533 // first ack block length. 3640 // first ack block length.
2534 0x34, 0x12, 3641 0x34, 0x12,
2535 // num timestamps. 3642 // num timestamps.
2536 0x00, 3643 0x00,
2537 }; 3644 };
3645
3646 unsigned char packet_cid_be[] = {
3647 // public flags (8 byte connection_id)
3648 0x38,
3649 // connection_id
3650 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
3651 // packet number
3652 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
3653
3654 // frame type (ack frame)
3655 // (no ack blocks, 2 byte largest observed, 2 byte block length)
3656 0x45,
3657 // largest acked
3658 0x34, 0x12,
3659 // Zero delta time.
3660 0x00, 0x00,
3661 // first ack block length.
3662 0x34, 0x12,
3663 // num timestamps.
3664 0x00,
3665 };
2538 // clang-format on 3666 // clang-format on
2539 3667
2540 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 3668 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames));
2541 ASSERT_TRUE(data != nullptr); 3669 ASSERT_TRUE(data != nullptr);
2542 3670
2543 test::CompareCharArraysWithHexError("constructed packet", data->data(), 3671 test::CompareCharArraysWithHexError(
2544 data->length(), AsChars(packet), 3672 "constructed packet", data->data(), data->length(),
2545 arraysize(packet)); 3673 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
3674 ? packet_cid_be
3675 : packet),
3676 FLAGS_quic_restart_flag_quic_big_endian_connection_id
3677 ? arraysize(packet_cid_be)
3678 : arraysize(packet));
2546 } 3679 }
2547 3680
2548 TEST_P(QuicFramerTest, BuildAckFramePacketMultipleAckBlocks) { 3681 TEST_P(QuicFramerTest, BuildAckFramePacketMultipleAckBlocks) {
2549 QuicPacketHeader header; 3682 QuicPacketHeader header;
2550 header.public_header.connection_id = kConnectionId; 3683 header.public_header.connection_id = kConnectionId;
2551 header.public_header.reset_flag = false; 3684 header.public_header.reset_flag = false;
2552 header.public_header.version_flag = false; 3685 header.public_header.version_flag = false;
2553 header.packet_number = kPacketNumber; 3686 header.packet_number = kPacketNumber;
2554 3687
2555 // Use kSmallLargestObserved to make this test finished in a short time. 3688 // Use kSmallLargestObserved to make this test finished in a short time.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
2595 0x91, 3728 0x91,
2596 // ack block length. 3729 // ack block length.
2597 0xea, 0x01, 3730 0xea, 0x01,
2598 // gap to next block. 3731 // gap to next block.
2599 0x05, 3732 0x05,
2600 // ack block length. 3733 // ack block length.
2601 0x04, 0x00, 3734 0x04, 0x00,
2602 // num timestamps. 3735 // num timestamps.
2603 0x00, 3736 0x00,
2604 }; 3737 };
3738
3739 unsigned char packet_cid_be[] = {
3740 // public flags (8 byte connection_id)
3741 0x38,
3742 // connection_id
3743 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
3744 // packet number
3745 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
3746
3747 // frame type (ack frame)
3748 // (has ack blocks, 2 byte largest observed, 2 byte block length)
3749 0x65,
3750 // largest acked
3751 0x34, 0x12,
3752 // Zero delta time.
3753 0x00, 0x00,
3754 // num ack blocks ranges.
3755 0x04,
3756 // first ack block length.
3757 0x01, 0x00,
3758 // gap to next block.
3759 0x01,
3760 // ack block length.
3761 0xaf, 0x0e,
3762 // gap to next block.
3763 0xff,
3764 // ack block length.
3765 0x00, 0x00,
3766 // gap to next block.
3767 0x91,
3768 // ack block length.
3769 0xea, 0x01,
3770 // gap to next block.
3771 0x05,
3772 // ack block length.
3773 0x04, 0x00,
3774 // num timestamps.
3775 0x00,
3776 };
2605 // clang-format on 3777 // clang-format on
2606 3778
2607 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 3779 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames));
2608 ASSERT_TRUE(data != nullptr); 3780 ASSERT_TRUE(data != nullptr);
2609 3781
2610 test::CompareCharArraysWithHexError("constructed packet", data->data(), 3782 test::CompareCharArraysWithHexError(
2611 data->length(), AsChars(packet), 3783 "constructed packet", data->data(), data->length(),
2612 arraysize(packet)); 3784 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
3785 ? packet_cid_be
3786 : packet),
3787 FLAGS_quic_restart_flag_quic_big_endian_connection_id
3788 ? arraysize(packet_cid_be)
3789 : arraysize(packet));
2613 } 3790 }
2614 3791
2615 TEST_P(QuicFramerTest, BuildAckFramePacketMaxAckBlocks) { 3792 TEST_P(QuicFramerTest, BuildAckFramePacketMaxAckBlocks) {
2616 QuicPacketHeader header; 3793 QuicPacketHeader header;
2617 header.public_header.connection_id = kConnectionId; 3794 header.public_header.connection_id = kConnectionId;
2618 header.public_header.reset_flag = false; 3795 header.public_header.reset_flag = false;
2619 header.public_header.version_flag = false; 3796 header.public_header.version_flag = false;
2620 header.packet_number = kPacketNumber; 3797 header.packet_number = kPacketNumber;
2621 3798
2622 // Use kSmallLargestObservedto make this test finished in a short time. 3799 // Use kSmallLargestObservedto make this test finished in a short time.
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
2718 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 3895 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
2719 3896
2720 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 3897 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
2721 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 3898 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
2722 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 3899 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
2723 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 3900 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
2724 // num timestamps. 3901 // num timestamps.
2725 0x00, 3902 0x00,
2726 }; 3903 };
2727 3904
3905 unsigned char packet_cid_be[] = {
3906 // public flags (8 byte connection_id)
3907 0x38,
3908 // connection_id
3909 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
3910 // packet number
3911 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
3912 // frame type (ack frame)
3913 // (has ack blocks, 2 byte largest observed, 2 byte block length)
3914 0x65,
3915 // largest acked
3916 0x34, 0x12,
3917 // Zero delta time.
3918 0x00, 0x00,
3919 // num ack blocks ranges.
3920 0xff,
3921 // first ack block length.
3922 0xdd, 0x0f,
3923 // 255 = 4 * 63 + 3
3924 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3925 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3926 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3927 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3928 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3929 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3930 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3931 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3932 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3933 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3934
3935 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3936 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3937 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3938 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3939 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3940 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3941 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3942 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3943 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3944 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3945
3946 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3947 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3948 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3949 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3950 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3951 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3952 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3953 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3954 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3955 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3956
3957 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3958 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3959 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3960 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3961 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3962 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3963 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3964 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3965 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3966 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3967
3968 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3969 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3970 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3971 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3972 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3973 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3974 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3975 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3976 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3977 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3978
3979 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3980 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3981 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3982 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3983 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3984 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3985 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3986 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3987 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3988 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3989
3990 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3991 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3992 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3993 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
3994 // num timestamps.
3995 0x00,
3996 };
3997 // clang-format on
3998
2728 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 3999 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames));
2729 ASSERT_TRUE(data != nullptr); 4000 ASSERT_TRUE(data != nullptr);
2730 4001
2731 test::CompareCharArraysWithHexError("constructed packet", data->data(), 4002 test::CompareCharArraysWithHexError(
2732 data->length(), AsChars(packet), 4003 "constructed packet", data->data(), data->length(),
2733 arraysize(packet)); 4004 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
4005 ? packet_cid_be
4006 : packet),
4007 FLAGS_quic_restart_flag_quic_big_endian_connection_id
4008 ? arraysize(packet_cid_be)
4009 : arraysize(packet));
2734 } 4010 }
2735 4011
2736 TEST_P(QuicFramerTest, BuildNewStopWaitingPacket) { 4012 TEST_P(QuicFramerTest, BuildNewStopWaitingPacket) {
2737 QuicPacketHeader header; 4013 QuicPacketHeader header;
2738 header.public_header.connection_id = kConnectionId; 4014 header.public_header.connection_id = kConnectionId;
2739 header.public_header.reset_flag = false; 4015 header.public_header.reset_flag = false;
2740 header.public_header.version_flag = false; 4016 header.public_header.version_flag = false;
2741 header.packet_number = kPacketNumber; 4017 header.packet_number = kPacketNumber;
2742 4018
2743 QuicStopWaitingFrame stop_waiting_frame; 4019 QuicStopWaitingFrame stop_waiting_frame;
(...skipping 10 matching lines...) Expand all
2754 0x98, 0xBA, 0xDC, 0xFE, 4030 0x98, 0xBA, 0xDC, 0xFE,
2755 // packet number 4031 // packet number
2756 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, 4032 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
2757 4033
2758 // frame type (stop waiting frame) 4034 // frame type (stop waiting frame)
2759 0x06, 4035 0x06,
2760 // least packet number awaiting an ack, delta from packet number. 4036 // least packet number awaiting an ack, delta from packet number.
2761 0x1C, 0x00, 0x00, 0x00, 4037 0x1C, 0x00, 0x00, 0x00,
2762 0x00, 0x00, 4038 0x00, 0x00,
2763 }; 4039 };
4040
4041 unsigned char packet_cid_be[] = {
4042 // public flags (8 byte connection_id)
4043 0x38,
4044 // connection_id
4045 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
4046 // packet number
4047 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
4048
4049 // frame type (stop waiting frame)
4050 0x06,
4051 // least packet number awaiting an ack, delta from packet number.
4052 0x1C, 0x00, 0x00, 0x00,
4053 0x00, 0x00,
4054 };
2764 // clang-format on 4055 // clang-format on
2765 4056
2766 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 4057 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames));
2767 ASSERT_TRUE(data != nullptr); 4058 ASSERT_TRUE(data != nullptr);
2768 4059
2769 test::CompareCharArraysWithHexError("constructed packet", data->data(), 4060 test::CompareCharArraysWithHexError(
2770 data->length(), AsChars(packet), 4061 "constructed packet", data->data(), data->length(),
2771 arraysize(packet)); 4062 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
4063 ? packet_cid_be
4064 : packet),
4065 FLAGS_quic_restart_flag_quic_big_endian_connection_id
4066 ? arraysize(packet_cid_be)
4067 : arraysize(packet));
2772 } 4068 }
2773 4069
2774 TEST_P(QuicFramerTest, BuildRstFramePacketQuic) { 4070 TEST_P(QuicFramerTest, BuildRstFramePacketQuic) {
2775 QuicPacketHeader header; 4071 QuicPacketHeader header;
2776 header.public_header.connection_id = kConnectionId; 4072 header.public_header.connection_id = kConnectionId;
2777 header.public_header.reset_flag = false; 4073 header.public_header.reset_flag = false;
2778 header.public_header.version_flag = false; 4074 header.public_header.version_flag = false;
2779 header.packet_number = kPacketNumber; 4075 header.packet_number = kPacketNumber;
2780 4076
2781 QuicRstStreamFrame rst_frame; 4077 QuicRstStreamFrame rst_frame;
(...skipping 15 matching lines...) Expand all
2797 // frame type (rst stream frame) 4093 // frame type (rst stream frame)
2798 0x01, 4094 0x01,
2799 // stream id 4095 // stream id
2800 0x04, 0x03, 0x02, 0x01, 4096 0x04, 0x03, 0x02, 0x01,
2801 // sent byte offset 4097 // sent byte offset
2802 0x01, 0x02, 0x03, 0x04, 4098 0x01, 0x02, 0x03, 0x04,
2803 0x05, 0x06, 0x07, 0x08, 4099 0x05, 0x06, 0x07, 0x08,
2804 // error code 4100 // error code
2805 0x08, 0x07, 0x06, 0x05, 4101 0x08, 0x07, 0x06, 0x05,
2806 }; 4102 };
4103
4104 unsigned char packet_cid_be[] = {
4105 // public flags (8 byte connection_id)
4106 0x38,
4107 // connection_id
4108 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
4109 // packet number
4110 0xBC, 0x9A, 0x78, 0x56,
4111 0x34, 0x12,
4112
4113 // frame type (rst stream frame)
4114 0x01,
4115 // stream id
4116 0x04, 0x03, 0x02, 0x01,
4117 // sent byte offset
4118 0x01, 0x02, 0x03, 0x04,
4119 0x05, 0x06, 0x07, 0x08,
4120 // error code
4121 0x08, 0x07, 0x06, 0x05,
4122 };
2807 // clang-format on 4123 // clang-format on
2808 4124
2809 QuicFrames frames = {QuicFrame(&rst_frame)}; 4125 QuicFrames frames = {QuicFrame(&rst_frame)};
2810 4126
2811 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 4127 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames));
2812 ASSERT_TRUE(data != nullptr); 4128 ASSERT_TRUE(data != nullptr);
2813 4129
2814 test::CompareCharArraysWithHexError("constructed packet", data->data(), 4130 test::CompareCharArraysWithHexError(
2815 data->length(), AsChars(packet), 4131 "constructed packet", data->data(), data->length(),
2816 arraysize(packet)); 4132 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
4133 ? packet_cid_be
4134 : packet),
4135 FLAGS_quic_restart_flag_quic_big_endian_connection_id
4136 ? arraysize(packet_cid_be)
4137 : arraysize(packet));
2817 } 4138 }
2818 4139
2819 TEST_P(QuicFramerTest, BuildCloseFramePacket) { 4140 TEST_P(QuicFramerTest, BuildCloseFramePacket) {
2820 QuicPacketHeader header; 4141 QuicPacketHeader header;
2821 header.public_header.connection_id = kConnectionId; 4142 header.public_header.connection_id = kConnectionId;
2822 header.public_header.reset_flag = false; 4143 header.public_header.reset_flag = false;
2823 header.public_header.version_flag = false; 4144 header.public_header.version_flag = false;
2824 header.packet_number = kPacketNumber; 4145 header.packet_number = kPacketNumber;
2825 4146
2826 QuicConnectionCloseFrame close_frame; 4147 QuicConnectionCloseFrame close_frame;
(...skipping 18 matching lines...) Expand all
2845 // error code 4166 // error code
2846 0x08, 0x07, 0x06, 0x05, 4167 0x08, 0x07, 0x06, 0x05,
2847 // error details length 4168 // error details length
2848 0x0d, 0x00, 4169 0x0d, 0x00,
2849 // error details 4170 // error details
2850 'b', 'e', 'c', 'a', 4171 'b', 'e', 'c', 'a',
2851 'u', 's', 'e', ' ', 4172 'u', 's', 'e', ' ',
2852 'I', ' ', 'c', 'a', 4173 'I', ' ', 'c', 'a',
2853 'n', 4174 'n',
2854 }; 4175 };
4176
4177 unsigned char packet_cid_be[] = {
4178 // public flags (8 byte connection_id)
4179 0x38,
4180 // connection_id
4181 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
4182 // packet number
4183 0xBC, 0x9A, 0x78, 0x56,
4184 0x34, 0x12,
4185
4186 // frame type (connection close frame)
4187 0x02,
4188 // error code
4189 0x08, 0x07, 0x06, 0x05,
4190 // error details length
4191 0x0d, 0x00,
4192 // error details
4193 'b', 'e', 'c', 'a',
4194 'u', 's', 'e', ' ',
4195 'I', ' ', 'c', 'a',
4196 'n',
4197 };
2855 // clang-format on 4198 // clang-format on
2856 4199
2857 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 4200 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames));
2858 ASSERT_TRUE(data != nullptr); 4201 ASSERT_TRUE(data != nullptr);
2859 4202
2860 test::CompareCharArraysWithHexError("constructed packet", data->data(), 4203 test::CompareCharArraysWithHexError(
2861 data->length(), AsChars(packet), 4204 "constructed packet", data->data(), data->length(),
2862 arraysize(packet)); 4205 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
4206 ? packet_cid_be
4207 : packet),
4208 FLAGS_quic_restart_flag_quic_big_endian_connection_id
4209 ? arraysize(packet_cid_be)
4210 : arraysize(packet));
2863 } 4211 }
2864 4212
2865 TEST_P(QuicFramerTest, BuildGoAwayPacket) { 4213 TEST_P(QuicFramerTest, BuildGoAwayPacket) {
2866 QuicPacketHeader header; 4214 QuicPacketHeader header;
2867 header.public_header.connection_id = kConnectionId; 4215 header.public_header.connection_id = kConnectionId;
2868 header.public_header.reset_flag = false; 4216 header.public_header.reset_flag = false;
2869 header.public_header.version_flag = false; 4217 header.public_header.version_flag = false;
2870 header.packet_number = kPacketNumber; 4218 header.packet_number = kPacketNumber;
2871 4219
2872 QuicGoAwayFrame goaway_frame; 4220 QuicGoAwayFrame goaway_frame;
(...skipping 21 matching lines...) Expand all
2894 // stream id 4242 // stream id
2895 0x04, 0x03, 0x02, 0x01, 4243 0x04, 0x03, 0x02, 0x01,
2896 // error details length 4244 // error details length
2897 0x0d, 0x00, 4245 0x0d, 0x00,
2898 // error details 4246 // error details
2899 'b', 'e', 'c', 'a', 4247 'b', 'e', 'c', 'a',
2900 'u', 's', 'e', ' ', 4248 'u', 's', 'e', ' ',
2901 'I', ' ', 'c', 'a', 4249 'I', ' ', 'c', 'a',
2902 'n', 4250 'n',
2903 }; 4251 };
4252
4253 unsigned char packet_cid_be[] = {
4254 // public flags (8 byte connection_id)
4255 0x38,
4256 // connection_id
4257 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
4258 // packet number
4259 0xBC, 0x9A, 0x78, 0x56,
4260 0x34, 0x12,
4261
4262 // frame type (go away frame)
4263 0x03,
4264 // error code
4265 0x08, 0x07, 0x06, 0x05,
4266 // stream id
4267 0x04, 0x03, 0x02, 0x01,
4268 // error details length
4269 0x0d, 0x00,
4270 // error details
4271 'b', 'e', 'c', 'a',
4272 'u', 's', 'e', ' ',
4273 'I', ' ', 'c', 'a',
4274 'n',
4275 };
2904 // clang-format on 4276 // clang-format on
2905 4277
2906 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 4278 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames));
2907 ASSERT_TRUE(data != nullptr); 4279 ASSERT_TRUE(data != nullptr);
2908 4280
2909 test::CompareCharArraysWithHexError("constructed packet", data->data(), 4281 test::CompareCharArraysWithHexError(
2910 data->length(), AsChars(packet), 4282 "constructed packet", data->data(), data->length(),
2911 arraysize(packet)); 4283 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
4284 ? packet_cid_be
4285 : packet),
4286 FLAGS_quic_restart_flag_quic_big_endian_connection_id
4287 ? arraysize(packet_cid_be)
4288 : arraysize(packet));
2912 } 4289 }
2913 4290
2914 TEST_P(QuicFramerTest, BuildWindowUpdatePacket) { 4291 TEST_P(QuicFramerTest, BuildWindowUpdatePacket) {
2915 QuicPacketHeader header; 4292 QuicPacketHeader header;
2916 header.public_header.connection_id = kConnectionId; 4293 header.public_header.connection_id = kConnectionId;
2917 header.public_header.reset_flag = false; 4294 header.public_header.reset_flag = false;
2918 header.public_header.version_flag = false; 4295 header.public_header.version_flag = false;
2919 header.packet_number = kPacketNumber; 4296 header.packet_number = kPacketNumber;
2920 4297
2921 QuicWindowUpdateFrame window_update_frame; 4298 QuicWindowUpdateFrame window_update_frame;
(...skipping 14 matching lines...) Expand all
2936 0x34, 0x12, 4313 0x34, 0x12,
2937 4314
2938 // frame type (window update frame) 4315 // frame type (window update frame)
2939 0x04, 4316 0x04,
2940 // stream id 4317 // stream id
2941 0x04, 0x03, 0x02, 0x01, 4318 0x04, 0x03, 0x02, 0x01,
2942 // byte offset 4319 // byte offset
2943 0x88, 0x77, 0x66, 0x55, 4320 0x88, 0x77, 0x66, 0x55,
2944 0x44, 0x33, 0x22, 0x11, 4321 0x44, 0x33, 0x22, 0x11,
2945 }; 4322 };
4323
4324 unsigned char packet_cid_be[] = {
4325 // public flags (8 byte connection_id)
4326 0x38,
4327 // connection_id
4328 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
4329 // packet number
4330 0xBC, 0x9A, 0x78, 0x56,
4331 0x34, 0x12,
4332
4333 // frame type (window update frame)
4334 0x04,
4335 // stream id
4336 0x04, 0x03, 0x02, 0x01,
4337 // byte offset
4338 0x88, 0x77, 0x66, 0x55,
4339 0x44, 0x33, 0x22, 0x11,
4340 };
2946 // clang-format on 4341 // clang-format on
2947 4342
2948 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 4343 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames));
2949 ASSERT_TRUE(data != nullptr); 4344 ASSERT_TRUE(data != nullptr);
2950 4345
2951 test::CompareCharArraysWithHexError("constructed packet", data->data(), 4346 test::CompareCharArraysWithHexError(
2952 data->length(), AsChars(packet), 4347 "constructed packet", data->data(), data->length(),
2953 arraysize(packet)); 4348 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
4349 ? packet_cid_be
4350 : packet),
4351 FLAGS_quic_restart_flag_quic_big_endian_connection_id
4352 ? arraysize(packet_cid_be)
4353 : arraysize(packet));
2954 } 4354 }
2955 4355
2956 TEST_P(QuicFramerTest, BuildBlockedPacket) { 4356 TEST_P(QuicFramerTest, BuildBlockedPacket) {
2957 QuicPacketHeader header; 4357 QuicPacketHeader header;
2958 header.public_header.connection_id = kConnectionId; 4358 header.public_header.connection_id = kConnectionId;
2959 header.public_header.reset_flag = false; 4359 header.public_header.reset_flag = false;
2960 header.public_header.version_flag = false; 4360 header.public_header.version_flag = false;
2961 header.packet_number = kPacketNumber; 4361 header.packet_number = kPacketNumber;
2962 4362
2963 QuicBlockedFrame blocked_frame; 4363 QuicBlockedFrame blocked_frame;
(...skipping 10 matching lines...) Expand all
2974 0x98, 0xBA, 0xDC, 0xFE, 4374 0x98, 0xBA, 0xDC, 0xFE,
2975 // packet number 4375 // packet number
2976 0xBC, 0x9A, 0x78, 0x56, 4376 0xBC, 0x9A, 0x78, 0x56,
2977 0x34, 0x12, 4377 0x34, 0x12,
2978 4378
2979 // frame type (blocked frame) 4379 // frame type (blocked frame)
2980 0x05, 4380 0x05,
2981 // stream id 4381 // stream id
2982 0x04, 0x03, 0x02, 0x01, 4382 0x04, 0x03, 0x02, 0x01,
2983 }; 4383 };
4384
4385 unsigned char packet_cid_be[] = {
4386 // public flags (8 byte connection_id)
4387 0x38,
4388 // connection_id
4389 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
4390 // packet number
4391 0xBC, 0x9A, 0x78, 0x56,
4392 0x34, 0x12,
4393
4394 // frame type (blocked frame)
4395 0x05,
4396 // stream id
4397 0x04, 0x03, 0x02, 0x01,
4398 };
2984 // clang-format on 4399 // clang-format on
2985 4400
2986 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 4401 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames));
2987 ASSERT_TRUE(data != nullptr); 4402 ASSERT_TRUE(data != nullptr);
2988 4403
2989 test::CompareCharArraysWithHexError("constructed packet", data->data(), 4404 test::CompareCharArraysWithHexError(
2990 data->length(), AsChars(packet), 4405 "constructed packet", data->data(), data->length(),
2991 arraysize(packet)); 4406 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
4407 ? packet_cid_be
4408 : packet),
4409 FLAGS_quic_restart_flag_quic_big_endian_connection_id
4410 ? arraysize(packet_cid_be)
4411 : arraysize(packet));
2992 } 4412 }
2993 4413
2994 TEST_P(QuicFramerTest, BuildPingPacket) { 4414 TEST_P(QuicFramerTest, BuildPingPacket) {
2995 QuicPacketHeader header; 4415 QuicPacketHeader header;
2996 header.public_header.connection_id = kConnectionId; 4416 header.public_header.connection_id = kConnectionId;
2997 header.public_header.reset_flag = false; 4417 header.public_header.reset_flag = false;
2998 header.public_header.version_flag = false; 4418 header.public_header.version_flag = false;
2999 header.packet_number = kPacketNumber; 4419 header.packet_number = kPacketNumber;
3000 4420
3001 QuicFrames frames = {QuicFrame(QuicPingFrame())}; 4421 QuicFrames frames = {QuicFrame(QuicPingFrame())};
3002 4422
3003 // clang-format off 4423 // clang-format off
3004 unsigned char packet[] = { 4424 unsigned char packet[] = {
3005 // public flags (8 byte connection_id) 4425 // public flags (8 byte connection_id)
3006 0x38, 4426 0x38,
3007 // connection_id 4427 // connection_id
3008 0x10, 0x32, 0x54, 0x76, 4428 0x10, 0x32, 0x54, 0x76,
3009 0x98, 0xBA, 0xDC, 0xFE, 4429 0x98, 0xBA, 0xDC, 0xFE,
3010 // packet number 4430 // packet number
3011 0xBC, 0x9A, 0x78, 0x56, 4431 0xBC, 0x9A, 0x78, 0x56,
3012 0x34, 0x12, 4432 0x34, 0x12,
4433
4434 // frame type (ping frame)
4435 0x07,
4436 };
4437
4438 unsigned char packet_cid_be[] = {
4439 // public flags (8 byte connection_id)
4440 0x38,
4441 // connection_id
4442 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
4443 // packet number
4444 0xBC, 0x9A, 0x78, 0x56,
4445 0x34, 0x12,
3013 4446
3014 // frame type (ping frame) 4447 // frame type (ping frame)
3015 0x07, 4448 0x07,
3016 }; 4449 };
3017 // clang-format on 4450 // clang-format on
3018 4451
3019 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 4452 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3020 ASSERT_TRUE(data != nullptr); 4453 ASSERT_TRUE(data != nullptr);
3021 4454
3022 test::CompareCharArraysWithHexError("constructed packet", data->data(), 4455 test::CompareCharArraysWithHexError(
3023 data->length(), AsChars(packet), 4456 "constructed packet", data->data(), data->length(),
3024 arraysize(packet)); 4457 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
4458 ? packet_cid_be
4459 : packet),
4460 FLAGS_quic_restart_flag_quic_big_endian_connection_id
4461 ? arraysize(packet_cid_be)
4462 : arraysize(packet));
3025 } 4463 }
3026 4464
3027 // Test that the MTU discovery packet is serialized correctly as a PING packet. 4465 // Test that the MTU discovery packet is serialized correctly as a PING packet.
3028 TEST_P(QuicFramerTest, BuildMtuDiscoveryPacket) { 4466 TEST_P(QuicFramerTest, BuildMtuDiscoveryPacket) {
3029 QuicPacketHeader header; 4467 QuicPacketHeader header;
3030 header.public_header.connection_id = kConnectionId; 4468 header.public_header.connection_id = kConnectionId;
3031 header.public_header.reset_flag = false; 4469 header.public_header.reset_flag = false;
3032 header.public_header.version_flag = false; 4470 header.public_header.version_flag = false;
3033 header.packet_number = kPacketNumber; 4471 header.packet_number = kPacketNumber;
3034 4472
3035 QuicFrames frames = {QuicFrame(QuicMtuDiscoveryFrame())}; 4473 QuicFrames frames = {QuicFrame(QuicMtuDiscoveryFrame())};
3036 4474
3037 // clang-format off 4475 // clang-format off
3038 unsigned char packet[] = { 4476 unsigned char packet[] = {
3039 // public flags (8 byte connection_id) 4477 // public flags (8 byte connection_id)
3040 0x38, 4478 0x38,
3041 // connection_id 4479 // connection_id
3042 0x10, 0x32, 0x54, 0x76, 4480 0x10, 0x32, 0x54, 0x76,
3043 0x98, 0xBA, 0xDC, 0xFE, 4481 0x98, 0xBA, 0xDC, 0xFE,
3044 // packet number 4482 // packet number
3045 0xBC, 0x9A, 0x78, 0x56, 4483 0xBC, 0x9A, 0x78, 0x56,
3046 0x34, 0x12, 4484 0x34, 0x12,
3047 4485
3048 // frame type (ping frame) 4486 // frame type (ping frame)
3049 0x07, 4487 0x07,
3050 }; 4488 };
4489
4490 unsigned char packet_cid_be[] = {
4491 // public flags (8 byte connection_id)
4492 0x38,
4493 // connection_id
4494 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
4495 // packet number
4496 0xBC, 0x9A, 0x78, 0x56,
4497 0x34, 0x12,
4498
4499 // frame type (ping frame)
4500 0x07,
4501 };
3051 // clang-format on 4502 // clang-format on
3052 4503
3053 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 4504 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3054 ASSERT_TRUE(data != nullptr); 4505 ASSERT_TRUE(data != nullptr);
3055 4506
3056 test::CompareCharArraysWithHexError("constructed packet", data->data(), 4507 test::CompareCharArraysWithHexError(
3057 data->length(), AsChars(packet), 4508 "constructed packet", data->data(), data->length(),
3058 arraysize(packet)); 4509 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
4510 ? packet_cid_be
4511 : packet),
4512 FLAGS_quic_restart_flag_quic_big_endian_connection_id
4513 ? arraysize(packet_cid_be)
4514 : arraysize(packet));
3059 } 4515 }
3060 4516
3061 TEST_P(QuicFramerTest, BuildPublicResetPacketOld) { 4517 TEST_P(QuicFramerTest, BuildPublicResetPacketOld) {
3062 FLAGS_quic_reloadable_flag_quic_use_old_public_reset_packets = true; 4518 FLAGS_quic_reloadable_flag_quic_use_old_public_reset_packets = true;
3063 QuicPublicResetPacket reset_packet; 4519 QuicPublicResetPacket reset_packet;
3064 reset_packet.public_header.connection_id = kConnectionId; 4520 reset_packet.public_header.connection_id = kConnectionId;
3065 reset_packet.public_header.reset_flag = true; 4521 reset_packet.public_header.reset_flag = true;
3066 reset_packet.public_header.version_flag = false; 4522 reset_packet.public_header.version_flag = false;
3067 reset_packet.rejected_packet_number = kPacketNumber; 4523 reset_packet.rejected_packet_number = kPacketNumber;
3068 reset_packet.nonce_proof = kNonceProof; 4524 reset_packet.nonce_proof = kNonceProof;
(...skipping 17 matching lines...) Expand all
3086 'R', 'S', 'E', 'Q', 4542 'R', 'S', 'E', 'Q',
3087 // end offset 16 4543 // end offset 16
3088 0x10, 0x00, 0x00, 0x00, 4544 0x10, 0x00, 0x00, 0x00,
3089 // nonce proof 4545 // nonce proof
3090 0x89, 0x67, 0x45, 0x23, 4546 0x89, 0x67, 0x45, 0x23,
3091 0x01, 0xEF, 0xCD, 0xAB, 4547 0x01, 0xEF, 0xCD, 0xAB,
3092 // rejected packet number 4548 // rejected packet number
3093 0xBC, 0x9A, 0x78, 0x56, 4549 0xBC, 0x9A, 0x78, 0x56,
3094 0x34, 0x12, 0x00, 0x00, 4550 0x34, 0x12, 0x00, 0x00,
3095 }; 4551 };
4552
4553 unsigned char packet_cid_be[] = {
4554 // public flags (public reset, 8 byte ConnectionId)
4555 0x0E,
4556 // connection_id
4557 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
4558 // message tag (kPRST)
4559 'P', 'R', 'S', 'T',
4560 // num_entries (2) + padding
4561 0x02, 0x00, 0x00, 0x00,
4562 // tag kRNON
4563 'R', 'N', 'O', 'N',
4564 // end offset 8
4565 0x08, 0x00, 0x00, 0x00,
4566 // tag kRSEQ
4567 'R', 'S', 'E', 'Q',
4568 // end offset 16
4569 0x10, 0x00, 0x00, 0x00,
4570 // nonce proof
4571 0x89, 0x67, 0x45, 0x23,
4572 0x01, 0xEF, 0xCD, 0xAB,
4573 // rejected packet number
4574 0xBC, 0x9A, 0x78, 0x56,
4575 0x34, 0x12, 0x00, 0x00,
4576 };
4577
3096 unsigned char packet_no_rejected_packet_number[] = { 4578 unsigned char packet_no_rejected_packet_number[] = {
3097 // public flags (public reset, 8 byte ConnectionId) 4579 // public flags (public reset, 8 byte ConnectionId)
3098 0x0E, 4580 0x0E,
3099 // connection_id 4581 // connection_id
3100 0x10, 0x32, 0x54, 0x76, 4582 0x10, 0x32, 0x54, 0x76,
3101 0x98, 0xBA, 0xDC, 0xFE, 4583 0x98, 0xBA, 0xDC, 0xFE,
3102 // message tag (kPRST) 4584 // message tag (kPRST)
3103 'P', 'R', 'S', 'T', 4585 'P', 'R', 'S', 'T',
3104 // num_entries (1) + padding 4586 // num_entries (1) + padding
3105 0x01, 0x00, 0x00, 0x00, 4587 0x01, 0x00, 0x00, 0x00,
3106 // tag kRNON 4588 // tag kRNON
3107 'R', 'N', 'O', 'N', 4589 'R', 'N', 'O', 'N',
3108 // end offset 8 4590 // end offset 8
3109 0x08, 0x00, 0x00, 0x00, 4591 0x08, 0x00, 0x00, 0x00,
3110 // nonce proof 4592 // nonce proof
3111 0x89, 0x67, 0x45, 0x23, 4593 0x89, 0x67, 0x45, 0x23,
3112 0x01, 0xEF, 0xCD, 0xAB, 4594 0x01, 0xEF, 0xCD, 0xAB,
3113 }; 4595 };
4596
4597 unsigned char packet_no_rejected_packet_number_cid_be[] = {
4598 // public flags (public reset, 8 byte ConnectionId)
4599 0x0E,
4600 // connection_id
4601 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
4602 // message tag (kPRST)
4603 'P', 'R', 'S', 'T',
4604 // num_entries (1) + padding
4605 0x01, 0x00, 0x00, 0x00,
4606 // tag kRNON
4607 'R', 'N', 'O', 'N',
4608 // end offset 8
4609 0x08, 0x00, 0x00, 0x00,
4610 // nonce proof
4611 0x89, 0x67, 0x45, 0x23,
4612 0x01, 0xEF, 0xCD, 0xAB,
4613 };
3114 // clang-format on 4614 // clang-format on
3115 4615
3116 std::unique_ptr<QuicEncryptedPacket> data( 4616 std::unique_ptr<QuicEncryptedPacket> data(
3117 framer_.BuildPublicResetPacket(reset_packet)); 4617 framer_.BuildPublicResetPacket(reset_packet));
3118 ASSERT_TRUE(data != nullptr); 4618 ASSERT_TRUE(data != nullptr);
3119 if (FLAGS_quic_reloadable_flag_quic_remove_packet_number_from_public_reset) { 4619 if (FLAGS_quic_reloadable_flag_quic_remove_packet_number_from_public_reset) {
3120 test::CompareCharArraysWithHexError( 4620 test::CompareCharArraysWithHexError(
3121 "constructed packet", data->data(), data->length(), 4621 "constructed packet", data->data(), data->length(),
3122 AsChars(packet_no_rejected_packet_number), 4622 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
3123 arraysize(packet_no_rejected_packet_number)); 4623 ? packet_no_rejected_packet_number_cid_be
4624 : packet_no_rejected_packet_number),
4625 FLAGS_quic_restart_flag_quic_big_endian_connection_id
4626 ? arraysize(packet_no_rejected_packet_number_cid_be)
4627 : arraysize(packet_no_rejected_packet_number));
3124 } else { 4628 } else {
3125 test::CompareCharArraysWithHexError("constructed packet", data->data(), 4629 test::CompareCharArraysWithHexError(
3126 data->length(), AsChars(packet), 4630 "constructed packet", data->data(), data->length(),
3127 arraysize(packet)); 4631 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
4632 ? packet_cid_be
4633 : packet),
4634 FLAGS_quic_restart_flag_quic_big_endian_connection_id
4635 ? arraysize(packet_cid_be)
4636 : arraysize(packet));
3128 } 4637 }
3129 } 4638 }
3130 4639
3131 TEST_P(QuicFramerTest, BuildPublicResetPacket) { 4640 TEST_P(QuicFramerTest, BuildPublicResetPacket) {
3132 FLAGS_quic_reloadable_flag_quic_use_old_public_reset_packets = false; 4641 FLAGS_quic_reloadable_flag_quic_use_old_public_reset_packets = false;
3133 QuicPublicResetPacket reset_packet; 4642 QuicPublicResetPacket reset_packet;
3134 reset_packet.public_header.connection_id = kConnectionId; 4643 reset_packet.public_header.connection_id = kConnectionId;
3135 reset_packet.public_header.reset_flag = true; 4644 reset_packet.public_header.reset_flag = true;
3136 reset_packet.public_header.version_flag = false; 4645 reset_packet.public_header.version_flag = false;
3137 reset_packet.rejected_packet_number = kPacketNumber; 4646 reset_packet.rejected_packet_number = kPacketNumber;
(...skipping 18 matching lines...) Expand all
3156 'R', 'S', 'E', 'Q', 4665 'R', 'S', 'E', 'Q',
3157 // end offset 16 4666 // end offset 16
3158 0x10, 0x00, 0x00, 0x00, 4667 0x10, 0x00, 0x00, 0x00,
3159 // nonce proof 4668 // nonce proof
3160 0x89, 0x67, 0x45, 0x23, 4669 0x89, 0x67, 0x45, 0x23,
3161 0x01, 0xEF, 0xCD, 0xAB, 4670 0x01, 0xEF, 0xCD, 0xAB,
3162 // rejected packet number 4671 // rejected packet number
3163 0xBC, 0x9A, 0x78, 0x56, 4672 0xBC, 0x9A, 0x78, 0x56,
3164 0x34, 0x12, 0x00, 0x00, 4673 0x34, 0x12, 0x00, 0x00,
3165 }; 4674 };
4675
4676 unsigned char packet_cid_be[] = {
4677 // public flags (public reset, 8 byte ConnectionId)
4678 0x0A,
4679 // connection_id
4680 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
4681 // message tag (kPRST)
4682 'P', 'R', 'S', 'T',
4683 // num_entries (2) + padding
4684 0x02, 0x00, 0x00, 0x00,
4685 // tag kRNON
4686 'R', 'N', 'O', 'N',
4687 // end offset 8
4688 0x08, 0x00, 0x00, 0x00,
4689 // tag kRSEQ
4690 'R', 'S', 'E', 'Q',
4691 // end offset 16
4692 0x10, 0x00, 0x00, 0x00,
4693 // nonce proof
4694 0x89, 0x67, 0x45, 0x23,
4695 0x01, 0xEF, 0xCD, 0xAB,
4696 // rejected packet number
4697 0xBC, 0x9A, 0x78, 0x56,
4698 0x34, 0x12, 0x00, 0x00,
4699 };
4700
3166 unsigned char packet_no_rejected_packet_number[] = { 4701 unsigned char packet_no_rejected_packet_number[] = {
3167 // public flags (public reset, 8 byte ConnectionId) 4702 // public flags (public reset, 8 byte ConnectionId)
3168 0x0A, 4703 0x0A,
3169 // connection_id 4704 // connection_id
3170 0x10, 0x32, 0x54, 0x76, 4705 0x10, 0x32, 0x54, 0x76,
3171 0x98, 0xBA, 0xDC, 0xFE, 4706 0x98, 0xBA, 0xDC, 0xFE,
3172 // message tag (kPRST) 4707 // message tag (kPRST)
3173 'P', 'R', 'S', 'T', 4708 'P', 'R', 'S', 'T',
3174 // num_entries (1) + padding 4709 // num_entries (1) + padding
3175 0x01, 0x00, 0x00, 0x00, 4710 0x01, 0x00, 0x00, 0x00,
3176 // tag kRNON 4711 // tag kRNON
3177 'R', 'N', 'O', 'N', 4712 'R', 'N', 'O', 'N',
3178 // end offset 8 4713 // end offset 8
3179 0x08, 0x00, 0x00, 0x00, 4714 0x08, 0x00, 0x00, 0x00,
3180 // nonce proof 4715 // nonce proof
3181 0x89, 0x67, 0x45, 0x23, 4716 0x89, 0x67, 0x45, 0x23,
3182 0x01, 0xEF, 0xCD, 0xAB, 4717 0x01, 0xEF, 0xCD, 0xAB,
3183 }; 4718 };
4719
4720 unsigned char packet_no_rejected_packet_number_cid_be[] = {
4721 // public flags (public reset, 8 byte ConnectionId)
4722 0x0A,
4723 // connection_id
4724 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
4725 // message tag (kPRST)
4726 'P', 'R', 'S', 'T',
4727 // num_entries (1) + padding
4728 0x01, 0x00, 0x00, 0x00,
4729 // tag kRNON
4730 'R', 'N', 'O', 'N',
4731 // end offset 8
4732 0x08, 0x00, 0x00, 0x00,
4733 // nonce proof
4734 0x89, 0x67, 0x45, 0x23,
4735 0x01, 0xEF, 0xCD, 0xAB,
4736 };
3184 // clang-format on 4737 // clang-format on
3185 4738
3186 std::unique_ptr<QuicEncryptedPacket> data( 4739 std::unique_ptr<QuicEncryptedPacket> data(
3187 framer_.BuildPublicResetPacket(reset_packet)); 4740 framer_.BuildPublicResetPacket(reset_packet));
3188 ASSERT_TRUE(data != nullptr); 4741 ASSERT_TRUE(data != nullptr);
3189 4742
3190 if (FLAGS_quic_reloadable_flag_quic_remove_packet_number_from_public_reset) { 4743 if (FLAGS_quic_reloadable_flag_quic_remove_packet_number_from_public_reset) {
3191 test::CompareCharArraysWithHexError( 4744 test::CompareCharArraysWithHexError(
3192 "constructed packet", data->data(), data->length(), 4745 "constructed packet", data->data(), data->length(),
3193 AsChars(packet_no_rejected_packet_number), 4746 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
3194 arraysize(packet_no_rejected_packet_number)); 4747 ? packet_no_rejected_packet_number_cid_be
4748 : packet_no_rejected_packet_number),
4749 FLAGS_quic_restart_flag_quic_big_endian_connection_id
4750 ? arraysize(packet_no_rejected_packet_number_cid_be)
4751 : arraysize(packet_no_rejected_packet_number));
3195 } else { 4752 } else {
3196 test::CompareCharArraysWithHexError("constructed packet", data->data(), 4753 test::CompareCharArraysWithHexError(
3197 data->length(), AsChars(packet), 4754 "constructed packet", data->data(), data->length(),
3198 arraysize(packet)); 4755 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
4756 ? packet_cid_be
4757 : packet),
4758 FLAGS_quic_restart_flag_quic_big_endian_connection_id
4759 ? arraysize(packet_cid_be)
4760 : arraysize(packet));
3199 } 4761 }
3200 } 4762 }
3201 4763
3202 TEST_P(QuicFramerTest, BuildPublicResetPacketWithClientAddress) { 4764 TEST_P(QuicFramerTest, BuildPublicResetPacketWithClientAddress) {
3203 FLAGS_quic_reloadable_flag_quic_use_old_public_reset_packets = false; 4765 FLAGS_quic_reloadable_flag_quic_use_old_public_reset_packets = false;
3204 QuicPublicResetPacket reset_packet; 4766 QuicPublicResetPacket reset_packet;
3205 reset_packet.public_header.connection_id = kConnectionId; 4767 reset_packet.public_header.connection_id = kConnectionId;
3206 reset_packet.public_header.reset_flag = true; 4768 reset_packet.public_header.reset_flag = true;
3207 reset_packet.public_header.version_flag = false; 4769 reset_packet.public_header.version_flag = false;
3208 reset_packet.rejected_packet_number = kPacketNumber; 4770 reset_packet.rejected_packet_number = kPacketNumber;
(...skipping 28 matching lines...) Expand all
3237 0x89, 0x67, 0x45, 0x23, 4799 0x89, 0x67, 0x45, 0x23,
3238 0x01, 0xEF, 0xCD, 0xAB, 4800 0x01, 0xEF, 0xCD, 0xAB,
3239 // rejected packet number 4801 // rejected packet number
3240 0xBC, 0x9A, 0x78, 0x56, 4802 0xBC, 0x9A, 0x78, 0x56,
3241 0x34, 0x12, 0x00, 0x00, 4803 0x34, 0x12, 0x00, 0x00,
3242 // client address 4804 // client address
3243 0x02, 0x00, 4805 0x02, 0x00,
3244 0x7F, 0x00, 0x00, 0x01, 4806 0x7F, 0x00, 0x00, 0x01,
3245 0x34, 0x12, 4807 0x34, 0x12,
3246 }; 4808 };
4809
4810 unsigned char packet_cid_be[] = {
4811 // public flags (public reset, 8 byte ConnectionId)
4812 0x0A,
4813 // connection_id
4814 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
4815 // message tag (kPRST)
4816 'P', 'R', 'S', 'T',
4817 // num_entries (3) + padding
4818 0x03, 0x00, 0x00, 0x00,
4819 // tag kRNON
4820 'R', 'N', 'O', 'N',
4821 // end offset 8
4822 0x08, 0x00, 0x00, 0x00,
4823 // tag kRSEQ
4824 'R', 'S', 'E', 'Q',
4825 // end offset 16
4826 0x10, 0x00, 0x00, 0x00,
4827 // tag kCADR
4828 'C', 'A', 'D', 'R',
4829 // end offset 24
4830 0x18, 0x00, 0x00, 0x00,
4831 // nonce proof
4832 0x89, 0x67, 0x45, 0x23,
4833 0x01, 0xEF, 0xCD, 0xAB,
4834 // rejected packet number
4835 0xBC, 0x9A, 0x78, 0x56,
4836 0x34, 0x12, 0x00, 0x00,
4837 // client address
4838 0x02, 0x00,
4839 0x7F, 0x00, 0x00, 0x01,
4840 0x34, 0x12,
4841 };
4842
3247 unsigned char packet_no_rejected_packet_number[] = { 4843 unsigned char packet_no_rejected_packet_number[] = {
3248 // public flags (public reset, 8 byte ConnectionId) 4844 // public flags (public reset, 8 byte ConnectionId)
3249 0x0A, 4845 0x0A,
3250 // connection_id 4846 // connection_id
3251 0x10, 0x32, 0x54, 0x76, 4847 0x10, 0x32, 0x54, 0x76,
3252 0x98, 0xBA, 0xDC, 0xFE, 4848 0x98, 0xBA, 0xDC, 0xFE,
3253 // message tag (kPRST) 4849 // message tag (kPRST)
3254 'P', 'R', 'S', 'T', 4850 'P', 'R', 'S', 'T',
3255 // num_entries (2) + padding 4851 // num_entries (2) + padding
3256 0x02, 0x00, 0x00, 0x00, 4852 0x02, 0x00, 0x00, 0x00,
3257 // tag kRNON 4853 // tag kRNON
3258 'R', 'N', 'O', 'N', 4854 'R', 'N', 'O', 'N',
3259 // end offset 8 4855 // end offset 8
3260 0x08, 0x00, 0x00, 0x00, 4856 0x08, 0x00, 0x00, 0x00,
3261 // tag kCADR 4857 // tag kCADR
3262 'C', 'A', 'D', 'R', 4858 'C', 'A', 'D', 'R',
3263 // end offset 16 4859 // end offset 16
3264 0x10, 0x00, 0x00, 0x00, 4860 0x10, 0x00, 0x00, 0x00,
3265 // nonce proof 4861 // nonce proof
3266 0x89, 0x67, 0x45, 0x23, 4862 0x89, 0x67, 0x45, 0x23,
3267 0x01, 0xEF, 0xCD, 0xAB, 4863 0x01, 0xEF, 0xCD, 0xAB,
3268 // client address 4864 // client address
3269 0x02, 0x00, 4865 0x02, 0x00,
3270 0x7F, 0x00, 0x00, 0x01, 4866 0x7F, 0x00, 0x00, 0x01,
3271 0x34, 0x12, 4867 0x34, 0x12,
3272 }; 4868 };
4869
4870 unsigned char packet_no_rejected_packet_number_cid_be[] = {
4871 // public flags (public reset, 8 byte ConnectionId)
4872 0x0A,
4873 // connection_id
4874 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
4875 // message tag (kPRST)
4876 'P', 'R', 'S', 'T',
4877 // num_entries (2) + padding
4878 0x02, 0x00, 0x00, 0x00,
4879 // tag kRNON
4880 'R', 'N', 'O', 'N',
4881 // end offset 8
4882 0x08, 0x00, 0x00, 0x00,
4883 // tag kCADR
4884 'C', 'A', 'D', 'R',
4885 // end offset 16
4886 0x10, 0x00, 0x00, 0x00,
4887 // nonce proof
4888 0x89, 0x67, 0x45, 0x23,
4889 0x01, 0xEF, 0xCD, 0xAB,
4890 // client address
4891 0x02, 0x00,
4892 0x7F, 0x00, 0x00, 0x01,
4893 0x34, 0x12,
4894 };
3273 // clang-format on 4895 // clang-format on
3274 4896
3275 std::unique_ptr<QuicEncryptedPacket> data( 4897 std::unique_ptr<QuicEncryptedPacket> data(
3276 framer_.BuildPublicResetPacket(reset_packet)); 4898 framer_.BuildPublicResetPacket(reset_packet));
3277 ASSERT_TRUE(data != nullptr); 4899 ASSERT_TRUE(data != nullptr);
3278 4900
3279 if (FLAGS_quic_reloadable_flag_quic_remove_packet_number_from_public_reset) { 4901 if (FLAGS_quic_reloadable_flag_quic_remove_packet_number_from_public_reset) {
3280 test::CompareCharArraysWithHexError( 4902 test::CompareCharArraysWithHexError(
3281 "constructed packet", data->data(), data->length(), 4903 "constructed packet", data->data(), data->length(),
3282 AsChars(packet_no_rejected_packet_number), 4904 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
3283 arraysize(packet_no_rejected_packet_number)); 4905 ? packet_no_rejected_packet_number_cid_be
4906 : packet_no_rejected_packet_number),
4907
4908 FLAGS_quic_restart_flag_quic_big_endian_connection_id
4909 ? arraysize(packet_no_rejected_packet_number_cid_be)
4910 : arraysize(packet_no_rejected_packet_number));
3284 } else { 4911 } else {
3285 test::CompareCharArraysWithHexError("constructed packet", data->data(), 4912 test::CompareCharArraysWithHexError(
3286 data->length(), AsChars(packet), 4913 "constructed packet", data->data(), data->length(),
3287 arraysize(packet)); 4914 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
4915 ? packet_cid_be
4916 : packet),
4917
4918 FLAGS_quic_restart_flag_quic_big_endian_connection_id
4919 ? arraysize(packet_cid_be)
4920 : arraysize(packet));
3288 } 4921 }
3289 } 4922 }
3290 4923
3291 TEST_P(QuicFramerTest, EncryptPacket) { 4924 TEST_P(QuicFramerTest, EncryptPacket) {
3292 QuicPacketNumber packet_number = kPacketNumber; 4925 QuicPacketNumber packet_number = kPacketNumber;
3293 // clang-format off 4926 // clang-format off
3294 unsigned char packet[] = { 4927 unsigned char packet[] = {
3295 // public flags (8 byte connection_id) 4928 // public flags (8 byte connection_id)
3296 0x38, 4929 0x38,
3297 // connection_id 4930 // connection_id
3298 0x10, 0x32, 0x54, 0x76, 4931 0x10, 0x32, 0x54, 0x76,
3299 0x98, 0xBA, 0xDC, 0xFE, 4932 0x98, 0xBA, 0xDC, 0xFE,
3300 // packet number 4933 // packet number
3301 0xBC, 0x9A, 0x78, 0x56, 4934 0xBC, 0x9A, 0x78, 0x56,
3302 0x34, 0x12, 4935 0x34, 0x12,
3303 4936
3304 // redundancy 4937 // redundancy
3305 'a', 'b', 'c', 'd', 4938 'a', 'b', 'c', 'd',
3306 'e', 'f', 'g', 'h', 4939 'e', 'f', 'g', 'h',
3307 'i', 'j', 'k', 'l', 4940 'i', 'j', 'k', 'l',
3308 'm', 'n', 'o', 'p', 4941 'm', 'n', 'o', 'p',
3309 }; 4942 };
4943
4944 unsigned char packet_cid_be[] = {
4945 // public flags (8 byte connection_id)
4946 0x38,
4947 // connection_id
4948 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
4949 // packet number
4950 0xBC, 0x9A, 0x78, 0x56,
4951 0x34, 0x12,
4952
4953 // redundancy
4954 'a', 'b', 'c', 'd',
4955 'e', 'f', 'g', 'h',
4956 'i', 'j', 'k', 'l',
4957 'm', 'n', 'o', 'p',
4958 };
3310 // clang-format on 4959 // clang-format on
3311 4960
3312 std::unique_ptr<QuicPacket> raw(new QuicPacket( 4961 std::unique_ptr<QuicPacket> raw(new QuicPacket(
3313 AsChars(packet), arraysize(packet), false, PACKET_8BYTE_CONNECTION_ID, 4962 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
3314 !kIncludeVersion, !kIncludeDiversificationNonce, 4963 ? packet_cid_be
3315 PACKET_6BYTE_PACKET_NUMBER)); 4964 : packet),
4965 FLAGS_quic_restart_flag_quic_big_endian_connection_id
4966 ? arraysize(packet_cid_be)
4967 : arraysize(packet),
4968 false, PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
4969 !kIncludeDiversificationNonce, PACKET_6BYTE_PACKET_NUMBER));
3316 char buffer[kMaxPacketSize]; 4970 char buffer[kMaxPacketSize];
3317 size_t encrypted_length = framer_.EncryptPayload( 4971 size_t encrypted_length = framer_.EncryptPayload(
3318 ENCRYPTION_NONE, packet_number, *raw, buffer, kMaxPacketSize); 4972 ENCRYPTION_NONE, packet_number, *raw, buffer, kMaxPacketSize);
3319 4973
3320 ASSERT_NE(0u, encrypted_length); 4974 ASSERT_NE(0u, encrypted_length);
3321 EXPECT_TRUE(CheckEncryption(packet_number, raw.get())); 4975 EXPECT_TRUE(CheckEncryption(packet_number, raw.get()));
3322 } 4976 }
3323 4977
3324 TEST_P(QuicFramerTest, EncryptPacketWithVersionFlag) { 4978 TEST_P(QuicFramerTest, EncryptPacketWithVersionFlag) {
3325 QuicPacketNumber packet_number = kPacketNumber; 4979 QuicPacketNumber packet_number = kPacketNumber;
3326 // clang-format off 4980 // clang-format off
3327 unsigned char packet[] = { 4981 unsigned char packet[] = {
3328 // public flags (version, 8 byte connection_id) 4982 // public flags (version, 8 byte connection_id)
3329 0x39, 4983 0x39,
3330 // connection_id 4984 // connection_id
3331 0x10, 0x32, 0x54, 0x76, 4985 0x10, 0x32, 0x54, 0x76,
3332 0x98, 0xBA, 0xDC, 0xFE, 4986 0x98, 0xBA, 0xDC, 0xFE,
3333 // version tag 4987 // version tag
3334 'Q', '.', '1', '0', 4988 'Q', '.', '1', '0',
3335 // packet number 4989 // packet number
3336 0xBC, 0x9A, 0x78, 0x56, 4990 0xBC, 0x9A, 0x78, 0x56,
3337 0x34, 0x12, 4991 0x34, 0x12,
3338 4992
3339 // redundancy 4993 // redundancy
3340 'a', 'b', 'c', 'd', 4994 'a', 'b', 'c', 'd',
3341 'e', 'f', 'g', 'h', 4995 'e', 'f', 'g', 'h',
3342 'i', 'j', 'k', 'l', 4996 'i', 'j', 'k', 'l',
3343 'm', 'n', 'o', 'p', 4997 'm', 'n', 'o', 'p',
3344 }; 4998 };
4999
5000 unsigned char packet_cid_be[] = {
5001 // public flags (version, 8 byte connection_id)
5002 0x39,
5003 // connection_id
5004 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
5005 // version tag
5006 'Q', '.', '1', '0',
5007 // packet number
5008 0xBC, 0x9A, 0x78, 0x56,
5009 0x34, 0x12,
5010
5011 // redundancy
5012 'a', 'b', 'c', 'd',
5013 'e', 'f', 'g', 'h',
5014 'i', 'j', 'k', 'l',
5015 'm', 'n', 'o', 'p',
5016 };
3345 // clang-format on 5017 // clang-format on
3346 5018
3347 std::unique_ptr<QuicPacket> raw(new QuicPacket( 5019 std::unique_ptr<QuicPacket> raw(new QuicPacket(
3348 AsChars(packet), arraysize(packet), false, PACKET_8BYTE_CONNECTION_ID, 5020 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
3349 kIncludeVersion, !kIncludeDiversificationNonce, 5021 ? packet_cid_be
3350 PACKET_6BYTE_PACKET_NUMBER)); 5022 : packet),
5023 FLAGS_quic_restart_flag_quic_big_endian_connection_id
5024 ? arraysize(packet_cid_be)
5025 : arraysize(packet),
5026 false, PACKET_8BYTE_CONNECTION_ID, kIncludeVersion,
5027 !kIncludeDiversificationNonce, PACKET_6BYTE_PACKET_NUMBER));
3351 char buffer[kMaxPacketSize]; 5028 char buffer[kMaxPacketSize];
3352 size_t encrypted_length = framer_.EncryptPayload( 5029 size_t encrypted_length = framer_.EncryptPayload(
3353 ENCRYPTION_NONE, packet_number, *raw, buffer, kMaxPacketSize); 5030 ENCRYPTION_NONE, packet_number, *raw, buffer, kMaxPacketSize);
3354 5031
3355 ASSERT_NE(0u, encrypted_length); 5032 ASSERT_NE(0u, encrypted_length);
3356 EXPECT_TRUE(CheckEncryption(packet_number, raw.get())); 5033 EXPECT_TRUE(CheckEncryption(packet_number, raw.get()));
3357 } 5034 }
3358 5035
3359 TEST_P(QuicFramerTest, AckTruncationLargePacket) { 5036 TEST_P(QuicFramerTest, AckTruncationLargePacket) {
3360 QuicPacketHeader header; 5037 QuicPacketHeader header;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
3491 0x34, 0x12, 5168 0x34, 0x12,
3492 // largest observed packet number 5169 // largest observed packet number
3493 0xBF, 0x9A, 0x78, 0x56, 5170 0xBF, 0x9A, 0x78, 0x56,
3494 0x34, 0x12, 5171 0x34, 0x12,
3495 // num missing packets 5172 // num missing packets
3496 0x01, 5173 0x01,
3497 // missing packet 5174 // missing packet
3498 0xBE, 0x9A, 0x78, 0x56, 5175 0xBE, 0x9A, 0x78, 0x56,
3499 0x34, 0x12, 5176 0x34, 0x12,
3500 }; 5177 };
5178
5179 unsigned char packet_cid_be[] = {
5180 // public flags (8 byte connection_id)
5181 0x38,
5182 // connection_id
5183 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
5184 // packet number
5185 0xBC, 0x9A, 0x78, 0x56,
5186 0x34, 0x12,
5187
5188 // frame type (stream frame with fin)
5189 0xFF,
5190 // stream id
5191 0x04, 0x03, 0x02, 0x01,
5192 // offset
5193 0x54, 0x76, 0x10, 0x32,
5194 0xDC, 0xFE, 0x98, 0xBA,
5195 // data length
5196 0x0c, 0x00,
5197 // data
5198 'h', 'e', 'l', 'l',
5199 'o', ' ', 'w', 'o',
5200 'r', 'l', 'd', '!',
5201
5202 // frame type (ack frame)
5203 0x40,
5204 // least packet number awaiting an ack
5205 0xA0, 0x9A, 0x78, 0x56,
5206 0x34, 0x12,
5207 // largest observed packet number
5208 0xBF, 0x9A, 0x78, 0x56,
5209 0x34, 0x12,
5210 // num missing packets
5211 0x01,
5212 // missing packet
5213 0xBE, 0x9A, 0x78, 0x56,
5214 0x34, 0x12,
5215 };
3501 // clang-format on 5216 // clang-format on
3502 5217
3503 MockFramerVisitor visitor; 5218 MockFramerVisitor visitor;
3504 framer_.set_visitor(&visitor); 5219 framer_.set_visitor(&visitor);
3505 EXPECT_CALL(visitor, OnPacket()); 5220 EXPECT_CALL(visitor, OnPacket());
3506 EXPECT_CALL(visitor, OnPacketHeader(_)); 5221 EXPECT_CALL(visitor, OnPacketHeader(_));
3507 EXPECT_CALL(visitor, OnStreamFrame(_)).WillOnce(Return(false)); 5222 EXPECT_CALL(visitor, OnStreamFrame(_)).WillOnce(Return(false));
3508 EXPECT_CALL(visitor, OnAckFrame(_)).Times(0); 5223 EXPECT_CALL(visitor, OnAckFrame(_)).Times(0);
3509 EXPECT_CALL(visitor, OnPacketComplete()); 5224 EXPECT_CALL(visitor, OnPacketComplete());
3510 EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)).WillOnce(Return(true)); 5225 EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)).WillOnce(Return(true));
3511 EXPECT_CALL(visitor, OnUnauthenticatedHeader(_)).WillOnce(Return(true)); 5226 EXPECT_CALL(visitor, OnUnauthenticatedHeader(_)).WillOnce(Return(true));
3512 EXPECT_CALL(visitor, OnDecryptedPacket(_)); 5227 EXPECT_CALL(visitor, OnDecryptedPacket(_));
3513 5228
3514 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 5229 QuicEncryptedPacket encrypted(
5230 AsChars(FLAGS_quic_restart_flag_quic_big_endian_connection_id
5231 ? packet_cid_be
5232 : packet),
5233 FLAGS_quic_restart_flag_quic_big_endian_connection_id
5234 ? arraysize(packet_cid_be)
5235 : arraysize(packet),
5236 false);
3515 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 5237 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
3516 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 5238 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
3517 } 5239 }
3518 5240
3519 static char kTestString[] = "At least 20 characters."; 5241 static char kTestString[] = "At least 20 characters.";
3520 static QuicStreamId kTestQuicStreamId = 1; 5242 static QuicStreamId kTestQuicStreamId = 1;
3521 static bool ExpectedStreamFrame(const QuicStreamFrame& frame) { 5243 static bool ExpectedStreamFrame(const QuicStreamFrame& frame) {
3522 return frame.stream_id == kTestQuicStreamId && !frame.fin && 5244 return frame.stream_id == kTestQuicStreamId && !frame.fin &&
3523 frame.offset == 0 && 5245 frame.offset == 0 &&
3524 string(frame.data_buffer, frame.data_length) == kTestString; 5246 string(frame.data_buffer, frame.data_length) == kTestString;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
3647 // offset 5369 // offset
3648 0x54, 0x76, 0x10, 0x32, 5370 0x54, 0x76, 0x10, 0x32,
3649 0xDC, 0xFE, 0x98, 0xBA, 5371 0xDC, 0xFE, 0x98, 0xBA,
3650 // data length 5372 // data length
3651 0x0c, 0x00, 5373 0x0c, 0x00,
3652 // data 5374 // data
3653 'h', 'e', 'l', 'l', 5375 'h', 'e', 'l', 'l',
3654 'o', ' ', 'w', 'o', 5376 'o', ' ', 'w', 'o',
3655 'r', 'l', 'd', '!', 5377 'r', 'l', 'd', '!',
3656 }; 5378 };
5379
5380 unsigned char packet_cid_be[] = {
5381 // public flags (8 byte connection_id)
5382 0x3C,
5383 // connection_id
5384 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
5385 // packet number
5386 0xBC, 0x9A, 0x78, 0x56,
5387 0x34, 0x12,
5388 // private flags
5389 0x00,
5390
5391 // frame type (stream frame with fin)
5392 0xFF,
5393 // stream id
5394 0x04, 0x03, 0x02, 0x01,
5395 // offset
5396 0x54, 0x76, 0x10, 0x32,
5397 0xDC, 0xFE, 0x98, 0xBA,
5398 // data length
5399 0x0c, 0x00,
5400 // data
5401 'h', 'e', 'l', 'l',
5402 'o', ' ', 'w', 'o',
5403 'r', 'l', 'd', '!',
5404 };
3657 // clang-format on 5405 // clang-format on
3658 5406
3659 QuicFramerFuzzFunc(packet, arraysize(packet)); 5407 QuicFramerFuzzFunc(FLAGS_quic_restart_flag_quic_big_endian_connection_id
5408 ? packet_cid_be
5409 : packet,
5410 FLAGS_quic_restart_flag_quic_big_endian_connection_id
5411 ? arraysize(packet_cid_be)
5412 : arraysize(packet));
3660 } 5413 }
3661 5414
3662 } // namespace test 5415 } // namespace test
3663 } // namespace net 5416 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/quic_framer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698