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
3 // found in the LICENSE file.
5 #include "net/quic/quic_framer.h"
12 #include "base/containers/hash_tables.h"
13 #include "base/logging.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/port.h"
16 #include "base/stl_util.h"
17 #include "net/quic/crypto/quic_decrypter.h"
18 #include "net/quic/crypto/quic_encrypter.h"
19 #include "net/quic/quic_protocol.h"
20 #include "net/quic/quic_utils.h"
21 #include "net/quic/test_tools/quic_framer_peer.h"
22 #include "net/quic/test_tools/quic_test_utils.h"
23 #include "net/test/gtest_util.h"
26 using base::StringPiece
;
29 using std::numeric_limits
;
33 using testing::Return
;
39 const QuicPacketSequenceNumber kEpoch
= GG_UINT64_C(1) << 48;
40 const QuicPacketSequenceNumber kMask
= kEpoch
- 1;
42 // Index into the connection_id offset in the header.
43 const size_t kConnectionIdOffset
= kPublicFlagsSize
;
44 // Index into the version string in the header. (if present).
45 const size_t kVersionOffset
= kConnectionIdOffset
+ PACKET_8BYTE_CONNECTION_ID
;
47 // Size in bytes of the stream frame fields for an arbitrary StreamID and
48 // offset and the last frame in a packet.
49 size_t GetMinStreamFrameSize(QuicVersion version
) {
50 return kQuicFrameTypeSize
+ kQuicMaxStreamIdSize
+ kQuicMaxStreamOffsetSize
;
53 // Index into the sequence number offset in the header.
54 size_t GetSequenceNumberOffset(QuicConnectionIdLength connection_id_length
,
55 bool include_version
) {
56 return kConnectionIdOffset
+ connection_id_length
+
57 (include_version
? kQuicVersionSize
: 0);
60 size_t GetSequenceNumberOffset(bool include_version
) {
61 return GetSequenceNumberOffset(PACKET_8BYTE_CONNECTION_ID
, include_version
);
64 // Index into the private flags offset in the data packet header.
65 size_t GetPrivateFlagsOffset(QuicConnectionIdLength connection_id_length
,
66 bool include_version
) {
67 return GetSequenceNumberOffset(connection_id_length
, include_version
) +
68 PACKET_6BYTE_SEQUENCE_NUMBER
;
71 size_t GetPrivateFlagsOffset(bool include_version
) {
72 return GetPrivateFlagsOffset(PACKET_8BYTE_CONNECTION_ID
, include_version
);
75 size_t GetPrivateFlagsOffset(bool include_version
,
76 QuicSequenceNumberLength sequence_number_length
) {
77 return GetSequenceNumberOffset(PACKET_8BYTE_CONNECTION_ID
, include_version
) +
78 sequence_number_length
;
81 // Index into the fec group offset in the header.
82 size_t GetFecGroupOffset(QuicConnectionIdLength connection_id_length
,
83 bool include_version
) {
84 return GetPrivateFlagsOffset(connection_id_length
, include_version
) +
88 size_t GetFecGroupOffset(bool include_version
) {
89 return GetPrivateFlagsOffset(PACKET_8BYTE_CONNECTION_ID
, include_version
) +
93 size_t GetFecGroupOffset(bool include_version
,
94 QuicSequenceNumberLength sequence_number_length
) {
95 return GetPrivateFlagsOffset(include_version
, sequence_number_length
) +
99 // Index into the message tag of the public reset packet.
100 // Public resets always have full connection_ids.
101 const size_t kPublicResetPacketMessageTagOffset
=
102 kConnectionIdOffset
+ PACKET_8BYTE_CONNECTION_ID
;
104 class TestEncrypter
: public QuicEncrypter
{
106 virtual ~TestEncrypter() {}
107 virtual bool SetKey(StringPiece key
) OVERRIDE
{
110 virtual bool SetNoncePrefix(StringPiece nonce_prefix
) OVERRIDE
{
113 virtual bool Encrypt(StringPiece nonce
,
114 StringPiece associated_data
,
115 StringPiece plaintext
,
116 unsigned char* output
) OVERRIDE
{
117 CHECK(false) << "Not implemented";
120 virtual QuicData
* EncryptPacket(QuicPacketSequenceNumber sequence_number
,
121 StringPiece associated_data
,
122 StringPiece plaintext
) OVERRIDE
{
123 sequence_number_
= sequence_number
;
124 associated_data_
= associated_data
.as_string();
125 plaintext_
= plaintext
.as_string();
126 return new QuicData(plaintext
.data(), plaintext
.length());
128 virtual size_t GetKeySize() const OVERRIDE
{
131 virtual size_t GetNoncePrefixSize() const OVERRIDE
{
134 virtual size_t GetMaxPlaintextSize(size_t ciphertext_size
) const OVERRIDE
{
135 return ciphertext_size
;
137 virtual size_t GetCiphertextSize(size_t plaintext_size
) const OVERRIDE
{
138 return plaintext_size
;
140 virtual StringPiece
GetKey() const OVERRIDE
{
141 return StringPiece();
143 virtual StringPiece
GetNoncePrefix() const OVERRIDE
{
144 return StringPiece();
146 QuicPacketSequenceNumber sequence_number_
;
147 string associated_data_
;
151 class TestDecrypter
: public QuicDecrypter
{
153 virtual ~TestDecrypter() {}
154 virtual bool SetKey(StringPiece key
) OVERRIDE
{
157 virtual bool SetNoncePrefix(StringPiece nonce_prefix
) OVERRIDE
{
160 virtual bool Decrypt(StringPiece nonce
,
161 StringPiece associated_data
,
162 StringPiece ciphertext
,
163 unsigned char* output
,
164 size_t* output_length
) OVERRIDE
{
165 CHECK(false) << "Not implemented";
168 virtual QuicData
* DecryptPacket(QuicPacketSequenceNumber sequence_number
,
169 StringPiece associated_data
,
170 StringPiece ciphertext
) OVERRIDE
{
171 sequence_number_
= sequence_number
;
172 associated_data_
= associated_data
.as_string();
173 ciphertext_
= ciphertext
.as_string();
174 return new QuicData(ciphertext
.data(), ciphertext
.length());
176 virtual StringPiece
GetKey() const OVERRIDE
{
177 return StringPiece();
179 virtual StringPiece
GetNoncePrefix() const OVERRIDE
{
180 return StringPiece();
182 QuicPacketSequenceNumber sequence_number_
;
183 string associated_data_
;
187 class TestQuicVisitor
: public ::net::QuicFramerVisitorInterface
{
191 version_mismatch_(0),
195 complete_packets_(0),
197 accept_packet_(true),
198 accept_public_header_(true) {
201 virtual ~TestQuicVisitor() {
202 STLDeleteElements(&stream_frames_
);
203 STLDeleteElements(&ack_frames_
);
204 STLDeleteElements(&congestion_feedback_frames_
);
205 STLDeleteElements(&stop_waiting_frames_
);
206 STLDeleteElements(&ping_frames_
);
207 STLDeleteElements(&fec_data_
);
210 virtual void OnError(QuicFramer
* f
) OVERRIDE
{
211 DVLOG(1) << "QuicFramer Error: " << QuicUtils::ErrorToString(f
->error())
212 << " (" << f
->error() << ")";
216 virtual void OnPacket() OVERRIDE
{}
218 virtual void OnPublicResetPacket(
219 const QuicPublicResetPacket
& packet
) OVERRIDE
{
220 public_reset_packet_
.reset(new QuicPublicResetPacket(packet
));
223 virtual void OnVersionNegotiationPacket(
224 const QuicVersionNegotiationPacket
& packet
) OVERRIDE
{
225 version_negotiation_packet_
.reset(new QuicVersionNegotiationPacket(packet
));
228 virtual void OnRevivedPacket() OVERRIDE
{
232 virtual bool OnProtocolVersionMismatch(QuicVersion version
) OVERRIDE
{
233 DVLOG(1) << "QuicFramer Version Mismatch, version: " << version
;
238 virtual bool OnUnauthenticatedPublicHeader(
239 const QuicPacketPublicHeader
& header
) OVERRIDE
{
240 public_header_
.reset(new QuicPacketPublicHeader(header
));
241 return accept_public_header_
;
244 virtual bool OnUnauthenticatedHeader(
245 const QuicPacketHeader
& header
) OVERRIDE
{
249 virtual void OnDecryptedPacket(EncryptionLevel level
) OVERRIDE
{}
251 virtual bool OnPacketHeader(const QuicPacketHeader
& header
) OVERRIDE
{
253 header_
.reset(new QuicPacketHeader(header
));
254 return accept_packet_
;
257 virtual bool OnStreamFrame(const QuicStreamFrame
& frame
) OVERRIDE
{
259 stream_frames_
.push_back(new QuicStreamFrame(frame
));
263 virtual void OnFecProtectedPayload(StringPiece payload
) OVERRIDE
{
264 fec_protected_payload_
= payload
.as_string();
267 virtual bool OnAckFrame(const QuicAckFrame
& frame
) OVERRIDE
{
269 ack_frames_
.push_back(new QuicAckFrame(frame
));
273 virtual bool OnCongestionFeedbackFrame(
274 const QuicCongestionFeedbackFrame
& frame
) OVERRIDE
{
276 congestion_feedback_frames_
.push_back(
277 new QuicCongestionFeedbackFrame(frame
));
281 virtual bool OnStopWaitingFrame(const QuicStopWaitingFrame
& frame
) OVERRIDE
{
283 stop_waiting_frames_
.push_back(new QuicStopWaitingFrame(frame
));
287 virtual bool OnPingFrame(const QuicPingFrame
& frame
) OVERRIDE
{
289 ping_frames_
.push_back(new QuicPingFrame(frame
));
293 virtual void OnFecData(const QuicFecData
& fec
) OVERRIDE
{
295 fec_data_
.push_back(new QuicFecData(fec
));
298 virtual void OnPacketComplete() OVERRIDE
{
302 virtual bool OnRstStreamFrame(const QuicRstStreamFrame
& frame
) OVERRIDE
{
303 rst_stream_frame_
= frame
;
307 virtual bool OnConnectionCloseFrame(
308 const QuicConnectionCloseFrame
& frame
) OVERRIDE
{
309 connection_close_frame_
= frame
;
313 virtual bool OnGoAwayFrame(const QuicGoAwayFrame
& frame
) OVERRIDE
{
314 goaway_frame_
= frame
;
318 virtual bool OnWindowUpdateFrame(const QuicWindowUpdateFrame
& frame
)
320 window_update_frame_
= frame
;
324 virtual bool OnBlockedFrame(const QuicBlockedFrame
& frame
) OVERRIDE
{
325 blocked_frame_
= frame
;
329 // Counters from the visitor_ callbacks.
331 int version_mismatch_
;
335 int complete_packets_
;
336 int revived_packets_
;
338 bool accept_public_header_
;
340 scoped_ptr
<QuicPacketHeader
> header_
;
341 scoped_ptr
<QuicPacketPublicHeader
> public_header_
;
342 scoped_ptr
<QuicPublicResetPacket
> public_reset_packet_
;
343 scoped_ptr
<QuicVersionNegotiationPacket
> version_negotiation_packet_
;
344 vector
<QuicStreamFrame
*> stream_frames_
;
345 vector
<QuicAckFrame
*> ack_frames_
;
346 vector
<QuicCongestionFeedbackFrame
*> congestion_feedback_frames_
;
347 vector
<QuicStopWaitingFrame
*> stop_waiting_frames_
;
348 vector
<QuicPingFrame
*> ping_frames_
;
349 vector
<QuicFecData
*> fec_data_
;
350 string fec_protected_payload_
;
351 QuicRstStreamFrame rst_stream_frame_
;
352 QuicConnectionCloseFrame connection_close_frame_
;
353 QuicGoAwayFrame goaway_frame_
;
354 QuicWindowUpdateFrame window_update_frame_
;
355 QuicBlockedFrame blocked_frame_
;
358 class QuicFramerTest
: public ::testing::TestWithParam
<QuicVersion
> {
361 : encrypter_(new test::TestEncrypter()),
362 decrypter_(new test::TestDecrypter()),
363 start_(QuicTime::Zero().Add(QuicTime::Delta::FromMicroseconds(0x10))),
364 framer_(QuicSupportedVersions(), start_
, true) {
365 version_
= GetParam();
366 framer_
.set_version(version_
);
367 framer_
.SetDecrypter(decrypter_
, ENCRYPTION_NONE
);
368 framer_
.SetEncrypter(ENCRYPTION_NONE
, encrypter_
);
369 framer_
.set_visitor(&visitor_
);
370 framer_
.set_received_entropy_calculator(&entropy_calculator_
);
373 // Helper function to get unsigned char representation of digit in the
374 // units place of the current QUIC version number.
375 unsigned char GetQuicVersionDigitOnes() {
376 return static_cast<unsigned char> ('0' + version_
%10);
379 // Helper function to get unsigned char representation of digit in the
380 // tens place of the current QUIC version number.
381 unsigned char GetQuicVersionDigitTens() {
382 return static_cast<unsigned char> ('0' + (version_
/10)%10);
385 bool CheckEncryption(QuicPacketSequenceNumber sequence_number
,
386 QuicPacket
* packet
) {
387 if (sequence_number
!= encrypter_
->sequence_number_
) {
388 LOG(ERROR
) << "Encrypted incorrect packet sequence number. expected "
389 << sequence_number
<< " actual: "
390 << encrypter_
->sequence_number_
;
393 if (packet
->AssociatedData() != encrypter_
->associated_data_
) {
394 LOG(ERROR
) << "Encrypted incorrect associated data. expected "
395 << packet
->AssociatedData() << " actual: "
396 << encrypter_
->associated_data_
;
399 if (packet
->Plaintext() != encrypter_
->plaintext_
) {
400 LOG(ERROR
) << "Encrypted incorrect plaintext data. expected "
401 << packet
->Plaintext() << " actual: "
402 << encrypter_
->plaintext_
;
408 bool CheckDecryption(const QuicEncryptedPacket
& encrypted
,
409 bool includes_version
) {
410 if (visitor_
.header_
->packet_sequence_number
!=
411 decrypter_
->sequence_number_
) {
412 LOG(ERROR
) << "Decrypted incorrect packet sequence number. expected "
413 << visitor_
.header_
->packet_sequence_number
<< " actual: "
414 << decrypter_
->sequence_number_
;
417 if (QuicFramer::GetAssociatedDataFromEncryptedPacket(
418 encrypted
, PACKET_8BYTE_CONNECTION_ID
,
419 includes_version
, PACKET_6BYTE_SEQUENCE_NUMBER
) !=
420 decrypter_
->associated_data_
) {
421 LOG(ERROR
) << "Decrypted incorrect associated data. expected "
422 << QuicFramer::GetAssociatedDataFromEncryptedPacket(
423 encrypted
, PACKET_8BYTE_CONNECTION_ID
,
424 includes_version
, PACKET_6BYTE_SEQUENCE_NUMBER
)
425 << " actual: " << decrypter_
->associated_data_
;
428 StringPiece
ciphertext(encrypted
.AsStringPiece().substr(
429 GetStartOfEncryptedData(PACKET_8BYTE_CONNECTION_ID
, includes_version
,
430 PACKET_6BYTE_SEQUENCE_NUMBER
)));
431 if (ciphertext
!= decrypter_
->ciphertext_
) {
432 LOG(ERROR
) << "Decrypted incorrect ciphertext data. expected "
433 << ciphertext
<< " actual: "
434 << decrypter_
->ciphertext_
;
440 char* AsChars(unsigned char* data
) {
441 return reinterpret_cast<char*>(data
);
444 void CheckProcessingFails(unsigned char* packet
,
446 string expected_error
,
447 QuicErrorCode error_code
) {
448 QuicEncryptedPacket
encrypted(AsChars(packet
), len
, false);
449 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
)) << "len: " << len
;
450 EXPECT_EQ(expected_error
, framer_
.detailed_error()) << "len: " << len
;
451 EXPECT_EQ(error_code
, framer_
.error()) << "len: " << len
;
454 // Checks if the supplied string matches data in the supplied StreamFrame.
455 void CheckStreamFrameData(string str
, QuicStreamFrame
* frame
) {
456 scoped_ptr
<string
> frame_data(frame
->GetDataAsString());
457 EXPECT_EQ(str
, *frame_data
);
460 void CheckStreamFrameBoundaries(unsigned char* packet
,
461 size_t stream_id_size
,
462 bool include_version
) {
463 // Now test framing boundaries
464 for (size_t i
= kQuicFrameTypeSize
;
465 i
< GetMinStreamFrameSize(framer_
.version()); ++i
) {
466 string expected_error
;
467 if (i
< kQuicFrameTypeSize
+ stream_id_size
) {
468 expected_error
= "Unable to read stream_id.";
469 } else if (i
< kQuicFrameTypeSize
+ stream_id_size
+
470 kQuicMaxStreamOffsetSize
) {
471 expected_error
= "Unable to read offset.";
473 expected_error
= "Unable to read frame data.";
475 CheckProcessingFails(
477 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, include_version
,
478 PACKET_6BYTE_SEQUENCE_NUMBER
,
480 expected_error
, QUIC_INVALID_STREAM_DATA
);
484 void CheckCalculatePacketSequenceNumber(
485 QuicPacketSequenceNumber expected_sequence_number
,
486 QuicPacketSequenceNumber last_sequence_number
) {
487 QuicPacketSequenceNumber wire_sequence_number
=
488 expected_sequence_number
& kMask
;
489 QuicFramerPeer::SetLastSequenceNumber(&framer_
, last_sequence_number
);
490 EXPECT_EQ(expected_sequence_number
,
491 QuicFramerPeer::CalculatePacketSequenceNumberFromWire(
492 &framer_
, PACKET_6BYTE_SEQUENCE_NUMBER
, wire_sequence_number
))
493 << "last_sequence_number: " << last_sequence_number
494 << " wire_sequence_number: " << wire_sequence_number
;
497 QuicPacket
* BuildDataPacket(const QuicPacketHeader
& header
,
498 const QuicFrames
& frames
) {
499 return BuildUnsizedDataPacket(&framer_
, header
, frames
).packet
;
502 test::TestEncrypter
* encrypter_
;
503 test::TestDecrypter
* decrypter_
;
504 QuicVersion version_
;
507 test::TestQuicVisitor visitor_
;
508 test::TestEntropyCalculator entropy_calculator_
;
511 // Run all framer tests with all supported versions of QUIC.
512 INSTANTIATE_TEST_CASE_P(QuicFramerTests
,
514 ::testing::ValuesIn(kSupportedQuicVersions
));
516 TEST_P(QuicFramerTest
, CalculatePacketSequenceNumberFromWireNearEpochStart
) {
517 // A few quick manual sanity checks
518 CheckCalculatePacketSequenceNumber(GG_UINT64_C(1), GG_UINT64_C(0));
519 CheckCalculatePacketSequenceNumber(kEpoch
+ 1, kMask
);
520 CheckCalculatePacketSequenceNumber(kEpoch
, kMask
);
522 // Cases where the last number was close to the start of the range
523 for (uint64 last
= 0; last
< 10; last
++) {
524 // Small numbers should not wrap (even if they're out of order).
525 for (uint64 j
= 0; j
< 10; j
++) {
526 CheckCalculatePacketSequenceNumber(j
, last
);
529 // Large numbers should not wrap either (because we're near 0 already).
530 for (uint64 j
= 0; j
< 10; j
++) {
531 CheckCalculatePacketSequenceNumber(kEpoch
- 1 - j
, last
);
536 TEST_P(QuicFramerTest
, CalculatePacketSequenceNumberFromWireNearEpochEnd
) {
537 // Cases where the last number was close to the end of the range
538 for (uint64 i
= 0; i
< 10; i
++) {
539 QuicPacketSequenceNumber last
= kEpoch
- i
;
541 // Small numbers should wrap.
542 for (uint64 j
= 0; j
< 10; j
++) {
543 CheckCalculatePacketSequenceNumber(kEpoch
+ j
, last
);
546 // Large numbers should not (even if they're out of order).
547 for (uint64 j
= 0; j
< 10; j
++) {
548 CheckCalculatePacketSequenceNumber(kEpoch
- 1 - j
, last
);
553 // Next check where we're in a non-zero epoch to verify we handle
554 // reverse wrapping, too.
555 TEST_P(QuicFramerTest
, CalculatePacketSequenceNumberFromWireNearPrevEpoch
) {
556 const uint64 prev_epoch
= 1 * kEpoch
;
557 const uint64 cur_epoch
= 2 * kEpoch
;
558 // Cases where the last number was close to the start of the range
559 for (uint64 i
= 0; i
< 10; i
++) {
560 uint64 last
= cur_epoch
+ i
;
561 // Small number should not wrap (even if they're out of order).
562 for (uint64 j
= 0; j
< 10; j
++) {
563 CheckCalculatePacketSequenceNumber(cur_epoch
+ j
, last
);
566 // But large numbers should reverse wrap.
567 for (uint64 j
= 0; j
< 10; j
++) {
568 uint64 num
= kEpoch
- 1 - j
;
569 CheckCalculatePacketSequenceNumber(prev_epoch
+ num
, last
);
574 TEST_P(QuicFramerTest
, CalculatePacketSequenceNumberFromWireNearNextEpoch
) {
575 const uint64 cur_epoch
= 2 * kEpoch
;
576 const uint64 next_epoch
= 3 * kEpoch
;
577 // Cases where the last number was close to the end of the range
578 for (uint64 i
= 0; i
< 10; i
++) {
579 QuicPacketSequenceNumber last
= next_epoch
- 1 - i
;
581 // Small numbers should wrap.
582 for (uint64 j
= 0; j
< 10; j
++) {
583 CheckCalculatePacketSequenceNumber(next_epoch
+ j
, last
);
586 // but large numbers should not (even if they're out of order).
587 for (uint64 j
= 0; j
< 10; j
++) {
588 uint64 num
= kEpoch
- 1 - j
;
589 CheckCalculatePacketSequenceNumber(cur_epoch
+ num
, last
);
594 TEST_P(QuicFramerTest
, CalculatePacketSequenceNumberFromWireNearNextMax
) {
595 const uint64 max_number
= numeric_limits
<uint64
>::max();
596 const uint64 max_epoch
= max_number
& ~kMask
;
598 // Cases where the last number was close to the end of the range
599 for (uint64 i
= 0; i
< 10; i
++) {
600 // Subtract 1, because the expected next sequence number is 1 more than the
601 // last sequence number.
602 QuicPacketSequenceNumber last
= max_number
- i
- 1;
604 // Small numbers should not wrap, because they have nowhere to go.
605 for (uint64 j
= 0; j
< 10; j
++) {
606 CheckCalculatePacketSequenceNumber(max_epoch
+ j
, last
);
609 // Large numbers should not wrap either.
610 for (uint64 j
= 0; j
< 10; j
++) {
611 uint64 num
= kEpoch
- 1 - j
;
612 CheckCalculatePacketSequenceNumber(max_epoch
+ num
, last
);
617 TEST_P(QuicFramerTest
, EmptyPacket
) {
618 char packet
[] = { 0x00 };
619 QuicEncryptedPacket
encrypted(packet
, 0, false);
620 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
621 EXPECT_EQ(QUIC_INVALID_PACKET_HEADER
, framer_
.error());
624 TEST_P(QuicFramerTest
, LargePacket
) {
625 unsigned char packet
[kMaxPacketSize
+ 1] = {
626 // public flags (8 byte connection_id)
629 0x10, 0x32, 0x54, 0x76,
630 0x98, 0xBA, 0xDC, 0xFE,
631 // packet sequence number
632 0xBC, 0x9A, 0x78, 0x56,
638 memset(packet
+ GetPacketHeaderSize(
639 PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
640 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
), 0,
641 kMaxPacketSize
- GetPacketHeaderSize(
642 PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
643 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
) + 1);
645 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
646 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
648 ASSERT_TRUE(visitor_
.header_
.get());
649 // Make sure we've parsed the packet header, so we can send an error.
650 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
651 visitor_
.header_
->public_header
.connection_id
);
652 // Make sure the correct error is propagated.
653 EXPECT_EQ(QUIC_PACKET_TOO_LARGE
, framer_
.error());
656 TEST_P(QuicFramerTest
, PacketHeader
) {
657 unsigned char packet
[] = {
658 // public flags (8 byte connection_id)
661 0x10, 0x32, 0x54, 0x76,
662 0x98, 0xBA, 0xDC, 0xFE,
663 // packet sequence number
664 0xBC, 0x9A, 0x78, 0x56,
670 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
671 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
672 EXPECT_EQ(QUIC_MISSING_PAYLOAD
, framer_
.error());
673 ASSERT_TRUE(visitor_
.header_
.get());
674 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
675 visitor_
.header_
->public_header
.connection_id
);
676 EXPECT_FALSE(visitor_
.header_
->public_header
.reset_flag
);
677 EXPECT_FALSE(visitor_
.header_
->public_header
.version_flag
);
678 EXPECT_FALSE(visitor_
.header_
->fec_flag
);
679 EXPECT_FALSE(visitor_
.header_
->entropy_flag
);
680 EXPECT_EQ(0, visitor_
.header_
->entropy_hash
);
681 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
682 visitor_
.header_
->packet_sequence_number
);
683 EXPECT_EQ(NOT_IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
684 EXPECT_EQ(0x00u
, visitor_
.header_
->fec_group
);
686 // Now test framing boundaries
688 i
< GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
689 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
691 string expected_error
;
692 if (i
< kConnectionIdOffset
) {
693 expected_error
= "Unable to read public flags.";
694 } else if (i
< GetSequenceNumberOffset(!kIncludeVersion
)) {
695 expected_error
= "Unable to read ConnectionId.";
696 } else if (i
< GetPrivateFlagsOffset(!kIncludeVersion
)) {
697 expected_error
= "Unable to read sequence number.";
698 } else if (i
< GetFecGroupOffset(!kIncludeVersion
)) {
699 expected_error
= "Unable to read private flags.";
701 expected_error
= "Unable to read first fec protected packet offset.";
703 CheckProcessingFails(packet
, i
, expected_error
, QUIC_INVALID_PACKET_HEADER
);
707 TEST_P(QuicFramerTest
, PacketHeaderWith4ByteConnectionId
) {
708 QuicFramerPeer::SetLastSerializedConnectionId(
709 &framer_
, GG_UINT64_C(0xFEDCBA9876543210));
711 unsigned char packet
[] = {
712 // public flags (4 byte connection_id)
715 0x10, 0x32, 0x54, 0x76,
716 // packet sequence number
717 0xBC, 0x9A, 0x78, 0x56,
723 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
724 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
725 EXPECT_EQ(QUIC_MISSING_PAYLOAD
, framer_
.error());
726 ASSERT_TRUE(visitor_
.header_
.get());
727 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
728 visitor_
.header_
->public_header
.connection_id
);
729 EXPECT_FALSE(visitor_
.header_
->public_header
.reset_flag
);
730 EXPECT_FALSE(visitor_
.header_
->public_header
.version_flag
);
731 EXPECT_FALSE(visitor_
.header_
->fec_flag
);
732 EXPECT_FALSE(visitor_
.header_
->entropy_flag
);
733 EXPECT_EQ(0, visitor_
.header_
->entropy_hash
);
734 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
735 visitor_
.header_
->packet_sequence_number
);
736 EXPECT_EQ(NOT_IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
737 EXPECT_EQ(0x00u
, visitor_
.header_
->fec_group
);
739 // Now test framing boundaries
741 i
< GetPacketHeaderSize(PACKET_4BYTE_CONNECTION_ID
, !kIncludeVersion
,
742 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
744 string expected_error
;
745 if (i
< kConnectionIdOffset
) {
746 expected_error
= "Unable to read public flags.";
747 } else if (i
< GetSequenceNumberOffset(PACKET_4BYTE_CONNECTION_ID
,
749 expected_error
= "Unable to read ConnectionId.";
750 } else if (i
< GetPrivateFlagsOffset(PACKET_4BYTE_CONNECTION_ID
,
752 expected_error
= "Unable to read sequence number.";
753 } else if (i
< GetFecGroupOffset(PACKET_4BYTE_CONNECTION_ID
,
755 expected_error
= "Unable to read private flags.";
757 expected_error
= "Unable to read first fec protected packet offset.";
759 CheckProcessingFails(packet
, i
, expected_error
, QUIC_INVALID_PACKET_HEADER
);
763 TEST_P(QuicFramerTest
, PacketHeader1ByteConnectionId
) {
764 QuicFramerPeer::SetLastSerializedConnectionId(
765 &framer_
, GG_UINT64_C(0xFEDCBA9876543210));
767 unsigned char packet
[] = {
768 // public flags (1 byte connection_id)
772 // packet sequence number
773 0xBC, 0x9A, 0x78, 0x56,
779 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
780 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
781 EXPECT_EQ(QUIC_MISSING_PAYLOAD
, framer_
.error());
782 ASSERT_TRUE(visitor_
.header_
.get());
783 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
784 visitor_
.header_
->public_header
.connection_id
);
785 EXPECT_FALSE(visitor_
.header_
->public_header
.reset_flag
);
786 EXPECT_FALSE(visitor_
.header_
->public_header
.version_flag
);
787 EXPECT_FALSE(visitor_
.header_
->fec_flag
);
788 EXPECT_FALSE(visitor_
.header_
->entropy_flag
);
789 EXPECT_EQ(0, visitor_
.header_
->entropy_hash
);
790 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
791 visitor_
.header_
->packet_sequence_number
);
792 EXPECT_EQ(NOT_IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
793 EXPECT_EQ(0x00u
, visitor_
.header_
->fec_group
);
795 // Now test framing boundaries
797 i
< GetPacketHeaderSize(PACKET_1BYTE_CONNECTION_ID
, !kIncludeVersion
,
798 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
800 string expected_error
;
801 if (i
< kConnectionIdOffset
) {
802 expected_error
= "Unable to read public flags.";
803 } else if (i
< GetSequenceNumberOffset(PACKET_1BYTE_CONNECTION_ID
,
805 expected_error
= "Unable to read ConnectionId.";
806 } else if (i
< GetPrivateFlagsOffset(PACKET_1BYTE_CONNECTION_ID
,
808 expected_error
= "Unable to read sequence number.";
809 } else if (i
< GetFecGroupOffset(PACKET_1BYTE_CONNECTION_ID
,
811 expected_error
= "Unable to read private flags.";
813 expected_error
= "Unable to read first fec protected packet offset.";
815 CheckProcessingFails(packet
, i
, expected_error
, QUIC_INVALID_PACKET_HEADER
);
819 TEST_P(QuicFramerTest
, PacketHeaderWith0ByteConnectionId
) {
820 QuicFramerPeer::SetLastSerializedConnectionId(
821 &framer_
, GG_UINT64_C(0xFEDCBA9876543210));
823 unsigned char packet
[] = {
824 // public flags (0 byte connection_id)
827 // packet sequence number
828 0xBC, 0x9A, 0x78, 0x56,
834 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
835 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
836 EXPECT_EQ(QUIC_MISSING_PAYLOAD
, framer_
.error());
837 ASSERT_TRUE(visitor_
.header_
.get());
838 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
839 visitor_
.header_
->public_header
.connection_id
);
840 EXPECT_FALSE(visitor_
.header_
->public_header
.reset_flag
);
841 EXPECT_FALSE(visitor_
.header_
->public_header
.version_flag
);
842 EXPECT_FALSE(visitor_
.header_
->fec_flag
);
843 EXPECT_FALSE(visitor_
.header_
->entropy_flag
);
844 EXPECT_EQ(0, visitor_
.header_
->entropy_hash
);
845 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
846 visitor_
.header_
->packet_sequence_number
);
847 EXPECT_EQ(NOT_IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
848 EXPECT_EQ(0x00u
, visitor_
.header_
->fec_group
);
850 // Now test framing boundaries
852 i
< GetPacketHeaderSize(PACKET_0BYTE_CONNECTION_ID
, !kIncludeVersion
,
853 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
855 string expected_error
;
856 if (i
< kConnectionIdOffset
) {
857 expected_error
= "Unable to read public flags.";
858 } else if (i
< GetSequenceNumberOffset(PACKET_0BYTE_CONNECTION_ID
,
860 expected_error
= "Unable to read ConnectionId.";
861 } else if (i
< GetPrivateFlagsOffset(PACKET_0BYTE_CONNECTION_ID
,
863 expected_error
= "Unable to read sequence number.";
864 } else if (i
< GetFecGroupOffset(PACKET_0BYTE_CONNECTION_ID
,
866 expected_error
= "Unable to read private flags.";
868 expected_error
= "Unable to read first fec protected packet offset.";
870 CheckProcessingFails(packet
, i
, expected_error
, QUIC_INVALID_PACKET_HEADER
);
874 TEST_P(QuicFramerTest
, PacketHeaderWithVersionFlag
) {
875 unsigned char packet
[] = {
876 // public flags (version)
879 0x10, 0x32, 0x54, 0x76,
880 0x98, 0xBA, 0xDC, 0xFE,
882 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
883 // packet sequence number
884 0xBC, 0x9A, 0x78, 0x56,
890 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
891 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
892 EXPECT_EQ(QUIC_MISSING_PAYLOAD
, framer_
.error());
893 ASSERT_TRUE(visitor_
.header_
.get());
894 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
895 visitor_
.header_
->public_header
.connection_id
);
896 EXPECT_FALSE(visitor_
.header_
->public_header
.reset_flag
);
897 EXPECT_TRUE(visitor_
.header_
->public_header
.version_flag
);
898 EXPECT_EQ(GetParam(), visitor_
.header_
->public_header
.versions
[0]);
899 EXPECT_FALSE(visitor_
.header_
->fec_flag
);
900 EXPECT_FALSE(visitor_
.header_
->entropy_flag
);
901 EXPECT_EQ(0, visitor_
.header_
->entropy_hash
);
902 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
903 visitor_
.header_
->packet_sequence_number
);
904 EXPECT_EQ(NOT_IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
905 EXPECT_EQ(0x00u
, visitor_
.header_
->fec_group
);
907 // Now test framing boundaries
909 i
< GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, kIncludeVersion
,
910 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
912 string expected_error
;
913 if (i
< kConnectionIdOffset
) {
914 expected_error
= "Unable to read public flags.";
915 } else if (i
< kVersionOffset
) {
916 expected_error
= "Unable to read ConnectionId.";
917 } else if (i
< GetSequenceNumberOffset(kIncludeVersion
)) {
918 expected_error
= "Unable to read protocol version.";
919 } else if (i
< GetPrivateFlagsOffset(kIncludeVersion
)) {
920 expected_error
= "Unable to read sequence number.";
921 } else if (i
< GetFecGroupOffset(kIncludeVersion
)) {
922 expected_error
= "Unable to read private flags.";
924 expected_error
= "Unable to read first fec protected packet offset.";
926 CheckProcessingFails(packet
, i
, expected_error
, QUIC_INVALID_PACKET_HEADER
);
930 TEST_P(QuicFramerTest
, PacketHeaderWith4ByteSequenceNumber
) {
931 QuicFramerPeer::SetLastSequenceNumber(&framer_
,
932 GG_UINT64_C(0x123456789ABA));
934 unsigned char packet
[] = {
935 // public flags (8 byte connection_id and 4 byte sequence number)
938 0x10, 0x32, 0x54, 0x76,
939 0x98, 0xBA, 0xDC, 0xFE,
940 // packet sequence number
941 0xBC, 0x9A, 0x78, 0x56,
946 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
947 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
948 EXPECT_EQ(QUIC_MISSING_PAYLOAD
, framer_
.error());
949 ASSERT_TRUE(visitor_
.header_
.get());
950 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
951 visitor_
.header_
->public_header
.connection_id
);
952 EXPECT_FALSE(visitor_
.header_
->public_header
.reset_flag
);
953 EXPECT_FALSE(visitor_
.header_
->public_header
.version_flag
);
954 EXPECT_FALSE(visitor_
.header_
->fec_flag
);
955 EXPECT_FALSE(visitor_
.header_
->entropy_flag
);
956 EXPECT_EQ(0, visitor_
.header_
->entropy_hash
);
957 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
958 visitor_
.header_
->packet_sequence_number
);
959 EXPECT_EQ(NOT_IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
960 EXPECT_EQ(0x00u
, visitor_
.header_
->fec_group
);
962 // Now test framing boundaries
964 i
< GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
965 PACKET_4BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
967 string expected_error
;
968 if (i
< kConnectionIdOffset
) {
969 expected_error
= "Unable to read public flags.";
970 } else if (i
< GetSequenceNumberOffset(!kIncludeVersion
)) {
971 expected_error
= "Unable to read ConnectionId.";
972 } else if (i
< GetPrivateFlagsOffset(!kIncludeVersion
,
973 PACKET_4BYTE_SEQUENCE_NUMBER
)) {
974 expected_error
= "Unable to read sequence number.";
975 } else if (i
< GetFecGroupOffset(!kIncludeVersion
,
976 PACKET_4BYTE_SEQUENCE_NUMBER
)) {
977 expected_error
= "Unable to read private flags.";
979 expected_error
= "Unable to read first fec protected packet offset.";
981 CheckProcessingFails(packet
, i
, expected_error
, QUIC_INVALID_PACKET_HEADER
);
985 TEST_P(QuicFramerTest
, PacketHeaderWith2ByteSequenceNumber
) {
986 QuicFramerPeer::SetLastSequenceNumber(&framer_
,
987 GG_UINT64_C(0x123456789ABA));
989 unsigned char packet
[] = {
990 // public flags (8 byte connection_id and 2 byte sequence number)
993 0x10, 0x32, 0x54, 0x76,
994 0x98, 0xBA, 0xDC, 0xFE,
995 // packet sequence number
1001 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1002 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
1003 EXPECT_EQ(QUIC_MISSING_PAYLOAD
, framer_
.error());
1004 ASSERT_TRUE(visitor_
.header_
.get());
1005 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
1006 visitor_
.header_
->public_header
.connection_id
);
1007 EXPECT_FALSE(visitor_
.header_
->public_header
.reset_flag
);
1008 EXPECT_FALSE(visitor_
.header_
->public_header
.version_flag
);
1009 EXPECT_FALSE(visitor_
.header_
->fec_flag
);
1010 EXPECT_FALSE(visitor_
.header_
->entropy_flag
);
1011 EXPECT_EQ(0, visitor_
.header_
->entropy_hash
);
1012 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
1013 visitor_
.header_
->packet_sequence_number
);
1014 EXPECT_EQ(NOT_IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
1015 EXPECT_EQ(0x00u
, visitor_
.header_
->fec_group
);
1017 // Now test framing boundaries
1019 i
< GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
1020 PACKET_2BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
1022 string expected_error
;
1023 if (i
< kConnectionIdOffset
) {
1024 expected_error
= "Unable to read public flags.";
1025 } else if (i
< GetSequenceNumberOffset(!kIncludeVersion
)) {
1026 expected_error
= "Unable to read ConnectionId.";
1027 } else if (i
< GetPrivateFlagsOffset(!kIncludeVersion
,
1028 PACKET_2BYTE_SEQUENCE_NUMBER
)) {
1029 expected_error
= "Unable to read sequence number.";
1030 } else if (i
< GetFecGroupOffset(!kIncludeVersion
,
1031 PACKET_2BYTE_SEQUENCE_NUMBER
)) {
1032 expected_error
= "Unable to read private flags.";
1034 expected_error
= "Unable to read first fec protected packet offset.";
1036 CheckProcessingFails(packet
, i
, expected_error
, QUIC_INVALID_PACKET_HEADER
);
1040 TEST_P(QuicFramerTest
, PacketHeaderWith1ByteSequenceNumber
) {
1041 QuicFramerPeer::SetLastSequenceNumber(&framer_
,
1042 GG_UINT64_C(0x123456789ABA));
1044 unsigned char packet
[] = {
1045 // public flags (8 byte connection_id and 1 byte sequence number)
1048 0x10, 0x32, 0x54, 0x76,
1049 0x98, 0xBA, 0xDC, 0xFE,
1050 // packet sequence number
1056 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1057 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
1058 EXPECT_EQ(QUIC_MISSING_PAYLOAD
, framer_
.error());
1059 ASSERT_TRUE(visitor_
.header_
.get());
1060 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
1061 visitor_
.header_
->public_header
.connection_id
);
1062 EXPECT_FALSE(visitor_
.header_
->public_header
.reset_flag
);
1063 EXPECT_FALSE(visitor_
.header_
->public_header
.version_flag
);
1064 EXPECT_FALSE(visitor_
.header_
->fec_flag
);
1065 EXPECT_FALSE(visitor_
.header_
->entropy_flag
);
1066 EXPECT_EQ(0, visitor_
.header_
->entropy_hash
);
1067 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
1068 visitor_
.header_
->packet_sequence_number
);
1069 EXPECT_EQ(NOT_IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
1070 EXPECT_EQ(0x00u
, visitor_
.header_
->fec_group
);
1072 // Now test framing boundaries
1074 i
< GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
1075 PACKET_1BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
1077 string expected_error
;
1078 if (i
< kConnectionIdOffset
) {
1079 expected_error
= "Unable to read public flags.";
1080 } else if (i
< GetSequenceNumberOffset(!kIncludeVersion
)) {
1081 expected_error
= "Unable to read ConnectionId.";
1082 } else if (i
< GetPrivateFlagsOffset(!kIncludeVersion
,
1083 PACKET_1BYTE_SEQUENCE_NUMBER
)) {
1084 expected_error
= "Unable to read sequence number.";
1085 } else if (i
< GetFecGroupOffset(!kIncludeVersion
,
1086 PACKET_1BYTE_SEQUENCE_NUMBER
)) {
1087 expected_error
= "Unable to read private flags.";
1089 expected_error
= "Unable to read first fec protected packet offset.";
1091 CheckProcessingFails(packet
, i
, expected_error
, QUIC_INVALID_PACKET_HEADER
);
1095 TEST_P(QuicFramerTest
, InvalidPublicFlag
) {
1096 unsigned char packet
[] = {
1097 // public flags: all flags set but the public reset flag and version flag.
1100 0x10, 0x32, 0x54, 0x76,
1101 0x98, 0xBA, 0xDC, 0xFE,
1102 // packet sequence number
1103 0xBC, 0x9A, 0x78, 0x56,
1108 // frame type (padding)
1110 0x00, 0x00, 0x00, 0x00
1112 CheckProcessingFails(packet
,
1114 "Illegal public flags value.",
1115 QUIC_INVALID_PACKET_HEADER
);
1117 // Now turn off validation.
1118 framer_
.set_validate_flags(false);
1119 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1120 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1123 TEST_P(QuicFramerTest
, InvalidPublicFlagWithMatchingVersions
) {
1124 unsigned char packet
[] = {
1125 // public flags (8 byte connection_id and version flag and an unknown flag)
1128 0x10, 0x32, 0x54, 0x76,
1129 0x98, 0xBA, 0xDC, 0xFE,
1131 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
1132 // packet sequence number
1133 0xBC, 0x9A, 0x78, 0x56,
1138 // frame type (padding)
1140 0x00, 0x00, 0x00, 0x00
1142 CheckProcessingFails(packet
,
1144 "Illegal public flags value.",
1145 QUIC_INVALID_PACKET_HEADER
);
1148 TEST_P(QuicFramerTest
, LargePublicFlagWithMismatchedVersions
) {
1149 unsigned char packet
[] = {
1150 // public flags (8 byte connection_id, version flag and an unknown flag)
1153 0x10, 0x32, 0x54, 0x76,
1154 0x98, 0xBA, 0xDC, 0xFE,
1157 // packet sequence number
1158 0xBC, 0x9A, 0x78, 0x56,
1163 // frame type (padding frame)
1165 0x00, 0x00, 0x00, 0x00
1167 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1168 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1169 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1170 ASSERT_TRUE(visitor_
.header_
.get());
1171 EXPECT_EQ(0, visitor_
.frame_count_
);
1172 EXPECT_EQ(1, visitor_
.version_mismatch_
);
1175 TEST_P(QuicFramerTest
, InvalidPrivateFlag
) {
1176 unsigned char packet
[] = {
1177 // public flags (8 byte connection_id)
1180 0x10, 0x32, 0x54, 0x76,
1181 0x98, 0xBA, 0xDC, 0xFE,
1182 // packet sequence number
1183 0xBC, 0x9A, 0x78, 0x56,
1188 // frame type (padding)
1190 0x00, 0x00, 0x00, 0x00
1192 CheckProcessingFails(packet
,
1194 "Illegal private flags value.",
1195 QUIC_INVALID_PACKET_HEADER
);
1198 TEST_P(QuicFramerTest
, InvalidFECGroupOffset
) {
1199 unsigned char packet
[] = {
1200 // public flags (8 byte connection_id)
1203 0x10, 0x32, 0x54, 0x76,
1204 0x98, 0xBA, 0xDC, 0xFE,
1205 // packet sequence number
1206 0x01, 0x00, 0x00, 0x00,
1208 // private flags (fec group)
1210 // first fec protected packet offset
1213 CheckProcessingFails(packet
,
1215 "First fec protected packet offset must be less "
1216 "than the sequence number.",
1217 QUIC_INVALID_PACKET_HEADER
);
1220 TEST_P(QuicFramerTest
, PaddingFrame
) {
1221 unsigned char packet
[] = {
1222 // public flags (8 byte connection_id)
1225 0x10, 0x32, 0x54, 0x76,
1226 0x98, 0xBA, 0xDC, 0xFE,
1227 // packet sequence number
1228 0xBC, 0x9A, 0x78, 0x56,
1233 // frame type (padding frame)
1235 // Ignored data (which in this case is a stream frame)
1236 // frame type (stream frame with fin)
1239 0x04, 0x03, 0x02, 0x01,
1241 0x54, 0x76, 0x10, 0x32,
1242 0xDC, 0xFE, 0x98, 0xBA,
1251 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1252 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1253 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1254 ASSERT_TRUE(visitor_
.header_
.get());
1255 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1257 ASSERT_EQ(0u, visitor_
.stream_frames_
.size());
1258 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
1259 // A packet with no frames is not acceptable.
1260 CheckProcessingFails(
1262 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
1263 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
1264 "Packet has no frames.", QUIC_MISSING_PAYLOAD
);
1267 TEST_P(QuicFramerTest
, StreamFrame
) {
1268 unsigned char packet
[] = {
1269 // public flags (8 byte connection_id)
1272 0x10, 0x32, 0x54, 0x76,
1273 0x98, 0xBA, 0xDC, 0xFE,
1274 // packet sequence number
1275 0xBC, 0x9A, 0x78, 0x56,
1280 // frame type (stream frame with fin)
1283 0x04, 0x03, 0x02, 0x01,
1285 0x54, 0x76, 0x10, 0x32,
1286 0xDC, 0xFE, 0x98, 0xBA,
1295 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1296 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1298 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1299 ASSERT_TRUE(visitor_
.header_
.get());
1300 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1302 ASSERT_EQ(1u, visitor_
.stream_frames_
.size());
1303 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
1304 EXPECT_EQ(static_cast<uint64
>(0x01020304),
1305 visitor_
.stream_frames_
[0]->stream_id
);
1306 EXPECT_TRUE(visitor_
.stream_frames_
[0]->fin
);
1307 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1308 visitor_
.stream_frames_
[0]->offset
);
1309 CheckStreamFrameData("hello world!", visitor_
.stream_frames_
[0]);
1311 // Now test framing boundaries
1312 CheckStreamFrameBoundaries(packet
, kQuicMaxStreamIdSize
, !kIncludeVersion
);
1315 TEST_P(QuicFramerTest
, StreamFrame3ByteStreamId
) {
1316 unsigned char packet
[] = {
1317 // public flags (8 byte connection_id)
1320 0x10, 0x32, 0x54, 0x76,
1321 0x98, 0xBA, 0xDC, 0xFE,
1322 // packet sequence number
1323 0xBC, 0x9A, 0x78, 0x56,
1328 // frame type (stream frame with fin)
1333 0x54, 0x76, 0x10, 0x32,
1334 0xDC, 0xFE, 0x98, 0xBA,
1343 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1344 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1346 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1347 ASSERT_TRUE(visitor_
.header_
.get());
1348 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1350 ASSERT_EQ(1u, visitor_
.stream_frames_
.size());
1351 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
1352 EXPECT_EQ(GG_UINT64_C(0x00020304),
1353 visitor_
.stream_frames_
[0]->stream_id
);
1354 EXPECT_TRUE(visitor_
.stream_frames_
[0]->fin
);
1355 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1356 visitor_
.stream_frames_
[0]->offset
);
1357 CheckStreamFrameData("hello world!", visitor_
.stream_frames_
[0]);
1359 // Now test framing boundaries
1360 const size_t stream_id_size
= 3;
1361 CheckStreamFrameBoundaries(packet
, stream_id_size
, !kIncludeVersion
);
1364 TEST_P(QuicFramerTest
, StreamFrame2ByteStreamId
) {
1365 unsigned char packet
[] = {
1366 // public flags (8 byte connection_id)
1369 0x10, 0x32, 0x54, 0x76,
1370 0x98, 0xBA, 0xDC, 0xFE,
1371 // packet sequence number
1372 0xBC, 0x9A, 0x78, 0x56,
1377 // frame type (stream frame with fin)
1382 0x54, 0x76, 0x10, 0x32,
1383 0xDC, 0xFE, 0x98, 0xBA,
1392 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1393 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1395 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1396 ASSERT_TRUE(visitor_
.header_
.get());
1397 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1399 ASSERT_EQ(1u, visitor_
.stream_frames_
.size());
1400 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
1401 EXPECT_EQ(static_cast<uint64
>(0x00000304),
1402 visitor_
.stream_frames_
[0]->stream_id
);
1403 EXPECT_TRUE(visitor_
.stream_frames_
[0]->fin
);
1404 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1405 visitor_
.stream_frames_
[0]->offset
);
1406 CheckStreamFrameData("hello world!", visitor_
.stream_frames_
[0]);
1408 // Now test framing boundaries
1409 const size_t stream_id_size
= 2;
1410 CheckStreamFrameBoundaries(packet
, stream_id_size
, !kIncludeVersion
);
1413 TEST_P(QuicFramerTest
, StreamFrame1ByteStreamId
) {
1414 unsigned char packet
[] = {
1415 // public flags (8 byte connection_id)
1418 0x10, 0x32, 0x54, 0x76,
1419 0x98, 0xBA, 0xDC, 0xFE,
1420 // packet sequence number
1421 0xBC, 0x9A, 0x78, 0x56,
1426 // frame type (stream frame with fin)
1431 0x54, 0x76, 0x10, 0x32,
1432 0xDC, 0xFE, 0x98, 0xBA,
1441 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1442 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1444 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1445 ASSERT_TRUE(visitor_
.header_
.get());
1446 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1448 ASSERT_EQ(1u, visitor_
.stream_frames_
.size());
1449 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
1450 EXPECT_EQ(static_cast<uint64
>(0x00000004),
1451 visitor_
.stream_frames_
[0]->stream_id
);
1452 EXPECT_TRUE(visitor_
.stream_frames_
[0]->fin
);
1453 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1454 visitor_
.stream_frames_
[0]->offset
);
1455 CheckStreamFrameData("hello world!", visitor_
.stream_frames_
[0]);
1457 // Now test framing boundaries
1458 const size_t stream_id_size
= 1;
1459 CheckStreamFrameBoundaries(packet
, stream_id_size
, !kIncludeVersion
);
1462 TEST_P(QuicFramerTest
, StreamFrameWithVersion
) {
1463 unsigned char packet
[] = {
1464 // public flags (version, 8 byte connection_id)
1467 0x10, 0x32, 0x54, 0x76,
1468 0x98, 0xBA, 0xDC, 0xFE,
1470 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
1471 // packet sequence number
1472 0xBC, 0x9A, 0x78, 0x56,
1477 // frame type (stream frame with fin)
1480 0x04, 0x03, 0x02, 0x01,
1482 0x54, 0x76, 0x10, 0x32,
1483 0xDC, 0xFE, 0x98, 0xBA,
1492 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1493 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1495 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1496 ASSERT_TRUE(visitor_
.header_
.get());
1497 EXPECT_TRUE(visitor_
.header_
->public_header
.version_flag
);
1498 EXPECT_EQ(GetParam(), visitor_
.header_
->public_header
.versions
[0]);
1499 EXPECT_TRUE(CheckDecryption(encrypted
, kIncludeVersion
));
1501 ASSERT_EQ(1u, visitor_
.stream_frames_
.size());
1502 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
1503 EXPECT_EQ(static_cast<uint64
>(0x01020304),
1504 visitor_
.stream_frames_
[0]->stream_id
);
1505 EXPECT_TRUE(visitor_
.stream_frames_
[0]->fin
);
1506 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1507 visitor_
.stream_frames_
[0]->offset
);
1508 CheckStreamFrameData("hello world!", visitor_
.stream_frames_
[0]);
1510 // Now test framing boundaries
1511 CheckStreamFrameBoundaries(packet
, kQuicMaxStreamIdSize
, kIncludeVersion
);
1514 TEST_P(QuicFramerTest
, RejectPacket
) {
1515 visitor_
.accept_packet_
= false;
1517 unsigned char packet
[] = {
1518 // public flags (8 byte connection_id)
1521 0x10, 0x32, 0x54, 0x76,
1522 0x98, 0xBA, 0xDC, 0xFE,
1523 // packet sequence number
1524 0xBC, 0x9A, 0x78, 0x56,
1529 // frame type (stream frame with fin)
1532 0x04, 0x03, 0x02, 0x01,
1534 0x54, 0x76, 0x10, 0x32,
1535 0xDC, 0xFE, 0x98, 0xBA,
1544 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1545 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1547 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1548 ASSERT_TRUE(visitor_
.header_
.get());
1549 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1551 ASSERT_EQ(0u, visitor_
.stream_frames_
.size());
1552 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
1555 TEST_P(QuicFramerTest
, RejectPublicHeader
) {
1556 visitor_
.accept_public_header_
= false;
1558 unsigned char packet
[] = {
1559 // public flags (8 byte connection_id)
1562 0x10, 0x32, 0x54, 0x76,
1563 0x98, 0xBA, 0xDC, 0xFE,
1566 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1567 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1569 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1570 ASSERT_TRUE(visitor_
.public_header_
.get());
1571 ASSERT_FALSE(visitor_
.header_
.get());
1574 TEST_P(QuicFramerTest
, RevivedStreamFrame
) {
1575 unsigned char payload
[] = {
1576 // frame type (stream frame with fin)
1579 0x04, 0x03, 0x02, 0x01,
1581 0x54, 0x76, 0x10, 0x32,
1582 0xDC, 0xFE, 0x98, 0xBA,
1591 QuicPacketHeader header
;
1592 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
1593 header
.public_header
.reset_flag
= false;
1594 header
.public_header
.version_flag
= false;
1595 header
.fec_flag
= true;
1596 header
.entropy_flag
= true;
1597 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
1598 header
.fec_group
= 0;
1600 // Do not encrypt the payload because the revived payload is post-encryption.
1601 EXPECT_TRUE(framer_
.ProcessRevivedPacket(&header
,
1602 StringPiece(AsChars(payload
),
1603 arraysize(payload
))));
1605 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1606 ASSERT_EQ(1, visitor_
.revived_packets_
);
1607 ASSERT_TRUE(visitor_
.header_
.get());
1608 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
1609 visitor_
.header_
->public_header
.connection_id
);
1610 EXPECT_FALSE(visitor_
.header_
->public_header
.reset_flag
);
1611 EXPECT_FALSE(visitor_
.header_
->public_header
.version_flag
);
1612 EXPECT_TRUE(visitor_
.header_
->fec_flag
);
1613 EXPECT_TRUE(visitor_
.header_
->entropy_flag
);
1614 EXPECT_EQ(1 << (header
.packet_sequence_number
% 8),
1615 visitor_
.header_
->entropy_hash
);
1616 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
1617 visitor_
.header_
->packet_sequence_number
);
1618 EXPECT_EQ(NOT_IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
1619 EXPECT_EQ(0x00u
, visitor_
.header_
->fec_group
);
1621 ASSERT_EQ(1u, visitor_
.stream_frames_
.size());
1622 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
1623 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_
.stream_frames_
[0]->stream_id
);
1624 EXPECT_TRUE(visitor_
.stream_frames_
[0]->fin
);
1625 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1626 visitor_
.stream_frames_
[0]->offset
);
1627 CheckStreamFrameData("hello world!", visitor_
.stream_frames_
[0]);
1630 TEST_P(QuicFramerTest
, StreamFrameInFecGroup
) {
1631 unsigned char packet
[] = {
1632 // public flags (8 byte connection_id)
1635 0x10, 0x32, 0x54, 0x76,
1636 0x98, 0xBA, 0xDC, 0xFE,
1637 // packet sequence number
1638 0xBC, 0x9A, 0x78, 0x56,
1640 // private flags (fec group)
1642 // first fec protected packet offset
1645 // frame type (stream frame with fin)
1648 0x04, 0x03, 0x02, 0x01,
1650 0x54, 0x76, 0x10, 0x32,
1651 0xDC, 0xFE, 0x98, 0xBA,
1660 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1661 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1663 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1664 ASSERT_TRUE(visitor_
.header_
.get());
1665 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1666 EXPECT_EQ(IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
1667 EXPECT_EQ(GG_UINT64_C(0x341256789ABA),
1668 visitor_
.header_
->fec_group
);
1669 const size_t fec_offset
=
1670 GetStartOfFecProtectedData(PACKET_8BYTE_CONNECTION_ID
,
1672 PACKET_6BYTE_SEQUENCE_NUMBER
);
1674 string(AsChars(packet
) + fec_offset
, arraysize(packet
) - fec_offset
),
1675 visitor_
.fec_protected_payload_
);
1677 ASSERT_EQ(1u, visitor_
.stream_frames_
.size());
1678 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
1679 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_
.stream_frames_
[0]->stream_id
);
1680 EXPECT_TRUE(visitor_
.stream_frames_
[0]->fin
);
1681 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1682 visitor_
.stream_frames_
[0]->offset
);
1683 CheckStreamFrameData("hello world!", visitor_
.stream_frames_
[0]);
1686 TEST_P(QuicFramerTest
, AckFrame15
) {
1687 if (framer_
.version() != QUIC_VERSION_15
) {
1691 unsigned char packet
[] = {
1692 // public flags (8 byte connection_id)
1695 0x10, 0x32, 0x54, 0x76,
1696 0x98, 0xBA, 0xDC, 0xFE,
1697 // packet sequence number
1698 0xA8, 0x9A, 0x78, 0x56,
1700 // private flags (entropy)
1703 // frame type (ack frame)
1704 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
1706 // entropy hash of sent packets till least awaiting - 1.
1708 // least packet sequence number awaiting an ack, delta from sequence number.
1709 0x08, 0x00, 0x00, 0x00,
1711 // entropy hash of all received packets.
1713 // largest observed packet sequence number
1714 0xBF, 0x9A, 0x78, 0x56,
1718 // num missing packets
1720 // missing packet delta
1722 // 0 more missing packets in range.
1724 // Number of revived packets.
1728 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1729 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1731 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1732 ASSERT_TRUE(visitor_
.header_
.get());
1733 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1735 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
1736 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
1737 const QuicAckFrame
& frame
= *visitor_
.ack_frames_
[0];
1738 EXPECT_EQ(0xAB, frame
.sent_info
.entropy_hash
);
1739 EXPECT_EQ(0xBA, frame
.received_info
.entropy_hash
);
1740 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame
.received_info
.largest_observed
);
1741 ASSERT_EQ(1u, frame
.received_info
.missing_packets
.size());
1742 SequenceNumberSet::const_iterator missing_iter
=
1743 frame
.received_info
.missing_packets
.begin();
1744 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter
);
1745 EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame
.sent_info
.least_unacked
);
1747 const size_t kSentEntropyOffset
= kQuicFrameTypeSize
;
1748 const size_t kLeastUnackedOffset
= kSentEntropyOffset
+ kQuicEntropyHashSize
;
1749 const size_t kReceivedEntropyOffset
= kLeastUnackedOffset
+
1750 PACKET_6BYTE_SEQUENCE_NUMBER
;
1751 const size_t kLargestObservedOffset
= kReceivedEntropyOffset
+
1752 kQuicEntropyHashSize
;
1753 const size_t kMissingDeltaTimeOffset
= kLargestObservedOffset
+
1754 PACKET_6BYTE_SEQUENCE_NUMBER
;
1755 const size_t kNumMissingPacketOffset
= kMissingDeltaTimeOffset
+
1756 kQuicDeltaTimeLargestObservedSize
;
1757 const size_t kMissingPacketsOffset
= kNumMissingPacketOffset
+
1758 kNumberOfNackRangesSize
;
1759 const size_t kMissingPacketsRange
= kMissingPacketsOffset
+
1760 PACKET_1BYTE_SEQUENCE_NUMBER
;
1761 const size_t kRevivedPacketsLength
= kMissingPacketsRange
+
1762 PACKET_1BYTE_SEQUENCE_NUMBER
;
1763 // Now test framing boundaries
1764 const size_t ack_frame_size
= kRevivedPacketsLength
+
1765 PACKET_1BYTE_SEQUENCE_NUMBER
;
1766 for (size_t i
= kQuicFrameTypeSize
; i
< ack_frame_size
; ++i
) {
1767 string expected_error
;
1768 if (i
< kLeastUnackedOffset
) {
1769 expected_error
= "Unable to read entropy hash for sent packets.";
1770 } else if (i
< kReceivedEntropyOffset
) {
1771 expected_error
= "Unable to read least unacked delta.";
1772 } else if (i
< kLargestObservedOffset
) {
1773 expected_error
= "Unable to read entropy hash for received packets.";
1774 } else if (i
< kMissingDeltaTimeOffset
) {
1775 expected_error
= "Unable to read largest observed.";
1776 } else if (i
< kNumMissingPacketOffset
) {
1777 expected_error
= "Unable to read delta time largest observed.";
1778 } else if (i
< kMissingPacketsOffset
) {
1779 expected_error
= "Unable to read num missing packet ranges.";
1780 } else if (i
< kMissingPacketsRange
) {
1781 expected_error
= "Unable to read missing sequence number delta.";
1782 } else if (i
< kRevivedPacketsLength
) {
1783 expected_error
= "Unable to read missing sequence number range.";
1785 expected_error
= "Unable to read num revived packets.";
1787 CheckProcessingFails(
1789 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
1790 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
1791 expected_error
, QUIC_INVALID_ACK_DATA
);
1795 TEST_P(QuicFramerTest
, AckFrame
) {
1796 if (framer_
.version() <= QUIC_VERSION_15
) {
1800 unsigned char packet
[] = {
1801 // public flags (8 byte connection_id)
1804 0x10, 0x32, 0x54, 0x76,
1805 0x98, 0xBA, 0xDC, 0xFE,
1806 // packet sequence number
1807 0xA8, 0x9A, 0x78, 0x56,
1809 // private flags (entropy)
1812 // frame type (ack frame)
1813 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
1815 // entropy hash of all received packets.
1817 // largest observed packet sequence number
1818 0xBF, 0x9A, 0x78, 0x56,
1822 // num missing packets
1824 // missing packet delta
1826 // 0 more missing packets in range.
1828 // Number of revived packets.
1832 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1833 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1835 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1836 ASSERT_TRUE(visitor_
.header_
.get());
1837 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1839 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
1840 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
1841 const QuicAckFrame
& frame
= *visitor_
.ack_frames_
[0];
1842 EXPECT_EQ(0xBA, frame
.received_info
.entropy_hash
);
1843 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame
.received_info
.largest_observed
);
1844 ASSERT_EQ(1u, frame
.received_info
.missing_packets
.size());
1845 SequenceNumberSet::const_iterator missing_iter
=
1846 frame
.received_info
.missing_packets
.begin();
1847 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter
);
1849 const size_t kReceivedEntropyOffset
= kQuicFrameTypeSize
;
1850 const size_t kLargestObservedOffset
= kReceivedEntropyOffset
+
1851 kQuicEntropyHashSize
;
1852 const size_t kMissingDeltaTimeOffset
= kLargestObservedOffset
+
1853 PACKET_6BYTE_SEQUENCE_NUMBER
;
1854 const size_t kNumMissingPacketOffset
= kMissingDeltaTimeOffset
+
1855 kQuicDeltaTimeLargestObservedSize
;
1856 const size_t kMissingPacketsOffset
= kNumMissingPacketOffset
+
1857 kNumberOfNackRangesSize
;
1858 const size_t kMissingPacketsRange
= kMissingPacketsOffset
+
1859 PACKET_1BYTE_SEQUENCE_NUMBER
;
1860 const size_t kRevivedPacketsLength
= kMissingPacketsRange
+
1861 PACKET_1BYTE_SEQUENCE_NUMBER
;
1862 // Now test framing boundaries
1863 const size_t ack_frame_size
= kRevivedPacketsLength
+
1864 PACKET_1BYTE_SEQUENCE_NUMBER
;
1865 for (size_t i
= kQuicFrameTypeSize
; i
< ack_frame_size
; ++i
) {
1866 string expected_error
;
1867 if (i
< kLargestObservedOffset
) {
1868 expected_error
= "Unable to read entropy hash for received packets.";
1869 } else if (i
< kMissingDeltaTimeOffset
) {
1870 expected_error
= "Unable to read largest observed.";
1871 } else if (i
< kNumMissingPacketOffset
) {
1872 expected_error
= "Unable to read delta time largest observed.";
1873 } else if (i
< kMissingPacketsOffset
) {
1874 expected_error
= "Unable to read num missing packet ranges.";
1875 } else if (i
< kMissingPacketsRange
) {
1876 expected_error
= "Unable to read missing sequence number delta.";
1877 } else if (i
< kRevivedPacketsLength
) {
1878 expected_error
= "Unable to read missing sequence number range.";
1880 expected_error
= "Unable to read num revived packets.";
1882 CheckProcessingFails(
1884 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
1885 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
1886 expected_error
, QUIC_INVALID_ACK_DATA
);
1890 TEST_P(QuicFramerTest
, AckFrameRevivedPackets
) {
1891 if (framer_
.version() <= QUIC_VERSION_15
) {
1895 unsigned char packet
[] = {
1896 // public flags (8 byte connection_id)
1899 0x10, 0x32, 0x54, 0x76,
1900 0x98, 0xBA, 0xDC, 0xFE,
1901 // packet sequence number
1902 0xA8, 0x9A, 0x78, 0x56,
1904 // private flags (entropy)
1907 // frame type (ack frame)
1908 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
1910 // entropy hash of all received packets.
1912 // largest observed packet sequence number
1913 0xBF, 0x9A, 0x78, 0x56,
1917 // num missing packets
1919 // missing packet delta
1921 // 0 more missing packets in range.
1923 // Number of revived packets.
1925 // Revived packet sequence number.
1926 0xBE, 0x9A, 0x78, 0x56,
1930 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1931 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1933 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1934 ASSERT_TRUE(visitor_
.header_
.get());
1935 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1937 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
1938 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
1939 const QuicAckFrame
& frame
= *visitor_
.ack_frames_
[0];
1940 EXPECT_EQ(0xBA, frame
.received_info
.entropy_hash
);
1941 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame
.received_info
.largest_observed
);
1942 ASSERT_EQ(1u, frame
.received_info
.missing_packets
.size());
1943 SequenceNumberSet::const_iterator missing_iter
=
1944 frame
.received_info
.missing_packets
.begin();
1945 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter
);
1947 const size_t kReceivedEntropyOffset
= kQuicFrameTypeSize
;
1948 const size_t kLargestObservedOffset
= kReceivedEntropyOffset
+
1949 kQuicEntropyHashSize
;
1950 const size_t kMissingDeltaTimeOffset
= kLargestObservedOffset
+
1951 PACKET_6BYTE_SEQUENCE_NUMBER
;
1952 const size_t kNumMissingPacketOffset
= kMissingDeltaTimeOffset
+
1953 kQuicDeltaTimeLargestObservedSize
;
1954 const size_t kMissingPacketsOffset
= kNumMissingPacketOffset
+
1955 kNumberOfNackRangesSize
;
1956 const size_t kMissingPacketsRange
= kMissingPacketsOffset
+
1957 PACKET_1BYTE_SEQUENCE_NUMBER
;
1958 const size_t kRevivedPacketsLength
= kMissingPacketsRange
+
1959 PACKET_1BYTE_SEQUENCE_NUMBER
;
1960 const size_t kRevivedPacketSequenceNumberLength
= kRevivedPacketsLength
+
1961 PACKET_1BYTE_SEQUENCE_NUMBER
;
1962 // Now test framing boundaries
1963 const size_t ack_frame_size
= kRevivedPacketSequenceNumberLength
+
1964 PACKET_6BYTE_SEQUENCE_NUMBER
;
1965 for (size_t i
= kQuicFrameTypeSize
; i
< ack_frame_size
; ++i
) {
1966 string expected_error
;
1967 if (i
< kReceivedEntropyOffset
) {
1968 expected_error
= "Unable to read least unacked delta.";
1969 } else if (i
< kLargestObservedOffset
) {
1970 expected_error
= "Unable to read entropy hash for received packets.";
1971 } else if (i
< kMissingDeltaTimeOffset
) {
1972 expected_error
= "Unable to read largest observed.";
1973 } else if (i
< kNumMissingPacketOffset
) {
1974 expected_error
= "Unable to read delta time largest observed.";
1975 } else if (i
< kMissingPacketsOffset
) {
1976 expected_error
= "Unable to read num missing packet ranges.";
1977 } else if (i
< kMissingPacketsRange
) {
1978 expected_error
= "Unable to read missing sequence number delta.";
1979 } else if (i
< kRevivedPacketsLength
) {
1980 expected_error
= "Unable to read missing sequence number range.";
1981 } else if (i
< kRevivedPacketSequenceNumberLength
) {
1982 expected_error
= "Unable to read num revived packets.";
1984 expected_error
= "Unable to read revived packet.";
1986 CheckProcessingFails(
1988 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
1989 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
1990 expected_error
, QUIC_INVALID_ACK_DATA
);
1994 TEST_P(QuicFramerTest
, AckFrameRevivedPackets15
) {
1995 if (framer_
.version() != QUIC_VERSION_15
) {
1999 unsigned char packet
[] = {
2000 // public flags (8 byte connection_id)
2003 0x10, 0x32, 0x54, 0x76,
2004 0x98, 0xBA, 0xDC, 0xFE,
2005 // packet sequence number
2006 0xA8, 0x9A, 0x78, 0x56,
2008 // private flags (entropy)
2011 // frame type (ack frame)
2012 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
2014 // entropy hash of sent packets till least awaiting - 1.
2016 // least packet sequence number awaiting an ack, delta from sequence number.
2017 0x08, 0x00, 0x00, 0x00,
2019 // entropy hash of all received packets.
2021 // largest observed packet sequence number
2022 0xBF, 0x9A, 0x78, 0x56,
2026 // num missing packets
2028 // missing packet delta
2030 // 0 more missing packets in range.
2032 // Number of revived packets.
2034 // Revived packet sequence number.
2035 0xBE, 0x9A, 0x78, 0x56,
2039 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2040 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2042 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2043 ASSERT_TRUE(visitor_
.header_
.get());
2044 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2046 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
2047 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
2048 const QuicAckFrame
& frame
= *visitor_
.ack_frames_
[0];
2049 EXPECT_EQ(0xAB, frame
.sent_info
.entropy_hash
);
2050 EXPECT_EQ(0xBA, frame
.received_info
.entropy_hash
);
2051 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame
.received_info
.largest_observed
);
2052 ASSERT_EQ(1u, frame
.received_info
.missing_packets
.size());
2053 SequenceNumberSet::const_iterator missing_iter
=
2054 frame
.received_info
.missing_packets
.begin();
2055 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter
);
2056 EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame
.sent_info
.least_unacked
);
2058 const size_t kSentEntropyOffset
= kQuicFrameTypeSize
;
2059 const size_t kLeastUnackedOffset
= kSentEntropyOffset
+ kQuicEntropyHashSize
;
2060 const size_t kReceivedEntropyOffset
= kLeastUnackedOffset
+
2061 PACKET_6BYTE_SEQUENCE_NUMBER
;
2062 const size_t kLargestObservedOffset
= kReceivedEntropyOffset
+
2063 kQuicEntropyHashSize
;
2064 const size_t kMissingDeltaTimeOffset
= kLargestObservedOffset
+
2065 PACKET_6BYTE_SEQUENCE_NUMBER
;
2066 const size_t kNumMissingPacketOffset
= kMissingDeltaTimeOffset
+
2067 kQuicDeltaTimeLargestObservedSize
;
2068 const size_t kMissingPacketsOffset
= kNumMissingPacketOffset
+
2069 kNumberOfNackRangesSize
;
2070 const size_t kMissingPacketsRange
= kMissingPacketsOffset
+
2071 PACKET_1BYTE_SEQUENCE_NUMBER
;
2072 const size_t kRevivedPacketsLength
= kMissingPacketsRange
+
2073 PACKET_1BYTE_SEQUENCE_NUMBER
;
2074 const size_t kRevivedPacketSequenceNumberLength
= kRevivedPacketsLength
+
2075 PACKET_1BYTE_SEQUENCE_NUMBER
;
2076 // Now test framing boundaries
2077 const size_t ack_frame_size
= kRevivedPacketSequenceNumberLength
+
2078 PACKET_6BYTE_SEQUENCE_NUMBER
;
2079 for (size_t i
= kQuicFrameTypeSize
; i
< ack_frame_size
; ++i
) {
2080 string expected_error
;
2081 if (i
< kLeastUnackedOffset
) {
2082 expected_error
= "Unable to read entropy hash for sent packets.";
2083 } else if (i
< kReceivedEntropyOffset
) {
2084 expected_error
= "Unable to read least unacked delta.";
2085 } else if (i
< kLargestObservedOffset
) {
2086 expected_error
= "Unable to read entropy hash for received packets.";
2087 } else if (i
< kMissingDeltaTimeOffset
) {
2088 expected_error
= "Unable to read largest observed.";
2089 } else if (i
< kNumMissingPacketOffset
) {
2090 expected_error
= "Unable to read delta time largest observed.";
2091 } else if (i
< kMissingPacketsOffset
) {
2092 expected_error
= "Unable to read num missing packet ranges.";
2093 } else if (i
< kMissingPacketsRange
) {
2094 expected_error
= "Unable to read missing sequence number delta.";
2095 } else if (i
< kRevivedPacketsLength
) {
2096 expected_error
= "Unable to read missing sequence number range.";
2097 } else if (i
< kRevivedPacketSequenceNumberLength
) {
2098 expected_error
= "Unable to read num revived packets.";
2100 expected_error
= "Unable to read revived packet.";
2102 CheckProcessingFails(
2104 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
2105 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
2106 expected_error
, QUIC_INVALID_ACK_DATA
);
2110 TEST_P(QuicFramerTest
, AckFrameNoNacks
) {
2111 if (framer_
.version() <= QUIC_VERSION_15
) {
2114 unsigned char packet
[] = {
2115 // public flags (8 byte connection_id)
2118 0x10, 0x32, 0x54, 0x76,
2119 0x98, 0xBA, 0xDC, 0xFE,
2120 // packet sequence number
2121 0xA8, 0x9A, 0x78, 0x56,
2123 // private flags (entropy)
2126 // frame type (ack frame)
2127 // (no nacks, not truncated, 6 byte largest observed, 1 byte delta)
2129 // entropy hash of all received packets.
2131 // largest observed packet sequence number
2132 0xBF, 0x9A, 0x78, 0x56,
2138 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2139 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2141 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2142 ASSERT_TRUE(visitor_
.header_
.get());
2143 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2145 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
2146 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
2147 QuicAckFrame
* frame
= visitor_
.ack_frames_
[0];
2148 EXPECT_EQ(0xBA, frame
->received_info
.entropy_hash
);
2149 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF),
2150 frame
->received_info
.largest_observed
);
2151 ASSERT_EQ(0u, frame
->received_info
.missing_packets
.size());
2153 // Verify that the packet re-serializes identically.
2155 frames
.push_back(QuicFrame(frame
));
2156 scoped_ptr
<QuicPacket
> data(BuildDataPacket(*visitor_
.header_
, frames
));
2157 ASSERT_TRUE(data
!= NULL
);
2159 test::CompareCharArraysWithHexError("constructed packet",
2160 data
->data(), data
->length(),
2161 AsChars(packet
), arraysize(packet
));
2164 TEST_P(QuicFramerTest
, AckFrameNoNacks15
) {
2165 if (framer_
.version() > QUIC_VERSION_15
) {
2168 unsigned char packet
[] = {
2169 // public flags (8 byte connection_id)
2172 0x10, 0x32, 0x54, 0x76,
2173 0x98, 0xBA, 0xDC, 0xFE,
2174 // packet sequence number
2175 0xA8, 0x9A, 0x78, 0x56,
2177 // private flags (entropy)
2180 // frame type (ack frame)
2181 // (no nacks, not truncated, 6 byte largest observed, 1 byte delta)
2183 // entropy hash of sent packets till least awaiting - 1.
2185 // least packet sequence number awaiting an ack, delta from sequence number.
2186 0x08, 0x00, 0x00, 0x00,
2188 // entropy hash of all received packets.
2190 // largest observed packet sequence number
2191 0xBF, 0x9A, 0x78, 0x56,
2197 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2198 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2200 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2201 ASSERT_TRUE(visitor_
.header_
.get());
2202 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2204 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
2205 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
2206 QuicAckFrame
* frame
= visitor_
.ack_frames_
[0];
2207 EXPECT_EQ(0xAB, frame
->sent_info
.entropy_hash
);
2208 EXPECT_EQ(0xBA, frame
->received_info
.entropy_hash
);
2209 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF),
2210 frame
->received_info
.largest_observed
);
2211 ASSERT_EQ(0u, frame
->received_info
.missing_packets
.size());
2212 EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame
->sent_info
.least_unacked
);
2214 // Verify that the packet re-serializes identically.
2216 frames
.push_back(QuicFrame(frame
));
2217 scoped_ptr
<QuicPacket
> data(BuildDataPacket(*visitor_
.header_
, frames
));
2218 ASSERT_TRUE(data
!= NULL
);
2220 test::CompareCharArraysWithHexError("constructed packet",
2221 data
->data(), data
->length(),
2222 AsChars(packet
), arraysize(packet
));
2225 TEST_P(QuicFramerTest
, AckFrame500Nacks
) {
2226 if (framer_
.version() <= QUIC_VERSION_15
) {
2229 unsigned char packet
[] = {
2230 // public flags (8 byte connection_id)
2233 0x10, 0x32, 0x54, 0x76,
2234 0x98, 0xBA, 0xDC, 0xFE,
2235 // packet sequence number
2236 0xA8, 0x9A, 0x78, 0x56,
2238 // private flags (entropy)
2241 // frame type (ack frame)
2242 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
2244 // entropy hash of all received packets.
2246 // largest observed packet sequence number
2247 0xBF, 0x9A, 0x78, 0x56,
2251 // num missing packet ranges
2253 // missing packet delta
2255 // 243 more missing packets in range.
2256 // The ranges are listed in this order so the re-constructed packet matches.
2258 // No gap between ranges
2260 // 255 more missing packets in range.
2262 // No revived packets.
2266 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2267 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2269 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2270 ASSERT_TRUE(visitor_
.header_
.get());
2271 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2273 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
2274 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
2275 QuicAckFrame
* frame
= visitor_
.ack_frames_
[0];
2276 EXPECT_EQ(0xBA, frame
->received_info
.entropy_hash
);
2277 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF),
2278 frame
->received_info
.largest_observed
);
2279 EXPECT_EQ(0u, frame
->received_info
.revived_packets
.size());
2280 ASSERT_EQ(500u, frame
->received_info
.missing_packets
.size());
2281 SequenceNumberSet::const_iterator first_missing_iter
=
2282 frame
->received_info
.missing_packets
.begin();
2283 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE) - 499, *first_missing_iter
);
2284 SequenceNumberSet::const_reverse_iterator last_missing_iter
=
2285 frame
->received_info
.missing_packets
.rbegin();
2286 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *last_missing_iter
);
2288 // Verify that the packet re-serializes identically.
2290 frames
.push_back(QuicFrame(frame
));
2291 scoped_ptr
<QuicPacket
> data(BuildDataPacket(*visitor_
.header_
, frames
));
2292 ASSERT_TRUE(data
!= NULL
);
2294 test::CompareCharArraysWithHexError("constructed packet",
2295 data
->data(), data
->length(),
2296 AsChars(packet
), arraysize(packet
));
2299 TEST_P(QuicFramerTest
, AckFrame500Nacks15
) {
2300 if (framer_
.version() != QUIC_VERSION_15
) {
2303 unsigned char packet
[] = {
2304 // public flags (8 byte connection_id)
2307 0x10, 0x32, 0x54, 0x76,
2308 0x98, 0xBA, 0xDC, 0xFE,
2309 // packet sequence number
2310 0xA8, 0x9A, 0x78, 0x56,
2312 // private flags (entropy)
2315 // frame type (ack frame)
2316 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
2318 // entropy hash of sent packets till least awaiting - 1.
2320 // least packet sequence number awaiting an ack, delta from sequence number.
2321 0x08, 0x00, 0x00, 0x00,
2323 // entropy hash of all received packets.
2325 // largest observed packet sequence number
2326 0xBF, 0x9A, 0x78, 0x56,
2330 // num missing packet ranges
2332 // missing packet delta
2334 // 243 more missing packets in range.
2335 // The ranges are listed in this order so the re-constructed packet matches.
2337 // No gap between ranges
2339 // 255 more missing packets in range.
2341 // No revived packets.
2345 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2346 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2348 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2349 ASSERT_TRUE(visitor_
.header_
.get());
2350 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2352 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
2353 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
2354 QuicAckFrame
* frame
= visitor_
.ack_frames_
[0];
2355 EXPECT_EQ(0xAB, frame
->sent_info
.entropy_hash
);
2356 EXPECT_EQ(0xBA, frame
->received_info
.entropy_hash
);
2357 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF),
2358 frame
->received_info
.largest_observed
);
2359 EXPECT_EQ(0u, frame
->received_info
.revived_packets
.size());
2360 ASSERT_EQ(500u, frame
->received_info
.missing_packets
.size());
2361 SequenceNumberSet::const_iterator first_missing_iter
=
2362 frame
->received_info
.missing_packets
.begin();
2363 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE) - 499, *first_missing_iter
);
2364 SequenceNumberSet::const_reverse_iterator last_missing_iter
=
2365 frame
->received_info
.missing_packets
.rbegin();
2366 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *last_missing_iter
);
2367 EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame
->sent_info
.least_unacked
);
2369 // Verify that the packet re-serializes identically.
2371 frames
.push_back(QuicFrame(frame
));
2372 scoped_ptr
<QuicPacket
> data(BuildDataPacket(*visitor_
.header_
, frames
));
2373 ASSERT_TRUE(data
!= NULL
);
2375 test::CompareCharArraysWithHexError("constructed packet",
2376 data
->data(), data
->length(),
2377 AsChars(packet
), arraysize(packet
));
2380 TEST_P(QuicFramerTest
, CongestionFeedbackFrameTCP
) {
2381 unsigned char packet
[] = {
2382 // public flags (8 byte connection_id)
2385 0x10, 0x32, 0x54, 0x76,
2386 0x98, 0xBA, 0xDC, 0xFE,
2387 // packet sequence number
2388 0xBC, 0x9A, 0x78, 0x56,
2393 // frame type (congestion feedback frame)
2395 // congestion feedback type (tcp)
2397 // ack_frame.feedback.tcp.receive_window
2401 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2402 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2404 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2405 ASSERT_TRUE(visitor_
.header_
.get());
2406 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2408 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
2409 ASSERT_EQ(1u, visitor_
.congestion_feedback_frames_
.size());
2410 const QuicCongestionFeedbackFrame
& frame
=
2411 *visitor_
.congestion_feedback_frames_
[0];
2412 ASSERT_EQ(kTCP
, frame
.type
);
2413 EXPECT_EQ(0x4030u
, frame
.tcp
.receive_window
);
2415 // Now test framing boundaries
2416 for (size_t i
= kQuicFrameTypeSize
; i
< 4; ++i
) {
2417 string expected_error
;
2419 expected_error
= "Unable to read congestion feedback type.";
2421 expected_error
= "Unable to read receive window.";
2423 CheckProcessingFails(
2425 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
2426 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
2427 expected_error
, QUIC_INVALID_CONGESTION_FEEDBACK_DATA
);
2431 TEST_P(QuicFramerTest
, CongestionFeedbackFrameInterArrival
) {
2432 unsigned char packet
[] = {
2433 // public flags (8 byte connection_id)
2436 0x10, 0x32, 0x54, 0x76,
2437 0x98, 0xBA, 0xDC, 0xFE,
2438 // packet sequence number
2439 0xBC, 0x9A, 0x78, 0x56,
2444 // frame type (congestion feedback frame)
2446 // congestion feedback type (inter arrival)
2448 // num received packets
2450 // lowest sequence number
2451 0xBA, 0x9A, 0x78, 0x56,
2454 0x87, 0x96, 0xA5, 0xB4,
2455 0xC3, 0xD2, 0xE1, 0x07,
2459 0x01, 0x00, 0x00, 0x00,
2460 // sequence delta (skip one packet)
2463 0x02, 0x00, 0x00, 0x00,
2466 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2467 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2469 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2470 ASSERT_TRUE(visitor_
.header_
.get());
2471 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2473 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
2474 ASSERT_EQ(1u, visitor_
.congestion_feedback_frames_
.size());
2475 const QuicCongestionFeedbackFrame
& frame
=
2476 *visitor_
.congestion_feedback_frames_
[0];
2477 ASSERT_EQ(kInterArrival
, frame
.type
);
2478 ASSERT_EQ(3u, frame
.inter_arrival
.received_packet_times
.size());
2479 TimeMap::const_iterator iter
=
2480 frame
.inter_arrival
.received_packet_times
.begin();
2481 EXPECT_EQ(GG_UINT64_C(0x0123456789ABA), iter
->first
);
2482 EXPECT_EQ(GG_INT64_C(0x07E1D2C3B4A59687),
2483 iter
->second
.Subtract(start_
).ToMicroseconds());
2485 EXPECT_EQ(GG_UINT64_C(0x0123456789ABB), iter
->first
);
2486 EXPECT_EQ(GG_INT64_C(0x07E1D2C3B4A59688),
2487 iter
->second
.Subtract(start_
).ToMicroseconds());
2489 EXPECT_EQ(GG_UINT64_C(0x0123456789ABD), iter
->first
);
2490 EXPECT_EQ(GG_INT64_C(0x07E1D2C3B4A59689),
2491 iter
->second
.Subtract(start_
).ToMicroseconds());
2493 // Now test framing boundaries
2494 for (size_t i
= kQuicFrameTypeSize
; i
< 29; ++i
) {
2495 string expected_error
;
2497 expected_error
= "Unable to read congestion feedback type.";
2499 expected_error
= "Unable to read num received packets.";
2501 expected_error
= "Unable to read smallest received.";
2502 } else if (i
< 17) {
2503 expected_error
= "Unable to read time received.";
2504 } else if (i
< 19) {
2505 expected_error
= "Unable to read sequence delta in received packets.";
2506 } else if (i
< 23) {
2507 expected_error
= "Unable to read time delta in received packets.";
2508 } else if (i
< 25) {
2509 expected_error
= "Unable to read sequence delta in received packets.";
2510 } else if (i
< 29) {
2511 expected_error
= "Unable to read time delta in received packets.";
2513 CheckProcessingFails(
2515 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
2516 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
2517 expected_error
, QUIC_INVALID_CONGESTION_FEEDBACK_DATA
);
2521 TEST_P(QuicFramerTest
, CongestionFeedbackFrameFixRate
) {
2522 unsigned char packet
[] = {
2523 // public flags (8 byte connection_id)
2526 0x10, 0x32, 0x54, 0x76,
2527 0x98, 0xBA, 0xDC, 0xFE,
2528 // packet sequence number
2529 0xBC, 0x9A, 0x78, 0x56,
2534 // frame type (congestion feedback frame)
2536 // congestion feedback type (fix rate)
2538 // bitrate_in_bytes_per_second;
2539 0x01, 0x02, 0x03, 0x04,
2542 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2543 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2545 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2546 ASSERT_TRUE(visitor_
.header_
.get());
2547 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2549 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
2550 ASSERT_EQ(1u, visitor_
.congestion_feedback_frames_
.size());
2551 const QuicCongestionFeedbackFrame
& frame
=
2552 *visitor_
.congestion_feedback_frames_
[0];
2553 ASSERT_EQ(kFixRate
, frame
.type
);
2554 EXPECT_EQ(static_cast<uint32
>(0x04030201),
2555 frame
.fix_rate
.bitrate
.ToBytesPerSecond());
2557 // Now test framing boundaries
2558 for (size_t i
= kQuicFrameTypeSize
; i
< 6; ++i
) {
2559 string expected_error
;
2561 expected_error
= "Unable to read congestion feedback type.";
2563 expected_error
= "Unable to read bitrate.";
2565 CheckProcessingFails(
2567 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
2568 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
2569 expected_error
, QUIC_INVALID_CONGESTION_FEEDBACK_DATA
);
2573 TEST_P(QuicFramerTest
, CongestionFeedbackFrameInvalidFeedback
) {
2574 unsigned char packet
[] = {
2575 // public flags (8 byte connection_id)
2578 0x10, 0x32, 0x54, 0x76,
2579 0x98, 0xBA, 0xDC, 0xFE,
2580 // packet sequence number
2581 0xBC, 0x9A, 0x78, 0x56,
2586 // frame type (congestion feedback frame)
2588 // congestion feedback type (invalid)
2592 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2593 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
2594 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2595 EXPECT_EQ(QUIC_INVALID_CONGESTION_FEEDBACK_DATA
, framer_
.error());
2598 TEST_P(QuicFramerTest
, StopWaitingFrame
) {
2599 if (framer_
.version() <= QUIC_VERSION_15
) {
2602 unsigned char packet
[] = {
2603 // public flags (8 byte connection_id)
2606 0x10, 0x32, 0x54, 0x76,
2607 0x98, 0xBA, 0xDC, 0xFE,
2608 // packet sequence number
2609 0xA8, 0x9A, 0x78, 0x56,
2611 // private flags (entropy)
2614 // frame type (ack frame)
2615 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
2617 // entropy hash of sent packets till least awaiting - 1.
2619 // least packet sequence number awaiting an ack, delta from sequence number.
2620 0x08, 0x00, 0x00, 0x00,
2624 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2625 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2627 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2628 ASSERT_TRUE(visitor_
.header_
.get());
2629 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2631 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
2632 ASSERT_EQ(1u, visitor_
.stop_waiting_frames_
.size());
2633 const QuicStopWaitingFrame
& frame
= *visitor_
.stop_waiting_frames_
[0];
2634 EXPECT_EQ(0xAB, frame
.entropy_hash
);
2635 EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame
.least_unacked
);
2637 const size_t kSentEntropyOffset
= kQuicFrameTypeSize
;
2638 const size_t kLeastUnackedOffset
= kSentEntropyOffset
+ kQuicEntropyHashSize
;
2639 const size_t frame_size
= 7;
2640 for (size_t i
= kQuicFrameTypeSize
; i
< frame_size
; ++i
) {
2641 string expected_error
;
2642 if (i
< kLeastUnackedOffset
) {
2643 expected_error
= "Unable to read entropy hash for sent packets.";
2645 expected_error
= "Unable to read least unacked delta.";
2647 CheckProcessingFails(
2649 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
2650 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
2651 expected_error
, QUIC_INVALID_STOP_WAITING_DATA
);
2655 TEST_P(QuicFramerTest
, RstStreamFrameQuic
) {
2656 unsigned char packet
[] = {
2657 // public flags (8 byte connection_id)
2660 0x10, 0x32, 0x54, 0x76,
2661 0x98, 0xBA, 0xDC, 0xFE,
2662 // packet sequence number
2663 0xBC, 0x9A, 0x78, 0x56,
2668 // frame type (rst stream frame)
2671 0x04, 0x03, 0x02, 0x01,
2674 0x01, 0x02, 0x03, 0x04,
2675 0x05, 0x06, 0x07, 0x08,
2678 0x01, 0x00, 0x00, 0x00,
2680 // error details length
2689 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2690 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2692 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2693 ASSERT_TRUE(visitor_
.header_
.get());
2694 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2696 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_
.rst_stream_frame_
.stream_id
);
2697 EXPECT_EQ(0x01, visitor_
.rst_stream_frame_
.error_code
);
2698 EXPECT_EQ("because I can", visitor_
.rst_stream_frame_
.error_details
);
2699 EXPECT_EQ(GG_UINT64_C(0x0807060504030201),
2700 visitor_
.rst_stream_frame_
.byte_offset
);
2702 // Now test framing boundaries
2703 for (size_t i
= kQuicFrameTypeSize
;
2704 i
< QuicFramer::GetMinRstStreamFrameSize(version_
); ++i
) {
2705 string expected_error
;
2706 if (i
< kQuicFrameTypeSize
+ kQuicMaxStreamIdSize
) {
2707 expected_error
= "Unable to read stream_id.";
2708 } else if (i
< kQuicFrameTypeSize
+ kQuicMaxStreamIdSize
+
2709 + kQuicMaxStreamOffsetSize
) {
2710 expected_error
= "Unable to read rst stream sent byte offset.";
2711 } else if (i
< kQuicFrameTypeSize
+ kQuicMaxStreamIdSize
+
2712 + kQuicMaxStreamOffsetSize
+ kQuicErrorCodeSize
) {
2713 expected_error
= "Unable to read rst stream error code.";
2715 expected_error
= "Unable to read rst stream error details.";
2717 CheckProcessingFails(
2719 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
2720 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
2721 expected_error
, QUIC_INVALID_RST_STREAM_DATA
);
2725 TEST_P(QuicFramerTest
, ConnectionCloseFrame
) {
2726 unsigned char packet
[] = {
2727 // public flags (8 byte connection_id)
2730 0x10, 0x32, 0x54, 0x76,
2731 0x98, 0xBA, 0xDC, 0xFE,
2732 // packet sequence number
2733 0xBC, 0x9A, 0x78, 0x56,
2738 // frame type (connection close frame)
2741 0x11, 0x00, 0x00, 0x00,
2743 // error details length
2752 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2753 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2755 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2756 ASSERT_TRUE(visitor_
.header_
.get());
2757 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2759 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
2761 EXPECT_EQ(0x11, visitor_
.connection_close_frame_
.error_code
);
2762 EXPECT_EQ("because I can", visitor_
.connection_close_frame_
.error_details
);
2764 ASSERT_EQ(0u, visitor_
.ack_frames_
.size());
2766 // Now test framing boundaries
2767 for (size_t i
= kQuicFrameTypeSize
;
2768 i
< QuicFramer::GetMinConnectionCloseFrameSize(); ++i
) {
2769 string expected_error
;
2770 if (i
< kQuicFrameTypeSize
+ kQuicErrorCodeSize
) {
2771 expected_error
= "Unable to read connection close error code.";
2773 expected_error
= "Unable to read connection close error details.";
2775 CheckProcessingFails(
2777 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
2778 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
2779 expected_error
, QUIC_INVALID_CONNECTION_CLOSE_DATA
);
2783 TEST_P(QuicFramerTest
, GoAwayFrame
) {
2784 unsigned char packet
[] = {
2785 // public flags (8 byte connection_id)
2788 0x10, 0x32, 0x54, 0x76,
2789 0x98, 0xBA, 0xDC, 0xFE,
2790 // packet sequence number
2791 0xBC, 0x9A, 0x78, 0x56,
2796 // frame type (go away frame)
2799 0x09, 0x00, 0x00, 0x00,
2801 0x04, 0x03, 0x02, 0x01,
2802 // error details length
2811 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2812 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2814 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2815 ASSERT_TRUE(visitor_
.header_
.get());
2816 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2818 EXPECT_EQ(GG_UINT64_C(0x01020304),
2819 visitor_
.goaway_frame_
.last_good_stream_id
);
2820 EXPECT_EQ(0x9, visitor_
.goaway_frame_
.error_code
);
2821 EXPECT_EQ("because I can", visitor_
.goaway_frame_
.reason_phrase
);
2823 const size_t reason_size
= arraysize("because I can") - 1;
2824 // Now test framing boundaries
2825 for (size_t i
= kQuicFrameTypeSize
;
2826 i
< QuicFramer::GetMinGoAwayFrameSize() + reason_size
; ++i
) {
2827 string expected_error
;
2828 if (i
< kQuicFrameTypeSize
+ kQuicErrorCodeSize
) {
2829 expected_error
= "Unable to read go away error code.";
2830 } else if (i
< kQuicFrameTypeSize
+ kQuicErrorCodeSize
+
2831 kQuicMaxStreamIdSize
) {
2832 expected_error
= "Unable to read last good stream id.";
2834 expected_error
= "Unable to read goaway reason.";
2836 CheckProcessingFails(
2838 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
2839 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
2840 expected_error
, QUIC_INVALID_GOAWAY_DATA
);
2844 TEST_P(QuicFramerTest
, WindowUpdateFrame
) {
2845 unsigned char packet
[] = {
2846 // public flags (8 byte connection_id)
2849 0x10, 0x32, 0x54, 0x76,
2850 0x98, 0xBA, 0xDC, 0xFE,
2851 // packet sequence number
2852 0xBC, 0x9A, 0x78, 0x56,
2857 // frame type (window update frame)
2860 0x04, 0x03, 0x02, 0x01,
2862 0x05, 0x06, 0x07, 0x08,
2863 0x09, 0x0a, 0x0b, 0x0c,
2866 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2868 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2870 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2871 ASSERT_TRUE(visitor_
.header_
.get());
2872 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2874 EXPECT_EQ(GG_UINT64_C(0x01020304),
2875 visitor_
.window_update_frame_
.stream_id
);
2876 EXPECT_EQ(GG_UINT64_C(0x0c0b0a0908070605),
2877 visitor_
.window_update_frame_
.byte_offset
);
2879 // Now test framing boundaries
2880 for (size_t i
= kQuicFrameTypeSize
;
2881 i
< QuicFramer::GetWindowUpdateFrameSize(); ++i
) {
2882 string expected_error
;
2883 if (i
< kQuicFrameTypeSize
+ kQuicMaxStreamIdSize
) {
2884 expected_error
= "Unable to read stream_id.";
2886 expected_error
= "Unable to read window byte_offset.";
2888 CheckProcessingFails(
2890 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
2891 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
2892 expected_error
, QUIC_INVALID_WINDOW_UPDATE_DATA
);
2896 TEST_P(QuicFramerTest
, BlockedFrame
) {
2897 unsigned char packet
[] = {
2898 // public flags (8 byte connection_id)
2901 0x10, 0x32, 0x54, 0x76,
2902 0x98, 0xBA, 0xDC, 0xFE,
2903 // packet sequence number
2904 0xBC, 0x9A, 0x78, 0x56,
2909 // frame type (blocked frame)
2912 0x04, 0x03, 0x02, 0x01,
2915 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2917 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2919 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2920 ASSERT_TRUE(visitor_
.header_
.get());
2921 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2923 EXPECT_EQ(GG_UINT64_C(0x01020304),
2924 visitor_
.blocked_frame_
.stream_id
);
2926 // Now test framing boundaries
2927 for (size_t i
= kQuicFrameTypeSize
; i
< QuicFramer::GetBlockedFrameSize();
2929 string expected_error
= "Unable to read stream_id.";
2930 CheckProcessingFails(
2932 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
2933 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
2934 expected_error
, QUIC_INVALID_BLOCKED_DATA
);
2938 TEST_P(QuicFramerTest
, PingFrame
) {
2939 if (version_
<= QUIC_VERSION_16
) {
2943 unsigned char packet
[] = {
2944 // public flags (8 byte connection_id)
2947 0x10, 0x32, 0x54, 0x76,
2948 0x98, 0xBA, 0xDC, 0xFE,
2949 // packet sequence number
2950 0xBC, 0x9A, 0x78, 0x56,
2955 // frame type (ping frame)
2959 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2960 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2962 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2963 ASSERT_TRUE(visitor_
.header_
.get());
2964 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2966 EXPECT_EQ(1u, visitor_
.ping_frames_
.size());
2968 // No need to check the PING frame boundaries because it has no payload.
2971 TEST_P(QuicFramerTest
, PublicResetPacket
) {
2972 unsigned char packet
[] = {
2973 // public flags (public reset, 8 byte connection_id)
2976 0x10, 0x32, 0x54, 0x76,
2977 0x98, 0xBA, 0xDC, 0xFE,
2978 // message tag (kPRST)
2980 // num_entries (2) + padding
2981 0x02, 0x00, 0x00, 0x00,
2985 0x08, 0x00, 0x00, 0x00,
2989 0x10, 0x00, 0x00, 0x00,
2991 0x89, 0x67, 0x45, 0x23,
2992 0x01, 0xEF, 0xCD, 0xAB,
2993 // rejected sequence number
2994 0xBC, 0x9A, 0x78, 0x56,
2995 0x34, 0x12, 0x00, 0x00,
2998 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2999 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
3000 ASSERT_EQ(QUIC_NO_ERROR
, framer_
.error());
3001 ASSERT_TRUE(visitor_
.public_reset_packet_
.get());
3002 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
3003 visitor_
.public_reset_packet_
->public_header
.connection_id
);
3004 EXPECT_TRUE(visitor_
.public_reset_packet_
->public_header
.reset_flag
);
3005 EXPECT_FALSE(visitor_
.public_reset_packet_
->public_header
.version_flag
);
3006 EXPECT_EQ(GG_UINT64_C(0xABCDEF0123456789),
3007 visitor_
.public_reset_packet_
->nonce_proof
);
3008 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
3009 visitor_
.public_reset_packet_
->rejected_sequence_number
);
3011 visitor_
.public_reset_packet_
->client_address
.address().empty());
3013 // Now test framing boundaries
3014 for (size_t i
= 0; i
< arraysize(packet
); ++i
) {
3015 string expected_error
;
3016 DVLOG(1) << "iteration: " << i
;
3017 if (i
< kConnectionIdOffset
) {
3018 expected_error
= "Unable to read public flags.";
3019 CheckProcessingFails(packet
, i
, expected_error
,
3020 QUIC_INVALID_PACKET_HEADER
);
3021 } else if (i
< kPublicResetPacketMessageTagOffset
) {
3022 expected_error
= "Unable to read ConnectionId.";
3023 CheckProcessingFails(packet
, i
, expected_error
,
3024 QUIC_INVALID_PACKET_HEADER
);
3026 expected_error
= "Unable to read reset message.";
3027 CheckProcessingFails(packet
, i
, expected_error
,
3028 QUIC_INVALID_PUBLIC_RST_PACKET
);
3033 TEST_P(QuicFramerTest
, PublicResetPacketWithTrailingJunk
) {
3034 unsigned char packet
[] = {
3035 // public flags (public reset, 8 byte connection_id)
3038 0x10, 0x32, 0x54, 0x76,
3039 0x98, 0xBA, 0xDC, 0xFE,
3040 // message tag (kPRST)
3042 // num_entries (2) + padding
3043 0x02, 0x00, 0x00, 0x00,
3047 0x08, 0x00, 0x00, 0x00,
3051 0x10, 0x00, 0x00, 0x00,
3053 0x89, 0x67, 0x45, 0x23,
3054 0x01, 0xEF, 0xCD, 0xAB,
3055 // rejected sequence number
3056 0xBC, 0x9A, 0x78, 0x56,
3057 0x34, 0x12, 0x00, 0x00,
3062 string expected_error
= "Unable to read reset message.";
3063 CheckProcessingFails(packet
, arraysize(packet
), expected_error
,
3064 QUIC_INVALID_PUBLIC_RST_PACKET
);
3067 TEST_P(QuicFramerTest
, PublicResetPacketWithClientAddress
) {
3068 unsigned char packet
[] = {
3069 // public flags (public reset, 8 byte connection_id)
3072 0x10, 0x32, 0x54, 0x76,
3073 0x98, 0xBA, 0xDC, 0xFE,
3074 // message tag (kPRST)
3076 // num_entries (3) + padding
3077 0x03, 0x00, 0x00, 0x00,
3081 0x08, 0x00, 0x00, 0x00,
3085 0x10, 0x00, 0x00, 0x00,
3089 0x18, 0x00, 0x00, 0x00,
3091 0x89, 0x67, 0x45, 0x23,
3092 0x01, 0xEF, 0xCD, 0xAB,
3093 // rejected sequence number
3094 0xBC, 0x9A, 0x78, 0x56,
3095 0x34, 0x12, 0x00, 0x00,
3096 // client address: 4.31.198.44:443
3098 0x04, 0x1F, 0xC6, 0x2C,
3102 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
3103 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
3104 ASSERT_EQ(QUIC_NO_ERROR
, framer_
.error());
3105 ASSERT_TRUE(visitor_
.public_reset_packet_
.get());
3106 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
3107 visitor_
.public_reset_packet_
->public_header
.connection_id
);
3108 EXPECT_TRUE(visitor_
.public_reset_packet_
->public_header
.reset_flag
);
3109 EXPECT_FALSE(visitor_
.public_reset_packet_
->public_header
.version_flag
);
3110 EXPECT_EQ(GG_UINT64_C(0xABCDEF0123456789),
3111 visitor_
.public_reset_packet_
->nonce_proof
);
3112 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
3113 visitor_
.public_reset_packet_
->rejected_sequence_number
);
3114 EXPECT_EQ("4.31.198.44",
3115 IPAddressToString(visitor_
.public_reset_packet_
->
3116 client_address
.address()));
3117 EXPECT_EQ(443, visitor_
.public_reset_packet_
->client_address
.port());
3119 // Now test framing boundaries
3120 for (size_t i
= 0; i
< arraysize(packet
); ++i
) {
3121 string expected_error
;
3122 DVLOG(1) << "iteration: " << i
;
3123 if (i
< kConnectionIdOffset
) {
3124 expected_error
= "Unable to read public flags.";
3125 CheckProcessingFails(packet
, i
, expected_error
,
3126 QUIC_INVALID_PACKET_HEADER
);
3127 } else if (i
< kPublicResetPacketMessageTagOffset
) {
3128 expected_error
= "Unable to read ConnectionId.";
3129 CheckProcessingFails(packet
, i
, expected_error
,
3130 QUIC_INVALID_PACKET_HEADER
);
3132 expected_error
= "Unable to read reset message.";
3133 CheckProcessingFails(packet
, i
, expected_error
,
3134 QUIC_INVALID_PUBLIC_RST_PACKET
);
3139 TEST_P(QuicFramerTest
, VersionNegotiationPacket
) {
3140 unsigned char packet
[] = {
3141 // public flags (version, 8 byte connection_id)
3144 0x10, 0x32, 0x54, 0x76,
3145 0x98, 0xBA, 0xDC, 0xFE,
3147 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
3151 QuicFramerPeer::SetIsServer(&framer_
, false);
3153 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
3154 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
3155 ASSERT_EQ(QUIC_NO_ERROR
, framer_
.error());
3156 ASSERT_TRUE(visitor_
.version_negotiation_packet_
.get());
3157 EXPECT_EQ(2u, visitor_
.version_negotiation_packet_
->versions
.size());
3158 EXPECT_EQ(GetParam(), visitor_
.version_negotiation_packet_
->versions
[0]);
3160 for (size_t i
= 0; i
<= kPublicFlagsSize
+ PACKET_8BYTE_CONNECTION_ID
; ++i
) {
3161 string expected_error
;
3162 QuicErrorCode error_code
= QUIC_INVALID_PACKET_HEADER
;
3163 if (i
< kConnectionIdOffset
) {
3164 expected_error
= "Unable to read public flags.";
3165 } else if (i
< kVersionOffset
) {
3166 expected_error
= "Unable to read ConnectionId.";
3168 expected_error
= "Unable to read supported version in negotiation.";
3169 error_code
= QUIC_INVALID_VERSION_NEGOTIATION_PACKET
;
3171 CheckProcessingFails(packet
, i
, expected_error
, error_code
);
3175 TEST_P(QuicFramerTest
, FecPacket
) {
3176 unsigned char packet
[] = {
3177 // public flags (8 byte connection_id)
3180 0x10, 0x32, 0x54, 0x76,
3181 0x98, 0xBA, 0xDC, 0xFE,
3182 // packet sequence number
3183 0xBC, 0x9A, 0x78, 0x56,
3185 // private flags (fec group & FEC)
3187 // first fec protected packet offset
3197 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
3198 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
3200 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
3201 ASSERT_TRUE(visitor_
.header_
.get());
3202 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
3204 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
3205 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
3206 ASSERT_EQ(1, visitor_
.fec_count_
);
3207 const QuicFecData
& fec_data
= *visitor_
.fec_data_
[0];
3208 EXPECT_EQ(GG_UINT64_C(0x0123456789ABB), fec_data
.fec_group
);
3209 EXPECT_EQ("abcdefghijklmnop", fec_data
.redundancy
);
3212 TEST_P(QuicFramerTest
, BuildPaddingFramePacket
) {
3213 QuicPacketHeader header
;
3214 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3215 header
.public_header
.reset_flag
= false;
3216 header
.public_header
.version_flag
= false;
3217 header
.fec_flag
= false;
3218 header
.entropy_flag
= false;
3219 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
3220 header
.fec_group
= 0;
3222 QuicPaddingFrame padding_frame
;
3225 frames
.push_back(QuicFrame(&padding_frame
));
3227 unsigned char packet
[kMaxPacketSize
] = {
3228 // public flags (8 byte connection_id)
3231 0x10, 0x32, 0x54, 0x76,
3232 0x98, 0xBA, 0xDC, 0xFE,
3233 // packet sequence number
3234 0xBC, 0x9A, 0x78, 0x56,
3239 // frame type (padding frame)
3241 0x00, 0x00, 0x00, 0x00
3244 uint64 header_size
=
3245 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
3246 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
3247 memset(packet
+ header_size
+ 1, 0x00, kMaxPacketSize
- header_size
- 1);
3249 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
3250 ASSERT_TRUE(data
!= NULL
);
3252 test::CompareCharArraysWithHexError("constructed packet",
3253 data
->data(), data
->length(),
3258 TEST_P(QuicFramerTest
, Build4ByteSequenceNumberPaddingFramePacket
) {
3259 QuicPacketHeader header
;
3260 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3261 header
.public_header
.reset_flag
= false;
3262 header
.public_header
.version_flag
= false;
3263 header
.fec_flag
= false;
3264 header
.entropy_flag
= false;
3265 header
.public_header
.sequence_number_length
= PACKET_4BYTE_SEQUENCE_NUMBER
;
3266 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
3267 header
.fec_group
= 0;
3269 QuicPaddingFrame padding_frame
;
3272 frames
.push_back(QuicFrame(&padding_frame
));
3274 unsigned char packet
[kMaxPacketSize
] = {
3275 // public flags (8 byte connection_id and 4 byte sequence number)
3278 0x10, 0x32, 0x54, 0x76,
3279 0x98, 0xBA, 0xDC, 0xFE,
3280 // packet sequence number
3281 0xBC, 0x9A, 0x78, 0x56,
3285 // frame type (padding frame)
3287 0x00, 0x00, 0x00, 0x00
3290 uint64 header_size
=
3291 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
3292 PACKET_4BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
3293 memset(packet
+ header_size
+ 1, 0x00, kMaxPacketSize
- header_size
- 1);
3295 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
3296 ASSERT_TRUE(data
!= NULL
);
3298 test::CompareCharArraysWithHexError("constructed packet",
3299 data
->data(), data
->length(),
3304 TEST_P(QuicFramerTest
, Build2ByteSequenceNumberPaddingFramePacket
) {
3305 QuicPacketHeader header
;
3306 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3307 header
.public_header
.reset_flag
= false;
3308 header
.public_header
.version_flag
= false;
3309 header
.fec_flag
= false;
3310 header
.entropy_flag
= false;
3311 header
.public_header
.sequence_number_length
= PACKET_2BYTE_SEQUENCE_NUMBER
;
3312 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
3313 header
.fec_group
= 0;
3315 QuicPaddingFrame padding_frame
;
3318 frames
.push_back(QuicFrame(&padding_frame
));
3320 unsigned char packet
[kMaxPacketSize
] = {
3321 // public flags (8 byte connection_id and 2 byte sequence number)
3324 0x10, 0x32, 0x54, 0x76,
3325 0x98, 0xBA, 0xDC, 0xFE,
3326 // packet sequence number
3331 // frame type (padding frame)
3333 0x00, 0x00, 0x00, 0x00
3336 uint64 header_size
=
3337 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
3338 PACKET_2BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
3339 memset(packet
+ header_size
+ 1, 0x00, kMaxPacketSize
- header_size
- 1);
3341 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
3342 ASSERT_TRUE(data
!= NULL
);
3344 test::CompareCharArraysWithHexError("constructed packet",
3345 data
->data(), data
->length(),
3350 TEST_P(QuicFramerTest
, Build1ByteSequenceNumberPaddingFramePacket
) {
3351 QuicPacketHeader header
;
3352 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3353 header
.public_header
.reset_flag
= false;
3354 header
.public_header
.version_flag
= false;
3355 header
.fec_flag
= false;
3356 header
.entropy_flag
= false;
3357 header
.public_header
.sequence_number_length
= PACKET_1BYTE_SEQUENCE_NUMBER
;
3358 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
3359 header
.fec_group
= 0;
3361 QuicPaddingFrame padding_frame
;
3364 frames
.push_back(QuicFrame(&padding_frame
));
3366 unsigned char packet
[kMaxPacketSize
] = {
3367 // public flags (8 byte connection_id and 1 byte sequence number)
3370 0x10, 0x32, 0x54, 0x76,
3371 0x98, 0xBA, 0xDC, 0xFE,
3372 // packet sequence number
3377 // frame type (padding frame)
3379 0x00, 0x00, 0x00, 0x00
3382 uint64 header_size
=
3383 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
3384 PACKET_1BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
3385 memset(packet
+ header_size
+ 1, 0x00, kMaxPacketSize
- header_size
- 1);
3387 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
3388 ASSERT_TRUE(data
!= NULL
);
3390 test::CompareCharArraysWithHexError("constructed packet",
3391 data
->data(), data
->length(),
3396 TEST_P(QuicFramerTest
, BuildStreamFramePacket
) {
3397 QuicPacketHeader header
;
3398 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3399 header
.public_header
.reset_flag
= false;
3400 header
.public_header
.version_flag
= false;
3401 header
.fec_flag
= false;
3402 header
.entropy_flag
= true;
3403 header
.packet_sequence_number
= GG_UINT64_C(0x77123456789ABC);
3404 header
.fec_group
= 0;
3406 QuicStreamFrame stream_frame
;
3407 stream_frame
.stream_id
= 0x01020304;
3408 stream_frame
.fin
= true;
3409 stream_frame
.offset
= GG_UINT64_C(0xBA98FEDC32107654);
3410 stream_frame
.data
= MakeIOVector("hello world!");
3413 frames
.push_back(QuicFrame(&stream_frame
));
3415 unsigned char packet
[] = {
3416 // public flags (8 byte connection_id)
3419 0x10, 0x32, 0x54, 0x76,
3420 0x98, 0xBA, 0xDC, 0xFE,
3421 // packet sequence number
3422 0xBC, 0x9A, 0x78, 0x56,
3424 // private flags (entropy)
3427 // frame type (stream frame with fin and no length)
3430 0x04, 0x03, 0x02, 0x01,
3432 0x54, 0x76, 0x10, 0x32,
3433 0xDC, 0xFE, 0x98, 0xBA,
3440 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
3441 ASSERT_TRUE(data
!= NULL
);
3443 test::CompareCharArraysWithHexError("constructed packet",
3444 data
->data(), data
->length(),
3445 AsChars(packet
), arraysize(packet
));
3448 TEST_P(QuicFramerTest
, BuildStreamFramePacketInFecGroup
) {
3449 QuicPacketHeader header
;
3450 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3451 header
.public_header
.reset_flag
= false;
3452 header
.public_header
.version_flag
= false;
3453 header
.fec_flag
= false;
3454 header
.entropy_flag
= true;
3455 header
.packet_sequence_number
= GG_UINT64_C(0x77123456789ABC);
3456 header
.is_in_fec_group
= IN_FEC_GROUP
;
3457 header
.fec_group
= GG_UINT64_C(0x77123456789ABC);
3459 QuicStreamFrame stream_frame
;
3460 stream_frame
.stream_id
= 0x01020304;
3461 stream_frame
.fin
= true;
3462 stream_frame
.offset
= GG_UINT64_C(0xBA98FEDC32107654);
3463 stream_frame
.data
= MakeIOVector("hello world!");
3466 frames
.push_back(QuicFrame(&stream_frame
));
3467 unsigned char packet
[] = {
3468 // public flags (8 byte connection_id)
3471 0x10, 0x32, 0x54, 0x76,
3472 0x98, 0xBA, 0xDC, 0xFE,
3473 // packet sequence number
3474 0xBC, 0x9A, 0x78, 0x56,
3476 // private flags (entropy, is_in_fec_group)
3480 // frame type (stream frame with fin and data length field)
3483 0x04, 0x03, 0x02, 0x01,
3485 0x54, 0x76, 0x10, 0x32,
3486 0xDC, 0xFE, 0x98, 0xBA,
3487 // data length (since packet is in an FEC group)
3495 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
3496 ASSERT_TRUE(data
!= NULL
);
3498 test::CompareCharArraysWithHexError("constructed packet",
3499 data
->data(), data
->length(),
3500 AsChars(packet
), arraysize(packet
));
3503 TEST_P(QuicFramerTest
, BuildStreamFramePacketWithVersionFlag
) {
3504 QuicPacketHeader header
;
3505 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3506 header
.public_header
.reset_flag
= false;
3507 header
.public_header
.version_flag
= true;
3508 header
.fec_flag
= false;
3509 header
.entropy_flag
= true;
3510 header
.packet_sequence_number
= GG_UINT64_C(0x77123456789ABC);
3511 header
.fec_group
= 0;
3513 QuicStreamFrame stream_frame
;
3514 stream_frame
.stream_id
= 0x01020304;
3515 stream_frame
.fin
= true;
3516 stream_frame
.offset
= GG_UINT64_C(0xBA98FEDC32107654);
3517 stream_frame
.data
= MakeIOVector("hello world!");
3520 frames
.push_back(QuicFrame(&stream_frame
));
3522 unsigned char packet
[] = {
3523 // public flags (version, 8 byte connection_id)
3526 0x10, 0x32, 0x54, 0x76,
3527 0x98, 0xBA, 0xDC, 0xFE,
3529 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
3530 // packet sequence number
3531 0xBC, 0x9A, 0x78, 0x56,
3533 // private flags (entropy)
3536 // frame type (stream frame with fin and no length)
3539 0x04, 0x03, 0x02, 0x01,
3541 0x54, 0x76, 0x10, 0x32,
3542 0xDC, 0xFE, 0x98, 0xBA,
3549 QuicFramerPeer::SetIsServer(&framer_
, false);
3550 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
3551 ASSERT_TRUE(data
!= NULL
);
3553 test::CompareCharArraysWithHexError("constructed packet",
3554 data
->data(), data
->length(),
3555 AsChars(packet
), arraysize(packet
));
3558 TEST_P(QuicFramerTest
, BuildVersionNegotiationPacket
) {
3559 QuicPacketPublicHeader header
;
3560 header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3561 header
.reset_flag
= false;
3562 header
.version_flag
= true;
3564 unsigned char packet
[] = {
3565 // public flags (version, 8 byte connection_id)
3568 0x10, 0x32, 0x54, 0x76,
3569 0x98, 0xBA, 0xDC, 0xFE,
3571 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
3574 QuicVersionVector versions
;
3575 versions
.push_back(GetParam());
3576 scoped_ptr
<QuicEncryptedPacket
> data(
3577 framer_
.BuildVersionNegotiationPacket(header
, versions
));
3579 test::CompareCharArraysWithHexError("constructed packet",
3580 data
->data(), data
->length(),
3581 AsChars(packet
), arraysize(packet
));
3584 TEST_P(QuicFramerTest
, BuildAckFramePacket
) {
3585 if (version_
<= QUIC_VERSION_15
) {
3588 QuicPacketHeader header
;
3589 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3590 header
.public_header
.reset_flag
= false;
3591 header
.public_header
.version_flag
= false;
3592 header
.fec_flag
= false;
3593 header
.entropy_flag
= true;
3594 header
.packet_sequence_number
= GG_UINT64_C(0x770123456789AA8);
3595 header
.fec_group
= 0;
3597 QuicAckFrame ack_frame
;
3598 ack_frame
.received_info
.entropy_hash
= 0x43;
3599 ack_frame
.received_info
.largest_observed
= GG_UINT64_C(0x770123456789ABF);
3600 ack_frame
.received_info
.delta_time_largest_observed
= QuicTime::Delta::Zero();
3601 ack_frame
.received_info
.missing_packets
.insert(
3602 GG_UINT64_C(0x770123456789ABE));
3605 frames
.push_back(QuicFrame(&ack_frame
));
3607 unsigned char packet
[] = {
3608 // public flags (8 byte connection_id)
3611 0x10, 0x32, 0x54, 0x76,
3612 0x98, 0xBA, 0xDC, 0xFE,
3613 // packet sequence number
3614 0xA8, 0x9A, 0x78, 0x56,
3616 // private flags (entropy)
3619 // frame type (ack frame)
3620 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
3622 // entropy hash of all received packets.
3624 // largest observed packet sequence number
3625 0xBF, 0x9A, 0x78, 0x56,
3629 // num missing packet ranges
3631 // missing packet delta
3633 // 0 more missing packets in range.
3635 // 0 revived packets.
3639 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
3640 ASSERT_TRUE(data
!= NULL
);
3642 test::CompareCharArraysWithHexError("constructed packet",
3643 data
->data(), data
->length(),
3644 AsChars(packet
), arraysize(packet
));
3647 TEST_P(QuicFramerTest
, BuildAckFramePacket15
) {
3648 if (version_
!= QUIC_VERSION_15
) {
3651 QuicPacketHeader header
;
3652 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3653 header
.public_header
.reset_flag
= false;
3654 header
.public_header
.version_flag
= false;
3655 header
.fec_flag
= false;
3656 header
.entropy_flag
= true;
3657 header
.packet_sequence_number
= GG_UINT64_C(0x770123456789AA8);
3658 header
.fec_group
= 0;
3660 QuicAckFrame ack_frame
;
3661 ack_frame
.received_info
.entropy_hash
= 0x43;
3662 ack_frame
.received_info
.largest_observed
= GG_UINT64_C(0x770123456789ABF);
3663 ack_frame
.received_info
.delta_time_largest_observed
= QuicTime::Delta::Zero();
3664 ack_frame
.received_info
.missing_packets
.insert(
3665 GG_UINT64_C(0x770123456789ABE));
3666 ack_frame
.sent_info
.entropy_hash
= 0x14;
3667 ack_frame
.sent_info
.least_unacked
= GG_UINT64_C(0x770123456789AA0);
3670 frames
.push_back(QuicFrame(&ack_frame
));
3672 unsigned char packet
[] = {
3673 // public flags (8 byte connection_id)
3676 0x10, 0x32, 0x54, 0x76,
3677 0x98, 0xBA, 0xDC, 0xFE,
3678 // packet sequence number
3679 0xA8, 0x9A, 0x78, 0x56,
3681 // private flags (entropy)
3684 // frame type (ack frame)
3685 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
3687 // entropy hash of sent packets till least awaiting - 1.
3689 // least packet sequence number awaiting an ack, delta from sequence number.
3690 0x08, 0x00, 0x00, 0x00,
3692 // entropy hash of all received packets.
3694 // largest observed packet sequence number
3695 0xBF, 0x9A, 0x78, 0x56,
3699 // num missing packet ranges
3701 // missing packet delta
3703 // 0 more missing packets in range.
3705 // 0 revived packets.
3709 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
3710 ASSERT_TRUE(data
!= NULL
);
3712 test::CompareCharArraysWithHexError("constructed packet",
3713 data
->data(), data
->length(),
3714 AsChars(packet
), arraysize(packet
));
3717 // TODO(jri): Add test for tuncated packets in which the original ack frame had
3718 // revived packets. (In both the large and small packet cases below).
3719 TEST_P(QuicFramerTest
, BuildTruncatedAckFrameLargePacket
) {
3720 if (version_
<= QUIC_VERSION_15
) {
3723 QuicPacketHeader header
;
3724 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3725 header
.public_header
.reset_flag
= false;
3726 header
.public_header
.version_flag
= false;
3727 header
.fec_flag
= false;
3728 header
.entropy_flag
= true;
3729 header
.packet_sequence_number
= GG_UINT64_C(0x770123456789AA8);
3730 header
.fec_group
= 0;
3732 QuicAckFrame ack_frame
;
3733 // This entropy hash is different from what shows up in the packet below,
3734 // since entropy is recomputed by the framer on ack truncation (by
3735 // TestEntropyCalculator for this test.)
3736 ack_frame
.received_info
.entropy_hash
= 0x43;
3737 ack_frame
.received_info
.largest_observed
= 2 * 300;
3738 ack_frame
.received_info
.delta_time_largest_observed
= QuicTime::Delta::Zero();
3739 for (size_t i
= 1; i
< 2 * 300; i
+= 2) {
3740 ack_frame
.received_info
.missing_packets
.insert(i
);
3744 frames
.push_back(QuicFrame(&ack_frame
));
3746 unsigned char packet
[] = {
3747 // public flags (8 byte connection_id)
3750 0x10, 0x32, 0x54, 0x76,
3751 0x98, 0xBA, 0xDC, 0xFE,
3752 // packet sequence number
3753 0xA8, 0x9A, 0x78, 0x56,
3755 // private flags (entropy)
3758 // frame type (ack frame)
3759 // (has nacks, is truncated, 2 byte largest observed, 1 byte delta)
3761 // entropy hash of all received packets, set to 1 by TestEntropyCalculator
3762 // since ack is truncated.
3764 // 2-byte largest observed packet sequence number.
3765 // Expected to be 510 (0x1FE), since only 255 nack ranges can fit.
3769 // num missing packet ranges (limited to 255 by size of this field).
3771 // {missing packet delta, further missing packets in range}
3772 // 6 nack ranges x 42 + 3 nack ranges
3773 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3774 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3775 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3776 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3777 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3778 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3779 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3780 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3781 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3782 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3784 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3785 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3786 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3787 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3788 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3789 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3790 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3791 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3792 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3793 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3795 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3796 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3797 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3798 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3799 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3800 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3801 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3802 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3803 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3804 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 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3815 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,
3821 // 0 revived packets.
3825 scoped_ptr
<QuicPacket
> data(
3826 framer_
.BuildDataPacket(header
, frames
, kMaxPacketSize
).packet
);
3827 ASSERT_TRUE(data
!= NULL
);
3829 test::CompareCharArraysWithHexError("constructed packet",
3830 data
->data(), data
->length(),
3831 AsChars(packet
), arraysize(packet
));
3835 TEST_P(QuicFramerTest
, BuildTruncatedAckFrameSmallPacket
) {
3836 if (version_
<= QUIC_VERSION_15
) {
3839 QuicPacketHeader header
;
3840 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3841 header
.public_header
.reset_flag
= false;
3842 header
.public_header
.version_flag
= false;
3843 header
.fec_flag
= false;
3844 header
.entropy_flag
= true;
3845 header
.packet_sequence_number
= GG_UINT64_C(0x770123456789AA8);
3846 header
.fec_group
= 0;
3848 QuicAckFrame ack_frame
;
3849 // This entropy hash is different from what shows up in the packet below,
3850 // since entropy is recomputed by the framer on ack truncation (by
3851 // TestEntropyCalculator for this test.)
3852 ack_frame
.received_info
.entropy_hash
= 0x43;
3853 ack_frame
.received_info
.largest_observed
= 2 * 300;
3854 ack_frame
.received_info
.delta_time_largest_observed
= QuicTime::Delta::Zero();
3855 for (size_t i
= 1; i
< 2 * 300; i
+= 2) {
3856 ack_frame
.received_info
.missing_packets
.insert(i
);
3860 frames
.push_back(QuicFrame(&ack_frame
));
3862 unsigned char packet
[] = {
3863 // public flags (8 byte connection_id)
3866 0x10, 0x32, 0x54, 0x76,
3867 0x98, 0xBA, 0xDC, 0xFE,
3868 // packet sequence number
3869 0xA8, 0x9A, 0x78, 0x56,
3871 // private flags (entropy)
3874 // frame type (ack frame)
3875 // (has nacks, is truncated, 2 byte largest observed, 1 byte delta)
3877 // entropy hash of all received packets, set to 1 by TestEntropyCalculator
3878 // since ack is truncated.
3880 // 2-byte largest observed packet sequence number.
3881 // Expected to be 12 (0x0C), since only 6 nack ranges can fit.
3885 // num missing packet ranges (limited to 6 by packet size of 37).
3887 // {missing packet delta, further missing packets in range}
3889 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3890 // 0 revived packets.
3894 scoped_ptr
<QuicPacket
> data(
3895 framer_
.BuildDataPacket(header
, frames
, 37u).packet
);
3896 ASSERT_TRUE(data
!= NULL
);
3897 // Expect 1 byte unused since at least 2 bytes are needed to fit more nacks.
3898 EXPECT_EQ(36u, data
->length());
3899 test::CompareCharArraysWithHexError("constructed packet",
3900 data
->data(), data
->length(),
3901 AsChars(packet
), arraysize(packet
));
3904 TEST_P(QuicFramerTest
, BuildCongestionFeedbackFramePacketTCP
) {
3905 QuicPacketHeader header
;
3906 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3907 header
.public_header
.reset_flag
= false;
3908 header
.public_header
.version_flag
= false;
3909 header
.fec_flag
= false;
3910 header
.entropy_flag
= false;
3911 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
3912 header
.fec_group
= 0;
3914 QuicCongestionFeedbackFrame congestion_feedback_frame
;
3915 congestion_feedback_frame
.type
= kTCP
;
3916 congestion_feedback_frame
.tcp
.receive_window
= 0x4030;
3919 frames
.push_back(QuicFrame(&congestion_feedback_frame
));
3921 unsigned char packet
[] = {
3922 // public flags (8 byte connection_id)
3925 0x10, 0x32, 0x54, 0x76,
3926 0x98, 0xBA, 0xDC, 0xFE,
3927 // packet sequence number
3928 0xBC, 0x9A, 0x78, 0x56,
3933 // frame type (congestion feedback frame)
3935 // congestion feedback type (TCP)
3937 // TCP receive window
3941 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
3942 ASSERT_TRUE(data
!= NULL
);
3944 test::CompareCharArraysWithHexError("constructed packet",
3945 data
->data(), data
->length(),
3946 AsChars(packet
), arraysize(packet
));
3949 TEST_P(QuicFramerTest
, BuildCongestionFeedbackFramePacketInterArrival
) {
3950 QuicPacketHeader header
;
3951 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3952 header
.public_header
.reset_flag
= false;
3953 header
.public_header
.version_flag
= false;
3954 header
.fec_flag
= false;
3955 header
.entropy_flag
= false;
3956 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
3957 header
.fec_group
= 0;
3959 QuicCongestionFeedbackFrame frame
;
3960 frame
.type
= kInterArrival
;
3961 frame
.inter_arrival
.received_packet_times
.insert(
3962 make_pair(GG_UINT64_C(0x0123456789ABA),
3963 start_
.Add(QuicTime::Delta::FromMicroseconds(
3964 GG_UINT64_C(0x07E1D2C3B4A59687)))));
3965 frame
.inter_arrival
.received_packet_times
.insert(
3966 make_pair(GG_UINT64_C(0x0123456789ABB),
3967 start_
.Add(QuicTime::Delta::FromMicroseconds(
3968 GG_UINT64_C(0x07E1D2C3B4A59688)))));
3969 frame
.inter_arrival
.received_packet_times
.insert(
3970 make_pair(GG_UINT64_C(0x0123456789ABD),
3971 start_
.Add(QuicTime::Delta::FromMicroseconds(
3972 GG_UINT64_C(0x07E1D2C3B4A59689)))));
3974 frames
.push_back(QuicFrame(&frame
));
3976 unsigned char packet
[] = {
3977 // public flags (8 byte connection_id)
3980 0x10, 0x32, 0x54, 0x76,
3981 0x98, 0xBA, 0xDC, 0xFE,
3982 // packet sequence number
3983 0xBC, 0x9A, 0x78, 0x56,
3988 // frame type (congestion feedback frame)
3990 // congestion feedback type (inter arrival)
3992 // num received packets
3994 // lowest sequence number
3995 0xBA, 0x9A, 0x78, 0x56,
3998 0x87, 0x96, 0xA5, 0xB4,
3999 0xC3, 0xD2, 0xE1, 0x07,
4003 0x01, 0x00, 0x00, 0x00,
4004 // sequence delta (skip one packet)
4007 0x02, 0x00, 0x00, 0x00,
4010 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
4011 ASSERT_TRUE(data
!= NULL
);
4013 test::CompareCharArraysWithHexError("constructed packet",
4014 data
->data(), data
->length(),
4015 AsChars(packet
), arraysize(packet
));
4018 TEST_P(QuicFramerTest
, BuildStopWaitingPacket
) {
4019 if (version_
<= QUIC_VERSION_15
) {
4022 QuicPacketHeader header
;
4023 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4024 header
.public_header
.reset_flag
= false;
4025 header
.public_header
.version_flag
= false;
4026 header
.fec_flag
= false;
4027 header
.entropy_flag
= true;
4028 header
.packet_sequence_number
= GG_UINT64_C(0x770123456789AA8);
4029 header
.fec_group
= 0;
4031 QuicStopWaitingFrame stop_waiting_frame
;
4032 stop_waiting_frame
.entropy_hash
= 0x14;
4033 stop_waiting_frame
.least_unacked
= GG_UINT64_C(0x770123456789AA0);
4036 frames
.push_back(QuicFrame(&stop_waiting_frame
));
4038 unsigned char packet
[] = {
4039 // public flags (8 byte connection_id)
4042 0x10, 0x32, 0x54, 0x76,
4043 0x98, 0xBA, 0xDC, 0xFE,
4044 // packet sequence number
4045 0xA8, 0x9A, 0x78, 0x56,
4047 // private flags (entropy)
4050 // frame type (stop waiting frame)
4052 // entropy hash of sent packets till least awaiting - 1.
4054 // least packet sequence number awaiting an ack, delta from sequence number.
4055 0x08, 0x00, 0x00, 0x00,
4059 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
4060 ASSERT_TRUE(data
!= NULL
);
4062 test::CompareCharArraysWithHexError("constructed packet",
4063 data
->data(), data
->length(),
4064 AsChars(packet
), arraysize(packet
));
4067 TEST_P(QuicFramerTest
, BuildCongestionFeedbackFramePacketFixRate
) {
4068 QuicPacketHeader header
;
4069 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4070 header
.public_header
.reset_flag
= false;
4071 header
.public_header
.version_flag
= false;
4072 header
.fec_flag
= false;
4073 header
.entropy_flag
= false;
4074 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
4075 header
.fec_group
= 0;
4077 QuicCongestionFeedbackFrame congestion_feedback_frame
;
4078 congestion_feedback_frame
.type
= kFixRate
;
4079 congestion_feedback_frame
.fix_rate
.bitrate
4080 = QuicBandwidth::FromBytesPerSecond(0x04030201);
4083 frames
.push_back(QuicFrame(&congestion_feedback_frame
));
4085 unsigned char packet
[] = {
4086 // public flags (8 byte connection_id)
4089 0x10, 0x32, 0x54, 0x76,
4090 0x98, 0xBA, 0xDC, 0xFE,
4091 // packet sequence number
4092 0xBC, 0x9A, 0x78, 0x56,
4097 // frame type (congestion feedback frame)
4099 // congestion feedback type (fix rate)
4101 // bitrate_in_bytes_per_second;
4102 0x01, 0x02, 0x03, 0x04,
4105 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
4106 ASSERT_TRUE(data
!= NULL
);
4108 test::CompareCharArraysWithHexError("constructed packet",
4109 data
->data(), data
->length(),
4110 AsChars(packet
), arraysize(packet
));
4113 TEST_P(QuicFramerTest
, BuildCongestionFeedbackFramePacketInvalidFeedback
) {
4114 QuicPacketHeader header
;
4115 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4116 header
.public_header
.reset_flag
= false;
4117 header
.public_header
.version_flag
= false;
4118 header
.fec_flag
= false;
4119 header
.entropy_flag
= false;
4120 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
4121 header
.fec_group
= 0;
4123 QuicCongestionFeedbackFrame congestion_feedback_frame
;
4124 congestion_feedback_frame
.type
=
4125 static_cast<CongestionFeedbackType
>(kFixRate
+ 1);
4128 frames
.push_back(QuicFrame(&congestion_feedback_frame
));
4130 scoped_ptr
<QuicPacket
> data
;
4132 data
.reset(BuildDataPacket(header
, frames
)),
4133 "AppendCongestionFeedbackFrame failed");
4134 ASSERT_TRUE(data
== NULL
);
4137 TEST_P(QuicFramerTest
, BuildRstFramePacketQuic
) {
4138 QuicPacketHeader header
;
4139 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4140 header
.public_header
.reset_flag
= false;
4141 header
.public_header
.version_flag
= false;
4142 header
.fec_flag
= false;
4143 header
.entropy_flag
= false;
4144 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
4145 header
.fec_group
= 0;
4147 QuicRstStreamFrame rst_frame
;
4148 rst_frame
.stream_id
= 0x01020304;
4149 rst_frame
.error_code
= static_cast<QuicRstStreamErrorCode
>(0x05060708);
4150 rst_frame
.error_details
= "because I can";
4151 rst_frame
.byte_offset
= 0x0807060504030201;
4153 unsigned char packet
[] = {
4154 // public flags (8 byte connection_id)
4157 0x10, 0x32, 0x54, 0x76,
4158 0x98, 0xBA, 0xDC, 0xFE,
4159 // packet sequence number
4160 0xBC, 0x9A, 0x78, 0x56,
4165 // frame type (rst stream frame)
4168 0x04, 0x03, 0x02, 0x01,
4170 0x01, 0x02, 0x03, 0x04,
4171 0x05, 0x06, 0x07, 0x08,
4173 0x08, 0x07, 0x06, 0x05,
4174 // error details length
4184 frames
.push_back(QuicFrame(&rst_frame
));
4186 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
4187 ASSERT_TRUE(data
!= NULL
);
4189 test::CompareCharArraysWithHexError("constructed packet",
4190 data
->data(), data
->length(),
4191 AsChars(packet
), arraysize(packet
));
4194 TEST_P(QuicFramerTest
, BuildCloseFramePacket
) {
4195 QuicPacketHeader header
;
4196 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4197 header
.public_header
.reset_flag
= false;
4198 header
.public_header
.version_flag
= false;
4199 header
.fec_flag
= false;
4200 header
.entropy_flag
= true;
4201 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
4202 header
.fec_group
= 0;
4204 QuicConnectionCloseFrame close_frame
;
4205 close_frame
.error_code
= static_cast<QuicErrorCode
>(0x05060708);
4206 close_frame
.error_details
= "because I can";
4209 frames
.push_back(QuicFrame(&close_frame
));
4211 unsigned char packet
[] = {
4212 // public flags (8 byte connection_id)
4215 0x10, 0x32, 0x54, 0x76,
4216 0x98, 0xBA, 0xDC, 0xFE,
4217 // packet sequence number
4218 0xBC, 0x9A, 0x78, 0x56,
4220 // private flags (entropy)
4223 // frame type (connection close frame)
4226 0x08, 0x07, 0x06, 0x05,
4227 // error details length
4236 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
4237 ASSERT_TRUE(data
!= NULL
);
4239 test::CompareCharArraysWithHexError("constructed packet",
4240 data
->data(), data
->length(),
4241 AsChars(packet
), arraysize(packet
));
4244 TEST_P(QuicFramerTest
, BuildGoAwayPacket
) {
4245 QuicPacketHeader header
;
4246 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4247 header
.public_header
.reset_flag
= false;
4248 header
.public_header
.version_flag
= false;
4249 header
.fec_flag
= false;
4250 header
.entropy_flag
= true;
4251 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
4252 header
.fec_group
= 0;
4254 QuicGoAwayFrame goaway_frame
;
4255 goaway_frame
.error_code
= static_cast<QuicErrorCode
>(0x05060708);
4256 goaway_frame
.last_good_stream_id
= 0x01020304;
4257 goaway_frame
.reason_phrase
= "because I can";
4260 frames
.push_back(QuicFrame(&goaway_frame
));
4262 unsigned char packet
[] = {
4263 // public flags (8 byte connection_id)
4266 0x10, 0x32, 0x54, 0x76,
4267 0x98, 0xBA, 0xDC, 0xFE,
4268 // packet sequence number
4269 0xBC, 0x9A, 0x78, 0x56,
4271 // private flags(entropy)
4274 // frame type (go away frame)
4277 0x08, 0x07, 0x06, 0x05,
4279 0x04, 0x03, 0x02, 0x01,
4280 // error details length
4289 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
4290 ASSERT_TRUE(data
!= NULL
);
4292 test::CompareCharArraysWithHexError("constructed packet",
4293 data
->data(), data
->length(),
4294 AsChars(packet
), arraysize(packet
));
4297 TEST_P(QuicFramerTest
, BuildWindowUpdatePacket
) {
4298 QuicPacketHeader header
;
4299 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4300 header
.public_header
.reset_flag
= false;
4301 header
.public_header
.version_flag
= false;
4302 header
.fec_flag
= false;
4303 header
.entropy_flag
= true;
4304 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
4305 header
.fec_group
= 0;
4307 QuicWindowUpdateFrame window_update_frame
;
4308 window_update_frame
.stream_id
= 0x01020304;
4309 window_update_frame
.byte_offset
= 0x1122334455667788;
4312 frames
.push_back(QuicFrame(&window_update_frame
));
4314 unsigned char packet
[] = {
4315 // public flags (8 byte connection_id)
4318 0x10, 0x32, 0x54, 0x76,
4319 0x98, 0xBA, 0xDC, 0xFE,
4320 // packet sequence number
4321 0xBC, 0x9A, 0x78, 0x56,
4323 // private flags(entropy)
4326 // frame type (window update frame)
4329 0x04, 0x03, 0x02, 0x01,
4331 0x88, 0x77, 0x66, 0x55,
4332 0x44, 0x33, 0x22, 0x11,
4335 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
4336 ASSERT_TRUE(data
!= NULL
);
4338 test::CompareCharArraysWithHexError("constructed packet", data
->data(),
4339 data
->length(), AsChars(packet
),
4343 TEST_P(QuicFramerTest
, BuildBlockedPacket
) {
4344 QuicPacketHeader header
;
4345 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4346 header
.public_header
.reset_flag
= false;
4347 header
.public_header
.version_flag
= false;
4348 header
.fec_flag
= false;
4349 header
.entropy_flag
= true;
4350 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
4351 header
.fec_group
= 0;
4353 QuicBlockedFrame blocked_frame
;
4354 blocked_frame
.stream_id
= 0x01020304;
4357 frames
.push_back(QuicFrame(&blocked_frame
));
4359 unsigned char packet
[] = {
4360 // public flags (8 byte connection_id)
4363 0x10, 0x32, 0x54, 0x76,
4364 0x98, 0xBA, 0xDC, 0xFE,
4365 // packet sequence number
4366 0xBC, 0x9A, 0x78, 0x56,
4368 // private flags(entropy)
4371 // frame type (blocked frame)
4374 0x04, 0x03, 0x02, 0x01,
4377 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
4378 ASSERT_TRUE(data
!= NULL
);
4380 test::CompareCharArraysWithHexError("constructed packet", data
->data(),
4381 data
->length(), AsChars(packet
),
4385 TEST_P(QuicFramerTest
, BuildPingPacket
) {
4386 QuicPacketHeader header
;
4387 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4388 header
.public_header
.reset_flag
= false;
4389 header
.public_header
.version_flag
= false;
4390 header
.fec_flag
= false;
4391 header
.entropy_flag
= true;
4392 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
4393 header
.fec_group
= 0;
4395 QuicPingFrame ping_frame
;
4398 frames
.push_back(QuicFrame(&ping_frame
));
4400 unsigned char packet
[] = {
4401 // public flags (8 byte connection_id)
4404 0x10, 0x32, 0x54, 0x76,
4405 0x98, 0xBA, 0xDC, 0xFE,
4406 // packet sequence number
4407 0xBC, 0x9A, 0x78, 0x56,
4409 // private flags(entropy)
4412 // frame type (ping frame)
4416 if (version_
>= QUIC_VERSION_18
) {
4417 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
4418 ASSERT_TRUE(data
!= NULL
);
4420 test::CompareCharArraysWithHexError("constructed packet", data
->data(),
4421 data
->length(), AsChars(packet
),
4424 string expected_error
=
4425 "Attempt to add a PingFrame in " + QuicVersionToString(version_
);
4426 EXPECT_DFATAL(BuildDataPacket(header
, frames
),
4432 TEST_P(QuicFramerTest
, BuildPublicResetPacket
) {
4433 QuicPublicResetPacket reset_packet
;
4434 reset_packet
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4435 reset_packet
.public_header
.reset_flag
= true;
4436 reset_packet
.public_header
.version_flag
= false;
4437 reset_packet
.rejected_sequence_number
= GG_UINT64_C(0x123456789ABC);
4438 reset_packet
.nonce_proof
= GG_UINT64_C(0xABCDEF0123456789);
4440 unsigned char packet
[] = {
4441 // public flags (public reset, 8 byte ConnectionId)
4444 0x10, 0x32, 0x54, 0x76,
4445 0x98, 0xBA, 0xDC, 0xFE,
4446 // message tag (kPRST)
4448 // num_entries (2) + padding
4449 0x02, 0x00, 0x00, 0x00,
4453 0x08, 0x00, 0x00, 0x00,
4457 0x10, 0x00, 0x00, 0x00,
4459 0x89, 0x67, 0x45, 0x23,
4460 0x01, 0xEF, 0xCD, 0xAB,
4461 // rejected sequence number
4462 0xBC, 0x9A, 0x78, 0x56,
4463 0x34, 0x12, 0x00, 0x00,
4466 scoped_ptr
<QuicEncryptedPacket
> data(
4467 framer_
.BuildPublicResetPacket(reset_packet
));
4468 ASSERT_TRUE(data
!= NULL
);
4470 test::CompareCharArraysWithHexError("constructed packet",
4471 data
->data(), data
->length(),
4472 AsChars(packet
), arraysize(packet
));
4475 TEST_P(QuicFramerTest
, BuildPublicResetPacketWithClientAddress
) {
4476 QuicPublicResetPacket reset_packet
;
4477 reset_packet
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4478 reset_packet
.public_header
.reset_flag
= true;
4479 reset_packet
.public_header
.version_flag
= false;
4480 reset_packet
.rejected_sequence_number
= GG_UINT64_C(0x123456789ABC);
4481 reset_packet
.nonce_proof
= GG_UINT64_C(0xABCDEF0123456789);
4482 reset_packet
.client_address
= IPEndPoint(Loopback4(), 0x1234);
4484 unsigned char packet
[] = {
4485 // public flags (public reset, 8 byte ConnectionId)
4488 0x10, 0x32, 0x54, 0x76,
4489 0x98, 0xBA, 0xDC, 0xFE,
4490 // message tag (kPRST)
4492 // num_entries (3) + padding
4493 0x03, 0x00, 0x00, 0x00,
4497 0x08, 0x00, 0x00, 0x00,
4501 0x10, 0x00, 0x00, 0x00,
4505 0x18, 0x00, 0x00, 0x00,
4507 0x89, 0x67, 0x45, 0x23,
4508 0x01, 0xEF, 0xCD, 0xAB,
4509 // rejected sequence number
4510 0xBC, 0x9A, 0x78, 0x56,
4511 0x34, 0x12, 0x00, 0x00,
4514 0x7F, 0x00, 0x00, 0x01,
4518 scoped_ptr
<QuicEncryptedPacket
> data(
4519 framer_
.BuildPublicResetPacket(reset_packet
));
4520 ASSERT_TRUE(data
!= NULL
);
4522 test::CompareCharArraysWithHexError("constructed packet",
4523 data
->data(), data
->length(),
4524 AsChars(packet
), arraysize(packet
));
4527 TEST_P(QuicFramerTest
, BuildFecPacket
) {
4528 QuicPacketHeader header
;
4529 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4530 header
.public_header
.reset_flag
= false;
4531 header
.public_header
.version_flag
= false;
4532 header
.fec_flag
= true;
4533 header
.entropy_flag
= true;
4534 header
.packet_sequence_number
= (GG_UINT64_C(0x123456789ABC));
4535 header
.is_in_fec_group
= IN_FEC_GROUP
;
4536 header
.fec_group
= GG_UINT64_C(0x123456789ABB);;
4538 QuicFecData fec_data
;
4539 fec_data
.fec_group
= 1;
4540 fec_data
.redundancy
= "abcdefghijklmnop";
4542 unsigned char packet
[] = {
4543 // public flags (8 byte connection_id)
4546 0x10, 0x32, 0x54, 0x76,
4547 0x98, 0xBA, 0xDC, 0xFE,
4548 // packet sequence number
4549 0xBC, 0x9A, 0x78, 0x56,
4551 // private flags (entropy & fec group & fec packet)
4553 // first fec protected packet offset
4563 scoped_ptr
<QuicPacket
> data(
4564 framer_
.BuildFecPacket(header
, fec_data
).packet
);
4565 ASSERT_TRUE(data
!= NULL
);
4567 test::CompareCharArraysWithHexError("constructed packet",
4568 data
->data(), data
->length(),
4569 AsChars(packet
), arraysize(packet
));
4572 TEST_P(QuicFramerTest
, EncryptPacket
) {
4573 QuicPacketSequenceNumber sequence_number
= GG_UINT64_C(0x123456789ABC);
4574 unsigned char packet
[] = {
4575 // public flags (8 byte connection_id)
4578 0x10, 0x32, 0x54, 0x76,
4579 0x98, 0xBA, 0xDC, 0xFE,
4580 // packet sequence number
4581 0xBC, 0x9A, 0x78, 0x56,
4583 // private flags (fec group & fec packet)
4585 // first fec protected packet offset
4595 scoped_ptr
<QuicPacket
> raw(
4596 QuicPacket::NewDataPacket(AsChars(packet
), arraysize(packet
), false,
4597 PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
4598 PACKET_6BYTE_SEQUENCE_NUMBER
));
4599 scoped_ptr
<QuicEncryptedPacket
> encrypted(
4600 framer_
.EncryptPacket(ENCRYPTION_NONE
, sequence_number
, *raw
));
4602 ASSERT_TRUE(encrypted
.get() != NULL
);
4603 EXPECT_TRUE(CheckEncryption(sequence_number
, raw
.get()));
4606 TEST_P(QuicFramerTest
, EncryptPacketWithVersionFlag
) {
4607 QuicPacketSequenceNumber sequence_number
= GG_UINT64_C(0x123456789ABC);
4608 unsigned char packet
[] = {
4609 // public flags (version, 8 byte connection_id)
4612 0x10, 0x32, 0x54, 0x76,
4613 0x98, 0xBA, 0xDC, 0xFE,
4616 // packet sequence number
4617 0xBC, 0x9A, 0x78, 0x56,
4619 // private flags (fec group & fec flags)
4621 // first fec protected packet offset
4631 scoped_ptr
<QuicPacket
> raw(
4632 QuicPacket::NewDataPacket(AsChars(packet
), arraysize(packet
), false,
4633 PACKET_8BYTE_CONNECTION_ID
, kIncludeVersion
,
4634 PACKET_6BYTE_SEQUENCE_NUMBER
));
4635 scoped_ptr
<QuicEncryptedPacket
> encrypted(
4636 framer_
.EncryptPacket(ENCRYPTION_NONE
, sequence_number
, *raw
));
4638 ASSERT_TRUE(encrypted
.get() != NULL
);
4639 EXPECT_TRUE(CheckEncryption(sequence_number
, raw
.get()));
4642 TEST_P(QuicFramerTest
, AckTruncationLargePacket
) {
4643 if (framer_
.version() <= QUIC_VERSION_15
) {
4646 QuicPacketHeader header
;
4647 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4648 header
.public_header
.reset_flag
= false;
4649 header
.public_header
.version_flag
= false;
4650 header
.fec_flag
= false;
4651 header
.entropy_flag
= false;
4652 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
4653 header
.fec_group
= 0;
4655 // Create a packet with just the ack.
4656 QuicAckFrame ack_frame
= MakeAckFrameWithNackRanges(300, 0u);
4658 frame
.type
= ACK_FRAME
;
4659 frame
.ack_frame
= &ack_frame
;
4661 frames
.push_back(frame
);
4663 // Build an ack packet with truncation due to limit in number of nack ranges.
4664 scoped_ptr
<QuicPacket
> raw_ack_packet(
4665 framer_
.BuildDataPacket(header
, frames
, kMaxPacketSize
).packet
);
4666 ASSERT_TRUE(raw_ack_packet
!= NULL
);
4667 scoped_ptr
<QuicEncryptedPacket
> ack_packet(
4668 framer_
.EncryptPacket(ENCRYPTION_NONE
, header
.packet_sequence_number
,
4670 // Now make sure we can turn our ack packet back into an ack frame.
4671 ASSERT_TRUE(framer_
.ProcessPacket(*ack_packet
));
4672 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
4673 QuicAckFrame
& processed_ack_frame
= *visitor_
.ack_frames_
[0];
4674 EXPECT_TRUE(processed_ack_frame
.received_info
.is_truncated
);
4675 EXPECT_EQ(510u, processed_ack_frame
.received_info
.largest_observed
);
4676 ASSERT_EQ(255u, processed_ack_frame
.received_info
.missing_packets
.size());
4677 SequenceNumberSet::const_iterator missing_iter
=
4678 processed_ack_frame
.received_info
.missing_packets
.begin();
4679 EXPECT_EQ(1u, *missing_iter
);
4680 SequenceNumberSet::const_reverse_iterator last_missing_iter
=
4681 processed_ack_frame
.received_info
.missing_packets
.rbegin();
4682 EXPECT_EQ(509u, *last_missing_iter
);
4685 TEST_P(QuicFramerTest
, AckTruncationSmallPacket
) {
4686 if (framer_
.version() <= QUIC_VERSION_15
) {
4689 QuicPacketHeader header
;
4690 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4691 header
.public_header
.reset_flag
= false;
4692 header
.public_header
.version_flag
= false;
4693 header
.fec_flag
= false;
4694 header
.entropy_flag
= false;
4695 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
4696 header
.fec_group
= 0;
4698 // Create a packet with just the ack.
4699 QuicAckFrame ack_frame
= MakeAckFrameWithNackRanges(300, 0u);
4701 frame
.type
= ACK_FRAME
;
4702 frame
.ack_frame
= &ack_frame
;
4704 frames
.push_back(frame
);
4706 // Build an ack packet with truncation due to limit in number of nack ranges.
4707 scoped_ptr
<QuicPacket
> raw_ack_packet(
4708 framer_
.BuildDataPacket(header
, frames
, 500).packet
);
4709 ASSERT_TRUE(raw_ack_packet
!= NULL
);
4710 scoped_ptr
<QuicEncryptedPacket
> ack_packet(
4711 framer_
.EncryptPacket(ENCRYPTION_NONE
, header
.packet_sequence_number
,
4713 // Now make sure we can turn our ack packet back into an ack frame.
4714 ASSERT_TRUE(framer_
.ProcessPacket(*ack_packet
));
4715 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
4716 QuicAckFrame
& processed_ack_frame
= *visitor_
.ack_frames_
[0];
4717 EXPECT_TRUE(processed_ack_frame
.received_info
.is_truncated
);
4718 EXPECT_EQ(476u, processed_ack_frame
.received_info
.largest_observed
);
4719 ASSERT_EQ(238u, processed_ack_frame
.received_info
.missing_packets
.size());
4720 SequenceNumberSet::const_iterator missing_iter
=
4721 processed_ack_frame
.received_info
.missing_packets
.begin();
4722 EXPECT_EQ(1u, *missing_iter
);
4723 SequenceNumberSet::const_reverse_iterator last_missing_iter
=
4724 processed_ack_frame
.received_info
.missing_packets
.rbegin();
4725 EXPECT_EQ(475u, *last_missing_iter
);
4728 TEST_P(QuicFramerTest
, Truncation15
) {
4729 if (framer_
.version() > QUIC_VERSION_15
) {
4732 QuicPacketHeader header
;
4733 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4734 header
.public_header
.reset_flag
= false;
4735 header
.public_header
.version_flag
= false;
4736 header
.fec_flag
= false;
4737 header
.entropy_flag
= false;
4738 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
4739 header
.fec_group
= 0;
4741 QuicAckFrame ack_frame
;
4742 ack_frame
.received_info
.largest_observed
= 601;
4743 ack_frame
.sent_info
.least_unacked
= header
.packet_sequence_number
- 1;
4744 for (uint64 i
= 1; i
< ack_frame
.received_info
.largest_observed
; i
+= 2) {
4745 ack_frame
.received_info
.missing_packets
.insert(i
);
4748 // Create a packet with just the ack.
4750 frame
.type
= ACK_FRAME
;
4751 frame
.ack_frame
= &ack_frame
;
4753 frames
.push_back(frame
);
4755 scoped_ptr
<QuicPacket
> raw_ack_packet(BuildDataPacket(header
, frames
));
4756 ASSERT_TRUE(raw_ack_packet
!= NULL
);
4758 scoped_ptr
<QuicEncryptedPacket
> ack_packet(
4759 framer_
.EncryptPacket(ENCRYPTION_NONE
, header
.packet_sequence_number
,
4762 // Now make sure we can turn our ack packet back into an ack frame.
4763 ASSERT_TRUE(framer_
.ProcessPacket(*ack_packet
));
4764 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
4765 const QuicAckFrame
& processed_ack_frame
= *visitor_
.ack_frames_
[0];
4766 EXPECT_EQ(header
.packet_sequence_number
- 1,
4767 processed_ack_frame
.sent_info
.least_unacked
);
4768 EXPECT_TRUE(processed_ack_frame
.received_info
.is_truncated
);
4769 EXPECT_EQ(510u, processed_ack_frame
.received_info
.largest_observed
);
4770 ASSERT_EQ(255u, processed_ack_frame
.received_info
.missing_packets
.size());
4771 SequenceNumberSet::const_iterator missing_iter
=
4772 processed_ack_frame
.received_info
.missing_packets
.begin();
4773 EXPECT_EQ(1u, *missing_iter
);
4774 SequenceNumberSet::const_reverse_iterator last_missing_iter
=
4775 processed_ack_frame
.received_info
.missing_packets
.rbegin();
4776 EXPECT_EQ(509u, *last_missing_iter
);
4779 TEST_P(QuicFramerTest
, CleanTruncation
) {
4780 QuicPacketHeader header
;
4781 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4782 header
.public_header
.reset_flag
= false;
4783 header
.public_header
.version_flag
= false;
4784 header
.fec_flag
= false;
4785 header
.entropy_flag
= true;
4786 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
4787 header
.fec_group
= 0;
4789 QuicAckFrame ack_frame
;
4790 ack_frame
.received_info
.largest_observed
= 201;
4791 ack_frame
.sent_info
.least_unacked
= header
.packet_sequence_number
- 2;
4792 for (uint64 i
= 1; i
< ack_frame
.received_info
.largest_observed
; ++i
) {
4793 ack_frame
.received_info
.missing_packets
.insert(i
);
4796 // Create a packet with just the ack.
4798 frame
.type
= ACK_FRAME
;
4799 frame
.ack_frame
= &ack_frame
;
4801 frames
.push_back(frame
);
4803 scoped_ptr
<QuicPacket
> raw_ack_packet(BuildDataPacket(header
, frames
));
4804 ASSERT_TRUE(raw_ack_packet
!= NULL
);
4806 scoped_ptr
<QuicEncryptedPacket
> ack_packet(
4807 framer_
.EncryptPacket(ENCRYPTION_NONE
, header
.packet_sequence_number
,
4810 // Now make sure we can turn our ack packet back into an ack frame.
4811 ASSERT_TRUE(framer_
.ProcessPacket(*ack_packet
));
4813 // Test for clean truncation of the ack by comparing the length of the
4814 // original packets to the re-serialized packets.
4816 frame
.type
= ACK_FRAME
;
4817 frame
.ack_frame
= visitor_
.ack_frames_
[0];
4818 frames
.push_back(frame
);
4820 size_t original_raw_length
= raw_ack_packet
->length();
4821 raw_ack_packet
.reset(BuildDataPacket(header
, frames
));
4822 ASSERT_TRUE(raw_ack_packet
!= NULL
);
4823 EXPECT_EQ(original_raw_length
, raw_ack_packet
->length());
4824 ASSERT_TRUE(raw_ack_packet
!= NULL
);
4827 TEST_P(QuicFramerTest
, EntropyFlagTest
) {
4828 unsigned char packet
[] = {
4829 // public flags (8 byte connection_id)
4832 0x10, 0x32, 0x54, 0x76,
4833 0x98, 0xBA, 0xDC, 0xFE,
4834 // packet sequence number
4835 0xBC, 0x9A, 0x78, 0x56,
4837 // private flags (Entropy)
4840 // frame type (stream frame with fin and no length)
4843 0x04, 0x03, 0x02, 0x01,
4845 0x54, 0x76, 0x10, 0x32,
4846 0xDC, 0xFE, 0x98, 0xBA,
4853 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
4854 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
4855 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
4856 ASSERT_TRUE(visitor_
.header_
.get());
4857 EXPECT_TRUE(visitor_
.header_
->entropy_flag
);
4858 EXPECT_EQ(1 << 4, visitor_
.header_
->entropy_hash
);
4859 EXPECT_FALSE(visitor_
.header_
->fec_flag
);
4862 TEST_P(QuicFramerTest
, FecEntropyTest
) {
4863 unsigned char packet
[] = {
4864 // public flags (8 byte connection_id)
4867 0x10, 0x32, 0x54, 0x76,
4868 0x98, 0xBA, 0xDC, 0xFE,
4869 // packet sequence number
4870 0xBC, 0x9A, 0x78, 0x56,
4872 // private flags (Entropy & fec group & FEC)
4874 // first fec protected packet offset
4877 // frame type (stream frame with fin and no length)
4880 0x04, 0x03, 0x02, 0x01,
4882 0x54, 0x76, 0x10, 0x32,
4883 0xDC, 0xFE, 0x98, 0xBA,
4890 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
4891 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
4892 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
4893 ASSERT_TRUE(visitor_
.header_
.get());
4894 EXPECT_TRUE(visitor_
.header_
->fec_flag
);
4895 EXPECT_TRUE(visitor_
.header_
->entropy_flag
);
4896 EXPECT_EQ(1 << 4, visitor_
.header_
->entropy_hash
);
4899 TEST_P(QuicFramerTest
, StopPacketProcessing
) {
4900 unsigned char packet
[] = {
4901 // public flags (8 byte connection_id)
4904 0x10, 0x32, 0x54, 0x76,
4905 0x98, 0xBA, 0xDC, 0xFE,
4906 // packet sequence number
4907 0xBC, 0x9A, 0x78, 0x56,
4912 // frame type (stream frame with fin)
4915 0x04, 0x03, 0x02, 0x01,
4917 0x54, 0x76, 0x10, 0x32,
4918 0xDC, 0xFE, 0x98, 0xBA,
4926 // frame type (ack frame)
4928 // entropy hash of sent packets till least awaiting - 1.
4930 // least packet sequence number awaiting an ack
4931 0xA0, 0x9A, 0x78, 0x56,
4933 // entropy hash of all received packets.
4935 // largest observed packet sequence number
4936 0xBF, 0x9A, 0x78, 0x56,
4938 // num missing packets
4941 0xBE, 0x9A, 0x78, 0x56,
4945 MockFramerVisitor visitor
;
4946 framer_
.set_visitor(&visitor
);
4947 EXPECT_CALL(visitor
, OnPacket());
4948 EXPECT_CALL(visitor
, OnPacketHeader(_
));
4949 EXPECT_CALL(visitor
, OnStreamFrame(_
)).WillOnce(Return(false));
4950 EXPECT_CALL(visitor
, OnAckFrame(_
)).Times(0);
4951 EXPECT_CALL(visitor
, OnPacketComplete());
4952 EXPECT_CALL(visitor
, OnUnauthenticatedPublicHeader(_
)).WillOnce(Return(true));
4954 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
4955 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
4956 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());