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() {
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
; i
< GetMinStreamFrameSize(); ++i
) {
465 string expected_error
;
466 if (i
< kQuicFrameTypeSize
+ stream_id_size
) {
467 expected_error
= "Unable to read stream_id.";
468 } else if (i
< kQuicFrameTypeSize
+ stream_id_size
+
469 kQuicMaxStreamOffsetSize
) {
470 expected_error
= "Unable to read offset.";
472 expected_error
= "Unable to read frame data.";
474 CheckProcessingFails(
476 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, include_version
,
477 PACKET_6BYTE_SEQUENCE_NUMBER
,
479 expected_error
, QUIC_INVALID_STREAM_DATA
);
483 void CheckCalculatePacketSequenceNumber(
484 QuicPacketSequenceNumber expected_sequence_number
,
485 QuicPacketSequenceNumber last_sequence_number
) {
486 QuicPacketSequenceNumber wire_sequence_number
=
487 expected_sequence_number
& kMask
;
488 QuicFramerPeer::SetLastSequenceNumber(&framer_
, last_sequence_number
);
489 EXPECT_EQ(expected_sequence_number
,
490 QuicFramerPeer::CalculatePacketSequenceNumberFromWire(
491 &framer_
, PACKET_6BYTE_SEQUENCE_NUMBER
, wire_sequence_number
))
492 << "last_sequence_number: " << last_sequence_number
493 << " wire_sequence_number: " << wire_sequence_number
;
496 QuicPacket
* BuildDataPacket(const QuicPacketHeader
& header
,
497 const QuicFrames
& frames
) {
498 return BuildUnsizedDataPacket(&framer_
, header
, frames
).packet
;
501 test::TestEncrypter
* encrypter_
;
502 test::TestDecrypter
* decrypter_
;
503 QuicVersion version_
;
506 test::TestQuicVisitor visitor_
;
507 test::TestEntropyCalculator entropy_calculator_
;
510 // Run all framer tests with all supported versions of QUIC.
511 INSTANTIATE_TEST_CASE_P(QuicFramerTests
,
513 ::testing::ValuesIn(kSupportedQuicVersions
));
515 TEST_P(QuicFramerTest
, CalculatePacketSequenceNumberFromWireNearEpochStart
) {
516 // A few quick manual sanity checks
517 CheckCalculatePacketSequenceNumber(GG_UINT64_C(1), GG_UINT64_C(0));
518 CheckCalculatePacketSequenceNumber(kEpoch
+ 1, kMask
);
519 CheckCalculatePacketSequenceNumber(kEpoch
, kMask
);
521 // Cases where the last number was close to the start of the range
522 for (uint64 last
= 0; last
< 10; last
++) {
523 // Small numbers should not wrap (even if they're out of order).
524 for (uint64 j
= 0; j
< 10; j
++) {
525 CheckCalculatePacketSequenceNumber(j
, last
);
528 // Large numbers should not wrap either (because we're near 0 already).
529 for (uint64 j
= 0; j
< 10; j
++) {
530 CheckCalculatePacketSequenceNumber(kEpoch
- 1 - j
, last
);
535 TEST_P(QuicFramerTest
, CalculatePacketSequenceNumberFromWireNearEpochEnd
) {
536 // Cases where the last number was close to the end of the range
537 for (uint64 i
= 0; i
< 10; i
++) {
538 QuicPacketSequenceNumber last
= kEpoch
- i
;
540 // Small numbers should wrap.
541 for (uint64 j
= 0; j
< 10; j
++) {
542 CheckCalculatePacketSequenceNumber(kEpoch
+ j
, last
);
545 // Large numbers should not (even if they're out of order).
546 for (uint64 j
= 0; j
< 10; j
++) {
547 CheckCalculatePacketSequenceNumber(kEpoch
- 1 - j
, last
);
552 // Next check where we're in a non-zero epoch to verify we handle
553 // reverse wrapping, too.
554 TEST_P(QuicFramerTest
, CalculatePacketSequenceNumberFromWireNearPrevEpoch
) {
555 const uint64 prev_epoch
= 1 * kEpoch
;
556 const uint64 cur_epoch
= 2 * kEpoch
;
557 // Cases where the last number was close to the start of the range
558 for (uint64 i
= 0; i
< 10; i
++) {
559 uint64 last
= cur_epoch
+ i
;
560 // Small number should not wrap (even if they're out of order).
561 for (uint64 j
= 0; j
< 10; j
++) {
562 CheckCalculatePacketSequenceNumber(cur_epoch
+ j
, last
);
565 // But large numbers should reverse wrap.
566 for (uint64 j
= 0; j
< 10; j
++) {
567 uint64 num
= kEpoch
- 1 - j
;
568 CheckCalculatePacketSequenceNumber(prev_epoch
+ num
, last
);
573 TEST_P(QuicFramerTest
, CalculatePacketSequenceNumberFromWireNearNextEpoch
) {
574 const uint64 cur_epoch
= 2 * kEpoch
;
575 const uint64 next_epoch
= 3 * kEpoch
;
576 // Cases where the last number was close to the end of the range
577 for (uint64 i
= 0; i
< 10; i
++) {
578 QuicPacketSequenceNumber last
= next_epoch
- 1 - i
;
580 // Small numbers should wrap.
581 for (uint64 j
= 0; j
< 10; j
++) {
582 CheckCalculatePacketSequenceNumber(next_epoch
+ j
, last
);
585 // but large numbers should not (even if they're out of order).
586 for (uint64 j
= 0; j
< 10; j
++) {
587 uint64 num
= kEpoch
- 1 - j
;
588 CheckCalculatePacketSequenceNumber(cur_epoch
+ num
, last
);
593 TEST_P(QuicFramerTest
, CalculatePacketSequenceNumberFromWireNearNextMax
) {
594 const uint64 max_number
= numeric_limits
<uint64
>::max();
595 const uint64 max_epoch
= max_number
& ~kMask
;
597 // Cases where the last number was close to the end of the range
598 for (uint64 i
= 0; i
< 10; i
++) {
599 // Subtract 1, because the expected next sequence number is 1 more than the
600 // last sequence number.
601 QuicPacketSequenceNumber last
= max_number
- i
- 1;
603 // Small numbers should not wrap, because they have nowhere to go.
604 for (uint64 j
= 0; j
< 10; j
++) {
605 CheckCalculatePacketSequenceNumber(max_epoch
+ j
, last
);
608 // Large numbers should not wrap either.
609 for (uint64 j
= 0; j
< 10; j
++) {
610 uint64 num
= kEpoch
- 1 - j
;
611 CheckCalculatePacketSequenceNumber(max_epoch
+ num
, last
);
616 TEST_P(QuicFramerTest
, EmptyPacket
) {
617 char packet
[] = { 0x00 };
618 QuicEncryptedPacket
encrypted(packet
, 0, false);
619 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
620 EXPECT_EQ(QUIC_INVALID_PACKET_HEADER
, framer_
.error());
623 TEST_P(QuicFramerTest
, LargePacket
) {
624 unsigned char packet
[kMaxPacketSize
+ 1] = {
625 // public flags (8 byte connection_id)
628 0x10, 0x32, 0x54, 0x76,
629 0x98, 0xBA, 0xDC, 0xFE,
630 // packet sequence number
631 0xBC, 0x9A, 0x78, 0x56,
637 memset(packet
+ GetPacketHeaderSize(
638 PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
639 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
), 0,
640 kMaxPacketSize
- GetPacketHeaderSize(
641 PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
642 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
) + 1);
644 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
645 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
647 ASSERT_TRUE(visitor_
.header_
.get());
648 // Make sure we've parsed the packet header, so we can send an error.
649 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
650 visitor_
.header_
->public_header
.connection_id
);
651 // Make sure the correct error is propagated.
652 EXPECT_EQ(QUIC_PACKET_TOO_LARGE
, framer_
.error());
655 TEST_P(QuicFramerTest
, PacketHeader
) {
656 unsigned char packet
[] = {
657 // public flags (8 byte connection_id)
660 0x10, 0x32, 0x54, 0x76,
661 0x98, 0xBA, 0xDC, 0xFE,
662 // packet sequence number
663 0xBC, 0x9A, 0x78, 0x56,
669 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
670 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
671 EXPECT_EQ(QUIC_MISSING_PAYLOAD
, framer_
.error());
672 ASSERT_TRUE(visitor_
.header_
.get());
673 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
674 visitor_
.header_
->public_header
.connection_id
);
675 EXPECT_FALSE(visitor_
.header_
->public_header
.reset_flag
);
676 EXPECT_FALSE(visitor_
.header_
->public_header
.version_flag
);
677 EXPECT_FALSE(visitor_
.header_
->fec_flag
);
678 EXPECT_FALSE(visitor_
.header_
->entropy_flag
);
679 EXPECT_EQ(0, visitor_
.header_
->entropy_hash
);
680 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
681 visitor_
.header_
->packet_sequence_number
);
682 EXPECT_EQ(NOT_IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
683 EXPECT_EQ(0x00u
, visitor_
.header_
->fec_group
);
685 // Now test framing boundaries.
687 i
< GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
688 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
690 string expected_error
;
691 if (i
< kConnectionIdOffset
) {
692 expected_error
= "Unable to read public flags.";
693 } else if (i
< GetSequenceNumberOffset(!kIncludeVersion
)) {
694 expected_error
= "Unable to read ConnectionId.";
695 } else if (i
< GetPrivateFlagsOffset(!kIncludeVersion
)) {
696 expected_error
= "Unable to read sequence number.";
697 } else if (i
< GetFecGroupOffset(!kIncludeVersion
)) {
698 expected_error
= "Unable to read private flags.";
700 expected_error
= "Unable to read first fec protected packet offset.";
702 CheckProcessingFails(packet
, i
, expected_error
, QUIC_INVALID_PACKET_HEADER
);
706 TEST_P(QuicFramerTest
, PacketHeaderWith4ByteConnectionId
) {
707 QuicFramerPeer::SetLastSerializedConnectionId(
708 &framer_
, GG_UINT64_C(0xFEDCBA9876543210));
710 unsigned char packet
[] = {
711 // public flags (4 byte connection_id)
714 0x10, 0x32, 0x54, 0x76,
715 // packet sequence number
716 0xBC, 0x9A, 0x78, 0x56,
722 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
723 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
724 EXPECT_EQ(QUIC_MISSING_PAYLOAD
, framer_
.error());
725 ASSERT_TRUE(visitor_
.header_
.get());
726 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
727 visitor_
.header_
->public_header
.connection_id
);
728 EXPECT_FALSE(visitor_
.header_
->public_header
.reset_flag
);
729 EXPECT_FALSE(visitor_
.header_
->public_header
.version_flag
);
730 EXPECT_FALSE(visitor_
.header_
->fec_flag
);
731 EXPECT_FALSE(visitor_
.header_
->entropy_flag
);
732 EXPECT_EQ(0, visitor_
.header_
->entropy_hash
);
733 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
734 visitor_
.header_
->packet_sequence_number
);
735 EXPECT_EQ(NOT_IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
736 EXPECT_EQ(0x00u
, visitor_
.header_
->fec_group
);
738 // Now test framing boundaries.
740 i
< GetPacketHeaderSize(PACKET_4BYTE_CONNECTION_ID
, !kIncludeVersion
,
741 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
743 string expected_error
;
744 if (i
< kConnectionIdOffset
) {
745 expected_error
= "Unable to read public flags.";
746 } else if (i
< GetSequenceNumberOffset(PACKET_4BYTE_CONNECTION_ID
,
748 expected_error
= "Unable to read ConnectionId.";
749 } else if (i
< GetPrivateFlagsOffset(PACKET_4BYTE_CONNECTION_ID
,
751 expected_error
= "Unable to read sequence number.";
752 } else if (i
< GetFecGroupOffset(PACKET_4BYTE_CONNECTION_ID
,
754 expected_error
= "Unable to read private flags.";
756 expected_error
= "Unable to read first fec protected packet offset.";
758 CheckProcessingFails(packet
, i
, expected_error
, QUIC_INVALID_PACKET_HEADER
);
762 TEST_P(QuicFramerTest
, PacketHeader1ByteConnectionId
) {
763 QuicFramerPeer::SetLastSerializedConnectionId(
764 &framer_
, GG_UINT64_C(0xFEDCBA9876543210));
766 unsigned char packet
[] = {
767 // public flags (1 byte connection_id)
771 // packet sequence number
772 0xBC, 0x9A, 0x78, 0x56,
778 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
779 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
780 EXPECT_EQ(QUIC_MISSING_PAYLOAD
, framer_
.error());
781 ASSERT_TRUE(visitor_
.header_
.get());
782 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
783 visitor_
.header_
->public_header
.connection_id
);
784 EXPECT_FALSE(visitor_
.header_
->public_header
.reset_flag
);
785 EXPECT_FALSE(visitor_
.header_
->public_header
.version_flag
);
786 EXPECT_FALSE(visitor_
.header_
->fec_flag
);
787 EXPECT_FALSE(visitor_
.header_
->entropy_flag
);
788 EXPECT_EQ(0, visitor_
.header_
->entropy_hash
);
789 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
790 visitor_
.header_
->packet_sequence_number
);
791 EXPECT_EQ(NOT_IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
792 EXPECT_EQ(0x00u
, visitor_
.header_
->fec_group
);
794 // Now test framing boundaries.
796 i
< GetPacketHeaderSize(PACKET_1BYTE_CONNECTION_ID
, !kIncludeVersion
,
797 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
799 string expected_error
;
800 if (i
< kConnectionIdOffset
) {
801 expected_error
= "Unable to read public flags.";
802 } else if (i
< GetSequenceNumberOffset(PACKET_1BYTE_CONNECTION_ID
,
804 expected_error
= "Unable to read ConnectionId.";
805 } else if (i
< GetPrivateFlagsOffset(PACKET_1BYTE_CONNECTION_ID
,
807 expected_error
= "Unable to read sequence number.";
808 } else if (i
< GetFecGroupOffset(PACKET_1BYTE_CONNECTION_ID
,
810 expected_error
= "Unable to read private flags.";
812 expected_error
= "Unable to read first fec protected packet offset.";
814 CheckProcessingFails(packet
, i
, expected_error
, QUIC_INVALID_PACKET_HEADER
);
818 TEST_P(QuicFramerTest
, PacketHeaderWith0ByteConnectionId
) {
819 QuicFramerPeer::SetLastSerializedConnectionId(
820 &framer_
, GG_UINT64_C(0xFEDCBA9876543210));
822 unsigned char packet
[] = {
823 // public flags (0 byte connection_id)
826 // packet sequence number
827 0xBC, 0x9A, 0x78, 0x56,
833 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
834 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
835 EXPECT_EQ(QUIC_MISSING_PAYLOAD
, framer_
.error());
836 ASSERT_TRUE(visitor_
.header_
.get());
837 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
838 visitor_
.header_
->public_header
.connection_id
);
839 EXPECT_FALSE(visitor_
.header_
->public_header
.reset_flag
);
840 EXPECT_FALSE(visitor_
.header_
->public_header
.version_flag
);
841 EXPECT_FALSE(visitor_
.header_
->fec_flag
);
842 EXPECT_FALSE(visitor_
.header_
->entropy_flag
);
843 EXPECT_EQ(0, visitor_
.header_
->entropy_hash
);
844 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
845 visitor_
.header_
->packet_sequence_number
);
846 EXPECT_EQ(NOT_IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
847 EXPECT_EQ(0x00u
, visitor_
.header_
->fec_group
);
849 // Now test framing boundaries.
851 i
< GetPacketHeaderSize(PACKET_0BYTE_CONNECTION_ID
, !kIncludeVersion
,
852 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
854 string expected_error
;
855 if (i
< kConnectionIdOffset
) {
856 expected_error
= "Unable to read public flags.";
857 } else if (i
< GetSequenceNumberOffset(PACKET_0BYTE_CONNECTION_ID
,
859 expected_error
= "Unable to read ConnectionId.";
860 } else if (i
< GetPrivateFlagsOffset(PACKET_0BYTE_CONNECTION_ID
,
862 expected_error
= "Unable to read sequence number.";
863 } else if (i
< GetFecGroupOffset(PACKET_0BYTE_CONNECTION_ID
,
865 expected_error
= "Unable to read private flags.";
867 expected_error
= "Unable to read first fec protected packet offset.";
869 CheckProcessingFails(packet
, i
, expected_error
, QUIC_INVALID_PACKET_HEADER
);
873 TEST_P(QuicFramerTest
, PacketHeaderWithVersionFlag
) {
874 unsigned char packet
[] = {
875 // public flags (version)
878 0x10, 0x32, 0x54, 0x76,
879 0x98, 0xBA, 0xDC, 0xFE,
881 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
882 // packet sequence number
883 0xBC, 0x9A, 0x78, 0x56,
889 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
890 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
891 EXPECT_EQ(QUIC_MISSING_PAYLOAD
, framer_
.error());
892 ASSERT_TRUE(visitor_
.header_
.get());
893 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
894 visitor_
.header_
->public_header
.connection_id
);
895 EXPECT_FALSE(visitor_
.header_
->public_header
.reset_flag
);
896 EXPECT_TRUE(visitor_
.header_
->public_header
.version_flag
);
897 EXPECT_EQ(GetParam(), visitor_
.header_
->public_header
.versions
[0]);
898 EXPECT_FALSE(visitor_
.header_
->fec_flag
);
899 EXPECT_FALSE(visitor_
.header_
->entropy_flag
);
900 EXPECT_EQ(0, visitor_
.header_
->entropy_hash
);
901 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
902 visitor_
.header_
->packet_sequence_number
);
903 EXPECT_EQ(NOT_IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
904 EXPECT_EQ(0x00u
, visitor_
.header_
->fec_group
);
906 // Now test framing boundaries.
908 i
< GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, kIncludeVersion
,
909 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
911 string expected_error
;
912 if (i
< kConnectionIdOffset
) {
913 expected_error
= "Unable to read public flags.";
914 } else if (i
< kVersionOffset
) {
915 expected_error
= "Unable to read ConnectionId.";
916 } else if (i
< GetSequenceNumberOffset(kIncludeVersion
)) {
917 expected_error
= "Unable to read protocol version.";
918 } else if (i
< GetPrivateFlagsOffset(kIncludeVersion
)) {
919 expected_error
= "Unable to read sequence number.";
920 } else if (i
< GetFecGroupOffset(kIncludeVersion
)) {
921 expected_error
= "Unable to read private flags.";
923 expected_error
= "Unable to read first fec protected packet offset.";
925 CheckProcessingFails(packet
, i
, expected_error
, QUIC_INVALID_PACKET_HEADER
);
929 TEST_P(QuicFramerTest
, PacketHeaderWith4ByteSequenceNumber
) {
930 QuicFramerPeer::SetLastSequenceNumber(&framer_
,
931 GG_UINT64_C(0x123456789ABA));
933 unsigned char packet
[] = {
934 // public flags (8 byte connection_id and 4 byte sequence number)
937 0x10, 0x32, 0x54, 0x76,
938 0x98, 0xBA, 0xDC, 0xFE,
939 // packet sequence number
940 0xBC, 0x9A, 0x78, 0x56,
945 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
946 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
947 EXPECT_EQ(QUIC_MISSING_PAYLOAD
, framer_
.error());
948 ASSERT_TRUE(visitor_
.header_
.get());
949 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
950 visitor_
.header_
->public_header
.connection_id
);
951 EXPECT_FALSE(visitor_
.header_
->public_header
.reset_flag
);
952 EXPECT_FALSE(visitor_
.header_
->public_header
.version_flag
);
953 EXPECT_FALSE(visitor_
.header_
->fec_flag
);
954 EXPECT_FALSE(visitor_
.header_
->entropy_flag
);
955 EXPECT_EQ(0, visitor_
.header_
->entropy_hash
);
956 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
957 visitor_
.header_
->packet_sequence_number
);
958 EXPECT_EQ(NOT_IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
959 EXPECT_EQ(0x00u
, visitor_
.header_
->fec_group
);
961 // Now test framing boundaries.
963 i
< GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
964 PACKET_4BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
966 string expected_error
;
967 if (i
< kConnectionIdOffset
) {
968 expected_error
= "Unable to read public flags.";
969 } else if (i
< GetSequenceNumberOffset(!kIncludeVersion
)) {
970 expected_error
= "Unable to read ConnectionId.";
971 } else if (i
< GetPrivateFlagsOffset(!kIncludeVersion
,
972 PACKET_4BYTE_SEQUENCE_NUMBER
)) {
973 expected_error
= "Unable to read sequence number.";
974 } else if (i
< GetFecGroupOffset(!kIncludeVersion
,
975 PACKET_4BYTE_SEQUENCE_NUMBER
)) {
976 expected_error
= "Unable to read private flags.";
978 expected_error
= "Unable to read first fec protected packet offset.";
980 CheckProcessingFails(packet
, i
, expected_error
, QUIC_INVALID_PACKET_HEADER
);
984 TEST_P(QuicFramerTest
, PacketHeaderWith2ByteSequenceNumber
) {
985 QuicFramerPeer::SetLastSequenceNumber(&framer_
,
986 GG_UINT64_C(0x123456789ABA));
988 unsigned char packet
[] = {
989 // public flags (8 byte connection_id and 2 byte sequence number)
992 0x10, 0x32, 0x54, 0x76,
993 0x98, 0xBA, 0xDC, 0xFE,
994 // packet sequence number
1000 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1001 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
1002 EXPECT_EQ(QUIC_MISSING_PAYLOAD
, framer_
.error());
1003 ASSERT_TRUE(visitor_
.header_
.get());
1004 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
1005 visitor_
.header_
->public_header
.connection_id
);
1006 EXPECT_FALSE(visitor_
.header_
->public_header
.reset_flag
);
1007 EXPECT_FALSE(visitor_
.header_
->public_header
.version_flag
);
1008 EXPECT_FALSE(visitor_
.header_
->fec_flag
);
1009 EXPECT_FALSE(visitor_
.header_
->entropy_flag
);
1010 EXPECT_EQ(0, visitor_
.header_
->entropy_hash
);
1011 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
1012 visitor_
.header_
->packet_sequence_number
);
1013 EXPECT_EQ(NOT_IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
1014 EXPECT_EQ(0x00u
, visitor_
.header_
->fec_group
);
1016 // Now test framing boundaries.
1018 i
< GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
1019 PACKET_2BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
1021 string expected_error
;
1022 if (i
< kConnectionIdOffset
) {
1023 expected_error
= "Unable to read public flags.";
1024 } else if (i
< GetSequenceNumberOffset(!kIncludeVersion
)) {
1025 expected_error
= "Unable to read ConnectionId.";
1026 } else if (i
< GetPrivateFlagsOffset(!kIncludeVersion
,
1027 PACKET_2BYTE_SEQUENCE_NUMBER
)) {
1028 expected_error
= "Unable to read sequence number.";
1029 } else if (i
< GetFecGroupOffset(!kIncludeVersion
,
1030 PACKET_2BYTE_SEQUENCE_NUMBER
)) {
1031 expected_error
= "Unable to read private flags.";
1033 expected_error
= "Unable to read first fec protected packet offset.";
1035 CheckProcessingFails(packet
, i
, expected_error
, QUIC_INVALID_PACKET_HEADER
);
1039 TEST_P(QuicFramerTest
, PacketHeaderWith1ByteSequenceNumber
) {
1040 QuicFramerPeer::SetLastSequenceNumber(&framer_
,
1041 GG_UINT64_C(0x123456789ABA));
1043 unsigned char packet
[] = {
1044 // public flags (8 byte connection_id and 1 byte sequence number)
1047 0x10, 0x32, 0x54, 0x76,
1048 0x98, 0xBA, 0xDC, 0xFE,
1049 // packet sequence number
1055 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1056 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
1057 EXPECT_EQ(QUIC_MISSING_PAYLOAD
, framer_
.error());
1058 ASSERT_TRUE(visitor_
.header_
.get());
1059 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
1060 visitor_
.header_
->public_header
.connection_id
);
1061 EXPECT_FALSE(visitor_
.header_
->public_header
.reset_flag
);
1062 EXPECT_FALSE(visitor_
.header_
->public_header
.version_flag
);
1063 EXPECT_FALSE(visitor_
.header_
->fec_flag
);
1064 EXPECT_FALSE(visitor_
.header_
->entropy_flag
);
1065 EXPECT_EQ(0, visitor_
.header_
->entropy_hash
);
1066 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
1067 visitor_
.header_
->packet_sequence_number
);
1068 EXPECT_EQ(NOT_IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
1069 EXPECT_EQ(0x00u
, visitor_
.header_
->fec_group
);
1071 // Now test framing boundaries.
1073 i
< GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
1074 PACKET_1BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
1076 string expected_error
;
1077 if (i
< kConnectionIdOffset
) {
1078 expected_error
= "Unable to read public flags.";
1079 } else if (i
< GetSequenceNumberOffset(!kIncludeVersion
)) {
1080 expected_error
= "Unable to read ConnectionId.";
1081 } else if (i
< GetPrivateFlagsOffset(!kIncludeVersion
,
1082 PACKET_1BYTE_SEQUENCE_NUMBER
)) {
1083 expected_error
= "Unable to read sequence number.";
1084 } else if (i
< GetFecGroupOffset(!kIncludeVersion
,
1085 PACKET_1BYTE_SEQUENCE_NUMBER
)) {
1086 expected_error
= "Unable to read private flags.";
1088 expected_error
= "Unable to read first fec protected packet offset.";
1090 CheckProcessingFails(packet
, i
, expected_error
, QUIC_INVALID_PACKET_HEADER
);
1094 TEST_P(QuicFramerTest
, InvalidPublicFlag
) {
1095 unsigned char packet
[] = {
1096 // public flags: all flags set but the public reset flag and version flag.
1099 0x10, 0x32, 0x54, 0x76,
1100 0x98, 0xBA, 0xDC, 0xFE,
1101 // packet sequence number
1102 0xBC, 0x9A, 0x78, 0x56,
1107 // frame type (padding)
1109 0x00, 0x00, 0x00, 0x00
1111 CheckProcessingFails(packet
,
1113 "Illegal public flags value.",
1114 QUIC_INVALID_PACKET_HEADER
);
1116 // Now turn off validation.
1117 framer_
.set_validate_flags(false);
1118 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1119 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1122 TEST_P(QuicFramerTest
, InvalidPublicFlagWithMatchingVersions
) {
1123 unsigned char packet
[] = {
1124 // public flags (8 byte connection_id and version flag and an unknown flag)
1127 0x10, 0x32, 0x54, 0x76,
1128 0x98, 0xBA, 0xDC, 0xFE,
1130 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
1131 // packet sequence number
1132 0xBC, 0x9A, 0x78, 0x56,
1137 // frame type (padding)
1139 0x00, 0x00, 0x00, 0x00
1141 CheckProcessingFails(packet
,
1143 "Illegal public flags value.",
1144 QUIC_INVALID_PACKET_HEADER
);
1147 TEST_P(QuicFramerTest
, LargePublicFlagWithMismatchedVersions
) {
1148 unsigned char packet
[] = {
1149 // public flags (8 byte connection_id, version flag and an unknown flag)
1152 0x10, 0x32, 0x54, 0x76,
1153 0x98, 0xBA, 0xDC, 0xFE,
1156 // packet sequence number
1157 0xBC, 0x9A, 0x78, 0x56,
1162 // frame type (padding frame)
1164 0x00, 0x00, 0x00, 0x00
1166 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1167 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1168 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1169 ASSERT_TRUE(visitor_
.header_
.get());
1170 EXPECT_EQ(0, visitor_
.frame_count_
);
1171 EXPECT_EQ(1, visitor_
.version_mismatch_
);
1174 TEST_P(QuicFramerTest
, InvalidPrivateFlag
) {
1175 unsigned char packet
[] = {
1176 // public flags (8 byte connection_id)
1179 0x10, 0x32, 0x54, 0x76,
1180 0x98, 0xBA, 0xDC, 0xFE,
1181 // packet sequence number
1182 0xBC, 0x9A, 0x78, 0x56,
1187 // frame type (padding)
1189 0x00, 0x00, 0x00, 0x00
1191 CheckProcessingFails(packet
,
1193 "Illegal private flags value.",
1194 QUIC_INVALID_PACKET_HEADER
);
1197 TEST_P(QuicFramerTest
, InvalidFECGroupOffset
) {
1198 unsigned char packet
[] = {
1199 // public flags (8 byte connection_id)
1202 0x10, 0x32, 0x54, 0x76,
1203 0x98, 0xBA, 0xDC, 0xFE,
1204 // packet sequence number
1205 0x01, 0x00, 0x00, 0x00,
1207 // private flags (fec group)
1209 // first fec protected packet offset
1212 CheckProcessingFails(packet
,
1214 "First fec protected packet offset must be less "
1215 "than the sequence number.",
1216 QUIC_INVALID_PACKET_HEADER
);
1219 TEST_P(QuicFramerTest
, PaddingFrame
) {
1220 unsigned char packet
[] = {
1221 // public flags (8 byte connection_id)
1224 0x10, 0x32, 0x54, 0x76,
1225 0x98, 0xBA, 0xDC, 0xFE,
1226 // packet sequence number
1227 0xBC, 0x9A, 0x78, 0x56,
1232 // frame type (padding frame)
1234 // Ignored data (which in this case is a stream frame)
1235 // frame type (stream frame with fin)
1238 0x04, 0x03, 0x02, 0x01,
1240 0x54, 0x76, 0x10, 0x32,
1241 0xDC, 0xFE, 0x98, 0xBA,
1250 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1251 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1252 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1253 ASSERT_TRUE(visitor_
.header_
.get());
1254 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1256 ASSERT_EQ(0u, visitor_
.stream_frames_
.size());
1257 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
1258 // A packet with no frames is not acceptable.
1259 CheckProcessingFails(
1261 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
1262 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
1263 "Packet has no frames.", QUIC_MISSING_PAYLOAD
);
1266 TEST_P(QuicFramerTest
, StreamFrame
) {
1267 unsigned char packet
[] = {
1268 // public flags (8 byte connection_id)
1271 0x10, 0x32, 0x54, 0x76,
1272 0x98, 0xBA, 0xDC, 0xFE,
1273 // packet sequence number
1274 0xBC, 0x9A, 0x78, 0x56,
1279 // frame type (stream frame with fin)
1282 0x04, 0x03, 0x02, 0x01,
1284 0x54, 0x76, 0x10, 0x32,
1285 0xDC, 0xFE, 0x98, 0xBA,
1294 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1295 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1297 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1298 ASSERT_TRUE(visitor_
.header_
.get());
1299 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1301 ASSERT_EQ(1u, visitor_
.stream_frames_
.size());
1302 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
1303 EXPECT_EQ(static_cast<uint64
>(0x01020304),
1304 visitor_
.stream_frames_
[0]->stream_id
);
1305 EXPECT_TRUE(visitor_
.stream_frames_
[0]->fin
);
1306 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1307 visitor_
.stream_frames_
[0]->offset
);
1308 CheckStreamFrameData("hello world!", visitor_
.stream_frames_
[0]);
1310 // Now test framing boundaries.
1311 CheckStreamFrameBoundaries(packet
, kQuicMaxStreamIdSize
, !kIncludeVersion
);
1314 TEST_P(QuicFramerTest
, StreamFrame3ByteStreamId
) {
1315 unsigned char packet
[] = {
1316 // public flags (8 byte connection_id)
1319 0x10, 0x32, 0x54, 0x76,
1320 0x98, 0xBA, 0xDC, 0xFE,
1321 // packet sequence number
1322 0xBC, 0x9A, 0x78, 0x56,
1327 // frame type (stream frame with fin)
1332 0x54, 0x76, 0x10, 0x32,
1333 0xDC, 0xFE, 0x98, 0xBA,
1342 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1343 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1345 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1346 ASSERT_TRUE(visitor_
.header_
.get());
1347 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1349 ASSERT_EQ(1u, visitor_
.stream_frames_
.size());
1350 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
1351 EXPECT_EQ(GG_UINT64_C(0x00020304),
1352 visitor_
.stream_frames_
[0]->stream_id
);
1353 EXPECT_TRUE(visitor_
.stream_frames_
[0]->fin
);
1354 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1355 visitor_
.stream_frames_
[0]->offset
);
1356 CheckStreamFrameData("hello world!", visitor_
.stream_frames_
[0]);
1358 // Now test framing boundaries.
1359 const size_t stream_id_size
= 3;
1360 CheckStreamFrameBoundaries(packet
, stream_id_size
, !kIncludeVersion
);
1363 TEST_P(QuicFramerTest
, StreamFrame2ByteStreamId
) {
1364 unsigned char packet
[] = {
1365 // public flags (8 byte connection_id)
1368 0x10, 0x32, 0x54, 0x76,
1369 0x98, 0xBA, 0xDC, 0xFE,
1370 // packet sequence number
1371 0xBC, 0x9A, 0x78, 0x56,
1376 // frame type (stream frame with fin)
1381 0x54, 0x76, 0x10, 0x32,
1382 0xDC, 0xFE, 0x98, 0xBA,
1391 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1392 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1394 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1395 ASSERT_TRUE(visitor_
.header_
.get());
1396 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1398 ASSERT_EQ(1u, visitor_
.stream_frames_
.size());
1399 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
1400 EXPECT_EQ(static_cast<uint64
>(0x00000304),
1401 visitor_
.stream_frames_
[0]->stream_id
);
1402 EXPECT_TRUE(visitor_
.stream_frames_
[0]->fin
);
1403 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1404 visitor_
.stream_frames_
[0]->offset
);
1405 CheckStreamFrameData("hello world!", visitor_
.stream_frames_
[0]);
1407 // Now test framing boundaries.
1408 const size_t stream_id_size
= 2;
1409 CheckStreamFrameBoundaries(packet
, stream_id_size
, !kIncludeVersion
);
1412 TEST_P(QuicFramerTest
, StreamFrame1ByteStreamId
) {
1413 unsigned char packet
[] = {
1414 // public flags (8 byte connection_id)
1417 0x10, 0x32, 0x54, 0x76,
1418 0x98, 0xBA, 0xDC, 0xFE,
1419 // packet sequence number
1420 0xBC, 0x9A, 0x78, 0x56,
1425 // frame type (stream frame with fin)
1430 0x54, 0x76, 0x10, 0x32,
1431 0xDC, 0xFE, 0x98, 0xBA,
1440 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1441 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1443 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1444 ASSERT_TRUE(visitor_
.header_
.get());
1445 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1447 ASSERT_EQ(1u, visitor_
.stream_frames_
.size());
1448 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
1449 EXPECT_EQ(static_cast<uint64
>(0x00000004),
1450 visitor_
.stream_frames_
[0]->stream_id
);
1451 EXPECT_TRUE(visitor_
.stream_frames_
[0]->fin
);
1452 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1453 visitor_
.stream_frames_
[0]->offset
);
1454 CheckStreamFrameData("hello world!", visitor_
.stream_frames_
[0]);
1456 // Now test framing boundaries.
1457 const size_t stream_id_size
= 1;
1458 CheckStreamFrameBoundaries(packet
, stream_id_size
, !kIncludeVersion
);
1461 TEST_P(QuicFramerTest
, StreamFrameWithVersion
) {
1462 unsigned char packet
[] = {
1463 // public flags (version, 8 byte connection_id)
1466 0x10, 0x32, 0x54, 0x76,
1467 0x98, 0xBA, 0xDC, 0xFE,
1469 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
1470 // packet sequence number
1471 0xBC, 0x9A, 0x78, 0x56,
1476 // frame type (stream frame with fin)
1479 0x04, 0x03, 0x02, 0x01,
1481 0x54, 0x76, 0x10, 0x32,
1482 0xDC, 0xFE, 0x98, 0xBA,
1491 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1492 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1494 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1495 ASSERT_TRUE(visitor_
.header_
.get());
1496 EXPECT_TRUE(visitor_
.header_
->public_header
.version_flag
);
1497 EXPECT_EQ(GetParam(), visitor_
.header_
->public_header
.versions
[0]);
1498 EXPECT_TRUE(CheckDecryption(encrypted
, kIncludeVersion
));
1500 ASSERT_EQ(1u, visitor_
.stream_frames_
.size());
1501 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
1502 EXPECT_EQ(static_cast<uint64
>(0x01020304),
1503 visitor_
.stream_frames_
[0]->stream_id
);
1504 EXPECT_TRUE(visitor_
.stream_frames_
[0]->fin
);
1505 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1506 visitor_
.stream_frames_
[0]->offset
);
1507 CheckStreamFrameData("hello world!", visitor_
.stream_frames_
[0]);
1509 // Now test framing boundaries.
1510 CheckStreamFrameBoundaries(packet
, kQuicMaxStreamIdSize
, kIncludeVersion
);
1513 TEST_P(QuicFramerTest
, RejectPacket
) {
1514 visitor_
.accept_packet_
= false;
1516 unsigned char packet
[] = {
1517 // public flags (8 byte connection_id)
1520 0x10, 0x32, 0x54, 0x76,
1521 0x98, 0xBA, 0xDC, 0xFE,
1522 // packet sequence number
1523 0xBC, 0x9A, 0x78, 0x56,
1528 // frame type (stream frame with fin)
1531 0x04, 0x03, 0x02, 0x01,
1533 0x54, 0x76, 0x10, 0x32,
1534 0xDC, 0xFE, 0x98, 0xBA,
1543 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1544 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1546 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1547 ASSERT_TRUE(visitor_
.header_
.get());
1548 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1550 ASSERT_EQ(0u, visitor_
.stream_frames_
.size());
1551 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
1554 TEST_P(QuicFramerTest
, RejectPublicHeader
) {
1555 visitor_
.accept_public_header_
= false;
1557 unsigned char packet
[] = {
1558 // public flags (8 byte connection_id)
1561 0x10, 0x32, 0x54, 0x76,
1562 0x98, 0xBA, 0xDC, 0xFE,
1565 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1566 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1568 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1569 ASSERT_TRUE(visitor_
.public_header_
.get());
1570 ASSERT_FALSE(visitor_
.header_
.get());
1573 TEST_P(QuicFramerTest
, RevivedStreamFrame
) {
1574 unsigned char payload
[] = {
1575 // frame type (stream frame with fin)
1578 0x04, 0x03, 0x02, 0x01,
1580 0x54, 0x76, 0x10, 0x32,
1581 0xDC, 0xFE, 0x98, 0xBA,
1590 QuicPacketHeader header
;
1591 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
1592 header
.public_header
.reset_flag
= false;
1593 header
.public_header
.version_flag
= false;
1594 header
.fec_flag
= true;
1595 header
.entropy_flag
= true;
1596 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
1597 header
.fec_group
= 0;
1599 // Do not encrypt the payload because the revived payload is post-encryption.
1600 EXPECT_TRUE(framer_
.ProcessRevivedPacket(&header
,
1601 StringPiece(AsChars(payload
),
1602 arraysize(payload
))));
1604 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1605 ASSERT_EQ(1, visitor_
.revived_packets_
);
1606 ASSERT_TRUE(visitor_
.header_
.get());
1607 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
1608 visitor_
.header_
->public_header
.connection_id
);
1609 EXPECT_FALSE(visitor_
.header_
->public_header
.reset_flag
);
1610 EXPECT_FALSE(visitor_
.header_
->public_header
.version_flag
);
1611 EXPECT_TRUE(visitor_
.header_
->fec_flag
);
1612 EXPECT_TRUE(visitor_
.header_
->entropy_flag
);
1613 EXPECT_EQ(1 << (header
.packet_sequence_number
% 8),
1614 visitor_
.header_
->entropy_hash
);
1615 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
1616 visitor_
.header_
->packet_sequence_number
);
1617 EXPECT_EQ(NOT_IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
1618 EXPECT_EQ(0x00u
, visitor_
.header_
->fec_group
);
1620 ASSERT_EQ(1u, visitor_
.stream_frames_
.size());
1621 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
1622 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_
.stream_frames_
[0]->stream_id
);
1623 EXPECT_TRUE(visitor_
.stream_frames_
[0]->fin
);
1624 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1625 visitor_
.stream_frames_
[0]->offset
);
1626 CheckStreamFrameData("hello world!", visitor_
.stream_frames_
[0]);
1629 TEST_P(QuicFramerTest
, StreamFrameInFecGroup
) {
1630 unsigned char packet
[] = {
1631 // public flags (8 byte connection_id)
1634 0x10, 0x32, 0x54, 0x76,
1635 0x98, 0xBA, 0xDC, 0xFE,
1636 // packet sequence number
1637 0xBC, 0x9A, 0x78, 0x56,
1639 // private flags (fec group)
1641 // first fec protected packet offset
1644 // frame type (stream frame with fin)
1647 0x04, 0x03, 0x02, 0x01,
1649 0x54, 0x76, 0x10, 0x32,
1650 0xDC, 0xFE, 0x98, 0xBA,
1659 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1660 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1662 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1663 ASSERT_TRUE(visitor_
.header_
.get());
1664 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1665 EXPECT_EQ(IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
1666 EXPECT_EQ(GG_UINT64_C(0x341256789ABA),
1667 visitor_
.header_
->fec_group
);
1668 const size_t fec_offset
=
1669 GetStartOfFecProtectedData(PACKET_8BYTE_CONNECTION_ID
,
1671 PACKET_6BYTE_SEQUENCE_NUMBER
);
1673 string(AsChars(packet
) + fec_offset
, arraysize(packet
) - fec_offset
),
1674 visitor_
.fec_protected_payload_
);
1676 ASSERT_EQ(1u, visitor_
.stream_frames_
.size());
1677 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
1678 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_
.stream_frames_
[0]->stream_id
);
1679 EXPECT_TRUE(visitor_
.stream_frames_
[0]->fin
);
1680 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1681 visitor_
.stream_frames_
[0]->offset
);
1682 CheckStreamFrameData("hello world!", visitor_
.stream_frames_
[0]);
1685 TEST_P(QuicFramerTest
, AckFramev22
) {
1686 if (version_
> QUIC_VERSION_22
) {
1689 unsigned char packet
[] = {
1690 // public flags (8 byte connection_id)
1693 0x10, 0x32, 0x54, 0x76,
1694 0x98, 0xBA, 0xDC, 0xFE,
1695 // packet sequence number
1696 0xA8, 0x9A, 0x78, 0x56,
1698 // private flags (entropy)
1701 // frame type (ack frame)
1702 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
1704 // entropy hash of all received packets.
1706 // largest observed packet sequence number
1707 0xBF, 0x9A, 0x78, 0x56,
1711 // num missing packets
1713 // missing packet delta
1715 // 0 more missing packets in range.
1717 // Number of revived packets.
1721 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1722 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1724 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1725 ASSERT_TRUE(visitor_
.header_
.get());
1726 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1728 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
1729 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
1730 const QuicAckFrame
& frame
= *visitor_
.ack_frames_
[0];
1731 EXPECT_EQ(0xBA, frame
.entropy_hash
);
1732 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame
.largest_observed
);
1733 ASSERT_EQ(1u, frame
.missing_packets
.size());
1734 SequenceNumberSet::const_iterator missing_iter
=
1735 frame
.missing_packets
.begin();
1736 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter
);
1738 const size_t kReceivedEntropyOffset
= kQuicFrameTypeSize
;
1739 const size_t kLargestObservedOffset
= kReceivedEntropyOffset
+
1740 kQuicEntropyHashSize
;
1741 const size_t kMissingDeltaTimeOffset
= kLargestObservedOffset
+
1742 PACKET_6BYTE_SEQUENCE_NUMBER
;
1743 const size_t kNumMissingPacketOffset
= kMissingDeltaTimeOffset
+
1744 kQuicDeltaTimeLargestObservedSize
;
1745 const size_t kMissingPacketsOffset
= kNumMissingPacketOffset
+
1746 kNumberOfNackRangesSize
;
1747 const size_t kMissingPacketsRange
= kMissingPacketsOffset
+
1748 PACKET_1BYTE_SEQUENCE_NUMBER
;
1749 const size_t kRevivedPacketsLength
= kMissingPacketsRange
+
1750 PACKET_1BYTE_SEQUENCE_NUMBER
;
1751 // Now test framing boundaries.
1752 const size_t ack_frame_size
= kRevivedPacketsLength
+
1753 PACKET_1BYTE_SEQUENCE_NUMBER
;
1754 for (size_t i
= kQuicFrameTypeSize
; i
< ack_frame_size
; ++i
) {
1755 string expected_error
;
1756 if (i
< kLargestObservedOffset
) {
1757 expected_error
= "Unable to read entropy hash for received packets.";
1758 } else if (i
< kMissingDeltaTimeOffset
) {
1759 expected_error
= "Unable to read largest observed.";
1760 } else if (i
< kNumMissingPacketOffset
) {
1761 expected_error
= "Unable to read delta time largest observed.";
1762 } else if (i
< kMissingPacketsOffset
) {
1763 expected_error
= "Unable to read num missing packet ranges.";
1764 } else if (i
< kMissingPacketsRange
) {
1765 expected_error
= "Unable to read missing sequence number delta.";
1766 } else if (i
< kRevivedPacketsLength
) {
1767 expected_error
= "Unable to read missing sequence number range.";
1769 expected_error
= "Unable to read num revived packets.";
1771 CheckProcessingFails(
1773 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
1774 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
1775 expected_error
, QUIC_INVALID_ACK_DATA
);
1780 TEST_P(QuicFramerTest
, AckFrameTwoTimestamp
) {
1781 if (version_
<= QUIC_VERSION_22
) {
1784 unsigned char packet
[] = {
1785 // public flags (8 byte connection_id)
1788 0x10, 0x32, 0x54, 0x76,
1789 0x98, 0xBA, 0xDC, 0xFE,
1790 // packet sequence number
1791 0xA8, 0x9A, 0x78, 0x56,
1793 // private flags (entropy)
1796 // frame type (ack frame)
1797 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
1799 // entropy hash of all received packets.
1801 // largest observed packet sequence number
1802 0xBF, 0x9A, 0x78, 0x56,
1806 // Number of timestamps.
1808 // Delta from largest observed.
1811 0x10, 0x32, 0x54, 0x76,
1812 // Delta from largest observed.
1816 // num missing packets
1818 // missing packet delta
1820 // 0 more missing packets in range.
1822 // Number of revived packets.
1826 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1827 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1829 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1830 ASSERT_TRUE(visitor_
.header_
.get());
1831 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1833 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
1834 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
1835 const QuicAckFrame
& frame
= *visitor_
.ack_frames_
[0];
1836 EXPECT_EQ(0xBA, frame
.entropy_hash
);
1837 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame
.largest_observed
);
1838 ASSERT_EQ(1u, frame
.missing_packets
.size());
1839 ASSERT_EQ(2u, frame
.received_packet_times
.size());
1840 SequenceNumberSet::const_iterator missing_iter
=
1841 frame
.missing_packets
.begin();
1842 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter
);
1844 const size_t kReceivedEntropyOffset
= kQuicFrameTypeSize
;
1845 const size_t kLargestObservedOffset
= kReceivedEntropyOffset
+
1846 kQuicEntropyHashSize
;
1847 const size_t kMissingDeltaTimeOffset
= kLargestObservedOffset
+
1848 PACKET_6BYTE_SEQUENCE_NUMBER
;
1849 const size_t kNumTimestampsOffset
= kMissingDeltaTimeOffset
+
1850 kQuicDeltaTimeLargestObservedSize
;
1851 const size_t kTimestampDeltaLargestObserved1
= kNumTimestampsOffset
+
1852 kQuicNumTimestampsSize
;
1853 const size_t kTimestampTimeDeltaLargestObserved1
=
1854 kTimestampDeltaLargestObserved1
+ 1;
1855 const size_t kTimestampDeltaLargestObserved2
=
1856 kTimestampTimeDeltaLargestObserved1
+ 4;
1857 const size_t kTimestampTimeDeltaLargestObserved2
=
1858 kTimestampDeltaLargestObserved2
+ 1;
1859 const size_t kNumMissingPacketOffset
=
1860 kTimestampTimeDeltaLargestObserved2
+ 2;
1861 const size_t kMissingPacketsOffset
= kNumMissingPacketOffset
+
1862 kNumberOfNackRangesSize
;
1863 const size_t kMissingPacketsRange
= kMissingPacketsOffset
+
1864 PACKET_1BYTE_SEQUENCE_NUMBER
;
1865 const size_t kRevivedPacketsLength
= kMissingPacketsRange
+
1866 PACKET_1BYTE_SEQUENCE_NUMBER
;
1867 // Now test framing boundaries.
1868 const size_t ack_frame_size
= kRevivedPacketsLength
+
1869 PACKET_1BYTE_SEQUENCE_NUMBER
;
1870 for (size_t i
= kQuicFrameTypeSize
; i
< ack_frame_size
; ++i
) {
1871 string expected_error
;
1872 if (i
< kLargestObservedOffset
) {
1873 expected_error
= "Unable to read entropy hash for received packets.";
1874 } else if (i
< kMissingDeltaTimeOffset
) {
1875 expected_error
= "Unable to read largest observed.";
1876 } else if (i
< kNumTimestampsOffset
) {
1877 expected_error
= "Unable to read delta time largest observed.";
1878 } else if (i
< kTimestampDeltaLargestObserved1
) {
1879 expected_error
= "Unable to read num received packets.";
1880 } else if (i
< kTimestampTimeDeltaLargestObserved1
) {
1881 expected_error
= "Unable to read sequence delta in received packets.";
1882 } else if (i
< kTimestampDeltaLargestObserved2
) {
1883 expected_error
= "Unable to read time delta in received packets.";
1884 } else if (i
< kTimestampTimeDeltaLargestObserved2
) {
1885 expected_error
= "Unable to read sequence delta in received packets.";
1886 } else if (i
< kNumMissingPacketOffset
) {
1888 "Unable to read incremental time delta in received packets.";
1889 } else if (i
< kMissingPacketsOffset
) {
1890 expected_error
= "Unable to read num missing packet ranges.";
1891 } else if (i
< kMissingPacketsRange
) {
1892 expected_error
= "Unable to read missing sequence number delta.";
1893 } else if (i
< kRevivedPacketsLength
) {
1894 expected_error
= "Unable to read missing sequence number range.";
1896 expected_error
= "Unable to read num revived packets.";
1898 CheckProcessingFails(
1900 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
1901 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
1902 expected_error
, QUIC_INVALID_ACK_DATA
);
1907 TEST_P(QuicFramerTest
, AckFrameOneTimestamp
) {
1908 if (version_
<= QUIC_VERSION_22
) {
1911 unsigned char packet
[] = {
1912 // public flags (8 byte connection_id)
1915 0x10, 0x32, 0x54, 0x76,
1916 0x98, 0xBA, 0xDC, 0xFE,
1917 // packet sequence number
1918 0xA8, 0x9A, 0x78, 0x56,
1920 // private flags (entropy)
1923 // frame type (ack frame)
1924 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
1926 // entropy hash of all received packets.
1928 // largest observed packet sequence number
1929 0xBF, 0x9A, 0x78, 0x56,
1933 // Number of timestamps.
1935 // Delta from largest observed.
1938 0x10, 0x32, 0x54, 0x76,
1939 // num missing packets
1941 // missing packet delta
1943 // 0 more missing packets in range.
1945 // Number of revived packets.
1949 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1950 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1952 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1953 ASSERT_TRUE(visitor_
.header_
.get());
1954 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1956 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
1957 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
1958 const QuicAckFrame
& frame
= *visitor_
.ack_frames_
[0];
1959 EXPECT_EQ(0xBA, frame
.entropy_hash
);
1960 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame
.largest_observed
);
1961 ASSERT_EQ(1u, frame
.missing_packets
.size());
1962 ASSERT_EQ(1u, frame
.received_packet_times
.size());
1963 SequenceNumberSet::const_iterator missing_iter
=
1964 frame
.missing_packets
.begin();
1965 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter
);
1967 const size_t kReceivedEntropyOffset
= kQuicFrameTypeSize
;
1968 const size_t kLargestObservedOffset
= kReceivedEntropyOffset
+
1969 kQuicEntropyHashSize
;
1970 const size_t kMissingDeltaTimeOffset
= kLargestObservedOffset
+
1971 PACKET_6BYTE_SEQUENCE_NUMBER
;
1972 const size_t kNumTimestampsOffset
= kMissingDeltaTimeOffset
+
1973 kQuicDeltaTimeLargestObservedSize
;
1974 const size_t kTimestampDeltaLargestObserved
= kNumTimestampsOffset
+
1975 kQuicNumTimestampsSize
;
1976 const size_t kTimestampTimeDeltaLargestObserved
=
1977 kTimestampDeltaLargestObserved
+ 1;
1978 const size_t kNumMissingPacketOffset
= kTimestampTimeDeltaLargestObserved
+ 4;
1979 const size_t kMissingPacketsOffset
= kNumMissingPacketOffset
+
1980 kNumberOfNackRangesSize
;
1981 const size_t kMissingPacketsRange
= kMissingPacketsOffset
+
1982 PACKET_1BYTE_SEQUENCE_NUMBER
;
1983 const size_t kRevivedPacketsLength
= kMissingPacketsRange
+
1984 PACKET_1BYTE_SEQUENCE_NUMBER
;
1985 // Now test framing boundaries.
1986 const size_t ack_frame_size
= kRevivedPacketsLength
+
1987 PACKET_1BYTE_SEQUENCE_NUMBER
;
1988 for (size_t i
= kQuicFrameTypeSize
; i
< ack_frame_size
; ++i
) {
1989 string expected_error
;
1990 if (i
< kLargestObservedOffset
) {
1991 expected_error
= "Unable to read entropy hash for received packets.";
1992 } else if (i
< kMissingDeltaTimeOffset
) {
1993 expected_error
= "Unable to read largest observed.";
1994 } else if (i
< kNumTimestampsOffset
) {
1995 expected_error
= "Unable to read delta time largest observed.";
1996 } else if (i
< kTimestampDeltaLargestObserved
) {
1997 expected_error
= "Unable to read num received packets.";
1998 } else if (i
< kTimestampTimeDeltaLargestObserved
) {
1999 expected_error
= "Unable to read sequence delta in received packets.";
2000 } else if (i
< kNumMissingPacketOffset
) {
2001 expected_error
= "Unable to read time delta in received packets.";
2002 } else if (i
< kMissingPacketsOffset
) {
2003 expected_error
= "Unable to read num missing packet ranges.";
2004 } else if (i
< kMissingPacketsRange
) {
2005 expected_error
= "Unable to read missing sequence number delta.";
2006 } else if (i
< kRevivedPacketsLength
) {
2007 expected_error
= "Unable to read missing sequence number range.";
2009 expected_error
= "Unable to read num revived packets.";
2011 CheckProcessingFails(
2013 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
2014 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
2015 expected_error
, QUIC_INVALID_ACK_DATA
);
2020 TEST_P(QuicFramerTest
, AckFrame
) {
2021 if (version_
<= QUIC_VERSION_22
) {
2024 unsigned char packet
[] = {
2025 // public flags (8 byte connection_id)
2028 0x10, 0x32, 0x54, 0x76,
2029 0x98, 0xBA, 0xDC, 0xFE,
2030 // packet sequence number
2031 0xA8, 0x9A, 0x78, 0x56,
2033 // private flags (entropy)
2036 // frame type (ack frame)
2037 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
2039 // entropy hash of all received packets.
2041 // largest observed packet sequence number
2042 0xBF, 0x9A, 0x78, 0x56,
2046 // Number of timestamps.
2048 // num missing packets
2050 // missing packet delta
2052 // 0 more missing packets in range.
2054 // Number of revived packets.
2058 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2059 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2061 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2062 ASSERT_TRUE(visitor_
.header_
.get());
2063 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2065 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
2066 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
2067 const QuicAckFrame
& frame
= *visitor_
.ack_frames_
[0];
2068 EXPECT_EQ(0xBA, frame
.entropy_hash
);
2069 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame
.largest_observed
);
2070 ASSERT_EQ(1u, frame
.missing_packets
.size());
2071 SequenceNumberSet::const_iterator missing_iter
=
2072 frame
.missing_packets
.begin();
2073 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter
);
2075 const size_t kReceivedEntropyOffset
= kQuicFrameTypeSize
;
2076 const size_t kLargestObservedOffset
= kReceivedEntropyOffset
+
2077 kQuicEntropyHashSize
;
2078 const size_t kMissingDeltaTimeOffset
= kLargestObservedOffset
+
2079 PACKET_6BYTE_SEQUENCE_NUMBER
;
2080 const size_t kNumTimestampsOffset
= kMissingDeltaTimeOffset
+
2081 kQuicDeltaTimeLargestObservedSize
;
2082 const size_t kNumMissingPacketOffset
= kNumTimestampsOffset
+
2083 kQuicNumTimestampsSize
;
2084 const size_t kMissingPacketsOffset
= kNumMissingPacketOffset
+
2085 kNumberOfNackRangesSize
;
2086 const size_t kMissingPacketsRange
= kMissingPacketsOffset
+
2087 PACKET_1BYTE_SEQUENCE_NUMBER
;
2088 const size_t kRevivedPacketsLength
= kMissingPacketsRange
+
2089 PACKET_1BYTE_SEQUENCE_NUMBER
;
2090 // Now test framing boundaries.
2091 const size_t ack_frame_size
= kRevivedPacketsLength
+
2092 PACKET_1BYTE_SEQUENCE_NUMBER
;
2093 for (size_t i
= kQuicFrameTypeSize
; i
< ack_frame_size
; ++i
) {
2094 string expected_error
;
2095 if (i
< kLargestObservedOffset
) {
2096 expected_error
= "Unable to read entropy hash for received packets.";
2097 } else if (i
< kMissingDeltaTimeOffset
) {
2098 expected_error
= "Unable to read largest observed.";
2099 } else if (i
< kNumTimestampsOffset
) {
2100 expected_error
= "Unable to read delta time largest observed.";
2101 } else if (i
< kNumMissingPacketOffset
) {
2102 expected_error
= "Unable to read num received packets.";
2103 } else if (i
< kMissingPacketsOffset
) {
2104 expected_error
= "Unable to read num missing packet ranges.";
2105 } else if (i
< kMissingPacketsRange
) {
2106 expected_error
= "Unable to read missing sequence number delta.";
2107 } else if (i
< kRevivedPacketsLength
) {
2108 expected_error
= "Unable to read missing sequence number range.";
2110 expected_error
= "Unable to read num revived packets.";
2112 CheckProcessingFails(
2114 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
2115 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
2116 expected_error
, QUIC_INVALID_ACK_DATA
);
2120 TEST_P(QuicFramerTest
, AckFrameRevivedPackets
) {
2121 if (version_
<= QUIC_VERSION_22
) {
2124 unsigned char packet
[] = {
2125 // public flags (8 byte connection_id)
2128 0x10, 0x32, 0x54, 0x76,
2129 0x98, 0xBA, 0xDC, 0xFE,
2130 // packet sequence number
2131 0xA8, 0x9A, 0x78, 0x56,
2133 // private flags (entropy)
2136 // frame type (ack frame)
2137 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
2139 // entropy hash of all received packets.
2141 // largest observed packet sequence number
2142 0xBF, 0x9A, 0x78, 0x56,
2146 // num received packets.
2148 // num missing packets
2150 // missing packet delta
2152 // 0 more missing packets in range.
2154 // Number of revived packets.
2156 // Revived packet sequence number.
2157 0xBE, 0x9A, 0x78, 0x56,
2159 // Number of revived packets.
2163 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2164 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2166 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2167 ASSERT_TRUE(visitor_
.header_
.get());
2168 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2170 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
2171 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
2172 const QuicAckFrame
& frame
= *visitor_
.ack_frames_
[0];
2173 EXPECT_EQ(0xBA, frame
.entropy_hash
);
2174 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame
.largest_observed
);
2175 ASSERT_EQ(1u, frame
.missing_packets
.size());
2176 SequenceNumberSet::const_iterator missing_iter
=
2177 frame
.missing_packets
.begin();
2178 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter
);
2180 const size_t kReceivedEntropyOffset
= kQuicFrameTypeSize
;
2181 const size_t kLargestObservedOffset
= kReceivedEntropyOffset
+
2182 kQuicEntropyHashSize
;
2183 const size_t kMissingDeltaTimeOffset
= kLargestObservedOffset
+
2184 PACKET_6BYTE_SEQUENCE_NUMBER
;
2185 const size_t kNumTimestampsOffset
= kMissingDeltaTimeOffset
+
2186 kQuicDeltaTimeLargestObservedSize
;
2187 const size_t kNumMissingPacketOffset
= kNumTimestampsOffset
+
2188 kQuicNumTimestampsSize
;
2189 const size_t kMissingPacketsOffset
= kNumMissingPacketOffset
+
2190 kNumberOfNackRangesSize
;
2191 const size_t kMissingPacketsRange
= kMissingPacketsOffset
+
2192 PACKET_1BYTE_SEQUENCE_NUMBER
;
2193 const size_t kRevivedPacketsLength
= kMissingPacketsRange
+
2194 PACKET_1BYTE_SEQUENCE_NUMBER
;
2195 const size_t kRevivedPacketSequenceNumberLength
= kRevivedPacketsLength
+
2196 PACKET_1BYTE_SEQUENCE_NUMBER
;
2197 // Now test framing boundaries.
2198 const size_t ack_frame_size
= kRevivedPacketSequenceNumberLength
+
2199 PACKET_6BYTE_SEQUENCE_NUMBER
;
2200 for (size_t i
= kQuicFrameTypeSize
; i
< ack_frame_size
; ++i
) {
2201 string expected_error
;
2202 if (i
< kReceivedEntropyOffset
) {
2203 expected_error
= "Unable to read least unacked delta.";
2204 } else if (i
< kLargestObservedOffset
) {
2205 expected_error
= "Unable to read entropy hash for received packets.";
2206 } else if (i
< kMissingDeltaTimeOffset
) {
2207 expected_error
= "Unable to read largest observed.";
2208 } else if (i
< kNumTimestampsOffset
) {
2209 expected_error
= "Unable to read delta time largest observed.";
2210 } else if (i
< kNumMissingPacketOffset
) {
2211 expected_error
= "Unable to read num received packets.";
2212 } else if (i
< kMissingPacketsOffset
) {
2213 expected_error
= "Unable to read num missing packet ranges.";
2214 } else if (i
< kMissingPacketsRange
) {
2215 expected_error
= "Unable to read missing sequence number delta.";
2216 } else if (i
< kRevivedPacketsLength
) {
2217 expected_error
= "Unable to read missing sequence number range.";
2218 } else if (i
< kRevivedPacketSequenceNumberLength
) {
2219 expected_error
= "Unable to read num revived packets.";
2221 expected_error
= "Unable to read revived packet.";
2223 CheckProcessingFails(
2225 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
2226 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
2227 expected_error
, QUIC_INVALID_ACK_DATA
);
2231 TEST_P(QuicFramerTest
, AckFrameRevivedPacketsv22
) {
2232 if (version_
> QUIC_VERSION_22
) {
2235 unsigned char packet
[] = {
2236 // public flags (8 byte connection_id)
2239 0x10, 0x32, 0x54, 0x76,
2240 0x98, 0xBA, 0xDC, 0xFE,
2241 // packet sequence number
2242 0xA8, 0x9A, 0x78, 0x56,
2244 // private flags (entropy)
2247 // frame type (ack frame)
2248 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
2250 // entropy hash of all received packets.
2252 // largest observed packet sequence number
2253 0xBF, 0x9A, 0x78, 0x56,
2257 // num missing packets
2259 // missing packet delta
2261 // 0 more missing packets in range.
2263 // Number of revived packets.
2265 // Revived packet sequence number.
2266 0xBE, 0x9A, 0x78, 0x56,
2268 // Number of revived packets.
2272 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2273 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2275 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2276 ASSERT_TRUE(visitor_
.header_
.get());
2277 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2279 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
2280 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
2281 const QuicAckFrame
& frame
= *visitor_
.ack_frames_
[0];
2282 EXPECT_EQ(0xBA, frame
.entropy_hash
);
2283 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame
.largest_observed
);
2284 ASSERT_EQ(1u, frame
.missing_packets
.size());
2285 SequenceNumberSet::const_iterator missing_iter
=
2286 frame
.missing_packets
.begin();
2287 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter
);
2289 const size_t kReceivedEntropyOffset
= kQuicFrameTypeSize
;
2290 const size_t kLargestObservedOffset
= kReceivedEntropyOffset
+
2291 kQuicEntropyHashSize
;
2292 const size_t kMissingDeltaTimeOffset
= kLargestObservedOffset
+
2293 PACKET_6BYTE_SEQUENCE_NUMBER
;
2294 const size_t kNumMissingPacketOffset
= kMissingDeltaTimeOffset
+
2295 kQuicDeltaTimeLargestObservedSize
;
2296 const size_t kMissingPacketsOffset
= kNumMissingPacketOffset
+
2297 kNumberOfNackRangesSize
;
2298 const size_t kMissingPacketsRange
= kMissingPacketsOffset
+
2299 PACKET_1BYTE_SEQUENCE_NUMBER
;
2300 const size_t kRevivedPacketsLength
= kMissingPacketsRange
+
2301 PACKET_1BYTE_SEQUENCE_NUMBER
;
2302 const size_t kRevivedPacketSequenceNumberLength
= kRevivedPacketsLength
+
2303 PACKET_1BYTE_SEQUENCE_NUMBER
;
2304 // Now test framing boundaries.
2305 const size_t ack_frame_size
= kRevivedPacketSequenceNumberLength
+
2306 PACKET_6BYTE_SEQUENCE_NUMBER
;
2307 for (size_t i
= kQuicFrameTypeSize
; i
< ack_frame_size
; ++i
) {
2308 string expected_error
;
2309 if (i
< kReceivedEntropyOffset
) {
2310 expected_error
= "Unable to read least unacked delta.";
2311 } else if (i
< kLargestObservedOffset
) {
2312 expected_error
= "Unable to read entropy hash for received packets.";
2313 } else if (i
< kMissingDeltaTimeOffset
) {
2314 expected_error
= "Unable to read largest observed.";
2315 } else if (i
< kNumMissingPacketOffset
) {
2316 expected_error
= "Unable to read delta time largest observed.";
2317 } else if (i
< kMissingPacketsOffset
) {
2318 expected_error
= "Unable to read num missing packet ranges.";
2319 } else if (i
< kMissingPacketsRange
) {
2320 expected_error
= "Unable to read missing sequence number delta.";
2321 } else if (i
< kRevivedPacketsLength
) {
2322 expected_error
= "Unable to read missing sequence number range.";
2323 } else if (i
< kRevivedPacketSequenceNumberLength
) {
2324 expected_error
= "Unable to read num revived packets.";
2326 expected_error
= "Unable to read revived packet.";
2328 CheckProcessingFails(
2330 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
2331 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
2332 expected_error
, QUIC_INVALID_ACK_DATA
);
2336 TEST_P(QuicFramerTest
, AckFrameNoNacksv22
) {
2337 if (version_
> QUIC_VERSION_22
) {
2340 unsigned char packet
[] = {
2341 // public flags (8 byte connection_id)
2344 0x10, 0x32, 0x54, 0x76,
2345 0x98, 0xBA, 0xDC, 0xFE,
2346 // packet sequence number
2347 0xA8, 0x9A, 0x78, 0x56,
2349 // private flags (entropy)
2352 // frame type (ack frame)
2353 // (no nacks, not truncated, 6 byte largest observed, 1 byte delta)
2355 // entropy hash of all received packets.
2357 // largest observed packet sequence number
2358 0xBF, 0x9A, 0x78, 0x56,
2364 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2365 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2367 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2368 ASSERT_TRUE(visitor_
.header_
.get());
2369 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2371 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
2372 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
2373 QuicAckFrame
* frame
= visitor_
.ack_frames_
[0];
2374 EXPECT_EQ(0xBA, frame
->entropy_hash
);
2375 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame
->largest_observed
);
2376 ASSERT_EQ(0u, frame
->missing_packets
.size());
2378 // Verify that the packet re-serializes identically.
2380 frames
.push_back(QuicFrame(frame
));
2381 scoped_ptr
<QuicPacket
> data(BuildDataPacket(*visitor_
.header_
, frames
));
2382 ASSERT_TRUE(data
!= NULL
);
2384 test::CompareCharArraysWithHexError("constructed packet",
2385 data
->data(), data
->length(),
2386 AsChars(packet
), arraysize(packet
));
2389 TEST_P(QuicFramerTest
, AckFrameNoNacks
) {
2390 if (version_
<= QUIC_VERSION_22
) {
2393 unsigned char packet
[] = {
2394 // public flags (8 byte connection_id)
2397 0x10, 0x32, 0x54, 0x76,
2398 0x98, 0xBA, 0xDC, 0xFE,
2399 // packet sequence number
2400 0xA8, 0x9A, 0x78, 0x56,
2402 // private flags (entropy)
2405 // frame type (ack frame)
2406 // (no nacks, not truncated, 6 byte largest observed, 1 byte delta)
2408 // entropy hash of all received packets.
2410 // largest observed packet sequence number
2411 0xBF, 0x9A, 0x78, 0x56,
2415 // Number of received packets.
2419 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2420 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2422 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2423 ASSERT_TRUE(visitor_
.header_
.get());
2424 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2426 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
2427 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
2428 QuicAckFrame
* frame
= visitor_
.ack_frames_
[0];
2429 EXPECT_EQ(0xBA, frame
->entropy_hash
);
2430 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame
->largest_observed
);
2431 ASSERT_EQ(0u, frame
->missing_packets
.size());
2433 // Verify that the packet re-serializes identically.
2435 frames
.push_back(QuicFrame(frame
));
2436 scoped_ptr
<QuicPacket
> data(BuildDataPacket(*visitor_
.header_
, frames
));
2437 ASSERT_TRUE(data
!= NULL
);
2439 test::CompareCharArraysWithHexError("constructed packet",
2440 data
->data(), data
->length(),
2441 AsChars(packet
), arraysize(packet
));
2444 TEST_P(QuicFramerTest
, AckFrame500Nacksv22
) {
2445 if (version_
> QUIC_VERSION_22
) {
2448 unsigned char packet
[] = {
2449 // public flags (8 byte connection_id)
2452 0x10, 0x32, 0x54, 0x76,
2453 0x98, 0xBA, 0xDC, 0xFE,
2454 // packet sequence number
2455 0xA8, 0x9A, 0x78, 0x56,
2457 // private flags (entropy)
2460 // frame type (ack frame)
2461 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
2463 // entropy hash of all received packets.
2465 // largest observed packet sequence number
2466 0xBF, 0x9A, 0x78, 0x56,
2470 // num missing packet ranges
2472 // missing packet delta
2474 // 243 more missing packets in range.
2475 // The ranges are listed in this order so the re-constructed packet matches.
2477 // No gap between ranges
2479 // 255 more missing packets in range.
2481 // No revived packets.
2485 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2486 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2488 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2489 ASSERT_TRUE(visitor_
.header_
.get());
2490 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2492 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
2493 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
2494 QuicAckFrame
* frame
= visitor_
.ack_frames_
[0];
2495 EXPECT_EQ(0xBA, frame
->entropy_hash
);
2496 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame
->largest_observed
);
2497 EXPECT_EQ(0u, frame
->revived_packets
.size());
2498 ASSERT_EQ(500u, frame
->missing_packets
.size());
2499 SequenceNumberSet::const_iterator first_missing_iter
=
2500 frame
->missing_packets
.begin();
2501 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE) - 499, *first_missing_iter
);
2502 SequenceNumberSet::const_reverse_iterator last_missing_iter
=
2503 frame
->missing_packets
.rbegin();
2504 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *last_missing_iter
);
2506 // Verify that the packet re-serializes identically.
2508 frames
.push_back(QuicFrame(frame
));
2509 scoped_ptr
<QuicPacket
> data(BuildDataPacket(*visitor_
.header_
, frames
));
2510 ASSERT_TRUE(data
!= NULL
);
2512 test::CompareCharArraysWithHexError("constructed packet",
2513 data
->data(), data
->length(),
2514 AsChars(packet
), arraysize(packet
));
2517 TEST_P(QuicFramerTest
, AckFrame500Nacks
) {
2518 if (version_
<= QUIC_VERSION_22
) {
2521 unsigned char packet
[] = {
2522 // public flags (8 byte connection_id)
2525 0x10, 0x32, 0x54, 0x76,
2526 0x98, 0xBA, 0xDC, 0xFE,
2527 // packet sequence number
2528 0xA8, 0x9A, 0x78, 0x56,
2530 // private flags (entropy)
2533 // frame type (ack frame)
2534 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
2536 // entropy hash of all received packets.
2538 // largest observed packet sequence number
2539 0xBF, 0x9A, 0x78, 0x56,
2543 // No received packets.
2545 // num missing packet ranges
2547 // missing packet delta
2549 // 243 more missing packets in range.
2550 // The ranges are listed in this order so the re-constructed packet matches.
2552 // No gap between ranges
2554 // 255 more missing packets in range.
2556 // No revived packets.
2560 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2561 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2563 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2564 ASSERT_TRUE(visitor_
.header_
.get());
2565 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2567 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
2568 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
2569 QuicAckFrame
* frame
= visitor_
.ack_frames_
[0];
2570 EXPECT_EQ(0xBA, frame
->entropy_hash
);
2571 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame
->largest_observed
);
2572 EXPECT_EQ(0u, frame
->revived_packets
.size());
2573 ASSERT_EQ(500u, frame
->missing_packets
.size());
2574 SequenceNumberSet::const_iterator first_missing_iter
=
2575 frame
->missing_packets
.begin();
2576 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE) - 499, *first_missing_iter
);
2577 SequenceNumberSet::const_reverse_iterator last_missing_iter
=
2578 frame
->missing_packets
.rbegin();
2579 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *last_missing_iter
);
2581 // Verify that the packet re-serializes identically.
2583 frames
.push_back(QuicFrame(frame
));
2584 scoped_ptr
<QuicPacket
> data(BuildDataPacket(*visitor_
.header_
, frames
));
2585 ASSERT_TRUE(data
!= NULL
);
2587 test::CompareCharArraysWithHexError("constructed packet",
2588 data
->data(), data
->length(),
2589 AsChars(packet
), arraysize(packet
));
2592 TEST_P(QuicFramerTest
, CongestionFeedbackFrameTCP
) {
2593 unsigned char packet
[] = {
2594 // public flags (8 byte connection_id)
2597 0x10, 0x32, 0x54, 0x76,
2598 0x98, 0xBA, 0xDC, 0xFE,
2599 // packet sequence number
2600 0xBC, 0x9A, 0x78, 0x56,
2605 // frame type (congestion feedback frame)
2607 // congestion feedback type (tcp)
2609 // ack_frame.feedback.tcp.receive_window
2613 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2614 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2616 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2617 ASSERT_TRUE(visitor_
.header_
.get());
2618 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2620 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
2621 ASSERT_EQ(1u, visitor_
.congestion_feedback_frames_
.size());
2622 const QuicCongestionFeedbackFrame
& frame
=
2623 *visitor_
.congestion_feedback_frames_
[0];
2624 ASSERT_EQ(kTCP
, frame
.type
);
2625 EXPECT_EQ(0x4030u
, frame
.tcp
.receive_window
);
2627 // Now test framing boundaries.
2628 for (size_t i
= kQuicFrameTypeSize
; i
< 4; ++i
) {
2629 string expected_error
;
2631 expected_error
= "Unable to read congestion feedback type.";
2633 expected_error
= "Unable to read receive window.";
2635 CheckProcessingFails(
2637 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
2638 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
2639 expected_error
, QUIC_INVALID_CONGESTION_FEEDBACK_DATA
);
2643 TEST_P(QuicFramerTest
, CongestionFeedbackFrameInvalidFeedback
) {
2644 unsigned char packet
[] = {
2645 // public flags (8 byte connection_id)
2648 0x10, 0x32, 0x54, 0x76,
2649 0x98, 0xBA, 0xDC, 0xFE,
2650 // packet sequence number
2651 0xBC, 0x9A, 0x78, 0x56,
2656 // frame type (congestion feedback frame)
2658 // congestion feedback type (invalid)
2662 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2663 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
2664 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2665 EXPECT_EQ(QUIC_INVALID_CONGESTION_FEEDBACK_DATA
, framer_
.error());
2668 TEST_P(QuicFramerTest
, StopWaitingFrame
) {
2669 unsigned char packet
[] = {
2670 // public flags (8 byte connection_id)
2673 0x10, 0x32, 0x54, 0x76,
2674 0x98, 0xBA, 0xDC, 0xFE,
2675 // packet sequence number
2676 0xA8, 0x9A, 0x78, 0x56,
2678 // private flags (entropy)
2681 // frame type (ack frame)
2682 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
2684 // entropy hash of sent packets till least awaiting - 1.
2686 // least packet sequence number awaiting an ack, delta from sequence number.
2687 0x08, 0x00, 0x00, 0x00,
2691 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2692 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2694 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2695 ASSERT_TRUE(visitor_
.header_
.get());
2696 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2698 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
2699 ASSERT_EQ(1u, visitor_
.stop_waiting_frames_
.size());
2700 const QuicStopWaitingFrame
& frame
= *visitor_
.stop_waiting_frames_
[0];
2701 EXPECT_EQ(0xAB, frame
.entropy_hash
);
2702 EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame
.least_unacked
);
2704 const size_t kSentEntropyOffset
= kQuicFrameTypeSize
;
2705 const size_t kLeastUnackedOffset
= kSentEntropyOffset
+ kQuicEntropyHashSize
;
2706 const size_t frame_size
= 7;
2707 for (size_t i
= kQuicFrameTypeSize
; i
< frame_size
; ++i
) {
2708 string expected_error
;
2709 if (i
< kLeastUnackedOffset
) {
2710 expected_error
= "Unable to read entropy hash for sent packets.";
2712 expected_error
= "Unable to read least unacked delta.";
2714 CheckProcessingFails(
2716 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
2717 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
2718 expected_error
, QUIC_INVALID_STOP_WAITING_DATA
);
2722 TEST_P(QuicFramerTest
, RstStreamFrameQuic
) {
2723 unsigned char packet
[] = {
2724 // public flags (8 byte connection_id)
2727 0x10, 0x32, 0x54, 0x76,
2728 0x98, 0xBA, 0xDC, 0xFE,
2729 // packet sequence number
2730 0xBC, 0x9A, 0x78, 0x56,
2735 // frame type (rst stream frame)
2738 0x04, 0x03, 0x02, 0x01,
2741 0x01, 0x02, 0x03, 0x04,
2742 0x05, 0x06, 0x07, 0x08,
2745 0x01, 0x00, 0x00, 0x00,
2747 // error details length
2756 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2757 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2759 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2760 ASSERT_TRUE(visitor_
.header_
.get());
2761 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2763 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_
.rst_stream_frame_
.stream_id
);
2764 EXPECT_EQ(0x01, visitor_
.rst_stream_frame_
.error_code
);
2765 EXPECT_EQ("because I can", visitor_
.rst_stream_frame_
.error_details
);
2766 EXPECT_EQ(GG_UINT64_C(0x0807060504030201),
2767 visitor_
.rst_stream_frame_
.byte_offset
);
2769 // Now test framing boundaries.
2770 for (size_t i
= kQuicFrameTypeSize
;
2771 i
< QuicFramer::GetMinRstStreamFrameSize(); ++i
) {
2772 string expected_error
;
2773 if (i
< kQuicFrameTypeSize
+ kQuicMaxStreamIdSize
) {
2774 expected_error
= "Unable to read stream_id.";
2775 } else if (i
< kQuicFrameTypeSize
+ kQuicMaxStreamIdSize
+
2776 + kQuicMaxStreamOffsetSize
) {
2777 expected_error
= "Unable to read rst stream sent byte offset.";
2778 } else if (i
< kQuicFrameTypeSize
+ kQuicMaxStreamIdSize
+
2779 + kQuicMaxStreamOffsetSize
+ kQuicErrorCodeSize
) {
2780 expected_error
= "Unable to read rst stream error code.";
2782 expected_error
= "Unable to read rst stream error details.";
2784 CheckProcessingFails(
2786 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
2787 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
2788 expected_error
, QUIC_INVALID_RST_STREAM_DATA
);
2792 TEST_P(QuicFramerTest
, ConnectionCloseFrame
) {
2793 unsigned char packet
[] = {
2794 // public flags (8 byte connection_id)
2797 0x10, 0x32, 0x54, 0x76,
2798 0x98, 0xBA, 0xDC, 0xFE,
2799 // packet sequence number
2800 0xBC, 0x9A, 0x78, 0x56,
2805 // frame type (connection close frame)
2808 0x11, 0x00, 0x00, 0x00,
2810 // error details length
2819 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2820 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2822 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2823 ASSERT_TRUE(visitor_
.header_
.get());
2824 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2826 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
2828 EXPECT_EQ(0x11, visitor_
.connection_close_frame_
.error_code
);
2829 EXPECT_EQ("because I can", visitor_
.connection_close_frame_
.error_details
);
2831 ASSERT_EQ(0u, visitor_
.ack_frames_
.size());
2833 // Now test framing boundaries.
2834 for (size_t i
= kQuicFrameTypeSize
;
2835 i
< QuicFramer::GetMinConnectionCloseFrameSize(); ++i
) {
2836 string expected_error
;
2837 if (i
< kQuicFrameTypeSize
+ kQuicErrorCodeSize
) {
2838 expected_error
= "Unable to read connection close error code.";
2840 expected_error
= "Unable to read connection close error details.";
2842 CheckProcessingFails(
2844 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
2845 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
2846 expected_error
, QUIC_INVALID_CONNECTION_CLOSE_DATA
);
2850 TEST_P(QuicFramerTest
, GoAwayFrame
) {
2851 unsigned char packet
[] = {
2852 // public flags (8 byte connection_id)
2855 0x10, 0x32, 0x54, 0x76,
2856 0x98, 0xBA, 0xDC, 0xFE,
2857 // packet sequence number
2858 0xBC, 0x9A, 0x78, 0x56,
2863 // frame type (go away frame)
2866 0x09, 0x00, 0x00, 0x00,
2868 0x04, 0x03, 0x02, 0x01,
2869 // error details length
2878 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2879 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2881 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2882 ASSERT_TRUE(visitor_
.header_
.get());
2883 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2885 EXPECT_EQ(GG_UINT64_C(0x01020304),
2886 visitor_
.goaway_frame_
.last_good_stream_id
);
2887 EXPECT_EQ(0x9, visitor_
.goaway_frame_
.error_code
);
2888 EXPECT_EQ("because I can", visitor_
.goaway_frame_
.reason_phrase
);
2890 const size_t reason_size
= arraysize("because I can") - 1;
2891 // Now test framing boundaries.
2892 for (size_t i
= kQuicFrameTypeSize
;
2893 i
< QuicFramer::GetMinGoAwayFrameSize() + reason_size
; ++i
) {
2894 string expected_error
;
2895 if (i
< kQuicFrameTypeSize
+ kQuicErrorCodeSize
) {
2896 expected_error
= "Unable to read go away error code.";
2897 } else if (i
< kQuicFrameTypeSize
+ kQuicErrorCodeSize
+
2898 kQuicMaxStreamIdSize
) {
2899 expected_error
= "Unable to read last good stream id.";
2901 expected_error
= "Unable to read goaway reason.";
2903 CheckProcessingFails(
2905 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
2906 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
2907 expected_error
, QUIC_INVALID_GOAWAY_DATA
);
2911 TEST_P(QuicFramerTest
, WindowUpdateFrame
) {
2912 unsigned char packet
[] = {
2913 // public flags (8 byte connection_id)
2916 0x10, 0x32, 0x54, 0x76,
2917 0x98, 0xBA, 0xDC, 0xFE,
2918 // packet sequence number
2919 0xBC, 0x9A, 0x78, 0x56,
2924 // frame type (window update frame)
2927 0x04, 0x03, 0x02, 0x01,
2929 0x05, 0x06, 0x07, 0x08,
2930 0x09, 0x0a, 0x0b, 0x0c,
2933 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2935 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2937 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2938 ASSERT_TRUE(visitor_
.header_
.get());
2939 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2941 EXPECT_EQ(GG_UINT64_C(0x01020304),
2942 visitor_
.window_update_frame_
.stream_id
);
2943 EXPECT_EQ(GG_UINT64_C(0x0c0b0a0908070605),
2944 visitor_
.window_update_frame_
.byte_offset
);
2946 // Now test framing boundaries.
2947 for (size_t i
= kQuicFrameTypeSize
;
2948 i
< QuicFramer::GetWindowUpdateFrameSize(); ++i
) {
2949 string expected_error
;
2950 if (i
< kQuicFrameTypeSize
+ kQuicMaxStreamIdSize
) {
2951 expected_error
= "Unable to read stream_id.";
2953 expected_error
= "Unable to read window byte_offset.";
2955 CheckProcessingFails(
2957 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
2958 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
2959 expected_error
, QUIC_INVALID_WINDOW_UPDATE_DATA
);
2963 TEST_P(QuicFramerTest
, BlockedFrame
) {
2964 unsigned char packet
[] = {
2965 // public flags (8 byte connection_id)
2968 0x10, 0x32, 0x54, 0x76,
2969 0x98, 0xBA, 0xDC, 0xFE,
2970 // packet sequence number
2971 0xBC, 0x9A, 0x78, 0x56,
2976 // frame type (blocked frame)
2979 0x04, 0x03, 0x02, 0x01,
2982 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2984 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2986 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2987 ASSERT_TRUE(visitor_
.header_
.get());
2988 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2990 EXPECT_EQ(GG_UINT64_C(0x01020304),
2991 visitor_
.blocked_frame_
.stream_id
);
2993 // Now test framing boundaries.
2994 for (size_t i
= kQuicFrameTypeSize
; i
< QuicFramer::GetBlockedFrameSize();
2996 string expected_error
= "Unable to read stream_id.";
2997 CheckProcessingFails(
2999 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
3000 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
3001 expected_error
, QUIC_INVALID_BLOCKED_DATA
);
3005 TEST_P(QuicFramerTest
, PingFrame
) {
3006 if (version_
<= QUIC_VERSION_16
) {
3010 unsigned char packet
[] = {
3011 // public flags (8 byte connection_id)
3014 0x10, 0x32, 0x54, 0x76,
3015 0x98, 0xBA, 0xDC, 0xFE,
3016 // packet sequence number
3017 0xBC, 0x9A, 0x78, 0x56,
3022 // frame type (ping frame)
3026 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
3027 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
3029 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
3030 ASSERT_TRUE(visitor_
.header_
.get());
3031 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
3033 EXPECT_EQ(1u, visitor_
.ping_frames_
.size());
3035 // No need to check the PING frame boundaries because it has no payload.
3038 TEST_P(QuicFramerTest
, PublicResetPacket
) {
3039 unsigned char packet
[] = {
3040 // public flags (public reset, 8 byte connection_id)
3043 0x10, 0x32, 0x54, 0x76,
3044 0x98, 0xBA, 0xDC, 0xFE,
3045 // message tag (kPRST)
3047 // num_entries (2) + padding
3048 0x02, 0x00, 0x00, 0x00,
3052 0x08, 0x00, 0x00, 0x00,
3056 0x10, 0x00, 0x00, 0x00,
3058 0x89, 0x67, 0x45, 0x23,
3059 0x01, 0xEF, 0xCD, 0xAB,
3060 // rejected sequence number
3061 0xBC, 0x9A, 0x78, 0x56,
3062 0x34, 0x12, 0x00, 0x00,
3065 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
3066 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
3067 ASSERT_EQ(QUIC_NO_ERROR
, framer_
.error());
3068 ASSERT_TRUE(visitor_
.public_reset_packet_
.get());
3069 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
3070 visitor_
.public_reset_packet_
->public_header
.connection_id
);
3071 EXPECT_TRUE(visitor_
.public_reset_packet_
->public_header
.reset_flag
);
3072 EXPECT_FALSE(visitor_
.public_reset_packet_
->public_header
.version_flag
);
3073 EXPECT_EQ(GG_UINT64_C(0xABCDEF0123456789),
3074 visitor_
.public_reset_packet_
->nonce_proof
);
3075 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
3076 visitor_
.public_reset_packet_
->rejected_sequence_number
);
3078 visitor_
.public_reset_packet_
->client_address
.address().empty());
3080 // Now test framing boundaries.
3081 for (size_t i
= 0; i
< arraysize(packet
); ++i
) {
3082 string expected_error
;
3083 DVLOG(1) << "iteration: " << i
;
3084 if (i
< kConnectionIdOffset
) {
3085 expected_error
= "Unable to read public flags.";
3086 CheckProcessingFails(packet
, i
, expected_error
,
3087 QUIC_INVALID_PACKET_HEADER
);
3088 } else if (i
< kPublicResetPacketMessageTagOffset
) {
3089 expected_error
= "Unable to read ConnectionId.";
3090 CheckProcessingFails(packet
, i
, expected_error
,
3091 QUIC_INVALID_PACKET_HEADER
);
3093 expected_error
= "Unable to read reset message.";
3094 CheckProcessingFails(packet
, i
, expected_error
,
3095 QUIC_INVALID_PUBLIC_RST_PACKET
);
3100 TEST_P(QuicFramerTest
, PublicResetPacketWithTrailingJunk
) {
3101 unsigned char packet
[] = {
3102 // public flags (public reset, 8 byte connection_id)
3105 0x10, 0x32, 0x54, 0x76,
3106 0x98, 0xBA, 0xDC, 0xFE,
3107 // message tag (kPRST)
3109 // num_entries (2) + padding
3110 0x02, 0x00, 0x00, 0x00,
3114 0x08, 0x00, 0x00, 0x00,
3118 0x10, 0x00, 0x00, 0x00,
3120 0x89, 0x67, 0x45, 0x23,
3121 0x01, 0xEF, 0xCD, 0xAB,
3122 // rejected sequence number
3123 0xBC, 0x9A, 0x78, 0x56,
3124 0x34, 0x12, 0x00, 0x00,
3129 string expected_error
= "Unable to read reset message.";
3130 CheckProcessingFails(packet
, arraysize(packet
), expected_error
,
3131 QUIC_INVALID_PUBLIC_RST_PACKET
);
3134 TEST_P(QuicFramerTest
, PublicResetPacketWithClientAddress
) {
3135 unsigned char packet
[] = {
3136 // public flags (public reset, 8 byte connection_id)
3139 0x10, 0x32, 0x54, 0x76,
3140 0x98, 0xBA, 0xDC, 0xFE,
3141 // message tag (kPRST)
3143 // num_entries (3) + padding
3144 0x03, 0x00, 0x00, 0x00,
3148 0x08, 0x00, 0x00, 0x00,
3152 0x10, 0x00, 0x00, 0x00,
3156 0x18, 0x00, 0x00, 0x00,
3158 0x89, 0x67, 0x45, 0x23,
3159 0x01, 0xEF, 0xCD, 0xAB,
3160 // rejected sequence number
3161 0xBC, 0x9A, 0x78, 0x56,
3162 0x34, 0x12, 0x00, 0x00,
3163 // client address: 4.31.198.44:443
3165 0x04, 0x1F, 0xC6, 0x2C,
3169 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
3170 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
3171 ASSERT_EQ(QUIC_NO_ERROR
, framer_
.error());
3172 ASSERT_TRUE(visitor_
.public_reset_packet_
.get());
3173 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
3174 visitor_
.public_reset_packet_
->public_header
.connection_id
);
3175 EXPECT_TRUE(visitor_
.public_reset_packet_
->public_header
.reset_flag
);
3176 EXPECT_FALSE(visitor_
.public_reset_packet_
->public_header
.version_flag
);
3177 EXPECT_EQ(GG_UINT64_C(0xABCDEF0123456789),
3178 visitor_
.public_reset_packet_
->nonce_proof
);
3179 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
3180 visitor_
.public_reset_packet_
->rejected_sequence_number
);
3181 EXPECT_EQ("4.31.198.44",
3182 IPAddressToString(visitor_
.public_reset_packet_
->
3183 client_address
.address()));
3184 EXPECT_EQ(443, visitor_
.public_reset_packet_
->client_address
.port());
3186 // Now test framing boundaries.
3187 for (size_t i
= 0; i
< arraysize(packet
); ++i
) {
3188 string expected_error
;
3189 DVLOG(1) << "iteration: " << i
;
3190 if (i
< kConnectionIdOffset
) {
3191 expected_error
= "Unable to read public flags.";
3192 CheckProcessingFails(packet
, i
, expected_error
,
3193 QUIC_INVALID_PACKET_HEADER
);
3194 } else if (i
< kPublicResetPacketMessageTagOffset
) {
3195 expected_error
= "Unable to read ConnectionId.";
3196 CheckProcessingFails(packet
, i
, expected_error
,
3197 QUIC_INVALID_PACKET_HEADER
);
3199 expected_error
= "Unable to read reset message.";
3200 CheckProcessingFails(packet
, i
, expected_error
,
3201 QUIC_INVALID_PUBLIC_RST_PACKET
);
3206 TEST_P(QuicFramerTest
, VersionNegotiationPacket
) {
3207 unsigned char packet
[] = {
3208 // public flags (version, 8 byte connection_id)
3211 0x10, 0x32, 0x54, 0x76,
3212 0x98, 0xBA, 0xDC, 0xFE,
3214 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
3218 QuicFramerPeer::SetIsServer(&framer_
, false);
3220 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
3221 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
3222 ASSERT_EQ(QUIC_NO_ERROR
, framer_
.error());
3223 ASSERT_TRUE(visitor_
.version_negotiation_packet_
.get());
3224 EXPECT_EQ(2u, visitor_
.version_negotiation_packet_
->versions
.size());
3225 EXPECT_EQ(GetParam(), visitor_
.version_negotiation_packet_
->versions
[0]);
3227 for (size_t i
= 0; i
<= kPublicFlagsSize
+ PACKET_8BYTE_CONNECTION_ID
; ++i
) {
3228 string expected_error
;
3229 QuicErrorCode error_code
= QUIC_INVALID_PACKET_HEADER
;
3230 if (i
< kConnectionIdOffset
) {
3231 expected_error
= "Unable to read public flags.";
3232 } else if (i
< kVersionOffset
) {
3233 expected_error
= "Unable to read ConnectionId.";
3235 expected_error
= "Unable to read supported version in negotiation.";
3236 error_code
= QUIC_INVALID_VERSION_NEGOTIATION_PACKET
;
3238 CheckProcessingFails(packet
, i
, expected_error
, error_code
);
3242 TEST_P(QuicFramerTest
, FecPacket
) {
3243 unsigned char packet
[] = {
3244 // public flags (8 byte connection_id)
3247 0x10, 0x32, 0x54, 0x76,
3248 0x98, 0xBA, 0xDC, 0xFE,
3249 // packet sequence number
3250 0xBC, 0x9A, 0x78, 0x56,
3252 // private flags (fec group & FEC)
3254 // first fec protected packet offset
3264 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
3265 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
3267 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
3268 ASSERT_TRUE(visitor_
.header_
.get());
3269 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
3271 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
3272 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
3273 ASSERT_EQ(1, visitor_
.fec_count_
);
3274 const QuicFecData
& fec_data
= *visitor_
.fec_data_
[0];
3275 EXPECT_EQ(GG_UINT64_C(0x0123456789ABB), fec_data
.fec_group
);
3276 EXPECT_EQ("abcdefghijklmnop", fec_data
.redundancy
);
3279 TEST_P(QuicFramerTest
, BuildPaddingFramePacket
) {
3280 QuicPacketHeader header
;
3281 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3282 header
.public_header
.reset_flag
= false;
3283 header
.public_header
.version_flag
= false;
3284 header
.fec_flag
= false;
3285 header
.entropy_flag
= false;
3286 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
3287 header
.fec_group
= 0;
3289 QuicPaddingFrame padding_frame
;
3292 frames
.push_back(QuicFrame(&padding_frame
));
3294 unsigned char packet
[kMaxPacketSize
] = {
3295 // public flags (8 byte connection_id)
3298 0x10, 0x32, 0x54, 0x76,
3299 0x98, 0xBA, 0xDC, 0xFE,
3300 // packet sequence number
3301 0xBC, 0x9A, 0x78, 0x56,
3306 // frame type (padding frame)
3308 0x00, 0x00, 0x00, 0x00
3311 uint64 header_size
=
3312 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
3313 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
3314 memset(packet
+ header_size
+ 1, 0x00, kMaxPacketSize
- header_size
- 1);
3316 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
3317 ASSERT_TRUE(data
!= NULL
);
3319 test::CompareCharArraysWithHexError("constructed packet",
3320 data
->data(), data
->length(),
3325 TEST_P(QuicFramerTest
, Build4ByteSequenceNumberPaddingFramePacket
) {
3326 QuicPacketHeader header
;
3327 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3328 header
.public_header
.reset_flag
= false;
3329 header
.public_header
.version_flag
= false;
3330 header
.fec_flag
= false;
3331 header
.entropy_flag
= false;
3332 header
.public_header
.sequence_number_length
= PACKET_4BYTE_SEQUENCE_NUMBER
;
3333 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
3334 header
.fec_group
= 0;
3336 QuicPaddingFrame padding_frame
;
3339 frames
.push_back(QuicFrame(&padding_frame
));
3341 unsigned char packet
[kMaxPacketSize
] = {
3342 // public flags (8 byte connection_id and 4 byte sequence number)
3345 0x10, 0x32, 0x54, 0x76,
3346 0x98, 0xBA, 0xDC, 0xFE,
3347 // packet sequence number
3348 0xBC, 0x9A, 0x78, 0x56,
3352 // frame type (padding frame)
3354 0x00, 0x00, 0x00, 0x00
3357 uint64 header_size
=
3358 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
3359 PACKET_4BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
3360 memset(packet
+ header_size
+ 1, 0x00, kMaxPacketSize
- header_size
- 1);
3362 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
3363 ASSERT_TRUE(data
!= NULL
);
3365 test::CompareCharArraysWithHexError("constructed packet",
3366 data
->data(), data
->length(),
3371 TEST_P(QuicFramerTest
, Build2ByteSequenceNumberPaddingFramePacket
) {
3372 QuicPacketHeader header
;
3373 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3374 header
.public_header
.reset_flag
= false;
3375 header
.public_header
.version_flag
= false;
3376 header
.fec_flag
= false;
3377 header
.entropy_flag
= false;
3378 header
.public_header
.sequence_number_length
= PACKET_2BYTE_SEQUENCE_NUMBER
;
3379 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
3380 header
.fec_group
= 0;
3382 QuicPaddingFrame padding_frame
;
3385 frames
.push_back(QuicFrame(&padding_frame
));
3387 unsigned char packet
[kMaxPacketSize
] = {
3388 // public flags (8 byte connection_id and 2 byte sequence number)
3391 0x10, 0x32, 0x54, 0x76,
3392 0x98, 0xBA, 0xDC, 0xFE,
3393 // packet sequence number
3398 // frame type (padding frame)
3400 0x00, 0x00, 0x00, 0x00
3403 uint64 header_size
=
3404 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
3405 PACKET_2BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
3406 memset(packet
+ header_size
+ 1, 0x00, kMaxPacketSize
- header_size
- 1);
3408 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
3409 ASSERT_TRUE(data
!= NULL
);
3411 test::CompareCharArraysWithHexError("constructed packet",
3412 data
->data(), data
->length(),
3417 TEST_P(QuicFramerTest
, Build1ByteSequenceNumberPaddingFramePacket
) {
3418 QuicPacketHeader header
;
3419 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3420 header
.public_header
.reset_flag
= false;
3421 header
.public_header
.version_flag
= false;
3422 header
.fec_flag
= false;
3423 header
.entropy_flag
= false;
3424 header
.public_header
.sequence_number_length
= PACKET_1BYTE_SEQUENCE_NUMBER
;
3425 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
3426 header
.fec_group
= 0;
3428 QuicPaddingFrame padding_frame
;
3431 frames
.push_back(QuicFrame(&padding_frame
));
3433 unsigned char packet
[kMaxPacketSize
] = {
3434 // public flags (8 byte connection_id and 1 byte sequence number)
3437 0x10, 0x32, 0x54, 0x76,
3438 0x98, 0xBA, 0xDC, 0xFE,
3439 // packet sequence number
3444 // frame type (padding frame)
3446 0x00, 0x00, 0x00, 0x00
3449 uint64 header_size
=
3450 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
3451 PACKET_1BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
3452 memset(packet
+ header_size
+ 1, 0x00, kMaxPacketSize
- header_size
- 1);
3454 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
3455 ASSERT_TRUE(data
!= NULL
);
3457 test::CompareCharArraysWithHexError("constructed packet",
3458 data
->data(), data
->length(),
3463 TEST_P(QuicFramerTest
, BuildStreamFramePacket
) {
3464 QuicPacketHeader header
;
3465 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3466 header
.public_header
.reset_flag
= false;
3467 header
.public_header
.version_flag
= false;
3468 header
.fec_flag
= false;
3469 header
.entropy_flag
= true;
3470 header
.packet_sequence_number
= GG_UINT64_C(0x77123456789ABC);
3471 header
.fec_group
= 0;
3473 QuicStreamFrame stream_frame
;
3474 stream_frame
.stream_id
= 0x01020304;
3475 stream_frame
.fin
= true;
3476 stream_frame
.offset
= GG_UINT64_C(0xBA98FEDC32107654);
3477 stream_frame
.data
= MakeIOVector("hello world!");
3480 frames
.push_back(QuicFrame(&stream_frame
));
3482 unsigned char packet
[] = {
3483 // public flags (8 byte connection_id)
3486 0x10, 0x32, 0x54, 0x76,
3487 0x98, 0xBA, 0xDC, 0xFE,
3488 // packet sequence number
3489 0xBC, 0x9A, 0x78, 0x56,
3491 // private flags (entropy)
3494 // frame type (stream frame with fin and no length)
3497 0x04, 0x03, 0x02, 0x01,
3499 0x54, 0x76, 0x10, 0x32,
3500 0xDC, 0xFE, 0x98, 0xBA,
3507 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
3508 ASSERT_TRUE(data
!= NULL
);
3510 test::CompareCharArraysWithHexError("constructed packet",
3511 data
->data(), data
->length(),
3512 AsChars(packet
), arraysize(packet
));
3515 TEST_P(QuicFramerTest
, BuildStreamFramePacketInFecGroup
) {
3516 QuicPacketHeader header
;
3517 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3518 header
.public_header
.reset_flag
= false;
3519 header
.public_header
.version_flag
= false;
3520 header
.fec_flag
= false;
3521 header
.entropy_flag
= true;
3522 header
.packet_sequence_number
= GG_UINT64_C(0x77123456789ABC);
3523 header
.is_in_fec_group
= IN_FEC_GROUP
;
3524 header
.fec_group
= GG_UINT64_C(0x77123456789ABC);
3526 QuicStreamFrame stream_frame
;
3527 stream_frame
.stream_id
= 0x01020304;
3528 stream_frame
.fin
= true;
3529 stream_frame
.offset
= GG_UINT64_C(0xBA98FEDC32107654);
3530 stream_frame
.data
= MakeIOVector("hello world!");
3533 frames
.push_back(QuicFrame(&stream_frame
));
3534 unsigned char packet
[] = {
3535 // public flags (8 byte connection_id)
3538 0x10, 0x32, 0x54, 0x76,
3539 0x98, 0xBA, 0xDC, 0xFE,
3540 // packet sequence number
3541 0xBC, 0x9A, 0x78, 0x56,
3543 // private flags (entropy, is_in_fec_group)
3547 // frame type (stream frame with fin and data length field)
3550 0x04, 0x03, 0x02, 0x01,
3552 0x54, 0x76, 0x10, 0x32,
3553 0xDC, 0xFE, 0x98, 0xBA,
3554 // data length (since packet is in an FEC group)
3562 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
3563 ASSERT_TRUE(data
!= NULL
);
3565 test::CompareCharArraysWithHexError("constructed packet",
3566 data
->data(), data
->length(),
3567 AsChars(packet
), arraysize(packet
));
3570 TEST_P(QuicFramerTest
, BuildStreamFramePacketWithVersionFlag
) {
3571 QuicPacketHeader header
;
3572 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3573 header
.public_header
.reset_flag
= false;
3574 header
.public_header
.version_flag
= true;
3575 header
.fec_flag
= false;
3576 header
.entropy_flag
= true;
3577 header
.packet_sequence_number
= GG_UINT64_C(0x77123456789ABC);
3578 header
.fec_group
= 0;
3580 QuicStreamFrame stream_frame
;
3581 stream_frame
.stream_id
= 0x01020304;
3582 stream_frame
.fin
= true;
3583 stream_frame
.offset
= GG_UINT64_C(0xBA98FEDC32107654);
3584 stream_frame
.data
= MakeIOVector("hello world!");
3587 frames
.push_back(QuicFrame(&stream_frame
));
3589 unsigned char packet
[] = {
3590 // public flags (version, 8 byte connection_id)
3593 0x10, 0x32, 0x54, 0x76,
3594 0x98, 0xBA, 0xDC, 0xFE,
3596 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
3597 // packet sequence number
3598 0xBC, 0x9A, 0x78, 0x56,
3600 // private flags (entropy)
3603 // frame type (stream frame with fin and no length)
3606 0x04, 0x03, 0x02, 0x01,
3608 0x54, 0x76, 0x10, 0x32,
3609 0xDC, 0xFE, 0x98, 0xBA,
3616 QuicFramerPeer::SetIsServer(&framer_
, false);
3617 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
3618 ASSERT_TRUE(data
!= NULL
);
3620 test::CompareCharArraysWithHexError("constructed packet",
3621 data
->data(), data
->length(),
3622 AsChars(packet
), arraysize(packet
));
3625 TEST_P(QuicFramerTest
, BuildVersionNegotiationPacket
) {
3626 QuicPacketPublicHeader header
;
3627 header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3628 header
.reset_flag
= false;
3629 header
.version_flag
= true;
3631 unsigned char packet
[] = {
3632 // public flags (version, 8 byte connection_id)
3635 0x10, 0x32, 0x54, 0x76,
3636 0x98, 0xBA, 0xDC, 0xFE,
3638 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
3641 QuicVersionVector versions
;
3642 versions
.push_back(GetParam());
3643 scoped_ptr
<QuicEncryptedPacket
> data(
3644 framer_
.BuildVersionNegotiationPacket(header
, versions
));
3646 test::CompareCharArraysWithHexError("constructed packet",
3647 data
->data(), data
->length(),
3648 AsChars(packet
), arraysize(packet
));
3651 TEST_P(QuicFramerTest
, BuildAckFramePacketv22
) {
3652 if (version_
> QUIC_VERSION_22
) {
3655 QuicPacketHeader header
;
3656 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3657 header
.public_header
.reset_flag
= false;
3658 header
.public_header
.version_flag
= false;
3659 header
.fec_flag
= false;
3660 header
.entropy_flag
= true;
3661 header
.packet_sequence_number
= GG_UINT64_C(0x770123456789AA8);
3662 header
.fec_group
= 0;
3664 QuicAckFrame ack_frame
;
3665 ack_frame
.entropy_hash
= 0x43;
3666 ack_frame
.largest_observed
= GG_UINT64_C(0x770123456789ABF);
3667 ack_frame
.delta_time_largest_observed
= QuicTime::Delta::Zero();
3668 ack_frame
.missing_packets
.insert(
3669 GG_UINT64_C(0x770123456789ABE));
3672 frames
.push_back(QuicFrame(&ack_frame
));
3674 unsigned char packet
[] = {
3675 // public flags (8 byte connection_id)
3678 0x10, 0x32, 0x54, 0x76,
3679 0x98, 0xBA, 0xDC, 0xFE,
3680 // packet sequence number
3681 0xA8, 0x9A, 0x78, 0x56,
3683 // private flags (entropy)
3686 // frame type (ack frame)
3687 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
3689 // entropy hash of all received packets.
3691 // largest observed packet sequence number
3692 0xBF, 0x9A, 0x78, 0x56,
3696 // num missing packet ranges
3698 // missing packet delta
3700 // 0 more missing packets in range.
3702 // 0 revived packets.
3706 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
3707 ASSERT_TRUE(data
!= NULL
);
3709 test::CompareCharArraysWithHexError("constructed packet",
3710 data
->data(), data
->length(),
3711 AsChars(packet
), arraysize(packet
));
3714 TEST_P(QuicFramerTest
, BuildAckFramePacket
) {
3715 if (version_
<= QUIC_VERSION_22
) {
3718 QuicPacketHeader header
;
3719 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3720 header
.public_header
.reset_flag
= false;
3721 header
.public_header
.version_flag
= false;
3722 header
.fec_flag
= false;
3723 header
.entropy_flag
= true;
3724 header
.packet_sequence_number
= GG_UINT64_C(0x770123456789AA8);
3725 header
.fec_group
= 0;
3727 QuicAckFrame ack_frame
;
3728 ack_frame
.entropy_hash
= 0x43;
3729 ack_frame
.largest_observed
= GG_UINT64_C(0x770123456789ABF);
3730 ack_frame
.delta_time_largest_observed
= QuicTime::Delta::Zero();
3731 ack_frame
.missing_packets
.insert(
3732 GG_UINT64_C(0x770123456789ABE));
3735 frames
.push_back(QuicFrame(&ack_frame
));
3737 unsigned char packet
[] = {
3738 // public flags (8 byte connection_id)
3741 0x10, 0x32, 0x54, 0x76,
3742 0x98, 0xBA, 0xDC, 0xFE,
3743 // packet sequence number
3744 0xA8, 0x9A, 0x78, 0x56,
3746 // private flags (entropy)
3749 // frame type (ack frame)
3750 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
3752 // entropy hash of all received packets.
3754 // largest observed packet sequence number
3755 0xBF, 0x9A, 0x78, 0x56,
3759 // num received packets.
3761 // num missing packet ranges
3763 // missing packet delta
3765 // 0 more missing packets in range.
3767 // 0 revived packets.
3771 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
3772 ASSERT_TRUE(data
!= NULL
);
3774 test::CompareCharArraysWithHexError("constructed packet",
3775 data
->data(), data
->length(),
3776 AsChars(packet
), arraysize(packet
));
3779 // TODO(jri): Add test for tuncated packets in which the original ack frame had
3780 // revived packets. (In both the large and small packet cases below).
3782 TEST_P(QuicFramerTest
, BuildTruncatedAckFrameLargePacketv22
) {
3783 if (version_
> QUIC_VERSION_22
) {
3786 QuicPacketHeader header
;
3787 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3788 header
.public_header
.reset_flag
= false;
3789 header
.public_header
.version_flag
= false;
3790 header
.fec_flag
= false;
3791 header
.entropy_flag
= true;
3792 header
.packet_sequence_number
= GG_UINT64_C(0x770123456789AA8);
3793 header
.fec_group
= 0;
3795 QuicAckFrame ack_frame
;
3796 // This entropy hash is different from what shows up in the packet below,
3797 // since entropy is recomputed by the framer on ack truncation (by
3798 // TestEntropyCalculator for this test.)
3799 ack_frame
.entropy_hash
= 0x43;
3800 ack_frame
.largest_observed
= 2 * 300;
3801 ack_frame
.delta_time_largest_observed
= QuicTime::Delta::Zero();
3802 for (size_t i
= 1; i
< 2 * 300; i
+= 2) {
3803 ack_frame
.missing_packets
.insert(i
);
3807 frames
.push_back(QuicFrame(&ack_frame
));
3809 unsigned char packet
[] = {
3810 // public flags (8 byte connection_id)
3813 0x10, 0x32, 0x54, 0x76,
3814 0x98, 0xBA, 0xDC, 0xFE,
3815 // packet sequence number
3816 0xA8, 0x9A, 0x78, 0x56,
3818 // private flags (entropy)
3821 // frame type (ack frame)
3822 // (has nacks, is truncated, 2 byte largest observed, 1 byte delta)
3824 // entropy hash of all received packets, set to 1 by TestEntropyCalculator
3825 // since ack is truncated.
3827 // 2-byte largest observed packet sequence number.
3828 // Expected to be 510 (0x1FE), since only 255 nack ranges can fit.
3832 // num missing packet ranges (limited to 255 by size of this field).
3834 // {missing packet delta, further missing packets in range}
3835 // 6 nack ranges x 42 + 3 nack ranges
3836 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3837 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3838 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3839 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3840 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3841 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3842 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3843 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3844 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3845 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3847 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3848 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3849 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3850 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3851 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3852 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3853 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3854 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3855 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3856 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3858 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3859 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3860 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3861 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3862 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3863 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3864 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3865 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3866 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3867 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3869 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3870 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3871 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3872 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3873 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3874 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3875 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3876 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3877 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3878 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3880 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3881 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3882 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3884 // 0 revived packets.
3888 scoped_ptr
<QuicPacket
> data(
3889 framer_
.BuildDataPacket(header
, frames
, kMaxPacketSize
).packet
);
3890 ASSERT_TRUE(data
!= NULL
);
3892 test::CompareCharArraysWithHexError("constructed packet",
3893 data
->data(), data
->length(),
3894 AsChars(packet
), arraysize(packet
));
3897 TEST_P(QuicFramerTest
, BuildTruncatedAckFrameLargePacket
) {
3898 if (version_
<= QUIC_VERSION_22
) {
3901 QuicPacketHeader header
;
3902 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3903 header
.public_header
.reset_flag
= false;
3904 header
.public_header
.version_flag
= false;
3905 header
.fec_flag
= false;
3906 header
.entropy_flag
= true;
3907 header
.packet_sequence_number
= GG_UINT64_C(0x770123456789AA8);
3908 header
.fec_group
= 0;
3910 QuicAckFrame ack_frame
;
3911 // This entropy hash is different from what shows up in the packet below,
3912 // since entropy is recomputed by the framer on ack truncation (by
3913 // TestEntropyCalculator for this test.)
3914 ack_frame
.entropy_hash
= 0x43;
3915 ack_frame
.largest_observed
= 2 * 300;
3916 ack_frame
.delta_time_largest_observed
= QuicTime::Delta::Zero();
3917 for (size_t i
= 1; i
< 2 * 300; i
+= 2) {
3918 ack_frame
.missing_packets
.insert(i
);
3922 frames
.push_back(QuicFrame(&ack_frame
));
3924 unsigned char packet
[] = {
3925 // public flags (8 byte connection_id)
3928 0x10, 0x32, 0x54, 0x76,
3929 0x98, 0xBA, 0xDC, 0xFE,
3930 // packet sequence number
3931 0xA8, 0x9A, 0x78, 0x56,
3933 // private flags (entropy)
3936 // frame type (ack frame)
3937 // (has nacks, is truncated, 2 byte largest observed, 1 byte delta)
3939 // entropy hash of all received packets, set to 1 by TestEntropyCalculator
3940 // since ack is truncated.
3942 // 2-byte largest observed packet sequence number.
3943 // Expected to be 510 (0x1FE), since only 255 nack ranges can fit.
3947 // num missing packet ranges (limited to 255 by size of this field).
3949 // {missing packet delta, further missing packets in range}
3950 // 6 nack ranges x 42 + 3 nack ranges
3951 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3952 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3953 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3954 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3955 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3956 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3957 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3958 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3959 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3960 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3962 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3963 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3964 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3965 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3966 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3967 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3968 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3969 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3970 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3971 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3973 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3974 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3975 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3976 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3977 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3978 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3979 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3980 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3981 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3982 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3984 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3985 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3986 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3987 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3988 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3989 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3990 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3991 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3992 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3993 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3995 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3996 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3997 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3999 // 0 revived packets.
4003 scoped_ptr
<QuicPacket
> data(
4004 framer_
.BuildDataPacket(header
, frames
, kMaxPacketSize
).packet
);
4005 ASSERT_TRUE(data
!= NULL
);
4007 test::CompareCharArraysWithHexError("constructed packet",
4008 data
->data(), data
->length(),
4009 AsChars(packet
), arraysize(packet
));
4013 TEST_P(QuicFramerTest
, BuildTruncatedAckFrameSmallPacketv22
) {
4014 if (version_
> QUIC_VERSION_22
) {
4017 QuicPacketHeader header
;
4018 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4019 header
.public_header
.reset_flag
= false;
4020 header
.public_header
.version_flag
= false;
4021 header
.fec_flag
= false;
4022 header
.entropy_flag
= true;
4023 header
.packet_sequence_number
= GG_UINT64_C(0x770123456789AA8);
4024 header
.fec_group
= 0;
4026 QuicAckFrame ack_frame
;
4027 // This entropy hash is different from what shows up in the packet below,
4028 // since entropy is recomputed by the framer on ack truncation (by
4029 // TestEntropyCalculator for this test.)
4030 ack_frame
.entropy_hash
= 0x43;
4031 ack_frame
.largest_observed
= 2 * 300;
4032 ack_frame
.delta_time_largest_observed
= QuicTime::Delta::Zero();
4033 for (size_t i
= 1; i
< 2 * 300; i
+= 2) {
4034 ack_frame
.missing_packets
.insert(i
);
4038 frames
.push_back(QuicFrame(&ack_frame
));
4040 unsigned char packet
[] = {
4041 // public flags (8 byte connection_id)
4044 0x10, 0x32, 0x54, 0x76,
4045 0x98, 0xBA, 0xDC, 0xFE,
4046 // packet sequence number
4047 0xA8, 0x9A, 0x78, 0x56,
4049 // private flags (entropy)
4052 // frame type (ack frame)
4053 // (has nacks, is truncated, 2 byte largest observed, 1 byte delta)
4055 // entropy hash of all received packets, set to 1 by TestEntropyCalculator
4056 // since ack is truncated.
4058 // 2-byte largest observed packet sequence number.
4059 // Expected to be 12 (0x0C), since only 6 nack ranges can fit.
4063 // num missing packet ranges (limited to 6 by packet size of 37).
4065 // {missing packet delta, further missing packets in range}
4067 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
4068 // 0 revived packets.
4072 scoped_ptr
<QuicPacket
> data(
4073 framer_
.BuildDataPacket(header
, frames
, 37u).packet
);
4074 ASSERT_TRUE(data
!= NULL
);
4075 // Expect 1 byte unused since at least 2 bytes are needed to fit more nacks.
4076 EXPECT_EQ(36u, data
->length());
4077 test::CompareCharArraysWithHexError("constructed packet",
4078 data
->data(), data
->length(),
4079 AsChars(packet
), arraysize(packet
));
4082 TEST_P(QuicFramerTest
, BuildTruncatedAckFrameSmallPacket
) {
4083 if (version_
<= QUIC_VERSION_22
) {
4086 QuicPacketHeader header
;
4087 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4088 header
.public_header
.reset_flag
= false;
4089 header
.public_header
.version_flag
= false;
4090 header
.fec_flag
= false;
4091 header
.entropy_flag
= true;
4092 header
.packet_sequence_number
= GG_UINT64_C(0x770123456789AA8);
4093 header
.fec_group
= 0;
4095 QuicAckFrame ack_frame
;
4096 // This entropy hash is different from what shows up in the packet below,
4097 // since entropy is recomputed by the framer on ack truncation (by
4098 // TestEntropyCalculator for this test.)
4099 ack_frame
.entropy_hash
= 0x43;
4100 ack_frame
.largest_observed
= 2 * 300;
4101 ack_frame
.delta_time_largest_observed
= QuicTime::Delta::Zero();
4102 for (size_t i
= 1; i
< 2 * 300; i
+= 2) {
4103 ack_frame
.missing_packets
.insert(i
);
4107 frames
.push_back(QuicFrame(&ack_frame
));
4109 unsigned char packet
[] = {
4110 // public flags (8 byte connection_id)
4113 0x10, 0x32, 0x54, 0x76,
4114 0x98, 0xBA, 0xDC, 0xFE,
4115 // packet sequence number
4116 0xA8, 0x9A, 0x78, 0x56,
4118 // private flags (entropy)
4121 // frame type (ack frame)
4122 // (has nacks, is truncated, 2 byte largest observed, 1 byte delta)
4124 // entropy hash of all received packets, set to 1 by TestEntropyCalculator
4125 // since ack is truncated.
4127 // 2-byte largest observed packet sequence number.
4128 // Expected to be 12 (0x0C), since only 6 nack ranges can fit.
4132 // num missing packet ranges (limited to 6 by packet size of 37).
4134 // {missing packet delta, further missing packets in range}
4136 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
4137 // 0 revived packets.
4141 scoped_ptr
<QuicPacket
> data(
4142 framer_
.BuildDataPacket(header
, frames
, 37u).packet
);
4143 ASSERT_TRUE(data
!= NULL
);
4144 // Expect 1 byte unused since at least 2 bytes are needed to fit more nacks.
4145 EXPECT_EQ(36u, data
->length());
4146 test::CompareCharArraysWithHexError("constructed packet",
4147 data
->data(), data
->length(),
4148 AsChars(packet
), arraysize(packet
));
4151 TEST_P(QuicFramerTest
, BuildCongestionFeedbackFramePacketTCP
) {
4152 QuicPacketHeader header
;
4153 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4154 header
.public_header
.reset_flag
= false;
4155 header
.public_header
.version_flag
= false;
4156 header
.fec_flag
= false;
4157 header
.entropy_flag
= false;
4158 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
4159 header
.fec_group
= 0;
4161 QuicCongestionFeedbackFrame congestion_feedback_frame
;
4162 congestion_feedback_frame
.type
= kTCP
;
4163 congestion_feedback_frame
.tcp
.receive_window
= 0x4030;
4166 frames
.push_back(QuicFrame(&congestion_feedback_frame
));
4168 unsigned char packet
[] = {
4169 // public flags (8 byte connection_id)
4172 0x10, 0x32, 0x54, 0x76,
4173 0x98, 0xBA, 0xDC, 0xFE,
4174 // packet sequence number
4175 0xBC, 0x9A, 0x78, 0x56,
4180 // frame type (congestion feedback frame)
4182 // congestion feedback type (TCP)
4184 // TCP receive window
4188 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
4189 ASSERT_TRUE(data
!= NULL
);
4191 test::CompareCharArraysWithHexError("constructed packet",
4192 data
->data(), data
->length(),
4193 AsChars(packet
), arraysize(packet
));
4196 TEST_P(QuicFramerTest
, BuildStopWaitingPacket
) {
4197 QuicPacketHeader header
;
4198 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4199 header
.public_header
.reset_flag
= false;
4200 header
.public_header
.version_flag
= false;
4201 header
.fec_flag
= false;
4202 header
.entropy_flag
= true;
4203 header
.packet_sequence_number
= GG_UINT64_C(0x770123456789AA8);
4204 header
.fec_group
= 0;
4206 QuicStopWaitingFrame stop_waiting_frame
;
4207 stop_waiting_frame
.entropy_hash
= 0x14;
4208 stop_waiting_frame
.least_unacked
= GG_UINT64_C(0x770123456789AA0);
4211 frames
.push_back(QuicFrame(&stop_waiting_frame
));
4213 unsigned char packet
[] = {
4214 // public flags (8 byte connection_id)
4217 0x10, 0x32, 0x54, 0x76,
4218 0x98, 0xBA, 0xDC, 0xFE,
4219 // packet sequence number
4220 0xA8, 0x9A, 0x78, 0x56,
4222 // private flags (entropy)
4225 // frame type (stop waiting frame)
4227 // entropy hash of sent packets till least awaiting - 1.
4229 // least packet sequence number awaiting an ack, delta from sequence number.
4230 0x08, 0x00, 0x00, 0x00,
4234 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
4235 ASSERT_TRUE(data
!= NULL
);
4237 test::CompareCharArraysWithHexError("constructed packet",
4238 data
->data(), data
->length(),
4239 AsChars(packet
), arraysize(packet
));
4242 TEST_P(QuicFramerTest
, BuildCongestionFeedbackFramePacketInvalidFeedback
) {
4243 QuicPacketHeader header
;
4244 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4245 header
.public_header
.reset_flag
= false;
4246 header
.public_header
.version_flag
= false;
4247 header
.fec_flag
= false;
4248 header
.entropy_flag
= false;
4249 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
4250 header
.fec_group
= 0;
4252 QuicCongestionFeedbackFrame congestion_feedback_frame
;
4253 congestion_feedback_frame
.type
=
4254 static_cast<CongestionFeedbackType
>(kTCP
+ 1);
4257 frames
.push_back(QuicFrame(&congestion_feedback_frame
));
4259 scoped_ptr
<QuicPacket
> data
;
4261 data
.reset(BuildDataPacket(header
, frames
)),
4262 "AppendCongestionFeedbackFrame failed");
4263 ASSERT_TRUE(data
== NULL
);
4266 TEST_P(QuicFramerTest
, BuildRstFramePacketQuic
) {
4267 QuicPacketHeader header
;
4268 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4269 header
.public_header
.reset_flag
= false;
4270 header
.public_header
.version_flag
= false;
4271 header
.fec_flag
= false;
4272 header
.entropy_flag
= false;
4273 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
4274 header
.fec_group
= 0;
4276 QuicRstStreamFrame rst_frame
;
4277 rst_frame
.stream_id
= 0x01020304;
4278 rst_frame
.error_code
= static_cast<QuicRstStreamErrorCode
>(0x05060708);
4279 rst_frame
.error_details
= "because I can";
4280 rst_frame
.byte_offset
= 0x0807060504030201;
4282 unsigned char packet
[] = {
4283 // public flags (8 byte connection_id)
4286 0x10, 0x32, 0x54, 0x76,
4287 0x98, 0xBA, 0xDC, 0xFE,
4288 // packet sequence number
4289 0xBC, 0x9A, 0x78, 0x56,
4294 // frame type (rst stream frame)
4297 0x04, 0x03, 0x02, 0x01,
4299 0x01, 0x02, 0x03, 0x04,
4300 0x05, 0x06, 0x07, 0x08,
4302 0x08, 0x07, 0x06, 0x05,
4303 // error details length
4313 frames
.push_back(QuicFrame(&rst_frame
));
4315 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
4316 ASSERT_TRUE(data
!= NULL
);
4318 test::CompareCharArraysWithHexError("constructed packet",
4319 data
->data(), data
->length(),
4320 AsChars(packet
), arraysize(packet
));
4323 TEST_P(QuicFramerTest
, BuildCloseFramePacket
) {
4324 QuicPacketHeader header
;
4325 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4326 header
.public_header
.reset_flag
= false;
4327 header
.public_header
.version_flag
= false;
4328 header
.fec_flag
= false;
4329 header
.entropy_flag
= true;
4330 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
4331 header
.fec_group
= 0;
4333 QuicConnectionCloseFrame close_frame
;
4334 close_frame
.error_code
= static_cast<QuicErrorCode
>(0x05060708);
4335 close_frame
.error_details
= "because I can";
4338 frames
.push_back(QuicFrame(&close_frame
));
4340 unsigned char packet
[] = {
4341 // public flags (8 byte connection_id)
4344 0x10, 0x32, 0x54, 0x76,
4345 0x98, 0xBA, 0xDC, 0xFE,
4346 // packet sequence number
4347 0xBC, 0x9A, 0x78, 0x56,
4349 // private flags (entropy)
4352 // frame type (connection close frame)
4355 0x08, 0x07, 0x06, 0x05,
4356 // error details length
4365 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
4366 ASSERT_TRUE(data
!= NULL
);
4368 test::CompareCharArraysWithHexError("constructed packet",
4369 data
->data(), data
->length(),
4370 AsChars(packet
), arraysize(packet
));
4373 TEST_P(QuicFramerTest
, BuildGoAwayPacket
) {
4374 QuicPacketHeader header
;
4375 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4376 header
.public_header
.reset_flag
= false;
4377 header
.public_header
.version_flag
= false;
4378 header
.fec_flag
= false;
4379 header
.entropy_flag
= true;
4380 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
4381 header
.fec_group
= 0;
4383 QuicGoAwayFrame goaway_frame
;
4384 goaway_frame
.error_code
= static_cast<QuicErrorCode
>(0x05060708);
4385 goaway_frame
.last_good_stream_id
= 0x01020304;
4386 goaway_frame
.reason_phrase
= "because I can";
4389 frames
.push_back(QuicFrame(&goaway_frame
));
4391 unsigned char packet
[] = {
4392 // public flags (8 byte connection_id)
4395 0x10, 0x32, 0x54, 0x76,
4396 0x98, 0xBA, 0xDC, 0xFE,
4397 // packet sequence number
4398 0xBC, 0x9A, 0x78, 0x56,
4400 // private flags(entropy)
4403 // frame type (go away frame)
4406 0x08, 0x07, 0x06, 0x05,
4408 0x04, 0x03, 0x02, 0x01,
4409 // error details length
4418 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
4419 ASSERT_TRUE(data
!= NULL
);
4421 test::CompareCharArraysWithHexError("constructed packet",
4422 data
->data(), data
->length(),
4423 AsChars(packet
), arraysize(packet
));
4426 TEST_P(QuicFramerTest
, BuildWindowUpdatePacket
) {
4427 QuicPacketHeader header
;
4428 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4429 header
.public_header
.reset_flag
= false;
4430 header
.public_header
.version_flag
= false;
4431 header
.fec_flag
= false;
4432 header
.entropy_flag
= true;
4433 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
4434 header
.fec_group
= 0;
4436 QuicWindowUpdateFrame window_update_frame
;
4437 window_update_frame
.stream_id
= 0x01020304;
4438 window_update_frame
.byte_offset
= 0x1122334455667788;
4441 frames
.push_back(QuicFrame(&window_update_frame
));
4443 unsigned char packet
[] = {
4444 // public flags (8 byte connection_id)
4447 0x10, 0x32, 0x54, 0x76,
4448 0x98, 0xBA, 0xDC, 0xFE,
4449 // packet sequence number
4450 0xBC, 0x9A, 0x78, 0x56,
4452 // private flags(entropy)
4455 // frame type (window update frame)
4458 0x04, 0x03, 0x02, 0x01,
4460 0x88, 0x77, 0x66, 0x55,
4461 0x44, 0x33, 0x22, 0x11,
4464 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
4465 ASSERT_TRUE(data
!= NULL
);
4467 test::CompareCharArraysWithHexError("constructed packet", data
->data(),
4468 data
->length(), AsChars(packet
),
4472 TEST_P(QuicFramerTest
, BuildBlockedPacket
) {
4473 QuicPacketHeader header
;
4474 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4475 header
.public_header
.reset_flag
= false;
4476 header
.public_header
.version_flag
= false;
4477 header
.fec_flag
= false;
4478 header
.entropy_flag
= true;
4479 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
4480 header
.fec_group
= 0;
4482 QuicBlockedFrame blocked_frame
;
4483 blocked_frame
.stream_id
= 0x01020304;
4486 frames
.push_back(QuicFrame(&blocked_frame
));
4488 unsigned char packet
[] = {
4489 // public flags (8 byte connection_id)
4492 0x10, 0x32, 0x54, 0x76,
4493 0x98, 0xBA, 0xDC, 0xFE,
4494 // packet sequence number
4495 0xBC, 0x9A, 0x78, 0x56,
4497 // private flags(entropy)
4500 // frame type (blocked frame)
4503 0x04, 0x03, 0x02, 0x01,
4506 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
4507 ASSERT_TRUE(data
!= NULL
);
4509 test::CompareCharArraysWithHexError("constructed packet", data
->data(),
4510 data
->length(), AsChars(packet
),
4514 TEST_P(QuicFramerTest
, BuildPingPacket
) {
4515 QuicPacketHeader header
;
4516 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4517 header
.public_header
.reset_flag
= false;
4518 header
.public_header
.version_flag
= false;
4519 header
.fec_flag
= false;
4520 header
.entropy_flag
= true;
4521 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
4522 header
.fec_group
= 0;
4524 QuicPingFrame ping_frame
;
4527 frames
.push_back(QuicFrame(&ping_frame
));
4529 unsigned char packet
[] = {
4530 // public flags (8 byte connection_id)
4533 0x10, 0x32, 0x54, 0x76,
4534 0x98, 0xBA, 0xDC, 0xFE,
4535 // packet sequence number
4536 0xBC, 0x9A, 0x78, 0x56,
4538 // private flags(entropy)
4541 // frame type (ping frame)
4545 if (version_
>= QUIC_VERSION_18
) {
4546 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
4547 ASSERT_TRUE(data
!= NULL
);
4549 test::CompareCharArraysWithHexError("constructed packet", data
->data(),
4550 data
->length(), AsChars(packet
),
4553 string expected_error
=
4554 "Attempt to add a PingFrame in " + QuicVersionToString(version_
);
4555 EXPECT_DFATAL(BuildDataPacket(header
, frames
),
4561 TEST_P(QuicFramerTest
, BuildPublicResetPacket
) {
4562 QuicPublicResetPacket reset_packet
;
4563 reset_packet
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4564 reset_packet
.public_header
.reset_flag
= true;
4565 reset_packet
.public_header
.version_flag
= false;
4566 reset_packet
.rejected_sequence_number
= GG_UINT64_C(0x123456789ABC);
4567 reset_packet
.nonce_proof
= GG_UINT64_C(0xABCDEF0123456789);
4569 unsigned char packet
[] = {
4570 // public flags (public reset, 8 byte ConnectionId)
4573 0x10, 0x32, 0x54, 0x76,
4574 0x98, 0xBA, 0xDC, 0xFE,
4575 // message tag (kPRST)
4577 // num_entries (2) + padding
4578 0x02, 0x00, 0x00, 0x00,
4582 0x08, 0x00, 0x00, 0x00,
4586 0x10, 0x00, 0x00, 0x00,
4588 0x89, 0x67, 0x45, 0x23,
4589 0x01, 0xEF, 0xCD, 0xAB,
4590 // rejected sequence number
4591 0xBC, 0x9A, 0x78, 0x56,
4592 0x34, 0x12, 0x00, 0x00,
4595 scoped_ptr
<QuicEncryptedPacket
> data(
4596 framer_
.BuildPublicResetPacket(reset_packet
));
4597 ASSERT_TRUE(data
!= NULL
);
4599 test::CompareCharArraysWithHexError("constructed packet",
4600 data
->data(), data
->length(),
4601 AsChars(packet
), arraysize(packet
));
4604 TEST_P(QuicFramerTest
, BuildPublicResetPacketWithClientAddress
) {
4605 QuicPublicResetPacket reset_packet
;
4606 reset_packet
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4607 reset_packet
.public_header
.reset_flag
= true;
4608 reset_packet
.public_header
.version_flag
= false;
4609 reset_packet
.rejected_sequence_number
= GG_UINT64_C(0x123456789ABC);
4610 reset_packet
.nonce_proof
= GG_UINT64_C(0xABCDEF0123456789);
4611 reset_packet
.client_address
= IPEndPoint(Loopback4(), 0x1234);
4613 unsigned char packet
[] = {
4614 // public flags (public reset, 8 byte ConnectionId)
4617 0x10, 0x32, 0x54, 0x76,
4618 0x98, 0xBA, 0xDC, 0xFE,
4619 // message tag (kPRST)
4621 // num_entries (3) + padding
4622 0x03, 0x00, 0x00, 0x00,
4626 0x08, 0x00, 0x00, 0x00,
4630 0x10, 0x00, 0x00, 0x00,
4634 0x18, 0x00, 0x00, 0x00,
4636 0x89, 0x67, 0x45, 0x23,
4637 0x01, 0xEF, 0xCD, 0xAB,
4638 // rejected sequence number
4639 0xBC, 0x9A, 0x78, 0x56,
4640 0x34, 0x12, 0x00, 0x00,
4643 0x7F, 0x00, 0x00, 0x01,
4647 scoped_ptr
<QuicEncryptedPacket
> data(
4648 framer_
.BuildPublicResetPacket(reset_packet
));
4649 ASSERT_TRUE(data
!= NULL
);
4651 test::CompareCharArraysWithHexError("constructed packet",
4652 data
->data(), data
->length(),
4653 AsChars(packet
), arraysize(packet
));
4656 TEST_P(QuicFramerTest
, BuildFecPacket
) {
4657 QuicPacketHeader header
;
4658 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4659 header
.public_header
.reset_flag
= false;
4660 header
.public_header
.version_flag
= false;
4661 header
.fec_flag
= true;
4662 header
.entropy_flag
= true;
4663 header
.packet_sequence_number
= (GG_UINT64_C(0x123456789ABC));
4664 header
.is_in_fec_group
= IN_FEC_GROUP
;
4665 header
.fec_group
= GG_UINT64_C(0x123456789ABB);;
4667 QuicFecData fec_data
;
4668 fec_data
.fec_group
= 1;
4669 fec_data
.redundancy
= "abcdefghijklmnop";
4671 unsigned char packet
[] = {
4672 // public flags (8 byte connection_id)
4675 0x10, 0x32, 0x54, 0x76,
4676 0x98, 0xBA, 0xDC, 0xFE,
4677 // packet sequence number
4678 0xBC, 0x9A, 0x78, 0x56,
4680 // private flags (entropy & fec group & fec packet)
4682 // first fec protected packet offset
4692 scoped_ptr
<QuicPacket
> data(
4693 framer_
.BuildFecPacket(header
, fec_data
).packet
);
4694 ASSERT_TRUE(data
!= NULL
);
4696 test::CompareCharArraysWithHexError("constructed packet",
4697 data
->data(), data
->length(),
4698 AsChars(packet
), arraysize(packet
));
4701 TEST_P(QuicFramerTest
, EncryptPacket
) {
4702 QuicPacketSequenceNumber sequence_number
= GG_UINT64_C(0x123456789ABC);
4703 unsigned char packet
[] = {
4704 // public flags (8 byte connection_id)
4707 0x10, 0x32, 0x54, 0x76,
4708 0x98, 0xBA, 0xDC, 0xFE,
4709 // packet sequence number
4710 0xBC, 0x9A, 0x78, 0x56,
4712 // private flags (fec group & fec packet)
4714 // first fec protected packet offset
4724 scoped_ptr
<QuicPacket
> raw(
4725 QuicPacket::NewDataPacket(AsChars(packet
), arraysize(packet
), false,
4726 PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
4727 PACKET_6BYTE_SEQUENCE_NUMBER
));
4728 scoped_ptr
<QuicEncryptedPacket
> encrypted(
4729 framer_
.EncryptPacket(ENCRYPTION_NONE
, sequence_number
, *raw
));
4731 ASSERT_TRUE(encrypted
.get() != NULL
);
4732 EXPECT_TRUE(CheckEncryption(sequence_number
, raw
.get()));
4735 TEST_P(QuicFramerTest
, EncryptPacketWithVersionFlag
) {
4736 QuicPacketSequenceNumber sequence_number
= GG_UINT64_C(0x123456789ABC);
4737 unsigned char packet
[] = {
4738 // public flags (version, 8 byte connection_id)
4741 0x10, 0x32, 0x54, 0x76,
4742 0x98, 0xBA, 0xDC, 0xFE,
4745 // packet sequence number
4746 0xBC, 0x9A, 0x78, 0x56,
4748 // private flags (fec group & fec flags)
4750 // first fec protected packet offset
4760 scoped_ptr
<QuicPacket
> raw(
4761 QuicPacket::NewDataPacket(AsChars(packet
), arraysize(packet
), false,
4762 PACKET_8BYTE_CONNECTION_ID
, kIncludeVersion
,
4763 PACKET_6BYTE_SEQUENCE_NUMBER
));
4764 scoped_ptr
<QuicEncryptedPacket
> encrypted(
4765 framer_
.EncryptPacket(ENCRYPTION_NONE
, sequence_number
, *raw
));
4767 ASSERT_TRUE(encrypted
.get() != NULL
);
4768 EXPECT_TRUE(CheckEncryption(sequence_number
, raw
.get()));
4771 TEST_P(QuicFramerTest
, AckTruncationLargePacket
) {
4772 QuicPacketHeader header
;
4773 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4774 header
.public_header
.reset_flag
= false;
4775 header
.public_header
.version_flag
= false;
4776 header
.fec_flag
= false;
4777 header
.entropy_flag
= false;
4778 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
4779 header
.fec_group
= 0;
4781 // Create a packet with just the ack.
4782 QuicAckFrame ack_frame
= MakeAckFrameWithNackRanges(300, 0u);
4784 frame
.type
= ACK_FRAME
;
4785 frame
.ack_frame
= &ack_frame
;
4787 frames
.push_back(frame
);
4789 // Build an ack packet with truncation due to limit in number of nack ranges.
4790 scoped_ptr
<QuicPacket
> raw_ack_packet(
4791 framer_
.BuildDataPacket(header
, frames
, kMaxPacketSize
).packet
);
4792 ASSERT_TRUE(raw_ack_packet
!= NULL
);
4793 scoped_ptr
<QuicEncryptedPacket
> ack_packet(
4794 framer_
.EncryptPacket(ENCRYPTION_NONE
, header
.packet_sequence_number
,
4796 // Now make sure we can turn our ack packet back into an ack frame.
4797 ASSERT_TRUE(framer_
.ProcessPacket(*ack_packet
));
4798 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
4799 QuicAckFrame
& processed_ack_frame
= *visitor_
.ack_frames_
[0];
4800 EXPECT_TRUE(processed_ack_frame
.is_truncated
);
4801 EXPECT_EQ(510u, processed_ack_frame
.largest_observed
);
4802 ASSERT_EQ(255u, processed_ack_frame
.missing_packets
.size());
4803 SequenceNumberSet::const_iterator missing_iter
=
4804 processed_ack_frame
.missing_packets
.begin();
4805 EXPECT_EQ(1u, *missing_iter
);
4806 SequenceNumberSet::const_reverse_iterator last_missing_iter
=
4807 processed_ack_frame
.missing_packets
.rbegin();
4808 EXPECT_EQ(509u, *last_missing_iter
);
4811 TEST_P(QuicFramerTest
, AckTruncationSmallPacketv22
) {
4812 if (version_
> QUIC_VERSION_22
) {
4815 QuicPacketHeader header
;
4816 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4817 header
.public_header
.reset_flag
= false;
4818 header
.public_header
.version_flag
= false;
4819 header
.fec_flag
= false;
4820 header
.entropy_flag
= false;
4821 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
4822 header
.fec_group
= 0;
4824 // Create a packet with just the ack.
4825 QuicAckFrame ack_frame
= MakeAckFrameWithNackRanges(300, 0u);
4827 frame
.type
= ACK_FRAME
;
4828 frame
.ack_frame
= &ack_frame
;
4830 frames
.push_back(frame
);
4832 // Build an ack packet with truncation due to limit in number of nack ranges.
4833 scoped_ptr
<QuicPacket
> raw_ack_packet(
4834 framer_
.BuildDataPacket(header
, frames
, 500).packet
);
4835 ASSERT_TRUE(raw_ack_packet
!= NULL
);
4836 scoped_ptr
<QuicEncryptedPacket
> ack_packet(
4837 framer_
.EncryptPacket(ENCRYPTION_NONE
, header
.packet_sequence_number
,
4839 // Now make sure we can turn our ack packet back into an ack frame.
4840 ASSERT_TRUE(framer_
.ProcessPacket(*ack_packet
));
4841 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
4842 QuicAckFrame
& processed_ack_frame
= *visitor_
.ack_frames_
[0];
4843 EXPECT_TRUE(processed_ack_frame
.is_truncated
);
4844 EXPECT_EQ(476u, processed_ack_frame
.largest_observed
);
4845 ASSERT_EQ(238u, processed_ack_frame
.missing_packets
.size());
4846 SequenceNumberSet::const_iterator missing_iter
=
4847 processed_ack_frame
.missing_packets
.begin();
4848 EXPECT_EQ(1u, *missing_iter
);
4849 SequenceNumberSet::const_reverse_iterator last_missing_iter
=
4850 processed_ack_frame
.missing_packets
.rbegin();
4851 EXPECT_EQ(475u, *last_missing_iter
);
4855 TEST_P(QuicFramerTest
, AckTruncationSmallPacket
) {
4856 if (version_
<= QUIC_VERSION_22
) {
4859 QuicPacketHeader header
;
4860 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4861 header
.public_header
.reset_flag
= false;
4862 header
.public_header
.version_flag
= false;
4863 header
.fec_flag
= false;
4864 header
.entropy_flag
= false;
4865 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
4866 header
.fec_group
= 0;
4868 // Create a packet with just the ack.
4869 QuicAckFrame ack_frame
= MakeAckFrameWithNackRanges(300, 0u);
4871 frame
.type
= ACK_FRAME
;
4872 frame
.ack_frame
= &ack_frame
;
4874 frames
.push_back(frame
);
4876 // Build an ack packet with truncation due to limit in number of nack ranges.
4877 scoped_ptr
<QuicPacket
> raw_ack_packet(
4878 framer_
.BuildDataPacket(header
, frames
, 500).packet
);
4879 ASSERT_TRUE(raw_ack_packet
!= NULL
);
4880 scoped_ptr
<QuicEncryptedPacket
> ack_packet(
4881 framer_
.EncryptPacket(ENCRYPTION_NONE
, header
.packet_sequence_number
,
4883 // Now make sure we can turn our ack packet back into an ack frame.
4884 ASSERT_TRUE(framer_
.ProcessPacket(*ack_packet
));
4885 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
4886 QuicAckFrame
& processed_ack_frame
= *visitor_
.ack_frames_
[0];
4887 EXPECT_TRUE(processed_ack_frame
.is_truncated
);
4888 EXPECT_EQ(476u, processed_ack_frame
.largest_observed
);
4889 ASSERT_EQ(238u, processed_ack_frame
.missing_packets
.size());
4890 SequenceNumberSet::const_iterator missing_iter
=
4891 processed_ack_frame
.missing_packets
.begin();
4892 EXPECT_EQ(1u, *missing_iter
);
4893 SequenceNumberSet::const_reverse_iterator last_missing_iter
=
4894 processed_ack_frame
.missing_packets
.rbegin();
4895 EXPECT_EQ(475u, *last_missing_iter
);
4898 TEST_P(QuicFramerTest
, CleanTruncation
) {
4899 QuicPacketHeader header
;
4900 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4901 header
.public_header
.reset_flag
= false;
4902 header
.public_header
.version_flag
= false;
4903 header
.fec_flag
= false;
4904 header
.entropy_flag
= true;
4905 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
4906 header
.fec_group
= 0;
4908 QuicAckFrame ack_frame
;
4909 ack_frame
.largest_observed
= 201;
4910 for (uint64 i
= 1; i
< ack_frame
.largest_observed
; ++i
) {
4911 ack_frame
.missing_packets
.insert(i
);
4914 // Create a packet with just the ack.
4916 frame
.type
= ACK_FRAME
;
4917 frame
.ack_frame
= &ack_frame
;
4919 frames
.push_back(frame
);
4921 scoped_ptr
<QuicPacket
> raw_ack_packet(BuildDataPacket(header
, frames
));
4922 ASSERT_TRUE(raw_ack_packet
!= NULL
);
4924 scoped_ptr
<QuicEncryptedPacket
> ack_packet(
4925 framer_
.EncryptPacket(ENCRYPTION_NONE
, header
.packet_sequence_number
,
4928 // Now make sure we can turn our ack packet back into an ack frame.
4929 ASSERT_TRUE(framer_
.ProcessPacket(*ack_packet
));
4931 // Test for clean truncation of the ack by comparing the length of the
4932 // original packets to the re-serialized packets.
4934 frame
.type
= ACK_FRAME
;
4935 frame
.ack_frame
= visitor_
.ack_frames_
[0];
4936 frames
.push_back(frame
);
4938 size_t original_raw_length
= raw_ack_packet
->length();
4939 raw_ack_packet
.reset(BuildDataPacket(header
, frames
));
4940 ASSERT_TRUE(raw_ack_packet
!= NULL
);
4941 EXPECT_EQ(original_raw_length
, raw_ack_packet
->length());
4942 ASSERT_TRUE(raw_ack_packet
!= NULL
);
4945 TEST_P(QuicFramerTest
, EntropyFlagTest
) {
4946 unsigned char packet
[] = {
4947 // public flags (8 byte connection_id)
4950 0x10, 0x32, 0x54, 0x76,
4951 0x98, 0xBA, 0xDC, 0xFE,
4952 // packet sequence number
4953 0xBC, 0x9A, 0x78, 0x56,
4955 // private flags (Entropy)
4958 // frame type (stream frame with fin and no length)
4961 0x04, 0x03, 0x02, 0x01,
4963 0x54, 0x76, 0x10, 0x32,
4964 0xDC, 0xFE, 0x98, 0xBA,
4971 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
4972 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
4973 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
4974 ASSERT_TRUE(visitor_
.header_
.get());
4975 EXPECT_TRUE(visitor_
.header_
->entropy_flag
);
4976 EXPECT_EQ(1 << 4, visitor_
.header_
->entropy_hash
);
4977 EXPECT_FALSE(visitor_
.header_
->fec_flag
);
4980 TEST_P(QuicFramerTest
, FecEntropyTest
) {
4981 unsigned char packet
[] = {
4982 // public flags (8 byte connection_id)
4985 0x10, 0x32, 0x54, 0x76,
4986 0x98, 0xBA, 0xDC, 0xFE,
4987 // packet sequence number
4988 0xBC, 0x9A, 0x78, 0x56,
4990 // private flags (Entropy & fec group & FEC)
4992 // first fec protected packet offset
4995 // frame type (stream frame with fin and no length)
4998 0x04, 0x03, 0x02, 0x01,
5000 0x54, 0x76, 0x10, 0x32,
5001 0xDC, 0xFE, 0x98, 0xBA,
5008 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
5009 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
5010 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
5011 ASSERT_TRUE(visitor_
.header_
.get());
5012 EXPECT_TRUE(visitor_
.header_
->fec_flag
);
5013 EXPECT_TRUE(visitor_
.header_
->entropy_flag
);
5014 EXPECT_EQ(1 << 4, visitor_
.header_
->entropy_hash
);
5017 TEST_P(QuicFramerTest
, StopPacketProcessing
) {
5018 unsigned char packet
[] = {
5019 // public flags (8 byte connection_id)
5022 0x10, 0x32, 0x54, 0x76,
5023 0x98, 0xBA, 0xDC, 0xFE,
5024 // packet sequence number
5025 0xBC, 0x9A, 0x78, 0x56,
5030 // frame type (stream frame with fin)
5033 0x04, 0x03, 0x02, 0x01,
5035 0x54, 0x76, 0x10, 0x32,
5036 0xDC, 0xFE, 0x98, 0xBA,
5044 // frame type (ack frame)
5046 // entropy hash of sent packets till least awaiting - 1.
5048 // least packet sequence number awaiting an ack
5049 0xA0, 0x9A, 0x78, 0x56,
5051 // entropy hash of all received packets.
5053 // largest observed packet sequence number
5054 0xBF, 0x9A, 0x78, 0x56,
5056 // num missing packets
5059 0xBE, 0x9A, 0x78, 0x56,
5063 MockFramerVisitor visitor
;
5064 framer_
.set_visitor(&visitor
);
5065 EXPECT_CALL(visitor
, OnPacket());
5066 EXPECT_CALL(visitor
, OnPacketHeader(_
));
5067 EXPECT_CALL(visitor
, OnStreamFrame(_
)).WillOnce(Return(false));
5068 EXPECT_CALL(visitor
, OnAckFrame(_
)).Times(0);
5069 EXPECT_CALL(visitor
, OnPacketComplete());
5070 EXPECT_CALL(visitor
, OnUnauthenticatedPublicHeader(_
)).WillOnce(Return(true));
5072 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
5073 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
5074 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());