Update V8 to version 4.7.42.
[chromium-blink-merge.git] / net / quic / quic_framer_test.cc
blob90524171151c42e829a904a84907e95649c1cdfc
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 <stdint.h>
8 #include <algorithm>
9 #include <map>
10 #include <string>
11 #include <vector>
13 #include "base/containers/hash_tables.h"
14 #include "base/logging.h"
15 #include "base/memory/scoped_ptr.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::Truly;
35 using testing::_;
37 namespace net {
38 namespace test {
40 const QuicPacketNumber kEpoch = UINT64_C(1) << 48;
41 const QuicPacketNumber kMask = kEpoch - 1;
43 // Index into the connection_id offset in the header.
44 const size_t kConnectionIdOffset = kPublicFlagsSize;
45 // Index into the version string in the header. (if present).
46 const size_t kVersionOffset = kConnectionIdOffset + PACKET_8BYTE_CONNECTION_ID;
48 // Size in bytes of the stream frame fields for an arbitrary StreamID and
49 // offset and the last frame in a packet.
50 size_t GetMinStreamFrameSize() {
51 return kQuicFrameTypeSize + kQuicMaxStreamIdSize + kQuicMaxStreamOffsetSize;
54 // Index into the packet number offset in the header.
55 size_t GetPacketNumberOffset(QuicConnectionIdLength connection_id_length,
56 bool include_version) {
57 return kConnectionIdOffset + connection_id_length +
58 (include_version ? kQuicVersionSize : 0);
61 size_t GetPacketNumberOffset(bool include_version) {
62 return GetPacketNumberOffset(PACKET_8BYTE_CONNECTION_ID, include_version);
65 // Index into the private flags offset in the data packet header.
66 size_t GetPrivateFlagsOffset(QuicConnectionIdLength connection_id_length,
67 bool include_version) {
68 return GetPacketNumberOffset(connection_id_length, include_version) +
69 PACKET_6BYTE_PACKET_NUMBER;
72 size_t GetPrivateFlagsOffset(bool include_version) {
73 return GetPrivateFlagsOffset(PACKET_8BYTE_CONNECTION_ID, include_version);
76 size_t GetPrivateFlagsOffset(bool include_version,
77 QuicPacketNumberLength packet_number_length) {
78 return GetPacketNumberOffset(PACKET_8BYTE_CONNECTION_ID, include_version) +
79 packet_number_length;
82 // Index into the fec group offset in the header.
83 size_t GetFecGroupOffset(QuicConnectionIdLength connection_id_length,
84 bool include_version) {
85 return GetPrivateFlagsOffset(connection_id_length, include_version) +
86 kPrivateFlagsSize;
89 size_t GetFecGroupOffset(bool include_version) {
90 return GetPrivateFlagsOffset(PACKET_8BYTE_CONNECTION_ID, include_version) +
91 kPrivateFlagsSize;
94 size_t GetFecGroupOffset(bool include_version,
95 QuicPacketNumberLength packet_number_length) {
96 return GetPrivateFlagsOffset(include_version, packet_number_length) +
97 kPrivateFlagsSize;
100 // Index into the message tag of the public reset packet.
101 // Public resets always have full connection_ids.
102 const size_t kPublicResetPacketMessageTagOffset =
103 kConnectionIdOffset + PACKET_8BYTE_CONNECTION_ID;
105 class TestEncrypter : public QuicEncrypter {
106 public:
107 ~TestEncrypter() override {}
108 bool SetKey(StringPiece key) override { return true; }
109 bool SetNoncePrefix(StringPiece nonce_prefix) override { return true; }
110 bool EncryptPacket(QuicPacketNumber packet_number,
111 StringPiece associated_data,
112 StringPiece plaintext,
113 char* output,
114 size_t* output_length,
115 size_t max_output_length) override {
116 packet_number_ = packet_number;
117 associated_data_ = associated_data.as_string();
118 plaintext_ = plaintext.as_string();
119 memcpy(output, plaintext.data(), plaintext.length());
120 *output_length = plaintext.length();
121 return true;
123 size_t GetKeySize() const override { return 0; }
124 size_t GetNoncePrefixSize() const override { return 0; }
125 size_t GetMaxPlaintextSize(size_t ciphertext_size) const override {
126 return ciphertext_size;
128 size_t GetCiphertextSize(size_t plaintext_size) const override {
129 return plaintext_size;
131 StringPiece GetKey() const override { return StringPiece(); }
132 StringPiece GetNoncePrefix() const override { return StringPiece(); }
133 QuicPacketNumber packet_number_;
134 string associated_data_;
135 string plaintext_;
138 class TestDecrypter : public QuicDecrypter {
139 public:
140 ~TestDecrypter() override {}
141 bool SetKey(StringPiece key) override { return true; }
142 bool SetNoncePrefix(StringPiece nonce_prefix) override { return true; }
143 bool DecryptPacket(QuicPacketNumber packet_number,
144 const StringPiece& associated_data,
145 const StringPiece& ciphertext,
146 char* output,
147 size_t* output_length,
148 size_t max_output_length) override {
149 packet_number_ = packet_number;
150 associated_data_ = associated_data.as_string();
151 ciphertext_ = ciphertext.as_string();
152 memcpy(output, ciphertext.data(), ciphertext.length());
153 *output_length = ciphertext.length();
154 return true;
156 StringPiece GetKey() const override { return StringPiece(); }
157 StringPiece GetNoncePrefix() const override { return StringPiece(); }
158 const char* cipher_name() const override { return "Test"; }
159 // Use a distinct value starting with 0xFFFFFF, which is never used by TLS.
160 uint32 cipher_id() const override { return 0xFFFFFFF2; }
161 QuicPacketNumber packet_number_;
162 string associated_data_;
163 string ciphertext_;
166 class TestQuicVisitor : public QuicFramerVisitorInterface {
167 public:
168 TestQuicVisitor()
169 : error_count_(0),
170 version_mismatch_(0),
171 packet_count_(0),
172 frame_count_(0),
173 fec_count_(0),
174 complete_packets_(0),
175 revived_packets_(0),
176 accept_packet_(true),
177 accept_public_header_(true) {
180 ~TestQuicVisitor() override {
181 STLDeleteElements(&stream_frames_);
182 STLDeleteElements(&ack_frames_);
183 STLDeleteElements(&stop_waiting_frames_);
184 STLDeleteElements(&ping_frames_);
185 STLDeleteElements(&fec_data_);
186 STLDeleteElements(&stream_data_);
187 STLDeleteElements(&fec_data_redundancy_);
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 // Save a copy of the data so it is valid after the packet is processed.
236 string* string_data = new string();
237 frame.data.AppendToString(string_data);
238 stream_data_.push_back(string_data);
239 QuicStreamFrame* stream_frame = new QuicStreamFrame(frame);
240 // Make sure that the stream frame points to this data.
241 stream_frame->data = StringPiece(*string_data);
242 stream_frames_.push_back(stream_frame);
243 return true;
246 void OnFecProtectedPayload(StringPiece payload) override {
247 fec_protected_payload_ = payload.as_string();
250 bool OnAckFrame(const QuicAckFrame& frame) override {
251 ++frame_count_;
252 ack_frames_.push_back(new QuicAckFrame(frame));
253 return true;
256 bool OnStopWaitingFrame(const QuicStopWaitingFrame& frame) override {
257 ++frame_count_;
258 stop_waiting_frames_.push_back(new QuicStopWaitingFrame(frame));
259 return true;
262 bool OnPingFrame(const QuicPingFrame& frame) override {
263 ++frame_count_;
264 ping_frames_.push_back(new QuicPingFrame(frame));
265 return true;
268 void OnFecData(const QuicFecData& fec) override {
269 ++fec_count_;
270 QuicFecData* fec_data = new QuicFecData();
271 fec_data->fec_group = fec.fec_group;
272 // Save a copy of the data so it is valid after the packet is processed.
273 string* redundancy = new string(fec.redundancy.as_string());
274 fec_data_redundancy_.push_back(redundancy);
275 fec_data->redundancy = StringPiece(*redundancy);
276 fec_data_.push_back(fec_data);
279 void OnPacketComplete() override { ++complete_packets_; }
281 bool OnRstStreamFrame(const QuicRstStreamFrame& frame) override {
282 rst_stream_frame_ = frame;
283 return true;
286 bool OnConnectionCloseFrame(const QuicConnectionCloseFrame& frame) override {
287 connection_close_frame_ = frame;
288 return true;
291 bool OnGoAwayFrame(const QuicGoAwayFrame& frame) override {
292 goaway_frame_ = frame;
293 return true;
296 bool OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) override {
297 window_update_frame_ = frame;
298 return true;
301 bool OnBlockedFrame(const QuicBlockedFrame& frame) override {
302 blocked_frame_ = frame;
303 return true;
306 // Counters from the visitor_ callbacks.
307 int error_count_;
308 int version_mismatch_;
309 int packet_count_;
310 int frame_count_;
311 int fec_count_;
312 int complete_packets_;
313 int revived_packets_;
314 bool accept_packet_;
315 bool accept_public_header_;
317 scoped_ptr<QuicPacketHeader> header_;
318 scoped_ptr<QuicPacketPublicHeader> public_header_;
319 scoped_ptr<QuicPublicResetPacket> public_reset_packet_;
320 scoped_ptr<QuicVersionNegotiationPacket> version_negotiation_packet_;
321 vector<QuicStreamFrame*> stream_frames_;
322 vector<QuicAckFrame*> ack_frames_;
323 vector<QuicStopWaitingFrame*> stop_waiting_frames_;
324 vector<QuicPingFrame*> ping_frames_;
325 vector<QuicFecData*> fec_data_;
326 string fec_protected_payload_;
327 QuicRstStreamFrame rst_stream_frame_;
328 QuicConnectionCloseFrame connection_close_frame_;
329 QuicGoAwayFrame goaway_frame_;
330 QuicWindowUpdateFrame window_update_frame_;
331 QuicBlockedFrame blocked_frame_;
332 vector<string*> stream_data_;
333 vector<string*> fec_data_redundancy_;
336 class QuicFramerTest : public ::testing::TestWithParam<QuicVersion> {
337 public:
338 QuicFramerTest()
339 : encrypter_(new test::TestEncrypter()),
340 decrypter_(new test::TestDecrypter()),
341 start_(QuicTime::Zero().Add(QuicTime::Delta::FromMicroseconds(0x10))),
342 framer_(QuicSupportedVersions(), start_, Perspective::IS_SERVER) {
343 version_ = GetParam();
344 framer_.set_version(version_);
345 framer_.SetDecrypter(ENCRYPTION_NONE, decrypter_);
346 framer_.SetEncrypter(ENCRYPTION_NONE, encrypter_);
347 framer_.set_visitor(&visitor_);
348 framer_.set_received_entropy_calculator(&entropy_calculator_);
351 // Helper function to get unsigned char representation of digit in the
352 // units place of the current QUIC version number.
353 unsigned char GetQuicVersionDigitOnes() {
354 return static_cast<unsigned char> ('0' + version_%10);
357 // Helper function to get unsigned char representation of digit in the
358 // tens place of the current QUIC version number.
359 unsigned char GetQuicVersionDigitTens() {
360 return static_cast<unsigned char> ('0' + (version_/10)%10);
363 bool CheckEncryption(QuicPacketNumber packet_number, QuicPacket* packet) {
364 if (packet_number != encrypter_->packet_number_) {
365 LOG(ERROR) << "Encrypted incorrect packet number. expected "
366 << packet_number << " actual: " << encrypter_->packet_number_;
367 return false;
369 if (packet->AssociatedData() != encrypter_->associated_data_) {
370 LOG(ERROR) << "Encrypted incorrect associated data. expected "
371 << packet->AssociatedData() << " actual: "
372 << encrypter_->associated_data_;
373 return false;
375 if (packet->Plaintext() != encrypter_->plaintext_) {
376 LOG(ERROR) << "Encrypted incorrect plaintext data. expected "
377 << packet->Plaintext() << " actual: "
378 << encrypter_->plaintext_;
379 return false;
381 return true;
384 bool CheckDecryption(const QuicEncryptedPacket& encrypted,
385 bool includes_version) {
386 if (visitor_.header_->packet_packet_number != decrypter_->packet_number_) {
387 LOG(ERROR) << "Decrypted incorrect packet number. expected "
388 << visitor_.header_->packet_packet_number
389 << " actual: " << decrypter_->packet_number_;
390 return false;
392 if (QuicFramer::GetAssociatedDataFromEncryptedPacket(
393 encrypted, PACKET_8BYTE_CONNECTION_ID, includes_version,
394 PACKET_6BYTE_PACKET_NUMBER) != decrypter_->associated_data_) {
395 LOG(ERROR) << "Decrypted incorrect associated data. expected "
396 << QuicFramer::GetAssociatedDataFromEncryptedPacket(
397 encrypted, PACKET_8BYTE_CONNECTION_ID, includes_version,
398 PACKET_6BYTE_PACKET_NUMBER)
399 << " actual: " << decrypter_->associated_data_;
400 return false;
402 StringPiece ciphertext(encrypted.AsStringPiece().substr(
403 GetStartOfEncryptedData(PACKET_8BYTE_CONNECTION_ID, includes_version,
404 PACKET_6BYTE_PACKET_NUMBER)));
405 if (ciphertext != decrypter_->ciphertext_) {
406 LOG(ERROR) << "Decrypted incorrect ciphertext data. expected "
407 << ciphertext << " actual: "
408 << decrypter_->ciphertext_;
409 return false;
411 return true;
414 char* AsChars(unsigned char* data) {
415 return reinterpret_cast<char*>(data);
418 void CheckProcessingFails(unsigned char* packet,
419 size_t len,
420 string expected_error,
421 QuicErrorCode error_code) {
422 QuicEncryptedPacket encrypted(AsChars(packet), len, false);
423 EXPECT_FALSE(framer_.ProcessPacket(encrypted)) << "len: " << len;
424 EXPECT_EQ(expected_error, framer_.detailed_error()) << "len: " << len;
425 EXPECT_EQ(error_code, framer_.error()) << "len: " << len;
428 // Checks if the supplied string matches data in the supplied StreamFrame.
429 void CheckStreamFrameData(string str, QuicStreamFrame* frame) {
430 EXPECT_EQ(str, frame->data);
433 void CheckStreamFrameBoundaries(unsigned char* packet,
434 size_t stream_id_size,
435 bool include_version) {
436 // Now test framing boundaries.
437 for (size_t i = kQuicFrameTypeSize; i < GetMinStreamFrameSize(); ++i) {
438 string expected_error;
439 if (i < kQuicFrameTypeSize + stream_id_size) {
440 expected_error = "Unable to read stream_id.";
441 } else if (i < kQuicFrameTypeSize + stream_id_size +
442 kQuicMaxStreamOffsetSize) {
443 expected_error = "Unable to read offset.";
444 } else {
445 expected_error = "Unable to read frame data.";
447 CheckProcessingFails(
448 packet,
449 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, include_version,
450 PACKET_6BYTE_PACKET_NUMBER, NOT_IN_FEC_GROUP),
451 expected_error, QUIC_INVALID_STREAM_DATA);
455 void CheckCalculatePacketNumber(QuicPacketNumber expected_packet_number,
456 QuicPacketNumber last_packet_number) {
457 QuicPacketNumber wire_packet_number = expected_packet_number & kMask;
458 QuicFramerPeer::SetLastPacketNumber(&framer_, last_packet_number);
459 EXPECT_EQ(expected_packet_number,
460 QuicFramerPeer::CalculatePacketNumberFromWire(
461 &framer_, PACKET_6BYTE_PACKET_NUMBER, wire_packet_number))
462 << "last_packet_number: " << last_packet_number
463 << " wire_packet_number: " << wire_packet_number;
466 QuicPacket* BuildDataPacket(const QuicPacketHeader& header,
467 const QuicFrames& frames) {
468 return BuildUnsizedDataPacket(&framer_, header, frames);
471 QuicPacket* BuildDataPacket(const QuicPacketHeader& header,
472 const QuicFrames& frames,
473 size_t packet_size) {
474 return BuildUnsizedDataPacket(&framer_, header, frames, packet_size);
477 test::TestEncrypter* encrypter_;
478 test::TestDecrypter* decrypter_;
479 QuicVersion version_;
480 QuicTime start_;
481 QuicFramer framer_;
482 test::TestQuicVisitor visitor_;
483 test::TestEntropyCalculator entropy_calculator_;
486 // Run all framer tests with all supported versions of QUIC.
487 INSTANTIATE_TEST_CASE_P(QuicFramerTests,
488 QuicFramerTest,
489 ::testing::ValuesIn(kSupportedQuicVersions));
491 TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearEpochStart) {
492 // A few quick manual sanity checks.
493 CheckCalculatePacketNumber(UINT64_C(1), UINT64_C(0));
494 CheckCalculatePacketNumber(kEpoch + 1, kMask);
495 CheckCalculatePacketNumber(kEpoch, kMask);
497 // Cases where the last number was close to the start of the range.
498 for (uint64 last = 0; last < 10; last++) {
499 // Small numbers should not wrap (even if they're out of order).
500 for (uint64 j = 0; j < 10; j++) {
501 CheckCalculatePacketNumber(j, last);
504 // Large numbers should not wrap either (because we're near 0 already).
505 for (uint64 j = 0; j < 10; j++) {
506 CheckCalculatePacketNumber(kEpoch - 1 - j, last);
511 TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearEpochEnd) {
512 // Cases where the last number was close to the end of the range
513 for (uint64 i = 0; i < 10; i++) {
514 QuicPacketNumber last = kEpoch - i;
516 // Small numbers should wrap.
517 for (uint64 j = 0; j < 10; j++) {
518 CheckCalculatePacketNumber(kEpoch + j, last);
521 // Large numbers should not (even if they're out of order).
522 for (uint64 j = 0; j < 10; j++) {
523 CheckCalculatePacketNumber(kEpoch - 1 - j, last);
528 // Next check where we're in a non-zero epoch to verify we handle
529 // reverse wrapping, too.
530 TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearPrevEpoch) {
531 const uint64 prev_epoch = 1 * kEpoch;
532 const uint64 cur_epoch = 2 * kEpoch;
533 // Cases where the last number was close to the start of the range
534 for (uint64 i = 0; i < 10; i++) {
535 uint64 last = cur_epoch + i;
536 // Small number should not wrap (even if they're out of order).
537 for (uint64 j = 0; j < 10; j++) {
538 CheckCalculatePacketNumber(cur_epoch + j, last);
541 // But large numbers should reverse wrap.
542 for (uint64 j = 0; j < 10; j++) {
543 uint64 num = kEpoch - 1 - j;
544 CheckCalculatePacketNumber(prev_epoch + num, last);
549 TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearNextEpoch) {
550 const uint64 cur_epoch = 2 * kEpoch;
551 const uint64 next_epoch = 3 * kEpoch;
552 // Cases where the last number was close to the end of the range
553 for (uint64 i = 0; i < 10; i++) {
554 QuicPacketNumber last = next_epoch - 1 - i;
556 // Small numbers should wrap.
557 for (uint64 j = 0; j < 10; j++) {
558 CheckCalculatePacketNumber(next_epoch + j, last);
561 // but large numbers should not (even if they're out of order).
562 for (uint64 j = 0; j < 10; j++) {
563 uint64 num = kEpoch - 1 - j;
564 CheckCalculatePacketNumber(cur_epoch + num, last);
569 TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearNextMax) {
570 const uint64 max_number = numeric_limits<uint64>::max();
571 const uint64 max_epoch = max_number & ~kMask;
573 // Cases where the last number was close to the end of the range
574 for (uint64 i = 0; i < 10; i++) {
575 // Subtract 1, because the expected next packet number is 1 more than the
576 // last packet number.
577 QuicPacketNumber last = max_number - i - 1;
579 // Small numbers should not wrap, because they have nowhere to go.
580 for (uint64 j = 0; j < 10; j++) {
581 CheckCalculatePacketNumber(max_epoch + j, last);
584 // Large numbers should not wrap either.
585 for (uint64 j = 0; j < 10; j++) {
586 uint64 num = kEpoch - 1 - j;
587 CheckCalculatePacketNumber(max_epoch + num, last);
592 TEST_P(QuicFramerTest, EmptyPacket) {
593 char packet[] = { 0x00 };
594 QuicEncryptedPacket encrypted(packet, 0, false);
595 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
596 EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error());
599 TEST_P(QuicFramerTest, LargePacket) {
600 // clang-format off
601 unsigned char packet[kMaxPacketSize + 1] = {
602 // public flags (8 byte connection_id)
603 0x3C,
604 // connection_id
605 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
606 // packet number
607 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
608 // private flags
609 0x00,
612 memset(packet + GetPacketHeaderSize(
613 PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
614 PACKET_6BYTE_PACKET_NUMBER, NOT_IN_FEC_GROUP), 0,
615 kMaxPacketSize - GetPacketHeaderSize(
616 PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
617 PACKET_6BYTE_PACKET_NUMBER, NOT_IN_FEC_GROUP) + 1);
618 // clang-format on
620 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
621 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
623 ASSERT_TRUE(visitor_.header_.get());
624 // Make sure we've parsed the packet header, so we can send an error.
625 EXPECT_EQ(UINT64_C(0xFEDCBA9876543210),
626 visitor_.header_->public_header.connection_id);
627 // Make sure the correct error is propagated.
628 EXPECT_EQ(QUIC_PACKET_TOO_LARGE, framer_.error());
631 TEST_P(QuicFramerTest, PacketHeader) {
632 // clang-format off
633 unsigned char packet[] = {
634 // public flags (8 byte connection_id)
635 0x3C,
636 // connection_id
637 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
638 // packet number
639 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
640 // private flags
641 0x00,
643 // clang-format on
645 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
646 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
647 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
648 ASSERT_TRUE(visitor_.header_.get());
649 EXPECT_EQ(UINT64_C(0xFEDCBA9876543210),
650 visitor_.header_->public_header.connection_id);
651 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
652 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
653 EXPECT_FALSE(visitor_.header_->fec_flag);
654 EXPECT_FALSE(visitor_.header_->entropy_flag);
655 EXPECT_EQ(0, visitor_.header_->entropy_hash);
656 EXPECT_EQ(UINT64_C(0x123456789ABC), visitor_.header_->packet_packet_number);
657 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
658 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
660 // Now test framing boundaries.
661 for (size_t i = 0;
662 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
663 PACKET_6BYTE_PACKET_NUMBER, NOT_IN_FEC_GROUP);
664 ++i) {
665 string expected_error;
666 if (i < kConnectionIdOffset) {
667 expected_error = "Unable to read public flags.";
668 } else if (i < GetPacketNumberOffset(!kIncludeVersion)) {
669 expected_error = "Unable to read ConnectionId.";
670 } else if (i < GetPrivateFlagsOffset(!kIncludeVersion)) {
671 expected_error = "Unable to read packet number.";
672 } else if (i < GetFecGroupOffset(!kIncludeVersion)) {
673 expected_error = "Unable to read private flags.";
674 } else {
675 expected_error = "Unable to read first fec protected packet offset.";
677 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER);
681 TEST_P(QuicFramerTest, PacketHeaderWith4ByteConnectionId) {
682 QuicFramerPeer::SetLastSerializedConnectionId(
683 &framer_, UINT64_C(0xFEDCBA9876543210));
685 // clang-format off
686 unsigned char packet[] = {
687 // public flags (4 byte connection_id)
688 0x38,
689 // connection_id
690 0x10, 0x32, 0x54, 0x76,
691 // packet number
692 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
693 // private flags
694 0x00,
696 // clang-format on
698 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
699 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
700 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
701 ASSERT_TRUE(visitor_.header_.get());
702 EXPECT_EQ(UINT64_C(0xFEDCBA9876543210),
703 visitor_.header_->public_header.connection_id);
704 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
705 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
706 EXPECT_FALSE(visitor_.header_->fec_flag);
707 EXPECT_FALSE(visitor_.header_->entropy_flag);
708 EXPECT_EQ(0, visitor_.header_->entropy_hash);
709 EXPECT_EQ(UINT64_C(0x123456789ABC), visitor_.header_->packet_packet_number);
710 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
711 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
713 // Now test framing boundaries.
714 for (size_t i = 0;
715 i < GetPacketHeaderSize(PACKET_4BYTE_CONNECTION_ID, !kIncludeVersion,
716 PACKET_6BYTE_PACKET_NUMBER, NOT_IN_FEC_GROUP);
717 ++i) {
718 string expected_error;
719 if (i < kConnectionIdOffset) {
720 expected_error = "Unable to read public flags.";
721 } else if (i < GetPacketNumberOffset(PACKET_4BYTE_CONNECTION_ID,
722 !kIncludeVersion)) {
723 expected_error = "Unable to read ConnectionId.";
724 } else if (i < GetPrivateFlagsOffset(PACKET_4BYTE_CONNECTION_ID,
725 !kIncludeVersion)) {
726 expected_error = "Unable to read packet number.";
727 } else if (i < GetFecGroupOffset(PACKET_4BYTE_CONNECTION_ID,
728 !kIncludeVersion)) {
729 expected_error = "Unable to read private flags.";
730 } else {
731 expected_error = "Unable to read first fec protected packet offset.";
733 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER);
737 TEST_P(QuicFramerTest, PacketHeader1ByteConnectionId) {
738 QuicFramerPeer::SetLastSerializedConnectionId(
739 &framer_, UINT64_C(0xFEDCBA9876543210));
741 // clang-format off
742 unsigned char packet[] = {
743 // public flags (1 byte connection_id)
744 0x34,
745 // connection_id
746 0x10,
747 // packet number
748 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
749 // private flags
750 0x00,
752 // clang-format on
754 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
755 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
756 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
757 ASSERT_TRUE(visitor_.header_.get());
758 EXPECT_EQ(UINT64_C(0xFEDCBA9876543210),
759 visitor_.header_->public_header.connection_id);
760 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
761 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
762 EXPECT_FALSE(visitor_.header_->fec_flag);
763 EXPECT_FALSE(visitor_.header_->entropy_flag);
764 EXPECT_EQ(0, visitor_.header_->entropy_hash);
765 EXPECT_EQ(UINT64_C(0x123456789ABC), visitor_.header_->packet_packet_number);
766 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
767 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
769 // Now test framing boundaries.
770 for (size_t i = 0;
771 i < GetPacketHeaderSize(PACKET_1BYTE_CONNECTION_ID, !kIncludeVersion,
772 PACKET_6BYTE_PACKET_NUMBER, NOT_IN_FEC_GROUP);
773 ++i) {
774 string expected_error;
775 if (i < kConnectionIdOffset) {
776 expected_error = "Unable to read public flags.";
777 } else if (i < GetPacketNumberOffset(PACKET_1BYTE_CONNECTION_ID,
778 !kIncludeVersion)) {
779 expected_error = "Unable to read ConnectionId.";
780 } else if (i < GetPrivateFlagsOffset(PACKET_1BYTE_CONNECTION_ID,
781 !kIncludeVersion)) {
782 expected_error = "Unable to read packet number.";
783 } else if (i < GetFecGroupOffset(PACKET_1BYTE_CONNECTION_ID,
784 !kIncludeVersion)) {
785 expected_error = "Unable to read private flags.";
786 } else {
787 expected_error = "Unable to read first fec protected packet offset.";
789 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER);
793 TEST_P(QuicFramerTest, PacketHeaderWith0ByteConnectionId) {
794 QuicFramerPeer::SetLastSerializedConnectionId(
795 &framer_, UINT64_C(0xFEDCBA9876543210));
797 // clang-format off
798 unsigned char packet[] = {
799 // public flags (0 byte connection_id)
800 0x30,
801 // connection_id
802 // packet number
803 0xBC, 0x9A, 0x78, 0x56,
804 0x34, 0x12,
805 // private flags
806 0x00,
808 // clang-format on
810 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
811 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
812 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
813 ASSERT_TRUE(visitor_.header_.get());
814 EXPECT_EQ(UINT64_C(0xFEDCBA9876543210),
815 visitor_.header_->public_header.connection_id);
816 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
817 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
818 EXPECT_FALSE(visitor_.header_->fec_flag);
819 EXPECT_FALSE(visitor_.header_->entropy_flag);
820 EXPECT_EQ(0, visitor_.header_->entropy_hash);
821 EXPECT_EQ(UINT64_C(0x123456789ABC), visitor_.header_->packet_packet_number);
822 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
823 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
825 // Now test framing boundaries.
826 for (size_t i = 0;
827 i < GetPacketHeaderSize(PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion,
828 PACKET_6BYTE_PACKET_NUMBER, NOT_IN_FEC_GROUP);
829 ++i) {
830 string expected_error;
831 if (i < kConnectionIdOffset) {
832 expected_error = "Unable to read public flags.";
833 } else if (i < GetPacketNumberOffset(PACKET_0BYTE_CONNECTION_ID,
834 !kIncludeVersion)) {
835 expected_error = "Unable to read ConnectionId.";
836 } else if (i < GetPrivateFlagsOffset(PACKET_0BYTE_CONNECTION_ID,
837 !kIncludeVersion)) {
838 expected_error = "Unable to read packet number.";
839 } else if (i < GetFecGroupOffset(PACKET_0BYTE_CONNECTION_ID,
840 !kIncludeVersion)) {
841 expected_error = "Unable to read private flags.";
842 } else {
843 expected_error = "Unable to read first fec protected packet offset.";
845 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER);
849 TEST_P(QuicFramerTest, PacketHeaderWithVersionFlag) {
850 // clang-format off
851 unsigned char packet[] = {
852 // public flags (version)
853 0x3D,
854 // connection_id
855 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
856 // version tag
857 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
858 // packet number
859 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
860 // private flags
861 0x00,
863 // clang-format on
865 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
866 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
867 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
868 ASSERT_TRUE(visitor_.header_.get());
869 EXPECT_EQ(UINT64_C(0xFEDCBA9876543210),
870 visitor_.header_->public_header.connection_id);
871 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
872 EXPECT_TRUE(visitor_.header_->public_header.version_flag);
873 EXPECT_EQ(GetParam(), visitor_.header_->public_header.versions[0]);
874 EXPECT_FALSE(visitor_.header_->fec_flag);
875 EXPECT_FALSE(visitor_.header_->entropy_flag);
876 EXPECT_EQ(0, visitor_.header_->entropy_hash);
877 EXPECT_EQ(UINT64_C(0x123456789ABC), visitor_.header_->packet_packet_number);
878 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
879 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
881 // Now test framing boundaries.
882 for (size_t i = 0;
883 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, kIncludeVersion,
884 PACKET_6BYTE_PACKET_NUMBER, NOT_IN_FEC_GROUP);
885 ++i) {
886 string expected_error;
887 if (i < kConnectionIdOffset) {
888 expected_error = "Unable to read public flags.";
889 } else if (i < kVersionOffset) {
890 expected_error = "Unable to read ConnectionId.";
891 } else if (i < GetPacketNumberOffset(kIncludeVersion)) {
892 expected_error = "Unable to read protocol version.";
893 } else if (i < GetPrivateFlagsOffset(kIncludeVersion)) {
894 expected_error = "Unable to read packet number.";
895 } else if (i < GetFecGroupOffset(kIncludeVersion)) {
896 expected_error = "Unable to read private flags.";
897 } else {
898 expected_error = "Unable to read first fec protected packet offset.";
900 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER);
904 TEST_P(QuicFramerTest, PacketHeaderWith4BytePacketNumber) {
905 QuicFramerPeer::SetLastPacketNumber(&framer_, UINT64_C(0x123456789ABA));
907 // clang-format off
908 unsigned char packet[] = {
909 // public flags (8 byte connection_id and 4 byte packet number)
910 0x2C,
911 // connection_id
912 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
913 // packet number
914 0xBC, 0x9A, 0x78, 0x56,
915 // private flags
916 0x00,
918 // clang-format on
920 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
921 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
922 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
923 ASSERT_TRUE(visitor_.header_.get());
924 EXPECT_EQ(UINT64_C(0xFEDCBA9876543210),
925 visitor_.header_->public_header.connection_id);
926 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
927 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
928 EXPECT_FALSE(visitor_.header_->fec_flag);
929 EXPECT_FALSE(visitor_.header_->entropy_flag);
930 EXPECT_EQ(0, visitor_.header_->entropy_hash);
931 EXPECT_EQ(UINT64_C(0x123456789ABC), visitor_.header_->packet_packet_number);
932 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
933 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
935 // Now test framing boundaries.
936 for (size_t i = 0;
937 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
938 PACKET_4BYTE_PACKET_NUMBER, NOT_IN_FEC_GROUP);
939 ++i) {
940 string expected_error;
941 if (i < kConnectionIdOffset) {
942 expected_error = "Unable to read public flags.";
943 } else if (i < GetPacketNumberOffset(!kIncludeVersion)) {
944 expected_error = "Unable to read ConnectionId.";
945 } else if (i < GetPrivateFlagsOffset(!kIncludeVersion,
946 PACKET_4BYTE_PACKET_NUMBER)) {
947 expected_error = "Unable to read packet number.";
948 } else if (i < GetFecGroupOffset(!kIncludeVersion,
949 PACKET_4BYTE_PACKET_NUMBER)) {
950 expected_error = "Unable to read private flags.";
951 } else {
952 expected_error = "Unable to read first fec protected packet offset.";
954 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER);
958 TEST_P(QuicFramerTest, PacketHeaderWith2BytePacketNumber) {
959 QuicFramerPeer::SetLastPacketNumber(&framer_, UINT64_C(0x123456789ABA));
961 // clang-format off
962 unsigned char packet[] = {
963 // public flags (8 byte connection_id and 2 byte packet number)
964 0x1C,
965 // connection_id
966 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
967 // packet number
968 0xBC, 0x9A,
969 // private flags
970 0x00,
972 // clang-format on
974 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
975 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
976 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
977 ASSERT_TRUE(visitor_.header_.get());
978 EXPECT_EQ(UINT64_C(0xFEDCBA9876543210),
979 visitor_.header_->public_header.connection_id);
980 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
981 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
982 EXPECT_FALSE(visitor_.header_->fec_flag);
983 EXPECT_FALSE(visitor_.header_->entropy_flag);
984 EXPECT_EQ(0, visitor_.header_->entropy_hash);
985 EXPECT_EQ(UINT64_C(0x123456789ABC), visitor_.header_->packet_packet_number);
986 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
987 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
989 // Now test framing boundaries.
990 for (size_t i = 0;
991 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
992 PACKET_2BYTE_PACKET_NUMBER, NOT_IN_FEC_GROUP);
993 ++i) {
994 string expected_error;
995 if (i < kConnectionIdOffset) {
996 expected_error = "Unable to read public flags.";
997 } else if (i < GetPacketNumberOffset(!kIncludeVersion)) {
998 expected_error = "Unable to read ConnectionId.";
999 } else if (i < GetPrivateFlagsOffset(!kIncludeVersion,
1000 PACKET_2BYTE_PACKET_NUMBER)) {
1001 expected_error = "Unable to read packet number.";
1002 } else if (i < GetFecGroupOffset(!kIncludeVersion,
1003 PACKET_2BYTE_PACKET_NUMBER)) {
1004 expected_error = "Unable to read private flags.";
1005 } else {
1006 expected_error = "Unable to read first fec protected packet offset.";
1008 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER);
1012 TEST_P(QuicFramerTest, PacketHeaderWith1BytePacketNumber) {
1013 QuicFramerPeer::SetLastPacketNumber(&framer_, UINT64_C(0x123456789ABA));
1015 // clang-format off
1016 unsigned char packet[] = {
1017 // public flags (8 byte connection_id and 1 byte packet number)
1018 0x0C,
1019 // connection_id
1020 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
1021 // packet number
1022 0xBC,
1023 // private flags
1024 0x00,
1026 // clang-format on
1028 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1029 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
1030 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
1031 ASSERT_TRUE(visitor_.header_.get());
1032 EXPECT_EQ(UINT64_C(0xFEDCBA9876543210),
1033 visitor_.header_->public_header.connection_id);
1034 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
1035 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
1036 EXPECT_FALSE(visitor_.header_->fec_flag);
1037 EXPECT_FALSE(visitor_.header_->entropy_flag);
1038 EXPECT_EQ(0, visitor_.header_->entropy_hash);
1039 EXPECT_EQ(UINT64_C(0x123456789ABC), visitor_.header_->packet_packet_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_PACKET_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 < GetPacketNumberOffset(!kIncludeVersion)) {
1052 expected_error = "Unable to read ConnectionId.";
1053 } else if (i < GetPrivateFlagsOffset(!kIncludeVersion,
1054 PACKET_1BYTE_PACKET_NUMBER)) {
1055 expected_error = "Unable to read packet number.";
1056 } else if (i < GetFecGroupOffset(!kIncludeVersion,
1057 PACKET_1BYTE_PACKET_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 // clang-format off
1068 unsigned char packet[] = {
1069 // public flags: all flags set but the public reset flag and version flag.
1070 0xFC,
1071 // connection_id
1072 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
1073 // packet number
1074 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
1075 // private flags
1076 0x00,
1078 // frame type (padding)
1079 0x00,
1080 0x00, 0x00, 0x00, 0x00
1082 // clang-format on
1084 CheckProcessingFails(packet,
1085 arraysize(packet),
1086 "Illegal public flags value.",
1087 QUIC_INVALID_PACKET_HEADER);
1089 // Now turn off validation.
1090 framer_.set_validate_flags(false);
1091 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1092 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1095 TEST_P(QuicFramerTest, InvalidPublicFlagWithMatchingVersions) {
1096 // clang-format off
1097 unsigned char packet[] = {
1098 // public flags (8 byte connection_id and version flag and an unknown flag)
1099 0x4D,
1100 // connection_id
1101 0x10, 0x32, 0x54, 0x76,
1102 0x98, 0xBA, 0xDC, 0xFE,
1103 // version tag
1104 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
1105 // packet number
1106 0xBC, 0x9A, 0x78, 0x56,
1107 0x34, 0x12,
1108 // private flags
1109 0x00,
1111 // frame type (padding)
1112 0x00,
1113 0x00, 0x00, 0x00, 0x00
1115 // clang-format on
1116 CheckProcessingFails(packet,
1117 arraysize(packet),
1118 "Illegal public flags value.",
1119 QUIC_INVALID_PACKET_HEADER);
1122 TEST_P(QuicFramerTest, LargePublicFlagWithMismatchedVersions) {
1123 // clang-format off
1124 unsigned char packet[] = {
1125 // public flags (8 byte connection_id, version flag and an unknown flag)
1126 0x7D,
1127 // connection_id
1128 0x10, 0x32, 0x54, 0x76,
1129 0x98, 0xBA, 0xDC, 0xFE,
1130 // version tag
1131 'Q', '0', '0', '0',
1132 // packet number
1133 0xBC, 0x9A, 0x78, 0x56,
1134 0x34, 0x12,
1135 // private flags
1136 0x00,
1138 // frame type (padding frame)
1139 0x00,
1140 0x00, 0x00, 0x00, 0x00
1142 // clang-format on
1143 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1144 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1145 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1146 ASSERT_TRUE(visitor_.header_.get());
1147 EXPECT_EQ(0, visitor_.frame_count_);
1148 EXPECT_EQ(1, visitor_.version_mismatch_);
1151 TEST_P(QuicFramerTest, InvalidPrivateFlag) {
1152 // clang-format off
1153 unsigned char packet[] = {
1154 // public flags (8 byte connection_id)
1155 0x3C,
1156 // connection_id
1157 0x10, 0x32, 0x54, 0x76,
1158 0x98, 0xBA, 0xDC, 0xFE,
1159 // packet number
1160 0xBC, 0x9A, 0x78, 0x56,
1161 0x34, 0x12,
1162 // private flags
1163 0x10,
1165 // frame type (padding)
1166 0x00,
1167 0x00, 0x00, 0x00, 0x00
1169 // clang-format on
1170 CheckProcessingFails(packet,
1171 arraysize(packet),
1172 "Illegal private flags value.",
1173 QUIC_INVALID_PACKET_HEADER);
1176 TEST_P(QuicFramerTest, InvalidFECGroupOffset) {
1177 // clang-format off
1178 unsigned char packet[] = {
1179 // public flags (8 byte connection_id)
1180 0x3C,
1181 // connection_id
1182 0x10, 0x32, 0x54, 0x76,
1183 0x98, 0xBA, 0xDC, 0xFE,
1184 // packet number
1185 0x01, 0x00, 0x00, 0x00,
1186 0x00, 0x00,
1187 // private flags (fec group)
1188 0x02,
1189 // first fec protected packet offset
1190 0x10
1192 // clang-format on
1193 CheckProcessingFails(packet, arraysize(packet),
1194 "First fec protected packet offset must be less "
1195 "than the packet number.",
1196 QUIC_INVALID_PACKET_HEADER);
1199 TEST_P(QuicFramerTest, PaddingFrame) {
1200 // clang-format off
1201 unsigned char packet[] = {
1202 // public flags (8 byte connection_id)
1203 0x3C,
1204 // connection_id
1205 0x10, 0x32, 0x54, 0x76,
1206 0x98, 0xBA, 0xDC, 0xFE,
1207 // packet number
1208 0xBC, 0x9A, 0x78, 0x56,
1209 0x34, 0x12,
1210 // private flags
1211 0x00,
1213 // frame type (padding frame)
1214 0x00,
1215 // Ignored data (which in this case is a stream frame)
1216 // frame type (stream frame with fin)
1217 0xFF,
1218 // stream id
1219 0x04, 0x03, 0x02, 0x01,
1220 // offset
1221 0x54, 0x76, 0x10, 0x32,
1222 0xDC, 0xFE, 0x98, 0xBA,
1223 // data length
1224 0x0c, 0x00,
1225 // data
1226 'h', 'e', 'l', 'l',
1227 'o', ' ', 'w', 'o',
1228 'r', 'l', 'd', '!',
1230 // clang-format on
1232 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1233 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1234 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1235 ASSERT_TRUE(visitor_.header_.get());
1236 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1238 ASSERT_EQ(0u, visitor_.stream_frames_.size());
1239 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1240 // A packet with no frames is not acceptable.
1241 CheckProcessingFails(
1242 packet, GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
1243 PACKET_6BYTE_PACKET_NUMBER, NOT_IN_FEC_GROUP),
1244 "Packet has no frames.", QUIC_MISSING_PAYLOAD);
1247 TEST_P(QuicFramerTest, StreamFrame) {
1248 // clang-format off
1249 unsigned char packet[] = {
1250 // public flags (8 byte connection_id)
1251 0x3C,
1252 // connection_id
1253 0x10, 0x32, 0x54, 0x76,
1254 0x98, 0xBA, 0xDC, 0xFE,
1255 // packet number
1256 0xBC, 0x9A, 0x78, 0x56,
1257 0x34, 0x12,
1258 // private flags
1259 0x00,
1261 // frame type (stream frame with fin)
1262 0xFF,
1263 // stream id
1264 0x04, 0x03, 0x02, 0x01,
1265 // offset
1266 0x54, 0x76, 0x10, 0x32,
1267 0xDC, 0xFE, 0x98, 0xBA,
1268 // data length
1269 0x0c, 0x00,
1270 // data
1271 'h', 'e', 'l', 'l',
1272 'o', ' ', 'w', 'o',
1273 'r', 'l', 'd', '!',
1275 // clang-format on
1277 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1278 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1280 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1281 ASSERT_TRUE(visitor_.header_.get());
1282 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1284 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1285 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1286 EXPECT_EQ(static_cast<uint64>(0x01020304),
1287 visitor_.stream_frames_[0]->stream_id);
1288 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1289 EXPECT_EQ(UINT64_C(0xBA98FEDC32107654), visitor_.stream_frames_[0]->offset);
1290 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]);
1292 // Now test framing boundaries.
1293 CheckStreamFrameBoundaries(packet, kQuicMaxStreamIdSize, !kIncludeVersion);
1296 TEST_P(QuicFramerTest, StreamFrame3ByteStreamId) {
1297 // clang-format off
1298 unsigned char packet[] = {
1299 // public flags (8 byte connection_id)
1300 0x3C,
1301 // connection_id
1302 0x10, 0x32, 0x54, 0x76,
1303 0x98, 0xBA, 0xDC, 0xFE,
1304 // packet number
1305 0xBC, 0x9A, 0x78, 0x56,
1306 0x34, 0x12,
1307 // private flags
1308 0x00,
1310 // frame type (stream frame with fin)
1311 0xFE,
1312 // stream id
1313 0x04, 0x03, 0x02,
1314 // offset
1315 0x54, 0x76, 0x10, 0x32,
1316 0xDC, 0xFE, 0x98, 0xBA,
1317 // data length
1318 0x0c, 0x00,
1319 // data
1320 'h', 'e', 'l', 'l',
1321 'o', ' ', 'w', 'o',
1322 'r', 'l', 'd', '!',
1324 // clang-format on
1326 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1327 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1329 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1330 ASSERT_TRUE(visitor_.header_.get());
1331 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1333 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1334 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1335 EXPECT_EQ(UINT64_C(0x00020304), visitor_.stream_frames_[0]->stream_id);
1336 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1337 EXPECT_EQ(UINT64_C(0xBA98FEDC32107654), visitor_.stream_frames_[0]->offset);
1338 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]);
1340 // Now test framing boundaries.
1341 const size_t stream_id_size = 3;
1342 CheckStreamFrameBoundaries(packet, stream_id_size, !kIncludeVersion);
1345 TEST_P(QuicFramerTest, StreamFrame2ByteStreamId) {
1346 // clang-format off
1347 unsigned char packet[] = {
1348 // public flags (8 byte connection_id)
1349 0x3C,
1350 // connection_id
1351 0x10, 0x32, 0x54, 0x76,
1352 0x98, 0xBA, 0xDC, 0xFE,
1353 // packet number
1354 0xBC, 0x9A, 0x78, 0x56,
1355 0x34, 0x12,
1356 // private flags
1357 0x00,
1359 // frame type (stream frame with fin)
1360 0xFD,
1361 // stream id
1362 0x04, 0x03,
1363 // offset
1364 0x54, 0x76, 0x10, 0x32,
1365 0xDC, 0xFE, 0x98, 0xBA,
1366 // data length
1367 0x0c, 0x00,
1368 // data
1369 'h', 'e', 'l', 'l',
1370 'o', ' ', 'w', 'o',
1371 'r', 'l', 'd', '!',
1373 // clang-format on
1375 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1376 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1378 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1379 ASSERT_TRUE(visitor_.header_.get());
1380 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1382 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1383 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1384 EXPECT_EQ(static_cast<uint64>(0x00000304),
1385 visitor_.stream_frames_[0]->stream_id);
1386 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1387 EXPECT_EQ(UINT64_C(0xBA98FEDC32107654), visitor_.stream_frames_[0]->offset);
1388 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]);
1390 // Now test framing boundaries.
1391 const size_t stream_id_size = 2;
1392 CheckStreamFrameBoundaries(packet, stream_id_size, !kIncludeVersion);
1395 TEST_P(QuicFramerTest, StreamFrame1ByteStreamId) {
1396 // clang-format off
1397 unsigned char packet[] = {
1398 // public flags (8 byte connection_id)
1399 0x3C,
1400 // connection_id
1401 0x10, 0x32, 0x54, 0x76,
1402 0x98, 0xBA, 0xDC, 0xFE,
1403 // packet number
1404 0xBC, 0x9A, 0x78, 0x56,
1405 0x34, 0x12,
1406 // private flags
1407 0x00,
1409 // frame type (stream frame with fin)
1410 0xFC,
1411 // stream id
1412 0x04,
1413 // offset
1414 0x54, 0x76, 0x10, 0x32,
1415 0xDC, 0xFE, 0x98, 0xBA,
1416 // data length
1417 0x0c, 0x00,
1418 // data
1419 'h', 'e', 'l', 'l',
1420 'o', ' ', 'w', 'o',
1421 'r', 'l', 'd', '!',
1423 // clang-format on
1425 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1426 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1428 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1429 ASSERT_TRUE(visitor_.header_.get());
1430 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1432 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1433 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1434 EXPECT_EQ(static_cast<uint64>(0x00000004),
1435 visitor_.stream_frames_[0]->stream_id);
1436 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1437 EXPECT_EQ(UINT64_C(0xBA98FEDC32107654), visitor_.stream_frames_[0]->offset);
1438 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]);
1440 // Now test framing boundaries.
1441 const size_t stream_id_size = 1;
1442 CheckStreamFrameBoundaries(packet, stream_id_size, !kIncludeVersion);
1445 TEST_P(QuicFramerTest, StreamFrameWithVersion) {
1446 // clang-format off
1447 unsigned char packet[] = {
1448 // public flags (version, 8 byte connection_id)
1449 0x3D,
1450 // connection_id
1451 0x10, 0x32, 0x54, 0x76,
1452 0x98, 0xBA, 0xDC, 0xFE,
1453 // version tag
1454 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
1455 // packet number
1456 0xBC, 0x9A, 0x78, 0x56,
1457 0x34, 0x12,
1458 // private flags
1459 0x00,
1461 // frame type (stream frame with fin)
1462 0xFF,
1463 // stream id
1464 0x04, 0x03, 0x02, 0x01,
1465 // offset
1466 0x54, 0x76, 0x10, 0x32,
1467 0xDC, 0xFE, 0x98, 0xBA,
1468 // data length
1469 0x0c, 0x00,
1470 // data
1471 'h', 'e', 'l', 'l',
1472 'o', ' ', 'w', 'o',
1473 'r', 'l', 'd', '!',
1475 // clang-format on
1477 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1478 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1480 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1481 ASSERT_TRUE(visitor_.header_.get());
1482 EXPECT_TRUE(visitor_.header_->public_header.version_flag);
1483 EXPECT_EQ(GetParam(), visitor_.header_->public_header.versions[0]);
1484 EXPECT_TRUE(CheckDecryption(encrypted, kIncludeVersion));
1486 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1487 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1488 EXPECT_EQ(static_cast<uint64>(0x01020304),
1489 visitor_.stream_frames_[0]->stream_id);
1490 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1491 EXPECT_EQ(UINT64_C(0xBA98FEDC32107654), visitor_.stream_frames_[0]->offset);
1492 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]);
1494 // Now test framing boundaries.
1495 CheckStreamFrameBoundaries(packet, kQuicMaxStreamIdSize, kIncludeVersion);
1498 TEST_P(QuicFramerTest, RejectPacket) {
1499 visitor_.accept_packet_ = false;
1501 // clang-format off
1502 unsigned char packet[] = {
1503 // public flags (8 byte connection_id)
1504 0x3C,
1505 // connection_id
1506 0x10, 0x32, 0x54, 0x76,
1507 0x98, 0xBA, 0xDC, 0xFE,
1508 // packet number
1509 0xBC, 0x9A, 0x78, 0x56,
1510 0x34, 0x12,
1511 // private flags
1512 0x00,
1514 // frame type (stream frame with fin)
1515 0xFF,
1516 // stream id
1517 0x04, 0x03, 0x02, 0x01,
1518 // offset
1519 0x54, 0x76, 0x10, 0x32,
1520 0xDC, 0xFE, 0x98, 0xBA,
1521 // data length
1522 0x0c, 0x00,
1523 // data
1524 'h', 'e', 'l', 'l',
1525 'o', ' ', 'w', 'o',
1526 'r', 'l', 'd', '!',
1528 // clang-format on
1530 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1531 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1533 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1534 ASSERT_TRUE(visitor_.header_.get());
1535 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1537 ASSERT_EQ(0u, visitor_.stream_frames_.size());
1538 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1541 TEST_P(QuicFramerTest, RejectPublicHeader) {
1542 visitor_.accept_public_header_ = false;
1544 // clang-format off
1545 unsigned char packet[] = {
1546 // public flags (8 byte connection_id)
1547 0x3C,
1548 // connection_id
1549 0x10, 0x32, 0x54, 0x76,
1550 0x98, 0xBA, 0xDC, 0xFE,
1552 // clang-format on
1554 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1555 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1557 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1558 ASSERT_TRUE(visitor_.public_header_.get());
1559 ASSERT_FALSE(visitor_.header_.get());
1562 TEST_P(QuicFramerTest, RevivedStreamFrame) {
1563 // clang-format off
1564 unsigned char payload[] = {
1565 // frame type (stream frame with fin)
1566 0xFF,
1567 // stream id
1568 0x04, 0x03, 0x02, 0x01,
1569 // offset
1570 0x54, 0x76, 0x10, 0x32,
1571 0xDC, 0xFE, 0x98, 0xBA,
1572 // data length
1573 0x0c, 0x00,
1574 // data
1575 'h', 'e', 'l', 'l',
1576 'o', ' ', 'w', 'o',
1577 'r', 'l', 'd', '!',
1579 // clang-format on
1581 QuicPacketHeader header;
1582 header.public_header.connection_id = UINT64_C(0xFEDCBA9876543210);
1583 header.public_header.reset_flag = false;
1584 header.public_header.version_flag = false;
1585 header.fec_flag = true;
1586 header.entropy_flag = true;
1587 header.packet_packet_number = UINT64_C(0x123456789ABC);
1588 header.fec_group = 0;
1590 // Do not encrypt the payload because the revived payload is post-encryption.
1591 EXPECT_TRUE(framer_.ProcessRevivedPacket(&header,
1592 StringPiece(AsChars(payload),
1593 arraysize(payload))));
1595 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1596 ASSERT_EQ(1, visitor_.revived_packets_);
1597 ASSERT_TRUE(visitor_.header_.get());
1598 EXPECT_EQ(UINT64_C(0xFEDCBA9876543210),
1599 visitor_.header_->public_header.connection_id);
1600 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
1601 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
1602 EXPECT_TRUE(visitor_.header_->fec_flag);
1603 EXPECT_TRUE(visitor_.header_->entropy_flag);
1604 EXPECT_EQ(1 << (header.packet_packet_number % 8),
1605 visitor_.header_->entropy_hash);
1606 EXPECT_EQ(UINT64_C(0x123456789ABC), visitor_.header_->packet_packet_number);
1607 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
1608 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
1610 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1611 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1612 EXPECT_EQ(UINT64_C(0x01020304), visitor_.stream_frames_[0]->stream_id);
1613 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1614 EXPECT_EQ(UINT64_C(0xBA98FEDC32107654), visitor_.stream_frames_[0]->offset);
1615 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]);
1618 TEST_P(QuicFramerTest, StreamFrameInFecGroup) {
1619 // clang-format off
1620 unsigned char packet[] = {
1621 // public flags (8 byte connection_id)
1622 0x3C,
1623 // connection_id
1624 0x10, 0x32, 0x54, 0x76,
1625 0x98, 0xBA, 0xDC, 0xFE,
1626 // packet number
1627 0xBC, 0x9A, 0x78, 0x56,
1628 0x12, 0x34,
1629 // private flags (fec group)
1630 0x02,
1631 // first fec protected packet offset
1632 0x02,
1634 // frame type (stream frame with fin)
1635 0xFF,
1636 // stream id
1637 0x04, 0x03, 0x02, 0x01,
1638 // offset
1639 0x54, 0x76, 0x10, 0x32,
1640 0xDC, 0xFE, 0x98, 0xBA,
1641 // data length
1642 0x0c, 0x00,
1643 // data
1644 'h', 'e', 'l', 'l',
1645 'o', ' ', 'w', 'o',
1646 'r', 'l', 'd', '!',
1648 // clang-format on
1650 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1651 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1653 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1654 ASSERT_TRUE(visitor_.header_.get());
1655 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1656 EXPECT_EQ(IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
1657 EXPECT_EQ(UINT64_C(0x341256789ABA), visitor_.header_->fec_group);
1658 const size_t fec_offset = GetStartOfFecProtectedData(
1659 PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, PACKET_6BYTE_PACKET_NUMBER);
1660 EXPECT_EQ(
1661 string(AsChars(packet) + fec_offset, arraysize(packet) - fec_offset),
1662 visitor_.fec_protected_payload_);
1664 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1665 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1666 EXPECT_EQ(UINT64_C(0x01020304), visitor_.stream_frames_[0]->stream_id);
1667 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1668 EXPECT_EQ(UINT64_C(0xBA98FEDC32107654), visitor_.stream_frames_[0]->offset);
1669 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]);
1672 TEST_P(QuicFramerTest, AckFrameTwoTimestamp) {
1673 // clang-format off
1674 unsigned char packet[] = {
1675 // public flags (8 byte connection_id)
1676 0x3C,
1677 // connection_id
1678 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
1679 // packet number
1680 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
1681 // private flags (entropy)
1682 0x01,
1684 // frame type (ack frame)
1685 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
1686 0x6C,
1687 // entropy hash of all received packets.
1688 0xBA,
1689 // largest observed packet number
1690 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12,
1691 // Zero delta time.
1692 0x00, 0x00,
1693 // Number of timestamps.
1694 0x02,
1695 // Delta from largest observed.
1696 0x01,
1697 // Delta time.
1698 0x10, 0x32, 0x54, 0x76,
1699 // Delta from largest observed.
1700 0x02,
1701 // Delta time.
1702 0x10, 0x32,
1703 // num missing packets
1704 0x01,
1705 // missing packet delta
1706 0x01,
1707 // 0 more missing packets in range.
1708 0x00,
1709 // Number of revived packets.
1710 0x00,
1712 // clang-format on
1714 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1715 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1717 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1718 ASSERT_TRUE(visitor_.header_.get());
1719 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1721 EXPECT_EQ(0u, visitor_.stream_frames_.size());
1722 ASSERT_EQ(1u, visitor_.ack_frames_.size());
1723 const QuicAckFrame& frame = *visitor_.ack_frames_[0];
1724 EXPECT_EQ(0xBA, frame.entropy_hash);
1725 EXPECT_EQ(UINT64_C(0x0123456789ABF), frame.largest_observed);
1726 ASSERT_EQ(1u, frame.missing_packets.size());
1727 ASSERT_EQ(2u, frame.received_packet_times.size());
1728 PacketNumberSet::const_iterator missing_iter = frame.missing_packets.begin();
1729 EXPECT_EQ(UINT64_C(0x0123456789ABE), *missing_iter);
1731 const size_t kReceivedEntropyOffset = kQuicFrameTypeSize;
1732 const size_t kLargestObservedOffset = kReceivedEntropyOffset +
1733 kQuicEntropyHashSize;
1734 const size_t kMissingDeltaTimeOffset =
1735 kLargestObservedOffset + PACKET_6BYTE_PACKET_NUMBER;
1736 const size_t kNumTimestampsOffset =
1737 kMissingDeltaTimeOffset + kQuicDeltaTimeLargestObservedSize;
1738 const size_t kTimestampDeltaLargestObserved1 =
1739 kNumTimestampsOffset + kQuicNumTimestampsSize;
1740 const size_t kTimestampTimeDeltaLargestObserved1 =
1741 kTimestampDeltaLargestObserved1 + 1;
1742 const size_t kTimestampDeltaLargestObserved2 =
1743 kTimestampTimeDeltaLargestObserved1 + 4;
1744 const size_t kTimestampTimeDeltaLargestObserved2 =
1745 kTimestampDeltaLargestObserved2 + 1;
1746 const size_t kNumMissingPacketOffset =
1747 kTimestampTimeDeltaLargestObserved2 + 2;
1748 const size_t kMissingPacketsOffset =
1749 kNumMissingPacketOffset + kNumberOfNackRangesSize;
1750 const size_t kMissingPacketsRange =
1751 kMissingPacketsOffset + PACKET_1BYTE_PACKET_NUMBER;
1752 const size_t kRevivedPacketsLength =
1753 kMissingPacketsRange + PACKET_1BYTE_PACKET_NUMBER;
1754 // Now test framing boundaries.
1755 const size_t ack_frame_size =
1756 kRevivedPacketsLength + PACKET_1BYTE_PACKET_NUMBER;
1757 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) {
1758 string expected_error;
1759 if (i < kLargestObservedOffset) {
1760 expected_error = "Unable to read entropy hash for received packets.";
1761 } else if (i < kMissingDeltaTimeOffset) {
1762 expected_error = "Unable to read largest observed.";
1763 } else if (i < kNumTimestampsOffset) {
1764 expected_error = "Unable to read delta time largest observed.";
1765 } else if (i < kTimestampDeltaLargestObserved1) {
1766 expected_error = "Unable to read num received packets.";
1767 } else if (i < kTimestampTimeDeltaLargestObserved1) {
1768 expected_error = "Unable to read sequence delta in received packets.";
1769 } else if (i < kTimestampDeltaLargestObserved2) {
1770 expected_error = "Unable to read time delta in received packets.";
1771 } else if (i < kTimestampTimeDeltaLargestObserved2) {
1772 expected_error = "Unable to read sequence delta in received packets.";
1773 } else if (i < kNumMissingPacketOffset) {
1774 expected_error =
1775 "Unable to read incremental time delta in received packets.";
1776 } else if (i < kMissingPacketsOffset) {
1777 expected_error = "Unable to read num missing packet ranges.";
1778 } else if (i < kMissingPacketsRange) {
1779 expected_error = "Unable to read missing packet number delta.";
1780 } else if (i < kRevivedPacketsLength) {
1781 expected_error = "Unable to read missing packet number range.";
1782 } else {
1783 expected_error = "Unable to read num revived packets.";
1785 CheckProcessingFails(
1786 packet,
1787 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
1788 PACKET_6BYTE_PACKET_NUMBER, NOT_IN_FEC_GROUP),
1789 expected_error, QUIC_INVALID_ACK_DATA);
1793 TEST_P(QuicFramerTest, AckFrameOneTimestamp) {
1794 // clang-format off
1795 unsigned char packet[] = {
1796 // public flags (8 byte connection_id)
1797 0x3C,
1798 // connection_id
1799 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
1800 // packet number
1801 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
1802 // private flags (entropy)
1803 0x01,
1805 // frame type (ack frame)
1806 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
1807 0x6C,
1808 // entropy hash of all received packets.
1809 0xBA,
1810 // largest observed packet number
1811 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12,
1812 // Zero delta time.
1813 0x00, 0x00,
1814 // Number of timestamps.
1815 0x01,
1816 // Delta from largest observed.
1817 0x01,
1818 // Delta time.
1819 0x10, 0x32, 0x54, 0x76,
1820 // num missing packets
1821 0x01,
1822 // missing packet delta
1823 0x01,
1824 // 0 more missing packets in range.
1825 0x00,
1826 // Number of revived packets.
1827 0x00,
1829 // clang-format on
1831 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1832 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1834 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1835 ASSERT_TRUE(visitor_.header_.get());
1836 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1838 EXPECT_EQ(0u, visitor_.stream_frames_.size());
1839 ASSERT_EQ(1u, visitor_.ack_frames_.size());
1840 const QuicAckFrame& frame = *visitor_.ack_frames_[0];
1841 EXPECT_EQ(0xBA, frame.entropy_hash);
1842 EXPECT_EQ(UINT64_C(0x0123456789ABF), frame.largest_observed);
1843 ASSERT_EQ(1u, frame.missing_packets.size());
1844 ASSERT_EQ(1u, frame.received_packet_times.size());
1845 PacketNumberSet::const_iterator missing_iter = frame.missing_packets.begin();
1846 EXPECT_EQ(UINT64_C(0x0123456789ABE), *missing_iter);
1848 const size_t kReceivedEntropyOffset = kQuicFrameTypeSize;
1849 const size_t kLargestObservedOffset =
1850 kReceivedEntropyOffset + kQuicEntropyHashSize;
1851 const size_t kMissingDeltaTimeOffset =
1852 kLargestObservedOffset + PACKET_6BYTE_PACKET_NUMBER;
1853 const size_t kNumTimestampsOffset =
1854 kMissingDeltaTimeOffset + kQuicDeltaTimeLargestObservedSize;
1855 const size_t kTimestampDeltaLargestObserved =
1856 kNumTimestampsOffset + kQuicNumTimestampsSize;
1857 const size_t kTimestampTimeDeltaLargestObserved =
1858 kTimestampDeltaLargestObserved + 1;
1859 const size_t kNumMissingPacketOffset = kTimestampTimeDeltaLargestObserved + 4;
1860 const size_t kMissingPacketsOffset =
1861 kNumMissingPacketOffset + kNumberOfNackRangesSize;
1862 const size_t kMissingPacketsRange =
1863 kMissingPacketsOffset + PACKET_1BYTE_PACKET_NUMBER;
1864 const size_t kRevivedPacketsLength =
1865 kMissingPacketsRange + PACKET_1BYTE_PACKET_NUMBER;
1866 // Now test framing boundaries.
1867 const size_t ack_frame_size =
1868 kRevivedPacketsLength + PACKET_1BYTE_PACKET_NUMBER;
1869 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) {
1870 string expected_error;
1871 if (i < kLargestObservedOffset) {
1872 expected_error = "Unable to read entropy hash for received packets.";
1873 } else if (i < kMissingDeltaTimeOffset) {
1874 expected_error = "Unable to read largest observed.";
1875 } else if (i < kNumTimestampsOffset) {
1876 expected_error = "Unable to read delta time largest observed.";
1877 } else if (i < kTimestampDeltaLargestObserved) {
1878 expected_error = "Unable to read num received packets.";
1879 } else if (i < kTimestampTimeDeltaLargestObserved) {
1880 expected_error = "Unable to read sequence delta in received packets.";
1881 } else if (i < kNumMissingPacketOffset) {
1882 expected_error = "Unable to read time delta in received packets.";
1883 } else if (i < kMissingPacketsOffset) {
1884 expected_error = "Unable to read num missing packet ranges.";
1885 } else if (i < kMissingPacketsRange) {
1886 expected_error = "Unable to read missing packet number delta.";
1887 } else if (i < kRevivedPacketsLength) {
1888 expected_error = "Unable to read missing packet number range.";
1889 } else {
1890 expected_error = "Unable to read num revived packets.";
1892 CheckProcessingFails(
1893 packet,
1894 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
1895 PACKET_6BYTE_PACKET_NUMBER, NOT_IN_FEC_GROUP),
1896 expected_error, QUIC_INVALID_ACK_DATA);
1900 TEST_P(QuicFramerTest, AckFrame) {
1901 // clang-format off
1902 unsigned char packet[] = {
1903 // public flags (8 byte connection_id)
1904 0x3C,
1905 // connection_id
1906 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
1907 // packet number
1908 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
1909 // private flags (entropy)
1910 0x01,
1912 // frame type (ack frame)
1913 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
1914 0x6C,
1915 // entropy hash of all received packets.
1916 0xBA,
1917 // largest observed packet number
1918 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12,
1919 // Zero delta time.
1920 0x00, 0x00,
1921 // Number of timestamps.
1922 0x00,
1923 // num missing packets
1924 0x01,
1925 // missing packet delta
1926 0x01,
1927 // 0 more missing packets in range.
1928 0x00,
1929 // Number of revived packets.
1930 0x00,
1932 // clang-format on
1934 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1935 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1937 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1938 ASSERT_TRUE(visitor_.header_.get());
1939 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1941 EXPECT_EQ(0u, visitor_.stream_frames_.size());
1942 ASSERT_EQ(1u, visitor_.ack_frames_.size());
1943 const QuicAckFrame& frame = *visitor_.ack_frames_[0];
1944 EXPECT_EQ(0xBA, frame.entropy_hash);
1945 EXPECT_EQ(UINT64_C(0x0123456789ABF), frame.largest_observed);
1946 ASSERT_EQ(1u, frame.missing_packets.size());
1947 PacketNumberSet::const_iterator missing_iter = frame.missing_packets.begin();
1948 EXPECT_EQ(UINT64_C(0x0123456789ABE), *missing_iter);
1950 const size_t kReceivedEntropyOffset = kQuicFrameTypeSize;
1951 const size_t kLargestObservedOffset = kReceivedEntropyOffset +
1952 kQuicEntropyHashSize;
1953 const size_t kMissingDeltaTimeOffset =
1954 kLargestObservedOffset + PACKET_6BYTE_PACKET_NUMBER;
1955 const size_t kNumTimestampsOffset = kMissingDeltaTimeOffset +
1956 kQuicDeltaTimeLargestObservedSize;
1957 const size_t kNumMissingPacketOffset = kNumTimestampsOffset +
1958 kQuicNumTimestampsSize;
1959 const size_t kMissingPacketsOffset = kNumMissingPacketOffset +
1960 kNumberOfNackRangesSize;
1961 const size_t kMissingPacketsRange =
1962 kMissingPacketsOffset + PACKET_1BYTE_PACKET_NUMBER;
1963 const size_t kRevivedPacketsLength =
1964 kMissingPacketsRange + PACKET_1BYTE_PACKET_NUMBER;
1965 // Now test framing boundaries.
1966 const size_t ack_frame_size =
1967 kRevivedPacketsLength + PACKET_1BYTE_PACKET_NUMBER;
1968 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) {
1969 string expected_error;
1970 if (i < kLargestObservedOffset) {
1971 expected_error = "Unable to read entropy hash for received packets.";
1972 } else if (i < kMissingDeltaTimeOffset) {
1973 expected_error = "Unable to read largest observed.";
1974 } else if (i < kNumTimestampsOffset) {
1975 expected_error = "Unable to read delta time largest observed.";
1976 } else if (i < kNumMissingPacketOffset) {
1977 expected_error = "Unable to read num received packets.";
1978 } else if (i < kMissingPacketsOffset) {
1979 expected_error = "Unable to read num missing packet ranges.";
1980 } else if (i < kMissingPacketsRange) {
1981 expected_error = "Unable to read missing packet number delta.";
1982 } else if (i < kRevivedPacketsLength) {
1983 expected_error = "Unable to read missing packet number range.";
1984 } else {
1985 expected_error = "Unable to read num revived packets.";
1987 CheckProcessingFails(
1988 packet,
1989 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
1990 PACKET_6BYTE_PACKET_NUMBER, NOT_IN_FEC_GROUP),
1991 expected_error, QUIC_INVALID_ACK_DATA);
1995 TEST_P(QuicFramerTest, AckFrameRevivedPackets) {
1996 // clang-format off
1997 unsigned char packet[] = {
1998 // public flags (8 byte connection_id)
1999 0x3C,
2000 // connection_id
2001 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
2002 // packet number
2003 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
2004 // private flags (entropy)
2005 0x01,
2007 // frame type (ack frame)
2008 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
2009 0x6C,
2010 // entropy hash of all received packets.
2011 0xBA,
2012 // largest observed packet number
2013 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12,
2014 // Zero delta time.
2015 0x00, 0x00,
2016 // num received packets.
2017 0x00,
2018 // num missing packets
2019 0x01,
2020 // missing packet delta
2021 0x01,
2022 // 0 more missing packets in range.
2023 0x00,
2024 // Number of revived packets.
2025 0x01,
2026 // Revived packet number.
2027 0xBE, 0x9A, 0x78, 0x56, 0x34, 0x12,
2028 // Number of revived packets.
2029 0x00,
2031 // clang-format on
2033 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2034 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2036 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2037 ASSERT_TRUE(visitor_.header_.get());
2038 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2040 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2041 ASSERT_EQ(1u, visitor_.ack_frames_.size());
2042 const QuicAckFrame& frame = *visitor_.ack_frames_[0];
2043 EXPECT_EQ(0xBA, frame.entropy_hash);
2044 EXPECT_EQ(UINT64_C(0x0123456789ABF), frame.largest_observed);
2045 ASSERT_EQ(1u, frame.missing_packets.size());
2046 PacketNumberSet::const_iterator missing_iter = frame.missing_packets.begin();
2047 EXPECT_EQ(UINT64_C(0x0123456789ABE), *missing_iter);
2049 const size_t kReceivedEntropyOffset = kQuicFrameTypeSize;
2050 const size_t kLargestObservedOffset = kReceivedEntropyOffset +
2051 kQuicEntropyHashSize;
2052 const size_t kMissingDeltaTimeOffset =
2053 kLargestObservedOffset + PACKET_6BYTE_PACKET_NUMBER;
2054 const size_t kNumTimestampsOffset = kMissingDeltaTimeOffset +
2055 kQuicDeltaTimeLargestObservedSize;
2056 const size_t kNumMissingPacketOffset = kNumTimestampsOffset +
2057 kQuicNumTimestampsSize;
2058 const size_t kMissingPacketsOffset = kNumMissingPacketOffset +
2059 kNumberOfNackRangesSize;
2060 const size_t kMissingPacketsRange =
2061 kMissingPacketsOffset + PACKET_1BYTE_PACKET_NUMBER;
2062 const size_t kRevivedPacketsLength =
2063 kMissingPacketsRange + PACKET_1BYTE_PACKET_NUMBER;
2064 const size_t kRevivedPacketSequenceNumberLength =
2065 kRevivedPacketsLength + PACKET_1BYTE_PACKET_NUMBER;
2066 // Now test framing boundaries.
2067 const size_t ack_frame_size =
2068 kRevivedPacketSequenceNumberLength + PACKET_6BYTE_PACKET_NUMBER;
2069 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) {
2070 string expected_error;
2071 if (i < kReceivedEntropyOffset) {
2072 expected_error = "Unable to read least unacked delta.";
2073 } else if (i < kLargestObservedOffset) {
2074 expected_error = "Unable to read entropy hash for received packets.";
2075 } else if (i < kMissingDeltaTimeOffset) {
2076 expected_error = "Unable to read largest observed.";
2077 } else if (i < kNumTimestampsOffset) {
2078 expected_error = "Unable to read delta time largest observed.";
2079 } else if (i < kNumMissingPacketOffset) {
2080 expected_error = "Unable to read num received packets.";
2081 } else if (i < kMissingPacketsOffset) {
2082 expected_error = "Unable to read num missing packet ranges.";
2083 } else if (i < kMissingPacketsRange) {
2084 expected_error = "Unable to read missing packet number delta.";
2085 } else if (i < kRevivedPacketsLength) {
2086 expected_error = "Unable to read missing packet number range.";
2087 } else if (i < kRevivedPacketSequenceNumberLength) {
2088 expected_error = "Unable to read num revived packets.";
2089 } else {
2090 expected_error = "Unable to read revived packet.";
2092 CheckProcessingFails(
2093 packet,
2094 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
2095 PACKET_6BYTE_PACKET_NUMBER, NOT_IN_FEC_GROUP),
2096 expected_error, QUIC_INVALID_ACK_DATA);
2100 TEST_P(QuicFramerTest, AckFrameNoNacks) {
2101 // clang-format off
2102 unsigned char packet[] = {
2103 // public flags (8 byte connection_id)
2104 0x3C,
2105 // connection_id
2106 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
2107 // packet number
2108 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
2109 // private flags (entropy)
2110 0x01,
2112 // frame type (ack frame)
2113 // (no nacks, not truncated, 6 byte largest observed, 1 byte delta)
2114 0x4C,
2115 // entropy hash of all received packets.
2116 0xBA,
2117 // largest observed packet number
2118 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12,
2119 // Zero delta time.
2120 0x00, 0x00,
2121 // Number of received packets.
2122 0x00,
2124 // clang-format on
2126 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2127 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2129 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2130 ASSERT_TRUE(visitor_.header_.get());
2131 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2133 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2134 ASSERT_EQ(1u, visitor_.ack_frames_.size());
2135 QuicAckFrame* frame = visitor_.ack_frames_[0];
2136 EXPECT_EQ(0xBA, frame->entropy_hash);
2137 EXPECT_EQ(UINT64_C(0x0123456789ABF), frame->largest_observed);
2138 ASSERT_EQ(0u, frame->missing_packets.size());
2140 // Verify that the packet re-serializes identically.
2141 QuicFrames frames;
2142 frames.push_back(QuicFrame(frame));
2143 scoped_ptr<QuicPacket> data(BuildDataPacket(*visitor_.header_, frames));
2144 ASSERT_TRUE(data != nullptr);
2146 test::CompareCharArraysWithHexError("constructed packet", data->data(),
2147 data->length(), AsChars(packet),
2148 arraysize(packet));
2151 TEST_P(QuicFramerTest, AckFrame500Nacks) {
2152 // clang-format off
2153 unsigned char packet[] = {
2154 // public flags (8 byte connection_id)
2155 0x3C,
2156 // connection_id
2157 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
2158 // packet number
2159 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
2160 // private flags (entropy)
2161 0x01,
2163 // frame type (ack frame)
2164 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
2165 0x6C,
2166 // entropy hash of all received packets.
2167 0xBA,
2168 // largest observed packet number
2169 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12,
2170 // Zero delta time.
2171 0x00, 0x00,
2172 // No received packets.
2173 0x00,
2174 // num missing packet ranges
2175 0x02,
2176 // missing packet delta
2177 0x01,
2178 // 243 more missing packets in range.
2179 // The ranges are listed in this order so the re-constructed packet
2180 // matches.
2181 0xF3,
2182 // No gap between ranges
2183 0x00,
2184 // 255 more missing packets in range.
2185 0xFF,
2186 // No revived packets.
2187 0x00,
2189 // clang-format on
2191 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2192 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2194 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2195 ASSERT_TRUE(visitor_.header_.get());
2196 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2198 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2199 ASSERT_EQ(1u, visitor_.ack_frames_.size());
2200 QuicAckFrame* frame = visitor_.ack_frames_[0];
2201 EXPECT_EQ(0xBA, frame->entropy_hash);
2202 EXPECT_EQ(UINT64_C(0x0123456789ABF), frame->largest_observed);
2203 EXPECT_EQ(0u, frame->revived_packets.size());
2204 ASSERT_EQ(500u, frame->missing_packets.size());
2205 PacketNumberSet::const_iterator first_missing_iter =
2206 frame->missing_packets.begin();
2207 EXPECT_EQ(UINT64_C(0x0123456789ABE) - 499, *first_missing_iter);
2208 PacketNumberSet::const_reverse_iterator last_missing_iter =
2209 frame->missing_packets.rbegin();
2210 EXPECT_EQ(UINT64_C(0x0123456789ABE), *last_missing_iter);
2212 // Verify that the packet re-serializes identically.
2213 QuicFrames frames;
2214 frames.push_back(QuicFrame(frame));
2215 scoped_ptr<QuicPacket> data(BuildDataPacket(*visitor_.header_, frames));
2216 ASSERT_TRUE(data != nullptr);
2218 test::CompareCharArraysWithHexError("constructed packet",
2219 data->data(), data->length(),
2220 AsChars(packet), arraysize(packet));
2223 TEST_P(QuicFramerTest, StopWaitingFrame) {
2224 // clang-format off
2225 unsigned char packet[] = {
2226 // public flags (8 byte connection_id)
2227 0x3C,
2228 // connection_id
2229 0x10, 0x32, 0x54, 0x76,
2230 0x98, 0xBA, 0xDC, 0xFE,
2231 // packet number
2232 0xA8, 0x9A, 0x78, 0x56,
2233 0x34, 0x12,
2234 // private flags (entropy)
2235 0x01,
2237 // frame type (ack frame)
2238 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
2239 0x06,
2240 // entropy hash of sent packets till least awaiting - 1.
2241 0xAB,
2242 // least packet number awaiting an ack, delta from packet number.
2243 0x08, 0x00, 0x00, 0x00,
2244 0x00, 0x00,
2246 // clang-format on
2248 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2249 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2251 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2252 ASSERT_TRUE(visitor_.header_.get());
2253 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2255 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2256 ASSERT_EQ(1u, visitor_.stop_waiting_frames_.size());
2257 const QuicStopWaitingFrame& frame = *visitor_.stop_waiting_frames_[0];
2258 EXPECT_EQ(0xAB, frame.entropy_hash);
2259 EXPECT_EQ(UINT64_C(0x0123456789AA0), frame.least_unacked);
2261 const size_t kSentEntropyOffset = kQuicFrameTypeSize;
2262 const size_t kLeastUnackedOffset = kSentEntropyOffset + kQuicEntropyHashSize;
2263 const size_t frame_size = 7;
2264 for (size_t i = kQuicFrameTypeSize; i < frame_size; ++i) {
2265 string expected_error;
2266 if (i < kLeastUnackedOffset) {
2267 expected_error = "Unable to read entropy hash for sent packets.";
2268 } else {
2269 expected_error = "Unable to read least unacked delta.";
2271 CheckProcessingFails(
2272 packet,
2273 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
2274 PACKET_6BYTE_PACKET_NUMBER, NOT_IN_FEC_GROUP),
2275 expected_error, QUIC_INVALID_STOP_WAITING_DATA);
2279 TEST_P(QuicFramerTest, RstStreamFrameQuicVersion24) {
2280 if (version_ > QUIC_VERSION_24) {
2281 // QUIC_VERSION_25 removes the error_details field from QuicRstStreamFrame.
2282 return;
2285 // clang-format off
2286 unsigned char packet[] = {
2287 // public flags (8 byte connection_id)
2288 0x3C,
2289 // connection_id
2290 0x10, 0x32, 0x54, 0x76,
2291 0x98, 0xBA, 0xDC, 0xFE,
2292 // packet number
2293 0xBC, 0x9A, 0x78, 0x56,
2294 0x34, 0x12,
2295 // private flags
2296 0x00,
2298 // frame type (rst stream frame)
2299 0x01,
2300 // stream id
2301 0x04, 0x03, 0x02, 0x01,
2303 // sent byte offset
2304 0x01, 0x02, 0x03, 0x04,
2305 0x05, 0x06, 0x07, 0x08,
2307 // error code
2308 0x01, 0x00, 0x00, 0x00,
2310 // error details length
2311 0x0d, 0x00,
2312 // error details
2313 'b', 'e', 'c', 'a',
2314 'u', 's', 'e', ' ',
2315 'I', ' ', 'c', 'a',
2316 'n',
2318 // clang-format on
2320 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2321 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2323 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2324 ASSERT_TRUE(visitor_.header_.get());
2325 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2327 EXPECT_EQ(UINT64_C(0x01020304), visitor_.rst_stream_frame_.stream_id);
2328 EXPECT_EQ(0x01, visitor_.rst_stream_frame_.error_code);
2329 EXPECT_EQ("because I can", visitor_.rst_stream_frame_.error_details);
2330 EXPECT_EQ(UINT64_C(0x0807060504030201),
2331 visitor_.rst_stream_frame_.byte_offset);
2333 // Now test framing boundaries.
2334 for (size_t i = kQuicFrameTypeSize;
2335 i < QuicFramer::GetMinRstStreamFrameSize(); ++i) {
2336 string expected_error;
2337 if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize) {
2338 expected_error = "Unable to read stream_id.";
2339 } else if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize +
2340 kQuicMaxStreamOffsetSize) {
2341 expected_error = "Unable to read rst stream sent byte offset.";
2342 } else if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize +
2343 kQuicMaxStreamOffsetSize + kQuicErrorCodeSize) {
2344 expected_error = "Unable to read rst stream error code.";
2345 } else {
2346 expected_error = "Unable to read rst stream error details.";
2348 CheckProcessingFails(
2349 packet,
2350 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
2351 PACKET_6BYTE_PACKET_NUMBER, NOT_IN_FEC_GROUP),
2352 expected_error, QUIC_INVALID_RST_STREAM_DATA);
2356 TEST_P(QuicFramerTest, RstStreamFrameQuic) {
2357 if (version_ <= QUIC_VERSION_24) {
2358 // QUIC_VERSION_25 removes the error_details field from QuicRstStreamFrame.
2359 return;
2362 // clang-format off
2363 unsigned char packet[] = {
2364 // public flags (8 byte connection_id)
2365 0x3C,
2366 // connection_id
2367 0x10, 0x32, 0x54, 0x76,
2368 0x98, 0xBA, 0xDC, 0xFE,
2369 // packet number
2370 0xBC, 0x9A, 0x78, 0x56,
2371 0x34, 0x12,
2372 // private flags
2373 0x00,
2375 // frame type (rst stream frame)
2376 0x01,
2377 // stream id
2378 0x04, 0x03, 0x02, 0x01,
2380 // sent byte offset
2381 0x01, 0x02, 0x03, 0x04,
2382 0x05, 0x06, 0x07, 0x08,
2384 // error code
2385 0x01, 0x00, 0x00, 0x00,
2387 // clang-format on
2389 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2390 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2392 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2393 ASSERT_TRUE(visitor_.header_.get());
2394 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2396 EXPECT_EQ(UINT64_C(0x01020304), visitor_.rst_stream_frame_.stream_id);
2397 EXPECT_EQ(0x01, visitor_.rst_stream_frame_.error_code);
2398 EXPECT_EQ(UINT64_C(0x0807060504030201),
2399 visitor_.rst_stream_frame_.byte_offset);
2401 // Now test framing boundaries.
2402 for (size_t i = kQuicFrameTypeSize; i < QuicFramer::GetRstStreamFrameSize();
2403 ++i) {
2404 string expected_error;
2405 if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize) {
2406 expected_error = "Unable to read stream_id.";
2407 } else if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize +
2408 kQuicMaxStreamOffsetSize) {
2409 expected_error = "Unable to read rst stream sent byte offset.";
2410 } else if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize +
2411 kQuicMaxStreamOffsetSize + kQuicErrorCodeSize) {
2412 expected_error = "Unable to read rst stream error code.";
2414 CheckProcessingFails(
2415 packet,
2416 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
2417 PACKET_6BYTE_PACKET_NUMBER, NOT_IN_FEC_GROUP),
2418 expected_error, QUIC_INVALID_RST_STREAM_DATA);
2422 TEST_P(QuicFramerTest, ConnectionCloseFrame) {
2423 // clang-format off
2424 unsigned char packet[] = {
2425 // public flags (8 byte connection_id)
2426 0x3C,
2427 // connection_id
2428 0x10, 0x32, 0x54, 0x76,
2429 0x98, 0xBA, 0xDC, 0xFE,
2430 // packet number
2431 0xBC, 0x9A, 0x78, 0x56,
2432 0x34, 0x12,
2433 // private flags
2434 0x00,
2436 // frame type (connection close frame)
2437 0x02,
2438 // error code
2439 0x11, 0x00, 0x00, 0x00,
2441 // error details length
2442 0x0d, 0x00,
2443 // error details
2444 'b', 'e', 'c', 'a',
2445 'u', 's', 'e', ' ',
2446 'I', ' ', 'c', 'a',
2447 'n',
2449 // clang-format on
2451 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2452 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2454 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2455 ASSERT_TRUE(visitor_.header_.get());
2456 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2458 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2460 EXPECT_EQ(0x11, visitor_.connection_close_frame_.error_code);
2461 EXPECT_EQ("because I can", visitor_.connection_close_frame_.error_details);
2463 ASSERT_EQ(0u, visitor_.ack_frames_.size());
2465 // Now test framing boundaries.
2466 for (size_t i = kQuicFrameTypeSize;
2467 i < QuicFramer::GetMinConnectionCloseFrameSize(); ++i) {
2468 string expected_error;
2469 if (i < kQuicFrameTypeSize + kQuicErrorCodeSize) {
2470 expected_error = "Unable to read connection close error code.";
2471 } else {
2472 expected_error = "Unable to read connection close error details.";
2474 CheckProcessingFails(
2475 packet,
2476 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
2477 PACKET_6BYTE_PACKET_NUMBER, NOT_IN_FEC_GROUP),
2478 expected_error, QUIC_INVALID_CONNECTION_CLOSE_DATA);
2482 TEST_P(QuicFramerTest, GoAwayFrame) {
2483 // clang-format off
2484 unsigned char packet[] = {
2485 // public flags (8 byte connection_id)
2486 0x3C,
2487 // connection_id
2488 0x10, 0x32, 0x54, 0x76,
2489 0x98, 0xBA, 0xDC, 0xFE,
2490 // packet number
2491 0xBC, 0x9A, 0x78, 0x56,
2492 0x34, 0x12,
2493 // private flags
2494 0x00,
2496 // frame type (go away frame)
2497 0x03,
2498 // error code
2499 0x09, 0x00, 0x00, 0x00,
2500 // stream id
2501 0x04, 0x03, 0x02, 0x01,
2502 // error details length
2503 0x0d, 0x00,
2504 // error details
2505 'b', 'e', 'c', 'a',
2506 'u', 's', 'e', ' ',
2507 'I', ' ', 'c', 'a',
2508 'n',
2510 // clang-format on
2512 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2513 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2515 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2516 ASSERT_TRUE(visitor_.header_.get());
2517 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2519 EXPECT_EQ(UINT64_C(0x01020304), visitor_.goaway_frame_.last_good_stream_id);
2520 EXPECT_EQ(0x9, visitor_.goaway_frame_.error_code);
2521 EXPECT_EQ("because I can", visitor_.goaway_frame_.reason_phrase);
2523 const size_t reason_size = arraysize("because I can") - 1;
2524 // Now test framing boundaries.
2525 for (size_t i = kQuicFrameTypeSize;
2526 i < QuicFramer::GetMinGoAwayFrameSize() + reason_size; ++i) {
2527 string expected_error;
2528 if (i < kQuicFrameTypeSize + kQuicErrorCodeSize) {
2529 expected_error = "Unable to read go away error code.";
2530 } else if (i < kQuicFrameTypeSize + kQuicErrorCodeSize +
2531 kQuicMaxStreamIdSize) {
2532 expected_error = "Unable to read last good stream id.";
2533 } else {
2534 expected_error = "Unable to read goaway reason.";
2536 CheckProcessingFails(
2537 packet,
2538 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
2539 PACKET_6BYTE_PACKET_NUMBER, NOT_IN_FEC_GROUP),
2540 expected_error, QUIC_INVALID_GOAWAY_DATA);
2544 TEST_P(QuicFramerTest, WindowUpdateFrame) {
2545 // clang-format off
2546 unsigned char packet[] = {
2547 // public flags (8 byte connection_id)
2548 0x3C,
2549 // connection_id
2550 0x10, 0x32, 0x54, 0x76,
2551 0x98, 0xBA, 0xDC, 0xFE,
2552 // packet number
2553 0xBC, 0x9A, 0x78, 0x56,
2554 0x34, 0x12,
2555 // private flags
2556 0x00,
2558 // frame type (window update frame)
2559 0x04,
2560 // stream id
2561 0x04, 0x03, 0x02, 0x01,
2562 // byte offset
2563 0x05, 0x06, 0x07, 0x08,
2564 0x09, 0x0a, 0x0b, 0x0c,
2566 // clang-format on
2568 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2570 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2572 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2573 ASSERT_TRUE(visitor_.header_.get());
2574 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2576 EXPECT_EQ(UINT64_C(0x01020304), visitor_.window_update_frame_.stream_id);
2577 EXPECT_EQ(UINT64_C(0x0c0b0a0908070605),
2578 visitor_.window_update_frame_.byte_offset);
2580 // Now test framing boundaries.
2581 for (size_t i = kQuicFrameTypeSize;
2582 i < QuicFramer::GetWindowUpdateFrameSize(); ++i) {
2583 string expected_error;
2584 if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize) {
2585 expected_error = "Unable to read stream_id.";
2586 } else {
2587 expected_error = "Unable to read window byte_offset.";
2589 CheckProcessingFails(
2590 packet,
2591 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
2592 PACKET_6BYTE_PACKET_NUMBER, NOT_IN_FEC_GROUP),
2593 expected_error, QUIC_INVALID_WINDOW_UPDATE_DATA);
2597 TEST_P(QuicFramerTest, BlockedFrame) {
2598 // clang-format off
2599 unsigned char packet[] = {
2600 // public flags (8 byte connection_id)
2601 0x3C,
2602 // connection_id
2603 0x10, 0x32, 0x54, 0x76,
2604 0x98, 0xBA, 0xDC, 0xFE,
2605 // packet number
2606 0xBC, 0x9A, 0x78, 0x56,
2607 0x34, 0x12,
2608 // private flags
2609 0x00,
2611 // frame type (blocked frame)
2612 0x05,
2613 // stream id
2614 0x04, 0x03, 0x02, 0x01,
2616 // clang-format on
2618 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2620 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2622 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2623 ASSERT_TRUE(visitor_.header_.get());
2624 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2626 EXPECT_EQ(UINT64_C(0x01020304), visitor_.blocked_frame_.stream_id);
2628 // Now test framing boundaries.
2629 for (size_t i = kQuicFrameTypeSize; i < QuicFramer::GetBlockedFrameSize();
2630 ++i) {
2631 string expected_error = "Unable to read stream_id.";
2632 CheckProcessingFails(
2633 packet,
2634 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
2635 PACKET_6BYTE_PACKET_NUMBER, NOT_IN_FEC_GROUP),
2636 expected_error, QUIC_INVALID_BLOCKED_DATA);
2640 TEST_P(QuicFramerTest, PingFrame) {
2641 // clang-format off
2642 unsigned char packet[] = {
2643 // public flags (8 byte connection_id)
2644 0x3C,
2645 // connection_id
2646 0x10, 0x32, 0x54, 0x76,
2647 0x98, 0xBA, 0xDC, 0xFE,
2648 // packet number
2649 0xBC, 0x9A, 0x78, 0x56,
2650 0x34, 0x12,
2651 // private flags
2652 0x00,
2654 // frame type (ping frame)
2655 0x07,
2657 // clang-format on
2659 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2660 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2662 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2663 ASSERT_TRUE(visitor_.header_.get());
2664 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2666 EXPECT_EQ(1u, visitor_.ping_frames_.size());
2668 // No need to check the PING frame boundaries because it has no payload.
2671 TEST_P(QuicFramerTest, PublicResetPacket) {
2672 // clang-format off
2673 unsigned char packet[] = {
2674 // public flags (public reset, 8 byte connection_id)
2675 0x0E,
2676 // connection_id
2677 0x10, 0x32, 0x54, 0x76,
2678 0x98, 0xBA, 0xDC, 0xFE,
2679 // message tag (kPRST)
2680 'P', 'R', 'S', 'T',
2681 // num_entries (2) + padding
2682 0x02, 0x00, 0x00, 0x00,
2683 // tag kRNON
2684 'R', 'N', 'O', 'N',
2685 // end offset 8
2686 0x08, 0x00, 0x00, 0x00,
2687 // tag kRSEQ
2688 'R', 'S', 'E', 'Q',
2689 // end offset 16
2690 0x10, 0x00, 0x00, 0x00,
2691 // nonce proof
2692 0x89, 0x67, 0x45, 0x23,
2693 0x01, 0xEF, 0xCD, 0xAB,
2694 // rejected packet number
2695 0xBC, 0x9A, 0x78, 0x56,
2696 0x34, 0x12, 0x00, 0x00,
2698 // clang-format on
2700 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2701 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2702 ASSERT_EQ(QUIC_NO_ERROR, framer_.error());
2703 ASSERT_TRUE(visitor_.public_reset_packet_.get());
2704 EXPECT_EQ(UINT64_C(0xFEDCBA9876543210),
2705 visitor_.public_reset_packet_->public_header.connection_id);
2706 EXPECT_TRUE(visitor_.public_reset_packet_->public_header.reset_flag);
2707 EXPECT_FALSE(visitor_.public_reset_packet_->public_header.version_flag);
2708 EXPECT_EQ(UINT64_C(0xABCDEF0123456789),
2709 visitor_.public_reset_packet_->nonce_proof);
2710 EXPECT_EQ(UINT64_C(0x123456789ABC),
2711 visitor_.public_reset_packet_->rejected_packet_number);
2712 EXPECT_TRUE(
2713 visitor_.public_reset_packet_->client_address.address().empty());
2715 // Now test framing boundaries.
2716 for (size_t i = 0; i < arraysize(packet); ++i) {
2717 string expected_error;
2718 DVLOG(1) << "iteration: " << i;
2719 if (i < kConnectionIdOffset) {
2720 expected_error = "Unable to read public flags.";
2721 CheckProcessingFails(packet, i, expected_error,
2722 QUIC_INVALID_PACKET_HEADER);
2723 } else if (i < kPublicResetPacketMessageTagOffset) {
2724 expected_error = "Unable to read ConnectionId.";
2725 CheckProcessingFails(packet, i, expected_error,
2726 QUIC_INVALID_PACKET_HEADER);
2727 } else {
2728 expected_error = "Unable to read reset message.";
2729 CheckProcessingFails(packet, i, expected_error,
2730 QUIC_INVALID_PUBLIC_RST_PACKET);
2735 TEST_P(QuicFramerTest, PublicResetPacketWithTrailingJunk) {
2736 // clang-format off
2737 unsigned char packet[] = {
2738 // public flags (public reset, 8 byte connection_id)
2739 0x0E,
2740 // connection_id
2741 0x10, 0x32, 0x54, 0x76,
2742 0x98, 0xBA, 0xDC, 0xFE,
2743 // message tag (kPRST)
2744 'P', 'R', 'S', 'T',
2745 // num_entries (2) + padding
2746 0x02, 0x00, 0x00, 0x00,
2747 // tag kRNON
2748 'R', 'N', 'O', 'N',
2749 // end offset 8
2750 0x08, 0x00, 0x00, 0x00,
2751 // tag kRSEQ
2752 'R', 'S', 'E', 'Q',
2753 // end offset 16
2754 0x10, 0x00, 0x00, 0x00,
2755 // nonce proof
2756 0x89, 0x67, 0x45, 0x23,
2757 0x01, 0xEF, 0xCD, 0xAB,
2758 // rejected packet number
2759 0xBC, 0x9A, 0x78, 0x56,
2760 0x34, 0x12, 0x00, 0x00,
2761 // trailing junk
2762 'j', 'u', 'n', 'k',
2764 // clang-format on
2766 string expected_error = "Unable to read reset message.";
2767 CheckProcessingFails(packet, arraysize(packet), expected_error,
2768 QUIC_INVALID_PUBLIC_RST_PACKET);
2771 TEST_P(QuicFramerTest, PublicResetPacketWithClientAddress) {
2772 // clang-format off
2773 unsigned char packet[] = {
2774 // public flags (public reset, 8 byte connection_id)
2775 0x0E,
2776 // connection_id
2777 0x10, 0x32, 0x54, 0x76,
2778 0x98, 0xBA, 0xDC, 0xFE,
2779 // message tag (kPRST)
2780 'P', 'R', 'S', 'T',
2781 // num_entries (3) + padding
2782 0x03, 0x00, 0x00, 0x00,
2783 // tag kRNON
2784 'R', 'N', 'O', 'N',
2785 // end offset 8
2786 0x08, 0x00, 0x00, 0x00,
2787 // tag kRSEQ
2788 'R', 'S', 'E', 'Q',
2789 // end offset 16
2790 0x10, 0x00, 0x00, 0x00,
2791 // tag kCADR
2792 'C', 'A', 'D', 'R',
2793 // end offset 24
2794 0x18, 0x00, 0x00, 0x00,
2795 // nonce proof
2796 0x89, 0x67, 0x45, 0x23,
2797 0x01, 0xEF, 0xCD, 0xAB,
2798 // rejected packet number
2799 0xBC, 0x9A, 0x78, 0x56,
2800 0x34, 0x12, 0x00, 0x00,
2801 // client address: 4.31.198.44:443
2802 0x02, 0x00,
2803 0x04, 0x1F, 0xC6, 0x2C,
2804 0xBB, 0x01,
2806 // clang-format on
2808 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2809 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2810 ASSERT_EQ(QUIC_NO_ERROR, framer_.error());
2811 ASSERT_TRUE(visitor_.public_reset_packet_.get());
2812 EXPECT_EQ(UINT64_C(0xFEDCBA9876543210),
2813 visitor_.public_reset_packet_->public_header.connection_id);
2814 EXPECT_TRUE(visitor_.public_reset_packet_->public_header.reset_flag);
2815 EXPECT_FALSE(visitor_.public_reset_packet_->public_header.version_flag);
2816 EXPECT_EQ(UINT64_C(0xABCDEF0123456789),
2817 visitor_.public_reset_packet_->nonce_proof);
2818 EXPECT_EQ(UINT64_C(0x123456789ABC),
2819 visitor_.public_reset_packet_->rejected_packet_number);
2820 EXPECT_EQ("4.31.198.44",
2821 IPAddressToString(visitor_.public_reset_packet_->
2822 client_address.address()));
2823 EXPECT_EQ(443, visitor_.public_reset_packet_->client_address.port());
2825 // Now test framing boundaries.
2826 for (size_t i = 0; i < arraysize(packet); ++i) {
2827 string expected_error;
2828 DVLOG(1) << "iteration: " << i;
2829 if (i < kConnectionIdOffset) {
2830 expected_error = "Unable to read public flags.";
2831 CheckProcessingFails(packet, i, expected_error,
2832 QUIC_INVALID_PACKET_HEADER);
2833 } else if (i < kPublicResetPacketMessageTagOffset) {
2834 expected_error = "Unable to read ConnectionId.";
2835 CheckProcessingFails(packet, i, expected_error,
2836 QUIC_INVALID_PACKET_HEADER);
2837 } else {
2838 expected_error = "Unable to read reset message.";
2839 CheckProcessingFails(packet, i, expected_error,
2840 QUIC_INVALID_PUBLIC_RST_PACKET);
2845 TEST_P(QuicFramerTest, VersionNegotiationPacket) {
2846 // clang-format off
2847 unsigned char packet[] = {
2848 // public flags (version, 8 byte connection_id)
2849 0x3D,
2850 // connection_id
2851 0x10, 0x32, 0x54, 0x76,
2852 0x98, 0xBA, 0xDC, 0xFE,
2853 // version tag
2854 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
2855 'Q', '2', '.', '0',
2857 // clang-format on
2859 QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT);
2861 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2862 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2863 ASSERT_EQ(QUIC_NO_ERROR, framer_.error());
2864 ASSERT_TRUE(visitor_.version_negotiation_packet_.get());
2865 EXPECT_EQ(2u, visitor_.version_negotiation_packet_->versions.size());
2866 EXPECT_EQ(GetParam(), visitor_.version_negotiation_packet_->versions[0]);
2868 for (size_t i = 0; i <= kPublicFlagsSize + PACKET_8BYTE_CONNECTION_ID; ++i) {
2869 string expected_error;
2870 QuicErrorCode error_code = QUIC_INVALID_PACKET_HEADER;
2871 if (i < kConnectionIdOffset) {
2872 expected_error = "Unable to read public flags.";
2873 } else if (i < kVersionOffset) {
2874 expected_error = "Unable to read ConnectionId.";
2875 } else {
2876 expected_error = "Unable to read supported version in negotiation.";
2877 error_code = QUIC_INVALID_VERSION_NEGOTIATION_PACKET;
2879 CheckProcessingFails(packet, i, expected_error, error_code);
2883 TEST_P(QuicFramerTest, FecPacket) {
2884 // clang-format off
2885 unsigned char packet[] = {
2886 // public flags (8 byte connection_id)
2887 0x3C,
2888 // connection_id
2889 0x10, 0x32, 0x54, 0x76,
2890 0x98, 0xBA, 0xDC, 0xFE,
2891 // packet number
2892 0xBC, 0x9A, 0x78, 0x56,
2893 0x34, 0x12,
2894 // private flags (fec group & FEC)
2895 0x06,
2896 // first fec protected packet offset
2897 0x01,
2899 // redundancy
2900 'a', 'b', 'c', 'd',
2901 'e', 'f', 'g', 'h',
2902 'i', 'j', 'k', 'l',
2903 'm', 'n', 'o', 'p',
2905 // clang-format on
2907 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2908 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2910 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2911 ASSERT_TRUE(visitor_.header_.get());
2912 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2914 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2915 EXPECT_EQ(0u, visitor_.ack_frames_.size());
2916 ASSERT_EQ(1, visitor_.fec_count_);
2917 const QuicFecData& fec_data = *visitor_.fec_data_[0];
2918 EXPECT_EQ(UINT64_C(0x0123456789ABB), fec_data.fec_group);
2919 EXPECT_EQ("abcdefghijklmnop", fec_data.redundancy);
2922 TEST_P(QuicFramerTest, BuildPaddingFramePacket) {
2923 QuicPacketHeader header;
2924 header.public_header.connection_id = UINT64_C(0xFEDCBA9876543210);
2925 header.public_header.reset_flag = false;
2926 header.public_header.version_flag = false;
2927 header.fec_flag = false;
2928 header.entropy_flag = false;
2929 header.packet_packet_number = UINT64_C(0x123456789ABC);
2930 header.fec_group = 0;
2932 QuicPaddingFrame padding_frame;
2934 QuicFrames frames;
2935 frames.push_back(QuicFrame(&padding_frame));
2937 // clang-format off
2938 unsigned char packet[kMaxPacketSize] = {
2939 // public flags (8 byte connection_id)
2940 0x3C,
2941 // connection_id
2942 0x10, 0x32, 0x54, 0x76,
2943 0x98, 0xBA, 0xDC, 0xFE,
2944 // packet number
2945 0xBC, 0x9A, 0x78, 0x56,
2946 0x34, 0x12,
2947 // private flags
2948 0x00,
2950 // frame type (padding frame)
2951 0x00,
2952 0x00, 0x00, 0x00, 0x00
2954 // clang-format on
2956 uint64 header_size =
2957 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
2958 PACKET_6BYTE_PACKET_NUMBER, NOT_IN_FEC_GROUP);
2959 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1);
2961 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
2962 ASSERT_TRUE(data != nullptr);
2964 test::CompareCharArraysWithHexError("constructed packet",
2965 data->data(), data->length(),
2966 AsChars(packet),
2967 arraysize(packet));
2970 TEST_P(QuicFramerTest, Build4ByteSequenceNumberPaddingFramePacket) {
2971 QuicPacketHeader header;
2972 header.public_header.connection_id = UINT64_C(0xFEDCBA9876543210);
2973 header.public_header.reset_flag = false;
2974 header.public_header.version_flag = false;
2975 header.fec_flag = false;
2976 header.entropy_flag = false;
2977 header.public_header.packet_number_length = PACKET_4BYTE_PACKET_NUMBER;
2978 header.packet_packet_number = UINT64_C(0x123456789ABC);
2979 header.fec_group = 0;
2981 QuicPaddingFrame padding_frame;
2983 QuicFrames frames;
2984 frames.push_back(QuicFrame(&padding_frame));
2986 // clang-format off
2987 unsigned char packet[kMaxPacketSize] = {
2988 // public flags (8 byte connection_id and 4 byte packet number)
2989 0x2C,
2990 // connection_id
2991 0x10, 0x32, 0x54, 0x76,
2992 0x98, 0xBA, 0xDC, 0xFE,
2993 // packet number
2994 0xBC, 0x9A, 0x78, 0x56,
2995 // private flags
2996 0x00,
2998 // frame type (padding frame)
2999 0x00,
3000 0x00, 0x00, 0x00, 0x00
3002 // clang-format on
3004 uint64 header_size =
3005 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
3006 PACKET_4BYTE_PACKET_NUMBER, NOT_IN_FEC_GROUP);
3007 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1);
3009 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3010 ASSERT_TRUE(data != nullptr);
3012 test::CompareCharArraysWithHexError("constructed packet",
3013 data->data(), data->length(),
3014 AsChars(packet),
3015 arraysize(packet));
3018 TEST_P(QuicFramerTest, Build2ByteSequenceNumberPaddingFramePacket) {
3019 QuicPacketHeader header;
3020 header.public_header.connection_id = UINT64_C(0xFEDCBA9876543210);
3021 header.public_header.reset_flag = false;
3022 header.public_header.version_flag = false;
3023 header.fec_flag = false;
3024 header.entropy_flag = false;
3025 header.public_header.packet_number_length = PACKET_2BYTE_PACKET_NUMBER;
3026 header.packet_packet_number = UINT64_C(0x123456789ABC);
3027 header.fec_group = 0;
3029 QuicPaddingFrame padding_frame;
3031 QuicFrames frames;
3032 frames.push_back(QuicFrame(&padding_frame));
3034 // clang-format off
3035 unsigned char packet[kMaxPacketSize] = {
3036 // public flags (8 byte connection_id and 2 byte packet number)
3037 0x1C,
3038 // connection_id
3039 0x10, 0x32, 0x54, 0x76,
3040 0x98, 0xBA, 0xDC, 0xFE,
3041 // packet number
3042 0xBC, 0x9A,
3043 // private flags
3044 0x00,
3046 // frame type (padding frame)
3047 0x00,
3048 0x00, 0x00, 0x00, 0x00
3050 // clang-format on
3052 uint64 header_size =
3053 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
3054 PACKET_2BYTE_PACKET_NUMBER, NOT_IN_FEC_GROUP);
3055 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1);
3057 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3058 ASSERT_TRUE(data != nullptr);
3060 test::CompareCharArraysWithHexError("constructed packet",
3061 data->data(), data->length(),
3062 AsChars(packet),
3063 arraysize(packet));
3066 TEST_P(QuicFramerTest, Build1ByteSequenceNumberPaddingFramePacket) {
3067 QuicPacketHeader header;
3068 header.public_header.connection_id = UINT64_C(0xFEDCBA9876543210);
3069 header.public_header.reset_flag = false;
3070 header.public_header.version_flag = false;
3071 header.fec_flag = false;
3072 header.entropy_flag = false;
3073 header.public_header.packet_number_length = PACKET_1BYTE_PACKET_NUMBER;
3074 header.packet_packet_number = UINT64_C(0x123456789ABC);
3075 header.fec_group = 0;
3077 QuicPaddingFrame padding_frame;
3079 QuicFrames frames;
3080 frames.push_back(QuicFrame(&padding_frame));
3082 // clang-format off
3083 unsigned char packet[kMaxPacketSize] = {
3084 // public flags (8 byte connection_id and 1 byte packet number)
3085 0x0C,
3086 // connection_id
3087 0x10, 0x32, 0x54, 0x76,
3088 0x98, 0xBA, 0xDC, 0xFE,
3089 // packet number
3090 0xBC,
3091 // private flags
3092 0x00,
3094 // frame type (padding frame)
3095 0x00,
3096 0x00, 0x00, 0x00, 0x00
3098 // clang-format on
3100 uint64 header_size =
3101 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
3102 PACKET_1BYTE_PACKET_NUMBER, NOT_IN_FEC_GROUP);
3103 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1);
3105 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3106 ASSERT_TRUE(data != nullptr);
3108 test::CompareCharArraysWithHexError("constructed packet",
3109 data->data(), data->length(),
3110 AsChars(packet),
3111 arraysize(packet));
3114 TEST_P(QuicFramerTest, BuildStreamFramePacket) {
3115 QuicPacketHeader header;
3116 header.public_header.connection_id = UINT64_C(0xFEDCBA9876543210);
3117 header.public_header.reset_flag = false;
3118 header.public_header.version_flag = false;
3119 header.fec_flag = false;
3120 header.entropy_flag = true;
3121 header.packet_packet_number = UINT64_C(0x77123456789ABC);
3122 header.fec_group = 0;
3124 QuicStreamFrame stream_frame(0x01020304, true, UINT64_C(0xBA98FEDC32107654),
3125 StringPiece("hello world!"));
3127 QuicFrames frames;
3128 frames.push_back(QuicFrame(&stream_frame));
3130 // clang-format off
3131 unsigned char packet[] = {
3132 // public flags (8 byte connection_id)
3133 0x3C,
3134 // connection_id
3135 0x10, 0x32, 0x54, 0x76,
3136 0x98, 0xBA, 0xDC, 0xFE,
3137 // packet number
3138 0xBC, 0x9A, 0x78, 0x56,
3139 0x34, 0x12,
3140 // private flags (entropy)
3141 0x01,
3143 // frame type (stream frame with fin and no length)
3144 0xDF,
3145 // stream id
3146 0x04, 0x03, 0x02, 0x01,
3147 // offset
3148 0x54, 0x76, 0x10, 0x32,
3149 0xDC, 0xFE, 0x98, 0xBA,
3150 // data
3151 'h', 'e', 'l', 'l',
3152 'o', ' ', 'w', 'o',
3153 'r', 'l', 'd', '!',
3155 // clang-format on
3157 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3158 ASSERT_TRUE(data != nullptr);
3160 test::CompareCharArraysWithHexError("constructed packet",
3161 data->data(), data->length(),
3162 AsChars(packet), arraysize(packet));
3165 TEST_P(QuicFramerTest, BuildStreamFramePacketInFecGroup) {
3166 QuicPacketHeader header;
3167 header.public_header.connection_id = UINT64_C(0xFEDCBA9876543210);
3168 header.public_header.reset_flag = false;
3169 header.public_header.version_flag = false;
3170 header.fec_flag = false;
3171 header.entropy_flag = true;
3172 header.packet_packet_number = UINT64_C(0x77123456789ABC);
3173 header.is_in_fec_group = IN_FEC_GROUP;
3174 header.fec_group = UINT64_C(0x77123456789ABC);
3176 QuicStreamFrame stream_frame(0x01020304, true, UINT64_C(0xBA98FEDC32107654),
3177 StringPiece("hello world!"));
3179 QuicFrames frames;
3180 frames.push_back(QuicFrame(&stream_frame));
3181 // clang-format off
3182 unsigned char packet[] = {
3183 // public flags (8 byte connection_id)
3184 0x3C,
3185 // connection_id
3186 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
3187 // packet number
3188 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
3189 // private flags (entropy, is_in_fec_group)
3190 0x03,
3191 // FEC group
3192 0x00,
3193 // frame type (stream frame with fin and data length field)
3194 0xFF,
3195 // stream id
3196 0x04, 0x03, 0x02, 0x01,
3197 // offset
3198 0x54, 0x76, 0x10, 0x32, 0xDC, 0xFE, 0x98, 0xBA,
3199 // data length (since packet is in an FEC group)
3200 0x0C, 0x00,
3201 // data
3202 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!',
3204 // clang-format on
3206 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3207 ASSERT_TRUE(data != nullptr);
3209 test::CompareCharArraysWithHexError("constructed packet",
3210 data->data(), data->length(),
3211 AsChars(packet), arraysize(packet));
3214 TEST_P(QuicFramerTest, BuildStreamFramePacketWithVersionFlag) {
3215 QuicPacketHeader header;
3216 header.public_header.connection_id = UINT64_C(0xFEDCBA9876543210);
3217 header.public_header.reset_flag = false;
3218 header.public_header.version_flag = true;
3219 header.fec_flag = false;
3220 header.entropy_flag = true;
3221 header.packet_packet_number = UINT64_C(0x77123456789ABC);
3222 header.fec_group = 0;
3224 QuicStreamFrame stream_frame(0x01020304, true, UINT64_C(0xBA98FEDC32107654),
3225 StringPiece("hello world!"));
3227 QuicFrames frames;
3228 frames.push_back(QuicFrame(&stream_frame));
3230 // clang-format off
3231 unsigned char packet[] = {
3232 // public flags (version, 8 byte connection_id)
3233 0x3D,
3234 // connection_id
3235 0x10,
3236 0x32,
3237 0x54,
3238 0x76,
3239 0x98,
3240 0xBA,
3241 0xDC,
3242 0xFE,
3243 // version tag
3244 'Q',
3245 '0',
3246 GetQuicVersionDigitTens(),
3247 GetQuicVersionDigitOnes(),
3248 // packet number
3249 0xBC,
3250 0x9A,
3251 0x78,
3252 0x56,
3253 0x34,
3254 0x12,
3255 // private flags (entropy)
3256 0x01,
3258 // frame type (stream frame with fin and no length)
3259 0xDF,
3260 // stream id
3261 0x04,
3262 0x03,
3263 0x02,
3264 0x01,
3265 // offset
3266 0x54,
3267 0x76,
3268 0x10,
3269 0x32,
3270 0xDC,
3271 0xFE,
3272 0x98,
3273 0xBA,
3274 // data
3275 'h',
3276 'e',
3277 'l',
3278 'l',
3279 'o',
3280 ' ',
3281 'w',
3282 'o',
3283 'r',
3284 'l',
3285 'd',
3286 '!',
3288 // clang-format on
3290 QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT);
3291 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3292 ASSERT_TRUE(data != nullptr);
3294 test::CompareCharArraysWithHexError("constructed packet",
3295 data->data(), data->length(),
3296 AsChars(packet), arraysize(packet));
3299 TEST_P(QuicFramerTest, BuildVersionNegotiationPacket) {
3300 QuicPacketPublicHeader header;
3301 header.connection_id = UINT64_C(0xFEDCBA9876543210);
3302 header.reset_flag = false;
3303 header.version_flag = true;
3305 // clang-format off
3306 unsigned char packet[] = {
3307 // public flags (version, 8 byte connection_id)
3308 0x0D,
3309 // connection_id
3310 0x10,
3311 0x32,
3312 0x54,
3313 0x76,
3314 0x98,
3315 0xBA,
3316 0xDC,
3317 0xFE,
3318 // version tag
3319 'Q',
3320 '0',
3321 GetQuicVersionDigitTens(),
3322 GetQuicVersionDigitOnes(),
3324 // clang-format on
3326 QuicVersionVector versions;
3327 versions.push_back(GetParam());
3328 scoped_ptr<QuicEncryptedPacket> data(
3329 framer_.BuildVersionNegotiationPacket(header, versions));
3331 test::CompareCharArraysWithHexError("constructed packet", data->data(),
3332 data->length(), AsChars(packet),
3333 arraysize(packet));
3336 TEST_P(QuicFramerTest, BuildAckFramePacket) {
3337 QuicPacketHeader header;
3338 header.public_header.connection_id = UINT64_C(0xFEDCBA9876543210);
3339 header.public_header.reset_flag = false;
3340 header.public_header.version_flag = false;
3341 header.fec_flag = false;
3342 header.entropy_flag = true;
3343 header.packet_packet_number = UINT64_C(0x770123456789AA8);
3344 header.fec_group = 0;
3346 QuicAckFrame ack_frame;
3347 ack_frame.entropy_hash = 0x43;
3348 ack_frame.largest_observed = UINT64_C(0x770123456789ABF);
3349 ack_frame.delta_time_largest_observed = QuicTime::Delta::Zero();
3350 ack_frame.missing_packets.insert(UINT64_C(0x770123456789ABE));
3352 QuicFrames frames;
3353 frames.push_back(QuicFrame(&ack_frame));
3355 // clang-format off
3356 unsigned char packet[] = {
3357 // public flags (8 byte connection_id)
3358 0x3C,
3359 // connection_id
3360 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
3361 // packet number
3362 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
3363 // private flags (entropy)
3364 0x01,
3366 // frame type (ack frame)
3367 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
3368 0x6C,
3369 // entropy hash of all received packets.
3370 0x43,
3371 // largest observed packet number
3372 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12,
3373 // Zero delta time.
3374 0x00, 0x00,
3375 // num received packets.
3376 0x00,
3377 // num missing packet ranges
3378 0x01,
3379 // missing packet delta
3380 0x01,
3381 // 0 more missing packets in range.
3382 0x00,
3383 // 0 revived packets.
3384 0x00,
3386 // clang-format on
3388 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3389 ASSERT_TRUE(data != nullptr);
3391 test::CompareCharArraysWithHexError("constructed packet",
3392 data->data(), data->length(),
3393 AsChars(packet), arraysize(packet));
3396 // TODO(jri): Add test for tuncated packets in which the original ack frame had
3397 // revived packets. (In both the large and small packet cases below).
3399 TEST_P(QuicFramerTest, BuildTruncatedAckFrameLargePacket) {
3400 QuicPacketHeader header;
3401 header.public_header.connection_id = UINT64_C(0xFEDCBA9876543210);
3402 header.public_header.reset_flag = false;
3403 header.public_header.version_flag = false;
3404 header.fec_flag = false;
3405 header.entropy_flag = true;
3406 header.packet_packet_number = UINT64_C(0x770123456789AA8);
3407 header.fec_group = 0;
3409 QuicAckFrame ack_frame;
3410 // This entropy hash is different from what shows up in the packet below,
3411 // since entropy is recomputed by the framer on ack truncation (by
3412 // TestEntropyCalculator for this test.)
3413 ack_frame.entropy_hash = 0x43;
3414 ack_frame.largest_observed = 2 * 300;
3415 ack_frame.delta_time_largest_observed = QuicTime::Delta::Zero();
3416 for (size_t i = 1; i < 2 * 300; i += 2) {
3417 ack_frame.missing_packets.insert(i);
3420 QuicFrames frames;
3421 frames.push_back(QuicFrame(&ack_frame));
3423 // clang-format off
3424 unsigned char packet[] = {
3425 // public flags (8 byte connection_id)
3426 0x3C,
3427 // connection_id
3428 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
3429 // packet number
3430 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
3431 // private flags (entropy)
3432 0x01,
3434 // frame type (ack frame)
3435 // (has nacks, is truncated, 2 byte largest observed, 1 byte delta)
3436 0x74,
3437 // entropy hash of all received packets, set to 1 by TestEntropyCalculator
3438 // since ack is truncated.
3439 0x01,
3440 // 2-byte largest observed packet number.
3441 // Expected to be 510 (0x1FE), since only 255 nack ranges can fit.
3442 0xFE, 0x01,
3443 // Zero delta time.
3444 0x00, 0x00,
3445 // num missing packet ranges (limited to 255 by size of this field).
3446 0xFF,
3447 // {missing packet delta, further missing packets in range}
3448 // 6 nack ranges x 42 + 3 nack ranges
3449 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3450 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3451 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3452 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3453 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3454 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3455 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3456 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3457 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3458 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3460 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3461 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3462 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3463 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3464 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3465 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3466 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3467 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3468 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3469 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3471 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3472 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3473 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3474 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3475 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3476 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3477 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3478 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3479 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3480 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3482 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3483 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3484 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3485 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3486 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3487 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3488 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3489 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3490 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3491 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3493 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3494 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3495 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3497 // 0 revived packets.
3498 0x00,
3500 // clang-format on
3502 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3503 ASSERT_TRUE(data != nullptr);
3505 test::CompareCharArraysWithHexError("constructed packet",
3506 data->data(), data->length(),
3507 AsChars(packet), arraysize(packet));
3510 TEST_P(QuicFramerTest, BuildTruncatedAckFrameSmallPacket) {
3511 QuicPacketHeader header;
3512 header.public_header.connection_id = UINT64_C(0xFEDCBA9876543210);
3513 header.public_header.reset_flag = false;
3514 header.public_header.version_flag = false;
3515 header.fec_flag = false;
3516 header.entropy_flag = true;
3517 header.packet_packet_number = UINT64_C(0x770123456789AA8);
3518 header.fec_group = 0;
3520 QuicAckFrame ack_frame;
3521 // This entropy hash is different from what shows up in the packet below,
3522 // since entropy is recomputed by the framer on ack truncation (by
3523 // TestEntropyCalculator for this test.)
3524 ack_frame.entropy_hash = 0x43;
3525 ack_frame.largest_observed = 2 * 300;
3526 ack_frame.delta_time_largest_observed = QuicTime::Delta::Zero();
3527 for (size_t i = 1; i < 2 * 300; i += 2) {
3528 ack_frame.missing_packets.insert(i);
3531 QuicFrames frames;
3532 frames.push_back(QuicFrame(&ack_frame));
3534 // clang-format off
3535 unsigned char packet[] = {
3536 // public flags (8 byte connection_id)
3537 0x3C,
3538 // connection_id
3539 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
3540 // packet number
3541 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
3542 // private flags (entropy)
3543 0x01,
3545 // frame type (ack frame)
3546 // (has nacks, is truncated, 2 byte largest observed, 1 byte delta)
3547 0x74,
3548 // entropy hash of all received packets, set to 1 by TestEntropyCalculator
3549 // since ack is truncated.
3550 0x01,
3551 // 2-byte largest observed packet number.
3552 // Expected to be 12 (0x0C), since only 6 nack ranges can fit.
3553 0x0C, 0x00,
3554 // Zero delta time.
3555 0x00, 0x00,
3556 // num missing packet ranges (limited to 6 by packet size of 37).
3557 0x06,
3558 // {missing packet delta, further missing packets in range}
3559 // 6 nack ranges
3560 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
3561 // 0 revived packets.
3562 0x00,
3564 // clang-format on
3566 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames, 37u));
3567 ASSERT_TRUE(data != nullptr);
3568 // Expect 1 byte unused since at least 2 bytes are needed to fit more nacks.
3569 EXPECT_EQ(36u, data->length());
3570 test::CompareCharArraysWithHexError("constructed packet",
3571 data->data(), data->length(),
3572 AsChars(packet), arraysize(packet));
3575 TEST_P(QuicFramerTest, BuildStopWaitingPacket) {
3576 QuicPacketHeader header;
3577 header.public_header.connection_id = UINT64_C(0xFEDCBA9876543210);
3578 header.public_header.reset_flag = false;
3579 header.public_header.version_flag = false;
3580 header.fec_flag = false;
3581 header.entropy_flag = true;
3582 header.packet_packet_number = UINT64_C(0x770123456789AA8);
3583 header.fec_group = 0;
3585 QuicStopWaitingFrame stop_waiting_frame;
3586 stop_waiting_frame.entropy_hash = 0x14;
3587 stop_waiting_frame.least_unacked = UINT64_C(0x770123456789AA0);
3589 QuicFrames frames;
3590 frames.push_back(QuicFrame(&stop_waiting_frame));
3592 // clang-format off
3593 unsigned char packet[] = {
3594 // public flags (8 byte connection_id)
3595 0x3C,
3596 // connection_id
3597 0x10, 0x32, 0x54, 0x76,
3598 0x98, 0xBA, 0xDC, 0xFE,
3599 // packet number
3600 0xA8, 0x9A, 0x78, 0x56,
3601 0x34, 0x12,
3602 // private flags (entropy)
3603 0x01,
3605 // frame type (stop waiting frame)
3606 0x06,
3607 // entropy hash of sent packets till least awaiting - 1.
3608 0x14,
3609 // least packet number awaiting an ack, delta from packet number.
3610 0x08, 0x00, 0x00, 0x00,
3611 0x00, 0x00,
3613 // clang-format on
3615 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3616 ASSERT_TRUE(data != nullptr);
3618 test::CompareCharArraysWithHexError("constructed packet",
3619 data->data(), data->length(),
3620 AsChars(packet), arraysize(packet));
3623 TEST_P(QuicFramerTest, BuildRstFramePacketQuicVersion24) {
3624 if (version_ > QUIC_VERSION_24) {
3625 // QUIC_VERSION_25 removes the error_details field from QuicRstStreamFrame.
3626 return;
3629 QuicPacketHeader header;
3630 header.public_header.connection_id = UINT64_C(0xFEDCBA9876543210);
3631 header.public_header.reset_flag = false;
3632 header.public_header.version_flag = false;
3633 header.fec_flag = false;
3634 header.entropy_flag = false;
3635 header.packet_packet_number = UINT64_C(0x123456789ABC);
3636 header.fec_group = 0;
3638 QuicRstStreamFrame rst_frame;
3639 rst_frame.stream_id = 0x01020304;
3640 rst_frame.error_code = static_cast<QuicRstStreamErrorCode>(0x05060708);
3641 rst_frame.error_details = "because I can";
3642 rst_frame.byte_offset = 0x0807060504030201;
3644 // clang-format off
3645 unsigned char packet[] = {
3646 // public flags (8 byte connection_id)
3647 0x3C,
3648 // connection_id
3649 0x10, 0x32, 0x54, 0x76,
3650 0x98, 0xBA, 0xDC, 0xFE,
3651 // packet number
3652 0xBC, 0x9A, 0x78, 0x56,
3653 0x34, 0x12,
3654 // private flags
3655 0x00,
3657 // frame type (rst stream frame)
3658 0x01,
3659 // stream id
3660 0x04, 0x03, 0x02, 0x01,
3661 // sent byte offset
3662 0x01, 0x02, 0x03, 0x04,
3663 0x05, 0x06, 0x07, 0x08,
3664 // error code
3665 0x08, 0x07, 0x06, 0x05,
3666 // error details length
3667 0x0d, 0x00,
3668 // error details
3669 'b', 'e', 'c', 'a',
3670 'u', 's', 'e', ' ',
3671 'I', ' ', 'c', 'a',
3672 'n',
3674 // clang-format on
3676 QuicFrames frames;
3677 frames.push_back(QuicFrame(&rst_frame));
3679 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3680 ASSERT_TRUE(data != nullptr);
3682 test::CompareCharArraysWithHexError("constructed packet", data->data(),
3683 data->length(), AsChars(packet),
3684 arraysize(packet));
3687 TEST_P(QuicFramerTest, BuildRstFramePacketQuic) {
3688 if (version_ <= QUIC_VERSION_24) {
3689 // QUIC_VERSION_25 removes the error_details field from QuicRstStreamFrame.
3690 return;
3693 QuicPacketHeader header;
3694 header.public_header.connection_id = UINT64_C(0xFEDCBA9876543210);
3695 header.public_header.reset_flag = false;
3696 header.public_header.version_flag = false;
3697 header.fec_flag = false;
3698 header.entropy_flag = false;
3699 header.packet_packet_number = UINT64_C(0x123456789ABC);
3700 header.fec_group = 0;
3702 QuicRstStreamFrame rst_frame;
3703 rst_frame.stream_id = 0x01020304;
3704 rst_frame.error_code = static_cast<QuicRstStreamErrorCode>(0x05060708);
3705 rst_frame.byte_offset = 0x0807060504030201;
3707 // clang-format off
3708 unsigned char packet[] = {
3709 // public flags (8 byte connection_id)
3710 0x3C,
3711 // connection_id
3712 0x10, 0x32, 0x54, 0x76,
3713 0x98, 0xBA, 0xDC, 0xFE,
3714 // packet number
3715 0xBC, 0x9A, 0x78, 0x56,
3716 0x34, 0x12,
3717 // private flags
3718 0x00,
3720 // frame type (rst stream frame)
3721 0x01,
3722 // stream id
3723 0x04, 0x03, 0x02, 0x01,
3724 // sent byte offset
3725 0x01, 0x02, 0x03, 0x04,
3726 0x05, 0x06, 0x07, 0x08,
3727 // error code
3728 0x08, 0x07, 0x06, 0x05,
3730 // clang-format on
3732 QuicFrames frames;
3733 frames.push_back(QuicFrame(&rst_frame));
3735 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3736 ASSERT_TRUE(data != nullptr);
3738 test::CompareCharArraysWithHexError("constructed packet", data->data(),
3739 data->length(), AsChars(packet),
3740 arraysize(packet));
3743 TEST_P(QuicFramerTest, BuildCloseFramePacket) {
3744 QuicPacketHeader header;
3745 header.public_header.connection_id = UINT64_C(0xFEDCBA9876543210);
3746 header.public_header.reset_flag = false;
3747 header.public_header.version_flag = false;
3748 header.fec_flag = false;
3749 header.entropy_flag = true;
3750 header.packet_packet_number = UINT64_C(0x123456789ABC);
3751 header.fec_group = 0;
3753 QuicConnectionCloseFrame close_frame;
3754 close_frame.error_code = static_cast<QuicErrorCode>(0x05060708);
3755 close_frame.error_details = "because I can";
3757 QuicFrames frames;
3758 frames.push_back(QuicFrame(&close_frame));
3760 // clang-format off
3761 unsigned char packet[] = {
3762 // public flags (8 byte connection_id)
3763 0x3C,
3764 // connection_id
3765 0x10, 0x32, 0x54, 0x76,
3766 0x98, 0xBA, 0xDC, 0xFE,
3767 // packet number
3768 0xBC, 0x9A, 0x78, 0x56,
3769 0x34, 0x12,
3770 // private flags (entropy)
3771 0x01,
3773 // frame type (connection close frame)
3774 0x02,
3775 // error code
3776 0x08, 0x07, 0x06, 0x05,
3777 // error details length
3778 0x0d, 0x00,
3779 // error details
3780 'b', 'e', 'c', 'a',
3781 'u', 's', 'e', ' ',
3782 'I', ' ', 'c', 'a',
3783 'n',
3785 // clang-format on
3787 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3788 ASSERT_TRUE(data != nullptr);
3790 test::CompareCharArraysWithHexError("constructed packet",
3791 data->data(), data->length(),
3792 AsChars(packet), arraysize(packet));
3795 TEST_P(QuicFramerTest, BuildGoAwayPacket) {
3796 QuicPacketHeader header;
3797 header.public_header.connection_id = UINT64_C(0xFEDCBA9876543210);
3798 header.public_header.reset_flag = false;
3799 header.public_header.version_flag = false;
3800 header.fec_flag = false;
3801 header.entropy_flag = true;
3802 header.packet_packet_number = UINT64_C(0x123456789ABC);
3803 header.fec_group = 0;
3805 QuicGoAwayFrame goaway_frame;
3806 goaway_frame.error_code = static_cast<QuicErrorCode>(0x05060708);
3807 goaway_frame.last_good_stream_id = 0x01020304;
3808 goaway_frame.reason_phrase = "because I can";
3810 QuicFrames frames;
3811 frames.push_back(QuicFrame(&goaway_frame));
3813 // clang-format off
3814 unsigned char packet[] = {
3815 // public flags (8 byte connection_id)
3816 0x3C,
3817 // connection_id
3818 0x10, 0x32, 0x54, 0x76,
3819 0x98, 0xBA, 0xDC, 0xFE,
3820 // packet number
3821 0xBC, 0x9A, 0x78, 0x56,
3822 0x34, 0x12,
3823 // private flags(entropy)
3824 0x01,
3826 // frame type (go away frame)
3827 0x03,
3828 // error code
3829 0x08, 0x07, 0x06, 0x05,
3830 // stream id
3831 0x04, 0x03, 0x02, 0x01,
3832 // error details length
3833 0x0d, 0x00,
3834 // error details
3835 'b', 'e', 'c', 'a',
3836 'u', 's', 'e', ' ',
3837 'I', ' ', 'c', 'a',
3838 'n',
3840 // clang-format on
3842 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3843 ASSERT_TRUE(data != nullptr);
3845 test::CompareCharArraysWithHexError("constructed packet",
3846 data->data(), data->length(),
3847 AsChars(packet), arraysize(packet));
3850 TEST_P(QuicFramerTest, BuildWindowUpdatePacket) {
3851 QuicPacketHeader header;
3852 header.public_header.connection_id = UINT64_C(0xFEDCBA9876543210);
3853 header.public_header.reset_flag = false;
3854 header.public_header.version_flag = false;
3855 header.fec_flag = false;
3856 header.entropy_flag = true;
3857 header.packet_packet_number = UINT64_C(0x123456789ABC);
3858 header.fec_group = 0;
3860 QuicWindowUpdateFrame window_update_frame;
3861 window_update_frame.stream_id = 0x01020304;
3862 window_update_frame.byte_offset = 0x1122334455667788;
3864 QuicFrames frames;
3865 frames.push_back(QuicFrame(&window_update_frame));
3867 // clang-format off
3868 unsigned char packet[] = {
3869 // public flags (8 byte connection_id)
3870 0x3C,
3871 // connection_id
3872 0x10, 0x32, 0x54, 0x76,
3873 0x98, 0xBA, 0xDC, 0xFE,
3874 // packet number
3875 0xBC, 0x9A, 0x78, 0x56,
3876 0x34, 0x12,
3877 // private flags(entropy)
3878 0x01,
3880 // frame type (window update frame)
3881 0x04,
3882 // stream id
3883 0x04, 0x03, 0x02, 0x01,
3884 // byte offset
3885 0x88, 0x77, 0x66, 0x55,
3886 0x44, 0x33, 0x22, 0x11,
3888 // clang-format on
3890 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3891 ASSERT_TRUE(data != nullptr);
3893 test::CompareCharArraysWithHexError("constructed packet", data->data(),
3894 data->length(), AsChars(packet),
3895 arraysize(packet));
3898 TEST_P(QuicFramerTest, BuildBlockedPacket) {
3899 QuicPacketHeader header;
3900 header.public_header.connection_id = UINT64_C(0xFEDCBA9876543210);
3901 header.public_header.reset_flag = false;
3902 header.public_header.version_flag = false;
3903 header.fec_flag = false;
3904 header.entropy_flag = true;
3905 header.packet_packet_number = UINT64_C(0x123456789ABC);
3906 header.fec_group = 0;
3908 QuicBlockedFrame blocked_frame;
3909 blocked_frame.stream_id = 0x01020304;
3911 QuicFrames frames;
3912 frames.push_back(QuicFrame(&blocked_frame));
3914 // clang-format off
3915 unsigned char packet[] = {
3916 // public flags (8 byte connection_id)
3917 0x3C,
3918 // connection_id
3919 0x10, 0x32, 0x54, 0x76,
3920 0x98, 0xBA, 0xDC, 0xFE,
3921 // packet number
3922 0xBC, 0x9A, 0x78, 0x56,
3923 0x34, 0x12,
3924 // private flags(entropy)
3925 0x01,
3927 // frame type (blocked frame)
3928 0x05,
3929 // stream id
3930 0x04, 0x03, 0x02, 0x01,
3932 // clang-format on
3934 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3935 ASSERT_TRUE(data != nullptr);
3937 test::CompareCharArraysWithHexError("constructed packet", data->data(),
3938 data->length(), AsChars(packet),
3939 arraysize(packet));
3942 TEST_P(QuicFramerTest, BuildPingPacket) {
3943 QuicPacketHeader header;
3944 header.public_header.connection_id = UINT64_C(0xFEDCBA9876543210);
3945 header.public_header.reset_flag = false;
3946 header.public_header.version_flag = false;
3947 header.fec_flag = false;
3948 header.entropy_flag = true;
3949 header.packet_packet_number = UINT64_C(0x123456789ABC);
3950 header.fec_group = 0;
3952 QuicPingFrame ping_frame;
3954 QuicFrames frames;
3955 frames.push_back(QuicFrame(&ping_frame));
3957 // clang-format off
3958 unsigned char packet[] = {
3959 // public flags (8 byte connection_id)
3960 0x3C,
3961 // connection_id
3962 0x10, 0x32, 0x54, 0x76,
3963 0x98, 0xBA, 0xDC, 0xFE,
3964 // packet number
3965 0xBC, 0x9A, 0x78, 0x56,
3966 0x34, 0x12,
3967 // private flags(entropy)
3968 0x01,
3970 // frame type (ping frame)
3971 0x07,
3973 // clang-format on
3975 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
3976 ASSERT_TRUE(data != nullptr);
3978 test::CompareCharArraysWithHexError("constructed packet", data->data(),
3979 data->length(), AsChars(packet),
3980 arraysize(packet));
3983 // Test that the MTU discovery packet is serialized correctly as a PING packet.
3984 TEST_P(QuicFramerTest, BuildMtuDiscoveryPacket) {
3985 QuicPacketHeader header;
3986 header.public_header.connection_id = 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_packet_number = UINT64_C(0x123456789ABC);
3992 header.fec_group = 0;
3994 QuicMtuDiscoveryFrame mtu_discovery_frame;
3996 QuicFrames frames;
3997 frames.push_back(QuicFrame(&mtu_discovery_frame));
3999 // clang-format off
4000 unsigned char packet[] = {
4001 // public flags (8 byte connection_id)
4002 0x3C,
4003 // connection_id
4004 0x10, 0x32, 0x54, 0x76,
4005 0x98, 0xBA, 0xDC, 0xFE,
4006 // packet number
4007 0xBC, 0x9A, 0x78, 0x56,
4008 0x34, 0x12,
4009 // private flags(entropy)
4010 0x01,
4012 // frame type (ping frame)
4013 0x07,
4015 // clang-format on
4017 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames));
4018 ASSERT_TRUE(data != nullptr);
4020 test::CompareCharArraysWithHexError("constructed packet", data->data(),
4021 data->length(), AsChars(packet),
4022 arraysize(packet));
4025 TEST_P(QuicFramerTest, BuildPublicResetPacket) {
4026 QuicPublicResetPacket reset_packet;
4027 reset_packet.public_header.connection_id = UINT64_C(0xFEDCBA9876543210);
4028 reset_packet.public_header.reset_flag = true;
4029 reset_packet.public_header.version_flag = false;
4030 reset_packet.rejected_packet_number = UINT64_C(0x123456789ABC);
4031 reset_packet.nonce_proof = UINT64_C(0xABCDEF0123456789);
4033 // clang-format off
4034 unsigned char packet[] = {
4035 // public flags (public reset, 8 byte ConnectionId)
4036 0x0E,
4037 // connection_id
4038 0x10, 0x32, 0x54, 0x76,
4039 0x98, 0xBA, 0xDC, 0xFE,
4040 // message tag (kPRST)
4041 'P', 'R', 'S', 'T',
4042 // num_entries (2) + padding
4043 0x02, 0x00, 0x00, 0x00,
4044 // tag kRNON
4045 'R', 'N', 'O', 'N',
4046 // end offset 8
4047 0x08, 0x00, 0x00, 0x00,
4048 // tag kRSEQ
4049 'R', 'S', 'E', 'Q',
4050 // end offset 16
4051 0x10, 0x00, 0x00, 0x00,
4052 // nonce proof
4053 0x89, 0x67, 0x45, 0x23,
4054 0x01, 0xEF, 0xCD, 0xAB,
4055 // rejected packet number
4056 0xBC, 0x9A, 0x78, 0x56,
4057 0x34, 0x12, 0x00, 0x00,
4059 // clang-format on
4061 scoped_ptr<QuicEncryptedPacket> data(
4062 framer_.BuildPublicResetPacket(reset_packet));
4063 ASSERT_TRUE(data != nullptr);
4065 test::CompareCharArraysWithHexError("constructed packet",
4066 data->data(), data->length(),
4067 AsChars(packet), arraysize(packet));
4070 TEST_P(QuicFramerTest, BuildPublicResetPacketWithClientAddress) {
4071 QuicPublicResetPacket reset_packet;
4072 reset_packet.public_header.connection_id = UINT64_C(0xFEDCBA9876543210);
4073 reset_packet.public_header.reset_flag = true;
4074 reset_packet.public_header.version_flag = false;
4075 reset_packet.rejected_packet_number = UINT64_C(0x123456789ABC);
4076 reset_packet.nonce_proof = UINT64_C(0xABCDEF0123456789);
4077 reset_packet.client_address = IPEndPoint(Loopback4(), 0x1234);
4079 // clang-format off
4080 unsigned char packet[] = {
4081 // public flags (public reset, 8 byte ConnectionId)
4082 0x0E,
4083 // connection_id
4084 0x10, 0x32, 0x54, 0x76,
4085 0x98, 0xBA, 0xDC, 0xFE,
4086 // message tag (kPRST)
4087 'P', 'R', 'S', 'T',
4088 // num_entries (3) + padding
4089 0x03, 0x00, 0x00, 0x00,
4090 // tag kRNON
4091 'R', 'N', 'O', 'N',
4092 // end offset 8
4093 0x08, 0x00, 0x00, 0x00,
4094 // tag kRSEQ
4095 'R', 'S', 'E', 'Q',
4096 // end offset 16
4097 0x10, 0x00, 0x00, 0x00,
4098 // tag kCADR
4099 'C', 'A', 'D', 'R',
4100 // end offset 24
4101 0x18, 0x00, 0x00, 0x00,
4102 // nonce proof
4103 0x89, 0x67, 0x45, 0x23,
4104 0x01, 0xEF, 0xCD, 0xAB,
4105 // rejected packet number
4106 0xBC, 0x9A, 0x78, 0x56,
4107 0x34, 0x12, 0x00, 0x00,
4108 // client address
4109 0x02, 0x00,
4110 0x7F, 0x00, 0x00, 0x01,
4111 0x34, 0x12,
4113 // clang-format on
4115 scoped_ptr<QuicEncryptedPacket> data(
4116 framer_.BuildPublicResetPacket(reset_packet));
4117 ASSERT_TRUE(data != nullptr);
4119 test::CompareCharArraysWithHexError("constructed packet",
4120 data->data(), data->length(),
4121 AsChars(packet), arraysize(packet));
4124 TEST_P(QuicFramerTest, BuildFecPacket) {
4125 QuicPacketHeader header;
4126 header.public_header.connection_id = UINT64_C(0xFEDCBA9876543210);
4127 header.public_header.reset_flag = false;
4128 header.public_header.version_flag = false;
4129 header.fec_flag = true;
4130 header.entropy_flag = true;
4131 header.packet_packet_number = (UINT64_C(0x123456789ABC));
4132 header.is_in_fec_group = IN_FEC_GROUP;
4133 header.fec_group = UINT64_C(0x123456789ABB);
4135 QuicFecData fec_data;
4136 fec_data.fec_group = 1;
4137 fec_data.redundancy = "abcdefghijklmnop";
4139 // clang-format off
4140 unsigned char packet[] = {
4141 // public flags (8 byte connection_id)
4142 0x3C,
4143 // connection_id
4144 0x10, 0x32, 0x54, 0x76,
4145 0x98, 0xBA, 0xDC, 0xFE,
4146 // packet number
4147 0xBC, 0x9A, 0x78, 0x56,
4148 0x34, 0x12,
4149 // private flags (entropy & fec group & fec packet)
4150 0x07,
4151 // first fec protected packet offset
4152 0x01,
4154 // redundancy
4155 'a', 'b', 'c', 'd',
4156 'e', 'f', 'g', 'h',
4157 'i', 'j', 'k', 'l',
4158 'm', 'n', 'o', 'p',
4160 // clang-format on
4162 scoped_ptr<QuicPacket> data(framer_.BuildFecPacket(header, fec_data));
4163 ASSERT_TRUE(data != nullptr);
4165 test::CompareCharArraysWithHexError("constructed packet",
4166 data->data(), data->length(),
4167 AsChars(packet), arraysize(packet));
4170 TEST_P(QuicFramerTest, EncryptPacket) {
4171 QuicPacketNumber packet_number = UINT64_C(0x123456789ABC);
4172 // clang-format off
4173 unsigned char packet[] = {
4174 // public flags (8 byte connection_id)
4175 0x3C,
4176 // connection_id
4177 0x10, 0x32, 0x54, 0x76,
4178 0x98, 0xBA, 0xDC, 0xFE,
4179 // packet number
4180 0xBC, 0x9A, 0x78, 0x56,
4181 0x34, 0x12,
4182 // private flags (fec group & fec packet)
4183 0x06,
4184 // first fec protected packet offset
4185 0x01,
4187 // redundancy
4188 'a', 'b', 'c', 'd',
4189 'e', 'f', 'g', 'h',
4190 'i', 'j', 'k', 'l',
4191 'm', 'n', 'o', 'p',
4193 // clang-format on
4195 scoped_ptr<QuicPacket> raw(new QuicPacket(
4196 AsChars(packet), arraysize(packet), false, PACKET_8BYTE_CONNECTION_ID,
4197 !kIncludeVersion, PACKET_6BYTE_PACKET_NUMBER));
4198 char buffer[kMaxPacketSize];
4199 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPayload(
4200 ENCRYPTION_NONE, packet_number, *raw, buffer, kMaxPacketSize));
4202 ASSERT_TRUE(encrypted.get() != nullptr);
4203 EXPECT_TRUE(CheckEncryption(packet_number, raw.get()));
4206 TEST_P(QuicFramerTest, EncryptPacketWithVersionFlag) {
4207 QuicPacketNumber packet_number = UINT64_C(0x123456789ABC);
4208 // clang-format off
4209 unsigned char packet[] = {
4210 // public flags (version, 8 byte connection_id)
4211 0x3D,
4212 // connection_id
4213 0x10, 0x32, 0x54, 0x76,
4214 0x98, 0xBA, 0xDC, 0xFE,
4215 // version tag
4216 'Q', '.', '1', '0',
4217 // packet number
4218 0xBC, 0x9A, 0x78, 0x56,
4219 0x34, 0x12,
4220 // private flags (fec group & fec flags)
4221 0x06,
4222 // first fec protected packet offset
4223 0x01,
4225 // redundancy
4226 'a', 'b', 'c', 'd',
4227 'e', 'f', 'g', 'h',
4228 'i', 'j', 'k', 'l',
4229 'm', 'n', 'o', 'p',
4231 // clang-format on
4233 scoped_ptr<QuicPacket> raw(new QuicPacket(
4234 AsChars(packet), arraysize(packet), false, PACKET_8BYTE_CONNECTION_ID,
4235 kIncludeVersion, PACKET_6BYTE_PACKET_NUMBER));
4236 char buffer[kMaxPacketSize];
4237 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPayload(
4238 ENCRYPTION_NONE, packet_number, *raw, buffer, kMaxPacketSize));
4240 ASSERT_TRUE(encrypted.get() != nullptr);
4241 EXPECT_TRUE(CheckEncryption(packet_number, raw.get()));
4244 TEST_P(QuicFramerTest, AckTruncationLargePacket) {
4245 QuicPacketHeader header;
4246 header.public_header.connection_id = UINT64_C(0xFEDCBA9876543210);
4247 header.public_header.reset_flag = false;
4248 header.public_header.version_flag = false;
4249 header.fec_flag = false;
4250 header.entropy_flag = false;
4251 header.packet_packet_number = UINT64_C(0x123456789ABC);
4252 header.fec_group = 0;
4254 // Create a packet with just the ack.
4255 QuicAckFrame ack_frame = MakeAckFrameWithNackRanges(300, 0u);
4256 QuicFrame frame;
4257 frame.type = ACK_FRAME;
4258 frame.ack_frame = &ack_frame;
4259 QuicFrames frames;
4260 frames.push_back(frame);
4262 // Build an ack packet with truncation due to limit in number of nack ranges.
4263 scoped_ptr<QuicPacket> raw_ack_packet(BuildDataPacket(header, frames));
4264 ASSERT_TRUE(raw_ack_packet != nullptr);
4265 char buffer[kMaxPacketSize];
4266 scoped_ptr<QuicEncryptedPacket> ack_packet(
4267 framer_.EncryptPayload(ENCRYPTION_NONE, header.packet_packet_number,
4268 *raw_ack_packet, buffer, kMaxPacketSize));
4269 // Now make sure we can turn our ack packet back into an ack frame.
4270 ASSERT_TRUE(framer_.ProcessPacket(*ack_packet));
4271 ASSERT_EQ(1u, visitor_.ack_frames_.size());
4272 QuicAckFrame& processed_ack_frame = *visitor_.ack_frames_[0];
4273 EXPECT_TRUE(processed_ack_frame.is_truncated);
4274 EXPECT_EQ(510u, processed_ack_frame.largest_observed);
4275 ASSERT_EQ(255u, processed_ack_frame.missing_packets.size());
4276 PacketNumberSet::const_iterator missing_iter =
4277 processed_ack_frame.missing_packets.begin();
4278 EXPECT_EQ(1u, *missing_iter);
4279 PacketNumberSet::const_reverse_iterator last_missing_iter =
4280 processed_ack_frame.missing_packets.rbegin();
4281 EXPECT_EQ(509u, *last_missing_iter);
4284 TEST_P(QuicFramerTest, AckTruncationSmallPacket) {
4285 QuicPacketHeader header;
4286 header.public_header.connection_id = UINT64_C(0xFEDCBA9876543210);
4287 header.public_header.reset_flag = false;
4288 header.public_header.version_flag = false;
4289 header.fec_flag = false;
4290 header.entropy_flag = false;
4291 header.packet_packet_number = UINT64_C(0x123456789ABC);
4292 header.fec_group = 0;
4294 // Create a packet with just the ack.
4295 QuicAckFrame ack_frame = MakeAckFrameWithNackRanges(300, 0u);
4296 QuicFrame frame;
4297 frame.type = ACK_FRAME;
4298 frame.ack_frame = &ack_frame;
4299 QuicFrames frames;
4300 frames.push_back(frame);
4302 // Build an ack packet with truncation due to limit in number of nack ranges.
4303 scoped_ptr<QuicPacket> raw_ack_packet(BuildDataPacket(header, frames, 500));
4304 ASSERT_TRUE(raw_ack_packet != nullptr);
4305 char buffer[kMaxPacketSize];
4306 scoped_ptr<QuicEncryptedPacket> ack_packet(
4307 framer_.EncryptPayload(ENCRYPTION_NONE, header.packet_packet_number,
4308 *raw_ack_packet, buffer, kMaxPacketSize));
4309 // Now make sure we can turn our ack packet back into an ack frame.
4310 ASSERT_TRUE(framer_.ProcessPacket(*ack_packet));
4311 ASSERT_EQ(1u, visitor_.ack_frames_.size());
4312 QuicAckFrame& processed_ack_frame = *visitor_.ack_frames_[0];
4313 EXPECT_TRUE(processed_ack_frame.is_truncated);
4314 EXPECT_EQ(476u, processed_ack_frame.largest_observed);
4315 ASSERT_EQ(238u, processed_ack_frame.missing_packets.size());
4316 PacketNumberSet::const_iterator missing_iter =
4317 processed_ack_frame.missing_packets.begin();
4318 EXPECT_EQ(1u, *missing_iter);
4319 PacketNumberSet::const_reverse_iterator last_missing_iter =
4320 processed_ack_frame.missing_packets.rbegin();
4321 EXPECT_EQ(475u, *last_missing_iter);
4324 TEST_P(QuicFramerTest, CleanTruncation) {
4325 QuicPacketHeader header;
4326 header.public_header.connection_id = UINT64_C(0xFEDCBA9876543210);
4327 header.public_header.reset_flag = false;
4328 header.public_header.version_flag = false;
4329 header.fec_flag = false;
4330 header.entropy_flag = true;
4331 header.packet_packet_number = UINT64_C(0x123456789ABC);
4332 header.fec_group = 0;
4334 QuicAckFrame ack_frame;
4335 ack_frame.largest_observed = 201;
4336 for (uint64 i = 1; i < ack_frame.largest_observed; ++i) {
4337 ack_frame.missing_packets.insert(i);
4340 // Create a packet with just the ack.
4341 QuicFrame frame;
4342 frame.type = ACK_FRAME;
4343 frame.ack_frame = &ack_frame;
4344 QuicFrames frames;
4345 frames.push_back(frame);
4347 scoped_ptr<QuicPacket> raw_ack_packet(BuildDataPacket(header, frames));
4348 ASSERT_TRUE(raw_ack_packet != nullptr);
4350 char buffer[kMaxPacketSize];
4351 scoped_ptr<QuicEncryptedPacket> ack_packet(
4352 framer_.EncryptPayload(ENCRYPTION_NONE, header.packet_packet_number,
4353 *raw_ack_packet, buffer, kMaxPacketSize));
4355 // Now make sure we can turn our ack packet back into an ack frame.
4356 ASSERT_TRUE(framer_.ProcessPacket(*ack_packet));
4358 // Test for clean truncation of the ack by comparing the length of the
4359 // original packets to the re-serialized packets.
4360 frames.clear();
4361 frame.type = ACK_FRAME;
4362 frame.ack_frame = visitor_.ack_frames_[0];
4363 frames.push_back(frame);
4365 size_t original_raw_length = raw_ack_packet->length();
4366 raw_ack_packet.reset(BuildDataPacket(header, frames));
4367 ASSERT_TRUE(raw_ack_packet != nullptr);
4368 EXPECT_EQ(original_raw_length, raw_ack_packet->length());
4369 ASSERT_TRUE(raw_ack_packet != nullptr);
4372 TEST_P(QuicFramerTest, EntropyFlagTest) {
4373 // clang-format off
4374 unsigned char packet[] = {
4375 // public flags (8 byte connection_id)
4376 0x3C,
4377 // connection_id
4378 0x10, 0x32, 0x54, 0x76,
4379 0x98, 0xBA, 0xDC, 0xFE,
4380 // packet number
4381 0xBC, 0x9A, 0x78, 0x56,
4382 0x34, 0x12,
4383 // private flags (Entropy)
4384 0x01,
4386 // frame type (stream frame with fin and no length)
4387 0xDF,
4388 // stream id
4389 0x04, 0x03, 0x02, 0x01,
4390 // offset
4391 0x54, 0x76, 0x10, 0x32,
4392 0xDC, 0xFE, 0x98, 0xBA,
4393 // data
4394 'h', 'e', 'l', 'l',
4395 'o', ' ', 'w', 'o',
4396 'r', 'l', 'd', '!',
4398 // clang-format on
4400 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
4401 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
4402 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
4403 ASSERT_TRUE(visitor_.header_.get());
4404 EXPECT_TRUE(visitor_.header_->entropy_flag);
4405 EXPECT_EQ(1 << 4, visitor_.header_->entropy_hash);
4406 EXPECT_FALSE(visitor_.header_->fec_flag);
4409 TEST_P(QuicFramerTest, FecEntropyTest) {
4410 // clang-format off
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 number
4418 0xBC, 0x9A, 0x78, 0x56,
4419 0x34, 0x12,
4420 // private flags (Entropy & fec group & FEC)
4421 0x07,
4422 // first fec protected packet offset
4423 0xFF,
4425 // frame type (stream frame with fin and no length)
4426 0xDF,
4427 // stream id
4428 0x04, 0x03, 0x02, 0x01,
4429 // offset
4430 0x54, 0x76, 0x10, 0x32,
4431 0xDC, 0xFE, 0x98, 0xBA,
4432 // data
4433 'h', 'e', 'l', 'l',
4434 'o', ' ', 'w', 'o',
4435 'r', 'l', 'd', '!',
4437 // clang-format on
4439 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
4440 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
4441 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
4442 ASSERT_TRUE(visitor_.header_.get());
4443 EXPECT_TRUE(visitor_.header_->fec_flag);
4444 EXPECT_TRUE(visitor_.header_->entropy_flag);
4445 EXPECT_EQ(1 << 4, visitor_.header_->entropy_hash);
4448 TEST_P(QuicFramerTest, StopPacketProcessing) {
4449 // clang-format off
4450 unsigned char packet[] = {
4451 // public flags (8 byte connection_id)
4452 0x3C,
4453 // connection_id
4454 0x10, 0x32, 0x54, 0x76,
4455 0x98, 0xBA, 0xDC, 0xFE,
4456 // packet number
4457 0xBC, 0x9A, 0x78, 0x56,
4458 0x34, 0x12,
4459 // Entropy
4460 0x01,
4462 // frame type (stream frame with fin)
4463 0xFF,
4464 // stream id
4465 0x04, 0x03, 0x02, 0x01,
4466 // offset
4467 0x54, 0x76, 0x10, 0x32,
4468 0xDC, 0xFE, 0x98, 0xBA,
4469 // data length
4470 0x0c, 0x00,
4471 // data
4472 'h', 'e', 'l', 'l',
4473 'o', ' ', 'w', 'o',
4474 'r', 'l', 'd', '!',
4476 // frame type (ack frame)
4477 0x40,
4478 // entropy hash of sent packets till least awaiting - 1.
4479 0x14,
4480 // least packet number awaiting an ack
4481 0xA0, 0x9A, 0x78, 0x56,
4482 0x34, 0x12,
4483 // entropy hash of all received packets.
4484 0x43,
4485 // largest observed packet number
4486 0xBF, 0x9A, 0x78, 0x56,
4487 0x34, 0x12,
4488 // num missing packets
4489 0x01,
4490 // missing packet
4491 0xBE, 0x9A, 0x78, 0x56,
4492 0x34, 0x12,
4494 // clang-format on
4496 MockFramerVisitor visitor;
4497 framer_.set_visitor(&visitor);
4498 EXPECT_CALL(visitor, OnPacket());
4499 EXPECT_CALL(visitor, OnPacketHeader(_));
4500 EXPECT_CALL(visitor, OnStreamFrame(_)).WillOnce(Return(false));
4501 EXPECT_CALL(visitor, OnAckFrame(_)).Times(0);
4502 EXPECT_CALL(visitor, OnPacketComplete());
4503 EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)).WillOnce(Return(true));
4504 EXPECT_CALL(visitor, OnUnauthenticatedHeader(_)).WillOnce(Return(true));
4505 EXPECT_CALL(visitor, OnDecryptedPacket(_));
4507 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
4508 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
4509 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
4512 static char kTestString[] = "At least 20 characters.";
4513 static QuicStreamId kTestQuicStreamId = 1;
4514 static bool ExpectedStreamFrame(const QuicStreamFrame& frame) {
4515 return frame.stream_id == kTestQuicStreamId && !frame.fin &&
4516 frame.offset == 0 && frame.data == kTestString;
4517 // FIN is hard-coded false in ConstructEncryptedPacket.
4518 // Offset 0 is hard-coded in ConstructEncryptedPacket.
4521 // Verify that the packet returned by ConstructEncryptedPacket() can be properly
4522 // parsed by the framer.
4523 TEST_P(QuicFramerTest, ConstructEncryptedPacket) {
4524 // Since we are using ConstructEncryptedPacket, we have to set the framer's
4525 // crypto to be Null.
4526 framer_.SetDecrypter(ENCRYPTION_NONE, QuicDecrypter::Create(kNULL));
4527 framer_.SetEncrypter(ENCRYPTION_NONE, QuicEncrypter::Create(kNULL));
4529 scoped_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket(
4530 42, false, false, kTestQuicStreamId, kTestString,
4531 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER));
4533 MockFramerVisitor visitor;
4534 framer_.set_visitor(&visitor);
4535 EXPECT_CALL(visitor, OnPacket()).Times(1);
4536 EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_))
4537 .Times(1)
4538 .WillOnce(Return(true));
4539 EXPECT_CALL(visitor, OnUnauthenticatedHeader(_))
4540 .Times(1)
4541 .WillOnce(Return(true));
4542 EXPECT_CALL(visitor, OnPacketHeader(_)).Times(1).WillOnce(Return(true));
4543 EXPECT_CALL(visitor, OnDecryptedPacket(_)).Times(1);
4544 EXPECT_CALL(visitor, OnError(_)).Times(0);
4545 EXPECT_CALL(visitor, OnStreamFrame(_)).Times(0);
4546 EXPECT_CALL(visitor, OnStreamFrame(Truly(ExpectedStreamFrame))).Times(1);
4547 EXPECT_CALL(visitor, OnAckFrame(_)).Times(0);
4548 EXPECT_CALL(visitor, OnPacketComplete()).Times(1);
4550 EXPECT_TRUE(framer_.ProcessPacket(*packet));
4551 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
4554 // Verify that the packet returned by ConstructMisFramedEncryptedPacket()
4555 // does cause the framer to return an error.
4556 TEST_P(QuicFramerTest, ConstructMisFramedEncryptedPacket) {
4557 // Since we are using ConstructEncryptedPacket, we have to set the framer's
4558 // crypto to be Null.
4559 framer_.SetDecrypter(ENCRYPTION_NONE, QuicDecrypter::Create(kNULL));
4560 framer_.SetEncrypter(ENCRYPTION_NONE, QuicEncrypter::Create(kNULL));
4562 scoped_ptr<QuicEncryptedPacket> packet(ConstructMisFramedEncryptedPacket(
4563 42, false, false, kTestQuicStreamId, kTestString,
4564 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, nullptr));
4566 MockFramerVisitor visitor;
4567 framer_.set_visitor(&visitor);
4568 EXPECT_CALL(visitor, OnPacket()).Times(1);
4569 EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_))
4570 .Times(1)
4571 .WillOnce(Return(true));
4572 EXPECT_CALL(visitor, OnUnauthenticatedHeader(_))
4573 .Times(1)
4574 .WillOnce(Return(true));
4575 EXPECT_CALL(visitor, OnPacketHeader(_)).Times(0);
4576 EXPECT_CALL(visitor, OnDecryptedPacket(_)).Times(1);
4577 EXPECT_CALL(visitor, OnError(_)).Times(1);
4578 EXPECT_CALL(visitor, OnStreamFrame(_)).Times(0);
4579 EXPECT_CALL(visitor, OnAckFrame(_)).Times(0);
4580 EXPECT_CALL(visitor, OnPacketComplete()).Times(0);
4582 EXPECT_FALSE(framer_.ProcessPacket(*packet));
4583 EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error());
4586 } // namespace test
4587 } // namespace net