| OLD | NEW |
| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 static void SetLastSequenceNumber( | 42 static void SetLastSequenceNumber( |
| 43 QuicFramer* framer, | 43 QuicFramer* framer, |
| 44 QuicPacketSequenceNumber packet_sequence_number) { | 44 QuicPacketSequenceNumber packet_sequence_number) { |
| 45 framer->last_sequence_number_ = packet_sequence_number; | 45 framer->last_sequence_number_ = packet_sequence_number; |
| 46 } | 46 } |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 class TestEncrypter : public QuicEncrypter { | 49 class TestEncrypter : public QuicEncrypter { |
| 50 public: | 50 public: |
| 51 virtual ~TestEncrypter() {} | 51 virtual ~TestEncrypter() {} |
| 52 virtual QuicData* Encrypt(StringPiece associated_data, | 52 virtual bool SetKey(StringPiece key) OVERRIDE { |
| 53 StringPiece plaintext) OVERRIDE { | 53 return true; |
| 54 } |
| 55 virtual bool SetNoncePrefix(StringPiece nonce_prefix) OVERRIDE { |
| 56 return true; |
| 57 } |
| 58 virtual QuicData* Encrypt(QuicPacketSequenceNumber sequence_number, |
| 59 StringPiece associated_data, |
| 60 StringPiece plaintext) OVERRIDE{ |
| 61 sequence_number_ = sequence_number; |
| 54 associated_data_ = associated_data.as_string(); | 62 associated_data_ = associated_data.as_string(); |
| 55 plaintext_ = plaintext.as_string(); | 63 plaintext_ = plaintext.as_string(); |
| 56 return new QuicData(plaintext.data(), plaintext.length()); | 64 return new QuicData(plaintext.data(), plaintext.length()); |
| 57 } | 65 } |
| 58 virtual size_t GetMaxPlaintextSize(size_t ciphertext_size) OVERRIDE { | 66 virtual size_t GetKeySize() const OVERRIDE { |
| 67 return 0; |
| 68 } |
| 69 virtual size_t GetNoncePrefixSize() const OVERRIDE{ |
| 70 return 0; |
| 71 } |
| 72 virtual size_t GetMaxPlaintextSize(size_t ciphertext_size) const OVERRIDE { |
| 59 return ciphertext_size; | 73 return ciphertext_size; |
| 60 } | 74 } |
| 61 virtual size_t GetCiphertextSize(size_t plaintext_size) OVERRIDE { | 75 virtual size_t GetCiphertextSize(size_t plaintext_size) const OVERRIDE { |
| 62 return plaintext_size; | 76 return plaintext_size; |
| 63 } | 77 } |
| 78 QuicPacketSequenceNumber sequence_number_; |
| 64 string associated_data_; | 79 string associated_data_; |
| 65 string plaintext_; | 80 string plaintext_; |
| 66 }; | 81 }; |
| 67 | 82 |
| 68 class TestDecrypter : public QuicDecrypter { | 83 class TestDecrypter : public QuicDecrypter { |
| 69 public: | 84 public: |
| 70 virtual ~TestDecrypter() {} | 85 virtual ~TestDecrypter() {} |
| 71 virtual QuicData* Decrypt(StringPiece associated_data, | 86 virtual bool SetKey(StringPiece key) OVERRIDE { |
| 72 StringPiece ciphertext) OVERRIDE { | 87 return true; |
| 88 } |
| 89 virtual bool SetNoncePrefix(StringPiece nonce_prefix) OVERRIDE { |
| 90 return true; |
| 91 } |
| 92 virtual QuicData* Decrypt(QuicPacketSequenceNumber sequence_number, |
| 93 StringPiece associated_data, |
| 94 StringPiece ciphertext) OVERRIDE{ |
| 95 sequence_number_ = sequence_number; |
| 73 associated_data_ = associated_data.as_string(); | 96 associated_data_ = associated_data.as_string(); |
| 74 ciphertext_ = ciphertext.as_string(); | 97 ciphertext_ = ciphertext.as_string(); |
| 75 return new QuicData(ciphertext.data(), ciphertext.length()); | 98 return new QuicData(ciphertext.data(), ciphertext.length()); |
| 76 } | 99 } |
| 100 QuicPacketSequenceNumber sequence_number_; |
| 77 string associated_data_; | 101 string associated_data_; |
| 78 string ciphertext_; | 102 string ciphertext_; |
| 79 }; | 103 }; |
| 80 | 104 |
| 81 class TestQuicVisitor : public ::net::QuicFramerVisitorInterface { | 105 class TestQuicVisitor : public ::net::QuicFramerVisitorInterface { |
| 82 public: | 106 public: |
| 83 TestQuicVisitor() | 107 TestQuicVisitor() |
| 84 : error_count_(0), | 108 : error_count_(0), |
| 85 packet_count_(0), | 109 packet_count_(0), |
| 86 frame_count_(0), | 110 frame_count_(0), |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 | 176 |
| 153 virtual void OnRstStreamFrame(const QuicRstStreamFrame& frame) OVERRIDE { | 177 virtual void OnRstStreamFrame(const QuicRstStreamFrame& frame) OVERRIDE { |
| 154 rst_stream_frame_ = frame; | 178 rst_stream_frame_ = frame; |
| 155 } | 179 } |
| 156 | 180 |
| 157 virtual void OnConnectionCloseFrame( | 181 virtual void OnConnectionCloseFrame( |
| 158 const QuicConnectionCloseFrame& frame) OVERRIDE { | 182 const QuicConnectionCloseFrame& frame) OVERRIDE { |
| 159 connection_close_frame_ = frame; | 183 connection_close_frame_ = frame; |
| 160 } | 184 } |
| 161 | 185 |
| 186 virtual void OnGoAwayFrame(const QuicGoAwayFrame& frame) { |
| 187 goaway_frame_ = frame; |
| 188 } |
| 189 |
| 162 // Counters from the visitor_ callbacks. | 190 // Counters from the visitor_ callbacks. |
| 163 int error_count_; | 191 int error_count_; |
| 164 int packet_count_; | 192 int packet_count_; |
| 165 int frame_count_; | 193 int frame_count_; |
| 166 int fec_count_; | 194 int fec_count_; |
| 167 int complete_packets_; | 195 int complete_packets_; |
| 168 int revived_packets_; | 196 int revived_packets_; |
| 169 bool accept_packet_; | 197 bool accept_packet_; |
| 170 | 198 |
| 171 scoped_ptr<QuicPacketHeader> header_; | 199 scoped_ptr<QuicPacketHeader> header_; |
| 172 scoped_ptr<QuicPublicResetPacket> public_reset_packet_; | 200 scoped_ptr<QuicPublicResetPacket> public_reset_packet_; |
| 173 vector<QuicStreamFrame*> stream_frames_; | 201 vector<QuicStreamFrame*> stream_frames_; |
| 174 vector<QuicAckFrame*> ack_frames_; | 202 vector<QuicAckFrame*> ack_frames_; |
| 175 vector<QuicCongestionFeedbackFrame*> congestion_feedback_frames_; | 203 vector<QuicCongestionFeedbackFrame*> congestion_feedback_frames_; |
| 176 vector<QuicFecData*> fec_data_; | 204 vector<QuicFecData*> fec_data_; |
| 177 string fec_protected_payload_; | 205 string fec_protected_payload_; |
| 178 QuicRstStreamFrame rst_stream_frame_; | 206 QuicRstStreamFrame rst_stream_frame_; |
| 179 QuicConnectionCloseFrame connection_close_frame_; | 207 QuicConnectionCloseFrame connection_close_frame_; |
| 208 QuicGoAwayFrame goaway_frame_; |
| 180 }; | 209 }; |
| 181 | 210 |
| 182 class QuicFramerTest : public ::testing::Test { | 211 class QuicFramerTest : public ::testing::Test { |
| 183 public: | 212 public: |
| 184 QuicFramerTest() | 213 QuicFramerTest() |
| 185 : encrypter_(new test::TestEncrypter()), | 214 : encrypter_(new test::TestEncrypter()), |
| 186 decrypter_(new test::TestDecrypter()), | 215 decrypter_(new test::TestDecrypter()), |
| 187 framer_(decrypter_, encrypter_) { | 216 framer_(decrypter_, encrypter_) { |
| 188 framer_.set_visitor(&visitor_); | 217 framer_.set_visitor(&visitor_); |
| 218 framer_.set_entropy_calculator(&entropy_calculator_); |
| 189 } | 219 } |
| 190 | 220 |
| 191 bool CheckEncryption(StringPiece packet) { | 221 bool CheckEncryption(QuicPacketSequenceNumber sequence_number, |
| 222 StringPiece packet) { |
| 223 if (sequence_number != encrypter_->sequence_number_) { |
| 224 LOG(ERROR) << "Encrypted incorrect packet sequence number. expected " |
| 225 << sequence_number << " actual: " |
| 226 << encrypter_->sequence_number_; |
| 227 return false; |
| 228 } |
| 192 StringPiece associated_data( | 229 StringPiece associated_data( |
| 193 packet.substr(kStartOfHashData, | 230 packet.substr(kStartOfHashData, |
| 194 kStartOfEncryptedData - kStartOfHashData)); | 231 kStartOfEncryptedData - kStartOfHashData)); |
| 195 if (associated_data != encrypter_->associated_data_) { | 232 if (associated_data != encrypter_->associated_data_) { |
| 196 LOG(ERROR) << "Encrypted incorrect associated data. expected " | 233 LOG(ERROR) << "Encrypted incorrect associated data. expected " |
| 197 << associated_data << " actual: " | 234 << associated_data << " actual: " |
| 198 << encrypter_->associated_data_; | 235 << encrypter_->associated_data_; |
| 199 return false; | 236 return false; |
| 200 } | 237 } |
| 201 StringPiece plaintext(packet.substr(kStartOfEncryptedData)); | 238 StringPiece plaintext(packet.substr(kStartOfEncryptedData)); |
| 202 if (plaintext != encrypter_->plaintext_) { | 239 if (plaintext != encrypter_->plaintext_) { |
| 203 LOG(ERROR) << "Encrypted incorrect plaintext data. expected " | 240 LOG(ERROR) << "Encrypted incorrect plaintext data. expected " |
| 204 << plaintext << " actual: " | 241 << plaintext << " actual: " |
| 205 << encrypter_->plaintext_; | 242 << encrypter_->plaintext_; |
| 206 return false; | 243 return false; |
| 207 } | 244 } |
| 208 return true; | 245 return true; |
| 209 } | 246 } |
| 210 | 247 |
| 211 bool CheckDecryption(StringPiece packet) { | 248 bool CheckDecryption(StringPiece packet) { |
| 249 if (visitor_.header_->packet_sequence_number != |
| 250 decrypter_->sequence_number_) { |
| 251 LOG(ERROR) << "Decrypted incorrect packet sequence number. expected " |
| 252 << visitor_.header_->packet_sequence_number << " actual: " |
| 253 << decrypter_->sequence_number_; |
| 254 return false; |
| 255 } |
| 212 StringPiece associated_data( | 256 StringPiece associated_data( |
| 213 packet.substr(kStartOfHashData, | 257 packet.substr(kStartOfHashData, |
| 214 kStartOfEncryptedData - kStartOfHashData)); | 258 kStartOfEncryptedData - kStartOfHashData)); |
| 215 if (associated_data != decrypter_->associated_data_) { | 259 if (associated_data != decrypter_->associated_data_) { |
| 216 LOG(ERROR) << "Decrypted incorrect associated data. expected " | 260 LOG(ERROR) << "Decrypted incorrect associated data. expected " |
| 217 << associated_data << " actual: " | 261 << associated_data << " actual: " |
| 218 << decrypter_->associated_data_; | 262 << decrypter_->associated_data_; |
| 219 return false; | 263 return false; |
| 220 } | 264 } |
| 221 StringPiece plaintext(packet.substr(kStartOfEncryptedData)); | 265 StringPiece ciphertext(packet.substr(kStartOfEncryptedData)); |
| 222 if (plaintext != decrypter_->ciphertext_) { | 266 if (ciphertext != decrypter_->ciphertext_) { |
| 223 LOG(ERROR) << "Decrypted incorrect chipertext data. expected " | 267 LOG(ERROR) << "Decrypted incorrect chipertext data. expected " |
| 224 << plaintext << " actual: " | 268 << ciphertext << " actual: " |
| 225 << decrypter_->ciphertext_; | 269 << decrypter_->ciphertext_; |
| 226 return false; | 270 return false; |
| 227 } | 271 } |
| 228 return true; | 272 return true; |
| 229 } | 273 } |
| 230 | 274 |
| 231 char* AsChars(unsigned char* data) { | 275 char* AsChars(unsigned char* data) { |
| 232 return reinterpret_cast<char*>(data); | 276 return reinterpret_cast<char*>(data); |
| 233 } | 277 } |
| 234 | 278 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 259 QuicFramerPeer::CalculatePacketSequenceNumberFromWire( | 303 QuicFramerPeer::CalculatePacketSequenceNumberFromWire( |
| 260 &framer_, wire_sequence_number)) | 304 &framer_, wire_sequence_number)) |
| 261 << "last_sequence_number: " << last_sequence_number | 305 << "last_sequence_number: " << last_sequence_number |
| 262 << "wire_sequence_number: " << wire_sequence_number; | 306 << "wire_sequence_number: " << wire_sequence_number; |
| 263 } | 307 } |
| 264 | 308 |
| 265 test::TestEncrypter* encrypter_; | 309 test::TestEncrypter* encrypter_; |
| 266 test::TestDecrypter* decrypter_; | 310 test::TestDecrypter* decrypter_; |
| 267 QuicFramer framer_; | 311 QuicFramer framer_; |
| 268 test::TestQuicVisitor visitor_; | 312 test::TestQuicVisitor visitor_; |
| 313 test::TestEntropyCalculator entropy_calculator_; |
| 269 }; | 314 }; |
| 270 | 315 |
| 271 TEST_F(QuicFramerTest, CalculatePacketSequenceNumberFromWireNearEpochStart) { | 316 TEST_F(QuicFramerTest, CalculatePacketSequenceNumberFromWireNearEpochStart) { |
| 272 // A few quick manual sanity checks | 317 // A few quick manual sanity checks |
| 273 CheckCalculatePacketSequenceNumber(GG_UINT64_C(1), GG_UINT64_C(0)); | 318 CheckCalculatePacketSequenceNumber(GG_UINT64_C(1), GG_UINT64_C(0)); |
| 274 CheckCalculatePacketSequenceNumber(kEpoch + 1, kMask); | 319 CheckCalculatePacketSequenceNumber(kEpoch + 1, kMask); |
| 275 CheckCalculatePacketSequenceNumber(kEpoch, kMask); | 320 CheckCalculatePacketSequenceNumber(kEpoch, kMask); |
| 276 | 321 |
| 277 // Cases where the last number was close to the start of the range | 322 // Cases where the last number was close to the start of the range |
| 278 for (uint64 last = 0; last < 10; last++) { | 323 for (uint64 last = 0; last < 10; last++) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 | 385 |
| 341 // but large numbers should not (even if they're out of order). | 386 // but large numbers should not (even if they're out of order). |
| 342 for (uint64 j = 0; j < 10; j++) { | 387 for (uint64 j = 0; j < 10; j++) { |
| 343 uint64 num = kEpoch - 1 - j; | 388 uint64 num = kEpoch - 1 - j; |
| 344 CheckCalculatePacketSequenceNumber(cur_epoch + num, last); | 389 CheckCalculatePacketSequenceNumber(cur_epoch + num, last); |
| 345 } | 390 } |
| 346 } | 391 } |
| 347 } | 392 } |
| 348 | 393 |
| 349 TEST_F(QuicFramerTest, CalculatePacketSequenceNumberFromWireNearNextMax) { | 394 TEST_F(QuicFramerTest, CalculatePacketSequenceNumberFromWireNearNextMax) { |
| 350 const uint64 max_number = std::numeric_limits<uint64>::max(); | 395 const uint64 max_number = numeric_limits<uint64>::max(); |
| 351 const uint64 max_epoch = max_number & ~kMask; | 396 const uint64 max_epoch = max_number & ~kMask; |
| 352 | 397 |
| 353 // Cases where the last number was close to the end of the range | 398 // Cases where the last number was close to the end of the range |
| 354 for (uint64 i = 0; i < 10; i++) { | 399 for (uint64 i = 0; i < 10; i++) { |
| 355 QuicPacketSequenceNumber last = max_number - i; | 400 QuicPacketSequenceNumber last = max_number - i; |
| 356 | 401 |
| 357 // Small numbers should not wrap (because they have nowhere to go. | 402 // Small numbers should not wrap (because they have nowhere to go. |
| 358 for (uint64 j = 0; j < 10; j++) { | 403 for (uint64 j = 0; j < 10; j++) { |
| 359 CheckCalculatePacketSequenceNumber(max_epoch + j, last); | 404 CheckCalculatePacketSequenceNumber(max_epoch + j, last); |
| 360 } | 405 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 // first fec protected packet offset | 463 // first fec protected packet offset |
| 419 0xFF, | 464 0xFF, |
| 420 }; | 465 }; |
| 421 | 466 |
| 422 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 467 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
| 423 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); | 468 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 424 EXPECT_EQ(QUIC_INVALID_FRAME_DATA, framer_.error()); | 469 EXPECT_EQ(QUIC_INVALID_FRAME_DATA, framer_.error()); |
| 425 ASSERT_TRUE(visitor_.header_.get()); | 470 ASSERT_TRUE(visitor_.header_.get()); |
| 426 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210), | 471 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210), |
| 427 visitor_.header_->public_header.guid); | 472 visitor_.header_->public_header.guid); |
| 428 EXPECT_EQ(0x00, visitor_.header_->public_header.flags); | 473 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); |
| 429 EXPECT_EQ(0x00, visitor_.header_->private_flags); | 474 EXPECT_FALSE(visitor_.header_->public_header.version_flag); |
| 475 EXPECT_FALSE(visitor_.header_->fec_flag); |
| 476 EXPECT_FALSE(visitor_.header_->entropy_flag); |
| 477 EXPECT_FALSE(visitor_.header_->fec_entropy_flag); |
| 478 EXPECT_EQ(0, visitor_.header_->entropy_hash); |
| 430 EXPECT_EQ(GG_UINT64_C(0x123456789ABC), | 479 EXPECT_EQ(GG_UINT64_C(0x123456789ABC), |
| 431 visitor_.header_->packet_sequence_number); | 480 visitor_.header_->packet_sequence_number); |
| 432 EXPECT_EQ(0x00u, visitor_.header_->fec_group); | 481 EXPECT_EQ(0x00u, visitor_.header_->fec_group); |
| 433 | 482 |
| 434 // Now test framing boundaries | 483 // Now test framing boundaries |
| 435 for (size_t i = 0; i < kPacketHeaderSize; ++i) { | 484 for (size_t i = 0; i < kPacketHeaderSize; ++i) { |
| 436 string expected_error; | 485 string expected_error; |
| 437 if (i < kPublicFlagsOffset) { | 486 if (i < kPublicFlagsOffset) { |
| 438 expected_error = "Unable to read GUID."; | 487 expected_error = "Unable to read GUID."; |
| 439 } else if (i < kSequenceNumberOffset) { | 488 } else if (i < kSequenceNumberOffset) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 unsigned char packet[] = { | 541 unsigned char packet[] = { |
| 493 // guid | 542 // guid |
| 494 0x10, 0x32, 0x54, 0x76, | 543 0x10, 0x32, 0x54, 0x76, |
| 495 0x98, 0xBA, 0xDC, 0xFE, | 544 0x98, 0xBA, 0xDC, 0xFE, |
| 496 // public flags | 545 // public flags |
| 497 0x00, | 546 0x00, |
| 498 // packet sequence number | 547 // packet sequence number |
| 499 0xBC, 0x9A, 0x78, 0x56, | 548 0xBC, 0x9A, 0x78, 0x56, |
| 500 0x34, 0x12, | 549 0x34, 0x12, |
| 501 // private flags | 550 // private flags |
| 502 0x07, | 551 0x08, |
| 503 // first fec protected packet offset | 552 // first fec protected packet offset |
| 504 0xFF, | 553 0xFF, |
| 505 | 554 |
| 506 // frame count | 555 // frame count |
| 507 0x01, | 556 0x01, |
| 508 // frame type (stream frame) | 557 // frame type (stream frame) |
| 509 0x01, | 558 0x01, |
| 510 // stream id | 559 // stream id |
| 511 0x04, 0x03, 0x02, 0x01, | 560 0x04, 0x03, 0x02, 0x01, |
| 512 // fin | 561 // fin |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 0x54, 0x76, 0x10, 0x32, | 600 0x54, 0x76, 0x10, 0x32, |
| 552 0xDC, 0xFE, 0x98, 0xBA, | 601 0xDC, 0xFE, 0x98, 0xBA, |
| 553 0x0c, 0x00, | 602 0x0c, 0x00, |
| 554 'h', 'e', 'l', 'l', | 603 'h', 'e', 'l', 'l', |
| 555 'o', ' ', 'w', 'o', | 604 'o', ' ', 'w', 'o', |
| 556 'r', 'l', 'd', '!', | 605 'r', 'l', 'd', '!', |
| 557 }; | 606 }; |
| 558 | 607 |
| 559 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 608 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
| 560 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 609 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 561 EXPECT_TRUE(CheckDecryption(StringPiece(AsChars(packet), arraysize(packet)))); | |
| 562 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 610 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 563 ASSERT_TRUE(visitor_.header_.get()); | 611 ASSERT_TRUE(visitor_.header_.get()); |
| 612 EXPECT_TRUE(CheckDecryption(StringPiece(AsChars(packet), arraysize(packet)))); |
| 564 | 613 |
| 565 ASSERT_EQ(0u, visitor_.stream_frames_.size()); | 614 ASSERT_EQ(0u, visitor_.stream_frames_.size()); |
| 566 EXPECT_EQ(0u, visitor_.ack_frames_.size()); | 615 EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 567 | 616 |
| 568 // Now test framing boundaries | 617 // Now test framing boundaries |
| 569 for (size_t i = 0; i < 1; ++i) { | 618 for (size_t i = 0; i < 1; ++i) { |
| 570 string expected_error; | 619 string expected_error; |
| 571 if (i < 1) { | 620 if (i < 1) { |
| 572 expected_error = "Unable to read frame type."; | 621 expected_error = "Unable to read frame type."; |
| 573 } | 622 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 604 0x0c, 0x00, | 653 0x0c, 0x00, |
| 605 // data | 654 // data |
| 606 'h', 'e', 'l', 'l', | 655 'h', 'e', 'l', 'l', |
| 607 'o', ' ', 'w', 'o', | 656 'o', ' ', 'w', 'o', |
| 608 'r', 'l', 'd', '!', | 657 'r', 'l', 'd', '!', |
| 609 }; | 658 }; |
| 610 | 659 |
| 611 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 660 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
| 612 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 661 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 613 | 662 |
| 614 EXPECT_TRUE(CheckDecryption(StringPiece(AsChars(packet), arraysize(packet)))); | |
| 615 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 663 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 616 ASSERT_TRUE(visitor_.header_.get()); | 664 ASSERT_TRUE(visitor_.header_.get()); |
| 665 EXPECT_TRUE(CheckDecryption(StringPiece(AsChars(packet), arraysize(packet)))); |
| 617 | 666 |
| 618 ASSERT_EQ(1u, visitor_.stream_frames_.size()); | 667 ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 619 EXPECT_EQ(0u, visitor_.ack_frames_.size()); | 668 EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 620 EXPECT_EQ(static_cast<uint64>(0x01020304), | 669 EXPECT_EQ(static_cast<uint64>(0x01020304), |
| 621 visitor_.stream_frames_[0]->stream_id); | 670 visitor_.stream_frames_[0]->stream_id); |
| 622 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); | 671 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 623 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654), | 672 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654), |
| 624 visitor_.stream_frames_[0]->offset); | 673 visitor_.stream_frames_[0]->offset); |
| 625 EXPECT_EQ("hello world!", visitor_.stream_frames_[0]->data); | 674 EXPECT_EQ("hello world!", visitor_.stream_frames_[0]->data); |
| 626 | 675 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 0x0c, 0x00, | 722 0x0c, 0x00, |
| 674 // data | 723 // data |
| 675 'h', 'e', 'l', 'l', | 724 'h', 'e', 'l', 'l', |
| 676 'o', ' ', 'w', 'o', | 725 'o', ' ', 'w', 'o', |
| 677 'r', 'l', 'd', '!', | 726 'r', 'l', 'd', '!', |
| 678 }; | 727 }; |
| 679 | 728 |
| 680 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 729 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
| 681 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 730 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 682 | 731 |
| 683 EXPECT_TRUE(CheckDecryption(StringPiece(AsChars(packet), arraysize(packet)))); | |
| 684 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 732 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 685 ASSERT_TRUE(visitor_.header_.get()); | 733 ASSERT_TRUE(visitor_.header_.get()); |
| 734 EXPECT_TRUE(CheckDecryption(StringPiece(AsChars(packet), arraysize(packet)))); |
| 686 | 735 |
| 687 ASSERT_EQ(0u, visitor_.stream_frames_.size()); | 736 ASSERT_EQ(0u, visitor_.stream_frames_.size()); |
| 688 EXPECT_EQ(0u, visitor_.ack_frames_.size()); | 737 EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 689 } | 738 } |
| 690 | 739 |
| 691 TEST_F(QuicFramerTest, RevivedStreamFrame) { | 740 TEST_F(QuicFramerTest, RevivedStreamFrame) { |
| 692 unsigned char payload[] = { | 741 unsigned char payload[] = { |
| 693 // frame type (stream frame) | 742 // frame type (stream frame) |
| 694 0x01, | 743 0x01, |
| 695 // stream id | 744 // stream id |
| 696 0x04, 0x03, 0x02, 0x01, | 745 0x04, 0x03, 0x02, 0x01, |
| 697 // fin | 746 // fin |
| 698 0x01, | 747 0x01, |
| 699 // offset | 748 // offset |
| 700 0x54, 0x76, 0x10, 0x32, | 749 0x54, 0x76, 0x10, 0x32, |
| 701 0xDC, 0xFE, 0x98, 0xBA, | 750 0xDC, 0xFE, 0x98, 0xBA, |
| 702 // data length | 751 // data length |
| 703 0x0c, 0x00, | 752 0x0c, 0x00, |
| 704 // data | 753 // data |
| 705 'h', 'e', 'l', 'l', | 754 'h', 'e', 'l', 'l', |
| 706 'o', ' ', 'w', 'o', | 755 'o', ' ', 'w', 'o', |
| 707 'r', 'l', 'd', '!', | 756 'r', 'l', 'd', '!', |
| 708 }; | 757 }; |
| 709 | 758 |
| 710 QuicPacketHeader header; | 759 QuicPacketHeader header; |
| 711 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); | 760 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); |
| 712 header.public_header.flags = PACKET_PUBLIC_FLAGS_NONE; | 761 header.public_header.reset_flag = false; |
| 713 header.private_flags = PACKET_PRIVATE_FLAGS_NONE; | 762 header.public_header.version_flag = false; |
| 763 header.fec_flag = true; |
| 764 header.entropy_flag = true; |
| 765 header.fec_entropy_flag = false; |
| 714 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); | 766 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); |
| 715 header.fec_group = 0; | 767 header.fec_group = 0; |
| 716 | 768 |
| 717 // Do not encrypt the payload because the revived payload is post-encryption. | 769 // Do not encrypt the payload because the revived payload is post-encryption. |
| 718 EXPECT_TRUE(framer_.ProcessRevivedPacket(header, | 770 EXPECT_TRUE(framer_.ProcessRevivedPacket(&header, |
| 719 StringPiece(AsChars(payload), | 771 StringPiece(AsChars(payload), |
| 720 arraysize(payload)))); | 772 arraysize(payload)))); |
| 721 | 773 |
| 722 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 774 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 723 ASSERT_EQ(1, visitor_.revived_packets_); | 775 ASSERT_EQ(1, visitor_.revived_packets_); |
| 724 ASSERT_TRUE(visitor_.header_.get()); | 776 ASSERT_TRUE(visitor_.header_.get()); |
| 725 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210), | 777 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210), |
| 726 visitor_.header_->public_header.guid); | 778 visitor_.header_->public_header.guid); |
| 727 EXPECT_EQ(0x00, visitor_.header_->public_header.flags); | 779 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); |
| 728 EXPECT_EQ(0x00, visitor_.header_->private_flags); | 780 EXPECT_FALSE(visitor_.header_->public_header.version_flag); |
| 781 EXPECT_TRUE(visitor_.header_->fec_flag); |
| 782 EXPECT_TRUE(visitor_.header_->entropy_flag); |
| 783 EXPECT_FALSE(visitor_.header_->fec_entropy_flag); |
| 784 EXPECT_EQ(1 << (header.packet_sequence_number % 8), |
| 785 visitor_.header_->entropy_hash); |
| 729 EXPECT_EQ(GG_UINT64_C(0x123456789ABC), | 786 EXPECT_EQ(GG_UINT64_C(0x123456789ABC), |
| 730 visitor_.header_->packet_sequence_number); | 787 visitor_.header_->packet_sequence_number); |
| 731 EXPECT_EQ(0x00u, visitor_.header_->fec_group); | 788 EXPECT_EQ(0x00u, visitor_.header_->fec_group); |
| 732 | 789 |
| 733 ASSERT_EQ(1u, visitor_.stream_frames_.size()); | 790 ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 734 EXPECT_EQ(0u, visitor_.ack_frames_.size()); | 791 EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 735 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_.stream_frames_[0]->stream_id); | 792 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_.stream_frames_[0]->stream_id); |
| 736 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); | 793 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 737 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654), | 794 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654), |
| 738 visitor_.stream_frames_[0]->offset); | 795 visitor_.stream_frames_[0]->offset); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 767 0x0c, 0x00, | 824 0x0c, 0x00, |
| 768 // data | 825 // data |
| 769 'h', 'e', 'l', 'l', | 826 'h', 'e', 'l', 'l', |
| 770 'o', ' ', 'w', 'o', | 827 'o', ' ', 'w', 'o', |
| 771 'r', 'l', 'd', '!', | 828 'r', 'l', 'd', '!', |
| 772 }; | 829 }; |
| 773 | 830 |
| 774 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 831 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
| 775 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 832 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 776 | 833 |
| 777 EXPECT_TRUE(CheckDecryption(StringPiece(AsChars(packet), arraysize(packet)))); | |
| 778 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 834 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 779 ASSERT_TRUE(visitor_.header_.get()); | 835 ASSERT_TRUE(visitor_.header_.get()); |
| 836 EXPECT_TRUE(CheckDecryption(StringPiece(AsChars(packet), arraysize(packet)))); |
| 780 EXPECT_EQ(GG_UINT64_C(0x341256789ABA), | 837 EXPECT_EQ(GG_UINT64_C(0x341256789ABA), |
| 781 visitor_.header_->fec_group); | 838 visitor_.header_->fec_group); |
| 782 EXPECT_EQ(string(AsChars(packet) + kStartOfFecProtectedData, | 839 EXPECT_EQ(string(AsChars(packet) + kStartOfFecProtectedData, |
| 783 arraysize(packet) - kStartOfFecProtectedData), | 840 arraysize(packet) - kStartOfFecProtectedData), |
| 784 visitor_.fec_protected_payload_); | 841 visitor_.fec_protected_payload_); |
| 785 | 842 |
| 786 ASSERT_EQ(1u, visitor_.stream_frames_.size()); | 843 ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 787 EXPECT_EQ(0u, visitor_.ack_frames_.size()); | 844 EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 788 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_.stream_frames_[0]->stream_id); | 845 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_.stream_frames_[0]->stream_id); |
| 789 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); | 846 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 802 // packet sequence number | 859 // packet sequence number |
| 803 0xBC, 0x9A, 0x78, 0x56, | 860 0xBC, 0x9A, 0x78, 0x56, |
| 804 0x34, 0x12, | 861 0x34, 0x12, |
| 805 // private flags | 862 // private flags |
| 806 0x00, | 863 0x00, |
| 807 // first fec protected packet offset | 864 // first fec protected packet offset |
| 808 0xFF, | 865 0xFF, |
| 809 | 866 |
| 810 // frame type (ack frame) | 867 // frame type (ack frame) |
| 811 0x02, | 868 0x02, |
| 869 // entropy hash of sent packets till least awaiting - 1. |
| 870 0xAB, |
| 812 // least packet sequence number awaiting an ack | 871 // least packet sequence number awaiting an ack |
| 813 0xA0, 0x9A, 0x78, 0x56, | 872 0xA0, 0x9A, 0x78, 0x56, |
| 814 0x34, 0x12, | 873 0x34, 0x12, |
| 874 // entropy hash of all received packets. |
| 875 0xBA, |
| 815 // largest observed packet sequence number | 876 // largest observed packet sequence number |
| 816 0xBF, 0x9A, 0x78, 0x56, | 877 0xBF, 0x9A, 0x78, 0x56, |
| 817 0x34, 0x12, | 878 0x34, 0x12, |
| 818 // num missing packets | 879 // num missing packets |
| 819 0x01, | 880 0x01, |
| 820 // missing packet | 881 // missing packet |
| 821 0xBE, 0x9A, 0x78, 0x56, | 882 0xBE, 0x9A, 0x78, 0x56, |
| 822 0x34, 0x12, | 883 0x34, 0x12, |
| 823 }; | 884 }; |
| 824 | 885 |
| 825 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 886 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
| 826 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 887 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 827 | 888 |
| 828 EXPECT_TRUE(CheckDecryption(StringPiece(AsChars(packet), arraysize(packet)))); | |
| 829 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 889 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 830 ASSERT_TRUE(visitor_.header_.get()); | 890 ASSERT_TRUE(visitor_.header_.get()); |
| 891 EXPECT_TRUE(CheckDecryption(StringPiece(AsChars(packet), arraysize(packet)))); |
| 831 | 892 |
| 832 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | 893 EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 833 ASSERT_EQ(1u, visitor_.ack_frames_.size()); | 894 ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 834 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; | 895 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; |
| 896 EXPECT_EQ(0xAB, frame.sent_info.entropy_hash); |
| 897 EXPECT_EQ(0xBA, frame.received_info.entropy_hash); |
| 835 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame.received_info.largest_observed); | 898 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame.received_info.largest_observed); |
| 836 ASSERT_EQ(1u, frame.received_info.missing_packets.size()); | 899 ASSERT_EQ(1u, frame.received_info.missing_packets.size()); |
| 837 SequenceSet::const_iterator missing_iter = | 900 SequenceNumberSet::const_iterator missing_iter = |
| 838 frame.received_info.missing_packets.begin(); | 901 frame.received_info.missing_packets.begin(); |
| 839 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter); | 902 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter); |
| 840 EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame.sent_info.least_unacked); | 903 EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame.sent_info.least_unacked); |
| 841 | 904 |
| 842 // Now test framing boundaries | 905 // Now test framing boundaries |
| 843 for (size_t i = 0; i < 20; ++i) { | 906 for (size_t i = 0; i < 22; ++i) { |
| 844 string expected_error; | 907 string expected_error; |
| 845 if (i < 1) { | 908 if (i < 1) { |
| 846 expected_error = "Unable to read frame type."; | 909 expected_error = "Unable to read frame type."; |
| 847 } else if (i < 7) { | 910 } else if (i < 2) { |
| 911 expected_error = "Unable to read entropy hash for sent packets."; |
| 912 } else if (i < 8) { |
| 848 expected_error = "Unable to read least unacked."; | 913 expected_error = "Unable to read least unacked."; |
| 849 } else if (i < 13) { | 914 } else if (i < 9) { |
| 915 expected_error = "Unable to read entropy hash for received packets."; |
| 916 } else if (i < 15) { |
| 850 expected_error = "Unable to read largest observed."; | 917 expected_error = "Unable to read largest observed."; |
| 851 } else if (i < 14) { | 918 } else if (i < 16) { |
| 852 expected_error = "Unable to read num missing packets."; | 919 expected_error = "Unable to read num missing packets."; |
| 853 } else if (i < 20) { | 920 } else { |
| 854 expected_error = "Unable to read sequence number in missing packets."; | 921 expected_error = "Unable to read sequence number in missing packets."; |
| 855 } CheckProcessingFails(packet, i + kPacketHeaderSize, expected_error, | 922 } |
| 923 CheckProcessingFails(packet, i + kPacketHeaderSize, expected_error, |
| 856 QUIC_INVALID_FRAME_DATA); | 924 QUIC_INVALID_FRAME_DATA); |
| 857 } | 925 } |
| 858 } | 926 } |
| 859 | 927 |
| 860 TEST_F(QuicFramerTest, CongestionFeedbackFrameTCP) { | 928 TEST_F(QuicFramerTest, CongestionFeedbackFrameTCP) { |
| 861 unsigned char packet[] = { | 929 unsigned char packet[] = { |
| 862 // guid | 930 // guid |
| 863 0x10, 0x32, 0x54, 0x76, | 931 0x10, 0x32, 0x54, 0x76, |
| 864 0x98, 0xBA, 0xDC, 0xFE, | 932 0x98, 0xBA, 0xDC, 0xFE, |
| 865 // public flags | 933 // public flags |
| (...skipping 12 matching lines...) Expand all Loading... |
| 878 0x00, | 946 0x00, |
| 879 // ack_frame.feedback.tcp.accumulated_number_of_lost_packets | 947 // ack_frame.feedback.tcp.accumulated_number_of_lost_packets |
| 880 0x01, 0x02, | 948 0x01, 0x02, |
| 881 // ack_frame.feedback.tcp.receive_window | 949 // ack_frame.feedback.tcp.receive_window |
| 882 0x03, 0x04, | 950 0x03, 0x04, |
| 883 }; | 951 }; |
| 884 | 952 |
| 885 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 953 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
| 886 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 954 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 887 | 955 |
| 888 EXPECT_TRUE(CheckDecryption(StringPiece(AsChars(packet), arraysize(packet)))); | |
| 889 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 956 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 890 ASSERT_TRUE(visitor_.header_.get()); | 957 ASSERT_TRUE(visitor_.header_.get()); |
| 958 EXPECT_TRUE(CheckDecryption(StringPiece(AsChars(packet), arraysize(packet)))); |
| 891 | 959 |
| 892 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | 960 EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 893 ASSERT_EQ(1u, visitor_.congestion_feedback_frames_.size()); | 961 ASSERT_EQ(1u, visitor_.congestion_feedback_frames_.size()); |
| 894 const QuicCongestionFeedbackFrame& frame = | 962 const QuicCongestionFeedbackFrame& frame = |
| 895 *visitor_.congestion_feedback_frames_[0]; | 963 *visitor_.congestion_feedback_frames_[0]; |
| 896 ASSERT_EQ(kTCP, frame.type); | 964 ASSERT_EQ(kTCP, frame.type); |
| 897 EXPECT_EQ(0x0201, | 965 EXPECT_EQ(0x0201, |
| 898 frame.tcp.accumulated_number_of_lost_packets); | 966 frame.tcp.accumulated_number_of_lost_packets); |
| 899 EXPECT_EQ(0x4030u, frame.tcp.receive_window); | 967 EXPECT_EQ(0x4030u, frame.tcp.receive_window); |
| 900 | 968 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 950 0x01, 0x00, 0x00, 0x00, | 1018 0x01, 0x00, 0x00, 0x00, |
| 951 // sequence delta (skip one packet) | 1019 // sequence delta (skip one packet) |
| 952 0x03, 0x00, | 1020 0x03, 0x00, |
| 953 // time delta | 1021 // time delta |
| 954 0x02, 0x00, 0x00, 0x00, | 1022 0x02, 0x00, 0x00, 0x00, |
| 955 }; | 1023 }; |
| 956 | 1024 |
| 957 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 1025 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
| 958 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 1026 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 959 | 1027 |
| 960 EXPECT_TRUE(CheckDecryption(StringPiece(AsChars(packet), arraysize(packet)))); | |
| 961 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 1028 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 962 ASSERT_TRUE(visitor_.header_.get()); | 1029 ASSERT_TRUE(visitor_.header_.get()); |
| 1030 EXPECT_TRUE(CheckDecryption(StringPiece(AsChars(packet), arraysize(packet)))); |
| 963 | 1031 |
| 964 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | 1032 EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 965 ASSERT_EQ(1u, visitor_.congestion_feedback_frames_.size()); | 1033 ASSERT_EQ(1u, visitor_.congestion_feedback_frames_.size()); |
| 966 const QuicCongestionFeedbackFrame& frame = | 1034 const QuicCongestionFeedbackFrame& frame = |
| 967 *visitor_.congestion_feedback_frames_[0]; | 1035 *visitor_.congestion_feedback_frames_[0]; |
| 968 ASSERT_EQ(kInterArrival, frame.type); | 1036 ASSERT_EQ(kInterArrival, frame.type); |
| 969 EXPECT_EQ(0x0302, frame.inter_arrival. | 1037 EXPECT_EQ(0x0302, frame.inter_arrival. |
| 970 accumulated_number_of_lost_packets); | 1038 accumulated_number_of_lost_packets); |
| 971 ASSERT_EQ(3u, frame.inter_arrival.received_packet_times.size()); | 1039 ASSERT_EQ(3u, frame.inter_arrival.received_packet_times.size()); |
| 972 TimeMap::const_iterator iter = | 1040 TimeMap::const_iterator iter = |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1031 0x03, | 1099 0x03, |
| 1032 // congestion feedback type (fix rate) | 1100 // congestion feedback type (fix rate) |
| 1033 0x02, | 1101 0x02, |
| 1034 // bitrate_in_bytes_per_second; | 1102 // bitrate_in_bytes_per_second; |
| 1035 0x01, 0x02, 0x03, 0x04, | 1103 0x01, 0x02, 0x03, 0x04, |
| 1036 }; | 1104 }; |
| 1037 | 1105 |
| 1038 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 1106 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
| 1039 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 1107 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 1040 | 1108 |
| 1041 EXPECT_TRUE(CheckDecryption(StringPiece(AsChars(packet), arraysize(packet)))); | |
| 1042 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 1109 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 1043 ASSERT_TRUE(visitor_.header_.get()); | 1110 ASSERT_TRUE(visitor_.header_.get()); |
| 1111 EXPECT_TRUE(CheckDecryption(StringPiece(AsChars(packet), arraysize(packet)))); |
| 1044 | 1112 |
| 1045 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | 1113 EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 1046 ASSERT_EQ(1u, visitor_.congestion_feedback_frames_.size()); | 1114 ASSERT_EQ(1u, visitor_.congestion_feedback_frames_.size()); |
| 1047 const QuicCongestionFeedbackFrame& frame = | 1115 const QuicCongestionFeedbackFrame& frame = |
| 1048 *visitor_.congestion_feedback_frames_[0]; | 1116 *visitor_.congestion_feedback_frames_[0]; |
| 1049 ASSERT_EQ(kFixRate, frame.type); | 1117 ASSERT_EQ(kFixRate, frame.type); |
| 1050 EXPECT_EQ(static_cast<uint32>(0x04030201), | 1118 EXPECT_EQ(static_cast<uint32>(0x04030201), |
| 1051 frame.fix_rate.bitrate.ToBytesPerSecond()); | 1119 frame.fix_rate.bitrate.ToBytesPerSecond()); |
| 1052 | 1120 |
| 1053 // Now test framing boundaries | 1121 // Now test framing boundaries |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1105 0x34, 0x12, | 1173 0x34, 0x12, |
| 1106 // private flags | 1174 // private flags |
| 1107 0x00, | 1175 0x00, |
| 1108 // first fec protected packet offset | 1176 // first fec protected packet offset |
| 1109 0xFF, | 1177 0xFF, |
| 1110 | 1178 |
| 1111 // frame type (rst stream frame) | 1179 // frame type (rst stream frame) |
| 1112 0x04, | 1180 0x04, |
| 1113 // stream id | 1181 // stream id |
| 1114 0x04, 0x03, 0x02, 0x01, | 1182 0x04, 0x03, 0x02, 0x01, |
| 1115 // offset | |
| 1116 0x54, 0x76, 0x10, 0x32, | |
| 1117 0xDC, 0xFE, 0x98, 0xBA, | |
| 1118 // error code | 1183 // error code |
| 1119 0x08, 0x07, 0x06, 0x05, | 1184 0x08, 0x07, 0x06, 0x05, |
| 1120 | 1185 |
| 1121 // error details length | 1186 // error details length |
| 1122 0x0d, 0x00, | 1187 0x0d, 0x00, |
| 1123 // error details | 1188 // error details |
| 1124 'b', 'e', 'c', 'a', | 1189 'b', 'e', 'c', 'a', |
| 1125 'u', 's', 'e', ' ', | 1190 'u', 's', 'e', ' ', |
| 1126 'I', ' ', 'c', 'a', | 1191 'I', ' ', 'c', 'a', |
| 1127 'n', | 1192 'n', |
| 1128 }; | 1193 }; |
| 1129 | 1194 |
| 1130 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 1195 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
| 1131 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 1196 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 1132 | 1197 |
| 1133 EXPECT_TRUE(CheckDecryption(StringPiece(AsChars(packet), arraysize(packet)))); | |
| 1134 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 1198 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 1135 ASSERT_TRUE(visitor_.header_.get()); | 1199 ASSERT_TRUE(visitor_.header_.get()); |
| 1200 EXPECT_TRUE(CheckDecryption(StringPiece(AsChars(packet), arraysize(packet)))); |
| 1136 | 1201 |
| 1137 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_.rst_stream_frame_.stream_id); | 1202 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_.rst_stream_frame_.stream_id); |
| 1138 EXPECT_EQ(0x05060708, visitor_.rst_stream_frame_.error_code); | 1203 EXPECT_EQ(0x05060708, visitor_.rst_stream_frame_.error_code); |
| 1139 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654), | |
| 1140 visitor_.rst_stream_frame_.offset); | |
| 1141 EXPECT_EQ("because I can", visitor_.rst_stream_frame_.error_details); | 1204 EXPECT_EQ("because I can", visitor_.rst_stream_frame_.error_details); |
| 1142 | 1205 |
| 1143 // Now test framing boundaries | 1206 // Now test framing boundaries |
| 1144 for (size_t i = 2; i < 32; ++i) { | 1207 for (size_t i = 2; i < 24; ++i) { |
| 1145 string expected_error; | 1208 string expected_error; |
| 1146 if (i < 5) { | 1209 if (i < 5) { |
| 1147 expected_error = "Unable to read stream_id."; | 1210 expected_error = "Unable to read stream_id."; |
| 1148 } else if (i < 13) { | 1211 } else if (i < 9) { |
| 1149 expected_error = "Unable to read offset in rst frame."; | |
| 1150 } else if (i < 17) { | |
| 1151 expected_error = "Unable to read rst stream error code."; | 1212 expected_error = "Unable to read rst stream error code."; |
| 1152 } else if (i < 32) { | 1213 } else if (i < 24) { |
| 1153 expected_error = "Unable to read rst stream error details."; | 1214 expected_error = "Unable to read rst stream error details."; |
| 1154 } | 1215 } |
| 1155 CheckProcessingFails(packet, i + kPacketHeaderSize, expected_error, | 1216 CheckProcessingFails(packet, i + kPacketHeaderSize, expected_error, |
| 1156 QUIC_INVALID_RST_STREAM_DATA); | 1217 QUIC_INVALID_RST_STREAM_DATA); |
| 1157 } | 1218 } |
| 1158 } | 1219 } |
| 1159 | 1220 |
| 1160 TEST_F(QuicFramerTest, ConnectionCloseFrame) { | 1221 TEST_F(QuicFramerTest, ConnectionCloseFrame) { |
| 1161 unsigned char packet[] = { | 1222 unsigned char packet[] = { |
| 1162 // guid | 1223 // guid |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1179 | 1240 |
| 1180 // error details length | 1241 // error details length |
| 1181 0x0d, 0x00, | 1242 0x0d, 0x00, |
| 1182 // error details | 1243 // error details |
| 1183 'b', 'e', 'c', 'a', | 1244 'b', 'e', 'c', 'a', |
| 1184 'u', 's', 'e', ' ', | 1245 'u', 's', 'e', ' ', |
| 1185 'I', ' ', 'c', 'a', | 1246 'I', ' ', 'c', 'a', |
| 1186 'n', | 1247 'n', |
| 1187 | 1248 |
| 1188 // Ack frame. | 1249 // Ack frame. |
| 1250 // entropy hash of sent packets till least awaiting - 1. |
| 1251 0xBF, |
| 1189 // least packet sequence number awaiting an ack | 1252 // least packet sequence number awaiting an ack |
| 1190 0xA0, 0x9A, 0x78, 0x56, | 1253 0xA0, 0x9A, 0x78, 0x56, |
| 1191 0x34, 0x12, | 1254 0x34, 0x12, |
| 1255 // entropy hash of all received packets. |
| 1256 0xEB, |
| 1192 // largest observed packet sequence number | 1257 // largest observed packet sequence number |
| 1193 0xBF, 0x9A, 0x78, 0x56, | 1258 0xBF, 0x9A, 0x78, 0x56, |
| 1194 0x34, 0x12, | 1259 0x34, 0x12, |
| 1195 // num missing packets | 1260 // num missing packets |
| 1196 0x01, | 1261 0x01, |
| 1197 // missing packet | 1262 // missing packet |
| 1198 0xBE, 0x9A, 0x78, 0x56, | 1263 0xBE, 0x9A, 0x78, 0x56, |
| 1199 0x34, 0x12, | 1264 0x34, 0x12, |
| 1200 }; | 1265 }; |
| 1201 | 1266 |
| 1202 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 1267 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
| 1203 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 1268 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 1204 | 1269 |
| 1205 EXPECT_TRUE(CheckDecryption(StringPiece(AsChars(packet), arraysize(packet)))); | |
| 1206 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 1270 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 1207 ASSERT_TRUE(visitor_.header_.get()); | 1271 ASSERT_TRUE(visitor_.header_.get()); |
| 1272 EXPECT_TRUE(CheckDecryption(StringPiece(AsChars(packet), arraysize(packet)))); |
| 1208 | 1273 |
| 1209 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | 1274 EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 1210 | 1275 |
| 1211 EXPECT_EQ(0x05060708, visitor_.connection_close_frame_.error_code); | 1276 EXPECT_EQ(0x05060708, visitor_.connection_close_frame_.error_code); |
| 1212 EXPECT_EQ("because I can", visitor_.connection_close_frame_.error_details); | 1277 EXPECT_EQ("because I can", visitor_.connection_close_frame_.error_details); |
| 1213 | 1278 |
| 1214 ASSERT_EQ(1u, visitor_.ack_frames_.size()); | 1279 ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 1215 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; | 1280 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; |
| 1281 EXPECT_EQ(0xBF, frame.sent_info.entropy_hash); |
| 1282 EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame.sent_info.least_unacked); |
| 1283 EXPECT_EQ(0xEB, frame.received_info.entropy_hash); |
| 1216 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame.received_info.largest_observed); | 1284 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame.received_info.largest_observed); |
| 1217 ASSERT_EQ(1u, frame.received_info.missing_packets.size()); | 1285 ASSERT_EQ(1u, frame.received_info.missing_packets.size()); |
| 1218 SequenceSet::const_iterator missing_iter = | 1286 SequenceNumberSet::const_iterator missing_iter = |
| 1219 frame.received_info.missing_packets.begin(); | 1287 frame.received_info.missing_packets.begin(); |
| 1220 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter); | 1288 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter); |
| 1221 EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame.sent_info.least_unacked); | |
| 1222 | 1289 |
| 1223 // Now test framing boundaries | 1290 // Now test framing boundaries |
| 1224 for (size_t i = 2; i < 20; ++i) { | 1291 for (size_t i = 2; i < 20; ++i) { |
| 1225 string expected_error; | 1292 string expected_error; |
| 1226 if (i < 5) { | 1293 if (i < 5) { |
| 1227 expected_error = "Unable to read connection close error code."; | 1294 expected_error = "Unable to read connection close error code."; |
| 1228 } else if (i < 20) { | 1295 } else if (i < 20) { |
| 1229 expected_error = "Unable to read connection close error details."; | 1296 expected_error = "Unable to read connection close error details."; |
| 1230 } | 1297 } |
| 1231 CheckProcessingFails(packet, i + kPacketHeaderSize, expected_error, | 1298 CheckProcessingFails(packet, i + kPacketHeaderSize, expected_error, |
| 1232 QUIC_INVALID_CONNECTION_CLOSE_DATA); | 1299 QUIC_INVALID_CONNECTION_CLOSE_DATA); |
| 1233 } | 1300 } |
| 1234 } | 1301 } |
| 1235 | 1302 |
| 1303 TEST_F(QuicFramerTest, GoAwayFrame) { |
| 1304 unsigned char packet[] = { |
| 1305 // guid |
| 1306 0x10, 0x32, 0x54, 0x76, |
| 1307 0x98, 0xBA, 0xDC, 0xFE, |
| 1308 // public flags |
| 1309 0x00, |
| 1310 // packet sequence number |
| 1311 0xBC, 0x9A, 0x78, 0x56, |
| 1312 0x34, 0x12, |
| 1313 // private flags |
| 1314 0x00, |
| 1315 // first fec protected packet offset |
| 1316 0xFF, |
| 1317 |
| 1318 // frame type (go away frame) |
| 1319 0x06, |
| 1320 // error code |
| 1321 0x08, 0x07, 0x06, 0x05, |
| 1322 // stream id |
| 1323 0x04, 0x03, 0x02, 0x01, |
| 1324 // error details length |
| 1325 0x0d, 0x00, |
| 1326 // error details |
| 1327 'b', 'e', 'c', 'a', |
| 1328 'u', 's', 'e', ' ', |
| 1329 'I', ' ', 'c', 'a', |
| 1330 'n', |
| 1331 }; |
| 1332 |
| 1333 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
| 1334 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 1335 |
| 1336 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 1337 ASSERT_TRUE(visitor_.header_.get()); |
| 1338 EXPECT_TRUE(CheckDecryption(StringPiece(AsChars(packet), arraysize(packet)))); |
| 1339 |
| 1340 EXPECT_EQ(GG_UINT64_C(0x01020304), |
| 1341 visitor_.goaway_frame_.last_good_stream_id); |
| 1342 EXPECT_EQ(0x05060708, visitor_.goaway_frame_.error_code); |
| 1343 EXPECT_EQ("because I can", visitor_.goaway_frame_.reason_phrase); |
| 1344 |
| 1345 // Now test framing boundaries |
| 1346 for (size_t i = 2; i < 24; ++i) { |
| 1347 string expected_error; |
| 1348 if (i < 5) { |
| 1349 expected_error = "Unable to read go away error code."; |
| 1350 } else if (i < 9) { |
| 1351 expected_error = "Unable to read last good stream id."; |
| 1352 } else if (i < 24) { |
| 1353 expected_error = "Unable to read goaway reason."; |
| 1354 } |
| 1355 CheckProcessingFails(packet, i + kPacketHeaderSize, expected_error, |
| 1356 QUIC_INVALID_GOAWAY_DATA); |
| 1357 } |
| 1358 } |
| 1359 |
| 1236 TEST_F(QuicFramerTest, PublicResetPacket) { | 1360 TEST_F(QuicFramerTest, PublicResetPacket) { |
| 1237 unsigned char packet[] = { | 1361 unsigned char packet[] = { |
| 1238 // guid | 1362 // guid |
| 1239 0x10, 0x32, 0x54, 0x76, | 1363 0x10, 0x32, 0x54, 0x76, |
| 1240 0x98, 0xBA, 0xDC, 0xFE, | 1364 0x98, 0xBA, 0xDC, 0xFE, |
| 1241 // public flags (public reset) | 1365 // public flags (public reset) |
| 1242 0x02, | 1366 0x02, |
| 1243 // nonce proof | 1367 // nonce proof |
| 1244 0x89, 0x67, 0x45, 0x23, | 1368 0x89, 0x67, 0x45, 0x23, |
| 1245 0x01, 0xEF, 0xCD, 0xAB, | 1369 0x01, 0xEF, 0xCD, 0xAB, |
| 1246 // rejected sequence number | 1370 // rejected sequence number |
| 1247 0xBC, 0x9A, 0x78, 0x56, | 1371 0xBC, 0x9A, 0x78, 0x56, |
| 1248 0x34, 0x12, | 1372 0x34, 0x12, |
| 1249 }; | 1373 }; |
| 1250 | 1374 |
| 1251 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 1375 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
| 1252 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 1376 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 1253 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 1377 ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 1254 ASSERT_TRUE(visitor_.public_reset_packet_.get()); | 1378 ASSERT_TRUE(visitor_.public_reset_packet_.get()); |
| 1255 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210), | 1379 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210), |
| 1256 visitor_.public_reset_packet_->public_header.guid); | 1380 visitor_.public_reset_packet_->public_header.guid); |
| 1257 EXPECT_EQ(PACKET_PUBLIC_FLAGS_RST, | 1381 EXPECT_TRUE(visitor_.public_reset_packet_->public_header.reset_flag); |
| 1258 visitor_.public_reset_packet_->public_header.flags); | 1382 EXPECT_FALSE(visitor_.public_reset_packet_->public_header.version_flag); |
| 1259 EXPECT_EQ(GG_UINT64_C(0xABCDEF0123456789), | 1383 EXPECT_EQ(GG_UINT64_C(0xABCDEF0123456789), |
| 1260 visitor_.public_reset_packet_->nonce_proof); | 1384 visitor_.public_reset_packet_->nonce_proof); |
| 1261 EXPECT_EQ(GG_UINT64_C(0x123456789ABC), | 1385 EXPECT_EQ(GG_UINT64_C(0x123456789ABC), |
| 1262 visitor_.public_reset_packet_->rejected_sequence_number); | 1386 visitor_.public_reset_packet_->rejected_sequence_number); |
| 1263 | 1387 |
| 1264 // Now test framing boundaries | 1388 // Now test framing boundaries |
| 1265 for (size_t i = 0; i < kPublicResetPacketSize; ++i) { | 1389 for (size_t i = 0; i < kPublicResetPacketSize; ++i) { |
| 1266 string expected_error; | 1390 string expected_error; |
| 1267 if (i < kPublicFlagsOffset) { | 1391 if (i < kPublicFlagsOffset) { |
| 1268 expected_error = "Unable to read GUID."; | 1392 expected_error = "Unable to read GUID."; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1295 // redundancy | 1419 // redundancy |
| 1296 'a', 'b', 'c', 'd', | 1420 'a', 'b', 'c', 'd', |
| 1297 'e', 'f', 'g', 'h', | 1421 'e', 'f', 'g', 'h', |
| 1298 'i', 'j', 'k', 'l', | 1422 'i', 'j', 'k', 'l', |
| 1299 'm', 'n', 'o', 'p', | 1423 'm', 'n', 'o', 'p', |
| 1300 }; | 1424 }; |
| 1301 | 1425 |
| 1302 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 1426 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
| 1303 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 1427 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 1304 | 1428 |
| 1305 EXPECT_TRUE(CheckDecryption(StringPiece(AsChars(packet), arraysize(packet)))); | |
| 1306 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 1429 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 1307 ASSERT_TRUE(visitor_.header_.get()); | 1430 ASSERT_TRUE(visitor_.header_.get()); |
| 1431 EXPECT_TRUE(CheckDecryption(StringPiece(AsChars(packet), arraysize(packet)))); |
| 1308 | 1432 |
| 1309 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | 1433 EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 1310 EXPECT_EQ(0u, visitor_.ack_frames_.size()); | 1434 EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 1311 ASSERT_EQ(1, visitor_.fec_count_); | 1435 ASSERT_EQ(1, visitor_.fec_count_); |
| 1312 const QuicFecData& fec_data = *visitor_.fec_data_[0]; | 1436 const QuicFecData& fec_data = *visitor_.fec_data_[0]; |
| 1313 EXPECT_EQ(GG_UINT64_C(0x0123456789ABB), fec_data.fec_group); | 1437 EXPECT_EQ(GG_UINT64_C(0x0123456789ABB), fec_data.fec_group); |
| 1314 EXPECT_EQ("abcdefghijklmnop", fec_data.redundancy); | 1438 EXPECT_EQ("abcdefghijklmnop", fec_data.redundancy); |
| 1315 } | 1439 } |
| 1316 | 1440 |
| 1317 TEST_F(QuicFramerTest, ConstructPaddingFramePacket) { | 1441 TEST_F(QuicFramerTest, ConstructPaddingFramePacket) { |
| 1318 QuicPacketHeader header; | 1442 QuicPacketHeader header; |
| 1319 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); | 1443 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); |
| 1320 header.public_header.flags = PACKET_PUBLIC_FLAGS_NONE; | 1444 header.public_header.reset_flag = false; |
| 1321 header.private_flags = PACKET_PRIVATE_FLAGS_NONE; | 1445 header.public_header.version_flag = false; |
| 1446 header.fec_flag = false; |
| 1447 header.entropy_flag = false; |
| 1448 header.fec_entropy_flag = false; |
| 1322 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); | 1449 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); |
| 1323 header.fec_group = 0; | 1450 header.fec_group = 0; |
| 1324 | 1451 |
| 1325 QuicPaddingFrame padding_frame; | 1452 QuicPaddingFrame padding_frame; |
| 1326 | 1453 |
| 1327 QuicFrames frames; | 1454 QuicFrames frames; |
| 1328 frames.push_back(QuicFrame(&padding_frame)); | 1455 frames.push_back(QuicFrame(&padding_frame)); |
| 1329 | 1456 |
| 1330 unsigned char packet[kMaxPacketSize] = { | 1457 unsigned char packet[kMaxPacketSize] = { |
| 1331 // guid | 1458 // guid |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1342 0xFF, | 1469 0xFF, |
| 1343 | 1470 |
| 1344 // frame type (padding frame) | 1471 // frame type (padding frame) |
| 1345 0x00, | 1472 0x00, |
| 1346 }; | 1473 }; |
| 1347 | 1474 |
| 1348 // unsigned char packet[kMaxPacketSize]; | 1475 // unsigned char packet[kMaxPacketSize]; |
| 1349 memset(packet + kPacketHeaderSize + 1, 0x00, | 1476 memset(packet + kPacketHeaderSize + 1, 0x00, |
| 1350 kMaxPacketSize - kPacketHeaderSize - 1); | 1477 kMaxPacketSize - kPacketHeaderSize - 1); |
| 1351 | 1478 |
| 1352 scoped_ptr<QuicPacket> data(framer_.ConstructFrameDataPacket(header, frames)); | 1479 scoped_ptr<QuicPacket> data( |
| 1480 framer_.ConstructFrameDataPacket(header, frames).packet); |
| 1353 ASSERT_TRUE(data != NULL); | 1481 ASSERT_TRUE(data != NULL); |
| 1354 | 1482 |
| 1355 test::CompareCharArraysWithHexError("constructed packet", | 1483 test::CompareCharArraysWithHexError("constructed packet", |
| 1356 data->data(), data->length(), | 1484 data->data(), data->length(), |
| 1357 AsChars(packet), arraysize(packet)); | 1485 AsChars(packet), arraysize(packet)); |
| 1358 } | 1486 } |
| 1359 | 1487 |
| 1360 TEST_F(QuicFramerTest, ConstructStreamFramePacket) { | 1488 TEST_F(QuicFramerTest, ConstructStreamFramePacket) { |
| 1361 QuicPacketHeader header; | 1489 QuicPacketHeader header; |
| 1362 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); | 1490 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); |
| 1363 header.public_header.flags = PACKET_PUBLIC_FLAGS_NONE; | 1491 header.public_header.reset_flag = false; |
| 1364 header.private_flags = PACKET_PRIVATE_FLAGS_NONE; | 1492 header.public_header.version_flag = false; |
| 1493 header.fec_flag = false; |
| 1494 header.entropy_flag = true; |
| 1495 header.fec_entropy_flag = false; |
| 1365 header.packet_sequence_number = GG_UINT64_C(0x77123456789ABC); | 1496 header.packet_sequence_number = GG_UINT64_C(0x77123456789ABC); |
| 1366 header.fec_group = 0; | 1497 header.fec_group = 0; |
| 1367 | 1498 |
| 1368 QuicStreamFrame stream_frame; | 1499 QuicStreamFrame stream_frame; |
| 1369 stream_frame.stream_id = 0x01020304; | 1500 stream_frame.stream_id = 0x01020304; |
| 1370 stream_frame.fin = true; | 1501 stream_frame.fin = true; |
| 1371 stream_frame.offset = GG_UINT64_C(0xBA98FEDC32107654); | 1502 stream_frame.offset = GG_UINT64_C(0xBA98FEDC32107654); |
| 1372 stream_frame.data = "hello world!"; | 1503 stream_frame.data = "hello world!"; |
| 1373 | 1504 |
| 1374 QuicFrames frames; | 1505 QuicFrames frames; |
| 1375 frames.push_back(QuicFrame(&stream_frame)); | 1506 frames.push_back(QuicFrame(&stream_frame)); |
| 1376 | 1507 |
| 1377 unsigned char packet[] = { | 1508 unsigned char packet[] = { |
| 1378 // guid | 1509 // guid |
| 1379 0x10, 0x32, 0x54, 0x76, | 1510 0x10, 0x32, 0x54, 0x76, |
| 1380 0x98, 0xBA, 0xDC, 0xFE, | 1511 0x98, 0xBA, 0xDC, 0xFE, |
| 1381 // public flags | 1512 // public flags |
| 1382 0x00, | 1513 0x00, |
| 1383 // packet sequence number | 1514 // packet sequence number |
| 1384 0xBC, 0x9A, 0x78, 0x56, | 1515 0xBC, 0x9A, 0x78, 0x56, |
| 1385 0x34, 0x12, | 1516 0x34, 0x12, |
| 1386 // private flags | 1517 // private flags (entropy) |
| 1387 0x00, | 1518 0x02, |
| 1388 // first fec protected packet offset | 1519 // first fec protected packet offset |
| 1389 0xFF, | 1520 0xFF, |
| 1390 | 1521 |
| 1391 // frame type (stream frame) | 1522 // frame type (stream frame) |
| 1392 0x01, | 1523 0x01, |
| 1393 // stream id | 1524 // stream id |
| 1394 0x04, 0x03, 0x02, 0x01, | 1525 0x04, 0x03, 0x02, 0x01, |
| 1395 // fin | 1526 // fin |
| 1396 0x01, | 1527 0x01, |
| 1397 // offset | 1528 // offset |
| 1398 0x54, 0x76, 0x10, 0x32, | 1529 0x54, 0x76, 0x10, 0x32, |
| 1399 0xDC, 0xFE, 0x98, 0xBA, | 1530 0xDC, 0xFE, 0x98, 0xBA, |
| 1400 // data length | 1531 // data length |
| 1401 0x0c, 0x00, | 1532 0x0c, 0x00, |
| 1402 // data | 1533 // data |
| 1403 'h', 'e', 'l', 'l', | 1534 'h', 'e', 'l', 'l', |
| 1404 'o', ' ', 'w', 'o', | 1535 'o', ' ', 'w', 'o', |
| 1405 'r', 'l', 'd', '!', | 1536 'r', 'l', 'd', '!', |
| 1406 }; | 1537 }; |
| 1407 | 1538 |
| 1408 scoped_ptr<QuicPacket> data(framer_.ConstructFrameDataPacket(header, frames)); | 1539 scoped_ptr<QuicPacket> data( |
| 1540 framer_.ConstructFrameDataPacket(header, frames).packet); |
| 1409 ASSERT_TRUE(data != NULL); | 1541 ASSERT_TRUE(data != NULL); |
| 1410 | 1542 |
| 1411 test::CompareCharArraysWithHexError("constructed packet", | 1543 test::CompareCharArraysWithHexError("constructed packet", |
| 1412 data->data(), data->length(), | 1544 data->data(), data->length(), |
| 1413 AsChars(packet), arraysize(packet)); | 1545 AsChars(packet), arraysize(packet)); |
| 1414 } | 1546 } |
| 1415 | 1547 |
| 1416 TEST_F(QuicFramerTest, ConstructAckFramePacket) { | 1548 TEST_F(QuicFramerTest, ConstructAckFramePacket) { |
| 1417 QuicPacketHeader header; | 1549 QuicPacketHeader header; |
| 1418 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); | 1550 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); |
| 1419 header.public_header.flags = PACKET_PUBLIC_FLAGS_NONE; | 1551 header.public_header.reset_flag = false; |
| 1420 header.private_flags = PACKET_PRIVATE_FLAGS_NONE; | 1552 header.public_header.version_flag = false; |
| 1553 header.fec_flag = false; |
| 1554 header.entropy_flag = true; |
| 1555 header.fec_entropy_flag = true; |
| 1421 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); | 1556 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); |
| 1422 header.fec_group = 0; | 1557 header.fec_group = 0; |
| 1423 | 1558 |
| 1424 QuicAckFrame ack_frame; | 1559 QuicAckFrame ack_frame; |
| 1560 ack_frame.received_info.entropy_hash = 0x43; |
| 1425 ack_frame.received_info.largest_observed = GG_UINT64_C(0x770123456789ABF); | 1561 ack_frame.received_info.largest_observed = GG_UINT64_C(0x770123456789ABF); |
| 1426 ack_frame.received_info.missing_packets.insert( | 1562 ack_frame.received_info.missing_packets.insert( |
| 1427 GG_UINT64_C(0x770123456789ABE)); | 1563 GG_UINT64_C(0x770123456789ABE)); |
| 1564 ack_frame.sent_info.entropy_hash = 0x14; |
| 1428 ack_frame.sent_info.least_unacked = GG_UINT64_C(0x770123456789AA0); | 1565 ack_frame.sent_info.least_unacked = GG_UINT64_C(0x770123456789AA0); |
| 1429 | 1566 |
| 1430 QuicFrames frames; | 1567 QuicFrames frames; |
| 1431 frames.push_back(QuicFrame(&ack_frame)); | 1568 frames.push_back(QuicFrame(&ack_frame)); |
| 1432 | 1569 |
| 1433 unsigned char packet[] = { | 1570 unsigned char packet[] = { |
| 1434 // guid | 1571 // guid |
| 1435 0x10, 0x32, 0x54, 0x76, | 1572 0x10, 0x32, 0x54, 0x76, |
| 1436 0x98, 0xBA, 0xDC, 0xFE, | 1573 0x98, 0xBA, 0xDC, 0xFE, |
| 1437 // public flags | 1574 // public flags |
| 1438 0x00, | 1575 0x00, |
| 1439 // packet sequence number | 1576 // packet sequence number |
| 1440 0xBC, 0x9A, 0x78, 0x56, | 1577 0xBC, 0x9A, 0x78, 0x56, |
| 1441 0x34, 0x12, | 1578 0x34, 0x12, |
| 1442 // private flags | 1579 // private flags (entropy & fec_entropy -- not relevant) |
| 1443 0x00, | 1580 0x06, |
| 1444 // first fec protected packet offset | 1581 // first fec protected packet offset |
| 1445 0xFF, | 1582 0xFF, |
| 1446 | 1583 |
| 1447 // frame type (ack frame) | 1584 // frame type (ack frame) |
| 1448 0x02, | 1585 0x02, |
| 1586 // entropy hash of sent packets till least awaiting - 1. |
| 1587 0x14, |
| 1449 // least packet sequence number awaiting an ack | 1588 // least packet sequence number awaiting an ack |
| 1450 0xA0, 0x9A, 0x78, 0x56, | 1589 0xA0, 0x9A, 0x78, 0x56, |
| 1451 0x34, 0x12, | 1590 0x34, 0x12, |
| 1591 // entropy hash of all received packets. |
| 1592 0x43, |
| 1452 // largest observed packet sequence number | 1593 // largest observed packet sequence number |
| 1453 0xBF, 0x9A, 0x78, 0x56, | 1594 0xBF, 0x9A, 0x78, 0x56, |
| 1454 0x34, 0x12, | 1595 0x34, 0x12, |
| 1455 // num missing packets | 1596 // num missing packets |
| 1456 0x01, | 1597 0x01, |
| 1457 // missing packet | 1598 // missing packet |
| 1458 0xBE, 0x9A, 0x78, 0x56, | 1599 0xBE, 0x9A, 0x78, 0x56, |
| 1459 0x34, 0x12, | 1600 0x34, 0x12, |
| 1460 }; | 1601 }; |
| 1461 | 1602 |
| 1462 scoped_ptr<QuicPacket> data(framer_.ConstructFrameDataPacket(header, frames)); | 1603 scoped_ptr<QuicPacket> data( |
| 1604 framer_.ConstructFrameDataPacket(header, frames).packet); |
| 1463 ASSERT_TRUE(data != NULL); | 1605 ASSERT_TRUE(data != NULL); |
| 1464 | 1606 |
| 1465 test::CompareCharArraysWithHexError("constructed packet", | 1607 test::CompareCharArraysWithHexError("constructed packet", |
| 1466 data->data(), data->length(), | 1608 data->data(), data->length(), |
| 1467 AsChars(packet), arraysize(packet)); | 1609 AsChars(packet), arraysize(packet)); |
| 1468 } | 1610 } |
| 1469 | 1611 |
| 1470 TEST_F(QuicFramerTest, ConstructCongestionFeedbackFramePacketTCP) { | 1612 TEST_F(QuicFramerTest, ConstructCongestionFeedbackFramePacketTCP) { |
| 1471 QuicPacketHeader header; | 1613 QuicPacketHeader header; |
| 1472 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); | 1614 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); |
| 1473 header.public_header.flags = PACKET_PUBLIC_FLAGS_NONE; | 1615 header.public_header.reset_flag = false; |
| 1474 header.private_flags = PACKET_PRIVATE_FLAGS_NONE; | 1616 header.public_header.version_flag = false; |
| 1617 header.fec_flag = false; |
| 1618 header.entropy_flag = false; |
| 1619 header.fec_entropy_flag = true; |
| 1475 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); | 1620 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); |
| 1476 header.fec_group = 0; | 1621 header.fec_group = 0; |
| 1477 | 1622 |
| 1478 QuicCongestionFeedbackFrame congestion_feedback_frame; | 1623 QuicCongestionFeedbackFrame congestion_feedback_frame; |
| 1479 congestion_feedback_frame.type = kTCP; | 1624 congestion_feedback_frame.type = kTCP; |
| 1480 congestion_feedback_frame.tcp.accumulated_number_of_lost_packets = 0x0201; | 1625 congestion_feedback_frame.tcp.accumulated_number_of_lost_packets = 0x0201; |
| 1481 congestion_feedback_frame.tcp.receive_window = 0x4030; | 1626 congestion_feedback_frame.tcp.receive_window = 0x4030; |
| 1482 | 1627 |
| 1483 QuicFrames frames; | 1628 QuicFrames frames; |
| 1484 frames.push_back(QuicFrame(&congestion_feedback_frame)); | 1629 frames.push_back(QuicFrame(&congestion_feedback_frame)); |
| 1485 | 1630 |
| 1486 unsigned char packet[] = { | 1631 unsigned char packet[] = { |
| 1487 // guid | 1632 // guid |
| 1488 0x10, 0x32, 0x54, 0x76, | 1633 0x10, 0x32, 0x54, 0x76, |
| 1489 0x98, 0xBA, 0xDC, 0xFE, | 1634 0x98, 0xBA, 0xDC, 0xFE, |
| 1490 // public flags | 1635 // public flags |
| 1491 0x00, | 1636 0x00, |
| 1492 // packet sequence number | 1637 // packet sequence number |
| 1493 0xBC, 0x9A, 0x78, 0x56, | 1638 0xBC, 0x9A, 0x78, 0x56, |
| 1494 0x34, 0x12, | 1639 0x34, 0x12, |
| 1495 // private flags | 1640 // private flags |
| 1496 0x00, | 1641 0x04, // (fec_entropy_flag) |
| 1497 // first fec protected packet offset | 1642 // first fec protected packet offset |
| 1498 0xFF, | 1643 0xFF, |
| 1499 | 1644 |
| 1500 // frame type (congestion feedback frame) | 1645 // frame type (congestion feedback frame) |
| 1501 0x03, | 1646 0x03, |
| 1502 // congestion feedback type (TCP) | 1647 // congestion feedback type (TCP) |
| 1503 0x00, | 1648 0x00, |
| 1504 // accumulated number of lost packets | 1649 // accumulated number of lost packets |
| 1505 0x01, 0x02, | 1650 0x01, 0x02, |
| 1506 // TCP receive window | 1651 // TCP receive window |
| 1507 0x03, 0x04, | 1652 0x03, 0x04, |
| 1508 }; | 1653 }; |
| 1509 | 1654 |
| 1510 scoped_ptr<QuicPacket> data(framer_.ConstructFrameDataPacket(header, frames)); | 1655 scoped_ptr<QuicPacket> data( |
| 1656 framer_.ConstructFrameDataPacket(header, frames).packet); |
| 1511 ASSERT_TRUE(data != NULL); | 1657 ASSERT_TRUE(data != NULL); |
| 1512 | 1658 |
| 1513 test::CompareCharArraysWithHexError("constructed packet", | 1659 test::CompareCharArraysWithHexError("constructed packet", |
| 1514 data->data(), data->length(), | 1660 data->data(), data->length(), |
| 1515 AsChars(packet), arraysize(packet)); | 1661 AsChars(packet), arraysize(packet)); |
| 1516 } | 1662 } |
| 1517 | 1663 |
| 1518 TEST_F(QuicFramerTest, ConstructCongestionFeedbackFramePacketInterArrival) { | 1664 TEST_F(QuicFramerTest, ConstructCongestionFeedbackFramePacketInterArrival) { |
| 1519 QuicPacketHeader header; | 1665 QuicPacketHeader header; |
| 1520 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); | 1666 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); |
| 1521 header.public_header.flags = PACKET_PUBLIC_FLAGS_NONE; | 1667 header.public_header.reset_flag = false; |
| 1522 header.private_flags = PACKET_PRIVATE_FLAGS_NONE; | 1668 header.public_header.version_flag = false; |
| 1669 header.fec_flag = false; |
| 1670 header.entropy_flag = false; |
| 1671 header.fec_entropy_flag = false; |
| 1523 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); | 1672 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); |
| 1524 header.fec_group = 0; | 1673 header.fec_group = 0; |
| 1525 | 1674 |
| 1526 QuicCongestionFeedbackFrame frame; | 1675 QuicCongestionFeedbackFrame frame; |
| 1527 frame.type = kInterArrival; | 1676 frame.type = kInterArrival; |
| 1528 frame.inter_arrival.accumulated_number_of_lost_packets = 0x0302; | 1677 frame.inter_arrival.accumulated_number_of_lost_packets = 0x0302; |
| 1529 frame.inter_arrival.received_packet_times.insert( | 1678 frame.inter_arrival.received_packet_times.insert( |
| 1530 make_pair(GG_UINT64_C(0x0123456789ABA), | 1679 make_pair(GG_UINT64_C(0x0123456789ABA), |
| 1531 QuicTime::FromMicroseconds(GG_UINT64_C(0x07E1D2C3B4A59687)))); | 1680 QuicTime::FromMicroseconds(GG_UINT64_C(0x07E1D2C3B4A59687)))); |
| 1532 frame.inter_arrival.received_packet_times.insert( | 1681 frame.inter_arrival.received_packet_times.insert( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1569 // sequence delta | 1718 // sequence delta |
| 1570 0x01, 0x00, | 1719 0x01, 0x00, |
| 1571 // time delta | 1720 // time delta |
| 1572 0x01, 0x00, 0x00, 0x00, | 1721 0x01, 0x00, 0x00, 0x00, |
| 1573 // sequence delta (skip one packet) | 1722 // sequence delta (skip one packet) |
| 1574 0x03, 0x00, | 1723 0x03, 0x00, |
| 1575 // time delta | 1724 // time delta |
| 1576 0x02, 0x00, 0x00, 0x00, | 1725 0x02, 0x00, 0x00, 0x00, |
| 1577 }; | 1726 }; |
| 1578 | 1727 |
| 1579 scoped_ptr<QuicPacket> data(framer_.ConstructFrameDataPacket(header, frames)); | 1728 scoped_ptr<QuicPacket> data( |
| 1729 framer_.ConstructFrameDataPacket(header, frames).packet); |
| 1580 ASSERT_TRUE(data != NULL); | 1730 ASSERT_TRUE(data != NULL); |
| 1581 | 1731 |
| 1582 test::CompareCharArraysWithHexError("constructed packet", | 1732 test::CompareCharArraysWithHexError("constructed packet", |
| 1583 data->data(), data->length(), | 1733 data->data(), data->length(), |
| 1584 AsChars(packet), arraysize(packet)); | 1734 AsChars(packet), arraysize(packet)); |
| 1585 } | 1735 } |
| 1586 | 1736 |
| 1587 TEST_F(QuicFramerTest, ConstructCongestionFeedbackFramePacketFixRate) { | 1737 TEST_F(QuicFramerTest, ConstructCongestionFeedbackFramePacketFixRate) { |
| 1588 QuicPacketHeader header; | 1738 QuicPacketHeader header; |
| 1589 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); | 1739 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); |
| 1590 header.public_header.flags = PACKET_PUBLIC_FLAGS_NONE; | 1740 header.public_header.reset_flag = false; |
| 1591 header.private_flags = PACKET_PRIVATE_FLAGS_NONE; | 1741 header.public_header.version_flag = false; |
| 1742 header.fec_flag = false; |
| 1743 header.entropy_flag = false; |
| 1744 header.fec_entropy_flag = false; |
| 1592 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); | 1745 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); |
| 1593 header.fec_group = 0; | 1746 header.fec_group = 0; |
| 1594 | 1747 |
| 1595 QuicCongestionFeedbackFrame congestion_feedback_frame; | 1748 QuicCongestionFeedbackFrame congestion_feedback_frame; |
| 1596 congestion_feedback_frame.type = kFixRate; | 1749 congestion_feedback_frame.type = kFixRate; |
| 1597 congestion_feedback_frame.fix_rate.bitrate | 1750 congestion_feedback_frame.fix_rate.bitrate |
| 1598 = QuicBandwidth::FromBytesPerSecond(0x04030201); | 1751 = QuicBandwidth::FromBytesPerSecond(0x04030201); |
| 1599 | 1752 |
| 1600 QuicFrames frames; | 1753 QuicFrames frames; |
| 1601 frames.push_back(QuicFrame(&congestion_feedback_frame)); | 1754 frames.push_back(QuicFrame(&congestion_feedback_frame)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1615 0xFF, | 1768 0xFF, |
| 1616 | 1769 |
| 1617 // frame type (congestion feedback frame) | 1770 // frame type (congestion feedback frame) |
| 1618 0x03, | 1771 0x03, |
| 1619 // congestion feedback type (fix rate) | 1772 // congestion feedback type (fix rate) |
| 1620 0x02, | 1773 0x02, |
| 1621 // bitrate_in_bytes_per_second; | 1774 // bitrate_in_bytes_per_second; |
| 1622 0x01, 0x02, 0x03, 0x04, | 1775 0x01, 0x02, 0x03, 0x04, |
| 1623 }; | 1776 }; |
| 1624 | 1777 |
| 1625 scoped_ptr<QuicPacket> data(framer_.ConstructFrameDataPacket(header, frames)); | 1778 scoped_ptr<QuicPacket> data( |
| 1779 framer_.ConstructFrameDataPacket(header, frames).packet); |
| 1626 ASSERT_TRUE(data != NULL); | 1780 ASSERT_TRUE(data != NULL); |
| 1627 | 1781 |
| 1628 test::CompareCharArraysWithHexError("constructed packet", | 1782 test::CompareCharArraysWithHexError("constructed packet", |
| 1629 data->data(), data->length(), | 1783 data->data(), data->length(), |
| 1630 AsChars(packet), arraysize(packet)); | 1784 AsChars(packet), arraysize(packet)); |
| 1631 } | 1785 } |
| 1632 | 1786 |
| 1633 TEST_F(QuicFramerTest, ConstructCongestionFeedbackFramePacketInvalidFeedback) { | 1787 TEST_F(QuicFramerTest, ConstructCongestionFeedbackFramePacketInvalidFeedback) { |
| 1634 QuicPacketHeader header; | 1788 QuicPacketHeader header; |
| 1635 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); | 1789 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); |
| 1636 header.public_header.flags = PACKET_PUBLIC_FLAGS_NONE; | 1790 header.public_header.reset_flag = false; |
| 1637 header.private_flags = PACKET_PRIVATE_FLAGS_NONE; | 1791 header.public_header.version_flag = false; |
| 1792 header.fec_flag = false; |
| 1793 header.entropy_flag = false; |
| 1794 header.fec_entropy_flag = false; |
| 1638 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); | 1795 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); |
| 1639 header.fec_group = 0; | 1796 header.fec_group = 0; |
| 1640 | 1797 |
| 1641 QuicCongestionFeedbackFrame congestion_feedback_frame; | 1798 QuicCongestionFeedbackFrame congestion_feedback_frame; |
| 1642 congestion_feedback_frame.type = | 1799 congestion_feedback_frame.type = |
| 1643 static_cast<CongestionFeedbackType>(kFixRate + 1); | 1800 static_cast<CongestionFeedbackType>(kFixRate + 1); |
| 1644 | 1801 |
| 1645 QuicFrames frames; | 1802 QuicFrames frames; |
| 1646 frames.push_back(QuicFrame(&congestion_feedback_frame)); | 1803 frames.push_back(QuicFrame(&congestion_feedback_frame)); |
| 1647 | 1804 |
| 1648 scoped_ptr<QuicPacket> data(framer_.ConstructFrameDataPacket(header, frames)); | 1805 scoped_ptr<QuicPacket> data( |
| 1806 framer_.ConstructFrameDataPacket(header, frames).packet); |
| 1649 ASSERT_TRUE(data == NULL); | 1807 ASSERT_TRUE(data == NULL); |
| 1650 } | 1808 } |
| 1651 | 1809 |
| 1652 TEST_F(QuicFramerTest, ConstructRstFramePacket) { | 1810 TEST_F(QuicFramerTest, ConstructRstFramePacket) { |
| 1653 QuicPacketHeader header; | 1811 QuicPacketHeader header; |
| 1654 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); | 1812 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); |
| 1655 header.public_header.flags = PACKET_PUBLIC_FLAGS_NONE; | 1813 header.public_header.reset_flag = false; |
| 1656 header.private_flags = PACKET_PRIVATE_FLAGS_NONE; | 1814 header.public_header.version_flag = false; |
| 1815 header.fec_flag = false; |
| 1816 header.entropy_flag = false; |
| 1817 header.fec_entropy_flag = false; |
| 1657 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); | 1818 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); |
| 1658 header.fec_group = 0; | 1819 header.fec_group = 0; |
| 1659 | 1820 |
| 1660 QuicRstStreamFrame rst_frame; | 1821 QuicRstStreamFrame rst_frame; |
| 1661 rst_frame.stream_id = 0x01020304; | 1822 rst_frame.stream_id = 0x01020304; |
| 1662 rst_frame.error_code = static_cast<QuicErrorCode>(0x05060708); | 1823 rst_frame.error_code = static_cast<QuicErrorCode>(0x05060708); |
| 1663 rst_frame.offset = GG_UINT64_C(0xBA98FEDC32107654); | |
| 1664 rst_frame.error_details = "because I can"; | 1824 rst_frame.error_details = "because I can"; |
| 1665 | 1825 |
| 1666 unsigned char packet[] = { | 1826 unsigned char packet[] = { |
| 1667 // guid | 1827 // guid |
| 1668 0x10, 0x32, 0x54, 0x76, | 1828 0x10, 0x32, 0x54, 0x76, |
| 1669 0x98, 0xBA, 0xDC, 0xFE, | 1829 0x98, 0xBA, 0xDC, 0xFE, |
| 1670 // public flags | 1830 // public flags |
| 1671 0x00, | 1831 0x00, |
| 1672 // packet sequence number | 1832 // packet sequence number |
| 1673 0xBC, 0x9A, 0x78, 0x56, | 1833 0xBC, 0x9A, 0x78, 0x56, |
| 1674 0x34, 0x12, | 1834 0x34, 0x12, |
| 1675 // private flags | 1835 // private flags |
| 1676 0x00, | 1836 0x00, |
| 1677 // first fec protected packet offset | 1837 // first fec protected packet offset |
| 1678 0xFF, | 1838 0xFF, |
| 1679 | 1839 |
| 1680 // frame type (rst stream frame) | 1840 // frame type (rst stream frame) |
| 1681 0x04, | 1841 0x04, |
| 1682 // stream id | 1842 // stream id |
| 1683 0x04, 0x03, 0x02, 0x01, | 1843 0x04, 0x03, 0x02, 0x01, |
| 1684 // offset | |
| 1685 0x54, 0x76, 0x10, 0x32, | |
| 1686 0xDC, 0xFE, 0x98, 0xBA, | |
| 1687 // error code | 1844 // error code |
| 1688 0x08, 0x07, 0x06, 0x05, | 1845 0x08, 0x07, 0x06, 0x05, |
| 1689 // error details length | 1846 // error details length |
| 1690 0x0d, 0x00, | 1847 0x0d, 0x00, |
| 1691 // error details | 1848 // error details |
| 1692 'b', 'e', 'c', 'a', | 1849 'b', 'e', 'c', 'a', |
| 1693 'u', 's', 'e', ' ', | 1850 'u', 's', 'e', ' ', |
| 1694 'I', ' ', 'c', 'a', | 1851 'I', ' ', 'c', 'a', |
| 1695 'n', | 1852 'n', |
| 1696 }; | 1853 }; |
| 1697 | 1854 |
| 1698 QuicFrames frames; | 1855 QuicFrames frames; |
| 1699 frames.push_back(QuicFrame(&rst_frame)); | 1856 frames.push_back(QuicFrame(&rst_frame)); |
| 1700 | 1857 |
| 1701 scoped_ptr<QuicPacket> data(framer_.ConstructFrameDataPacket(header, frames)); | 1858 scoped_ptr<QuicPacket> data( |
| 1859 framer_.ConstructFrameDataPacket(header, frames).packet); |
| 1702 ASSERT_TRUE(data != NULL); | 1860 ASSERT_TRUE(data != NULL); |
| 1703 | 1861 |
| 1704 test::CompareCharArraysWithHexError("constructed packet", | 1862 test::CompareCharArraysWithHexError("constructed packet", |
| 1705 data->data(), data->length(), | 1863 data->data(), data->length(), |
| 1706 AsChars(packet), arraysize(packet)); | 1864 AsChars(packet), arraysize(packet)); |
| 1707 } | 1865 } |
| 1708 | 1866 |
| 1709 TEST_F(QuicFramerTest, ConstructCloseFramePacket) { | 1867 TEST_F(QuicFramerTest, ConstructCloseFramePacket) { |
| 1710 QuicPacketHeader header; | 1868 QuicPacketHeader header; |
| 1711 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); | 1869 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); |
| 1712 header.public_header.flags = PACKET_PUBLIC_FLAGS_NONE; | 1870 header.public_header.reset_flag = false; |
| 1713 header.private_flags = PACKET_PRIVATE_FLAGS_NONE; | 1871 header.public_header.version_flag = false; |
| 1872 header.fec_flag = false; |
| 1873 header.entropy_flag = true; |
| 1874 header.fec_entropy_flag = false; |
| 1714 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); | 1875 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); |
| 1715 header.fec_group = 0; | 1876 header.fec_group = 0; |
| 1716 | 1877 |
| 1717 QuicConnectionCloseFrame close_frame; | 1878 QuicConnectionCloseFrame close_frame; |
| 1718 close_frame.error_code = static_cast<QuicErrorCode>(0x05060708); | 1879 close_frame.error_code = static_cast<QuicErrorCode>(0x05060708); |
| 1719 close_frame.error_details = "because I can"; | 1880 close_frame.error_details = "because I can"; |
| 1720 | 1881 |
| 1721 QuicAckFrame* ack_frame = &close_frame.ack_frame; | 1882 QuicAckFrame* ack_frame = &close_frame.ack_frame; |
| 1883 ack_frame->received_info.entropy_hash = 0x43; |
| 1722 ack_frame->received_info.largest_observed = GG_UINT64_C(0x0123456789ABF); | 1884 ack_frame->received_info.largest_observed = GG_UINT64_C(0x0123456789ABF); |
| 1723 ack_frame->received_info.missing_packets.insert(GG_UINT64_C(0x0123456789ABE)); | 1885 ack_frame->received_info.missing_packets.insert(GG_UINT64_C(0x0123456789ABE)); |
| 1886 ack_frame->sent_info.entropy_hash = 0xE0; |
| 1724 ack_frame->sent_info.least_unacked = GG_UINT64_C(0x0123456789AA0); | 1887 ack_frame->sent_info.least_unacked = GG_UINT64_C(0x0123456789AA0); |
| 1725 | 1888 |
| 1726 QuicFrames frames; | 1889 QuicFrames frames; |
| 1727 frames.push_back(QuicFrame(&close_frame)); | 1890 frames.push_back(QuicFrame(&close_frame)); |
| 1728 | 1891 |
| 1729 unsigned char packet[] = { | 1892 unsigned char packet[] = { |
| 1730 // guid | 1893 // guid |
| 1731 0x10, 0x32, 0x54, 0x76, | 1894 0x10, 0x32, 0x54, 0x76, |
| 1732 0x98, 0xBA, 0xDC, 0xFE, | 1895 0x98, 0xBA, 0xDC, 0xFE, |
| 1733 // public flags | 1896 // public flags |
| 1734 0x00, | 1897 0x00, |
| 1735 // packet sequence number | 1898 // packet sequence number |
| 1736 0xBC, 0x9A, 0x78, 0x56, | 1899 0xBC, 0x9A, 0x78, 0x56, |
| 1737 0x34, 0x12, | 1900 0x34, 0x12, |
| 1738 // private flags | 1901 // private flags |
| 1739 0x00, | 1902 0x02, |
| 1740 // first fec protected packet offset | 1903 // first fec protected packet offset |
| 1741 0xFF, | 1904 0xFF, |
| 1742 | 1905 |
| 1743 // frame type (connection close frame) | 1906 // frame type (connection close frame) |
| 1744 0x05, | 1907 0x05, |
| 1745 // error code | 1908 // error code |
| 1746 0x08, 0x07, 0x06, 0x05, | 1909 0x08, 0x07, 0x06, 0x05, |
| 1747 // error details length | 1910 // error details length |
| 1748 0x0d, 0x00, | 1911 0x0d, 0x00, |
| 1749 // error details | 1912 // error details |
| 1750 'b', 'e', 'c', 'a', | 1913 'b', 'e', 'c', 'a', |
| 1751 'u', 's', 'e', ' ', | 1914 'u', 's', 'e', ' ', |
| 1752 'I', ' ', 'c', 'a', | 1915 'I', ' ', 'c', 'a', |
| 1753 'n', | 1916 'n', |
| 1754 | 1917 |
| 1755 // Ack frame. | 1918 // Ack frame. |
| 1919 // entropy hash of sent packets till least awaiting - 1. |
| 1920 0xE0, |
| 1756 // least packet sequence number awaiting an ack | 1921 // least packet sequence number awaiting an ack |
| 1757 0xA0, 0x9A, 0x78, 0x56, | 1922 0xA0, 0x9A, 0x78, 0x56, |
| 1758 0x34, 0x12, | 1923 0x34, 0x12, |
| 1924 // entropy hash of all received packets. |
| 1925 0x43, |
| 1759 // largest observed packet sequence number | 1926 // largest observed packet sequence number |
| 1760 0xBF, 0x9A, 0x78, 0x56, | 1927 0xBF, 0x9A, 0x78, 0x56, |
| 1761 0x34, 0x12, | 1928 0x34, 0x12, |
| 1762 // num missing packets | 1929 // num missing packets |
| 1763 0x01, | 1930 0x01, |
| 1764 // missing packet | 1931 // missing packet |
| 1765 0xBE, 0x9A, 0x78, 0x56, | 1932 0xBE, 0x9A, 0x78, 0x56, |
| 1766 0x34, 0x12, | 1933 0x34, 0x12, |
| 1767 }; | 1934 }; |
| 1768 | 1935 |
| 1769 scoped_ptr<QuicPacket> data(framer_.ConstructFrameDataPacket(header, frames)); | 1936 scoped_ptr<QuicPacket> data( |
| 1937 framer_.ConstructFrameDataPacket(header, frames).packet); |
| 1770 ASSERT_TRUE(data != NULL); | 1938 ASSERT_TRUE(data != NULL); |
| 1771 | 1939 |
| 1772 test::CompareCharArraysWithHexError("constructed packet", | 1940 test::CompareCharArraysWithHexError("constructed packet", |
| 1941 data->data(), data->length(), |
| 1942 AsChars(packet), arraysize(packet)); |
| 1943 } |
| 1944 |
| 1945 TEST_F(QuicFramerTest, ConstructGoAwayPacket) { |
| 1946 QuicPacketHeader header; |
| 1947 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); |
| 1948 header.public_header.reset_flag = false; |
| 1949 header.public_header.version_flag = false; |
| 1950 header.fec_flag = false; |
| 1951 header.entropy_flag = true; |
| 1952 header.fec_entropy_flag = false; |
| 1953 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); |
| 1954 header.fec_group = 0; |
| 1955 |
| 1956 QuicGoAwayFrame goaway_frame; |
| 1957 goaway_frame.error_code = static_cast<QuicErrorCode>(0x05060708); |
| 1958 goaway_frame.last_good_stream_id = 0x01020304; |
| 1959 goaway_frame.reason_phrase = "because I can"; |
| 1960 |
| 1961 QuicFrames frames; |
| 1962 frames.push_back(QuicFrame(&goaway_frame)); |
| 1963 |
| 1964 unsigned char packet[] = { |
| 1965 // guid |
| 1966 0x10, 0x32, 0x54, 0x76, |
| 1967 0x98, 0xBA, 0xDC, 0xFE, |
| 1968 // public flags |
| 1969 0x00, |
| 1970 // packet sequence number |
| 1971 0xBC, 0x9A, 0x78, 0x56, |
| 1972 0x34, 0x12, |
| 1973 // private flags |
| 1974 0x02, |
| 1975 // first fec protected packet offset |
| 1976 0xFF, |
| 1977 |
| 1978 // frame type (go away frame) |
| 1979 0x06, |
| 1980 // error code |
| 1981 0x08, 0x07, 0x06, 0x05, |
| 1982 // stream id |
| 1983 0x04, 0x03, 0x02, 0x01, |
| 1984 // error details length |
| 1985 0x0d, 0x00, |
| 1986 // error details |
| 1987 'b', 'e', 'c', 'a', |
| 1988 'u', 's', 'e', ' ', |
| 1989 'I', ' ', 'c', 'a', |
| 1990 'n', |
| 1991 }; |
| 1992 |
| 1993 scoped_ptr<QuicPacket> data( |
| 1994 framer_.ConstructFrameDataPacket(header, frames).packet); |
| 1995 ASSERT_TRUE(data != NULL); |
| 1996 |
| 1997 test::CompareCharArraysWithHexError("constructed packet", |
| 1773 data->data(), data->length(), | 1998 data->data(), data->length(), |
| 1774 AsChars(packet), arraysize(packet)); | 1999 AsChars(packet), arraysize(packet)); |
| 1775 } | 2000 } |
| 1776 | 2001 |
| 1777 TEST_F(QuicFramerTest, ConstructPublicResetPacket) { | 2002 TEST_F(QuicFramerTest, ConstructPublicResetPacket) { |
| 1778 QuicPublicResetPacket reset_packet; | 2003 QuicPublicResetPacket reset_packet; |
| 1779 reset_packet.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); | 2004 reset_packet.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); |
| 1780 reset_packet.public_header.flags = PACKET_PUBLIC_FLAGS_RST; | 2005 reset_packet.public_header.reset_flag = true; |
| 2006 reset_packet.public_header.version_flag = false; |
| 1781 reset_packet.rejected_sequence_number = GG_UINT64_C(0x123456789ABC); | 2007 reset_packet.rejected_sequence_number = GG_UINT64_C(0x123456789ABC); |
| 1782 reset_packet.nonce_proof = GG_UINT64_C(0xABCDEF0123456789); | 2008 reset_packet.nonce_proof = GG_UINT64_C(0xABCDEF0123456789); |
| 1783 | 2009 |
| 1784 unsigned char packet[] = { | 2010 unsigned char packet[] = { |
| 1785 // guid | 2011 // guid |
| 1786 0x10, 0x32, 0x54, 0x76, | 2012 0x10, 0x32, 0x54, 0x76, |
| 1787 0x98, 0xBA, 0xDC, 0xFE, | 2013 0x98, 0xBA, 0xDC, 0xFE, |
| 1788 // public flags | 2014 // public flags |
| 1789 0x02, | 2015 0x02, |
| 1790 // nonce proof | 2016 // nonce proof |
| 1791 0x89, 0x67, 0x45, 0x23, | 2017 0x89, 0x67, 0x45, 0x23, |
| 1792 0x01, 0xEF, 0xCD, 0xAB, | 2018 0x01, 0xEF, 0xCD, 0xAB, |
| 1793 // rejected sequence number | 2019 // rejected sequence number |
| 1794 0xBC, 0x9A, 0x78, 0x56, | 2020 0xBC, 0x9A, 0x78, 0x56, |
| 1795 0x34, 0x12, | 2021 0x34, 0x12, |
| 1796 }; | 2022 }; |
| 1797 | 2023 |
| 1798 scoped_ptr<QuicEncryptedPacket> data( | 2024 scoped_ptr<QuicEncryptedPacket> data( |
| 1799 framer_.ConstructPublicResetPacket(reset_packet)); | 2025 framer_.ConstructPublicResetPacket(reset_packet)); |
| 1800 ASSERT_TRUE(data != NULL); | 2026 ASSERT_TRUE(data != NULL); |
| 1801 | 2027 |
| 1802 test::CompareCharArraysWithHexError("constructed packet", | 2028 test::CompareCharArraysWithHexError("constructed packet", |
| 1803 data->data(), data->length(), | 2029 data->data(), data->length(), |
| 1804 AsChars(packet), arraysize(packet)); | 2030 AsChars(packet), arraysize(packet)); |
| 1805 } | 2031 } |
| 1806 | 2032 |
| 1807 TEST_F(QuicFramerTest, ConstructFecPacket) { | 2033 TEST_F(QuicFramerTest, ConstructFecPacket) { |
| 1808 QuicPacketHeader header; | 2034 QuicPacketHeader header; |
| 1809 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); | 2035 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); |
| 1810 header.public_header.flags = PACKET_PUBLIC_FLAGS_NONE; | 2036 header.public_header.reset_flag = false; |
| 1811 header.private_flags = PACKET_PRIVATE_FLAGS_FEC; | 2037 header.public_header.version_flag = false; |
| 2038 header.fec_flag = true; |
| 2039 header.entropy_flag = true; |
| 2040 header.fec_entropy_flag = false; |
| 1812 header.packet_sequence_number = (GG_UINT64_C(0x123456789ABC)); | 2041 header.packet_sequence_number = (GG_UINT64_C(0x123456789ABC)); |
| 1813 header.fec_group = GG_UINT64_C(0x123456789ABB);; | 2042 header.fec_group = GG_UINT64_C(0x123456789ABB);; |
| 1814 | 2043 |
| 1815 QuicFecData fec_data; | 2044 QuicFecData fec_data; |
| 1816 fec_data.fec_group = 1; | 2045 fec_data.fec_group = 1; |
| 1817 fec_data.redundancy = "abcdefghijklmnop"; | 2046 fec_data.redundancy = "abcdefghijklmnop"; |
| 1818 | 2047 |
| 1819 unsigned char packet[] = { | 2048 unsigned char packet[] = { |
| 1820 // guid | 2049 // guid |
| 1821 0x10, 0x32, 0x54, 0x76, | 2050 0x10, 0x32, 0x54, 0x76, |
| 1822 0x98, 0xBA, 0xDC, 0xFE, | 2051 0x98, 0xBA, 0xDC, 0xFE, |
| 1823 // public flags | 2052 // public flags |
| 1824 0x00, | 2053 0x00, |
| 1825 // packet sequence number | 2054 // packet sequence number |
| 1826 0xBC, 0x9A, 0x78, 0x56, | 2055 0xBC, 0x9A, 0x78, 0x56, |
| 1827 0x34, 0x12, | 2056 0x34, 0x12, |
| 1828 // private flags | 2057 // private flags |
| 1829 0x01, | 2058 0x03, |
| 1830 // first fec protected packet offset | 2059 // first fec protected packet offset |
| 1831 0x01, | 2060 0x01, |
| 1832 | 2061 |
| 1833 // redundancy | 2062 // redundancy |
| 1834 'a', 'b', 'c', 'd', | 2063 'a', 'b', 'c', 'd', |
| 1835 'e', 'f', 'g', 'h', | 2064 'e', 'f', 'g', 'h', |
| 1836 'i', 'j', 'k', 'l', | 2065 'i', 'j', 'k', 'l', |
| 1837 'm', 'n', 'o', 'p', | 2066 'm', 'n', 'o', 'p', |
| 1838 }; | 2067 }; |
| 1839 | 2068 |
| 1840 scoped_ptr<QuicPacket> data(framer_.ConstructFecPacket(header, fec_data)); | 2069 scoped_ptr<QuicPacket> data( |
| 2070 framer_.ConstructFecPacket(header, fec_data).packet); |
| 1841 ASSERT_TRUE(data != NULL); | 2071 ASSERT_TRUE(data != NULL); |
| 1842 | 2072 |
| 1843 test::CompareCharArraysWithHexError("constructed packet", | 2073 test::CompareCharArraysWithHexError("constructed packet", |
| 1844 data->data(), data->length(), | 2074 data->data(), data->length(), |
| 1845 AsChars(packet), arraysize(packet)); | 2075 AsChars(packet), arraysize(packet)); |
| 1846 } | 2076 } |
| 1847 | 2077 |
| 1848 TEST_F(QuicFramerTest, EncryptPacket) { | 2078 TEST_F(QuicFramerTest, EncryptPacket) { |
| 2079 QuicPacketSequenceNumber sequence_number = GG_UINT64_C(0x123456789ABC); |
| 1849 unsigned char packet[] = { | 2080 unsigned char packet[] = { |
| 1850 // guid | 2081 // guid |
| 1851 0x10, 0x32, 0x54, 0x76, | 2082 0x10, 0x32, 0x54, 0x76, |
| 1852 0x98, 0xBA, 0xDC, 0xFE, | 2083 0x98, 0xBA, 0xDC, 0xFE, |
| 1853 // public flags | 2084 // public flags |
| 1854 0x00, | 2085 0x00, |
| 1855 // packet sequence number | 2086 // packet sequence number |
| 1856 0xBC, 0x9A, 0x78, 0x56, | 2087 0xBC, 0x9A, 0x78, 0x56, |
| 1857 0x34, 0x12, | 2088 0x34, 0x12, |
| 1858 // private flags | 2089 // private flags |
| 1859 0x01, | 2090 0x01, |
| 1860 // first fec protected packet offset | 2091 // first fec protected packet offset |
| 1861 0x01, | 2092 0x01, |
| 1862 | 2093 |
| 1863 // redundancy | 2094 // redundancy |
| 1864 'a', 'b', 'c', 'd', | 2095 'a', 'b', 'c', 'd', |
| 1865 'e', 'f', 'g', 'h', | 2096 'e', 'f', 'g', 'h', |
| 1866 'i', 'j', 'k', 'l', | 2097 'i', 'j', 'k', 'l', |
| 1867 'm', 'n', 'o', 'p', | 2098 'm', 'n', 'o', 'p', |
| 1868 }; | 2099 }; |
| 1869 | 2100 |
| 1870 scoped_ptr<QuicPacket> raw( | 2101 scoped_ptr<QuicPacket> raw( |
| 1871 QuicPacket::NewDataPacket(AsChars(packet), arraysize(packet), false)); | 2102 QuicPacket::NewDataPacket(AsChars(packet), arraysize(packet), false)); |
| 1872 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPacket(*raw)); | 2103 scoped_ptr<QuicEncryptedPacket> encrypted( |
| 2104 framer_.EncryptPacket(sequence_number, *raw)); |
| 1873 | 2105 |
| 1874 ASSERT_TRUE(encrypted.get() != NULL); | 2106 ASSERT_TRUE(encrypted.get() != NULL); |
| 1875 EXPECT_TRUE(CheckEncryption(StringPiece(AsChars(packet), arraysize(packet)))); | 2107 EXPECT_TRUE(CheckEncryption(sequence_number, |
| 2108 StringPiece(AsChars(packet), arraysize(packet)))); |
| 1876 } | 2109 } |
| 1877 | 2110 |
| 1878 // TODO(rch): re-enable after https://codereview.chromium.org/11820005/ | 2111 // TODO(rch): re-enable after https://codereview.chromium.org/11820005/ |
| 1879 // lands. Currently this is causing valgrind problems, but it should be | 2112 // lands. Currently this is causing valgrind problems, but it should be |
| 1880 // fixed in the followup CL. | 2113 // fixed in the followup CL. |
| 1881 TEST_F(QuicFramerTest, DISABLED_CalculateLargestReceived) { | 2114 TEST_F(QuicFramerTest, DISABLED_CalculateLargestReceived) { |
| 1882 SequenceSet missing; | 2115 SequenceNumberSet missing; |
| 1883 missing.insert(1); | 2116 missing.insert(1); |
| 1884 missing.insert(5); | 2117 missing.insert(5); |
| 1885 missing.insert(7); | 2118 missing.insert(7); |
| 1886 | 2119 |
| 1887 // These two we just walk to the next gap, and return the largest seen. | 2120 // These two we just walk to the next gap, and return the largest seen. |
| 1888 EXPECT_EQ(4u, QuicFramer::CalculateLargestObserved(missing, missing.find(1))); | 2121 EXPECT_EQ(4u, QuicFramer::CalculateLargestObserved(missing, missing.find(1))); |
| 1889 EXPECT_EQ(6u, QuicFramer::CalculateLargestObserved(missing, missing.find(5))); | 2122 EXPECT_EQ(6u, QuicFramer::CalculateLargestObserved(missing, missing.find(5))); |
| 1890 | 2123 |
| 1891 missing.insert(2); | 2124 missing.insert(2); |
| 1892 // For 1, we can't go forward as 2 would be implicitly acked so we return the | 2125 // For 1, we can't go forward as 2 would be implicitly acked so we return the |
| 1893 // largest missing packet. | 2126 // largest missing packet. |
| 1894 EXPECT_EQ(1u, QuicFramer::CalculateLargestObserved(missing, missing.find(1))); | 2127 EXPECT_EQ(1u, QuicFramer::CalculateLargestObserved(missing, missing.find(1))); |
| 1895 // For 2, we've seen 3 and 4, so can admit to a largest observed. | 2128 // For 2, we've seen 3 and 4, so can admit to a largest observed. |
| 1896 EXPECT_EQ(4u, QuicFramer::CalculateLargestObserved(missing, missing.find(2))); | 2129 EXPECT_EQ(4u, QuicFramer::CalculateLargestObserved(missing, missing.find(2))); |
| 1897 } | 2130 } |
| 1898 | 2131 |
| 1899 // TODO(rch) enable after landing the revised truncation CL. | 2132 // TODO(rch) enable after landing the revised truncation CL. |
| 1900 TEST_F(QuicFramerTest, DISABLED_Truncation) { | 2133 TEST_F(QuicFramerTest, DISABLED_Truncation) { |
| 1901 QuicPacketHeader header; | 2134 QuicPacketHeader header; |
| 1902 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); | 2135 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); |
| 1903 header.public_header.flags = PACKET_PUBLIC_FLAGS_NONE; | 2136 header.public_header.reset_flag = false; |
| 1904 header.private_flags = PACKET_PRIVATE_FLAGS_NONE; | 2137 header.public_header.version_flag = false; |
| 2138 header.fec_flag = false; |
| 2139 header.entropy_flag = false; |
| 2140 header.fec_entropy_flag = false; |
| 1905 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); | 2141 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); |
| 1906 header.fec_group = 0; | 2142 header.fec_group = 0; |
| 1907 | 2143 |
| 1908 QuicConnectionCloseFrame close_frame; | 2144 QuicConnectionCloseFrame close_frame; |
| 1909 QuicAckFrame* ack_frame = &close_frame.ack_frame; | 2145 QuicAckFrame* ack_frame = &close_frame.ack_frame; |
| 1910 close_frame.error_code = static_cast<QuicErrorCode>(0x05060708); | 2146 close_frame.error_code = static_cast<QuicErrorCode>(0x05060708); |
| 1911 close_frame.error_details = "because I can"; | 2147 close_frame.error_details = "because I can"; |
| 1912 ack_frame->received_info.largest_observed = 201; | 2148 ack_frame->received_info.largest_observed = 201; |
| 1913 ack_frame->sent_info.least_unacked = 0; | 2149 ack_frame->sent_info.least_unacked = 0; |
| 1914 for (uint64 i = 1; i < ack_frame->received_info.largest_observed; ++i) { | 2150 for (uint64 i = 1; i < ack_frame->received_info.largest_observed; ++i) { |
| 1915 ack_frame->received_info.missing_packets.insert(i); | 2151 ack_frame->received_info.missing_packets.insert(i); |
| 1916 } | 2152 } |
| 1917 | 2153 |
| 1918 // Create a packet with just the ack | 2154 // Create a packet with just the ack |
| 1919 QuicFrame frame; | 2155 QuicFrame frame; |
| 1920 frame.type = ACK_FRAME; | 2156 frame.type = ACK_FRAME; |
| 1921 frame.ack_frame = ack_frame; | 2157 frame.ack_frame = ack_frame; |
| 1922 QuicFrames frames; | 2158 QuicFrames frames; |
| 1923 frames.push_back(frame); | 2159 frames.push_back(frame); |
| 1924 | 2160 |
| 1925 scoped_ptr<QuicPacket> raw_ack_packet( | 2161 scoped_ptr<QuicPacket> raw_ack_packet( |
| 1926 framer_.ConstructFrameDataPacket(header, frames)); | 2162 framer_.ConstructFrameDataPacket(header, frames).packet); |
| 1927 ASSERT_TRUE(raw_ack_packet != NULL); | 2163 ASSERT_TRUE(raw_ack_packet != NULL); |
| 1928 | 2164 |
| 1929 scoped_ptr<QuicEncryptedPacket> ack_packet( | 2165 scoped_ptr<QuicEncryptedPacket> ack_packet( |
| 1930 framer_.EncryptPacket(*raw_ack_packet)); | 2166 framer_.EncryptPacket(header.packet_sequence_number, *raw_ack_packet)); |
| 1931 | 2167 |
| 1932 // Create a packet with just connection close. | 2168 // Create a packet with just connection close. |
| 1933 frames.clear(); | 2169 frames.clear(); |
| 1934 frame.type = CONNECTION_CLOSE_FRAME; | 2170 frame.type = CONNECTION_CLOSE_FRAME; |
| 1935 frame.connection_close_frame = &close_frame; | 2171 frame.connection_close_frame = &close_frame; |
| 1936 frames.push_back(frame); | 2172 frames.push_back(frame); |
| 1937 | 2173 |
| 1938 scoped_ptr<QuicPacket> raw_close_packet( | 2174 scoped_ptr<QuicPacket> raw_close_packet( |
| 1939 framer_.ConstructFrameDataPacket(header, frames)); | 2175 framer_.ConstructFrameDataPacket(header, frames).packet); |
| 1940 ASSERT_TRUE(raw_close_packet != NULL); | 2176 ASSERT_TRUE(raw_close_packet != NULL); |
| 1941 | 2177 |
| 1942 scoped_ptr<QuicEncryptedPacket> close_packet( | 2178 scoped_ptr<QuicEncryptedPacket> close_packet( |
| 1943 framer_.EncryptPacket(*raw_close_packet)); | 2179 framer_.EncryptPacket(header.packet_sequence_number, *raw_close_packet)); |
| 1944 | 2180 |
| 1945 // Now make sure we can turn our ack packet back into an ack frame | 2181 // Now make sure we can turn our ack packet back into an ack frame |
| 1946 ASSERT_TRUE(framer_.ProcessPacket(*ack_packet)); | 2182 ASSERT_TRUE(framer_.ProcessPacket(*ack_packet)); |
| 1947 | 2183 |
| 1948 // And do the same for the close frame. | 2184 // And do the same for the close frame. |
| 1949 ASSERT_TRUE(framer_.ProcessPacket(*close_packet)); | 2185 ASSERT_TRUE(framer_.ProcessPacket(*close_packet)); |
| 1950 } | 2186 } |
| 1951 | 2187 |
| 1952 TEST_F(QuicFramerTest, CleanTruncation) { | 2188 TEST_F(QuicFramerTest, CleanTruncation) { |
| 1953 QuicPacketHeader header; | 2189 QuicPacketHeader header; |
| 1954 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); | 2190 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); |
| 1955 header.public_header.flags = PACKET_PUBLIC_FLAGS_NONE; | 2191 header.public_header.reset_flag = false; |
| 1956 header.private_flags = PACKET_PRIVATE_FLAGS_NONE; | 2192 header.public_header.version_flag = false; |
| 2193 header.fec_flag = false; |
| 2194 header.entropy_flag = true; |
| 2195 header.fec_entropy_flag = false; |
| 1957 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); | 2196 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); |
| 1958 header.fec_group = 0; | 2197 header.fec_group = 0; |
| 1959 | 2198 |
| 1960 QuicConnectionCloseFrame close_frame; | 2199 QuicConnectionCloseFrame close_frame; |
| 1961 QuicAckFrame* ack_frame = &close_frame.ack_frame; | 2200 QuicAckFrame* ack_frame = &close_frame.ack_frame; |
| 1962 close_frame.error_code = static_cast<QuicErrorCode>(0x05060708); | 2201 close_frame.error_code = static_cast<QuicErrorCode>(0x05060708); |
| 1963 close_frame.error_details = "because I can"; | 2202 close_frame.error_details = "because I can"; |
| 1964 ack_frame->received_info.largest_observed = 201; | 2203 ack_frame->received_info.largest_observed = 201; |
| 1965 ack_frame->sent_info.least_unacked = 0; | 2204 ack_frame->sent_info.least_unacked = 0; |
| 1966 for (uint64 i = 1; i < ack_frame->received_info.largest_observed; ++i) { | 2205 for (uint64 i = 1; i < ack_frame->received_info.largest_observed; ++i) { |
| 1967 ack_frame->received_info.missing_packets.insert(i); | 2206 ack_frame->received_info.missing_packets.insert(i); |
| 1968 } | 2207 } |
| 1969 | 2208 |
| 1970 // Create a packet with just the ack | 2209 // Create a packet with just the ack |
| 1971 QuicFrame frame; | 2210 QuicFrame frame; |
| 1972 frame.type = ACK_FRAME; | 2211 frame.type = ACK_FRAME; |
| 1973 frame.ack_frame = ack_frame; | 2212 frame.ack_frame = ack_frame; |
| 1974 QuicFrames frames; | 2213 QuicFrames frames; |
| 1975 frames.push_back(frame); | 2214 frames.push_back(frame); |
| 1976 | 2215 |
| 1977 scoped_ptr<QuicPacket> raw_ack_packet( | 2216 scoped_ptr<QuicPacket> raw_ack_packet( |
| 1978 framer_.ConstructFrameDataPacket(header, frames)); | 2217 framer_.ConstructFrameDataPacket(header, frames).packet); |
| 1979 ASSERT_TRUE(raw_ack_packet != NULL); | 2218 ASSERT_TRUE(raw_ack_packet != NULL); |
| 1980 | 2219 |
| 1981 scoped_ptr<QuicEncryptedPacket> ack_packet( | 2220 scoped_ptr<QuicEncryptedPacket> ack_packet( |
| 1982 framer_.EncryptPacket(*raw_ack_packet)); | 2221 framer_.EncryptPacket(header.packet_sequence_number, *raw_ack_packet)); |
| 1983 | 2222 |
| 1984 // Create a packet with just connection close. | 2223 // Create a packet with just connection close. |
| 1985 frames.clear(); | 2224 frames.clear(); |
| 1986 frame.type = CONNECTION_CLOSE_FRAME; | 2225 frame.type = CONNECTION_CLOSE_FRAME; |
| 1987 frame.connection_close_frame = &close_frame; | 2226 frame.connection_close_frame = &close_frame; |
| 1988 frames.push_back(frame); | 2227 frames.push_back(frame); |
| 1989 | 2228 |
| 1990 scoped_ptr<QuicPacket> raw_close_packet( | 2229 scoped_ptr<QuicPacket> raw_close_packet( |
| 1991 framer_.ConstructFrameDataPacket(header, frames)); | 2230 framer_.ConstructFrameDataPacket(header, frames).packet); |
| 1992 ASSERT_TRUE(raw_close_packet != NULL); | 2231 ASSERT_TRUE(raw_close_packet != NULL); |
| 1993 | 2232 |
| 1994 scoped_ptr<QuicEncryptedPacket> close_packet( | 2233 scoped_ptr<QuicEncryptedPacket> close_packet( |
| 1995 framer_.EncryptPacket(*raw_close_packet)); | 2234 framer_.EncryptPacket(header.packet_sequence_number, *raw_close_packet)); |
| 1996 | 2235 |
| 1997 // Now make sure we can turn our ack packet back into an ack frame | 2236 // Now make sure we can turn our ack packet back into an ack frame |
| 1998 ASSERT_TRUE(framer_.ProcessPacket(*ack_packet)); | 2237 ASSERT_TRUE(framer_.ProcessPacket(*ack_packet)); |
| 1999 | 2238 |
| 2000 // And do the same for the close frame. | 2239 // And do the same for the close frame. |
| 2001 ASSERT_TRUE(framer_.ProcessPacket(*close_packet)); | 2240 ASSERT_TRUE(framer_.ProcessPacket(*close_packet)); |
| 2002 | 2241 |
| 2003 // Test for clean truncation of the ack by comparing the length of the | 2242 // Test for clean truncation of the ack by comparing the length of the |
| 2004 // original packets to the re-serialized packets. | 2243 // original packets to the re-serialized packets. |
| 2005 frames.clear(); | 2244 frames.clear(); |
| 2006 frame.type = ACK_FRAME; | 2245 frame.type = ACK_FRAME; |
| 2007 frame.ack_frame = visitor_.ack_frames_[0]; | 2246 frame.ack_frame = visitor_.ack_frames_[0]; |
| 2008 frames.push_back(frame); | 2247 frames.push_back(frame); |
| 2009 | 2248 |
| 2010 size_t original_raw_length = raw_ack_packet->length(); | 2249 size_t original_raw_length = raw_ack_packet->length(); |
| 2011 raw_ack_packet.reset( | 2250 raw_ack_packet.reset( |
| 2012 framer_.ConstructFrameDataPacket(header, frames)); | 2251 framer_.ConstructFrameDataPacket(header, frames).packet); |
| 2013 ASSERT_TRUE(raw_ack_packet != NULL); | 2252 ASSERT_TRUE(raw_ack_packet != NULL); |
| 2014 EXPECT_EQ(original_raw_length, raw_ack_packet->length()); | 2253 EXPECT_EQ(original_raw_length, raw_ack_packet->length()); |
| 2015 | 2254 |
| 2016 frames.clear(); | 2255 frames.clear(); |
| 2017 frame.type = CONNECTION_CLOSE_FRAME; | 2256 frame.type = CONNECTION_CLOSE_FRAME; |
| 2018 frame.connection_close_frame = &visitor_.connection_close_frame_; | 2257 frame.connection_close_frame = &visitor_.connection_close_frame_; |
| 2019 frames.push_back(frame); | 2258 frames.push_back(frame); |
| 2020 | 2259 |
| 2021 original_raw_length = raw_close_packet->length(); | 2260 original_raw_length = raw_close_packet->length(); |
| 2022 raw_close_packet.reset( | 2261 raw_close_packet.reset( |
| 2023 framer_.ConstructFrameDataPacket(header, frames)); | 2262 framer_.ConstructFrameDataPacket(header, frames).packet); |
| 2024 ASSERT_TRUE(raw_ack_packet != NULL); | 2263 ASSERT_TRUE(raw_ack_packet != NULL); |
| 2025 EXPECT_EQ(original_raw_length, raw_close_packet->length()); | 2264 EXPECT_EQ(original_raw_length, raw_close_packet->length()); |
| 2026 } | 2265 } |
| 2027 | 2266 |
| 2267 TEST_F(QuicFramerTest, EntropyFlagTest) { |
| 2268 unsigned char packet[] = { |
| 2269 // guid |
| 2270 0x10, 0x32, 0x54, 0x76, |
| 2271 0x98, 0xBA, 0xDC, 0xFE, |
| 2272 // public flags |
| 2273 0x00, |
| 2274 // packet sequence number |
| 2275 0xBC, 0x9A, 0x78, 0x56, |
| 2276 0x34, 0x12, |
| 2277 // Entropy |
| 2278 0x02, |
| 2279 // first fec protected packet offset |
| 2280 0xFF, |
| 2281 |
| 2282 // frame type (stream frame) |
| 2283 0x01, |
| 2284 // stream id |
| 2285 0x04, 0x03, 0x02, 0x01, |
| 2286 // fin |
| 2287 0x01, |
| 2288 // offset |
| 2289 0x54, 0x76, 0x10, 0x32, |
| 2290 0xDC, 0xFE, 0x98, 0xBA, |
| 2291 // data length |
| 2292 0x0c, 0x00, |
| 2293 // data |
| 2294 'h', 'e', 'l', 'l', |
| 2295 'o', ' ', 'w', 'o', |
| 2296 'r', 'l', 'd', '!', |
| 2297 }; |
| 2298 |
| 2299 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
| 2300 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 2301 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 2302 ASSERT_TRUE(visitor_.header_.get()); |
| 2303 EXPECT_TRUE(visitor_.header_->entropy_flag); |
| 2304 EXPECT_EQ(1 << 4, visitor_.header_->entropy_hash); |
| 2305 EXPECT_FALSE(visitor_.header_->fec_flag); |
| 2306 }; |
| 2307 |
| 2308 TEST_F(QuicFramerTest, FecEntropyFlagTest) { |
| 2309 unsigned char packet[] = { |
| 2310 // guid |
| 2311 0x10, 0x32, 0x54, 0x76, |
| 2312 0x98, 0xBA, 0xDC, 0xFE, |
| 2313 // public flags |
| 2314 0x00, |
| 2315 // packet sequence number |
| 2316 0xBC, 0x9A, 0x78, 0x56, |
| 2317 0x34, 0x12, |
| 2318 // Flags: Entropy, FEC-Entropy, FEC |
| 2319 0x07, |
| 2320 // first fec protected packet offset |
| 2321 0xFF, |
| 2322 |
| 2323 // frame type (stream frame) |
| 2324 0x01, |
| 2325 // stream id |
| 2326 0x04, 0x03, 0x02, 0x01, |
| 2327 // fin |
| 2328 0x01, |
| 2329 // offset |
| 2330 0x54, 0x76, 0x10, 0x32, |
| 2331 0xDC, 0xFE, 0x98, 0xBA, |
| 2332 // data length |
| 2333 0x0c, 0x00, |
| 2334 // data |
| 2335 'h', 'e', 'l', 'l', |
| 2336 'o', ' ', 'w', 'o', |
| 2337 'r', 'l', 'd', '!', |
| 2338 }; |
| 2339 |
| 2340 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
| 2341 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 2342 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 2343 ASSERT_TRUE(visitor_.header_.get()); |
| 2344 EXPECT_TRUE(visitor_.header_->fec_flag); |
| 2345 EXPECT_TRUE(visitor_.header_->entropy_flag); |
| 2346 EXPECT_TRUE(visitor_.header_->fec_entropy_flag); |
| 2347 EXPECT_EQ(1 << 4, visitor_.header_->entropy_hash); |
| 2348 }; |
| 2349 |
| 2028 } // namespace test | 2350 } // namespace test |
| 2029 } // namespace net | 2351 } // namespace net |
| OLD | NEW |