1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "net/quic/quic_framer.h"
12 #include "base/containers/hash_tables.h"
13 #include "base/logging.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/port.h"
16 #include "base/stl_util.h"
17 #include "net/quic/crypto/quic_decrypter.h"
18 #include "net/quic/crypto/quic_encrypter.h"
19 #include "net/quic/quic_protocol.h"
20 #include "net/quic/quic_utils.h"
21 #include "net/quic/test_tools/quic_framer_peer.h"
22 #include "net/quic/test_tools/quic_test_utils.h"
23 #include "net/test/gtest_util.h"
26 using base::StringPiece
;
29 using std::numeric_limits
;
33 using testing::Return
;
39 const QuicPacketSequenceNumber kEpoch
= GG_UINT64_C(1) << 48;
40 const QuicPacketSequenceNumber kMask
= kEpoch
- 1;
42 // Index into the connection_id offset in the header.
43 const size_t kConnectionIdOffset
= kPublicFlagsSize
;
44 // Index into the version string in the header. (if present).
45 const size_t kVersionOffset
= kConnectionIdOffset
+ PACKET_8BYTE_CONNECTION_ID
;
47 // Size in bytes of the stream frame fields for an arbitrary StreamID and
48 // offset and the last frame in a packet.
49 size_t GetMinStreamFrameSize() {
50 return kQuicFrameTypeSize
+ kQuicMaxStreamIdSize
+ kQuicMaxStreamOffsetSize
;
53 // Index into the sequence number offset in the header.
54 size_t GetSequenceNumberOffset(QuicConnectionIdLength connection_id_length
,
55 bool include_version
) {
56 return kConnectionIdOffset
+ connection_id_length
+
57 (include_version
? kQuicVersionSize
: 0);
60 size_t GetSequenceNumberOffset(bool include_version
) {
61 return GetSequenceNumberOffset(PACKET_8BYTE_CONNECTION_ID
, include_version
);
64 // Index into the private flags offset in the data packet header.
65 size_t GetPrivateFlagsOffset(QuicConnectionIdLength connection_id_length
,
66 bool include_version
) {
67 return GetSequenceNumberOffset(connection_id_length
, include_version
) +
68 PACKET_6BYTE_SEQUENCE_NUMBER
;
71 size_t GetPrivateFlagsOffset(bool include_version
) {
72 return GetPrivateFlagsOffset(PACKET_8BYTE_CONNECTION_ID
, include_version
);
75 size_t GetPrivateFlagsOffset(bool include_version
,
76 QuicSequenceNumberLength sequence_number_length
) {
77 return GetSequenceNumberOffset(PACKET_8BYTE_CONNECTION_ID
, include_version
) +
78 sequence_number_length
;
81 // Index into the fec group offset in the header.
82 size_t GetFecGroupOffset(QuicConnectionIdLength connection_id_length
,
83 bool include_version
) {
84 return GetPrivateFlagsOffset(connection_id_length
, include_version
) +
88 size_t GetFecGroupOffset(bool include_version
) {
89 return GetPrivateFlagsOffset(PACKET_8BYTE_CONNECTION_ID
, include_version
) +
93 size_t GetFecGroupOffset(bool include_version
,
94 QuicSequenceNumberLength sequence_number_length
) {
95 return GetPrivateFlagsOffset(include_version
, sequence_number_length
) +
99 // Index into the message tag of the public reset packet.
100 // Public resets always have full connection_ids.
101 const size_t kPublicResetPacketMessageTagOffset
=
102 kConnectionIdOffset
+ PACKET_8BYTE_CONNECTION_ID
;
104 class TestEncrypter
: public QuicEncrypter
{
106 ~TestEncrypter() override
{}
107 bool SetKey(StringPiece key
) override
{ return true; }
108 bool SetNoncePrefix(StringPiece nonce_prefix
) override
{ return true; }
109 bool Encrypt(StringPiece nonce
,
110 StringPiece associated_data
,
111 StringPiece plaintext
,
112 unsigned char* output
) override
{
113 CHECK(false) << "Not implemented";
116 bool EncryptPacket(QuicPacketSequenceNumber sequence_number
,
117 StringPiece associated_data
,
118 StringPiece plaintext
,
120 size_t* output_length
,
121 size_t max_output_length
) override
{
122 sequence_number_
= sequence_number
;
123 associated_data_
= associated_data
.as_string();
124 plaintext_
= plaintext
.as_string();
125 memcpy(output
, plaintext
.data(), plaintext
.length());
126 *output_length
= plaintext
.length();
129 size_t GetKeySize() const override
{ return 0; }
130 size_t GetNoncePrefixSize() const override
{ return 0; }
131 size_t GetMaxPlaintextSize(size_t ciphertext_size
) const override
{
132 return ciphertext_size
;
134 size_t GetCiphertextSize(size_t plaintext_size
) const override
{
135 return plaintext_size
;
137 StringPiece
GetKey() const override
{ return StringPiece(); }
138 StringPiece
GetNoncePrefix() const override
{ return StringPiece(); }
139 QuicPacketSequenceNumber sequence_number_
;
140 string associated_data_
;
144 class TestDecrypter
: public QuicDecrypter
{
146 ~TestDecrypter() override
{}
147 bool SetKey(StringPiece key
) override
{ return true; }
148 bool SetNoncePrefix(StringPiece nonce_prefix
) override
{ return true; }
149 bool DecryptPacket(QuicPacketSequenceNumber sequence_number
,
150 const StringPiece
& associated_data
,
151 const StringPiece
& ciphertext
,
153 size_t* output_length
,
154 size_t max_output_length
) override
{
155 sequence_number_
= sequence_number
;
156 associated_data_
= associated_data
.as_string();
157 ciphertext_
= ciphertext
.as_string();
158 memcpy(output
, ciphertext
.data(), ciphertext
.length());
159 *output_length
= ciphertext
.length();
162 StringPiece
GetKey() const override
{ return StringPiece(); }
163 StringPiece
GetNoncePrefix() const override
{ return StringPiece(); }
164 QuicPacketSequenceNumber sequence_number_
;
165 string associated_data_
;
169 class TestQuicVisitor
: public QuicFramerVisitorInterface
{
173 version_mismatch_(0),
177 complete_packets_(0),
179 accept_packet_(true),
180 accept_public_header_(true) {
183 ~TestQuicVisitor() override
{
184 STLDeleteElements(&stream_frames_
);
185 STLDeleteElements(&ack_frames_
);
186 STLDeleteElements(&stop_waiting_frames_
);
187 STLDeleteElements(&ping_frames_
);
188 STLDeleteElements(&fec_data_
);
189 STLDeleteElements(&stream_data_
);
190 STLDeleteElements(&fec_data_redundancy_
);
193 void OnError(QuicFramer
* f
) override
{
194 DVLOG(1) << "QuicFramer Error: " << QuicUtils::ErrorToString(f
->error())
195 << " (" << f
->error() << ")";
199 void OnPacket() override
{}
201 void OnPublicResetPacket(const QuicPublicResetPacket
& packet
) override
{
202 public_reset_packet_
.reset(new QuicPublicResetPacket(packet
));
205 void OnVersionNegotiationPacket(
206 const QuicVersionNegotiationPacket
& packet
) override
{
207 version_negotiation_packet_
.reset(new QuicVersionNegotiationPacket(packet
));
210 void OnRevivedPacket() override
{ ++revived_packets_
; }
212 bool OnProtocolVersionMismatch(QuicVersion version
) override
{
213 DVLOG(1) << "QuicFramer Version Mismatch, version: " << version
;
218 bool OnUnauthenticatedPublicHeader(
219 const QuicPacketPublicHeader
& header
) override
{
220 public_header_
.reset(new QuicPacketPublicHeader(header
));
221 return accept_public_header_
;
224 bool OnUnauthenticatedHeader(const QuicPacketHeader
& header
) override
{
228 void OnDecryptedPacket(EncryptionLevel level
) override
{}
230 bool OnPacketHeader(const QuicPacketHeader
& header
) override
{
232 header_
.reset(new QuicPacketHeader(header
));
233 return accept_packet_
;
236 bool OnStreamFrame(const QuicStreamFrame
& frame
) override
{
238 // Save a copy of the data so it is valid after the packet is processed.
239 stream_data_
.push_back(frame
.GetDataAsString());
240 QuicStreamFrame
* stream_frame
= new QuicStreamFrame(frame
);
241 // Make sure that the stream frame points to this data.
242 stream_frame
->data
.Clear();
243 stream_frame
->data
.Append(const_cast<char*>(stream_data_
.back()->data()),
244 stream_data_
.back()->size());
245 stream_frames_
.push_back(stream_frame
);
249 void OnFecProtectedPayload(StringPiece payload
) override
{
250 fec_protected_payload_
= payload
.as_string();
253 bool OnAckFrame(const QuicAckFrame
& frame
) override
{
255 ack_frames_
.push_back(new QuicAckFrame(frame
));
259 bool OnStopWaitingFrame(const QuicStopWaitingFrame
& frame
) override
{
261 stop_waiting_frames_
.push_back(new QuicStopWaitingFrame(frame
));
265 bool OnPingFrame(const QuicPingFrame
& frame
) override
{
267 ping_frames_
.push_back(new QuicPingFrame(frame
));
271 void OnFecData(const QuicFecData
& fec
) override
{
273 QuicFecData
* fec_data
= new QuicFecData();
274 fec_data
->fec_group
= fec
.fec_group
;
275 // Save a copy of the data so it is valid after the packet is processed.
276 string
* redundancy
= new string(fec
.redundancy
.as_string());
277 fec_data_redundancy_
.push_back(redundancy
);
278 fec_data
->redundancy
= StringPiece(*redundancy
);
279 fec_data_
.push_back(fec_data
);
282 void OnPacketComplete() override
{ ++complete_packets_
; }
284 bool OnRstStreamFrame(const QuicRstStreamFrame
& frame
) override
{
285 rst_stream_frame_
= frame
;
289 bool OnConnectionCloseFrame(const QuicConnectionCloseFrame
& frame
) override
{
290 connection_close_frame_
= frame
;
294 bool OnGoAwayFrame(const QuicGoAwayFrame
& frame
) override
{
295 goaway_frame_
= frame
;
299 bool OnWindowUpdateFrame(const QuicWindowUpdateFrame
& frame
) override
{
300 window_update_frame_
= frame
;
304 bool OnBlockedFrame(const QuicBlockedFrame
& frame
) override
{
305 blocked_frame_
= frame
;
309 // Counters from the visitor_ callbacks.
311 int version_mismatch_
;
315 int complete_packets_
;
316 int revived_packets_
;
318 bool accept_public_header_
;
320 scoped_ptr
<QuicPacketHeader
> header_
;
321 scoped_ptr
<QuicPacketPublicHeader
> public_header_
;
322 scoped_ptr
<QuicPublicResetPacket
> public_reset_packet_
;
323 scoped_ptr
<QuicVersionNegotiationPacket
> version_negotiation_packet_
;
324 vector
<QuicStreamFrame
*> stream_frames_
;
325 vector
<QuicAckFrame
*> ack_frames_
;
326 vector
<QuicStopWaitingFrame
*> stop_waiting_frames_
;
327 vector
<QuicPingFrame
*> ping_frames_
;
328 vector
<QuicFecData
*> fec_data_
;
329 string fec_protected_payload_
;
330 QuicRstStreamFrame rst_stream_frame_
;
331 QuicConnectionCloseFrame connection_close_frame_
;
332 QuicGoAwayFrame goaway_frame_
;
333 QuicWindowUpdateFrame window_update_frame_
;
334 QuicBlockedFrame blocked_frame_
;
335 vector
<string
*> stream_data_
;
336 vector
<string
*> fec_data_redundancy_
;
339 class QuicFramerTest
: public ::testing::TestWithParam
<QuicVersion
> {
342 : encrypter_(new test::TestEncrypter()),
343 decrypter_(new test::TestDecrypter()),
344 start_(QuicTime::Zero().Add(QuicTime::Delta::FromMicroseconds(0x10))),
345 framer_(QuicSupportedVersions(), start_
, Perspective::IS_SERVER
) {
346 version_
= GetParam();
347 framer_
.set_version(version_
);
348 framer_
.SetDecrypter(decrypter_
, ENCRYPTION_NONE
);
349 framer_
.SetEncrypter(ENCRYPTION_NONE
, encrypter_
);
350 framer_
.set_visitor(&visitor_
);
351 framer_
.set_received_entropy_calculator(&entropy_calculator_
);
354 // Helper function to get unsigned char representation of digit in the
355 // units place of the current QUIC version number.
356 unsigned char GetQuicVersionDigitOnes() {
357 return static_cast<unsigned char> ('0' + version_
%10);
360 // Helper function to get unsigned char representation of digit in the
361 // tens place of the current QUIC version number.
362 unsigned char GetQuicVersionDigitTens() {
363 return static_cast<unsigned char> ('0' + (version_
/10)%10);
366 bool CheckEncryption(QuicPacketSequenceNumber sequence_number
,
367 QuicPacket
* packet
) {
368 if (sequence_number
!= encrypter_
->sequence_number_
) {
369 LOG(ERROR
) << "Encrypted incorrect packet sequence number. expected "
370 << sequence_number
<< " actual: "
371 << encrypter_
->sequence_number_
;
374 if (packet
->AssociatedData() != encrypter_
->associated_data_
) {
375 LOG(ERROR
) << "Encrypted incorrect associated data. expected "
376 << packet
->AssociatedData() << " actual: "
377 << encrypter_
->associated_data_
;
380 if (packet
->Plaintext() != encrypter_
->plaintext_
) {
381 LOG(ERROR
) << "Encrypted incorrect plaintext data. expected "
382 << packet
->Plaintext() << " actual: "
383 << encrypter_
->plaintext_
;
389 bool CheckDecryption(const QuicEncryptedPacket
& encrypted
,
390 bool includes_version
) {
391 if (visitor_
.header_
->packet_sequence_number
!=
392 decrypter_
->sequence_number_
) {
393 LOG(ERROR
) << "Decrypted incorrect packet sequence number. expected "
394 << visitor_
.header_
->packet_sequence_number
<< " actual: "
395 << decrypter_
->sequence_number_
;
398 if (QuicFramer::GetAssociatedDataFromEncryptedPacket(
399 encrypted
, PACKET_8BYTE_CONNECTION_ID
,
400 includes_version
, PACKET_6BYTE_SEQUENCE_NUMBER
) !=
401 decrypter_
->associated_data_
) {
402 LOG(ERROR
) << "Decrypted incorrect associated data. expected "
403 << QuicFramer::GetAssociatedDataFromEncryptedPacket(
404 encrypted
, PACKET_8BYTE_CONNECTION_ID
,
405 includes_version
, PACKET_6BYTE_SEQUENCE_NUMBER
)
406 << " actual: " << decrypter_
->associated_data_
;
409 StringPiece
ciphertext(encrypted
.AsStringPiece().substr(
410 GetStartOfEncryptedData(PACKET_8BYTE_CONNECTION_ID
, includes_version
,
411 PACKET_6BYTE_SEQUENCE_NUMBER
)));
412 if (ciphertext
!= decrypter_
->ciphertext_
) {
413 LOG(ERROR
) << "Decrypted incorrect ciphertext data. expected "
414 << ciphertext
<< " actual: "
415 << decrypter_
->ciphertext_
;
421 char* AsChars(unsigned char* data
) {
422 return reinterpret_cast<char*>(data
);
425 void CheckProcessingFails(unsigned char* packet
,
427 string expected_error
,
428 QuicErrorCode error_code
) {
429 QuicEncryptedPacket
encrypted(AsChars(packet
), len
, false);
430 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
)) << "len: " << len
;
431 EXPECT_EQ(expected_error
, framer_
.detailed_error()) << "len: " << len
;
432 EXPECT_EQ(error_code
, framer_
.error()) << "len: " << len
;
435 // Checks if the supplied string matches data in the supplied StreamFrame.
436 void CheckStreamFrameData(string str
, QuicStreamFrame
* frame
) {
437 scoped_ptr
<string
> frame_data(frame
->GetDataAsString());
438 EXPECT_EQ(str
, *frame_data
);
441 void CheckStreamFrameBoundaries(unsigned char* packet
,
442 size_t stream_id_size
,
443 bool include_version
) {
444 // Now test framing boundaries.
445 for (size_t i
= kQuicFrameTypeSize
; i
< GetMinStreamFrameSize(); ++i
) {
446 string expected_error
;
447 if (i
< kQuicFrameTypeSize
+ stream_id_size
) {
448 expected_error
= "Unable to read stream_id.";
449 } else if (i
< kQuicFrameTypeSize
+ stream_id_size
+
450 kQuicMaxStreamOffsetSize
) {
451 expected_error
= "Unable to read offset.";
453 expected_error
= "Unable to read frame data.";
455 CheckProcessingFails(
457 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, include_version
,
458 PACKET_6BYTE_SEQUENCE_NUMBER
,
460 expected_error
, QUIC_INVALID_STREAM_DATA
);
464 void CheckCalculatePacketSequenceNumber(
465 QuicPacketSequenceNumber expected_sequence_number
,
466 QuicPacketSequenceNumber last_sequence_number
) {
467 QuicPacketSequenceNumber wire_sequence_number
=
468 expected_sequence_number
& kMask
;
469 QuicFramerPeer::SetLastSequenceNumber(&framer_
, last_sequence_number
);
470 EXPECT_EQ(expected_sequence_number
,
471 QuicFramerPeer::CalculatePacketSequenceNumberFromWire(
472 &framer_
, PACKET_6BYTE_SEQUENCE_NUMBER
, wire_sequence_number
))
473 << "last_sequence_number: " << last_sequence_number
474 << " wire_sequence_number: " << wire_sequence_number
;
477 QuicPacket
* BuildDataPacket(const QuicPacketHeader
& header
,
478 const QuicFrames
& frames
) {
479 return BuildUnsizedDataPacket(&framer_
, header
, frames
);
482 QuicPacket
* BuildDataPacket(const QuicPacketHeader
& header
,
483 const QuicFrames
& frames
,
484 size_t packet_size
) {
485 return BuildUnsizedDataPacket(&framer_
, header
, frames
, packet_size
);
488 test::TestEncrypter
* encrypter_
;
489 test::TestDecrypter
* decrypter_
;
490 QuicVersion version_
;
493 test::TestQuicVisitor visitor_
;
494 test::TestEntropyCalculator entropy_calculator_
;
497 // Run all framer tests with all supported versions of QUIC.
498 INSTANTIATE_TEST_CASE_P(QuicFramerTests
,
500 ::testing::ValuesIn(kSupportedQuicVersions
));
502 TEST_P(QuicFramerTest
, CalculatePacketSequenceNumberFromWireNearEpochStart
) {
503 // A few quick manual sanity checks
504 CheckCalculatePacketSequenceNumber(GG_UINT64_C(1), GG_UINT64_C(0));
505 CheckCalculatePacketSequenceNumber(kEpoch
+ 1, kMask
);
506 CheckCalculatePacketSequenceNumber(kEpoch
, kMask
);
508 // Cases where the last number was close to the start of the range
509 for (uint64 last
= 0; last
< 10; last
++) {
510 // Small numbers should not wrap (even if they're out of order).
511 for (uint64 j
= 0; j
< 10; j
++) {
512 CheckCalculatePacketSequenceNumber(j
, last
);
515 // Large numbers should not wrap either (because we're near 0 already).
516 for (uint64 j
= 0; j
< 10; j
++) {
517 CheckCalculatePacketSequenceNumber(kEpoch
- 1 - j
, last
);
522 TEST_P(QuicFramerTest
, CalculatePacketSequenceNumberFromWireNearEpochEnd
) {
523 // Cases where the last number was close to the end of the range
524 for (uint64 i
= 0; i
< 10; i
++) {
525 QuicPacketSequenceNumber last
= kEpoch
- i
;
527 // Small numbers should wrap.
528 for (uint64 j
= 0; j
< 10; j
++) {
529 CheckCalculatePacketSequenceNumber(kEpoch
+ j
, last
);
532 // Large numbers should not (even if they're out of order).
533 for (uint64 j
= 0; j
< 10; j
++) {
534 CheckCalculatePacketSequenceNumber(kEpoch
- 1 - j
, last
);
539 // Next check where we're in a non-zero epoch to verify we handle
540 // reverse wrapping, too.
541 TEST_P(QuicFramerTest
, CalculatePacketSequenceNumberFromWireNearPrevEpoch
) {
542 const uint64 prev_epoch
= 1 * kEpoch
;
543 const uint64 cur_epoch
= 2 * kEpoch
;
544 // Cases where the last number was close to the start of the range
545 for (uint64 i
= 0; i
< 10; i
++) {
546 uint64 last
= cur_epoch
+ i
;
547 // Small number should not wrap (even if they're out of order).
548 for (uint64 j
= 0; j
< 10; j
++) {
549 CheckCalculatePacketSequenceNumber(cur_epoch
+ j
, last
);
552 // But large numbers should reverse wrap.
553 for (uint64 j
= 0; j
< 10; j
++) {
554 uint64 num
= kEpoch
- 1 - j
;
555 CheckCalculatePacketSequenceNumber(prev_epoch
+ num
, last
);
560 TEST_P(QuicFramerTest
, CalculatePacketSequenceNumberFromWireNearNextEpoch
) {
561 const uint64 cur_epoch
= 2 * kEpoch
;
562 const uint64 next_epoch
= 3 * kEpoch
;
563 // Cases where the last number was close to the end of the range
564 for (uint64 i
= 0; i
< 10; i
++) {
565 QuicPacketSequenceNumber last
= next_epoch
- 1 - i
;
567 // Small numbers should wrap.
568 for (uint64 j
= 0; j
< 10; j
++) {
569 CheckCalculatePacketSequenceNumber(next_epoch
+ j
, last
);
572 // but large numbers should not (even if they're out of order).
573 for (uint64 j
= 0; j
< 10; j
++) {
574 uint64 num
= kEpoch
- 1 - j
;
575 CheckCalculatePacketSequenceNumber(cur_epoch
+ num
, last
);
580 TEST_P(QuicFramerTest
, CalculatePacketSequenceNumberFromWireNearNextMax
) {
581 const uint64 max_number
= numeric_limits
<uint64
>::max();
582 const uint64 max_epoch
= max_number
& ~kMask
;
584 // Cases where the last number was close to the end of the range
585 for (uint64 i
= 0; i
< 10; i
++) {
586 // Subtract 1, because the expected next sequence number is 1 more than the
587 // last sequence number.
588 QuicPacketSequenceNumber last
= max_number
- i
- 1;
590 // Small numbers should not wrap, because they have nowhere to go.
591 for (uint64 j
= 0; j
< 10; j
++) {
592 CheckCalculatePacketSequenceNumber(max_epoch
+ j
, last
);
595 // Large numbers should not wrap either.
596 for (uint64 j
= 0; j
< 10; j
++) {
597 uint64 num
= kEpoch
- 1 - j
;
598 CheckCalculatePacketSequenceNumber(max_epoch
+ num
, last
);
603 TEST_P(QuicFramerTest
, EmptyPacket
) {
604 char packet
[] = { 0x00 };
605 QuicEncryptedPacket
encrypted(packet
, 0, false);
606 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
607 EXPECT_EQ(QUIC_INVALID_PACKET_HEADER
, framer_
.error());
610 TEST_P(QuicFramerTest
, LargePacket
) {
611 unsigned char packet
[kMaxPacketSize
+ 1] = {
612 // public flags (8 byte connection_id)
623 // packet sequence number
634 memset(packet
+ GetPacketHeaderSize(
635 PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
636 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
), 0,
637 kMaxPacketSize
- GetPacketHeaderSize(
638 PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
639 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
) + 1);
641 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
642 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
644 ASSERT_TRUE(visitor_
.header_
.get());
645 // Make sure we've parsed the packet header, so we can send an error.
646 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
647 visitor_
.header_
->public_header
.connection_id
);
648 // Make sure the correct error is propagated.
649 EXPECT_EQ(QUIC_PACKET_TOO_LARGE
, framer_
.error());
652 TEST_P(QuicFramerTest
, PacketHeader
) {
653 unsigned char packet
[] = {
654 // public flags (8 byte connection_id)
657 0x10, 0x32, 0x54, 0x76,
658 0x98, 0xBA, 0xDC, 0xFE,
659 // packet sequence number
660 0xBC, 0x9A, 0x78, 0x56,
666 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
667 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
668 EXPECT_EQ(QUIC_MISSING_PAYLOAD
, framer_
.error());
669 ASSERT_TRUE(visitor_
.header_
.get());
670 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
671 visitor_
.header_
->public_header
.connection_id
);
672 EXPECT_FALSE(visitor_
.header_
->public_header
.reset_flag
);
673 EXPECT_FALSE(visitor_
.header_
->public_header
.version_flag
);
674 EXPECT_FALSE(visitor_
.header_
->fec_flag
);
675 EXPECT_FALSE(visitor_
.header_
->entropy_flag
);
676 EXPECT_EQ(0, visitor_
.header_
->entropy_hash
);
677 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
678 visitor_
.header_
->packet_sequence_number
);
679 EXPECT_EQ(NOT_IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
680 EXPECT_EQ(0x00u
, visitor_
.header_
->fec_group
);
682 // Now test framing boundaries.
684 i
< GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
685 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
687 string expected_error
;
688 if (i
< kConnectionIdOffset
) {
689 expected_error
= "Unable to read public flags.";
690 } else if (i
< GetSequenceNumberOffset(!kIncludeVersion
)) {
691 expected_error
= "Unable to read ConnectionId.";
692 } else if (i
< GetPrivateFlagsOffset(!kIncludeVersion
)) {
693 expected_error
= "Unable to read sequence number.";
694 } else if (i
< GetFecGroupOffset(!kIncludeVersion
)) {
695 expected_error
= "Unable to read private flags.";
697 expected_error
= "Unable to read first fec protected packet offset.";
699 CheckProcessingFails(packet
, i
, expected_error
, QUIC_INVALID_PACKET_HEADER
);
703 TEST_P(QuicFramerTest
, PacketHeaderWith4ByteConnectionId
) {
704 QuicFramerPeer::SetLastSerializedConnectionId(
705 &framer_
, GG_UINT64_C(0xFEDCBA9876543210));
707 unsigned char packet
[] = {
708 // public flags (4 byte connection_id)
711 0x10, 0x32, 0x54, 0x76,
712 // packet sequence number
713 0xBC, 0x9A, 0x78, 0x56,
719 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
720 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
721 EXPECT_EQ(QUIC_MISSING_PAYLOAD
, framer_
.error());
722 ASSERT_TRUE(visitor_
.header_
.get());
723 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
724 visitor_
.header_
->public_header
.connection_id
);
725 EXPECT_FALSE(visitor_
.header_
->public_header
.reset_flag
);
726 EXPECT_FALSE(visitor_
.header_
->public_header
.version_flag
);
727 EXPECT_FALSE(visitor_
.header_
->fec_flag
);
728 EXPECT_FALSE(visitor_
.header_
->entropy_flag
);
729 EXPECT_EQ(0, visitor_
.header_
->entropy_hash
);
730 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
731 visitor_
.header_
->packet_sequence_number
);
732 EXPECT_EQ(NOT_IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
733 EXPECT_EQ(0x00u
, visitor_
.header_
->fec_group
);
735 // Now test framing boundaries.
737 i
< GetPacketHeaderSize(PACKET_4BYTE_CONNECTION_ID
, !kIncludeVersion
,
738 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
740 string expected_error
;
741 if (i
< kConnectionIdOffset
) {
742 expected_error
= "Unable to read public flags.";
743 } else if (i
< GetSequenceNumberOffset(PACKET_4BYTE_CONNECTION_ID
,
745 expected_error
= "Unable to read ConnectionId.";
746 } else if (i
< GetPrivateFlagsOffset(PACKET_4BYTE_CONNECTION_ID
,
748 expected_error
= "Unable to read sequence number.";
749 } else if (i
< GetFecGroupOffset(PACKET_4BYTE_CONNECTION_ID
,
751 expected_error
= "Unable to read private flags.";
753 expected_error
= "Unable to read first fec protected packet offset.";
755 CheckProcessingFails(packet
, i
, expected_error
, QUIC_INVALID_PACKET_HEADER
);
759 TEST_P(QuicFramerTest
, PacketHeader1ByteConnectionId
) {
760 QuicFramerPeer::SetLastSerializedConnectionId(
761 &framer_
, GG_UINT64_C(0xFEDCBA9876543210));
763 unsigned char packet
[] = {
764 // public flags (1 byte connection_id)
768 // packet sequence number
769 0xBC, 0x9A, 0x78, 0x56,
775 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
776 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
777 EXPECT_EQ(QUIC_MISSING_PAYLOAD
, framer_
.error());
778 ASSERT_TRUE(visitor_
.header_
.get());
779 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
780 visitor_
.header_
->public_header
.connection_id
);
781 EXPECT_FALSE(visitor_
.header_
->public_header
.reset_flag
);
782 EXPECT_FALSE(visitor_
.header_
->public_header
.version_flag
);
783 EXPECT_FALSE(visitor_
.header_
->fec_flag
);
784 EXPECT_FALSE(visitor_
.header_
->entropy_flag
);
785 EXPECT_EQ(0, visitor_
.header_
->entropy_hash
);
786 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
787 visitor_
.header_
->packet_sequence_number
);
788 EXPECT_EQ(NOT_IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
789 EXPECT_EQ(0x00u
, visitor_
.header_
->fec_group
);
791 // Now test framing boundaries.
793 i
< GetPacketHeaderSize(PACKET_1BYTE_CONNECTION_ID
, !kIncludeVersion
,
794 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
796 string expected_error
;
797 if (i
< kConnectionIdOffset
) {
798 expected_error
= "Unable to read public flags.";
799 } else if (i
< GetSequenceNumberOffset(PACKET_1BYTE_CONNECTION_ID
,
801 expected_error
= "Unable to read ConnectionId.";
802 } else if (i
< GetPrivateFlagsOffset(PACKET_1BYTE_CONNECTION_ID
,
804 expected_error
= "Unable to read sequence number.";
805 } else if (i
< GetFecGroupOffset(PACKET_1BYTE_CONNECTION_ID
,
807 expected_error
= "Unable to read private flags.";
809 expected_error
= "Unable to read first fec protected packet offset.";
811 CheckProcessingFails(packet
, i
, expected_error
, QUIC_INVALID_PACKET_HEADER
);
815 TEST_P(QuicFramerTest
, PacketHeaderWith0ByteConnectionId
) {
816 QuicFramerPeer::SetLastSerializedConnectionId(
817 &framer_
, GG_UINT64_C(0xFEDCBA9876543210));
819 unsigned char packet
[] = {
820 // public flags (0 byte connection_id)
823 // packet sequence number
824 0xBC, 0x9A, 0x78, 0x56,
830 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
831 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
832 EXPECT_EQ(QUIC_MISSING_PAYLOAD
, framer_
.error());
833 ASSERT_TRUE(visitor_
.header_
.get());
834 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
835 visitor_
.header_
->public_header
.connection_id
);
836 EXPECT_FALSE(visitor_
.header_
->public_header
.reset_flag
);
837 EXPECT_FALSE(visitor_
.header_
->public_header
.version_flag
);
838 EXPECT_FALSE(visitor_
.header_
->fec_flag
);
839 EXPECT_FALSE(visitor_
.header_
->entropy_flag
);
840 EXPECT_EQ(0, visitor_
.header_
->entropy_hash
);
841 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
842 visitor_
.header_
->packet_sequence_number
);
843 EXPECT_EQ(NOT_IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
844 EXPECT_EQ(0x00u
, visitor_
.header_
->fec_group
);
846 // Now test framing boundaries.
848 i
< GetPacketHeaderSize(PACKET_0BYTE_CONNECTION_ID
, !kIncludeVersion
,
849 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
851 string expected_error
;
852 if (i
< kConnectionIdOffset
) {
853 expected_error
= "Unable to read public flags.";
854 } else if (i
< GetSequenceNumberOffset(PACKET_0BYTE_CONNECTION_ID
,
856 expected_error
= "Unable to read ConnectionId.";
857 } else if (i
< GetPrivateFlagsOffset(PACKET_0BYTE_CONNECTION_ID
,
859 expected_error
= "Unable to read sequence number.";
860 } else if (i
< GetFecGroupOffset(PACKET_0BYTE_CONNECTION_ID
,
862 expected_error
= "Unable to read private flags.";
864 expected_error
= "Unable to read first fec protected packet offset.";
866 CheckProcessingFails(packet
, i
, expected_error
, QUIC_INVALID_PACKET_HEADER
);
870 TEST_P(QuicFramerTest
, PacketHeaderWithVersionFlag
) {
871 unsigned char packet
[] = {
872 // public flags (version)
875 0x10, 0x32, 0x54, 0x76,
876 0x98, 0xBA, 0xDC, 0xFE,
878 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
879 // packet sequence number
880 0xBC, 0x9A, 0x78, 0x56,
886 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
887 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
888 EXPECT_EQ(QUIC_MISSING_PAYLOAD
, framer_
.error());
889 ASSERT_TRUE(visitor_
.header_
.get());
890 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
891 visitor_
.header_
->public_header
.connection_id
);
892 EXPECT_FALSE(visitor_
.header_
->public_header
.reset_flag
);
893 EXPECT_TRUE(visitor_
.header_
->public_header
.version_flag
);
894 EXPECT_EQ(GetParam(), visitor_
.header_
->public_header
.versions
[0]);
895 EXPECT_FALSE(visitor_
.header_
->fec_flag
);
896 EXPECT_FALSE(visitor_
.header_
->entropy_flag
);
897 EXPECT_EQ(0, visitor_
.header_
->entropy_hash
);
898 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
899 visitor_
.header_
->packet_sequence_number
);
900 EXPECT_EQ(NOT_IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
901 EXPECT_EQ(0x00u
, visitor_
.header_
->fec_group
);
903 // Now test framing boundaries.
905 i
< GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, kIncludeVersion
,
906 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
908 string expected_error
;
909 if (i
< kConnectionIdOffset
) {
910 expected_error
= "Unable to read public flags.";
911 } else if (i
< kVersionOffset
) {
912 expected_error
= "Unable to read ConnectionId.";
913 } else if (i
< GetSequenceNumberOffset(kIncludeVersion
)) {
914 expected_error
= "Unable to read protocol version.";
915 } else if (i
< GetPrivateFlagsOffset(kIncludeVersion
)) {
916 expected_error
= "Unable to read sequence number.";
917 } else if (i
< GetFecGroupOffset(kIncludeVersion
)) {
918 expected_error
= "Unable to read private flags.";
920 expected_error
= "Unable to read first fec protected packet offset.";
922 CheckProcessingFails(packet
, i
, expected_error
, QUIC_INVALID_PACKET_HEADER
);
926 TEST_P(QuicFramerTest
, PacketHeaderWith4ByteSequenceNumber
) {
927 QuicFramerPeer::SetLastSequenceNumber(&framer_
,
928 GG_UINT64_C(0x123456789ABA));
930 unsigned char packet
[] = {
931 // public flags (8 byte connection_id and 4 byte sequence number)
934 0x10, 0x32, 0x54, 0x76,
935 0x98, 0xBA, 0xDC, 0xFE,
936 // packet sequence number
937 0xBC, 0x9A, 0x78, 0x56,
942 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
943 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
944 EXPECT_EQ(QUIC_MISSING_PAYLOAD
, framer_
.error());
945 ASSERT_TRUE(visitor_
.header_
.get());
946 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
947 visitor_
.header_
->public_header
.connection_id
);
948 EXPECT_FALSE(visitor_
.header_
->public_header
.reset_flag
);
949 EXPECT_FALSE(visitor_
.header_
->public_header
.version_flag
);
950 EXPECT_FALSE(visitor_
.header_
->fec_flag
);
951 EXPECT_FALSE(visitor_
.header_
->entropy_flag
);
952 EXPECT_EQ(0, visitor_
.header_
->entropy_hash
);
953 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
954 visitor_
.header_
->packet_sequence_number
);
955 EXPECT_EQ(NOT_IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
956 EXPECT_EQ(0x00u
, visitor_
.header_
->fec_group
);
958 // Now test framing boundaries.
960 i
< GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
961 PACKET_4BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
963 string expected_error
;
964 if (i
< kConnectionIdOffset
) {
965 expected_error
= "Unable to read public flags.";
966 } else if (i
< GetSequenceNumberOffset(!kIncludeVersion
)) {
967 expected_error
= "Unable to read ConnectionId.";
968 } else if (i
< GetPrivateFlagsOffset(!kIncludeVersion
,
969 PACKET_4BYTE_SEQUENCE_NUMBER
)) {
970 expected_error
= "Unable to read sequence number.";
971 } else if (i
< GetFecGroupOffset(!kIncludeVersion
,
972 PACKET_4BYTE_SEQUENCE_NUMBER
)) {
973 expected_error
= "Unable to read private flags.";
975 expected_error
= "Unable to read first fec protected packet offset.";
977 CheckProcessingFails(packet
, i
, expected_error
, QUIC_INVALID_PACKET_HEADER
);
981 TEST_P(QuicFramerTest
, PacketHeaderWith2ByteSequenceNumber
) {
982 QuicFramerPeer::SetLastSequenceNumber(&framer_
,
983 GG_UINT64_C(0x123456789ABA));
985 unsigned char packet
[] = {
986 // public flags (8 byte connection_id and 2 byte sequence number)
989 0x10, 0x32, 0x54, 0x76,
990 0x98, 0xBA, 0xDC, 0xFE,
991 // packet sequence number
997 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
998 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
999 EXPECT_EQ(QUIC_MISSING_PAYLOAD
, framer_
.error());
1000 ASSERT_TRUE(visitor_
.header_
.get());
1001 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
1002 visitor_
.header_
->public_header
.connection_id
);
1003 EXPECT_FALSE(visitor_
.header_
->public_header
.reset_flag
);
1004 EXPECT_FALSE(visitor_
.header_
->public_header
.version_flag
);
1005 EXPECT_FALSE(visitor_
.header_
->fec_flag
);
1006 EXPECT_FALSE(visitor_
.header_
->entropy_flag
);
1007 EXPECT_EQ(0, visitor_
.header_
->entropy_hash
);
1008 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
1009 visitor_
.header_
->packet_sequence_number
);
1010 EXPECT_EQ(NOT_IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
1011 EXPECT_EQ(0x00u
, visitor_
.header_
->fec_group
);
1013 // Now test framing boundaries.
1015 i
< GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
1016 PACKET_2BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
1018 string expected_error
;
1019 if (i
< kConnectionIdOffset
) {
1020 expected_error
= "Unable to read public flags.";
1021 } else if (i
< GetSequenceNumberOffset(!kIncludeVersion
)) {
1022 expected_error
= "Unable to read ConnectionId.";
1023 } else if (i
< GetPrivateFlagsOffset(!kIncludeVersion
,
1024 PACKET_2BYTE_SEQUENCE_NUMBER
)) {
1025 expected_error
= "Unable to read sequence number.";
1026 } else if (i
< GetFecGroupOffset(!kIncludeVersion
,
1027 PACKET_2BYTE_SEQUENCE_NUMBER
)) {
1028 expected_error
= "Unable to read private flags.";
1030 expected_error
= "Unable to read first fec protected packet offset.";
1032 CheckProcessingFails(packet
, i
, expected_error
, QUIC_INVALID_PACKET_HEADER
);
1036 TEST_P(QuicFramerTest
, PacketHeaderWith1ByteSequenceNumber
) {
1037 QuicFramerPeer::SetLastSequenceNumber(&framer_
,
1038 GG_UINT64_C(0x123456789ABA));
1040 unsigned char packet
[] = {
1041 // public flags (8 byte connection_id and 1 byte sequence number)
1044 0x10, 0x32, 0x54, 0x76,
1045 0x98, 0xBA, 0xDC, 0xFE,
1046 // packet sequence number
1052 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1053 EXPECT_FALSE(framer_
.ProcessPacket(encrypted
));
1054 EXPECT_EQ(QUIC_MISSING_PAYLOAD
, framer_
.error());
1055 ASSERT_TRUE(visitor_
.header_
.get());
1056 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
1057 visitor_
.header_
->public_header
.connection_id
);
1058 EXPECT_FALSE(visitor_
.header_
->public_header
.reset_flag
);
1059 EXPECT_FALSE(visitor_
.header_
->public_header
.version_flag
);
1060 EXPECT_FALSE(visitor_
.header_
->fec_flag
);
1061 EXPECT_FALSE(visitor_
.header_
->entropy_flag
);
1062 EXPECT_EQ(0, visitor_
.header_
->entropy_hash
);
1063 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
1064 visitor_
.header_
->packet_sequence_number
);
1065 EXPECT_EQ(NOT_IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
1066 EXPECT_EQ(0x00u
, visitor_
.header_
->fec_group
);
1068 // Now test framing boundaries.
1070 i
< GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
1071 PACKET_1BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
1073 string expected_error
;
1074 if (i
< kConnectionIdOffset
) {
1075 expected_error
= "Unable to read public flags.";
1076 } else if (i
< GetSequenceNumberOffset(!kIncludeVersion
)) {
1077 expected_error
= "Unable to read ConnectionId.";
1078 } else if (i
< GetPrivateFlagsOffset(!kIncludeVersion
,
1079 PACKET_1BYTE_SEQUENCE_NUMBER
)) {
1080 expected_error
= "Unable to read sequence number.";
1081 } else if (i
< GetFecGroupOffset(!kIncludeVersion
,
1082 PACKET_1BYTE_SEQUENCE_NUMBER
)) {
1083 expected_error
= "Unable to read private flags.";
1085 expected_error
= "Unable to read first fec protected packet offset.";
1087 CheckProcessingFails(packet
, i
, expected_error
, QUIC_INVALID_PACKET_HEADER
);
1091 TEST_P(QuicFramerTest
, InvalidPublicFlag
) {
1092 unsigned char packet
[] = {
1093 // public flags: all flags set but the public reset flag and version flag.
1096 0x10, 0x32, 0x54, 0x76,
1097 0x98, 0xBA, 0xDC, 0xFE,
1098 // packet sequence number
1099 0xBC, 0x9A, 0x78, 0x56,
1104 // frame type (padding)
1106 0x00, 0x00, 0x00, 0x00
1108 CheckProcessingFails(packet
,
1110 "Illegal public flags value.",
1111 QUIC_INVALID_PACKET_HEADER
);
1113 // Now turn off validation.
1114 framer_
.set_validate_flags(false);
1115 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1116 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1119 TEST_P(QuicFramerTest
, InvalidPublicFlagWithMatchingVersions
) {
1120 unsigned char packet
[] = {
1121 // public flags (8 byte connection_id and version flag and an unknown flag)
1124 0x10, 0x32, 0x54, 0x76,
1125 0x98, 0xBA, 0xDC, 0xFE,
1127 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
1128 // packet sequence number
1129 0xBC, 0x9A, 0x78, 0x56,
1134 // frame type (padding)
1136 0x00, 0x00, 0x00, 0x00
1138 CheckProcessingFails(packet
,
1140 "Illegal public flags value.",
1141 QUIC_INVALID_PACKET_HEADER
);
1144 TEST_P(QuicFramerTest
, LargePublicFlagWithMismatchedVersions
) {
1145 unsigned char packet
[] = {
1146 // public flags (8 byte connection_id, version flag and an unknown flag)
1149 0x10, 0x32, 0x54, 0x76,
1150 0x98, 0xBA, 0xDC, 0xFE,
1153 // packet sequence number
1154 0xBC, 0x9A, 0x78, 0x56,
1159 // frame type (padding frame)
1161 0x00, 0x00, 0x00, 0x00
1163 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1164 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1165 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1166 ASSERT_TRUE(visitor_
.header_
.get());
1167 EXPECT_EQ(0, visitor_
.frame_count_
);
1168 EXPECT_EQ(1, visitor_
.version_mismatch_
);
1171 TEST_P(QuicFramerTest
, InvalidPrivateFlag
) {
1172 unsigned char packet
[] = {
1173 // public flags (8 byte connection_id)
1176 0x10, 0x32, 0x54, 0x76,
1177 0x98, 0xBA, 0xDC, 0xFE,
1178 // packet sequence number
1179 0xBC, 0x9A, 0x78, 0x56,
1184 // frame type (padding)
1186 0x00, 0x00, 0x00, 0x00
1188 CheckProcessingFails(packet
,
1190 "Illegal private flags value.",
1191 QUIC_INVALID_PACKET_HEADER
);
1194 TEST_P(QuicFramerTest
, InvalidFECGroupOffset
) {
1195 unsigned char packet
[] = {
1196 // public flags (8 byte connection_id)
1199 0x10, 0x32, 0x54, 0x76,
1200 0x98, 0xBA, 0xDC, 0xFE,
1201 // packet sequence number
1202 0x01, 0x00, 0x00, 0x00,
1204 // private flags (fec group)
1206 // first fec protected packet offset
1209 CheckProcessingFails(packet
,
1211 "First fec protected packet offset must be less "
1212 "than the sequence number.",
1213 QUIC_INVALID_PACKET_HEADER
);
1216 TEST_P(QuicFramerTest
, PaddingFrame
) {
1217 unsigned char packet
[] = {
1218 // public flags (8 byte connection_id)
1221 0x10, 0x32, 0x54, 0x76,
1222 0x98, 0xBA, 0xDC, 0xFE,
1223 // packet sequence number
1224 0xBC, 0x9A, 0x78, 0x56,
1229 // frame type (padding frame)
1231 // Ignored data (which in this case is a stream frame)
1232 // frame type (stream frame with fin)
1235 0x04, 0x03, 0x02, 0x01,
1237 0x54, 0x76, 0x10, 0x32,
1238 0xDC, 0xFE, 0x98, 0xBA,
1247 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1248 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1249 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1250 ASSERT_TRUE(visitor_
.header_
.get());
1251 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1253 ASSERT_EQ(0u, visitor_
.stream_frames_
.size());
1254 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
1255 // A packet with no frames is not acceptable.
1256 CheckProcessingFails(
1258 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
1259 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
1260 "Packet has no frames.", QUIC_MISSING_PAYLOAD
);
1263 TEST_P(QuicFramerTest
, StreamFrame
) {
1264 unsigned char packet
[] = {
1265 // public flags (8 byte connection_id)
1268 0x10, 0x32, 0x54, 0x76,
1269 0x98, 0xBA, 0xDC, 0xFE,
1270 // packet sequence number
1271 0xBC, 0x9A, 0x78, 0x56,
1276 // frame type (stream frame with fin)
1279 0x04, 0x03, 0x02, 0x01,
1281 0x54, 0x76, 0x10, 0x32,
1282 0xDC, 0xFE, 0x98, 0xBA,
1291 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1292 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1294 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1295 ASSERT_TRUE(visitor_
.header_
.get());
1296 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1298 ASSERT_EQ(1u, visitor_
.stream_frames_
.size());
1299 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
1300 EXPECT_EQ(static_cast<uint64
>(0x01020304),
1301 visitor_
.stream_frames_
[0]->stream_id
);
1302 EXPECT_TRUE(visitor_
.stream_frames_
[0]->fin
);
1303 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1304 visitor_
.stream_frames_
[0]->offset
);
1305 CheckStreamFrameData("hello world!", visitor_
.stream_frames_
[0]);
1307 // Now test framing boundaries.
1308 CheckStreamFrameBoundaries(packet
, kQuicMaxStreamIdSize
, !kIncludeVersion
);
1311 TEST_P(QuicFramerTest
, StreamFrame3ByteStreamId
) {
1312 unsigned char packet
[] = {
1313 // public flags (8 byte connection_id)
1316 0x10, 0x32, 0x54, 0x76,
1317 0x98, 0xBA, 0xDC, 0xFE,
1318 // packet sequence number
1319 0xBC, 0x9A, 0x78, 0x56,
1324 // frame type (stream frame with fin)
1329 0x54, 0x76, 0x10, 0x32,
1330 0xDC, 0xFE, 0x98, 0xBA,
1339 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1340 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1342 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1343 ASSERT_TRUE(visitor_
.header_
.get());
1344 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1346 ASSERT_EQ(1u, visitor_
.stream_frames_
.size());
1347 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
1348 EXPECT_EQ(GG_UINT64_C(0x00020304), visitor_
.stream_frames_
[0]->stream_id
);
1349 EXPECT_TRUE(visitor_
.stream_frames_
[0]->fin
);
1350 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1351 visitor_
.stream_frames_
[0]->offset
);
1352 CheckStreamFrameData("hello world!", visitor_
.stream_frames_
[0]);
1354 // Now test framing boundaries.
1355 const size_t stream_id_size
= 3;
1356 CheckStreamFrameBoundaries(packet
, stream_id_size
, !kIncludeVersion
);
1359 TEST_P(QuicFramerTest
, StreamFrame2ByteStreamId
) {
1360 unsigned char packet
[] = {
1361 // public flags (8 byte connection_id)
1364 0x10, 0x32, 0x54, 0x76,
1365 0x98, 0xBA, 0xDC, 0xFE,
1366 // packet sequence number
1367 0xBC, 0x9A, 0x78, 0x56,
1372 // frame type (stream frame with fin)
1377 0x54, 0x76, 0x10, 0x32,
1378 0xDC, 0xFE, 0x98, 0xBA,
1387 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1388 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1390 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1391 ASSERT_TRUE(visitor_
.header_
.get());
1392 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1394 ASSERT_EQ(1u, visitor_
.stream_frames_
.size());
1395 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
1396 EXPECT_EQ(static_cast<uint64
>(0x00000304),
1397 visitor_
.stream_frames_
[0]->stream_id
);
1398 EXPECT_TRUE(visitor_
.stream_frames_
[0]->fin
);
1399 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1400 visitor_
.stream_frames_
[0]->offset
);
1401 CheckStreamFrameData("hello world!", visitor_
.stream_frames_
[0]);
1403 // Now test framing boundaries.
1404 const size_t stream_id_size
= 2;
1405 CheckStreamFrameBoundaries(packet
, stream_id_size
, !kIncludeVersion
);
1408 TEST_P(QuicFramerTest
, StreamFrame1ByteStreamId
) {
1409 unsigned char packet
[] = {
1410 // public flags (8 byte connection_id)
1413 0x10, 0x32, 0x54, 0x76,
1414 0x98, 0xBA, 0xDC, 0xFE,
1415 // packet sequence number
1416 0xBC, 0x9A, 0x78, 0x56,
1421 // frame type (stream frame with fin)
1426 0x54, 0x76, 0x10, 0x32,
1427 0xDC, 0xFE, 0x98, 0xBA,
1436 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1437 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1439 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1440 ASSERT_TRUE(visitor_
.header_
.get());
1441 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1443 ASSERT_EQ(1u, visitor_
.stream_frames_
.size());
1444 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
1445 EXPECT_EQ(static_cast<uint64
>(0x00000004),
1446 visitor_
.stream_frames_
[0]->stream_id
);
1447 EXPECT_TRUE(visitor_
.stream_frames_
[0]->fin
);
1448 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1449 visitor_
.stream_frames_
[0]->offset
);
1450 CheckStreamFrameData("hello world!", visitor_
.stream_frames_
[0]);
1452 // Now test framing boundaries.
1453 const size_t stream_id_size
= 1;
1454 CheckStreamFrameBoundaries(packet
, stream_id_size
, !kIncludeVersion
);
1457 TEST_P(QuicFramerTest
, StreamFrameWithVersion
) {
1458 unsigned char packet
[] = {
1459 // public flags (version, 8 byte connection_id)
1462 0x10, 0x32, 0x54, 0x76,
1463 0x98, 0xBA, 0xDC, 0xFE,
1465 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
1466 // packet sequence number
1467 0xBC, 0x9A, 0x78, 0x56,
1472 // frame type (stream frame with fin)
1475 0x04, 0x03, 0x02, 0x01,
1477 0x54, 0x76, 0x10, 0x32,
1478 0xDC, 0xFE, 0x98, 0xBA,
1487 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1488 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1490 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1491 ASSERT_TRUE(visitor_
.header_
.get());
1492 EXPECT_TRUE(visitor_
.header_
->public_header
.version_flag
);
1493 EXPECT_EQ(GetParam(), visitor_
.header_
->public_header
.versions
[0]);
1494 EXPECT_TRUE(CheckDecryption(encrypted
, kIncludeVersion
));
1496 ASSERT_EQ(1u, visitor_
.stream_frames_
.size());
1497 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
1498 EXPECT_EQ(static_cast<uint64
>(0x01020304),
1499 visitor_
.stream_frames_
[0]->stream_id
);
1500 EXPECT_TRUE(visitor_
.stream_frames_
[0]->fin
);
1501 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1502 visitor_
.stream_frames_
[0]->offset
);
1503 CheckStreamFrameData("hello world!", visitor_
.stream_frames_
[0]);
1505 // Now test framing boundaries.
1506 CheckStreamFrameBoundaries(packet
, kQuicMaxStreamIdSize
, kIncludeVersion
);
1509 TEST_P(QuicFramerTest
, RejectPacket
) {
1510 visitor_
.accept_packet_
= false;
1512 unsigned char packet
[] = {
1513 // public flags (8 byte connection_id)
1516 0x10, 0x32, 0x54, 0x76,
1517 0x98, 0xBA, 0xDC, 0xFE,
1518 // packet sequence number
1519 0xBC, 0x9A, 0x78, 0x56,
1524 // frame type (stream frame with fin)
1527 0x04, 0x03, 0x02, 0x01,
1529 0x54, 0x76, 0x10, 0x32,
1530 0xDC, 0xFE, 0x98, 0xBA,
1539 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1540 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1542 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1543 ASSERT_TRUE(visitor_
.header_
.get());
1544 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1546 ASSERT_EQ(0u, visitor_
.stream_frames_
.size());
1547 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
1550 TEST_P(QuicFramerTest
, RejectPublicHeader
) {
1551 visitor_
.accept_public_header_
= false;
1553 unsigned char packet
[] = {
1554 // public flags (8 byte connection_id)
1557 0x10, 0x32, 0x54, 0x76,
1558 0x98, 0xBA, 0xDC, 0xFE,
1561 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1562 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1564 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1565 ASSERT_TRUE(visitor_
.public_header_
.get());
1566 ASSERT_FALSE(visitor_
.header_
.get());
1569 TEST_P(QuicFramerTest
, RevivedStreamFrame
) {
1570 unsigned char payload
[] = {
1571 // frame type (stream frame with fin)
1574 0x04, 0x03, 0x02, 0x01,
1576 0x54, 0x76, 0x10, 0x32,
1577 0xDC, 0xFE, 0x98, 0xBA,
1586 QuicPacketHeader header
;
1587 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
1588 header
.public_header
.reset_flag
= false;
1589 header
.public_header
.version_flag
= false;
1590 header
.fec_flag
= true;
1591 header
.entropy_flag
= true;
1592 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
1593 header
.fec_group
= 0;
1595 // Do not encrypt the payload because the revived payload is post-encryption.
1596 EXPECT_TRUE(framer_
.ProcessRevivedPacket(&header
,
1597 StringPiece(AsChars(payload
),
1598 arraysize(payload
))));
1600 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1601 ASSERT_EQ(1, visitor_
.revived_packets_
);
1602 ASSERT_TRUE(visitor_
.header_
.get());
1603 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
1604 visitor_
.header_
->public_header
.connection_id
);
1605 EXPECT_FALSE(visitor_
.header_
->public_header
.reset_flag
);
1606 EXPECT_FALSE(visitor_
.header_
->public_header
.version_flag
);
1607 EXPECT_TRUE(visitor_
.header_
->fec_flag
);
1608 EXPECT_TRUE(visitor_
.header_
->entropy_flag
);
1609 EXPECT_EQ(1 << (header
.packet_sequence_number
% 8),
1610 visitor_
.header_
->entropy_hash
);
1611 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
1612 visitor_
.header_
->packet_sequence_number
);
1613 EXPECT_EQ(NOT_IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
1614 EXPECT_EQ(0x00u
, visitor_
.header_
->fec_group
);
1616 ASSERT_EQ(1u, visitor_
.stream_frames_
.size());
1617 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
1618 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_
.stream_frames_
[0]->stream_id
);
1619 EXPECT_TRUE(visitor_
.stream_frames_
[0]->fin
);
1620 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1621 visitor_
.stream_frames_
[0]->offset
);
1622 CheckStreamFrameData("hello world!", visitor_
.stream_frames_
[0]);
1625 TEST_P(QuicFramerTest
, StreamFrameInFecGroup
) {
1626 unsigned char packet
[] = {
1627 // public flags (8 byte connection_id)
1630 0x10, 0x32, 0x54, 0x76,
1631 0x98, 0xBA, 0xDC, 0xFE,
1632 // packet sequence number
1633 0xBC, 0x9A, 0x78, 0x56,
1635 // private flags (fec group)
1637 // first fec protected packet offset
1640 // frame type (stream frame with fin)
1643 0x04, 0x03, 0x02, 0x01,
1645 0x54, 0x76, 0x10, 0x32,
1646 0xDC, 0xFE, 0x98, 0xBA,
1655 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1656 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1658 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1659 ASSERT_TRUE(visitor_
.header_
.get());
1660 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1661 EXPECT_EQ(IN_FEC_GROUP
, visitor_
.header_
->is_in_fec_group
);
1662 EXPECT_EQ(GG_UINT64_C(0x341256789ABA),
1663 visitor_
.header_
->fec_group
);
1664 const size_t fec_offset
=
1665 GetStartOfFecProtectedData(PACKET_8BYTE_CONNECTION_ID
,
1667 PACKET_6BYTE_SEQUENCE_NUMBER
);
1669 string(AsChars(packet
) + fec_offset
, arraysize(packet
) - fec_offset
),
1670 visitor_
.fec_protected_payload_
);
1672 ASSERT_EQ(1u, visitor_
.stream_frames_
.size());
1673 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
1674 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_
.stream_frames_
[0]->stream_id
);
1675 EXPECT_TRUE(visitor_
.stream_frames_
[0]->fin
);
1676 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1677 visitor_
.stream_frames_
[0]->offset
);
1678 CheckStreamFrameData("hello world!", visitor_
.stream_frames_
[0]);
1681 TEST_P(QuicFramerTest
, AckFrameTwoTimestamp
) {
1682 unsigned char packet
[] = {
1683 // public flags (8 byte connection_id)
1686 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
1687 // packet sequence number
1688 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
1689 // private flags (entropy)
1692 // frame type (ack frame)
1693 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
1695 // entropy hash of all received packets.
1697 // largest observed packet sequence number
1698 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12,
1701 // Number of timestamps.
1703 // Delta from largest observed.
1706 0x10, 0x32, 0x54, 0x76,
1707 // Delta from largest observed.
1711 // num missing packets
1713 // missing packet delta
1715 // 0 more missing packets in range.
1717 // Number of revived packets.
1721 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1722 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1724 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1725 ASSERT_TRUE(visitor_
.header_
.get());
1726 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1728 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
1729 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
1730 const QuicAckFrame
& frame
= *visitor_
.ack_frames_
[0];
1731 EXPECT_EQ(0xBA, frame
.entropy_hash
);
1732 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame
.largest_observed
);
1733 ASSERT_EQ(1u, frame
.missing_packets
.size());
1734 ASSERT_EQ(2u, frame
.received_packet_times
.size());
1735 SequenceNumberSet::const_iterator missing_iter
=
1736 frame
.missing_packets
.begin();
1737 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter
);
1739 const size_t kReceivedEntropyOffset
= kQuicFrameTypeSize
;
1740 const size_t kLargestObservedOffset
= kReceivedEntropyOffset
+
1741 kQuicEntropyHashSize
;
1742 const size_t kMissingDeltaTimeOffset
= kLargestObservedOffset
+
1743 PACKET_6BYTE_SEQUENCE_NUMBER
;
1744 const size_t kNumTimestampsOffset
= kMissingDeltaTimeOffset
+
1745 kQuicDeltaTimeLargestObservedSize
;
1746 const size_t kTimestampDeltaLargestObserved1
= kNumTimestampsOffset
+
1747 kQuicNumTimestampsSize
;
1748 const size_t kTimestampTimeDeltaLargestObserved1
=
1749 kTimestampDeltaLargestObserved1
+ 1;
1750 const size_t kTimestampDeltaLargestObserved2
=
1751 kTimestampTimeDeltaLargestObserved1
+ 4;
1752 const size_t kTimestampTimeDeltaLargestObserved2
=
1753 kTimestampDeltaLargestObserved2
+ 1;
1754 const size_t kNumMissingPacketOffset
=
1755 kTimestampTimeDeltaLargestObserved2
+ 2;
1756 const size_t kMissingPacketsOffset
= kNumMissingPacketOffset
+
1757 kNumberOfNackRangesSize
;
1758 const size_t kMissingPacketsRange
= kMissingPacketsOffset
+
1759 PACKET_1BYTE_SEQUENCE_NUMBER
;
1760 const size_t kRevivedPacketsLength
= kMissingPacketsRange
+
1761 PACKET_1BYTE_SEQUENCE_NUMBER
;
1762 // Now test framing boundaries.
1763 const size_t ack_frame_size
= kRevivedPacketsLength
+
1764 PACKET_1BYTE_SEQUENCE_NUMBER
;
1765 for (size_t i
= kQuicFrameTypeSize
; i
< ack_frame_size
; ++i
) {
1766 string expected_error
;
1767 if (i
< kLargestObservedOffset
) {
1768 expected_error
= "Unable to read entropy hash for received packets.";
1769 } else if (i
< kMissingDeltaTimeOffset
) {
1770 expected_error
= "Unable to read largest observed.";
1771 } else if (i
< kNumTimestampsOffset
) {
1772 expected_error
= "Unable to read delta time largest observed.";
1773 } else if (i
< kTimestampDeltaLargestObserved1
) {
1774 expected_error
= "Unable to read num received packets.";
1775 } else if (i
< kTimestampTimeDeltaLargestObserved1
) {
1776 expected_error
= "Unable to read sequence delta in received packets.";
1777 } else if (i
< kTimestampDeltaLargestObserved2
) {
1778 expected_error
= "Unable to read time delta in received packets.";
1779 } else if (i
< kTimestampTimeDeltaLargestObserved2
) {
1780 expected_error
= "Unable to read sequence delta in received packets.";
1781 } else if (i
< kNumMissingPacketOffset
) {
1783 "Unable to read incremental time delta in received packets.";
1784 } else if (i
< kMissingPacketsOffset
) {
1785 expected_error
= "Unable to read num missing packet ranges.";
1786 } else if (i
< kMissingPacketsRange
) {
1787 expected_error
= "Unable to read missing sequence number delta.";
1788 } else if (i
< kRevivedPacketsLength
) {
1789 expected_error
= "Unable to read missing sequence number range.";
1791 expected_error
= "Unable to read num revived packets.";
1793 CheckProcessingFails(
1795 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
1796 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
1797 expected_error
, QUIC_INVALID_ACK_DATA
);
1802 TEST_P(QuicFramerTest
, AckFrameOneTimestamp
) {
1803 unsigned char packet
[] = {
1804 // public flags (8 byte connection_id)
1807 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
1808 // packet sequence number
1809 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
1810 // private flags (entropy)
1813 // frame type (ack frame)
1814 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
1816 // entropy hash of all received packets.
1818 // largest observed packet sequence number
1819 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12,
1822 // Number of timestamps.
1824 // Delta from largest observed.
1827 0x10, 0x32, 0x54, 0x76,
1828 // num missing packets
1830 // missing packet delta
1832 // 0 more missing packets in range.
1834 // Number of revived packets.
1838 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1839 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1841 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1842 ASSERT_TRUE(visitor_
.header_
.get());
1843 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1845 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
1846 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
1847 const QuicAckFrame
& frame
= *visitor_
.ack_frames_
[0];
1848 EXPECT_EQ(0xBA, frame
.entropy_hash
);
1849 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame
.largest_observed
);
1850 ASSERT_EQ(1u, frame
.missing_packets
.size());
1851 ASSERT_EQ(1u, frame
.received_packet_times
.size());
1852 SequenceNumberSet::const_iterator missing_iter
=
1853 frame
.missing_packets
.begin();
1854 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter
);
1856 const size_t kReceivedEntropyOffset
= kQuicFrameTypeSize
;
1857 const size_t kLargestObservedOffset
= kReceivedEntropyOffset
+
1858 kQuicEntropyHashSize
;
1859 const size_t kMissingDeltaTimeOffset
= kLargestObservedOffset
+
1860 PACKET_6BYTE_SEQUENCE_NUMBER
;
1861 const size_t kNumTimestampsOffset
= kMissingDeltaTimeOffset
+
1862 kQuicDeltaTimeLargestObservedSize
;
1863 const size_t kTimestampDeltaLargestObserved
= kNumTimestampsOffset
+
1864 kQuicNumTimestampsSize
;
1865 const size_t kTimestampTimeDeltaLargestObserved
=
1866 kTimestampDeltaLargestObserved
+ 1;
1867 const size_t kNumMissingPacketOffset
= kTimestampTimeDeltaLargestObserved
+ 4;
1868 const size_t kMissingPacketsOffset
= kNumMissingPacketOffset
+
1869 kNumberOfNackRangesSize
;
1870 const size_t kMissingPacketsRange
= kMissingPacketsOffset
+
1871 PACKET_1BYTE_SEQUENCE_NUMBER
;
1872 const size_t kRevivedPacketsLength
= kMissingPacketsRange
+
1873 PACKET_1BYTE_SEQUENCE_NUMBER
;
1874 // Now test framing boundaries.
1875 const size_t ack_frame_size
= kRevivedPacketsLength
+
1876 PACKET_1BYTE_SEQUENCE_NUMBER
;
1877 for (size_t i
= kQuicFrameTypeSize
; i
< ack_frame_size
; ++i
) {
1878 string expected_error
;
1879 if (i
< kLargestObservedOffset
) {
1880 expected_error
= "Unable to read entropy hash for received packets.";
1881 } else if (i
< kMissingDeltaTimeOffset
) {
1882 expected_error
= "Unable to read largest observed.";
1883 } else if (i
< kNumTimestampsOffset
) {
1884 expected_error
= "Unable to read delta time largest observed.";
1885 } else if (i
< kTimestampDeltaLargestObserved
) {
1886 expected_error
= "Unable to read num received packets.";
1887 } else if (i
< kTimestampTimeDeltaLargestObserved
) {
1888 expected_error
= "Unable to read sequence delta in received packets.";
1889 } else if (i
< kNumMissingPacketOffset
) {
1890 expected_error
= "Unable to read time delta in received packets.";
1891 } else if (i
< kMissingPacketsOffset
) {
1892 expected_error
= "Unable to read num missing packet ranges.";
1893 } else if (i
< kMissingPacketsRange
) {
1894 expected_error
= "Unable to read missing sequence number delta.";
1895 } else if (i
< kRevivedPacketsLength
) {
1896 expected_error
= "Unable to read missing sequence number range.";
1898 expected_error
= "Unable to read num revived packets.";
1900 CheckProcessingFails(
1902 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
1903 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
1904 expected_error
, QUIC_INVALID_ACK_DATA
);
1909 TEST_P(QuicFramerTest
, AckFrame
) {
1910 unsigned char packet
[] = {
1911 // public flags (8 byte connection_id)
1914 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
1915 // packet sequence number
1916 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
1917 // private flags (entropy)
1920 // frame type (ack frame)
1921 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
1923 // entropy hash of all received packets.
1925 // largest observed packet sequence number
1926 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12,
1929 // Number of timestamps.
1931 // num missing packets
1933 // missing packet delta
1935 // 0 more missing packets in range.
1937 // Number of revived packets.
1941 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
1942 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
1944 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
1945 ASSERT_TRUE(visitor_
.header_
.get());
1946 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
1948 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
1949 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
1950 const QuicAckFrame
& frame
= *visitor_
.ack_frames_
[0];
1951 EXPECT_EQ(0xBA, frame
.entropy_hash
);
1952 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame
.largest_observed
);
1953 ASSERT_EQ(1u, frame
.missing_packets
.size());
1954 SequenceNumberSet::const_iterator missing_iter
=
1955 frame
.missing_packets
.begin();
1956 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter
);
1958 const size_t kReceivedEntropyOffset
= kQuicFrameTypeSize
;
1959 const size_t kLargestObservedOffset
= kReceivedEntropyOffset
+
1960 kQuicEntropyHashSize
;
1961 const size_t kMissingDeltaTimeOffset
= kLargestObservedOffset
+
1962 PACKET_6BYTE_SEQUENCE_NUMBER
;
1963 const size_t kNumTimestampsOffset
= kMissingDeltaTimeOffset
+
1964 kQuicDeltaTimeLargestObservedSize
;
1965 const size_t kNumMissingPacketOffset
= kNumTimestampsOffset
+
1966 kQuicNumTimestampsSize
;
1967 const size_t kMissingPacketsOffset
= kNumMissingPacketOffset
+
1968 kNumberOfNackRangesSize
;
1969 const size_t kMissingPacketsRange
= kMissingPacketsOffset
+
1970 PACKET_1BYTE_SEQUENCE_NUMBER
;
1971 const size_t kRevivedPacketsLength
= kMissingPacketsRange
+
1972 PACKET_1BYTE_SEQUENCE_NUMBER
;
1973 // Now test framing boundaries.
1974 const size_t ack_frame_size
= kRevivedPacketsLength
+
1975 PACKET_1BYTE_SEQUENCE_NUMBER
;
1976 for (size_t i
= kQuicFrameTypeSize
; i
< ack_frame_size
; ++i
) {
1977 string expected_error
;
1978 if (i
< kLargestObservedOffset
) {
1979 expected_error
= "Unable to read entropy hash for received packets.";
1980 } else if (i
< kMissingDeltaTimeOffset
) {
1981 expected_error
= "Unable to read largest observed.";
1982 } else if (i
< kNumTimestampsOffset
) {
1983 expected_error
= "Unable to read delta time largest observed.";
1984 } else if (i
< kNumMissingPacketOffset
) {
1985 expected_error
= "Unable to read num received packets.";
1986 } else if (i
< kMissingPacketsOffset
) {
1987 expected_error
= "Unable to read num missing packet ranges.";
1988 } else if (i
< kMissingPacketsRange
) {
1989 expected_error
= "Unable to read missing sequence number delta.";
1990 } else if (i
< kRevivedPacketsLength
) {
1991 expected_error
= "Unable to read missing sequence number range.";
1993 expected_error
= "Unable to read num revived packets.";
1995 CheckProcessingFails(
1997 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
1998 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
1999 expected_error
, QUIC_INVALID_ACK_DATA
);
2003 TEST_P(QuicFramerTest
, AckFrameRevivedPackets
) {
2004 unsigned char packet
[] = {
2005 // public flags (8 byte connection_id)
2008 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
2009 // packet sequence number
2010 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
2011 // private flags (entropy)
2014 // frame type (ack frame)
2015 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
2017 // entropy hash of all received packets.
2019 // largest observed packet sequence number
2020 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12,
2023 // num received packets.
2025 // num missing packets
2027 // missing packet delta
2029 // 0 more missing packets in range.
2031 // Number of revived packets.
2033 // Revived packet sequence number.
2034 0xBE, 0x9A, 0x78, 0x56, 0x34, 0x12,
2035 // Number of revived packets.
2039 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2040 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2042 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2043 ASSERT_TRUE(visitor_
.header_
.get());
2044 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2046 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
2047 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
2048 const QuicAckFrame
& frame
= *visitor_
.ack_frames_
[0];
2049 EXPECT_EQ(0xBA, frame
.entropy_hash
);
2050 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame
.largest_observed
);
2051 ASSERT_EQ(1u, frame
.missing_packets
.size());
2052 SequenceNumberSet::const_iterator missing_iter
=
2053 frame
.missing_packets
.begin();
2054 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter
);
2056 const size_t kReceivedEntropyOffset
= kQuicFrameTypeSize
;
2057 const size_t kLargestObservedOffset
= kReceivedEntropyOffset
+
2058 kQuicEntropyHashSize
;
2059 const size_t kMissingDeltaTimeOffset
= kLargestObservedOffset
+
2060 PACKET_6BYTE_SEQUENCE_NUMBER
;
2061 const size_t kNumTimestampsOffset
= kMissingDeltaTimeOffset
+
2062 kQuicDeltaTimeLargestObservedSize
;
2063 const size_t kNumMissingPacketOffset
= kNumTimestampsOffset
+
2064 kQuicNumTimestampsSize
;
2065 const size_t kMissingPacketsOffset
= kNumMissingPacketOffset
+
2066 kNumberOfNackRangesSize
;
2067 const size_t kMissingPacketsRange
= kMissingPacketsOffset
+
2068 PACKET_1BYTE_SEQUENCE_NUMBER
;
2069 const size_t kRevivedPacketsLength
= kMissingPacketsRange
+
2070 PACKET_1BYTE_SEQUENCE_NUMBER
;
2071 const size_t kRevivedPacketSequenceNumberLength
= kRevivedPacketsLength
+
2072 PACKET_1BYTE_SEQUENCE_NUMBER
;
2073 // Now test framing boundaries.
2074 const size_t ack_frame_size
= kRevivedPacketSequenceNumberLength
+
2075 PACKET_6BYTE_SEQUENCE_NUMBER
;
2076 for (size_t i
= kQuicFrameTypeSize
; i
< ack_frame_size
; ++i
) {
2077 string expected_error
;
2078 if (i
< kReceivedEntropyOffset
) {
2079 expected_error
= "Unable to read least unacked delta.";
2080 } else if (i
< kLargestObservedOffset
) {
2081 expected_error
= "Unable to read entropy hash for received packets.";
2082 } else if (i
< kMissingDeltaTimeOffset
) {
2083 expected_error
= "Unable to read largest observed.";
2084 } else if (i
< kNumTimestampsOffset
) {
2085 expected_error
= "Unable to read delta time largest observed.";
2086 } else if (i
< kNumMissingPacketOffset
) {
2087 expected_error
= "Unable to read num received packets.";
2088 } else if (i
< kMissingPacketsOffset
) {
2089 expected_error
= "Unable to read num missing packet ranges.";
2090 } else if (i
< kMissingPacketsRange
) {
2091 expected_error
= "Unable to read missing sequence number delta.";
2092 } else if (i
< kRevivedPacketsLength
) {
2093 expected_error
= "Unable to read missing sequence number range.";
2094 } else if (i
< kRevivedPacketSequenceNumberLength
) {
2095 expected_error
= "Unable to read num revived packets.";
2097 expected_error
= "Unable to read revived packet.";
2099 CheckProcessingFails(
2101 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
2102 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
2103 expected_error
, QUIC_INVALID_ACK_DATA
);
2107 TEST_P(QuicFramerTest
, AckFrameNoNacks
) {
2108 unsigned char packet
[] = {
2109 // public flags (8 byte connection_id)
2112 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
2113 // packet sequence number
2114 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
2115 // private flags (entropy)
2118 // frame type (ack frame)
2119 // (no nacks, not truncated, 6 byte largest observed, 1 byte delta)
2121 // entropy hash of all received packets.
2123 // largest observed packet sequence number
2124 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12,
2127 // Number of received packets.
2131 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2132 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2134 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2135 ASSERT_TRUE(visitor_
.header_
.get());
2136 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2138 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
2139 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
2140 QuicAckFrame
* frame
= visitor_
.ack_frames_
[0];
2141 EXPECT_EQ(0xBA, frame
->entropy_hash
);
2142 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame
->largest_observed
);
2143 ASSERT_EQ(0u, frame
->missing_packets
.size());
2145 // Verify that the packet re-serializes identically.
2147 frames
.push_back(QuicFrame(frame
));
2148 scoped_ptr
<QuicPacket
> data(BuildDataPacket(*visitor_
.header_
, frames
));
2149 ASSERT_TRUE(data
!= nullptr);
2151 test::CompareCharArraysWithHexError("constructed packet", data
->data(),
2152 data
->length(), AsChars(packet
),
2156 TEST_P(QuicFramerTest
, AckFrame500Nacks
) {
2157 unsigned char packet
[] = {
2158 // public flags (8 byte connection_id)
2161 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
2162 // packet sequence number
2163 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
2164 // private flags (entropy)
2167 // frame type (ack frame)
2168 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
2170 // entropy hash of all received packets.
2172 // largest observed packet sequence number
2173 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12,
2176 // No received packets.
2178 // num missing packet ranges
2180 // missing packet delta
2182 // 243 more missing packets in range.
2183 // The ranges are listed in this order so the re-constructed packet
2186 // No gap between ranges
2188 // 255 more missing packets in range.
2190 // No revived packets.
2194 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2195 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2197 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2198 ASSERT_TRUE(visitor_
.header_
.get());
2199 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2201 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
2202 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
2203 QuicAckFrame
* frame
= visitor_
.ack_frames_
[0];
2204 EXPECT_EQ(0xBA, frame
->entropy_hash
);
2205 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame
->largest_observed
);
2206 EXPECT_EQ(0u, frame
->revived_packets
.size());
2207 ASSERT_EQ(500u, frame
->missing_packets
.size());
2208 SequenceNumberSet::const_iterator first_missing_iter
=
2209 frame
->missing_packets
.begin();
2210 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE) - 499, *first_missing_iter
);
2211 SequenceNumberSet::const_reverse_iterator last_missing_iter
=
2212 frame
->missing_packets
.rbegin();
2213 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *last_missing_iter
);
2215 // Verify that the packet re-serializes identically.
2217 frames
.push_back(QuicFrame(frame
));
2218 scoped_ptr
<QuicPacket
> data(BuildDataPacket(*visitor_
.header_
, frames
));
2219 ASSERT_TRUE(data
!= nullptr);
2221 test::CompareCharArraysWithHexError("constructed packet",
2222 data
->data(), data
->length(),
2223 AsChars(packet
), arraysize(packet
));
2226 TEST_P(QuicFramerTest
, StopWaitingFrame
) {
2227 unsigned char packet
[] = {
2228 // public flags (8 byte connection_id)
2231 0x10, 0x32, 0x54, 0x76,
2232 0x98, 0xBA, 0xDC, 0xFE,
2233 // packet sequence number
2234 0xA8, 0x9A, 0x78, 0x56,
2236 // private flags (entropy)
2239 // frame type (ack frame)
2240 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
2242 // entropy hash of sent packets till least awaiting - 1.
2244 // least packet sequence number awaiting an ack, delta from sequence number.
2245 0x08, 0x00, 0x00, 0x00,
2249 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2250 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2252 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2253 ASSERT_TRUE(visitor_
.header_
.get());
2254 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2256 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
2257 ASSERT_EQ(1u, visitor_
.stop_waiting_frames_
.size());
2258 const QuicStopWaitingFrame
& frame
= *visitor_
.stop_waiting_frames_
[0];
2259 EXPECT_EQ(0xAB, frame
.entropy_hash
);
2260 EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame
.least_unacked
);
2262 const size_t kSentEntropyOffset
= kQuicFrameTypeSize
;
2263 const size_t kLeastUnackedOffset
= kSentEntropyOffset
+ kQuicEntropyHashSize
;
2264 const size_t frame_size
= 7;
2265 for (size_t i
= kQuicFrameTypeSize
; i
< frame_size
; ++i
) {
2266 string expected_error
;
2267 if (i
< kLeastUnackedOffset
) {
2268 expected_error
= "Unable to read entropy hash for sent packets.";
2270 expected_error
= "Unable to read least unacked delta.";
2272 CheckProcessingFails(
2274 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
2275 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
2276 expected_error
, QUIC_INVALID_STOP_WAITING_DATA
);
2280 TEST_P(QuicFramerTest
, RstStreamFrameQuicVersion24
) {
2281 if (version_
> QUIC_VERSION_24
) {
2282 // QUIC_VERSION_25 removes the error_details field from QuicRstStreamFrame.
2286 unsigned char packet
[] = {
2287 // public flags (8 byte connection_id)
2290 0x10, 0x32, 0x54, 0x76,
2291 0x98, 0xBA, 0xDC, 0xFE,
2292 // packet sequence number
2293 0xBC, 0x9A, 0x78, 0x56,
2298 // frame type (rst stream frame)
2301 0x04, 0x03, 0x02, 0x01,
2304 0x01, 0x02, 0x03, 0x04,
2305 0x05, 0x06, 0x07, 0x08,
2308 0x01, 0x00, 0x00, 0x00,
2310 // error details length
2319 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2320 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2322 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2323 ASSERT_TRUE(visitor_
.header_
.get());
2324 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2326 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_
.rst_stream_frame_
.stream_id
);
2327 EXPECT_EQ(0x01, visitor_
.rst_stream_frame_
.error_code
);
2328 EXPECT_EQ("because I can", visitor_
.rst_stream_frame_
.error_details
);
2329 EXPECT_EQ(GG_UINT64_C(0x0807060504030201),
2330 visitor_
.rst_stream_frame_
.byte_offset
);
2332 // Now test framing boundaries.
2333 for (size_t i
= kQuicFrameTypeSize
;
2334 i
< QuicFramer::GetMinRstStreamFrameSize(); ++i
) {
2335 string expected_error
;
2336 if (i
< kQuicFrameTypeSize
+ kQuicMaxStreamIdSize
) {
2337 expected_error
= "Unable to read stream_id.";
2338 } else if (i
< kQuicFrameTypeSize
+ kQuicMaxStreamIdSize
+
2339 + kQuicMaxStreamOffsetSize
) {
2340 expected_error
= "Unable to read rst stream sent byte offset.";
2341 } else if (i
< kQuicFrameTypeSize
+ kQuicMaxStreamIdSize
+
2342 + kQuicMaxStreamOffsetSize
+ kQuicErrorCodeSize
) {
2343 expected_error
= "Unable to read rst stream error code.";
2345 expected_error
= "Unable to read rst stream error details.";
2347 CheckProcessingFails(
2349 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
2350 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
2351 expected_error
, QUIC_INVALID_RST_STREAM_DATA
);
2355 TEST_P(QuicFramerTest
, RstStreamFrameQuic
) {
2356 if (version_
<= QUIC_VERSION_24
) {
2357 // QUIC_VERSION_25 removes the error_details field from QuicRstStreamFrame.
2361 unsigned char packet
[] = {
2362 // public flags (8 byte connection_id)
2365 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
2366 // packet sequence number
2367 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
2371 // frame type (rst stream frame)
2374 0x04, 0x03, 0x02, 0x01,
2377 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
2380 0x01, 0x00, 0x00, 0x00,
2383 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2384 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2386 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2387 ASSERT_TRUE(visitor_
.header_
.get());
2388 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2390 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_
.rst_stream_frame_
.stream_id
);
2391 EXPECT_EQ(0x01, visitor_
.rst_stream_frame_
.error_code
);
2392 EXPECT_EQ(GG_UINT64_C(0x0807060504030201),
2393 visitor_
.rst_stream_frame_
.byte_offset
);
2395 // Now test framing boundaries.
2396 for (size_t i
= kQuicFrameTypeSize
; i
< QuicFramer::GetRstStreamFrameSize();
2398 string expected_error
;
2399 if (i
< kQuicFrameTypeSize
+ kQuicMaxStreamIdSize
) {
2400 expected_error
= "Unable to read stream_id.";
2401 } else if (i
< kQuicFrameTypeSize
+ kQuicMaxStreamIdSize
+
2402 +kQuicMaxStreamOffsetSize
) {
2403 expected_error
= "Unable to read rst stream sent byte offset.";
2404 } else if (i
< kQuicFrameTypeSize
+ kQuicMaxStreamIdSize
+
2405 +kQuicMaxStreamOffsetSize
+ kQuicErrorCodeSize
) {
2406 expected_error
= "Unable to read rst stream error code.";
2408 CheckProcessingFails(
2410 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
2411 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
2412 expected_error
, QUIC_INVALID_RST_STREAM_DATA
);
2416 TEST_P(QuicFramerTest
, ConnectionCloseFrame
) {
2417 unsigned char packet
[] = {
2418 // public flags (8 byte connection_id)
2421 0x10, 0x32, 0x54, 0x76,
2422 0x98, 0xBA, 0xDC, 0xFE,
2423 // packet sequence number
2424 0xBC, 0x9A, 0x78, 0x56,
2429 // frame type (connection close frame)
2432 0x11, 0x00, 0x00, 0x00,
2434 // error details length
2443 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2444 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2446 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2447 ASSERT_TRUE(visitor_
.header_
.get());
2448 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2450 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
2452 EXPECT_EQ(0x11, visitor_
.connection_close_frame_
.error_code
);
2453 EXPECT_EQ("because I can", visitor_
.connection_close_frame_
.error_details
);
2455 ASSERT_EQ(0u, visitor_
.ack_frames_
.size());
2457 // Now test framing boundaries.
2458 for (size_t i
= kQuicFrameTypeSize
;
2459 i
< QuicFramer::GetMinConnectionCloseFrameSize(); ++i
) {
2460 string expected_error
;
2461 if (i
< kQuicFrameTypeSize
+ kQuicErrorCodeSize
) {
2462 expected_error
= "Unable to read connection close error code.";
2464 expected_error
= "Unable to read connection close error details.";
2466 CheckProcessingFails(
2468 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
2469 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
2470 expected_error
, QUIC_INVALID_CONNECTION_CLOSE_DATA
);
2474 TEST_P(QuicFramerTest
, GoAwayFrame
) {
2475 unsigned char packet
[] = {
2476 // public flags (8 byte connection_id)
2479 0x10, 0x32, 0x54, 0x76,
2480 0x98, 0xBA, 0xDC, 0xFE,
2481 // packet sequence number
2482 0xBC, 0x9A, 0x78, 0x56,
2487 // frame type (go away frame)
2490 0x09, 0x00, 0x00, 0x00,
2492 0x04, 0x03, 0x02, 0x01,
2493 // error details length
2502 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2503 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2505 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2506 ASSERT_TRUE(visitor_
.header_
.get());
2507 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2509 EXPECT_EQ(GG_UINT64_C(0x01020304),
2510 visitor_
.goaway_frame_
.last_good_stream_id
);
2511 EXPECT_EQ(0x9, visitor_
.goaway_frame_
.error_code
);
2512 EXPECT_EQ("because I can", visitor_
.goaway_frame_
.reason_phrase
);
2514 const size_t reason_size
= arraysize("because I can") - 1;
2515 // Now test framing boundaries.
2516 for (size_t i
= kQuicFrameTypeSize
;
2517 i
< QuicFramer::GetMinGoAwayFrameSize() + reason_size
; ++i
) {
2518 string expected_error
;
2519 if (i
< kQuicFrameTypeSize
+ kQuicErrorCodeSize
) {
2520 expected_error
= "Unable to read go away error code.";
2521 } else if (i
< kQuicFrameTypeSize
+ kQuicErrorCodeSize
+
2522 kQuicMaxStreamIdSize
) {
2523 expected_error
= "Unable to read last good stream id.";
2525 expected_error
= "Unable to read goaway reason.";
2527 CheckProcessingFails(
2529 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
2530 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
2531 expected_error
, QUIC_INVALID_GOAWAY_DATA
);
2535 TEST_P(QuicFramerTest
, WindowUpdateFrame
) {
2536 unsigned char packet
[] = {
2537 // public flags (8 byte connection_id)
2540 0x10, 0x32, 0x54, 0x76,
2541 0x98, 0xBA, 0xDC, 0xFE,
2542 // packet sequence number
2543 0xBC, 0x9A, 0x78, 0x56,
2548 // frame type (window update frame)
2551 0x04, 0x03, 0x02, 0x01,
2553 0x05, 0x06, 0x07, 0x08,
2554 0x09, 0x0a, 0x0b, 0x0c,
2557 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2559 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2561 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2562 ASSERT_TRUE(visitor_
.header_
.get());
2563 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2565 EXPECT_EQ(GG_UINT64_C(0x01020304),
2566 visitor_
.window_update_frame_
.stream_id
);
2567 EXPECT_EQ(GG_UINT64_C(0x0c0b0a0908070605),
2568 visitor_
.window_update_frame_
.byte_offset
);
2570 // Now test framing boundaries.
2571 for (size_t i
= kQuicFrameTypeSize
;
2572 i
< QuicFramer::GetWindowUpdateFrameSize(); ++i
) {
2573 string expected_error
;
2574 if (i
< kQuicFrameTypeSize
+ kQuicMaxStreamIdSize
) {
2575 expected_error
= "Unable to read stream_id.";
2577 expected_error
= "Unable to read window byte_offset.";
2579 CheckProcessingFails(
2581 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
2582 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
2583 expected_error
, QUIC_INVALID_WINDOW_UPDATE_DATA
);
2587 TEST_P(QuicFramerTest
, BlockedFrame
) {
2588 unsigned char packet
[] = {
2589 // public flags (8 byte connection_id)
2592 0x10, 0x32, 0x54, 0x76,
2593 0x98, 0xBA, 0xDC, 0xFE,
2594 // packet sequence number
2595 0xBC, 0x9A, 0x78, 0x56,
2600 // frame type (blocked frame)
2603 0x04, 0x03, 0x02, 0x01,
2606 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2608 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2610 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2611 ASSERT_TRUE(visitor_
.header_
.get());
2612 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2614 EXPECT_EQ(GG_UINT64_C(0x01020304),
2615 visitor_
.blocked_frame_
.stream_id
);
2617 // Now test framing boundaries.
2618 for (size_t i
= kQuicFrameTypeSize
; i
< QuicFramer::GetBlockedFrameSize();
2620 string expected_error
= "Unable to read stream_id.";
2621 CheckProcessingFails(
2623 i
+ GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
2624 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
),
2625 expected_error
, QUIC_INVALID_BLOCKED_DATA
);
2629 TEST_P(QuicFramerTest
, PingFrame
) {
2630 unsigned char packet
[] = {
2631 // public flags (8 byte connection_id)
2634 0x10, 0x32, 0x54, 0x76,
2635 0x98, 0xBA, 0xDC, 0xFE,
2636 // packet sequence number
2637 0xBC, 0x9A, 0x78, 0x56,
2642 // frame type (ping frame)
2646 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2647 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2649 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2650 ASSERT_TRUE(visitor_
.header_
.get());
2651 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2653 EXPECT_EQ(1u, visitor_
.ping_frames_
.size());
2655 // No need to check the PING frame boundaries because it has no payload.
2658 TEST_P(QuicFramerTest
, PublicResetPacket
) {
2659 unsigned char packet
[] = {
2660 // public flags (public reset, 8 byte connection_id)
2663 0x10, 0x32, 0x54, 0x76,
2664 0x98, 0xBA, 0xDC, 0xFE,
2665 // message tag (kPRST)
2667 // num_entries (2) + padding
2668 0x02, 0x00, 0x00, 0x00,
2672 0x08, 0x00, 0x00, 0x00,
2676 0x10, 0x00, 0x00, 0x00,
2678 0x89, 0x67, 0x45, 0x23,
2679 0x01, 0xEF, 0xCD, 0xAB,
2680 // rejected sequence number
2681 0xBC, 0x9A, 0x78, 0x56,
2682 0x34, 0x12, 0x00, 0x00,
2685 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2686 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2687 ASSERT_EQ(QUIC_NO_ERROR
, framer_
.error());
2688 ASSERT_TRUE(visitor_
.public_reset_packet_
.get());
2689 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
2690 visitor_
.public_reset_packet_
->public_header
.connection_id
);
2691 EXPECT_TRUE(visitor_
.public_reset_packet_
->public_header
.reset_flag
);
2692 EXPECT_FALSE(visitor_
.public_reset_packet_
->public_header
.version_flag
);
2693 EXPECT_EQ(GG_UINT64_C(0xABCDEF0123456789),
2694 visitor_
.public_reset_packet_
->nonce_proof
);
2695 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
2696 visitor_
.public_reset_packet_
->rejected_sequence_number
);
2698 visitor_
.public_reset_packet_
->client_address
.address().empty());
2700 // Now test framing boundaries.
2701 for (size_t i
= 0; i
< arraysize(packet
); ++i
) {
2702 string expected_error
;
2703 DVLOG(1) << "iteration: " << i
;
2704 if (i
< kConnectionIdOffset
) {
2705 expected_error
= "Unable to read public flags.";
2706 CheckProcessingFails(packet
, i
, expected_error
,
2707 QUIC_INVALID_PACKET_HEADER
);
2708 } else if (i
< kPublicResetPacketMessageTagOffset
) {
2709 expected_error
= "Unable to read ConnectionId.";
2710 CheckProcessingFails(packet
, i
, expected_error
,
2711 QUIC_INVALID_PACKET_HEADER
);
2713 expected_error
= "Unable to read reset message.";
2714 CheckProcessingFails(packet
, i
, expected_error
,
2715 QUIC_INVALID_PUBLIC_RST_PACKET
);
2720 TEST_P(QuicFramerTest
, PublicResetPacketWithTrailingJunk
) {
2721 unsigned char packet
[] = {
2722 // public flags (public reset, 8 byte connection_id)
2725 0x10, 0x32, 0x54, 0x76,
2726 0x98, 0xBA, 0xDC, 0xFE,
2727 // message tag (kPRST)
2729 // num_entries (2) + padding
2730 0x02, 0x00, 0x00, 0x00,
2734 0x08, 0x00, 0x00, 0x00,
2738 0x10, 0x00, 0x00, 0x00,
2740 0x89, 0x67, 0x45, 0x23,
2741 0x01, 0xEF, 0xCD, 0xAB,
2742 // rejected sequence number
2743 0xBC, 0x9A, 0x78, 0x56,
2744 0x34, 0x12, 0x00, 0x00,
2749 string expected_error
= "Unable to read reset message.";
2750 CheckProcessingFails(packet
, arraysize(packet
), expected_error
,
2751 QUIC_INVALID_PUBLIC_RST_PACKET
);
2754 TEST_P(QuicFramerTest
, PublicResetPacketWithClientAddress
) {
2755 unsigned char packet
[] = {
2756 // public flags (public reset, 8 byte connection_id)
2759 0x10, 0x32, 0x54, 0x76,
2760 0x98, 0xBA, 0xDC, 0xFE,
2761 // message tag (kPRST)
2763 // num_entries (3) + padding
2764 0x03, 0x00, 0x00, 0x00,
2768 0x08, 0x00, 0x00, 0x00,
2772 0x10, 0x00, 0x00, 0x00,
2776 0x18, 0x00, 0x00, 0x00,
2778 0x89, 0x67, 0x45, 0x23,
2779 0x01, 0xEF, 0xCD, 0xAB,
2780 // rejected sequence number
2781 0xBC, 0x9A, 0x78, 0x56,
2782 0x34, 0x12, 0x00, 0x00,
2783 // client address: 4.31.198.44:443
2785 0x04, 0x1F, 0xC6, 0x2C,
2789 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2790 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2791 ASSERT_EQ(QUIC_NO_ERROR
, framer_
.error());
2792 ASSERT_TRUE(visitor_
.public_reset_packet_
.get());
2793 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
2794 visitor_
.public_reset_packet_
->public_header
.connection_id
);
2795 EXPECT_TRUE(visitor_
.public_reset_packet_
->public_header
.reset_flag
);
2796 EXPECT_FALSE(visitor_
.public_reset_packet_
->public_header
.version_flag
);
2797 EXPECT_EQ(GG_UINT64_C(0xABCDEF0123456789),
2798 visitor_
.public_reset_packet_
->nonce_proof
);
2799 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
2800 visitor_
.public_reset_packet_
->rejected_sequence_number
);
2801 EXPECT_EQ("4.31.198.44",
2802 IPAddressToString(visitor_
.public_reset_packet_
->
2803 client_address
.address()));
2804 EXPECT_EQ(443, visitor_
.public_reset_packet_
->client_address
.port());
2806 // Now test framing boundaries.
2807 for (size_t i
= 0; i
< arraysize(packet
); ++i
) {
2808 string expected_error
;
2809 DVLOG(1) << "iteration: " << i
;
2810 if (i
< kConnectionIdOffset
) {
2811 expected_error
= "Unable to read public flags.";
2812 CheckProcessingFails(packet
, i
, expected_error
,
2813 QUIC_INVALID_PACKET_HEADER
);
2814 } else if (i
< kPublicResetPacketMessageTagOffset
) {
2815 expected_error
= "Unable to read ConnectionId.";
2816 CheckProcessingFails(packet
, i
, expected_error
,
2817 QUIC_INVALID_PACKET_HEADER
);
2819 expected_error
= "Unable to read reset message.";
2820 CheckProcessingFails(packet
, i
, expected_error
,
2821 QUIC_INVALID_PUBLIC_RST_PACKET
);
2826 TEST_P(QuicFramerTest
, VersionNegotiationPacket
) {
2827 unsigned char packet
[] = {
2828 // public flags (version, 8 byte connection_id)
2831 0x10, 0x32, 0x54, 0x76,
2832 0x98, 0xBA, 0xDC, 0xFE,
2834 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
2838 QuicFramerPeer::SetPerspective(&framer_
, Perspective::IS_CLIENT
);
2840 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2841 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2842 ASSERT_EQ(QUIC_NO_ERROR
, framer_
.error());
2843 ASSERT_TRUE(visitor_
.version_negotiation_packet_
.get());
2844 EXPECT_EQ(2u, visitor_
.version_negotiation_packet_
->versions
.size());
2845 EXPECT_EQ(GetParam(), visitor_
.version_negotiation_packet_
->versions
[0]);
2847 for (size_t i
= 0; i
<= kPublicFlagsSize
+ PACKET_8BYTE_CONNECTION_ID
; ++i
) {
2848 string expected_error
;
2849 QuicErrorCode error_code
= QUIC_INVALID_PACKET_HEADER
;
2850 if (i
< kConnectionIdOffset
) {
2851 expected_error
= "Unable to read public flags.";
2852 } else if (i
< kVersionOffset
) {
2853 expected_error
= "Unable to read ConnectionId.";
2855 expected_error
= "Unable to read supported version in negotiation.";
2856 error_code
= QUIC_INVALID_VERSION_NEGOTIATION_PACKET
;
2858 CheckProcessingFails(packet
, i
, expected_error
, error_code
);
2862 TEST_P(QuicFramerTest
, FecPacket
) {
2863 unsigned char packet
[] = {
2864 // public flags (8 byte connection_id)
2867 0x10, 0x32, 0x54, 0x76,
2868 0x98, 0xBA, 0xDC, 0xFE,
2869 // packet sequence number
2870 0xBC, 0x9A, 0x78, 0x56,
2872 // private flags (fec group & FEC)
2874 // first fec protected packet offset
2884 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
2885 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
2887 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
2888 ASSERT_TRUE(visitor_
.header_
.get());
2889 EXPECT_TRUE(CheckDecryption(encrypted
, !kIncludeVersion
));
2891 EXPECT_EQ(0u, visitor_
.stream_frames_
.size());
2892 EXPECT_EQ(0u, visitor_
.ack_frames_
.size());
2893 ASSERT_EQ(1, visitor_
.fec_count_
);
2894 const QuicFecData
& fec_data
= *visitor_
.fec_data_
[0];
2895 EXPECT_EQ(GG_UINT64_C(0x0123456789ABB), fec_data
.fec_group
);
2896 EXPECT_EQ("abcdefghijklmnop", fec_data
.redundancy
);
2899 TEST_P(QuicFramerTest
, BuildPaddingFramePacket
) {
2900 QuicPacketHeader header
;
2901 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
2902 header
.public_header
.reset_flag
= false;
2903 header
.public_header
.version_flag
= false;
2904 header
.fec_flag
= false;
2905 header
.entropy_flag
= false;
2906 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
2907 header
.fec_group
= 0;
2909 QuicPaddingFrame padding_frame
;
2912 frames
.push_back(QuicFrame(&padding_frame
));
2914 unsigned char packet
[kMaxPacketSize
] = {
2915 // public flags (8 byte connection_id)
2918 0x10, 0x32, 0x54, 0x76,
2919 0x98, 0xBA, 0xDC, 0xFE,
2920 // packet sequence number
2921 0xBC, 0x9A, 0x78, 0x56,
2926 // frame type (padding frame)
2928 0x00, 0x00, 0x00, 0x00
2931 uint64 header_size
=
2932 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
2933 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
2934 memset(packet
+ header_size
+ 1, 0x00, kMaxPacketSize
- header_size
- 1);
2936 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
2937 ASSERT_TRUE(data
!= nullptr);
2939 test::CompareCharArraysWithHexError("constructed packet",
2940 data
->data(), data
->length(),
2945 TEST_P(QuicFramerTest
, Build4ByteSequenceNumberPaddingFramePacket
) {
2946 QuicPacketHeader header
;
2947 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
2948 header
.public_header
.reset_flag
= false;
2949 header
.public_header
.version_flag
= false;
2950 header
.fec_flag
= false;
2951 header
.entropy_flag
= false;
2952 header
.public_header
.sequence_number_length
= PACKET_4BYTE_SEQUENCE_NUMBER
;
2953 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
2954 header
.fec_group
= 0;
2956 QuicPaddingFrame padding_frame
;
2959 frames
.push_back(QuicFrame(&padding_frame
));
2961 unsigned char packet
[kMaxPacketSize
] = {
2962 // public flags (8 byte connection_id and 4 byte sequence number)
2965 0x10, 0x32, 0x54, 0x76,
2966 0x98, 0xBA, 0xDC, 0xFE,
2967 // packet sequence number
2968 0xBC, 0x9A, 0x78, 0x56,
2972 // frame type (padding frame)
2974 0x00, 0x00, 0x00, 0x00
2977 uint64 header_size
=
2978 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
2979 PACKET_4BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
2980 memset(packet
+ header_size
+ 1, 0x00, kMaxPacketSize
- header_size
- 1);
2982 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
2983 ASSERT_TRUE(data
!= nullptr);
2985 test::CompareCharArraysWithHexError("constructed packet",
2986 data
->data(), data
->length(),
2991 TEST_P(QuicFramerTest
, Build2ByteSequenceNumberPaddingFramePacket
) {
2992 QuicPacketHeader header
;
2993 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
2994 header
.public_header
.reset_flag
= false;
2995 header
.public_header
.version_flag
= false;
2996 header
.fec_flag
= false;
2997 header
.entropy_flag
= false;
2998 header
.public_header
.sequence_number_length
= PACKET_2BYTE_SEQUENCE_NUMBER
;
2999 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
3000 header
.fec_group
= 0;
3002 QuicPaddingFrame padding_frame
;
3005 frames
.push_back(QuicFrame(&padding_frame
));
3007 unsigned char packet
[kMaxPacketSize
] = {
3008 // public flags (8 byte connection_id and 2 byte sequence number)
3011 0x10, 0x32, 0x54, 0x76,
3012 0x98, 0xBA, 0xDC, 0xFE,
3013 // packet sequence number
3018 // frame type (padding frame)
3020 0x00, 0x00, 0x00, 0x00
3023 uint64 header_size
=
3024 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
3025 PACKET_2BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
3026 memset(packet
+ header_size
+ 1, 0x00, kMaxPacketSize
- header_size
- 1);
3028 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
3029 ASSERT_TRUE(data
!= nullptr);
3031 test::CompareCharArraysWithHexError("constructed packet",
3032 data
->data(), data
->length(),
3037 TEST_P(QuicFramerTest
, Build1ByteSequenceNumberPaddingFramePacket
) {
3038 QuicPacketHeader header
;
3039 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3040 header
.public_header
.reset_flag
= false;
3041 header
.public_header
.version_flag
= false;
3042 header
.fec_flag
= false;
3043 header
.entropy_flag
= false;
3044 header
.public_header
.sequence_number_length
= PACKET_1BYTE_SEQUENCE_NUMBER
;
3045 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
3046 header
.fec_group
= 0;
3048 QuicPaddingFrame padding_frame
;
3051 frames
.push_back(QuicFrame(&padding_frame
));
3053 unsigned char packet
[kMaxPacketSize
] = {
3054 // public flags (8 byte connection_id and 1 byte sequence number)
3057 0x10, 0x32, 0x54, 0x76,
3058 0x98, 0xBA, 0xDC, 0xFE,
3059 // packet sequence number
3064 // frame type (padding frame)
3066 0x00, 0x00, 0x00, 0x00
3069 uint64 header_size
=
3070 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
3071 PACKET_1BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
3072 memset(packet
+ header_size
+ 1, 0x00, kMaxPacketSize
- header_size
- 1);
3074 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
3075 ASSERT_TRUE(data
!= nullptr);
3077 test::CompareCharArraysWithHexError("constructed packet",
3078 data
->data(), data
->length(),
3083 TEST_P(QuicFramerTest
, BuildStreamFramePacket
) {
3084 QuicPacketHeader header
;
3085 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3086 header
.public_header
.reset_flag
= false;
3087 header
.public_header
.version_flag
= false;
3088 header
.fec_flag
= false;
3089 header
.entropy_flag
= true;
3090 header
.packet_sequence_number
= GG_UINT64_C(0x77123456789ABC);
3091 header
.fec_group
= 0;
3093 QuicStreamFrame stream_frame
;
3094 stream_frame
.stream_id
= 0x01020304;
3095 stream_frame
.fin
= true;
3096 stream_frame
.offset
= GG_UINT64_C(0xBA98FEDC32107654);
3097 stream_frame
.data
= MakeIOVector("hello world!");
3100 frames
.push_back(QuicFrame(&stream_frame
));
3102 unsigned char packet
[] = {
3103 // public flags (8 byte connection_id)
3106 0x10, 0x32, 0x54, 0x76,
3107 0x98, 0xBA, 0xDC, 0xFE,
3108 // packet sequence number
3109 0xBC, 0x9A, 0x78, 0x56,
3111 // private flags (entropy)
3114 // frame type (stream frame with fin and no length)
3117 0x04, 0x03, 0x02, 0x01,
3119 0x54, 0x76, 0x10, 0x32,
3120 0xDC, 0xFE, 0x98, 0xBA,
3127 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
3128 ASSERT_TRUE(data
!= nullptr);
3130 test::CompareCharArraysWithHexError("constructed packet",
3131 data
->data(), data
->length(),
3132 AsChars(packet
), arraysize(packet
));
3135 TEST_P(QuicFramerTest
, BuildStreamFramePacketInFecGroup
) {
3136 QuicPacketHeader header
;
3137 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3138 header
.public_header
.reset_flag
= false;
3139 header
.public_header
.version_flag
= false;
3140 header
.fec_flag
= false;
3141 header
.entropy_flag
= true;
3142 header
.packet_sequence_number
= GG_UINT64_C(0x77123456789ABC);
3143 header
.is_in_fec_group
= IN_FEC_GROUP
;
3144 header
.fec_group
= GG_UINT64_C(0x77123456789ABC);
3146 QuicStreamFrame stream_frame
;
3147 stream_frame
.stream_id
= 0x01020304;
3148 stream_frame
.fin
= true;
3149 stream_frame
.offset
= GG_UINT64_C(0xBA98FEDC32107654);
3150 stream_frame
.data
= MakeIOVector("hello world!");
3153 frames
.push_back(QuicFrame(&stream_frame
));
3154 unsigned char packet
[] = {
3155 // public flags (8 byte connection_id)
3158 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
3159 // packet sequence number
3160 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
3161 // private flags (entropy, is_in_fec_group)
3165 // frame type (stream frame with fin and data length field)
3168 0x04, 0x03, 0x02, 0x01,
3170 0x54, 0x76, 0x10, 0x32, 0xDC, 0xFE, 0x98, 0xBA,
3171 // data length (since packet is in an FEC group)
3174 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!',
3177 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
3178 ASSERT_TRUE(data
!= nullptr);
3180 test::CompareCharArraysWithHexError("constructed packet",
3181 data
->data(), data
->length(),
3182 AsChars(packet
), arraysize(packet
));
3185 TEST_P(QuicFramerTest
, BuildStreamFramePacketWithVersionFlag
) {
3186 QuicPacketHeader header
;
3187 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3188 header
.public_header
.reset_flag
= false;
3189 header
.public_header
.version_flag
= true;
3190 header
.fec_flag
= false;
3191 header
.entropy_flag
= true;
3192 header
.packet_sequence_number
= GG_UINT64_C(0x77123456789ABC);
3193 header
.fec_group
= 0;
3195 QuicStreamFrame stream_frame
;
3196 stream_frame
.stream_id
= 0x01020304;
3197 stream_frame
.fin
= true;
3198 stream_frame
.offset
= GG_UINT64_C(0xBA98FEDC32107654);
3199 stream_frame
.data
= MakeIOVector("hello world!");
3202 frames
.push_back(QuicFrame(&stream_frame
));
3204 unsigned char packet
[] = {
3205 // public flags (version, 8 byte connection_id)
3219 GetQuicVersionDigitTens(),
3220 GetQuicVersionDigitOnes(),
3221 // packet sequence number
3228 // private flags (entropy)
3231 // frame type (stream frame with fin and no length)
3262 QuicFramerPeer::SetPerspective(&framer_
, Perspective::IS_CLIENT
);
3263 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
3264 ASSERT_TRUE(data
!= nullptr);
3266 test::CompareCharArraysWithHexError("constructed packet",
3267 data
->data(), data
->length(),
3268 AsChars(packet
), arraysize(packet
));
3271 TEST_P(QuicFramerTest
, BuildVersionNegotiationPacket
) {
3272 QuicPacketPublicHeader header
;
3273 header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3274 header
.reset_flag
= false;
3275 header
.version_flag
= true;
3277 unsigned char packet
[] = {
3278 // public flags (version, 8 byte connection_id)
3292 GetQuicVersionDigitTens(),
3293 GetQuicVersionDigitOnes(),
3296 QuicVersionVector versions
;
3297 versions
.push_back(GetParam());
3298 scoped_ptr
<QuicEncryptedPacket
> data(
3299 framer_
.BuildVersionNegotiationPacket(header
, versions
));
3301 test::CompareCharArraysWithHexError("constructed packet", data
->data(),
3302 data
->length(), AsChars(packet
),
3306 TEST_P(QuicFramerTest
, BuildAckFramePacket
) {
3307 QuicPacketHeader header
;
3308 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3309 header
.public_header
.reset_flag
= false;
3310 header
.public_header
.version_flag
= false;
3311 header
.fec_flag
= false;
3312 header
.entropy_flag
= true;
3313 header
.packet_sequence_number
= GG_UINT64_C(0x770123456789AA8);
3314 header
.fec_group
= 0;
3316 QuicAckFrame ack_frame
;
3317 ack_frame
.entropy_hash
= 0x43;
3318 ack_frame
.largest_observed
= GG_UINT64_C(0x770123456789ABF);
3319 ack_frame
.delta_time_largest_observed
= QuicTime::Delta::Zero();
3320 ack_frame
.missing_packets
.insert(GG_UINT64_C(0x770123456789ABE));
3323 frames
.push_back(QuicFrame(&ack_frame
));
3325 unsigned char packet
[] = {
3326 // public flags (8 byte connection_id)
3329 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
3330 // packet sequence number
3331 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
3332 // private flags (entropy)
3335 // frame type (ack frame)
3336 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
3338 // entropy hash of all received packets.
3340 // largest observed packet sequence number
3341 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12,
3344 // num received packets.
3346 // num missing packet ranges
3348 // missing packet delta
3350 // 0 more missing packets in range.
3352 // 0 revived packets.
3356 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
3357 ASSERT_TRUE(data
!= nullptr);
3359 test::CompareCharArraysWithHexError("constructed packet",
3360 data
->data(), data
->length(),
3361 AsChars(packet
), arraysize(packet
));
3364 // TODO(jri): Add test for tuncated packets in which the original ack frame had
3365 // revived packets. (In both the large and small packet cases below).
3367 TEST_P(QuicFramerTest
, BuildTruncatedAckFrameLargePacket
) {
3368 QuicPacketHeader header
;
3369 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3370 header
.public_header
.reset_flag
= false;
3371 header
.public_header
.version_flag
= false;
3372 header
.fec_flag
= false;
3373 header
.entropy_flag
= true;
3374 header
.packet_sequence_number
= GG_UINT64_C(0x770123456789AA8);
3375 header
.fec_group
= 0;
3377 QuicAckFrame ack_frame
;
3378 // This entropy hash is different from what shows up in the packet below,
3379 // since entropy is recomputed by the framer on ack truncation (by
3380 // TestEntropyCalculator for this test.)
3381 ack_frame
.entropy_hash
= 0x43;
3382 ack_frame
.largest_observed
= 2 * 300;
3383 ack_frame
.delta_time_largest_observed
= QuicTime::Delta::Zero();
3384 for (size_t i
= 1; i
< 2 * 300; i
+= 2) {
3385 ack_frame
.missing_packets
.insert(i
);
3389 frames
.push_back(QuicFrame(&ack_frame
));
3391 unsigned char packet
[] = {
3392 // public flags (8 byte connection_id)
3395 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
3396 // packet sequence number
3397 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
3398 // private flags (entropy)
3401 // frame type (ack frame)
3402 // (has nacks, is truncated, 2 byte largest observed, 1 byte delta)
3404 // entropy hash of all received packets, set to 1 by TestEntropyCalculator
3405 // since ack is truncated.
3407 // 2-byte largest observed packet sequence number.
3408 // Expected to be 510 (0x1FE), since only 255 nack ranges can fit.
3412 // num missing packet ranges (limited to 255 by size of this field).
3414 // {missing packet delta, further missing packets in range}
3415 // 6 nack ranges x 42 + 3 nack ranges
3416 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3417 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3418 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3419 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3420 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3421 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3422 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3423 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3424 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3425 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3427 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3428 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3429 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3430 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3431 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3432 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3433 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3434 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3435 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3436 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3438 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3439 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3440 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3441 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3442 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3443 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3444 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3445 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3446 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3447 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3449 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3450 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3451 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3452 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3453 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3454 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3455 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3456 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3457 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3458 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3460 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3461 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3462 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3464 // 0 revived packets.
3468 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
3469 ASSERT_TRUE(data
!= nullptr);
3471 test::CompareCharArraysWithHexError("constructed packet",
3472 data
->data(), data
->length(),
3473 AsChars(packet
), arraysize(packet
));
3476 TEST_P(QuicFramerTest
, BuildTruncatedAckFrameSmallPacket
) {
3477 QuicPacketHeader header
;
3478 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3479 header
.public_header
.reset_flag
= false;
3480 header
.public_header
.version_flag
= false;
3481 header
.fec_flag
= false;
3482 header
.entropy_flag
= true;
3483 header
.packet_sequence_number
= GG_UINT64_C(0x770123456789AA8);
3484 header
.fec_group
= 0;
3486 QuicAckFrame ack_frame
;
3487 // This entropy hash is different from what shows up in the packet below,
3488 // since entropy is recomputed by the framer on ack truncation (by
3489 // TestEntropyCalculator for this test.)
3490 ack_frame
.entropy_hash
= 0x43;
3491 ack_frame
.largest_observed
= 2 * 300;
3492 ack_frame
.delta_time_largest_observed
= QuicTime::Delta::Zero();
3493 for (size_t i
= 1; i
< 2 * 300; i
+= 2) {
3494 ack_frame
.missing_packets
.insert(i
);
3498 frames
.push_back(QuicFrame(&ack_frame
));
3500 unsigned char packet
[] = {
3501 // public flags (8 byte connection_id)
3504 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
3505 // packet sequence number
3506 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
3507 // private flags (entropy)
3510 // frame type (ack frame)
3511 // (has nacks, is truncated, 2 byte largest observed, 1 byte delta)
3513 // entropy hash of all received packets, set to 1 by TestEntropyCalculator
3514 // since ack is truncated.
3516 // 2-byte largest observed packet sequence number.
3517 // Expected to be 12 (0x0C), since only 6 nack ranges can fit.
3521 // num missing packet ranges (limited to 6 by packet size of 37).
3523 // {missing packet delta, further missing packets in range}
3525 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3526 // 0 revived packets.
3530 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
, 37u));
3531 ASSERT_TRUE(data
!= nullptr);
3532 // Expect 1 byte unused since at least 2 bytes are needed to fit more nacks.
3533 EXPECT_EQ(36u, data
->length());
3534 test::CompareCharArraysWithHexError("constructed packet",
3535 data
->data(), data
->length(),
3536 AsChars(packet
), arraysize(packet
));
3539 TEST_P(QuicFramerTest
, BuildStopWaitingPacket
) {
3540 QuicPacketHeader header
;
3541 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3542 header
.public_header
.reset_flag
= false;
3543 header
.public_header
.version_flag
= false;
3544 header
.fec_flag
= false;
3545 header
.entropy_flag
= true;
3546 header
.packet_sequence_number
= GG_UINT64_C(0x770123456789AA8);
3547 header
.fec_group
= 0;
3549 QuicStopWaitingFrame stop_waiting_frame
;
3550 stop_waiting_frame
.entropy_hash
= 0x14;
3551 stop_waiting_frame
.least_unacked
= GG_UINT64_C(0x770123456789AA0);
3554 frames
.push_back(QuicFrame(&stop_waiting_frame
));
3556 unsigned char packet
[] = {
3557 // public flags (8 byte connection_id)
3560 0x10, 0x32, 0x54, 0x76,
3561 0x98, 0xBA, 0xDC, 0xFE,
3562 // packet sequence number
3563 0xA8, 0x9A, 0x78, 0x56,
3565 // private flags (entropy)
3568 // frame type (stop waiting frame)
3570 // entropy hash of sent packets till least awaiting - 1.
3572 // least packet sequence number awaiting an ack, delta from sequence number.
3573 0x08, 0x00, 0x00, 0x00,
3577 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
3578 ASSERT_TRUE(data
!= nullptr);
3580 test::CompareCharArraysWithHexError("constructed packet",
3581 data
->data(), data
->length(),
3582 AsChars(packet
), arraysize(packet
));
3585 TEST_P(QuicFramerTest
, BuildRstFramePacketQuicVersion24
) {
3586 if (version_
> QUIC_VERSION_24
) {
3587 // QUIC_VERSION_25 removes the error_details field from QuicRstStreamFrame.
3591 QuicPacketHeader header
;
3592 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3593 header
.public_header
.reset_flag
= false;
3594 header
.public_header
.version_flag
= false;
3595 header
.fec_flag
= false;
3596 header
.entropy_flag
= false;
3597 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
3598 header
.fec_group
= 0;
3600 QuicRstStreamFrame rst_frame
;
3601 rst_frame
.stream_id
= 0x01020304;
3602 rst_frame
.error_code
= static_cast<QuicRstStreamErrorCode
>(0x05060708);
3603 rst_frame
.error_details
= "because I can";
3604 rst_frame
.byte_offset
= 0x0807060504030201;
3606 unsigned char packet
[] = {
3607 // public flags (8 byte connection_id)
3610 0x10, 0x32, 0x54, 0x76,
3611 0x98, 0xBA, 0xDC, 0xFE,
3612 // packet sequence number
3613 0xBC, 0x9A, 0x78, 0x56,
3618 // frame type (rst stream frame)
3621 0x04, 0x03, 0x02, 0x01,
3623 0x01, 0x02, 0x03, 0x04,
3624 0x05, 0x06, 0x07, 0x08,
3626 0x08, 0x07, 0x06, 0x05,
3627 // error details length
3637 frames
.push_back(QuicFrame(&rst_frame
));
3639 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
3640 ASSERT_TRUE(data
!= nullptr);
3642 test::CompareCharArraysWithHexError("constructed packet", data
->data(),
3643 data
->length(), AsChars(packet
),
3647 TEST_P(QuicFramerTest
, BuildRstFramePacketQuic
) {
3648 if (version_
<= QUIC_VERSION_24
) {
3649 // QUIC_VERSION_25 removes the error_details field from QuicRstStreamFrame.
3653 QuicPacketHeader header
;
3654 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3655 header
.public_header
.reset_flag
= false;
3656 header
.public_header
.version_flag
= false;
3657 header
.fec_flag
= false;
3658 header
.entropy_flag
= false;
3659 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
3660 header
.fec_group
= 0;
3662 QuicRstStreamFrame rst_frame
;
3663 rst_frame
.stream_id
= 0x01020304;
3664 rst_frame
.error_code
= static_cast<QuicRstStreamErrorCode
>(0x05060708);
3665 rst_frame
.byte_offset
= 0x0807060504030201;
3667 unsigned char packet
[] = {
3668 // public flags (8 byte connection_id)
3671 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
3672 // packet sequence number
3673 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
3677 // frame type (rst stream frame)
3680 0x04, 0x03, 0x02, 0x01,
3682 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
3684 0x08, 0x07, 0x06, 0x05,
3688 frames
.push_back(QuicFrame(&rst_frame
));
3690 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
3691 ASSERT_TRUE(data
!= nullptr);
3693 test::CompareCharArraysWithHexError("constructed packet", data
->data(),
3694 data
->length(), AsChars(packet
),
3698 TEST_P(QuicFramerTest
, BuildCloseFramePacket
) {
3699 QuicPacketHeader header
;
3700 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3701 header
.public_header
.reset_flag
= false;
3702 header
.public_header
.version_flag
= false;
3703 header
.fec_flag
= false;
3704 header
.entropy_flag
= true;
3705 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
3706 header
.fec_group
= 0;
3708 QuicConnectionCloseFrame close_frame
;
3709 close_frame
.error_code
= static_cast<QuicErrorCode
>(0x05060708);
3710 close_frame
.error_details
= "because I can";
3713 frames
.push_back(QuicFrame(&close_frame
));
3715 unsigned char packet
[] = {
3716 // public flags (8 byte connection_id)
3719 0x10, 0x32, 0x54, 0x76,
3720 0x98, 0xBA, 0xDC, 0xFE,
3721 // packet sequence number
3722 0xBC, 0x9A, 0x78, 0x56,
3724 // private flags (entropy)
3727 // frame type (connection close frame)
3730 0x08, 0x07, 0x06, 0x05,
3731 // error details length
3740 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
3741 ASSERT_TRUE(data
!= nullptr);
3743 test::CompareCharArraysWithHexError("constructed packet",
3744 data
->data(), data
->length(),
3745 AsChars(packet
), arraysize(packet
));
3748 TEST_P(QuicFramerTest
, BuildGoAwayPacket
) {
3749 QuicPacketHeader header
;
3750 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3751 header
.public_header
.reset_flag
= false;
3752 header
.public_header
.version_flag
= false;
3753 header
.fec_flag
= false;
3754 header
.entropy_flag
= true;
3755 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
3756 header
.fec_group
= 0;
3758 QuicGoAwayFrame goaway_frame
;
3759 goaway_frame
.error_code
= static_cast<QuicErrorCode
>(0x05060708);
3760 goaway_frame
.last_good_stream_id
= 0x01020304;
3761 goaway_frame
.reason_phrase
= "because I can";
3764 frames
.push_back(QuicFrame(&goaway_frame
));
3766 unsigned char packet
[] = {
3767 // public flags (8 byte connection_id)
3770 0x10, 0x32, 0x54, 0x76,
3771 0x98, 0xBA, 0xDC, 0xFE,
3772 // packet sequence number
3773 0xBC, 0x9A, 0x78, 0x56,
3775 // private flags(entropy)
3778 // frame type (go away frame)
3781 0x08, 0x07, 0x06, 0x05,
3783 0x04, 0x03, 0x02, 0x01,
3784 // error details length
3793 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
3794 ASSERT_TRUE(data
!= nullptr);
3796 test::CompareCharArraysWithHexError("constructed packet",
3797 data
->data(), data
->length(),
3798 AsChars(packet
), arraysize(packet
));
3801 TEST_P(QuicFramerTest
, BuildWindowUpdatePacket
) {
3802 QuicPacketHeader header
;
3803 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3804 header
.public_header
.reset_flag
= false;
3805 header
.public_header
.version_flag
= false;
3806 header
.fec_flag
= false;
3807 header
.entropy_flag
= true;
3808 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
3809 header
.fec_group
= 0;
3811 QuicWindowUpdateFrame window_update_frame
;
3812 window_update_frame
.stream_id
= 0x01020304;
3813 window_update_frame
.byte_offset
= 0x1122334455667788;
3816 frames
.push_back(QuicFrame(&window_update_frame
));
3818 unsigned char packet
[] = {
3819 // public flags (8 byte connection_id)
3822 0x10, 0x32, 0x54, 0x76,
3823 0x98, 0xBA, 0xDC, 0xFE,
3824 // packet sequence number
3825 0xBC, 0x9A, 0x78, 0x56,
3827 // private flags(entropy)
3830 // frame type (window update frame)
3833 0x04, 0x03, 0x02, 0x01,
3835 0x88, 0x77, 0x66, 0x55,
3836 0x44, 0x33, 0x22, 0x11,
3839 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
3840 ASSERT_TRUE(data
!= nullptr);
3842 test::CompareCharArraysWithHexError("constructed packet", data
->data(),
3843 data
->length(), AsChars(packet
),
3847 TEST_P(QuicFramerTest
, BuildBlockedPacket
) {
3848 QuicPacketHeader header
;
3849 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3850 header
.public_header
.reset_flag
= false;
3851 header
.public_header
.version_flag
= false;
3852 header
.fec_flag
= false;
3853 header
.entropy_flag
= true;
3854 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
3855 header
.fec_group
= 0;
3857 QuicBlockedFrame blocked_frame
;
3858 blocked_frame
.stream_id
= 0x01020304;
3861 frames
.push_back(QuicFrame(&blocked_frame
));
3863 unsigned char packet
[] = {
3864 // public flags (8 byte connection_id)
3867 0x10, 0x32, 0x54, 0x76,
3868 0x98, 0xBA, 0xDC, 0xFE,
3869 // packet sequence number
3870 0xBC, 0x9A, 0x78, 0x56,
3872 // private flags(entropy)
3875 // frame type (blocked frame)
3878 0x04, 0x03, 0x02, 0x01,
3881 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
3882 ASSERT_TRUE(data
!= nullptr);
3884 test::CompareCharArraysWithHexError("constructed packet", data
->data(),
3885 data
->length(), AsChars(packet
),
3889 TEST_P(QuicFramerTest
, BuildPingPacket
) {
3890 QuicPacketHeader header
;
3891 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3892 header
.public_header
.reset_flag
= false;
3893 header
.public_header
.version_flag
= false;
3894 header
.fec_flag
= false;
3895 header
.entropy_flag
= true;
3896 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
3897 header
.fec_group
= 0;
3899 QuicPingFrame ping_frame
;
3902 frames
.push_back(QuicFrame(&ping_frame
));
3904 unsigned char packet
[] = {
3905 // public flags (8 byte connection_id)
3908 0x10, 0x32, 0x54, 0x76,
3909 0x98, 0xBA, 0xDC, 0xFE,
3910 // packet sequence number
3911 0xBC, 0x9A, 0x78, 0x56,
3913 // private flags(entropy)
3916 // frame type (ping frame)
3920 scoped_ptr
<QuicPacket
> data(BuildDataPacket(header
, frames
));
3921 ASSERT_TRUE(data
!= nullptr);
3923 test::CompareCharArraysWithHexError("constructed packet", data
->data(),
3924 data
->length(), AsChars(packet
),
3928 TEST_P(QuicFramerTest
, BuildPublicResetPacket
) {
3929 QuicPublicResetPacket reset_packet
;
3930 reset_packet
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3931 reset_packet
.public_header
.reset_flag
= true;
3932 reset_packet
.public_header
.version_flag
= false;
3933 reset_packet
.rejected_sequence_number
= GG_UINT64_C(0x123456789ABC);
3934 reset_packet
.nonce_proof
= GG_UINT64_C(0xABCDEF0123456789);
3936 unsigned char packet
[] = {
3937 // public flags (public reset, 8 byte ConnectionId)
3940 0x10, 0x32, 0x54, 0x76,
3941 0x98, 0xBA, 0xDC, 0xFE,
3942 // message tag (kPRST)
3944 // num_entries (2) + padding
3945 0x02, 0x00, 0x00, 0x00,
3949 0x08, 0x00, 0x00, 0x00,
3953 0x10, 0x00, 0x00, 0x00,
3955 0x89, 0x67, 0x45, 0x23,
3956 0x01, 0xEF, 0xCD, 0xAB,
3957 // rejected sequence number
3958 0xBC, 0x9A, 0x78, 0x56,
3959 0x34, 0x12, 0x00, 0x00,
3962 scoped_ptr
<QuicEncryptedPacket
> data(
3963 framer_
.BuildPublicResetPacket(reset_packet
));
3964 ASSERT_TRUE(data
!= nullptr);
3966 test::CompareCharArraysWithHexError("constructed packet",
3967 data
->data(), data
->length(),
3968 AsChars(packet
), arraysize(packet
));
3971 TEST_P(QuicFramerTest
, BuildPublicResetPacketWithClientAddress
) {
3972 QuicPublicResetPacket reset_packet
;
3973 reset_packet
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
3974 reset_packet
.public_header
.reset_flag
= true;
3975 reset_packet
.public_header
.version_flag
= false;
3976 reset_packet
.rejected_sequence_number
= GG_UINT64_C(0x123456789ABC);
3977 reset_packet
.nonce_proof
= GG_UINT64_C(0xABCDEF0123456789);
3978 reset_packet
.client_address
= IPEndPoint(Loopback4(), 0x1234);
3980 unsigned char packet
[] = {
3981 // public flags (public reset, 8 byte ConnectionId)
3984 0x10, 0x32, 0x54, 0x76,
3985 0x98, 0xBA, 0xDC, 0xFE,
3986 // message tag (kPRST)
3988 // num_entries (3) + padding
3989 0x03, 0x00, 0x00, 0x00,
3993 0x08, 0x00, 0x00, 0x00,
3997 0x10, 0x00, 0x00, 0x00,
4001 0x18, 0x00, 0x00, 0x00,
4003 0x89, 0x67, 0x45, 0x23,
4004 0x01, 0xEF, 0xCD, 0xAB,
4005 // rejected sequence number
4006 0xBC, 0x9A, 0x78, 0x56,
4007 0x34, 0x12, 0x00, 0x00,
4010 0x7F, 0x00, 0x00, 0x01,
4014 scoped_ptr
<QuicEncryptedPacket
> data(
4015 framer_
.BuildPublicResetPacket(reset_packet
));
4016 ASSERT_TRUE(data
!= nullptr);
4018 test::CompareCharArraysWithHexError("constructed packet",
4019 data
->data(), data
->length(),
4020 AsChars(packet
), arraysize(packet
));
4023 TEST_P(QuicFramerTest
, BuildFecPacket
) {
4024 QuicPacketHeader header
;
4025 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4026 header
.public_header
.reset_flag
= false;
4027 header
.public_header
.version_flag
= false;
4028 header
.fec_flag
= true;
4029 header
.entropy_flag
= true;
4030 header
.packet_sequence_number
= (GG_UINT64_C(0x123456789ABC));
4031 header
.is_in_fec_group
= IN_FEC_GROUP
;
4032 header
.fec_group
= GG_UINT64_C(0x123456789ABB);;
4034 QuicFecData fec_data
;
4035 fec_data
.fec_group
= 1;
4036 fec_data
.redundancy
= "abcdefghijklmnop";
4038 unsigned char packet
[] = {
4039 // public flags (8 byte connection_id)
4042 0x10, 0x32, 0x54, 0x76,
4043 0x98, 0xBA, 0xDC, 0xFE,
4044 // packet sequence number
4045 0xBC, 0x9A, 0x78, 0x56,
4047 // private flags (entropy & fec group & fec packet)
4049 // first fec protected packet offset
4059 scoped_ptr
<QuicPacket
> data(framer_
.BuildFecPacket(header
, fec_data
));
4060 ASSERT_TRUE(data
!= nullptr);
4062 test::CompareCharArraysWithHexError("constructed packet",
4063 data
->data(), data
->length(),
4064 AsChars(packet
), arraysize(packet
));
4067 TEST_P(QuicFramerTest
, EncryptPacket
) {
4068 QuicPacketSequenceNumber sequence_number
= GG_UINT64_C(0x123456789ABC);
4069 unsigned char packet
[] = {
4070 // public flags (8 byte connection_id)
4073 0x10, 0x32, 0x54, 0x76,
4074 0x98, 0xBA, 0xDC, 0xFE,
4075 // packet sequence number
4076 0xBC, 0x9A, 0x78, 0x56,
4078 // private flags (fec group & fec packet)
4080 // first fec protected packet offset
4090 scoped_ptr
<QuicPacket
> raw(new QuicPacket(
4091 AsChars(packet
), arraysize(packet
), false, PACKET_8BYTE_CONNECTION_ID
,
4092 !kIncludeVersion
, PACKET_6BYTE_SEQUENCE_NUMBER
));
4093 scoped_ptr
<QuicEncryptedPacket
> encrypted(
4094 framer_
.EncryptPacket(ENCRYPTION_NONE
, sequence_number
, *raw
));
4096 ASSERT_TRUE(encrypted
.get() != nullptr);
4097 EXPECT_TRUE(CheckEncryption(sequence_number
, raw
.get()));
4100 TEST_P(QuicFramerTest
, EncryptPacketWithVersionFlag
) {
4101 QuicPacketSequenceNumber sequence_number
= GG_UINT64_C(0x123456789ABC);
4102 unsigned char packet
[] = {
4103 // public flags (version, 8 byte connection_id)
4106 0x10, 0x32, 0x54, 0x76,
4107 0x98, 0xBA, 0xDC, 0xFE,
4110 // packet sequence number
4111 0xBC, 0x9A, 0x78, 0x56,
4113 // private flags (fec group & fec flags)
4115 // first fec protected packet offset
4125 scoped_ptr
<QuicPacket
> raw(new QuicPacket(
4126 AsChars(packet
), arraysize(packet
), false, PACKET_8BYTE_CONNECTION_ID
,
4127 kIncludeVersion
, PACKET_6BYTE_SEQUENCE_NUMBER
));
4128 scoped_ptr
<QuicEncryptedPacket
> encrypted(
4129 framer_
.EncryptPacket(ENCRYPTION_NONE
, sequence_number
, *raw
));
4131 ASSERT_TRUE(encrypted
.get() != nullptr);
4132 EXPECT_TRUE(CheckEncryption(sequence_number
, raw
.get()));
4135 TEST_P(QuicFramerTest
, AckTruncationLargePacket
) {
4136 QuicPacketHeader header
;
4137 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4138 header
.public_header
.reset_flag
= false;
4139 header
.public_header
.version_flag
= false;
4140 header
.fec_flag
= false;
4141 header
.entropy_flag
= false;
4142 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
4143 header
.fec_group
= 0;
4145 // Create a packet with just the ack.
4146 QuicAckFrame ack_frame
= MakeAckFrameWithNackRanges(300, 0u);
4148 frame
.type
= ACK_FRAME
;
4149 frame
.ack_frame
= &ack_frame
;
4151 frames
.push_back(frame
);
4153 // Build an ack packet with truncation due to limit in number of nack ranges.
4154 scoped_ptr
<QuicPacket
> raw_ack_packet(BuildDataPacket(header
, frames
));
4155 ASSERT_TRUE(raw_ack_packet
!= nullptr);
4156 scoped_ptr
<QuicEncryptedPacket
> ack_packet(
4157 framer_
.EncryptPacket(ENCRYPTION_NONE
, header
.packet_sequence_number
,
4159 // Now make sure we can turn our ack packet back into an ack frame.
4160 ASSERT_TRUE(framer_
.ProcessPacket(*ack_packet
));
4161 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
4162 QuicAckFrame
& processed_ack_frame
= *visitor_
.ack_frames_
[0];
4163 EXPECT_TRUE(processed_ack_frame
.is_truncated
);
4164 EXPECT_EQ(510u, processed_ack_frame
.largest_observed
);
4165 ASSERT_EQ(255u, processed_ack_frame
.missing_packets
.size());
4166 SequenceNumberSet::const_iterator missing_iter
=
4167 processed_ack_frame
.missing_packets
.begin();
4168 EXPECT_EQ(1u, *missing_iter
);
4169 SequenceNumberSet::const_reverse_iterator last_missing_iter
=
4170 processed_ack_frame
.missing_packets
.rbegin();
4171 EXPECT_EQ(509u, *last_missing_iter
);
4174 TEST_P(QuicFramerTest
, AckTruncationSmallPacket
) {
4175 QuicPacketHeader header
;
4176 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4177 header
.public_header
.reset_flag
= false;
4178 header
.public_header
.version_flag
= false;
4179 header
.fec_flag
= false;
4180 header
.entropy_flag
= false;
4181 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
4182 header
.fec_group
= 0;
4184 // Create a packet with just the ack.
4185 QuicAckFrame ack_frame
= MakeAckFrameWithNackRanges(300, 0u);
4187 frame
.type
= ACK_FRAME
;
4188 frame
.ack_frame
= &ack_frame
;
4190 frames
.push_back(frame
);
4192 // Build an ack packet with truncation due to limit in number of nack ranges.
4193 scoped_ptr
<QuicPacket
> raw_ack_packet(BuildDataPacket(header
, frames
, 500));
4194 ASSERT_TRUE(raw_ack_packet
!= nullptr);
4195 scoped_ptr
<QuicEncryptedPacket
> ack_packet(
4196 framer_
.EncryptPacket(ENCRYPTION_NONE
, header
.packet_sequence_number
,
4198 // Now make sure we can turn our ack packet back into an ack frame.
4199 ASSERT_TRUE(framer_
.ProcessPacket(*ack_packet
));
4200 ASSERT_EQ(1u, visitor_
.ack_frames_
.size());
4201 QuicAckFrame
& processed_ack_frame
= *visitor_
.ack_frames_
[0];
4202 EXPECT_TRUE(processed_ack_frame
.is_truncated
);
4203 EXPECT_EQ(476u, processed_ack_frame
.largest_observed
);
4204 ASSERT_EQ(238u, processed_ack_frame
.missing_packets
.size());
4205 SequenceNumberSet::const_iterator missing_iter
=
4206 processed_ack_frame
.missing_packets
.begin();
4207 EXPECT_EQ(1u, *missing_iter
);
4208 SequenceNumberSet::const_reverse_iterator last_missing_iter
=
4209 processed_ack_frame
.missing_packets
.rbegin();
4210 EXPECT_EQ(475u, *last_missing_iter
);
4213 TEST_P(QuicFramerTest
, CleanTruncation
) {
4214 QuicPacketHeader header
;
4215 header
.public_header
.connection_id
= GG_UINT64_C(0xFEDCBA9876543210);
4216 header
.public_header
.reset_flag
= false;
4217 header
.public_header
.version_flag
= false;
4218 header
.fec_flag
= false;
4219 header
.entropy_flag
= true;
4220 header
.packet_sequence_number
= GG_UINT64_C(0x123456789ABC);
4221 header
.fec_group
= 0;
4223 QuicAckFrame ack_frame
;
4224 ack_frame
.largest_observed
= 201;
4225 for (uint64 i
= 1; i
< ack_frame
.largest_observed
; ++i
) {
4226 ack_frame
.missing_packets
.insert(i
);
4229 // Create a packet with just the ack.
4231 frame
.type
= ACK_FRAME
;
4232 frame
.ack_frame
= &ack_frame
;
4234 frames
.push_back(frame
);
4236 scoped_ptr
<QuicPacket
> raw_ack_packet(BuildDataPacket(header
, frames
));
4237 ASSERT_TRUE(raw_ack_packet
!= nullptr);
4239 scoped_ptr
<QuicEncryptedPacket
> ack_packet(
4240 framer_
.EncryptPacket(ENCRYPTION_NONE
, header
.packet_sequence_number
,
4243 // Now make sure we can turn our ack packet back into an ack frame.
4244 ASSERT_TRUE(framer_
.ProcessPacket(*ack_packet
));
4246 // Test for clean truncation of the ack by comparing the length of the
4247 // original packets to the re-serialized packets.
4249 frame
.type
= ACK_FRAME
;
4250 frame
.ack_frame
= visitor_
.ack_frames_
[0];
4251 frames
.push_back(frame
);
4253 size_t original_raw_length
= raw_ack_packet
->length();
4254 raw_ack_packet
.reset(BuildDataPacket(header
, frames
));
4255 ASSERT_TRUE(raw_ack_packet
!= nullptr);
4256 EXPECT_EQ(original_raw_length
, raw_ack_packet
->length());
4257 ASSERT_TRUE(raw_ack_packet
!= nullptr);
4260 TEST_P(QuicFramerTest
, EntropyFlagTest
) {
4261 unsigned char packet
[] = {
4262 // public flags (8 byte connection_id)
4265 0x10, 0x32, 0x54, 0x76,
4266 0x98, 0xBA, 0xDC, 0xFE,
4267 // packet sequence number
4268 0xBC, 0x9A, 0x78, 0x56,
4270 // private flags (Entropy)
4273 // frame type (stream frame with fin and no length)
4276 0x04, 0x03, 0x02, 0x01,
4278 0x54, 0x76, 0x10, 0x32,
4279 0xDC, 0xFE, 0x98, 0xBA,
4286 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
4287 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
4288 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
4289 ASSERT_TRUE(visitor_
.header_
.get());
4290 EXPECT_TRUE(visitor_
.header_
->entropy_flag
);
4291 EXPECT_EQ(1 << 4, visitor_
.header_
->entropy_hash
);
4292 EXPECT_FALSE(visitor_
.header_
->fec_flag
);
4295 TEST_P(QuicFramerTest
, FecEntropyTest
) {
4296 unsigned char packet
[] = {
4297 // public flags (8 byte connection_id)
4300 0x10, 0x32, 0x54, 0x76,
4301 0x98, 0xBA, 0xDC, 0xFE,
4302 // packet sequence number
4303 0xBC, 0x9A, 0x78, 0x56,
4305 // private flags (Entropy & fec group & FEC)
4307 // first fec protected packet offset
4310 // frame type (stream frame with fin and no length)
4313 0x04, 0x03, 0x02, 0x01,
4315 0x54, 0x76, 0x10, 0x32,
4316 0xDC, 0xFE, 0x98, 0xBA,
4323 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
4324 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
4325 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());
4326 ASSERT_TRUE(visitor_
.header_
.get());
4327 EXPECT_TRUE(visitor_
.header_
->fec_flag
);
4328 EXPECT_TRUE(visitor_
.header_
->entropy_flag
);
4329 EXPECT_EQ(1 << 4, visitor_
.header_
->entropy_hash
);
4332 TEST_P(QuicFramerTest
, StopPacketProcessing
) {
4333 unsigned char packet
[] = {
4334 // public flags (8 byte connection_id)
4337 0x10, 0x32, 0x54, 0x76,
4338 0x98, 0xBA, 0xDC, 0xFE,
4339 // packet sequence number
4340 0xBC, 0x9A, 0x78, 0x56,
4345 // frame type (stream frame with fin)
4348 0x04, 0x03, 0x02, 0x01,
4350 0x54, 0x76, 0x10, 0x32,
4351 0xDC, 0xFE, 0x98, 0xBA,
4359 // frame type (ack frame)
4361 // entropy hash of sent packets till least awaiting - 1.
4363 // least packet sequence number awaiting an ack
4364 0xA0, 0x9A, 0x78, 0x56,
4366 // entropy hash of all received packets.
4368 // largest observed packet sequence number
4369 0xBF, 0x9A, 0x78, 0x56,
4371 // num missing packets
4374 0xBE, 0x9A, 0x78, 0x56,
4378 MockFramerVisitor visitor
;
4379 framer_
.set_visitor(&visitor
);
4380 EXPECT_CALL(visitor
, OnPacket());
4381 EXPECT_CALL(visitor
, OnPacketHeader(_
));
4382 EXPECT_CALL(visitor
, OnStreamFrame(_
)).WillOnce(Return(false));
4383 EXPECT_CALL(visitor
, OnAckFrame(_
)).Times(0);
4384 EXPECT_CALL(visitor
, OnPacketComplete());
4385 EXPECT_CALL(visitor
, OnUnauthenticatedPublicHeader(_
)).WillOnce(Return(true));
4386 EXPECT_CALL(visitor
, OnUnauthenticatedHeader(_
)).WillOnce(Return(true));
4387 EXPECT_CALL(visitor
, OnDecryptedPacket(_
));
4389 QuicEncryptedPacket
encrypted(AsChars(packet
), arraysize(packet
), false);
4390 EXPECT_TRUE(framer_
.ProcessPacket(encrypted
));
4391 EXPECT_EQ(QUIC_NO_ERROR
, framer_
.error());