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.
10 #include "base/containers/hash_tables.h"
11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/port.h"
14 #include "base/stl_util.h"
15 #include "net/quic/crypto/quic_decrypter.h"
16 #include "net/quic/crypto/quic_encrypter.h"
17 #include "net/quic/quic_framer.h"
18 #include "net/quic/quic_protocol.h"
19 #include "net/quic/quic_utils.h"
20 #include "net/quic/test_tools/quic_framer_peer.h"
21 #include "net/quic/test_tools/quic_test_utils.h"
24 using base::StringPiece
;
27 using std::numeric_limits
;
31 using testing::Return
;
37 const QuicPacketSequenceNumber kEpoch
= GG_UINT64_C(1) << 48;
38 const QuicPacketSequenceNumber kMask
= kEpoch
- 1;
40 // Index into the guid offset in the header.
41 const size_t kGuidOffset
= kPublicFlagsSize
;
42 // Index into the version string in the header. (if present).
43 const size_t kVersionOffset
= kGuidOffset
+ PACKET_8BYTE_GUID
;
45 // Index into the sequence number offset in the header.
46 size_t GetSequenceNumberOffset(QuicGuidLength guid_length
,
47 bool include_version
) {
48 return kGuidOffset
+ guid_length
+
49 (include_version
? kQuicVersionSize
: 0);
52 size_t GetSequenceNumberOffset(bool include_version
) {
53 return GetSequenceNumberOffset(PACKET_8BYTE_GUID
, include_version
);
56 // Index into the private flags offset in the data packet header.
57 size_t GetPrivateFlagsOffset(QuicGuidLength guid_length
, bool include_version
) {
58 return GetSequenceNumberOffset(guid_length
, include_version
) +
59 PACKET_6BYTE_SEQUENCE_NUMBER
;
62 size_t GetPrivateFlagsOffset(bool include_version
) {
63 return GetPrivateFlagsOffset(PACKET_8BYTE_GUID
, include_version
);
66 size_t GetPrivateFlagsOffset(bool include_version
,
67 QuicSequenceNumberLength sequence_number_length
) {
68 return GetSequenceNumberOffset(PACKET_8BYTE_GUID
, include_version
) +
69 sequence_number_length
;
72 // Index into the fec group offset in the header.
73 size_t GetFecGroupOffset(QuicGuidLength guid_length
, bool include_version
) {
74 return GetPrivateFlagsOffset(guid_length
, include_version
) +
78 size_t GetFecGroupOffset(bool include_version
) {
79 return GetPrivateFlagsOffset(PACKET_8BYTE_GUID
, include_version
) +
83 size_t GetFecGroupOffset(bool include_version
,
84 QuicSequenceNumberLength sequence_number_length
) {
85 return GetPrivateFlagsOffset(include_version
, sequence_number_length
) +
89 // Index into the nonce proof of the public reset packet.
90 // Public resets always have full guids.
91 const size_t kPublicResetPacketNonceProofOffset
=
92 kGuidOffset
+ PACKET_8BYTE_GUID
;
94 // Index into the rejected sequence number of the public reset packet.
95 const size_t kPublicResetPacketRejectedSequenceNumberOffset
=
96 kPublicResetPacketNonceProofOffset
+ kPublicResetNonceSize
;
98 class TestEncrypter
: public QuicEncrypter
{
100 virtual ~TestEncrypter() {}
101 virtual bool SetKey(StringPiece key
) OVERRIDE
{
104 virtual bool SetNoncePrefix(StringPiece nonce_prefix
) OVERRIDE
{
107 virtual bool Encrypt(StringPiece nonce
,
108 StringPiece associated_data
,
109 StringPiece plaintext
,
110 unsigned char* output
) OVERRIDE
{
111 CHECK(false) << "Not implemented";
114 virtual QuicData
* EncryptPacket(QuicPacketSequenceNumber sequence_number
,
115 StringPiece associated_data
,
116 StringPiece plaintext
) OVERRIDE
{
117 sequence_number_
= sequence_number
;
118 associated_data_
= associated_data
.as_string();
119 plaintext_
= plaintext
.as_string();
120 return new QuicData(plaintext
.data(), plaintext
.length());
122 virtual size_t GetKeySize() const OVERRIDE
{
125 virtual size_t GetNoncePrefixSize() const OVERRIDE
{
128 virtual size_t GetMaxPlaintextSize(size_t ciphertext_size
) const OVERRIDE
{
129 return ciphertext_size
;
131 virtual size_t GetCiphertextSize(size_t plaintext_size
) const OVERRIDE
{
132 return plaintext_size
;
134 virtual StringPiece
GetKey() const OVERRIDE
{
135 return StringPiece();
137 virtual StringPiece
GetNoncePrefix() const OVERRIDE
{
138 return StringPiece();
140 QuicPacketSequenceNumber sequence_number_
;
141 string associated_data_
;
145 class TestDecrypter
: public QuicDecrypter
{
147 virtual ~TestDecrypter() {}
148 virtual bool SetKey(StringPiece key
) OVERRIDE
{
151 virtual bool SetNoncePrefix(StringPiece nonce_prefix
) OVERRIDE
{
154 virtual bool Decrypt(StringPiece nonce
,
155 StringPiece associated_data
,
156 StringPiece ciphertext
,
157 unsigned char* output
,
158 size_t* output_length
) OVERRIDE
{
159 CHECK(false) << "Not implemented";
162 virtual QuicData
* DecryptPacket(QuicPacketSequenceNumber sequence_number
,
163 StringPiece associated_data
,
164 StringPiece ciphertext
) OVERRIDE
{
165 sequence_number_
= sequence_number
;
166 associated_data_
= associated_data
.as_string();
167 ciphertext_
= ciphertext
.as_string();
168 return new QuicData(ciphertext
.data(), ciphertext
.length());
170 virtual StringPiece
GetKey() const OVERRIDE
{
171 return StringPiece();
173 virtual StringPiece
GetNoncePrefix() const OVERRIDE
{
174 return StringPiece();
176 QuicPacketSequenceNumber sequence_number_
;
177 string associated_data_
;
181 class TestQuicVisitor
: public ::net::QuicFramerVisitorInterface
{
185 version_mismatch_(0),
189 complete_packets_(0),
191 accept_packet_(true) {
194 virtual ~TestQuicVisitor() {
195 STLDeleteElements(&stream_frames_
);
196 STLDeleteElements(&ack_frames_
);
197 STLDeleteElements(&congestion_feedback_frames_
);
198 STLDeleteElements(&fec_data_
);
201 virtual void OnError(QuicFramer
* f
) OVERRIDE
{
202 DLOG(INFO
) << "QuicFramer Error: " << QuicUtils::ErrorToString(f
->error())
203 << " (" << f
->error() << ")";
207 virtual void OnPacket() OVERRIDE
{}
209 virtual void OnPublicResetPacket(
210 const QuicPublicResetPacket
& packet
) OVERRIDE
{
211 public_reset_packet_
.reset(new QuicPublicResetPacket(packet
));
214 virtual void OnVersionNegotiationPacket(
215 const QuicVersionNegotiationPacket
& packet
) OVERRIDE
{
216 version_negotiation_packet_
.reset(new QuicVersionNegotiationPacket(packet
));
219 virtual void OnRevivedPacket() OVERRIDE
{
223 virtual bool OnProtocolVersionMismatch(QuicVersion version
) OVERRIDE
{
224 DLOG(INFO
) << "QuicFramer Version Mismatch, version: " << version
;
229 virtual bool OnPacketHeader(const QuicPacketHeader
& header
) OVERRIDE
{
231 header_
.reset(new QuicPacketHeader(header
));
232 return accept_packet_
;
235 virtual bool OnUnauthenticatedHeader(
236 const QuicPacketHeader
& header
) OVERRIDE
{
240 virtual bool OnStreamFrame(const QuicStreamFrame
& frame
) OVERRIDE
{
242 stream_frames_
.push_back(new QuicStreamFrame(frame
));
246 virtual void OnFecProtectedPayload(StringPiece payload
) OVERRIDE
{
247 fec_protected_payload_
= payload
.as_string();
250 virtual bool OnAckFrame(const QuicAckFrame
& frame
) OVERRIDE
{
252 ack_frames_
.push_back(new QuicAckFrame(frame
));
256 virtual bool OnCongestionFeedbackFrame(
257 const QuicCongestionFeedbackFrame
& frame
) OVERRIDE
{
259 congestion_feedback_frames_
.push_back(
260 new QuicCongestionFeedbackFrame(frame
));
264 virtual void OnFecData(const QuicFecData
& fec
) OVERRIDE
{
266 fec_data_
.push_back(new QuicFecData(fec
));
269 virtual void OnPacketComplete() OVERRIDE
{
273 virtual bool OnRstStreamFrame(const QuicRstStreamFrame
& frame
) OVERRIDE
{
274 rst_stream_frame_
= frame
;
278 virtual bool OnConnectionCloseFrame(
279 const QuicConnectionCloseFrame
& frame
) OVERRIDE
{
280 connection_close_frame_
= frame
;
284 virtual bool OnGoAwayFrame(const QuicGoAwayFrame
& frame
) OVERRIDE
{
285 goaway_frame_
= frame
;
289 // Counters from the visitor_ callbacks.
291 int version_mismatch_
;
295 int complete_packets_
;
296 int revived_packets_
;
299 scoped_ptr
<QuicPacketHeader
> header_
;
300 scoped_ptr
<QuicPublicResetPacket
> public_reset_packet_
;
301 scoped_ptr
<QuicVersionNegotiationPacket
> version_negotiation_packet_
;
302 vector
<QuicStreamFrame
*> stream_frames_
;
303 vector
<QuicAckFrame
*> ack_frames_
;
304 vector
<QuicCongestionFeedbackFrame
*> congestion_feedback_frames_
;
305 vector
<QuicFecData
*> fec_data_
;
306 string fec_protected_payload_
;
307 QuicRstStreamFrame rst_stream_frame_
;
308 QuicConnectionCloseFrame connection_close_frame_
;
309 QuicGoAwayFrame goaway_frame_
;
312 class QuicFramerTest
: public ::testing::TestWithParam
<QuicVersion
> {
315 : encrypter_(new test::TestEncrypter()),
316 decrypter_(new test::TestDecrypter()),
317 start_(QuicTime::Zero().Add(QuicTime::Delta::FromMicroseconds(0x10))),
318 framer_(QuicSupportedVersions(), start_
, true) {
319 version_
= GetParam();
320 framer_
.set_version(version_
);
321 framer_
.SetDecrypter(decrypter_
);
322 framer_
.SetEncrypter(ENCRYPTION_NONE
, encrypter_
);
323 framer_
.set_visitor(&visitor_
);
324 framer_
.set_received_entropy_calculator(&entropy_calculator_
);
327 // Helper function to get unsigned char representation of digit in the
328 // units place of the current QUIC version number.
329 unsigned char GetQuicVersionDigitOnes() {
330 return static_cast<unsigned char> ('0' + version_
%10);
333 // Helper function to get unsigned char representation of digit in the
334 // tens place of the current QUIC version number.
335 unsigned char GetQuicVersionDigitTens() {
336 return static_cast<unsigned char> ('0' + (version_
/10)%10);
339 bool CheckEncryption(QuicPacketSequenceNumber sequence_number
,
340 QuicPacket
* packet
) {
341 if (sequence_number
!= encrypter_
->sequence_number_
) {
342 LOG(ERROR
) << "Encrypted incorrect packet sequence number. expected "
343 << sequence_number
<< " actual: "
344 << encrypter_
->sequence_number_
;
347 if (packet
->AssociatedData() != encrypter_
->associated_data_
) {
348 LOG(ERROR
) << "Encrypted incorrect associated data. expected "
349 << packet
->AssociatedData() << " actual: "
350 << encrypter_
->associated_data_
;
353 if (packet
->Plaintext() != encrypter_
->plaintext_
) {
354 LOG(ERROR
) << "Encrypted incorrect plaintext data. expected "
355 << packet
->Plaintext() << " actual: "
356 << encrypter_
->plaintext_
;
362 bool CheckDecryption(const QuicEncryptedPacket
& encrypted
,
363 bool includes_version
) {
364 if (visitor_
.header_
->packet_sequence_number
!=
365 decrypter_
->sequence_number_
) {
366 LOG(ERROR
) << "Decrypted incorrect packet sequence number. expected "
367 << visitor_
.header_
->packet_sequence_number
<< " actual: "
368 << decrypter_
->sequence_number_
;
371 if (QuicFramer::GetAssociatedDataFromEncryptedPacket(
372 encrypted
, PACKET_8BYTE_GUID
,
373 includes_version
, PACKET_6BYTE_SEQUENCE_NUMBER
) !=
374 decrypter_
->associated_data_
) {
375 LOG(ERROR
) << "Decrypted incorrect associated data. expected "
376 << QuicFramer::GetAssociatedDataFromEncryptedPacket(
377 encrypted
, PACKET_8BYTE_GUID
,
378 includes_version
, PACKET_6BYTE_SEQUENCE_NUMBER
)
379 << " actual: " << decrypter_
->associated_data_
;
382 StringPiece
ciphertext(encrypted
.AsStringPiece().substr(
383 GetStartOfEncryptedData(PACKET_8BYTE_GUID
, includes_version
,
384 PACKET_6BYTE_SEQUENCE_NUMBER
)));
385 if (ciphertext
!= decrypter_
->ciphertext_
) {
386 LOG(ERROR
) << "Decrypted incorrect ciphertext data. expected "
387 << ciphertext
<< " actual: "
388 << decrypter_
->ciphertext_
;
394 char* AsChars(unsigned char* data
) {
395 return reinterpret_cast<char*>(data
);
398 void CheckProcessingFails(unsigned char* packet
,
400 string expected_error
,
401 QuicErrorCode error_code
) {
402 QuicEncryptedPacket
encrypted(AsChars(packet
), len
, false);
403 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
)) << "len: " << len
;
404 EXPECT_EQ(expected_error
, framer_
.detailed_error()) << "len: " << len
;
405 EXPECT_EQ(error_code
, framer_
.error()) << "len: " << len
;
408 // Checks if the supplied string matches data in the supplied StreamFrame.
409 void CheckStreamFrameData(string str
, QuicStreamFrame
* frame
) {
410 scoped_ptr
<string
> frame_data(frame
->GetDataAsString());
411 EXPECT_EQ(str
, *frame_data
);
414 void CheckStreamFrameBoundaries(unsigned char* packet
,
415 size_t stream_id_size
,
416 bool include_version
) {
417 // Now test framing boundaries
418 for (size_t i
= kQuicFrameTypeSize
;
419 i
< GetMinStreamFrameSize(framer_
.version()); ++i
) {
420 string expected_error
;
421 if (i
< kQuicFrameTypeSize
+ stream_id_size
) {
422 expected_error
= "Unable to read stream_id.";
423 } else if (i
< kQuicFrameTypeSize
+ stream_id_size
+
424 kQuicMaxStreamOffsetSize
) {
425 expected_error
= "Unable to read offset.";
427 expected_error
= "Unable to read frame data.";
429 CheckProcessingFails(
431 i
+ GetPacketHeaderSize(PACKET_8BYTE_GUID
, include_version
,
432 PACKET_6BYTE_SEQUENCE_NUMBER
,
434 expected_error
, QUIC_INVALID_STREAM_DATA
);
438 void CheckCalculatePacketSequenceNumber(
439 QuicPacketSequenceNumber expected_sequence_number
,
440 QuicPacketSequenceNumber last_sequence_number
) {
441 QuicPacketSequenceNumber wire_sequence_number
=
442 expected_sequence_number
& kMask
;
443 QuicFramerPeer::SetLastSequenceNumber(&framer_
, last_sequence_number
);
444 EXPECT_EQ(expected_sequence_number
,
445 QuicFramerPeer::CalculatePacketSequenceNumberFromWire(
446 &framer_
, PACKET_6BYTE_SEQUENCE_NUMBER
, wire_sequence_number
))
447 << "last_sequence_number: " << last_sequence_number
448 << " wire_sequence_number: " << wire_sequence_number
;
451 test::TestEncrypter
* encrypter_
;
452 test::TestDecrypter
* decrypter_
;
453 QuicVersion version_
;
456 test::TestQuicVisitor visitor_
;
457 test::TestEntropyCalculator entropy_calculator_
;
460 // Run all framer tests with all supported versions of QUIC.
461 INSTANTIATE_TEST_CASE_P(QuicFramerTests
,
463 ::testing::ValuesIn(kSupportedQuicVersions
));
465 TEST_P(QuicFramerTest
, CalculatePacketSequenceNumberFromWireNearEpochStart
) {
466 // A few quick manual sanity checks
467 CheckCalculatePacketSequenceNumber(GG_UINT64_C(1), GG_UINT64_C(0));
468 CheckCalculatePacketSequenceNumber(kEpoch
+ 1, kMask
);
469 CheckCalculatePacketSequenceNumber(kEpoch
, kMask
);
471 // Cases where the last number was close to the start of the range
472 for (uint64 last
= 0; last
< 10; last
++) {
473 // Small numbers should not wrap (even if they're out of order).
474 for (uint64 j
= 0; j
< 10; j
++) {
475 CheckCalculatePacketSequenceNumber(j
, last
);
478 // Large numbers should not wrap either (because we're near 0 already).
479 for (uint64 j
= 0; j
< 10; j
++) {
480 CheckCalculatePacketSequenceNumber(kEpoch
- 1 - j
, last
);
485 TEST_P(QuicFramerTest
, CalculatePacketSequenceNumberFromWireNearEpochEnd
) {
486 // Cases where the last number was close to the end of the range
487 for (uint64 i
= 0; i
< 10; i
++) {
488 QuicPacketSequenceNumber last
= kEpoch
- i
;
490 // Small numbers should wrap.
491 for (uint64 j
= 0; j
< 10; j
++) {
492 CheckCalculatePacketSequenceNumber(kEpoch
+ j
, last
);
495 // Large numbers should not (even if they're out of order).
496 for (uint64 j
= 0; j
< 10; j
++) {
497 CheckCalculatePacketSequenceNumber(kEpoch
- 1 - j
, last
);
502 // Next check where we're in a non-zero epoch to verify we handle
503 // reverse wrapping, too.
504 TEST_P(QuicFramerTest
, CalculatePacketSequenceNumberFromWireNearPrevEpoch
) {
505 const uint64 prev_epoch
= 1 * kEpoch
;
506 const uint64 cur_epoch
= 2 * kEpoch
;
507 // Cases where the last number was close to the start of the range
508 for (uint64 i
= 0; i
< 10; i
++) {
509 uint64 last
= cur_epoch
+ i
;
510 // Small number should not wrap (even if they're out of order).
511 for (uint64 j
= 0; j
< 10; j
++) {
512 CheckCalculatePacketSequenceNumber(cur_epoch
+ j
, last
);
515 // But large numbers should reverse wrap.
516 for (uint64 j
= 0; j
< 10; j
++) {
517 uint64 num
= kEpoch
- 1 - j
;
518 CheckCalculatePacketSequenceNumber(prev_epoch
+ num
, last
);
523 TEST_P(QuicFramerTest
, CalculatePacketSequenceNumberFromWireNearNextEpoch
) {
524 const uint64 cur_epoch
= 2 * kEpoch
;
525 const uint64 next_epoch
= 3 * kEpoch
;
526 // Cases where the last number was close to the end of the range
527 for (uint64 i
= 0; i
< 10; i
++) {
528 QuicPacketSequenceNumber last
= next_epoch
- 1 - i
;
530 // Small numbers should wrap.
531 for (uint64 j
= 0; j
< 10; j
++) {
532 CheckCalculatePacketSequenceNumber(next_epoch
+ j
, last
);
535 // but large numbers should not (even if they're out of order).
536 for (uint64 j
= 0; j
< 10; j
++) {
537 uint64 num
= kEpoch
- 1 - j
;
538 CheckCalculatePacketSequenceNumber(cur_epoch
+ num
, last
);
543 TEST_P(QuicFramerTest
, CalculatePacketSequenceNumberFromWireNearNextMax
) {
544 const uint64 max_number
= numeric_limits
<uint64
>::max();
545 const uint64 max_epoch
= max_number
& ~kMask
;
547 // Cases where the last number was close to the end of the range
548 for (uint64 i
= 0; i
< 10; i
++) {
549 // Subtract 1, because the expected next sequence number is 1 more than the
550 // last sequence number.
551 QuicPacketSequenceNumber last
= max_number
- i
- 1;
553 // Small numbers should not wrap, because they have nowhere to go.
554 for (uint64 j
= 0; j
< 10; j
++) {
555 CheckCalculatePacketSequenceNumber(max_epoch
+ j
, last
);
558 // Large numbers should not wrap either.
559 for (uint64 j
= 0; j
< 10; j
++) {
560 uint64 num
= kEpoch
- 1 - j
;
561 CheckCalculatePacketSequenceNumber(max_epoch
+ num
, last
);
566 TEST_P(QuicFramerTest
, EmptyPacket
) {
567 char packet
[] = { 0x00 };
568 QuicEncryptedPacket
encrypted(packet
, 0, false);
569 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
570 EXPECT_EQ(QUIC_INVALID_PACKET_HEADER
, framer_
.error());
573 TEST_P(QuicFramerTest
, LargePacket
) {
574 unsigned char packet
[kMaxPacketSize
+ 1] = {
575 // public flags (8 byte guid)
578 0x10, 0x32, 0x54, 0x76,
579 0x98, 0xBA, 0xDC, 0xFE,
580 // packet sequence number
581 0xBC, 0x9A, 0x78, 0x56,
587 memset(packet
+ GetPacketHeaderSize(
588 PACKET_8BYTE_GUID
, !kIncludeVersion
,
589 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
), 0,
590 kMaxPacketSize
- GetPacketHeaderSize(
591 PACKET_8BYTE_GUID
, !kIncludeVersion
,
592 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
) + 1);
594 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
595 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
597 ASSERT_TRUE(visitor_
.header_
.get());
598 // Make sure we've parsed the packet header, so we can send an error.
599 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
600 visitor_
.header_
->public_header
.guid
);
601 // Make sure the correct error is propagated.
602 EXPECT_EQ(QUIC_PACKET_TOO_LARGE
, framer_
.error());
605 TEST_P(QuicFramerTest
, PacketHeader
) {
606 unsigned char packet
[] = {
607 // public flags (8 byte guid)
610 0x10, 0x32, 0x54, 0x76,
611 0x98, 0xBA, 0xDC, 0xFE,
612 // packet sequence number
613 0xBC, 0x9A, 0x78, 0x56,
619 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
620 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
621 EXPECT_EQ(QUIC_MISSING_PAYLOAD
, framer_
.error());
622 ASSERT_TRUE(visitor_
.header_
.get());
623 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
624 visitor_
.header_
->public_header
.guid
);
625 EXPECT_FALSE(visitor_
.header_
->public_header
.reset_flag
);
626 EXPECT_FALSE(visitor_
.header_
->public_header
.version_flag
);
627 EXPECT_FALSE(visitor_
.header_
->fec_flag
);
628 EXPECT_FALSE(visitor_
.header_
->entropy_flag
);
629 EXPECT_EQ(0, visitor_
.header_
->entropy_hash
);
630 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
631 visitor_
.header_
->packet_sequence_number
);
632 EXPECT_EQ(NOT_IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
633 EXPECT_EQ(0x00u
, visitor_
.header_
->fec_group
);
635 // Now test framing boundaries
637 i
< GetPacketHeaderSize(PACKET_8BYTE_GUID
, !kIncludeVersion
,
638 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
640 string expected_error
;
641 if (i
< kGuidOffset
) {
642 expected_error
= "Unable to read public flags.";
643 } else if (i
< GetSequenceNumberOffset(!kIncludeVersion
)) {
644 expected_error
= "Unable to read GUID.";
645 } else if (i
< GetPrivateFlagsOffset(!kIncludeVersion
)) {
646 expected_error
= "Unable to read sequence number.";
647 } else if (i
< GetFecGroupOffset(!kIncludeVersion
)) {
648 expected_error
= "Unable to read private flags.";
650 expected_error
= "Unable to read first fec protected packet offset.";
652 CheckProcessingFails(packet
, i
, expected_error
, QUIC_INVALID_PACKET_HEADER
);
656 TEST_P(QuicFramerTest
, PacketHeaderWith4ByteGuid
) {
657 QuicFramerPeer::SetLastSerializedGuid(&framer_
,
658 GG_UINT64_C(0xFEDCBA9876543210));
660 unsigned char packet
[] = {
661 // public flags (4 byte guid)
664 0x10, 0x32, 0x54, 0x76,
665 // packet sequence number
666 0xBC, 0x9A, 0x78, 0x56,
672 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
673 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
674 EXPECT_EQ(QUIC_MISSING_PAYLOAD
, framer_
.error());
675 ASSERT_TRUE(visitor_
.header_
.get());
676 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
677 visitor_
.header_
->public_header
.guid
);
678 EXPECT_FALSE(visitor_
.header_
->public_header
.reset_flag
);
679 EXPECT_FALSE(visitor_
.header_
->public_header
.version_flag
);
680 EXPECT_FALSE(visitor_
.header_
->fec_flag
);
681 EXPECT_FALSE(visitor_
.header_
->entropy_flag
);
682 EXPECT_EQ(0, visitor_
.header_
->entropy_hash
);
683 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
684 visitor_
.header_
->packet_sequence_number
);
685 EXPECT_EQ(NOT_IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
686 EXPECT_EQ(0x00u
, visitor_
.header_
->fec_group
);
688 // Now test framing boundaries
690 i
< GetPacketHeaderSize(PACKET_4BYTE_GUID
, !kIncludeVersion
,
691 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
693 string expected_error
;
694 if (i
< kGuidOffset
) {
695 expected_error
= "Unable to read public flags.";
696 } else if (i
< GetSequenceNumberOffset(PACKET_4BYTE_GUID
,
698 expected_error
= "Unable to read GUID.";
699 } else if (i
< GetPrivateFlagsOffset(PACKET_4BYTE_GUID
,
701 expected_error
= "Unable to read sequence number.";
702 } else if (i
< GetFecGroupOffset(PACKET_4BYTE_GUID
, !kIncludeVersion
)) {
703 expected_error
= "Unable to read private flags.";
705 expected_error
= "Unable to read first fec protected packet offset.";
707 CheckProcessingFails(packet
, i
, expected_error
, QUIC_INVALID_PACKET_HEADER
);
711 TEST_P(QuicFramerTest
, PacketHeader1ByteGuid
) {
712 QuicFramerPeer::SetLastSerializedGuid(&framer_
,
713 GG_UINT64_C(0xFEDCBA9876543210));
715 unsigned char packet
[] = {
716 // public flags (1 byte guid)
720 // packet sequence number
721 0xBC, 0x9A, 0x78, 0x56,
727 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
728 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
729 EXPECT_EQ(QUIC_MISSING_PAYLOAD
, framer_
.error());
730 ASSERT_TRUE(visitor_
.header_
.get());
731 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
732 visitor_
.header_
->public_header
.guid
);
733 EXPECT_FALSE(visitor_
.header_
->public_header
.reset_flag
);
734 EXPECT_FALSE(visitor_
.header_
->public_header
.version_flag
);
735 EXPECT_FALSE(visitor_
.header_
->fec_flag
);
736 EXPECT_FALSE(visitor_
.header_
->entropy_flag
);
737 EXPECT_EQ(0, visitor_
.header_
->entropy_hash
);
738 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
739 visitor_
.header_
->packet_sequence_number
);
740 EXPECT_EQ(NOT_IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
741 EXPECT_EQ(0x00u
, visitor_
.header_
->fec_group
);
743 // Now test framing boundaries
745 i
< GetPacketHeaderSize(PACKET_1BYTE_GUID
, !kIncludeVersion
,
746 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
748 string expected_error
;
749 if (i
< kGuidOffset
) {
750 expected_error
= "Unable to read public flags.";
751 } else if (i
< GetSequenceNumberOffset(PACKET_1BYTE_GUID
,
753 expected_error
= "Unable to read GUID.";
754 } else if (i
< GetPrivateFlagsOffset(PACKET_1BYTE_GUID
, !kIncludeVersion
)) {
755 expected_error
= "Unable to read sequence number.";
756 } else if (i
< GetFecGroupOffset(PACKET_1BYTE_GUID
, !kIncludeVersion
)) {
757 expected_error
= "Unable to read private flags.";
759 expected_error
= "Unable to read first fec protected packet offset.";
761 CheckProcessingFails(packet
, i
, expected_error
, QUIC_INVALID_PACKET_HEADER
);
765 TEST_P(QuicFramerTest
, PacketHeaderWith0ByteGuid
) {
766 QuicFramerPeer::SetLastSerializedGuid(&framer_
,
767 GG_UINT64_C(0xFEDCBA9876543210));
769 unsigned char packet
[] = {
770 // public flags (0 byte guid)
773 // packet sequence number
774 0xBC, 0x9A, 0x78, 0x56,
780 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
781 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
782 EXPECT_EQ(QUIC_MISSING_PAYLOAD
, framer_
.error());
783 ASSERT_TRUE(visitor_
.header_
.get());
784 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
785 visitor_
.header_
->public_header
.guid
);
786 EXPECT_FALSE(visitor_
.header_
->public_header
.reset_flag
);
787 EXPECT_FALSE(visitor_
.header_
->public_header
.version_flag
);
788 EXPECT_FALSE(visitor_
.header_
->fec_flag
);
789 EXPECT_FALSE(visitor_
.header_
->entropy_flag
);
790 EXPECT_EQ(0, visitor_
.header_
->entropy_hash
);
791 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
792 visitor_
.header_
->packet_sequence_number
);
793 EXPECT_EQ(NOT_IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
794 EXPECT_EQ(0x00u
, visitor_
.header_
->fec_group
);
796 // Now test framing boundaries
798 i
< GetPacketHeaderSize(PACKET_0BYTE_GUID
, !kIncludeVersion
,
799 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
801 string expected_error
;
802 if (i
< kGuidOffset
) {
803 expected_error
= "Unable to read public flags.";
804 } else if (i
< GetSequenceNumberOffset(PACKET_0BYTE_GUID
,
806 expected_error
= "Unable to read GUID.";
807 } else if (i
< GetPrivateFlagsOffset(PACKET_0BYTE_GUID
, !kIncludeVersion
)) {
808 expected_error
= "Unable to read sequence number.";
809 } else if (i
< GetFecGroupOffset(PACKET_0BYTE_GUID
, !kIncludeVersion
)) {
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
, PacketHeaderWithVersionFlag
) {
819 unsigned char packet
[] = {
820 // public flags (version)
823 0x10, 0x32, 0x54, 0x76,
824 0x98, 0xBA, 0xDC, 0xFE,
826 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
827 // packet sequence number
828 0xBC, 0x9A, 0x78, 0x56,
834 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
835 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
836 EXPECT_EQ(QUIC_MISSING_PAYLOAD
, framer_
.error());
837 ASSERT_TRUE(visitor_
.header_
.get());
838 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
839 visitor_
.header_
->public_header
.guid
);
840 EXPECT_FALSE(visitor_
.header_
->public_header
.reset_flag
);
841 EXPECT_TRUE(visitor_
.header_
->public_header
.version_flag
);
842 EXPECT_EQ(GetParam(), visitor_
.header_
->public_header
.versions
[0]);
843 EXPECT_FALSE(visitor_
.header_
->fec_flag
);
844 EXPECT_FALSE(visitor_
.header_
->entropy_flag
);
845 EXPECT_EQ(0, visitor_
.header_
->entropy_hash
);
846 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
847 visitor_
.header_
->packet_sequence_number
);
848 EXPECT_EQ(NOT_IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
849 EXPECT_EQ(0x00u
, visitor_
.header_
->fec_group
);
851 // Now test framing boundaries
853 i
< GetPacketHeaderSize(PACKET_8BYTE_GUID
, kIncludeVersion
,
854 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
856 string expected_error
;
857 if (i
< kGuidOffset
) {
858 expected_error
= "Unable to read public flags.";
859 } else if (i
< kVersionOffset
) {
860 expected_error
= "Unable to read GUID.";
861 } else if (i
< GetSequenceNumberOffset(kIncludeVersion
)) {
862 expected_error
= "Unable to read protocol version.";
863 } else if (i
< GetPrivateFlagsOffset(kIncludeVersion
)) {
864 expected_error
= "Unable to read sequence number.";
865 } else if (i
< GetFecGroupOffset(kIncludeVersion
)) {
866 expected_error
= "Unable to read private flags.";
868 expected_error
= "Unable to read first fec protected packet offset.";
870 CheckProcessingFails(packet
, i
, expected_error
, QUIC_INVALID_PACKET_HEADER
);
874 TEST_P(QuicFramerTest
, PacketHeaderWith4ByteSequenceNumber
) {
875 QuicFramerPeer::SetLastSequenceNumber(&framer_
,
876 GG_UINT64_C(0x123456789ABA));
878 unsigned char packet
[] = {
879 // public flags (8 byte guid and 4 byte sequence number)
882 0x10, 0x32, 0x54, 0x76,
883 0x98, 0xBA, 0xDC, 0xFE,
884 // packet sequence number
885 0xBC, 0x9A, 0x78, 0x56,
890 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
891 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
892 EXPECT_EQ(QUIC_MISSING_PAYLOAD
, framer_
.error());
893 ASSERT_TRUE(visitor_
.header_
.get());
894 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
895 visitor_
.header_
->public_header
.guid
);
896 EXPECT_FALSE(visitor_
.header_
->public_header
.reset_flag
);
897 EXPECT_FALSE(visitor_
.header_
->public_header
.version_flag
);
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_GUID
, !kIncludeVersion
,
909 PACKET_4BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
911 string expected_error
;
912 if (i
< kGuidOffset
) {
913 expected_error
= "Unable to read public flags.";
914 } else if (i
< GetSequenceNumberOffset(!kIncludeVersion
)) {
915 expected_error
= "Unable to read GUID.";
916 } else if (i
< GetPrivateFlagsOffset(!kIncludeVersion
,
917 PACKET_4BYTE_SEQUENCE_NUMBER
)) {
918 expected_error
= "Unable to read sequence number.";
919 } else if (i
< GetFecGroupOffset(!kIncludeVersion
,
920 PACKET_4BYTE_SEQUENCE_NUMBER
)) {
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
, PacketHeaderWith2ByteSequenceNumber
) {
930 QuicFramerPeer::SetLastSequenceNumber(&framer_
,
931 GG_UINT64_C(0x123456789ABA));
933 unsigned char packet
[] = {
934 // public flags (8 byte guid and 2 byte sequence number)
937 0x10, 0x32, 0x54, 0x76,
938 0x98, 0xBA, 0xDC, 0xFE,
939 // packet sequence number
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
.guid
);
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_GUID
, !kIncludeVersion
,
964 PACKET_2BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
966 string expected_error
;
967 if (i
< kGuidOffset
) {
968 expected_error
= "Unable to read public flags.";
969 } else if (i
< GetSequenceNumberOffset(!kIncludeVersion
)) {
970 expected_error
= "Unable to read GUID.";
971 } else if (i
< GetPrivateFlagsOffset(!kIncludeVersion
,
972 PACKET_2BYTE_SEQUENCE_NUMBER
)) {
973 expected_error
= "Unable to read sequence number.";
974 } else if (i
< GetFecGroupOffset(!kIncludeVersion
,
975 PACKET_2BYTE_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
, PacketHeaderWith1ByteSequenceNumber
) {
985 QuicFramerPeer::SetLastSequenceNumber(&framer_
,
986 GG_UINT64_C(0x123456789ABA));
988 unsigned char packet
[] = {
989 // public flags (8 byte guid and 1 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
.guid
);
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_GUID
, !kIncludeVersion
,
1019 PACKET_1BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
1021 string expected_error
;
1022 if (i
< kGuidOffset
) {
1023 expected_error
= "Unable to read public flags.";
1024 } else if (i
< GetSequenceNumberOffset(!kIncludeVersion
)) {
1025 expected_error
= "Unable to read GUID.";
1026 } else if (i
< GetPrivateFlagsOffset(!kIncludeVersion
,
1027 PACKET_1BYTE_SEQUENCE_NUMBER
)) {
1028 expected_error
= "Unable to read sequence number.";
1029 } else if (i
< GetFecGroupOffset(!kIncludeVersion
,
1030 PACKET_1BYTE_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
, InvalidPublicFlag
) {
1040 unsigned char packet
[] = {
1041 // public flags, unknown flag at bit 6
1044 0x10, 0x32, 0x54, 0x76,
1045 0x98, 0xBA, 0xDC, 0xFE,
1046 // packet sequence number
1047 0xBC, 0x9A, 0x78, 0x56,
1052 // frame type (padding)
1054 0x00, 0x00, 0x00, 0x00
1056 CheckProcessingFails(packet
,
1058 "Illegal public flags value.",
1059 QUIC_INVALID_PACKET_HEADER
);
1062 TEST_P(QuicFramerTest
, InvalidPublicFlagWithMatchingVersions
) {
1063 unsigned char packet
[] = {
1064 // public flags (8 byte guid and version flag and an unknown flag)
1067 0x10, 0x32, 0x54, 0x76,
1068 0x98, 0xBA, 0xDC, 0xFE,
1070 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
1071 // packet sequence number
1072 0xBC, 0x9A, 0x78, 0x56,
1077 // frame type (padding)
1079 0x00, 0x00, 0x00, 0x00
1081 CheckProcessingFails(packet
,
1083 "Illegal public flags value.",
1084 QUIC_INVALID_PACKET_HEADER
);
1087 TEST_P(QuicFramerTest
, LargePublicFlagWithMismatchedVersions
) {
1088 unsigned char packet
[] = {
1089 // public flags (8 byte guid, version flag and an unknown flag)
1092 0x10, 0x32, 0x54, 0x76,
1093 0x98, 0xBA, 0xDC, 0xFE,
1096 // packet sequence number
1097 0xBC, 0x9A, 0x78, 0x56,
1102 // frame type (padding frame)
1104 0x00, 0x00, 0x00, 0x00
1106 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1107 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1108 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1109 ASSERT_TRUE(visitor_
.header_
.get());
1110 EXPECT_EQ(0, visitor_
.frame_count_
);
1111 EXPECT_EQ(1, visitor_
.version_mismatch_
);
1114 TEST_P(QuicFramerTest
, InvalidPrivateFlag
) {
1115 unsigned char packet
[] = {
1116 // public flags (8 byte guid)
1119 0x10, 0x32, 0x54, 0x76,
1120 0x98, 0xBA, 0xDC, 0xFE,
1121 // packet sequence number
1122 0xBC, 0x9A, 0x78, 0x56,
1127 // frame type (padding)
1129 0x00, 0x00, 0x00, 0x00
1131 CheckProcessingFails(packet
,
1133 "Illegal private flags value.",
1134 QUIC_INVALID_PACKET_HEADER
);
1137 TEST_P(QuicFramerTest
, InvalidFECGroupOffset
) {
1138 unsigned char packet
[] = {
1139 // public flags (8 byte guid)
1142 0x10, 0x32, 0x54, 0x76,
1143 0x98, 0xBA, 0xDC, 0xFE,
1144 // packet sequence number
1145 0x01, 0x00, 0x00, 0x00,
1147 // private flags (fec group)
1149 // first fec protected packet offset
1152 CheckProcessingFails(packet
,
1154 "First fec protected packet offset must be less "
1155 "than the sequence number.",
1156 QUIC_INVALID_PACKET_HEADER
);
1159 TEST_P(QuicFramerTest
, PaddingFrame
) {
1160 unsigned char packet
[] = {
1161 // public flags (8 byte guid)
1164 0x10, 0x32, 0x54, 0x76,
1165 0x98, 0xBA, 0xDC, 0xFE,
1166 // packet sequence number
1167 0xBC, 0x9A, 0x78, 0x56,
1172 // frame type (padding frame)
1174 // Ignored data (which in this case is a stream frame)
1175 // frame type (stream frame with fin)
1178 0x04, 0x03, 0x02, 0x01,
1180 0x54, 0x76, 0x10, 0x32,
1181 0xDC, 0xFE, 0x98, 0xBA,
1190 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1191 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1192 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1193 ASSERT_TRUE(visitor_
.header_
.get());
1194 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1196 ASSERT_EQ(0u, visitor_
.stream_frames_
.size());
1197 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
1198 // A packet with no frames is not acceptable.
1199 CheckProcessingFails(
1201 GetPacketHeaderSize(PACKET_8BYTE_GUID
, !kIncludeVersion
,
1202 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
1203 "Packet has no frames.", QUIC_MISSING_PAYLOAD
);
1206 TEST_P(QuicFramerTest
, StreamFrame
) {
1207 unsigned char packet
[] = {
1208 // public flags (8 byte guid)
1211 0x10, 0x32, 0x54, 0x76,
1212 0x98, 0xBA, 0xDC, 0xFE,
1213 // packet sequence number
1214 0xBC, 0x9A, 0x78, 0x56,
1219 // frame type (stream frame with fin)
1222 0x04, 0x03, 0x02, 0x01,
1224 0x54, 0x76, 0x10, 0x32,
1225 0xDC, 0xFE, 0x98, 0xBA,
1234 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1235 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1237 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1238 ASSERT_TRUE(visitor_
.header_
.get());
1239 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1241 ASSERT_EQ(1u, visitor_
.stream_frames_
.size());
1242 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
1243 EXPECT_EQ(static_cast<uint64
>(0x01020304),
1244 visitor_
.stream_frames_
[0]->stream_id
);
1245 EXPECT_TRUE(visitor_
.stream_frames_
[0]->fin
);
1246 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1247 visitor_
.stream_frames_
[0]->offset
);
1248 CheckStreamFrameData("hello world!", visitor_
.stream_frames_
[0]);
1250 // Now test framing boundaries
1251 CheckStreamFrameBoundaries(packet
, kQuicMaxStreamIdSize
, !kIncludeVersion
);
1254 TEST_P(QuicFramerTest
, StreamFrame3ByteStreamId
) {
1255 unsigned char packet
[] = {
1256 // public flags (8 byte guid)
1259 0x10, 0x32, 0x54, 0x76,
1260 0x98, 0xBA, 0xDC, 0xFE,
1261 // packet sequence number
1262 0xBC, 0x9A, 0x78, 0x56,
1267 // frame type (stream frame with fin)
1272 0x54, 0x76, 0x10, 0x32,
1273 0xDC, 0xFE, 0x98, 0xBA,
1282 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1283 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1285 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1286 ASSERT_TRUE(visitor_
.header_
.get());
1287 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1289 ASSERT_EQ(1u, visitor_
.stream_frames_
.size());
1290 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
1291 EXPECT_EQ(GG_UINT64_C(0x00020304),
1292 visitor_
.stream_frames_
[0]->stream_id
);
1293 EXPECT_TRUE(visitor_
.stream_frames_
[0]->fin
);
1294 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1295 visitor_
.stream_frames_
[0]->offset
);
1296 CheckStreamFrameData("hello world!", visitor_
.stream_frames_
[0]);
1298 // Now test framing boundaries
1299 const size_t stream_id_size
= 3;
1300 CheckStreamFrameBoundaries(packet
, stream_id_size
, !kIncludeVersion
);
1303 TEST_P(QuicFramerTest
, StreamFrame2ByteStreamId
) {
1304 unsigned char packet
[] = {
1305 // public flags (8 byte guid)
1308 0x10, 0x32, 0x54, 0x76,
1309 0x98, 0xBA, 0xDC, 0xFE,
1310 // packet sequence number
1311 0xBC, 0x9A, 0x78, 0x56,
1316 // frame type (stream frame with fin)
1321 0x54, 0x76, 0x10, 0x32,
1322 0xDC, 0xFE, 0x98, 0xBA,
1331 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1332 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1334 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1335 ASSERT_TRUE(visitor_
.header_
.get());
1336 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1338 ASSERT_EQ(1u, visitor_
.stream_frames_
.size());
1339 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
1340 EXPECT_EQ(static_cast<uint64
>(0x00000304),
1341 visitor_
.stream_frames_
[0]->stream_id
);
1342 EXPECT_TRUE(visitor_
.stream_frames_
[0]->fin
);
1343 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1344 visitor_
.stream_frames_
[0]->offset
);
1345 CheckStreamFrameData("hello world!", visitor_
.stream_frames_
[0]);
1347 // Now test framing boundaries
1348 const size_t stream_id_size
= 2;
1349 CheckStreamFrameBoundaries(packet
, stream_id_size
, !kIncludeVersion
);
1352 TEST_P(QuicFramerTest
, StreamFrame1ByteStreamId
) {
1353 unsigned char packet
[] = {
1354 // public flags (8 byte guid)
1357 0x10, 0x32, 0x54, 0x76,
1358 0x98, 0xBA, 0xDC, 0xFE,
1359 // packet sequence number
1360 0xBC, 0x9A, 0x78, 0x56,
1365 // frame type (stream frame with fin)
1370 0x54, 0x76, 0x10, 0x32,
1371 0xDC, 0xFE, 0x98, 0xBA,
1380 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1381 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1383 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1384 ASSERT_TRUE(visitor_
.header_
.get());
1385 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1387 ASSERT_EQ(1u, visitor_
.stream_frames_
.size());
1388 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
1389 EXPECT_EQ(static_cast<uint64
>(0x00000004),
1390 visitor_
.stream_frames_
[0]->stream_id
);
1391 EXPECT_TRUE(visitor_
.stream_frames_
[0]->fin
);
1392 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1393 visitor_
.stream_frames_
[0]->offset
);
1394 CheckStreamFrameData("hello world!", visitor_
.stream_frames_
[0]);
1396 // Now test framing boundaries
1397 const size_t stream_id_size
= 1;
1398 CheckStreamFrameBoundaries(packet
, stream_id_size
, !kIncludeVersion
);
1401 TEST_P(QuicFramerTest
, StreamFrameWithVersion
) {
1402 unsigned char packet
[] = {
1403 // public flags (version, 8 byte guid)
1406 0x10, 0x32, 0x54, 0x76,
1407 0x98, 0xBA, 0xDC, 0xFE,
1409 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
1410 // packet sequence number
1411 0xBC, 0x9A, 0x78, 0x56,
1416 // frame type (stream frame with fin)
1419 0x04, 0x03, 0x02, 0x01,
1421 0x54, 0x76, 0x10, 0x32,
1422 0xDC, 0xFE, 0x98, 0xBA,
1431 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1432 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1434 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1435 ASSERT_TRUE(visitor_
.header_
.get());
1436 EXPECT_TRUE(visitor_
.header_
.get()->public_header
.version_flag
);
1437 EXPECT_EQ(GetParam(), visitor_
.header_
.get()->public_header
.versions
[0]);
1438 EXPECT_TRUE(CheckDecryption(encrypted
, kIncludeVersion
));
1440 ASSERT_EQ(1u, visitor_
.stream_frames_
.size());
1441 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
1442 EXPECT_EQ(static_cast<uint64
>(0x01020304),
1443 visitor_
.stream_frames_
[0]->stream_id
);
1444 EXPECT_TRUE(visitor_
.stream_frames_
[0]->fin
);
1445 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1446 visitor_
.stream_frames_
[0]->offset
);
1447 CheckStreamFrameData("hello world!", visitor_
.stream_frames_
[0]);
1449 // Now test framing boundaries
1450 CheckStreamFrameBoundaries(packet
, kQuicMaxStreamIdSize
, kIncludeVersion
);
1453 TEST_P(QuicFramerTest
, RejectPacket
) {
1454 visitor_
.accept_packet_
= false;
1456 unsigned char packet
[] = {
1457 // public flags (8 byte guid)
1460 0x10, 0x32, 0x54, 0x76,
1461 0x98, 0xBA, 0xDC, 0xFE,
1462 // packet sequence number
1463 0xBC, 0x9A, 0x78, 0x56,
1468 // frame type (stream frame with fin)
1471 0x04, 0x03, 0x02, 0x01,
1473 0x54, 0x76, 0x10, 0x32,
1474 0xDC, 0xFE, 0x98, 0xBA,
1483 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1484 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1486 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1487 ASSERT_TRUE(visitor_
.header_
.get());
1488 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1490 ASSERT_EQ(0u, visitor_
.stream_frames_
.size());
1491 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
1494 TEST_P(QuicFramerTest
, RevivedStreamFrame
) {
1495 unsigned char payload
[] = {
1496 // frame type (stream frame with fin)
1499 0x04, 0x03, 0x02, 0x01,
1501 0x54, 0x76, 0x10, 0x32,
1502 0xDC, 0xFE, 0x98, 0xBA,
1511 QuicPacketHeader header
;
1512 header
.public_header
.guid
= GG_UINT64_C(0xFEDCBA9876543210);
1513 header
.public_header
.reset_flag
= false;
1514 header
.public_header
.version_flag
= false;
1515 header
.fec_flag
= true;
1516 header
.entropy_flag
= true;
1517 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
1518 header
.fec_group
= 0;
1520 // Do not encrypt the payload because the revived payload is post-encryption.
1521 EXPECT_TRUE(framer_
.ProcessRevivedPacket(&header
,
1522 StringPiece(AsChars(payload
),
1523 arraysize(payload
))));
1525 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1526 ASSERT_EQ(1, visitor_
.revived_packets_
);
1527 ASSERT_TRUE(visitor_
.header_
.get());
1528 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
1529 visitor_
.header_
->public_header
.guid
);
1530 EXPECT_FALSE(visitor_
.header_
->public_header
.reset_flag
);
1531 EXPECT_FALSE(visitor_
.header_
->public_header
.version_flag
);
1532 EXPECT_TRUE(visitor_
.header_
->fec_flag
);
1533 EXPECT_TRUE(visitor_
.header_
->entropy_flag
);
1534 EXPECT_EQ(1 << (header
.packet_sequence_number
% 8),
1535 visitor_
.header_
->entropy_hash
);
1536 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
1537 visitor_
.header_
->packet_sequence_number
);
1538 EXPECT_EQ(NOT_IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
1539 EXPECT_EQ(0x00u
, visitor_
.header_
->fec_group
);
1541 ASSERT_EQ(1u, visitor_
.stream_frames_
.size());
1542 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
1543 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_
.stream_frames_
[0]->stream_id
);
1544 EXPECT_TRUE(visitor_
.stream_frames_
[0]->fin
);
1545 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1546 visitor_
.stream_frames_
[0]->offset
);
1547 CheckStreamFrameData("hello world!", visitor_
.stream_frames_
[0]);
1550 TEST_P(QuicFramerTest
, StreamFrameInFecGroup
) {
1551 unsigned char packet
[] = {
1552 // public flags (8 byte guid)
1555 0x10, 0x32, 0x54, 0x76,
1556 0x98, 0xBA, 0xDC, 0xFE,
1557 // packet sequence number
1558 0xBC, 0x9A, 0x78, 0x56,
1560 // private flags (fec group)
1562 // first fec protected packet offset
1565 // frame type (stream frame with fin)
1568 0x04, 0x03, 0x02, 0x01,
1570 0x54, 0x76, 0x10, 0x32,
1571 0xDC, 0xFE, 0x98, 0xBA,
1580 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1581 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1583 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1584 ASSERT_TRUE(visitor_
.header_
.get());
1585 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1586 EXPECT_EQ(IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
1587 EXPECT_EQ(GG_UINT64_C(0x341256789ABA),
1588 visitor_
.header_
->fec_group
);
1589 const size_t fec_offset
= GetStartOfFecProtectedData(
1590 PACKET_8BYTE_GUID
, !kIncludeVersion
, PACKET_6BYTE_SEQUENCE_NUMBER
);
1592 string(AsChars(packet
) + fec_offset
, arraysize(packet
) - fec_offset
),
1593 visitor_
.fec_protected_payload_
);
1595 ASSERT_EQ(1u, visitor_
.stream_frames_
.size());
1596 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
1597 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_
.stream_frames_
[0]->stream_id
);
1598 EXPECT_TRUE(visitor_
.stream_frames_
[0]->fin
);
1599 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1600 visitor_
.stream_frames_
[0]->offset
);
1601 CheckStreamFrameData("hello world!", visitor_
.stream_frames_
[0]);
1604 TEST_P(QuicFramerTest
, DISABLED_AckFramev11
) {
1605 if (GetParam() > QUIC_VERSION_11
) {
1608 unsigned char packet
[] = {
1609 // public flags (8 byte guid)
1612 0x10, 0x32, 0x54, 0x76,
1613 0x98, 0xBA, 0xDC, 0xFE,
1614 // packet sequence number
1615 0xBC, 0x9A, 0x78, 0x56,
1620 // frame type (ack frame)
1622 // entropy hash of sent packets till least awaiting - 1.
1624 // least packet sequence number awaiting an ack
1625 0xA0, 0x9A, 0x78, 0x56,
1627 // entropy hash of all received packets.
1629 // largest observed packet sequence number
1630 0xBF, 0x9A, 0x78, 0x56,
1632 // Infinite delta time.
1633 0xFF, 0xFF, 0xFF, 0xFF,
1634 // num missing packets
1637 0xBE, 0x9A, 0x78, 0x56,
1641 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1642 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1644 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1645 ASSERT_TRUE(visitor_
.header_
.get());
1646 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1648 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
1649 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
1650 const QuicAckFrame
& frame
= *visitor_
.ack_frames_
[0];
1651 EXPECT_EQ(0xAB, frame
.sent_info
.entropy_hash
);
1652 EXPECT_EQ(0xBA, frame
.received_info
.entropy_hash
);
1653 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame
.received_info
.largest_observed
);
1654 ASSERT_EQ(1u, frame
.received_info
.missing_packets
.size());
1655 SequenceNumberSet::const_iterator missing_iter
=
1656 frame
.received_info
.missing_packets
.begin();
1657 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter
);
1658 EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame
.sent_info
.least_unacked
);
1660 const size_t kSentEntropyOffset
= kQuicFrameTypeSize
;
1661 const size_t kLeastUnackedOffset
= kSentEntropyOffset
+ kQuicEntropyHashSize
;
1662 const size_t kReceivedEntropyOffset
= kLeastUnackedOffset
+
1663 PACKET_6BYTE_SEQUENCE_NUMBER
;
1664 const size_t kLargestObservedOffset
= kReceivedEntropyOffset
+
1665 kQuicEntropyHashSize
;
1666 const size_t kMissingDeltaTimeOffset
= kLargestObservedOffset
+
1667 PACKET_6BYTE_SEQUENCE_NUMBER
;
1668 const size_t kNumMissingPacketOffset
= kMissingDeltaTimeOffset
+
1669 kQuicv11DeltaTimeLargestObservedSize
;
1670 const size_t kMissingPacketsOffset
= kNumMissingPacketOffset
+
1671 kNumberOfMissingPacketsSize
;
1672 // Now test framing boundaries
1673 const size_t missing_packets_size
= 1 * PACKET_6BYTE_SEQUENCE_NUMBER
;
1674 for (size_t i
= kQuicFrameTypeSize
;
1675 i
< QuicFramer::GetMinAckFrameSizev11() + missing_packets_size
; ++i
) {
1676 string expected_error
;
1677 if (i
< kLeastUnackedOffset
) {
1678 expected_error
= "Unable to read entropy hash for sent packets.";
1679 } else if (i
< kReceivedEntropyOffset
) {
1680 expected_error
= "Unable to read least unacked.";
1681 } else if (i
< kLargestObservedOffset
) {
1682 expected_error
= "Unable to read entropy hash for received packets.";
1683 } else if (i
< kMissingDeltaTimeOffset
) {
1684 expected_error
= "Unable to read largest observed.";
1685 } else if (i
< kNumMissingPacketOffset
) {
1686 expected_error
= "Unable to read delta time largest observed.";
1687 } else if (i
< kMissingPacketsOffset
) {
1688 expected_error
= "Unable to read num missing packets.";
1690 expected_error
= "Unable to read sequence number in missing packets.";
1692 CheckProcessingFails(
1694 i
+ GetPacketHeaderSize(PACKET_8BYTE_GUID
, !kIncludeVersion
,
1695 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
1696 expected_error
, QUIC_INVALID_ACK_DATA
);
1700 TEST_P(QuicFramerTest
, AckFrame
) {
1701 if (GetParam() <= QUIC_VERSION_11
) {
1704 unsigned char packet
[] = {
1705 // public flags (8 byte guid)
1708 0x10, 0x32, 0x54, 0x76,
1709 0x98, 0xBA, 0xDC, 0xFE,
1710 // packet sequence number
1711 0xA8, 0x9A, 0x78, 0x56,
1713 // private flags (entropy)
1716 // frame type (ack frame)
1717 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
1719 // entropy hash of sent packets till least awaiting - 1.
1721 // least packet sequence number awaiting an ack, delta from sequence number.
1722 0x08, 0x00, 0x00, 0x00,
1724 // entropy hash of all received packets.
1726 // largest observed packet sequence number
1727 0xBF, 0x9A, 0x78, 0x56,
1731 // num missing packets
1733 // missing packet delta
1735 // 0 more missing packets in range.
1739 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1740 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1742 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1743 ASSERT_TRUE(visitor_
.header_
.get());
1744 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1746 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
1747 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
1748 const QuicAckFrame
& frame
= *visitor_
.ack_frames_
[0];
1749 EXPECT_EQ(0xAB, frame
.sent_info
.entropy_hash
);
1750 EXPECT_EQ(0xBA, frame
.received_info
.entropy_hash
);
1751 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame
.received_info
.largest_observed
);
1752 ASSERT_EQ(1u, frame
.received_info
.missing_packets
.size());
1753 SequenceNumberSet::const_iterator missing_iter
=
1754 frame
.received_info
.missing_packets
.begin();
1755 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter
);
1756 EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame
.sent_info
.least_unacked
);
1758 const size_t kSentEntropyOffset
= kQuicFrameTypeSize
;
1759 const size_t kLeastUnackedOffset
= kSentEntropyOffset
+ kQuicEntropyHashSize
;
1760 const size_t kReceivedEntropyOffset
= kLeastUnackedOffset
+
1761 PACKET_6BYTE_SEQUENCE_NUMBER
;
1762 const size_t kLargestObservedOffset
= kReceivedEntropyOffset
+
1763 kQuicEntropyHashSize
;
1764 const size_t kMissingDeltaTimeOffset
= kLargestObservedOffset
+
1765 PACKET_6BYTE_SEQUENCE_NUMBER
;
1766 const size_t kNumMissingPacketOffset
= kMissingDeltaTimeOffset
+
1767 kQuicDeltaTimeLargestObservedSize
;
1768 const size_t kMissingPacketsOffset
= kNumMissingPacketOffset
+
1769 kNumberOfMissingPacketsSize
;
1770 const size_t kMissingPacketsRange
= kMissingPacketsOffset
+
1771 PACKET_1BYTE_SEQUENCE_NUMBER
;
1772 // Now test framing boundaries
1773 const size_t ack_frame_size
= kMissingPacketsRange
+
1774 PACKET_1BYTE_SEQUENCE_NUMBER
;
1775 for (size_t i
= kQuicFrameTypeSize
; i
< ack_frame_size
; ++i
) {
1776 string expected_error
;
1777 if (i
< kLeastUnackedOffset
) {
1778 expected_error
= "Unable to read entropy hash for sent packets.";
1779 } else if (i
< kReceivedEntropyOffset
) {
1780 expected_error
= "Unable to read least unacked delta.";
1781 } else if (i
< kLargestObservedOffset
) {
1782 expected_error
= "Unable to read entropy hash for received packets.";
1783 } else if (i
< kMissingDeltaTimeOffset
) {
1784 expected_error
= "Unable to read largest observed.";
1785 } else if (i
< kNumMissingPacketOffset
) {
1786 expected_error
= "Unable to read delta time largest observed.";
1787 } else if (i
< kMissingPacketsOffset
) {
1788 expected_error
= "Unable to read num missing packet ranges.";
1789 } else if (i
< kMissingPacketsRange
) {
1790 expected_error
= "Unable to read missing sequence number delta.";
1792 expected_error
= "Unable to read missing sequence number range.";
1794 CheckProcessingFails(
1796 i
+ GetPacketHeaderSize(PACKET_8BYTE_GUID
, !kIncludeVersion
,
1797 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
1798 expected_error
, QUIC_INVALID_ACK_DATA
);
1802 TEST_P(QuicFramerTest
, AckFrameNoNacks
) {
1803 if (GetParam() <= QUIC_VERSION_11
) {
1806 unsigned char packet
[] = {
1807 // public flags (8 byte guid)
1810 0x10, 0x32, 0x54, 0x76,
1811 0x98, 0xBA, 0xDC, 0xFE,
1812 // packet sequence number
1813 0xA8, 0x9A, 0x78, 0x56,
1815 // private flags (entropy)
1818 // frame type (ack frame)
1819 // (no nacks, not truncated, 6 byte largest observed, 1 byte delta)
1821 // entropy hash of sent packets till least awaiting - 1.
1823 // least packet sequence number awaiting an ack, delta from sequence number.
1824 0x08, 0x00, 0x00, 0x00,
1826 // entropy hash of all received packets.
1828 // largest observed packet sequence number
1829 0xBF, 0x9A, 0x78, 0x56,
1835 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1836 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1838 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1839 ASSERT_TRUE(visitor_
.header_
.get());
1840 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1842 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
1843 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
1844 QuicAckFrame
* frame
= visitor_
.ack_frames_
[0];
1845 EXPECT_EQ(0xAB, frame
->sent_info
.entropy_hash
);
1846 EXPECT_EQ(0xBA, frame
->received_info
.entropy_hash
);
1847 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF),
1848 frame
->received_info
.largest_observed
);
1849 ASSERT_EQ(0u, frame
->received_info
.missing_packets
.size());
1850 EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame
->sent_info
.least_unacked
);
1852 // Verify that the packet re-serializes identically.
1854 frames
.push_back(QuicFrame(frame
));
1855 scoped_ptr
<QuicPacket
> data(
1856 framer_
.BuildUnsizedDataPacket(*visitor_
.header_
, frames
).packet
);
1857 ASSERT_TRUE(data
!= NULL
);
1859 test::CompareCharArraysWithHexError("constructed packet",
1860 data
->data(), data
->length(),
1861 AsChars(packet
), arraysize(packet
));
1864 TEST_P(QuicFramerTest
, AckFrame500Nacks
) {
1865 if (GetParam() <= QUIC_VERSION_11
) {
1868 unsigned char packet
[] = {
1869 // public flags (8 byte guid)
1872 0x10, 0x32, 0x54, 0x76,
1873 0x98, 0xBA, 0xDC, 0xFE,
1874 // packet sequence number
1875 0xA8, 0x9A, 0x78, 0x56,
1877 // private flags (entropy)
1880 // frame type (ack frame)
1881 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
1883 // entropy hash of sent packets till least awaiting - 1.
1885 // least packet sequence number awaiting an ack, delta from sequence number.
1886 0x08, 0x00, 0x00, 0x00,
1888 // entropy hash of all received packets.
1890 // largest observed packet sequence number
1891 0xBF, 0x9A, 0x78, 0x56,
1895 // num missing packet ranges
1897 // missing packet delta
1899 // 243 more missing packets in range.
1900 // The ranges are listed in this order so the re-constructed packet matches.
1902 // No gap between ranges
1904 // 255 more missing packets in range.
1908 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1909 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1911 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1912 ASSERT_TRUE(visitor_
.header_
.get());
1913 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1915 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
1916 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
1917 QuicAckFrame
* frame
= visitor_
.ack_frames_
[0];
1918 EXPECT_EQ(0xAB, frame
->sent_info
.entropy_hash
);
1919 EXPECT_EQ(0xBA, frame
->received_info
.entropy_hash
);
1920 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF),
1921 frame
->received_info
.largest_observed
);
1922 ASSERT_EQ(500u, frame
->received_info
.missing_packets
.size());
1923 SequenceNumberSet::const_iterator first_missing_iter
=
1924 frame
->received_info
.missing_packets
.begin();
1925 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE) - 499, *first_missing_iter
);
1926 SequenceNumberSet::const_reverse_iterator last_missing_iter
=
1927 frame
->received_info
.missing_packets
.rbegin();
1928 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *last_missing_iter
);
1929 EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame
->sent_info
.least_unacked
);
1931 // Verify that the packet re-serializes identically.
1933 frames
.push_back(QuicFrame(frame
));
1934 scoped_ptr
<QuicPacket
> data(
1935 framer_
.BuildUnsizedDataPacket(*visitor_
.header_
, frames
).packet
);
1936 ASSERT_TRUE(data
!= NULL
);
1938 test::CompareCharArraysWithHexError("constructed packet",
1939 data
->data(), data
->length(),
1940 AsChars(packet
), arraysize(packet
));
1943 TEST_P(QuicFramerTest
, CongestionFeedbackFrameTCP
) {
1944 unsigned char packet
[] = {
1945 // public flags (8 byte guid)
1948 0x10, 0x32, 0x54, 0x76,
1949 0x98, 0xBA, 0xDC, 0xFE,
1950 // packet sequence number
1951 0xBC, 0x9A, 0x78, 0x56,
1956 // frame type (congestion feedback frame)
1958 // congestion feedback type (tcp)
1960 // ack_frame.feedback.tcp.accumulated_number_of_lost_packets
1962 // ack_frame.feedback.tcp.receive_window
1966 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1967 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1969 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1970 ASSERT_TRUE(visitor_
.header_
.get());
1971 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1973 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
1974 ASSERT_EQ(1u, visitor_
.congestion_feedback_frames_
.size());
1975 const QuicCongestionFeedbackFrame
& frame
=
1976 *visitor_
.congestion_feedback_frames_
[0];
1977 ASSERT_EQ(kTCP
, frame
.type
);
1979 frame
.tcp
.accumulated_number_of_lost_packets
);
1980 EXPECT_EQ(0x4030u
, frame
.tcp
.receive_window
);
1982 // Now test framing boundaries
1983 for (size_t i
= kQuicFrameTypeSize
; i
< 6; ++i
) {
1984 string expected_error
;
1986 expected_error
= "Unable to read congestion feedback type.";
1988 expected_error
= "Unable to read accumulated number of lost packets.";
1990 expected_error
= "Unable to read receive window.";
1992 CheckProcessingFails(
1994 i
+ GetPacketHeaderSize(PACKET_8BYTE_GUID
, !kIncludeVersion
,
1995 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
1996 expected_error
, QUIC_INVALID_CONGESTION_FEEDBACK_DATA
);
2000 TEST_P(QuicFramerTest
, CongestionFeedbackFrameInterArrival
) {
2001 unsigned char packet
[] = {
2002 // public flags (8 byte guid)
2005 0x10, 0x32, 0x54, 0x76,
2006 0x98, 0xBA, 0xDC, 0xFE,
2007 // packet sequence number
2008 0xBC, 0x9A, 0x78, 0x56,
2013 // frame type (congestion feedback frame)
2015 // congestion feedback type (inter arrival)
2017 // accumulated_number_of_lost_packets
2019 // num received packets
2021 // lowest sequence number
2022 0xBA, 0x9A, 0x78, 0x56,
2025 0x87, 0x96, 0xA5, 0xB4,
2026 0xC3, 0xD2, 0xE1, 0x07,
2030 0x01, 0x00, 0x00, 0x00,
2031 // sequence delta (skip one packet)
2034 0x02, 0x00, 0x00, 0x00,
2037 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2038 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2040 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2041 ASSERT_TRUE(visitor_
.header_
.get());
2042 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2044 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
2045 ASSERT_EQ(1u, visitor_
.congestion_feedback_frames_
.size());
2046 const QuicCongestionFeedbackFrame
& frame
=
2047 *visitor_
.congestion_feedback_frames_
[0];
2048 ASSERT_EQ(kInterArrival
, frame
.type
);
2049 EXPECT_EQ(0x0302, frame
.inter_arrival
.
2050 accumulated_number_of_lost_packets
);
2051 ASSERT_EQ(3u, frame
.inter_arrival
.received_packet_times
.size());
2052 TimeMap::const_iterator iter
=
2053 frame
.inter_arrival
.received_packet_times
.begin();
2054 EXPECT_EQ(GG_UINT64_C(0x0123456789ABA), iter
->first
);
2055 EXPECT_EQ(GG_INT64_C(0x07E1D2C3B4A59687),
2056 iter
->second
.Subtract(start_
).ToMicroseconds());
2058 EXPECT_EQ(GG_UINT64_C(0x0123456789ABB), iter
->first
);
2059 EXPECT_EQ(GG_INT64_C(0x07E1D2C3B4A59688),
2060 iter
->second
.Subtract(start_
).ToMicroseconds());
2062 EXPECT_EQ(GG_UINT64_C(0x0123456789ABD), iter
->first
);
2063 EXPECT_EQ(GG_INT64_C(0x07E1D2C3B4A59689),
2064 iter
->second
.Subtract(start_
).ToMicroseconds());
2066 // Now test framing boundaries
2067 for (size_t i
= kQuicFrameTypeSize
; i
< 31; ++i
) {
2068 string expected_error
;
2070 expected_error
= "Unable to read congestion feedback type.";
2072 expected_error
= "Unable to read accumulated number of lost packets.";
2074 expected_error
= "Unable to read num received packets.";
2075 } else if (i
< 11) {
2076 expected_error
= "Unable to read smallest received.";
2077 } else if (i
< 19) {
2078 expected_error
= "Unable to read time received.";
2079 } else if (i
< 21) {
2080 expected_error
= "Unable to read sequence delta in received packets.";
2081 } else if (i
< 25) {
2082 expected_error
= "Unable to read time delta in received packets.";
2083 } else if (i
< 27) {
2084 expected_error
= "Unable to read sequence delta in received packets.";
2085 } else if (i
< 31) {
2086 expected_error
= "Unable to read time delta in received packets.";
2088 CheckProcessingFails(
2090 i
+ GetPacketHeaderSize(PACKET_8BYTE_GUID
, !kIncludeVersion
,
2091 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
2092 expected_error
, QUIC_INVALID_CONGESTION_FEEDBACK_DATA
);
2096 TEST_P(QuicFramerTest
, CongestionFeedbackFrameFixRate
) {
2097 unsigned char packet
[] = {
2098 // public flags (8 byte guid)
2101 0x10, 0x32, 0x54, 0x76,
2102 0x98, 0xBA, 0xDC, 0xFE,
2103 // packet sequence number
2104 0xBC, 0x9A, 0x78, 0x56,
2109 // frame type (congestion feedback frame)
2111 // congestion feedback type (fix rate)
2113 // bitrate_in_bytes_per_second;
2114 0x01, 0x02, 0x03, 0x04,
2117 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2118 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2120 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2121 ASSERT_TRUE(visitor_
.header_
.get());
2122 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2124 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
2125 ASSERT_EQ(1u, visitor_
.congestion_feedback_frames_
.size());
2126 const QuicCongestionFeedbackFrame
& frame
=
2127 *visitor_
.congestion_feedback_frames_
[0];
2128 ASSERT_EQ(kFixRate
, frame
.type
);
2129 EXPECT_EQ(static_cast<uint32
>(0x04030201),
2130 frame
.fix_rate
.bitrate
.ToBytesPerSecond());
2132 // Now test framing boundaries
2133 for (size_t i
= kQuicFrameTypeSize
; i
< 6; ++i
) {
2134 string expected_error
;
2136 expected_error
= "Unable to read congestion feedback type.";
2138 expected_error
= "Unable to read bitrate.";
2140 CheckProcessingFails(
2142 i
+ GetPacketHeaderSize(PACKET_8BYTE_GUID
, !kIncludeVersion
,
2143 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
2144 expected_error
, QUIC_INVALID_CONGESTION_FEEDBACK_DATA
);
2148 TEST_P(QuicFramerTest
, CongestionFeedbackFrameInvalidFeedback
) {
2149 unsigned char packet
[] = {
2150 // public flags (8 byte guid)
2153 0x10, 0x32, 0x54, 0x76,
2154 0x98, 0xBA, 0xDC, 0xFE,
2155 // packet sequence number
2156 0xBC, 0x9A, 0x78, 0x56,
2161 // frame type (congestion feedback frame)
2163 // congestion feedback type (invalid)
2167 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2168 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
2169 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2170 EXPECT_EQ(QUIC_INVALID_CONGESTION_FEEDBACK_DATA
, framer_
.error());
2173 TEST_P(QuicFramerTest
, RstStreamFrame
) {
2174 unsigned char packet
[] = {
2175 // public flags (8 byte guid)
2178 0x10, 0x32, 0x54, 0x76,
2179 0x98, 0xBA, 0xDC, 0xFE,
2180 // packet sequence number
2181 0xBC, 0x9A, 0x78, 0x56,
2186 // frame type (rst stream frame)
2189 0x04, 0x03, 0x02, 0x01,
2191 0x01, 0x00, 0x00, 0x00,
2193 // error details length
2202 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2203 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2205 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2206 ASSERT_TRUE(visitor_
.header_
.get());
2207 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2209 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_
.rst_stream_frame_
.stream_id
);
2210 EXPECT_EQ(0x01, visitor_
.rst_stream_frame_
.error_code
);
2211 EXPECT_EQ("because I can", visitor_
.rst_stream_frame_
.error_details
);
2213 // Now test framing boundaries
2214 for (size_t i
= kQuicFrameTypeSize
; i
< 24; ++i
) {
2215 string expected_error
;
2216 if (i
< kQuicFrameTypeSize
+ kQuicMaxStreamIdSize
) {
2217 expected_error
= "Unable to read stream_id.";
2218 } else if (i
< kQuicFrameTypeSize
+ kQuicMaxStreamIdSize
+
2219 kQuicErrorCodeSize
) {
2220 expected_error
= "Unable to read rst stream error code.";
2222 expected_error
= "Unable to read rst stream error details.";
2224 CheckProcessingFails(
2226 i
+ GetPacketHeaderSize(PACKET_8BYTE_GUID
, !kIncludeVersion
,
2227 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
2228 expected_error
, QUIC_INVALID_RST_STREAM_DATA
);
2232 TEST_P(QuicFramerTest
, DISABLED_ConnectionCloseFramev11
) {
2233 if (GetParam() > QUIC_VERSION_11
) {
2236 unsigned char packet
[] = {
2237 // public flags (8 byte guid)
2240 0x10, 0x32, 0x54, 0x76,
2241 0x98, 0xBA, 0xDC, 0xFE,
2242 // packet sequence number
2243 0xBC, 0x9A, 0x78, 0x56,
2248 // frame type (connection close frame)
2251 0x11, 0x00, 0x00, 0x00,
2253 // error details length
2262 // entropy hash of sent packets till least awaiting - 1.
2264 // least packet sequence number awaiting an ack
2265 0xA0, 0x9A, 0x78, 0x56,
2267 // entropy hash of all received packets.
2269 // largest observed packet sequence number
2270 0xBF, 0x9A, 0x78, 0x56,
2272 // Infinite delta time.
2273 0xFF, 0xFF, 0xFF, 0xFF,
2274 // num missing packets
2277 0xBE, 0x9A, 0x78, 0x56,
2281 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2282 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2284 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2285 ASSERT_TRUE(visitor_
.header_
.get());
2286 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2288 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
2290 EXPECT_EQ(0x11, visitor_
.connection_close_frame_
.error_code
);
2291 EXPECT_EQ("because I can", visitor_
.connection_close_frame_
.error_details
);
2293 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
2294 const QuicAckFrame
& frame
= *visitor_
.ack_frames_
[0];
2295 EXPECT_EQ(0xBF, frame
.sent_info
.entropy_hash
);
2296 EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame
.sent_info
.least_unacked
);
2297 EXPECT_EQ(0xEB, frame
.received_info
.entropy_hash
);
2298 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame
.received_info
.largest_observed
);
2299 ASSERT_EQ(1u, frame
.received_info
.missing_packets
.size());
2300 SequenceNumberSet::const_iterator missing_iter
=
2301 frame
.received_info
.missing_packets
.begin();
2302 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter
);
2304 // Now test framing boundaries
2305 for (size_t i
= kQuicFrameTypeSize
;
2306 i
< QuicFramer::GetMinConnectionCloseFrameSize(); ++i
) {
2307 string expected_error
;
2308 if (i
< kQuicFrameTypeSize
+ kQuicErrorCodeSize
) {
2309 expected_error
= "Unable to read connection close error code.";
2311 expected_error
= "Unable to read connection close error details.";
2313 CheckProcessingFails(
2315 i
+ GetPacketHeaderSize(PACKET_8BYTE_GUID
, !kIncludeVersion
,
2316 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
2317 expected_error
, QUIC_INVALID_CONNECTION_CLOSE_DATA
);
2321 TEST_P(QuicFramerTest
, ConnectionCloseFrame
) {
2322 if (GetParam() <= QUIC_VERSION_11
) {
2325 unsigned char packet
[] = {
2326 // public flags (8 byte guid)
2329 0x10, 0x32, 0x54, 0x76,
2330 0x98, 0xBA, 0xDC, 0xFE,
2331 // packet sequence number
2332 0xBC, 0x9A, 0x78, 0x56,
2337 // frame type (connection close frame)
2340 0x11, 0x00, 0x00, 0x00,
2342 // error details length
2351 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2352 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2354 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2355 ASSERT_TRUE(visitor_
.header_
.get());
2356 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2358 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
2360 EXPECT_EQ(0x11, visitor_
.connection_close_frame_
.error_code
);
2361 EXPECT_EQ("because I can", visitor_
.connection_close_frame_
.error_details
);
2363 ASSERT_EQ(0u, visitor_
.ack_frames_
.size());
2365 // Now test framing boundaries
2366 for (size_t i
= kQuicFrameTypeSize
;
2367 i
< QuicFramer::GetMinConnectionCloseFrameSize(); ++i
) {
2368 string expected_error
;
2369 if (i
< kQuicFrameTypeSize
+ kQuicErrorCodeSize
) {
2370 expected_error
= "Unable to read connection close error code.";
2372 expected_error
= "Unable to read connection close error details.";
2374 CheckProcessingFails(
2376 i
+ GetPacketHeaderSize(PACKET_8BYTE_GUID
, !kIncludeVersion
,
2377 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
2378 expected_error
, QUIC_INVALID_CONNECTION_CLOSE_DATA
);
2382 TEST_P(QuicFramerTest
, GoAwayFrame
) {
2383 unsigned char packet
[] = {
2384 // public flags (8 byte guid)
2387 0x10, 0x32, 0x54, 0x76,
2388 0x98, 0xBA, 0xDC, 0xFE,
2389 // packet sequence number
2390 0xBC, 0x9A, 0x78, 0x56,
2395 // frame type (go away frame)
2398 0x09, 0x00, 0x00, 0x00,
2400 0x04, 0x03, 0x02, 0x01,
2401 // error details length
2410 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2411 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2413 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2414 ASSERT_TRUE(visitor_
.header_
.get());
2415 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2417 EXPECT_EQ(GG_UINT64_C(0x01020304),
2418 visitor_
.goaway_frame_
.last_good_stream_id
);
2419 EXPECT_EQ(0x9, visitor_
.goaway_frame_
.error_code
);
2420 EXPECT_EQ("because I can", visitor_
.goaway_frame_
.reason_phrase
);
2422 const size_t reason_size
= arraysize("because I can") - 1;
2423 // Now test framing boundaries
2424 for (size_t i
= kQuicFrameTypeSize
;
2425 i
< QuicFramer::GetMinGoAwayFrameSize() + reason_size
; ++i
) {
2426 string expected_error
;
2427 if (i
< kQuicFrameTypeSize
+ kQuicErrorCodeSize
) {
2428 expected_error
= "Unable to read go away error code.";
2429 } else if (i
< kQuicFrameTypeSize
+ kQuicErrorCodeSize
+
2430 kQuicMaxStreamIdSize
) {
2431 expected_error
= "Unable to read last good stream id.";
2433 expected_error
= "Unable to read goaway reason.";
2435 CheckProcessingFails(
2437 i
+ GetPacketHeaderSize(PACKET_8BYTE_GUID
, !kIncludeVersion
,
2438 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
2439 expected_error
, QUIC_INVALID_GOAWAY_DATA
);
2443 TEST_P(QuicFramerTest
, PublicResetPacket
) {
2444 unsigned char packet
[] = {
2445 // public flags (public reset, 8 byte guid)
2448 0x10, 0x32, 0x54, 0x76,
2449 0x98, 0xBA, 0xDC, 0xFE,
2451 0x89, 0x67, 0x45, 0x23,
2452 0x01, 0xEF, 0xCD, 0xAB,
2453 // rejected sequence number
2454 0xBC, 0x9A, 0x78, 0x56,
2458 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2459 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2460 ASSERT_EQ(QUIC_NO_ERROR
, framer_
.error());
2461 ASSERT_TRUE(visitor_
.public_reset_packet_
.get());
2462 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
2463 visitor_
.public_reset_packet_
->public_header
.guid
);
2464 EXPECT_TRUE(visitor_
.public_reset_packet_
->public_header
.reset_flag
);
2465 EXPECT_FALSE(visitor_
.public_reset_packet_
->public_header
.version_flag
);
2466 EXPECT_EQ(GG_UINT64_C(0xABCDEF0123456789),
2467 visitor_
.public_reset_packet_
->nonce_proof
);
2468 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
2469 visitor_
.public_reset_packet_
->rejected_sequence_number
);
2471 // Now test framing boundaries
2472 for (size_t i
= 0; i
< GetPublicResetPacketSize(); ++i
) {
2473 string expected_error
;
2474 DLOG(INFO
) << "iteration: " << i
;
2475 if (i
< kGuidOffset
) {
2476 expected_error
= "Unable to read public flags.";
2477 CheckProcessingFails(packet
, i
, expected_error
,
2478 QUIC_INVALID_PACKET_HEADER
);
2479 } else if (i
< kPublicResetPacketNonceProofOffset
) {
2480 expected_error
= "Unable to read GUID.";
2481 CheckProcessingFails(packet
, i
, expected_error
,
2482 QUIC_INVALID_PACKET_HEADER
);
2483 } else if (i
< kPublicResetPacketRejectedSequenceNumberOffset
) {
2484 expected_error
= "Unable to read nonce proof.";
2485 CheckProcessingFails(packet
, i
, expected_error
,
2486 QUIC_INVALID_PUBLIC_RST_PACKET
);
2488 expected_error
= "Unable to read rejected sequence number.";
2489 CheckProcessingFails(packet
, i
, expected_error
,
2490 QUIC_INVALID_PUBLIC_RST_PACKET
);
2495 TEST_P(QuicFramerTest
, VersionNegotiationPacket
) {
2496 unsigned char packet
[] = {
2497 // public flags (version, 8 byte guid)
2500 0x10, 0x32, 0x54, 0x76,
2501 0x98, 0xBA, 0xDC, 0xFE,
2503 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
2507 QuicFramerPeer::SetIsServer(&framer_
, false);
2509 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2510 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2511 ASSERT_EQ(QUIC_NO_ERROR
, framer_
.error());
2512 ASSERT_TRUE(visitor_
.version_negotiation_packet_
.get());
2513 EXPECT_EQ(2u, visitor_
.version_negotiation_packet_
->versions
.size());
2514 EXPECT_EQ(GetParam(), visitor_
.version_negotiation_packet_
->versions
[0]);
2516 for (size_t i
= 0; i
<= kPublicFlagsSize
+ PACKET_8BYTE_GUID
; ++i
) {
2517 string expected_error
;
2518 QuicErrorCode error_code
= QUIC_INVALID_PACKET_HEADER
;
2519 if (i
< kGuidOffset
) {
2520 expected_error
= "Unable to read public flags.";
2521 } else if (i
< kVersionOffset
) {
2522 expected_error
= "Unable to read GUID.";
2524 expected_error
= "Unable to read supported version in negotiation.";
2525 error_code
= QUIC_INVALID_VERSION_NEGOTIATION_PACKET
;
2527 CheckProcessingFails(packet
, i
, expected_error
, error_code
);
2531 TEST_P(QuicFramerTest
, FecPacket
) {
2532 unsigned char packet
[] = {
2533 // public flags (8 byte guid)
2536 0x10, 0x32, 0x54, 0x76,
2537 0x98, 0xBA, 0xDC, 0xFE,
2538 // packet sequence number
2539 0xBC, 0x9A, 0x78, 0x56,
2541 // private flags (fec group & FEC)
2543 // first fec protected packet offset
2553 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2554 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2556 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2557 ASSERT_TRUE(visitor_
.header_
.get());
2558 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2560 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
2561 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
2562 ASSERT_EQ(1, visitor_
.fec_count_
);
2563 const QuicFecData
& fec_data
= *visitor_
.fec_data_
[0];
2564 EXPECT_EQ(GG_UINT64_C(0x0123456789ABB), fec_data
.fec_group
);
2565 EXPECT_EQ("abcdefghijklmnop", fec_data
.redundancy
);
2568 TEST_P(QuicFramerTest
, BuildPaddingFramePacket
) {
2569 QuicPacketHeader header
;
2570 header
.public_header
.guid
= GG_UINT64_C(0xFEDCBA9876543210);
2571 header
.public_header
.reset_flag
= false;
2572 header
.public_header
.version_flag
= false;
2573 header
.fec_flag
= false;
2574 header
.entropy_flag
= false;
2575 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
2576 header
.fec_group
= 0;
2578 QuicPaddingFrame padding_frame
;
2581 frames
.push_back(QuicFrame(&padding_frame
));
2583 unsigned char packet
[kMaxPacketSize
] = {
2584 // public flags (8 byte guid)
2587 0x10, 0x32, 0x54, 0x76,
2588 0x98, 0xBA, 0xDC, 0xFE,
2589 // packet sequence number
2590 0xBC, 0x9A, 0x78, 0x56,
2595 // frame type (padding frame)
2597 0x00, 0x00, 0x00, 0x00
2600 uint64 header_size
=
2601 GetPacketHeaderSize(PACKET_8BYTE_GUID
, !kIncludeVersion
,
2602 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
2603 memset(packet
+ header_size
+ 1, 0x00, kMaxPacketSize
- header_size
- 1);
2605 scoped_ptr
<QuicPacket
> data(
2606 framer_
.BuildUnsizedDataPacket(header
, frames
).packet
);
2607 ASSERT_TRUE(data
!= NULL
);
2609 test::CompareCharArraysWithHexError("constructed packet",
2610 data
->data(), data
->length(),
2615 TEST_P(QuicFramerTest
, Build4ByteSequenceNumberPaddingFramePacket
) {
2616 QuicPacketHeader header
;
2617 header
.public_header
.guid
= GG_UINT64_C(0xFEDCBA9876543210);
2618 header
.public_header
.reset_flag
= false;
2619 header
.public_header
.version_flag
= false;
2620 header
.fec_flag
= false;
2621 header
.entropy_flag
= false;
2622 header
.public_header
.sequence_number_length
= PACKET_4BYTE_SEQUENCE_NUMBER
;
2623 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
2624 header
.fec_group
= 0;
2626 QuicPaddingFrame padding_frame
;
2629 frames
.push_back(QuicFrame(&padding_frame
));
2631 unsigned char packet
[kMaxPacketSize
] = {
2632 // public flags (8 byte guid and 4 byte sequence number)
2635 0x10, 0x32, 0x54, 0x76,
2636 0x98, 0xBA, 0xDC, 0xFE,
2637 // packet sequence number
2638 0xBC, 0x9A, 0x78, 0x56,
2642 // frame type (padding frame)
2644 0x00, 0x00, 0x00, 0x00
2647 uint64 header_size
=
2648 GetPacketHeaderSize(PACKET_8BYTE_GUID
, !kIncludeVersion
,
2649 PACKET_4BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
2650 memset(packet
+ header_size
+ 1, 0x00, kMaxPacketSize
- header_size
- 1);
2652 scoped_ptr
<QuicPacket
> data(
2653 framer_
.BuildUnsizedDataPacket(header
, frames
).packet
);
2654 ASSERT_TRUE(data
!= NULL
);
2656 test::CompareCharArraysWithHexError("constructed packet",
2657 data
->data(), data
->length(),
2662 TEST_P(QuicFramerTest
, Build2ByteSequenceNumberPaddingFramePacket
) {
2663 QuicPacketHeader header
;
2664 header
.public_header
.guid
= GG_UINT64_C(0xFEDCBA9876543210);
2665 header
.public_header
.reset_flag
= false;
2666 header
.public_header
.version_flag
= false;
2667 header
.fec_flag
= false;
2668 header
.entropy_flag
= false;
2669 header
.public_header
.sequence_number_length
= PACKET_2BYTE_SEQUENCE_NUMBER
;
2670 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
2671 header
.fec_group
= 0;
2673 QuicPaddingFrame padding_frame
;
2676 frames
.push_back(QuicFrame(&padding_frame
));
2678 unsigned char packet
[kMaxPacketSize
] = {
2679 // public flags (8 byte guid and 2 byte sequence number)
2682 0x10, 0x32, 0x54, 0x76,
2683 0x98, 0xBA, 0xDC, 0xFE,
2684 // packet sequence number
2689 // frame type (padding frame)
2691 0x00, 0x00, 0x00, 0x00
2694 uint64 header_size
=
2695 GetPacketHeaderSize(PACKET_8BYTE_GUID
, !kIncludeVersion
,
2696 PACKET_2BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
2697 memset(packet
+ header_size
+ 1, 0x00, kMaxPacketSize
- header_size
- 1);
2699 scoped_ptr
<QuicPacket
> data(
2700 framer_
.BuildUnsizedDataPacket(header
, frames
).packet
);
2701 ASSERT_TRUE(data
!= NULL
);
2703 test::CompareCharArraysWithHexError("constructed packet",
2704 data
->data(), data
->length(),
2709 TEST_P(QuicFramerTest
, Build1ByteSequenceNumberPaddingFramePacket
) {
2710 QuicPacketHeader header
;
2711 header
.public_header
.guid
= GG_UINT64_C(0xFEDCBA9876543210);
2712 header
.public_header
.reset_flag
= false;
2713 header
.public_header
.version_flag
= false;
2714 header
.fec_flag
= false;
2715 header
.entropy_flag
= false;
2716 header
.public_header
.sequence_number_length
= PACKET_1BYTE_SEQUENCE_NUMBER
;
2717 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
2718 header
.fec_group
= 0;
2720 QuicPaddingFrame padding_frame
;
2723 frames
.push_back(QuicFrame(&padding_frame
));
2725 unsigned char packet
[kMaxPacketSize
] = {
2726 // public flags (8 byte guid and 1 byte sequence number)
2729 0x10, 0x32, 0x54, 0x76,
2730 0x98, 0xBA, 0xDC, 0xFE,
2731 // packet sequence number
2736 // frame type (padding frame)
2738 0x00, 0x00, 0x00, 0x00
2741 uint64 header_size
=
2742 GetPacketHeaderSize(PACKET_8BYTE_GUID
, !kIncludeVersion
,
2743 PACKET_1BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
2744 memset(packet
+ header_size
+ 1, 0x00, kMaxPacketSize
- header_size
- 1);
2746 scoped_ptr
<QuicPacket
> data(
2747 framer_
.BuildUnsizedDataPacket(header
, frames
).packet
);
2748 ASSERT_TRUE(data
!= NULL
);
2750 test::CompareCharArraysWithHexError("constructed packet",
2751 data
->data(), data
->length(),
2756 TEST_P(QuicFramerTest
, BuildStreamFramePacket
) {
2757 QuicPacketHeader header
;
2758 header
.public_header
.guid
= GG_UINT64_C(0xFEDCBA9876543210);
2759 header
.public_header
.reset_flag
= false;
2760 header
.public_header
.version_flag
= false;
2761 header
.fec_flag
= false;
2762 header
.entropy_flag
= true;
2763 header
.packet_sequence_number
= GG_UINT64_C(0x77123456789ABC);
2764 header
.fec_group
= 0;
2766 QuicStreamFrame stream_frame
;
2767 stream_frame
.stream_id
= 0x01020304;
2768 stream_frame
.fin
= true;
2769 stream_frame
.offset
= GG_UINT64_C(0xBA98FEDC32107654);
2770 stream_frame
.data
= MakeIOVector("hello world!");
2773 frames
.push_back(QuicFrame(&stream_frame
));
2775 unsigned char packet
[] = {
2776 // public flags (8 byte guid)
2779 0x10, 0x32, 0x54, 0x76,
2780 0x98, 0xBA, 0xDC, 0xFE,
2781 // packet sequence number
2782 0xBC, 0x9A, 0x78, 0x56,
2784 // private flags (entropy)
2787 // frame type (stream frame with fin and no length)
2790 0x04, 0x03, 0x02, 0x01,
2792 0x54, 0x76, 0x10, 0x32,
2793 0xDC, 0xFE, 0x98, 0xBA,
2800 scoped_ptr
<QuicPacket
> data(
2801 framer_
.BuildUnsizedDataPacket(header
, frames
).packet
);
2802 ASSERT_TRUE(data
!= NULL
);
2804 test::CompareCharArraysWithHexError("constructed packet",
2805 data
->data(), data
->length(),
2806 AsChars(packet
), arraysize(packet
));
2809 TEST_P(QuicFramerTest
, BuildStreamFramePacketWithVersionFlag
) {
2810 QuicPacketHeader header
;
2811 header
.public_header
.guid
= GG_UINT64_C(0xFEDCBA9876543210);
2812 header
.public_header
.reset_flag
= false;
2813 header
.public_header
.version_flag
= true;
2814 header
.fec_flag
= false;
2815 header
.entropy_flag
= true;
2816 header
.packet_sequence_number
= GG_UINT64_C(0x77123456789ABC);
2817 header
.fec_group
= 0;
2819 QuicStreamFrame stream_frame
;
2820 stream_frame
.stream_id
= 0x01020304;
2821 stream_frame
.fin
= true;
2822 stream_frame
.offset
= GG_UINT64_C(0xBA98FEDC32107654);
2823 stream_frame
.data
= MakeIOVector("hello world!");
2826 frames
.push_back(QuicFrame(&stream_frame
));
2828 unsigned char packet
[] = {
2829 // public flags (version, 8 byte guid)
2832 0x10, 0x32, 0x54, 0x76,
2833 0x98, 0xBA, 0xDC, 0xFE,
2835 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
2836 // packet sequence number
2837 0xBC, 0x9A, 0x78, 0x56,
2839 // private flags (entropy)
2842 // frame type (stream frame with fin and no length)
2845 0x04, 0x03, 0x02, 0x01,
2847 0x54, 0x76, 0x10, 0x32,
2848 0xDC, 0xFE, 0x98, 0xBA,
2855 QuicFramerPeer::SetIsServer(&framer_
, false);
2856 scoped_ptr
<QuicPacket
> data(
2857 framer_
.BuildUnsizedDataPacket(header
, frames
).packet
);
2858 ASSERT_TRUE(data
!= NULL
);
2860 test::CompareCharArraysWithHexError("constructed packet",
2861 data
->data(), data
->length(),
2862 AsChars(packet
), arraysize(packet
));
2865 TEST_P(QuicFramerTest
, BuildVersionNegotiationPacket
) {
2866 QuicPacketPublicHeader header
;
2867 header
.guid
= GG_UINT64_C(0xFEDCBA9876543210);
2868 header
.reset_flag
= false;
2869 header
.version_flag
= true;
2871 unsigned char packet
[] = {
2872 // public flags (version, 8 byte guid)
2875 0x10, 0x32, 0x54, 0x76,
2876 0x98, 0xBA, 0xDC, 0xFE,
2878 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
2881 QuicVersionVector versions
;
2882 versions
.push_back(GetParam());
2883 scoped_ptr
<QuicEncryptedPacket
> data(
2884 framer_
.BuildVersionNegotiationPacket(header
, versions
));
2886 test::CompareCharArraysWithHexError("constructed packet",
2887 data
->data(), data
->length(),
2888 AsChars(packet
), arraysize(packet
));
2891 TEST_P(QuicFramerTest
, DISABLED_BuildAckFramePacketv11
) {
2892 if (GetParam() > QUIC_VERSION_11
) {
2895 QuicPacketHeader header
;
2896 header
.public_header
.guid
= GG_UINT64_C(0xFEDCBA9876543210);
2897 header
.public_header
.reset_flag
= false;
2898 header
.public_header
.version_flag
= false;
2899 header
.fec_flag
= false;
2900 header
.entropy_flag
= true;
2901 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
2902 header
.fec_group
= 0;
2904 QuicAckFrame ack_frame
;
2905 ack_frame
.received_info
.entropy_hash
= 0x43;
2906 ack_frame
.received_info
.largest_observed
= GG_UINT64_C(0x770123456789ABF);
2907 ack_frame
.received_info
.delta_time_largest_observed
= QuicTime::Delta::Zero();
2908 ack_frame
.received_info
.missing_packets
.insert(
2909 GG_UINT64_C(0x770123456789ABE));
2910 ack_frame
.sent_info
.entropy_hash
= 0x14;
2911 ack_frame
.sent_info
.least_unacked
= GG_UINT64_C(0x770123456789AA0);
2914 frames
.push_back(QuicFrame(&ack_frame
));
2916 unsigned char packet
[] = {
2917 // public flags (8 byte guid)
2920 0x10, 0x32, 0x54, 0x76,
2921 0x98, 0xBA, 0xDC, 0xFE,
2922 // packet sequence number
2923 0xBC, 0x9A, 0x78, 0x56,
2925 // private flags (entropy)
2928 // frame type (ack frame)
2930 // entropy hash of sent packets till least awaiting - 1.
2932 // least packet sequence number awaiting an ack
2933 0xA0, 0x9A, 0x78, 0x56,
2935 // entropy hash of all received packets.
2937 // largest observed packet sequence number
2938 0xBF, 0x9A, 0x78, 0x56,
2942 // num missing packets
2945 0xBE, 0x9A, 0x78, 0x56,
2949 scoped_ptr
<QuicPacket
> data(
2950 framer_
.BuildUnsizedDataPacket(header
, frames
).packet
);
2951 ASSERT_TRUE(data
!= NULL
);
2953 test::CompareCharArraysWithHexError("constructed packet",
2954 data
->data(), data
->length(),
2955 AsChars(packet
), arraysize(packet
));
2958 TEST_P(QuicFramerTest
, BuildAckFramePacket
) {
2959 if (GetParam() <= QUIC_VERSION_11
) {
2962 QuicPacketHeader header
;
2963 header
.public_header
.guid
= GG_UINT64_C(0xFEDCBA9876543210);
2964 header
.public_header
.reset_flag
= false;
2965 header
.public_header
.version_flag
= false;
2966 header
.fec_flag
= false;
2967 header
.entropy_flag
= true;
2968 header
.packet_sequence_number
= GG_UINT64_C(0x770123456789AA8);
2969 header
.fec_group
= 0;
2971 QuicAckFrame ack_frame
;
2972 ack_frame
.received_info
.entropy_hash
= 0x43;
2973 ack_frame
.received_info
.largest_observed
= GG_UINT64_C(0x770123456789ABF);
2974 ack_frame
.received_info
.delta_time_largest_observed
= QuicTime::Delta::Zero();
2975 ack_frame
.received_info
.missing_packets
.insert(
2976 GG_UINT64_C(0x770123456789ABE));
2977 ack_frame
.sent_info
.entropy_hash
= 0x14;
2978 ack_frame
.sent_info
.least_unacked
= GG_UINT64_C(0x770123456789AA0);
2981 frames
.push_back(QuicFrame(&ack_frame
));
2983 unsigned char packet
[] = {
2984 // public flags (8 byte guid)
2987 0x10, 0x32, 0x54, 0x76,
2988 0x98, 0xBA, 0xDC, 0xFE,
2989 // packet sequence number
2990 0xA8, 0x9A, 0x78, 0x56,
2992 // private flags (entropy)
2995 // frame type (ack frame)
2996 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
2998 // entropy hash of sent packets till least awaiting - 1.
3000 // least packet sequence number awaiting an ack, delta from sequence number.
3001 0x08, 0x00, 0x00, 0x00,
3003 // entropy hash of all received packets.
3005 // largest observed packet sequence number
3006 0xBF, 0x9A, 0x78, 0x56,
3010 // num missing packet ranges
3012 // missing packet delta
3014 // 0 more missing packets in range.
3018 scoped_ptr
<QuicPacket
> data(
3019 framer_
.BuildUnsizedDataPacket(header
, frames
).packet
);
3020 ASSERT_TRUE(data
!= NULL
);
3022 test::CompareCharArraysWithHexError("constructed packet",
3023 data
->data(), data
->length(),
3024 AsChars(packet
), arraysize(packet
));
3027 TEST_P(QuicFramerTest
, BuildCongestionFeedbackFramePacketTCP
) {
3028 QuicPacketHeader header
;
3029 header
.public_header
.guid
= GG_UINT64_C(0xFEDCBA9876543210);
3030 header
.public_header
.reset_flag
= false;
3031 header
.public_header
.version_flag
= false;
3032 header
.fec_flag
= false;
3033 header
.entropy_flag
= false;
3034 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
3035 header
.fec_group
= 0;
3037 QuicCongestionFeedbackFrame congestion_feedback_frame
;
3038 congestion_feedback_frame
.type
= kTCP
;
3039 congestion_feedback_frame
.tcp
.accumulated_number_of_lost_packets
= 0x0201;
3040 congestion_feedback_frame
.tcp
.receive_window
= 0x4030;
3043 frames
.push_back(QuicFrame(&congestion_feedback_frame
));
3045 unsigned char packet
[] = {
3046 // public flags (8 byte guid)
3049 0x10, 0x32, 0x54, 0x76,
3050 0x98, 0xBA, 0xDC, 0xFE,
3051 // packet sequence number
3052 0xBC, 0x9A, 0x78, 0x56,
3057 // frame type (congestion feedback frame)
3059 // congestion feedback type (TCP)
3061 // accumulated number of lost packets
3063 // TCP receive window
3067 scoped_ptr
<QuicPacket
> data(
3068 framer_
.BuildUnsizedDataPacket(header
, frames
).packet
);
3069 ASSERT_TRUE(data
!= NULL
);
3071 test::CompareCharArraysWithHexError("constructed packet",
3072 data
->data(), data
->length(),
3073 AsChars(packet
), arraysize(packet
));
3076 TEST_P(QuicFramerTest
, BuildCongestionFeedbackFramePacketInterArrival
) {
3077 QuicPacketHeader header
;
3078 header
.public_header
.guid
= GG_UINT64_C(0xFEDCBA9876543210);
3079 header
.public_header
.reset_flag
= false;
3080 header
.public_header
.version_flag
= false;
3081 header
.fec_flag
= false;
3082 header
.entropy_flag
= false;
3083 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
3084 header
.fec_group
= 0;
3086 QuicCongestionFeedbackFrame frame
;
3087 frame
.type
= kInterArrival
;
3088 frame
.inter_arrival
.accumulated_number_of_lost_packets
= 0x0302;
3089 frame
.inter_arrival
.received_packet_times
.insert(
3090 make_pair(GG_UINT64_C(0x0123456789ABA),
3091 start_
.Add(QuicTime::Delta::FromMicroseconds(
3092 GG_UINT64_C(0x07E1D2C3B4A59687)))));
3093 frame
.inter_arrival
.received_packet_times
.insert(
3094 make_pair(GG_UINT64_C(0x0123456789ABB),
3095 start_
.Add(QuicTime::Delta::FromMicroseconds(
3096 GG_UINT64_C(0x07E1D2C3B4A59688)))));
3097 frame
.inter_arrival
.received_packet_times
.insert(
3098 make_pair(GG_UINT64_C(0x0123456789ABD),
3099 start_
.Add(QuicTime::Delta::FromMicroseconds(
3100 GG_UINT64_C(0x07E1D2C3B4A59689)))));
3102 frames
.push_back(QuicFrame(&frame
));
3104 unsigned char packet
[] = {
3105 // public flags (8 byte guid)
3108 0x10, 0x32, 0x54, 0x76,
3109 0x98, 0xBA, 0xDC, 0xFE,
3110 // packet sequence number
3111 0xBC, 0x9A, 0x78, 0x56,
3116 // frame type (congestion feedback frame)
3118 // congestion feedback type (inter arrival)
3120 // accumulated_number_of_lost_packets
3122 // num received packets
3124 // lowest sequence number
3125 0xBA, 0x9A, 0x78, 0x56,
3128 0x87, 0x96, 0xA5, 0xB4,
3129 0xC3, 0xD2, 0xE1, 0x07,
3133 0x01, 0x00, 0x00, 0x00,
3134 // sequence delta (skip one packet)
3137 0x02, 0x00, 0x00, 0x00,
3140 scoped_ptr
<QuicPacket
> data(
3141 framer_
.BuildUnsizedDataPacket(header
, frames
).packet
);
3142 ASSERT_TRUE(data
!= NULL
);
3144 test::CompareCharArraysWithHexError("constructed packet",
3145 data
->data(), data
->length(),
3146 AsChars(packet
), arraysize(packet
));
3149 TEST_P(QuicFramerTest
, BuildCongestionFeedbackFramePacketFixRate
) {
3150 QuicPacketHeader header
;
3151 header
.public_header
.guid
= GG_UINT64_C(0xFEDCBA9876543210);
3152 header
.public_header
.reset_flag
= false;
3153 header
.public_header
.version_flag
= false;
3154 header
.fec_flag
= false;
3155 header
.entropy_flag
= false;
3156 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
3157 header
.fec_group
= 0;
3159 QuicCongestionFeedbackFrame congestion_feedback_frame
;
3160 congestion_feedback_frame
.type
= kFixRate
;
3161 congestion_feedback_frame
.fix_rate
.bitrate
3162 = QuicBandwidth::FromBytesPerSecond(0x04030201);
3165 frames
.push_back(QuicFrame(&congestion_feedback_frame
));
3167 unsigned char packet
[] = {
3168 // public flags (8 byte guid)
3171 0x10, 0x32, 0x54, 0x76,
3172 0x98, 0xBA, 0xDC, 0xFE,
3173 // packet sequence number
3174 0xBC, 0x9A, 0x78, 0x56,
3179 // frame type (congestion feedback frame)
3181 // congestion feedback type (fix rate)
3183 // bitrate_in_bytes_per_second;
3184 0x01, 0x02, 0x03, 0x04,
3187 scoped_ptr
<QuicPacket
> data(
3188 framer_
.BuildUnsizedDataPacket(header
, frames
).packet
);
3189 ASSERT_TRUE(data
!= NULL
);
3191 test::CompareCharArraysWithHexError("constructed packet",
3192 data
->data(), data
->length(),
3193 AsChars(packet
), arraysize(packet
));
3196 TEST_P(QuicFramerTest
, BuildCongestionFeedbackFramePacketInvalidFeedback
) {
3197 QuicPacketHeader header
;
3198 header
.public_header
.guid
= GG_UINT64_C(0xFEDCBA9876543210);
3199 header
.public_header
.reset_flag
= false;
3200 header
.public_header
.version_flag
= false;
3201 header
.fec_flag
= false;
3202 header
.entropy_flag
= false;
3203 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
3204 header
.fec_group
= 0;
3206 QuicCongestionFeedbackFrame congestion_feedback_frame
;
3207 congestion_feedback_frame
.type
=
3208 static_cast<CongestionFeedbackType
>(kFixRate
+ 1);
3211 frames
.push_back(QuicFrame(&congestion_feedback_frame
));
3213 scoped_ptr
<QuicPacket
> data(
3214 framer_
.BuildUnsizedDataPacket(header
, frames
).packet
);
3215 ASSERT_TRUE(data
== NULL
);
3218 TEST_P(QuicFramerTest
, BuildRstFramePacket
) {
3219 QuicPacketHeader header
;
3220 header
.public_header
.guid
= GG_UINT64_C(0xFEDCBA9876543210);
3221 header
.public_header
.reset_flag
= false;
3222 header
.public_header
.version_flag
= false;
3223 header
.fec_flag
= false;
3224 header
.entropy_flag
= false;
3225 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
3226 header
.fec_group
= 0;
3228 QuicRstStreamFrame rst_frame
;
3229 rst_frame
.stream_id
= 0x01020304;
3230 rst_frame
.error_code
= static_cast<QuicRstStreamErrorCode
>(0x05060708);
3231 rst_frame
.error_details
= "because I can";
3233 unsigned char packet
[] = {
3234 // public flags (8 byte guid)
3237 0x10, 0x32, 0x54, 0x76,
3238 0x98, 0xBA, 0xDC, 0xFE,
3239 // packet sequence number
3240 0xBC, 0x9A, 0x78, 0x56,
3245 // frame type (rst stream frame)
3248 0x04, 0x03, 0x02, 0x01,
3250 0x08, 0x07, 0x06, 0x05,
3251 // error details length
3261 frames
.push_back(QuicFrame(&rst_frame
));
3263 scoped_ptr
<QuicPacket
> data(
3264 framer_
.BuildUnsizedDataPacket(header
, frames
).packet
);
3265 ASSERT_TRUE(data
!= NULL
);
3267 test::CompareCharArraysWithHexError("constructed packet",
3268 data
->data(), data
->length(),
3269 AsChars(packet
), arraysize(packet
));
3272 TEST_P(QuicFramerTest
, DISABLED_BuildCloseFramePacketv11
) {
3273 if (GetParam() > QUIC_VERSION_11
) {
3276 QuicPacketHeader header
;
3277 header
.public_header
.guid
= GG_UINT64_C(0xFEDCBA9876543210);
3278 header
.public_header
.reset_flag
= false;
3279 header
.public_header
.version_flag
= false;
3280 header
.fec_flag
= false;
3281 header
.entropy_flag
= true;
3282 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
3283 header
.fec_group
= 0;
3285 QuicConnectionCloseFrame close_frame
;
3286 close_frame
.error_code
= static_cast<QuicErrorCode
>(0x05060708);
3287 close_frame
.error_details
= "because I can";
3289 QuicAckFrame
* ack_frame
= &close_frame
.ack_frame
;
3290 ack_frame
->received_info
.entropy_hash
= 0x43;
3291 ack_frame
->received_info
.largest_observed
= GG_UINT64_C(0x0123456789ABF);
3292 ack_frame
->received_info
.missing_packets
.insert(GG_UINT64_C(0x0123456789ABE));
3293 ack_frame
->sent_info
.entropy_hash
= 0xE0;
3294 ack_frame
->sent_info
.least_unacked
= GG_UINT64_C(0x0123456789AA0);
3297 frames
.push_back(QuicFrame(&close_frame
));
3299 unsigned char packet
[] = {
3300 // public flags (8 byte guid)
3303 0x10, 0x32, 0x54, 0x76,
3304 0x98, 0xBA, 0xDC, 0xFE,
3305 // packet sequence number
3306 0xBC, 0x9A, 0x78, 0x56,
3308 // private flags (entropy)
3311 // frame type (connection close frame)
3314 0x08, 0x07, 0x06, 0x05,
3315 // error details length
3324 // entropy hash of sent packets till least awaiting - 1.
3326 // least packet sequence number awaiting an ack
3327 0xA0, 0x9A, 0x78, 0x56,
3329 // entropy hash of all received packets.
3331 // largest observed packet sequence number
3332 0xBF, 0x9A, 0x78, 0x56,
3334 // Infinite delta time.
3335 0xFF, 0xFF, 0xFF, 0xFF,
3336 // num missing packets
3339 0xBE, 0x9A, 0x78, 0x56,
3343 scoped_ptr
<QuicPacket
> data(
3344 framer_
.BuildUnsizedDataPacket(header
, frames
).packet
);
3345 ASSERT_TRUE(data
!= NULL
);
3347 test::CompareCharArraysWithHexError("constructed packet",
3348 data
->data(), data
->length(),
3349 AsChars(packet
), arraysize(packet
));
3352 TEST_P(QuicFramerTest
, BuildCloseFramePacket
) {
3353 if (GetParam() <= QUIC_VERSION_11
) {
3356 QuicPacketHeader header
;
3357 header
.public_header
.guid
= GG_UINT64_C(0xFEDCBA9876543210);
3358 header
.public_header
.reset_flag
= false;
3359 header
.public_header
.version_flag
= false;
3360 header
.fec_flag
= false;
3361 header
.entropy_flag
= true;
3362 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
3363 header
.fec_group
= 0;
3365 QuicConnectionCloseFrame close_frame
;
3366 close_frame
.error_code
= static_cast<QuicErrorCode
>(0x05060708);
3367 close_frame
.error_details
= "because I can";
3370 frames
.push_back(QuicFrame(&close_frame
));
3372 unsigned char packet
[] = {
3373 // public flags (8 byte guid)
3376 0x10, 0x32, 0x54, 0x76,
3377 0x98, 0xBA, 0xDC, 0xFE,
3378 // packet sequence number
3379 0xBC, 0x9A, 0x78, 0x56,
3381 // private flags (entropy)
3384 // frame type (connection close frame)
3387 0x08, 0x07, 0x06, 0x05,
3388 // error details length
3397 scoped_ptr
<QuicPacket
> data(
3398 framer_
.BuildUnsizedDataPacket(header
, frames
).packet
);
3399 ASSERT_TRUE(data
!= NULL
);
3401 test::CompareCharArraysWithHexError("constructed packet",
3402 data
->data(), data
->length(),
3403 AsChars(packet
), arraysize(packet
));
3406 TEST_P(QuicFramerTest
, BuildGoAwayPacket
) {
3407 QuicPacketHeader header
;
3408 header
.public_header
.guid
= GG_UINT64_C(0xFEDCBA9876543210);
3409 header
.public_header
.reset_flag
= false;
3410 header
.public_header
.version_flag
= false;
3411 header
.fec_flag
= false;
3412 header
.entropy_flag
= true;
3413 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
3414 header
.fec_group
= 0;
3416 QuicGoAwayFrame goaway_frame
;
3417 goaway_frame
.error_code
= static_cast<QuicErrorCode
>(0x05060708);
3418 goaway_frame
.last_good_stream_id
= 0x01020304;
3419 goaway_frame
.reason_phrase
= "because I can";
3422 frames
.push_back(QuicFrame(&goaway_frame
));
3424 unsigned char packet
[] = {
3425 // public flags (8 byte guid)
3428 0x10, 0x32, 0x54, 0x76,
3429 0x98, 0xBA, 0xDC, 0xFE,
3430 // packet sequence number
3431 0xBC, 0x9A, 0x78, 0x56,
3433 // private flags(entropy)
3436 // frame type (go away frame)
3439 0x08, 0x07, 0x06, 0x05,
3441 0x04, 0x03, 0x02, 0x01,
3442 // error details length
3451 scoped_ptr
<QuicPacket
> data(
3452 framer_
.BuildUnsizedDataPacket(header
, frames
).packet
);
3453 ASSERT_TRUE(data
!= NULL
);
3455 test::CompareCharArraysWithHexError("constructed packet",
3456 data
->data(), data
->length(),
3457 AsChars(packet
), arraysize(packet
));
3460 TEST_P(QuicFramerTest
, BuildPublicResetPacket
) {
3461 QuicPublicResetPacket reset_packet
;
3462 reset_packet
.public_header
.guid
= GG_UINT64_C(0xFEDCBA9876543210);
3463 reset_packet
.public_header
.reset_flag
= true;
3464 reset_packet
.public_header
.version_flag
= false;
3465 reset_packet
.rejected_sequence_number
= GG_UINT64_C(0x123456789ABC);
3466 reset_packet
.nonce_proof
= GG_UINT64_C(0xABCDEF0123456789);
3468 unsigned char packet
[] = {
3469 // public flags (public reset, 8 byte GUID)
3472 0x10, 0x32, 0x54, 0x76,
3473 0x98, 0xBA, 0xDC, 0xFE,
3475 0x89, 0x67, 0x45, 0x23,
3476 0x01, 0xEF, 0xCD, 0xAB,
3477 // rejected sequence number
3478 0xBC, 0x9A, 0x78, 0x56,
3482 scoped_ptr
<QuicEncryptedPacket
> data(
3483 framer_
.BuildPublicResetPacket(reset_packet
));
3484 ASSERT_TRUE(data
!= NULL
);
3486 test::CompareCharArraysWithHexError("constructed packet",
3487 data
->data(), data
->length(),
3488 AsChars(packet
), arraysize(packet
));
3491 TEST_P(QuicFramerTest
, BuildFecPacket
) {
3492 QuicPacketHeader header
;
3493 header
.public_header
.guid
= GG_UINT64_C(0xFEDCBA9876543210);
3494 header
.public_header
.reset_flag
= false;
3495 header
.public_header
.version_flag
= false;
3496 header
.fec_flag
= true;
3497 header
.entropy_flag
= true;
3498 header
.packet_sequence_number
= (GG_UINT64_C(0x123456789ABC));
3499 header
.is_in_fec_group
= IN_FEC_GROUP
;
3500 header
.fec_group
= GG_UINT64_C(0x123456789ABB);;
3502 QuicFecData fec_data
;
3503 fec_data
.fec_group
= 1;
3504 fec_data
.redundancy
= "abcdefghijklmnop";
3506 unsigned char packet
[] = {
3507 // public flags (8 byte guid)
3510 0x10, 0x32, 0x54, 0x76,
3511 0x98, 0xBA, 0xDC, 0xFE,
3512 // packet sequence number
3513 0xBC, 0x9A, 0x78, 0x56,
3515 // private flags (entropy & fec group & fec packet)
3517 // first fec protected packet offset
3527 scoped_ptr
<QuicPacket
> data(
3528 framer_
.BuildFecPacket(header
, fec_data
).packet
);
3529 ASSERT_TRUE(data
!= NULL
);
3531 test::CompareCharArraysWithHexError("constructed packet",
3532 data
->data(), data
->length(),
3533 AsChars(packet
), arraysize(packet
));
3536 TEST_P(QuicFramerTest
, EncryptPacket
) {
3537 QuicPacketSequenceNumber sequence_number
= GG_UINT64_C(0x123456789ABC);
3538 unsigned char packet
[] = {
3539 // public flags (8 byte guid)
3542 0x10, 0x32, 0x54, 0x76,
3543 0x98, 0xBA, 0xDC, 0xFE,
3544 // packet sequence number
3545 0xBC, 0x9A, 0x78, 0x56,
3547 // private flags (fec group & fec packet)
3549 // first fec protected packet offset
3559 scoped_ptr
<QuicPacket
> raw(
3560 QuicPacket::NewDataPacket(AsChars(packet
), arraysize(packet
), false,
3561 PACKET_8BYTE_GUID
, !kIncludeVersion
,
3562 PACKET_6BYTE_SEQUENCE_NUMBER
));
3563 scoped_ptr
<QuicEncryptedPacket
> encrypted(
3564 framer_
.EncryptPacket(ENCRYPTION_NONE
, sequence_number
, *raw
));
3566 ASSERT_TRUE(encrypted
.get() != NULL
);
3567 EXPECT_TRUE(CheckEncryption(sequence_number
, raw
.get()));
3570 TEST_P(QuicFramerTest
, EncryptPacketWithVersionFlag
) {
3571 QuicPacketSequenceNumber sequence_number
= GG_UINT64_C(0x123456789ABC);
3572 unsigned char packet
[] = {
3573 // public flags (version, 8 byte guid)
3576 0x10, 0x32, 0x54, 0x76,
3577 0x98, 0xBA, 0xDC, 0xFE,
3580 // packet sequence number
3581 0xBC, 0x9A, 0x78, 0x56,
3583 // private flags (fec group & fec flags)
3585 // first fec protected packet offset
3595 scoped_ptr
<QuicPacket
> raw(
3596 QuicPacket::NewDataPacket(AsChars(packet
), arraysize(packet
), false,
3597 PACKET_8BYTE_GUID
, kIncludeVersion
,
3598 PACKET_6BYTE_SEQUENCE_NUMBER
));
3599 scoped_ptr
<QuicEncryptedPacket
> encrypted(
3600 framer_
.EncryptPacket(ENCRYPTION_NONE
, sequence_number
, *raw
));
3602 ASSERT_TRUE(encrypted
.get() != NULL
);
3603 EXPECT_TRUE(CheckEncryption(sequence_number
, raw
.get()));
3606 // TODO(rch): re-enable after https://codereview.chromium.org/11820005/
3607 // lands. Currently this is causing valgrind problems, but it should be
3608 // fixed in the followup CL.
3609 TEST_P(QuicFramerTest
, DISABLED_CalculateLargestReceived
) {
3610 SequenceNumberSet missing
;
3615 // These two we just walk to the next gap, and return the largest seen.
3616 EXPECT_EQ(4u, QuicFramer::CalculateLargestObserved(missing
, missing
.find(1)));
3617 EXPECT_EQ(6u, QuicFramer::CalculateLargestObserved(missing
, missing
.find(5)));
3620 // For 1, we can't go forward as 2 would be implicitly acked so we return the
3621 // largest missing packet.
3622 EXPECT_EQ(1u, QuicFramer::CalculateLargestObserved(missing
, missing
.find(1)));
3623 // For 2, we've seen 3 and 4, so can admit to a largest observed.
3624 EXPECT_EQ(4u, QuicFramer::CalculateLargestObserved(missing
, missing
.find(2)));
3627 // TODO(rch) enable after landing the revised truncation CL.
3628 TEST_P(QuicFramerTest
, DISABLED_Truncation
) {
3629 QuicPacketHeader header
;
3630 header
.public_header
.guid
= GG_UINT64_C(0xFEDCBA9876543210);
3631 header
.public_header
.reset_flag
= false;
3632 header
.public_header
.version_flag
= false;
3633 header
.fec_flag
= false;
3634 header
.entropy_flag
= false;
3635 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
3636 header
.fec_group
= 0;
3638 QuicConnectionCloseFrame close_frame
;
3639 QuicAckFrame
* ack_frame
= &close_frame
.ack_frame
;
3640 close_frame
.error_code
= static_cast<QuicErrorCode
>(0x05);
3641 close_frame
.error_details
= "because I can";
3642 ack_frame
->received_info
.largest_observed
= 601;
3643 ack_frame
->sent_info
.least_unacked
= 0;
3644 for (uint64 i
= 1; i
< ack_frame
->received_info
.largest_observed
; i
+= 2) {
3645 ack_frame
->received_info
.missing_packets
.insert(i
);
3648 // Create a packet with just the ack
3650 frame
.type
= ACK_FRAME
;
3651 frame
.ack_frame
= ack_frame
;
3653 frames
.push_back(frame
);
3655 scoped_ptr
<QuicPacket
> raw_ack_packet(
3656 framer_
.BuildUnsizedDataPacket(header
, frames
).packet
);
3657 ASSERT_TRUE(raw_ack_packet
!= NULL
);
3659 scoped_ptr
<QuicEncryptedPacket
> ack_packet(
3660 framer_
.EncryptPacket(ENCRYPTION_NONE
, header
.packet_sequence_number
,
3663 // Create a packet with just connection close.
3664 // TODO(ianswett): Remove this section when v11 is retired because v12 no
3665 // longer embeds an ack frame in the connection close frame.
3667 frame
.type
= CONNECTION_CLOSE_FRAME
;
3668 frame
.connection_close_frame
= &close_frame
;
3669 frames
.push_back(frame
);
3671 scoped_ptr
<QuicPacket
> raw_close_packet(
3672 framer_
.BuildUnsizedDataPacket(header
, frames
).packet
);
3673 ASSERT_TRUE(raw_close_packet
!= NULL
);
3675 scoped_ptr
<QuicEncryptedPacket
> close_packet(
3676 framer_
.EncryptPacket(ENCRYPTION_NONE
, header
.packet_sequence_number
,
3677 *raw_close_packet
));
3679 // Now make sure we can turn our ack packet back into an ack frame
3680 ASSERT_TRUE(framer_
.ProcessPacket(*ack_packet
));
3681 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
3682 const QuicAckFrame
& processed_ack_frame
= *visitor_
.ack_frames_
[0];
3683 EXPECT_EQ(0u, processed_ack_frame
.sent_info
.least_unacked
);
3684 if (GetParam() > QUIC_VERSION_11
) {
3685 EXPECT_TRUE(processed_ack_frame
.received_info
.is_truncated
);
3686 EXPECT_EQ(510u, processed_ack_frame
.received_info
.largest_observed
);
3687 ASSERT_EQ(255u, processed_ack_frame
.received_info
.missing_packets
.size());
3688 SequenceNumberSet::const_iterator missing_iter
=
3689 processed_ack_frame
.received_info
.missing_packets
.begin();
3690 EXPECT_EQ(1u, *missing_iter
);
3691 SequenceNumberSet::const_reverse_iterator last_missing_iter
=
3692 processed_ack_frame
.received_info
.missing_packets
.rbegin();
3693 EXPECT_EQ(509u, *last_missing_iter
);
3696 // And do the same for the close frame.
3697 ASSERT_TRUE(framer_
.ProcessPacket(*close_packet
));
3700 TEST_P(QuicFramerTest
, CleanTruncation
) {
3701 QuicPacketHeader header
;
3702 header
.public_header
.guid
= GG_UINT64_C(0xFEDCBA9876543210);
3703 header
.public_header
.reset_flag
= false;
3704 header
.public_header
.version_flag
= false;
3705 header
.fec_flag
= false;
3706 header
.entropy_flag
= true;
3707 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
3708 header
.fec_group
= 0;
3710 QuicConnectionCloseFrame close_frame
;
3711 QuicAckFrame
* ack_frame
= &close_frame
.ack_frame
;
3712 close_frame
.error_code
= static_cast<QuicErrorCode
>(0x05);
3713 close_frame
.error_details
= "because I can";
3714 ack_frame
->received_info
.largest_observed
= 201;
3715 ack_frame
->sent_info
.least_unacked
= 0;
3716 for (uint64 i
= 1; i
< ack_frame
->received_info
.largest_observed
; ++i
) {
3717 ack_frame
->received_info
.missing_packets
.insert(i
);
3720 // Create a packet with just the ack
3722 frame
.type
= ACK_FRAME
;
3723 frame
.ack_frame
= ack_frame
;
3725 frames
.push_back(frame
);
3727 scoped_ptr
<QuicPacket
> raw_ack_packet(
3728 framer_
.BuildUnsizedDataPacket(header
, frames
).packet
);
3729 ASSERT_TRUE(raw_ack_packet
!= NULL
);
3731 scoped_ptr
<QuicEncryptedPacket
> ack_packet(
3732 framer_
.EncryptPacket(ENCRYPTION_NONE
, header
.packet_sequence_number
,
3735 // Create a packet with just connection close.
3737 frame
.type
= CONNECTION_CLOSE_FRAME
;
3738 frame
.connection_close_frame
= &close_frame
;
3739 frames
.push_back(frame
);
3741 scoped_ptr
<QuicPacket
> raw_close_packet(
3742 framer_
.BuildUnsizedDataPacket(header
, frames
).packet
);
3743 ASSERT_TRUE(raw_close_packet
!= NULL
);
3745 scoped_ptr
<QuicEncryptedPacket
> close_packet(
3746 framer_
.EncryptPacket(ENCRYPTION_NONE
, header
.packet_sequence_number
,
3747 *raw_close_packet
));
3749 // Now make sure we can turn our ack packet back into an ack frame
3750 ASSERT_TRUE(framer_
.ProcessPacket(*ack_packet
));
3752 // And do the same for the close frame.
3753 ASSERT_TRUE(framer_
.ProcessPacket(*close_packet
));
3755 // Test for clean truncation of the ack by comparing the length of the
3756 // original packets to the re-serialized packets.
3758 frame
.type
= ACK_FRAME
;
3759 frame
.ack_frame
= visitor_
.ack_frames_
[0];
3760 frames
.push_back(frame
);
3762 size_t original_raw_length
= raw_ack_packet
->length();
3763 raw_ack_packet
.reset(
3764 framer_
.BuildUnsizedDataPacket(header
, frames
).packet
);
3765 ASSERT_TRUE(raw_ack_packet
!= NULL
);
3766 EXPECT_EQ(original_raw_length
, raw_ack_packet
->length());
3769 frame
.type
= CONNECTION_CLOSE_FRAME
;
3770 frame
.connection_close_frame
= &visitor_
.connection_close_frame_
;
3771 frames
.push_back(frame
);
3773 original_raw_length
= raw_close_packet
->length();
3774 raw_close_packet
.reset(
3775 framer_
.BuildUnsizedDataPacket(header
, frames
).packet
);
3776 ASSERT_TRUE(raw_ack_packet
!= NULL
);
3777 EXPECT_EQ(original_raw_length
, raw_close_packet
->length());
3780 TEST_P(QuicFramerTest
, EntropyFlagTest
) {
3781 unsigned char packet
[] = {
3782 // public flags (8 byte guid)
3785 0x10, 0x32, 0x54, 0x76,
3786 0x98, 0xBA, 0xDC, 0xFE,
3787 // packet sequence number
3788 0xBC, 0x9A, 0x78, 0x56,
3790 // private flags (Entropy)
3793 // frame type (stream frame with fin and no length)
3796 0x04, 0x03, 0x02, 0x01,
3798 0x54, 0x76, 0x10, 0x32,
3799 0xDC, 0xFE, 0x98, 0xBA,
3806 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
3807 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
3808 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
3809 ASSERT_TRUE(visitor_
.header_
.get());
3810 EXPECT_TRUE(visitor_
.header_
->entropy_flag
);
3811 EXPECT_EQ(1 << 4, visitor_
.header_
->entropy_hash
);
3812 EXPECT_FALSE(visitor_
.header_
->fec_flag
);
3815 TEST_P(QuicFramerTest
, FecEntropyTest
) {
3816 unsigned char packet
[] = {
3817 // public flags (8 byte guid)
3820 0x10, 0x32, 0x54, 0x76,
3821 0x98, 0xBA, 0xDC, 0xFE,
3822 // packet sequence number
3823 0xBC, 0x9A, 0x78, 0x56,
3825 // private flags (Entropy & fec group & FEC)
3827 // first fec protected packet offset
3830 // frame type (stream frame with fin and no length)
3833 0x04, 0x03, 0x02, 0x01,
3835 0x54, 0x76, 0x10, 0x32,
3836 0xDC, 0xFE, 0x98, 0xBA,
3843 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
3844 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
3845 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
3846 ASSERT_TRUE(visitor_
.header_
.get());
3847 EXPECT_TRUE(visitor_
.header_
->fec_flag
);
3848 EXPECT_TRUE(visitor_
.header_
->entropy_flag
);
3849 EXPECT_EQ(1 << 4, visitor_
.header_
->entropy_hash
);
3852 TEST_P(QuicFramerTest
, StopPacketProcessing
) {
3853 unsigned char packet
[] = {
3854 // public flags (8 byte guid)
3857 0x10, 0x32, 0x54, 0x76,
3858 0x98, 0xBA, 0xDC, 0xFE,
3859 // packet sequence number
3860 0xBC, 0x9A, 0x78, 0x56,
3865 // frame type (stream frame with fin)
3868 0x04, 0x03, 0x02, 0x01,
3870 0x54, 0x76, 0x10, 0x32,
3871 0xDC, 0xFE, 0x98, 0xBA,
3879 // frame type (ack frame)
3881 // entropy hash of sent packets till least awaiting - 1.
3883 // least packet sequence number awaiting an ack
3884 0xA0, 0x9A, 0x78, 0x56,
3886 // entropy hash of all received packets.
3888 // largest observed packet sequence number
3889 0xBF, 0x9A, 0x78, 0x56,
3891 // num missing packets
3894 0xBE, 0x9A, 0x78, 0x56,
3898 MockFramerVisitor visitor
;
3899 framer_
.set_visitor(&visitor
);
3900 EXPECT_CALL(visitor
, OnPacket());
3901 EXPECT_CALL(visitor
, OnPacketHeader(_
));
3902 EXPECT_CALL(visitor
, OnStreamFrame(_
)).WillOnce(Return(false));
3903 EXPECT_CALL(visitor
, OnAckFrame(_
)).Times(0);
3904 EXPECT_CALL(visitor
, OnPacketComplete());
3906 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
3907 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
3908 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
3911 TEST_P(QuicFramerTest
, DISABLED_ConnectionCloseWithInvalidAck
) {
3912 if (GetParam() > QUIC_VERSION_11
) {
3915 unsigned char packet
[] = {
3916 // public flags (8 byte guid)
3919 0x10, 0x32, 0x54, 0x76,
3920 0x98, 0xBA, 0xDC, 0xFE,
3921 // packet sequence number
3922 0xBC, 0x9A, 0x78, 0x56,
3927 // frame type (connection close frame)
3930 0x11, 0x00, 0x00, 0x00,
3931 // error details length
3940 // entropy hash of sent packets till least awaiting - 1.
3942 // least packet sequence number awaiting an ack
3943 0xA0, 0x9A, 0x78, 0x56,
3945 // entropy hash of all received packets.
3947 // largest observed packet sequence number
3948 0xBF, 0x9A, 0x78, 0x56,
3950 // Infinite delta time.
3951 0xFF, 0xFF, 0xFF, 0xFF,
3952 // num missing packets
3955 0xBE, 0x9A, 0x78, 0x56,
3959 MockFramerVisitor visitor
;
3960 framer_
.set_visitor(&visitor
);
3961 EXPECT_CALL(visitor
, OnPacket());
3962 EXPECT_CALL(visitor
, OnPacketHeader(_
));
3963 EXPECT_CALL(visitor
, OnAckFrame(_
)).WillOnce(Return(false));
3964 EXPECT_CALL(visitor
, OnConnectionCloseFrame(_
)).Times(0);
3965 EXPECT_CALL(visitor
, OnPacketComplete());
3967 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
3968 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
3969 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());