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

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

Issue 2706893002: Make QuicFramer unaware of path. Also, send/receive PathClose has no effect. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/core/quic_framer.cc ('k') | net/quic/test_tools/quic_framer_peer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/quic/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 21 matching lines...) Expand all
32 32
33 namespace net { 33 namespace net {
34 namespace test { 34 namespace test {
35 35
36 const QuicPacketNumber kEpoch = UINT64_C(1) << 48; 36 const QuicPacketNumber kEpoch = UINT64_C(1) << 48;
37 const QuicPacketNumber kMask = kEpoch - 1; 37 const QuicPacketNumber kMask = kEpoch - 1;
38 38
39 // Use fields in which each byte is distinct to ensure that every byte is 39 // Use fields in which each byte is distinct to ensure that every byte is
40 // framed correctly. The values are otherwise arbitrary. 40 // framed correctly. The values are otherwise arbitrary.
41 const QuicConnectionId kConnectionId = UINT64_C(0xFEDCBA9876543210); 41 const QuicConnectionId kConnectionId = UINT64_C(0xFEDCBA9876543210);
42 const QuicPathId kPathId = 0x42;
43 const QuicPacketNumber kPacketNumber = UINT64_C(0x123456789ABC); 42 const QuicPacketNumber kPacketNumber = UINT64_C(0x123456789ABC);
44 const QuicPacketNumber kSmallLargestObserved = UINT16_C(0x1234); 43 const QuicPacketNumber kSmallLargestObserved = UINT16_C(0x1234);
45 const QuicPacketNumber kSmallMissingPacket = UINT16_C(0x1233); 44 const QuicPacketNumber kSmallMissingPacket = UINT16_C(0x1233);
46 const QuicPacketNumber kLeastUnacked = UINT64_C(0x0123456789AA0); 45 const QuicPacketNumber kLeastUnacked = UINT64_C(0x0123456789AA0);
47 const QuicStreamId kStreamId = UINT64_C(0x01020304); 46 const QuicStreamId kStreamId = UINT64_C(0x01020304);
48 const QuicStreamOffset kStreamOffset = UINT64_C(0xBA98FEDC32107654); 47 const QuicStreamOffset kStreamOffset = UINT64_C(0xBA98FEDC32107654);
49 const QuicPublicResetNonceProof kNonceProof = UINT64_C(0xABCDEF0123456789); 48 const QuicPublicResetNonceProof kNonceProof = UINT64_C(0xABCDEF0123456789);
50 49
51 // Index into the connection_id offset in the header. 50 // Index into the connection_id offset in the header.
52 const size_t kConnectionIdOffset = kPublicFlagsSize; 51 const size_t kConnectionIdOffset = kPublicFlagsSize;
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 expected_error = "Unable to read ConnectionId."; 753 expected_error = "Unable to read ConnectionId.";
755 } else if (i < GetPacketNumberOffset(kIncludeVersion, !kIncludePathId)) { 754 } else if (i < GetPacketNumberOffset(kIncludeVersion, !kIncludePathId)) {
756 expected_error = "Unable to read protocol version."; 755 expected_error = "Unable to read protocol version.";
757 } else { 756 } else {
758 expected_error = "Unable to read packet number."; 757 expected_error = "Unable to read packet number.";
759 } 758 }
760 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER); 759 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER);
761 } 760 }
762 } 761 }
763 762
764 TEST_P(QuicFramerTest, PacketHeaderWithPathChange) {
765 // Packet 1 from path 0x42.
766 // clang-format off
767 unsigned char packet1[] = {
768 // public flags (version)
769 0x78,
770 // connection_id
771 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
772 // path_id
773 0x42,
774 // packet number
775 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
776 };
777 // clang-format on
778
779 EXPECT_EQ(0u, QuicFramerPeer::GetLastPacketNumber(&framer_));
780 EXPECT_EQ(kInvalidPathId, QuicFramerPeer::GetLastPathId(&framer_));
781 QuicEncryptedPacket encrypted1(AsChars(packet1), arraysize(packet1), false);
782 EXPECT_FALSE(framer_.ProcessPacket(encrypted1));
783 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
784 ASSERT_TRUE(visitor_.header_.get());
785 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id);
786 EXPECT_EQ(kPathId, visitor_.header_->path_id);
787 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number);
788 EXPECT_EQ(kPacketNumber, QuicFramerPeer::GetLastPacketNumber(&framer_));
789 EXPECT_EQ(kPathId, QuicFramerPeer::GetLastPathId(&framer_));
790
791 // Packet 2 from default path.
792 // clang-format off
793 unsigned char packet2[] = {
794 // public flags (version)
795 0x78,
796 // connection_id
797 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
798 // path_id
799 0x00,
800 // packet number
801 0xCC, 0x9A, 0x78, 0x56, 0x34, 0x12,
802 };
803 // clang-format on
804
805 QuicEncryptedPacket encrypted2(AsChars(packet2), arraysize(packet2), false);
806 EXPECT_FALSE(framer_.ProcessPacket(encrypted2));
807 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
808 ASSERT_TRUE(visitor_.header_.get());
809 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id);
810 EXPECT_EQ(kDefaultPathId, visitor_.header_->path_id);
811 EXPECT_EQ(kPacketNumber + 16, visitor_.header_->packet_number);
812 EXPECT_EQ(kPacketNumber + 16, QuicFramerPeer::GetLastPacketNumber(&framer_));
813 EXPECT_EQ(kDefaultPathId, QuicFramerPeer::GetLastPathId(&framer_));
814
815 // Packet 3 from path 0x42.
816 // clang-format off
817 unsigned char packet3[] = {
818 // public flags (version)
819 0x78,
820 // connection_id
821 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
822 // path_id
823 0x42,
824 // packet number
825 0xBD, 0x9A, 0x78, 0x56, 0x34, 0x12,
826 };
827 // clang-format on
828
829 QuicEncryptedPacket encrypted3(AsChars(packet3), arraysize(packet3), false);
830 EXPECT_FALSE(framer_.ProcessPacket(encrypted3));
831 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
832 ASSERT_TRUE(visitor_.header_.get());
833 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id);
834 EXPECT_EQ(kPathId, visitor_.header_->path_id);
835 EXPECT_EQ(kPacketNumber + 1, visitor_.header_->packet_number);
836 EXPECT_EQ(kPacketNumber + 1, QuicFramerPeer::GetLastPacketNumber(&framer_));
837 EXPECT_EQ(kPathId, QuicFramerPeer::GetLastPathId(&framer_));
838 }
839
840 TEST_P(QuicFramerTest, ReceivedPacketOnClosedPath) {
841 // Packet 1 from path 0x42.
842 // clang-format off
843 unsigned char packet[] = {
844 // public flags (version)
845 0x78,
846 // connection_id
847 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
848 // path_id
849 0x42,
850 // packet number
851 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
852 // private flags
853 0x00,
854 };
855 // clang-format on
856
857 framer_.OnPathClosed(kPathId);
858 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
859 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
860 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
861 EXPECT_EQ(0u, QuicFramerPeer::GetLastPacketNumber(&framer_));
862 EXPECT_EQ(kInvalidPathId, QuicFramerPeer::GetLastPathId(&framer_));
863 }
864
865 TEST_P(QuicFramerTest, PacketHeaderWith4BytePacketNumber) { 763 TEST_P(QuicFramerTest, PacketHeaderWith4BytePacketNumber) {
866 QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2); 764 QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2);
867 765
868 // clang-format off 766 // clang-format off
869 unsigned char packet[] = { 767 unsigned char packet[] = {
870 // public flags (8 byte connection_id and 4 byte packet number) 768 // public flags (8 byte connection_id and 4 byte packet number)
871 0x28, 769 0x28,
872 // connection_id 770 // connection_id
873 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, 771 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
874 // packet number 772 // packet number
(...skipping 2922 matching lines...) Expand 10 before | Expand all | Expand 10 after
3797 'o', ' ', 'w', 'o', 3695 'o', ' ', 'w', 'o',
3798 'r', 'l', 'd', '!', 3696 'r', 'l', 'd', '!',
3799 }; 3697 };
3800 // clang-format on 3698 // clang-format on
3801 3699
3802 QuicFramerFuzzFunc(packet, arraysize(packet)); 3700 QuicFramerFuzzFunc(packet, arraysize(packet));
3803 } 3701 }
3804 3702
3805 } // namespace test 3703 } // namespace test
3806 } // namespace net 3704 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/quic_framer.cc ('k') | net/quic/test_tools/quic_framer_peer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698