Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(369)

Side by Side Diff: net/quic/quic_framer_test.cc

Issue 15937012: Land Recent QUIC changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Small bug fixes Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 #include <map> 6 #include <map>
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/hash_tables.h" 10 #include "base/hash_tables.h"
(...skipping 23 matching lines...) Expand all
34 namespace test { 34 namespace test {
35 35
36 const QuicPacketSequenceNumber kEpoch = GG_UINT64_C(1) << 48; 36 const QuicPacketSequenceNumber kEpoch = GG_UINT64_C(1) << 48;
37 const QuicPacketSequenceNumber kMask = kEpoch - 1; 37 const QuicPacketSequenceNumber kMask = kEpoch - 1;
38 38
39 // Index into the flags offset in the header. 39 // Index into the flags offset in the header.
40 const size_t kPublicFlagsOffset = 0; 40 const size_t kPublicFlagsOffset = 0;
41 // Index into the guid offset in the header. 41 // Index into the guid offset in the header.
42 const size_t kGuidOffset = kPublicFlagsSize; 42 const size_t kGuidOffset = kPublicFlagsSize;
43 // Index into the version string in the header. (if present). 43 // Index into the version string in the header. (if present).
44 const size_t kVersionOffset = kGuidOffset + kQuicGuidSize; 44 const size_t kVersionOffset = kGuidOffset + PACKET_8BYTE_GUID;
45 45
46 // Index into the sequence number offset in the header. 46 // Index into the sequence number offset in the header.
47 size_t GetSequenceNumberOffset(bool include_version) { 47 size_t GetSequenceNumberOffset(QuicGuidLength guid_length,
48 return kGuidOffset + kQuicGuidSize + 48 bool include_version) {
49 return kGuidOffset + guid_length +
49 (include_version ? kQuicVersionSize : 0); 50 (include_version ? kQuicVersionSize : 0);
50 } 51 }
51 52
53 size_t GetSequenceNumberOffset(bool include_version) {
54 return GetSequenceNumberOffset(PACKET_8BYTE_GUID, include_version);
55 }
56
52 // Index into the private flags offset in the data packet header. 57 // Index into the private flags offset in the data packet header.
58 size_t GetPrivateFlagsOffset(QuicGuidLength guid_length, bool include_version) {
59 return GetSequenceNumberOffset(guid_length, include_version) +
60 kSequenceNumberSize;
61 }
62
53 size_t GetPrivateFlagsOffset(bool include_version) { 63 size_t GetPrivateFlagsOffset(bool include_version) {
54 return GetSequenceNumberOffset(include_version) + kSequenceNumberSize; 64 return GetPrivateFlagsOffset(PACKET_8BYTE_GUID, include_version);
55 } 65 }
56 66
57 // Index into the fec group offset in the header. 67 // Index into the fec group offset in the header.
68 size_t GetFecGroupOffset(QuicGuidLength guid_length, bool include_version) {
69 return GetPrivateFlagsOffset(guid_length, include_version) +
70 kPrivateFlagsSize;
71 }
72
58 size_t GetFecGroupOffset(bool include_version) { 73 size_t GetFecGroupOffset(bool include_version) {
59 return GetPrivateFlagsOffset(include_version) + kPrivateFlagsSize; 74 return GetPrivateFlagsOffset(PACKET_8BYTE_GUID, include_version) +
75 kPrivateFlagsSize;
60 } 76 }
61 77
62 // Index into the nonce proof of the public reset packet. 78 // Index into the nonce proof of the public reset packet.
63 const size_t kPublicResetPacketNonceProofOffset = kGuidOffset + kQuicGuidSize; 79 // Public resets always have full guids.
80 const size_t kPublicResetPacketNonceProofOffset =
81 kGuidOffset + PACKET_8BYTE_GUID;
82
64 // Index into the rejected sequence number of the public reset packet. 83 // Index into the rejected sequence number of the public reset packet.
65 const size_t kPublicResetPacketRejectedSequenceNumberOffset = 84 const size_t kPublicResetPacketRejectedSequenceNumberOffset =
66 kPublicResetPacketNonceProofOffset + kPublicResetNonceSize; 85 kPublicResetPacketNonceProofOffset + kPublicResetNonceSize;
67 86
68 class TestEncrypter : public QuicEncrypter { 87 class TestEncrypter : public QuicEncrypter {
69 public: 88 public:
70 virtual ~TestEncrypter() {} 89 virtual ~TestEncrypter() {}
71 virtual bool SetKey(StringPiece key) OVERRIDE { 90 virtual bool SetKey(StringPiece key) OVERRIDE {
72 return true; 91 return true;
73 } 92 }
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 bool CheckDecryption(const QuicEncryptedPacket& encrypted, 329 bool CheckDecryption(const QuicEncryptedPacket& encrypted,
311 bool includes_version) { 330 bool includes_version) {
312 if (visitor_.header_->packet_sequence_number != 331 if (visitor_.header_->packet_sequence_number !=
313 decrypter_->sequence_number_) { 332 decrypter_->sequence_number_) {
314 LOG(ERROR) << "Decrypted incorrect packet sequence number. expected " 333 LOG(ERROR) << "Decrypted incorrect packet sequence number. expected "
315 << visitor_.header_->packet_sequence_number << " actual: " 334 << visitor_.header_->packet_sequence_number << " actual: "
316 << decrypter_->sequence_number_; 335 << decrypter_->sequence_number_;
317 return false; 336 return false;
318 } 337 }
319 if (QuicFramer::GetAssociatedDataFromEncryptedPacket( 338 if (QuicFramer::GetAssociatedDataFromEncryptedPacket(
320 encrypted, includes_version) != decrypter_->associated_data_) { 339 encrypted, PACKET_8BYTE_GUID, includes_version) !=
340 decrypter_->associated_data_) {
321 LOG(ERROR) << "Decrypted incorrect associated data. expected " 341 LOG(ERROR) << "Decrypted incorrect associated data. expected "
322 << QuicFramer::GetAssociatedDataFromEncryptedPacket( 342 << QuicFramer::GetAssociatedDataFromEncryptedPacket(
323 encrypted, includes_version) 343 encrypted, PACKET_8BYTE_GUID, includes_version)
324 << " actual: " << decrypter_->associated_data_; 344 << " actual: " << decrypter_->associated_data_;
325 return false; 345 return false;
326 } 346 }
327 StringPiece ciphertext(encrypted.AsStringPiece().substr( 347 StringPiece ciphertext(encrypted.AsStringPiece().substr(
328 GetStartOfEncryptedData(includes_version))); 348 GetStartOfEncryptedData(PACKET_8BYTE_GUID, includes_version)));
329 if (ciphertext != decrypter_->ciphertext_) { 349 if (ciphertext != decrypter_->ciphertext_) {
330 LOG(ERROR) << "Decrypted incorrect chipertext data. expected " 350 LOG(ERROR) << "Decrypted incorrect chipertext data. expected "
331 << ciphertext << " actual: " 351 << ciphertext << " actual: "
332 << decrypter_->ciphertext_; 352 << decrypter_->ciphertext_;
333 return false; 353 return false;
334 } 354 }
335 return true; 355 return true;
336 } 356 }
337 357
338 char* AsChars(unsigned char* data) { 358 char* AsChars(unsigned char* data) {
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 // public flags (8 byte guid) 508 // public flags (8 byte guid)
489 0x0C, 509 0x0C,
490 // guid 510 // guid
491 0x10, 0x32, 0x54, 0x76, 511 0x10, 0x32, 0x54, 0x76,
492 0x98, 0xBA, 0xDC, 0xFE, 512 0x98, 0xBA, 0xDC, 0xFE,
493 // packet sequence number 513 // packet sequence number
494 0xBC, 0x9A, 0x78, 0x56, 514 0xBC, 0x9A, 0x78, 0x56,
495 0x34, 0x12, 515 0x34, 0x12,
496 // private flags 516 // private flags
497 0x00, 517 0x00,
498 // first fec protected packet offset
499 0xFF
500 }; 518 };
501 519
502 memset(packet + GetPacketHeaderSize(!kIncludeVersion), 0, 520 memset(packet + GetPacketHeaderSize(
503 kMaxPacketSize - GetPacketHeaderSize(!kIncludeVersion) + 1); 521 PACKET_8BYTE_GUID, !kIncludeVersion, NOT_IN_FEC_GROUP), 0,
522 kMaxPacketSize - GetPacketHeaderSize(
523 PACKET_8BYTE_GUID, !kIncludeVersion, NOT_IN_FEC_GROUP) + 1);
504 524
505 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 525 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
506 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); 526 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
507 527
508 ASSERT_TRUE(visitor_.header_.get()); 528 ASSERT_TRUE(visitor_.header_.get());
509 // Make sure we've parsed the packet header, so we can send an error. 529 // Make sure we've parsed the packet header, so we can send an error.
510 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210), 530 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
511 visitor_.header_->public_header.guid); 531 visitor_.header_->public_header.guid);
512 // Make sure the correct error is propagated. 532 // Make sure the correct error is propagated.
513 EXPECT_EQ(QUIC_PACKET_TOO_LARGE, framer_.error()); 533 EXPECT_EQ(QUIC_PACKET_TOO_LARGE, framer_.error());
514 } 534 }
515 535
516 TEST_F(QuicFramerTest, PacketHeader) { 536 TEST_F(QuicFramerTest, PacketHeader) {
517 unsigned char packet[] = { 537 unsigned char packet[] = {
518 // public flags (8 byte guid) 538 // public flags (8 byte guid)
519 0x0C, 539 0x0C,
520 // guid 540 // guid
521 0x10, 0x32, 0x54, 0x76, 541 0x10, 0x32, 0x54, 0x76,
522 0x98, 0xBA, 0xDC, 0xFE, 542 0x98, 0xBA, 0xDC, 0xFE,
523 // packet sequence number 543 // packet sequence number
524 0xBC, 0x9A, 0x78, 0x56, 544 0xBC, 0x9A, 0x78, 0x56,
525 0x34, 0x12, 545 0x34, 0x12,
526 // private flags 546 // private flags
527 0x00, 547 0x00,
528 // first fec protected packet offset
529 0xFF,
530 }; 548 };
531 549
532 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 550 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
533 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); 551 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
534 EXPECT_EQ(QUIC_INVALID_FRAME_DATA, framer_.error()); 552 EXPECT_EQ(QUIC_INVALID_FRAME_DATA, framer_.error());
535 ASSERT_TRUE(visitor_.header_.get()); 553 ASSERT_TRUE(visitor_.header_.get());
536 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210), 554 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
537 visitor_.header_->public_header.guid); 555 visitor_.header_->public_header.guid);
538 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); 556 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
539 EXPECT_FALSE(visitor_.header_->public_header.version_flag); 557 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
540 EXPECT_FALSE(visitor_.header_->fec_flag); 558 EXPECT_FALSE(visitor_.header_->fec_flag);
541 EXPECT_FALSE(visitor_.header_->entropy_flag); 559 EXPECT_FALSE(visitor_.header_->entropy_flag);
542 EXPECT_FALSE(visitor_.header_->fec_entropy_flag);
543 EXPECT_EQ(0, visitor_.header_->entropy_hash); 560 EXPECT_EQ(0, visitor_.header_->entropy_hash);
544 EXPECT_EQ(GG_UINT64_C(0x123456789ABC), 561 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
545 visitor_.header_->packet_sequence_number); 562 visitor_.header_->packet_sequence_number);
563 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
546 EXPECT_EQ(0x00u, visitor_.header_->fec_group); 564 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
547 565
548 // Now test framing boundaries 566 // Now test framing boundaries
549 for (size_t i = 0; i < GetPacketHeaderSize(!kIncludeVersion); ++i) { 567 for (size_t i = 0;
568 i < GetPacketHeaderSize(
569 PACKET_8BYTE_GUID, !kIncludeVersion, NOT_IN_FEC_GROUP); ++i) {
550 string expected_error; 570 string expected_error;
551 if (i < kGuidOffset) { 571 if (i < kGuidOffset) {
552 expected_error = "Unable to read public flags."; 572 expected_error = "Unable to read public flags.";
553 } else if (i < GetSequenceNumberOffset(!kIncludeVersion)) { 573 } else if (i < GetSequenceNumberOffset(!kIncludeVersion)) {
554 expected_error = "Unable to read GUID."; 574 expected_error = "Unable to read GUID.";
555 } else if (i < GetPrivateFlagsOffset(!kIncludeVersion)) { 575 } else if (i < GetPrivateFlagsOffset(!kIncludeVersion)) {
556 expected_error = "Unable to read sequence number."; 576 expected_error = "Unable to read sequence number.";
557 } else if (i < GetFecGroupOffset(!kIncludeVersion)) { 577 } else if (i < GetFecGroupOffset(!kIncludeVersion)) {
558 expected_error = "Unable to read private flags."; 578 expected_error = "Unable to read private flags.";
559 } else { 579 } else {
560 expected_error = "Unable to read first fec protected packet offset."; 580 expected_error = "Unable to read first fec protected packet offset.";
561 } 581 }
562 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER); 582 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER);
563 } 583 }
564 } 584 }
565 585
586 TEST_F(QuicFramerTest, PacketHeaderWith4ByteGuid) {
587 QuicFramerPeer::SetLastSerializedGuid(&framer_,
588 GG_UINT64_C(0xFEDCBA9876543210));
589
590 unsigned char packet[] = {
591 // public flags (4 byte guid)
592 0x08,
593 // guid
594 0x10, 0x32, 0x54, 0x76,
595 // packet sequence number
596 0xBC, 0x9A, 0x78, 0x56,
597 0x34, 0x12,
598 // private flags
599 0x00,
600 };
601
602 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
603 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
604 EXPECT_EQ(QUIC_INVALID_FRAME_DATA, framer_.error());
605 ASSERT_TRUE(visitor_.header_.get());
606 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
607 visitor_.header_->public_header.guid);
608 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
609 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
610 EXPECT_FALSE(visitor_.header_->fec_flag);
611 EXPECT_FALSE(visitor_.header_->entropy_flag);
612 EXPECT_EQ(0, visitor_.header_->entropy_hash);
613 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
614 visitor_.header_->packet_sequence_number);
615 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
616 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
617
618 // Now test framing boundaries
619 for (size_t i = 0;
620 i < GetPacketHeaderSize(
621 PACKET_4BYTE_GUID, !kIncludeVersion, NOT_IN_FEC_GROUP); ++i) {
622 string expected_error;
623 if (i < kGuidOffset) {
624 expected_error = "Unable to read public flags.";
625 } else if (i < GetSequenceNumberOffset(PACKET_4BYTE_GUID,
626 !kIncludeVersion)) {
627 expected_error = "Unable to read GUID.";
628 } else if (i < GetPrivateFlagsOffset(PACKET_4BYTE_GUID,
629 !kIncludeVersion)) {
630 expected_error = "Unable to read sequence number.";
631 } else if (i < GetFecGroupOffset(PACKET_4BYTE_GUID, !kIncludeVersion)) {
632 expected_error = "Unable to read private flags.";
633 } else {
634 expected_error = "Unable to read first fec protected packet offset.";
635 }
636 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER);
637 }
638 }
639
640 TEST_F(QuicFramerTest, PacketHeader1ByteGuid) {
641 QuicFramerPeer::SetLastSerializedGuid(&framer_,
642 GG_UINT64_C(0xFEDCBA9876543210));
643
644 unsigned char packet[] = {
645 // public flags (1 byte guid)
646 0x04,
647 // guid
648 0x10,
649 // packet sequence number
650 0xBC, 0x9A, 0x78, 0x56,
651 0x34, 0x12,
652 // private flags
653 0x00,
654 };
655
656 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
657 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
658 EXPECT_EQ(QUIC_INVALID_FRAME_DATA, framer_.error());
659 ASSERT_TRUE(visitor_.header_.get());
660 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
661 visitor_.header_->public_header.guid);
662 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
663 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
664 EXPECT_FALSE(visitor_.header_->fec_flag);
665 EXPECT_FALSE(visitor_.header_->entropy_flag);
666 EXPECT_EQ(0, visitor_.header_->entropy_hash);
667 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
668 visitor_.header_->packet_sequence_number);
669 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
670 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
671
672 // Now test framing boundaries
673 for (size_t i = 0;
674 i < GetPacketHeaderSize(
675 PACKET_1BYTE_GUID, !kIncludeVersion, NOT_IN_FEC_GROUP); ++i) {
676 string expected_error;
677 if (i < kGuidOffset) {
678 expected_error = "Unable to read public flags.";
679 } else if (i < GetSequenceNumberOffset(PACKET_1BYTE_GUID,
680 !kIncludeVersion)) {
681 expected_error = "Unable to read GUID.";
682 } else if (i < GetPrivateFlagsOffset(PACKET_1BYTE_GUID, !kIncludeVersion)) {
683 expected_error = "Unable to read sequence number.";
684 } else if (i < GetFecGroupOffset(PACKET_1BYTE_GUID, !kIncludeVersion)) {
685 expected_error = "Unable to read private flags.";
686 } else {
687 expected_error = "Unable to read first fec protected packet offset.";
688 }
689 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER);
690 }
691 }
692
693 TEST_F(QuicFramerTest, PacketHeaderWith0ByteGuid) {
694 QuicFramerPeer::SetLastSerializedGuid(&framer_,
695 GG_UINT64_C(0xFEDCBA9876543210));
696
697 unsigned char packet[] = {
698 // public flags (0 byte guid)
699 0x00,
700 // guid
701 // packet sequence number
702 0xBC, 0x9A, 0x78, 0x56,
703 0x34, 0x12,
704 // private flags
705 0x00,
706 };
707
708 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
709 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
710 EXPECT_EQ(QUIC_INVALID_FRAME_DATA, framer_.error());
711 ASSERT_TRUE(visitor_.header_.get());
712 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
713 visitor_.header_->public_header.guid);
714 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
715 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
716 EXPECT_FALSE(visitor_.header_->fec_flag);
717 EXPECT_FALSE(visitor_.header_->entropy_flag);
718 EXPECT_EQ(0, visitor_.header_->entropy_hash);
719 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
720 visitor_.header_->packet_sequence_number);
721 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
722 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
723
724 // Now test framing boundaries
725 for (size_t i = 0;
726 i < GetPacketHeaderSize(
727 PACKET_0BYTE_GUID, !kIncludeVersion, NOT_IN_FEC_GROUP); ++i) {
728 string expected_error;
729 if (i < kGuidOffset) {
730 expected_error = "Unable to read public flags.";
731 } else if (i < GetSequenceNumberOffset(PACKET_0BYTE_GUID,
732 !kIncludeVersion)) {
733 expected_error = "Unable to read GUID.";
734 } else if (i < GetPrivateFlagsOffset(PACKET_0BYTE_GUID, !kIncludeVersion)) {
735 expected_error = "Unable to read sequence number.";
736 } else if (i < GetFecGroupOffset(PACKET_0BYTE_GUID, !kIncludeVersion)) {
737 expected_error = "Unable to read private flags.";
738 } else {
739 expected_error = "Unable to read first fec protected packet offset.";
740 }
741 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER);
742 }
743 }
744
566 TEST_F(QuicFramerTest, PacketHeaderWithVersionFlag) { 745 TEST_F(QuicFramerTest, PacketHeaderWithVersionFlag) {
567 unsigned char packet[] = { 746 unsigned char packet[] = {
568 // public flags (version) 747 // public flags (version)
569 0x0D, 748 0x0D,
570 // guid 749 // guid
571 0x10, 0x32, 0x54, 0x76, 750 0x10, 0x32, 0x54, 0x76,
572 0x98, 0xBA, 0xDC, 0xFE, 751 0x98, 0xBA, 0xDC, 0xFE,
573 // version tag 752 // version tag
574 'Q', '0', '0', '4', 753 'Q', '0', '0', '5',
575 // packet sequence number 754 // packet sequence number
576 0xBC, 0x9A, 0x78, 0x56, 755 0xBC, 0x9A, 0x78, 0x56,
577 0x34, 0x12, 756 0x34, 0x12,
578 // private flags 757 // private flags
579 0x00, 758 0x00,
580 // first fec protected packet offset
581 0xFF,
582 }; 759 };
583 760
584 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 761 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
585 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); 762 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
586 EXPECT_EQ(QUIC_INVALID_FRAME_DATA, framer_.error()); 763 EXPECT_EQ(QUIC_INVALID_FRAME_DATA, framer_.error());
587 ASSERT_TRUE(visitor_.header_.get()); 764 ASSERT_TRUE(visitor_.header_.get());
588 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210), 765 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
589 visitor_.header_->public_header.guid); 766 visitor_.header_->public_header.guid);
590 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); 767 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
591 EXPECT_TRUE(visitor_.header_->public_header.version_flag); 768 EXPECT_TRUE(visitor_.header_->public_header.version_flag);
592 EXPECT_EQ(kQuicVersion1, visitor_.header_->public_header.versions[0]); 769 EXPECT_EQ(kQuicVersion1, visitor_.header_->public_header.versions[0]);
593 EXPECT_FALSE(visitor_.header_->fec_flag); 770 EXPECT_FALSE(visitor_.header_->fec_flag);
594 EXPECT_FALSE(visitor_.header_->entropy_flag); 771 EXPECT_FALSE(visitor_.header_->entropy_flag);
595 EXPECT_FALSE(visitor_.header_->fec_entropy_flag);
596 EXPECT_EQ(0, visitor_.header_->entropy_hash); 772 EXPECT_EQ(0, visitor_.header_->entropy_hash);
597 EXPECT_EQ(GG_UINT64_C(0x123456789ABC), 773 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
598 visitor_.header_->packet_sequence_number); 774 visitor_.header_->packet_sequence_number);
775 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
599 EXPECT_EQ(0x00u, visitor_.header_->fec_group); 776 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
600 777
601 // Now test framing boundaries 778 // Now test framing boundaries
602 for (size_t i = 0; i < GetPacketHeaderSize(kIncludeVersion); ++i) { 779 for (size_t i = 0;
780 i < GetPacketHeaderSize(
781 PACKET_8BYTE_GUID, kIncludeVersion, NOT_IN_FEC_GROUP); ++i) {
603 string expected_error; 782 string expected_error;
604 if (i < kGuidOffset) { 783 if (i < kGuidOffset) {
605 expected_error = "Unable to read public flags."; 784 expected_error = "Unable to read public flags.";
606 } else if (i < kVersionOffset) { 785 } else if (i < kVersionOffset) {
607 expected_error = "Unable to read GUID."; 786 expected_error = "Unable to read GUID.";
608 } else if (i < GetSequenceNumberOffset(kIncludeVersion)) { 787 } else if (i < GetSequenceNumberOffset(kIncludeVersion)) {
609 expected_error = "Unable to read protocol version."; 788 expected_error = "Unable to read protocol version.";
610 } else if (i < GetPrivateFlagsOffset(kIncludeVersion)) { 789 } else if (i < GetPrivateFlagsOffset(kIncludeVersion)) {
611 expected_error = "Unable to read sequence number."; 790 expected_error = "Unable to read sequence number.";
612 } else if (i < GetFecGroupOffset(kIncludeVersion)) { 791 } else if (i < GetFecGroupOffset(kIncludeVersion)) {
(...skipping 11 matching lines...) Expand all
624 // public flags (8 byte guid) 803 // public flags (8 byte guid)
625 0x10, 804 0x10,
626 // guid 805 // guid
627 0x10, 0x32, 0x54, 0x76, 806 0x10, 0x32, 0x54, 0x76,
628 0x98, 0xBA, 0xDC, 0xFE, 807 0x98, 0xBA, 0xDC, 0xFE,
629 // packet sequence number 808 // packet sequence number
630 0xBC, 0x9A, 0x78, 0x56, 809 0xBC, 0x9A, 0x78, 0x56,
631 0x34, 0x12, 810 0x34, 0x12,
632 // private flags 811 // private flags
633 0x00, 812 0x00,
634 // first fec protected packet offset
635 0xFF,
636 813
637 // frame count 814 // frame count
638 0x01, 815 0x01,
639 // frame type (stream frame) 816 // frame type (stream frame)
640 0x01, 817 0x01,
641 // stream id 818 // stream id
642 0x04, 0x03, 0x02, 0x01, 819 0x04, 0x03, 0x02, 0x01,
643 // fin 820 // fin
644 0x01, 821 0x01,
645 // offset 822 // offset
(...skipping 16 matching lines...) Expand all
662 unsigned char packet[] = { 839 unsigned char packet[] = {
663 // public flags (8 byte guid) 840 // public flags (8 byte guid)
664 0x0C, 841 0x0C,
665 // guid 842 // guid
666 0x10, 0x32, 0x54, 0x76, 843 0x10, 0x32, 0x54, 0x76,
667 0x98, 0xBA, 0xDC, 0xFE, 844 0x98, 0xBA, 0xDC, 0xFE,
668 // packet sequence number 845 // packet sequence number
669 0xBC, 0x9A, 0x78, 0x56, 846 0xBC, 0x9A, 0x78, 0x56,
670 0x34, 0x12, 847 0x34, 0x12,
671 // private flags 848 // private flags
672 0x08, 849 0x10,
673 // first fec protected packet offset
674 0xFF,
675 850
676 // frame count 851 // frame count
677 0x01, 852 0x01,
678 // frame type (stream frame) 853 // frame type (stream frame)
679 0x01, 854 0x01,
680 // stream id 855 // stream id
681 0x04, 0x03, 0x02, 0x01, 856 0x04, 0x03, 0x02, 0x01,
682 // fin 857 // fin
683 0x01, 858 0x01,
684 // offset 859 // offset
(...skipping 17 matching lines...) Expand all
702 // public flags (8 byte guid) 877 // public flags (8 byte guid)
703 0x0C, 878 0x0C,
704 // guid 879 // guid
705 0x10, 0x32, 0x54, 0x76, 880 0x10, 0x32, 0x54, 0x76,
706 0x98, 0xBA, 0xDC, 0xFE, 881 0x98, 0xBA, 0xDC, 0xFE,
707 // packet sequence number 882 // packet sequence number
708 0xBC, 0x9A, 0x78, 0x56, 883 0xBC, 0x9A, 0x78, 0x56,
709 0x34, 0x12, 884 0x34, 0x12,
710 // private flags 885 // private flags
711 0x00, 886 0x00,
712 // first fec protected packet offset
713 0xFF,
714 887
715 // frame type (padding frame) 888 // frame type (padding frame)
716 0x00, 889 0x00,
717 // Ignored data (which in this case is a stream frame) 890 // Ignored data (which in this case is a stream frame)
718 0x01, 891 0x01,
719 0x04, 0x03, 0x02, 0x01, 892 0x04, 0x03, 0x02, 0x01,
720 0x01, 893 0x01,
721 0x54, 0x76, 0x10, 0x32, 894 0x54, 0x76, 0x10, 0x32,
722 0xDC, 0xFE, 0x98, 0xBA, 895 0xDC, 0xFE, 0x98, 0xBA,
723 0x0c, 0x00, 896 0x0c, 0x00,
724 'h', 'e', 'l', 'l', 897 'h', 'e', 'l', 'l',
725 'o', ' ', 'w', 'o', 898 'o', ' ', 'w', 'o',
726 'r', 'l', 'd', '!', 899 'r', 'l', 'd', '!',
727 }; 900 };
728 901
729 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 902 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
730 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 903 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
731 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 904 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
732 ASSERT_TRUE(visitor_.header_.get()); 905 ASSERT_TRUE(visitor_.header_.get());
733 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 906 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
734 907
735 ASSERT_EQ(0u, visitor_.stream_frames_.size()); 908 ASSERT_EQ(0u, visitor_.stream_frames_.size());
736 EXPECT_EQ(0u, visitor_.ack_frames_.size()); 909 EXPECT_EQ(0u, visitor_.ack_frames_.size());
737 // A packet with no frames is not acceptable. 910 // A packet with no frames is not acceptable.
738 CheckProcessingFails(packet, GetPacketHeaderSize(!kIncludeVersion), 911 CheckProcessingFails(
739 "Unable to read frame type.", QUIC_INVALID_FRAME_DATA); 912 packet,
913 GetPacketHeaderSize(
914 PACKET_8BYTE_GUID, !kIncludeVersion, NOT_IN_FEC_GROUP),
915 "Unable to read frame type.", QUIC_INVALID_FRAME_DATA);
740 } 916 }
741 917
742 TEST_F(QuicFramerTest, StreamFrame) { 918 TEST_F(QuicFramerTest, StreamFrame) {
743 unsigned char packet[] = { 919 unsigned char packet[] = {
744 // public flags (8 byte guid) 920 // public flags (8 byte guid)
745 0x0C, 921 0x0C,
746 // guid 922 // guid
747 0x10, 0x32, 0x54, 0x76, 923 0x10, 0x32, 0x54, 0x76,
748 0x98, 0xBA, 0xDC, 0xFE, 924 0x98, 0xBA, 0xDC, 0xFE,
749 // packet sequence number 925 // packet sequence number
750 0xBC, 0x9A, 0x78, 0x56, 926 0xBC, 0x9A, 0x78, 0x56,
751 0x34, 0x12, 927 0x34, 0x12,
752 // private flags 928 // private flags
753 0x00, 929 0x00,
754 // first fec protected packet offset
755 0xFF,
756 930
757 // frame type (stream frame) 931 // frame type (stream frame)
758 0x01, 932 0x01,
759 // stream id 933 // stream id
760 0x04, 0x03, 0x02, 0x01, 934 0x04, 0x03, 0x02, 0x01,
761 // fin 935 // fin
762 0x01, 936 0x01,
763 // offset 937 // offset
764 0x54, 0x76, 0x10, 0x32, 938 0x54, 0x76, 0x10, 0x32,
765 0xDC, 0xFE, 0x98, 0xBA, 939 0xDC, 0xFE, 0x98, 0xBA,
(...skipping 30 matching lines...) Expand all
796 expected_error = "Unable to read stream_id."; 970 expected_error = "Unable to read stream_id.";
797 } else if (i < kQuicFrameTypeSize + kQuicStreamIdSize + 971 } else if (i < kQuicFrameTypeSize + kQuicStreamIdSize +
798 kQuicStreamFinSize) { 972 kQuicStreamFinSize) {
799 expected_error = "Unable to read fin."; 973 expected_error = "Unable to read fin.";
800 } else if (i < kQuicFrameTypeSize + kQuicStreamIdSize + 974 } else if (i < kQuicFrameTypeSize + kQuicStreamIdSize +
801 kQuicStreamFinSize + kQuicStreamOffsetSize) { 975 kQuicStreamFinSize + kQuicStreamOffsetSize) {
802 expected_error = "Unable to read offset."; 976 expected_error = "Unable to read offset.";
803 } else { 977 } else {
804 expected_error = "Unable to read frame data."; 978 expected_error = "Unable to read frame data.";
805 } 979 }
806 CheckProcessingFails(packet, i + GetPacketHeaderSize(!kIncludeVersion), 980 CheckProcessingFails(
807 expected_error, QUIC_INVALID_FRAME_DATA); 981 packet,
982 i + GetPacketHeaderSize(
983 PACKET_8BYTE_GUID, !kIncludeVersion, NOT_IN_FEC_GROUP),
984 expected_error, QUIC_INVALID_FRAME_DATA);
808 } 985 }
809 } 986 }
810 987
811 TEST_F(QuicFramerTest, StreamFrameWithVersion) { 988 TEST_F(QuicFramerTest, StreamFrameWithVersion) {
812 unsigned char packet[] = { 989 unsigned char packet[] = {
813 // public flags (version, 8 byte guid) 990 // public flags (version, 8 byte guid)
814 0x0D, 991 0x0D,
815 // guid 992 // guid
816 0x10, 0x32, 0x54, 0x76, 993 0x10, 0x32, 0x54, 0x76,
817 0x98, 0xBA, 0xDC, 0xFE, 994 0x98, 0xBA, 0xDC, 0xFE,
818 // version tag 995 // version tag
819 'Q', '0', '0', '4', 996 'Q', '0', '0', '5',
820 // packet sequence number 997 // packet sequence number
821 0xBC, 0x9A, 0x78, 0x56, 998 0xBC, 0x9A, 0x78, 0x56,
822 0x34, 0x12, 999 0x34, 0x12,
823 // private flags 1000 // private flags
824 0x00, 1001 0x00,
825 // first fec protected packet offset
826 0xFF,
827 1002
828 // frame type (stream frame) 1003 // frame type (stream frame)
829 0x01, 1004 0x01,
830 // stream id 1005 // stream id
831 0x04, 0x03, 0x02, 0x01, 1006 0x04, 0x03, 0x02, 0x01,
832 // fin 1007 // fin
833 0x01, 1008 0x01,
834 // offset 1009 // offset
835 0x54, 0x76, 0x10, 0x32, 1010 0x54, 0x76, 0x10, 0x32,
836 0xDC, 0xFE, 0x98, 0xBA, 1011 0xDC, 0xFE, 0x98, 0xBA,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 expected_error = "Unable to read stream_id."; 1044 expected_error = "Unable to read stream_id.";
870 } else if (i < kQuicFrameTypeSize + kQuicStreamIdSize + 1045 } else if (i < kQuicFrameTypeSize + kQuicStreamIdSize +
871 kQuicStreamFinSize) { 1046 kQuicStreamFinSize) {
872 expected_error = "Unable to read fin."; 1047 expected_error = "Unable to read fin.";
873 } else if (i < kQuicFrameTypeSize + kQuicStreamIdSize + 1048 } else if (i < kQuicFrameTypeSize + kQuicStreamIdSize +
874 kQuicStreamFinSize + kQuicStreamOffsetSize) { 1049 kQuicStreamFinSize + kQuicStreamOffsetSize) {
875 expected_error = "Unable to read offset."; 1050 expected_error = "Unable to read offset.";
876 } else { 1051 } else {
877 expected_error = "Unable to read frame data."; 1052 expected_error = "Unable to read frame data.";
878 } 1053 }
879 CheckProcessingFails(packet, i + GetPacketHeaderSize(kIncludeVersion), 1054 CheckProcessingFails(
880 expected_error, QUIC_INVALID_FRAME_DATA); 1055 packet, i + GetPacketHeaderSize(PACKET_8BYTE_GUID, kIncludeVersion,
1056 NOT_IN_FEC_GROUP),
1057 expected_error, QUIC_INVALID_FRAME_DATA);
881 } 1058 }
882 } 1059 }
883 1060
884 TEST_F(QuicFramerTest, RejectPacket) { 1061 TEST_F(QuicFramerTest, RejectPacket) {
885 visitor_.accept_packet_ = false; 1062 visitor_.accept_packet_ = false;
886 1063
887 unsigned char packet[] = { 1064 unsigned char packet[] = {
888 // public flags (8 byte guid) 1065 // public flags (8 byte guid)
889 0x0C, 1066 0x0C,
890 // guid 1067 // guid
891 0x10, 0x32, 0x54, 0x76, 1068 0x10, 0x32, 0x54, 0x76,
892 0x98, 0xBA, 0xDC, 0xFE, 1069 0x98, 0xBA, 0xDC, 0xFE,
893 // packet sequence number 1070 // packet sequence number
894 0xBC, 0x9A, 0x78, 0x56, 1071 0xBC, 0x9A, 0x78, 0x56,
895 0x34, 0x12, 1072 0x34, 0x12,
896 // private flags 1073 // private flags
897 0x00, 1074 0x00,
898 // first fec protected packet offset
899 0xFF,
900 1075
901 // frame type (stream frame) 1076 // frame type (stream frame)
902 0x01, 1077 0x01,
903 // stream id 1078 // stream id
904 0x04, 0x03, 0x02, 0x01, 1079 0x04, 0x03, 0x02, 0x01,
905 // fin 1080 // fin
906 0x01, 1081 0x01,
907 // offset 1082 // offset
908 0x54, 0x76, 0x10, 0x32, 1083 0x54, 0x76, 0x10, 0x32,
909 0xDC, 0xFE, 0x98, 0xBA, 1084 0xDC, 0xFE, 0x98, 0xBA,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 'o', ' ', 'w', 'o', 1119 'o', ' ', 'w', 'o',
945 'r', 'l', 'd', '!', 1120 'r', 'l', 'd', '!',
946 }; 1121 };
947 1122
948 QuicPacketHeader header; 1123 QuicPacketHeader header;
949 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); 1124 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210);
950 header.public_header.reset_flag = false; 1125 header.public_header.reset_flag = false;
951 header.public_header.version_flag = false; 1126 header.public_header.version_flag = false;
952 header.fec_flag = true; 1127 header.fec_flag = true;
953 header.entropy_flag = true; 1128 header.entropy_flag = true;
954 header.fec_entropy_flag = false;
955 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); 1129 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
956 header.fec_group = 0; 1130 header.fec_group = 0;
957 1131
958 // Do not encrypt the payload because the revived payload is post-encryption. 1132 // Do not encrypt the payload because the revived payload is post-encryption.
959 EXPECT_TRUE(framer_.ProcessRevivedPacket(&header, 1133 EXPECT_TRUE(framer_.ProcessRevivedPacket(&header,
960 StringPiece(AsChars(payload), 1134 StringPiece(AsChars(payload),
961 arraysize(payload)))); 1135 arraysize(payload))));
962 1136
963 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1137 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
964 ASSERT_EQ(1, visitor_.revived_packets_); 1138 ASSERT_EQ(1, visitor_.revived_packets_);
965 ASSERT_TRUE(visitor_.header_.get()); 1139 ASSERT_TRUE(visitor_.header_.get());
966 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210), 1140 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
967 visitor_.header_->public_header.guid); 1141 visitor_.header_->public_header.guid);
968 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); 1142 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
969 EXPECT_FALSE(visitor_.header_->public_header.version_flag); 1143 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
970 EXPECT_TRUE(visitor_.header_->fec_flag); 1144 EXPECT_TRUE(visitor_.header_->fec_flag);
971 EXPECT_TRUE(visitor_.header_->entropy_flag); 1145 EXPECT_TRUE(visitor_.header_->entropy_flag);
972 EXPECT_FALSE(visitor_.header_->fec_entropy_flag);
973 EXPECT_EQ(1 << (header.packet_sequence_number % 8), 1146 EXPECT_EQ(1 << (header.packet_sequence_number % 8),
974 visitor_.header_->entropy_hash); 1147 visitor_.header_->entropy_hash);
975 EXPECT_EQ(GG_UINT64_C(0x123456789ABC), 1148 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
976 visitor_.header_->packet_sequence_number); 1149 visitor_.header_->packet_sequence_number);
1150 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
977 EXPECT_EQ(0x00u, visitor_.header_->fec_group); 1151 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
978 1152
979 ASSERT_EQ(1u, visitor_.stream_frames_.size()); 1153 ASSERT_EQ(1u, visitor_.stream_frames_.size());
980 EXPECT_EQ(0u, visitor_.ack_frames_.size()); 1154 EXPECT_EQ(0u, visitor_.ack_frames_.size());
981 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_.stream_frames_[0]->stream_id); 1155 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_.stream_frames_[0]->stream_id);
982 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); 1156 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
983 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654), 1157 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
984 visitor_.stream_frames_[0]->offset); 1158 visitor_.stream_frames_[0]->offset);
985 EXPECT_EQ("hello world!", visitor_.stream_frames_[0]->data); 1159 EXPECT_EQ("hello world!", visitor_.stream_frames_[0]->data);
986 } 1160 }
987 1161
988 TEST_F(QuicFramerTest, StreamFrameInFecGroup) { 1162 TEST_F(QuicFramerTest, StreamFrameInFecGroup) {
989 unsigned char packet[] = { 1163 unsigned char packet[] = {
990 // public flags (8 byte guid) 1164 // public flags (8 byte guid)
991 0x0C, 1165 0x0C,
992 // guid 1166 // guid
993 0x10, 0x32, 0x54, 0x76, 1167 0x10, 0x32, 0x54, 0x76,
994 0x98, 0xBA, 0xDC, 0xFE, 1168 0x98, 0xBA, 0xDC, 0xFE,
995 // packet sequence number 1169 // packet sequence number
996 0xBC, 0x9A, 0x78, 0x56, 1170 0xBC, 0x9A, 0x78, 0x56,
997 0x12, 0x34, 1171 0x12, 0x34,
998 // private flags 1172 // private flags (fec group)
999 0x00, 1173 0x02,
1000 // first fec protected packet offset 1174 // first fec protected packet offset
1001 0x02, 1175 0x02,
1002 1176
1003 // frame type (stream frame) 1177 // frame type (stream frame)
1004 0x01, 1178 0x01,
1005 // stream id 1179 // stream id
1006 0x04, 0x03, 0x02, 0x01, 1180 0x04, 0x03, 0x02, 0x01,
1007 // fin 1181 // fin
1008 0x01, 1182 0x01,
1009 // offset 1183 // offset
1010 0x54, 0x76, 0x10, 0x32, 1184 0x54, 0x76, 0x10, 0x32,
1011 0xDC, 0xFE, 0x98, 0xBA, 1185 0xDC, 0xFE, 0x98, 0xBA,
1012 // data length 1186 // data length
1013 0x0c, 0x00, 1187 0x0c, 0x00,
1014 // data 1188 // data
1015 'h', 'e', 'l', 'l', 1189 'h', 'e', 'l', 'l',
1016 'o', ' ', 'w', 'o', 1190 'o', ' ', 'w', 'o',
1017 'r', 'l', 'd', '!', 1191 'r', 'l', 'd', '!',
1018 }; 1192 };
1019 1193
1020 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1194 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1021 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1195 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1022 1196
1023 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1197 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1024 ASSERT_TRUE(visitor_.header_.get()); 1198 ASSERT_TRUE(visitor_.header_.get());
1025 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 1199 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1200 EXPECT_EQ(IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
1026 EXPECT_EQ(GG_UINT64_C(0x341256789ABA), 1201 EXPECT_EQ(GG_UINT64_C(0x341256789ABA),
1027 visitor_.header_->fec_group); 1202 visitor_.header_->fec_group);
1028 EXPECT_EQ( 1203 EXPECT_EQ(
1029 string(AsChars(packet) + GetStartOfFecProtectedData(!kIncludeVersion), 1204 string(AsChars(packet) + GetStartOfFecProtectedData(PACKET_8BYTE_GUID,
1030 arraysize(packet) - GetStartOfFecProtectedData(!kIncludeVersion)), 1205 !kIncludeVersion),
1206 arraysize(packet) - GetStartOfFecProtectedData(PACKET_8BYTE_GUID,
1207 !kIncludeVersion)),
1031 visitor_.fec_protected_payload_); 1208 visitor_.fec_protected_payload_);
1032 1209
1033 ASSERT_EQ(1u, visitor_.stream_frames_.size()); 1210 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1034 EXPECT_EQ(0u, visitor_.ack_frames_.size()); 1211 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1035 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_.stream_frames_[0]->stream_id); 1212 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_.stream_frames_[0]->stream_id);
1036 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); 1213 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1037 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654), 1214 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1038 visitor_.stream_frames_[0]->offset); 1215 visitor_.stream_frames_[0]->offset);
1039 EXPECT_EQ("hello world!", visitor_.stream_frames_[0]->data); 1216 EXPECT_EQ("hello world!", visitor_.stream_frames_[0]->data);
1040 } 1217 }
1041 1218
1042 TEST_F(QuicFramerTest, AckFrame) { 1219 TEST_F(QuicFramerTest, AckFrame) {
1043 unsigned char packet[] = { 1220 unsigned char packet[] = {
1044 // public flags (8 byte guid) 1221 // public flags (8 byte guid)
1045 0x0C, 1222 0x0C,
1046 // guid 1223 // guid
1047 0x10, 0x32, 0x54, 0x76, 1224 0x10, 0x32, 0x54, 0x76,
1048 0x98, 0xBA, 0xDC, 0xFE, 1225 0x98, 0xBA, 0xDC, 0xFE,
1049 // packet sequence number 1226 // packet sequence number
1050 0xBC, 0x9A, 0x78, 0x56, 1227 0xBC, 0x9A, 0x78, 0x56,
1051 0x34, 0x12, 1228 0x34, 0x12,
1052 // private flags 1229 // private flags
1053 0x00, 1230 0x00,
1054 // first fec protected packet offset
1055 0xFF,
1056 1231
1057 // frame type (ack frame) 1232 // frame type (ack frame)
1058 0x02, 1233 0x02,
1059 // entropy hash of sent packets till least awaiting - 1. 1234 // entropy hash of sent packets till least awaiting - 1.
1060 0xAB, 1235 0xAB,
1061 // least packet sequence number awaiting an ack 1236 // least packet sequence number awaiting an ack
1062 0xA0, 0x9A, 0x78, 0x56, 1237 0xA0, 0x9A, 0x78, 0x56,
1063 0x34, 0x12, 1238 0x34, 0x12,
1064 // entropy hash of all received packets. 1239 // entropy hash of all received packets.
1065 0xBA, 1240 0xBA,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1121 expected_error = "Unable to read entropy hash for received packets."; 1296 expected_error = "Unable to read entropy hash for received packets.";
1122 } else if (i < kMissingDeltaTimeOffset) { 1297 } else if (i < kMissingDeltaTimeOffset) {
1123 expected_error = "Unable to read largest observed."; 1298 expected_error = "Unable to read largest observed.";
1124 } else if (i < kNumMissingPacketOffset) { 1299 } else if (i < kNumMissingPacketOffset) {
1125 expected_error = "Unable to read delta time largest observed."; 1300 expected_error = "Unable to read delta time largest observed.";
1126 } else if (i < kMissingPacketsOffset) { 1301 } else if (i < kMissingPacketsOffset) {
1127 expected_error = "Unable to read num missing packets."; 1302 expected_error = "Unable to read num missing packets.";
1128 } else { 1303 } else {
1129 expected_error = "Unable to read sequence number in missing packets."; 1304 expected_error = "Unable to read sequence number in missing packets.";
1130 } 1305 }
1131 CheckProcessingFails(packet, i + GetPacketHeaderSize(!kIncludeVersion), 1306 CheckProcessingFails(
1132 expected_error, QUIC_INVALID_FRAME_DATA); 1307 packet,
1308 i + GetPacketHeaderSize(
1309 PACKET_8BYTE_GUID, !kIncludeVersion, NOT_IN_FEC_GROUP),
1310 expected_error, QUIC_INVALID_FRAME_DATA);
1133 } 1311 }
1134 } 1312 }
1135 1313
1136 TEST_F(QuicFramerTest, CongestionFeedbackFrameTCP) { 1314 TEST_F(QuicFramerTest, CongestionFeedbackFrameTCP) {
1137 unsigned char packet[] = { 1315 unsigned char packet[] = {
1138 // public flags (8 byte guid) 1316 // public flags (8 byte guid)
1139 0x0C, 1317 0x0C,
1140 // guid 1318 // guid
1141 0x10, 0x32, 0x54, 0x76, 1319 0x10, 0x32, 0x54, 0x76,
1142 0x98, 0xBA, 0xDC, 0xFE, 1320 0x98, 0xBA, 0xDC, 0xFE,
1143 // packet sequence number 1321 // packet sequence number
1144 0xBC, 0x9A, 0x78, 0x56, 1322 0xBC, 0x9A, 0x78, 0x56,
1145 0x34, 0x12, 1323 0x34, 0x12,
1146 // private flags 1324 // private flags
1147 0x00, 1325 0x00,
1148 // first fec protected packet offset
1149 0xFF,
1150 1326
1151 // frame type (congestion feedback frame) 1327 // frame type (congestion feedback frame)
1152 0x03, 1328 0x03,
1153 // congestion feedback type (tcp) 1329 // congestion feedback type (tcp)
1154 0x00, 1330 0x00,
1155 // ack_frame.feedback.tcp.accumulated_number_of_lost_packets 1331 // ack_frame.feedback.tcp.accumulated_number_of_lost_packets
1156 0x01, 0x02, 1332 0x01, 0x02,
1157 // ack_frame.feedback.tcp.receive_window 1333 // ack_frame.feedback.tcp.receive_window
1158 0x03, 0x04, 1334 0x03, 0x04,
1159 }; 1335 };
(...skipping 19 matching lines...) Expand all
1179 string expected_error; 1355 string expected_error;
1180 if (i < 1) { 1356 if (i < 1) {
1181 expected_error = "Unable to read frame type."; 1357 expected_error = "Unable to read frame type.";
1182 } else if (i < 2) { 1358 } else if (i < 2) {
1183 expected_error = "Unable to read congestion feedback type."; 1359 expected_error = "Unable to read congestion feedback type.";
1184 } else if (i < 4) { 1360 } else if (i < 4) {
1185 expected_error = "Unable to read accumulated number of lost packets."; 1361 expected_error = "Unable to read accumulated number of lost packets.";
1186 } else if (i < 6) { 1362 } else if (i < 6) {
1187 expected_error = "Unable to read receive window."; 1363 expected_error = "Unable to read receive window.";
1188 } 1364 }
1189 CheckProcessingFails(packet, i + GetPacketHeaderSize(!kIncludeVersion), 1365 CheckProcessingFails(
1190 expected_error, QUIC_INVALID_FRAME_DATA); 1366 packet,
1367 i + GetPacketHeaderSize(
1368 PACKET_8BYTE_GUID, !kIncludeVersion, NOT_IN_FEC_GROUP),
1369 expected_error, QUIC_INVALID_FRAME_DATA);
1191 } 1370 }
1192 } 1371 }
1193 1372
1194 TEST_F(QuicFramerTest, CongestionFeedbackFrameInterArrival) { 1373 TEST_F(QuicFramerTest, CongestionFeedbackFrameInterArrival) {
1195 unsigned char packet[] = { 1374 unsigned char packet[] = {
1196 // public flags (8 byte guid) 1375 // public flags (8 byte guid)
1197 0x0C, 1376 0x0C,
1198 // guid 1377 // guid
1199 0x10, 0x32, 0x54, 0x76, 1378 0x10, 0x32, 0x54, 0x76,
1200 0x98, 0xBA, 0xDC, 0xFE, 1379 0x98, 0xBA, 0xDC, 0xFE,
1201 // packet sequence number 1380 // packet sequence number
1202 0xBC, 0x9A, 0x78, 0x56, 1381 0xBC, 0x9A, 0x78, 0x56,
1203 0x34, 0x12, 1382 0x34, 0x12,
1204 // private flags 1383 // private flags
1205 0x00, 1384 0x00,
1206 // first fec protected packet offset
1207 0xFF,
1208 1385
1209 // frame type (congestion feedback frame) 1386 // frame type (congestion feedback frame)
1210 0x03, 1387 0x03,
1211 // congestion feedback type (inter arrival) 1388 // congestion feedback type (inter arrival)
1212 0x01, 1389 0x01,
1213 // accumulated_number_of_lost_packets 1390 // accumulated_number_of_lost_packets
1214 0x02, 0x03, 1391 0x02, 0x03,
1215 // num received packets 1392 // num received packets
1216 0x03, 1393 0x03,
1217 // lowest sequence number 1394 // lowest sequence number
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1276 expected_error = "Unable to read time received."; 1453 expected_error = "Unable to read time received.";
1277 } else if (i < 21) { 1454 } else if (i < 21) {
1278 expected_error = "Unable to read sequence delta in received packets."; 1455 expected_error = "Unable to read sequence delta in received packets.";
1279 } else if (i < 25) { 1456 } else if (i < 25) {
1280 expected_error = "Unable to read time delta in received packets."; 1457 expected_error = "Unable to read time delta in received packets.";
1281 } else if (i < 27) { 1458 } else if (i < 27) {
1282 expected_error = "Unable to read sequence delta in received packets."; 1459 expected_error = "Unable to read sequence delta in received packets.";
1283 } else if (i < 31) { 1460 } else if (i < 31) {
1284 expected_error = "Unable to read time delta in received packets."; 1461 expected_error = "Unable to read time delta in received packets.";
1285 } 1462 }
1286 CheckProcessingFails(packet, i + GetPacketHeaderSize(!kIncludeVersion), 1463 CheckProcessingFails(
1287 expected_error, QUIC_INVALID_FRAME_DATA); 1464 packet,
1465 i + GetPacketHeaderSize(
1466 PACKET_8BYTE_GUID, !kIncludeVersion, NOT_IN_FEC_GROUP),
1467 expected_error, QUIC_INVALID_FRAME_DATA);
1288 } 1468 }
1289 } 1469 }
1290 1470
1291 TEST_F(QuicFramerTest, CongestionFeedbackFrameFixRate) { 1471 TEST_F(QuicFramerTest, CongestionFeedbackFrameFixRate) {
1292 unsigned char packet[] = { 1472 unsigned char packet[] = {
1293 // public flags (8 byte guid) 1473 // public flags (8 byte guid)
1294 0x0C, 1474 0x0C,
1295 // guid 1475 // guid
1296 0x10, 0x32, 0x54, 0x76, 1476 0x10, 0x32, 0x54, 0x76,
1297 0x98, 0xBA, 0xDC, 0xFE, 1477 0x98, 0xBA, 0xDC, 0xFE,
1298 // packet sequence number 1478 // packet sequence number
1299 0xBC, 0x9A, 0x78, 0x56, 1479 0xBC, 0x9A, 0x78, 0x56,
1300 0x34, 0x12, 1480 0x34, 0x12,
1301 // private flags 1481 // private flags
1302 0x00, 1482 0x00,
1303 // first fec protected packet offset
1304 0xFF,
1305 1483
1306 // frame type (congestion feedback frame) 1484 // frame type (congestion feedback frame)
1307 0x03, 1485 0x03,
1308 // congestion feedback type (fix rate) 1486 // congestion feedback type (fix rate)
1309 0x02, 1487 0x02,
1310 // bitrate_in_bytes_per_second; 1488 // bitrate_in_bytes_per_second;
1311 0x01, 0x02, 0x03, 0x04, 1489 0x01, 0x02, 0x03, 0x04,
1312 }; 1490 };
1313 1491
1314 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1492 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
(...skipping 14 matching lines...) Expand all
1329 // Now test framing boundaries 1507 // Now test framing boundaries
1330 for (size_t i = 0; i < 6; ++i) { 1508 for (size_t i = 0; i < 6; ++i) {
1331 string expected_error; 1509 string expected_error;
1332 if (i < 1) { 1510 if (i < 1) {
1333 expected_error = "Unable to read frame type."; 1511 expected_error = "Unable to read frame type.";
1334 } else if (i < 2) { 1512 } else if (i < 2) {
1335 expected_error = "Unable to read congestion feedback type."; 1513 expected_error = "Unable to read congestion feedback type.";
1336 } else if (i < 6) { 1514 } else if (i < 6) {
1337 expected_error = "Unable to read bitrate."; 1515 expected_error = "Unable to read bitrate.";
1338 } 1516 }
1339 CheckProcessingFails(packet, i + GetPacketHeaderSize(!kIncludeVersion), 1517 CheckProcessingFails(
1340 expected_error, QUIC_INVALID_FRAME_DATA); 1518 packet,
1519 i + GetPacketHeaderSize(
1520 PACKET_8BYTE_GUID, !kIncludeVersion, NOT_IN_FEC_GROUP),
1521 expected_error, QUIC_INVALID_FRAME_DATA);
1341 } 1522 }
1342 } 1523 }
1343 1524
1344 1525
1345 TEST_F(QuicFramerTest, CongestionFeedbackFrameInvalidFeedback) { 1526 TEST_F(QuicFramerTest, CongestionFeedbackFrameInvalidFeedback) {
1346 unsigned char packet[] = { 1527 unsigned char packet[] = {
1347 // public flags (8 byte guid) 1528 // public flags (8 byte guid)
1348 0x0C, 1529 0x0C,
1349 // guid 1530 // guid
1350 0x10, 0x32, 0x54, 0x76, 1531 0x10, 0x32, 0x54, 0x76,
1351 0x98, 0xBA, 0xDC, 0xFE, 1532 0x98, 0xBA, 0xDC, 0xFE,
1352 // packet sequence number 1533 // packet sequence number
1353 0xBC, 0x9A, 0x78, 0x56, 1534 0xBC, 0x9A, 0x78, 0x56,
1354 0x34, 0x12, 1535 0x34, 0x12,
1355 // private flags 1536 // private flags
1356 0x00, 1537 0x00,
1357 // first fec protected packet offset
1358 0xFF,
1359 1538
1360 // frame type (congestion feedback frame) 1539 // frame type (congestion feedback frame)
1361 0x03, 1540 0x03,
1362 // congestion feedback type (invalid) 1541 // congestion feedback type (invalid)
1363 0x03, 1542 0x03,
1364 }; 1543 };
1365 1544
1366 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1545 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1367 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); 1546 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
1368 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 1547 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1369 EXPECT_EQ(QUIC_INVALID_FRAME_DATA, framer_.error()); 1548 EXPECT_EQ(QUIC_INVALID_FRAME_DATA, framer_.error());
1370 } 1549 }
1371 1550
1372 TEST_F(QuicFramerTest, RstStreamFrame) { 1551 TEST_F(QuicFramerTest, RstStreamFrame) {
1373 unsigned char packet[] = { 1552 unsigned char packet[] = {
1374 // public flags (8 byte guid) 1553 // public flags (8 byte guid)
1375 0x0C, 1554 0x0C,
1376 // guid 1555 // guid
1377 0x10, 0x32, 0x54, 0x76, 1556 0x10, 0x32, 0x54, 0x76,
1378 0x98, 0xBA, 0xDC, 0xFE, 1557 0x98, 0xBA, 0xDC, 0xFE,
1379 // packet sequence number 1558 // packet sequence number
1380 0xBC, 0x9A, 0x78, 0x56, 1559 0xBC, 0x9A, 0x78, 0x56,
1381 0x34, 0x12, 1560 0x34, 0x12,
1382 // private flags 1561 // private flags
1383 0x00, 1562 0x00,
1384 // first fec protected packet offset
1385 0xFF,
1386 1563
1387 // frame type (rst stream frame) 1564 // frame type (rst stream frame)
1388 0x04, 1565 0x04,
1389 // stream id 1566 // stream id
1390 0x04, 0x03, 0x02, 0x01, 1567 0x04, 0x03, 0x02, 0x01,
1391 // error code 1568 // error code
1392 0x01, 0x00, 0x00, 0x00, 1569 0x01, 0x00, 0x00, 0x00,
1393 1570
1394 // error details length 1571 // error details length
1395 0x0d, 0x00, 1572 0x0d, 0x00,
(...skipping 19 matching lines...) Expand all
1415 for (size_t i = 2; i < 24; ++i) { 1592 for (size_t i = 2; i < 24; ++i) {
1416 string expected_error; 1593 string expected_error;
1417 if (i < kQuicFrameTypeSize + kQuicStreamIdSize) { 1594 if (i < kQuicFrameTypeSize + kQuicStreamIdSize) {
1418 expected_error = "Unable to read stream_id."; 1595 expected_error = "Unable to read stream_id.";
1419 } else if (i < kQuicFrameTypeSize + kQuicStreamIdSize + 1596 } else if (i < kQuicFrameTypeSize + kQuicStreamIdSize +
1420 kQuicErrorCodeSize) { 1597 kQuicErrorCodeSize) {
1421 expected_error = "Unable to read rst stream error code."; 1598 expected_error = "Unable to read rst stream error code.";
1422 } else { 1599 } else {
1423 expected_error = "Unable to read rst stream error details."; 1600 expected_error = "Unable to read rst stream error details.";
1424 } 1601 }
1425 CheckProcessingFails(packet, i + GetPacketHeaderSize(!kIncludeVersion), 1602 CheckProcessingFails(
1426 expected_error, QUIC_INVALID_RST_STREAM_DATA); 1603 packet,
1604 i + GetPacketHeaderSize(
1605 PACKET_8BYTE_GUID, !kIncludeVersion, NOT_IN_FEC_GROUP),
1606 expected_error, QUIC_INVALID_RST_STREAM_DATA);
1427 } 1607 }
1428 } 1608 }
1429 1609
1430 TEST_F(QuicFramerTest, ConnectionCloseFrame) { 1610 TEST_F(QuicFramerTest, ConnectionCloseFrame) {
1431 unsigned char packet[] = { 1611 unsigned char packet[] = {
1432 // public flags (8 byte guid) 1612 // public flags (8 byte guid)
1433 0x0C, 1613 0x0C,
1434 // guid 1614 // guid
1435 0x10, 0x32, 0x54, 0x76, 1615 0x10, 0x32, 0x54, 0x76,
1436 0x98, 0xBA, 0xDC, 0xFE, 1616 0x98, 0xBA, 0xDC, 0xFE,
1437 // packet sequence number 1617 // packet sequence number
1438 0xBC, 0x9A, 0x78, 0x56, 1618 0xBC, 0x9A, 0x78, 0x56,
1439 0x34, 0x12, 1619 0x34, 0x12,
1440 // private flags 1620 // private flags
1441 0x00, 1621 0x00,
1442 // first fec protected packet offset
1443 0xFF,
1444 1622
1445 // frame type (connection close frame) 1623 // frame type (connection close frame)
1446 0x05, 1624 0x05,
1447 // error code 1625 // error code
1448 0x11, 0x00, 0x00, 0x00, 1626 0x11, 0x00, 0x00, 0x00,
1449 1627
1450 // error details length 1628 // error details length
1451 0x0d, 0x00, 1629 0x0d, 0x00,
1452 // error details 1630 // error details
1453 'b', 'e', 'c', 'a', 1631 'b', 'e', 'c', 'a',
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1501 // Now test framing boundaries 1679 // Now test framing boundaries
1502 for (size_t i = kQuicFrameTypeSize; 1680 for (size_t i = kQuicFrameTypeSize;
1503 i < QuicFramer::GetMinConnectionCloseFrameSize() - 1681 i < QuicFramer::GetMinConnectionCloseFrameSize() -
1504 QuicFramer::GetMinAckFrameSize(); ++i) { 1682 QuicFramer::GetMinAckFrameSize(); ++i) {
1505 string expected_error; 1683 string expected_error;
1506 if (i < kQuicFrameTypeSize + kQuicErrorCodeSize) { 1684 if (i < kQuicFrameTypeSize + kQuicErrorCodeSize) {
1507 expected_error = "Unable to read connection close error code."; 1685 expected_error = "Unable to read connection close error code.";
1508 } else { 1686 } else {
1509 expected_error = "Unable to read connection close error details."; 1687 expected_error = "Unable to read connection close error details.";
1510 } 1688 }
1511 CheckProcessingFails(packet, i + GetPacketHeaderSize(!kIncludeVersion), 1689 CheckProcessingFails(
1512 expected_error, QUIC_INVALID_CONNECTION_CLOSE_DATA); 1690 packet,
1691 i + GetPacketHeaderSize(
1692 PACKET_8BYTE_GUID, !kIncludeVersion, NOT_IN_FEC_GROUP),
1693 expected_error, QUIC_INVALID_CONNECTION_CLOSE_DATA);
1513 } 1694 }
1514 } 1695 }
1515 1696
1516 TEST_F(QuicFramerTest, GoAwayFrame) { 1697 TEST_F(QuicFramerTest, GoAwayFrame) {
1517 unsigned char packet[] = { 1698 unsigned char packet[] = {
1518 // public flags (8 byte guid) 1699 // public flags (8 byte guid)
1519 0x0C, 1700 0x0C,
1520 // guid 1701 // guid
1521 0x10, 0x32, 0x54, 0x76, 1702 0x10, 0x32, 0x54, 0x76,
1522 0x98, 0xBA, 0xDC, 0xFE, 1703 0x98, 0xBA, 0xDC, 0xFE,
1523 // packet sequence number 1704 // packet sequence number
1524 0xBC, 0x9A, 0x78, 0x56, 1705 0xBC, 0x9A, 0x78, 0x56,
1525 0x34, 0x12, 1706 0x34, 0x12,
1526 // private flags 1707 // private flags
1527 0x00, 1708 0x00,
1528 // first fec protected packet offset
1529 0xFF,
1530 1709
1531 // frame type (go away frame) 1710 // frame type (go away frame)
1532 0x06, 1711 0x06,
1533 // error code 1712 // error code
1534 0x09, 0x00, 0x00, 0x00, 1713 0x09, 0x00, 0x00, 0x00,
1535 // stream id 1714 // stream id
1536 0x04, 0x03, 0x02, 0x01, 1715 0x04, 0x03, 0x02, 0x01,
1537 // error details length 1716 // error details length
1538 0x0d, 0x00, 1717 0x0d, 0x00,
1539 // error details 1718 // error details
(...skipping 21 matching lines...) Expand all
1561 i < QuicFramer::GetMinGoAwayFrameSize() + reason_size; ++i) { 1740 i < QuicFramer::GetMinGoAwayFrameSize() + reason_size; ++i) {
1562 string expected_error; 1741 string expected_error;
1563 if (i < kQuicFrameTypeSize + kQuicErrorCodeSize) { 1742 if (i < kQuicFrameTypeSize + kQuicErrorCodeSize) {
1564 expected_error = "Unable to read go away error code."; 1743 expected_error = "Unable to read go away error code.";
1565 } else if (i < kQuicFrameTypeSize + kQuicErrorCodeSize + 1744 } else if (i < kQuicFrameTypeSize + kQuicErrorCodeSize +
1566 kQuicStreamIdSize) { 1745 kQuicStreamIdSize) {
1567 expected_error = "Unable to read last good stream id."; 1746 expected_error = "Unable to read last good stream id.";
1568 } else { 1747 } else {
1569 expected_error = "Unable to read goaway reason."; 1748 expected_error = "Unable to read goaway reason.";
1570 } 1749 }
1571 CheckProcessingFails(packet, i + GetPacketHeaderSize(!kIncludeVersion), 1750 CheckProcessingFails(
1572 expected_error, QUIC_INVALID_GOAWAY_DATA); 1751 packet,
1752 i + GetPacketHeaderSize(
1753 PACKET_8BYTE_GUID, !kIncludeVersion, NOT_IN_FEC_GROUP),
1754 expected_error, QUIC_INVALID_GOAWAY_DATA);
1573 } 1755 }
1574 } 1756 }
1575 1757
1576 TEST_F(QuicFramerTest, PublicResetPacket) { 1758 TEST_F(QuicFramerTest, PublicResetPacket) {
1577 unsigned char packet[] = { 1759 unsigned char packet[] = {
1578 // public flags (public reset, 8 byte guid) 1760 // public flags (public reset, 8 byte guid)
1579 0x0E, 1761 0x0E,
1580 // guid 1762 // guid
1581 0x10, 0x32, 0x54, 0x76, 1763 0x10, 0x32, 0x54, 0x76,
1582 0x98, 0xBA, 0xDC, 0xFE, 1764 0x98, 0xBA, 0xDC, 0xFE,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1626 } 1808 }
1627 1809
1628 TEST_F(QuicFramerTest, VersionNegotiationPacket) { 1810 TEST_F(QuicFramerTest, VersionNegotiationPacket) {
1629 unsigned char packet[] = { 1811 unsigned char packet[] = {
1630 // public flags (version, 8 byte guid) 1812 // public flags (version, 8 byte guid)
1631 0x0D, 1813 0x0D,
1632 // guid 1814 // guid
1633 0x10, 0x32, 0x54, 0x76, 1815 0x10, 0x32, 0x54, 0x76,
1634 0x98, 0xBA, 0xDC, 0xFE, 1816 0x98, 0xBA, 0xDC, 0xFE,
1635 // version tag 1817 // version tag
1636 'Q', '0', '0', '4', 1818 'Q', '0', '0', '5',
1637 'Q', '2', '.', '0', 1819 'Q', '2', '.', '0',
1638 }; 1820 };
1639 1821
1640 QuicFramerPeer::SetIsServer(&framer_, false); 1822 QuicFramerPeer::SetIsServer(&framer_, false);
1641 1823
1642 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1824 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1643 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1825 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1644 ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); 1826 ASSERT_EQ(QUIC_NO_ERROR, framer_.error());
1645 ASSERT_TRUE(visitor_.version_negotiation_packet_.get()); 1827 ASSERT_TRUE(visitor_.version_negotiation_packet_.get());
1646 EXPECT_EQ(2u, visitor_.version_negotiation_packet_->versions.size()); 1828 EXPECT_EQ(2u, visitor_.version_negotiation_packet_->versions.size());
1647 EXPECT_EQ(kQuicVersion1, 1829 EXPECT_EQ(kQuicVersion1,
1648 visitor_.version_negotiation_packet_->versions[0]); 1830 visitor_.version_negotiation_packet_->versions[0]);
1649 1831
1650 for (size_t i = 0; i <= kPublicFlagsSize + kQuicGuidSize; ++i) { 1832 for (size_t i = 0; i <= kPublicFlagsSize + PACKET_8BYTE_GUID; ++i) {
1651 string expected_error; 1833 string expected_error;
1652 QuicErrorCode error_code = QUIC_INVALID_PACKET_HEADER; 1834 QuicErrorCode error_code = QUIC_INVALID_PACKET_HEADER;
1653 if (i < kGuidOffset) { 1835 if (i < kGuidOffset) {
1654 expected_error = "Unable to read public flags."; 1836 expected_error = "Unable to read public flags.";
1655 } else if (i < kVersionOffset) { 1837 } else if (i < kVersionOffset) {
1656 expected_error = "Unable to read GUID."; 1838 expected_error = "Unable to read GUID.";
1657 } else { 1839 } else {
1658 expected_error = "Unable to read supported version in negotiation."; 1840 expected_error = "Unable to read supported version in negotiation.";
1659 error_code = QUIC_INVALID_VERSION_NEGOTIATION_PACKET; 1841 error_code = QUIC_INVALID_VERSION_NEGOTIATION_PACKET;
1660 } 1842 }
1661 CheckProcessingFails(packet, i, expected_error, error_code); 1843 CheckProcessingFails(packet, i, expected_error, error_code);
1662 } 1844 }
1663 } 1845 }
1664 1846
1665 TEST_F(QuicFramerTest, FecPacket) { 1847 TEST_F(QuicFramerTest, FecPacket) {
1666 unsigned char packet[] = { 1848 unsigned char packet[] = {
1667 // public flags (8 byte guid) 1849 // public flags (8 byte guid)
1668 0x0C, 1850 0x0C,
1669 // guid 1851 // guid
1670 0x10, 0x32, 0x54, 0x76, 1852 0x10, 0x32, 0x54, 0x76,
1671 0x98, 0xBA, 0xDC, 0xFE, 1853 0x98, 0xBA, 0xDC, 0xFE,
1672 // packet sequence number 1854 // packet sequence number
1673 0xBC, 0x9A, 0x78, 0x56, 1855 0xBC, 0x9A, 0x78, 0x56,
1674 0x34, 0x12, 1856 0x34, 0x12,
1675 // private flags (FEC) 1857 // private flags (fec group & FEC)
1676 0x01, 1858 0x06,
1677 // first fec protected packet offset 1859 // first fec protected packet offset
1678 0x01, 1860 0x01,
1679 1861
1680 // redundancy 1862 // redundancy
1681 'a', 'b', 'c', 'd', 1863 'a', 'b', 'c', 'd',
1682 'e', 'f', 'g', 'h', 1864 'e', 'f', 'g', 'h',
1683 'i', 'j', 'k', 'l', 1865 'i', 'j', 'k', 'l',
1684 'm', 'n', 'o', 'p', 1866 'm', 'n', 'o', 'p',
1685 }; 1867 };
1686 1868
(...skipping 12 matching lines...) Expand all
1699 EXPECT_EQ("abcdefghijklmnop", fec_data.redundancy); 1881 EXPECT_EQ("abcdefghijklmnop", fec_data.redundancy);
1700 } 1882 }
1701 1883
1702 TEST_F(QuicFramerTest, ConstructPaddingFramePacket) { 1884 TEST_F(QuicFramerTest, ConstructPaddingFramePacket) {
1703 QuicPacketHeader header; 1885 QuicPacketHeader header;
1704 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); 1886 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210);
1705 header.public_header.reset_flag = false; 1887 header.public_header.reset_flag = false;
1706 header.public_header.version_flag = false; 1888 header.public_header.version_flag = false;
1707 header.fec_flag = false; 1889 header.fec_flag = false;
1708 header.entropy_flag = false; 1890 header.entropy_flag = false;
1709 header.fec_entropy_flag = false;
1710 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); 1891 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
1711 header.fec_group = 0; 1892 header.fec_group = 0;
1712 1893
1713 QuicPaddingFrame padding_frame; 1894 QuicPaddingFrame padding_frame;
1714 1895
1715 QuicFrames frames; 1896 QuicFrames frames;
1716 frames.push_back(QuicFrame(&padding_frame)); 1897 frames.push_back(QuicFrame(&padding_frame));
1717 1898
1718 unsigned char packet[kMaxPacketSize] = { 1899 unsigned char packet[kMaxPacketSize] = {
1719 // public flags (8 byte guid) 1900 // public flags (8 byte guid)
1720 0x0C, 1901 0x0C,
1721 // guid 1902 // guid
1722 0x10, 0x32, 0x54, 0x76, 1903 0x10, 0x32, 0x54, 0x76,
1723 0x98, 0xBA, 0xDC, 0xFE, 1904 0x98, 0xBA, 0xDC, 0xFE,
1724 // packet sequence number 1905 // packet sequence number
1725 0xBC, 0x9A, 0x78, 0x56, 1906 0xBC, 0x9A, 0x78, 0x56,
1726 0x34, 0x12, 1907 0x34, 0x12,
1727 // private flags 1908 // private flags
1728 0x00, 1909 0x00,
1729 // first fec protected packet offset
1730 0xFF,
1731 1910
1732 // frame type (padding frame) 1911 // frame type (padding frame)
1733 0x00, 1912 0x00,
1734 }; 1913 };
1735 1914
1736 memset(packet + GetPacketHeaderSize(!kIncludeVersion) + 1, 0x00, 1915 uint64 header_size = GetPacketHeaderSize(PACKET_8BYTE_GUID, !kIncludeVersion,
1737 kMaxPacketSize - GetPacketHeaderSize(!kIncludeVersion) - 1); 1916 NOT_IN_FEC_GROUP);
1917 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1);
1738 1918
1739 scoped_ptr<QuicPacket> data( 1919 scoped_ptr<QuicPacket> data(
1740 framer_.ConstructFrameDataPacket(header, frames).packet); 1920 framer_.ConstructFrameDataPacket(header, frames).packet);
1741 ASSERT_TRUE(data != NULL); 1921 ASSERT_TRUE(data != NULL);
1742 1922
1743 test::CompareCharArraysWithHexError("constructed packet", 1923 test::CompareCharArraysWithHexError("constructed packet",
1744 data->data(), data->length(), 1924 data->data(), data->length(),
1745 AsChars(packet), arraysize(packet)); 1925 AsChars(packet), arraysize(packet));
1746 } 1926 }
1747 1927
1748 TEST_F(QuicFramerTest, ConstructStreamFramePacket) { 1928 TEST_F(QuicFramerTest, ConstructStreamFramePacket) {
1749 QuicPacketHeader header; 1929 QuicPacketHeader header;
1750 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); 1930 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210);
1751 header.public_header.reset_flag = false; 1931 header.public_header.reset_flag = false;
1752 header.public_header.version_flag = false; 1932 header.public_header.version_flag = false;
1753 header.fec_flag = false; 1933 header.fec_flag = false;
1754 header.entropy_flag = true; 1934 header.entropy_flag = true;
1755 header.fec_entropy_flag = false;
1756 header.packet_sequence_number = GG_UINT64_C(0x77123456789ABC); 1935 header.packet_sequence_number = GG_UINT64_C(0x77123456789ABC);
1757 header.fec_group = 0; 1936 header.fec_group = 0;
1758 1937
1759 QuicStreamFrame stream_frame; 1938 QuicStreamFrame stream_frame;
1760 stream_frame.stream_id = 0x01020304; 1939 stream_frame.stream_id = 0x01020304;
1761 stream_frame.fin = true; 1940 stream_frame.fin = true;
1762 stream_frame.offset = GG_UINT64_C(0xBA98FEDC32107654); 1941 stream_frame.offset = GG_UINT64_C(0xBA98FEDC32107654);
1763 stream_frame.data = "hello world!"; 1942 stream_frame.data = "hello world!";
1764 1943
1765 QuicFrames frames; 1944 QuicFrames frames;
1766 frames.push_back(QuicFrame(&stream_frame)); 1945 frames.push_back(QuicFrame(&stream_frame));
1767 1946
1768 unsigned char packet[] = { 1947 unsigned char packet[] = {
1769 // public flags (8 byte guid) 1948 // public flags (8 byte guid)
1770 0x0C, 1949 0x0C,
1771 // guid 1950 // guid
1772 0x10, 0x32, 0x54, 0x76, 1951 0x10, 0x32, 0x54, 0x76,
1773 0x98, 0xBA, 0xDC, 0xFE, 1952 0x98, 0xBA, 0xDC, 0xFE,
1774 // packet sequence number 1953 // packet sequence number
1775 0xBC, 0x9A, 0x78, 0x56, 1954 0xBC, 0x9A, 0x78, 0x56,
1776 0x34, 0x12, 1955 0x34, 0x12,
1777 // private flags (entropy) 1956 // private flags (entropy)
1778 0x02, 1957 0x01,
1779 // first fec protected packet offset
1780 0xFF,
1781 1958
1782 // frame type (stream frame) 1959 // frame type (stream frame)
1783 0x01, 1960 0x01,
1784 // stream id 1961 // stream id
1785 0x04, 0x03, 0x02, 0x01, 1962 0x04, 0x03, 0x02, 0x01,
1786 // fin 1963 // fin
1787 0x01, 1964 0x01,
1788 // offset 1965 // offset
1789 0x54, 0x76, 0x10, 0x32, 1966 0x54, 0x76, 0x10, 0x32,
1790 0xDC, 0xFE, 0x98, 0xBA, 1967 0xDC, 0xFE, 0x98, 0xBA,
(...skipping 14 matching lines...) Expand all
1805 AsChars(packet), arraysize(packet)); 1982 AsChars(packet), arraysize(packet));
1806 } 1983 }
1807 1984
1808 TEST_F(QuicFramerTest, ConstructStreamFramePacketWithVersionFlag) { 1985 TEST_F(QuicFramerTest, ConstructStreamFramePacketWithVersionFlag) {
1809 QuicPacketHeader header; 1986 QuicPacketHeader header;
1810 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); 1987 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210);
1811 header.public_header.reset_flag = false; 1988 header.public_header.reset_flag = false;
1812 header.public_header.version_flag = true; 1989 header.public_header.version_flag = true;
1813 header.fec_flag = false; 1990 header.fec_flag = false;
1814 header.entropy_flag = true; 1991 header.entropy_flag = true;
1815 header.fec_entropy_flag = false;
1816 header.packet_sequence_number = GG_UINT64_C(0x77123456789ABC); 1992 header.packet_sequence_number = GG_UINT64_C(0x77123456789ABC);
1817 header.fec_group = 0; 1993 header.fec_group = 0;
1818 1994
1819 QuicStreamFrame stream_frame; 1995 QuicStreamFrame stream_frame;
1820 stream_frame.stream_id = 0x01020304; 1996 stream_frame.stream_id = 0x01020304;
1821 stream_frame.fin = true; 1997 stream_frame.fin = true;
1822 stream_frame.offset = GG_UINT64_C(0xBA98FEDC32107654); 1998 stream_frame.offset = GG_UINT64_C(0xBA98FEDC32107654);
1823 stream_frame.data = "hello world!"; 1999 stream_frame.data = "hello world!";
1824 2000
1825 QuicFrames frames; 2001 QuicFrames frames;
1826 frames.push_back(QuicFrame(&stream_frame)); 2002 frames.push_back(QuicFrame(&stream_frame));
1827 2003
1828 unsigned char packet[] = { 2004 unsigned char packet[] = {
1829 // public flags (version, 8 byte guid) 2005 // public flags (version, 8 byte guid)
1830 0x0D, 2006 0x0D,
1831 // guid 2007 // guid
1832 0x10, 0x32, 0x54, 0x76, 2008 0x10, 0x32, 0x54, 0x76,
1833 0x98, 0xBA, 0xDC, 0xFE, 2009 0x98, 0xBA, 0xDC, 0xFE,
1834 // version tag 2010 // version tag
1835 'Q', '0', '0', '4', 2011 'Q', '0', '0', '5',
1836 // packet sequence number 2012 // packet sequence number
1837 0xBC, 0x9A, 0x78, 0x56, 2013 0xBC, 0x9A, 0x78, 0x56,
1838 0x34, 0x12, 2014 0x34, 0x12,
1839 // private flags (entropy) 2015 // private flags (entropy)
1840 0x02, 2016 0x01,
1841 // first fec protected packet offset
1842 0xFF,
1843 2017
1844 // frame type (stream frame) 2018 // frame type (stream frame)
1845 0x01, 2019 0x01,
1846 // stream id 2020 // stream id
1847 0x04, 0x03, 0x02, 0x01, 2021 0x04, 0x03, 0x02, 0x01,
1848 // fin 2022 // fin
1849 0x01, 2023 0x01,
1850 // offset 2024 // offset
1851 0x54, 0x76, 0x10, 0x32, 2025 0x54, 0x76, 0x10, 0x32,
1852 0xDC, 0xFE, 0x98, 0xBA, 2026 0xDC, 0xFE, 0x98, 0xBA,
(...skipping 21 matching lines...) Expand all
1874 header.reset_flag = false; 2048 header.reset_flag = false;
1875 header.version_flag = true; 2049 header.version_flag = true;
1876 2050
1877 unsigned char packet[] = { 2051 unsigned char packet[] = {
1878 // public flags (version, 8 byte guid) 2052 // public flags (version, 8 byte guid)
1879 0x0D, 2053 0x0D,
1880 // guid 2054 // guid
1881 0x10, 0x32, 0x54, 0x76, 2055 0x10, 0x32, 0x54, 0x76,
1882 0x98, 0xBA, 0xDC, 0xFE, 2056 0x98, 0xBA, 0xDC, 0xFE,
1883 // version tag 2057 // version tag
1884 'Q', '0', '0', '4', 2058 'Q', '0', '0', '5',
1885 'Q', '2', '.', '0', 2059 'Q', '2', '.', '0',
1886 }; 2060 };
1887 2061
1888 const int kQuicVersion2 = MakeQuicTag('Q', '2', '.', '0'); 2062 const int kQuicVersion2 = MakeQuicTag('Q', '2', '.', '0');
1889 QuicTagVector versions; 2063 QuicTagVector versions;
1890 versions.push_back(kQuicVersion1); 2064 versions.push_back(kQuicVersion1);
1891 versions.push_back(kQuicVersion2); 2065 versions.push_back(kQuicVersion2);
1892 scoped_ptr<QuicEncryptedPacket> data( 2066 scoped_ptr<QuicEncryptedPacket> data(
1893 framer_.ConstructVersionNegotiationPacket(header, versions)); 2067 framer_.ConstructVersionNegotiationPacket(header, versions));
1894 2068
1895 test::CompareCharArraysWithHexError("constructed packet", 2069 test::CompareCharArraysWithHexError("constructed packet",
1896 data->data(), data->length(), 2070 data->data(), data->length(),
1897 AsChars(packet), arraysize(packet)); 2071 AsChars(packet), arraysize(packet));
1898 } 2072 }
1899 2073
1900 TEST_F(QuicFramerTest, ConstructAckFramePacket) { 2074 TEST_F(QuicFramerTest, ConstructAckFramePacket) {
1901 QuicPacketHeader header; 2075 QuicPacketHeader header;
1902 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); 2076 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210);
1903 header.public_header.reset_flag = false; 2077 header.public_header.reset_flag = false;
1904 header.public_header.version_flag = false; 2078 header.public_header.version_flag = false;
1905 header.fec_flag = false; 2079 header.fec_flag = false;
1906 header.entropy_flag = true; 2080 header.entropy_flag = true;
1907 header.fec_entropy_flag = true;
1908 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); 2081 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
1909 header.fec_group = 0; 2082 header.fec_group = 0;
1910 2083
1911 QuicAckFrame ack_frame; 2084 QuicAckFrame ack_frame;
1912 ack_frame.received_info.entropy_hash = 0x43; 2085 ack_frame.received_info.entropy_hash = 0x43;
1913 ack_frame.received_info.largest_observed = GG_UINT64_C(0x770123456789ABF); 2086 ack_frame.received_info.largest_observed = GG_UINT64_C(0x770123456789ABF);
1914 ack_frame.received_info.delta_time_largest_observed = QuicTime::Delta::Zero(); 2087 ack_frame.received_info.delta_time_largest_observed = QuicTime::Delta::Zero();
1915 ack_frame.received_info.missing_packets.insert( 2088 ack_frame.received_info.missing_packets.insert(
1916 GG_UINT64_C(0x770123456789ABE)); 2089 GG_UINT64_C(0x770123456789ABE));
1917 ack_frame.sent_info.entropy_hash = 0x14; 2090 ack_frame.sent_info.entropy_hash = 0x14;
1918 ack_frame.sent_info.least_unacked = GG_UINT64_C(0x770123456789AA0); 2091 ack_frame.sent_info.least_unacked = GG_UINT64_C(0x770123456789AA0);
1919 2092
1920 QuicFrames frames; 2093 QuicFrames frames;
1921 frames.push_back(QuicFrame(&ack_frame)); 2094 frames.push_back(QuicFrame(&ack_frame));
1922 2095
1923 unsigned char packet[] = { 2096 unsigned char packet[] = {
1924 // public flags (8 byte guid) 2097 // public flags (8 byte guid)
1925 0x0C, 2098 0x0C,
1926 // guid 2099 // guid
1927 0x10, 0x32, 0x54, 0x76, 2100 0x10, 0x32, 0x54, 0x76,
1928 0x98, 0xBA, 0xDC, 0xFE, 2101 0x98, 0xBA, 0xDC, 0xFE,
1929 // packet sequence number 2102 // packet sequence number
1930 0xBC, 0x9A, 0x78, 0x56, 2103 0xBC, 0x9A, 0x78, 0x56,
1931 0x34, 0x12, 2104 0x34, 0x12,
1932 // private flags (entropy & fec_entropy -- not relevant) 2105 // private flags (entropy)
1933 0x06, 2106 0x01,
1934 // first fec protected packet offset
1935 0xFF,
1936 2107
1937 // frame type (ack frame) 2108 // frame type (ack frame)
1938 0x02, 2109 0x02,
1939 // entropy hash of sent packets till least awaiting - 1. 2110 // entropy hash of sent packets till least awaiting - 1.
1940 0x14, 2111 0x14,
1941 // least packet sequence number awaiting an ack 2112 // least packet sequence number awaiting an ack
1942 0xA0, 0x9A, 0x78, 0x56, 2113 0xA0, 0x9A, 0x78, 0x56,
1943 0x34, 0x12, 2114 0x34, 0x12,
1944 // entropy hash of all received packets. 2115 // entropy hash of all received packets.
1945 0x43, 2116 0x43,
(...skipping 18 matching lines...) Expand all
1964 AsChars(packet), arraysize(packet)); 2135 AsChars(packet), arraysize(packet));
1965 } 2136 }
1966 2137
1967 TEST_F(QuicFramerTest, ConstructCongestionFeedbackFramePacketTCP) { 2138 TEST_F(QuicFramerTest, ConstructCongestionFeedbackFramePacketTCP) {
1968 QuicPacketHeader header; 2139 QuicPacketHeader header;
1969 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); 2140 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210);
1970 header.public_header.reset_flag = false; 2141 header.public_header.reset_flag = false;
1971 header.public_header.version_flag = false; 2142 header.public_header.version_flag = false;
1972 header.fec_flag = false; 2143 header.fec_flag = false;
1973 header.entropy_flag = false; 2144 header.entropy_flag = false;
1974 header.fec_entropy_flag = true;
1975 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); 2145 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
1976 header.fec_group = 0; 2146 header.fec_group = 0;
1977 2147
1978 QuicCongestionFeedbackFrame congestion_feedback_frame; 2148 QuicCongestionFeedbackFrame congestion_feedback_frame;
1979 congestion_feedback_frame.type = kTCP; 2149 congestion_feedback_frame.type = kTCP;
1980 congestion_feedback_frame.tcp.accumulated_number_of_lost_packets = 0x0201; 2150 congestion_feedback_frame.tcp.accumulated_number_of_lost_packets = 0x0201;
1981 congestion_feedback_frame.tcp.receive_window = 0x4030; 2151 congestion_feedback_frame.tcp.receive_window = 0x4030;
1982 2152
1983 QuicFrames frames; 2153 QuicFrames frames;
1984 frames.push_back(QuicFrame(&congestion_feedback_frame)); 2154 frames.push_back(QuicFrame(&congestion_feedback_frame));
1985 2155
1986 unsigned char packet[] = { 2156 unsigned char packet[] = {
1987 // public flags (8 byte guid) 2157 // public flags (8 byte guid)
1988 0x0C, 2158 0x0C,
1989 // guid 2159 // guid
1990 0x10, 0x32, 0x54, 0x76, 2160 0x10, 0x32, 0x54, 0x76,
1991 0x98, 0xBA, 0xDC, 0xFE, 2161 0x98, 0xBA, 0xDC, 0xFE,
1992 // packet sequence number 2162 // packet sequence number
1993 0xBC, 0x9A, 0x78, 0x56, 2163 0xBC, 0x9A, 0x78, 0x56,
1994 0x34, 0x12, 2164 0x34, 0x12,
1995 // private flags 2165 // private flags
1996 0x04, // (fec_entropy_flag) 2166 0x00,
1997 // first fec protected packet offset
1998 0xFF,
1999 2167
2000 // frame type (congestion feedback frame) 2168 // frame type (congestion feedback frame)
2001 0x03, 2169 0x03,
2002 // congestion feedback type (TCP) 2170 // congestion feedback type (TCP)
2003 0x00, 2171 0x00,
2004 // accumulated number of lost packets 2172 // accumulated number of lost packets
2005 0x01, 0x02, 2173 0x01, 0x02,
2006 // TCP receive window 2174 // TCP receive window
2007 0x03, 0x04, 2175 0x03, 0x04,
2008 }; 2176 };
2009 2177
2010 scoped_ptr<QuicPacket> data( 2178 scoped_ptr<QuicPacket> data(
2011 framer_.ConstructFrameDataPacket(header, frames).packet); 2179 framer_.ConstructFrameDataPacket(header, frames).packet);
2012 ASSERT_TRUE(data != NULL); 2180 ASSERT_TRUE(data != NULL);
2013 2181
2014 test::CompareCharArraysWithHexError("constructed packet", 2182 test::CompareCharArraysWithHexError("constructed packet",
2015 data->data(), data->length(), 2183 data->data(), data->length(),
2016 AsChars(packet), arraysize(packet)); 2184 AsChars(packet), arraysize(packet));
2017 } 2185 }
2018 2186
2019 TEST_F(QuicFramerTest, ConstructCongestionFeedbackFramePacketInterArrival) { 2187 TEST_F(QuicFramerTest, ConstructCongestionFeedbackFramePacketInterArrival) {
2020 QuicPacketHeader header; 2188 QuicPacketHeader header;
2021 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); 2189 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210);
2022 header.public_header.reset_flag = false; 2190 header.public_header.reset_flag = false;
2023 header.public_header.version_flag = false; 2191 header.public_header.version_flag = false;
2024 header.fec_flag = false; 2192 header.fec_flag = false;
2025 header.entropy_flag = false; 2193 header.entropy_flag = false;
2026 header.fec_entropy_flag = false;
2027 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); 2194 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
2028 header.fec_group = 0; 2195 header.fec_group = 0;
2029 2196
2030 QuicCongestionFeedbackFrame frame; 2197 QuicCongestionFeedbackFrame frame;
2031 frame.type = kInterArrival; 2198 frame.type = kInterArrival;
2032 frame.inter_arrival.accumulated_number_of_lost_packets = 0x0302; 2199 frame.inter_arrival.accumulated_number_of_lost_packets = 0x0302;
2033 frame.inter_arrival.received_packet_times.insert( 2200 frame.inter_arrival.received_packet_times.insert(
2034 make_pair(GG_UINT64_C(0x0123456789ABA), 2201 make_pair(GG_UINT64_C(0x0123456789ABA),
2035 start_.Add(QuicTime::Delta::FromMicroseconds( 2202 start_.Add(QuicTime::Delta::FromMicroseconds(
2036 GG_UINT64_C(0x07E1D2C3B4A59687))))); 2203 GG_UINT64_C(0x07E1D2C3B4A59687)))));
(...skipping 12 matching lines...) Expand all
2049 // public flags (8 byte guid) 2216 // public flags (8 byte guid)
2050 0x0C, 2217 0x0C,
2051 // guid 2218 // guid
2052 0x10, 0x32, 0x54, 0x76, 2219 0x10, 0x32, 0x54, 0x76,
2053 0x98, 0xBA, 0xDC, 0xFE, 2220 0x98, 0xBA, 0xDC, 0xFE,
2054 // packet sequence number 2221 // packet sequence number
2055 0xBC, 0x9A, 0x78, 0x56, 2222 0xBC, 0x9A, 0x78, 0x56,
2056 0x34, 0x12, 2223 0x34, 0x12,
2057 // private flags 2224 // private flags
2058 0x00, 2225 0x00,
2059 // first fec protected packet offset
2060 0xFF,
2061 2226
2062 // frame type (congestion feedback frame) 2227 // frame type (congestion feedback frame)
2063 0x03, 2228 0x03,
2064 // congestion feedback type (inter arrival) 2229 // congestion feedback type (inter arrival)
2065 0x01, 2230 0x01,
2066 // accumulated_number_of_lost_packets 2231 // accumulated_number_of_lost_packets
2067 0x02, 0x03, 2232 0x02, 0x03,
2068 // num received packets 2233 // num received packets
2069 0x03, 2234 0x03,
2070 // lowest sequence number 2235 // lowest sequence number
(...skipping 21 matching lines...) Expand all
2092 AsChars(packet), arraysize(packet)); 2257 AsChars(packet), arraysize(packet));
2093 } 2258 }
2094 2259
2095 TEST_F(QuicFramerTest, ConstructCongestionFeedbackFramePacketFixRate) { 2260 TEST_F(QuicFramerTest, ConstructCongestionFeedbackFramePacketFixRate) {
2096 QuicPacketHeader header; 2261 QuicPacketHeader header;
2097 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); 2262 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210);
2098 header.public_header.reset_flag = false; 2263 header.public_header.reset_flag = false;
2099 header.public_header.version_flag = false; 2264 header.public_header.version_flag = false;
2100 header.fec_flag = false; 2265 header.fec_flag = false;
2101 header.entropy_flag = false; 2266 header.entropy_flag = false;
2102 header.fec_entropy_flag = false;
2103 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); 2267 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
2104 header.fec_group = 0; 2268 header.fec_group = 0;
2105 2269
2106 QuicCongestionFeedbackFrame congestion_feedback_frame; 2270 QuicCongestionFeedbackFrame congestion_feedback_frame;
2107 congestion_feedback_frame.type = kFixRate; 2271 congestion_feedback_frame.type = kFixRate;
2108 congestion_feedback_frame.fix_rate.bitrate 2272 congestion_feedback_frame.fix_rate.bitrate
2109 = QuicBandwidth::FromBytesPerSecond(0x04030201); 2273 = QuicBandwidth::FromBytesPerSecond(0x04030201);
2110 2274
2111 QuicFrames frames; 2275 QuicFrames frames;
2112 frames.push_back(QuicFrame(&congestion_feedback_frame)); 2276 frames.push_back(QuicFrame(&congestion_feedback_frame));
2113 2277
2114 unsigned char packet[] = { 2278 unsigned char packet[] = {
2115 // public flags (8 byte guid) 2279 // public flags (8 byte guid)
2116 0x0C, 2280 0x0C,
2117 // guid 2281 // guid
2118 0x10, 0x32, 0x54, 0x76, 2282 0x10, 0x32, 0x54, 0x76,
2119 0x98, 0xBA, 0xDC, 0xFE, 2283 0x98, 0xBA, 0xDC, 0xFE,
2120 // packet sequence number 2284 // packet sequence number
2121 0xBC, 0x9A, 0x78, 0x56, 2285 0xBC, 0x9A, 0x78, 0x56,
2122 0x34, 0x12, 2286 0x34, 0x12,
2123 // private flags 2287 // private flags
2124 0x00, 2288 0x00,
2125 // first fec protected packet offset
2126 0xFF,
2127 2289
2128 // frame type (congestion feedback frame) 2290 // frame type (congestion feedback frame)
2129 0x03, 2291 0x03,
2130 // congestion feedback type (fix rate) 2292 // congestion feedback type (fix rate)
2131 0x02, 2293 0x02,
2132 // bitrate_in_bytes_per_second; 2294 // bitrate_in_bytes_per_second;
2133 0x01, 0x02, 0x03, 0x04, 2295 0x01, 0x02, 0x03, 0x04,
2134 }; 2296 };
2135 2297
2136 scoped_ptr<QuicPacket> data( 2298 scoped_ptr<QuicPacket> data(
2137 framer_.ConstructFrameDataPacket(header, frames).packet); 2299 framer_.ConstructFrameDataPacket(header, frames).packet);
2138 ASSERT_TRUE(data != NULL); 2300 ASSERT_TRUE(data != NULL);
2139 2301
2140 test::CompareCharArraysWithHexError("constructed packet", 2302 test::CompareCharArraysWithHexError("constructed packet",
2141 data->data(), data->length(), 2303 data->data(), data->length(),
2142 AsChars(packet), arraysize(packet)); 2304 AsChars(packet), arraysize(packet));
2143 } 2305 }
2144 2306
2145 TEST_F(QuicFramerTest, ConstructCongestionFeedbackFramePacketInvalidFeedback) { 2307 TEST_F(QuicFramerTest, ConstructCongestionFeedbackFramePacketInvalidFeedback) {
2146 QuicPacketHeader header; 2308 QuicPacketHeader header;
2147 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); 2309 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210);
2148 header.public_header.reset_flag = false; 2310 header.public_header.reset_flag = false;
2149 header.public_header.version_flag = false; 2311 header.public_header.version_flag = false;
2150 header.fec_flag = false; 2312 header.fec_flag = false;
2151 header.entropy_flag = false; 2313 header.entropy_flag = false;
2152 header.fec_entropy_flag = false;
2153 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); 2314 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
2154 header.fec_group = 0; 2315 header.fec_group = 0;
2155 2316
2156 QuicCongestionFeedbackFrame congestion_feedback_frame; 2317 QuicCongestionFeedbackFrame congestion_feedback_frame;
2157 congestion_feedback_frame.type = 2318 congestion_feedback_frame.type =
2158 static_cast<CongestionFeedbackType>(kFixRate + 1); 2319 static_cast<CongestionFeedbackType>(kFixRate + 1);
2159 2320
2160 QuicFrames frames; 2321 QuicFrames frames;
2161 frames.push_back(QuicFrame(&congestion_feedback_frame)); 2322 frames.push_back(QuicFrame(&congestion_feedback_frame));
2162 2323
2163 scoped_ptr<QuicPacket> data( 2324 scoped_ptr<QuicPacket> data(
2164 framer_.ConstructFrameDataPacket(header, frames).packet); 2325 framer_.ConstructFrameDataPacket(header, frames).packet);
2165 ASSERT_TRUE(data == NULL); 2326 ASSERT_TRUE(data == NULL);
2166 } 2327 }
2167 2328
2168 TEST_F(QuicFramerTest, ConstructRstFramePacket) { 2329 TEST_F(QuicFramerTest, ConstructRstFramePacket) {
2169 QuicPacketHeader header; 2330 QuicPacketHeader header;
2170 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); 2331 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210);
2171 header.public_header.reset_flag = false; 2332 header.public_header.reset_flag = false;
2172 header.public_header.version_flag = false; 2333 header.public_header.version_flag = false;
2173 header.fec_flag = false; 2334 header.fec_flag = false;
2174 header.entropy_flag = false; 2335 header.entropy_flag = false;
2175 header.fec_entropy_flag = false;
2176 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); 2336 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
2177 header.fec_group = 0; 2337 header.fec_group = 0;
2178 2338
2179 QuicRstStreamFrame rst_frame; 2339 QuicRstStreamFrame rst_frame;
2180 rst_frame.stream_id = 0x01020304; 2340 rst_frame.stream_id = 0x01020304;
2181 rst_frame.error_code = static_cast<QuicRstStreamErrorCode>(0x05060708); 2341 rst_frame.error_code = static_cast<QuicRstStreamErrorCode>(0x05060708);
2182 rst_frame.error_details = "because I can"; 2342 rst_frame.error_details = "because I can";
2183 2343
2184 unsigned char packet[] = { 2344 unsigned char packet[] = {
2185 // public flags (8 byte guid) 2345 // public flags (8 byte guid)
2186 0x0C, 2346 0x0C,
2187 // guid 2347 // guid
2188 0x10, 0x32, 0x54, 0x76, 2348 0x10, 0x32, 0x54, 0x76,
2189 0x98, 0xBA, 0xDC, 0xFE, 2349 0x98, 0xBA, 0xDC, 0xFE,
2190 // packet sequence number 2350 // packet sequence number
2191 0xBC, 0x9A, 0x78, 0x56, 2351 0xBC, 0x9A, 0x78, 0x56,
2192 0x34, 0x12, 2352 0x34, 0x12,
2193 // private flags 2353 // private flags
2194 0x00, 2354 0x00,
2195 // first fec protected packet offset
2196 0xFF,
2197 2355
2198 // frame type (rst stream frame) 2356 // frame type (rst stream frame)
2199 0x04, 2357 0x04,
2200 // stream id 2358 // stream id
2201 0x04, 0x03, 0x02, 0x01, 2359 0x04, 0x03, 0x02, 0x01,
2202 // error code 2360 // error code
2203 0x08, 0x07, 0x06, 0x05, 2361 0x08, 0x07, 0x06, 0x05,
2204 // error details length 2362 // error details length
2205 0x0d, 0x00, 2363 0x0d, 0x00,
2206 // error details 2364 // error details
(...skipping 15 matching lines...) Expand all
2222 AsChars(packet), arraysize(packet)); 2380 AsChars(packet), arraysize(packet));
2223 } 2381 }
2224 2382
2225 TEST_F(QuicFramerTest, ConstructCloseFramePacket) { 2383 TEST_F(QuicFramerTest, ConstructCloseFramePacket) {
2226 QuicPacketHeader header; 2384 QuicPacketHeader header;
2227 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); 2385 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210);
2228 header.public_header.reset_flag = false; 2386 header.public_header.reset_flag = false;
2229 header.public_header.version_flag = false; 2387 header.public_header.version_flag = false;
2230 header.fec_flag = false; 2388 header.fec_flag = false;
2231 header.entropy_flag = true; 2389 header.entropy_flag = true;
2232 header.fec_entropy_flag = false;
2233 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); 2390 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
2234 header.fec_group = 0; 2391 header.fec_group = 0;
2235 2392
2236 QuicConnectionCloseFrame close_frame; 2393 QuicConnectionCloseFrame close_frame;
2237 close_frame.error_code = static_cast<QuicErrorCode>(0x05060708); 2394 close_frame.error_code = static_cast<QuicErrorCode>(0x05060708);
2238 close_frame.error_details = "because I can"; 2395 close_frame.error_details = "because I can";
2239 2396
2240 QuicAckFrame* ack_frame = &close_frame.ack_frame; 2397 QuicAckFrame* ack_frame = &close_frame.ack_frame;
2241 ack_frame->received_info.entropy_hash = 0x43; 2398 ack_frame->received_info.entropy_hash = 0x43;
2242 ack_frame->received_info.largest_observed = GG_UINT64_C(0x0123456789ABF); 2399 ack_frame->received_info.largest_observed = GG_UINT64_C(0x0123456789ABF);
2243 ack_frame->received_info.missing_packets.insert(GG_UINT64_C(0x0123456789ABE)); 2400 ack_frame->received_info.missing_packets.insert(GG_UINT64_C(0x0123456789ABE));
2244 ack_frame->sent_info.entropy_hash = 0xE0; 2401 ack_frame->sent_info.entropy_hash = 0xE0;
2245 ack_frame->sent_info.least_unacked = GG_UINT64_C(0x0123456789AA0); 2402 ack_frame->sent_info.least_unacked = GG_UINT64_C(0x0123456789AA0);
2246 2403
2247 QuicFrames frames; 2404 QuicFrames frames;
2248 frames.push_back(QuicFrame(&close_frame)); 2405 frames.push_back(QuicFrame(&close_frame));
2249 2406
2250 unsigned char packet[] = { 2407 unsigned char packet[] = {
2251 // public flags (8 byte guid) 2408 // public flags (8 byte guid)
2252 0x0C, 2409 0x0C,
2253 // guid 2410 // guid
2254 0x10, 0x32, 0x54, 0x76, 2411 0x10, 0x32, 0x54, 0x76,
2255 0x98, 0xBA, 0xDC, 0xFE, 2412 0x98, 0xBA, 0xDC, 0xFE,
2256 // packet sequence number 2413 // packet sequence number
2257 0xBC, 0x9A, 0x78, 0x56, 2414 0xBC, 0x9A, 0x78, 0x56,
2258 0x34, 0x12, 2415 0x34, 0x12,
2259 // private flags 2416 // private flags (entropy)
2260 0x02, 2417 0x01,
2261 // first fec protected packet offset
2262 0xFF,
2263 2418
2264 // frame type (connection close frame) 2419 // frame type (connection close frame)
2265 0x05, 2420 0x05,
2266 // error code 2421 // error code
2267 0x08, 0x07, 0x06, 0x05, 2422 0x08, 0x07, 0x06, 0x05,
2268 // error details length 2423 // error details length
2269 0x0d, 0x00, 2424 0x0d, 0x00,
2270 // error details 2425 // error details
2271 'b', 'e', 'c', 'a', 2426 'b', 'e', 'c', 'a',
2272 'u', 's', 'e', ' ', 2427 'u', 's', 'e', ' ',
(...skipping 29 matching lines...) Expand all
2302 AsChars(packet), arraysize(packet)); 2457 AsChars(packet), arraysize(packet));
2303 } 2458 }
2304 2459
2305 TEST_F(QuicFramerTest, ConstructGoAwayPacket) { 2460 TEST_F(QuicFramerTest, ConstructGoAwayPacket) {
2306 QuicPacketHeader header; 2461 QuicPacketHeader header;
2307 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); 2462 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210);
2308 header.public_header.reset_flag = false; 2463 header.public_header.reset_flag = false;
2309 header.public_header.version_flag = false; 2464 header.public_header.version_flag = false;
2310 header.fec_flag = false; 2465 header.fec_flag = false;
2311 header.entropy_flag = true; 2466 header.entropy_flag = true;
2312 header.fec_entropy_flag = false;
2313 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); 2467 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
2314 header.fec_group = 0; 2468 header.fec_group = 0;
2315 2469
2316 QuicGoAwayFrame goaway_frame; 2470 QuicGoAwayFrame goaway_frame;
2317 goaway_frame.error_code = static_cast<QuicErrorCode>(0x05060708); 2471 goaway_frame.error_code = static_cast<QuicErrorCode>(0x05060708);
2318 goaway_frame.last_good_stream_id = 0x01020304; 2472 goaway_frame.last_good_stream_id = 0x01020304;
2319 goaway_frame.reason_phrase = "because I can"; 2473 goaway_frame.reason_phrase = "because I can";
2320 2474
2321 QuicFrames frames; 2475 QuicFrames frames;
2322 frames.push_back(QuicFrame(&goaway_frame)); 2476 frames.push_back(QuicFrame(&goaway_frame));
2323 2477
2324 unsigned char packet[] = { 2478 unsigned char packet[] = {
2325 // public flags (8 byte guid) 2479 // public flags (8 byte guid)
2326 0x0C, 2480 0x0C,
2327 // guid 2481 // guid
2328 0x10, 0x32, 0x54, 0x76, 2482 0x10, 0x32, 0x54, 0x76,
2329 0x98, 0xBA, 0xDC, 0xFE, 2483 0x98, 0xBA, 0xDC, 0xFE,
2330 // packet sequence number 2484 // packet sequence number
2331 0xBC, 0x9A, 0x78, 0x56, 2485 0xBC, 0x9A, 0x78, 0x56,
2332 0x34, 0x12, 2486 0x34, 0x12,
2333 // private flags 2487 // private flags(entropy)
2334 0x02, 2488 0x01,
2335 // first fec protected packet offset
2336 0xFF,
2337 2489
2338 // frame type (go away frame) 2490 // frame type (go away frame)
2339 0x06, 2491 0x06,
2340 // error code 2492 // error code
2341 0x08, 0x07, 0x06, 0x05, 2493 0x08, 0x07, 0x06, 0x05,
2342 // stream id 2494 // stream id
2343 0x04, 0x03, 0x02, 0x01, 2495 0x04, 0x03, 0x02, 0x01,
2344 // error details length 2496 // error details length
2345 0x0d, 0x00, 2497 0x0d, 0x00,
2346 // error details 2498 // error details
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2390 AsChars(packet), arraysize(packet)); 2542 AsChars(packet), arraysize(packet));
2391 } 2543 }
2392 2544
2393 TEST_F(QuicFramerTest, ConstructFecPacket) { 2545 TEST_F(QuicFramerTest, ConstructFecPacket) {
2394 QuicPacketHeader header; 2546 QuicPacketHeader header;
2395 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); 2547 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210);
2396 header.public_header.reset_flag = false; 2548 header.public_header.reset_flag = false;
2397 header.public_header.version_flag = false; 2549 header.public_header.version_flag = false;
2398 header.fec_flag = true; 2550 header.fec_flag = true;
2399 header.entropy_flag = true; 2551 header.entropy_flag = true;
2400 header.fec_entropy_flag = false;
2401 header.packet_sequence_number = (GG_UINT64_C(0x123456789ABC)); 2552 header.packet_sequence_number = (GG_UINT64_C(0x123456789ABC));
2553 header.is_in_fec_group = IN_FEC_GROUP;
2402 header.fec_group = GG_UINT64_C(0x123456789ABB);; 2554 header.fec_group = GG_UINT64_C(0x123456789ABB);;
2403 2555
2404 QuicFecData fec_data; 2556 QuicFecData fec_data;
2405 fec_data.fec_group = 1; 2557 fec_data.fec_group = 1;
2406 fec_data.redundancy = "abcdefghijklmnop"; 2558 fec_data.redundancy = "abcdefghijklmnop";
2407 2559
2408 unsigned char packet[] = { 2560 unsigned char packet[] = {
2409 // public flags (8 byte guid) 2561 // public flags (8 byte guid)
2410 0x0C, 2562 0x0C,
2411 // guid 2563 // guid
2412 0x10, 0x32, 0x54, 0x76, 2564 0x10, 0x32, 0x54, 0x76,
2413 0x98, 0xBA, 0xDC, 0xFE, 2565 0x98, 0xBA, 0xDC, 0xFE,
2414 // packet sequence number 2566 // packet sequence number
2415 0xBC, 0x9A, 0x78, 0x56, 2567 0xBC, 0x9A, 0x78, 0x56,
2416 0x34, 0x12, 2568 0x34, 0x12,
2417 // private flags 2569 // private flags (entropy & fec group & fec packet)
2418 0x03, 2570 0x07,
2419 // first fec protected packet offset 2571 // first fec protected packet offset
2420 0x01, 2572 0x01,
2421 2573
2422 // redundancy 2574 // redundancy
2423 'a', 'b', 'c', 'd', 2575 'a', 'b', 'c', 'd',
2424 'e', 'f', 'g', 'h', 2576 'e', 'f', 'g', 'h',
2425 'i', 'j', 'k', 'l', 2577 'i', 'j', 'k', 'l',
2426 'm', 'n', 'o', 'p', 2578 'm', 'n', 'o', 'p',
2427 }; 2579 };
2428 2580
(...skipping 10 matching lines...) Expand all
2439 QuicPacketSequenceNumber sequence_number = GG_UINT64_C(0x123456789ABC); 2591 QuicPacketSequenceNumber sequence_number = GG_UINT64_C(0x123456789ABC);
2440 unsigned char packet[] = { 2592 unsigned char packet[] = {
2441 // public flags (8 byte guid) 2593 // public flags (8 byte guid)
2442 0x0C, 2594 0x0C,
2443 // guid 2595 // guid
2444 0x10, 0x32, 0x54, 0x76, 2596 0x10, 0x32, 0x54, 0x76,
2445 0x98, 0xBA, 0xDC, 0xFE, 2597 0x98, 0xBA, 0xDC, 0xFE,
2446 // packet sequence number 2598 // packet sequence number
2447 0xBC, 0x9A, 0x78, 0x56, 2599 0xBC, 0x9A, 0x78, 0x56,
2448 0x34, 0x12, 2600 0x34, 0x12,
2449 // private flags 2601 // private flags (fec group & fec packet)
2450 0x01, 2602 0x06,
2451 // first fec protected packet offset 2603 // first fec protected packet offset
2452 0x01, 2604 0x01,
2453 2605
2454 // redundancy 2606 // redundancy
2455 'a', 'b', 'c', 'd', 2607 'a', 'b', 'c', 'd',
2456 'e', 'f', 'g', 'h', 2608 'e', 'f', 'g', 'h',
2457 'i', 'j', 'k', 'l', 2609 'i', 'j', 'k', 'l',
2458 'm', 'n', 'o', 'p', 2610 'm', 'n', 'o', 'p',
2459 }; 2611 };
2460 2612
2461 scoped_ptr<QuicPacket> raw( 2613 scoped_ptr<QuicPacket> raw(
2462 QuicPacket::NewDataPacket(AsChars(packet), arraysize(packet), false, 2614 QuicPacket::NewDataPacket(AsChars(packet), arraysize(packet), false,
2463 !kIncludeVersion)); 2615 PACKET_8BYTE_GUID, !kIncludeVersion));
2464 scoped_ptr<QuicEncryptedPacket> encrypted( 2616 scoped_ptr<QuicEncryptedPacket> encrypted(
2465 framer_.EncryptPacket(ENCRYPTION_NONE, sequence_number, *raw)); 2617 framer_.EncryptPacket(ENCRYPTION_NONE, sequence_number, *raw));
2466 2618
2467 ASSERT_TRUE(encrypted.get() != NULL); 2619 ASSERT_TRUE(encrypted.get() != NULL);
2468 EXPECT_TRUE(CheckEncryption(sequence_number, raw.get())); 2620 EXPECT_TRUE(CheckEncryption(sequence_number, raw.get()));
2469 } 2621 }
2470 2622
2471 TEST_F(QuicFramerTest, EncryptPacketWithVersionFlag) { 2623 TEST_F(QuicFramerTest, EncryptPacketWithVersionFlag) {
2472 QuicPacketSequenceNumber sequence_number = GG_UINT64_C(0x123456789ABC); 2624 QuicPacketSequenceNumber sequence_number = GG_UINT64_C(0x123456789ABC);
2473 unsigned char packet[] = { 2625 unsigned char packet[] = {
2474 // public flags (version, 8 byte guid) 2626 // public flags (version, 8 byte guid)
2475 0x0D, 2627 0x0D,
2476 // guid 2628 // guid
2477 0x10, 0x32, 0x54, 0x76, 2629 0x10, 0x32, 0x54, 0x76,
2478 0x98, 0xBA, 0xDC, 0xFE, 2630 0x98, 0xBA, 0xDC, 0xFE,
2479 // version tag 2631 // version tag
2480 'Q', '.', '1', '0', 2632 'Q', '.', '1', '0',
2481 // packet sequence number 2633 // packet sequence number
2482 0xBC, 0x9A, 0x78, 0x56, 2634 0xBC, 0x9A, 0x78, 0x56,
2483 0x34, 0x12, 2635 0x34, 0x12,
2484 // private flags 2636 // private flags (fec group & fec flags)
2485 0x01, 2637 0x06,
2486 // first fec protected packet offset 2638 // first fec protected packet offset
2487 0x01, 2639 0x01,
2488 2640
2489 // redundancy 2641 // redundancy
2490 'a', 'b', 'c', 'd', 2642 'a', 'b', 'c', 'd',
2491 'e', 'f', 'g', 'h', 2643 'e', 'f', 'g', 'h',
2492 'i', 'j', 'k', 'l', 2644 'i', 'j', 'k', 'l',
2493 'm', 'n', 'o', 'p', 2645 'm', 'n', 'o', 'p',
2494 }; 2646 };
2495 2647
2496 scoped_ptr<QuicPacket> raw( 2648 scoped_ptr<QuicPacket> raw(
2497 QuicPacket::NewDataPacket(AsChars(packet), arraysize(packet), false, 2649 QuicPacket::NewDataPacket(AsChars(packet), arraysize(packet), false,
2498 kIncludeVersion)); 2650 PACKET_8BYTE_GUID, kIncludeVersion));
2499 scoped_ptr<QuicEncryptedPacket> encrypted( 2651 scoped_ptr<QuicEncryptedPacket> encrypted(
2500 framer_.EncryptPacket(ENCRYPTION_NONE, sequence_number, *raw)); 2652 framer_.EncryptPacket(ENCRYPTION_NONE, sequence_number, *raw));
2501 2653
2502 ASSERT_TRUE(encrypted.get() != NULL); 2654 ASSERT_TRUE(encrypted.get() != NULL);
2503 EXPECT_TRUE(CheckEncryption(sequence_number, raw.get())); 2655 EXPECT_TRUE(CheckEncryption(sequence_number, raw.get()));
2504 } 2656 }
2505 2657
2506 // TODO(rch): re-enable after https://codereview.chromium.org/11820005/ 2658 // TODO(rch): re-enable after https://codereview.chromium.org/11820005/
2507 // lands. Currently this is causing valgrind problems, but it should be 2659 // lands. Currently this is causing valgrind problems, but it should be
2508 // fixed in the followup CL. 2660 // fixed in the followup CL.
(...skipping 16 matching lines...) Expand all
2525 } 2677 }
2526 2678
2527 // TODO(rch) enable after landing the revised truncation CL. 2679 // TODO(rch) enable after landing the revised truncation CL.
2528 TEST_F(QuicFramerTest, DISABLED_Truncation) { 2680 TEST_F(QuicFramerTest, DISABLED_Truncation) {
2529 QuicPacketHeader header; 2681 QuicPacketHeader header;
2530 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); 2682 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210);
2531 header.public_header.reset_flag = false; 2683 header.public_header.reset_flag = false;
2532 header.public_header.version_flag = false; 2684 header.public_header.version_flag = false;
2533 header.fec_flag = false; 2685 header.fec_flag = false;
2534 header.entropy_flag = false; 2686 header.entropy_flag = false;
2535 header.fec_entropy_flag = false;
2536 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); 2687 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
2537 header.fec_group = 0; 2688 header.fec_group = 0;
2538 2689
2539 QuicConnectionCloseFrame close_frame; 2690 QuicConnectionCloseFrame close_frame;
2540 QuicAckFrame* ack_frame = &close_frame.ack_frame; 2691 QuicAckFrame* ack_frame = &close_frame.ack_frame;
2541 close_frame.error_code = static_cast<QuicErrorCode>(0x05); 2692 close_frame.error_code = static_cast<QuicErrorCode>(0x05);
2542 close_frame.error_details = "because I can"; 2693 close_frame.error_details = "because I can";
2543 ack_frame->received_info.largest_observed = 201; 2694 ack_frame->received_info.largest_observed = 201;
2544 ack_frame->sent_info.least_unacked = 0; 2695 ack_frame->sent_info.least_unacked = 0;
2545 for (uint64 i = 1; i < ack_frame->received_info.largest_observed; ++i) { 2696 for (uint64 i = 1; i < ack_frame->received_info.largest_observed; ++i) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2582 ASSERT_TRUE(framer_.ProcessPacket(*close_packet)); 2733 ASSERT_TRUE(framer_.ProcessPacket(*close_packet));
2583 } 2734 }
2584 2735
2585 TEST_F(QuicFramerTest, CleanTruncation) { 2736 TEST_F(QuicFramerTest, CleanTruncation) {
2586 QuicPacketHeader header; 2737 QuicPacketHeader header;
2587 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); 2738 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210);
2588 header.public_header.reset_flag = false; 2739 header.public_header.reset_flag = false;
2589 header.public_header.version_flag = false; 2740 header.public_header.version_flag = false;
2590 header.fec_flag = false; 2741 header.fec_flag = false;
2591 header.entropy_flag = true; 2742 header.entropy_flag = true;
2592 header.fec_entropy_flag = false;
2593 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); 2743 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
2594 header.fec_group = 0; 2744 header.fec_group = 0;
2595 2745
2596 QuicConnectionCloseFrame close_frame; 2746 QuicConnectionCloseFrame close_frame;
2597 QuicAckFrame* ack_frame = &close_frame.ack_frame; 2747 QuicAckFrame* ack_frame = &close_frame.ack_frame;
2598 close_frame.error_code = static_cast<QuicErrorCode>(0x05); 2748 close_frame.error_code = static_cast<QuicErrorCode>(0x05);
2599 close_frame.error_details = "because I can"; 2749 close_frame.error_details = "because I can";
2600 ack_frame->received_info.largest_observed = 201; 2750 ack_frame->received_info.largest_observed = 201;
2601 ack_frame->sent_info.least_unacked = 0; 2751 ack_frame->sent_info.least_unacked = 0;
2602 for (uint64 i = 1; i < ack_frame->received_info.largest_observed; ++i) { 2752 for (uint64 i = 1; i < ack_frame->received_info.largest_observed; ++i) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
2666 TEST_F(QuicFramerTest, EntropyFlagTest) { 2816 TEST_F(QuicFramerTest, EntropyFlagTest) {
2667 unsigned char packet[] = { 2817 unsigned char packet[] = {
2668 // public flags (8 byte guid) 2818 // public flags (8 byte guid)
2669 0x0C, 2819 0x0C,
2670 // guid 2820 // guid
2671 0x10, 0x32, 0x54, 0x76, 2821 0x10, 0x32, 0x54, 0x76,
2672 0x98, 0xBA, 0xDC, 0xFE, 2822 0x98, 0xBA, 0xDC, 0xFE,
2673 // packet sequence number 2823 // packet sequence number
2674 0xBC, 0x9A, 0x78, 0x56, 2824 0xBC, 0x9A, 0x78, 0x56,
2675 0x34, 0x12, 2825 0x34, 0x12,
2676 // Entropy 2826 // private flags (Entropy)
2677 0x02, 2827 0x01,
2678 // first fec protected packet offset
2679 0xFF,
2680 2828
2681 // frame type (stream frame) 2829 // frame type (stream frame)
2682 0x01, 2830 0x01,
2683 // stream id 2831 // stream id
2684 0x04, 0x03, 0x02, 0x01, 2832 0x04, 0x03, 0x02, 0x01,
2685 // fin 2833 // fin
2686 0x01, 2834 0x01,
2687 // offset 2835 // offset
2688 0x54, 0x76, 0x10, 0x32, 2836 0x54, 0x76, 0x10, 0x32,
2689 0xDC, 0xFE, 0x98, 0xBA, 2837 0xDC, 0xFE, 0x98, 0xBA,
2690 // data length 2838 // data length
2691 0x0c, 0x00, 2839 0x0c, 0x00,
2692 // data 2840 // data
2693 'h', 'e', 'l', 'l', 2841 'h', 'e', 'l', 'l',
2694 'o', ' ', 'w', 'o', 2842 'o', ' ', 'w', 'o',
2695 'r', 'l', 'd', '!', 2843 'r', 'l', 'd', '!',
2696 }; 2844 };
2697 2845
2698 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 2846 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2699 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2847 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2700 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2848 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2701 ASSERT_TRUE(visitor_.header_.get()); 2849 ASSERT_TRUE(visitor_.header_.get());
2702 EXPECT_TRUE(visitor_.header_->entropy_flag); 2850 EXPECT_TRUE(visitor_.header_->entropy_flag);
2703 EXPECT_EQ(1 << 4, visitor_.header_->entropy_hash); 2851 EXPECT_EQ(1 << 4, visitor_.header_->entropy_hash);
2704 EXPECT_FALSE(visitor_.header_->fec_flag); 2852 EXPECT_FALSE(visitor_.header_->fec_flag);
2705 }; 2853 };
2706 2854
2707 TEST_F(QuicFramerTest, FecEntropyFlagTest) { 2855 TEST_F(QuicFramerTest, FecEntropyTest) {
2708 unsigned char packet[] = { 2856 unsigned char packet[] = {
2709 // public flags (8 byte guid) 2857 // public flags (8 byte guid)
2710 0x0C, 2858 0x0C,
2711 // guid 2859 // guid
2712 0x10, 0x32, 0x54, 0x76, 2860 0x10, 0x32, 0x54, 0x76,
2713 0x98, 0xBA, 0xDC, 0xFE, 2861 0x98, 0xBA, 0xDC, 0xFE,
2714 // packet sequence number 2862 // packet sequence number
2715 0xBC, 0x9A, 0x78, 0x56, 2863 0xBC, 0x9A, 0x78, 0x56,
2716 0x34, 0x12, 2864 0x34, 0x12,
2717 // Flags: Entropy, FEC-Entropy, FEC 2865 // private flags (Entropy & fec group & FEC)
2718 0x07, 2866 0x07,
2719 // first fec protected packet offset 2867 // first fec protected packet offset
2720 0xFF, 2868 0xFF,
2721 2869
2722 // frame type (stream frame) 2870 // frame type (stream frame)
2723 0x01, 2871 0x01,
2724 // stream id 2872 // stream id
2725 0x04, 0x03, 0x02, 0x01, 2873 0x04, 0x03, 0x02, 0x01,
2726 // fin 2874 // fin
2727 0x01, 2875 0x01,
2728 // offset 2876 // offset
2729 0x54, 0x76, 0x10, 0x32, 2877 0x54, 0x76, 0x10, 0x32,
2730 0xDC, 0xFE, 0x98, 0xBA, 2878 0xDC, 0xFE, 0x98, 0xBA,
2731 // data length 2879 // data length
2732 0x0c, 0x00, 2880 0x0c, 0x00,
2733 // data 2881 // data
2734 'h', 'e', 'l', 'l', 2882 'h', 'e', 'l', 'l',
2735 'o', ' ', 'w', 'o', 2883 'o', ' ', 'w', 'o',
2736 'r', 'l', 'd', '!', 2884 'r', 'l', 'd', '!',
2737 }; 2885 };
2738 2886
2739 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 2887 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2740 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2888 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2741 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2889 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2742 ASSERT_TRUE(visitor_.header_.get()); 2890 ASSERT_TRUE(visitor_.header_.get());
2743 EXPECT_TRUE(visitor_.header_->fec_flag); 2891 EXPECT_TRUE(visitor_.header_->fec_flag);
2744 EXPECT_TRUE(visitor_.header_->entropy_flag); 2892 EXPECT_TRUE(visitor_.header_->entropy_flag);
2745 EXPECT_TRUE(visitor_.header_->fec_entropy_flag);
2746 EXPECT_EQ(1 << 4, visitor_.header_->entropy_hash); 2893 EXPECT_EQ(1 << 4, visitor_.header_->entropy_hash);
2747 }; 2894 };
2748 2895
2749 TEST_F(QuicFramerTest, StopPacketProcessing) { 2896 TEST_F(QuicFramerTest, StopPacketProcessing) {
2750 unsigned char packet[] = { 2897 unsigned char packet[] = {
2751 // public flags (8 byte guid) 2898 // public flags (8 byte guid)
2752 0x0C, 2899 0x0C,
2753 // guid 2900 // guid
2754 0x10, 0x32, 0x54, 0x76, 2901 0x10, 0x32, 0x54, 0x76,
2755 0x98, 0xBA, 0xDC, 0xFE, 2902 0x98, 0xBA, 0xDC, 0xFE,
2756 // packet sequence number 2903 // packet sequence number
2757 0xBC, 0x9A, 0x78, 0x56, 2904 0xBC, 0x9A, 0x78, 0x56,
2758 0x34, 0x12, 2905 0x34, 0x12,
2759 // Entropy 2906 // Entropy
2760 0x02, 2907 0x01,
2761 // first fec protected packet offset
2762 0xFF,
2763 2908
2764 // frame type (stream frame) 2909 // frame type (stream frame)
2765 0x01, 2910 0x01,
2766 // stream id 2911 // stream id
2767 0x04, 0x03, 0x02, 0x01, 2912 0x04, 0x03, 0x02, 0x01,
2768 // fin 2913 // fin
2769 0x01, 2914 0x01,
2770 // offset 2915 // offset
2771 0x54, 0x76, 0x10, 0x32, 2916 0x54, 0x76, 0x10, 0x32,
2772 0xDC, 0xFE, 0x98, 0xBA, 2917 0xDC, 0xFE, 0x98, 0xBA,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2814 // public flags (8 byte guid) 2959 // public flags (8 byte guid)
2815 0x0C, 2960 0x0C,
2816 // guid 2961 // guid
2817 0x10, 0x32, 0x54, 0x76, 2962 0x10, 0x32, 0x54, 0x76,
2818 0x98, 0xBA, 0xDC, 0xFE, 2963 0x98, 0xBA, 0xDC, 0xFE,
2819 // packet sequence number 2964 // packet sequence number
2820 0xBC, 0x9A, 0x78, 0x56, 2965 0xBC, 0x9A, 0x78, 0x56,
2821 0x34, 0x12, 2966 0x34, 0x12,
2822 // private flags 2967 // private flags
2823 0x00, 2968 0x00,
2824 // first fec protected packet offset
2825 0xFF,
2826 2969
2827 // frame type (connection close frame) 2970 // frame type (connection close frame)
2828 0x05, 2971 0x05,
2829 // error code 2972 // error code
2830 0x11, 0x00, 0x00, 0x00, 2973 0x11, 0x00, 0x00, 0x00,
2831 // error details length 2974 // error details length
2832 0x0d, 0x00, 2975 0x0d, 0x00,
2833 // error details 2976 // error details
2834 'b', 'e', 'c', 'a', 2977 'b', 'e', 'c', 'a',
2835 'u', 's', 'e', ' ', 2978 'u', 's', 'e', ' ',
(...skipping 28 matching lines...) Expand all
2864 EXPECT_CALL(visitor, OnConnectionCloseFrame(_)).Times(0); 3007 EXPECT_CALL(visitor, OnConnectionCloseFrame(_)).Times(0);
2865 EXPECT_CALL(visitor, OnPacketComplete()); 3008 EXPECT_CALL(visitor, OnPacketComplete());
2866 3009
2867 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 3010 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2868 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 3011 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2869 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 3012 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2870 } 3013 }
2871 3014
2872 } // namespace test 3015 } // namespace test
2873 } // namespace net 3016 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698