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

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

Issue 862133002: Update from https://crrev.com/312398 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/quic/quic_framer.h" 5 #include "net/quic/quic_framer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 fec_count_(0), 174 fec_count_(0),
175 complete_packets_(0), 175 complete_packets_(0),
176 revived_packets_(0), 176 revived_packets_(0),
177 accept_packet_(true), 177 accept_packet_(true),
178 accept_public_header_(true) { 178 accept_public_header_(true) {
179 } 179 }
180 180
181 ~TestQuicVisitor() override { 181 ~TestQuicVisitor() override {
182 STLDeleteElements(&stream_frames_); 182 STLDeleteElements(&stream_frames_);
183 STLDeleteElements(&ack_frames_); 183 STLDeleteElements(&ack_frames_);
184 STLDeleteElements(&congestion_feedback_frames_);
185 STLDeleteElements(&stop_waiting_frames_); 184 STLDeleteElements(&stop_waiting_frames_);
186 STLDeleteElements(&ping_frames_); 185 STLDeleteElements(&ping_frames_);
187 STLDeleteElements(&fec_data_); 186 STLDeleteElements(&fec_data_);
188 } 187 }
189 188
190 void OnError(QuicFramer* f) override { 189 void OnError(QuicFramer* f) override {
191 DVLOG(1) << "QuicFramer Error: " << QuicUtils::ErrorToString(f->error()) 190 DVLOG(1) << "QuicFramer Error: " << QuicUtils::ErrorToString(f->error())
192 << " (" << f->error() << ")"; 191 << " (" << f->error() << ")";
193 ++error_count_; 192 ++error_count_;
194 } 193 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 void OnFecProtectedPayload(StringPiece payload) override { 238 void OnFecProtectedPayload(StringPiece payload) override {
240 fec_protected_payload_ = payload.as_string(); 239 fec_protected_payload_ = payload.as_string();
241 } 240 }
242 241
243 bool OnAckFrame(const QuicAckFrame& frame) override { 242 bool OnAckFrame(const QuicAckFrame& frame) override {
244 ++frame_count_; 243 ++frame_count_;
245 ack_frames_.push_back(new QuicAckFrame(frame)); 244 ack_frames_.push_back(new QuicAckFrame(frame));
246 return true; 245 return true;
247 } 246 }
248 247
249 bool OnCongestionFeedbackFrame(
250 const QuicCongestionFeedbackFrame& frame) override {
251 ++frame_count_;
252 congestion_feedback_frames_.push_back(
253 new QuicCongestionFeedbackFrame(frame));
254 return true;
255 }
256
257 bool OnStopWaitingFrame(const QuicStopWaitingFrame& frame) override { 248 bool OnStopWaitingFrame(const QuicStopWaitingFrame& frame) override {
258 ++frame_count_; 249 ++frame_count_;
259 stop_waiting_frames_.push_back(new QuicStopWaitingFrame(frame)); 250 stop_waiting_frames_.push_back(new QuicStopWaitingFrame(frame));
260 return true; 251 return true;
261 } 252 }
262 253
263 bool OnPingFrame(const QuicPingFrame& frame) override { 254 bool OnPingFrame(const QuicPingFrame& frame) override {
264 ++frame_count_; 255 ++frame_count_;
265 ping_frames_.push_back(new QuicPingFrame(frame)); 256 ping_frames_.push_back(new QuicPingFrame(frame));
266 return true; 257 return true;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 int revived_packets_; 299 int revived_packets_;
309 bool accept_packet_; 300 bool accept_packet_;
310 bool accept_public_header_; 301 bool accept_public_header_;
311 302
312 scoped_ptr<QuicPacketHeader> header_; 303 scoped_ptr<QuicPacketHeader> header_;
313 scoped_ptr<QuicPacketPublicHeader> public_header_; 304 scoped_ptr<QuicPacketPublicHeader> public_header_;
314 scoped_ptr<QuicPublicResetPacket> public_reset_packet_; 305 scoped_ptr<QuicPublicResetPacket> public_reset_packet_;
315 scoped_ptr<QuicVersionNegotiationPacket> version_negotiation_packet_; 306 scoped_ptr<QuicVersionNegotiationPacket> version_negotiation_packet_;
316 vector<QuicStreamFrame*> stream_frames_; 307 vector<QuicStreamFrame*> stream_frames_;
317 vector<QuicAckFrame*> ack_frames_; 308 vector<QuicAckFrame*> ack_frames_;
318 vector<QuicCongestionFeedbackFrame*> congestion_feedback_frames_;
319 vector<QuicStopWaitingFrame*> stop_waiting_frames_; 309 vector<QuicStopWaitingFrame*> stop_waiting_frames_;
320 vector<QuicPingFrame*> ping_frames_; 310 vector<QuicPingFrame*> ping_frames_;
321 vector<QuicFecData*> fec_data_; 311 vector<QuicFecData*> fec_data_;
322 string fec_protected_payload_; 312 string fec_protected_payload_;
323 QuicRstStreamFrame rst_stream_frame_; 313 QuicRstStreamFrame rst_stream_frame_;
324 QuicConnectionCloseFrame connection_close_frame_; 314 QuicConnectionCloseFrame connection_close_frame_;
325 QuicGoAwayFrame goaway_frame_; 315 QuicGoAwayFrame goaway_frame_;
326 QuicWindowUpdateFrame window_update_frame_; 316 QuicWindowUpdateFrame window_update_frame_;
327 QuicBlockedFrame blocked_frame_; 317 QuicBlockedFrame blocked_frame_;
328 }; 318 };
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 577
588 TEST_P(QuicFramerTest, EmptyPacket) { 578 TEST_P(QuicFramerTest, EmptyPacket) {
589 char packet[] = { 0x00 }; 579 char packet[] = { 0x00 };
590 QuicEncryptedPacket encrypted(packet, 0, false); 580 QuicEncryptedPacket encrypted(packet, 0, false);
591 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); 581 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
592 EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error()); 582 EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error());
593 } 583 }
594 584
595 TEST_P(QuicFramerTest, LargePacket) { 585 TEST_P(QuicFramerTest, LargePacket) {
596 unsigned char packet[kMaxPacketSize + 1] = { 586 unsigned char packet[kMaxPacketSize + 1] = {
597 // public flags (8 byte connection_id) 587 // public flags (8 byte connection_id)
598 0x3C, 588 0x3C,
599 // connection_id 589 // connection_id
600 0x10, 0x32, 0x54, 0x76, 590 0x10,
601 0x98, 0xBA, 0xDC, 0xFE, 591 0x32,
602 // packet sequence number 592 0x54,
603 0xBC, 0x9A, 0x78, 0x56, 593 0x76,
604 0x34, 0x12, 594 0x98,
605 // private flags 595 0xBA,
606 0x00, 596 0xDC,
597 0xFE,
598 // packet sequence number
599 0xBC,
600 0x9A,
601 0x78,
602 0x56,
603 0x34,
604 0x12,
605 // private flags
606 0x00,
607 }; 607 };
608 608
609 memset(packet + GetPacketHeaderSize( 609 memset(packet + GetPacketHeaderSize(
610 PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 610 PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
611 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), 0, 611 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), 0,
612 kMaxPacketSize - GetPacketHeaderSize( 612 kMaxPacketSize - GetPacketHeaderSize(
613 PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 613 PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
614 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP) + 1); 614 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP) + 1);
615 615
616 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 616 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
(...skipping 1030 matching lines...) Expand 10 before | Expand all | Expand 10 after
1647 1647
1648 ASSERT_EQ(1u, visitor_.stream_frames_.size()); 1648 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1649 EXPECT_EQ(0u, visitor_.ack_frames_.size()); 1649 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1650 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_.stream_frames_[0]->stream_id); 1650 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_.stream_frames_[0]->stream_id);
1651 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); 1651 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1652 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654), 1652 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1653 visitor_.stream_frames_[0]->offset); 1653 visitor_.stream_frames_[0]->offset);
1654 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); 1654 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]);
1655 } 1655 }
1656 1656
1657 TEST_P(QuicFramerTest, AckFramev22) { 1657 TEST_P(QuicFramerTest, AckFrameTwoTimestamp) {
1658 if (version_ > QUIC_VERSION_22) {
1659 return;
1660 }
1661 unsigned char packet[] = { 1658 unsigned char packet[] = {
1662 // public flags (8 byte connection_id) 1659 // public flags (8 byte connection_id)
1663 0x3C, 1660 0x3C,
1664 // connection_id 1661 // connection_id
1665 0x10, 0x32, 0x54, 0x76, 1662 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
1666 0x98, 0xBA, 0xDC, 0xFE, 1663 // packet sequence number
1667 // packet sequence number 1664 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
1668 0xA8, 0x9A, 0x78, 0x56, 1665 // private flags (entropy)
1669 0x34, 0x12, 1666 0x01,
1670 // private flags (entropy)
1671 0x01,
1672 1667
1673 // frame type (ack frame) 1668 // frame type (ack frame)
1674 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) 1669 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
1675 0x6C, 1670 0x6C,
1676 // entropy hash of all received packets. 1671 // entropy hash of all received packets.
1677 0xBA, 1672 0xBA,
1678 // largest observed packet sequence number 1673 // largest observed packet sequence number
1679 0xBF, 0x9A, 0x78, 0x56, 1674 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12,
1680 0x34, 0x12, 1675 // Zero delta time.
1681 // Zero delta time. 1676 0x00, 0x00,
1682 0x0, 0x0, 1677 // Number of timestamps.
1683 // num missing packets 1678 0x02,
1684 0x01, 1679 // Delta from largest observed.
1685 // missing packet delta 1680 0x01,
1686 0x01, 1681 // Delta time.
1687 // 0 more missing packets in range. 1682 0x10, 0x32, 0x54, 0x76,
1688 0x00, 1683 // Delta from largest observed.
1689 // Number of revived packets. 1684 0x02,
1690 0x00, 1685 // Delta time.
1686 0x10, 0x32,
1687 // num missing packets
1688 0x01,
1689 // missing packet delta
1690 0x01,
1691 // 0 more missing packets in range.
1692 0x00,
1693 // Number of revived packets.
1694 0x00,
1691 }; 1695 };
1692 1696
1693 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1697 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1694 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1695
1696 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1697 ASSERT_TRUE(visitor_.header_.get());
1698 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1699
1700 EXPECT_EQ(0u, visitor_.stream_frames_.size());
1701 ASSERT_EQ(1u, visitor_.ack_frames_.size());
1702 const QuicAckFrame& frame = *visitor_.ack_frames_[0];
1703 EXPECT_EQ(0xBA, frame.entropy_hash);
1704 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame.largest_observed);
1705 ASSERT_EQ(1u, frame.missing_packets.size());
1706 SequenceNumberSet::const_iterator missing_iter =
1707 frame.missing_packets.begin();
1708 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter);
1709
1710 const size_t kReceivedEntropyOffset = kQuicFrameTypeSize;
1711 const size_t kLargestObservedOffset = kReceivedEntropyOffset +
1712 kQuicEntropyHashSize;
1713 const size_t kMissingDeltaTimeOffset = kLargestObservedOffset +
1714 PACKET_6BYTE_SEQUENCE_NUMBER;
1715 const size_t kNumMissingPacketOffset = kMissingDeltaTimeOffset +
1716 kQuicDeltaTimeLargestObservedSize;
1717 const size_t kMissingPacketsOffset = kNumMissingPacketOffset +
1718 kNumberOfNackRangesSize;
1719 const size_t kMissingPacketsRange = kMissingPacketsOffset +
1720 PACKET_1BYTE_SEQUENCE_NUMBER;
1721 const size_t kRevivedPacketsLength = kMissingPacketsRange +
1722 PACKET_1BYTE_SEQUENCE_NUMBER;
1723 // Now test framing boundaries.
1724 const size_t ack_frame_size = kRevivedPacketsLength +
1725 PACKET_1BYTE_SEQUENCE_NUMBER;
1726 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) {
1727 string expected_error;
1728 if (i < kLargestObservedOffset) {
1729 expected_error = "Unable to read entropy hash for received packets.";
1730 } else if (i < kMissingDeltaTimeOffset) {
1731 expected_error = "Unable to read largest observed.";
1732 } else if (i < kNumMissingPacketOffset) {
1733 expected_error = "Unable to read delta time largest observed.";
1734 } else if (i < kMissingPacketsOffset) {
1735 expected_error = "Unable to read num missing packet ranges.";
1736 } else if (i < kMissingPacketsRange) {
1737 expected_error = "Unable to read missing sequence number delta.";
1738 } else if (i < kRevivedPacketsLength) {
1739 expected_error = "Unable to read missing sequence number range.";
1740 } else {
1741 expected_error = "Unable to read num revived packets.";
1742 }
1743 CheckProcessingFails(
1744 packet,
1745 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
1746 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP),
1747 expected_error, QUIC_INVALID_ACK_DATA);
1748 }
1749 }
1750
1751
1752 TEST_P(QuicFramerTest, AckFrameTwoTimestamp) {
1753 if (version_ <= QUIC_VERSION_22) {
1754 return;
1755 }
1756 unsigned char packet[] = {
1757 // public flags (8 byte connection_id)
1758 0x3C,
1759 // connection_id
1760 0x10, 0x32, 0x54, 0x76,
1761 0x98, 0xBA, 0xDC, 0xFE,
1762 // packet sequence number
1763 0xA8, 0x9A, 0x78, 0x56,
1764 0x34, 0x12,
1765 // private flags (entropy)
1766 0x01,
1767
1768 // frame type (ack frame)
1769 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
1770 0x6C,
1771 // entropy hash of all received packets.
1772 0xBA,
1773 // largest observed packet sequence number
1774 0xBF, 0x9A, 0x78, 0x56,
1775 0x34, 0x12,
1776 // Zero delta time.
1777 0x0, 0x0,
1778 // Number of timestamps.
1779 0x02,
1780 // Delta from largest observed.
1781 0x01,
1782 // Delta time.
1783 0x10, 0x32, 0x54, 0x76,
1784 // Delta from largest observed.
1785 0x02,
1786 // Delta time.
1787 0x10, 0x32,
1788 // num missing packets
1789 0x01,
1790 // missing packet delta
1791 0x01,
1792 // 0 more missing packets in range.
1793 0x00,
1794 // Number of revived packets.
1795 0x00,
1796 };
1797
1798 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1799 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1698 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1800 1699
1801 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1700 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1802 ASSERT_TRUE(visitor_.header_.get()); 1701 ASSERT_TRUE(visitor_.header_.get());
1803 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 1702 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1804 1703
1805 EXPECT_EQ(0u, visitor_.stream_frames_.size()); 1704 EXPECT_EQ(0u, visitor_.stream_frames_.size());
1806 ASSERT_EQ(1u, visitor_.ack_frames_.size()); 1705 ASSERT_EQ(1u, visitor_.ack_frames_.size());
1807 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; 1706 const QuicAckFrame& frame = *visitor_.ack_frames_[0];
1808 EXPECT_EQ(0xBA, frame.entropy_hash); 1707 EXPECT_EQ(0xBA, frame.entropy_hash);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1870 CheckProcessingFails( 1769 CheckProcessingFails(
1871 packet, 1770 packet,
1872 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 1771 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
1873 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), 1772 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP),
1874 expected_error, QUIC_INVALID_ACK_DATA); 1773 expected_error, QUIC_INVALID_ACK_DATA);
1875 } 1774 }
1876 } 1775 }
1877 1776
1878 1777
1879 TEST_P(QuicFramerTest, AckFrameOneTimestamp) { 1778 TEST_P(QuicFramerTest, AckFrameOneTimestamp) {
1880 if (version_ <= QUIC_VERSION_22) {
1881 return;
1882 }
1883 unsigned char packet[] = { 1779 unsigned char packet[] = {
1884 // public flags (8 byte connection_id) 1780 // public flags (8 byte connection_id)
1885 0x3C, 1781 0x3C,
1886 // connection_id 1782 // connection_id
1887 0x10, 0x32, 0x54, 0x76, 1783 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
1888 0x98, 0xBA, 0xDC, 0xFE, 1784 // packet sequence number
1889 // packet sequence number 1785 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
1890 0xA8, 0x9A, 0x78, 0x56, 1786 // private flags (entropy)
1891 0x34, 0x12, 1787 0x01,
1892 // private flags (entropy)
1893 0x01,
1894 1788
1895 // frame type (ack frame) 1789 // frame type (ack frame)
1896 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) 1790 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
1897 0x6C, 1791 0x6C,
1898 // entropy hash of all received packets. 1792 // entropy hash of all received packets.
1899 0xBA, 1793 0xBA,
1900 // largest observed packet sequence number 1794 // largest observed packet sequence number
1901 0xBF, 0x9A, 0x78, 0x56, 1795 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12,
1902 0x34, 0x12, 1796 // Zero delta time.
1903 // Zero delta time. 1797 0x00, 0x00,
1904 0x0, 0x0, 1798 // Number of timestamps.
1905 // Number of timestamps. 1799 0x01,
1906 0x01, 1800 // Delta from largest observed.
1907 // Delta from largest observed. 1801 0x01,
1908 0x01, 1802 // Delta time.
1909 // Delta time. 1803 0x10, 0x32, 0x54, 0x76,
1910 0x10, 0x32, 0x54, 0x76, 1804 // num missing packets
1911 // num missing packets 1805 0x01,
1912 0x01, 1806 // missing packet delta
1913 // missing packet delta 1807 0x01,
1914 0x01, 1808 // 0 more missing packets in range.
1915 // 0 more missing packets in range. 1809 0x00,
1916 0x00, 1810 // Number of revived packets.
1917 // Number of revived packets. 1811 0x00,
1918 0x00,
1919 }; 1812 };
1920 1813
1921 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1814 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1922 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1815 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1923 1816
1924 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1817 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1925 ASSERT_TRUE(visitor_.header_.get()); 1818 ASSERT_TRUE(visitor_.header_.get());
1926 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 1819 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1927 1820
1928 EXPECT_EQ(0u, visitor_.stream_frames_.size()); 1821 EXPECT_EQ(0u, visitor_.stream_frames_.size());
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1983 CheckProcessingFails( 1876 CheckProcessingFails(
1984 packet, 1877 packet,
1985 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 1878 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
1986 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), 1879 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP),
1987 expected_error, QUIC_INVALID_ACK_DATA); 1880 expected_error, QUIC_INVALID_ACK_DATA);
1988 } 1881 }
1989 } 1882 }
1990 1883
1991 1884
1992 TEST_P(QuicFramerTest, AckFrame) { 1885 TEST_P(QuicFramerTest, AckFrame) {
1993 if (version_ <= QUIC_VERSION_22) {
1994 return;
1995 }
1996 unsigned char packet[] = { 1886 unsigned char packet[] = {
1997 // public flags (8 byte connection_id) 1887 // public flags (8 byte connection_id)
1998 0x3C, 1888 0x3C,
1999 // connection_id 1889 // connection_id
2000 0x10, 0x32, 0x54, 0x76, 1890 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
2001 0x98, 0xBA, 0xDC, 0xFE, 1891 // packet sequence number
2002 // packet sequence number 1892 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
2003 0xA8, 0x9A, 0x78, 0x56, 1893 // private flags (entropy)
2004 0x34, 0x12, 1894 0x01,
2005 // private flags (entropy)
2006 0x01,
2007 1895
2008 // frame type (ack frame) 1896 // frame type (ack frame)
2009 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) 1897 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
2010 0x6C, 1898 0x6C,
2011 // entropy hash of all received packets. 1899 // entropy hash of all received packets.
2012 0xBA, 1900 0xBA,
2013 // largest observed packet sequence number 1901 // largest observed packet sequence number
2014 0xBF, 0x9A, 0x78, 0x56, 1902 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12,
2015 0x34, 0x12, 1903 // Zero delta time.
2016 // Zero delta time. 1904 0x00, 0x00,
2017 0x0, 0x0, 1905 // Number of timestamps.
2018 // Number of timestamps. 1906 0x00,
2019 0x00, 1907 // num missing packets
2020 // num missing packets 1908 0x01,
2021 0x01, 1909 // missing packet delta
2022 // missing packet delta 1910 0x01,
2023 0x01, 1911 // 0 more missing packets in range.
2024 // 0 more missing packets in range. 1912 0x00,
2025 0x00, 1913 // Number of revived packets.
2026 // Number of revived packets. 1914 0x00,
2027 0x00,
2028 }; 1915 };
2029 1916
2030 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1917 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2031 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1918 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2032 1919
2033 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1920 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2034 ASSERT_TRUE(visitor_.header_.get()); 1921 ASSERT_TRUE(visitor_.header_.get());
2035 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 1922 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2036 1923
2037 EXPECT_EQ(0u, visitor_.stream_frames_.size()); 1924 EXPECT_EQ(0u, visitor_.stream_frames_.size());
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2083 } 1970 }
2084 CheckProcessingFails( 1971 CheckProcessingFails(
2085 packet, 1972 packet,
2086 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 1973 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
2087 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), 1974 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP),
2088 expected_error, QUIC_INVALID_ACK_DATA); 1975 expected_error, QUIC_INVALID_ACK_DATA);
2089 } 1976 }
2090 } 1977 }
2091 1978
2092 TEST_P(QuicFramerTest, AckFrameRevivedPackets) { 1979 TEST_P(QuicFramerTest, AckFrameRevivedPackets) {
2093 if (version_ <= QUIC_VERSION_22) {
2094 return;
2095 }
2096 unsigned char packet[] = { 1980 unsigned char packet[] = {
2097 // public flags (8 byte connection_id) 1981 // public flags (8 byte connection_id)
2098 0x3C, 1982 0x3C,
2099 // connection_id 1983 // connection_id
2100 0x10, 0x32, 0x54, 0x76, 1984 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
2101 0x98, 0xBA, 0xDC, 0xFE, 1985 // packet sequence number
2102 // packet sequence number 1986 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
2103 0xA8, 0x9A, 0x78, 0x56, 1987 // private flags (entropy)
2104 0x34, 0x12, 1988 0x01,
2105 // private flags (entropy)
2106 0x01,
2107 1989
2108 // frame type (ack frame) 1990 // frame type (ack frame)
2109 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) 1991 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
2110 0x6C, 1992 0x6C,
2111 // entropy hash of all received packets. 1993 // entropy hash of all received packets.
2112 0xBA, 1994 0xBA,
2113 // largest observed packet sequence number 1995 // largest observed packet sequence number
2114 0xBF, 0x9A, 0x78, 0x56, 1996 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12,
2115 0x34, 0x12, 1997 // Zero delta time.
2116 // Zero delta time. 1998 0x00, 0x00,
2117 0x0, 0x0, 1999 // num received packets.
2118 // num received packets. 2000 0x00,
2119 0x00, 2001 // num missing packets
2120 // num missing packets 2002 0x01,
2121 0x01, 2003 // missing packet delta
2122 // missing packet delta 2004 0x01,
2123 0x01, 2005 // 0 more missing packets in range.
2124 // 0 more missing packets in range. 2006 0x00,
2125 0x00, 2007 // Number of revived packets.
2126 // Number of revived packets. 2008 0x01,
2127 0x01, 2009 // Revived packet sequence number.
2128 // Revived packet sequence number. 2010 0xBE, 0x9A, 0x78, 0x56, 0x34, 0x12,
2129 0xBE, 0x9A, 0x78, 0x56, 2011 // Number of revived packets.
2130 0x34, 0x12, 2012 0x00,
2131 // Number of revived packets.
2132 0x00,
2133 }; 2013 };
2134 2014
2135 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 2015 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2136 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2016 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2137 2017
2138 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2018 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2139 ASSERT_TRUE(visitor_.header_.get()); 2019 ASSERT_TRUE(visitor_.header_.get());
2140 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 2020 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2141 2021
2142 EXPECT_EQ(0u, visitor_.stream_frames_.size()); 2022 EXPECT_EQ(0u, visitor_.stream_frames_.size());
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
2193 expected_error = "Unable to read revived packet."; 2073 expected_error = "Unable to read revived packet.";
2194 } 2074 }
2195 CheckProcessingFails( 2075 CheckProcessingFails(
2196 packet, 2076 packet,
2197 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 2077 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
2198 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), 2078 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP),
2199 expected_error, QUIC_INVALID_ACK_DATA); 2079 expected_error, QUIC_INVALID_ACK_DATA);
2200 } 2080 }
2201 } 2081 }
2202 2082
2203 TEST_P(QuicFramerTest, AckFrameRevivedPacketsv22) { 2083 TEST_P(QuicFramerTest, AckFrameNoNacks) {
2204 if (version_ > QUIC_VERSION_22) {
2205 return;
2206 }
2207 unsigned char packet[] = { 2084 unsigned char packet[] = {
2208 // public flags (8 byte connection_id) 2085 // public flags (8 byte connection_id)
2209 0x3C, 2086 0x3C,
2210 // connection_id 2087 // connection_id
2211 0x10, 0x32, 0x54, 0x76, 2088 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
2212 0x98, 0xBA, 0xDC, 0xFE, 2089 // packet sequence number
2213 // packet sequence number 2090 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
2214 0xA8, 0x9A, 0x78, 0x56, 2091 // private flags (entropy)
2215 0x34, 0x12, 2092 0x01,
2216 // private flags (entropy)
2217 0x01,
2218 2093
2219 // frame type (ack frame) 2094 // frame type (ack frame)
2220 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) 2095 // (no nacks, not truncated, 6 byte largest observed, 1 byte delta)
2221 0x6C, 2096 0x4C,
2222 // entropy hash of all received packets. 2097 // entropy hash of all received packets.
2223 0xBA, 2098 0xBA,
2224 // largest observed packet sequence number 2099 // largest observed packet sequence number
2225 0xBF, 0x9A, 0x78, 0x56, 2100 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12,
2226 0x34, 0x12, 2101 // Zero delta time.
2227 // Zero delta time. 2102 0x00, 0x00,
2228 0x0, 0x0, 2103 // Number of received packets.
2229 // num missing packets 2104 0x00,
2230 0x01,
2231 // missing packet delta
2232 0x01,
2233 // 0 more missing packets in range.
2234 0x00,
2235 // Number of revived packets.
2236 0x01,
2237 // Revived packet sequence number.
2238 0xBE, 0x9A, 0x78, 0x56,
2239 0x34, 0x12,
2240 // Number of revived packets.
2241 0x00,
2242 }; 2105 };
2243 2106
2244 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 2107 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2245 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2108 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2246 2109
2247 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2110 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2248 ASSERT_TRUE(visitor_.header_.get()); 2111 ASSERT_TRUE(visitor_.header_.get());
2249 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 2112 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2250 2113
2251 EXPECT_EQ(0u, visitor_.stream_frames_.size()); 2114 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2252 ASSERT_EQ(1u, visitor_.ack_frames_.size()); 2115 ASSERT_EQ(1u, visitor_.ack_frames_.size());
2253 const QuicAckFrame& frame = *visitor_.ack_frames_[0];
2254 EXPECT_EQ(0xBA, frame.entropy_hash);
2255 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame.largest_observed);
2256 ASSERT_EQ(1u, frame.missing_packets.size());
2257 SequenceNumberSet::const_iterator missing_iter =
2258 frame.missing_packets.begin();
2259 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter);
2260
2261 const size_t kReceivedEntropyOffset = kQuicFrameTypeSize;
2262 const size_t kLargestObservedOffset = kReceivedEntropyOffset +
2263 kQuicEntropyHashSize;
2264 const size_t kMissingDeltaTimeOffset = kLargestObservedOffset +
2265 PACKET_6BYTE_SEQUENCE_NUMBER;
2266 const size_t kNumMissingPacketOffset = kMissingDeltaTimeOffset +
2267 kQuicDeltaTimeLargestObservedSize;
2268 const size_t kMissingPacketsOffset = kNumMissingPacketOffset +
2269 kNumberOfNackRangesSize;
2270 const size_t kMissingPacketsRange = kMissingPacketsOffset +
2271 PACKET_1BYTE_SEQUENCE_NUMBER;
2272 const size_t kRevivedPacketsLength = kMissingPacketsRange +
2273 PACKET_1BYTE_SEQUENCE_NUMBER;
2274 const size_t kRevivedPacketSequenceNumberLength = kRevivedPacketsLength +
2275 PACKET_1BYTE_SEQUENCE_NUMBER;
2276 // Now test framing boundaries.
2277 const size_t ack_frame_size = kRevivedPacketSequenceNumberLength +
2278 PACKET_6BYTE_SEQUENCE_NUMBER;
2279 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) {
2280 string expected_error;
2281 if (i < kReceivedEntropyOffset) {
2282 expected_error = "Unable to read least unacked delta.";
2283 } else if (i < kLargestObservedOffset) {
2284 expected_error = "Unable to read entropy hash for received packets.";
2285 } else if (i < kMissingDeltaTimeOffset) {
2286 expected_error = "Unable to read largest observed.";
2287 } else if (i < kNumMissingPacketOffset) {
2288 expected_error = "Unable to read delta time largest observed.";
2289 } else if (i < kMissingPacketsOffset) {
2290 expected_error = "Unable to read num missing packet ranges.";
2291 } else if (i < kMissingPacketsRange) {
2292 expected_error = "Unable to read missing sequence number delta.";
2293 } else if (i < kRevivedPacketsLength) {
2294 expected_error = "Unable to read missing sequence number range.";
2295 } else if (i < kRevivedPacketSequenceNumberLength) {
2296 expected_error = "Unable to read num revived packets.";
2297 } else {
2298 expected_error = "Unable to read revived packet.";
2299 }
2300 CheckProcessingFails(
2301 packet,
2302 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
2303 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP),
2304 expected_error, QUIC_INVALID_ACK_DATA);
2305 }
2306 }
2307
2308 TEST_P(QuicFramerTest, AckFrameNoNacksv22) {
2309 if (version_ > QUIC_VERSION_22) {
2310 return;
2311 }
2312 unsigned char packet[] = {
2313 // public flags (8 byte connection_id)
2314 0x3C,
2315 // connection_id
2316 0x10, 0x32, 0x54, 0x76,
2317 0x98, 0xBA, 0xDC, 0xFE,
2318 // packet sequence number
2319 0xA8, 0x9A, 0x78, 0x56,
2320 0x34, 0x12,
2321 // private flags (entropy)
2322 0x01,
2323
2324 // frame type (ack frame)
2325 // (no nacks, not truncated, 6 byte largest observed, 1 byte delta)
2326 0x4C,
2327 // entropy hash of all received packets.
2328 0xBA,
2329 // largest observed packet sequence number
2330 0xBF, 0x9A, 0x78, 0x56,
2331 0x34, 0x12,
2332 // Zero delta time.
2333 0x0, 0x0,
2334 };
2335
2336 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2337 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2338
2339 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2340 ASSERT_TRUE(visitor_.header_.get());
2341 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2342
2343 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2344 ASSERT_EQ(1u, visitor_.ack_frames_.size());
2345 QuicAckFrame* frame = visitor_.ack_frames_[0]; 2116 QuicAckFrame* frame = visitor_.ack_frames_[0];
2346 EXPECT_EQ(0xBA, frame->entropy_hash); 2117 EXPECT_EQ(0xBA, frame->entropy_hash);
2347 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame->largest_observed); 2118 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame->largest_observed);
2348 ASSERT_EQ(0u, frame->missing_packets.size()); 2119 ASSERT_EQ(0u, frame->missing_packets.size());
2349 2120
2350 // Verify that the packet re-serializes identically. 2121 // Verify that the packet re-serializes identically.
2351 QuicFrames frames; 2122 QuicFrames frames;
2352 frames.push_back(QuicFrame(frame));
2353 scoped_ptr<QuicPacket> data(BuildDataPacket(*visitor_.header_, frames));
2354 ASSERT_TRUE(data != nullptr);
2355
2356 test::CompareCharArraysWithHexError("constructed packet",
2357 data->data(), data->length(),
2358 AsChars(packet), arraysize(packet));
2359 }
2360
2361 TEST_P(QuicFramerTest, AckFrameNoNacks) {
2362 if (version_ <= QUIC_VERSION_22) {
2363 return;
2364 }
2365 unsigned char packet[] = {
2366 // public flags (8 byte connection_id)
2367 0x3C,
2368 // connection_id
2369 0x10, 0x32, 0x54, 0x76,
2370 0x98, 0xBA, 0xDC, 0xFE,
2371 // packet sequence number
2372 0xA8, 0x9A, 0x78, 0x56,
2373 0x34, 0x12,
2374 // private flags (entropy)
2375 0x01,
2376
2377 // frame type (ack frame)
2378 // (no nacks, not truncated, 6 byte largest observed, 1 byte delta)
2379 0x4C,
2380 // entropy hash of all received packets.
2381 0xBA,
2382 // largest observed packet sequence number
2383 0xBF, 0x9A, 0x78, 0x56,
2384 0x34, 0x12,
2385 // Zero delta time.
2386 0x0, 0x0,
2387 // Number of received packets.
2388 0x00,
2389 };
2390
2391 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2392 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2393
2394 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2395 ASSERT_TRUE(visitor_.header_.get());
2396 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2397
2398 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2399 ASSERT_EQ(1u, visitor_.ack_frames_.size());
2400 QuicAckFrame* frame = visitor_.ack_frames_[0];
2401 EXPECT_EQ(0xBA, frame->entropy_hash);
2402 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame->largest_observed);
2403 ASSERT_EQ(0u, frame->missing_packets.size());
2404
2405 // Verify that the packet re-serializes identically.
2406 QuicFrames frames;
2407 frames.push_back(QuicFrame(frame));
2408 scoped_ptr<QuicPacket> data(BuildDataPacket(*visitor_.header_, frames));
2409 ASSERT_TRUE(data != nullptr);
2410
2411 test::CompareCharArraysWithHexError("constructed packet",
2412 data->data(), data->length(),
2413 AsChars(packet), arraysize(packet));
2414 }
2415
2416 TEST_P(QuicFramerTest, AckFrame500Nacksv22) {
2417 if (version_ > QUIC_VERSION_22) {
2418 return;
2419 }
2420 unsigned char packet[] = {
2421 // public flags (8 byte connection_id)
2422 0x3C,
2423 // connection_id
2424 0x10, 0x32, 0x54, 0x76,
2425 0x98, 0xBA, 0xDC, 0xFE,
2426 // packet sequence number
2427 0xA8, 0x9A, 0x78, 0x56,
2428 0x34, 0x12,
2429 // private flags (entropy)
2430 0x01,
2431
2432 // frame type (ack frame)
2433 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
2434 0x6C,
2435 // entropy hash of all received packets.
2436 0xBA,
2437 // largest observed packet sequence number
2438 0xBF, 0x9A, 0x78, 0x56,
2439 0x34, 0x12,
2440 // Zero delta time.
2441 0x0, 0x0,
2442 // num missing packet ranges
2443 0x02,
2444 // missing packet delta
2445 0x01,
2446 // 243 more missing packets in range.
2447 // The ranges are listed in this order so the re-constructed packet matches.
2448 0xF3,
2449 // No gap between ranges
2450 0x00,
2451 // 255 more missing packets in range.
2452 0xFF,
2453 // No revived packets.
2454 0x00,
2455 };
2456
2457 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2458 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2459
2460 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2461 ASSERT_TRUE(visitor_.header_.get());
2462 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2463
2464 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2465 ASSERT_EQ(1u, visitor_.ack_frames_.size());
2466 QuicAckFrame* frame = visitor_.ack_frames_[0];
2467 EXPECT_EQ(0xBA, frame->entropy_hash);
2468 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame->largest_observed);
2469 EXPECT_EQ(0u, frame->revived_packets.size());
2470 ASSERT_EQ(500u, frame->missing_packets.size());
2471 SequenceNumberSet::const_iterator first_missing_iter =
2472 frame->missing_packets.begin();
2473 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE) - 499, *first_missing_iter);
2474 SequenceNumberSet::const_reverse_iterator last_missing_iter =
2475 frame->missing_packets.rbegin();
2476 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *last_missing_iter);
2477
2478 // Verify that the packet re-serializes identically.
2479 QuicFrames frames;
2480 frames.push_back(QuicFrame(frame)); 2123 frames.push_back(QuicFrame(frame));
2481 scoped_ptr<QuicPacket> data(BuildDataPacket(*visitor_.header_, frames)); 2124 scoped_ptr<QuicPacket> data(BuildDataPacket(*visitor_.header_, frames));
2482 ASSERT_TRUE(data != nullptr); 2125 ASSERT_TRUE(data != nullptr);
2483 2126
2484 test::CompareCharArraysWithHexError("constructed packet", 2127 test::CompareCharArraysWithHexError("constructed packet", data->data(),
2485 data->data(), data->length(), 2128 data->length(), AsChars(packet),
2486 AsChars(packet), arraysize(packet)); 2129 arraysize(packet));
2487 } 2130 }
2488 2131
2489 TEST_P(QuicFramerTest, AckFrame500Nacks) { 2132 TEST_P(QuicFramerTest, AckFrame500Nacks) {
2490 if (version_ <= QUIC_VERSION_22) {
2491 return;
2492 }
2493 unsigned char packet[] = { 2133 unsigned char packet[] = {
2494 // public flags (8 byte connection_id) 2134 // public flags (8 byte connection_id)
2495 0x3C, 2135 0x3C,
2496 // connection_id 2136 // connection_id
2497 0x10, 0x32, 0x54, 0x76, 2137 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
2498 0x98, 0xBA, 0xDC, 0xFE, 2138 // packet sequence number
2499 // packet sequence number 2139 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
2500 0xA8, 0x9A, 0x78, 0x56, 2140 // private flags (entropy)
2501 0x34, 0x12, 2141 0x01,
2502 // private flags (entropy)
2503 0x01,
2504 2142
2505 // frame type (ack frame) 2143 // frame type (ack frame)
2506 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) 2144 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
2507 0x6C, 2145 0x6C,
2508 // entropy hash of all received packets. 2146 // entropy hash of all received packets.
2509 0xBA, 2147 0xBA,
2510 // largest observed packet sequence number 2148 // largest observed packet sequence number
2511 0xBF, 0x9A, 0x78, 0x56, 2149 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12,
2512 0x34, 0x12, 2150 // Zero delta time.
2513 // Zero delta time. 2151 0x00, 0x00,
2514 0x0, 0x0, 2152 // No received packets.
2515 // No received packets. 2153 0x00,
2516 0x00, 2154 // num missing packet ranges
2517 // num missing packet ranges 2155 0x02,
2518 0x02, 2156 // missing packet delta
2519 // missing packet delta 2157 0x01,
2520 0x01, 2158 // 243 more missing packets in range.
2521 // 243 more missing packets in range. 2159 // The ranges are listed in this order so the re-constructed packet
2522 // The ranges are listed in this order so the re-constructed packet matches. 2160 // matches.
2523 0xF3, 2161 0xF3,
2524 // No gap between ranges 2162 // No gap between ranges
2525 0x00, 2163 0x00,
2526 // 255 more missing packets in range. 2164 // 255 more missing packets in range.
2527 0xFF, 2165 0xFF,
2528 // No revived packets. 2166 // No revived packets.
2529 0x00, 2167 0x00,
2530 }; 2168 };
2531 2169
2532 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 2170 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2533 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2171 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2534 2172
2535 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2173 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2536 ASSERT_TRUE(visitor_.header_.get()); 2174 ASSERT_TRUE(visitor_.header_.get());
2537 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 2175 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2538 2176
2539 EXPECT_EQ(0u, visitor_.stream_frames_.size()); 2177 EXPECT_EQ(0u, visitor_.stream_frames_.size());
(...skipping 14 matching lines...) Expand all
2554 QuicFrames frames; 2192 QuicFrames frames;
2555 frames.push_back(QuicFrame(frame)); 2193 frames.push_back(QuicFrame(frame));
2556 scoped_ptr<QuicPacket> data(BuildDataPacket(*visitor_.header_, frames)); 2194 scoped_ptr<QuicPacket> data(BuildDataPacket(*visitor_.header_, frames));
2557 ASSERT_TRUE(data != nullptr); 2195 ASSERT_TRUE(data != nullptr);
2558 2196
2559 test::CompareCharArraysWithHexError("constructed packet", 2197 test::CompareCharArraysWithHexError("constructed packet",
2560 data->data(), data->length(), 2198 data->data(), data->length(),
2561 AsChars(packet), arraysize(packet)); 2199 AsChars(packet), arraysize(packet));
2562 } 2200 }
2563 2201
2564 TEST_P(QuicFramerTest, CongestionFeedbackFrameTCP) {
2565 unsigned char packet[] = {
2566 // public flags (8 byte connection_id)
2567 0x3C,
2568 // connection_id
2569 0x10, 0x32, 0x54, 0x76,
2570 0x98, 0xBA, 0xDC, 0xFE,
2571 // packet sequence number
2572 0xBC, 0x9A, 0x78, 0x56,
2573 0x34, 0x12,
2574 // private flags
2575 0x00,
2576
2577 // frame type (congestion feedback frame)
2578 0x20,
2579 // congestion feedback type (tcp)
2580 0x00,
2581 // ack_frame.feedback.tcp.receive_window
2582 0x03, 0x04,
2583 };
2584
2585 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2586 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2587
2588 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2589 ASSERT_TRUE(visitor_.header_.get());
2590 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2591
2592 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2593 ASSERT_EQ(1u, visitor_.congestion_feedback_frames_.size());
2594 const QuicCongestionFeedbackFrame& frame =
2595 *visitor_.congestion_feedback_frames_[0];
2596 ASSERT_EQ(kTCP, frame.type);
2597 EXPECT_EQ(0x4030u, frame.tcp.receive_window);
2598
2599 // Now test framing boundaries.
2600 for (size_t i = kQuicFrameTypeSize; i < 4; ++i) {
2601 string expected_error;
2602 if (i < 2) {
2603 expected_error = "Unable to read congestion feedback type.";
2604 } else if (i < 4) {
2605 expected_error = "Unable to read receive window.";
2606 }
2607 CheckProcessingFails(
2608 packet,
2609 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
2610 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP),
2611 expected_error, QUIC_INVALID_CONGESTION_FEEDBACK_DATA);
2612 }
2613 }
2614
2615 TEST_P(QuicFramerTest, CongestionFeedbackFrameInvalidFeedback) {
2616 unsigned char packet[] = {
2617 // public flags (8 byte connection_id)
2618 0x3C,
2619 // connection_id
2620 0x10, 0x32, 0x54, 0x76,
2621 0x98, 0xBA, 0xDC, 0xFE,
2622 // packet sequence number
2623 0xBC, 0x9A, 0x78, 0x56,
2624 0x34, 0x12,
2625 // private flags
2626 0x00,
2627
2628 // frame type (congestion feedback frame)
2629 0x20,
2630 // congestion feedback type (invalid)
2631 0x03,
2632 };
2633
2634 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2635 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
2636 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2637 EXPECT_EQ(QUIC_INVALID_CONGESTION_FEEDBACK_DATA, framer_.error());
2638 }
2639
2640 TEST_P(QuicFramerTest, StopWaitingFrame) { 2202 TEST_P(QuicFramerTest, StopWaitingFrame) {
2641 unsigned char packet[] = { 2203 unsigned char packet[] = {
2642 // public flags (8 byte connection_id) 2204 // public flags (8 byte connection_id)
2643 0x3C, 2205 0x3C,
2644 // connection_id 2206 // connection_id
2645 0x10, 0x32, 0x54, 0x76, 2207 0x10, 0x32, 0x54, 0x76,
2646 0x98, 0xBA, 0xDC, 0xFE, 2208 0x98, 0xBA, 0xDC, 0xFE,
2647 // packet sequence number 2209 // packet sequence number
2648 0xA8, 0x9A, 0x78, 0x56, 2210 0xA8, 0x9A, 0x78, 0x56,
2649 0x34, 0x12, 2211 0x34, 0x12,
(...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after
3493 3055
3494 QuicStreamFrame stream_frame; 3056 QuicStreamFrame stream_frame;
3495 stream_frame.stream_id = 0x01020304; 3057 stream_frame.stream_id = 0x01020304;
3496 stream_frame.fin = true; 3058 stream_frame.fin = true;
3497 stream_frame.offset = GG_UINT64_C(0xBA98FEDC32107654); 3059 stream_frame.offset = GG_UINT64_C(0xBA98FEDC32107654);
3498 stream_frame.data = MakeIOVector("hello world!"); 3060 stream_frame.data = MakeIOVector("hello world!");
3499 3061
3500 QuicFrames frames; 3062 QuicFrames frames;
3501 frames.push_back(QuicFrame(&stream_frame)); 3063 frames.push_back(QuicFrame(&stream_frame));
3502 unsigned char packet[] = { 3064 unsigned char packet[] = {
3503 // public flags (8 byte connection_id) 3065 // public flags (8 byte connection_id)
3504 0x3C, 3066 0x3C,
3505 // connection_id 3067 // connection_id
3506 0x10, 0x32, 0x54, 0x76, 3068 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
3507 0x98, 0xBA, 0xDC, 0xFE, 3069 // packet sequence number
3508 // packet sequence number 3070 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
3509 0xBC, 0x9A, 0x78, 0x56, 3071 // private flags (entropy, is_in_fec_group)
3510 0x34, 0x12, 3072 0x03,
3511 // private flags (entropy, is_in_fec_group) 3073 // FEC group
3512 0x03, 3074 0x00,
3513 // FEC group 3075 // frame type (stream frame with fin and data length field)
3514 0x00, 3076 0xFF,
3515 // frame type (stream frame with fin and data length field) 3077 // stream id
3516 0xFF, 3078 0x04, 0x03, 0x02, 0x01,
3517 // stream id 3079 // offset
3518 0x04, 0x03, 0x02, 0x01, 3080 0x54, 0x76, 0x10, 0x32, 0xDC, 0xFE, 0x98, 0xBA,
3519 // offset 3081 // data length (since packet is in an FEC group)
3520 0x54, 0x76, 0x10, 0x32, 3082 0x0C, 0x00,
3521 0xDC, 0xFE, 0x98, 0xBA, 3083 // data
3522 // data length (since packet is in an FEC group) 3084 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!',
3523 0x0C, 0x00,
3524 // data
3525 'h', 'e', 'l', 'l',
3526 'o', ' ', 'w', 'o',
3527 'r', 'l', 'd', '!',
3528 }; 3085 };
3529 3086
3530 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 3087 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3531 ASSERT_TRUE(data != nullptr); 3088 ASSERT_TRUE(data != nullptr);
3532 3089
3533 test::CompareCharArraysWithHexError("constructed packet", 3090 test::CompareCharArraysWithHexError("constructed packet",
3534 data->data(), data->length(), 3091 data->data(), data->length(),
3535 AsChars(packet), arraysize(packet)); 3092 AsChars(packet), arraysize(packet));
3536 } 3093 }
3537 3094
(...skipping 10 matching lines...) Expand all
3548 QuicStreamFrame stream_frame; 3105 QuicStreamFrame stream_frame;
3549 stream_frame.stream_id = 0x01020304; 3106 stream_frame.stream_id = 0x01020304;
3550 stream_frame.fin = true; 3107 stream_frame.fin = true;
3551 stream_frame.offset = GG_UINT64_C(0xBA98FEDC32107654); 3108 stream_frame.offset = GG_UINT64_C(0xBA98FEDC32107654);
3552 stream_frame.data = MakeIOVector("hello world!"); 3109 stream_frame.data = MakeIOVector("hello world!");
3553 3110
3554 QuicFrames frames; 3111 QuicFrames frames;
3555 frames.push_back(QuicFrame(&stream_frame)); 3112 frames.push_back(QuicFrame(&stream_frame));
3556 3113
3557 unsigned char packet[] = { 3114 unsigned char packet[] = {
3558 // public flags (version, 8 byte connection_id) 3115 // public flags (version, 8 byte connection_id)
3559 0x3D, 3116 0x3D,
3560 // connection_id 3117 // connection_id
3561 0x10, 0x32, 0x54, 0x76, 3118 0x10,
3562 0x98, 0xBA, 0xDC, 0xFE, 3119 0x32,
3563 // version tag 3120 0x54,
3564 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), 3121 0x76,
3565 // packet sequence number 3122 0x98,
3566 0xBC, 0x9A, 0x78, 0x56, 3123 0xBA,
3567 0x34, 0x12, 3124 0xDC,
3568 // private flags (entropy) 3125 0xFE,
3569 0x01, 3126 // version tag
3127 'Q',
3128 '0',
3129 GetQuicVersionDigitTens(),
3130 GetQuicVersionDigitOnes(),
3131 // packet sequence number
3132 0xBC,
3133 0x9A,
3134 0x78,
3135 0x56,
3136 0x34,
3137 0x12,
3138 // private flags (entropy)
3139 0x01,
3570 3140
3571 // frame type (stream frame with fin and no length) 3141 // frame type (stream frame with fin and no length)
3572 0xDF, 3142 0xDF,
3573 // stream id 3143 // stream id
3574 0x04, 0x03, 0x02, 0x01, 3144 0x04,
3575 // offset 3145 0x03,
3576 0x54, 0x76, 0x10, 0x32, 3146 0x02,
3577 0xDC, 0xFE, 0x98, 0xBA, 3147 0x01,
3578 // data 3148 // offset
3579 'h', 'e', 'l', 'l', 3149 0x54,
3580 'o', ' ', 'w', 'o', 3150 0x76,
3581 'r', 'l', 'd', '!', 3151 0x10,
3152 0x32,
3153 0xDC,
3154 0xFE,
3155 0x98,
3156 0xBA,
3157 // data
3158 'h',
3159 'e',
3160 'l',
3161 'l',
3162 'o',
3163 ' ',
3164 'w',
3165 'o',
3166 'r',
3167 'l',
3168 'd',
3169 '!',
3582 }; 3170 };
3583 3171
3584 QuicFramerPeer::SetIsServer(&framer_, false); 3172 QuicFramerPeer::SetIsServer(&framer_, false);
3585 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 3173 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3586 ASSERT_TRUE(data != nullptr); 3174 ASSERT_TRUE(data != nullptr);
3587 3175
3588 test::CompareCharArraysWithHexError("constructed packet", 3176 test::CompareCharArraysWithHexError("constructed packet",
3589 data->data(), data->length(), 3177 data->data(), data->length(),
3590 AsChars(packet), arraysize(packet)); 3178 AsChars(packet), arraysize(packet));
3591 } 3179 }
3592 3180
3593 TEST_P(QuicFramerTest, BuildVersionNegotiationPacket) { 3181 TEST_P(QuicFramerTest, BuildVersionNegotiationPacket) {
3594 QuicPacketPublicHeader header; 3182 QuicPacketPublicHeader header;
3595 header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); 3183 header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3596 header.reset_flag = false; 3184 header.reset_flag = false;
3597 header.version_flag = true; 3185 header.version_flag = true;
3598 3186
3599 unsigned char packet[] = { 3187 unsigned char packet[] = {
3600 // public flags (version, 8 byte connection_id) 3188 // public flags (version, 8 byte connection_id)
3601 0x0D, 3189 0x0D,
3602 // connection_id 3190 // connection_id
3603 0x10, 0x32, 0x54, 0x76, 3191 0x10,
3604 0x98, 0xBA, 0xDC, 0xFE, 3192 0x32,
3605 // version tag 3193 0x54,
3606 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), 3194 0x76,
3195 0x98,
3196 0xBA,
3197 0xDC,
3198 0xFE,
3199 // version tag
3200 'Q',
3201 '0',
3202 GetQuicVersionDigitTens(),
3203 GetQuicVersionDigitOnes(),
3607 }; 3204 };
3608 3205
3609 QuicVersionVector versions; 3206 QuicVersionVector versions;
3610 versions.push_back(GetParam()); 3207 versions.push_back(GetParam());
3611 scoped_ptr<QuicEncryptedPacket> data( 3208 scoped_ptr<QuicEncryptedPacket> data(
3612 framer_.BuildVersionNegotiationPacket(header, versions)); 3209 framer_.BuildVersionNegotiationPacket(header, versions));
3613 3210
3614 test::CompareCharArraysWithHexError("constructed packet", 3211 test::CompareCharArraysWithHexError("constructed packet", data->data(),
3615 data->data(), data->length(), 3212 data->length(), AsChars(packet),
3616 AsChars(packet), arraysize(packet)); 3213 arraysize(packet));
3617 } 3214 }
3618 3215
3619 TEST_P(QuicFramerTest, BuildAckFramePacketv22) { 3216 TEST_P(QuicFramerTest, BuildAckFramePacket) {
3620 if (version_ > QUIC_VERSION_22) {
3621 return;
3622 }
3623 QuicPacketHeader header; 3217 QuicPacketHeader header;
3624 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); 3218 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3625 header.public_header.reset_flag = false; 3219 header.public_header.reset_flag = false;
3626 header.public_header.version_flag = false;
3627 header.fec_flag = false;
3628 header.entropy_flag = true;
3629 header.packet_sequence_number = GG_UINT64_C(0x770123456789AA8);
3630 header.fec_group = 0;
3631
3632 QuicAckFrame ack_frame;
3633 ack_frame.entropy_hash = 0x43;
3634 ack_frame.largest_observed = GG_UINT64_C(0x770123456789ABF);
3635 ack_frame.delta_time_largest_observed = QuicTime::Delta::Zero();
3636 ack_frame.missing_packets.insert(
3637 GG_UINT64_C(0x770123456789ABE));
3638
3639 QuicFrames frames;
3640 frames.push_back(QuicFrame(&ack_frame));
3641
3642 unsigned char packet[] = {
3643 // public flags (8 byte connection_id)
3644 0x3C,
3645 // connection_id
3646 0x10, 0x32, 0x54, 0x76,
3647 0x98, 0xBA, 0xDC, 0xFE,
3648 // packet sequence number
3649 0xA8, 0x9A, 0x78, 0x56,
3650 0x34, 0x12,
3651 // private flags (entropy)
3652 0x01,
3653
3654 // frame type (ack frame)
3655 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
3656 0x6C,
3657 // entropy hash of all received packets.
3658 0x43,
3659 // largest observed packet sequence number
3660 0xBF, 0x9A, 0x78, 0x56,
3661 0x34, 0x12,
3662 // Zero delta time.
3663 0x0, 0x0,
3664 // num missing packet ranges
3665 0x01,
3666 // missing packet delta
3667 0x01,
3668 // 0 more missing packets in range.
3669 0x00,
3670 // 0 revived packets.
3671 0x00,
3672 };
3673
3674 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3675 ASSERT_TRUE(data != nullptr);
3676
3677 test::CompareCharArraysWithHexError("constructed packet",
3678 data->data(), data->length(),
3679 AsChars(packet), arraysize(packet));
3680 }
3681
3682 TEST_P(QuicFramerTest, BuildAckFramePacket) {
3683 if (version_ <= QUIC_VERSION_22) {
3684 return;
3685 }
3686 QuicPacketHeader header;
3687 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3688 header.public_header.reset_flag = false;
3689 header.public_header.version_flag = false; 3220 header.public_header.version_flag = false;
3690 header.fec_flag = false; 3221 header.fec_flag = false;
3691 header.entropy_flag = true; 3222 header.entropy_flag = true;
3692 header.packet_sequence_number = GG_UINT64_C(0x770123456789AA8); 3223 header.packet_sequence_number = GG_UINT64_C(0x770123456789AA8);
3693 header.fec_group = 0; 3224 header.fec_group = 0;
3694 3225
3695 QuicAckFrame ack_frame; 3226 QuicAckFrame ack_frame;
3696 ack_frame.entropy_hash = 0x43; 3227 ack_frame.entropy_hash = 0x43;
3697 ack_frame.largest_observed = GG_UINT64_C(0x770123456789ABF); 3228 ack_frame.largest_observed = GG_UINT64_C(0x770123456789ABF);
3698 ack_frame.delta_time_largest_observed = QuicTime::Delta::Zero(); 3229 ack_frame.delta_time_largest_observed = QuicTime::Delta::Zero();
3699 ack_frame.missing_packets.insert( 3230 ack_frame.missing_packets.insert(GG_UINT64_C(0x770123456789ABE));
3700 GG_UINT64_C(0x770123456789ABE));
3701 3231
3702 QuicFrames frames; 3232 QuicFrames frames;
3703 frames.push_back(QuicFrame(&ack_frame)); 3233 frames.push_back(QuicFrame(&ack_frame));
3704 3234
3705 unsigned char packet[] = { 3235 unsigned char packet[] = {
3706 // public flags (8 byte connection_id) 3236 // public flags (8 byte connection_id)
3707 0x3C, 3237 0x3C,
3708 // connection_id 3238 // connection_id
3709 0x10, 0x32, 0x54, 0x76, 3239 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
3710 0x98, 0xBA, 0xDC, 0xFE, 3240 // packet sequence number
3711 // packet sequence number 3241 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
3712 0xA8, 0x9A, 0x78, 0x56, 3242 // private flags (entropy)
3713 0x34, 0x12, 3243 0x01,
3714 // private flags (entropy)
3715 0x01,
3716 3244
3717 // frame type (ack frame) 3245 // frame type (ack frame)
3718 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) 3246 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
3719 0x6C, 3247 0x6C,
3720 // entropy hash of all received packets. 3248 // entropy hash of all received packets.
3721 0x43, 3249 0x43,
3722 // largest observed packet sequence number 3250 // largest observed packet sequence number
3723 0xBF, 0x9A, 0x78, 0x56, 3251 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12,
3724 0x34, 0x12, 3252 // Zero delta time.
3725 // Zero delta time. 3253 0x00, 0x00,
3726 0x0, 0x0, 3254 // num received packets.
3727 // num received packets. 3255 0x00,
3728 0x00, 3256 // num missing packet ranges
3729 // num missing packet ranges 3257 0x01,
3730 0x01, 3258 // missing packet delta
3731 // missing packet delta 3259 0x01,
3732 0x01, 3260 // 0 more missing packets in range.
3733 // 0 more missing packets in range. 3261 0x00,
3734 0x00, 3262 // 0 revived packets.
3735 // 0 revived packets. 3263 0x00,
3736 0x00,
3737 }; 3264 };
3738 3265
3739 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 3266 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3740 ASSERT_TRUE(data != nullptr); 3267 ASSERT_TRUE(data != nullptr);
3741 3268
3742 test::CompareCharArraysWithHexError("constructed packet", 3269 test::CompareCharArraysWithHexError("constructed packet",
3743 data->data(), data->length(), 3270 data->data(), data->length(),
3744 AsChars(packet), arraysize(packet)); 3271 AsChars(packet), arraysize(packet));
3745 } 3272 }
3746 3273
3747 // TODO(jri): Add test for tuncated packets in which the original ack frame had 3274 // TODO(jri): Add test for tuncated packets in which the original ack frame had
3748 // revived packets. (In both the large and small packet cases below). 3275 // revived packets. (In both the large and small packet cases below).
3749 3276
3750 TEST_P(QuicFramerTest, BuildTruncatedAckFrameLargePacketv22) { 3277 TEST_P(QuicFramerTest, BuildTruncatedAckFrameLargePacket) {
3751 if (version_ > QUIC_VERSION_22) {
3752 return;
3753 }
3754 QuicPacketHeader header; 3278 QuicPacketHeader header;
3755 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); 3279 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3756 header.public_header.reset_flag = false; 3280 header.public_header.reset_flag = false;
3757 header.public_header.version_flag = false;
3758 header.fec_flag = false;
3759 header.entropy_flag = true;
3760 header.packet_sequence_number = GG_UINT64_C(0x770123456789AA8);
3761 header.fec_group = 0;
3762
3763 QuicAckFrame ack_frame;
3764 // This entropy hash is different from what shows up in the packet below,
3765 // since entropy is recomputed by the framer on ack truncation (by
3766 // TestEntropyCalculator for this test.)
3767 ack_frame.entropy_hash = 0x43;
3768 ack_frame.largest_observed = 2 * 300;
3769 ack_frame.delta_time_largest_observed = QuicTime::Delta::Zero();
3770 for (size_t i = 1; i < 2 * 300; i += 2) {
3771 ack_frame.missing_packets.insert(i);
3772 }
3773
3774 QuicFrames frames;
3775 frames.push_back(QuicFrame(&ack_frame));
3776
3777 unsigned char packet[] = {
3778 // public flags (8 byte connection_id)
3779 0x3C,
3780 // connection_id
3781 0x10, 0x32, 0x54, 0x76,
3782 0x98, 0xBA, 0xDC, 0xFE,
3783 // packet sequence number
3784 0xA8, 0x9A, 0x78, 0x56,
3785 0x34, 0x12,
3786 // private flags (entropy)
3787 0x01,
3788
3789 // frame type (ack frame)
3790 // (has nacks, is truncated, 2 byte largest observed, 1 byte delta)
3791 0x74,
3792 // entropy hash of all received packets, set to 1 by TestEntropyCalculator
3793 // since ack is truncated.
3794 0x01,
3795 // 2-byte largest observed packet sequence number.
3796 // Expected to be 510 (0x1FE), since only 255 nack ranges can fit.
3797 0xFE, 0x01,
3798 // Zero delta time.
3799 0x0, 0x0,
3800 // num missing packet ranges (limited to 255 by size of this field).
3801 0xFF,
3802 // {missing packet delta, further missing packets in range}
3803 // 6 nack ranges x 42 + 3 nack ranges
3804 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3805 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3806 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3807 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3808 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3809 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3810 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3811 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3812 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3813 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3814
3815 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3816 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3817 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3818 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3819 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3820 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3821 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3822 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3823 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3824 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3825
3826 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3827 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3828 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3829 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3830 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3831 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3832 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3833 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3834 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3835 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3836
3837 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3838 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3839 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3840 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3841 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3842 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3843 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3844 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3845 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3846 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3847
3848 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3849 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3850 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3851
3852 // 0 revived packets.
3853 0x00,
3854 };
3855
3856 scoped_ptr<QuicPacket> data(
3857 framer_.BuildDataPacket(header, frames, kMaxPacketSize).packet);
3858 ASSERT_TRUE(data != nullptr);
3859
3860 test::CompareCharArraysWithHexError("constructed packet",
3861 data->data(), data->length(),
3862 AsChars(packet), arraysize(packet));
3863 }
3864
3865 TEST_P(QuicFramerTest, BuildTruncatedAckFrameLargePacket) {
3866 if (version_ <= QUIC_VERSION_22) {
3867 return;
3868 }
3869 QuicPacketHeader header;
3870 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3871 header.public_header.reset_flag = false;
3872 header.public_header.version_flag = false; 3281 header.public_header.version_flag = false;
3873 header.fec_flag = false; 3282 header.fec_flag = false;
3874 header.entropy_flag = true; 3283 header.entropy_flag = true;
3875 header.packet_sequence_number = GG_UINT64_C(0x770123456789AA8); 3284 header.packet_sequence_number = GG_UINT64_C(0x770123456789AA8);
3876 header.fec_group = 0; 3285 header.fec_group = 0;
3877 3286
3878 QuicAckFrame ack_frame; 3287 QuicAckFrame ack_frame;
3879 // This entropy hash is different from what shows up in the packet below, 3288 // This entropy hash is different from what shows up in the packet below,
3880 // since entropy is recomputed by the framer on ack truncation (by 3289 // since entropy is recomputed by the framer on ack truncation (by
3881 // TestEntropyCalculator for this test.) 3290 // TestEntropyCalculator for this test.)
3882 ack_frame.entropy_hash = 0x43; 3291 ack_frame.entropy_hash = 0x43;
3883 ack_frame.largest_observed = 2 * 300; 3292 ack_frame.largest_observed = 2 * 300;
3884 ack_frame.delta_time_largest_observed = QuicTime::Delta::Zero(); 3293 ack_frame.delta_time_largest_observed = QuicTime::Delta::Zero();
3885 for (size_t i = 1; i < 2 * 300; i += 2) { 3294 for (size_t i = 1; i < 2 * 300; i += 2) {
3886 ack_frame.missing_packets.insert(i); 3295 ack_frame.missing_packets.insert(i);
3887 } 3296 }
3888 3297
3889 QuicFrames frames; 3298 QuicFrames frames;
3890 frames.push_back(QuicFrame(&ack_frame)); 3299 frames.push_back(QuicFrame(&ack_frame));
3891 3300
3892 unsigned char packet[] = { 3301 unsigned char packet[] = {
3893 // public flags (8 byte connection_id) 3302 // public flags (8 byte connection_id)
3894 0x3C, 3303 0x3C,
3895 // connection_id 3304 // connection_id
3896 0x10, 0x32, 0x54, 0x76, 3305 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
3897 0x98, 0xBA, 0xDC, 0xFE, 3306 // packet sequence number
3898 // packet sequence number 3307 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
3899 0xA8, 0x9A, 0x78, 0x56, 3308 // private flags (entropy)
3900 0x34, 0x12, 3309 0x01,
3901 // private flags (entropy)
3902 0x01,
3903 3310
3904 // frame type (ack frame) 3311 // frame type (ack frame)
3905 // (has nacks, is truncated, 2 byte largest observed, 1 byte delta) 3312 // (has nacks, is truncated, 2 byte largest observed, 1 byte delta)
3906 0x74, 3313 0x74,
3907 // entropy hash of all received packets, set to 1 by TestEntropyCalculator 3314 // entropy hash of all received packets, set to 1 by TestEntropyCalculator
3908 // since ack is truncated. 3315 // since ack is truncated.
3909 0x01, 3316 0x01,
3910 // 2-byte largest observed packet sequence number. 3317 // 2-byte largest observed packet sequence number.
3911 // Expected to be 510 (0x1FE), since only 255 nack ranges can fit. 3318 // Expected to be 510 (0x1FE), since only 255 nack ranges can fit.
3912 0xFE, 0x01, 3319 0xFE, 0x01,
3913 // Zero delta time. 3320 // Zero delta time.
3914 0x0, 0x0, 3321 0x00, 0x00,
3915 // num missing packet ranges (limited to 255 by size of this field). 3322 // num missing packet ranges (limited to 255 by size of this field).
3916 0xFF, 3323 0xFF,
3917 // {missing packet delta, further missing packets in range} 3324 // {missing packet delta, further missing packets in range}
3918 // 6 nack ranges x 42 + 3 nack ranges 3325 // 6 nack ranges x 42 + 3 nack ranges
3919 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3326 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3920 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3327 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3921 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3328 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3922 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3329 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3923 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3330 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3924 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3331 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3925 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3332 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3926 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3333 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3927 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3334 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3928 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3335 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3929 3336
3930 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3337 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3931 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3338 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3932 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3339 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3933 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3340 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3934 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3341 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3935 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3342 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3936 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3343 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3937 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3344 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3938 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3345 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3939 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3346 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3940 3347
3941 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3348 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3942 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3349 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3943 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3350 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3944 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3351 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3945 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3352 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3946 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3353 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3947 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3354 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3948 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3355 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3949 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3356 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3950 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3357 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3951 3358
3952 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3359 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3953 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3360 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3954 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3361 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3955 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3362 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3956 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3363 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3957 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3364 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3958 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3365 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3959 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3366 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3960 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3367 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3961 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3368 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3962 3369
3963 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3370 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3964 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3371 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3965 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3372 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3966 3373
3967 // 0 revived packets. 3374 // 0 revived packets.
3968 0x00, 3375 0x00,
3969 }; 3376 };
3970 3377
3971 scoped_ptr<QuicPacket> data( 3378 scoped_ptr<QuicPacket> data(
3972 framer_.BuildDataPacket(header, frames, kMaxPacketSize).packet); 3379 framer_.BuildDataPacket(header, frames, kMaxPacketSize).packet);
3973 ASSERT_TRUE(data != nullptr); 3380 ASSERT_TRUE(data != nullptr);
3974 3381
3975 test::CompareCharArraysWithHexError("constructed packet", 3382 test::CompareCharArraysWithHexError("constructed packet",
3976 data->data(), data->length(), 3383 data->data(), data->length(),
3977 AsChars(packet), arraysize(packet)); 3384 AsChars(packet), arraysize(packet));
3978 } 3385 }
3979 3386
3980
3981 TEST_P(QuicFramerTest, BuildTruncatedAckFrameSmallPacketv22) {
3982 if (version_ > QUIC_VERSION_22) {
3983 return;
3984 }
3985 QuicPacketHeader header;
3986 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3987 header.public_header.reset_flag = false;
3988 header.public_header.version_flag = false;
3989 header.fec_flag = false;
3990 header.entropy_flag = true;
3991 header.packet_sequence_number = GG_UINT64_C(0x770123456789AA8);
3992 header.fec_group = 0;
3993
3994 QuicAckFrame ack_frame;
3995 // This entropy hash is different from what shows up in the packet below,
3996 // since entropy is recomputed by the framer on ack truncation (by
3997 // TestEntropyCalculator for this test.)
3998 ack_frame.entropy_hash = 0x43;
3999 ack_frame.largest_observed = 2 * 300;
4000 ack_frame.delta_time_largest_observed = QuicTime::Delta::Zero();
4001 for (size_t i = 1; i < 2 * 300; i += 2) {
4002 ack_frame.missing_packets.insert(i);
4003 }
4004
4005 QuicFrames frames;
4006 frames.push_back(QuicFrame(&ack_frame));
4007
4008 unsigned char packet[] = {
4009 // public flags (8 byte connection_id)
4010 0x3C,
4011 // connection_id
4012 0x10, 0x32, 0x54, 0x76,
4013 0x98, 0xBA, 0xDC, 0xFE,
4014 // packet sequence number
4015 0xA8, 0x9A, 0x78, 0x56,
4016 0x34, 0x12,
4017 // private flags (entropy)
4018 0x01,
4019
4020 // frame type (ack frame)
4021 // (has nacks, is truncated, 2 byte largest observed, 1 byte delta)
4022 0x74,
4023 // entropy hash of all received packets, set to 1 by TestEntropyCalculator
4024 // since ack is truncated.
4025 0x01,
4026 // 2-byte largest observed packet sequence number.
4027 // Expected to be 12 (0x0C), since only 6 nack ranges can fit.
4028 0x0C, 0x00,
4029 // Zero delta time.
4030 0x0, 0x0,
4031 // num missing packet ranges (limited to 6 by packet size of 37).
4032 0x06,
4033 // {missing packet delta, further missing packets in range}
4034 // 6 nack ranges
4035 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
4036 // 0 revived packets.
4037 0x00,
4038 };
4039
4040 scoped_ptr<QuicPacket> data(
4041 framer_.BuildDataPacket(header, frames, 37u).packet);
4042 ASSERT_TRUE(data != nullptr);
4043 // Expect 1 byte unused since at least 2 bytes are needed to fit more nacks.
4044 EXPECT_EQ(36u, data->length());
4045 test::CompareCharArraysWithHexError("constructed packet",
4046 data->data(), data->length(),
4047 AsChars(packet), arraysize(packet));
4048 }
4049
4050 TEST_P(QuicFramerTest, BuildTruncatedAckFrameSmallPacket) { 3387 TEST_P(QuicFramerTest, BuildTruncatedAckFrameSmallPacket) {
4051 if (version_ <= QUIC_VERSION_22) {
4052 return;
4053 }
4054 QuicPacketHeader header; 3388 QuicPacketHeader header;
4055 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); 3389 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
4056 header.public_header.reset_flag = false; 3390 header.public_header.reset_flag = false;
4057 header.public_header.version_flag = false; 3391 header.public_header.version_flag = false;
4058 header.fec_flag = false; 3392 header.fec_flag = false;
4059 header.entropy_flag = true; 3393 header.entropy_flag = true;
4060 header.packet_sequence_number = GG_UINT64_C(0x770123456789AA8); 3394 header.packet_sequence_number = GG_UINT64_C(0x770123456789AA8);
4061 header.fec_group = 0; 3395 header.fec_group = 0;
4062 3396
4063 QuicAckFrame ack_frame; 3397 QuicAckFrame ack_frame;
4064 // This entropy hash is different from what shows up in the packet below, 3398 // This entropy hash is different from what shows up in the packet below,
4065 // since entropy is recomputed by the framer on ack truncation (by 3399 // since entropy is recomputed by the framer on ack truncation (by
4066 // TestEntropyCalculator for this test.) 3400 // TestEntropyCalculator for this test.)
4067 ack_frame.entropy_hash = 0x43; 3401 ack_frame.entropy_hash = 0x43;
4068 ack_frame.largest_observed = 2 * 300; 3402 ack_frame.largest_observed = 2 * 300;
4069 ack_frame.delta_time_largest_observed = QuicTime::Delta::Zero(); 3403 ack_frame.delta_time_largest_observed = QuicTime::Delta::Zero();
4070 for (size_t i = 1; i < 2 * 300; i += 2) { 3404 for (size_t i = 1; i < 2 * 300; i += 2) {
4071 ack_frame.missing_packets.insert(i); 3405 ack_frame.missing_packets.insert(i);
4072 } 3406 }
4073 3407
4074 QuicFrames frames; 3408 QuicFrames frames;
4075 frames.push_back(QuicFrame(&ack_frame)); 3409 frames.push_back(QuicFrame(&ack_frame));
4076 3410
4077 unsigned char packet[] = { 3411 unsigned char packet[] = {
4078 // public flags (8 byte connection_id) 3412 // public flags (8 byte connection_id)
4079 0x3C, 3413 0x3C,
4080 // connection_id 3414 // connection_id
4081 0x10, 0x32, 0x54, 0x76, 3415 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
4082 0x98, 0xBA, 0xDC, 0xFE, 3416 // packet sequence number
4083 // packet sequence number 3417 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
4084 0xA8, 0x9A, 0x78, 0x56, 3418 // private flags (entropy)
4085 0x34, 0x12, 3419 0x01,
4086 // private flags (entropy)
4087 0x01,
4088 3420
4089 // frame type (ack frame) 3421 // frame type (ack frame)
4090 // (has nacks, is truncated, 2 byte largest observed, 1 byte delta) 3422 // (has nacks, is truncated, 2 byte largest observed, 1 byte delta)
4091 0x74, 3423 0x74,
4092 // entropy hash of all received packets, set to 1 by TestEntropyCalculator 3424 // entropy hash of all received packets, set to 1 by TestEntropyCalculator
4093 // since ack is truncated. 3425 // since ack is truncated.
4094 0x01, 3426 0x01,
4095 // 2-byte largest observed packet sequence number. 3427 // 2-byte largest observed packet sequence number.
4096 // Expected to be 12 (0x0C), since only 6 nack ranges can fit. 3428 // Expected to be 12 (0x0C), since only 6 nack ranges can fit.
4097 0x0C, 0x00, 3429 0x0C, 0x00,
4098 // Zero delta time. 3430 // Zero delta time.
4099 0x0, 0x0, 3431 0x00, 0x00,
4100 // num missing packet ranges (limited to 6 by packet size of 37). 3432 // num missing packet ranges (limited to 6 by packet size of 37).
4101 0x06, 3433 0x06,
4102 // {missing packet delta, further missing packets in range} 3434 // {missing packet delta, further missing packets in range}
4103 // 6 nack ranges 3435 // 6 nack ranges
4104 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 3436 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
4105 // 0 revived packets. 3437 // 0 revived packets.
4106 0x00, 3438 0x00,
4107 }; 3439 };
4108 3440
4109 scoped_ptr<QuicPacket> data( 3441 scoped_ptr<QuicPacket> data(
4110 framer_.BuildDataPacket(header, frames, 37u).packet); 3442 framer_.BuildDataPacket(header, frames, 37u).packet);
4111 ASSERT_TRUE(data != nullptr); 3443 ASSERT_TRUE(data != nullptr);
4112 // Expect 1 byte unused since at least 2 bytes are needed to fit more nacks. 3444 // Expect 1 byte unused since at least 2 bytes are needed to fit more nacks.
4113 EXPECT_EQ(36u, data->length()); 3445 EXPECT_EQ(36u, data->length());
4114 test::CompareCharArraysWithHexError("constructed packet", 3446 test::CompareCharArraysWithHexError("constructed packet",
4115 data->data(), data->length(), 3447 data->data(), data->length(),
4116 AsChars(packet), arraysize(packet)); 3448 AsChars(packet), arraysize(packet));
4117 } 3449 }
4118 3450
4119 TEST_P(QuicFramerTest, BuildCongestionFeedbackFramePacketTCP) {
4120 QuicPacketHeader header;
4121 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
4122 header.public_header.reset_flag = false;
4123 header.public_header.version_flag = false;
4124 header.fec_flag = false;
4125 header.entropy_flag = false;
4126 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
4127 header.fec_group = 0;
4128
4129 QuicCongestionFeedbackFrame congestion_feedback_frame;
4130 congestion_feedback_frame.type = kTCP;
4131 congestion_feedback_frame.tcp.receive_window = 0x4030;
4132
4133 QuicFrames frames;
4134 frames.push_back(QuicFrame(&congestion_feedback_frame));
4135
4136 unsigned char packet[] = {
4137 // public flags (8 byte connection_id)
4138 0x3C,
4139 // connection_id
4140 0x10, 0x32, 0x54, 0x76,
4141 0x98, 0xBA, 0xDC, 0xFE,
4142 // packet sequence number
4143 0xBC, 0x9A, 0x78, 0x56,
4144 0x34, 0x12,
4145 // private flags
4146 0x00,
4147
4148 // frame type (congestion feedback frame)
4149 0x20,
4150 // congestion feedback type (TCP)
4151 0x00,
4152 // TCP receive window
4153 0x03, 0x04,
4154 };
4155
4156 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
4157 ASSERT_TRUE(data != nullptr);
4158
4159 test::CompareCharArraysWithHexError("constructed packet",
4160 data->data(), data->length(),
4161 AsChars(packet), arraysize(packet));
4162 }
4163
4164 TEST_P(QuicFramerTest, BuildStopWaitingPacket) { 3451 TEST_P(QuicFramerTest, BuildStopWaitingPacket) {
4165 QuicPacketHeader header; 3452 QuicPacketHeader header;
4166 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); 3453 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
4167 header.public_header.reset_flag = false; 3454 header.public_header.reset_flag = false;
4168 header.public_header.version_flag = false; 3455 header.public_header.version_flag = false;
4169 header.fec_flag = false; 3456 header.fec_flag = false;
4170 header.entropy_flag = true; 3457 header.entropy_flag = true;
4171 header.packet_sequence_number = GG_UINT64_C(0x770123456789AA8); 3458 header.packet_sequence_number = GG_UINT64_C(0x770123456789AA8);
4172 header.fec_group = 0; 3459 header.fec_group = 0;
4173 3460
(...skipping 26 matching lines...) Expand all
4200 }; 3487 };
4201 3488
4202 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames)); 3489 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
4203 ASSERT_TRUE(data != nullptr); 3490 ASSERT_TRUE(data != nullptr);
4204 3491
4205 test::CompareCharArraysWithHexError("constructed packet", 3492 test::CompareCharArraysWithHexError("constructed packet",
4206 data->data(), data->length(), 3493 data->data(), data->length(),
4207 AsChars(packet), arraysize(packet)); 3494 AsChars(packet), arraysize(packet));
4208 } 3495 }
4209 3496
4210 TEST_P(QuicFramerTest, BuildCongestionFeedbackFramePacketInvalidFeedback) {
4211 QuicPacketHeader header;
4212 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
4213 header.public_header.reset_flag = false;
4214 header.public_header.version_flag = false;
4215 header.fec_flag = false;
4216 header.entropy_flag = false;
4217 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
4218 header.fec_group = 0;
4219
4220 QuicCongestionFeedbackFrame congestion_feedback_frame;
4221 congestion_feedback_frame.type =
4222 static_cast<CongestionFeedbackType>(kTCP + 1);
4223
4224 QuicFrames frames;
4225 frames.push_back(QuicFrame(&congestion_feedback_frame));
4226
4227 scoped_ptr<QuicPacket> data;
4228 EXPECT_DFATAL(
4229 data.reset(BuildDataPacket(header, frames)),
4230 "AppendCongestionFeedbackFrame failed");
4231 ASSERT_TRUE(data == nullptr);
4232 }
4233
4234 TEST_P(QuicFramerTest, BuildRstFramePacketQuic) { 3497 TEST_P(QuicFramerTest, BuildRstFramePacketQuic) {
4235 QuicPacketHeader header; 3498 QuicPacketHeader header;
4236 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); 3499 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
4237 header.public_header.reset_flag = false; 3500 header.public_header.reset_flag = false;
4238 header.public_header.version_flag = false; 3501 header.public_header.version_flag = false;
4239 header.fec_flag = false; 3502 header.fec_flag = false;
4240 header.entropy_flag = false; 3503 header.entropy_flag = false;
4241 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); 3504 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
4242 header.fec_group = 0; 3505 header.fec_group = 0;
4243 3506
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
4761 EXPECT_EQ(510u, processed_ack_frame.largest_observed); 4024 EXPECT_EQ(510u, processed_ack_frame.largest_observed);
4762 ASSERT_EQ(255u, processed_ack_frame.missing_packets.size()); 4025 ASSERT_EQ(255u, processed_ack_frame.missing_packets.size());
4763 SequenceNumberSet::const_iterator missing_iter = 4026 SequenceNumberSet::const_iterator missing_iter =
4764 processed_ack_frame.missing_packets.begin(); 4027 processed_ack_frame.missing_packets.begin();
4765 EXPECT_EQ(1u, *missing_iter); 4028 EXPECT_EQ(1u, *missing_iter);
4766 SequenceNumberSet::const_reverse_iterator last_missing_iter = 4029 SequenceNumberSet::const_reverse_iterator last_missing_iter =
4767 processed_ack_frame.missing_packets.rbegin(); 4030 processed_ack_frame.missing_packets.rbegin();
4768 EXPECT_EQ(509u, *last_missing_iter); 4031 EXPECT_EQ(509u, *last_missing_iter);
4769 } 4032 }
4770 4033
4771 TEST_P(QuicFramerTest, AckTruncationSmallPacketv22) { 4034 TEST_P(QuicFramerTest, AckTruncationSmallPacket) {
4772 if (version_ > QUIC_VERSION_22) {
4773 return;
4774 }
4775 QuicPacketHeader header; 4035 QuicPacketHeader header;
4776 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); 4036 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
4777 header.public_header.reset_flag = false; 4037 header.public_header.reset_flag = false;
4778 header.public_header.version_flag = false;
4779 header.fec_flag = false;
4780 header.entropy_flag = false;
4781 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
4782 header.fec_group = 0;
4783
4784 // Create a packet with just the ack.
4785 QuicAckFrame ack_frame = MakeAckFrameWithNackRanges(300, 0u);
4786 QuicFrame frame;
4787 frame.type = ACK_FRAME;
4788 frame.ack_frame = &ack_frame;
4789 QuicFrames frames;
4790 frames.push_back(frame);
4791
4792 // Build an ack packet with truncation due to limit in number of nack ranges.
4793 scoped_ptr<QuicPacket> raw_ack_packet(
4794 framer_.BuildDataPacket(header, frames, 500).packet);
4795 ASSERT_TRUE(raw_ack_packet != nullptr);
4796 scoped_ptr<QuicEncryptedPacket> ack_packet(
4797 framer_.EncryptPacket(ENCRYPTION_NONE, header.packet_sequence_number,
4798 *raw_ack_packet));
4799 // Now make sure we can turn our ack packet back into an ack frame.
4800 ASSERT_TRUE(framer_.ProcessPacket(*ack_packet));
4801 ASSERT_EQ(1u, visitor_.ack_frames_.size());
4802 QuicAckFrame& processed_ack_frame = *visitor_.ack_frames_[0];
4803 EXPECT_TRUE(processed_ack_frame.is_truncated);
4804 EXPECT_EQ(476u, processed_ack_frame.largest_observed);
4805 ASSERT_EQ(238u, processed_ack_frame.missing_packets.size());
4806 SequenceNumberSet::const_iterator missing_iter =
4807 processed_ack_frame.missing_packets.begin();
4808 EXPECT_EQ(1u, *missing_iter);
4809 SequenceNumberSet::const_reverse_iterator last_missing_iter =
4810 processed_ack_frame.missing_packets.rbegin();
4811 EXPECT_EQ(475u, *last_missing_iter);
4812 }
4813
4814
4815 TEST_P(QuicFramerTest, AckTruncationSmallPacket) {
4816 if (version_ <= QUIC_VERSION_22) {
4817 return;
4818 }
4819 QuicPacketHeader header;
4820 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
4821 header.public_header.reset_flag = false;
4822 header.public_header.version_flag = false; 4038 header.public_header.version_flag = false;
4823 header.fec_flag = false; 4039 header.fec_flag = false;
4824 header.entropy_flag = false; 4040 header.entropy_flag = false;
4825 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); 4041 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
4826 header.fec_group = 0; 4042 header.fec_group = 0;
4827 4043
4828 // Create a packet with just the ack. 4044 // Create a packet with just the ack.
4829 QuicAckFrame ack_frame = MakeAckFrameWithNackRanges(300, 0u); 4045 QuicAckFrame ack_frame = MakeAckFrameWithNackRanges(300, 0u);
4830 QuicFrame frame; 4046 QuicFrame frame;
4831 frame.type = ACK_FRAME; 4047 frame.type = ACK_FRAME;
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
5029 EXPECT_CALL(visitor, OnPacketComplete()); 4245 EXPECT_CALL(visitor, OnPacketComplete());
5030 EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)).WillOnce(Return(true)); 4246 EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)).WillOnce(Return(true));
5031 4247
5032 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 4248 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
5033 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 4249 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
5034 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 4250 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
5035 } 4251 }
5036 4252
5037 } // namespace test 4253 } // namespace test
5038 } // namespace net 4254 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_framer.cc ('k') | net/quic/quic_headers_stream.h » ('j') | shell/BUILD.gn » ('J')

Powered by Google App Engine
This is Rietveld 408576698