MacViews: Get c/b/ui/views/tabs to build on Mac
[chromium-blink-merge.git] / net / quic / quic_framer_test.cc
blobb2dc6eb1202a3784d6e8c004bd7e437776d8f302
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"
7 #include <algorithm>
8 #include <map>
9 #include <string>
10 #include <vector>
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"
25 using base::hash_set;
26 using base::StringPiece;
27 using std::make_pair;
28 using std::map;
29 using std::numeric_limits;
30 using std::pair;
31 using std::string;
32 using std::vector;
33 using testing::Return;
34 using testing::_;
36 namespace net {
37 namespace test {
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) +
85 kPrivateFlagsSize;
88 size_t GetFecGroupOffset(bool include_version) {
89 return GetPrivateFlagsOffset(PACKET_8BYTE_CONNECTION_ID, include_version) +
90 kPrivateFlagsSize;
93 size_t GetFecGroupOffset(bool include_version,
94 QuicSequenceNumberLength sequence_number_length) {
95 return GetPrivateFlagsOffset(include_version, sequence_number_length) +
96 kPrivateFlagsSize;
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 {
105 public:
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";
114 return false;
116 QuicData* EncryptPacket(QuicPacketSequenceNumber sequence_number,
117 StringPiece associated_data,
118 StringPiece plaintext) override {
119 sequence_number_ = sequence_number;
120 associated_data_ = associated_data.as_string();
121 plaintext_ = plaintext.as_string();
122 return new QuicData(plaintext.data(), plaintext.length());
124 size_t GetKeySize() const override { return 0; }
125 size_t GetNoncePrefixSize() const override { return 0; }
126 size_t GetMaxPlaintextSize(size_t ciphertext_size) const override {
127 return ciphertext_size;
129 size_t GetCiphertextSize(size_t plaintext_size) const override {
130 return plaintext_size;
132 StringPiece GetKey() const override { return StringPiece(); }
133 StringPiece GetNoncePrefix() const override { return StringPiece(); }
134 QuicPacketSequenceNumber sequence_number_;
135 string associated_data_;
136 string plaintext_;
139 class TestDecrypter : public QuicDecrypter {
140 public:
141 ~TestDecrypter() override {}
142 bool SetKey(StringPiece key) override { return true; }
143 bool SetNoncePrefix(StringPiece nonce_prefix) override { return true; }
144 bool Decrypt(StringPiece nonce,
145 StringPiece associated_data,
146 StringPiece ciphertext,
147 unsigned char* output,
148 size_t* output_length) override {
149 CHECK(false) << "Not implemented";
150 return false;
152 QuicData* DecryptPacket(QuicPacketSequenceNumber sequence_number,
153 StringPiece associated_data,
154 StringPiece ciphertext) override {
155 sequence_number_ = sequence_number;
156 associated_data_ = associated_data.as_string();
157 ciphertext_ = ciphertext.as_string();
158 return new QuicData(ciphertext.data(), ciphertext.length());
160 StringPiece GetKey() const override { return StringPiece(); }
161 StringPiece GetNoncePrefix() const override { return StringPiece(); }
162 QuicPacketSequenceNumber sequence_number_;
163 string associated_data_;
164 string ciphertext_;
167 class TestQuicVisitor : public ::net::QuicFramerVisitorInterface {
168 public:
169 TestQuicVisitor()
170 : error_count_(0),
171 version_mismatch_(0),
172 packet_count_(0),
173 frame_count_(0),
174 fec_count_(0),
175 complete_packets_(0),
176 revived_packets_(0),
177 accept_packet_(true),
178 accept_public_header_(true) {
181 ~TestQuicVisitor() override {
182 STLDeleteElements(&stream_frames_);
183 STLDeleteElements(&ack_frames_);
184 STLDeleteElements(&congestion_feedback_frames_);
185 STLDeleteElements(&stop_waiting_frames_);
186 STLDeleteElements(&ping_frames_);
187 STLDeleteElements(&fec_data_);
190 void OnError(QuicFramer* f) override {
191 DVLOG(1) << "QuicFramer Error: " << QuicUtils::ErrorToString(f->error())
192 << " (" << f->error() << ")";
193 ++error_count_;
196 void OnPacket() override {}
198 void OnPublicResetPacket(const QuicPublicResetPacket& packet) override {
199 public_reset_packet_.reset(new QuicPublicResetPacket(packet));
202 void OnVersionNegotiationPacket(
203 const QuicVersionNegotiationPacket& packet) override {
204 version_negotiation_packet_.reset(new QuicVersionNegotiationPacket(packet));
207 void OnRevivedPacket() override { ++revived_packets_; }
209 bool OnProtocolVersionMismatch(QuicVersion version) override {
210 DVLOG(1) << "QuicFramer Version Mismatch, version: " << version;
211 ++version_mismatch_;
212 return true;
215 bool OnUnauthenticatedPublicHeader(
216 const QuicPacketPublicHeader& header) override {
217 public_header_.reset(new QuicPacketPublicHeader(header));
218 return accept_public_header_;
221 bool OnUnauthenticatedHeader(const QuicPacketHeader& header) override {
222 return true;
225 void OnDecryptedPacket(EncryptionLevel level) override {}
227 bool OnPacketHeader(const QuicPacketHeader& header) override {
228 ++packet_count_;
229 header_.reset(new QuicPacketHeader(header));
230 return accept_packet_;
233 bool OnStreamFrame(const QuicStreamFrame& frame) override {
234 ++frame_count_;
235 stream_frames_.push_back(new QuicStreamFrame(frame));
236 return true;
239 void OnFecProtectedPayload(StringPiece payload) override {
240 fec_protected_payload_ = payload.as_string();
243 bool OnAckFrame(const QuicAckFrame& frame) override {
244 ++frame_count_;
245 ack_frames_.push_back(new QuicAckFrame(frame));
246 return true;
249 bool OnCongestionFeedbackFrame(
250 const QuicCongestionFeedbackFrame& frame) override {
251 ++frame_count_;
252 congestion_feedback_frames_.push_back(
253 new QuicCongestionFeedbackFrame(frame));
254 return true;
257 bool OnStopWaitingFrame(const QuicStopWaitingFrame& frame) override {
258 ++frame_count_;
259 stop_waiting_frames_.push_back(new QuicStopWaitingFrame(frame));
260 return true;
263 bool OnPingFrame(const QuicPingFrame& frame) override {
264 ++frame_count_;
265 ping_frames_.push_back(new QuicPingFrame(frame));
266 return true;
269 void OnFecData(const QuicFecData& fec) override {
270 ++fec_count_;
271 fec_data_.push_back(new QuicFecData(fec));
274 void OnPacketComplete() override { ++complete_packets_; }
276 bool OnRstStreamFrame(const QuicRstStreamFrame& frame) override {
277 rst_stream_frame_ = frame;
278 return true;
281 bool OnConnectionCloseFrame(const QuicConnectionCloseFrame& frame) override {
282 connection_close_frame_ = frame;
283 return true;
286 bool OnGoAwayFrame(const QuicGoAwayFrame& frame) override {
287 goaway_frame_ = frame;
288 return true;
291 bool OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) override {
292 window_update_frame_ = frame;
293 return true;
296 bool OnBlockedFrame(const QuicBlockedFrame& frame) override {
297 blocked_frame_ = frame;
298 return true;
301 // Counters from the visitor_ callbacks.
302 int error_count_;
303 int version_mismatch_;
304 int packet_count_;
305 int frame_count_;
306 int fec_count_;
307 int complete_packets_;
308 int revived_packets_;
309 bool accept_packet_;
310 bool accept_public_header_;
312 scoped_ptr<QuicPacketHeader> header_;
313 scoped_ptr<QuicPacketPublicHeader> public_header_;
314 scoped_ptr<QuicPublicResetPacket> public_reset_packet_;
315 scoped_ptr<QuicVersionNegotiationPacket> version_negotiation_packet_;
316 vector<QuicStreamFrame*> stream_frames_;
317 vector<QuicAckFrame*> ack_frames_;
318 vector<QuicCongestionFeedbackFrame*> congestion_feedback_frames_;
319 vector<QuicStopWaitingFrame*> stop_waiting_frames_;
320 vector<QuicPingFrame*> ping_frames_;
321 vector<QuicFecData*> fec_data_;
322 string fec_protected_payload_;
323 QuicRstStreamFrame rst_stream_frame_;
324 QuicConnectionCloseFrame connection_close_frame_;
325 QuicGoAwayFrame goaway_frame_;
326 QuicWindowUpdateFrame window_update_frame_;
327 QuicBlockedFrame blocked_frame_;
330 class QuicFramerTest : public ::testing::TestWithParam<QuicVersion> {
331 public:
332 QuicFramerTest()
333 : encrypter_(new test::TestEncrypter()),
334 decrypter_(new test::TestDecrypter()),
335 start_(QuicTime::Zero().Add(QuicTime::Delta::FromMicroseconds(0x10))),
336 framer_(QuicSupportedVersions(), start_, true) {
337 version_ = GetParam();
338 framer_.set_version(version_);
339 framer_.SetDecrypter(decrypter_, ENCRYPTION_NONE);
340 framer_.SetEncrypter(ENCRYPTION_NONE, encrypter_);
341 framer_.set_visitor(&visitor_);
342 framer_.set_received_entropy_calculator(&entropy_calculator_);
345 // Helper function to get unsigned char representation of digit in the
346 // units place of the current QUIC version number.
347 unsigned char GetQuicVersionDigitOnes() {
348 return static_cast<unsigned char> ('0' + version_%10);
351 // Helper function to get unsigned char representation of digit in the
352 // tens place of the current QUIC version number.
353 unsigned char GetQuicVersionDigitTens() {
354 return static_cast<unsigned char> ('0' + (version_/10)%10);
357 bool CheckEncryption(QuicPacketSequenceNumber sequence_number,
358 QuicPacket* packet) {
359 if (sequence_number != encrypter_->sequence_number_) {
360 LOG(ERROR) << "Encrypted incorrect packet sequence number. expected "
361 << sequence_number << " actual: "
362 << encrypter_->sequence_number_;
363 return false;
365 if (packet->AssociatedData() != encrypter_->associated_data_) {
366 LOG(ERROR) << "Encrypted incorrect associated data. expected "
367 << packet->AssociatedData() << " actual: "
368 << encrypter_->associated_data_;
369 return false;
371 if (packet->Plaintext() != encrypter_->plaintext_) {
372 LOG(ERROR) << "Encrypted incorrect plaintext data. expected "
373 << packet->Plaintext() << " actual: "
374 << encrypter_->plaintext_;
375 return false;
377 return true;
380 bool CheckDecryption(const QuicEncryptedPacket& encrypted,
381 bool includes_version) {
382 if (visitor_.header_->packet_sequence_number !=
383 decrypter_->sequence_number_) {
384 LOG(ERROR) << "Decrypted incorrect packet sequence number. expected "
385 << visitor_.header_->packet_sequence_number << " actual: "
386 << decrypter_->sequence_number_;
387 return false;
389 if (QuicFramer::GetAssociatedDataFromEncryptedPacket(
390 encrypted, PACKET_8BYTE_CONNECTION_ID,
391 includes_version, PACKET_6BYTE_SEQUENCE_NUMBER) !=
392 decrypter_->associated_data_) {
393 LOG(ERROR) << "Decrypted incorrect associated data. expected "
394 << QuicFramer::GetAssociatedDataFromEncryptedPacket(
395 encrypted, PACKET_8BYTE_CONNECTION_ID,
396 includes_version, PACKET_6BYTE_SEQUENCE_NUMBER)
397 << " actual: " << decrypter_->associated_data_;
398 return false;
400 StringPiece ciphertext(encrypted.AsStringPiece().substr(
401 GetStartOfEncryptedData(PACKET_8BYTE_CONNECTION_ID, includes_version,
402 PACKET_6BYTE_SEQUENCE_NUMBER)));
403 if (ciphertext != decrypter_->ciphertext_) {
404 LOG(ERROR) << "Decrypted incorrect ciphertext data. expected "
405 << ciphertext << " actual: "
406 << decrypter_->ciphertext_;
407 return false;
409 return true;
412 char* AsChars(unsigned char* data) {
413 return reinterpret_cast<char*>(data);
416 void CheckProcessingFails(unsigned char* packet,
417 size_t len,
418 string expected_error,
419 QuicErrorCode error_code) {
420 QuicEncryptedPacket encrypted(AsChars(packet), len, false);
421 EXPECT_FALSE(framer_.ProcessPacket(encrypted)) << "len: " << len;
422 EXPECT_EQ(expected_error, framer_.detailed_error()) << "len: " << len;
423 EXPECT_EQ(error_code, framer_.error()) << "len: " << len;
426 // Checks if the supplied string matches data in the supplied StreamFrame.
427 void CheckStreamFrameData(string str, QuicStreamFrame* frame) {
428 scoped_ptr<string> frame_data(frame->GetDataAsString());
429 EXPECT_EQ(str, *frame_data);
432 void CheckStreamFrameBoundaries(unsigned char* packet,
433 size_t stream_id_size,
434 bool include_version) {
435 // Now test framing boundaries.
436 for (size_t i = kQuicFrameTypeSize; i < GetMinStreamFrameSize(); ++i) {
437 string expected_error;
438 if (i < kQuicFrameTypeSize + stream_id_size) {
439 expected_error = "Unable to read stream_id.";
440 } else if (i < kQuicFrameTypeSize + stream_id_size +
441 kQuicMaxStreamOffsetSize) {
442 expected_error = "Unable to read offset.";
443 } else {
444 expected_error = "Unable to read frame data.";
446 CheckProcessingFails(
447 packet,
448 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, include_version,
449 PACKET_6BYTE_SEQUENCE_NUMBER,
450 NOT_IN_FEC_GROUP),
451 expected_error, QUIC_INVALID_STREAM_DATA);
455 void CheckCalculatePacketSequenceNumber(
456 QuicPacketSequenceNumber expected_sequence_number,
457 QuicPacketSequenceNumber last_sequence_number) {
458 QuicPacketSequenceNumber wire_sequence_number =
459 expected_sequence_number & kMask;
460 QuicFramerPeer::SetLastSequenceNumber(&framer_, last_sequence_number);
461 EXPECT_EQ(expected_sequence_number,
462 QuicFramerPeer::CalculatePacketSequenceNumberFromWire(
463 &framer_, PACKET_6BYTE_SEQUENCE_NUMBER, wire_sequence_number))
464 << "last_sequence_number: " << last_sequence_number
465 << " wire_sequence_number: " << wire_sequence_number;
468 QuicPacket* BuildDataPacket(const QuicPacketHeader& header,
469 const QuicFrames& frames) {
470 return BuildUnsizedDataPacket(&framer_, header, frames).packet;
473 test::TestEncrypter* encrypter_;
474 test::TestDecrypter* decrypter_;
475 QuicVersion version_;
476 QuicTime start_;
477 QuicFramer framer_;
478 test::TestQuicVisitor visitor_;
479 test::TestEntropyCalculator entropy_calculator_;
482 // Run all framer tests with all supported versions of QUIC.
483 INSTANTIATE_TEST_CASE_P(QuicFramerTests,
484 QuicFramerTest,
485 ::testing::ValuesIn(kSupportedQuicVersions));
487 TEST_P(QuicFramerTest, CalculatePacketSequenceNumberFromWireNearEpochStart) {
488 // A few quick manual sanity checks
489 CheckCalculatePacketSequenceNumber(GG_UINT64_C(1), GG_UINT64_C(0));
490 CheckCalculatePacketSequenceNumber(kEpoch + 1, kMask);
491 CheckCalculatePacketSequenceNumber(kEpoch, kMask);
493 // Cases where the last number was close to the start of the range
494 for (uint64 last = 0; last < 10; last++) {
495 // Small numbers should not wrap (even if they're out of order).
496 for (uint64 j = 0; j < 10; j++) {
497 CheckCalculatePacketSequenceNumber(j, last);
500 // Large numbers should not wrap either (because we're near 0 already).
501 for (uint64 j = 0; j < 10; j++) {
502 CheckCalculatePacketSequenceNumber(kEpoch - 1 - j, last);
507 TEST_P(QuicFramerTest, CalculatePacketSequenceNumberFromWireNearEpochEnd) {
508 // Cases where the last number was close to the end of the range
509 for (uint64 i = 0; i < 10; i++) {
510 QuicPacketSequenceNumber last = kEpoch - i;
512 // Small numbers should wrap.
513 for (uint64 j = 0; j < 10; j++) {
514 CheckCalculatePacketSequenceNumber(kEpoch + j, last);
517 // Large numbers should not (even if they're out of order).
518 for (uint64 j = 0; j < 10; j++) {
519 CheckCalculatePacketSequenceNumber(kEpoch - 1 - j, last);
524 // Next check where we're in a non-zero epoch to verify we handle
525 // reverse wrapping, too.
526 TEST_P(QuicFramerTest, CalculatePacketSequenceNumberFromWireNearPrevEpoch) {
527 const uint64 prev_epoch = 1 * kEpoch;
528 const uint64 cur_epoch = 2 * kEpoch;
529 // Cases where the last number was close to the start of the range
530 for (uint64 i = 0; i < 10; i++) {
531 uint64 last = cur_epoch + i;
532 // Small number should not wrap (even if they're out of order).
533 for (uint64 j = 0; j < 10; j++) {
534 CheckCalculatePacketSequenceNumber(cur_epoch + j, last);
537 // But large numbers should reverse wrap.
538 for (uint64 j = 0; j < 10; j++) {
539 uint64 num = kEpoch - 1 - j;
540 CheckCalculatePacketSequenceNumber(prev_epoch + num, last);
545 TEST_P(QuicFramerTest, CalculatePacketSequenceNumberFromWireNearNextEpoch) {
546 const uint64 cur_epoch = 2 * kEpoch;
547 const uint64 next_epoch = 3 * kEpoch;
548 // Cases where the last number was close to the end of the range
549 for (uint64 i = 0; i < 10; i++) {
550 QuicPacketSequenceNumber last = next_epoch - 1 - i;
552 // Small numbers should wrap.
553 for (uint64 j = 0; j < 10; j++) {
554 CheckCalculatePacketSequenceNumber(next_epoch + j, last);
557 // but large numbers should not (even if they're out of order).
558 for (uint64 j = 0; j < 10; j++) {
559 uint64 num = kEpoch - 1 - j;
560 CheckCalculatePacketSequenceNumber(cur_epoch + num, last);
565 TEST_P(QuicFramerTest, CalculatePacketSequenceNumberFromWireNearNextMax) {
566 const uint64 max_number = numeric_limits<uint64>::max();
567 const uint64 max_epoch = max_number & ~kMask;
569 // Cases where the last number was close to the end of the range
570 for (uint64 i = 0; i < 10; i++) {
571 // Subtract 1, because the expected next sequence number is 1 more than the
572 // last sequence number.
573 QuicPacketSequenceNumber last = max_number - i - 1;
575 // Small numbers should not wrap, because they have nowhere to go.
576 for (uint64 j = 0; j < 10; j++) {
577 CheckCalculatePacketSequenceNumber(max_epoch + j, last);
580 // Large numbers should not wrap either.
581 for (uint64 j = 0; j < 10; j++) {
582 uint64 num = kEpoch - 1 - j;
583 CheckCalculatePacketSequenceNumber(max_epoch + num, last);
588 TEST_P(QuicFramerTest, EmptyPacket) {
589 char packet[] = { 0x00 };
590 QuicEncryptedPacket encrypted(packet, 0, false);
591 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
592 EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error());
595 TEST_P(QuicFramerTest, LargePacket) {
596 unsigned char packet[kMaxPacketSize + 1] = {
597 // public flags (8 byte connection_id)
598 0x3C,
599 // connection_id
600 0x10, 0x32, 0x54, 0x76,
601 0x98, 0xBA, 0xDC, 0xFE,
602 // packet sequence number
603 0xBC, 0x9A, 0x78, 0x56,
604 0x34, 0x12,
605 // private flags
606 0x00,
609 memset(packet + GetPacketHeaderSize(
610 PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
611 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), 0,
612 kMaxPacketSize - GetPacketHeaderSize(
613 PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
614 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP) + 1);
616 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
617 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
619 ASSERT_TRUE(visitor_.header_.get());
620 // Make sure we've parsed the packet header, so we can send an error.
621 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
622 visitor_.header_->public_header.connection_id);
623 // Make sure the correct error is propagated.
624 EXPECT_EQ(QUIC_PACKET_TOO_LARGE, framer_.error());
627 TEST_P(QuicFramerTest, PacketHeader) {
628 unsigned char packet[] = {
629 // public flags (8 byte connection_id)
630 0x3C,
631 // connection_id
632 0x10, 0x32, 0x54, 0x76,
633 0x98, 0xBA, 0xDC, 0xFE,
634 // packet sequence number
635 0xBC, 0x9A, 0x78, 0x56,
636 0x34, 0x12,
637 // private flags
638 0x00,
641 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
642 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
643 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
644 ASSERT_TRUE(visitor_.header_.get());
645 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
646 visitor_.header_->public_header.connection_id);
647 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
648 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
649 EXPECT_FALSE(visitor_.header_->fec_flag);
650 EXPECT_FALSE(visitor_.header_->entropy_flag);
651 EXPECT_EQ(0, visitor_.header_->entropy_hash);
652 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
653 visitor_.header_->packet_sequence_number);
654 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
655 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
657 // Now test framing boundaries.
658 for (size_t i = 0;
659 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
660 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP);
661 ++i) {
662 string expected_error;
663 if (i < kConnectionIdOffset) {
664 expected_error = "Unable to read public flags.";
665 } else if (i < GetSequenceNumberOffset(!kIncludeVersion)) {
666 expected_error = "Unable to read ConnectionId.";
667 } else if (i < GetPrivateFlagsOffset(!kIncludeVersion)) {
668 expected_error = "Unable to read sequence number.";
669 } else if (i < GetFecGroupOffset(!kIncludeVersion)) {
670 expected_error = "Unable to read private flags.";
671 } else {
672 expected_error = "Unable to read first fec protected packet offset.";
674 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER);
678 TEST_P(QuicFramerTest, PacketHeaderWith4ByteConnectionId) {
679 QuicFramerPeer::SetLastSerializedConnectionId(
680 &framer_, GG_UINT64_C(0xFEDCBA9876543210));
682 unsigned char packet[] = {
683 // public flags (4 byte connection_id)
684 0x38,
685 // connection_id
686 0x10, 0x32, 0x54, 0x76,
687 // packet sequence number
688 0xBC, 0x9A, 0x78, 0x56,
689 0x34, 0x12,
690 // private flags
691 0x00,
694 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
695 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
696 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
697 ASSERT_TRUE(visitor_.header_.get());
698 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
699 visitor_.header_->public_header.connection_id);
700 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
701 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
702 EXPECT_FALSE(visitor_.header_->fec_flag);
703 EXPECT_FALSE(visitor_.header_->entropy_flag);
704 EXPECT_EQ(0, visitor_.header_->entropy_hash);
705 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
706 visitor_.header_->packet_sequence_number);
707 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
708 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
710 // Now test framing boundaries.
711 for (size_t i = 0;
712 i < GetPacketHeaderSize(PACKET_4BYTE_CONNECTION_ID, !kIncludeVersion,
713 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP);
714 ++i) {
715 string expected_error;
716 if (i < kConnectionIdOffset) {
717 expected_error = "Unable to read public flags.";
718 } else if (i < GetSequenceNumberOffset(PACKET_4BYTE_CONNECTION_ID,
719 !kIncludeVersion)) {
720 expected_error = "Unable to read ConnectionId.";
721 } else if (i < GetPrivateFlagsOffset(PACKET_4BYTE_CONNECTION_ID,
722 !kIncludeVersion)) {
723 expected_error = "Unable to read sequence number.";
724 } else if (i < GetFecGroupOffset(PACKET_4BYTE_CONNECTION_ID,
725 !kIncludeVersion)) {
726 expected_error = "Unable to read private flags.";
727 } else {
728 expected_error = "Unable to read first fec protected packet offset.";
730 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER);
734 TEST_P(QuicFramerTest, PacketHeader1ByteConnectionId) {
735 QuicFramerPeer::SetLastSerializedConnectionId(
736 &framer_, GG_UINT64_C(0xFEDCBA9876543210));
738 unsigned char packet[] = {
739 // public flags (1 byte connection_id)
740 0x34,
741 // connection_id
742 0x10,
743 // packet sequence number
744 0xBC, 0x9A, 0x78, 0x56,
745 0x34, 0x12,
746 // private flags
747 0x00,
750 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
751 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
752 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
753 ASSERT_TRUE(visitor_.header_.get());
754 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
755 visitor_.header_->public_header.connection_id);
756 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
757 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
758 EXPECT_FALSE(visitor_.header_->fec_flag);
759 EXPECT_FALSE(visitor_.header_->entropy_flag);
760 EXPECT_EQ(0, visitor_.header_->entropy_hash);
761 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
762 visitor_.header_->packet_sequence_number);
763 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
764 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
766 // Now test framing boundaries.
767 for (size_t i = 0;
768 i < GetPacketHeaderSize(PACKET_1BYTE_CONNECTION_ID, !kIncludeVersion,
769 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP);
770 ++i) {
771 string expected_error;
772 if (i < kConnectionIdOffset) {
773 expected_error = "Unable to read public flags.";
774 } else if (i < GetSequenceNumberOffset(PACKET_1BYTE_CONNECTION_ID,
775 !kIncludeVersion)) {
776 expected_error = "Unable to read ConnectionId.";
777 } else if (i < GetPrivateFlagsOffset(PACKET_1BYTE_CONNECTION_ID,
778 !kIncludeVersion)) {
779 expected_error = "Unable to read sequence number.";
780 } else if (i < GetFecGroupOffset(PACKET_1BYTE_CONNECTION_ID,
781 !kIncludeVersion)) {
782 expected_error = "Unable to read private flags.";
783 } else {
784 expected_error = "Unable to read first fec protected packet offset.";
786 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER);
790 TEST_P(QuicFramerTest, PacketHeaderWith0ByteConnectionId) {
791 QuicFramerPeer::SetLastSerializedConnectionId(
792 &framer_, GG_UINT64_C(0xFEDCBA9876543210));
794 unsigned char packet[] = {
795 // public flags (0 byte connection_id)
796 0x30,
797 // connection_id
798 // packet sequence number
799 0xBC, 0x9A, 0x78, 0x56,
800 0x34, 0x12,
801 // private flags
802 0x00,
805 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
806 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
807 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
808 ASSERT_TRUE(visitor_.header_.get());
809 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
810 visitor_.header_->public_header.connection_id);
811 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
812 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
813 EXPECT_FALSE(visitor_.header_->fec_flag);
814 EXPECT_FALSE(visitor_.header_->entropy_flag);
815 EXPECT_EQ(0, visitor_.header_->entropy_hash);
816 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
817 visitor_.header_->packet_sequence_number);
818 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
819 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
821 // Now test framing boundaries.
822 for (size_t i = 0;
823 i < GetPacketHeaderSize(PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion,
824 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP);
825 ++i) {
826 string expected_error;
827 if (i < kConnectionIdOffset) {
828 expected_error = "Unable to read public flags.";
829 } else if (i < GetSequenceNumberOffset(PACKET_0BYTE_CONNECTION_ID,
830 !kIncludeVersion)) {
831 expected_error = "Unable to read ConnectionId.";
832 } else if (i < GetPrivateFlagsOffset(PACKET_0BYTE_CONNECTION_ID,
833 !kIncludeVersion)) {
834 expected_error = "Unable to read sequence number.";
835 } else if (i < GetFecGroupOffset(PACKET_0BYTE_CONNECTION_ID,
836 !kIncludeVersion)) {
837 expected_error = "Unable to read private flags.";
838 } else {
839 expected_error = "Unable to read first fec protected packet offset.";
841 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER);
845 TEST_P(QuicFramerTest, PacketHeaderWithVersionFlag) {
846 unsigned char packet[] = {
847 // public flags (version)
848 0x3D,
849 // connection_id
850 0x10, 0x32, 0x54, 0x76,
851 0x98, 0xBA, 0xDC, 0xFE,
852 // version tag
853 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
854 // packet sequence number
855 0xBC, 0x9A, 0x78, 0x56,
856 0x34, 0x12,
857 // private flags
858 0x00,
861 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
862 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
863 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
864 ASSERT_TRUE(visitor_.header_.get());
865 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
866 visitor_.header_->public_header.connection_id);
867 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
868 EXPECT_TRUE(visitor_.header_->public_header.version_flag);
869 EXPECT_EQ(GetParam(), visitor_.header_->public_header.versions[0]);
870 EXPECT_FALSE(visitor_.header_->fec_flag);
871 EXPECT_FALSE(visitor_.header_->entropy_flag);
872 EXPECT_EQ(0, visitor_.header_->entropy_hash);
873 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
874 visitor_.header_->packet_sequence_number);
875 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
876 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
878 // Now test framing boundaries.
879 for (size_t i = 0;
880 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, kIncludeVersion,
881 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP);
882 ++i) {
883 string expected_error;
884 if (i < kConnectionIdOffset) {
885 expected_error = "Unable to read public flags.";
886 } else if (i < kVersionOffset) {
887 expected_error = "Unable to read ConnectionId.";
888 } else if (i < GetSequenceNumberOffset(kIncludeVersion)) {
889 expected_error = "Unable to read protocol version.";
890 } else if (i < GetPrivateFlagsOffset(kIncludeVersion)) {
891 expected_error = "Unable to read sequence number.";
892 } else if (i < GetFecGroupOffset(kIncludeVersion)) {
893 expected_error = "Unable to read private flags.";
894 } else {
895 expected_error = "Unable to read first fec protected packet offset.";
897 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER);
901 TEST_P(QuicFramerTest, PacketHeaderWith4ByteSequenceNumber) {
902 QuicFramerPeer::SetLastSequenceNumber(&framer_,
903 GG_UINT64_C(0x123456789ABA));
905 unsigned char packet[] = {
906 // public flags (8 byte connection_id and 4 byte sequence number)
907 0x2C,
908 // connection_id
909 0x10, 0x32, 0x54, 0x76,
910 0x98, 0xBA, 0xDC, 0xFE,
911 // packet sequence number
912 0xBC, 0x9A, 0x78, 0x56,
913 // private flags
914 0x00,
917 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
918 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
919 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
920 ASSERT_TRUE(visitor_.header_.get());
921 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
922 visitor_.header_->public_header.connection_id);
923 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
924 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
925 EXPECT_FALSE(visitor_.header_->fec_flag);
926 EXPECT_FALSE(visitor_.header_->entropy_flag);
927 EXPECT_EQ(0, visitor_.header_->entropy_hash);
928 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
929 visitor_.header_->packet_sequence_number);
930 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
931 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
933 // Now test framing boundaries.
934 for (size_t i = 0;
935 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
936 PACKET_4BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP);
937 ++i) {
938 string expected_error;
939 if (i < kConnectionIdOffset) {
940 expected_error = "Unable to read public flags.";
941 } else if (i < GetSequenceNumberOffset(!kIncludeVersion)) {
942 expected_error = "Unable to read ConnectionId.";
943 } else if (i < GetPrivateFlagsOffset(!kIncludeVersion,
944 PACKET_4BYTE_SEQUENCE_NUMBER)) {
945 expected_error = "Unable to read sequence number.";
946 } else if (i < GetFecGroupOffset(!kIncludeVersion,
947 PACKET_4BYTE_SEQUENCE_NUMBER)) {
948 expected_error = "Unable to read private flags.";
949 } else {
950 expected_error = "Unable to read first fec protected packet offset.";
952 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER);
956 TEST_P(QuicFramerTest, PacketHeaderWith2ByteSequenceNumber) {
957 QuicFramerPeer::SetLastSequenceNumber(&framer_,
958 GG_UINT64_C(0x123456789ABA));
960 unsigned char packet[] = {
961 // public flags (8 byte connection_id and 2 byte sequence number)
962 0x1C,
963 // connection_id
964 0x10, 0x32, 0x54, 0x76,
965 0x98, 0xBA, 0xDC, 0xFE,
966 // packet sequence number
967 0xBC, 0x9A,
968 // private flags
969 0x00,
972 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
973 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
974 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
975 ASSERT_TRUE(visitor_.header_.get());
976 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
977 visitor_.header_->public_header.connection_id);
978 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
979 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
980 EXPECT_FALSE(visitor_.header_->fec_flag);
981 EXPECT_FALSE(visitor_.header_->entropy_flag);
982 EXPECT_EQ(0, visitor_.header_->entropy_hash);
983 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
984 visitor_.header_->packet_sequence_number);
985 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
986 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
988 // Now test framing boundaries.
989 for (size_t i = 0;
990 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
991 PACKET_2BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP);
992 ++i) {
993 string expected_error;
994 if (i < kConnectionIdOffset) {
995 expected_error = "Unable to read public flags.";
996 } else if (i < GetSequenceNumberOffset(!kIncludeVersion)) {
997 expected_error = "Unable to read ConnectionId.";
998 } else if (i < GetPrivateFlagsOffset(!kIncludeVersion,
999 PACKET_2BYTE_SEQUENCE_NUMBER)) {
1000 expected_error = "Unable to read sequence number.";
1001 } else if (i < GetFecGroupOffset(!kIncludeVersion,
1002 PACKET_2BYTE_SEQUENCE_NUMBER)) {
1003 expected_error = "Unable to read private flags.";
1004 } else {
1005 expected_error = "Unable to read first fec protected packet offset.";
1007 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER);
1011 TEST_P(QuicFramerTest, PacketHeaderWith1ByteSequenceNumber) {
1012 QuicFramerPeer::SetLastSequenceNumber(&framer_,
1013 GG_UINT64_C(0x123456789ABA));
1015 unsigned char packet[] = {
1016 // public flags (8 byte connection_id and 1 byte sequence number)
1017 0x0C,
1018 // connection_id
1019 0x10, 0x32, 0x54, 0x76,
1020 0x98, 0xBA, 0xDC, 0xFE,
1021 // packet sequence number
1022 0xBC,
1023 // private flags
1024 0x00,
1027 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1028 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
1029 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
1030 ASSERT_TRUE(visitor_.header_.get());
1031 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
1032 visitor_.header_->public_header.connection_id);
1033 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
1034 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
1035 EXPECT_FALSE(visitor_.header_->fec_flag);
1036 EXPECT_FALSE(visitor_.header_->entropy_flag);
1037 EXPECT_EQ(0, visitor_.header_->entropy_hash);
1038 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
1039 visitor_.header_->packet_sequence_number);
1040 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
1041 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
1043 // Now test framing boundaries.
1044 for (size_t i = 0;
1045 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
1046 PACKET_1BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP);
1047 ++i) {
1048 string expected_error;
1049 if (i < kConnectionIdOffset) {
1050 expected_error = "Unable to read public flags.";
1051 } else if (i < GetSequenceNumberOffset(!kIncludeVersion)) {
1052 expected_error = "Unable to read ConnectionId.";
1053 } else if (i < GetPrivateFlagsOffset(!kIncludeVersion,
1054 PACKET_1BYTE_SEQUENCE_NUMBER)) {
1055 expected_error = "Unable to read sequence number.";
1056 } else if (i < GetFecGroupOffset(!kIncludeVersion,
1057 PACKET_1BYTE_SEQUENCE_NUMBER)) {
1058 expected_error = "Unable to read private flags.";
1059 } else {
1060 expected_error = "Unable to read first fec protected packet offset.";
1062 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER);
1066 TEST_P(QuicFramerTest, InvalidPublicFlag) {
1067 unsigned char packet[] = {
1068 // public flags: all flags set but the public reset flag and version flag.
1069 0xFC,
1070 // connection_id
1071 0x10, 0x32, 0x54, 0x76,
1072 0x98, 0xBA, 0xDC, 0xFE,
1073 // packet sequence number
1074 0xBC, 0x9A, 0x78, 0x56,
1075 0x34, 0x12,
1076 // private flags
1077 0x00,
1079 // frame type (padding)
1080 0x00,
1081 0x00, 0x00, 0x00, 0x00
1083 CheckProcessingFails(packet,
1084 arraysize(packet),
1085 "Illegal public flags value.",
1086 QUIC_INVALID_PACKET_HEADER);
1088 // Now turn off validation.
1089 framer_.set_validate_flags(false);
1090 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1091 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1094 TEST_P(QuicFramerTest, InvalidPublicFlagWithMatchingVersions) {
1095 unsigned char packet[] = {
1096 // public flags (8 byte connection_id and version flag and an unknown flag)
1097 0x4D,
1098 // connection_id
1099 0x10, 0x32, 0x54, 0x76,
1100 0x98, 0xBA, 0xDC, 0xFE,
1101 // version tag
1102 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
1103 // packet sequence number
1104 0xBC, 0x9A, 0x78, 0x56,
1105 0x34, 0x12,
1106 // private flags
1107 0x00,
1109 // frame type (padding)
1110 0x00,
1111 0x00, 0x00, 0x00, 0x00
1113 CheckProcessingFails(packet,
1114 arraysize(packet),
1115 "Illegal public flags value.",
1116 QUIC_INVALID_PACKET_HEADER);
1119 TEST_P(QuicFramerTest, LargePublicFlagWithMismatchedVersions) {
1120 unsigned char packet[] = {
1121 // public flags (8 byte connection_id, version flag and an unknown flag)
1122 0x7D,
1123 // connection_id
1124 0x10, 0x32, 0x54, 0x76,
1125 0x98, 0xBA, 0xDC, 0xFE,
1126 // version tag
1127 'Q', '0', '0', '0',
1128 // packet sequence number
1129 0xBC, 0x9A, 0x78, 0x56,
1130 0x34, 0x12,
1131 // private flags
1132 0x00,
1134 // frame type (padding frame)
1135 0x00,
1136 0x00, 0x00, 0x00, 0x00
1138 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1139 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1140 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1141 ASSERT_TRUE(visitor_.header_.get());
1142 EXPECT_EQ(0, visitor_.frame_count_);
1143 EXPECT_EQ(1, visitor_.version_mismatch_);
1146 TEST_P(QuicFramerTest, InvalidPrivateFlag) {
1147 unsigned char packet[] = {
1148 // public flags (8 byte connection_id)
1149 0x3C,
1150 // connection_id
1151 0x10, 0x32, 0x54, 0x76,
1152 0x98, 0xBA, 0xDC, 0xFE,
1153 // packet sequence number
1154 0xBC, 0x9A, 0x78, 0x56,
1155 0x34, 0x12,
1156 // private flags
1157 0x10,
1159 // frame type (padding)
1160 0x00,
1161 0x00, 0x00, 0x00, 0x00
1163 CheckProcessingFails(packet,
1164 arraysize(packet),
1165 "Illegal private flags value.",
1166 QUIC_INVALID_PACKET_HEADER);
1169 TEST_P(QuicFramerTest, InvalidFECGroupOffset) {
1170 unsigned char packet[] = {
1171 // public flags (8 byte connection_id)
1172 0x3C,
1173 // connection_id
1174 0x10, 0x32, 0x54, 0x76,
1175 0x98, 0xBA, 0xDC, 0xFE,
1176 // packet sequence number
1177 0x01, 0x00, 0x00, 0x00,
1178 0x00, 0x00,
1179 // private flags (fec group)
1180 0x02,
1181 // first fec protected packet offset
1182 0x10
1184 CheckProcessingFails(packet,
1185 arraysize(packet),
1186 "First fec protected packet offset must be less "
1187 "than the sequence number.",
1188 QUIC_INVALID_PACKET_HEADER);
1191 TEST_P(QuicFramerTest, PaddingFrame) {
1192 unsigned char packet[] = {
1193 // public flags (8 byte connection_id)
1194 0x3C,
1195 // connection_id
1196 0x10, 0x32, 0x54, 0x76,
1197 0x98, 0xBA, 0xDC, 0xFE,
1198 // packet sequence number
1199 0xBC, 0x9A, 0x78, 0x56,
1200 0x34, 0x12,
1201 // private flags
1202 0x00,
1204 // frame type (padding frame)
1205 0x00,
1206 // Ignored data (which in this case is a stream frame)
1207 // frame type (stream frame with fin)
1208 0xFF,
1209 // stream id
1210 0x04, 0x03, 0x02, 0x01,
1211 // offset
1212 0x54, 0x76, 0x10, 0x32,
1213 0xDC, 0xFE, 0x98, 0xBA,
1214 // data length
1215 0x0c, 0x00,
1216 // data
1217 'h', 'e', 'l', 'l',
1218 'o', ' ', 'w', 'o',
1219 'r', 'l', 'd', '!',
1222 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1223 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1224 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1225 ASSERT_TRUE(visitor_.header_.get());
1226 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1228 ASSERT_EQ(0u, visitor_.stream_frames_.size());
1229 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1230 // A packet with no frames is not acceptable.
1231 CheckProcessingFails(
1232 packet,
1233 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
1234 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP),
1235 "Packet has no frames.", QUIC_MISSING_PAYLOAD);
1238 TEST_P(QuicFramerTest, StreamFrame) {
1239 unsigned char packet[] = {
1240 // public flags (8 byte connection_id)
1241 0x3C,
1242 // connection_id
1243 0x10, 0x32, 0x54, 0x76,
1244 0x98, 0xBA, 0xDC, 0xFE,
1245 // packet sequence number
1246 0xBC, 0x9A, 0x78, 0x56,
1247 0x34, 0x12,
1248 // private flags
1249 0x00,
1251 // frame type (stream frame with fin)
1252 0xFF,
1253 // stream id
1254 0x04, 0x03, 0x02, 0x01,
1255 // offset
1256 0x54, 0x76, 0x10, 0x32,
1257 0xDC, 0xFE, 0x98, 0xBA,
1258 // data length
1259 0x0c, 0x00,
1260 // data
1261 'h', 'e', 'l', 'l',
1262 'o', ' ', 'w', 'o',
1263 'r', 'l', 'd', '!',
1266 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1267 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1269 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1270 ASSERT_TRUE(visitor_.header_.get());
1271 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1273 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1274 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1275 EXPECT_EQ(static_cast<uint64>(0x01020304),
1276 visitor_.stream_frames_[0]->stream_id);
1277 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1278 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1279 visitor_.stream_frames_[0]->offset);
1280 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]);
1282 // Now test framing boundaries.
1283 CheckStreamFrameBoundaries(packet, kQuicMaxStreamIdSize, !kIncludeVersion);
1286 TEST_P(QuicFramerTest, StreamFrame3ByteStreamId) {
1287 unsigned char packet[] = {
1288 // public flags (8 byte connection_id)
1289 0x3C,
1290 // connection_id
1291 0x10, 0x32, 0x54, 0x76,
1292 0x98, 0xBA, 0xDC, 0xFE,
1293 // packet sequence number
1294 0xBC, 0x9A, 0x78, 0x56,
1295 0x34, 0x12,
1296 // private flags
1297 0x00,
1299 // frame type (stream frame with fin)
1300 0xFE,
1301 // stream id
1302 0x04, 0x03, 0x02,
1303 // offset
1304 0x54, 0x76, 0x10, 0x32,
1305 0xDC, 0xFE, 0x98, 0xBA,
1306 // data length
1307 0x0c, 0x00,
1308 // data
1309 'h', 'e', 'l', 'l',
1310 'o', ' ', 'w', 'o',
1311 'r', 'l', 'd', '!',
1314 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1315 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1317 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1318 ASSERT_TRUE(visitor_.header_.get());
1319 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1321 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1322 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1323 EXPECT_EQ(GG_UINT64_C(0x00020304),
1324 visitor_.stream_frames_[0]->stream_id);
1325 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1326 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1327 visitor_.stream_frames_[0]->offset);
1328 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]);
1330 // Now test framing boundaries.
1331 const size_t stream_id_size = 3;
1332 CheckStreamFrameBoundaries(packet, stream_id_size, !kIncludeVersion);
1335 TEST_P(QuicFramerTest, StreamFrame2ByteStreamId) {
1336 unsigned char packet[] = {
1337 // public flags (8 byte connection_id)
1338 0x3C,
1339 // connection_id
1340 0x10, 0x32, 0x54, 0x76,
1341 0x98, 0xBA, 0xDC, 0xFE,
1342 // packet sequence number
1343 0xBC, 0x9A, 0x78, 0x56,
1344 0x34, 0x12,
1345 // private flags
1346 0x00,
1348 // frame type (stream frame with fin)
1349 0xFD,
1350 // stream id
1351 0x04, 0x03,
1352 // offset
1353 0x54, 0x76, 0x10, 0x32,
1354 0xDC, 0xFE, 0x98, 0xBA,
1355 // data length
1356 0x0c, 0x00,
1357 // data
1358 'h', 'e', 'l', 'l',
1359 'o', ' ', 'w', 'o',
1360 'r', 'l', 'd', '!',
1363 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1364 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1366 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1367 ASSERT_TRUE(visitor_.header_.get());
1368 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1370 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1371 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1372 EXPECT_EQ(static_cast<uint64>(0x00000304),
1373 visitor_.stream_frames_[0]->stream_id);
1374 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1375 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1376 visitor_.stream_frames_[0]->offset);
1377 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]);
1379 // Now test framing boundaries.
1380 const size_t stream_id_size = 2;
1381 CheckStreamFrameBoundaries(packet, stream_id_size, !kIncludeVersion);
1384 TEST_P(QuicFramerTest, StreamFrame1ByteStreamId) {
1385 unsigned char packet[] = {
1386 // public flags (8 byte connection_id)
1387 0x3C,
1388 // connection_id
1389 0x10, 0x32, 0x54, 0x76,
1390 0x98, 0xBA, 0xDC, 0xFE,
1391 // packet sequence number
1392 0xBC, 0x9A, 0x78, 0x56,
1393 0x34, 0x12,
1394 // private flags
1395 0x00,
1397 // frame type (stream frame with fin)
1398 0xFC,
1399 // stream id
1400 0x04,
1401 // offset
1402 0x54, 0x76, 0x10, 0x32,
1403 0xDC, 0xFE, 0x98, 0xBA,
1404 // data length
1405 0x0c, 0x00,
1406 // data
1407 'h', 'e', 'l', 'l',
1408 'o', ' ', 'w', 'o',
1409 'r', 'l', 'd', '!',
1412 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1413 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1415 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1416 ASSERT_TRUE(visitor_.header_.get());
1417 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1419 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1420 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1421 EXPECT_EQ(static_cast<uint64>(0x00000004),
1422 visitor_.stream_frames_[0]->stream_id);
1423 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1424 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1425 visitor_.stream_frames_[0]->offset);
1426 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]);
1428 // Now test framing boundaries.
1429 const size_t stream_id_size = 1;
1430 CheckStreamFrameBoundaries(packet, stream_id_size, !kIncludeVersion);
1433 TEST_P(QuicFramerTest, StreamFrameWithVersion) {
1434 unsigned char packet[] = {
1435 // public flags (version, 8 byte connection_id)
1436 0x3D,
1437 // connection_id
1438 0x10, 0x32, 0x54, 0x76,
1439 0x98, 0xBA, 0xDC, 0xFE,
1440 // version tag
1441 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
1442 // packet sequence number
1443 0xBC, 0x9A, 0x78, 0x56,
1444 0x34, 0x12,
1445 // private flags
1446 0x00,
1448 // frame type (stream frame with fin)
1449 0xFF,
1450 // stream id
1451 0x04, 0x03, 0x02, 0x01,
1452 // offset
1453 0x54, 0x76, 0x10, 0x32,
1454 0xDC, 0xFE, 0x98, 0xBA,
1455 // data length
1456 0x0c, 0x00,
1457 // data
1458 'h', 'e', 'l', 'l',
1459 'o', ' ', 'w', 'o',
1460 'r', 'l', 'd', '!',
1463 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1464 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1466 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1467 ASSERT_TRUE(visitor_.header_.get());
1468 EXPECT_TRUE(visitor_.header_->public_header.version_flag);
1469 EXPECT_EQ(GetParam(), visitor_.header_->public_header.versions[0]);
1470 EXPECT_TRUE(CheckDecryption(encrypted, kIncludeVersion));
1472 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1473 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1474 EXPECT_EQ(static_cast<uint64>(0x01020304),
1475 visitor_.stream_frames_[0]->stream_id);
1476 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1477 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1478 visitor_.stream_frames_[0]->offset);
1479 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]);
1481 // Now test framing boundaries.
1482 CheckStreamFrameBoundaries(packet, kQuicMaxStreamIdSize, kIncludeVersion);
1485 TEST_P(QuicFramerTest, RejectPacket) {
1486 visitor_.accept_packet_ = false;
1488 unsigned char packet[] = {
1489 // public flags (8 byte connection_id)
1490 0x3C,
1491 // connection_id
1492 0x10, 0x32, 0x54, 0x76,
1493 0x98, 0xBA, 0xDC, 0xFE,
1494 // packet sequence number
1495 0xBC, 0x9A, 0x78, 0x56,
1496 0x34, 0x12,
1497 // private flags
1498 0x00,
1500 // frame type (stream frame with fin)
1501 0xFF,
1502 // stream id
1503 0x04, 0x03, 0x02, 0x01,
1504 // offset
1505 0x54, 0x76, 0x10, 0x32,
1506 0xDC, 0xFE, 0x98, 0xBA,
1507 // data length
1508 0x0c, 0x00,
1509 // data
1510 'h', 'e', 'l', 'l',
1511 'o', ' ', 'w', 'o',
1512 'r', 'l', 'd', '!',
1515 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1516 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1518 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1519 ASSERT_TRUE(visitor_.header_.get());
1520 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1522 ASSERT_EQ(0u, visitor_.stream_frames_.size());
1523 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1526 TEST_P(QuicFramerTest, RejectPublicHeader) {
1527 visitor_.accept_public_header_ = false;
1529 unsigned char packet[] = {
1530 // public flags (8 byte connection_id)
1531 0x3C,
1532 // connection_id
1533 0x10, 0x32, 0x54, 0x76,
1534 0x98, 0xBA, 0xDC, 0xFE,
1537 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1538 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1540 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1541 ASSERT_TRUE(visitor_.public_header_.get());
1542 ASSERT_FALSE(visitor_.header_.get());
1545 TEST_P(QuicFramerTest, RevivedStreamFrame) {
1546 unsigned char payload[] = {
1547 // frame type (stream frame with fin)
1548 0xFF,
1549 // stream id
1550 0x04, 0x03, 0x02, 0x01,
1551 // offset
1552 0x54, 0x76, 0x10, 0x32,
1553 0xDC, 0xFE, 0x98, 0xBA,
1554 // data length
1555 0x0c, 0x00,
1556 // data
1557 'h', 'e', 'l', 'l',
1558 'o', ' ', 'w', 'o',
1559 'r', 'l', 'd', '!',
1562 QuicPacketHeader header;
1563 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
1564 header.public_header.reset_flag = false;
1565 header.public_header.version_flag = false;
1566 header.fec_flag = true;
1567 header.entropy_flag = true;
1568 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
1569 header.fec_group = 0;
1571 // Do not encrypt the payload because the revived payload is post-encryption.
1572 EXPECT_TRUE(framer_.ProcessRevivedPacket(&header,
1573 StringPiece(AsChars(payload),
1574 arraysize(payload))));
1576 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1577 ASSERT_EQ(1, visitor_.revived_packets_);
1578 ASSERT_TRUE(visitor_.header_.get());
1579 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
1580 visitor_.header_->public_header.connection_id);
1581 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
1582 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
1583 EXPECT_TRUE(visitor_.header_->fec_flag);
1584 EXPECT_TRUE(visitor_.header_->entropy_flag);
1585 EXPECT_EQ(1 << (header.packet_sequence_number % 8),
1586 visitor_.header_->entropy_hash);
1587 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
1588 visitor_.header_->packet_sequence_number);
1589 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
1590 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
1592 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1593 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1594 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_.stream_frames_[0]->stream_id);
1595 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1596 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1597 visitor_.stream_frames_[0]->offset);
1598 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]);
1601 TEST_P(QuicFramerTest, StreamFrameInFecGroup) {
1602 unsigned char packet[] = {
1603 // public flags (8 byte connection_id)
1604 0x3C,
1605 // connection_id
1606 0x10, 0x32, 0x54, 0x76,
1607 0x98, 0xBA, 0xDC, 0xFE,
1608 // packet sequence number
1609 0xBC, 0x9A, 0x78, 0x56,
1610 0x12, 0x34,
1611 // private flags (fec group)
1612 0x02,
1613 // first fec protected packet offset
1614 0x02,
1616 // frame type (stream frame with fin)
1617 0xFF,
1618 // stream id
1619 0x04, 0x03, 0x02, 0x01,
1620 // offset
1621 0x54, 0x76, 0x10, 0x32,
1622 0xDC, 0xFE, 0x98, 0xBA,
1623 // data length
1624 0x0c, 0x00,
1625 // data
1626 'h', 'e', 'l', 'l',
1627 'o', ' ', 'w', 'o',
1628 'r', 'l', 'd', '!',
1631 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1632 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1634 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1635 ASSERT_TRUE(visitor_.header_.get());
1636 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1637 EXPECT_EQ(IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
1638 EXPECT_EQ(GG_UINT64_C(0x341256789ABA),
1639 visitor_.header_->fec_group);
1640 const size_t fec_offset =
1641 GetStartOfFecProtectedData(PACKET_8BYTE_CONNECTION_ID,
1642 !kIncludeVersion,
1643 PACKET_6BYTE_SEQUENCE_NUMBER);
1644 EXPECT_EQ(
1645 string(AsChars(packet) + fec_offset, arraysize(packet) - fec_offset),
1646 visitor_.fec_protected_payload_);
1648 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1649 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1650 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_.stream_frames_[0]->stream_id);
1651 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1652 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1653 visitor_.stream_frames_[0]->offset);
1654 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]);
1657 TEST_P(QuicFramerTest, AckFramev22) {
1658 if (version_ > QUIC_VERSION_22) {
1659 return;
1661 unsigned char packet[] = {
1662 // public flags (8 byte connection_id)
1663 0x3C,
1664 // connection_id
1665 0x10, 0x32, 0x54, 0x76,
1666 0x98, 0xBA, 0xDC, 0xFE,
1667 // packet sequence number
1668 0xA8, 0x9A, 0x78, 0x56,
1669 0x34, 0x12,
1670 // private flags (entropy)
1671 0x01,
1673 // frame type (ack frame)
1674 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
1675 0x6C,
1676 // entropy hash of all received packets.
1677 0xBA,
1678 // largest observed packet sequence number
1679 0xBF, 0x9A, 0x78, 0x56,
1680 0x34, 0x12,
1681 // Zero delta time.
1682 0x0, 0x0,
1683 // num missing packets
1684 0x01,
1685 // missing packet delta
1686 0x01,
1687 // 0 more missing packets in range.
1688 0x00,
1689 // Number of revived packets.
1690 0x00,
1693 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1694 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1696 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1697 ASSERT_TRUE(visitor_.header_.get());
1698 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1700 EXPECT_EQ(0u, visitor_.stream_frames_.size());
1701 ASSERT_EQ(1u, visitor_.ack_frames_.size());
1702 const QuicAckFrame& frame = *visitor_.ack_frames_[0];
1703 EXPECT_EQ(0xBA, frame.entropy_hash);
1704 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame.largest_observed);
1705 ASSERT_EQ(1u, frame.missing_packets.size());
1706 SequenceNumberSet::const_iterator missing_iter =
1707 frame.missing_packets.begin();
1708 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter);
1710 const size_t kReceivedEntropyOffset = kQuicFrameTypeSize;
1711 const size_t kLargestObservedOffset = kReceivedEntropyOffset +
1712 kQuicEntropyHashSize;
1713 const size_t kMissingDeltaTimeOffset = kLargestObservedOffset +
1714 PACKET_6BYTE_SEQUENCE_NUMBER;
1715 const size_t kNumMissingPacketOffset = kMissingDeltaTimeOffset +
1716 kQuicDeltaTimeLargestObservedSize;
1717 const size_t kMissingPacketsOffset = kNumMissingPacketOffset +
1718 kNumberOfNackRangesSize;
1719 const size_t kMissingPacketsRange = kMissingPacketsOffset +
1720 PACKET_1BYTE_SEQUENCE_NUMBER;
1721 const size_t kRevivedPacketsLength = kMissingPacketsRange +
1722 PACKET_1BYTE_SEQUENCE_NUMBER;
1723 // Now test framing boundaries.
1724 const size_t ack_frame_size = kRevivedPacketsLength +
1725 PACKET_1BYTE_SEQUENCE_NUMBER;
1726 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) {
1727 string expected_error;
1728 if (i < kLargestObservedOffset) {
1729 expected_error = "Unable to read entropy hash for received packets.";
1730 } else if (i < kMissingDeltaTimeOffset) {
1731 expected_error = "Unable to read largest observed.";
1732 } else if (i < kNumMissingPacketOffset) {
1733 expected_error = "Unable to read delta time largest observed.";
1734 } else if (i < kMissingPacketsOffset) {
1735 expected_error = "Unable to read num missing packet ranges.";
1736 } else if (i < kMissingPacketsRange) {
1737 expected_error = "Unable to read missing sequence number delta.";
1738 } else if (i < kRevivedPacketsLength) {
1739 expected_error = "Unable to read missing sequence number range.";
1740 } else {
1741 expected_error = "Unable to read num revived packets.";
1743 CheckProcessingFails(
1744 packet,
1745 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
1746 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP),
1747 expected_error, QUIC_INVALID_ACK_DATA);
1752 TEST_P(QuicFramerTest, AckFrameTwoTimestamp) {
1753 if (version_ <= QUIC_VERSION_22) {
1754 return;
1756 unsigned char packet[] = {
1757 // public flags (8 byte connection_id)
1758 0x3C,
1759 // connection_id
1760 0x10, 0x32, 0x54, 0x76,
1761 0x98, 0xBA, 0xDC, 0xFE,
1762 // packet sequence number
1763 0xA8, 0x9A, 0x78, 0x56,
1764 0x34, 0x12,
1765 // private flags (entropy)
1766 0x01,
1768 // frame type (ack frame)
1769 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
1770 0x6C,
1771 // entropy hash of all received packets.
1772 0xBA,
1773 // largest observed packet sequence number
1774 0xBF, 0x9A, 0x78, 0x56,
1775 0x34, 0x12,
1776 // Zero delta time.
1777 0x0, 0x0,
1778 // Number of timestamps.
1779 0x02,
1780 // Delta from largest observed.
1781 0x01,
1782 // Delta time.
1783 0x10, 0x32, 0x54, 0x76,
1784 // Delta from largest observed.
1785 0x02,
1786 // Delta time.
1787 0x10, 0x32,
1788 // num missing packets
1789 0x01,
1790 // missing packet delta
1791 0x01,
1792 // 0 more missing packets in range.
1793 0x00,
1794 // Number of revived packets.
1795 0x00,
1798 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1799 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1801 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1802 ASSERT_TRUE(visitor_.header_.get());
1803 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1805 EXPECT_EQ(0u, visitor_.stream_frames_.size());
1806 ASSERT_EQ(1u, visitor_.ack_frames_.size());
1807 const QuicAckFrame& frame = *visitor_.ack_frames_[0];
1808 EXPECT_EQ(0xBA, frame.entropy_hash);
1809 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame.largest_observed);
1810 ASSERT_EQ(1u, frame.missing_packets.size());
1811 ASSERT_EQ(2u, frame.received_packet_times.size());
1812 SequenceNumberSet::const_iterator missing_iter =
1813 frame.missing_packets.begin();
1814 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter);
1816 const size_t kReceivedEntropyOffset = kQuicFrameTypeSize;
1817 const size_t kLargestObservedOffset = kReceivedEntropyOffset +
1818 kQuicEntropyHashSize;
1819 const size_t kMissingDeltaTimeOffset = kLargestObservedOffset +
1820 PACKET_6BYTE_SEQUENCE_NUMBER;
1821 const size_t kNumTimestampsOffset = kMissingDeltaTimeOffset +
1822 kQuicDeltaTimeLargestObservedSize;
1823 const size_t kTimestampDeltaLargestObserved1 = kNumTimestampsOffset +
1824 kQuicNumTimestampsSize;
1825 const size_t kTimestampTimeDeltaLargestObserved1 =
1826 kTimestampDeltaLargestObserved1 + 1;
1827 const size_t kTimestampDeltaLargestObserved2 =
1828 kTimestampTimeDeltaLargestObserved1 + 4;
1829 const size_t kTimestampTimeDeltaLargestObserved2 =
1830 kTimestampDeltaLargestObserved2 + 1;
1831 const size_t kNumMissingPacketOffset =
1832 kTimestampTimeDeltaLargestObserved2 + 2;
1833 const size_t kMissingPacketsOffset = kNumMissingPacketOffset +
1834 kNumberOfNackRangesSize;
1835 const size_t kMissingPacketsRange = kMissingPacketsOffset +
1836 PACKET_1BYTE_SEQUENCE_NUMBER;
1837 const size_t kRevivedPacketsLength = kMissingPacketsRange +
1838 PACKET_1BYTE_SEQUENCE_NUMBER;
1839 // Now test framing boundaries.
1840 const size_t ack_frame_size = kRevivedPacketsLength +
1841 PACKET_1BYTE_SEQUENCE_NUMBER;
1842 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) {
1843 string expected_error;
1844 if (i < kLargestObservedOffset) {
1845 expected_error = "Unable to read entropy hash for received packets.";
1846 } else if (i < kMissingDeltaTimeOffset) {
1847 expected_error = "Unable to read largest observed.";
1848 } else if (i < kNumTimestampsOffset) {
1849 expected_error = "Unable to read delta time largest observed.";
1850 } else if (i < kTimestampDeltaLargestObserved1) {
1851 expected_error = "Unable to read num received packets.";
1852 } else if (i < kTimestampTimeDeltaLargestObserved1) {
1853 expected_error = "Unable to read sequence delta in received packets.";
1854 } else if (i < kTimestampDeltaLargestObserved2) {
1855 expected_error = "Unable to read time delta in received packets.";
1856 } else if (i < kTimestampTimeDeltaLargestObserved2) {
1857 expected_error = "Unable to read sequence delta in received packets.";
1858 } else if (i < kNumMissingPacketOffset) {
1859 expected_error =
1860 "Unable to read incremental time delta in received packets.";
1861 } else if (i < kMissingPacketsOffset) {
1862 expected_error = "Unable to read num missing packet ranges.";
1863 } else if (i < kMissingPacketsRange) {
1864 expected_error = "Unable to read missing sequence number delta.";
1865 } else if (i < kRevivedPacketsLength) {
1866 expected_error = "Unable to read missing sequence number range.";
1867 } else {
1868 expected_error = "Unable to read num revived packets.";
1870 CheckProcessingFails(
1871 packet,
1872 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
1873 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP),
1874 expected_error, QUIC_INVALID_ACK_DATA);
1879 TEST_P(QuicFramerTest, AckFrameOneTimestamp) {
1880 if (version_ <= QUIC_VERSION_22) {
1881 return;
1883 unsigned char packet[] = {
1884 // public flags (8 byte connection_id)
1885 0x3C,
1886 // connection_id
1887 0x10, 0x32, 0x54, 0x76,
1888 0x98, 0xBA, 0xDC, 0xFE,
1889 // packet sequence number
1890 0xA8, 0x9A, 0x78, 0x56,
1891 0x34, 0x12,
1892 // private flags (entropy)
1893 0x01,
1895 // frame type (ack frame)
1896 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
1897 0x6C,
1898 // entropy hash of all received packets.
1899 0xBA,
1900 // largest observed packet sequence number
1901 0xBF, 0x9A, 0x78, 0x56,
1902 0x34, 0x12,
1903 // Zero delta time.
1904 0x0, 0x0,
1905 // Number of timestamps.
1906 0x01,
1907 // Delta from largest observed.
1908 0x01,
1909 // Delta time.
1910 0x10, 0x32, 0x54, 0x76,
1911 // num missing packets
1912 0x01,
1913 // missing packet delta
1914 0x01,
1915 // 0 more missing packets in range.
1916 0x00,
1917 // Number of revived packets.
1918 0x00,
1921 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1922 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1924 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1925 ASSERT_TRUE(visitor_.header_.get());
1926 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1928 EXPECT_EQ(0u, visitor_.stream_frames_.size());
1929 ASSERT_EQ(1u, visitor_.ack_frames_.size());
1930 const QuicAckFrame& frame = *visitor_.ack_frames_[0];
1931 EXPECT_EQ(0xBA, frame.entropy_hash);
1932 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame.largest_observed);
1933 ASSERT_EQ(1u, frame.missing_packets.size());
1934 ASSERT_EQ(1u, frame.received_packet_times.size());
1935 SequenceNumberSet::const_iterator missing_iter =
1936 frame.missing_packets.begin();
1937 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter);
1939 const size_t kReceivedEntropyOffset = kQuicFrameTypeSize;
1940 const size_t kLargestObservedOffset = kReceivedEntropyOffset +
1941 kQuicEntropyHashSize;
1942 const size_t kMissingDeltaTimeOffset = kLargestObservedOffset +
1943 PACKET_6BYTE_SEQUENCE_NUMBER;
1944 const size_t kNumTimestampsOffset = kMissingDeltaTimeOffset +
1945 kQuicDeltaTimeLargestObservedSize;
1946 const size_t kTimestampDeltaLargestObserved = kNumTimestampsOffset +
1947 kQuicNumTimestampsSize;
1948 const size_t kTimestampTimeDeltaLargestObserved =
1949 kTimestampDeltaLargestObserved + 1;
1950 const size_t kNumMissingPacketOffset = kTimestampTimeDeltaLargestObserved + 4;
1951 const size_t kMissingPacketsOffset = kNumMissingPacketOffset +
1952 kNumberOfNackRangesSize;
1953 const size_t kMissingPacketsRange = kMissingPacketsOffset +
1954 PACKET_1BYTE_SEQUENCE_NUMBER;
1955 const size_t kRevivedPacketsLength = kMissingPacketsRange +
1956 PACKET_1BYTE_SEQUENCE_NUMBER;
1957 // Now test framing boundaries.
1958 const size_t ack_frame_size = kRevivedPacketsLength +
1959 PACKET_1BYTE_SEQUENCE_NUMBER;
1960 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) {
1961 string expected_error;
1962 if (i < kLargestObservedOffset) {
1963 expected_error = "Unable to read entropy hash for received packets.";
1964 } else if (i < kMissingDeltaTimeOffset) {
1965 expected_error = "Unable to read largest observed.";
1966 } else if (i < kNumTimestampsOffset) {
1967 expected_error = "Unable to read delta time largest observed.";
1968 } else if (i < kTimestampDeltaLargestObserved) {
1969 expected_error = "Unable to read num received packets.";
1970 } else if (i < kTimestampTimeDeltaLargestObserved) {
1971 expected_error = "Unable to read sequence delta in received packets.";
1972 } else if (i < kNumMissingPacketOffset) {
1973 expected_error = "Unable to read time delta in received packets.";
1974 } else if (i < kMissingPacketsOffset) {
1975 expected_error = "Unable to read num missing packet ranges.";
1976 } else if (i < kMissingPacketsRange) {
1977 expected_error = "Unable to read missing sequence number delta.";
1978 } else if (i < kRevivedPacketsLength) {
1979 expected_error = "Unable to read missing sequence number range.";
1980 } else {
1981 expected_error = "Unable to read num revived packets.";
1983 CheckProcessingFails(
1984 packet,
1985 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
1986 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP),
1987 expected_error, QUIC_INVALID_ACK_DATA);
1992 TEST_P(QuicFramerTest, AckFrame) {
1993 if (version_ <= QUIC_VERSION_22) {
1994 return;
1996 unsigned char packet[] = {
1997 // public flags (8 byte connection_id)
1998 0x3C,
1999 // connection_id
2000 0x10, 0x32, 0x54, 0x76,
2001 0x98, 0xBA, 0xDC, 0xFE,
2002 // packet sequence number
2003 0xA8, 0x9A, 0x78, 0x56,
2004 0x34, 0x12,
2005 // private flags (entropy)
2006 0x01,
2008 // frame type (ack frame)
2009 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
2010 0x6C,
2011 // entropy hash of all received packets.
2012 0xBA,
2013 // largest observed packet sequence number
2014 0xBF, 0x9A, 0x78, 0x56,
2015 0x34, 0x12,
2016 // Zero delta time.
2017 0x0, 0x0,
2018 // Number of timestamps.
2019 0x00,
2020 // num missing packets
2021 0x01,
2022 // missing packet delta
2023 0x01,
2024 // 0 more missing packets in range.
2025 0x00,
2026 // Number of revived packets.
2027 0x00,
2030 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2031 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2033 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2034 ASSERT_TRUE(visitor_.header_.get());
2035 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2037 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2038 ASSERT_EQ(1u, visitor_.ack_frames_.size());
2039 const QuicAckFrame& frame = *visitor_.ack_frames_[0];
2040 EXPECT_EQ(0xBA, frame.entropy_hash);
2041 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame.largest_observed);
2042 ASSERT_EQ(1u, frame.missing_packets.size());
2043 SequenceNumberSet::const_iterator missing_iter =
2044 frame.missing_packets.begin();
2045 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter);
2047 const size_t kReceivedEntropyOffset = kQuicFrameTypeSize;
2048 const size_t kLargestObservedOffset = kReceivedEntropyOffset +
2049 kQuicEntropyHashSize;
2050 const size_t kMissingDeltaTimeOffset = kLargestObservedOffset +
2051 PACKET_6BYTE_SEQUENCE_NUMBER;
2052 const size_t kNumTimestampsOffset = kMissingDeltaTimeOffset +
2053 kQuicDeltaTimeLargestObservedSize;
2054 const size_t kNumMissingPacketOffset = kNumTimestampsOffset +
2055 kQuicNumTimestampsSize;
2056 const size_t kMissingPacketsOffset = kNumMissingPacketOffset +
2057 kNumberOfNackRangesSize;
2058 const size_t kMissingPacketsRange = kMissingPacketsOffset +
2059 PACKET_1BYTE_SEQUENCE_NUMBER;
2060 const size_t kRevivedPacketsLength = kMissingPacketsRange +
2061 PACKET_1BYTE_SEQUENCE_NUMBER;
2062 // Now test framing boundaries.
2063 const size_t ack_frame_size = kRevivedPacketsLength +
2064 PACKET_1BYTE_SEQUENCE_NUMBER;
2065 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) {
2066 string expected_error;
2067 if (i < kLargestObservedOffset) {
2068 expected_error = "Unable to read entropy hash for received packets.";
2069 } else if (i < kMissingDeltaTimeOffset) {
2070 expected_error = "Unable to read largest observed.";
2071 } else if (i < kNumTimestampsOffset) {
2072 expected_error = "Unable to read delta time largest observed.";
2073 } else if (i < kNumMissingPacketOffset) {
2074 expected_error = "Unable to read num received packets.";
2075 } else if (i < kMissingPacketsOffset) {
2076 expected_error = "Unable to read num missing packet ranges.";
2077 } else if (i < kMissingPacketsRange) {
2078 expected_error = "Unable to read missing sequence number delta.";
2079 } else if (i < kRevivedPacketsLength) {
2080 expected_error = "Unable to read missing sequence number range.";
2081 } else {
2082 expected_error = "Unable to read num revived packets.";
2084 CheckProcessingFails(
2085 packet,
2086 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
2087 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP),
2088 expected_error, QUIC_INVALID_ACK_DATA);
2092 TEST_P(QuicFramerTest, AckFrameRevivedPackets) {
2093 if (version_ <= QUIC_VERSION_22) {
2094 return;
2096 unsigned char packet[] = {
2097 // public flags (8 byte connection_id)
2098 0x3C,
2099 // connection_id
2100 0x10, 0x32, 0x54, 0x76,
2101 0x98, 0xBA, 0xDC, 0xFE,
2102 // packet sequence number
2103 0xA8, 0x9A, 0x78, 0x56,
2104 0x34, 0x12,
2105 // private flags (entropy)
2106 0x01,
2108 // frame type (ack frame)
2109 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
2110 0x6C,
2111 // entropy hash of all received packets.
2112 0xBA,
2113 // largest observed packet sequence number
2114 0xBF, 0x9A, 0x78, 0x56,
2115 0x34, 0x12,
2116 // Zero delta time.
2117 0x0, 0x0,
2118 // num received packets.
2119 0x00,
2120 // num missing packets
2121 0x01,
2122 // missing packet delta
2123 0x01,
2124 // 0 more missing packets in range.
2125 0x00,
2126 // Number of revived packets.
2127 0x01,
2128 // Revived packet sequence number.
2129 0xBE, 0x9A, 0x78, 0x56,
2130 0x34, 0x12,
2131 // Number of revived packets.
2132 0x00,
2135 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2136 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2138 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2139 ASSERT_TRUE(visitor_.header_.get());
2140 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2142 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2143 ASSERT_EQ(1u, visitor_.ack_frames_.size());
2144 const QuicAckFrame& frame = *visitor_.ack_frames_[0];
2145 EXPECT_EQ(0xBA, frame.entropy_hash);
2146 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame.largest_observed);
2147 ASSERT_EQ(1u, frame.missing_packets.size());
2148 SequenceNumberSet::const_iterator missing_iter =
2149 frame.missing_packets.begin();
2150 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter);
2152 const size_t kReceivedEntropyOffset = kQuicFrameTypeSize;
2153 const size_t kLargestObservedOffset = kReceivedEntropyOffset +
2154 kQuicEntropyHashSize;
2155 const size_t kMissingDeltaTimeOffset = kLargestObservedOffset +
2156 PACKET_6BYTE_SEQUENCE_NUMBER;
2157 const size_t kNumTimestampsOffset = kMissingDeltaTimeOffset +
2158 kQuicDeltaTimeLargestObservedSize;
2159 const size_t kNumMissingPacketOffset = kNumTimestampsOffset +
2160 kQuicNumTimestampsSize;
2161 const size_t kMissingPacketsOffset = kNumMissingPacketOffset +
2162 kNumberOfNackRangesSize;
2163 const size_t kMissingPacketsRange = kMissingPacketsOffset +
2164 PACKET_1BYTE_SEQUENCE_NUMBER;
2165 const size_t kRevivedPacketsLength = kMissingPacketsRange +
2166 PACKET_1BYTE_SEQUENCE_NUMBER;
2167 const size_t kRevivedPacketSequenceNumberLength = kRevivedPacketsLength +
2168 PACKET_1BYTE_SEQUENCE_NUMBER;
2169 // Now test framing boundaries.
2170 const size_t ack_frame_size = kRevivedPacketSequenceNumberLength +
2171 PACKET_6BYTE_SEQUENCE_NUMBER;
2172 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) {
2173 string expected_error;
2174 if (i < kReceivedEntropyOffset) {
2175 expected_error = "Unable to read least unacked delta.";
2176 } else if (i < kLargestObservedOffset) {
2177 expected_error = "Unable to read entropy hash for received packets.";
2178 } else if (i < kMissingDeltaTimeOffset) {
2179 expected_error = "Unable to read largest observed.";
2180 } else if (i < kNumTimestampsOffset) {
2181 expected_error = "Unable to read delta time largest observed.";
2182 } else if (i < kNumMissingPacketOffset) {
2183 expected_error = "Unable to read num received packets.";
2184 } else if (i < kMissingPacketsOffset) {
2185 expected_error = "Unable to read num missing packet ranges.";
2186 } else if (i < kMissingPacketsRange) {
2187 expected_error = "Unable to read missing sequence number delta.";
2188 } else if (i < kRevivedPacketsLength) {
2189 expected_error = "Unable to read missing sequence number range.";
2190 } else if (i < kRevivedPacketSequenceNumberLength) {
2191 expected_error = "Unable to read num revived packets.";
2192 } else {
2193 expected_error = "Unable to read revived packet.";
2195 CheckProcessingFails(
2196 packet,
2197 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
2198 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP),
2199 expected_error, QUIC_INVALID_ACK_DATA);
2203 TEST_P(QuicFramerTest, AckFrameRevivedPacketsv22) {
2204 if (version_ > QUIC_VERSION_22) {
2205 return;
2207 unsigned char packet[] = {
2208 // public flags (8 byte connection_id)
2209 0x3C,
2210 // connection_id
2211 0x10, 0x32, 0x54, 0x76,
2212 0x98, 0xBA, 0xDC, 0xFE,
2213 // packet sequence number
2214 0xA8, 0x9A, 0x78, 0x56,
2215 0x34, 0x12,
2216 // private flags (entropy)
2217 0x01,
2219 // frame type (ack frame)
2220 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
2221 0x6C,
2222 // entropy hash of all received packets.
2223 0xBA,
2224 // largest observed packet sequence number
2225 0xBF, 0x9A, 0x78, 0x56,
2226 0x34, 0x12,
2227 // Zero delta time.
2228 0x0, 0x0,
2229 // num missing packets
2230 0x01,
2231 // missing packet delta
2232 0x01,
2233 // 0 more missing packets in range.
2234 0x00,
2235 // Number of revived packets.
2236 0x01,
2237 // Revived packet sequence number.
2238 0xBE, 0x9A, 0x78, 0x56,
2239 0x34, 0x12,
2240 // Number of revived packets.
2241 0x00,
2244 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2245 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2247 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2248 ASSERT_TRUE(visitor_.header_.get());
2249 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2251 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2252 ASSERT_EQ(1u, visitor_.ack_frames_.size());
2253 const QuicAckFrame& frame = *visitor_.ack_frames_[0];
2254 EXPECT_EQ(0xBA, frame.entropy_hash);
2255 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame.largest_observed);
2256 ASSERT_EQ(1u, frame.missing_packets.size());
2257 SequenceNumberSet::const_iterator missing_iter =
2258 frame.missing_packets.begin();
2259 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter);
2261 const size_t kReceivedEntropyOffset = kQuicFrameTypeSize;
2262 const size_t kLargestObservedOffset = kReceivedEntropyOffset +
2263 kQuicEntropyHashSize;
2264 const size_t kMissingDeltaTimeOffset = kLargestObservedOffset +
2265 PACKET_6BYTE_SEQUENCE_NUMBER;
2266 const size_t kNumMissingPacketOffset = kMissingDeltaTimeOffset +
2267 kQuicDeltaTimeLargestObservedSize;
2268 const size_t kMissingPacketsOffset = kNumMissingPacketOffset +
2269 kNumberOfNackRangesSize;
2270 const size_t kMissingPacketsRange = kMissingPacketsOffset +
2271 PACKET_1BYTE_SEQUENCE_NUMBER;
2272 const size_t kRevivedPacketsLength = kMissingPacketsRange +
2273 PACKET_1BYTE_SEQUENCE_NUMBER;
2274 const size_t kRevivedPacketSequenceNumberLength = kRevivedPacketsLength +
2275 PACKET_1BYTE_SEQUENCE_NUMBER;
2276 // Now test framing boundaries.
2277 const size_t ack_frame_size = kRevivedPacketSequenceNumberLength +
2278 PACKET_6BYTE_SEQUENCE_NUMBER;
2279 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) {
2280 string expected_error;
2281 if (i < kReceivedEntropyOffset) {
2282 expected_error = "Unable to read least unacked delta.";
2283 } else if (i < kLargestObservedOffset) {
2284 expected_error = "Unable to read entropy hash for received packets.";
2285 } else if (i < kMissingDeltaTimeOffset) {
2286 expected_error = "Unable to read largest observed.";
2287 } else if (i < kNumMissingPacketOffset) {
2288 expected_error = "Unable to read delta time largest observed.";
2289 } else if (i < kMissingPacketsOffset) {
2290 expected_error = "Unable to read num missing packet ranges.";
2291 } else if (i < kMissingPacketsRange) {
2292 expected_error = "Unable to read missing sequence number delta.";
2293 } else if (i < kRevivedPacketsLength) {
2294 expected_error = "Unable to read missing sequence number range.";
2295 } else if (i < kRevivedPacketSequenceNumberLength) {
2296 expected_error = "Unable to read num revived packets.";
2297 } else {
2298 expected_error = "Unable to read revived packet.";
2300 CheckProcessingFails(
2301 packet,
2302 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
2303 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP),
2304 expected_error, QUIC_INVALID_ACK_DATA);
2308 TEST_P(QuicFramerTest, AckFrameNoNacksv22) {
2309 if (version_ > QUIC_VERSION_22) {
2310 return;
2312 unsigned char packet[] = {
2313 // public flags (8 byte connection_id)
2314 0x3C,
2315 // connection_id
2316 0x10, 0x32, 0x54, 0x76,
2317 0x98, 0xBA, 0xDC, 0xFE,
2318 // packet sequence number
2319 0xA8, 0x9A, 0x78, 0x56,
2320 0x34, 0x12,
2321 // private flags (entropy)
2322 0x01,
2324 // frame type (ack frame)
2325 // (no nacks, not truncated, 6 byte largest observed, 1 byte delta)
2326 0x4C,
2327 // entropy hash of all received packets.
2328 0xBA,
2329 // largest observed packet sequence number
2330 0xBF, 0x9A, 0x78, 0x56,
2331 0x34, 0x12,
2332 // Zero delta time.
2333 0x0, 0x0,
2336 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2337 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2339 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2340 ASSERT_TRUE(visitor_.header_.get());
2341 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2343 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2344 ASSERT_EQ(1u, visitor_.ack_frames_.size());
2345 QuicAckFrame* frame = visitor_.ack_frames_[0];
2346 EXPECT_EQ(0xBA, frame->entropy_hash);
2347 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame->largest_observed);
2348 ASSERT_EQ(0u, frame->missing_packets.size());
2350 // Verify that the packet re-serializes identically.
2351 QuicFrames frames;
2352 frames.push_back(QuicFrame(frame));
2353 scoped_ptr<QuicPacket> data(BuildDataPacket(*visitor_.header_, frames));
2354 ASSERT_TRUE(data != nullptr);
2356 test::CompareCharArraysWithHexError("constructed packet",
2357 data->data(), data->length(),
2358 AsChars(packet), arraysize(packet));
2361 TEST_P(QuicFramerTest, AckFrameNoNacks) {
2362 if (version_ <= QUIC_VERSION_22) {
2363 return;
2365 unsigned char packet[] = {
2366 // public flags (8 byte connection_id)
2367 0x3C,
2368 // connection_id
2369 0x10, 0x32, 0x54, 0x76,
2370 0x98, 0xBA, 0xDC, 0xFE,
2371 // packet sequence number
2372 0xA8, 0x9A, 0x78, 0x56,
2373 0x34, 0x12,
2374 // private flags (entropy)
2375 0x01,
2377 // frame type (ack frame)
2378 // (no nacks, not truncated, 6 byte largest observed, 1 byte delta)
2379 0x4C,
2380 // entropy hash of all received packets.
2381 0xBA,
2382 // largest observed packet sequence number
2383 0xBF, 0x9A, 0x78, 0x56,
2384 0x34, 0x12,
2385 // Zero delta time.
2386 0x0, 0x0,
2387 // Number of received packets.
2388 0x00,
2391 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2392 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2394 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2395 ASSERT_TRUE(visitor_.header_.get());
2396 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2398 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2399 ASSERT_EQ(1u, visitor_.ack_frames_.size());
2400 QuicAckFrame* frame = visitor_.ack_frames_[0];
2401 EXPECT_EQ(0xBA, frame->entropy_hash);
2402 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame->largest_observed);
2403 ASSERT_EQ(0u, frame->missing_packets.size());
2405 // Verify that the packet re-serializes identically.
2406 QuicFrames frames;
2407 frames.push_back(QuicFrame(frame));
2408 scoped_ptr<QuicPacket> data(BuildDataPacket(*visitor_.header_, frames));
2409 ASSERT_TRUE(data != nullptr);
2411 test::CompareCharArraysWithHexError("constructed packet",
2412 data->data(), data->length(),
2413 AsChars(packet), arraysize(packet));
2416 TEST_P(QuicFramerTest, AckFrame500Nacksv22) {
2417 if (version_ > QUIC_VERSION_22) {
2418 return;
2420 unsigned char packet[] = {
2421 // public flags (8 byte connection_id)
2422 0x3C,
2423 // connection_id
2424 0x10, 0x32, 0x54, 0x76,
2425 0x98, 0xBA, 0xDC, 0xFE,
2426 // packet sequence number
2427 0xA8, 0x9A, 0x78, 0x56,
2428 0x34, 0x12,
2429 // private flags (entropy)
2430 0x01,
2432 // frame type (ack frame)
2433 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
2434 0x6C,
2435 // entropy hash of all received packets.
2436 0xBA,
2437 // largest observed packet sequence number
2438 0xBF, 0x9A, 0x78, 0x56,
2439 0x34, 0x12,
2440 // Zero delta time.
2441 0x0, 0x0,
2442 // num missing packet ranges
2443 0x02,
2444 // missing packet delta
2445 0x01,
2446 // 243 more missing packets in range.
2447 // The ranges are listed in this order so the re-constructed packet matches.
2448 0xF3,
2449 // No gap between ranges
2450 0x00,
2451 // 255 more missing packets in range.
2452 0xFF,
2453 // No revived packets.
2454 0x00,
2457 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2458 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2460 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2461 ASSERT_TRUE(visitor_.header_.get());
2462 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2464 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2465 ASSERT_EQ(1u, visitor_.ack_frames_.size());
2466 QuicAckFrame* frame = visitor_.ack_frames_[0];
2467 EXPECT_EQ(0xBA, frame->entropy_hash);
2468 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame->largest_observed);
2469 EXPECT_EQ(0u, frame->revived_packets.size());
2470 ASSERT_EQ(500u, frame->missing_packets.size());
2471 SequenceNumberSet::const_iterator first_missing_iter =
2472 frame->missing_packets.begin();
2473 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE) - 499, *first_missing_iter);
2474 SequenceNumberSet::const_reverse_iterator last_missing_iter =
2475 frame->missing_packets.rbegin();
2476 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *last_missing_iter);
2478 // Verify that the packet re-serializes identically.
2479 QuicFrames frames;
2480 frames.push_back(QuicFrame(frame));
2481 scoped_ptr<QuicPacket> data(BuildDataPacket(*visitor_.header_, frames));
2482 ASSERT_TRUE(data != nullptr);
2484 test::CompareCharArraysWithHexError("constructed packet",
2485 data->data(), data->length(),
2486 AsChars(packet), arraysize(packet));
2489 TEST_P(QuicFramerTest, AckFrame500Nacks) {
2490 if (version_ <= QUIC_VERSION_22) {
2491 return;
2493 unsigned char packet[] = {
2494 // public flags (8 byte connection_id)
2495 0x3C,
2496 // connection_id
2497 0x10, 0x32, 0x54, 0x76,
2498 0x98, 0xBA, 0xDC, 0xFE,
2499 // packet sequence number
2500 0xA8, 0x9A, 0x78, 0x56,
2501 0x34, 0x12,
2502 // private flags (entropy)
2503 0x01,
2505 // frame type (ack frame)
2506 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
2507 0x6C,
2508 // entropy hash of all received packets.
2509 0xBA,
2510 // largest observed packet sequence number
2511 0xBF, 0x9A, 0x78, 0x56,
2512 0x34, 0x12,
2513 // Zero delta time.
2514 0x0, 0x0,
2515 // No received packets.
2516 0x00,
2517 // num missing packet ranges
2518 0x02,
2519 // missing packet delta
2520 0x01,
2521 // 243 more missing packets in range.
2522 // The ranges are listed in this order so the re-constructed packet matches.
2523 0xF3,
2524 // No gap between ranges
2525 0x00,
2526 // 255 more missing packets in range.
2527 0xFF,
2528 // No revived packets.
2529 0x00,
2532 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2533 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2535 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2536 ASSERT_TRUE(visitor_.header_.get());
2537 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2539 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2540 ASSERT_EQ(1u, visitor_.ack_frames_.size());
2541 QuicAckFrame* frame = visitor_.ack_frames_[0];
2542 EXPECT_EQ(0xBA, frame->entropy_hash);
2543 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame->largest_observed);
2544 EXPECT_EQ(0u, frame->revived_packets.size());
2545 ASSERT_EQ(500u, frame->missing_packets.size());
2546 SequenceNumberSet::const_iterator first_missing_iter =
2547 frame->missing_packets.begin();
2548 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE) - 499, *first_missing_iter);
2549 SequenceNumberSet::const_reverse_iterator last_missing_iter =
2550 frame->missing_packets.rbegin();
2551 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *last_missing_iter);
2553 // Verify that the packet re-serializes identically.
2554 QuicFrames frames;
2555 frames.push_back(QuicFrame(frame));
2556 scoped_ptr<QuicPacket> data(BuildDataPacket(*visitor_.header_, frames));
2557 ASSERT_TRUE(data != nullptr);
2559 test::CompareCharArraysWithHexError("constructed packet",
2560 data->data(), data->length(),
2561 AsChars(packet), arraysize(packet));
2564 TEST_P(QuicFramerTest, CongestionFeedbackFrameTCP) {
2565 unsigned char packet[] = {
2566 // public flags (8 byte connection_id)
2567 0x3C,
2568 // connection_id
2569 0x10, 0x32, 0x54, 0x76,
2570 0x98, 0xBA, 0xDC, 0xFE,
2571 // packet sequence number
2572 0xBC, 0x9A, 0x78, 0x56,
2573 0x34, 0x12,
2574 // private flags
2575 0x00,
2577 // frame type (congestion feedback frame)
2578 0x20,
2579 // congestion feedback type (tcp)
2580 0x00,
2581 // ack_frame.feedback.tcp.receive_window
2582 0x03, 0x04,
2585 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2586 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2588 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2589 ASSERT_TRUE(visitor_.header_.get());
2590 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2592 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2593 ASSERT_EQ(1u, visitor_.congestion_feedback_frames_.size());
2594 const QuicCongestionFeedbackFrame& frame =
2595 *visitor_.congestion_feedback_frames_[0];
2596 ASSERT_EQ(kTCP, frame.type);
2597 EXPECT_EQ(0x4030u, frame.tcp.receive_window);
2599 // Now test framing boundaries.
2600 for (size_t i = kQuicFrameTypeSize; i < 4; ++i) {
2601 string expected_error;
2602 if (i < 2) {
2603 expected_error = "Unable to read congestion feedback type.";
2604 } else if (i < 4) {
2605 expected_error = "Unable to read receive window.";
2607 CheckProcessingFails(
2608 packet,
2609 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
2610 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP),
2611 expected_error, QUIC_INVALID_CONGESTION_FEEDBACK_DATA);
2615 TEST_P(QuicFramerTest, CongestionFeedbackFrameInvalidFeedback) {
2616 unsigned char packet[] = {
2617 // public flags (8 byte connection_id)
2618 0x3C,
2619 // connection_id
2620 0x10, 0x32, 0x54, 0x76,
2621 0x98, 0xBA, 0xDC, 0xFE,
2622 // packet sequence number
2623 0xBC, 0x9A, 0x78, 0x56,
2624 0x34, 0x12,
2625 // private flags
2626 0x00,
2628 // frame type (congestion feedback frame)
2629 0x20,
2630 // congestion feedback type (invalid)
2631 0x03,
2634 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2635 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
2636 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2637 EXPECT_EQ(QUIC_INVALID_CONGESTION_FEEDBACK_DATA, framer_.error());
2640 TEST_P(QuicFramerTest, StopWaitingFrame) {
2641 unsigned char packet[] = {
2642 // public flags (8 byte connection_id)
2643 0x3C,
2644 // connection_id
2645 0x10, 0x32, 0x54, 0x76,
2646 0x98, 0xBA, 0xDC, 0xFE,
2647 // packet sequence number
2648 0xA8, 0x9A, 0x78, 0x56,
2649 0x34, 0x12,
2650 // private flags (entropy)
2651 0x01,
2653 // frame type (ack frame)
2654 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
2655 0x06,
2656 // entropy hash of sent packets till least awaiting - 1.
2657 0xAB,
2658 // least packet sequence number awaiting an ack, delta from sequence number.
2659 0x08, 0x00, 0x00, 0x00,
2660 0x00, 0x00,
2663 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2664 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2666 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2667 ASSERT_TRUE(visitor_.header_.get());
2668 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2670 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2671 ASSERT_EQ(1u, visitor_.stop_waiting_frames_.size());
2672 const QuicStopWaitingFrame& frame = *visitor_.stop_waiting_frames_[0];
2673 EXPECT_EQ(0xAB, frame.entropy_hash);
2674 EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame.least_unacked);
2676 const size_t kSentEntropyOffset = kQuicFrameTypeSize;
2677 const size_t kLeastUnackedOffset = kSentEntropyOffset + kQuicEntropyHashSize;
2678 const size_t frame_size = 7;
2679 for (size_t i = kQuicFrameTypeSize; i < frame_size; ++i) {
2680 string expected_error;
2681 if (i < kLeastUnackedOffset) {
2682 expected_error = "Unable to read entropy hash for sent packets.";
2683 } else {
2684 expected_error = "Unable to read least unacked delta.";
2686 CheckProcessingFails(
2687 packet,
2688 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
2689 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP),
2690 expected_error, QUIC_INVALID_STOP_WAITING_DATA);
2694 TEST_P(QuicFramerTest, RstStreamFrameQuic) {
2695 unsigned char packet[] = {
2696 // public flags (8 byte connection_id)
2697 0x3C,
2698 // connection_id
2699 0x10, 0x32, 0x54, 0x76,
2700 0x98, 0xBA, 0xDC, 0xFE,
2701 // packet sequence number
2702 0xBC, 0x9A, 0x78, 0x56,
2703 0x34, 0x12,
2704 // private flags
2705 0x00,
2707 // frame type (rst stream frame)
2708 0x01,
2709 // stream id
2710 0x04, 0x03, 0x02, 0x01,
2712 // sent byte offset
2713 0x01, 0x02, 0x03, 0x04,
2714 0x05, 0x06, 0x07, 0x08,
2716 // error code
2717 0x01, 0x00, 0x00, 0x00,
2719 // error details length
2720 0x0d, 0x00,
2721 // error details
2722 'b', 'e', 'c', 'a',
2723 'u', 's', 'e', ' ',
2724 'I', ' ', 'c', 'a',
2725 'n',
2728 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2729 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2731 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2732 ASSERT_TRUE(visitor_.header_.get());
2733 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2735 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_.rst_stream_frame_.stream_id);
2736 EXPECT_EQ(0x01, visitor_.rst_stream_frame_.error_code);
2737 EXPECT_EQ("because I can", visitor_.rst_stream_frame_.error_details);
2738 EXPECT_EQ(GG_UINT64_C(0x0807060504030201),
2739 visitor_.rst_stream_frame_.byte_offset);
2741 // Now test framing boundaries.
2742 for (size_t i = kQuicFrameTypeSize;
2743 i < QuicFramer::GetMinRstStreamFrameSize(); ++i) {
2744 string expected_error;
2745 if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize) {
2746 expected_error = "Unable to read stream_id.";
2747 } else if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize +
2748 + kQuicMaxStreamOffsetSize) {
2749 expected_error = "Unable to read rst stream sent byte offset.";
2750 } else if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize +
2751 + kQuicMaxStreamOffsetSize + kQuicErrorCodeSize) {
2752 expected_error = "Unable to read rst stream error code.";
2753 } else {
2754 expected_error = "Unable to read rst stream error details.";
2756 CheckProcessingFails(
2757 packet,
2758 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
2759 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP),
2760 expected_error, QUIC_INVALID_RST_STREAM_DATA);
2764 TEST_P(QuicFramerTest, ConnectionCloseFrame) {
2765 unsigned char packet[] = {
2766 // public flags (8 byte connection_id)
2767 0x3C,
2768 // connection_id
2769 0x10, 0x32, 0x54, 0x76,
2770 0x98, 0xBA, 0xDC, 0xFE,
2771 // packet sequence number
2772 0xBC, 0x9A, 0x78, 0x56,
2773 0x34, 0x12,
2774 // private flags
2775 0x00,
2777 // frame type (connection close frame)
2778 0x02,
2779 // error code
2780 0x11, 0x00, 0x00, 0x00,
2782 // error details length
2783 0x0d, 0x00,
2784 // error details
2785 'b', 'e', 'c', 'a',
2786 'u', 's', 'e', ' ',
2787 'I', ' ', 'c', 'a',
2788 'n',
2791 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2792 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2794 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2795 ASSERT_TRUE(visitor_.header_.get());
2796 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2798 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2800 EXPECT_EQ(0x11, visitor_.connection_close_frame_.error_code);
2801 EXPECT_EQ("because I can", visitor_.connection_close_frame_.error_details);
2803 ASSERT_EQ(0u, visitor_.ack_frames_.size());
2805 // Now test framing boundaries.
2806 for (size_t i = kQuicFrameTypeSize;
2807 i < QuicFramer::GetMinConnectionCloseFrameSize(); ++i) {
2808 string expected_error;
2809 if (i < kQuicFrameTypeSize + kQuicErrorCodeSize) {
2810 expected_error = "Unable to read connection close error code.";
2811 } else {
2812 expected_error = "Unable to read connection close error details.";
2814 CheckProcessingFails(
2815 packet,
2816 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
2817 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP),
2818 expected_error, QUIC_INVALID_CONNECTION_CLOSE_DATA);
2822 TEST_P(QuicFramerTest, GoAwayFrame) {
2823 unsigned char packet[] = {
2824 // public flags (8 byte connection_id)
2825 0x3C,
2826 // connection_id
2827 0x10, 0x32, 0x54, 0x76,
2828 0x98, 0xBA, 0xDC, 0xFE,
2829 // packet sequence number
2830 0xBC, 0x9A, 0x78, 0x56,
2831 0x34, 0x12,
2832 // private flags
2833 0x00,
2835 // frame type (go away frame)
2836 0x03,
2837 // error code
2838 0x09, 0x00, 0x00, 0x00,
2839 // stream id
2840 0x04, 0x03, 0x02, 0x01,
2841 // error details length
2842 0x0d, 0x00,
2843 // error details
2844 'b', 'e', 'c', 'a',
2845 'u', 's', 'e', ' ',
2846 'I', ' ', 'c', 'a',
2847 'n',
2850 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2851 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2853 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2854 ASSERT_TRUE(visitor_.header_.get());
2855 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2857 EXPECT_EQ(GG_UINT64_C(0x01020304),
2858 visitor_.goaway_frame_.last_good_stream_id);
2859 EXPECT_EQ(0x9, visitor_.goaway_frame_.error_code);
2860 EXPECT_EQ("because I can", visitor_.goaway_frame_.reason_phrase);
2862 const size_t reason_size = arraysize("because I can") - 1;
2863 // Now test framing boundaries.
2864 for (size_t i = kQuicFrameTypeSize;
2865 i < QuicFramer::GetMinGoAwayFrameSize() + reason_size; ++i) {
2866 string expected_error;
2867 if (i < kQuicFrameTypeSize + kQuicErrorCodeSize) {
2868 expected_error = "Unable to read go away error code.";
2869 } else if (i < kQuicFrameTypeSize + kQuicErrorCodeSize +
2870 kQuicMaxStreamIdSize) {
2871 expected_error = "Unable to read last good stream id.";
2872 } else {
2873 expected_error = "Unable to read goaway reason.";
2875 CheckProcessingFails(
2876 packet,
2877 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
2878 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP),
2879 expected_error, QUIC_INVALID_GOAWAY_DATA);
2883 TEST_P(QuicFramerTest, WindowUpdateFrame) {
2884 unsigned char packet[] = {
2885 // public flags (8 byte connection_id)
2886 0x3C,
2887 // connection_id
2888 0x10, 0x32, 0x54, 0x76,
2889 0x98, 0xBA, 0xDC, 0xFE,
2890 // packet sequence number
2891 0xBC, 0x9A, 0x78, 0x56,
2892 0x34, 0x12,
2893 // private flags
2894 0x00,
2896 // frame type (window update frame)
2897 0x04,
2898 // stream id
2899 0x04, 0x03, 0x02, 0x01,
2900 // byte offset
2901 0x05, 0x06, 0x07, 0x08,
2902 0x09, 0x0a, 0x0b, 0x0c,
2905 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2907 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2909 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2910 ASSERT_TRUE(visitor_.header_.get());
2911 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2913 EXPECT_EQ(GG_UINT64_C(0x01020304),
2914 visitor_.window_update_frame_.stream_id);
2915 EXPECT_EQ(GG_UINT64_C(0x0c0b0a0908070605),
2916 visitor_.window_update_frame_.byte_offset);
2918 // Now test framing boundaries.
2919 for (size_t i = kQuicFrameTypeSize;
2920 i < QuicFramer::GetWindowUpdateFrameSize(); ++i) {
2921 string expected_error;
2922 if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize) {
2923 expected_error = "Unable to read stream_id.";
2924 } else {
2925 expected_error = "Unable to read window byte_offset.";
2927 CheckProcessingFails(
2928 packet,
2929 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
2930 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP),
2931 expected_error, QUIC_INVALID_WINDOW_UPDATE_DATA);
2935 TEST_P(QuicFramerTest, BlockedFrame) {
2936 unsigned char packet[] = {
2937 // public flags (8 byte connection_id)
2938 0x3C,
2939 // connection_id
2940 0x10, 0x32, 0x54, 0x76,
2941 0x98, 0xBA, 0xDC, 0xFE,
2942 // packet sequence number
2943 0xBC, 0x9A, 0x78, 0x56,
2944 0x34, 0x12,
2945 // private flags
2946 0x00,
2948 // frame type (blocked frame)
2949 0x05,
2950 // stream id
2951 0x04, 0x03, 0x02, 0x01,
2954 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2956 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2958 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2959 ASSERT_TRUE(visitor_.header_.get());
2960 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2962 EXPECT_EQ(GG_UINT64_C(0x01020304),
2963 visitor_.blocked_frame_.stream_id);
2965 // Now test framing boundaries.
2966 for (size_t i = kQuicFrameTypeSize; i < QuicFramer::GetBlockedFrameSize();
2967 ++i) {
2968 string expected_error = "Unable to read stream_id.";
2969 CheckProcessingFails(
2970 packet,
2971 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
2972 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP),
2973 expected_error, QUIC_INVALID_BLOCKED_DATA);
2977 TEST_P(QuicFramerTest, PingFrame) {
2978 unsigned char packet[] = {
2979 // public flags (8 byte connection_id)
2980 0x3C,
2981 // connection_id
2982 0x10, 0x32, 0x54, 0x76,
2983 0x98, 0xBA, 0xDC, 0xFE,
2984 // packet sequence number
2985 0xBC, 0x9A, 0x78, 0x56,
2986 0x34, 0x12,
2987 // private flags
2988 0x00,
2990 // frame type (ping frame)
2991 0x07,
2994 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2995 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2997 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2998 ASSERT_TRUE(visitor_.header_.get());
2999 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
3001 EXPECT_EQ(1u, visitor_.ping_frames_.size());
3003 // No need to check the PING frame boundaries because it has no payload.
3006 TEST_P(QuicFramerTest, PublicResetPacket) {
3007 unsigned char packet[] = {
3008 // public flags (public reset, 8 byte connection_id)
3009 0x0E,
3010 // connection_id
3011 0x10, 0x32, 0x54, 0x76,
3012 0x98, 0xBA, 0xDC, 0xFE,
3013 // message tag (kPRST)
3014 'P', 'R', 'S', 'T',
3015 // num_entries (2) + padding
3016 0x02, 0x00, 0x00, 0x00,
3017 // tag kRNON
3018 'R', 'N', 'O', 'N',
3019 // end offset 8
3020 0x08, 0x00, 0x00, 0x00,
3021 // tag kRSEQ
3022 'R', 'S', 'E', 'Q',
3023 // end offset 16
3024 0x10, 0x00, 0x00, 0x00,
3025 // nonce proof
3026 0x89, 0x67, 0x45, 0x23,
3027 0x01, 0xEF, 0xCD, 0xAB,
3028 // rejected sequence number
3029 0xBC, 0x9A, 0x78, 0x56,
3030 0x34, 0x12, 0x00, 0x00,
3033 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
3034 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
3035 ASSERT_EQ(QUIC_NO_ERROR, framer_.error());
3036 ASSERT_TRUE(visitor_.public_reset_packet_.get());
3037 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
3038 visitor_.public_reset_packet_->public_header.connection_id);
3039 EXPECT_TRUE(visitor_.public_reset_packet_->public_header.reset_flag);
3040 EXPECT_FALSE(visitor_.public_reset_packet_->public_header.version_flag);
3041 EXPECT_EQ(GG_UINT64_C(0xABCDEF0123456789),
3042 visitor_.public_reset_packet_->nonce_proof);
3043 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
3044 visitor_.public_reset_packet_->rejected_sequence_number);
3045 EXPECT_TRUE(
3046 visitor_.public_reset_packet_->client_address.address().empty());
3048 // Now test framing boundaries.
3049 for (size_t i = 0; i < arraysize(packet); ++i) {
3050 string expected_error;
3051 DVLOG(1) << "iteration: " << i;
3052 if (i < kConnectionIdOffset) {
3053 expected_error = "Unable to read public flags.";
3054 CheckProcessingFails(packet, i, expected_error,
3055 QUIC_INVALID_PACKET_HEADER);
3056 } else if (i < kPublicResetPacketMessageTagOffset) {
3057 expected_error = "Unable to read ConnectionId.";
3058 CheckProcessingFails(packet, i, expected_error,
3059 QUIC_INVALID_PACKET_HEADER);
3060 } else {
3061 expected_error = "Unable to read reset message.";
3062 CheckProcessingFails(packet, i, expected_error,
3063 QUIC_INVALID_PUBLIC_RST_PACKET);
3068 TEST_P(QuicFramerTest, PublicResetPacketWithTrailingJunk) {
3069 unsigned char packet[] = {
3070 // public flags (public reset, 8 byte connection_id)
3071 0x0E,
3072 // connection_id
3073 0x10, 0x32, 0x54, 0x76,
3074 0x98, 0xBA, 0xDC, 0xFE,
3075 // message tag (kPRST)
3076 'P', 'R', 'S', 'T',
3077 // num_entries (2) + padding
3078 0x02, 0x00, 0x00, 0x00,
3079 // tag kRNON
3080 'R', 'N', 'O', 'N',
3081 // end offset 8
3082 0x08, 0x00, 0x00, 0x00,
3083 // tag kRSEQ
3084 'R', 'S', 'E', 'Q',
3085 // end offset 16
3086 0x10, 0x00, 0x00, 0x00,
3087 // nonce proof
3088 0x89, 0x67, 0x45, 0x23,
3089 0x01, 0xEF, 0xCD, 0xAB,
3090 // rejected sequence number
3091 0xBC, 0x9A, 0x78, 0x56,
3092 0x34, 0x12, 0x00, 0x00,
3093 // trailing junk
3094 'j', 'u', 'n', 'k',
3097 string expected_error = "Unable to read reset message.";
3098 CheckProcessingFails(packet, arraysize(packet), expected_error,
3099 QUIC_INVALID_PUBLIC_RST_PACKET);
3102 TEST_P(QuicFramerTest, PublicResetPacketWithClientAddress) {
3103 unsigned char packet[] = {
3104 // public flags (public reset, 8 byte connection_id)
3105 0x0E,
3106 // connection_id
3107 0x10, 0x32, 0x54, 0x76,
3108 0x98, 0xBA, 0xDC, 0xFE,
3109 // message tag (kPRST)
3110 'P', 'R', 'S', 'T',
3111 // num_entries (3) + padding
3112 0x03, 0x00, 0x00, 0x00,
3113 // tag kRNON
3114 'R', 'N', 'O', 'N',
3115 // end offset 8
3116 0x08, 0x00, 0x00, 0x00,
3117 // tag kRSEQ
3118 'R', 'S', 'E', 'Q',
3119 // end offset 16
3120 0x10, 0x00, 0x00, 0x00,
3121 // tag kCADR
3122 'C', 'A', 'D', 'R',
3123 // end offset 24
3124 0x18, 0x00, 0x00, 0x00,
3125 // nonce proof
3126 0x89, 0x67, 0x45, 0x23,
3127 0x01, 0xEF, 0xCD, 0xAB,
3128 // rejected sequence number
3129 0xBC, 0x9A, 0x78, 0x56,
3130 0x34, 0x12, 0x00, 0x00,
3131 // client address: 4.31.198.44:443
3132 0x02, 0x00,
3133 0x04, 0x1F, 0xC6, 0x2C,
3134 0xBB, 0x01,
3137 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
3138 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
3139 ASSERT_EQ(QUIC_NO_ERROR, framer_.error());
3140 ASSERT_TRUE(visitor_.public_reset_packet_.get());
3141 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
3142 visitor_.public_reset_packet_->public_header.connection_id);
3143 EXPECT_TRUE(visitor_.public_reset_packet_->public_header.reset_flag);
3144 EXPECT_FALSE(visitor_.public_reset_packet_->public_header.version_flag);
3145 EXPECT_EQ(GG_UINT64_C(0xABCDEF0123456789),
3146 visitor_.public_reset_packet_->nonce_proof);
3147 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
3148 visitor_.public_reset_packet_->rejected_sequence_number);
3149 EXPECT_EQ("4.31.198.44",
3150 IPAddressToString(visitor_.public_reset_packet_->
3151 client_address.address()));
3152 EXPECT_EQ(443, visitor_.public_reset_packet_->client_address.port());
3154 // Now test framing boundaries.
3155 for (size_t i = 0; i < arraysize(packet); ++i) {
3156 string expected_error;
3157 DVLOG(1) << "iteration: " << i;
3158 if (i < kConnectionIdOffset) {
3159 expected_error = "Unable to read public flags.";
3160 CheckProcessingFails(packet, i, expected_error,
3161 QUIC_INVALID_PACKET_HEADER);
3162 } else if (i < kPublicResetPacketMessageTagOffset) {
3163 expected_error = "Unable to read ConnectionId.";
3164 CheckProcessingFails(packet, i, expected_error,
3165 QUIC_INVALID_PACKET_HEADER);
3166 } else {
3167 expected_error = "Unable to read reset message.";
3168 CheckProcessingFails(packet, i, expected_error,
3169 QUIC_INVALID_PUBLIC_RST_PACKET);
3174 TEST_P(QuicFramerTest, VersionNegotiationPacket) {
3175 unsigned char packet[] = {
3176 // public flags (version, 8 byte connection_id)
3177 0x3D,
3178 // connection_id
3179 0x10, 0x32, 0x54, 0x76,
3180 0x98, 0xBA, 0xDC, 0xFE,
3181 // version tag
3182 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
3183 'Q', '2', '.', '0',
3186 QuicFramerPeer::SetIsServer(&framer_, false);
3188 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
3189 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
3190 ASSERT_EQ(QUIC_NO_ERROR, framer_.error());
3191 ASSERT_TRUE(visitor_.version_negotiation_packet_.get());
3192 EXPECT_EQ(2u, visitor_.version_negotiation_packet_->versions.size());
3193 EXPECT_EQ(GetParam(), visitor_.version_negotiation_packet_->versions[0]);
3195 for (size_t i = 0; i <= kPublicFlagsSize + PACKET_8BYTE_CONNECTION_ID; ++i) {
3196 string expected_error;
3197 QuicErrorCode error_code = QUIC_INVALID_PACKET_HEADER;
3198 if (i < kConnectionIdOffset) {
3199 expected_error = "Unable to read public flags.";
3200 } else if (i < kVersionOffset) {
3201 expected_error = "Unable to read ConnectionId.";
3202 } else {
3203 expected_error = "Unable to read supported version in negotiation.";
3204 error_code = QUIC_INVALID_VERSION_NEGOTIATION_PACKET;
3206 CheckProcessingFails(packet, i, expected_error, error_code);
3210 TEST_P(QuicFramerTest, FecPacket) {
3211 unsigned char packet[] = {
3212 // public flags (8 byte connection_id)
3213 0x3C,
3214 // connection_id
3215 0x10, 0x32, 0x54, 0x76,
3216 0x98, 0xBA, 0xDC, 0xFE,
3217 // packet sequence number
3218 0xBC, 0x9A, 0x78, 0x56,
3219 0x34, 0x12,
3220 // private flags (fec group & FEC)
3221 0x06,
3222 // first fec protected packet offset
3223 0x01,
3225 // redundancy
3226 'a', 'b', 'c', 'd',
3227 'e', 'f', 'g', 'h',
3228 'i', 'j', 'k', 'l',
3229 'm', 'n', 'o', 'p',
3232 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
3233 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
3235 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
3236 ASSERT_TRUE(visitor_.header_.get());
3237 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
3239 EXPECT_EQ(0u, visitor_.stream_frames_.size());
3240 EXPECT_EQ(0u, visitor_.ack_frames_.size());
3241 ASSERT_EQ(1, visitor_.fec_count_);
3242 const QuicFecData& fec_data = *visitor_.fec_data_[0];
3243 EXPECT_EQ(GG_UINT64_C(0x0123456789ABB), fec_data.fec_group);
3244 EXPECT_EQ("abcdefghijklmnop", fec_data.redundancy);
3247 TEST_P(QuicFramerTest, BuildPaddingFramePacket) {
3248 QuicPacketHeader header;
3249 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3250 header.public_header.reset_flag = false;
3251 header.public_header.version_flag = false;
3252 header.fec_flag = false;
3253 header.entropy_flag = false;
3254 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
3255 header.fec_group = 0;
3257 QuicPaddingFrame padding_frame;
3259 QuicFrames frames;
3260 frames.push_back(QuicFrame(&padding_frame));
3262 unsigned char packet[kMaxPacketSize] = {
3263 // public flags (8 byte connection_id)
3264 0x3C,
3265 // connection_id
3266 0x10, 0x32, 0x54, 0x76,
3267 0x98, 0xBA, 0xDC, 0xFE,
3268 // packet sequence number
3269 0xBC, 0x9A, 0x78, 0x56,
3270 0x34, 0x12,
3271 // private flags
3272 0x00,
3274 // frame type (padding frame)
3275 0x00,
3276 0x00, 0x00, 0x00, 0x00
3279 uint64 header_size =
3280 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
3281 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP);
3282 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1);
3284 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3285 ASSERT_TRUE(data != nullptr);
3287 test::CompareCharArraysWithHexError("constructed packet",
3288 data->data(), data->length(),
3289 AsChars(packet),
3290 arraysize(packet));
3293 TEST_P(QuicFramerTest, Build4ByteSequenceNumberPaddingFramePacket) {
3294 QuicPacketHeader header;
3295 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3296 header.public_header.reset_flag = false;
3297 header.public_header.version_flag = false;
3298 header.fec_flag = false;
3299 header.entropy_flag = false;
3300 header.public_header.sequence_number_length = PACKET_4BYTE_SEQUENCE_NUMBER;
3301 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
3302 header.fec_group = 0;
3304 QuicPaddingFrame padding_frame;
3306 QuicFrames frames;
3307 frames.push_back(QuicFrame(&padding_frame));
3309 unsigned char packet[kMaxPacketSize] = {
3310 // public flags (8 byte connection_id and 4 byte sequence number)
3311 0x2C,
3312 // connection_id
3313 0x10, 0x32, 0x54, 0x76,
3314 0x98, 0xBA, 0xDC, 0xFE,
3315 // packet sequence number
3316 0xBC, 0x9A, 0x78, 0x56,
3317 // private flags
3318 0x00,
3320 // frame type (padding frame)
3321 0x00,
3322 0x00, 0x00, 0x00, 0x00
3325 uint64 header_size =
3326 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
3327 PACKET_4BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP);
3328 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1);
3330 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3331 ASSERT_TRUE(data != nullptr);
3333 test::CompareCharArraysWithHexError("constructed packet",
3334 data->data(), data->length(),
3335 AsChars(packet),
3336 arraysize(packet));
3339 TEST_P(QuicFramerTest, Build2ByteSequenceNumberPaddingFramePacket) {
3340 QuicPacketHeader header;
3341 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3342 header.public_header.reset_flag = false;
3343 header.public_header.version_flag = false;
3344 header.fec_flag = false;
3345 header.entropy_flag = false;
3346 header.public_header.sequence_number_length = PACKET_2BYTE_SEQUENCE_NUMBER;
3347 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
3348 header.fec_group = 0;
3350 QuicPaddingFrame padding_frame;
3352 QuicFrames frames;
3353 frames.push_back(QuicFrame(&padding_frame));
3355 unsigned char packet[kMaxPacketSize] = {
3356 // public flags (8 byte connection_id and 2 byte sequence number)
3357 0x1C,
3358 // connection_id
3359 0x10, 0x32, 0x54, 0x76,
3360 0x98, 0xBA, 0xDC, 0xFE,
3361 // packet sequence number
3362 0xBC, 0x9A,
3363 // private flags
3364 0x00,
3366 // frame type (padding frame)
3367 0x00,
3368 0x00, 0x00, 0x00, 0x00
3371 uint64 header_size =
3372 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
3373 PACKET_2BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP);
3374 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1);
3376 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3377 ASSERT_TRUE(data != nullptr);
3379 test::CompareCharArraysWithHexError("constructed packet",
3380 data->data(), data->length(),
3381 AsChars(packet),
3382 arraysize(packet));
3385 TEST_P(QuicFramerTest, Build1ByteSequenceNumberPaddingFramePacket) {
3386 QuicPacketHeader header;
3387 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3388 header.public_header.reset_flag = false;
3389 header.public_header.version_flag = false;
3390 header.fec_flag = false;
3391 header.entropy_flag = false;
3392 header.public_header.sequence_number_length = PACKET_1BYTE_SEQUENCE_NUMBER;
3393 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
3394 header.fec_group = 0;
3396 QuicPaddingFrame padding_frame;
3398 QuicFrames frames;
3399 frames.push_back(QuicFrame(&padding_frame));
3401 unsigned char packet[kMaxPacketSize] = {
3402 // public flags (8 byte connection_id and 1 byte sequence number)
3403 0x0C,
3404 // connection_id
3405 0x10, 0x32, 0x54, 0x76,
3406 0x98, 0xBA, 0xDC, 0xFE,
3407 // packet sequence number
3408 0xBC,
3409 // private flags
3410 0x00,
3412 // frame type (padding frame)
3413 0x00,
3414 0x00, 0x00, 0x00, 0x00
3417 uint64 header_size =
3418 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
3419 PACKET_1BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP);
3420 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1);
3422 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3423 ASSERT_TRUE(data != nullptr);
3425 test::CompareCharArraysWithHexError("constructed packet",
3426 data->data(), data->length(),
3427 AsChars(packet),
3428 arraysize(packet));
3431 TEST_P(QuicFramerTest, BuildStreamFramePacket) {
3432 QuicPacketHeader header;
3433 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3434 header.public_header.reset_flag = false;
3435 header.public_header.version_flag = false;
3436 header.fec_flag = false;
3437 header.entropy_flag = true;
3438 header.packet_sequence_number = GG_UINT64_C(0x77123456789ABC);
3439 header.fec_group = 0;
3441 QuicStreamFrame stream_frame;
3442 stream_frame.stream_id = 0x01020304;
3443 stream_frame.fin = true;
3444 stream_frame.offset = GG_UINT64_C(0xBA98FEDC32107654);
3445 stream_frame.data = MakeIOVector("hello world!");
3447 QuicFrames frames;
3448 frames.push_back(QuicFrame(&stream_frame));
3450 unsigned char packet[] = {
3451 // public flags (8 byte connection_id)
3452 0x3C,
3453 // connection_id
3454 0x10, 0x32, 0x54, 0x76,
3455 0x98, 0xBA, 0xDC, 0xFE,
3456 // packet sequence number
3457 0xBC, 0x9A, 0x78, 0x56,
3458 0x34, 0x12,
3459 // private flags (entropy)
3460 0x01,
3462 // frame type (stream frame with fin and no length)
3463 0xDF,
3464 // stream id
3465 0x04, 0x03, 0x02, 0x01,
3466 // offset
3467 0x54, 0x76, 0x10, 0x32,
3468 0xDC, 0xFE, 0x98, 0xBA,
3469 // data
3470 'h', 'e', 'l', 'l',
3471 'o', ' ', 'w', 'o',
3472 'r', 'l', 'd', '!',
3475 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3476 ASSERT_TRUE(data != nullptr);
3478 test::CompareCharArraysWithHexError("constructed packet",
3479 data->data(), data->length(),
3480 AsChars(packet), arraysize(packet));
3483 TEST_P(QuicFramerTest, BuildStreamFramePacketInFecGroup) {
3484 QuicPacketHeader header;
3485 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3486 header.public_header.reset_flag = false;
3487 header.public_header.version_flag = false;
3488 header.fec_flag = false;
3489 header.entropy_flag = true;
3490 header.packet_sequence_number = GG_UINT64_C(0x77123456789ABC);
3491 header.is_in_fec_group = IN_FEC_GROUP;
3492 header.fec_group = GG_UINT64_C(0x77123456789ABC);
3494 QuicStreamFrame stream_frame;
3495 stream_frame.stream_id = 0x01020304;
3496 stream_frame.fin = true;
3497 stream_frame.offset = GG_UINT64_C(0xBA98FEDC32107654);
3498 stream_frame.data = MakeIOVector("hello world!");
3500 QuicFrames frames;
3501 frames.push_back(QuicFrame(&stream_frame));
3502 unsigned char packet[] = {
3503 // public flags (8 byte connection_id)
3504 0x3C,
3505 // connection_id
3506 0x10, 0x32, 0x54, 0x76,
3507 0x98, 0xBA, 0xDC, 0xFE,
3508 // packet sequence number
3509 0xBC, 0x9A, 0x78, 0x56,
3510 0x34, 0x12,
3511 // private flags (entropy, is_in_fec_group)
3512 0x03,
3513 // FEC group
3514 0x00,
3515 // frame type (stream frame with fin and data length field)
3516 0xFF,
3517 // stream id
3518 0x04, 0x03, 0x02, 0x01,
3519 // offset
3520 0x54, 0x76, 0x10, 0x32,
3521 0xDC, 0xFE, 0x98, 0xBA,
3522 // data length (since packet is in an FEC group)
3523 0x0C, 0x00,
3524 // data
3525 'h', 'e', 'l', 'l',
3526 'o', ' ', 'w', 'o',
3527 'r', 'l', 'd', '!',
3530 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3531 ASSERT_TRUE(data != nullptr);
3533 test::CompareCharArraysWithHexError("constructed packet",
3534 data->data(), data->length(),
3535 AsChars(packet), arraysize(packet));
3538 TEST_P(QuicFramerTest, BuildStreamFramePacketWithVersionFlag) {
3539 QuicPacketHeader header;
3540 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3541 header.public_header.reset_flag = false;
3542 header.public_header.version_flag = true;
3543 header.fec_flag = false;
3544 header.entropy_flag = true;
3545 header.packet_sequence_number = GG_UINT64_C(0x77123456789ABC);
3546 header.fec_group = 0;
3548 QuicStreamFrame stream_frame;
3549 stream_frame.stream_id = 0x01020304;
3550 stream_frame.fin = true;
3551 stream_frame.offset = GG_UINT64_C(0xBA98FEDC32107654);
3552 stream_frame.data = MakeIOVector("hello world!");
3554 QuicFrames frames;
3555 frames.push_back(QuicFrame(&stream_frame));
3557 unsigned char packet[] = {
3558 // public flags (version, 8 byte connection_id)
3559 0x3D,
3560 // connection_id
3561 0x10, 0x32, 0x54, 0x76,
3562 0x98, 0xBA, 0xDC, 0xFE,
3563 // version tag
3564 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
3565 // packet sequence number
3566 0xBC, 0x9A, 0x78, 0x56,
3567 0x34, 0x12,
3568 // private flags (entropy)
3569 0x01,
3571 // frame type (stream frame with fin and no length)
3572 0xDF,
3573 // stream id
3574 0x04, 0x03, 0x02, 0x01,
3575 // offset
3576 0x54, 0x76, 0x10, 0x32,
3577 0xDC, 0xFE, 0x98, 0xBA,
3578 // data
3579 'h', 'e', 'l', 'l',
3580 'o', ' ', 'w', 'o',
3581 'r', 'l', 'd', '!',
3584 QuicFramerPeer::SetIsServer(&framer_, false);
3585 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3586 ASSERT_TRUE(data != nullptr);
3588 test::CompareCharArraysWithHexError("constructed packet",
3589 data->data(), data->length(),
3590 AsChars(packet), arraysize(packet));
3593 TEST_P(QuicFramerTest, BuildVersionNegotiationPacket) {
3594 QuicPacketPublicHeader header;
3595 header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3596 header.reset_flag = false;
3597 header.version_flag = true;
3599 unsigned char packet[] = {
3600 // public flags (version, 8 byte connection_id)
3601 0x0D,
3602 // connection_id
3603 0x10, 0x32, 0x54, 0x76,
3604 0x98, 0xBA, 0xDC, 0xFE,
3605 // version tag
3606 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
3609 QuicVersionVector versions;
3610 versions.push_back(GetParam());
3611 scoped_ptr<QuicEncryptedPacket> data(
3612 framer_.BuildVersionNegotiationPacket(header, versions));
3614 test::CompareCharArraysWithHexError("constructed packet",
3615 data->data(), data->length(),
3616 AsChars(packet), arraysize(packet));
3619 TEST_P(QuicFramerTest, BuildAckFramePacketv22) {
3620 if (version_ > QUIC_VERSION_22) {
3621 return;
3623 QuicPacketHeader header;
3624 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3625 header.public_header.reset_flag = false;
3626 header.public_header.version_flag = false;
3627 header.fec_flag = false;
3628 header.entropy_flag = true;
3629 header.packet_sequence_number = GG_UINT64_C(0x770123456789AA8);
3630 header.fec_group = 0;
3632 QuicAckFrame ack_frame;
3633 ack_frame.entropy_hash = 0x43;
3634 ack_frame.largest_observed = GG_UINT64_C(0x770123456789ABF);
3635 ack_frame.delta_time_largest_observed = QuicTime::Delta::Zero();
3636 ack_frame.missing_packets.insert(
3637 GG_UINT64_C(0x770123456789ABE));
3639 QuicFrames frames;
3640 frames.push_back(QuicFrame(&ack_frame));
3642 unsigned char packet[] = {
3643 // public flags (8 byte connection_id)
3644 0x3C,
3645 // connection_id
3646 0x10, 0x32, 0x54, 0x76,
3647 0x98, 0xBA, 0xDC, 0xFE,
3648 // packet sequence number
3649 0xA8, 0x9A, 0x78, 0x56,
3650 0x34, 0x12,
3651 // private flags (entropy)
3652 0x01,
3654 // frame type (ack frame)
3655 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
3656 0x6C,
3657 // entropy hash of all received packets.
3658 0x43,
3659 // largest observed packet sequence number
3660 0xBF, 0x9A, 0x78, 0x56,
3661 0x34, 0x12,
3662 // Zero delta time.
3663 0x0, 0x0,
3664 // num missing packet ranges
3665 0x01,
3666 // missing packet delta
3667 0x01,
3668 // 0 more missing packets in range.
3669 0x00,
3670 // 0 revived packets.
3671 0x00,
3674 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3675 ASSERT_TRUE(data != nullptr);
3677 test::CompareCharArraysWithHexError("constructed packet",
3678 data->data(), data->length(),
3679 AsChars(packet), arraysize(packet));
3682 TEST_P(QuicFramerTest, BuildAckFramePacket) {
3683 if (version_ <= QUIC_VERSION_22) {
3684 return;
3686 QuicPacketHeader header;
3687 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3688 header.public_header.reset_flag = false;
3689 header.public_header.version_flag = false;
3690 header.fec_flag = false;
3691 header.entropy_flag = true;
3692 header.packet_sequence_number = GG_UINT64_C(0x770123456789AA8);
3693 header.fec_group = 0;
3695 QuicAckFrame ack_frame;
3696 ack_frame.entropy_hash = 0x43;
3697 ack_frame.largest_observed = GG_UINT64_C(0x770123456789ABF);
3698 ack_frame.delta_time_largest_observed = QuicTime::Delta::Zero();
3699 ack_frame.missing_packets.insert(
3700 GG_UINT64_C(0x770123456789ABE));
3702 QuicFrames frames;
3703 frames.push_back(QuicFrame(&ack_frame));
3705 unsigned char packet[] = {
3706 // public flags (8 byte connection_id)
3707 0x3C,
3708 // connection_id
3709 0x10, 0x32, 0x54, 0x76,
3710 0x98, 0xBA, 0xDC, 0xFE,
3711 // packet sequence number
3712 0xA8, 0x9A, 0x78, 0x56,
3713 0x34, 0x12,
3714 // private flags (entropy)
3715 0x01,
3717 // frame type (ack frame)
3718 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
3719 0x6C,
3720 // entropy hash of all received packets.
3721 0x43,
3722 // largest observed packet sequence number
3723 0xBF, 0x9A, 0x78, 0x56,
3724 0x34, 0x12,
3725 // Zero delta time.
3726 0x0, 0x0,
3727 // num received packets.
3728 0x00,
3729 // num missing packet ranges
3730 0x01,
3731 // missing packet delta
3732 0x01,
3733 // 0 more missing packets in range.
3734 0x00,
3735 // 0 revived packets.
3736 0x00,
3739 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3740 ASSERT_TRUE(data != nullptr);
3742 test::CompareCharArraysWithHexError("constructed packet",
3743 data->data(), data->length(),
3744 AsChars(packet), arraysize(packet));
3747 // TODO(jri): Add test for tuncated packets in which the original ack frame had
3748 // revived packets. (In both the large and small packet cases below).
3750 TEST_P(QuicFramerTest, BuildTruncatedAckFrameLargePacketv22) {
3751 if (version_ > QUIC_VERSION_22) {
3752 return;
3754 QuicPacketHeader header;
3755 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3756 header.public_header.reset_flag = false;
3757 header.public_header.version_flag = false;
3758 header.fec_flag = false;
3759 header.entropy_flag = true;
3760 header.packet_sequence_number = GG_UINT64_C(0x770123456789AA8);
3761 header.fec_group = 0;
3763 QuicAckFrame ack_frame;
3764 // This entropy hash is different from what shows up in the packet below,
3765 // since entropy is recomputed by the framer on ack truncation (by
3766 // TestEntropyCalculator for this test.)
3767 ack_frame.entropy_hash = 0x43;
3768 ack_frame.largest_observed = 2 * 300;
3769 ack_frame.delta_time_largest_observed = QuicTime::Delta::Zero();
3770 for (size_t i = 1; i < 2 * 300; i += 2) {
3771 ack_frame.missing_packets.insert(i);
3774 QuicFrames frames;
3775 frames.push_back(QuicFrame(&ack_frame));
3777 unsigned char packet[] = {
3778 // public flags (8 byte connection_id)
3779 0x3C,
3780 // connection_id
3781 0x10, 0x32, 0x54, 0x76,
3782 0x98, 0xBA, 0xDC, 0xFE,
3783 // packet sequence number
3784 0xA8, 0x9A, 0x78, 0x56,
3785 0x34, 0x12,
3786 // private flags (entropy)
3787 0x01,
3789 // frame type (ack frame)
3790 // (has nacks, is truncated, 2 byte largest observed, 1 byte delta)
3791 0x74,
3792 // entropy hash of all received packets, set to 1 by TestEntropyCalculator
3793 // since ack is truncated.
3794 0x01,
3795 // 2-byte largest observed packet sequence number.
3796 // Expected to be 510 (0x1FE), since only 255 nack ranges can fit.
3797 0xFE, 0x01,
3798 // Zero delta time.
3799 0x0, 0x0,
3800 // num missing packet ranges (limited to 255 by size of this field).
3801 0xFF,
3802 // {missing packet delta, further missing packets in range}
3803 // 6 nack ranges x 42 + 3 nack ranges
3804 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3805 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3806 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3807 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3808 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3809 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3810 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3811 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3812 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3813 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3815 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3816 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3817 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3818 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3819 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3820 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3821 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3822 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3823 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3824 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3826 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3827 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3828 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3829 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3830 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3831 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3832 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3833 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3834 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3835 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3837 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3838 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3839 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3840 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3841 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3842 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3843 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3844 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3845 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3846 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3848 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3849 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3850 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3852 // 0 revived packets.
3853 0x00,
3856 scoped_ptr<QuicPacket> data(
3857 framer_.BuildDataPacket(header, frames, kMaxPacketSize).packet);
3858 ASSERT_TRUE(data != nullptr);
3860 test::CompareCharArraysWithHexError("constructed packet",
3861 data->data(), data->length(),
3862 AsChars(packet), arraysize(packet));
3865 TEST_P(QuicFramerTest, BuildTruncatedAckFrameLargePacket) {
3866 if (version_ <= QUIC_VERSION_22) {
3867 return;
3869 QuicPacketHeader header;
3870 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3871 header.public_header.reset_flag = false;
3872 header.public_header.version_flag = false;
3873 header.fec_flag = false;
3874 header.entropy_flag = true;
3875 header.packet_sequence_number = GG_UINT64_C(0x770123456789AA8);
3876 header.fec_group = 0;
3878 QuicAckFrame ack_frame;
3879 // This entropy hash is different from what shows up in the packet below,
3880 // since entropy is recomputed by the framer on ack truncation (by
3881 // TestEntropyCalculator for this test.)
3882 ack_frame.entropy_hash = 0x43;
3883 ack_frame.largest_observed = 2 * 300;
3884 ack_frame.delta_time_largest_observed = QuicTime::Delta::Zero();
3885 for (size_t i = 1; i < 2 * 300; i += 2) {
3886 ack_frame.missing_packets.insert(i);
3889 QuicFrames frames;
3890 frames.push_back(QuicFrame(&ack_frame));
3892 unsigned char packet[] = {
3893 // public flags (8 byte connection_id)
3894 0x3C,
3895 // connection_id
3896 0x10, 0x32, 0x54, 0x76,
3897 0x98, 0xBA, 0xDC, 0xFE,
3898 // packet sequence number
3899 0xA8, 0x9A, 0x78, 0x56,
3900 0x34, 0x12,
3901 // private flags (entropy)
3902 0x01,
3904 // frame type (ack frame)
3905 // (has nacks, is truncated, 2 byte largest observed, 1 byte delta)
3906 0x74,
3907 // entropy hash of all received packets, set to 1 by TestEntropyCalculator
3908 // since ack is truncated.
3909 0x01,
3910 // 2-byte largest observed packet sequence number.
3911 // Expected to be 510 (0x1FE), since only 255 nack ranges can fit.
3912 0xFE, 0x01,
3913 // Zero delta time.
3914 0x0, 0x0,
3915 // num missing packet ranges (limited to 255 by size of this field).
3916 0xFF,
3917 // {missing packet delta, further missing packets in range}
3918 // 6 nack ranges x 42 + 3 nack ranges
3919 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3920 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3921 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3922 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3923 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3924 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3925 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3926 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3927 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3928 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3930 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3931 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3932 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3933 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3934 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3935 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3936 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3937 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3938 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3939 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3941 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3942 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3943 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3944 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3945 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3946 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3947 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3948 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3949 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3950 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3952 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3953 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3954 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3955 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3956 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3957 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3958 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3959 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3960 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3961 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3963 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3964 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3965 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3967 // 0 revived packets.
3968 0x00,
3971 scoped_ptr<QuicPacket> data(
3972 framer_.BuildDataPacket(header, frames, kMaxPacketSize).packet);
3973 ASSERT_TRUE(data != nullptr);
3975 test::CompareCharArraysWithHexError("constructed packet",
3976 data->data(), data->length(),
3977 AsChars(packet), arraysize(packet));
3981 TEST_P(QuicFramerTest, BuildTruncatedAckFrameSmallPacketv22) {
3982 if (version_ > QUIC_VERSION_22) {
3983 return;
3985 QuicPacketHeader header;
3986 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3987 header.public_header.reset_flag = false;
3988 header.public_header.version_flag = false;
3989 header.fec_flag = false;
3990 header.entropy_flag = true;
3991 header.packet_sequence_number = GG_UINT64_C(0x770123456789AA8);
3992 header.fec_group = 0;
3994 QuicAckFrame ack_frame;
3995 // This entropy hash is different from what shows up in the packet below,
3996 // since entropy is recomputed by the framer on ack truncation (by
3997 // TestEntropyCalculator for this test.)
3998 ack_frame.entropy_hash = 0x43;
3999 ack_frame.largest_observed = 2 * 300;
4000 ack_frame.delta_time_largest_observed = QuicTime::Delta::Zero();
4001 for (size_t i = 1; i < 2 * 300; i += 2) {
4002 ack_frame.missing_packets.insert(i);
4005 QuicFrames frames;
4006 frames.push_back(QuicFrame(&ack_frame));
4008 unsigned char packet[] = {
4009 // public flags (8 byte connection_id)
4010 0x3C,
4011 // connection_id
4012 0x10, 0x32, 0x54, 0x76,
4013 0x98, 0xBA, 0xDC, 0xFE,
4014 // packet sequence number
4015 0xA8, 0x9A, 0x78, 0x56,
4016 0x34, 0x12,
4017 // private flags (entropy)
4018 0x01,
4020 // frame type (ack frame)
4021 // (has nacks, is truncated, 2 byte largest observed, 1 byte delta)
4022 0x74,
4023 // entropy hash of all received packets, set to 1 by TestEntropyCalculator
4024 // since ack is truncated.
4025 0x01,
4026 // 2-byte largest observed packet sequence number.
4027 // Expected to be 12 (0x0C), since only 6 nack ranges can fit.
4028 0x0C, 0x00,
4029 // Zero delta time.
4030 0x0, 0x0,
4031 // num missing packet ranges (limited to 6 by packet size of 37).
4032 0x06,
4033 // {missing packet delta, further missing packets in range}
4034 // 6 nack ranges
4035 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
4036 // 0 revived packets.
4037 0x00,
4040 scoped_ptr<QuicPacket> data(
4041 framer_.BuildDataPacket(header, frames, 37u).packet);
4042 ASSERT_TRUE(data != nullptr);
4043 // Expect 1 byte unused since at least 2 bytes are needed to fit more nacks.
4044 EXPECT_EQ(36u, data->length());
4045 test::CompareCharArraysWithHexError("constructed packet",
4046 data->data(), data->length(),
4047 AsChars(packet), arraysize(packet));
4050 TEST_P(QuicFramerTest, BuildTruncatedAckFrameSmallPacket) {
4051 if (version_ <= QUIC_VERSION_22) {
4052 return;
4054 QuicPacketHeader header;
4055 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
4056 header.public_header.reset_flag = false;
4057 header.public_header.version_flag = false;
4058 header.fec_flag = false;
4059 header.entropy_flag = true;
4060 header.packet_sequence_number = GG_UINT64_C(0x770123456789AA8);
4061 header.fec_group = 0;
4063 QuicAckFrame ack_frame;
4064 // This entropy hash is different from what shows up in the packet below,
4065 // since entropy is recomputed by the framer on ack truncation (by
4066 // TestEntropyCalculator for this test.)
4067 ack_frame.entropy_hash = 0x43;
4068 ack_frame.largest_observed = 2 * 300;
4069 ack_frame.delta_time_largest_observed = QuicTime::Delta::Zero();
4070 for (size_t i = 1; i < 2 * 300; i += 2) {
4071 ack_frame.missing_packets.insert(i);
4074 QuicFrames frames;
4075 frames.push_back(QuicFrame(&ack_frame));
4077 unsigned char packet[] = {
4078 // public flags (8 byte connection_id)
4079 0x3C,
4080 // connection_id
4081 0x10, 0x32, 0x54, 0x76,
4082 0x98, 0xBA, 0xDC, 0xFE,
4083 // packet sequence number
4084 0xA8, 0x9A, 0x78, 0x56,
4085 0x34, 0x12,
4086 // private flags (entropy)
4087 0x01,
4089 // frame type (ack frame)
4090 // (has nacks, is truncated, 2 byte largest observed, 1 byte delta)
4091 0x74,
4092 // entropy hash of all received packets, set to 1 by TestEntropyCalculator
4093 // since ack is truncated.
4094 0x01,
4095 // 2-byte largest observed packet sequence number.
4096 // Expected to be 12 (0x0C), since only 6 nack ranges can fit.
4097 0x0C, 0x00,
4098 // Zero delta time.
4099 0x0, 0x0,
4100 // num missing packet ranges (limited to 6 by packet size of 37).
4101 0x06,
4102 // {missing packet delta, further missing packets in range}
4103 // 6 nack ranges
4104 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
4105 // 0 revived packets.
4106 0x00,
4109 scoped_ptr<QuicPacket> data(
4110 framer_.BuildDataPacket(header, frames, 37u).packet);
4111 ASSERT_TRUE(data != nullptr);
4112 // Expect 1 byte unused since at least 2 bytes are needed to fit more nacks.
4113 EXPECT_EQ(36u, data->length());
4114 test::CompareCharArraysWithHexError("constructed packet",
4115 data->data(), data->length(),
4116 AsChars(packet), arraysize(packet));
4119 TEST_P(QuicFramerTest, BuildCongestionFeedbackFramePacketTCP) {
4120 QuicPacketHeader header;
4121 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
4122 header.public_header.reset_flag = false;
4123 header.public_header.version_flag = false;
4124 header.fec_flag = false;
4125 header.entropy_flag = false;
4126 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
4127 header.fec_group = 0;
4129 QuicCongestionFeedbackFrame congestion_feedback_frame;
4130 congestion_feedback_frame.type = kTCP;
4131 congestion_feedback_frame.tcp.receive_window = 0x4030;
4133 QuicFrames frames;
4134 frames.push_back(QuicFrame(&congestion_feedback_frame));
4136 unsigned char packet[] = {
4137 // public flags (8 byte connection_id)
4138 0x3C,
4139 // connection_id
4140 0x10, 0x32, 0x54, 0x76,
4141 0x98, 0xBA, 0xDC, 0xFE,
4142 // packet sequence number
4143 0xBC, 0x9A, 0x78, 0x56,
4144 0x34, 0x12,
4145 // private flags
4146 0x00,
4148 // frame type (congestion feedback frame)
4149 0x20,
4150 // congestion feedback type (TCP)
4151 0x00,
4152 // TCP receive window
4153 0x03, 0x04,
4156 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
4157 ASSERT_TRUE(data != nullptr);
4159 test::CompareCharArraysWithHexError("constructed packet",
4160 data->data(), data->length(),
4161 AsChars(packet), arraysize(packet));
4164 TEST_P(QuicFramerTest, BuildStopWaitingPacket) {
4165 QuicPacketHeader header;
4166 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
4167 header.public_header.reset_flag = false;
4168 header.public_header.version_flag = false;
4169 header.fec_flag = false;
4170 header.entropy_flag = true;
4171 header.packet_sequence_number = GG_UINT64_C(0x770123456789AA8);
4172 header.fec_group = 0;
4174 QuicStopWaitingFrame stop_waiting_frame;
4175 stop_waiting_frame.entropy_hash = 0x14;
4176 stop_waiting_frame.least_unacked = GG_UINT64_C(0x770123456789AA0);
4178 QuicFrames frames;
4179 frames.push_back(QuicFrame(&stop_waiting_frame));
4181 unsigned char packet[] = {
4182 // public flags (8 byte connection_id)
4183 0x3C,
4184 // connection_id
4185 0x10, 0x32, 0x54, 0x76,
4186 0x98, 0xBA, 0xDC, 0xFE,
4187 // packet sequence number
4188 0xA8, 0x9A, 0x78, 0x56,
4189 0x34, 0x12,
4190 // private flags (entropy)
4191 0x01,
4193 // frame type (stop waiting frame)
4194 0x06,
4195 // entropy hash of sent packets till least awaiting - 1.
4196 0x14,
4197 // least packet sequence number awaiting an ack, delta from sequence number.
4198 0x08, 0x00, 0x00, 0x00,
4199 0x00, 0x00,
4202 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
4203 ASSERT_TRUE(data != nullptr);
4205 test::CompareCharArraysWithHexError("constructed packet",
4206 data->data(), data->length(),
4207 AsChars(packet), arraysize(packet));
4210 TEST_P(QuicFramerTest, BuildCongestionFeedbackFramePacketInvalidFeedback) {
4211 QuicPacketHeader header;
4212 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
4213 header.public_header.reset_flag = false;
4214 header.public_header.version_flag = false;
4215 header.fec_flag = false;
4216 header.entropy_flag = false;
4217 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
4218 header.fec_group = 0;
4220 QuicCongestionFeedbackFrame congestion_feedback_frame;
4221 congestion_feedback_frame.type =
4222 static_cast<CongestionFeedbackType>(kTCP + 1);
4224 QuicFrames frames;
4225 frames.push_back(QuicFrame(&congestion_feedback_frame));
4227 scoped_ptr<QuicPacket> data;
4228 EXPECT_DFATAL(
4229 data.reset(BuildDataPacket(header, frames)),
4230 "AppendCongestionFeedbackFrame failed");
4231 ASSERT_TRUE(data == nullptr);
4234 TEST_P(QuicFramerTest, BuildRstFramePacketQuic) {
4235 QuicPacketHeader header;
4236 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
4237 header.public_header.reset_flag = false;
4238 header.public_header.version_flag = false;
4239 header.fec_flag = false;
4240 header.entropy_flag = false;
4241 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
4242 header.fec_group = 0;
4244 QuicRstStreamFrame rst_frame;
4245 rst_frame.stream_id = 0x01020304;
4246 rst_frame.error_code = static_cast<QuicRstStreamErrorCode>(0x05060708);
4247 rst_frame.error_details = "because I can";
4248 rst_frame.byte_offset = 0x0807060504030201;
4250 unsigned char packet[] = {
4251 // public flags (8 byte connection_id)
4252 0x3C,
4253 // connection_id
4254 0x10, 0x32, 0x54, 0x76,
4255 0x98, 0xBA, 0xDC, 0xFE,
4256 // packet sequence number
4257 0xBC, 0x9A, 0x78, 0x56,
4258 0x34, 0x12,
4259 // private flags
4260 0x00,
4262 // frame type (rst stream frame)
4263 0x01,
4264 // stream id
4265 0x04, 0x03, 0x02, 0x01,
4266 // sent byte offset
4267 0x01, 0x02, 0x03, 0x04,
4268 0x05, 0x06, 0x07, 0x08,
4269 // error code
4270 0x08, 0x07, 0x06, 0x05,
4271 // error details length
4272 0x0d, 0x00,
4273 // error details
4274 'b', 'e', 'c', 'a',
4275 'u', 's', 'e', ' ',
4276 'I', ' ', 'c', 'a',
4277 'n',
4280 QuicFrames frames;
4281 frames.push_back(QuicFrame(&rst_frame));
4283 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
4284 ASSERT_TRUE(data != nullptr);
4286 test::CompareCharArraysWithHexError("constructed packet",
4287 data->data(), data->length(),
4288 AsChars(packet), arraysize(packet));
4291 TEST_P(QuicFramerTest, BuildCloseFramePacket) {
4292 QuicPacketHeader header;
4293 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
4294 header.public_header.reset_flag = false;
4295 header.public_header.version_flag = false;
4296 header.fec_flag = false;
4297 header.entropy_flag = true;
4298 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
4299 header.fec_group = 0;
4301 QuicConnectionCloseFrame close_frame;
4302 close_frame.error_code = static_cast<QuicErrorCode>(0x05060708);
4303 close_frame.error_details = "because I can";
4305 QuicFrames frames;
4306 frames.push_back(QuicFrame(&close_frame));
4308 unsigned char packet[] = {
4309 // public flags (8 byte connection_id)
4310 0x3C,
4311 // connection_id
4312 0x10, 0x32, 0x54, 0x76,
4313 0x98, 0xBA, 0xDC, 0xFE,
4314 // packet sequence number
4315 0xBC, 0x9A, 0x78, 0x56,
4316 0x34, 0x12,
4317 // private flags (entropy)
4318 0x01,
4320 // frame type (connection close frame)
4321 0x02,
4322 // error code
4323 0x08, 0x07, 0x06, 0x05,
4324 // error details length
4325 0x0d, 0x00,
4326 // error details
4327 'b', 'e', 'c', 'a',
4328 'u', 's', 'e', ' ',
4329 'I', ' ', 'c', 'a',
4330 'n',
4333 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
4334 ASSERT_TRUE(data != nullptr);
4336 test::CompareCharArraysWithHexError("constructed packet",
4337 data->data(), data->length(),
4338 AsChars(packet), arraysize(packet));
4341 TEST_P(QuicFramerTest, BuildGoAwayPacket) {
4342 QuicPacketHeader header;
4343 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
4344 header.public_header.reset_flag = false;
4345 header.public_header.version_flag = false;
4346 header.fec_flag = false;
4347 header.entropy_flag = true;
4348 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
4349 header.fec_group = 0;
4351 QuicGoAwayFrame goaway_frame;
4352 goaway_frame.error_code = static_cast<QuicErrorCode>(0x05060708);
4353 goaway_frame.last_good_stream_id = 0x01020304;
4354 goaway_frame.reason_phrase = "because I can";
4356 QuicFrames frames;
4357 frames.push_back(QuicFrame(&goaway_frame));
4359 unsigned char packet[] = {
4360 // public flags (8 byte connection_id)
4361 0x3C,
4362 // connection_id
4363 0x10, 0x32, 0x54, 0x76,
4364 0x98, 0xBA, 0xDC, 0xFE,
4365 // packet sequence number
4366 0xBC, 0x9A, 0x78, 0x56,
4367 0x34, 0x12,
4368 // private flags(entropy)
4369 0x01,
4371 // frame type (go away frame)
4372 0x03,
4373 // error code
4374 0x08, 0x07, 0x06, 0x05,
4375 // stream id
4376 0x04, 0x03, 0x02, 0x01,
4377 // error details length
4378 0x0d, 0x00,
4379 // error details
4380 'b', 'e', 'c', 'a',
4381 'u', 's', 'e', ' ',
4382 'I', ' ', 'c', 'a',
4383 'n',
4386 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
4387 ASSERT_TRUE(data != nullptr);
4389 test::CompareCharArraysWithHexError("constructed packet",
4390 data->data(), data->length(),
4391 AsChars(packet), arraysize(packet));
4394 TEST_P(QuicFramerTest, BuildWindowUpdatePacket) {
4395 QuicPacketHeader header;
4396 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
4397 header.public_header.reset_flag = false;
4398 header.public_header.version_flag = false;
4399 header.fec_flag = false;
4400 header.entropy_flag = true;
4401 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
4402 header.fec_group = 0;
4404 QuicWindowUpdateFrame window_update_frame;
4405 window_update_frame.stream_id = 0x01020304;
4406 window_update_frame.byte_offset = 0x1122334455667788;
4408 QuicFrames frames;
4409 frames.push_back(QuicFrame(&window_update_frame));
4411 unsigned char packet[] = {
4412 // public flags (8 byte connection_id)
4413 0x3C,
4414 // connection_id
4415 0x10, 0x32, 0x54, 0x76,
4416 0x98, 0xBA, 0xDC, 0xFE,
4417 // packet sequence number
4418 0xBC, 0x9A, 0x78, 0x56,
4419 0x34, 0x12,
4420 // private flags(entropy)
4421 0x01,
4423 // frame type (window update frame)
4424 0x04,
4425 // stream id
4426 0x04, 0x03, 0x02, 0x01,
4427 // byte offset
4428 0x88, 0x77, 0x66, 0x55,
4429 0x44, 0x33, 0x22, 0x11,
4432 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
4433 ASSERT_TRUE(data != nullptr);
4435 test::CompareCharArraysWithHexError("constructed packet", data->data(),
4436 data->length(), AsChars(packet),
4437 arraysize(packet));
4440 TEST_P(QuicFramerTest, BuildBlockedPacket) {
4441 QuicPacketHeader header;
4442 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
4443 header.public_header.reset_flag = false;
4444 header.public_header.version_flag = false;
4445 header.fec_flag = false;
4446 header.entropy_flag = true;
4447 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
4448 header.fec_group = 0;
4450 QuicBlockedFrame blocked_frame;
4451 blocked_frame.stream_id = 0x01020304;
4453 QuicFrames frames;
4454 frames.push_back(QuicFrame(&blocked_frame));
4456 unsigned char packet[] = {
4457 // public flags (8 byte connection_id)
4458 0x3C,
4459 // connection_id
4460 0x10, 0x32, 0x54, 0x76,
4461 0x98, 0xBA, 0xDC, 0xFE,
4462 // packet sequence number
4463 0xBC, 0x9A, 0x78, 0x56,
4464 0x34, 0x12,
4465 // private flags(entropy)
4466 0x01,
4468 // frame type (blocked frame)
4469 0x05,
4470 // stream id
4471 0x04, 0x03, 0x02, 0x01,
4474 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
4475 ASSERT_TRUE(data != nullptr);
4477 test::CompareCharArraysWithHexError("constructed packet", data->data(),
4478 data->length(), AsChars(packet),
4479 arraysize(packet));
4482 TEST_P(QuicFramerTest, BuildPingPacket) {
4483 QuicPacketHeader header;
4484 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
4485 header.public_header.reset_flag = false;
4486 header.public_header.version_flag = false;
4487 header.fec_flag = false;
4488 header.entropy_flag = true;
4489 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
4490 header.fec_group = 0;
4492 QuicPingFrame ping_frame;
4494 QuicFrames frames;
4495 frames.push_back(QuicFrame(&ping_frame));
4497 unsigned char packet[] = {
4498 // public flags (8 byte connection_id)
4499 0x3C,
4500 // connection_id
4501 0x10, 0x32, 0x54, 0x76,
4502 0x98, 0xBA, 0xDC, 0xFE,
4503 // packet sequence number
4504 0xBC, 0x9A, 0x78, 0x56,
4505 0x34, 0x12,
4506 // private flags(entropy)
4507 0x01,
4509 // frame type (ping frame)
4510 0x07,
4513 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
4514 ASSERT_TRUE(data != nullptr);
4516 test::CompareCharArraysWithHexError("constructed packet", data->data(),
4517 data->length(), AsChars(packet),
4518 arraysize(packet));
4521 TEST_P(QuicFramerTest, BuildPublicResetPacket) {
4522 QuicPublicResetPacket reset_packet;
4523 reset_packet.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
4524 reset_packet.public_header.reset_flag = true;
4525 reset_packet.public_header.version_flag = false;
4526 reset_packet.rejected_sequence_number = GG_UINT64_C(0x123456789ABC);
4527 reset_packet.nonce_proof = GG_UINT64_C(0xABCDEF0123456789);
4529 unsigned char packet[] = {
4530 // public flags (public reset, 8 byte ConnectionId)
4531 0x0E,
4532 // connection_id
4533 0x10, 0x32, 0x54, 0x76,
4534 0x98, 0xBA, 0xDC, 0xFE,
4535 // message tag (kPRST)
4536 'P', 'R', 'S', 'T',
4537 // num_entries (2) + padding
4538 0x02, 0x00, 0x00, 0x00,
4539 // tag kRNON
4540 'R', 'N', 'O', 'N',
4541 // end offset 8
4542 0x08, 0x00, 0x00, 0x00,
4543 // tag kRSEQ
4544 'R', 'S', 'E', 'Q',
4545 // end offset 16
4546 0x10, 0x00, 0x00, 0x00,
4547 // nonce proof
4548 0x89, 0x67, 0x45, 0x23,
4549 0x01, 0xEF, 0xCD, 0xAB,
4550 // rejected sequence number
4551 0xBC, 0x9A, 0x78, 0x56,
4552 0x34, 0x12, 0x00, 0x00,
4555 scoped_ptr<QuicEncryptedPacket> data(
4556 framer_.BuildPublicResetPacket(reset_packet));
4557 ASSERT_TRUE(data != nullptr);
4559 test::CompareCharArraysWithHexError("constructed packet",
4560 data->data(), data->length(),
4561 AsChars(packet), arraysize(packet));
4564 TEST_P(QuicFramerTest, BuildPublicResetPacketWithClientAddress) {
4565 QuicPublicResetPacket reset_packet;
4566 reset_packet.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
4567 reset_packet.public_header.reset_flag = true;
4568 reset_packet.public_header.version_flag = false;
4569 reset_packet.rejected_sequence_number = GG_UINT64_C(0x123456789ABC);
4570 reset_packet.nonce_proof = GG_UINT64_C(0xABCDEF0123456789);
4571 reset_packet.client_address = IPEndPoint(Loopback4(), 0x1234);
4573 unsigned char packet[] = {
4574 // public flags (public reset, 8 byte ConnectionId)
4575 0x0E,
4576 // connection_id
4577 0x10, 0x32, 0x54, 0x76,
4578 0x98, 0xBA, 0xDC, 0xFE,
4579 // message tag (kPRST)
4580 'P', 'R', 'S', 'T',
4581 // num_entries (3) + padding
4582 0x03, 0x00, 0x00, 0x00,
4583 // tag kRNON
4584 'R', 'N', 'O', 'N',
4585 // end offset 8
4586 0x08, 0x00, 0x00, 0x00,
4587 // tag kRSEQ
4588 'R', 'S', 'E', 'Q',
4589 // end offset 16
4590 0x10, 0x00, 0x00, 0x00,
4591 // tag kCADR
4592 'C', 'A', 'D', 'R',
4593 // end offset 24
4594 0x18, 0x00, 0x00, 0x00,
4595 // nonce proof
4596 0x89, 0x67, 0x45, 0x23,
4597 0x01, 0xEF, 0xCD, 0xAB,
4598 // rejected sequence number
4599 0xBC, 0x9A, 0x78, 0x56,
4600 0x34, 0x12, 0x00, 0x00,
4601 // client address
4602 0x02, 0x00,
4603 0x7F, 0x00, 0x00, 0x01,
4604 0x34, 0x12,
4607 scoped_ptr<QuicEncryptedPacket> data(
4608 framer_.BuildPublicResetPacket(reset_packet));
4609 ASSERT_TRUE(data != nullptr);
4611 test::CompareCharArraysWithHexError("constructed packet",
4612 data->data(), data->length(),
4613 AsChars(packet), arraysize(packet));
4616 TEST_P(QuicFramerTest, BuildFecPacket) {
4617 QuicPacketHeader header;
4618 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
4619 header.public_header.reset_flag = false;
4620 header.public_header.version_flag = false;
4621 header.fec_flag = true;
4622 header.entropy_flag = true;
4623 header.packet_sequence_number = (GG_UINT64_C(0x123456789ABC));
4624 header.is_in_fec_group = IN_FEC_GROUP;
4625 header.fec_group = GG_UINT64_C(0x123456789ABB);;
4627 QuicFecData fec_data;
4628 fec_data.fec_group = 1;
4629 fec_data.redundancy = "abcdefghijklmnop";
4631 unsigned char packet[] = {
4632 // public flags (8 byte connection_id)
4633 0x3C,
4634 // connection_id
4635 0x10, 0x32, 0x54, 0x76,
4636 0x98, 0xBA, 0xDC, 0xFE,
4637 // packet sequence number
4638 0xBC, 0x9A, 0x78, 0x56,
4639 0x34, 0x12,
4640 // private flags (entropy & fec group & fec packet)
4641 0x07,
4642 // first fec protected packet offset
4643 0x01,
4645 // redundancy
4646 'a', 'b', 'c', 'd',
4647 'e', 'f', 'g', 'h',
4648 'i', 'j', 'k', 'l',
4649 'm', 'n', 'o', 'p',
4652 scoped_ptr<QuicPacket> data(
4653 framer_.BuildFecPacket(header, fec_data).packet);
4654 ASSERT_TRUE(data != nullptr);
4656 test::CompareCharArraysWithHexError("constructed packet",
4657 data->data(), data->length(),
4658 AsChars(packet), arraysize(packet));
4661 TEST_P(QuicFramerTest, EncryptPacket) {
4662 QuicPacketSequenceNumber sequence_number = GG_UINT64_C(0x123456789ABC);
4663 unsigned char packet[] = {
4664 // public flags (8 byte connection_id)
4665 0x3C,
4666 // connection_id
4667 0x10, 0x32, 0x54, 0x76,
4668 0x98, 0xBA, 0xDC, 0xFE,
4669 // packet sequence number
4670 0xBC, 0x9A, 0x78, 0x56,
4671 0x34, 0x12,
4672 // private flags (fec group & fec packet)
4673 0x06,
4674 // first fec protected packet offset
4675 0x01,
4677 // redundancy
4678 'a', 'b', 'c', 'd',
4679 'e', 'f', 'g', 'h',
4680 'i', 'j', 'k', 'l',
4681 'm', 'n', 'o', 'p',
4684 scoped_ptr<QuicPacket> raw(
4685 QuicPacket::NewDataPacket(AsChars(packet), arraysize(packet), false,
4686 PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
4687 PACKET_6BYTE_SEQUENCE_NUMBER));
4688 scoped_ptr<QuicEncryptedPacket> encrypted(
4689 framer_.EncryptPacket(ENCRYPTION_NONE, sequence_number, *raw));
4691 ASSERT_TRUE(encrypted.get() != nullptr);
4692 EXPECT_TRUE(CheckEncryption(sequence_number, raw.get()));
4695 TEST_P(QuicFramerTest, EncryptPacketWithVersionFlag) {
4696 QuicPacketSequenceNumber sequence_number = GG_UINT64_C(0x123456789ABC);
4697 unsigned char packet[] = {
4698 // public flags (version, 8 byte connection_id)
4699 0x3D,
4700 // connection_id
4701 0x10, 0x32, 0x54, 0x76,
4702 0x98, 0xBA, 0xDC, 0xFE,
4703 // version tag
4704 'Q', '.', '1', '0',
4705 // packet sequence number
4706 0xBC, 0x9A, 0x78, 0x56,
4707 0x34, 0x12,
4708 // private flags (fec group & fec flags)
4709 0x06,
4710 // first fec protected packet offset
4711 0x01,
4713 // redundancy
4714 'a', 'b', 'c', 'd',
4715 'e', 'f', 'g', 'h',
4716 'i', 'j', 'k', 'l',
4717 'm', 'n', 'o', 'p',
4720 scoped_ptr<QuicPacket> raw(
4721 QuicPacket::NewDataPacket(AsChars(packet), arraysize(packet), false,
4722 PACKET_8BYTE_CONNECTION_ID, kIncludeVersion,
4723 PACKET_6BYTE_SEQUENCE_NUMBER));
4724 scoped_ptr<QuicEncryptedPacket> encrypted(
4725 framer_.EncryptPacket(ENCRYPTION_NONE, sequence_number, *raw));
4727 ASSERT_TRUE(encrypted.get() != nullptr);
4728 EXPECT_TRUE(CheckEncryption(sequence_number, raw.get()));
4731 TEST_P(QuicFramerTest, AckTruncationLargePacket) {
4732 QuicPacketHeader header;
4733 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
4734 header.public_header.reset_flag = false;
4735 header.public_header.version_flag = false;
4736 header.fec_flag = false;
4737 header.entropy_flag = false;
4738 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
4739 header.fec_group = 0;
4741 // Create a packet with just the ack.
4742 QuicAckFrame ack_frame = MakeAckFrameWithNackRanges(300, 0u);
4743 QuicFrame frame;
4744 frame.type = ACK_FRAME;
4745 frame.ack_frame = &ack_frame;
4746 QuicFrames frames;
4747 frames.push_back(frame);
4749 // Build an ack packet with truncation due to limit in number of nack ranges.
4750 scoped_ptr<QuicPacket> raw_ack_packet(
4751 framer_.BuildDataPacket(header, frames, kMaxPacketSize).packet);
4752 ASSERT_TRUE(raw_ack_packet != nullptr);
4753 scoped_ptr<QuicEncryptedPacket> ack_packet(
4754 framer_.EncryptPacket(ENCRYPTION_NONE, header.packet_sequence_number,
4755 *raw_ack_packet));
4756 // Now make sure we can turn our ack packet back into an ack frame.
4757 ASSERT_TRUE(framer_.ProcessPacket(*ack_packet));
4758 ASSERT_EQ(1u, visitor_.ack_frames_.size());
4759 QuicAckFrame& processed_ack_frame = *visitor_.ack_frames_[0];
4760 EXPECT_TRUE(processed_ack_frame.is_truncated);
4761 EXPECT_EQ(510u, processed_ack_frame.largest_observed);
4762 ASSERT_EQ(255u, processed_ack_frame.missing_packets.size());
4763 SequenceNumberSet::const_iterator missing_iter =
4764 processed_ack_frame.missing_packets.begin();
4765 EXPECT_EQ(1u, *missing_iter);
4766 SequenceNumberSet::const_reverse_iterator last_missing_iter =
4767 processed_ack_frame.missing_packets.rbegin();
4768 EXPECT_EQ(509u, *last_missing_iter);
4771 TEST_P(QuicFramerTest, AckTruncationSmallPacketv22) {
4772 if (version_ > QUIC_VERSION_22) {
4773 return;
4775 QuicPacketHeader header;
4776 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
4777 header.public_header.reset_flag = false;
4778 header.public_header.version_flag = false;
4779 header.fec_flag = false;
4780 header.entropy_flag = false;
4781 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
4782 header.fec_group = 0;
4784 // Create a packet with just the ack.
4785 QuicAckFrame ack_frame = MakeAckFrameWithNackRanges(300, 0u);
4786 QuicFrame frame;
4787 frame.type = ACK_FRAME;
4788 frame.ack_frame = &ack_frame;
4789 QuicFrames frames;
4790 frames.push_back(frame);
4792 // Build an ack packet with truncation due to limit in number of nack ranges.
4793 scoped_ptr<QuicPacket> raw_ack_packet(
4794 framer_.BuildDataPacket(header, frames, 500).packet);
4795 ASSERT_TRUE(raw_ack_packet != nullptr);
4796 scoped_ptr<QuicEncryptedPacket> ack_packet(
4797 framer_.EncryptPacket(ENCRYPTION_NONE, header.packet_sequence_number,
4798 *raw_ack_packet));
4799 // Now make sure we can turn our ack packet back into an ack frame.
4800 ASSERT_TRUE(framer_.ProcessPacket(*ack_packet));
4801 ASSERT_EQ(1u, visitor_.ack_frames_.size());
4802 QuicAckFrame& processed_ack_frame = *visitor_.ack_frames_[0];
4803 EXPECT_TRUE(processed_ack_frame.is_truncated);
4804 EXPECT_EQ(476u, processed_ack_frame.largest_observed);
4805 ASSERT_EQ(238u, processed_ack_frame.missing_packets.size());
4806 SequenceNumberSet::const_iterator missing_iter =
4807 processed_ack_frame.missing_packets.begin();
4808 EXPECT_EQ(1u, *missing_iter);
4809 SequenceNumberSet::const_reverse_iterator last_missing_iter =
4810 processed_ack_frame.missing_packets.rbegin();
4811 EXPECT_EQ(475u, *last_missing_iter);
4815 TEST_P(QuicFramerTest, AckTruncationSmallPacket) {
4816 if (version_ <= QUIC_VERSION_22) {
4817 return;
4819 QuicPacketHeader header;
4820 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
4821 header.public_header.reset_flag = false;
4822 header.public_header.version_flag = false;
4823 header.fec_flag = false;
4824 header.entropy_flag = false;
4825 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
4826 header.fec_group = 0;
4828 // Create a packet with just the ack.
4829 QuicAckFrame ack_frame = MakeAckFrameWithNackRanges(300, 0u);
4830 QuicFrame frame;
4831 frame.type = ACK_FRAME;
4832 frame.ack_frame = &ack_frame;
4833 QuicFrames frames;
4834 frames.push_back(frame);
4836 // Build an ack packet with truncation due to limit in number of nack ranges.
4837 scoped_ptr<QuicPacket> raw_ack_packet(
4838 framer_.BuildDataPacket(header, frames, 500).packet);
4839 ASSERT_TRUE(raw_ack_packet != nullptr);
4840 scoped_ptr<QuicEncryptedPacket> ack_packet(
4841 framer_.EncryptPacket(ENCRYPTION_NONE, header.packet_sequence_number,
4842 *raw_ack_packet));
4843 // Now make sure we can turn our ack packet back into an ack frame.
4844 ASSERT_TRUE(framer_.ProcessPacket(*ack_packet));
4845 ASSERT_EQ(1u, visitor_.ack_frames_.size());
4846 QuicAckFrame& processed_ack_frame = *visitor_.ack_frames_[0];
4847 EXPECT_TRUE(processed_ack_frame.is_truncated);
4848 EXPECT_EQ(476u, processed_ack_frame.largest_observed);
4849 ASSERT_EQ(238u, processed_ack_frame.missing_packets.size());
4850 SequenceNumberSet::const_iterator missing_iter =
4851 processed_ack_frame.missing_packets.begin();
4852 EXPECT_EQ(1u, *missing_iter);
4853 SequenceNumberSet::const_reverse_iterator last_missing_iter =
4854 processed_ack_frame.missing_packets.rbegin();
4855 EXPECT_EQ(475u, *last_missing_iter);
4858 TEST_P(QuicFramerTest, CleanTruncation) {
4859 QuicPacketHeader header;
4860 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
4861 header.public_header.reset_flag = false;
4862 header.public_header.version_flag = false;
4863 header.fec_flag = false;
4864 header.entropy_flag = true;
4865 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
4866 header.fec_group = 0;
4868 QuicAckFrame ack_frame;
4869 ack_frame.largest_observed = 201;
4870 for (uint64 i = 1; i < ack_frame.largest_observed; ++i) {
4871 ack_frame.missing_packets.insert(i);
4874 // Create a packet with just the ack.
4875 QuicFrame frame;
4876 frame.type = ACK_FRAME;
4877 frame.ack_frame = &ack_frame;
4878 QuicFrames frames;
4879 frames.push_back(frame);
4881 scoped_ptr<QuicPacket> raw_ack_packet(BuildDataPacket(header, frames));
4882 ASSERT_TRUE(raw_ack_packet != nullptr);
4884 scoped_ptr<QuicEncryptedPacket> ack_packet(
4885 framer_.EncryptPacket(ENCRYPTION_NONE, header.packet_sequence_number,
4886 *raw_ack_packet));
4888 // Now make sure we can turn our ack packet back into an ack frame.
4889 ASSERT_TRUE(framer_.ProcessPacket(*ack_packet));
4891 // Test for clean truncation of the ack by comparing the length of the
4892 // original packets to the re-serialized packets.
4893 frames.clear();
4894 frame.type = ACK_FRAME;
4895 frame.ack_frame = visitor_.ack_frames_[0];
4896 frames.push_back(frame);
4898 size_t original_raw_length = raw_ack_packet->length();
4899 raw_ack_packet.reset(BuildDataPacket(header, frames));
4900 ASSERT_TRUE(raw_ack_packet != nullptr);
4901 EXPECT_EQ(original_raw_length, raw_ack_packet->length());
4902 ASSERT_TRUE(raw_ack_packet != nullptr);
4905 TEST_P(QuicFramerTest, EntropyFlagTest) {
4906 unsigned char packet[] = {
4907 // public flags (8 byte connection_id)
4908 0x3C,
4909 // connection_id
4910 0x10, 0x32, 0x54, 0x76,
4911 0x98, 0xBA, 0xDC, 0xFE,
4912 // packet sequence number
4913 0xBC, 0x9A, 0x78, 0x56,
4914 0x34, 0x12,
4915 // private flags (Entropy)
4916 0x01,
4918 // frame type (stream frame with fin and no length)
4919 0xDF,
4920 // stream id
4921 0x04, 0x03, 0x02, 0x01,
4922 // offset
4923 0x54, 0x76, 0x10, 0x32,
4924 0xDC, 0xFE, 0x98, 0xBA,
4925 // data
4926 'h', 'e', 'l', 'l',
4927 'o', ' ', 'w', 'o',
4928 'r', 'l', 'd', '!',
4931 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
4932 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
4933 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
4934 ASSERT_TRUE(visitor_.header_.get());
4935 EXPECT_TRUE(visitor_.header_->entropy_flag);
4936 EXPECT_EQ(1 << 4, visitor_.header_->entropy_hash);
4937 EXPECT_FALSE(visitor_.header_->fec_flag);
4940 TEST_P(QuicFramerTest, FecEntropyTest) {
4941 unsigned char packet[] = {
4942 // public flags (8 byte connection_id)
4943 0x3C,
4944 // connection_id
4945 0x10, 0x32, 0x54, 0x76,
4946 0x98, 0xBA, 0xDC, 0xFE,
4947 // packet sequence number
4948 0xBC, 0x9A, 0x78, 0x56,
4949 0x34, 0x12,
4950 // private flags (Entropy & fec group & FEC)
4951 0x07,
4952 // first fec protected packet offset
4953 0xFF,
4955 // frame type (stream frame with fin and no length)
4956 0xDF,
4957 // stream id
4958 0x04, 0x03, 0x02, 0x01,
4959 // offset
4960 0x54, 0x76, 0x10, 0x32,
4961 0xDC, 0xFE, 0x98, 0xBA,
4962 // data
4963 'h', 'e', 'l', 'l',
4964 'o', ' ', 'w', 'o',
4965 'r', 'l', 'd', '!',
4968 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
4969 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
4970 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
4971 ASSERT_TRUE(visitor_.header_.get());
4972 EXPECT_TRUE(visitor_.header_->fec_flag);
4973 EXPECT_TRUE(visitor_.header_->entropy_flag);
4974 EXPECT_EQ(1 << 4, visitor_.header_->entropy_hash);
4977 TEST_P(QuicFramerTest, StopPacketProcessing) {
4978 unsigned char packet[] = {
4979 // public flags (8 byte connection_id)
4980 0x3C,
4981 // connection_id
4982 0x10, 0x32, 0x54, 0x76,
4983 0x98, 0xBA, 0xDC, 0xFE,
4984 // packet sequence number
4985 0xBC, 0x9A, 0x78, 0x56,
4986 0x34, 0x12,
4987 // Entropy
4988 0x01,
4990 // frame type (stream frame with fin)
4991 0xFF,
4992 // stream id
4993 0x04, 0x03, 0x02, 0x01,
4994 // offset
4995 0x54, 0x76, 0x10, 0x32,
4996 0xDC, 0xFE, 0x98, 0xBA,
4997 // data length
4998 0x0c, 0x00,
4999 // data
5000 'h', 'e', 'l', 'l',
5001 'o', ' ', 'w', 'o',
5002 'r', 'l', 'd', '!',
5004 // frame type (ack frame)
5005 0x40,
5006 // entropy hash of sent packets till least awaiting - 1.
5007 0x14,
5008 // least packet sequence number awaiting an ack
5009 0xA0, 0x9A, 0x78, 0x56,
5010 0x34, 0x12,
5011 // entropy hash of all received packets.
5012 0x43,
5013 // largest observed packet sequence number
5014 0xBF, 0x9A, 0x78, 0x56,
5015 0x34, 0x12,
5016 // num missing packets
5017 0x01,
5018 // missing packet
5019 0xBE, 0x9A, 0x78, 0x56,
5020 0x34, 0x12,
5023 MockFramerVisitor visitor;
5024 framer_.set_visitor(&visitor);
5025 EXPECT_CALL(visitor, OnPacket());
5026 EXPECT_CALL(visitor, OnPacketHeader(_));
5027 EXPECT_CALL(visitor, OnStreamFrame(_)).WillOnce(Return(false));
5028 EXPECT_CALL(visitor, OnAckFrame(_)).Times(0);
5029 EXPECT_CALL(visitor, OnPacketComplete());
5030 EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)).WillOnce(Return(true));
5032 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
5033 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
5034 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
5037 } // namespace test
5038 } // namespace net