| 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 "net/quic/quic_connection.h" | 5 #include "net/quic/quic_connection.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 | 265 |
| 266 private: | 266 private: |
| 267 MockClock* clock_; | 267 MockClock* clock_; |
| 268 MockRandom* random_generator_; | 268 MockRandom* random_generator_; |
| 269 | 269 |
| 270 DISALLOW_COPY_AND_ASSIGN(TestConnectionHelper); | 270 DISALLOW_COPY_AND_ASSIGN(TestConnectionHelper); |
| 271 }; | 271 }; |
| 272 | 272 |
| 273 class TestPacketWriter : public QuicPacketWriter { | 273 class TestPacketWriter : public QuicPacketWriter { |
| 274 public: | 274 public: |
| 275 TestPacketWriter() | 275 explicit TestPacketWriter(QuicVersion version) |
| 276 : last_packet_size_(0), | 276 : version_(version), |
| 277 last_packet_size_(0), |
| 277 write_blocked_(false), | 278 write_blocked_(false), |
| 278 block_on_next_write_(false), | 279 block_on_next_write_(false), |
| 279 is_write_blocked_data_buffered_(false), | 280 is_write_blocked_data_buffered_(false), |
| 280 is_server_(true), | 281 is_server_(true), |
| 281 final_bytes_of_last_packet_(0), | 282 final_bytes_of_last_packet_(0), |
| 282 final_bytes_of_previous_packet_(0), | 283 final_bytes_of_previous_packet_(0), |
| 283 use_tagging_decrypter_(false), | 284 use_tagging_decrypter_(false), |
| 284 packets_write_attempts_(0) { | 285 packets_write_attempts_(0) { |
| 285 } | 286 } |
| 286 | 287 |
| 287 // QuicPacketWriter interface | 288 // QuicPacketWriter interface |
| 288 virtual WriteResult WritePacket( | 289 virtual WriteResult WritePacket( |
| 289 const char* buffer, size_t buf_len, | 290 const char* buffer, size_t buf_len, |
| 290 const IPAddressNumber& self_address, | 291 const IPAddressNumber& self_address, |
| 291 const IPEndPoint& peer_address) OVERRIDE { | 292 const IPEndPoint& peer_address) OVERRIDE { |
| 292 QuicEncryptedPacket packet(buffer, buf_len); | 293 QuicEncryptedPacket packet(buffer, buf_len); |
| 293 ++packets_write_attempts_; | 294 ++packets_write_attempts_; |
| 294 | 295 |
| 295 if (packet.length() >= sizeof(final_bytes_of_last_packet_)) { | 296 if (packet.length() >= sizeof(final_bytes_of_last_packet_)) { |
| 296 final_bytes_of_previous_packet_ = final_bytes_of_last_packet_; | 297 final_bytes_of_previous_packet_ = final_bytes_of_last_packet_; |
| 297 memcpy(&final_bytes_of_last_packet_, packet.data() + packet.length() - 4, | 298 memcpy(&final_bytes_of_last_packet_, packet.data() + packet.length() - 4, |
| 298 sizeof(final_bytes_of_last_packet_)); | 299 sizeof(final_bytes_of_last_packet_)); |
| 299 } | 300 } |
| 300 | 301 |
| 301 QuicFramer framer(QuicSupportedVersions(), QuicTime::Zero(), !is_server_); | 302 QuicFramer framer(SupportedVersions(version_), |
| 303 QuicTime::Zero(), !is_server_); |
| 302 if (use_tagging_decrypter_) { | 304 if (use_tagging_decrypter_) { |
| 303 framer.SetDecrypter(new TaggingDecrypter); | 305 framer.SetDecrypter(new TaggingDecrypter); |
| 304 } | 306 } |
| 305 visitor_.Reset(); | 307 visitor_.Reset(); |
| 306 framer.set_visitor(&visitor_); | 308 framer.set_visitor(&visitor_); |
| 307 EXPECT_TRUE(framer.ProcessPacket(packet)); | 309 EXPECT_TRUE(framer.ProcessPacket(packet)); |
| 308 if (block_on_next_write_) { | 310 if (block_on_next_write_) { |
| 309 write_blocked_ = true; | 311 write_blocked_ = true; |
| 310 block_on_next_write_ = false; | 312 block_on_next_write_ = false; |
| 311 } | 313 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 332 } | 334 } |
| 333 | 335 |
| 334 QuicPacketHeader* header() { return visitor_.header(); } | 336 QuicPacketHeader* header() { return visitor_.header(); } |
| 335 | 337 |
| 336 size_t frame_count() const { return visitor_.frame_count(); } | 338 size_t frame_count() const { return visitor_.frame_count(); } |
| 337 | 339 |
| 338 QuicAckFrame* ack() { return visitor_.ack(); } | 340 QuicAckFrame* ack() { return visitor_.ack(); } |
| 339 | 341 |
| 340 QuicCongestionFeedbackFrame* feedback() { return visitor_.feedback(); } | 342 QuicCongestionFeedbackFrame* feedback() { return visitor_.feedback(); } |
| 341 | 343 |
| 344 QuicStopWaitingFrame* stop_waiting() { return visitor_.stop_waiting(); } |
| 345 |
| 342 QuicConnectionCloseFrame* close() { return visitor_.close(); } | 346 QuicConnectionCloseFrame* close() { return visitor_.close(); } |
| 343 | 347 |
| 344 const vector<QuicStreamFrame>* stream_frames() const { | 348 const vector<QuicStreamFrame>* stream_frames() const { |
| 345 return visitor_.stream_frames(); | 349 return visitor_.stream_frames(); |
| 346 } | 350 } |
| 347 | 351 |
| 348 size_t last_packet_size() { | 352 size_t last_packet_size() { |
| 349 return last_packet_size_; | 353 return last_packet_size_; |
| 350 } | 354 } |
| 351 | 355 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 370 return final_bytes_of_previous_packet_; | 374 return final_bytes_of_previous_packet_; |
| 371 } | 375 } |
| 372 | 376 |
| 373 void use_tagging_decrypter() { | 377 void use_tagging_decrypter() { |
| 374 use_tagging_decrypter_ = true; | 378 use_tagging_decrypter_ = true; |
| 375 } | 379 } |
| 376 | 380 |
| 377 uint32 packets_write_attempts() { return packets_write_attempts_; } | 381 uint32 packets_write_attempts() { return packets_write_attempts_; } |
| 378 | 382 |
| 379 private: | 383 private: |
| 384 QuicVersion version_; |
| 380 FramerVisitorCapturingFrames visitor_; | 385 FramerVisitorCapturingFrames visitor_; |
| 381 size_t last_packet_size_; | 386 size_t last_packet_size_; |
| 382 bool write_blocked_; | 387 bool write_blocked_; |
| 383 bool block_on_next_write_; | 388 bool block_on_next_write_; |
| 384 bool is_write_blocked_data_buffered_; | 389 bool is_write_blocked_data_buffered_; |
| 385 bool is_server_; | 390 bool is_server_; |
| 386 uint32 final_bytes_of_last_packet_; | 391 uint32 final_bytes_of_last_packet_; |
| 387 uint32 final_bytes_of_previous_packet_; | 392 uint32 final_bytes_of_previous_packet_; |
| 388 bool use_tagging_decrypter_; | 393 bool use_tagging_decrypter_; |
| 389 uint32 packets_write_attempts_; | 394 uint32 packets_write_attempts_; |
| 390 | 395 |
| 391 DISALLOW_COPY_AND_ASSIGN(TestPacketWriter); | 396 DISALLOW_COPY_AND_ASSIGN(TestPacketWriter); |
| 392 }; | 397 }; |
| 393 | 398 |
| 394 class TestConnection : public QuicConnection { | 399 class TestConnection : public QuicConnection { |
| 395 public: | 400 public: |
| 396 TestConnection(QuicGuid guid, | 401 TestConnection(QuicGuid guid, |
| 397 IPEndPoint address, | 402 IPEndPoint address, |
| 398 TestConnectionHelper* helper, | 403 TestConnectionHelper* helper, |
| 399 TestPacketWriter* writer, | 404 TestPacketWriter* writer, |
| 400 bool is_server) | 405 bool is_server, |
| 406 QuicVersion version) |
| 401 : QuicConnection(guid, address, helper, writer, is_server, | 407 : QuicConnection(guid, address, helper, writer, is_server, |
| 402 QuicSupportedVersions()), | 408 SupportedVersions(version)), |
| 403 helper_(helper), | 409 helper_(helper), |
| 404 writer_(writer) { | 410 writer_(writer) { |
| 405 // Disable tail loss probes for most tests. | 411 // Disable tail loss probes for most tests. |
| 406 QuicSentPacketManagerPeer::SetMaxTailLossProbes( | 412 QuicSentPacketManagerPeer::SetMaxTailLossProbes( |
| 407 QuicConnectionPeer::GetSentPacketManager(this), 0); | 413 QuicConnectionPeer::GetSentPacketManager(this), 0); |
| 408 writer_->set_is_server(is_server); | 414 writer_->set_is_server(is_server); |
| 409 } | 415 } |
| 410 | 416 |
| 411 void SendAck() { | 417 void SendAck() { |
| 412 QuicConnectionPeer::SendAck(this); | 418 QuicConnectionPeer::SendAck(this); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 } | 480 } |
| 475 | 481 |
| 476 bool is_server() { | 482 bool is_server() { |
| 477 return QuicConnectionPeer::IsServer(this); | 483 return QuicConnectionPeer::IsServer(this); |
| 478 } | 484 } |
| 479 | 485 |
| 480 void set_version(QuicVersion version) { | 486 void set_version(QuicVersion version) { |
| 481 QuicConnectionPeer::GetFramer(this)->set_version(version); | 487 QuicConnectionPeer::GetFramer(this)->set_version(version); |
| 482 } | 488 } |
| 483 | 489 |
| 490 void SetSupportedVersions(const QuicVersionVector& versions) { |
| 491 QuicConnectionPeer::GetFramer(this)->SetSupportedVersions(versions); |
| 492 } |
| 493 |
| 484 void set_is_server(bool is_server) { | 494 void set_is_server(bool is_server) { |
| 485 writer_->set_is_server(is_server); | 495 writer_->set_is_server(is_server); |
| 486 QuicPacketCreatorPeer::SetIsServer( | 496 QuicPacketCreatorPeer::SetIsServer( |
| 487 QuicConnectionPeer::GetPacketCreator(this), is_server); | 497 QuicConnectionPeer::GetPacketCreator(this), is_server); |
| 488 QuicConnectionPeer::SetIsServer(this, is_server); | 498 QuicConnectionPeer::SetIsServer(this, is_server); |
| 489 } | 499 } |
| 490 | 500 |
| 491 TestConnectionHelper::TestAlarm* GetAckAlarm() { | 501 TestConnectionHelper::TestAlarm* GetAckAlarm() { |
| 492 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( | 502 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( |
| 493 QuicConnectionPeer::GetAckAlarm(this)); | 503 QuicConnectionPeer::GetAckAlarm(this)); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 515 | 525 |
| 516 using QuicConnection::SelectMutualVersion; | 526 using QuicConnection::SelectMutualVersion; |
| 517 | 527 |
| 518 private: | 528 private: |
| 519 TestConnectionHelper* helper_; | 529 TestConnectionHelper* helper_; |
| 520 TestPacketWriter* writer_; | 530 TestPacketWriter* writer_; |
| 521 | 531 |
| 522 DISALLOW_COPY_AND_ASSIGN(TestConnection); | 532 DISALLOW_COPY_AND_ASSIGN(TestConnection); |
| 523 }; | 533 }; |
| 524 | 534 |
| 525 class QuicConnectionTest : public ::testing::TestWithParam<bool> { | 535 class QuicConnectionTest : public ::testing::TestWithParam<QuicVersion> { |
| 526 protected: | 536 protected: |
| 527 QuicConnectionTest() | 537 QuicConnectionTest() |
| 528 : guid_(42), | 538 : guid_(42), |
| 529 framer_(QuicSupportedVersions(), QuicTime::Zero(), false), | 539 framer_(SupportedVersions(version()), QuicTime::Zero(), false), |
| 530 creator_(guid_, &framer_, &random_generator_, false), | 540 creator_(guid_, &framer_, &random_generator_, false), |
| 531 send_algorithm_(new StrictMock<MockSendAlgorithm>), | 541 send_algorithm_(new StrictMock<MockSendAlgorithm>), |
| 532 helper_(new TestConnectionHelper(&clock_, &random_generator_)), | 542 helper_(new TestConnectionHelper(&clock_, &random_generator_)), |
| 533 writer_(new TestPacketWriter()), | 543 writer_(new TestPacketWriter(version())), |
| 534 connection_(guid_, IPEndPoint(), helper_.get(), writer_.get(), false), | 544 connection_(guid_, IPEndPoint(), helper_.get(), writer_.get(), |
| 545 false, version()), |
| 535 frame1_(1, false, 0, MakeIOVector(data1)), | 546 frame1_(1, false, 0, MakeIOVector(data1)), |
| 536 frame2_(1, false, 3, MakeIOVector(data2)), | 547 frame2_(1, false, 3, MakeIOVector(data2)), |
| 537 accept_packet_(true) { | 548 accept_packet_(true) { |
| 538 connection_.set_visitor(&visitor_); | 549 connection_.set_visitor(&visitor_); |
| 539 connection_.SetSendAlgorithm(send_algorithm_); | 550 connection_.SetSendAlgorithm(send_algorithm_); |
| 540 framer_.set_received_entropy_calculator(&entropy_calculator_); | 551 framer_.set_received_entropy_calculator(&entropy_calculator_); |
| 541 // Simplify tests by not sending feedback unless specifically configured. | 552 // Simplify tests by not sending feedback unless specifically configured. |
| 542 SetFeedback(NULL); | 553 SetFeedback(NULL); |
| 543 EXPECT_CALL( | 554 EXPECT_CALL( |
| 544 *send_algorithm_, TimeUntilSend(_, _, _, _)).WillRepeatedly(Return( | 555 *send_algorithm_, TimeUntilSend(_, _, _, _)).WillRepeatedly(Return( |
| 545 QuicTime::Delta::Zero())); | 556 QuicTime::Delta::Zero())); |
| 546 EXPECT_CALL(*receive_algorithm_, | 557 EXPECT_CALL(*receive_algorithm_, |
| 547 RecordIncomingPacket(_, _, _)).Times(AnyNumber()); | 558 RecordIncomingPacket(_, _, _)).Times(AnyNumber()); |
| 548 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 559 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
| 549 .Times(AnyNumber()); | 560 .Times(AnyNumber()); |
| 550 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly( | 561 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly( |
| 551 Return(QuicTime::Delta::Zero())); | 562 Return(QuicTime::Delta::Zero())); |
| 552 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillRepeatedly(Return( | 563 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillRepeatedly(Return( |
| 553 QuicBandwidth::FromKBitsPerSecond(100))); | 564 QuicBandwidth::FromKBitsPerSecond(100))); |
| 554 EXPECT_CALL(*send_algorithm_, SmoothedRtt()).WillRepeatedly(Return( | 565 EXPECT_CALL(*send_algorithm_, SmoothedRtt()).WillRepeatedly(Return( |
| 555 QuicTime::Delta::FromMilliseconds(100))); | 566 QuicTime::Delta::FromMilliseconds(100))); |
| 556 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 567 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
| 557 .WillByDefault(Return(true)); | 568 .WillByDefault(Return(true)); |
| 558 EXPECT_CALL(visitor_, HasPendingWrites()).Times(AnyNumber()); | 569 EXPECT_CALL(visitor_, HasPendingWrites()).Times(AnyNumber()); |
| 559 EXPECT_CALL(visitor_, HasPendingHandshake()).Times(AnyNumber()); | 570 EXPECT_CALL(visitor_, HasPendingHandshake()).Times(AnyNumber()); |
| 560 EXPECT_CALL(visitor_, OnCanWrite()).Times(AnyNumber()); | 571 EXPECT_CALL(visitor_, OnCanWrite()).Times(AnyNumber()); |
| 561 } | 572 } |
| 562 | 573 |
| 574 QuicVersion version() { |
| 575 return GetParam(); |
| 576 } |
| 577 |
| 563 QuicAckFrame* outgoing_ack() { | 578 QuicAckFrame* outgoing_ack() { |
| 564 outgoing_ack_.reset(QuicConnectionPeer::CreateAckFrame(&connection_)); | 579 outgoing_ack_.reset(QuicConnectionPeer::CreateAckFrame(&connection_)); |
| 565 return outgoing_ack_.get(); | 580 return outgoing_ack_.get(); |
| 566 } | 581 } |
| 567 | 582 |
| 583 QuicPacketSequenceNumber least_unacked() { |
| 584 if (version() <= QUIC_VERSION_15) { |
| 585 QuicAckFrame* ack = last_ack(); |
| 586 if (ack == NULL) { |
| 587 return 0; |
| 588 } |
| 589 return ack->sent_info.least_unacked; |
| 590 } |
| 591 QuicStopWaitingFrame* stop_waiting = last_stop_waiting(); |
| 592 if (stop_waiting == NULL) { |
| 593 return 0; |
| 594 } |
| 595 return stop_waiting->least_unacked; |
| 596 } |
| 597 |
| 568 QuicAckFrame* last_ack() { | 598 QuicAckFrame* last_ack() { |
| 569 return writer_->ack(); | 599 return writer_->ack(); |
| 570 } | 600 } |
| 571 | 601 |
| 572 QuicCongestionFeedbackFrame* last_feedback() { | 602 QuicCongestionFeedbackFrame* last_feedback() { |
| 573 return writer_->feedback(); | 603 return writer_->feedback(); |
| 574 } | 604 } |
| 575 | 605 |
| 606 QuicStopWaitingFrame* last_stop_waiting() { |
| 607 return writer_->stop_waiting(); |
| 608 } |
| 609 |
| 576 QuicConnectionCloseFrame* last_close() { | 610 QuicConnectionCloseFrame* last_close() { |
| 577 return writer_->close(); | 611 return writer_->close(); |
| 578 } | 612 } |
| 579 | 613 |
| 580 QuicPacketHeader* last_header() { | 614 QuicPacketHeader* last_header() { |
| 581 return writer_->header(); | 615 return writer_->header(); |
| 582 } | 616 } |
| 583 | 617 |
| 584 size_t last_sent_packet_size() { | 618 size_t last_sent_packet_size() { |
| 585 return writer_->last_packet_size(); | 619 return writer_->last_packet_size(); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 764 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
| 731 connection_.SendAck(); | 765 connection_.SendAck(); |
| 732 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 766 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
| 733 .Times(AnyNumber()); | 767 .Times(AnyNumber()); |
| 734 } | 768 } |
| 735 | 769 |
| 736 QuicPacketEntropyHash ProcessAckPacket(QuicAckFrame* frame) { | 770 QuicPacketEntropyHash ProcessAckPacket(QuicAckFrame* frame) { |
| 737 return ProcessFramePacket(QuicFrame(frame)); | 771 return ProcessFramePacket(QuicFrame(frame)); |
| 738 } | 772 } |
| 739 | 773 |
| 774 QuicPacketEntropyHash ProcessStopWaitingPacket(QuicStopWaitingFrame* frame) { |
| 775 return ProcessFramePacket(QuicFrame(frame)); |
| 776 } |
| 777 |
| 740 QuicPacketEntropyHash ProcessGoAwayPacket(QuicGoAwayFrame* frame) { | 778 QuicPacketEntropyHash ProcessGoAwayPacket(QuicGoAwayFrame* frame) { |
| 741 return ProcessFramePacket(QuicFrame(frame)); | 779 return ProcessFramePacket(QuicFrame(frame)); |
| 742 } | 780 } |
| 743 | 781 |
| 744 bool IsMissing(QuicPacketSequenceNumber number) { | 782 bool IsMissing(QuicPacketSequenceNumber number) { |
| 745 return IsAwaitingPacket(outgoing_ack()->received_info, number); | 783 return IsAwaitingPacket(outgoing_ack()->received_info, number); |
| 746 } | 784 } |
| 747 | 785 |
| 748 QuicPacket* ConstructDataPacket(QuicPacketSequenceNumber number, | 786 QuicPacket* ConstructDataPacket(QuicPacketSequenceNumber number, |
| 749 QuicFecGroupNumber fec_group, | 787 QuicFecGroupNumber fec_group, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 const QuicAckFrame InitAckFrame(QuicPacketSequenceNumber largest_observed, | 844 const QuicAckFrame InitAckFrame(QuicPacketSequenceNumber largest_observed, |
| 807 QuicPacketSequenceNumber least_unacked) { | 845 QuicPacketSequenceNumber least_unacked) { |
| 808 QuicAckFrame frame(largest_observed, QuicTime::Zero(), least_unacked); | 846 QuicAckFrame frame(largest_observed, QuicTime::Zero(), least_unacked); |
| 809 if (largest_observed > 0) { | 847 if (largest_observed > 0) { |
| 810 frame.received_info.entropy_hash = | 848 frame.received_info.entropy_hash = |
| 811 QuicConnectionPeer::GetSentEntropyHash(&connection_, largest_observed); | 849 QuicConnectionPeer::GetSentEntropyHash(&connection_, largest_observed); |
| 812 } | 850 } |
| 813 return frame; | 851 return frame; |
| 814 } | 852 } |
| 815 | 853 |
| 854 const QuicStopWaitingFrame InitStopWaitingFrame( |
| 855 QuicPacketSequenceNumber least_unacked) { |
| 856 QuicStopWaitingFrame frame; |
| 857 frame.least_unacked = least_unacked; |
| 858 return frame; |
| 859 } |
| 816 // Explicitly nack a packet. | 860 // Explicitly nack a packet. |
| 817 void NackPacket(QuicPacketSequenceNumber missing, QuicAckFrame* frame) { | 861 void NackPacket(QuicPacketSequenceNumber missing, QuicAckFrame* frame) { |
| 818 frame->received_info.missing_packets.insert(missing); | 862 frame->received_info.missing_packets.insert(missing); |
| 819 frame->received_info.entropy_hash ^= | 863 frame->received_info.entropy_hash ^= |
| 820 QuicConnectionPeer::GetSentEntropyHash(&connection_, missing); | 864 QuicConnectionPeer::GetSentEntropyHash(&connection_, missing); |
| 821 if (missing > 1) { | 865 if (missing > 1) { |
| 822 frame->received_info.entropy_hash ^= | 866 frame->received_info.entropy_hash ^= |
| 823 QuicConnectionPeer::GetSentEntropyHash(&connection_, missing - 1); | 867 QuicConnectionPeer::GetSentEntropyHash(&connection_, missing - 1); |
| 824 } | 868 } |
| 825 } | 869 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 869 QuicPacketHeader header_; | 913 QuicPacketHeader header_; |
| 870 QuicStreamFrame frame1_; | 914 QuicStreamFrame frame1_; |
| 871 QuicStreamFrame frame2_; | 915 QuicStreamFrame frame2_; |
| 872 scoped_ptr<QuicAckFrame> outgoing_ack_; | 916 scoped_ptr<QuicAckFrame> outgoing_ack_; |
| 873 bool accept_packet_; | 917 bool accept_packet_; |
| 874 | 918 |
| 875 private: | 919 private: |
| 876 DISALLOW_COPY_AND_ASSIGN(QuicConnectionTest); | 920 DISALLOW_COPY_AND_ASSIGN(QuicConnectionTest); |
| 877 }; | 921 }; |
| 878 | 922 |
| 879 TEST_F(QuicConnectionTest, PacketsInOrder) { | 923 // Run all end to end tests with all supported versions. |
| 924 INSTANTIATE_TEST_CASE_P(SupportedVersion, |
| 925 QuicConnectionTest, |
| 926 ::testing::ValuesIn(QuicSupportedVersions())); |
| 927 |
| 928 TEST_P(QuicConnectionTest, PacketsInOrder) { |
| 880 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 929 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 881 | 930 |
| 882 ProcessPacket(1); | 931 ProcessPacket(1); |
| 883 EXPECT_EQ(1u, outgoing_ack()->received_info.largest_observed); | 932 EXPECT_EQ(1u, outgoing_ack()->received_info.largest_observed); |
| 884 EXPECT_EQ(0u, outgoing_ack()->received_info.missing_packets.size()); | 933 EXPECT_EQ(0u, outgoing_ack()->received_info.missing_packets.size()); |
| 885 | 934 |
| 886 ProcessPacket(2); | 935 ProcessPacket(2); |
| 887 EXPECT_EQ(2u, outgoing_ack()->received_info.largest_observed); | 936 EXPECT_EQ(2u, outgoing_ack()->received_info.largest_observed); |
| 888 EXPECT_EQ(0u, outgoing_ack()->received_info.missing_packets.size()); | 937 EXPECT_EQ(0u, outgoing_ack()->received_info.missing_packets.size()); |
| 889 | 938 |
| 890 ProcessPacket(3); | 939 ProcessPacket(3); |
| 891 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); | 940 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); |
| 892 EXPECT_EQ(0u, outgoing_ack()->received_info.missing_packets.size()); | 941 EXPECT_EQ(0u, outgoing_ack()->received_info.missing_packets.size()); |
| 893 } | 942 } |
| 894 | 943 |
| 895 TEST_F(QuicConnectionTest, PacketsRejected) { | 944 TEST_P(QuicConnectionTest, PacketsRejected) { |
| 896 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 945 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 897 | 946 |
| 898 ProcessPacket(1); | 947 ProcessPacket(1); |
| 899 EXPECT_EQ(1u, outgoing_ack()->received_info.largest_observed); | 948 EXPECT_EQ(1u, outgoing_ack()->received_info.largest_observed); |
| 900 EXPECT_EQ(0u, outgoing_ack()->received_info.missing_packets.size()); | 949 EXPECT_EQ(0u, outgoing_ack()->received_info.missing_packets.size()); |
| 901 | 950 |
| 902 accept_packet_ = false; | 951 accept_packet_ = false; |
| 903 ProcessPacket(2); | 952 ProcessPacket(2); |
| 904 // We should not have an ack for two. | 953 // We should not have an ack for two. |
| 905 EXPECT_EQ(1u, outgoing_ack()->received_info.largest_observed); | 954 EXPECT_EQ(1u, outgoing_ack()->received_info.largest_observed); |
| 906 EXPECT_EQ(0u, outgoing_ack()->received_info.missing_packets.size()); | 955 EXPECT_EQ(0u, outgoing_ack()->received_info.missing_packets.size()); |
| 907 } | 956 } |
| 908 | 957 |
| 909 TEST_F(QuicConnectionTest, PacketsOutOfOrder) { | 958 TEST_P(QuicConnectionTest, PacketsOutOfOrder) { |
| 910 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 959 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 911 | 960 |
| 912 ProcessPacket(3); | 961 ProcessPacket(3); |
| 913 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); | 962 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); |
| 914 EXPECT_TRUE(IsMissing(2)); | 963 EXPECT_TRUE(IsMissing(2)); |
| 915 EXPECT_TRUE(IsMissing(1)); | 964 EXPECT_TRUE(IsMissing(1)); |
| 916 | 965 |
| 917 ProcessPacket(2); | 966 ProcessPacket(2); |
| 918 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); | 967 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); |
| 919 EXPECT_FALSE(IsMissing(2)); | 968 EXPECT_FALSE(IsMissing(2)); |
| 920 EXPECT_TRUE(IsMissing(1)); | 969 EXPECT_TRUE(IsMissing(1)); |
| 921 | 970 |
| 922 ProcessPacket(1); | 971 ProcessPacket(1); |
| 923 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); | 972 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); |
| 924 EXPECT_FALSE(IsMissing(2)); | 973 EXPECT_FALSE(IsMissing(2)); |
| 925 EXPECT_FALSE(IsMissing(1)); | 974 EXPECT_FALSE(IsMissing(1)); |
| 926 } | 975 } |
| 927 | 976 |
| 928 TEST_F(QuicConnectionTest, DuplicatePacket) { | 977 TEST_P(QuicConnectionTest, DuplicatePacket) { |
| 929 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 978 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 930 | 979 |
| 931 ProcessPacket(3); | 980 ProcessPacket(3); |
| 932 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); | 981 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); |
| 933 EXPECT_TRUE(IsMissing(2)); | 982 EXPECT_TRUE(IsMissing(2)); |
| 934 EXPECT_TRUE(IsMissing(1)); | 983 EXPECT_TRUE(IsMissing(1)); |
| 935 | 984 |
| 936 // Send packet 3 again, but do not set the expectation that | 985 // Send packet 3 again, but do not set the expectation that |
| 937 // the visitor OnStreamFrames() will be called. | 986 // the visitor OnStreamFrames() will be called. |
| 938 ProcessDataPacket(3, 0, !kEntropyFlag); | 987 ProcessDataPacket(3, 0, !kEntropyFlag); |
| 939 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); | 988 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); |
| 940 EXPECT_TRUE(IsMissing(2)); | 989 EXPECT_TRUE(IsMissing(2)); |
| 941 EXPECT_TRUE(IsMissing(1)); | 990 EXPECT_TRUE(IsMissing(1)); |
| 942 } | 991 } |
| 943 | 992 |
| 944 TEST_F(QuicConnectionTest, PacketsOutOfOrderWithAdditionsAndLeastAwaiting) { | 993 TEST_P(QuicConnectionTest, PacketsOutOfOrderWithAdditionsAndLeastAwaiting) { |
| 945 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 994 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 946 | 995 |
| 947 ProcessPacket(3); | 996 ProcessPacket(3); |
| 948 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); | 997 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); |
| 949 EXPECT_TRUE(IsMissing(2)); | 998 EXPECT_TRUE(IsMissing(2)); |
| 950 EXPECT_TRUE(IsMissing(1)); | 999 EXPECT_TRUE(IsMissing(1)); |
| 951 | 1000 |
| 952 ProcessPacket(2); | 1001 ProcessPacket(2); |
| 953 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); | 1002 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); |
| 954 EXPECT_TRUE(IsMissing(1)); | 1003 EXPECT_TRUE(IsMissing(1)); |
| 955 | 1004 |
| 956 ProcessPacket(5); | 1005 ProcessPacket(5); |
| 957 EXPECT_EQ(5u, outgoing_ack()->received_info.largest_observed); | 1006 EXPECT_EQ(5u, outgoing_ack()->received_info.largest_observed); |
| 958 EXPECT_TRUE(IsMissing(1)); | 1007 EXPECT_TRUE(IsMissing(1)); |
| 959 EXPECT_TRUE(IsMissing(4)); | 1008 EXPECT_TRUE(IsMissing(4)); |
| 960 | 1009 |
| 961 // Pretend at this point the client has gotten acks for 2 and 3 and 1 is a | 1010 // Pretend at this point the client has gotten acks for 2 and 3 and 1 is a |
| 962 // packet the peer will not retransmit. It indicates this by sending 'least | 1011 // packet the peer will not retransmit. It indicates this by sending 'least |
| 963 // awaiting' is 4. The connection should then realize 1 will not be | 1012 // awaiting' is 4. The connection should then realize 1 will not be |
| 964 // retransmitted, and will remove it from the missing list. | 1013 // retransmitted, and will remove it from the missing list. |
| 965 creator_.set_sequence_number(5); | 1014 creator_.set_sequence_number(5); |
| 966 QuicAckFrame frame = InitAckFrame(0, 4); | 1015 QuicAckFrame frame = InitAckFrame(0, 4); |
| 967 ProcessAckPacket(&frame); | 1016 ProcessAckPacket(&frame); |
| 968 | 1017 |
| 969 // Force an ack to be sent. | 1018 // Force an ack to be sent. |
| 970 SendAckPacketToPeer(); | 1019 SendAckPacketToPeer(); |
| 971 EXPECT_TRUE(IsMissing(4)); | 1020 EXPECT_TRUE(IsMissing(4)); |
| 972 } | 1021 } |
| 973 | 1022 |
| 974 TEST_F(QuicConnectionTest, RejectPacketTooFarOut) { | 1023 TEST_P(QuicConnectionTest, RejectPacketTooFarOut) { |
| 975 EXPECT_CALL(visitor_, | 1024 EXPECT_CALL(visitor_, |
| 976 OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false)); | 1025 OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false)); |
| 977 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a | 1026 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a |
| 978 // packet call to the visitor. | 1027 // packet call to the visitor. |
| 979 ProcessDataPacket(6000, 0, !kEntropyFlag); | 1028 ProcessDataPacket(6000, 0, !kEntropyFlag); |
| 980 EXPECT_FALSE( | 1029 EXPECT_FALSE( |
| 981 QuicConnectionPeer::GetConnectionClosePacket(&connection_) == NULL); | 1030 QuicConnectionPeer::GetConnectionClosePacket(&connection_) == NULL); |
| 982 } | 1031 } |
| 983 | 1032 |
| 984 TEST_F(QuicConnectionTest, TruncatedAck) { | 1033 TEST_P(QuicConnectionTest, TruncatedAck) { |
| 985 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1034 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 986 QuicPacketSequenceNumber num_packets = 256 * 2 + 1; | 1035 QuicPacketSequenceNumber num_packets = 256 * 2 + 1; |
| 987 for (QuicPacketSequenceNumber i = 0; i < num_packets; ++i) { | 1036 for (QuicPacketSequenceNumber i = 0; i < num_packets; ++i) { |
| 988 SendStreamDataToPeer(3, "foo", i * 3, !kFin, NULL); | 1037 SendStreamDataToPeer(3, "foo", i * 3, !kFin, NULL); |
| 989 } | 1038 } |
| 990 | 1039 |
| 991 QuicAckFrame frame = InitAckFrame(num_packets, 1); | 1040 QuicAckFrame frame = InitAckFrame(num_packets, 1); |
| 992 // Create an ack with 256 nacks, none adjacent to one another. | 1041 // Create an ack with 256 nacks, none adjacent to one another. |
| 993 for (QuicPacketSequenceNumber i = 1; i <= 256; ++i) { | 1042 for (QuicPacketSequenceNumber i = 1; i <= 256; ++i) { |
| 994 NackPacket(i * 2, &frame); | 1043 NackPacket(i * 2, &frame); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1011 | 1060 |
| 1012 // Removing one missing packet allows us to ack 192 and one more range, but | 1061 // Removing one missing packet allows us to ack 192 and one more range, but |
| 1013 // 192 has already been declared lost, so it doesn't register as an ack. | 1062 // 192 has already been declared lost, so it doesn't register as an ack. |
| 1014 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); | 1063 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); |
| 1015 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(1); | 1064 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(1); |
| 1016 ProcessAckPacket(&frame); | 1065 ProcessAckPacket(&frame); |
| 1017 EXPECT_EQ(num_packets, | 1066 EXPECT_EQ(num_packets, |
| 1018 received_packet_manager->peer_largest_observed_packet()); | 1067 received_packet_manager->peer_largest_observed_packet()); |
| 1019 } | 1068 } |
| 1020 | 1069 |
| 1021 TEST_F(QuicConnectionTest, AckReceiptCausesAckSendBadEntropy) { | 1070 TEST_P(QuicConnectionTest, AckReceiptCausesAckSendBadEntropy) { |
| 1022 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1071 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1023 | 1072 |
| 1024 ProcessPacket(1); | 1073 ProcessPacket(1); |
| 1025 // Delay sending, then queue up an ack. | 1074 // Delay sending, then queue up an ack. |
| 1026 EXPECT_CALL(*send_algorithm_, | 1075 EXPECT_CALL(*send_algorithm_, |
| 1027 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( | 1076 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( |
| 1028 testing::Return(QuicTime::Delta::FromMicroseconds(1))); | 1077 testing::Return(QuicTime::Delta::FromMicroseconds(1))); |
| 1029 QuicConnectionPeer::SendAck(&connection_); | 1078 QuicConnectionPeer::SendAck(&connection_); |
| 1030 | 1079 |
| 1031 // Process an ack with a least unacked of the received ack. | 1080 // Process an ack with a least unacked of the received ack. |
| 1032 // This causes an ack to be sent when TimeUntilSend returns 0. | 1081 // This causes an ack to be sent when TimeUntilSend returns 0. |
| 1033 EXPECT_CALL(*send_algorithm_, | 1082 EXPECT_CALL(*send_algorithm_, |
| 1034 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillRepeatedly( | 1083 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillRepeatedly( |
| 1035 testing::Return(QuicTime::Delta::Zero())); | 1084 testing::Return(QuicTime::Delta::Zero())); |
| 1036 // Skip a packet and then record an ack. | 1085 // Skip a packet and then record an ack. |
| 1037 creator_.set_sequence_number(2); | 1086 creator_.set_sequence_number(2); |
| 1038 QuicAckFrame frame = InitAckFrame(0, 3); | 1087 QuicAckFrame frame = InitAckFrame(0, 3); |
| 1039 ProcessAckPacket(&frame); | 1088 ProcessAckPacket(&frame); |
| 1040 } | 1089 } |
| 1041 | 1090 |
| 1042 TEST_F(QuicConnectionTest, OutOfOrderReceiptCausesAckSend) { | 1091 TEST_P(QuicConnectionTest, OutOfOrderReceiptCausesAckSend) { |
| 1043 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1092 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1044 | 1093 |
| 1045 ProcessPacket(3); | 1094 ProcessPacket(3); |
| 1046 // Should ack immediately since we have missing packets. | 1095 // Should ack immediately since we have missing packets. |
| 1047 EXPECT_EQ(1u, writer_->packets_write_attempts()); | 1096 EXPECT_EQ(1u, writer_->packets_write_attempts()); |
| 1048 | 1097 |
| 1049 ProcessPacket(2); | 1098 ProcessPacket(2); |
| 1050 // Should ack immediately since we have missing packets. | 1099 // Should ack immediately since we have missing packets. |
| 1051 EXPECT_EQ(2u, writer_->packets_write_attempts()); | 1100 EXPECT_EQ(2u, writer_->packets_write_attempts()); |
| 1052 | 1101 |
| 1053 ProcessPacket(1); | 1102 ProcessPacket(1); |
| 1054 // Should ack immediately, since this fills the last hole. | 1103 // Should ack immediately, since this fills the last hole. |
| 1055 EXPECT_EQ(3u, writer_->packets_write_attempts()); | 1104 EXPECT_EQ(3u, writer_->packets_write_attempts()); |
| 1056 | 1105 |
| 1057 ProcessPacket(4); | 1106 ProcessPacket(4); |
| 1058 // Should not cause an ack. | 1107 // Should not cause an ack. |
| 1059 EXPECT_EQ(3u, writer_->packets_write_attempts()); | 1108 EXPECT_EQ(3u, writer_->packets_write_attempts()); |
| 1060 } | 1109 } |
| 1061 | 1110 |
| 1062 TEST_F(QuicConnectionTest, AckReceiptCausesAckSend) { | 1111 TEST_P(QuicConnectionTest, AckReceiptCausesAckSend) { |
| 1063 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1112 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1064 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(1); | 1113 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(1); |
| 1065 QuicPacketSequenceNumber original; | 1114 QuicPacketSequenceNumber original; |
| 1066 QuicByteCount packet_size; | 1115 QuicByteCount packet_size; |
| 1067 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)) | 1116 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)) |
| 1068 .WillOnce(DoAll(SaveArg<1>(&original), SaveArg<2>(&packet_size), | 1117 .WillOnce(DoAll(SaveArg<1>(&original), SaveArg<2>(&packet_size), |
| 1069 Return(true))); | 1118 Return(true))); |
| 1070 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(1, _)).Times(1); | 1119 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(1, _)).Times(1); |
| 1071 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); | 1120 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); |
| 1072 QuicAckFrame frame = InitAckFrame(original, 1); | 1121 QuicAckFrame frame = InitAckFrame(original, 1); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1096 // No ack sent. | 1145 // No ack sent. |
| 1097 EXPECT_EQ(1u, writer_->frame_count()); | 1146 EXPECT_EQ(1u, writer_->frame_count()); |
| 1098 EXPECT_EQ(1u, writer_->stream_frames()->size()); | 1147 EXPECT_EQ(1u, writer_->stream_frames()->size()); |
| 1099 writer_->Reset(); | 1148 writer_->Reset(); |
| 1100 | 1149 |
| 1101 ProcessAckPacket(&frame2); | 1150 ProcessAckPacket(&frame2); |
| 1102 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, | 1151 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, |
| 1103 HAS_RETRANSMITTABLE_DATA)); | 1152 HAS_RETRANSMITTABLE_DATA)); |
| 1104 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL); | 1153 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL); |
| 1105 // Ack bundled. | 1154 // Ack bundled. |
| 1106 EXPECT_EQ(2u, writer_->frame_count()); | 1155 if (version() > QUIC_VERSION_15) { |
| 1156 EXPECT_EQ(3u, writer_->frame_count()); |
| 1157 } else { |
| 1158 EXPECT_EQ(2u, writer_->frame_count()); |
| 1159 } |
| 1107 EXPECT_EQ(1u, writer_->stream_frames()->size()); | 1160 EXPECT_EQ(1u, writer_->stream_frames()->size()); |
| 1108 EXPECT_TRUE(writer_->ack()); | 1161 EXPECT_TRUE(writer_->ack()); |
| 1109 | 1162 |
| 1110 // But an ack with no missing packets will not send an ack. | 1163 // But an ack with no missing packets will not send an ack. |
| 1111 AckPacket(original, &frame2); | 1164 AckPacket(original, &frame2); |
| 1112 ProcessAckPacket(&frame2); | 1165 ProcessAckPacket(&frame2); |
| 1113 ProcessAckPacket(&frame2); | 1166 ProcessAckPacket(&frame2); |
| 1114 } | 1167 } |
| 1115 | 1168 |
| 1116 TEST_F(QuicConnectionTest, LeastUnackedLower) { | 1169 TEST_P(QuicConnectionTest, LeastUnackedLower) { |
| 1117 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1170 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1118 | 1171 |
| 1119 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); | 1172 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); |
| 1120 SendStreamDataToPeer(1, "bar", 3, !kFin, NULL); | 1173 SendStreamDataToPeer(1, "bar", 3, !kFin, NULL); |
| 1121 SendStreamDataToPeer(1, "eep", 6, !kFin, NULL); | 1174 SendStreamDataToPeer(1, "eep", 6, !kFin, NULL); |
| 1122 | 1175 |
| 1123 // Start out saying the least unacked is 2. | 1176 // Start out saying the least unacked is 2. |
| 1124 creator_.set_sequence_number(5); | 1177 creator_.set_sequence_number(5); |
| 1125 QuicAckFrame frame = InitAckFrame(0, 2); | 1178 if (version() > QUIC_VERSION_15) { |
| 1126 ProcessAckPacket(&frame); | 1179 QuicStopWaitingFrame frame = InitStopWaitingFrame(2); |
| 1180 ProcessStopWaitingPacket(&frame); |
| 1181 } else { |
| 1182 QuicAckFrame frame = InitAckFrame(0, 2); |
| 1183 ProcessAckPacket(&frame); |
| 1184 } |
| 1127 | 1185 |
| 1128 // Change it to 1, but lower the sequence number to fake out-of-order packets. | 1186 // Change it to 1, but lower the sequence number to fake out-of-order packets. |
| 1129 // This should be fine. | 1187 // This should be fine. |
| 1130 creator_.set_sequence_number(1); | 1188 creator_.set_sequence_number(1); |
| 1131 QuicAckFrame frame2 = InitAckFrame(0, 1); | |
| 1132 // The scheduler will not process out of order acks, but all packet processing | 1189 // The scheduler will not process out of order acks, but all packet processing |
| 1133 // causes the connection to try to write. | 1190 // causes the connection to try to write. |
| 1134 EXPECT_CALL(visitor_, OnCanWrite()); | 1191 EXPECT_CALL(visitor_, OnCanWrite()); |
| 1135 ProcessAckPacket(&frame2); | 1192 if (version() > QUIC_VERSION_15) { |
| 1193 QuicStopWaitingFrame frame2 = InitStopWaitingFrame(1); |
| 1194 ProcessStopWaitingPacket(&frame2); |
| 1195 } else { |
| 1196 QuicAckFrame frame2 = InitAckFrame(0, 1); |
| 1197 ProcessAckPacket(&frame2); |
| 1198 } |
| 1136 | 1199 |
| 1137 // Now claim it's one, but set the ordering so it was sent "after" the first | 1200 // Now claim it's one, but set the ordering so it was sent "after" the first |
| 1138 // one. This should cause a connection error. | 1201 // one. This should cause a connection error. |
| 1139 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_ACK_DATA, false)); | |
| 1140 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 1202 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| 1141 creator_.set_sequence_number(7); | 1203 creator_.set_sequence_number(7); |
| 1142 ProcessAckPacket(&frame2); | 1204 if (version() > QUIC_VERSION_15) { |
| 1205 EXPECT_CALL(visitor_, |
| 1206 OnConnectionClosed(QUIC_INVALID_STOP_WAITING_DATA, false)); |
| 1207 QuicStopWaitingFrame frame2 = InitStopWaitingFrame(1); |
| 1208 ProcessStopWaitingPacket(&frame2); |
| 1209 } else { |
| 1210 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_ACK_DATA, false)); |
| 1211 QuicAckFrame frame2 = InitAckFrame(0, 1); |
| 1212 ProcessAckPacket(&frame2); |
| 1213 } |
| 1143 } | 1214 } |
| 1144 | 1215 |
| 1145 TEST_F(QuicConnectionTest, LargestObservedLower) { | 1216 TEST_P(QuicConnectionTest, LargestObservedLower) { |
| 1146 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1217 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1147 | 1218 |
| 1148 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); | 1219 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); |
| 1149 SendStreamDataToPeer(1, "bar", 3, !kFin, NULL); | 1220 SendStreamDataToPeer(1, "bar", 3, !kFin, NULL); |
| 1150 SendStreamDataToPeer(1, "eep", 6, !kFin, NULL); | 1221 SendStreamDataToPeer(1, "eep", 6, !kFin, NULL); |
| 1151 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); | 1222 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); |
| 1152 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(2); | 1223 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(2); |
| 1153 | 1224 |
| 1154 // Start out saying the largest observed is 2. | 1225 // Start out saying the largest observed is 2. |
| 1155 QuicAckFrame frame1 = InitAckFrame(1, 0); | 1226 QuicAckFrame frame1 = InitAckFrame(1, 0); |
| 1156 QuicAckFrame frame2 = InitAckFrame(2, 0); | 1227 QuicAckFrame frame2 = InitAckFrame(2, 0); |
| 1157 ProcessAckPacket(&frame2); | 1228 ProcessAckPacket(&frame2); |
| 1158 | 1229 |
| 1159 // Now change it to 1, and it should cause a connection error. | 1230 // Now change it to 1, and it should cause a connection error. |
| 1160 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_ACK_DATA, false)); | 1231 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_ACK_DATA, false)); |
| 1161 EXPECT_CALL(visitor_, OnCanWrite()).Times(0); | 1232 EXPECT_CALL(visitor_, OnCanWrite()).Times(0); |
| 1162 ProcessAckPacket(&frame1); | 1233 ProcessAckPacket(&frame1); |
| 1163 } | 1234 } |
| 1164 | 1235 |
| 1165 TEST_F(QuicConnectionTest, AckUnsentData) { | 1236 TEST_P(QuicConnectionTest, AckUnsentData) { |
| 1166 // Ack a packet which has not been sent. | 1237 // Ack a packet which has not been sent. |
| 1167 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_ACK_DATA, false)); | 1238 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_ACK_DATA, false)); |
| 1168 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1239 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1169 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 1240 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| 1170 QuicAckFrame frame(1, QuicTime::Zero(), 0); | 1241 QuicAckFrame frame(1, QuicTime::Zero(), 0); |
| 1171 EXPECT_CALL(visitor_, OnCanWrite()).Times(0); | 1242 EXPECT_CALL(visitor_, OnCanWrite()).Times(0); |
| 1172 ProcessAckPacket(&frame); | 1243 ProcessAckPacket(&frame); |
| 1173 } | 1244 } |
| 1174 | 1245 |
| 1175 TEST_F(QuicConnectionTest, AckAll) { | 1246 TEST_P(QuicConnectionTest, AckAll) { |
| 1176 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1247 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1177 ProcessPacket(1); | 1248 ProcessPacket(1); |
| 1178 | 1249 |
| 1179 creator_.set_sequence_number(1); | 1250 creator_.set_sequence_number(1); |
| 1180 QuicAckFrame frame1 = InitAckFrame(0, 1); | 1251 QuicAckFrame frame1 = InitAckFrame(0, 1); |
| 1181 ProcessAckPacket(&frame1); | 1252 ProcessAckPacket(&frame1); |
| 1182 } | 1253 } |
| 1183 | 1254 |
| 1184 TEST_F(QuicConnectionTest, SendingDifferentSequenceNumberLengthsBandwidth) { | 1255 TEST_P(QuicConnectionTest, SendingDifferentSequenceNumberLengthsBandwidth) { |
| 1185 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillOnce(Return( | 1256 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillOnce(Return( |
| 1186 QuicBandwidth::FromKBitsPerSecond(1000))); | 1257 QuicBandwidth::FromKBitsPerSecond(1000))); |
| 1187 | 1258 |
| 1188 QuicPacketSequenceNumber last_packet; | 1259 QuicPacketSequenceNumber last_packet; |
| 1189 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); | 1260 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); |
| 1190 EXPECT_EQ(1u, last_packet); | 1261 EXPECT_EQ(1u, last_packet); |
| 1191 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, | 1262 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, |
| 1192 connection_.options()->send_sequence_number_length); | 1263 connection_.options()->send_sequence_number_length); |
| 1193 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, | 1264 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, |
| 1194 last_header()->public_header.sequence_number_length); | 1265 last_header()->public_header.sequence_number_length); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1229 QuicBandwidth::FromKBitsPerSecond(1000ll * 256 * 256 * 256 * 256))); | 1300 QuicBandwidth::FromKBitsPerSecond(1000ll * 256 * 256 * 256 * 256))); |
| 1230 | 1301 |
| 1231 SendStreamDataToPeer(1, "foo", 12, !kFin, &last_packet); | 1302 SendStreamDataToPeer(1, "foo", 12, !kFin, &last_packet); |
| 1232 EXPECT_EQ(5u, last_packet); | 1303 EXPECT_EQ(5u, last_packet); |
| 1233 EXPECT_EQ(PACKET_6BYTE_SEQUENCE_NUMBER, | 1304 EXPECT_EQ(PACKET_6BYTE_SEQUENCE_NUMBER, |
| 1234 connection_.options()->send_sequence_number_length); | 1305 connection_.options()->send_sequence_number_length); |
| 1235 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, | 1306 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, |
| 1236 last_header()->public_header.sequence_number_length); | 1307 last_header()->public_header.sequence_number_length); |
| 1237 } | 1308 } |
| 1238 | 1309 |
| 1239 TEST_F(QuicConnectionTest, SendingDifferentSequenceNumberLengthsUnackedDelta) { | 1310 TEST_P(QuicConnectionTest, SendingDifferentSequenceNumberLengthsUnackedDelta) { |
| 1240 QuicPacketSequenceNumber last_packet; | 1311 QuicPacketSequenceNumber last_packet; |
| 1241 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); | 1312 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); |
| 1242 EXPECT_EQ(1u, last_packet); | 1313 EXPECT_EQ(1u, last_packet); |
| 1243 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, | 1314 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, |
| 1244 connection_.options()->send_sequence_number_length); | 1315 connection_.options()->send_sequence_number_length); |
| 1245 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, | 1316 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, |
| 1246 last_header()->public_header.sequence_number_length); | 1317 last_header()->public_header.sequence_number_length); |
| 1247 | 1318 |
| 1248 QuicConnectionPeer::GetPacketCreator(&connection_)->set_sequence_number(100); | 1319 QuicConnectionPeer::GetPacketCreator(&connection_)->set_sequence_number(100); |
| 1249 | 1320 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1274 QuicConnectionPeer::GetPacketCreator(&connection_)->set_sequence_number( | 1345 QuicConnectionPeer::GetPacketCreator(&connection_)->set_sequence_number( |
| 1275 100 * 256 * 256 * 256); | 1346 100 * 256 * 256 * 256); |
| 1276 | 1347 |
| 1277 SendStreamDataToPeer(1, "foo", 12, !kFin, &last_packet); | 1348 SendStreamDataToPeer(1, "foo", 12, !kFin, &last_packet); |
| 1278 EXPECT_EQ(PACKET_6BYTE_SEQUENCE_NUMBER, | 1349 EXPECT_EQ(PACKET_6BYTE_SEQUENCE_NUMBER, |
| 1279 connection_.options()->send_sequence_number_length); | 1350 connection_.options()->send_sequence_number_length); |
| 1280 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, | 1351 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, |
| 1281 last_header()->public_header.sequence_number_length); | 1352 last_header()->public_header.sequence_number_length); |
| 1282 } | 1353 } |
| 1283 | 1354 |
| 1284 TEST_F(QuicConnectionTest, BasicSending) { | 1355 TEST_P(QuicConnectionTest, BasicSending) { |
| 1285 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1356 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1286 QuicPacketSequenceNumber last_packet; | 1357 QuicPacketSequenceNumber last_packet; |
| 1287 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 | 1358 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 |
| 1288 EXPECT_EQ(1u, last_packet); | 1359 EXPECT_EQ(1u, last_packet); |
| 1289 SendAckPacketToPeer(); // Packet 2 | 1360 SendAckPacketToPeer(); // Packet 2 |
| 1290 | 1361 |
| 1291 EXPECT_EQ(1u, last_ack()->sent_info.least_unacked); | 1362 EXPECT_EQ(1u, least_unacked()); |
| 1292 | 1363 |
| 1293 SendAckPacketToPeer(); // Packet 3 | 1364 SendAckPacketToPeer(); // Packet 3 |
| 1294 EXPECT_EQ(1u, last_ack()->sent_info.least_unacked); | 1365 EXPECT_EQ(1u, least_unacked()); |
| 1295 | 1366 |
| 1296 SendStreamDataToPeer(1, "bar", 3, !kFin, &last_packet); // Packet 4 | 1367 SendStreamDataToPeer(1, "bar", 3, !kFin, &last_packet); // Packet 4 |
| 1297 EXPECT_EQ(4u, last_packet); | 1368 EXPECT_EQ(4u, last_packet); |
| 1298 SendAckPacketToPeer(); // Packet 5 | 1369 SendAckPacketToPeer(); // Packet 5 |
| 1299 EXPECT_EQ(1u, last_ack()->sent_info.least_unacked); | 1370 EXPECT_EQ(1u, least_unacked()); |
| 1300 | 1371 |
| 1301 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); | 1372 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); |
| 1302 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(3); | 1373 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(3); |
| 1303 | 1374 |
| 1304 // Peer acks up to packet 3. | 1375 // Peer acks up to packet 3. |
| 1305 QuicAckFrame frame = InitAckFrame(3, 0); | 1376 QuicAckFrame frame = InitAckFrame(3, 0); |
| 1306 ProcessAckPacket(&frame); | 1377 ProcessAckPacket(&frame); |
| 1307 SendAckPacketToPeer(); // Packet 6 | 1378 SendAckPacketToPeer(); // Packet 6 |
| 1308 | 1379 |
| 1309 // As soon as we've acked one, we skip ack packets 2 and 3 and note lack of | 1380 // As soon as we've acked one, we skip ack packets 2 and 3 and note lack of |
| 1310 // ack for 4. | 1381 // ack for 4. |
| 1311 EXPECT_EQ(4u, last_ack()->sent_info.least_unacked); | 1382 EXPECT_EQ(4u, least_unacked()); |
| 1312 | 1383 |
| 1313 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); | 1384 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); |
| 1314 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(3); | 1385 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(3); |
| 1315 | 1386 |
| 1316 // Peer acks up to packet 4, the last packet. | 1387 // Peer acks up to packet 4, the last packet. |
| 1317 QuicAckFrame frame2 = InitAckFrame(6, 0); | 1388 QuicAckFrame frame2 = InitAckFrame(6, 0); |
| 1318 ProcessAckPacket(&frame2); // Acks don't instigate acks. | 1389 ProcessAckPacket(&frame2); // Acks don't instigate acks. |
| 1319 | 1390 |
| 1320 // Verify that we did not send an ack. | 1391 // Verify that we did not send an ack. |
| 1321 EXPECT_EQ(6u, last_header()->packet_sequence_number); | 1392 EXPECT_EQ(6u, last_header()->packet_sequence_number); |
| 1322 | 1393 |
| 1323 // So the last ack has not changed. | 1394 // So the last ack has not changed. |
| 1324 EXPECT_EQ(4u, last_ack()->sent_info.least_unacked); | 1395 EXPECT_EQ(4u, least_unacked()); |
| 1325 | 1396 |
| 1326 // If we force an ack, we shouldn't change our retransmit state. | 1397 // If we force an ack, we shouldn't change our retransmit state. |
| 1327 SendAckPacketToPeer(); // Packet 7 | 1398 SendAckPacketToPeer(); // Packet 7 |
| 1328 EXPECT_EQ(7u, last_ack()->sent_info.least_unacked); | 1399 EXPECT_EQ(7u, least_unacked()); |
| 1329 | 1400 |
| 1330 // But if we send more data it should. | 1401 // But if we send more data it should. |
| 1331 SendStreamDataToPeer(1, "eep", 6, !kFin, &last_packet); // Packet 8 | 1402 SendStreamDataToPeer(1, "eep", 6, !kFin, &last_packet); // Packet 8 |
| 1332 EXPECT_EQ(8u, last_packet); | 1403 EXPECT_EQ(8u, last_packet); |
| 1333 SendAckPacketToPeer(); // Packet 9 | 1404 SendAckPacketToPeer(); // Packet 9 |
| 1334 EXPECT_EQ(7u, last_ack()->sent_info.least_unacked); | 1405 EXPECT_EQ(7u, least_unacked()); |
| 1335 } | 1406 } |
| 1336 | 1407 |
| 1337 TEST_F(QuicConnectionTest, FECSending) { | 1408 TEST_P(QuicConnectionTest, FECSending) { |
| 1409 if (version() < QUIC_VERSION_15) { |
| 1410 return; |
| 1411 } |
| 1338 // All packets carry version info till version is negotiated. | 1412 // All packets carry version info till version is negotiated. |
| 1339 size_t payload_length; | 1413 size_t payload_length; |
| 1340 connection_.options()->max_packet_length = | 1414 connection_.options()->max_packet_length = |
| 1341 GetPacketLengthForOneStream( | 1415 GetPacketLengthForOneStream( |
| 1342 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, | 1416 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, |
| 1343 IN_FEC_GROUP, &payload_length); | 1417 IN_FEC_GROUP, &payload_length); |
| 1344 // And send FEC every two packets. | 1418 // And send FEC every two packets. |
| 1345 connection_.options()->max_packets_per_fec_group = 2; | 1419 connection_.options()->max_packets_per_fec_group = 2; |
| 1346 | 1420 |
| 1347 // Send 4 data packets and 2 FEC packets. | 1421 // Send 4 data packets and 2 FEC packets. |
| 1348 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); | 1422 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); |
| 1349 // The first stream frame will consume 2 fewer bytes than the other three. | 1423 // The first stream frame will consume 2 fewer bytes than the other three. |
| 1350 const string payload(payload_length * 4 - 6, 'a'); | 1424 const string payload(payload_length * 4 - 6, 'a'); |
| 1351 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL); | 1425 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL); |
| 1352 // Expect the FEC group to be closed after SendStreamDataWithString. | 1426 // Expect the FEC group to be closed after SendStreamDataWithString. |
| 1353 EXPECT_FALSE(creator_.ShouldSendFec(true)); | 1427 EXPECT_FALSE(creator_.ShouldSendFec(true)); |
| 1354 } | 1428 } |
| 1355 | 1429 |
| 1356 TEST_F(QuicConnectionTest, FECQueueing) { | 1430 TEST_P(QuicConnectionTest, FECQueueing) { |
| 1431 if (version() < QUIC_VERSION_15) { |
| 1432 return; |
| 1433 } |
| 1357 // All packets carry version info till version is negotiated. | 1434 // All packets carry version info till version is negotiated. |
| 1358 size_t payload_length; | 1435 size_t payload_length; |
| 1359 connection_.options()->max_packet_length = | 1436 connection_.options()->max_packet_length = |
| 1360 GetPacketLengthForOneStream( | 1437 GetPacketLengthForOneStream( |
| 1361 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, | 1438 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, |
| 1362 IN_FEC_GROUP, &payload_length); | 1439 IN_FEC_GROUP, &payload_length); |
| 1363 // And send FEC every two packets. | 1440 // And send FEC every two packets. |
| 1364 connection_.options()->max_packets_per_fec_group = 2; | 1441 connection_.options()->max_packets_per_fec_group = 2; |
| 1365 | 1442 |
| 1366 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1443 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 1367 BlockOnNextWrite(); | 1444 BlockOnNextWrite(); |
| 1368 const string payload(payload_length, 'a'); | 1445 const string payload(payload_length, 'a'); |
| 1369 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL); | 1446 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL); |
| 1370 EXPECT_FALSE(creator_.ShouldSendFec(true)); | 1447 EXPECT_FALSE(creator_.ShouldSendFec(true)); |
| 1371 // Expect the first data packet and the fec packet to be queued. | 1448 // Expect the first data packet and the fec packet to be queued. |
| 1372 EXPECT_EQ(2u, connection_.NumQueuedPackets()); | 1449 EXPECT_EQ(2u, connection_.NumQueuedPackets()); |
| 1373 } | 1450 } |
| 1374 | 1451 |
| 1375 TEST_F(QuicConnectionTest, AbandonFECFromCongestionWindow) { | 1452 TEST_P(QuicConnectionTest, AbandonFECFromCongestionWindow) { |
| 1453 if (version() < QUIC_VERSION_15) { |
| 1454 return; |
| 1455 } |
| 1376 connection_.options()->max_packets_per_fec_group = 1; | 1456 connection_.options()->max_packets_per_fec_group = 1; |
| 1377 // 1 Data and 1 FEC packet. | 1457 // 1 Data and 1 FEC packet. |
| 1378 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); | 1458 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); |
| 1379 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); | 1459 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); |
| 1380 | 1460 |
| 1381 const QuicTime::Delta retransmission_time = | 1461 const QuicTime::Delta retransmission_time = |
| 1382 QuicTime::Delta::FromMilliseconds(5000); | 1462 QuicTime::Delta::FromMilliseconds(5000); |
| 1383 clock_.AdvanceTime(retransmission_time); | 1463 clock_.AdvanceTime(retransmission_time); |
| 1384 | 1464 |
| 1385 // Abandon FEC packet and data packet. | 1465 // Abandon FEC packet and data packet. |
| 1386 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); | 1466 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
| 1387 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 1467 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
| 1388 EXPECT_CALL(visitor_, OnCanWrite()); | 1468 EXPECT_CALL(visitor_, OnCanWrite()); |
| 1389 connection_.OnRetransmissionTimeout(); | 1469 connection_.OnRetransmissionTimeout(); |
| 1390 } | 1470 } |
| 1391 | 1471 |
| 1392 TEST_F(QuicConnectionTest, DontAbandonAckedFEC) { | 1472 TEST_P(QuicConnectionTest, DontAbandonAckedFEC) { |
| 1473 if (version() < QUIC_VERSION_15) { |
| 1474 return; |
| 1475 } |
| 1393 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1476 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1394 connection_.options()->max_packets_per_fec_group = 1; | 1477 connection_.options()->max_packets_per_fec_group = 1; |
| 1395 | 1478 |
| 1396 // 1 Data and 1 FEC packet. | 1479 // 1 Data and 1 FEC packet. |
| 1397 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); | 1480 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); |
| 1398 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); | 1481 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); |
| 1399 // Send some more data afterwards to ensure early retransmit doesn't trigger. | 1482 // Send some more data afterwards to ensure early retransmit doesn't trigger. |
| 1400 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL); | 1483 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL); |
| 1401 connection_.SendStreamDataWithString(3, "foo", 6, !kFin, NULL); | 1484 connection_.SendStreamDataWithString(3, "foo", 6, !kFin, NULL); |
| 1402 | 1485 |
| 1403 QuicAckFrame ack_fec = InitAckFrame(2, 1); | 1486 QuicAckFrame ack_fec = InitAckFrame(2, 1); |
| 1404 // Data packet missing. | 1487 // Data packet missing. |
| 1405 // TODO(ianswett): Note that this is not a sensible ack, since if the FEC was | 1488 // TODO(ianswett): Note that this is not a sensible ack, since if the FEC was |
| 1406 // received, it would cause the covered packet to be acked as well. | 1489 // received, it would cause the covered packet to be acked as well. |
| 1407 NackPacket(1, &ack_fec); | 1490 NackPacket(1, &ack_fec); |
| 1408 | 1491 |
| 1409 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); | 1492 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); |
| 1410 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(1); | 1493 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(1); |
| 1411 ProcessAckPacket(&ack_fec); | 1494 ProcessAckPacket(&ack_fec); |
| 1412 clock_.AdvanceTime(DefaultRetransmissionTime()); | 1495 clock_.AdvanceTime(DefaultRetransmissionTime()); |
| 1413 | 1496 |
| 1414 // Don't abandon the acked FEC packet, but it will abandon 2 the subsequent | 1497 // Don't abandon the acked FEC packet, but it will abandon 2 the subsequent |
| 1415 // FEC packets. | 1498 // FEC packets. |
| 1416 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); | 1499 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
| 1417 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3); | 1500 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3); |
| 1418 connection_.GetRetransmissionAlarm()->Fire(); | 1501 connection_.GetRetransmissionAlarm()->Fire(); |
| 1419 } | 1502 } |
| 1420 | 1503 |
| 1421 TEST_F(QuicConnectionTest, AbandonAllFEC) { | 1504 TEST_P(QuicConnectionTest, AbandonAllFEC) { |
| 1505 if (version() < QUIC_VERSION_15) { |
| 1506 return; |
| 1507 } |
| 1422 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1508 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1423 connection_.options()->max_packets_per_fec_group = 1; | 1509 connection_.options()->max_packets_per_fec_group = 1; |
| 1424 | 1510 |
| 1425 // 1 Data and 1 FEC packet. | 1511 // 1 Data and 1 FEC packet. |
| 1426 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); | 1512 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); |
| 1427 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); | 1513 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); |
| 1428 // Send some more data afterwards to ensure early retransmit doesn't trigger. | 1514 // Send some more data afterwards to ensure early retransmit doesn't trigger. |
| 1429 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL); | 1515 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL); |
| 1430 // Advance the time so not all the FEC packets are abandoned. | 1516 // Advance the time so not all the FEC packets are abandoned. |
| 1431 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); | 1517 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1447 QuicTime::Delta::FromMilliseconds(1))); | 1533 QuicTime::Delta::FromMilliseconds(1))); |
| 1448 | 1534 |
| 1449 // Abandon all packets | 1535 // Abandon all packets |
| 1450 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(false)); | 1536 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(false)); |
| 1451 connection_.GetRetransmissionAlarm()->Fire(); | 1537 connection_.GetRetransmissionAlarm()->Fire(); |
| 1452 | 1538 |
| 1453 // Ensure the alarm is not set since all packets have been abandoned. | 1539 // Ensure the alarm is not set since all packets have been abandoned. |
| 1454 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); | 1540 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); |
| 1455 } | 1541 } |
| 1456 | 1542 |
| 1457 TEST_F(QuicConnectionTest, FramePacking) { | 1543 TEST_P(QuicConnectionTest, FramePacking) { |
| 1458 // Block the connection. | 1544 // Block the connection. |
| 1459 connection_.GetSendAlarm()->Set( | 1545 connection_.GetSendAlarm()->Set( |
| 1460 clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(1))); | 1546 clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(1))); |
| 1461 | 1547 |
| 1462 // Send an ack and two stream frames in 1 packet by queueing them. | 1548 // Send an ack and two stream frames in 1 packet by queueing them. |
| 1463 connection_.SendAck(); | 1549 connection_.SendAck(); |
| 1464 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( | 1550 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( |
| 1465 IgnoreResult(InvokeWithoutArgs(&connection_, | 1551 IgnoreResult(InvokeWithoutArgs(&connection_, |
| 1466 &TestConnection::SendStreamData3)), | 1552 &TestConnection::SendStreamData3)), |
| 1467 IgnoreResult(InvokeWithoutArgs(&connection_, | 1553 IgnoreResult(InvokeWithoutArgs(&connection_, |
| 1468 &TestConnection::SendStreamData5)))); | 1554 &TestConnection::SendStreamData5)))); |
| 1469 | 1555 |
| 1470 EXPECT_CALL(*send_algorithm_, | 1556 EXPECT_CALL(*send_algorithm_, |
| 1471 OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)) | 1557 OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)) |
| 1472 .Times(1); | 1558 .Times(1); |
| 1473 // Unblock the connection. | 1559 // Unblock the connection. |
| 1474 connection_.GetSendAlarm()->Fire(); | 1560 connection_.GetSendAlarm()->Fire(); |
| 1475 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1561 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 1476 EXPECT_FALSE(connection_.HasQueuedData()); | 1562 EXPECT_FALSE(connection_.HasQueuedData()); |
| 1477 | 1563 |
| 1478 // Parse the last packet and ensure it's an ack and two stream frames from | 1564 // Parse the last packet and ensure it's an ack and two stream frames from |
| 1479 // two different streams. | 1565 // two different streams. |
| 1480 EXPECT_EQ(3u, writer_->frame_count()); | 1566 if (version() > QUIC_VERSION_15) { |
| 1567 EXPECT_EQ(4u, writer_->frame_count()); |
| 1568 EXPECT_TRUE(writer_->stop_waiting()); |
| 1569 } else { |
| 1570 EXPECT_EQ(3u, writer_->frame_count()); |
| 1571 } |
| 1481 EXPECT_TRUE(writer_->ack()); | 1572 EXPECT_TRUE(writer_->ack()); |
| 1482 EXPECT_EQ(2u, writer_->stream_frames()->size()); | 1573 EXPECT_EQ(2u, writer_->stream_frames()->size()); |
| 1483 EXPECT_EQ(kStreamId3, (*writer_->stream_frames())[0].stream_id); | 1574 EXPECT_EQ(kStreamId3, (*writer_->stream_frames())[0].stream_id); |
| 1484 EXPECT_EQ(kStreamId5, (*writer_->stream_frames())[1].stream_id); | 1575 EXPECT_EQ(kStreamId5, (*writer_->stream_frames())[1].stream_id); |
| 1485 } | 1576 } |
| 1486 | 1577 |
| 1487 TEST_F(QuicConnectionTest, FramePackingNonCryptoThenCrypto) { | 1578 TEST_P(QuicConnectionTest, FramePackingNonCryptoThenCrypto) { |
| 1488 // Block the connection. | 1579 // Block the connection. |
| 1489 connection_.GetSendAlarm()->Set( | 1580 connection_.GetSendAlarm()->Set( |
| 1490 clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(1))); | 1581 clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(1))); |
| 1491 | 1582 |
| 1492 // Send an ack and two stream frames (one non-crypto, then one crypto) in 2 | 1583 // Send an ack and two stream frames (one non-crypto, then one crypto) in 2 |
| 1493 // packets by queueing them. | 1584 // packets by queueing them. |
| 1494 connection_.SendAck(); | 1585 connection_.SendAck(); |
| 1495 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( | 1586 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( |
| 1496 IgnoreResult(InvokeWithoutArgs(&connection_, | 1587 IgnoreResult(InvokeWithoutArgs(&connection_, |
| 1497 &TestConnection::SendStreamData3)), | 1588 &TestConnection::SendStreamData3)), |
| 1498 IgnoreResult(InvokeWithoutArgs(&connection_, | 1589 IgnoreResult(InvokeWithoutArgs(&connection_, |
| 1499 &TestConnection::SendCryptoStreamData)))); | 1590 &TestConnection::SendCryptoStreamData)))); |
| 1500 | 1591 |
| 1501 EXPECT_CALL(*send_algorithm_, | 1592 EXPECT_CALL(*send_algorithm_, |
| 1502 OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)) | 1593 OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)) |
| 1503 .Times(2); | 1594 .Times(2); |
| 1504 // Unblock the connection. | 1595 // Unblock the connection. |
| 1505 connection_.GetSendAlarm()->Fire(); | 1596 connection_.GetSendAlarm()->Fire(); |
| 1506 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1597 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 1507 EXPECT_FALSE(connection_.HasQueuedData()); | 1598 EXPECT_FALSE(connection_.HasQueuedData()); |
| 1508 | 1599 |
| 1509 // Parse the last packet and ensure it's the crypto stream frame. | 1600 // Parse the last packet and ensure it's the crypto stream frame. |
| 1510 EXPECT_EQ(1u, writer_->frame_count()); | 1601 EXPECT_EQ(1u, writer_->frame_count()); |
| 1511 EXPECT_EQ(1u, writer_->stream_frames()->size()); | 1602 EXPECT_EQ(1u, writer_->stream_frames()->size()); |
| 1512 EXPECT_EQ(kCryptoStreamId, (*writer_->stream_frames())[0].stream_id); | 1603 EXPECT_EQ(kCryptoStreamId, (*writer_->stream_frames())[0].stream_id); |
| 1513 } | 1604 } |
| 1514 | 1605 |
| 1515 TEST_F(QuicConnectionTest, FramePackingCryptoThenNonCrypto) { | 1606 TEST_P(QuicConnectionTest, FramePackingCryptoThenNonCrypto) { |
| 1516 // Block the connection. | 1607 // Block the connection. |
| 1517 connection_.GetSendAlarm()->Set( | 1608 connection_.GetSendAlarm()->Set( |
| 1518 clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(1))); | 1609 clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(1))); |
| 1519 | 1610 |
| 1520 // Send an ack and two stream frames (one crypto, then one non-crypto) in 3 | 1611 // Send an ack and two stream frames (one crypto, then one non-crypto) in 3 |
| 1521 // packets by queueing them. | 1612 // packets by queueing them. |
| 1522 connection_.SendAck(); | 1613 connection_.SendAck(); |
| 1523 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( | 1614 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( |
| 1524 IgnoreResult(InvokeWithoutArgs(&connection_, | 1615 IgnoreResult(InvokeWithoutArgs(&connection_, |
| 1525 &TestConnection::SendCryptoStreamData)), | 1616 &TestConnection::SendCryptoStreamData)), |
| 1526 IgnoreResult(InvokeWithoutArgs(&connection_, | 1617 IgnoreResult(InvokeWithoutArgs(&connection_, |
| 1527 &TestConnection::SendStreamData3)))); | 1618 &TestConnection::SendStreamData3)))); |
| 1528 | 1619 |
| 1529 EXPECT_CALL(*send_algorithm_, | 1620 EXPECT_CALL(*send_algorithm_, |
| 1530 OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)) | 1621 OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)) |
| 1531 .Times(3); | 1622 .Times(3); |
| 1532 // Unblock the connection. | 1623 // Unblock the connection. |
| 1533 connection_.GetSendAlarm()->Fire(); | 1624 connection_.GetSendAlarm()->Fire(); |
| 1534 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1625 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 1535 EXPECT_FALSE(connection_.HasQueuedData()); | 1626 EXPECT_FALSE(connection_.HasQueuedData()); |
| 1536 | 1627 |
| 1537 // Parse the last packet and ensure it's the stream frame from stream 3. | 1628 // Parse the last packet and ensure it's the stream frame from stream 3. |
| 1538 EXPECT_EQ(1u, writer_->frame_count()); | 1629 EXPECT_EQ(1u, writer_->frame_count()); |
| 1539 EXPECT_EQ(1u, writer_->stream_frames()->size()); | 1630 EXPECT_EQ(1u, writer_->stream_frames()->size()); |
| 1540 EXPECT_EQ(kStreamId3, (*writer_->stream_frames())[0].stream_id); | 1631 EXPECT_EQ(kStreamId3, (*writer_->stream_frames())[0].stream_id); |
| 1541 } | 1632 } |
| 1542 | 1633 |
| 1543 TEST_F(QuicConnectionTest, FramePackingFEC) { | 1634 TEST_P(QuicConnectionTest, FramePackingFEC) { |
| 1635 if (version() < QUIC_VERSION_15) { |
| 1636 return; |
| 1637 } |
| 1544 // Enable fec. | 1638 // Enable fec. |
| 1545 connection_.options()->max_packets_per_fec_group = 6; | 1639 connection_.options()->max_packets_per_fec_group = 6; |
| 1546 // Block the connection. | 1640 // Block the connection. |
| 1547 connection_.GetSendAlarm()->Set( | 1641 connection_.GetSendAlarm()->Set( |
| 1548 clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(1))); | 1642 clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(1))); |
| 1549 | 1643 |
| 1550 // Send an ack and two stream frames in 1 packet by queueing them. | 1644 // Send an ack and two stream frames in 1 packet by queueing them. |
| 1551 connection_.SendAck(); | 1645 connection_.SendAck(); |
| 1552 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( | 1646 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( |
| 1553 IgnoreResult(InvokeWithoutArgs(&connection_, | 1647 IgnoreResult(InvokeWithoutArgs(&connection_, |
| 1554 &TestConnection::SendStreamData3)), | 1648 &TestConnection::SendStreamData3)), |
| 1555 IgnoreResult(InvokeWithoutArgs(&connection_, | 1649 IgnoreResult(InvokeWithoutArgs(&connection_, |
| 1556 &TestConnection::SendStreamData5)))); | 1650 &TestConnection::SendStreamData5)))); |
| 1557 | 1651 |
| 1558 EXPECT_CALL(*send_algorithm_, | 1652 EXPECT_CALL(*send_algorithm_, |
| 1559 OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)).Times(2); | 1653 OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)).Times(2); |
| 1560 // Unblock the connection. | 1654 // Unblock the connection. |
| 1561 connection_.GetSendAlarm()->Fire(); | 1655 connection_.GetSendAlarm()->Fire(); |
| 1562 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1656 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 1563 EXPECT_FALSE(connection_.HasQueuedData()); | 1657 EXPECT_FALSE(connection_.HasQueuedData()); |
| 1564 | 1658 |
| 1565 // Parse the last packet and ensure it's in an fec group. | 1659 // Parse the last packet and ensure it's in an fec group. |
| 1566 EXPECT_EQ(1u, writer_->header()->fec_group); | 1660 EXPECT_EQ(1u, writer_->header()->fec_group); |
| 1567 EXPECT_EQ(0u, writer_->frame_count()); | 1661 EXPECT_EQ(0u, writer_->frame_count()); |
| 1568 } | 1662 } |
| 1569 | 1663 |
| 1570 TEST_F(QuicConnectionTest, FramePackingAckResponse) { | 1664 TEST_P(QuicConnectionTest, FramePackingAckResponse) { |
| 1571 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1665 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1572 // Process a data packet to queue up a pending ack. | 1666 // Process a data packet to queue up a pending ack. |
| 1573 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillOnce(Return(true)); | 1667 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillOnce(Return(true)); |
| 1574 ProcessDataPacket(1, 1, kEntropyFlag); | 1668 ProcessDataPacket(1, 1, kEntropyFlag); |
| 1575 | 1669 |
| 1576 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( | 1670 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( |
| 1577 IgnoreResult(InvokeWithoutArgs(&connection_, | 1671 IgnoreResult(InvokeWithoutArgs(&connection_, |
| 1578 &TestConnection::SendStreamData3)), | 1672 &TestConnection::SendStreamData3)), |
| 1579 IgnoreResult(InvokeWithoutArgs(&connection_, | 1673 IgnoreResult(InvokeWithoutArgs(&connection_, |
| 1580 &TestConnection::SendStreamData5)))); | 1674 &TestConnection::SendStreamData5)))); |
| 1581 | 1675 |
| 1582 EXPECT_CALL(*send_algorithm_, | 1676 EXPECT_CALL(*send_algorithm_, |
| 1583 OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)) | 1677 OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)) |
| 1584 .Times(1); | 1678 .Times(1); |
| 1585 | 1679 |
| 1586 // Process an ack to cause the visitor's OnCanWrite to be invoked. | 1680 // Process an ack to cause the visitor's OnCanWrite to be invoked. |
| 1587 creator_.set_sequence_number(2); | 1681 creator_.set_sequence_number(2); |
| 1588 QuicAckFrame ack_one = InitAckFrame(0, 0); | 1682 QuicAckFrame ack_one = InitAckFrame(0, 0); |
| 1589 ProcessAckPacket(&ack_one); | 1683 ProcessAckPacket(&ack_one); |
| 1590 | 1684 |
| 1591 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1685 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 1592 EXPECT_FALSE(connection_.HasQueuedData()); | 1686 EXPECT_FALSE(connection_.HasQueuedData()); |
| 1593 | 1687 |
| 1594 // Parse the last packet and ensure it's an ack and two stream frames from | 1688 // Parse the last packet and ensure it's an ack and two stream frames from |
| 1595 // two different streams. | 1689 // two different streams. |
| 1596 EXPECT_EQ(3u, writer_->frame_count()); | 1690 if (version() > QUIC_VERSION_15) { |
| 1691 EXPECT_EQ(4u, writer_->frame_count()); |
| 1692 EXPECT_TRUE(writer_->stop_waiting()); |
| 1693 } else { |
| 1694 EXPECT_EQ(3u, writer_->frame_count()); |
| 1695 } |
| 1597 EXPECT_TRUE(writer_->ack()); | 1696 EXPECT_TRUE(writer_->ack()); |
| 1598 ASSERT_EQ(2u, writer_->stream_frames()->size()); | 1697 ASSERT_EQ(2u, writer_->stream_frames()->size()); |
| 1599 EXPECT_EQ(kStreamId3, (*writer_->stream_frames())[0].stream_id); | 1698 EXPECT_EQ(kStreamId3, (*writer_->stream_frames())[0].stream_id); |
| 1600 EXPECT_EQ(kStreamId5, (*writer_->stream_frames())[1].stream_id); | 1699 EXPECT_EQ(kStreamId5, (*writer_->stream_frames())[1].stream_id); |
| 1601 } | 1700 } |
| 1602 | 1701 |
| 1603 TEST_F(QuicConnectionTest, FramePackingSendv) { | 1702 TEST_P(QuicConnectionTest, FramePackingSendv) { |
| 1604 // Send data in 1 packet by writing multiple blocks in a single iovector | 1703 // Send data in 1 packet by writing multiple blocks in a single iovector |
| 1605 // using writev. | 1704 // using writev. |
| 1606 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)); | 1705 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)); |
| 1607 | 1706 |
| 1608 char data[] = "ABCD"; | 1707 char data[] = "ABCD"; |
| 1609 IOVector data_iov; | 1708 IOVector data_iov; |
| 1610 data_iov.AppendNoCoalesce(data, 2); | 1709 data_iov.AppendNoCoalesce(data, 2); |
| 1611 data_iov.AppendNoCoalesce(data + 2, 2); | 1710 data_iov.AppendNoCoalesce(data + 2, 2); |
| 1612 connection_.SendStreamData(1, data_iov, 0, !kFin, NULL); | 1711 connection_.SendStreamData(1, data_iov, 0, !kFin, NULL); |
| 1613 | 1712 |
| 1614 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1713 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 1615 EXPECT_FALSE(connection_.HasQueuedData()); | 1714 EXPECT_FALSE(connection_.HasQueuedData()); |
| 1616 | 1715 |
| 1617 // Parse the last packet and ensure multiple iovector blocks have | 1716 // Parse the last packet and ensure multiple iovector blocks have |
| 1618 // been packed into a single stream frame from one stream. | 1717 // been packed into a single stream frame from one stream. |
| 1619 EXPECT_EQ(1u, writer_->frame_count()); | 1718 EXPECT_EQ(1u, writer_->frame_count()); |
| 1620 EXPECT_EQ(1u, writer_->stream_frames()->size()); | 1719 EXPECT_EQ(1u, writer_->stream_frames()->size()); |
| 1621 QuicStreamFrame frame = (*writer_->stream_frames())[0]; | 1720 QuicStreamFrame frame = (*writer_->stream_frames())[0]; |
| 1622 EXPECT_EQ(1u, frame.stream_id); | 1721 EXPECT_EQ(1u, frame.stream_id); |
| 1623 EXPECT_EQ("ABCD", string(static_cast<char*> | 1722 EXPECT_EQ("ABCD", string(static_cast<char*> |
| 1624 (frame.data.iovec()[0].iov_base), | 1723 (frame.data.iovec()[0].iov_base), |
| 1625 (frame.data.iovec()[0].iov_len))); | 1724 (frame.data.iovec()[0].iov_len))); |
| 1626 } | 1725 } |
| 1627 | 1726 |
| 1628 TEST_F(QuicConnectionTest, FramePackingSendvQueued) { | 1727 TEST_P(QuicConnectionTest, FramePackingSendvQueued) { |
| 1629 // Try to send two stream frames in 1 packet by using writev. | 1728 // Try to send two stream frames in 1 packet by using writev. |
| 1630 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)); | 1729 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)); |
| 1631 | 1730 |
| 1632 BlockOnNextWrite(); | 1731 BlockOnNextWrite(); |
| 1633 char data[] = "ABCD"; | 1732 char data[] = "ABCD"; |
| 1634 IOVector data_iov; | 1733 IOVector data_iov; |
| 1635 data_iov.AppendNoCoalesce(data, 2); | 1734 data_iov.AppendNoCoalesce(data, 2); |
| 1636 data_iov.AppendNoCoalesce(data + 2, 2); | 1735 data_iov.AppendNoCoalesce(data + 2, 2); |
| 1637 connection_.SendStreamData(1, data_iov, 0, !kFin, NULL); | 1736 connection_.SendStreamData(1, data_iov, 0, !kFin, NULL); |
| 1638 | 1737 |
| 1639 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 1738 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 1640 EXPECT_TRUE(connection_.HasQueuedData()); | 1739 EXPECT_TRUE(connection_.HasQueuedData()); |
| 1641 | 1740 |
| 1642 // Unblock the writes and actually send. | 1741 // Unblock the writes and actually send. |
| 1643 writer_->SetWritable(); | 1742 writer_->SetWritable(); |
| 1644 connection_.OnCanWrite(); | 1743 connection_.OnCanWrite(); |
| 1645 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1744 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 1646 | 1745 |
| 1647 // Parse the last packet and ensure it's one stream frame from one stream. | 1746 // Parse the last packet and ensure it's one stream frame from one stream. |
| 1648 EXPECT_EQ(1u, writer_->frame_count()); | 1747 EXPECT_EQ(1u, writer_->frame_count()); |
| 1649 EXPECT_EQ(1u, writer_->stream_frames()->size()); | 1748 EXPECT_EQ(1u, writer_->stream_frames()->size()); |
| 1650 EXPECT_EQ(1u, (*writer_->stream_frames())[0].stream_id); | 1749 EXPECT_EQ(1u, (*writer_->stream_frames())[0].stream_id); |
| 1651 } | 1750 } |
| 1652 | 1751 |
| 1653 TEST_F(QuicConnectionTest, SendingZeroBytes) { | 1752 TEST_P(QuicConnectionTest, SendingZeroBytes) { |
| 1654 // Send a zero byte write with a fin using writev. | 1753 // Send a zero byte write with a fin using writev. |
| 1655 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)); | 1754 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)); |
| 1656 IOVector empty_iov; | 1755 IOVector empty_iov; |
| 1657 connection_.SendStreamData(1, empty_iov, 0, kFin, NULL); | 1756 connection_.SendStreamData(1, empty_iov, 0, kFin, NULL); |
| 1658 | 1757 |
| 1659 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1758 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 1660 EXPECT_FALSE(connection_.HasQueuedData()); | 1759 EXPECT_FALSE(connection_.HasQueuedData()); |
| 1661 | 1760 |
| 1662 // Parse the last packet and ensure it's one stream frame from one stream. | 1761 // Parse the last packet and ensure it's one stream frame from one stream. |
| 1663 EXPECT_EQ(1u, writer_->frame_count()); | 1762 EXPECT_EQ(1u, writer_->frame_count()); |
| 1664 EXPECT_EQ(1u, writer_->stream_frames()->size()); | 1763 EXPECT_EQ(1u, writer_->stream_frames()->size()); |
| 1665 EXPECT_EQ(1u, (*writer_->stream_frames())[0].stream_id); | 1764 EXPECT_EQ(1u, (*writer_->stream_frames())[0].stream_id); |
| 1666 EXPECT_TRUE((*writer_->stream_frames())[0].fin); | 1765 EXPECT_TRUE((*writer_->stream_frames())[0].fin); |
| 1667 } | 1766 } |
| 1668 | 1767 |
| 1669 TEST_F(QuicConnectionTest, OnCanWrite) { | 1768 TEST_P(QuicConnectionTest, OnCanWrite) { |
| 1670 // Visitor's OnCanWrite will send data, but will have more pending writes. | 1769 // Visitor's OnCanWrite will send data, but will have more pending writes. |
| 1671 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( | 1770 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( |
| 1672 IgnoreResult(InvokeWithoutArgs(&connection_, | 1771 IgnoreResult(InvokeWithoutArgs(&connection_, |
| 1673 &TestConnection::SendStreamData3)), | 1772 &TestConnection::SendStreamData3)), |
| 1674 IgnoreResult(InvokeWithoutArgs(&connection_, | 1773 IgnoreResult(InvokeWithoutArgs(&connection_, |
| 1675 &TestConnection::SendStreamData5)))); | 1774 &TestConnection::SendStreamData5)))); |
| 1676 EXPECT_CALL(visitor_, HasPendingWrites()).WillOnce(Return(true)); | 1775 EXPECT_CALL(visitor_, HasPendingWrites()).WillOnce(Return(true)); |
| 1677 EXPECT_CALL(*send_algorithm_, | 1776 EXPECT_CALL(*send_algorithm_, |
| 1678 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillRepeatedly( | 1777 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillRepeatedly( |
| 1679 testing::Return(QuicTime::Delta::Zero())); | 1778 testing::Return(QuicTime::Delta::Zero())); |
| 1680 | 1779 |
| 1681 connection_.OnCanWrite(); | 1780 connection_.OnCanWrite(); |
| 1682 | 1781 |
| 1683 // Parse the last packet and ensure it's the two stream frames from | 1782 // Parse the last packet and ensure it's the two stream frames from |
| 1684 // two different streams. | 1783 // two different streams. |
| 1685 EXPECT_EQ(2u, writer_->frame_count()); | 1784 EXPECT_EQ(2u, writer_->frame_count()); |
| 1686 EXPECT_EQ(2u, writer_->stream_frames()->size()); | 1785 EXPECT_EQ(2u, writer_->stream_frames()->size()); |
| 1687 EXPECT_EQ(kStreamId3, (*writer_->stream_frames())[0].stream_id); | 1786 EXPECT_EQ(kStreamId3, (*writer_->stream_frames())[0].stream_id); |
| 1688 EXPECT_EQ(kStreamId5, (*writer_->stream_frames())[1].stream_id); | 1787 EXPECT_EQ(kStreamId5, (*writer_->stream_frames())[1].stream_id); |
| 1689 } | 1788 } |
| 1690 | 1789 |
| 1691 TEST_F(QuicConnectionTest, RetransmitOnNack) { | 1790 TEST_P(QuicConnectionTest, RetransmitOnNack) { |
| 1692 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); | 1791 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); |
| 1693 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)); | 1792 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)); |
| 1694 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(1); | 1793 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(1); |
| 1695 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(2, _)).Times(1); | 1794 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(2, _)).Times(1); |
| 1696 QuicPacketSequenceNumber last_packet; | 1795 QuicPacketSequenceNumber last_packet; |
| 1697 QuicByteCount second_packet_size; | 1796 QuicByteCount second_packet_size; |
| 1698 SendStreamDataToPeer(3, "foo", 0, !kFin, &last_packet); // Packet 1 | 1797 SendStreamDataToPeer(3, "foo", 0, !kFin, &last_packet); // Packet 1 |
| 1699 second_packet_size = | 1798 second_packet_size = |
| 1700 SendStreamDataToPeer(3, "foos", 3, !kFin, &last_packet); // Packet 2 | 1799 SendStreamDataToPeer(3, "foos", 3, !kFin, &last_packet); // Packet 2 |
| 1701 SendStreamDataToPeer(3, "fooos", 7, !kFin, &last_packet); // Packet 3 | 1800 SendStreamDataToPeer(3, "fooos", 7, !kFin, &last_packet); // Packet 3 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1715 NackPacket(2, &nack_two); | 1814 NackPacket(2, &nack_two); |
| 1716 // The third nack should trigger a retransmission. | 1815 // The third nack should trigger a retransmission. |
| 1717 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); | 1816 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); |
| 1718 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)); | 1817 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)); |
| 1719 EXPECT_CALL(*send_algorithm_, | 1818 EXPECT_CALL(*send_algorithm_, |
| 1720 OnPacketSent(_, _, second_packet_size - kQuicVersionSize, | 1819 OnPacketSent(_, _, second_packet_size - kQuicVersionSize, |
| 1721 NACK_RETRANSMISSION, _)).Times(1); | 1820 NACK_RETRANSMISSION, _)).Times(1); |
| 1722 ProcessAckPacket(&nack_two); | 1821 ProcessAckPacket(&nack_two); |
| 1723 } | 1822 } |
| 1724 | 1823 |
| 1725 TEST_F(QuicConnectionTest, DiscardRetransmit) { | 1824 TEST_P(QuicConnectionTest, DiscardRetransmit) { |
| 1726 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); | 1825 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); |
| 1727 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)); | 1826 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)); |
| 1728 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(1); | 1827 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(1); |
| 1729 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(2, _)).Times(1); | 1828 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(2, _)).Times(1); |
| 1730 QuicPacketSequenceNumber last_packet; | 1829 QuicPacketSequenceNumber last_packet; |
| 1731 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 | 1830 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 |
| 1732 SendStreamDataToPeer(1, "foos", 3, !kFin, &last_packet); // Packet 2 | 1831 SendStreamDataToPeer(1, "foos", 3, !kFin, &last_packet); // Packet 2 |
| 1733 SendStreamDataToPeer(1, "fooos", 7, !kFin, &last_packet); // Packet 3 | 1832 SendStreamDataToPeer(1, "fooos", 7, !kFin, &last_packet); // Packet 3 |
| 1734 | 1833 |
| 1735 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1834 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1762 // send the retransmission. | 1861 // send the retransmission. |
| 1763 EXPECT_CALL(*send_algorithm_, | 1862 EXPECT_CALL(*send_algorithm_, |
| 1764 OnPacketSent(_, _, _, _, _)).Times(0); | 1863 OnPacketSent(_, _, _, _, _)).Times(0); |
| 1765 | 1864 |
| 1766 writer_->SetWritable(); | 1865 writer_->SetWritable(); |
| 1767 connection_.OnCanWrite(); | 1866 connection_.OnCanWrite(); |
| 1768 | 1867 |
| 1769 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1868 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 1770 } | 1869 } |
| 1771 | 1870 |
| 1772 TEST_F(QuicConnectionTest, RetransmitNackedLargestObserved) { | 1871 TEST_P(QuicConnectionTest, RetransmitNackedLargestObserved) { |
| 1773 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1872 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1774 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(1); | 1873 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(1); |
| 1775 QuicPacketSequenceNumber largest_observed; | 1874 QuicPacketSequenceNumber largest_observed; |
| 1776 QuicByteCount packet_size; | 1875 QuicByteCount packet_size; |
| 1777 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)) | 1876 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)) |
| 1778 .WillOnce(DoAll(SaveArg<1>(&largest_observed), SaveArg<2>(&packet_size), | 1877 .WillOnce(DoAll(SaveArg<1>(&largest_observed), SaveArg<2>(&packet_size), |
| 1779 Return(true))); | 1878 Return(true))); |
| 1780 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(1, _)).Times(1); | 1879 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(1, _)).Times(1); |
| 1781 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); | 1880 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); |
| 1782 QuicAckFrame frame = InitAckFrame(1, largest_observed); | 1881 QuicAckFrame frame = InitAckFrame(1, largest_observed); |
| 1783 NackPacket(largest_observed, &frame); | 1882 NackPacket(largest_observed, &frame); |
| 1784 // The first nack should retransmit the largest observed packet. | 1883 // The first nack should retransmit the largest observed packet. |
| 1785 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); | 1884 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); |
| 1786 EXPECT_CALL(*send_algorithm_, | 1885 EXPECT_CALL(*send_algorithm_, |
| 1787 OnPacketSent(_, _, packet_size - kQuicVersionSize, | 1886 OnPacketSent(_, _, packet_size - kQuicVersionSize, |
| 1788 NACK_RETRANSMISSION, _)); | 1887 NACK_RETRANSMISSION, _)); |
| 1789 ProcessAckPacket(&frame); | 1888 ProcessAckPacket(&frame); |
| 1790 } | 1889 } |
| 1791 | 1890 |
| 1792 TEST_F(QuicConnectionTest, QueueAfterTwoRTOs) { | 1891 TEST_P(QuicConnectionTest, QueueAfterTwoRTOs) { |
| 1793 for (int i = 0; i < 10; ++i) { | 1892 for (int i = 0; i < 10; ++i) { |
| 1794 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 1893 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
| 1795 connection_.SendStreamDataWithString(3, "foo", i * 3, !kFin, NULL); | 1894 connection_.SendStreamDataWithString(3, "foo", i * 3, !kFin, NULL); |
| 1796 } | 1895 } |
| 1797 | 1896 |
| 1798 // Block the congestion window and ensure they're queued. | 1897 // Block the congestion window and ensure they're queued. |
| 1799 BlockOnNextWrite(); | 1898 BlockOnNextWrite(); |
| 1800 clock_.AdvanceTime(DefaultRetransmissionTime()); | 1899 clock_.AdvanceTime(DefaultRetransmissionTime()); |
| 1801 // Only one packet should be retransmitted. | 1900 // Only one packet should be retransmitted. |
| 1802 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); | 1901 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
| 1803 connection_.GetRetransmissionAlarm()->Fire(); | 1902 connection_.GetRetransmissionAlarm()->Fire(); |
| 1804 EXPECT_TRUE(connection_.HasQueuedData()); | 1903 EXPECT_TRUE(connection_.HasQueuedData()); |
| 1805 | 1904 |
| 1806 // Unblock the congestion window. | 1905 // Unblock the congestion window. |
| 1807 writer_->SetWritable(); | 1906 writer_->SetWritable(); |
| 1808 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds( | 1907 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds( |
| 1809 2 * DefaultRetransmissionTime().ToMicroseconds())); | 1908 2 * DefaultRetransmissionTime().ToMicroseconds())); |
| 1810 // Retransmit already retransmitted packets event though the sequence number | 1909 // Retransmit already retransmitted packets event though the sequence number |
| 1811 // greater than the largest observed. | 1910 // greater than the largest observed. |
| 1812 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(10); | 1911 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(10); |
| 1813 connection_.GetRetransmissionAlarm()->Fire(); | 1912 connection_.GetRetransmissionAlarm()->Fire(); |
| 1814 connection_.OnCanWrite(); | 1913 connection_.OnCanWrite(); |
| 1815 } | 1914 } |
| 1816 | 1915 |
| 1817 TEST_F(QuicConnectionTest, WriteBlockedThenSent) { | 1916 TEST_P(QuicConnectionTest, WriteBlockedThenSent) { |
| 1818 BlockOnNextWrite(); | 1917 BlockOnNextWrite(); |
| 1819 writer_->set_is_write_blocked_data_buffered(true); | 1918 writer_->set_is_write_blocked_data_buffered(true); |
| 1820 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); | 1919 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); |
| 1821 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); | 1920 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); |
| 1822 | 1921 |
| 1823 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 1922 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
| 1824 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0)); | 1923 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0)); |
| 1825 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); | 1924 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); |
| 1826 } | 1925 } |
| 1827 | 1926 |
| 1828 TEST_F(QuicConnectionTest, WriteBlockedAckedThenSent) { | 1927 TEST_P(QuicConnectionTest, WriteBlockedAckedThenSent) { |
| 1829 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1928 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1830 BlockOnNextWrite(); | 1929 BlockOnNextWrite(); |
| 1831 writer_->set_is_write_blocked_data_buffered(true); | 1930 writer_->set_is_write_blocked_data_buffered(true); |
| 1832 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); | 1931 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); |
| 1833 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); | 1932 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); |
| 1834 | 1933 |
| 1835 // Ack the sent packet before the callback returns, which happens in | 1934 // Ack the sent packet before the callback returns, which happens in |
| 1836 // rare circumstances with write blocked sockets. | 1935 // rare circumstances with write blocked sockets. |
| 1837 QuicAckFrame ack = InitAckFrame(1, 0); | 1936 QuicAckFrame ack = InitAckFrame(1, 0); |
| 1838 ProcessAckPacket(&ack); | 1937 ProcessAckPacket(&ack); |
| 1839 | 1938 |
| 1840 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); | 1939 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); |
| 1841 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0)); | 1940 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0)); |
| 1842 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); | 1941 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); |
| 1843 } | 1942 } |
| 1844 | 1943 |
| 1845 TEST_F(QuicConnectionTest, RetransmitWriteBlockedAckedOriginalThenSent) { | 1944 TEST_P(QuicConnectionTest, RetransmitWriteBlockedAckedOriginalThenSent) { |
| 1846 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1945 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1847 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); | 1946 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); |
| 1848 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); | 1947 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); |
| 1849 | 1948 |
| 1850 BlockOnNextWrite(); | 1949 BlockOnNextWrite(); |
| 1851 writer_->set_is_write_blocked_data_buffered(true); | 1950 writer_->set_is_write_blocked_data_buffered(true); |
| 1852 // Simulate the retransmission alarm firing. | 1951 // Simulate the retransmission alarm firing. |
| 1853 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(_)); | 1952 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(_)); |
| 1854 clock_.AdvanceTime(DefaultRetransmissionTime()); | 1953 clock_.AdvanceTime(DefaultRetransmissionTime()); |
| 1855 connection_.GetRetransmissionAlarm()->Fire(); | 1954 connection_.GetRetransmissionAlarm()->Fire(); |
| 1856 | 1955 |
| 1857 // Ack the sent packet before the callback returns, which happens in | 1956 // Ack the sent packet before the callback returns, which happens in |
| 1858 // rare circumstances with write blocked sockets. | 1957 // rare circumstances with write blocked sockets. |
| 1859 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); | 1958 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); |
| 1860 QuicAckFrame ack = InitAckFrame(1, 0); | 1959 QuicAckFrame ack = InitAckFrame(1, 0); |
| 1861 ProcessAckPacket(&ack); | 1960 ProcessAckPacket(&ack); |
| 1862 | 1961 |
| 1863 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0)); | 1962 connection_.OnPacketSent(WriteResult(WRITE_STATUS_OK, 0)); |
| 1864 // The retransmission alarm should not be set because there are | 1963 // The retransmission alarm should not be set because there are |
| 1865 // no unacked packets. | 1964 // no unacked packets. |
| 1866 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); | 1965 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); |
| 1867 } | 1966 } |
| 1868 | 1967 |
| 1869 TEST_F(QuicConnectionTest, AlarmsWhenWriteBlocked) { | 1968 TEST_P(QuicConnectionTest, AlarmsWhenWriteBlocked) { |
| 1870 // Block the connection. | 1969 // Block the connection. |
| 1871 BlockOnNextWrite(); | 1970 BlockOnNextWrite(); |
| 1872 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); | 1971 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); |
| 1873 EXPECT_EQ(1u, writer_->packets_write_attempts()); | 1972 EXPECT_EQ(1u, writer_->packets_write_attempts()); |
| 1874 EXPECT_TRUE(writer_->IsWriteBlocked()); | 1973 EXPECT_TRUE(writer_->IsWriteBlocked()); |
| 1875 | 1974 |
| 1876 // Set the send and resumption alarms. Fire the alarms and ensure they don't | 1975 // Set the send and resumption alarms. Fire the alarms and ensure they don't |
| 1877 // attempt to write. | 1976 // attempt to write. |
| 1878 connection_.GetResumeWritesAlarm()->Set(clock_.ApproximateNow()); | 1977 connection_.GetResumeWritesAlarm()->Set(clock_.ApproximateNow()); |
| 1879 connection_.GetSendAlarm()->Set(clock_.ApproximateNow()); | 1978 connection_.GetSendAlarm()->Set(clock_.ApproximateNow()); |
| 1880 connection_.GetResumeWritesAlarm()->Fire(); | 1979 connection_.GetResumeWritesAlarm()->Fire(); |
| 1881 connection_.GetSendAlarm()->Fire(); | 1980 connection_.GetSendAlarm()->Fire(); |
| 1882 EXPECT_TRUE(writer_->IsWriteBlocked()); | 1981 EXPECT_TRUE(writer_->IsWriteBlocked()); |
| 1883 EXPECT_EQ(1u, writer_->packets_write_attempts()); | 1982 EXPECT_EQ(1u, writer_->packets_write_attempts()); |
| 1884 } | 1983 } |
| 1885 | 1984 |
| 1886 TEST_F(QuicConnectionTest, NoLimitPacketsPerNack) { | 1985 TEST_P(QuicConnectionTest, NoLimitPacketsPerNack) { |
| 1887 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1986 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1888 int offset = 0; | 1987 int offset = 0; |
| 1889 // Send packets 1 to 15. | 1988 // Send packets 1 to 15. |
| 1890 for (int i = 0; i < 15; ++i) { | 1989 for (int i = 0; i < 15; ++i) { |
| 1891 SendStreamDataToPeer(1, "foo", offset, !kFin, NULL); | 1990 SendStreamDataToPeer(1, "foo", offset, !kFin, NULL); |
| 1892 offset += 3; | 1991 offset += 3; |
| 1893 } | 1992 } |
| 1894 | 1993 |
| 1895 // Ack 15, nack 1-14. | 1994 // Ack 15, nack 1-14. |
| 1896 QuicAckFrame nack = InitAckFrame(15, 0); | 1995 QuicAckFrame nack = InitAckFrame(15, 0); |
| 1897 for (int i = 1; i < 15; ++i) { | 1996 for (int i = 1; i < 15; ++i) { |
| 1898 NackPacket(i, &nack); | 1997 NackPacket(i, &nack); |
| 1899 } | 1998 } |
| 1900 | 1999 |
| 1901 // 14 packets have been NACK'd and lost. In TCP cubic, PRR limits | 2000 // 14 packets have been NACK'd and lost. In TCP cubic, PRR limits |
| 1902 // the retransmission rate in the case of burst losses. | 2001 // the retransmission rate in the case of burst losses. |
| 1903 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); | 2002 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); |
| 1904 EXPECT_CALL(*send_algorithm_, OnPacketAcked(15, _)).Times(1); | 2003 EXPECT_CALL(*send_algorithm_, OnPacketAcked(15, _)).Times(1); |
| 1905 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(14); | 2004 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(14); |
| 1906 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(14); | 2005 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(14); |
| 1907 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(14); | 2006 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(14); |
| 1908 ProcessAckPacket(&nack); | 2007 ProcessAckPacket(&nack); |
| 1909 } | 2008 } |
| 1910 | 2009 |
| 1911 // Test sending multiple acks from the connection to the session. | 2010 // Test sending multiple acks from the connection to the session. |
| 1912 TEST_F(QuicConnectionTest, MultipleAcks) { | 2011 TEST_P(QuicConnectionTest, MultipleAcks) { |
| 1913 QuicPacketSequenceNumber last_packet; | 2012 QuicPacketSequenceNumber last_packet; |
| 1914 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 | 2013 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 |
| 1915 EXPECT_EQ(1u, last_packet); | 2014 EXPECT_EQ(1u, last_packet); |
| 1916 SendStreamDataToPeer(3, "foo", 0, !kFin, &last_packet); // Packet 2 | 2015 SendStreamDataToPeer(3, "foo", 0, !kFin, &last_packet); // Packet 2 |
| 1917 EXPECT_EQ(2u, last_packet); | 2016 EXPECT_EQ(2u, last_packet); |
| 1918 SendAckPacketToPeer(); // Packet 3 | 2017 SendAckPacketToPeer(); // Packet 3 |
| 1919 SendStreamDataToPeer(5, "foo", 0, !kFin, &last_packet); // Packet 4 | 2018 SendStreamDataToPeer(5, "foo", 0, !kFin, &last_packet); // Packet 4 |
| 1920 EXPECT_EQ(4u, last_packet); | 2019 EXPECT_EQ(4u, last_packet); |
| 1921 SendStreamDataToPeer(1, "foo", 3, !kFin, &last_packet); // Packet 5 | 2020 SendStreamDataToPeer(1, "foo", 3, !kFin, &last_packet); // Packet 5 |
| 1922 EXPECT_EQ(5u, last_packet); | 2021 EXPECT_EQ(5u, last_packet); |
| 1923 SendStreamDataToPeer(3, "foo", 3, !kFin, &last_packet); // Packet 6 | 2022 SendStreamDataToPeer(3, "foo", 3, !kFin, &last_packet); // Packet 6 |
| 1924 EXPECT_EQ(6u, last_packet); | 2023 EXPECT_EQ(6u, last_packet); |
| 1925 | 2024 |
| 1926 // Client will ack packets 1, 2, [!3], 4, 5. | 2025 // Client will ack packets 1, 2, [!3], 4, 5. |
| 1927 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); | 2026 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); |
| 1928 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(4); | 2027 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(4); |
| 1929 QuicAckFrame frame1 = InitAckFrame(5, 0); | 2028 QuicAckFrame frame1 = InitAckFrame(5, 0); |
| 1930 NackPacket(3, &frame1); | 2029 NackPacket(3, &frame1); |
| 1931 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2030 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1932 ProcessAckPacket(&frame1); | 2031 ProcessAckPacket(&frame1); |
| 1933 | 2032 |
| 1934 // Now the client implicitly acks 3, and explicitly acks 6. | 2033 // Now the client implicitly acks 3, and explicitly acks 6. |
| 1935 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); | 2034 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); |
| 1936 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(2); | 2035 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(2); |
| 1937 QuicAckFrame frame2 = InitAckFrame(6, 0); | 2036 QuicAckFrame frame2 = InitAckFrame(6, 0); |
| 1938 ProcessAckPacket(&frame2); | 2037 ProcessAckPacket(&frame2); |
| 1939 } | 2038 } |
| 1940 | 2039 |
| 1941 TEST_F(QuicConnectionTest, DontLatchUnackedPacket) { | 2040 TEST_P(QuicConnectionTest, DontLatchUnackedPacket) { |
| 1942 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); | 2041 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); |
| 1943 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(1); | 2042 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(1); |
| 1944 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); // Packet 1; | 2043 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); // Packet 1; |
| 1945 // From now on, we send acks, so the send algorithm won't save them. | 2044 // From now on, we send acks, so the send algorithm won't save them. |
| 1946 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 2045 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
| 1947 .WillByDefault(Return(false)); | 2046 .WillByDefault(Return(false)); |
| 1948 SendAckPacketToPeer(); // Packet 2 | 2047 SendAckPacketToPeer(); // Packet 2 |
| 1949 | 2048 |
| 1950 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2049 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1951 QuicAckFrame frame = InitAckFrame(1, 0); | 2050 QuicAckFrame frame = InitAckFrame(1, 0); |
| 1952 ProcessAckPacket(&frame); | 2051 ProcessAckPacket(&frame); |
| 1953 | 2052 |
| 1954 // Verify that our internal state has least-unacked as 3. | 2053 // Verify that our internal state has least-unacked as 3. |
| 1955 EXPECT_EQ(3u, outgoing_ack()->sent_info.least_unacked); | 2054 EXPECT_EQ(3u, outgoing_ack()->sent_info.least_unacked); |
| 1956 | 2055 |
| 1957 // When we send an ack, we make sure our least-unacked makes sense. In this | 2056 // When we send an ack, we make sure our least-unacked makes sense. In this |
| 1958 // case since we're not waiting on an ack for 2 and all packets are acked, we | 2057 // case since we're not waiting on an ack for 2 and all packets are acked, we |
| 1959 // set it to 3. | 2058 // set it to 3. |
| 1960 SendAckPacketToPeer(); // Packet 3 | 2059 SendAckPacketToPeer(); // Packet 3 |
| 1961 // Since this was an ack packet, we set least_unacked to 4. | 2060 // Since this was an ack packet, we set least_unacked to 4. |
| 1962 EXPECT_EQ(4u, outgoing_ack()->sent_info.least_unacked); | 2061 EXPECT_EQ(4u, outgoing_ack()->sent_info.least_unacked); |
| 1963 // Check that the outgoing ack had its sequence number as least_unacked. | 2062 // Check that the outgoing ack had its sequence number as least_unacked. |
| 1964 EXPECT_EQ(3u, last_ack()->sent_info.least_unacked); | 2063 EXPECT_EQ(3u, least_unacked()); |
| 1965 | 2064 |
| 1966 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 2065 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
| 1967 .WillByDefault(Return(true)); | 2066 .WillByDefault(Return(true)); |
| 1968 SendStreamDataToPeer(1, "bar", 3, false, NULL); // Packet 4 | 2067 SendStreamDataToPeer(1, "bar", 3, false, NULL); // Packet 4 |
| 1969 EXPECT_EQ(4u, outgoing_ack()->sent_info.least_unacked); | 2068 EXPECT_EQ(4u, outgoing_ack()->sent_info.least_unacked); |
| 1970 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 2069 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
| 1971 .WillByDefault(Return(false)); | 2070 .WillByDefault(Return(false)); |
| 1972 SendAckPacketToPeer(); // Packet 5 | 2071 SendAckPacketToPeer(); // Packet 5 |
| 1973 EXPECT_EQ(4u, last_ack()->sent_info.least_unacked); | 2072 EXPECT_EQ(4u, least_unacked()); |
| 1974 } | 2073 } |
| 1975 | 2074 |
| 1976 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterFecPacket) { | 2075 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterFecPacket) { |
| 2076 if (version() < QUIC_VERSION_15) { |
| 2077 return; |
| 2078 } |
| 1977 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2079 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1978 | 2080 |
| 1979 // Don't send missing packet 1. | 2081 // Don't send missing packet 1. |
| 1980 ProcessFecPacket(2, 1, true, !kEntropyFlag, NULL); | 2082 ProcessFecPacket(2, 1, true, !kEntropyFlag, NULL); |
| 1981 // Entropy flag should be false, so entropy should be 0. | 2083 // Entropy flag should be false, so entropy should be 0. |
| 1982 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); | 2084 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); |
| 1983 } | 2085 } |
| 1984 | 2086 |
| 1985 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPacketThenFecPacket) { | 2087 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPacketThenFecPacket) { |
| 2088 if (version() < QUIC_VERSION_15) { |
| 2089 return; |
| 2090 } |
| 1986 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2091 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1987 | 2092 |
| 1988 ProcessFecProtectedPacket(1, false, kEntropyFlag); | 2093 ProcessFecProtectedPacket(1, false, kEntropyFlag); |
| 1989 // Don't send missing packet 2. | 2094 // Don't send missing packet 2. |
| 1990 ProcessFecPacket(3, 1, true, !kEntropyFlag, NULL); | 2095 ProcessFecPacket(3, 1, true, !kEntropyFlag, NULL); |
| 1991 // Entropy flag should be true, so entropy should not be 0. | 2096 // Entropy flag should be true, so entropy should not be 0. |
| 1992 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); | 2097 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); |
| 1993 } | 2098 } |
| 1994 | 2099 |
| 1995 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPacketsThenFecPacket) { | 2100 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPacketsThenFecPacket) { |
| 2101 if (version() < QUIC_VERSION_15) { |
| 2102 return; |
| 2103 } |
| 1996 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2104 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1997 | 2105 |
| 1998 ProcessFecProtectedPacket(1, false, !kEntropyFlag); | 2106 ProcessFecProtectedPacket(1, false, !kEntropyFlag); |
| 1999 // Don't send missing packet 2. | 2107 // Don't send missing packet 2. |
| 2000 ProcessFecProtectedPacket(3, false, !kEntropyFlag); | 2108 ProcessFecProtectedPacket(3, false, !kEntropyFlag); |
| 2001 ProcessFecPacket(4, 1, true, kEntropyFlag, NULL); | 2109 ProcessFecPacket(4, 1, true, kEntropyFlag, NULL); |
| 2002 // Ensure QUIC no longer revives entropy for lost packets. | 2110 // Ensure QUIC no longer revives entropy for lost packets. |
| 2003 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); | 2111 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); |
| 2004 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 4)); | 2112 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 4)); |
| 2005 } | 2113 } |
| 2006 | 2114 |
| 2007 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPacket) { | 2115 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPacket) { |
| 2116 if (version() < QUIC_VERSION_15) { |
| 2117 return; |
| 2118 } |
| 2008 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2119 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2009 | 2120 |
| 2010 // Don't send missing packet 1. | 2121 // Don't send missing packet 1. |
| 2011 ProcessFecPacket(3, 1, false, !kEntropyFlag, NULL); | 2122 ProcessFecPacket(3, 1, false, !kEntropyFlag, NULL); |
| 2012 // Out of order. | 2123 // Out of order. |
| 2013 ProcessFecProtectedPacket(2, true, !kEntropyFlag); | 2124 ProcessFecProtectedPacket(2, true, !kEntropyFlag); |
| 2014 // Entropy flag should be false, so entropy should be 0. | 2125 // Entropy flag should be false, so entropy should be 0. |
| 2015 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); | 2126 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); |
| 2016 } | 2127 } |
| 2017 | 2128 |
| 2018 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPackets) { | 2129 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPackets) { |
| 2130 if (version() < QUIC_VERSION_15) { |
| 2131 return; |
| 2132 } |
| 2019 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2133 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2020 | 2134 |
| 2021 ProcessFecProtectedPacket(1, false, !kEntropyFlag); | 2135 ProcessFecProtectedPacket(1, false, !kEntropyFlag); |
| 2022 // Don't send missing packet 2. | 2136 // Don't send missing packet 2. |
| 2023 ProcessFecPacket(6, 1, false, kEntropyFlag, NULL); | 2137 ProcessFecPacket(6, 1, false, kEntropyFlag, NULL); |
| 2024 ProcessFecProtectedPacket(3, false, kEntropyFlag); | 2138 ProcessFecProtectedPacket(3, false, kEntropyFlag); |
| 2025 ProcessFecProtectedPacket(4, false, kEntropyFlag); | 2139 ProcessFecProtectedPacket(4, false, kEntropyFlag); |
| 2026 ProcessFecProtectedPacket(5, true, !kEntropyFlag); | 2140 ProcessFecProtectedPacket(5, true, !kEntropyFlag); |
| 2027 // Ensure entropy is not revived for the missing packet. | 2141 // Ensure entropy is not revived for the missing packet. |
| 2028 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); | 2142 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); |
| 2029 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 3)); | 2143 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 3)); |
| 2030 } | 2144 } |
| 2031 | 2145 |
| 2032 TEST_F(QuicConnectionTest, RTO) { | 2146 TEST_P(QuicConnectionTest, RTO) { |
| 2033 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( | 2147 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( |
| 2034 DefaultRetransmissionTime()); | 2148 DefaultRetransmissionTime()); |
| 2035 SendStreamDataToPeer(3, "foo", 0, !kFin, NULL); | 2149 SendStreamDataToPeer(3, "foo", 0, !kFin, NULL); |
| 2036 EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked); | 2150 EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked); |
| 2037 | 2151 |
| 2038 EXPECT_EQ(1u, last_header()->packet_sequence_number); | 2152 EXPECT_EQ(1u, last_header()->packet_sequence_number); |
| 2039 EXPECT_EQ(default_retransmission_time, | 2153 EXPECT_EQ(default_retransmission_time, |
| 2040 connection_.GetRetransmissionAlarm()->deadline()); | 2154 connection_.GetRetransmissionAlarm()->deadline()); |
| 2041 // Simulate the retransmission alarm firing. | 2155 // Simulate the retransmission alarm firing. |
| 2042 clock_.AdvanceTime(DefaultRetransmissionTime()); | 2156 clock_.AdvanceTime(DefaultRetransmissionTime()); |
| 2043 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); | 2157 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
| 2044 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 2u, _, _, _)); | 2158 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 2u, _, _, _)); |
| 2045 connection_.GetRetransmissionAlarm()->Fire(); | 2159 connection_.GetRetransmissionAlarm()->Fire(); |
| 2046 EXPECT_EQ(2u, last_header()->packet_sequence_number); | 2160 EXPECT_EQ(2u, last_header()->packet_sequence_number); |
| 2047 // We do not raise the high water mark yet. | 2161 // We do not raise the high water mark yet. |
| 2048 EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked); | 2162 EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked); |
| 2049 } | 2163 } |
| 2050 | 2164 |
| 2051 TEST_F(QuicConnectionTest, RTOWithSameEncryptionLevel) { | 2165 TEST_P(QuicConnectionTest, RTOWithSameEncryptionLevel) { |
| 2052 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( | 2166 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( |
| 2053 DefaultRetransmissionTime()); | 2167 DefaultRetransmissionTime()); |
| 2054 use_tagging_decrypter(); | 2168 use_tagging_decrypter(); |
| 2055 | 2169 |
| 2056 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at | 2170 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at |
| 2057 // the end of the packet. We can test this to check which encrypter was used. | 2171 // the end of the packet. We can test this to check which encrypter was used. |
| 2058 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); | 2172 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); |
| 2059 SendStreamDataToPeer(3, "foo", 0, !kFin, NULL); | 2173 SendStreamDataToPeer(3, "foo", 0, !kFin, NULL); |
| 2060 EXPECT_EQ(0x01010101u, final_bytes_of_last_packet()); | 2174 EXPECT_EQ(0x01010101u, final_bytes_of_last_packet()); |
| 2061 | 2175 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2077 clock_.AdvanceTime(DefaultRetransmissionTime()); | 2191 clock_.AdvanceTime(DefaultRetransmissionTime()); |
| 2078 connection_.GetRetransmissionAlarm()->Fire(); | 2192 connection_.GetRetransmissionAlarm()->Fire(); |
| 2079 | 2193 |
| 2080 // Packet should have been sent with ENCRYPTION_NONE. | 2194 // Packet should have been sent with ENCRYPTION_NONE. |
| 2081 EXPECT_EQ(0x01010101u, final_bytes_of_previous_packet()); | 2195 EXPECT_EQ(0x01010101u, final_bytes_of_previous_packet()); |
| 2082 | 2196 |
| 2083 // Packet should have been sent with ENCRYPTION_INITIAL. | 2197 // Packet should have been sent with ENCRYPTION_INITIAL. |
| 2084 EXPECT_EQ(0x02020202u, final_bytes_of_last_packet()); | 2198 EXPECT_EQ(0x02020202u, final_bytes_of_last_packet()); |
| 2085 } | 2199 } |
| 2086 | 2200 |
| 2087 TEST_F(QuicConnectionTest, SendHandshakeMessages) { | 2201 TEST_P(QuicConnectionTest, SendHandshakeMessages) { |
| 2088 use_tagging_decrypter(); | 2202 use_tagging_decrypter(); |
| 2089 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at | 2203 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at |
| 2090 // the end of the packet. We can test this to check which encrypter was used. | 2204 // the end of the packet. We can test this to check which encrypter was used. |
| 2091 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); | 2205 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); |
| 2092 | 2206 |
| 2093 // Attempt to send a handshake message while the congestion manager | 2207 // Attempt to send a handshake message while the congestion manager |
| 2094 // does not permit sending. | 2208 // does not permit sending. |
| 2095 EXPECT_CALL(*send_algorithm_, | 2209 EXPECT_CALL(*send_algorithm_, |
| 2096 TimeUntilSend(_, _, _, IS_HANDSHAKE)).WillRepeatedly( | 2210 TimeUntilSend(_, _, _, IS_HANDSHAKE)).WillRepeatedly( |
| 2097 testing::Return(QuicTime::Delta::Infinite())); | 2211 testing::Return(QuicTime::Delta::Infinite())); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2108 TimeUntilSend(_, _, _, IS_HANDSHAKE)).WillRepeatedly( | 2222 TimeUntilSend(_, _, _, IS_HANDSHAKE)).WillRepeatedly( |
| 2109 testing::Return(QuicTime::Delta::Zero())); | 2223 testing::Return(QuicTime::Delta::Zero())); |
| 2110 EXPECT_CALL(visitor_, OnCanWrite()); | 2224 EXPECT_CALL(visitor_, OnCanWrite()); |
| 2111 connection_.OnCanWrite(); | 2225 connection_.OnCanWrite(); |
| 2112 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 2226 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 2113 | 2227 |
| 2114 // Verify that the handshake packet went out at the null encryption. | 2228 // Verify that the handshake packet went out at the null encryption. |
| 2115 EXPECT_EQ(0x01010101u, final_bytes_of_last_packet()); | 2229 EXPECT_EQ(0x01010101u, final_bytes_of_last_packet()); |
| 2116 } | 2230 } |
| 2117 | 2231 |
| 2118 TEST_F(QuicConnectionTest, | 2232 TEST_P(QuicConnectionTest, |
| 2119 DropRetransmitsForNullEncryptedPacketAfterForwardSecure) { | 2233 DropRetransmitsForNullEncryptedPacketAfterForwardSecure) { |
| 2120 use_tagging_decrypter(); | 2234 use_tagging_decrypter(); |
| 2121 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); | 2235 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); |
| 2122 QuicPacketSequenceNumber sequence_number; | 2236 QuicPacketSequenceNumber sequence_number; |
| 2123 SendStreamDataToPeer(3, "foo", 0, !kFin, &sequence_number); | 2237 SendStreamDataToPeer(3, "foo", 0, !kFin, &sequence_number); |
| 2124 | 2238 |
| 2125 connection_.SetEncrypter(ENCRYPTION_FORWARD_SECURE, | 2239 connection_.SetEncrypter(ENCRYPTION_FORWARD_SECURE, |
| 2126 new TaggingEncrypter(0x02)); | 2240 new TaggingEncrypter(0x02)); |
| 2127 connection_.SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); | 2241 connection_.SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); |
| 2128 | 2242 |
| 2129 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); | 2243 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
| 2130 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); | 2244 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); |
| 2131 | 2245 |
| 2132 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( | 2246 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( |
| 2133 DefaultRetransmissionTime()); | 2247 DefaultRetransmissionTime()); |
| 2134 | 2248 |
| 2135 EXPECT_EQ(default_retransmission_time, | 2249 EXPECT_EQ(default_retransmission_time, |
| 2136 connection_.GetRetransmissionAlarm()->deadline()); | 2250 connection_.GetRetransmissionAlarm()->deadline()); |
| 2137 // Simulate the retransmission alarm firing. | 2251 // Simulate the retransmission alarm firing. |
| 2138 clock_.AdvanceTime(DefaultRetransmissionTime()); | 2252 clock_.AdvanceTime(DefaultRetransmissionTime()); |
| 2139 connection_.GetRetransmissionAlarm()->Fire(); | 2253 connection_.GetRetransmissionAlarm()->Fire(); |
| 2140 } | 2254 } |
| 2141 | 2255 |
| 2142 TEST_F(QuicConnectionTest, RetransmitPacketsWithInitialEncryption) { | 2256 TEST_P(QuicConnectionTest, RetransmitPacketsWithInitialEncryption) { |
| 2143 use_tagging_decrypter(); | 2257 use_tagging_decrypter(); |
| 2144 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); | 2258 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); |
| 2145 connection_.SetDefaultEncryptionLevel(ENCRYPTION_NONE); | 2259 connection_.SetDefaultEncryptionLevel(ENCRYPTION_NONE); |
| 2146 | 2260 |
| 2147 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); | 2261 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); |
| 2148 | 2262 |
| 2149 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); | 2263 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); |
| 2150 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); | 2264 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); |
| 2151 | 2265 |
| 2152 SendStreamDataToPeer(2, "bar", 0, !kFin, NULL); | 2266 SendStreamDataToPeer(2, "bar", 0, !kFin, NULL); |
| 2153 | 2267 |
| 2154 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 2268 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
| 2155 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(1); | 2269 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(1); |
| 2156 | 2270 |
| 2157 connection_.RetransmitUnackedPackets(INITIAL_ENCRYPTION_ONLY); | 2271 connection_.RetransmitUnackedPackets(INITIAL_ENCRYPTION_ONLY); |
| 2158 } | 2272 } |
| 2159 | 2273 |
| 2160 TEST_F(QuicConnectionTest, BufferNonDecryptablePackets) { | 2274 TEST_P(QuicConnectionTest, BufferNonDecryptablePackets) { |
| 2161 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2275 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2162 use_tagging_decrypter(); | 2276 use_tagging_decrypter(); |
| 2163 | 2277 |
| 2164 const uint8 tag = 0x07; | 2278 const uint8 tag = 0x07; |
| 2165 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 2279 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
| 2166 | 2280 |
| 2167 // Process an encrypted packet which can not yet be decrypted | 2281 // Process an encrypted packet which can not yet be decrypted |
| 2168 // which should result in the packet being buffered. | 2282 // which should result in the packet being buffered. |
| 2169 ProcessDataPacketAtLevel(1, false, kEntropyFlag, ENCRYPTION_INITIAL); | 2283 ProcessDataPacketAtLevel(1, false, kEntropyFlag, ENCRYPTION_INITIAL); |
| 2170 | 2284 |
| 2171 // Transition to the new encryption state and process another | 2285 // Transition to the new encryption state and process another |
| 2172 // encrypted packet which should result in the original packet being | 2286 // encrypted packet which should result in the original packet being |
| 2173 // processed. | 2287 // processed. |
| 2174 connection_.SetDecrypter(new StrictTaggingDecrypter(tag)); | 2288 connection_.SetDecrypter(new StrictTaggingDecrypter(tag)); |
| 2175 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); | 2289 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); |
| 2176 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 2290 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
| 2177 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(2).WillRepeatedly( | 2291 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(2).WillRepeatedly( |
| 2178 Return(true)); | 2292 Return(true)); |
| 2179 ProcessDataPacketAtLevel(2, false, kEntropyFlag, ENCRYPTION_INITIAL); | 2293 ProcessDataPacketAtLevel(2, false, kEntropyFlag, ENCRYPTION_INITIAL); |
| 2180 | 2294 |
| 2181 // Finally, process a third packet and note that we do not | 2295 // Finally, process a third packet and note that we do not |
| 2182 // reprocess the buffered packet. | 2296 // reprocess the buffered packet. |
| 2183 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillOnce(Return(true)); | 2297 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillOnce(Return(true)); |
| 2184 ProcessDataPacketAtLevel(3, false, kEntropyFlag, ENCRYPTION_INITIAL); | 2298 ProcessDataPacketAtLevel(3, false, kEntropyFlag, ENCRYPTION_INITIAL); |
| 2185 } | 2299 } |
| 2186 | 2300 |
| 2187 TEST_F(QuicConnectionTest, TestRetransmitOrder) { | 2301 TEST_P(QuicConnectionTest, TestRetransmitOrder) { |
| 2188 QuicByteCount first_packet_size; | 2302 QuicByteCount first_packet_size; |
| 2189 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).WillOnce( | 2303 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).WillOnce( |
| 2190 DoAll(SaveArg<2>(&first_packet_size), Return(true))); | 2304 DoAll(SaveArg<2>(&first_packet_size), Return(true))); |
| 2191 | 2305 |
| 2192 connection_.SendStreamDataWithString(3, "first_packet", 0, !kFin, NULL); | 2306 connection_.SendStreamDataWithString(3, "first_packet", 0, !kFin, NULL); |
| 2193 QuicByteCount second_packet_size; | 2307 QuicByteCount second_packet_size; |
| 2194 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).WillOnce( | 2308 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).WillOnce( |
| 2195 DoAll(SaveArg<2>(&second_packet_size), Return(true))); | 2309 DoAll(SaveArg<2>(&second_packet_size), Return(true))); |
| 2196 connection_.SendStreamDataWithString(3, "second_packet", 12, !kFin, NULL); | 2310 connection_.SendStreamDataWithString(3, "second_packet", 12, !kFin, NULL); |
| 2197 EXPECT_NE(first_packet_size, second_packet_size); | 2311 EXPECT_NE(first_packet_size, second_packet_size); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2213 { | 2327 { |
| 2214 InSequence s; | 2328 InSequence s; |
| 2215 EXPECT_CALL(*send_algorithm_, | 2329 EXPECT_CALL(*send_algorithm_, |
| 2216 OnPacketSent(_, _, first_packet_size, _, _)); | 2330 OnPacketSent(_, _, first_packet_size, _, _)); |
| 2217 EXPECT_CALL(*send_algorithm_, | 2331 EXPECT_CALL(*send_algorithm_, |
| 2218 OnPacketSent(_, _, second_packet_size, _, _)); | 2332 OnPacketSent(_, _, second_packet_size, _, _)); |
| 2219 } | 2333 } |
| 2220 connection_.GetRetransmissionAlarm()->Fire(); | 2334 connection_.GetRetransmissionAlarm()->Fire(); |
| 2221 } | 2335 } |
| 2222 | 2336 |
| 2223 TEST_F(QuicConnectionTest, RetransmissionCountCalculation) { | 2337 TEST_P(QuicConnectionTest, RetransmissionCountCalculation) { |
| 2224 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2338 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2225 QuicPacketSequenceNumber original_sequence_number; | 2339 QuicPacketSequenceNumber original_sequence_number; |
| 2226 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)) | 2340 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)) |
| 2227 .WillOnce(DoAll(SaveArg<1>(&original_sequence_number), Return(true))); | 2341 .WillOnce(DoAll(SaveArg<1>(&original_sequence_number), Return(true))); |
| 2228 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); | 2342 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); |
| 2229 | 2343 |
| 2230 EXPECT_TRUE(QuicConnectionPeer::IsSavedForRetransmission( | 2344 EXPECT_TRUE(QuicConnectionPeer::IsSavedForRetransmission( |
| 2231 &connection_, original_sequence_number)); | 2345 &connection_, original_sequence_number)); |
| 2232 EXPECT_FALSE(QuicConnectionPeer::IsRetransmission( | 2346 EXPECT_FALSE(QuicConnectionPeer::IsRetransmission( |
| 2233 &connection_, original_sequence_number)); | 2347 &connection_, original_sequence_number)); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2265 } | 2379 } |
| 2266 ASSERT_NE(0u, nack_sequence_number); | 2380 ASSERT_NE(0u, nack_sequence_number); |
| 2267 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission( | 2381 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission( |
| 2268 &connection_, rto_sequence_number)); | 2382 &connection_, rto_sequence_number)); |
| 2269 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission( | 2383 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission( |
| 2270 &connection_, nack_sequence_number)); | 2384 &connection_, nack_sequence_number)); |
| 2271 EXPECT_TRUE(QuicConnectionPeer::IsRetransmission( | 2385 EXPECT_TRUE(QuicConnectionPeer::IsRetransmission( |
| 2272 &connection_, nack_sequence_number)); | 2386 &connection_, nack_sequence_number)); |
| 2273 } | 2387 } |
| 2274 | 2388 |
| 2275 TEST_F(QuicConnectionTest, SetRTOAfterWritingToSocket) { | 2389 TEST_P(QuicConnectionTest, SetRTOAfterWritingToSocket) { |
| 2276 BlockOnNextWrite(); | 2390 BlockOnNextWrite(); |
| 2277 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); | 2391 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); |
| 2278 // Make sure that RTO is not started when the packet is queued. | 2392 // Make sure that RTO is not started when the packet is queued. |
| 2279 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); | 2393 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); |
| 2280 | 2394 |
| 2281 // Test that RTO is started once we write to the socket. | 2395 // Test that RTO is started once we write to the socket. |
| 2282 writer_->SetWritable(); | 2396 writer_->SetWritable(); |
| 2283 connection_.OnCanWrite(); | 2397 connection_.OnCanWrite(); |
| 2284 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); | 2398 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); |
| 2285 } | 2399 } |
| 2286 | 2400 |
| 2287 TEST_F(QuicConnectionTest, DelayRTOWithAckReceipt) { | 2401 TEST_P(QuicConnectionTest, DelayRTOWithAckReceipt) { |
| 2288 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2402 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2289 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)) | 2403 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)) |
| 2290 .Times(2); | 2404 .Times(2); |
| 2291 connection_.SendStreamDataWithString(2, "foo", 0, !kFin, NULL); | 2405 connection_.SendStreamDataWithString(2, "foo", 0, !kFin, NULL); |
| 2292 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, NULL); | 2406 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, NULL); |
| 2293 QuicAlarm* retransmission_alarm = connection_.GetRetransmissionAlarm(); | 2407 QuicAlarm* retransmission_alarm = connection_.GetRetransmissionAlarm(); |
| 2294 EXPECT_TRUE(retransmission_alarm->IsSet()); | 2408 EXPECT_TRUE(retransmission_alarm->IsSet()); |
| 2295 | 2409 |
| 2296 // Advance the time right before the RTO, then receive an ack for the first | 2410 // Advance the time right before the RTO, then receive an ack for the first |
| 2297 // packet to delay the RTO. | 2411 // packet to delay the RTO. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2315 | 2429 |
| 2316 // The new retransmitted sequence number should set the RTO to a larger value | 2430 // The new retransmitted sequence number should set the RTO to a larger value |
| 2317 // than previously. | 2431 // than previously. |
| 2318 EXPECT_TRUE(retransmission_alarm->IsSet()); | 2432 EXPECT_TRUE(retransmission_alarm->IsSet()); |
| 2319 QuicTime next_rto_time = retransmission_alarm->deadline(); | 2433 QuicTime next_rto_time = retransmission_alarm->deadline(); |
| 2320 QuicTime expected_rto_time = | 2434 QuicTime expected_rto_time = |
| 2321 connection_.sent_packet_manager().GetRetransmissionTime(); | 2435 connection_.sent_packet_manager().GetRetransmissionTime(); |
| 2322 EXPECT_EQ(next_rto_time, expected_rto_time); | 2436 EXPECT_EQ(next_rto_time, expected_rto_time); |
| 2323 } | 2437 } |
| 2324 | 2438 |
| 2325 TEST_F(QuicConnectionTest, TestQueued) { | 2439 TEST_P(QuicConnectionTest, TestQueued) { |
| 2326 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 2440 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 2327 BlockOnNextWrite(); | 2441 BlockOnNextWrite(); |
| 2328 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); | 2442 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); |
| 2329 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 2443 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 2330 | 2444 |
| 2331 // Unblock the writes and actually send. | 2445 // Unblock the writes and actually send. |
| 2332 writer_->SetWritable(); | 2446 writer_->SetWritable(); |
| 2333 connection_.OnCanWrite(); | 2447 connection_.OnCanWrite(); |
| 2334 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 2448 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 2335 } | 2449 } |
| 2336 | 2450 |
| 2337 TEST_F(QuicConnectionTest, CloseFecGroup) { | 2451 TEST_P(QuicConnectionTest, CloseFecGroup) { |
| 2338 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2452 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2339 // Don't send missing packet 1. | 2453 // Don't send missing packet 1. |
| 2340 // Don't send missing packet 2. | 2454 // Don't send missing packet 2. |
| 2341 ProcessFecProtectedPacket(3, false, !kEntropyFlag); | 2455 ProcessFecProtectedPacket(3, false, !kEntropyFlag); |
| 2342 // Don't send missing FEC packet 3. | 2456 // Don't send missing FEC packet 3. |
| 2343 ASSERT_EQ(1u, connection_.NumFecGroups()); | 2457 ASSERT_EQ(1u, connection_.NumFecGroups()); |
| 2344 | 2458 |
| 2345 // Now send non-fec protected ack packet and close the group. | 2459 // Now send non-fec protected ack packet and close the group. |
| 2346 QuicAckFrame frame = InitAckFrame(0, 5); | |
| 2347 creator_.set_sequence_number(4); | 2460 creator_.set_sequence_number(4); |
| 2348 ProcessAckPacket(&frame); | 2461 if (version() > QUIC_VERSION_15) { |
| 2462 QuicStopWaitingFrame frame = InitStopWaitingFrame(5); |
| 2463 ProcessStopWaitingPacket(&frame); |
| 2464 } else { |
| 2465 QuicAckFrame frame = InitAckFrame(0, 5); |
| 2466 ProcessAckPacket(&frame); |
| 2467 } |
| 2349 ASSERT_EQ(0u, connection_.NumFecGroups()); | 2468 ASSERT_EQ(0u, connection_.NumFecGroups()); |
| 2350 } | 2469 } |
| 2351 | 2470 |
| 2352 TEST_F(QuicConnectionTest, NoQuicCongestionFeedbackFrame) { | 2471 TEST_P(QuicConnectionTest, NoQuicCongestionFeedbackFrame) { |
| 2353 SendAckPacketToPeer(); | 2472 SendAckPacketToPeer(); |
| 2354 EXPECT_TRUE(last_feedback() == NULL); | 2473 EXPECT_TRUE(last_feedback() == NULL); |
| 2355 } | 2474 } |
| 2356 | 2475 |
| 2357 TEST_F(QuicConnectionTest, WithQuicCongestionFeedbackFrame) { | 2476 TEST_P(QuicConnectionTest, WithQuicCongestionFeedbackFrame) { |
| 2358 QuicCongestionFeedbackFrame info; | 2477 QuicCongestionFeedbackFrame info; |
| 2359 info.type = kFixRate; | 2478 info.type = kFixRate; |
| 2360 info.fix_rate.bitrate = QuicBandwidth::FromBytesPerSecond(123); | 2479 info.fix_rate.bitrate = QuicBandwidth::FromBytesPerSecond(123); |
| 2361 SetFeedback(&info); | 2480 SetFeedback(&info); |
| 2362 | 2481 |
| 2363 SendAckPacketToPeer(); | 2482 SendAckPacketToPeer(); |
| 2364 EXPECT_EQ(kFixRate, last_feedback()->type); | 2483 EXPECT_EQ(kFixRate, last_feedback()->type); |
| 2365 EXPECT_EQ(info.fix_rate.bitrate, last_feedback()->fix_rate.bitrate); | 2484 EXPECT_EQ(info.fix_rate.bitrate, last_feedback()->fix_rate.bitrate); |
| 2366 } | 2485 } |
| 2367 | 2486 |
| 2368 TEST_F(QuicConnectionTest, UpdateQuicCongestionFeedbackFrame) { | 2487 TEST_P(QuicConnectionTest, UpdateQuicCongestionFeedbackFrame) { |
| 2369 SendAckPacketToPeer(); | 2488 SendAckPacketToPeer(); |
| 2370 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _)); | 2489 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _)); |
| 2371 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2490 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2372 ProcessPacket(1); | 2491 ProcessPacket(1); |
| 2373 } | 2492 } |
| 2374 | 2493 |
| 2375 TEST_F(QuicConnectionTest, DontUpdateQuicCongestionFeedbackFrameForRevived) { | 2494 TEST_P(QuicConnectionTest, DontUpdateQuicCongestionFeedbackFrameForRevived) { |
| 2495 if (version() < QUIC_VERSION_15) { |
| 2496 return; |
| 2497 } |
| 2376 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2498 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2377 SendAckPacketToPeer(); | 2499 SendAckPacketToPeer(); |
| 2378 // Process an FEC packet, and revive the missing data packet | 2500 // Process an FEC packet, and revive the missing data packet |
| 2379 // but only contact the receive_algorithm once. | 2501 // but only contact the receive_algorithm once. |
| 2380 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _)); | 2502 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _)); |
| 2381 ProcessFecPacket(2, 1, true, !kEntropyFlag, NULL); | 2503 ProcessFecPacket(2, 1, true, !kEntropyFlag, NULL); |
| 2382 } | 2504 } |
| 2383 | 2505 |
| 2384 TEST_F(QuicConnectionTest, InitialTimeout) { | 2506 TEST_P(QuicConnectionTest, InitialTimeout) { |
| 2385 EXPECT_TRUE(connection_.connected()); | 2507 EXPECT_TRUE(connection_.connected()); |
| 2386 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_CONNECTION_TIMED_OUT, false)); | 2508 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_CONNECTION_TIMED_OUT, false)); |
| 2387 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 2509 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| 2388 | 2510 |
| 2389 QuicTime default_timeout = clock_.ApproximateNow().Add( | 2511 QuicTime default_timeout = clock_.ApproximateNow().Add( |
| 2390 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)); | 2512 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)); |
| 2391 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); | 2513 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); |
| 2392 | 2514 |
| 2393 // Simulate the timeout alarm firing. | 2515 // Simulate the timeout alarm firing. |
| 2394 clock_.AdvanceTime( | 2516 clock_.AdvanceTime( |
| 2395 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)); | 2517 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)); |
| 2396 connection_.GetTimeoutAlarm()->Fire(); | 2518 connection_.GetTimeoutAlarm()->Fire(); |
| 2397 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); | 2519 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); |
| 2398 EXPECT_FALSE(connection_.connected()); | 2520 EXPECT_FALSE(connection_.connected()); |
| 2399 | 2521 |
| 2400 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 2522 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
| 2401 EXPECT_FALSE(connection_.GetResumeWritesAlarm()->IsSet()); | 2523 EXPECT_FALSE(connection_.GetResumeWritesAlarm()->IsSet()); |
| 2402 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); | 2524 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); |
| 2403 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet()); | 2525 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet()); |
| 2404 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); | 2526 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); |
| 2405 } | 2527 } |
| 2406 | 2528 |
| 2407 TEST_F(QuicConnectionTest, TimeoutAfterSend) { | 2529 TEST_P(QuicConnectionTest, TimeoutAfterSend) { |
| 2408 EXPECT_TRUE(connection_.connected()); | 2530 EXPECT_TRUE(connection_.connected()); |
| 2409 | 2531 |
| 2410 QuicTime default_timeout = clock_.ApproximateNow().Add( | 2532 QuicTime default_timeout = clock_.ApproximateNow().Add( |
| 2411 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)); | 2533 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)); |
| 2412 | 2534 |
| 2413 // When we send a packet, the timeout will change to 5000 + | 2535 // When we send a packet, the timeout will change to 5000 + |
| 2414 // kDefaultInitialTimeoutSecs. | 2536 // kDefaultInitialTimeoutSecs. |
| 2415 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); | 2537 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); |
| 2416 | 2538 |
| 2417 // Send an ack so we don't set the retransmission alarm. | 2539 // Send an ack so we don't set the retransmission alarm. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2433 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_CONNECTION_TIMED_OUT, false)); | 2555 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_CONNECTION_TIMED_OUT, false)); |
| 2434 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 2556 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| 2435 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); | 2557 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); |
| 2436 EXPECT_EQ(default_timeout.Add(QuicTime::Delta::FromMilliseconds(5)), | 2558 EXPECT_EQ(default_timeout.Add(QuicTime::Delta::FromMilliseconds(5)), |
| 2437 clock_.ApproximateNow()); | 2559 clock_.ApproximateNow()); |
| 2438 connection_.GetTimeoutAlarm()->Fire(); | 2560 connection_.GetTimeoutAlarm()->Fire(); |
| 2439 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); | 2561 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); |
| 2440 EXPECT_FALSE(connection_.connected()); | 2562 EXPECT_FALSE(connection_.connected()); |
| 2441 } | 2563 } |
| 2442 | 2564 |
| 2443 TEST_F(QuicConnectionTest, SendScheduler) { | 2565 TEST_P(QuicConnectionTest, SendScheduler) { |
| 2444 // Test that if we send a packet without delay, it is not queued. | 2566 // Test that if we send a packet without delay, it is not queued. |
| 2445 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); | 2567 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); |
| 2446 EXPECT_CALL(*send_algorithm_, | 2568 EXPECT_CALL(*send_algorithm_, |
| 2447 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( | 2569 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( |
| 2448 testing::Return(QuicTime::Delta::Zero())); | 2570 testing::Return(QuicTime::Delta::Zero())); |
| 2449 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 2571 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| 2450 connection_.SendPacket( | 2572 connection_.SendPacket( |
| 2451 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); | 2573 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); |
| 2452 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 2574 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 2453 } | 2575 } |
| 2454 | 2576 |
| 2455 TEST_F(QuicConnectionTest, SendSchedulerDelay) { | 2577 TEST_P(QuicConnectionTest, SendSchedulerDelay) { |
| 2456 // Test that if we send a packet with a delay, it ends up queued. | 2578 // Test that if we send a packet with a delay, it ends up queued. |
| 2457 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); | 2579 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); |
| 2458 EXPECT_CALL(*send_algorithm_, | 2580 EXPECT_CALL(*send_algorithm_, |
| 2459 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( | 2581 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( |
| 2460 testing::Return(QuicTime::Delta::FromMicroseconds(1))); | 2582 testing::Return(QuicTime::Delta::FromMicroseconds(1))); |
| 2461 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 1, _, _, _)).Times(0); | 2583 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 1, _, _, _)).Times(0); |
| 2462 connection_.SendPacket( | 2584 connection_.SendPacket( |
| 2463 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); | 2585 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); |
| 2464 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 2586 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 2465 } | 2587 } |
| 2466 | 2588 |
| 2467 TEST_F(QuicConnectionTest, SendSchedulerForce) { | 2589 TEST_P(QuicConnectionTest, SendSchedulerForce) { |
| 2468 // Test that if we force send a packet, it is not queued. | 2590 // Test that if we force send a packet, it is not queued. |
| 2469 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); | 2591 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); |
| 2470 EXPECT_CALL(*send_algorithm_, | 2592 EXPECT_CALL(*send_algorithm_, |
| 2471 TimeUntilSend(_, NACK_RETRANSMISSION, _, _)).Times(0); | 2593 TimeUntilSend(_, NACK_RETRANSMISSION, _, _)).Times(0); |
| 2472 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 2594 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| 2473 connection_.SendPacket( | 2595 connection_.SendPacket( |
| 2474 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); | 2596 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); |
| 2475 // XXX: fixme. was: connection_.SendPacket(1, packet, kForce); | 2597 // XXX: fixme. was: connection_.SendPacket(1, packet, kForce); |
| 2476 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 2598 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 2477 } | 2599 } |
| 2478 | 2600 |
| 2479 TEST_F(QuicConnectionTest, SendSchedulerEAGAIN) { | 2601 TEST_P(QuicConnectionTest, SendSchedulerEAGAIN) { |
| 2480 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); | 2602 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); |
| 2481 BlockOnNextWrite(); | 2603 BlockOnNextWrite(); |
| 2482 EXPECT_CALL(*send_algorithm_, | 2604 EXPECT_CALL(*send_algorithm_, |
| 2483 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( | 2605 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( |
| 2484 testing::Return(QuicTime::Delta::Zero())); | 2606 testing::Return(QuicTime::Delta::Zero())); |
| 2485 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 1, _, _, _)).Times(0); | 2607 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 1, _, _, _)).Times(0); |
| 2486 connection_.SendPacket( | 2608 connection_.SendPacket( |
| 2487 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); | 2609 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); |
| 2488 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 2610 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 2489 } | 2611 } |
| 2490 | 2612 |
| 2491 TEST_F(QuicConnectionTest, SendSchedulerDelayThenSend) { | 2613 TEST_P(QuicConnectionTest, SendSchedulerDelayThenSend) { |
| 2492 // Test that if we send a packet with a delay, it ends up queued. | 2614 // Test that if we send a packet with a delay, it ends up queued. |
| 2493 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); | 2615 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); |
| 2494 EXPECT_CALL(*send_algorithm_, | 2616 EXPECT_CALL(*send_algorithm_, |
| 2495 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( | 2617 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( |
| 2496 testing::Return(QuicTime::Delta::FromMicroseconds(1))); | 2618 testing::Return(QuicTime::Delta::FromMicroseconds(1))); |
| 2497 connection_.SendPacket( | 2619 connection_.SendPacket( |
| 2498 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); | 2620 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); |
| 2499 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 2621 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 2500 | 2622 |
| 2501 // Advance the clock to fire the alarm, and configure the scheduler | 2623 // Advance the clock to fire the alarm, and configure the scheduler |
| 2502 // to permit the packet to be sent. | 2624 // to permit the packet to be sent. |
| 2503 EXPECT_CALL(*send_algorithm_, | 2625 EXPECT_CALL(*send_algorithm_, |
| 2504 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillRepeatedly( | 2626 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillRepeatedly( |
| 2505 testing::Return(QuicTime::Delta::Zero())); | 2627 testing::Return(QuicTime::Delta::Zero())); |
| 2506 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1)); | 2628 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1)); |
| 2507 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 2629 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| 2508 connection_.GetSendAlarm()->Fire(); | 2630 connection_.GetSendAlarm()->Fire(); |
| 2509 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 2631 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 2510 } | 2632 } |
| 2511 | 2633 |
| 2512 TEST_F(QuicConnectionTest, SendSchedulerDelayThenRetransmit) { | 2634 TEST_P(QuicConnectionTest, SendSchedulerDelayThenRetransmit) { |
| 2513 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, NOT_RETRANSMISSION, _, _)) | 2635 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, NOT_RETRANSMISSION, _, _)) |
| 2514 .WillRepeatedly(testing::Return(QuicTime::Delta::Zero())); | 2636 .WillRepeatedly(testing::Return(QuicTime::Delta::Zero())); |
| 2515 EXPECT_CALL(*send_algorithm_, | 2637 EXPECT_CALL(*send_algorithm_, |
| 2516 OnPacketSent(_, 1, _, NOT_RETRANSMISSION, _)); | 2638 OnPacketSent(_, 1, _, NOT_RETRANSMISSION, _)); |
| 2517 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); | 2639 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); |
| 2518 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 2640 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 2519 // Advance the time for retransmission of lost packet. | 2641 // Advance the time for retransmission of lost packet. |
| 2520 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(501)); | 2642 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(501)); |
| 2521 // Test that if we send a retransmit with a delay, it ends up queued in the | 2643 // Test that if we send a retransmit with a delay, it ends up queued in the |
| 2522 // sent packet manager, but not yet serialized. | 2644 // sent packet manager, but not yet serialized. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2534 WillRepeatedly(testing::Return(QuicTime::Delta::Zero())); | 2656 WillRepeatedly(testing::Return(QuicTime::Delta::Zero())); |
| 2535 | 2657 |
| 2536 // Ensure the scheduler is notified this is a retransmit. | 2658 // Ensure the scheduler is notified this is a retransmit. |
| 2537 EXPECT_CALL(*send_algorithm_, | 2659 EXPECT_CALL(*send_algorithm_, |
| 2538 OnPacketSent(_, _, _, RTO_RETRANSMISSION, _)); | 2660 OnPacketSent(_, _, _, RTO_RETRANSMISSION, _)); |
| 2539 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1)); | 2661 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1)); |
| 2540 connection_.GetSendAlarm()->Fire(); | 2662 connection_.GetSendAlarm()->Fire(); |
| 2541 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 2663 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 2542 } | 2664 } |
| 2543 | 2665 |
| 2544 TEST_F(QuicConnectionTest, SendSchedulerDelayAndQueue) { | 2666 TEST_P(QuicConnectionTest, SendSchedulerDelayAndQueue) { |
| 2545 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); | 2667 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); |
| 2546 EXPECT_CALL(*send_algorithm_, | 2668 EXPECT_CALL(*send_algorithm_, |
| 2547 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( | 2669 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( |
| 2548 testing::Return(QuicTime::Delta::FromMicroseconds(1))); | 2670 testing::Return(QuicTime::Delta::FromMicroseconds(1))); |
| 2549 connection_.SendPacket( | 2671 connection_.SendPacket( |
| 2550 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); | 2672 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); |
| 2551 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 2673 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 2552 | 2674 |
| 2553 // Attempt to send another packet and make sure that it gets queued. | 2675 // Attempt to send another packet and make sure that it gets queued. |
| 2554 packet = ConstructDataPacket(2, 0, !kEntropyFlag); | 2676 packet = ConstructDataPacket(2, 0, !kEntropyFlag); |
| 2555 connection_.SendPacket( | 2677 connection_.SendPacket( |
| 2556 ENCRYPTION_NONE, 2, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); | 2678 ENCRYPTION_NONE, 2, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); |
| 2557 EXPECT_EQ(2u, connection_.NumQueuedPackets()); | 2679 EXPECT_EQ(2u, connection_.NumQueuedPackets()); |
| 2558 } | 2680 } |
| 2559 | 2681 |
| 2560 TEST_F(QuicConnectionTest, SendSchedulerDelayThenAckAndSend) { | 2682 TEST_P(QuicConnectionTest, SendSchedulerDelayThenAckAndSend) { |
| 2561 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2683 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2562 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); | 2684 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); |
| 2563 EXPECT_CALL(*send_algorithm_, | 2685 EXPECT_CALL(*send_algorithm_, |
| 2564 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( | 2686 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( |
| 2565 testing::Return(QuicTime::Delta::FromMicroseconds(10))); | 2687 testing::Return(QuicTime::Delta::FromMicroseconds(10))); |
| 2566 connection_.SendPacket( | 2688 connection_.SendPacket( |
| 2567 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); | 2689 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); |
| 2568 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 2690 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 2569 | 2691 |
| 2570 // Now send non-retransmitting information, that we're not going to | 2692 // Now send non-retransmitting information, that we're not going to |
| 2571 // retransmit 3. The far end should stop waiting for it. | 2693 // retransmit 3. The far end should stop waiting for it. |
| 2572 QuicAckFrame frame = InitAckFrame(0, 1); | 2694 QuicAckFrame frame = InitAckFrame(0, 1); |
| 2573 EXPECT_CALL(*send_algorithm_, | 2695 EXPECT_CALL(*send_algorithm_, |
| 2574 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillRepeatedly( | 2696 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillRepeatedly( |
| 2575 testing::Return(QuicTime::Delta::Zero())); | 2697 testing::Return(QuicTime::Delta::Zero())); |
| 2576 EXPECT_CALL(*send_algorithm_, | 2698 EXPECT_CALL(*send_algorithm_, |
| 2577 OnPacketSent(_, _, _, _, _)); | 2699 OnPacketSent(_, _, _, _, _)); |
| 2578 ProcessAckPacket(&frame); | 2700 ProcessAckPacket(&frame); |
| 2579 | 2701 |
| 2580 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 2702 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 2581 // Ensure alarm is not set | 2703 // Ensure alarm is not set |
| 2582 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet()); | 2704 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet()); |
| 2583 } | 2705 } |
| 2584 | 2706 |
| 2585 TEST_F(QuicConnectionTest, SendSchedulerDelayThenAckAndHold) { | 2707 TEST_P(QuicConnectionTest, SendSchedulerDelayThenAckAndHold) { |
| 2586 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2708 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2587 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); | 2709 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); |
| 2588 EXPECT_CALL(*send_algorithm_, | 2710 EXPECT_CALL(*send_algorithm_, |
| 2589 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( | 2711 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( |
| 2590 testing::Return(QuicTime::Delta::FromMicroseconds(10))); | 2712 testing::Return(QuicTime::Delta::FromMicroseconds(10))); |
| 2591 connection_.SendPacket( | 2713 connection_.SendPacket( |
| 2592 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); | 2714 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); |
| 2593 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 2715 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 2594 | 2716 |
| 2595 // Now send non-retransmitting information, that we're not going to | 2717 // Now send non-retransmitting information, that we're not going to |
| 2596 // retransmit 3. The far end should stop waiting for it. | 2718 // retransmit 3. The far end should stop waiting for it. |
| 2597 QuicAckFrame frame = InitAckFrame(0, 1); | 2719 QuicAckFrame frame = InitAckFrame(0, 1); |
| 2598 EXPECT_CALL(*send_algorithm_, | 2720 EXPECT_CALL(*send_algorithm_, |
| 2599 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( | 2721 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( |
| 2600 testing::Return(QuicTime::Delta::FromMicroseconds(1))); | 2722 testing::Return(QuicTime::Delta::FromMicroseconds(1))); |
| 2601 ProcessAckPacket(&frame); | 2723 ProcessAckPacket(&frame); |
| 2602 | 2724 |
| 2603 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 2725 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 2604 } | 2726 } |
| 2605 | 2727 |
| 2606 TEST_F(QuicConnectionTest, SendSchedulerDelayThenOnCanWrite) { | 2728 TEST_P(QuicConnectionTest, SendSchedulerDelayThenOnCanWrite) { |
| 2607 // TODO(ianswett): This test is unrealistic, because we would not serialize | 2729 // TODO(ianswett): This test is unrealistic, because we would not serialize |
| 2608 // new data if the send algorithm said not to. | 2730 // new data if the send algorithm said not to. |
| 2609 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); | 2731 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); |
| 2610 EXPECT_CALL(*send_algorithm_, | 2732 EXPECT_CALL(*send_algorithm_, |
| 2611 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( | 2733 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( |
| 2612 testing::Return(QuicTime::Delta::FromMicroseconds(10))); | 2734 testing::Return(QuicTime::Delta::FromMicroseconds(10))); |
| 2613 connection_.SendPacket( | 2735 connection_.SendPacket( |
| 2614 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); | 2736 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); |
| 2615 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 2737 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 2616 | 2738 |
| 2617 // OnCanWrite should send the packet, because it won't consult the send | 2739 // OnCanWrite should send the packet, because it won't consult the send |
| 2618 // algorithm for queued packets. | 2740 // algorithm for queued packets. |
| 2619 connection_.OnCanWrite(); | 2741 connection_.OnCanWrite(); |
| 2620 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 2742 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 2621 } | 2743 } |
| 2622 | 2744 |
| 2623 TEST_F(QuicConnectionTest, TestQueueLimitsOnSendStreamData) { | 2745 TEST_P(QuicConnectionTest, TestQueueLimitsOnSendStreamData) { |
| 2624 // All packets carry version info till version is negotiated. | 2746 // All packets carry version info till version is negotiated. |
| 2625 size_t payload_length; | 2747 size_t payload_length; |
| 2626 connection_.options()->max_packet_length = | 2748 connection_.options()->max_packet_length = |
| 2627 GetPacketLengthForOneStream( | 2749 GetPacketLengthForOneStream( |
| 2628 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, | 2750 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, |
| 2629 NOT_IN_FEC_GROUP, &payload_length); | 2751 NOT_IN_FEC_GROUP, &payload_length); |
| 2630 | 2752 |
| 2631 // Queue the first packet. | 2753 // Queue the first packet. |
| 2632 EXPECT_CALL(*send_algorithm_, | 2754 EXPECT_CALL(*send_algorithm_, |
| 2633 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( | 2755 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( |
| 2634 testing::Return(QuicTime::Delta::FromMicroseconds(10))); | 2756 testing::Return(QuicTime::Delta::FromMicroseconds(10))); |
| 2635 const string payload(payload_length, 'a'); | 2757 const string payload(payload_length, 'a'); |
| 2636 EXPECT_EQ(0u, | 2758 EXPECT_EQ(0u, |
| 2637 connection_.SendStreamDataWithString(3, payload, 0, | 2759 connection_.SendStreamDataWithString(3, payload, 0, |
| 2638 !kFin, NULL).bytes_consumed); | 2760 !kFin, NULL).bytes_consumed); |
| 2639 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 2761 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 2640 } | 2762 } |
| 2641 | 2763 |
| 2642 TEST_F(QuicConnectionTest, LoopThroughSendingPackets) { | 2764 TEST_P(QuicConnectionTest, LoopThroughSendingPackets) { |
| 2643 // All packets carry version info till version is negotiated. | 2765 // All packets carry version info till version is negotiated. |
| 2644 size_t payload_length; | 2766 size_t payload_length; |
| 2645 connection_.options()->max_packet_length = | 2767 connection_.options()->max_packet_length = |
| 2646 GetPacketLengthForOneStream( | 2768 GetPacketLengthForOneStream( |
| 2647 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, | 2769 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, |
| 2648 NOT_IN_FEC_GROUP, &payload_length); | 2770 NOT_IN_FEC_GROUP, &payload_length); |
| 2649 | 2771 |
| 2650 // Queue the first packet. | 2772 // Queue the first packet. |
| 2651 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(7); | 2773 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(7); |
| 2652 // The first stream frame will consume 2 fewer bytes than the other six. | 2774 // The first stream frame will consume 2 fewer bytes than the other six. |
| 2653 const string payload(payload_length * 7 - 12, 'a'); | 2775 const string payload(payload_length * 7 - 12, 'a'); |
| 2654 EXPECT_EQ(payload.size(), | 2776 EXPECT_EQ(payload.size(), |
| 2655 connection_.SendStreamDataWithString(1, payload, 0, | 2777 connection_.SendStreamDataWithString(1, payload, 0, |
| 2656 !kFin, NULL).bytes_consumed); | 2778 !kFin, NULL).bytes_consumed); |
| 2657 } | 2779 } |
| 2658 | 2780 |
| 2659 TEST_F(QuicConnectionTest, SendDelayedAckOnTimer) { | 2781 TEST_P(QuicConnectionTest, SendDelayedAckOnTimer) { |
| 2660 QuicTime ack_time = clock_.ApproximateNow().Add(DefaultDelayedAckTime()); | 2782 QuicTime ack_time = clock_.ApproximateNow().Add(DefaultDelayedAckTime()); |
| 2661 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2783 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2662 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 2784 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
| 2663 ProcessPacket(1); | 2785 ProcessPacket(1); |
| 2664 // Check if delayed ack timer is running for the expected interval. | 2786 // Check if delayed ack timer is running for the expected interval. |
| 2665 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); | 2787 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); |
| 2666 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); | 2788 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); |
| 2667 // Simulate delayed ack alarm firing. | 2789 // Simulate delayed ack alarm firing. |
| 2668 connection_.GetAckAlarm()->Fire(); | 2790 connection_.GetAckAlarm()->Fire(); |
| 2669 // Check that ack is sent and that delayed ack alarm is reset. | 2791 // Check that ack is sent and that delayed ack alarm is reset. |
| 2670 EXPECT_EQ(1u, writer_->frame_count()); | 2792 if (version() > QUIC_VERSION_15) { |
| 2793 EXPECT_EQ(2u, writer_->frame_count()); |
| 2794 EXPECT_TRUE(writer_->stop_waiting()); |
| 2795 } else { |
| 2796 EXPECT_EQ(1u, writer_->frame_count()); |
| 2797 } |
| 2671 EXPECT_TRUE(writer_->ack()); | 2798 EXPECT_TRUE(writer_->ack()); |
| 2672 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 2799 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
| 2673 } | 2800 } |
| 2674 | 2801 |
| 2675 TEST_F(QuicConnectionTest, SendDelayedAckOnSecondPacket) { | 2802 TEST_P(QuicConnectionTest, SendDelayedAckOnSecondPacket) { |
| 2676 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2803 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2677 ProcessPacket(1); | 2804 ProcessPacket(1); |
| 2678 ProcessPacket(2); | 2805 ProcessPacket(2); |
| 2679 // Check that ack is sent and that delayed ack alarm is reset. | 2806 // Check that ack is sent and that delayed ack alarm is reset. |
| 2680 EXPECT_EQ(1u, writer_->frame_count()); | 2807 if (version() > QUIC_VERSION_15) { |
| 2808 EXPECT_EQ(2u, writer_->frame_count()); |
| 2809 EXPECT_TRUE(writer_->stop_waiting()); |
| 2810 } else { |
| 2811 EXPECT_EQ(1u, writer_->frame_count()); |
| 2812 } |
| 2681 EXPECT_TRUE(writer_->ack()); | 2813 EXPECT_TRUE(writer_->ack()); |
| 2682 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 2814 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
| 2683 } | 2815 } |
| 2684 | 2816 |
| 2685 TEST_F(QuicConnectionTest, NoAckOnOldNacks) { | 2817 TEST_P(QuicConnectionTest, NoAckOnOldNacks) { |
| 2686 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2818 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2687 // Drop one packet, triggering a sequence of acks. | 2819 // Drop one packet, triggering a sequence of acks. |
| 2688 ProcessPacket(2); | 2820 ProcessPacket(2); |
| 2689 EXPECT_EQ(1u, writer_->frame_count()); | 2821 size_t frames_per_ack = version() > QUIC_VERSION_15 ? 2 : 1; |
| 2822 EXPECT_EQ(frames_per_ack, writer_->frame_count()); |
| 2690 EXPECT_TRUE(writer_->ack()); | 2823 EXPECT_TRUE(writer_->ack()); |
| 2691 writer_->Reset(); | 2824 writer_->Reset(); |
| 2692 ProcessPacket(3); | 2825 ProcessPacket(3); |
| 2693 EXPECT_EQ(1u, writer_->frame_count()); | 2826 EXPECT_EQ(frames_per_ack, writer_->frame_count()); |
| 2694 EXPECT_TRUE(writer_->ack()); | 2827 EXPECT_TRUE(writer_->ack()); |
| 2695 writer_->Reset(); | 2828 writer_->Reset(); |
| 2696 ProcessPacket(4); | 2829 ProcessPacket(4); |
| 2697 EXPECT_EQ(1u, writer_->frame_count()); | 2830 EXPECT_EQ(frames_per_ack, writer_->frame_count()); |
| 2698 EXPECT_TRUE(writer_->ack()); | 2831 EXPECT_TRUE(writer_->ack()); |
| 2699 writer_->Reset(); | 2832 writer_->Reset(); |
| 2700 ProcessPacket(5); | 2833 ProcessPacket(5); |
| 2701 EXPECT_EQ(1u, writer_->frame_count()); | 2834 EXPECT_EQ(frames_per_ack, writer_->frame_count()); |
| 2702 EXPECT_TRUE(writer_->ack()); | 2835 EXPECT_TRUE(writer_->ack()); |
| 2703 // Now only set the timer on the 6th packet, instead of sending another ack. | 2836 // Now only set the timer on the 6th packet, instead of sending another ack. |
| 2704 writer_->Reset(); | 2837 writer_->Reset(); |
| 2705 ProcessPacket(6); | 2838 ProcessPacket(6); |
| 2706 EXPECT_EQ(0u, writer_->frame_count()); | 2839 EXPECT_EQ(0u, writer_->frame_count()); |
| 2707 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); | 2840 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); |
| 2708 } | 2841 } |
| 2709 | 2842 |
| 2710 TEST_F(QuicConnectionTest, SendDelayedAckOnOutgoingPacket) { | 2843 TEST_P(QuicConnectionTest, SendDelayedAckOnOutgoingPacket) { |
| 2711 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2844 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2712 ProcessPacket(1); | 2845 ProcessPacket(1); |
| 2713 connection_.SendStreamDataWithString(kStreamId3, "foo", 0, !kFin, NULL); | 2846 connection_.SendStreamDataWithString(kStreamId3, "foo", 0, !kFin, NULL); |
| 2714 // Check that ack is bundled with outgoing data and that delayed ack | 2847 // Check that ack is bundled with outgoing data and that delayed ack |
| 2715 // alarm is reset. | 2848 // alarm is reset. |
| 2716 EXPECT_EQ(2u, writer_->frame_count()); | 2849 if (version() > QUIC_VERSION_15) { |
| 2850 EXPECT_EQ(3u, writer_->frame_count()); |
| 2851 EXPECT_TRUE(writer_->stop_waiting()); |
| 2852 } else { |
| 2853 EXPECT_EQ(2u, writer_->frame_count()); |
| 2854 } |
| 2717 EXPECT_TRUE(writer_->ack()); | 2855 EXPECT_TRUE(writer_->ack()); |
| 2718 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 2856 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
| 2719 } | 2857 } |
| 2720 | 2858 |
| 2721 TEST_F(QuicConnectionTest, DontSendDelayedAckOnOutgoingCryptoPacket) { | 2859 TEST_P(QuicConnectionTest, DontSendDelayedAckOnOutgoingCryptoPacket) { |
| 2722 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2860 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2723 ProcessPacket(1); | 2861 ProcessPacket(1); |
| 2724 connection_.SendStreamDataWithString(kCryptoStreamId, "foo", 0, !kFin, NULL); | 2862 connection_.SendStreamDataWithString(kCryptoStreamId, "foo", 0, !kFin, NULL); |
| 2725 // Check that ack is not bundled with outgoing data. | 2863 // Check that ack is not bundled with outgoing data. |
| 2726 EXPECT_EQ(1u, writer_->frame_count()); | 2864 EXPECT_EQ(1u, writer_->frame_count()); |
| 2727 EXPECT_FALSE(writer_->ack()); | 2865 EXPECT_FALSE(writer_->ack()); |
| 2728 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); | 2866 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); |
| 2729 } | 2867 } |
| 2730 | 2868 |
| 2731 TEST_F(QuicConnectionTest, BundleAckWithDataOnIncomingAck) { | 2869 TEST_P(QuicConnectionTest, BundleAckWithDataOnIncomingAck) { |
| 2732 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2870 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2733 connection_.SendStreamDataWithString(kStreamId3, "foo", 0, !kFin, NULL); | 2871 connection_.SendStreamDataWithString(kStreamId3, "foo", 0, !kFin, NULL); |
| 2734 connection_.SendStreamDataWithString(kStreamId3, "foo", 3, !kFin, NULL); | 2872 connection_.SendStreamDataWithString(kStreamId3, "foo", 3, !kFin, NULL); |
| 2735 // Ack the second packet, which will retransmit the first packet. | 2873 // Ack the second packet, which will retransmit the first packet. |
| 2736 QuicAckFrame ack = InitAckFrame(2, 0); | 2874 QuicAckFrame ack = InitAckFrame(2, 0); |
| 2737 NackPacket(1, &ack); | 2875 NackPacket(1, &ack); |
| 2738 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); | 2876 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); |
| 2739 EXPECT_CALL(*send_algorithm_, OnPacketAcked(2, _)).Times(1); | 2877 EXPECT_CALL(*send_algorithm_, OnPacketAcked(2, _)).Times(1); |
| 2740 EXPECT_CALL(*send_algorithm_, OnPacketLost(1, _)).Times(1); | 2878 EXPECT_CALL(*send_algorithm_, OnPacketLost(1, _)).Times(1); |
| 2741 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(1, _)).Times(1); | 2879 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(1, _)).Times(1); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2761 ack = InitAckFrame(3, 0); | 2899 ack = InitAckFrame(3, 0); |
| 2762 NackPacket(1, &ack); | 2900 NackPacket(1, &ack); |
| 2763 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce( | 2901 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce( |
| 2764 IgnoreResult(InvokeWithoutArgs( | 2902 IgnoreResult(InvokeWithoutArgs( |
| 2765 &connection_, | 2903 &connection_, |
| 2766 &TestConnection::EnsureWritableAndSendStreamData5))); | 2904 &TestConnection::EnsureWritableAndSendStreamData5))); |
| 2767 ProcessAckPacket(&ack); | 2905 ProcessAckPacket(&ack); |
| 2768 | 2906 |
| 2769 // Check that ack is bundled with outgoing data and the delayed ack | 2907 // Check that ack is bundled with outgoing data and the delayed ack |
| 2770 // alarm is reset. | 2908 // alarm is reset. |
| 2771 EXPECT_EQ(2u, writer_->frame_count()); | 2909 if (version() > QUIC_VERSION_15) { |
| 2910 EXPECT_EQ(3u, writer_->frame_count()); |
| 2911 EXPECT_TRUE(writer_->stop_waiting()); |
| 2912 } else { |
| 2913 EXPECT_EQ(2u, writer_->frame_count()); |
| 2914 } |
| 2772 EXPECT_TRUE(writer_->ack()); | 2915 EXPECT_TRUE(writer_->ack()); |
| 2773 EXPECT_EQ(1u, writer_->stream_frames()->size()); | 2916 EXPECT_EQ(1u, writer_->stream_frames()->size()); |
| 2774 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 2917 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
| 2775 } | 2918 } |
| 2776 | 2919 |
| 2777 TEST_F(QuicConnectionTest, NoAckForClose) { | 2920 TEST_P(QuicConnectionTest, NoAckForClose) { |
| 2778 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2921 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2779 ProcessPacket(1); | 2922 ProcessPacket(1); |
| 2780 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(0); | 2923 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(0); |
| 2781 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PEER_GOING_AWAY, true)); | 2924 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PEER_GOING_AWAY, true)); |
| 2782 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); | 2925 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); |
| 2783 ProcessClosePacket(2, 0); | 2926 ProcessClosePacket(2, 0); |
| 2784 } | 2927 } |
| 2785 | 2928 |
| 2786 TEST_F(QuicConnectionTest, SendWhenDisconnected) { | 2929 TEST_P(QuicConnectionTest, SendWhenDisconnected) { |
| 2787 EXPECT_TRUE(connection_.connected()); | 2930 EXPECT_TRUE(connection_.connected()); |
| 2788 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PEER_GOING_AWAY, false)); | 2931 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PEER_GOING_AWAY, false)); |
| 2789 connection_.CloseConnection(QUIC_PEER_GOING_AWAY, false); | 2932 connection_.CloseConnection(QUIC_PEER_GOING_AWAY, false); |
| 2790 EXPECT_FALSE(connection_.connected()); | 2933 EXPECT_FALSE(connection_.connected()); |
| 2791 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); | 2934 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); |
| 2792 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 1, _, _, _)).Times(0); | 2935 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 1, _, _, _)).Times(0); |
| 2793 connection_.SendPacket( | 2936 connection_.SendPacket( |
| 2794 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); | 2937 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); |
| 2795 } | 2938 } |
| 2796 | 2939 |
| 2797 TEST_F(QuicConnectionTest, PublicReset) { | 2940 TEST_P(QuicConnectionTest, PublicReset) { |
| 2798 QuicPublicResetPacket header; | 2941 QuicPublicResetPacket header; |
| 2799 header.public_header.guid = guid_; | 2942 header.public_header.guid = guid_; |
| 2800 header.public_header.reset_flag = true; | 2943 header.public_header.reset_flag = true; |
| 2801 header.public_header.version_flag = false; | 2944 header.public_header.version_flag = false; |
| 2802 header.rejected_sequence_number = 10101; | 2945 header.rejected_sequence_number = 10101; |
| 2803 scoped_ptr<QuicEncryptedPacket> packet( | 2946 scoped_ptr<QuicEncryptedPacket> packet( |
| 2804 framer_.BuildPublicResetPacket(header)); | 2947 framer_.BuildPublicResetPacket(header)); |
| 2805 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PUBLIC_RESET, true)); | 2948 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PUBLIC_RESET, true)); |
| 2806 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *packet); | 2949 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *packet); |
| 2807 } | 2950 } |
| 2808 | 2951 |
| 2809 TEST_F(QuicConnectionTest, GoAway) { | 2952 TEST_P(QuicConnectionTest, GoAway) { |
| 2810 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2953 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2811 | 2954 |
| 2812 QuicGoAwayFrame goaway; | 2955 QuicGoAwayFrame goaway; |
| 2813 goaway.last_good_stream_id = 1; | 2956 goaway.last_good_stream_id = 1; |
| 2814 goaway.error_code = QUIC_PEER_GOING_AWAY; | 2957 goaway.error_code = QUIC_PEER_GOING_AWAY; |
| 2815 goaway.reason_phrase = "Going away."; | 2958 goaway.reason_phrase = "Going away."; |
| 2816 EXPECT_CALL(visitor_, OnGoAway(_)); | 2959 EXPECT_CALL(visitor_, OnGoAway(_)); |
| 2817 ProcessGoAwayPacket(&goaway); | 2960 ProcessGoAwayPacket(&goaway); |
| 2818 } | 2961 } |
| 2819 | 2962 |
| 2820 TEST_F(QuicConnectionTest, WindowUpdate) { | 2963 TEST_P(QuicConnectionTest, WindowUpdate) { |
| 2964 if (version() < QUIC_VERSION_14) { |
| 2965 return; |
| 2966 } |
| 2821 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2967 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2822 | 2968 |
| 2823 QuicWindowUpdateFrame window_update; | 2969 QuicWindowUpdateFrame window_update; |
| 2824 window_update.stream_id = 3; | 2970 window_update.stream_id = 3; |
| 2825 window_update.byte_offset = 1234; | 2971 window_update.byte_offset = 1234; |
| 2826 EXPECT_CALL(visitor_, OnWindowUpdateFrames(_)); | 2972 EXPECT_CALL(visitor_, OnWindowUpdateFrames(_)); |
| 2827 ProcessFramePacket(QuicFrame(&window_update)); | 2973 ProcessFramePacket(QuicFrame(&window_update)); |
| 2828 } | 2974 } |
| 2829 | 2975 |
| 2830 TEST_F(QuicConnectionTest, Blocked) { | 2976 TEST_P(QuicConnectionTest, Blocked) { |
| 2977 if (version() < QUIC_VERSION_14) { |
| 2978 return; |
| 2979 } |
| 2831 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2980 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2832 | 2981 |
| 2833 QuicBlockedFrame blocked; | 2982 QuicBlockedFrame blocked; |
| 2834 blocked.stream_id = 3; | 2983 blocked.stream_id = 3; |
| 2835 EXPECT_CALL(visitor_, OnBlockedFrames(_)); | 2984 EXPECT_CALL(visitor_, OnBlockedFrames(_)); |
| 2836 ProcessFramePacket(QuicFrame(&blocked)); | 2985 ProcessFramePacket(QuicFrame(&blocked)); |
| 2837 } | 2986 } |
| 2838 | 2987 |
| 2839 TEST_F(QuicConnectionTest, InvalidPacket) { | 2988 TEST_P(QuicConnectionTest, InvalidPacket) { |
| 2840 EXPECT_CALL(visitor_, | 2989 EXPECT_CALL(visitor_, |
| 2841 OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false)); | 2990 OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false)); |
| 2842 QuicEncryptedPacket encrypted(NULL, 0); | 2991 QuicEncryptedPacket encrypted(NULL, 0); |
| 2843 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), encrypted); | 2992 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), encrypted); |
| 2844 // The connection close packet should have error details. | 2993 // The connection close packet should have error details. |
| 2845 ASSERT_TRUE(last_close() != NULL); | 2994 ASSERT_TRUE(last_close() != NULL); |
| 2846 EXPECT_EQ("Unable to read public flags.", last_close()->error_details); | 2995 EXPECT_EQ("Unable to read public flags.", last_close()->error_details); |
| 2847 } | 2996 } |
| 2848 | 2997 |
| 2849 TEST_F(QuicConnectionTest, MissingPacketsBeforeLeastUnacked) { | 2998 TEST_P(QuicConnectionTest, MissingPacketsBeforeLeastUnacked) { |
| 2850 QuicAckFrame ack = InitAckFrame(0, 4); | |
| 2851 // Set the sequence number of the ack packet to be least unacked (4). | 2999 // Set the sequence number of the ack packet to be least unacked (4). |
| 2852 creator_.set_sequence_number(3); | 3000 creator_.set_sequence_number(3); |
| 2853 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3001 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2854 ProcessAckPacket(&ack); | 3002 if (version() > QUIC_VERSION_15) { |
| 3003 QuicStopWaitingFrame frame = InitStopWaitingFrame(4); |
| 3004 ProcessStopWaitingPacket(&frame); |
| 3005 } else { |
| 3006 QuicAckFrame ack = InitAckFrame(0, 4); |
| 3007 ProcessAckPacket(&ack); |
| 3008 } |
| 2855 EXPECT_TRUE(outgoing_ack()->received_info.missing_packets.empty()); | 3009 EXPECT_TRUE(outgoing_ack()->received_info.missing_packets.empty()); |
| 2856 } | 3010 } |
| 2857 | 3011 |
| 2858 TEST_F(QuicConnectionTest, ReceivedEntropyHashCalculation) { | 3012 TEST_P(QuicConnectionTest, ReceivedEntropyHashCalculation) { |
| 2859 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillRepeatedly(Return(true)); | 3013 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillRepeatedly(Return(true)); |
| 2860 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3014 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2861 ProcessDataPacket(1, 1, kEntropyFlag); | 3015 ProcessDataPacket(1, 1, kEntropyFlag); |
| 2862 ProcessDataPacket(4, 1, kEntropyFlag); | 3016 ProcessDataPacket(4, 1, kEntropyFlag); |
| 2863 ProcessDataPacket(3, 1, !kEntropyFlag); | 3017 ProcessDataPacket(3, 1, !kEntropyFlag); |
| 2864 ProcessDataPacket(7, 1, kEntropyFlag); | 3018 ProcessDataPacket(7, 1, kEntropyFlag); |
| 2865 EXPECT_EQ(146u, outgoing_ack()->received_info.entropy_hash); | 3019 EXPECT_EQ(146u, outgoing_ack()->received_info.entropy_hash); |
| 2866 } | 3020 } |
| 2867 | 3021 |
| 2868 TEST_F(QuicConnectionTest, ReceivedEntropyHashCalculationHalfFEC) { | 3022 TEST_P(QuicConnectionTest, ReceivedEntropyHashCalculationHalfFEC) { |
| 3023 if (version() < QUIC_VERSION_15) { |
| 3024 return; |
| 3025 } |
| 2869 // FEC packets should not change the entropy hash calculation. | 3026 // FEC packets should not change the entropy hash calculation. |
| 2870 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillRepeatedly(Return(true)); | 3027 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillRepeatedly(Return(true)); |
| 2871 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3028 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2872 ProcessDataPacket(1, 1, kEntropyFlag); | 3029 ProcessDataPacket(1, 1, kEntropyFlag); |
| 2873 ProcessFecPacket(4, 1, false, kEntropyFlag, NULL); | 3030 ProcessFecPacket(4, 1, false, kEntropyFlag, NULL); |
| 2874 ProcessDataPacket(3, 3, !kEntropyFlag); | 3031 ProcessDataPacket(3, 3, !kEntropyFlag); |
| 2875 ProcessFecPacket(7, 3, false, kEntropyFlag, NULL); | 3032 ProcessFecPacket(7, 3, false, kEntropyFlag, NULL); |
| 2876 EXPECT_EQ(146u, outgoing_ack()->received_info.entropy_hash); | 3033 EXPECT_EQ(146u, outgoing_ack()->received_info.entropy_hash); |
| 2877 } | 3034 } |
| 2878 | 3035 |
| 2879 TEST_F(QuicConnectionTest, UpdateEntropyForReceivedPackets) { | 3036 TEST_P(QuicConnectionTest, UpdateEntropyForReceivedPackets) { |
| 2880 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillRepeatedly(Return(true)); | 3037 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillRepeatedly(Return(true)); |
| 2881 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3038 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2882 ProcessDataPacket(1, 1, kEntropyFlag); | 3039 ProcessDataPacket(1, 1, kEntropyFlag); |
| 2883 ProcessDataPacket(5, 1, kEntropyFlag); | 3040 ProcessDataPacket(5, 1, kEntropyFlag); |
| 2884 ProcessDataPacket(4, 1, !kEntropyFlag); | 3041 ProcessDataPacket(4, 1, !kEntropyFlag); |
| 2885 EXPECT_EQ(34u, outgoing_ack()->received_info.entropy_hash); | 3042 EXPECT_EQ(34u, outgoing_ack()->received_info.entropy_hash); |
| 2886 // Make 4th packet my least unacked, and update entropy for 2, 3 packets. | 3043 // Make 4th packet my least unacked, and update entropy for 2, 3 packets. |
| 2887 QuicAckFrame ack = InitAckFrame(0, 4); | |
| 2888 QuicPacketEntropyHash kRandomEntropyHash = 129u; | |
| 2889 ack.sent_info.entropy_hash = kRandomEntropyHash; | |
| 2890 creator_.set_sequence_number(5); | 3044 creator_.set_sequence_number(5); |
| 2891 QuicPacketEntropyHash six_packet_entropy_hash = 0; | 3045 QuicPacketEntropyHash six_packet_entropy_hash = 0; |
| 2892 if (ProcessAckPacket(&ack)) { | 3046 QuicPacketEntropyHash kRandomEntropyHash = 129u; |
| 2893 six_packet_entropy_hash = 1 << 6; | 3047 if (version() > QUIC_VERSION_15) { |
| 3048 QuicStopWaitingFrame frame = InitStopWaitingFrame(4); |
| 3049 frame.entropy_hash = kRandomEntropyHash; |
| 3050 if (ProcessStopWaitingPacket(&frame)) { |
| 3051 six_packet_entropy_hash = 1 << 6; |
| 3052 } |
| 3053 } else { |
| 3054 QuicAckFrame ack = InitAckFrame(0, 4); |
| 3055 ack.sent_info.entropy_hash = kRandomEntropyHash; |
| 3056 if (ProcessAckPacket(&ack)) { |
| 3057 six_packet_entropy_hash = 1 << 6; |
| 3058 } |
| 2894 } | 3059 } |
| 2895 | 3060 |
| 2896 EXPECT_EQ((kRandomEntropyHash + (1 << 5) + six_packet_entropy_hash), | 3061 EXPECT_EQ((kRandomEntropyHash + (1 << 5) + six_packet_entropy_hash), |
| 2897 outgoing_ack()->received_info.entropy_hash); | 3062 outgoing_ack()->received_info.entropy_hash); |
| 2898 } | 3063 } |
| 2899 | 3064 |
| 2900 TEST_F(QuicConnectionTest, UpdateEntropyHashUptoCurrentPacket) { | 3065 TEST_P(QuicConnectionTest, UpdateEntropyHashUptoCurrentPacket) { |
| 2901 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillRepeatedly(Return(true)); | 3066 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillRepeatedly(Return(true)); |
| 2902 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3067 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2903 ProcessDataPacket(1, 1, kEntropyFlag); | 3068 ProcessDataPacket(1, 1, kEntropyFlag); |
| 2904 ProcessDataPacket(5, 1, !kEntropyFlag); | 3069 ProcessDataPacket(5, 1, !kEntropyFlag); |
| 2905 ProcessDataPacket(22, 1, kEntropyFlag); | 3070 ProcessDataPacket(22, 1, kEntropyFlag); |
| 2906 EXPECT_EQ(66u, outgoing_ack()->received_info.entropy_hash); | 3071 EXPECT_EQ(66u, outgoing_ack()->received_info.entropy_hash); |
| 2907 creator_.set_sequence_number(22); | 3072 creator_.set_sequence_number(22); |
| 2908 QuicPacketEntropyHash kRandomEntropyHash = 85u; | 3073 QuicPacketEntropyHash kRandomEntropyHash = 85u; |
| 2909 // Current packet is the least unacked packet. | 3074 // Current packet is the least unacked packet. |
| 2910 QuicAckFrame ack = InitAckFrame(0, 23); | 3075 QuicPacketEntropyHash ack_entropy_hash; |
| 2911 ack.sent_info.entropy_hash = kRandomEntropyHash; | 3076 if (version() > QUIC_VERSION_15) { |
| 2912 QuicPacketEntropyHash ack_entropy_hash = ProcessAckPacket(&ack); | 3077 QuicStopWaitingFrame frame = InitStopWaitingFrame(23); |
| 3078 frame.entropy_hash = kRandomEntropyHash; |
| 3079 ack_entropy_hash = ProcessStopWaitingPacket(&frame); |
| 3080 } else { |
| 3081 QuicAckFrame ack = InitAckFrame(0, 23); |
| 3082 ack.sent_info.entropy_hash = kRandomEntropyHash; |
| 3083 ack_entropy_hash = ProcessAckPacket(&ack); |
| 3084 } |
| 2913 EXPECT_EQ((kRandomEntropyHash + ack_entropy_hash), | 3085 EXPECT_EQ((kRandomEntropyHash + ack_entropy_hash), |
| 2914 outgoing_ack()->received_info.entropy_hash); | 3086 outgoing_ack()->received_info.entropy_hash); |
| 2915 ProcessDataPacket(25, 1, kEntropyFlag); | 3087 ProcessDataPacket(25, 1, kEntropyFlag); |
| 2916 EXPECT_EQ((kRandomEntropyHash + ack_entropy_hash + (1 << (25 % 8))), | 3088 EXPECT_EQ((kRandomEntropyHash + ack_entropy_hash + (1 << (25 % 8))), |
| 2917 outgoing_ack()->received_info.entropy_hash); | 3089 outgoing_ack()->received_info.entropy_hash); |
| 2918 } | 3090 } |
| 2919 | 3091 |
| 2920 TEST_F(QuicConnectionTest, EntropyCalculationForTruncatedAck) { | 3092 TEST_P(QuicConnectionTest, EntropyCalculationForTruncatedAck) { |
| 2921 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillRepeatedly(Return(true)); | 3093 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillRepeatedly(Return(true)); |
| 2922 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3094 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2923 QuicPacketEntropyHash entropy[51]; | 3095 QuicPacketEntropyHash entropy[51]; |
| 2924 entropy[0] = 0; | 3096 entropy[0] = 0; |
| 2925 for (int i = 1; i < 51; ++i) { | 3097 for (int i = 1; i < 51; ++i) { |
| 2926 bool should_send = i % 10 != 0; | 3098 bool should_send = i % 10 != 0; |
| 2927 bool entropy_flag = (i & (i - 1)) != 0; | 3099 bool entropy_flag = (i & (i - 1)) != 0; |
| 2928 if (!should_send) { | 3100 if (!should_send) { |
| 2929 entropy[i] = entropy[i - 1]; | 3101 entropy[i] = entropy[i - 1]; |
| 2930 continue; | 3102 continue; |
| 2931 } | 3103 } |
| 2932 if (entropy_flag) { | 3104 if (entropy_flag) { |
| 2933 entropy[i] = entropy[i - 1] ^ (1 << (i % 8)); | 3105 entropy[i] = entropy[i - 1] ^ (1 << (i % 8)); |
| 2934 } else { | 3106 } else { |
| 2935 entropy[i] = entropy[i - 1]; | 3107 entropy[i] = entropy[i - 1]; |
| 2936 } | 3108 } |
| 2937 ProcessDataPacket(i, 1, entropy_flag); | 3109 ProcessDataPacket(i, 1, entropy_flag); |
| 2938 } | 3110 } |
| 2939 // Till 50 since 50th packet is not sent. | 3111 // Till 50 since 50th packet is not sent. |
| 2940 for (int i = 1; i < 50; ++i) { | 3112 for (int i = 1; i < 50; ++i) { |
| 2941 EXPECT_EQ(entropy[i], QuicConnectionPeer::ReceivedEntropyHash( | 3113 EXPECT_EQ(entropy[i], QuicConnectionPeer::ReceivedEntropyHash( |
| 2942 &connection_, i)); | 3114 &connection_, i)); |
| 2943 } | 3115 } |
| 2944 } | 3116 } |
| 2945 | 3117 |
| 2946 TEST_F(QuicConnectionTest, CheckSentEntropyHash) { | 3118 TEST_P(QuicConnectionTest, CheckSentEntropyHash) { |
| 2947 creator_.set_sequence_number(1); | 3119 creator_.set_sequence_number(1); |
| 2948 SequenceNumberSet missing_packets; | 3120 SequenceNumberSet missing_packets; |
| 2949 QuicPacketEntropyHash entropy_hash = 0; | 3121 QuicPacketEntropyHash entropy_hash = 0; |
| 2950 QuicPacketSequenceNumber max_sequence_number = 51; | 3122 QuicPacketSequenceNumber max_sequence_number = 51; |
| 2951 for (QuicPacketSequenceNumber i = 1; i <= max_sequence_number; ++i) { | 3123 for (QuicPacketSequenceNumber i = 1; i <= max_sequence_number; ++i) { |
| 2952 bool is_missing = i % 10 != 0; | 3124 bool is_missing = i % 10 != 0; |
| 2953 bool entropy_flag = (i & (i - 1)) != 0; | 3125 bool entropy_flag = (i & (i - 1)) != 0; |
| 2954 QuicPacketEntropyHash packet_entropy_hash = 0; | 3126 QuicPacketEntropyHash packet_entropy_hash = 0; |
| 2955 if (entropy_flag) { | 3127 if (entropy_flag) { |
| 2956 packet_entropy_hash = 1 << (i % 8); | 3128 packet_entropy_hash = 1 << (i % 8); |
| 2957 } | 3129 } |
| 2958 QuicPacket* packet = ConstructDataPacket(i, 0, entropy_flag); | 3130 QuicPacket* packet = ConstructDataPacket(i, 0, entropy_flag); |
| 2959 connection_.SendPacket( | 3131 connection_.SendPacket( |
| 2960 ENCRYPTION_NONE, i, packet, packet_entropy_hash, | 3132 ENCRYPTION_NONE, i, packet, packet_entropy_hash, |
| 2961 HAS_RETRANSMITTABLE_DATA); | 3133 HAS_RETRANSMITTABLE_DATA); |
| 2962 | 3134 |
| 2963 if (is_missing) { | 3135 if (is_missing) { |
| 2964 missing_packets.insert(i); | 3136 missing_packets.insert(i); |
| 2965 continue; | 3137 continue; |
| 2966 } | 3138 } |
| 2967 | 3139 |
| 2968 entropy_hash ^= packet_entropy_hash; | 3140 entropy_hash ^= packet_entropy_hash; |
| 2969 } | 3141 } |
| 2970 EXPECT_TRUE(QuicConnectionPeer::IsValidEntropy( | 3142 EXPECT_TRUE(QuicConnectionPeer::IsValidEntropy( |
| 2971 &connection_, max_sequence_number, missing_packets, entropy_hash)) | 3143 &connection_, max_sequence_number, missing_packets, entropy_hash)) |
| 2972 << ""; | 3144 << ""; |
| 2973 } | 3145 } |
| 2974 | 3146 |
| 2975 TEST_F(QuicConnectionTest, ServerSendsVersionNegotiationPacket) { | 3147 TEST_P(QuicConnectionTest, ServerSendsVersionNegotiationPacket) { |
| 3148 connection_.SetSupportedVersions(QuicSupportedVersions()); |
| 2976 framer_.set_version_for_tests(QUIC_VERSION_UNSUPPORTED); | 3149 framer_.set_version_for_tests(QUIC_VERSION_UNSUPPORTED); |
| 2977 | 3150 |
| 2978 QuicPacketHeader header; | 3151 QuicPacketHeader header; |
| 2979 header.public_header.guid = guid_; | 3152 header.public_header.guid = guid_; |
| 2980 header.public_header.reset_flag = false; | 3153 header.public_header.reset_flag = false; |
| 2981 header.public_header.version_flag = true; | 3154 header.public_header.version_flag = true; |
| 2982 header.entropy_flag = false; | 3155 header.entropy_flag = false; |
| 2983 header.fec_flag = false; | 3156 header.fec_flag = false; |
| 2984 header.packet_sequence_number = 12; | 3157 header.packet_sequence_number = 12; |
| 2985 header.fec_group = 0; | 3158 header.fec_group = 0; |
| 2986 | 3159 |
| 2987 QuicFrames frames; | 3160 QuicFrames frames; |
| 2988 QuicFrame frame(&frame1_); | 3161 QuicFrame frame(&frame1_); |
| 2989 frames.push_back(frame); | 3162 frames.push_back(frame); |
| 2990 scoped_ptr<QuicPacket> packet( | 3163 scoped_ptr<QuicPacket> packet( |
| 2991 framer_.BuildUnsizedDataPacket(header, frames).packet); | 3164 framer_.BuildUnsizedDataPacket(header, frames).packet); |
| 2992 scoped_ptr<QuicEncryptedPacket> encrypted( | 3165 scoped_ptr<QuicEncryptedPacket> encrypted( |
| 2993 framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); | 3166 framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); |
| 2994 | 3167 |
| 2995 framer_.set_version(QuicVersionMax()); | 3168 framer_.set_version(version()); |
| 2996 connection_.set_is_server(true); | 3169 connection_.set_is_server(true); |
| 2997 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 3170 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); |
| 2998 EXPECT_TRUE(writer_->version_negotiation_packet() != NULL); | 3171 EXPECT_TRUE(writer_->version_negotiation_packet() != NULL); |
| 2999 | 3172 |
| 3000 size_t num_versions = arraysize(kSupportedQuicVersions); | 3173 size_t num_versions = arraysize(kSupportedQuicVersions); |
| 3001 EXPECT_EQ(num_versions, | 3174 ASSERT_EQ(num_versions, |
| 3002 writer_->version_negotiation_packet()->versions.size()); | 3175 writer_->version_negotiation_packet()->versions.size()); |
| 3003 | 3176 |
| 3004 // We expect all versions in kSupportedQuicVersions to be | 3177 // We expect all versions in kSupportedQuicVersions to be |
| 3005 // included in the packet. | 3178 // included in the packet. |
| 3006 for (size_t i = 0; i < num_versions; ++i) { | 3179 for (size_t i = 0; i < num_versions; ++i) { |
| 3007 EXPECT_EQ(kSupportedQuicVersions[i], | 3180 EXPECT_EQ(kSupportedQuicVersions[i], |
| 3008 writer_->version_negotiation_packet()->versions[i]); | 3181 writer_->version_negotiation_packet()->versions[i]); |
| 3009 } | 3182 } |
| 3010 } | 3183 } |
| 3011 | 3184 |
| 3012 TEST_F(QuicConnectionTest, ServerSendsVersionNegotiationPacketSocketBlocked) { | 3185 TEST_P(QuicConnectionTest, ServerSendsVersionNegotiationPacketSocketBlocked) { |
| 3186 connection_.SetSupportedVersions(QuicSupportedVersions()); |
| 3013 framer_.set_version_for_tests(QUIC_VERSION_UNSUPPORTED); | 3187 framer_.set_version_for_tests(QUIC_VERSION_UNSUPPORTED); |
| 3014 | 3188 |
| 3015 QuicPacketHeader header; | 3189 QuicPacketHeader header; |
| 3016 header.public_header.guid = guid_; | 3190 header.public_header.guid = guid_; |
| 3017 header.public_header.reset_flag = false; | 3191 header.public_header.reset_flag = false; |
| 3018 header.public_header.version_flag = true; | 3192 header.public_header.version_flag = true; |
| 3019 header.entropy_flag = false; | 3193 header.entropy_flag = false; |
| 3020 header.fec_flag = false; | 3194 header.fec_flag = false; |
| 3021 header.packet_sequence_number = 12; | 3195 header.packet_sequence_number = 12; |
| 3022 header.fec_group = 0; | 3196 header.fec_group = 0; |
| 3023 | 3197 |
| 3024 QuicFrames frames; | 3198 QuicFrames frames; |
| 3025 QuicFrame frame(&frame1_); | 3199 QuicFrame frame(&frame1_); |
| 3026 frames.push_back(frame); | 3200 frames.push_back(frame); |
| 3027 scoped_ptr<QuicPacket> packet( | 3201 scoped_ptr<QuicPacket> packet( |
| 3028 framer_.BuildUnsizedDataPacket(header, frames).packet); | 3202 framer_.BuildUnsizedDataPacket(header, frames).packet); |
| 3029 scoped_ptr<QuicEncryptedPacket> encrypted( | 3203 scoped_ptr<QuicEncryptedPacket> encrypted( |
| 3030 framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); | 3204 framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); |
| 3031 | 3205 |
| 3032 framer_.set_version(QuicVersionMax()); | 3206 framer_.set_version(version()); |
| 3033 connection_.set_is_server(true); | 3207 connection_.set_is_server(true); |
| 3034 BlockOnNextWrite(); | 3208 BlockOnNextWrite(); |
| 3035 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 3209 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); |
| 3036 EXPECT_EQ(0u, writer_->last_packet_size()); | 3210 EXPECT_EQ(0u, writer_->last_packet_size()); |
| 3037 EXPECT_TRUE(connection_.HasQueuedData()); | 3211 EXPECT_TRUE(connection_.HasQueuedData()); |
| 3038 | 3212 |
| 3039 writer_->SetWritable(); | 3213 writer_->SetWritable(); |
| 3040 connection_.OnCanWrite(); | 3214 connection_.OnCanWrite(); |
| 3041 EXPECT_TRUE(writer_->version_negotiation_packet() != NULL); | 3215 EXPECT_TRUE(writer_->version_negotiation_packet() != NULL); |
| 3042 | 3216 |
| 3043 size_t num_versions = arraysize(kSupportedQuicVersions); | 3217 size_t num_versions = arraysize(kSupportedQuicVersions); |
| 3044 EXPECT_EQ(num_versions, | 3218 ASSERT_EQ(num_versions, |
| 3045 writer_->version_negotiation_packet()->versions.size()); | 3219 writer_->version_negotiation_packet()->versions.size()); |
| 3046 | 3220 |
| 3047 // We expect all versions in kSupportedQuicVersions to be | 3221 // We expect all versions in kSupportedQuicVersions to be |
| 3048 // included in the packet. | 3222 // included in the packet. |
| 3049 for (size_t i = 0; i < num_versions; ++i) { | 3223 for (size_t i = 0; i < num_versions; ++i) { |
| 3050 EXPECT_EQ(kSupportedQuicVersions[i], | 3224 EXPECT_EQ(kSupportedQuicVersions[i], |
| 3051 writer_->version_negotiation_packet()->versions[i]); | 3225 writer_->version_negotiation_packet()->versions[i]); |
| 3052 } | 3226 } |
| 3053 } | 3227 } |
| 3054 | 3228 |
| 3055 TEST_F(QuicConnectionTest, | 3229 TEST_P(QuicConnectionTest, |
| 3056 ServerSendsVersionNegotiationPacketSocketBlockedDataBuffered) { | 3230 ServerSendsVersionNegotiationPacketSocketBlockedDataBuffered) { |
| 3231 connection_.SetSupportedVersions(QuicSupportedVersions()); |
| 3057 framer_.set_version_for_tests(QUIC_VERSION_UNSUPPORTED); | 3232 framer_.set_version_for_tests(QUIC_VERSION_UNSUPPORTED); |
| 3058 | 3233 |
| 3059 QuicPacketHeader header; | 3234 QuicPacketHeader header; |
| 3060 header.public_header.guid = guid_; | 3235 header.public_header.guid = guid_; |
| 3061 header.public_header.reset_flag = false; | 3236 header.public_header.reset_flag = false; |
| 3062 header.public_header.version_flag = true; | 3237 header.public_header.version_flag = true; |
| 3063 header.entropy_flag = false; | 3238 header.entropy_flag = false; |
| 3064 header.fec_flag = false; | 3239 header.fec_flag = false; |
| 3065 header.packet_sequence_number = 12; | 3240 header.packet_sequence_number = 12; |
| 3066 header.fec_group = 0; | 3241 header.fec_group = 0; |
| 3067 | 3242 |
| 3068 QuicFrames frames; | 3243 QuicFrames frames; |
| 3069 QuicFrame frame(&frame1_); | 3244 QuicFrame frame(&frame1_); |
| 3070 frames.push_back(frame); | 3245 frames.push_back(frame); |
| 3071 scoped_ptr<QuicPacket> packet( | 3246 scoped_ptr<QuicPacket> packet( |
| 3072 framer_.BuildUnsizedDataPacket(header, frames).packet); | 3247 framer_.BuildUnsizedDataPacket(header, frames).packet); |
| 3073 scoped_ptr<QuicEncryptedPacket> encrypted( | 3248 scoped_ptr<QuicEncryptedPacket> encrypted( |
| 3074 framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); | 3249 framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); |
| 3075 | 3250 |
| 3076 framer_.set_version(QuicVersionMax()); | 3251 framer_.set_version(version()); |
| 3077 connection_.set_is_server(true); | 3252 connection_.set_is_server(true); |
| 3078 BlockOnNextWrite(); | 3253 BlockOnNextWrite(); |
| 3079 writer_->set_is_write_blocked_data_buffered(true); | 3254 writer_->set_is_write_blocked_data_buffered(true); |
| 3080 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 3255 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); |
| 3081 EXPECT_EQ(0u, writer_->last_packet_size()); | 3256 EXPECT_EQ(0u, writer_->last_packet_size()); |
| 3082 EXPECT_FALSE(connection_.HasQueuedData()); | 3257 EXPECT_FALSE(connection_.HasQueuedData()); |
| 3083 } | 3258 } |
| 3084 | 3259 |
| 3085 TEST_F(QuicConnectionTest, ClientHandlesVersionNegotiation) { | 3260 TEST_P(QuicConnectionTest, ClientHandlesVersionNegotiation) { |
| 3086 // Start out with some unsupported version. | 3261 // Start out with some unsupported version. |
| 3087 QuicConnectionPeer::GetFramer(&connection_)->set_version_for_tests( | 3262 QuicConnectionPeer::GetFramer(&connection_)->set_version_for_tests( |
| 3088 QUIC_VERSION_UNSUPPORTED); | 3263 QUIC_VERSION_UNSUPPORTED); |
| 3089 | 3264 |
| 3090 QuicPacketHeader header; | 3265 QuicPacketHeader header; |
| 3091 header.public_header.guid = guid_; | 3266 header.public_header.guid = guid_; |
| 3092 header.public_header.reset_flag = false; | 3267 header.public_header.reset_flag = false; |
| 3093 header.public_header.version_flag = true; | 3268 header.public_header.version_flag = true; |
| 3094 header.entropy_flag = false; | 3269 header.entropy_flag = false; |
| 3095 header.fec_flag = false; | 3270 header.fec_flag = false; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 3117 framer_.BuildUnsizedDataPacket(header, frames).packet); | 3292 framer_.BuildUnsizedDataPacket(header, frames).packet); |
| 3118 encrypted.reset(framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); | 3293 encrypted.reset(framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); |
| 3119 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); | 3294 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); |
| 3120 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3295 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3121 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 3296 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); |
| 3122 | 3297 |
| 3123 ASSERT_FALSE(QuicPacketCreatorPeer::SendVersionInPacket( | 3298 ASSERT_FALSE(QuicPacketCreatorPeer::SendVersionInPacket( |
| 3124 QuicConnectionPeer::GetPacketCreator(&connection_))); | 3299 QuicConnectionPeer::GetPacketCreator(&connection_))); |
| 3125 } | 3300 } |
| 3126 | 3301 |
| 3127 TEST_F(QuicConnectionTest, BadVersionNegotiation) { | 3302 TEST_P(QuicConnectionTest, BadVersionNegotiation) { |
| 3128 QuicPacketHeader header; | 3303 QuicPacketHeader header; |
| 3129 header.public_header.guid = guid_; | 3304 header.public_header.guid = guid_; |
| 3130 header.public_header.reset_flag = false; | 3305 header.public_header.reset_flag = false; |
| 3131 header.public_header.version_flag = true; | 3306 header.public_header.version_flag = true; |
| 3132 header.entropy_flag = false; | 3307 header.entropy_flag = false; |
| 3133 header.fec_flag = false; | 3308 header.fec_flag = false; |
| 3134 header.packet_sequence_number = 12; | 3309 header.packet_sequence_number = 12; |
| 3135 header.fec_group = 0; | 3310 header.fec_group = 0; |
| 3136 | 3311 |
| 3137 QuicVersionVector supported_versions; | 3312 QuicVersionVector supported_versions; |
| 3138 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { | 3313 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { |
| 3139 supported_versions.push_back(kSupportedQuicVersions[i]); | 3314 supported_versions.push_back(kSupportedQuicVersions[i]); |
| 3140 } | 3315 } |
| 3141 | 3316 |
| 3142 // Send a version negotiation packet with the version the client started with. | 3317 // Send a version negotiation packet with the version the client started with. |
| 3143 // It should be rejected. | 3318 // It should be rejected. |
| 3144 EXPECT_CALL(visitor_, | 3319 EXPECT_CALL(visitor_, |
| 3145 OnConnectionClosed(QUIC_INVALID_VERSION_NEGOTIATION_PACKET, | 3320 OnConnectionClosed(QUIC_INVALID_VERSION_NEGOTIATION_PACKET, |
| 3146 false)); | 3321 false)); |
| 3147 scoped_ptr<QuicEncryptedPacket> encrypted( | 3322 scoped_ptr<QuicEncryptedPacket> encrypted( |
| 3148 framer_.BuildVersionNegotiationPacket( | 3323 framer_.BuildVersionNegotiationPacket( |
| 3149 header.public_header, supported_versions)); | 3324 header.public_header, supported_versions)); |
| 3150 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 3325 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); |
| 3151 } | 3326 } |
| 3152 | 3327 |
| 3153 TEST_F(QuicConnectionTest, CheckSendStats) { | 3328 TEST_P(QuicConnectionTest, CheckSendStats) { |
| 3154 EXPECT_CALL(*send_algorithm_, | 3329 EXPECT_CALL(*send_algorithm_, |
| 3155 OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)); | 3330 OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)); |
| 3156 connection_.SendStreamDataWithString(3, "first", 0, !kFin, NULL); | 3331 connection_.SendStreamDataWithString(3, "first", 0, !kFin, NULL); |
| 3157 size_t first_packet_size = last_sent_packet_size(); | 3332 size_t first_packet_size = last_sent_packet_size(); |
| 3158 | 3333 |
| 3159 EXPECT_CALL(*send_algorithm_, | 3334 EXPECT_CALL(*send_algorithm_, |
| 3160 OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)); | 3335 OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)); |
| 3161 connection_.SendStreamDataWithString(5, "second", 0, !kFin, NULL); | 3336 connection_.SendStreamDataWithString(5, "second", 0, !kFin, NULL); |
| 3162 size_t second_packet_size = last_sent_packet_size(); | 3337 size_t second_packet_size = last_sent_packet_size(); |
| 3163 | 3338 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3196 const QuicConnectionStats& stats = connection_.GetStats(); | 3371 const QuicConnectionStats& stats = connection_.GetStats(); |
| 3197 EXPECT_EQ(3 * first_packet_size + 2 * second_packet_size - kQuicVersionSize, | 3372 EXPECT_EQ(3 * first_packet_size + 2 * second_packet_size - kQuicVersionSize, |
| 3198 stats.bytes_sent); | 3373 stats.bytes_sent); |
| 3199 EXPECT_EQ(5u, stats.packets_sent); | 3374 EXPECT_EQ(5u, stats.packets_sent); |
| 3200 EXPECT_EQ(2 * first_packet_size + second_packet_size - kQuicVersionSize, | 3375 EXPECT_EQ(2 * first_packet_size + second_packet_size - kQuicVersionSize, |
| 3201 stats.bytes_retransmitted); | 3376 stats.bytes_retransmitted); |
| 3202 EXPECT_EQ(3u, stats.packets_retransmitted); | 3377 EXPECT_EQ(3u, stats.packets_retransmitted); |
| 3203 EXPECT_EQ(1u, stats.rto_count); | 3378 EXPECT_EQ(1u, stats.rto_count); |
| 3204 } | 3379 } |
| 3205 | 3380 |
| 3206 TEST_F(QuicConnectionTest, CheckReceiveStats) { | 3381 TEST_P(QuicConnectionTest, CheckReceiveStats) { |
| 3382 if (version() < QUIC_VERSION_15) { |
| 3383 return; |
| 3384 } |
| 3207 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3385 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3208 | 3386 |
| 3209 size_t received_bytes = 0; | 3387 size_t received_bytes = 0; |
| 3210 received_bytes += ProcessFecProtectedPacket(1, false, !kEntropyFlag); | 3388 received_bytes += ProcessFecProtectedPacket(1, false, !kEntropyFlag); |
| 3211 received_bytes += ProcessFecProtectedPacket(3, false, !kEntropyFlag); | 3389 received_bytes += ProcessFecProtectedPacket(3, false, !kEntropyFlag); |
| 3212 // Should be counted against dropped packets. | 3390 // Should be counted against dropped packets. |
| 3213 received_bytes += ProcessDataPacket(3, 1, !kEntropyFlag); | 3391 received_bytes += ProcessDataPacket(3, 1, !kEntropyFlag); |
| 3214 received_bytes += ProcessFecPacket(4, 1, true, !kEntropyFlag, NULL); | 3392 received_bytes += ProcessFecPacket(4, 1, true, !kEntropyFlag, NULL); |
| 3215 | 3393 |
| 3216 EXPECT_CALL(*send_algorithm_, SmoothedRtt()).WillOnce( | 3394 EXPECT_CALL(*send_algorithm_, SmoothedRtt()).WillOnce( |
| 3217 Return(QuicTime::Delta::Zero())); | 3395 Return(QuicTime::Delta::Zero())); |
| 3218 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillOnce( | 3396 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillOnce( |
| 3219 Return(QuicBandwidth::Zero())); | 3397 Return(QuicBandwidth::Zero())); |
| 3220 | 3398 |
| 3221 const QuicConnectionStats& stats = connection_.GetStats(); | 3399 const QuicConnectionStats& stats = connection_.GetStats(); |
| 3222 EXPECT_EQ(received_bytes, stats.bytes_received); | 3400 EXPECT_EQ(received_bytes, stats.bytes_received); |
| 3223 EXPECT_EQ(4u, stats.packets_received); | 3401 EXPECT_EQ(4u, stats.packets_received); |
| 3224 | 3402 |
| 3225 EXPECT_EQ(1u, stats.packets_revived); | 3403 EXPECT_EQ(1u, stats.packets_revived); |
| 3226 EXPECT_EQ(1u, stats.packets_dropped); | 3404 EXPECT_EQ(1u, stats.packets_dropped); |
| 3227 } | 3405 } |
| 3228 | 3406 |
| 3229 TEST_F(QuicConnectionTest, TestFecGroupLimits) { | 3407 TEST_P(QuicConnectionTest, TestFecGroupLimits) { |
| 3230 // Create and return a group for 1. | 3408 // Create and return a group for 1. |
| 3231 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 1) != NULL); | 3409 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 1) != NULL); |
| 3232 | 3410 |
| 3233 // Create and return a group for 2. | 3411 // Create and return a group for 2. |
| 3234 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 2) != NULL); | 3412 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 2) != NULL); |
| 3235 | 3413 |
| 3236 // Create and return a group for 4. This should remove 1 but not 2. | 3414 // Create and return a group for 4. This should remove 1 but not 2. |
| 3237 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 4) != NULL); | 3415 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 4) != NULL); |
| 3238 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 1) == NULL); | 3416 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 1) == NULL); |
| 3239 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 2) != NULL); | 3417 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 2) != NULL); |
| 3240 | 3418 |
| 3241 // Create and return a group for 3. This will kill off 2. | 3419 // Create and return a group for 3. This will kill off 2. |
| 3242 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 3) != NULL); | 3420 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 3) != NULL); |
| 3243 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 2) == NULL); | 3421 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 2) == NULL); |
| 3244 | 3422 |
| 3245 // Verify that adding 5 kills off 3, despite 4 being created before 3. | 3423 // Verify that adding 5 kills off 3, despite 4 being created before 3. |
| 3246 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 5) != NULL); | 3424 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 5) != NULL); |
| 3247 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 4) != NULL); | 3425 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 4) != NULL); |
| 3248 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 3) == NULL); | 3426 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 3) == NULL); |
| 3249 } | 3427 } |
| 3250 | 3428 |
| 3251 TEST_F(QuicConnectionTest, ProcessFramesIfPacketClosedConnection) { | 3429 TEST_P(QuicConnectionTest, ProcessFramesIfPacketClosedConnection) { |
| 3252 // Construct a packet with stream frame and connection close frame. | 3430 // Construct a packet with stream frame and connection close frame. |
| 3253 header_.public_header.guid = guid_; | 3431 header_.public_header.guid = guid_; |
| 3254 header_.packet_sequence_number = 1; | 3432 header_.packet_sequence_number = 1; |
| 3255 header_.public_header.reset_flag = false; | 3433 header_.public_header.reset_flag = false; |
| 3256 header_.public_header.version_flag = false; | 3434 header_.public_header.version_flag = false; |
| 3257 header_.entropy_flag = false; | 3435 header_.entropy_flag = false; |
| 3258 header_.fec_flag = false; | 3436 header_.fec_flag = false; |
| 3259 header_.fec_group = 0; | 3437 header_.fec_group = 0; |
| 3260 | 3438 |
| 3261 QuicConnectionCloseFrame qccf; | 3439 QuicConnectionCloseFrame qccf; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 3272 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPacket( | 3450 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPacket( |
| 3273 ENCRYPTION_NONE, 1, *packet)); | 3451 ENCRYPTION_NONE, 1, *packet)); |
| 3274 | 3452 |
| 3275 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PEER_GOING_AWAY, true)); | 3453 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PEER_GOING_AWAY, true)); |
| 3276 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillOnce(Return(true)); | 3454 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillOnce(Return(true)); |
| 3277 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3455 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3278 | 3456 |
| 3279 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 3457 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); |
| 3280 } | 3458 } |
| 3281 | 3459 |
| 3282 TEST_F(QuicConnectionTest, DontProcessStreamFrameAndIgnoreCloseFrame) { | 3460 TEST_P(QuicConnectionTest, DontProcessStreamFrameAndIgnoreCloseFrame) { |
| 3283 // Construct a packet with stream frame, ack frame, | 3461 // Construct a packet with stream frame, ack frame, |
| 3284 // and connection close frame. | 3462 // and connection close frame. |
| 3285 header_.public_header.guid = guid_; | 3463 header_.public_header.guid = guid_; |
| 3286 header_.packet_sequence_number = 1; | 3464 header_.packet_sequence_number = 1; |
| 3287 header_.public_header.reset_flag = false; | 3465 header_.public_header.reset_flag = false; |
| 3288 header_.public_header.version_flag = false; | 3466 header_.public_header.version_flag = false; |
| 3289 header_.entropy_flag = false; | 3467 header_.entropy_flag = false; |
| 3290 header_.fec_flag = false; | 3468 header_.fec_flag = false; |
| 3291 header_.fec_group = 0; | 3469 header_.fec_group = 0; |
| 3292 | 3470 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 3303 EXPECT_TRUE(NULL != packet.get()); | 3481 EXPECT_TRUE(NULL != packet.get()); |
| 3304 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPacket( | 3482 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPacket( |
| 3305 ENCRYPTION_NONE, 1, *packet)); | 3483 ENCRYPTION_NONE, 1, *packet)); |
| 3306 | 3484 |
| 3307 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillOnce(Return(false)); | 3485 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillOnce(Return(false)); |
| 3308 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3486 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3309 | 3487 |
| 3310 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 3488 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); |
| 3311 } | 3489 } |
| 3312 | 3490 |
| 3313 TEST_F(QuicConnectionTest, SelectMutualVersion) { | 3491 TEST_P(QuicConnectionTest, SelectMutualVersion) { |
| 3492 connection_.SetSupportedVersions(QuicSupportedVersions()); |
| 3314 // Set the connection to speak the lowest quic version. | 3493 // Set the connection to speak the lowest quic version. |
| 3315 connection_.set_version(QuicVersionMin()); | 3494 connection_.set_version(QuicVersionMin()); |
| 3316 EXPECT_EQ(QuicVersionMin(), connection_.version()); | 3495 EXPECT_EQ(QuicVersionMin(), connection_.version()); |
| 3317 | 3496 |
| 3318 // Pass in available versions which includes a higher mutually supported | 3497 // Pass in available versions which includes a higher mutually supported |
| 3319 // version. The higher mutually supported version should be selected. | 3498 // version. The higher mutually supported version should be selected. |
| 3320 QuicVersionVector supported_versions; | 3499 QuicVersionVector supported_versions; |
| 3321 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { | 3500 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { |
| 3322 supported_versions.push_back(kSupportedQuicVersions[i]); | 3501 supported_versions.push_back(kSupportedQuicVersions[i]); |
| 3323 } | 3502 } |
| 3324 EXPECT_TRUE(connection_.SelectMutualVersion(supported_versions)); | 3503 EXPECT_TRUE(connection_.SelectMutualVersion(supported_versions)); |
| 3325 EXPECT_EQ(QuicVersionMax(), connection_.version()); | 3504 EXPECT_EQ(QuicVersionMax(), connection_.version()); |
| 3326 | 3505 |
| 3327 // Expect that the lowest version is selected. | 3506 // Expect that the lowest version is selected. |
| 3328 // Ensure the lowest supported version is less than the max, unless they're | 3507 // Ensure the lowest supported version is less than the max, unless they're |
| 3329 // the same. | 3508 // the same. |
| 3330 EXPECT_LE(QuicVersionMin(), QuicVersionMax()); | 3509 EXPECT_LE(QuicVersionMin(), QuicVersionMax()); |
| 3331 QuicVersionVector lowest_version_vector; | 3510 QuicVersionVector lowest_version_vector; |
| 3332 lowest_version_vector.push_back(QuicVersionMin()); | 3511 lowest_version_vector.push_back(QuicVersionMin()); |
| 3333 EXPECT_TRUE(connection_.SelectMutualVersion(lowest_version_vector)); | 3512 EXPECT_TRUE(connection_.SelectMutualVersion(lowest_version_vector)); |
| 3334 EXPECT_EQ(QuicVersionMin(), connection_.version()); | 3513 EXPECT_EQ(QuicVersionMin(), connection_.version()); |
| 3335 | 3514 |
| 3336 // Shouldn't be able to find a mutually supported version. | 3515 // Shouldn't be able to find a mutually supported version. |
| 3337 QuicVersionVector unsupported_version; | 3516 QuicVersionVector unsupported_version; |
| 3338 unsupported_version.push_back(QUIC_VERSION_UNSUPPORTED); | 3517 unsupported_version.push_back(QUIC_VERSION_UNSUPPORTED); |
| 3339 EXPECT_FALSE(connection_.SelectMutualVersion(unsupported_version)); | 3518 EXPECT_FALSE(connection_.SelectMutualVersion(unsupported_version)); |
| 3340 } | 3519 } |
| 3341 | 3520 |
| 3342 TEST_F(QuicConnectionTest, ConnectionCloseWhenWritable) { | 3521 TEST_P(QuicConnectionTest, ConnectionCloseWhenWritable) { |
| 3343 EXPECT_FALSE(writer_->IsWriteBlocked()); | 3522 EXPECT_FALSE(writer_->IsWriteBlocked()); |
| 3344 | 3523 |
| 3345 // Send a packet. | 3524 // Send a packet. |
| 3346 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); | 3525 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); |
| 3347 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 3526 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 3348 EXPECT_EQ(1u, writer_->packets_write_attempts()); | 3527 EXPECT_EQ(1u, writer_->packets_write_attempts()); |
| 3349 | 3528 |
| 3350 TriggerConnectionClose(); | 3529 TriggerConnectionClose(); |
| 3351 EXPECT_EQ(2u, writer_->packets_write_attempts()); | 3530 EXPECT_EQ(2u, writer_->packets_write_attempts()); |
| 3352 } | 3531 } |
| 3353 | 3532 |
| 3354 TEST_F(QuicConnectionTest, ConnectionCloseGettingWriteBlocked) { | 3533 TEST_P(QuicConnectionTest, ConnectionCloseGettingWriteBlocked) { |
| 3355 BlockOnNextWrite(); | 3534 BlockOnNextWrite(); |
| 3356 TriggerConnectionClose(); | 3535 TriggerConnectionClose(); |
| 3357 EXPECT_EQ(1u, writer_->packets_write_attempts()); | 3536 EXPECT_EQ(1u, writer_->packets_write_attempts()); |
| 3358 EXPECT_TRUE(writer_->IsWriteBlocked()); | 3537 EXPECT_TRUE(writer_->IsWriteBlocked()); |
| 3359 } | 3538 } |
| 3360 | 3539 |
| 3361 TEST_F(QuicConnectionTest, ConnectionCloseWhenWriteBlocked) { | 3540 TEST_P(QuicConnectionTest, ConnectionCloseWhenWriteBlocked) { |
| 3362 BlockOnNextWrite(); | 3541 BlockOnNextWrite(); |
| 3363 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); | 3542 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); |
| 3364 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 3543 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 3365 EXPECT_EQ(1u, writer_->packets_write_attempts()); | 3544 EXPECT_EQ(1u, writer_->packets_write_attempts()); |
| 3366 EXPECT_TRUE(writer_->IsWriteBlocked()); | 3545 EXPECT_TRUE(writer_->IsWriteBlocked()); |
| 3367 TriggerConnectionClose(); | 3546 TriggerConnectionClose(); |
| 3368 EXPECT_EQ(1u, writer_->packets_write_attempts()); | 3547 EXPECT_EQ(1u, writer_->packets_write_attempts()); |
| 3369 } | 3548 } |
| 3370 | 3549 |
| 3371 TEST_F(QuicConnectionTest, AckNotifierTriggerCallback) { | 3550 TEST_P(QuicConnectionTest, AckNotifierTriggerCallback) { |
| 3372 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3551 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3373 | 3552 |
| 3374 // Create a delegate which we expect to be called. | 3553 // Create a delegate which we expect to be called. |
| 3375 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); | 3554 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); |
| 3376 EXPECT_CALL(*delegate, OnAckNotification()).Times(1); | 3555 EXPECT_CALL(*delegate, OnAckNotification()).Times(1); |
| 3377 | 3556 |
| 3378 // Send some data, which will register the delegate to be notified. | 3557 // Send some data, which will register the delegate to be notified. |
| 3379 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); | 3558 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); |
| 3380 | 3559 |
| 3381 // Process an ACK from the server which should trigger the callback. | 3560 // Process an ACK from the server which should trigger the callback. |
| 3382 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); | 3561 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); |
| 3383 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(1); | 3562 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(1); |
| 3384 QuicAckFrame frame = InitAckFrame(1, 0); | 3563 QuicAckFrame frame = InitAckFrame(1, 0); |
| 3385 ProcessAckPacket(&frame); | 3564 ProcessAckPacket(&frame); |
| 3386 } | 3565 } |
| 3387 | 3566 |
| 3388 TEST_F(QuicConnectionTest, AckNotifierFailToTriggerCallback) { | 3567 TEST_P(QuicConnectionTest, AckNotifierFailToTriggerCallback) { |
| 3389 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3568 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3390 | 3569 |
| 3391 // Create a delegate which we don't expect to be called. | 3570 // Create a delegate which we don't expect to be called. |
| 3392 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); | 3571 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); |
| 3393 EXPECT_CALL(*delegate, OnAckNotification()).Times(0); | 3572 EXPECT_CALL(*delegate, OnAckNotification()).Times(0); |
| 3394 | 3573 |
| 3395 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); | 3574 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); |
| 3396 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(2); | 3575 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(2); |
| 3397 | 3576 |
| 3398 // Send some data, which will register the delegate to be notified. This will | 3577 // Send some data, which will register the delegate to be notified. This will |
| 3399 // not be ACKed and so the delegate should never be called. | 3578 // not be ACKed and so the delegate should never be called. |
| 3400 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); | 3579 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); |
| 3401 | 3580 |
| 3402 // Send some other data which we will ACK. | 3581 // Send some other data which we will ACK. |
| 3403 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); | 3582 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); |
| 3404 connection_.SendStreamDataWithString(1, "bar", 0, !kFin, NULL); | 3583 connection_.SendStreamDataWithString(1, "bar", 0, !kFin, NULL); |
| 3405 | 3584 |
| 3406 // Now we receive ACK for packets 2 and 3, but importantly missing packet 1 | 3585 // Now we receive ACK for packets 2 and 3, but importantly missing packet 1 |
| 3407 // which we registered to be notified about. | 3586 // which we registered to be notified about. |
| 3408 QuicAckFrame frame = InitAckFrame(3, 0); | 3587 QuicAckFrame frame = InitAckFrame(3, 0); |
| 3409 NackPacket(1, &frame); | 3588 NackPacket(1, &frame); |
| 3410 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)); | 3589 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)); |
| 3411 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)); | 3590 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)); |
| 3412 ProcessAckPacket(&frame); | 3591 ProcessAckPacket(&frame); |
| 3413 } | 3592 } |
| 3414 | 3593 |
| 3415 TEST_F(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) { | 3594 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) { |
| 3416 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3595 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3417 | 3596 |
| 3418 // Create a delegate which we expect to be called. | 3597 // Create a delegate which we expect to be called. |
| 3419 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); | 3598 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); |
| 3420 EXPECT_CALL(*delegate, OnAckNotification()).Times(1); | 3599 EXPECT_CALL(*delegate, OnAckNotification()).Times(1); |
| 3421 | 3600 |
| 3422 // In total expect ACKs for all 4 packets. | 3601 // In total expect ACKs for all 4 packets. |
| 3423 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)).Times(2); | 3602 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)).Times(2); |
| 3424 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(4); | 3603 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(4); |
| 3425 | 3604 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 3438 ProcessAckPacket(&frame); | 3617 ProcessAckPacket(&frame); |
| 3439 | 3618 |
| 3440 // Now we get an ACK for packet 5 (retransmitted packet 2), which should | 3619 // Now we get an ACK for packet 5 (retransmitted packet 2), which should |
| 3441 // trigger the callback. | 3620 // trigger the callback. |
| 3442 QuicAckFrame second_ack_frame = InitAckFrame(5, 0); | 3621 QuicAckFrame second_ack_frame = InitAckFrame(5, 0); |
| 3443 ProcessAckPacket(&second_ack_frame); | 3622 ProcessAckPacket(&second_ack_frame); |
| 3444 } | 3623 } |
| 3445 | 3624 |
| 3446 // TODO(rjshade): Add a similar test that FEC recovery on peer (and resulting | 3625 // TODO(rjshade): Add a similar test that FEC recovery on peer (and resulting |
| 3447 // ACK) triggers notification on our end. | 3626 // ACK) triggers notification on our end. |
| 3448 TEST_F(QuicConnectionTest, AckNotifierCallbackAfterFECRecovery) { | 3627 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterFECRecovery) { |
| 3628 if (version() < QUIC_VERSION_15) { |
| 3629 return; |
| 3630 } |
| 3449 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3631 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3450 EXPECT_CALL(visitor_, OnCanWrite()); | 3632 EXPECT_CALL(visitor_, OnCanWrite()); |
| 3451 | 3633 |
| 3452 // Create a delegate which we expect to be called. | 3634 // Create a delegate which we expect to be called. |
| 3453 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); | 3635 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); |
| 3454 EXPECT_CALL(*delegate, OnAckNotification()).Times(1); | 3636 EXPECT_CALL(*delegate, OnAckNotification()).Times(1); |
| 3455 | 3637 |
| 3456 // Expect ACKs for 1 packet. | 3638 // Expect ACKs for 1 packet. |
| 3457 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); | 3639 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); |
| 3458 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(1); | 3640 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(1); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3517 | 3699 |
| 3518 MOCK_METHOD1(OnStreamFrame, | 3700 MOCK_METHOD1(OnStreamFrame, |
| 3519 void(const QuicStreamFrame&)); | 3701 void(const QuicStreamFrame&)); |
| 3520 | 3702 |
| 3521 MOCK_METHOD1(OnAckFrame, | 3703 MOCK_METHOD1(OnAckFrame, |
| 3522 void(const QuicAckFrame& frame)); | 3704 void(const QuicAckFrame& frame)); |
| 3523 | 3705 |
| 3524 MOCK_METHOD1(OnCongestionFeedbackFrame, | 3706 MOCK_METHOD1(OnCongestionFeedbackFrame, |
| 3525 void(const QuicCongestionFeedbackFrame&)); | 3707 void(const QuicCongestionFeedbackFrame&)); |
| 3526 | 3708 |
| 3709 MOCK_METHOD1(OnStopWaitingFrame, |
| 3710 void(const QuicStopWaitingFrame&)); |
| 3711 |
| 3527 MOCK_METHOD1(OnRstStreamFrame, | 3712 MOCK_METHOD1(OnRstStreamFrame, |
| 3528 void(const QuicRstStreamFrame&)); | 3713 void(const QuicRstStreamFrame&)); |
| 3529 | 3714 |
| 3530 MOCK_METHOD1(OnConnectionCloseFrame, | 3715 MOCK_METHOD1(OnConnectionCloseFrame, |
| 3531 void(const QuicConnectionCloseFrame&)); | 3716 void(const QuicConnectionCloseFrame&)); |
| 3532 | 3717 |
| 3533 MOCK_METHOD1(OnPublicResetPacket, | 3718 MOCK_METHOD1(OnPublicResetPacket, |
| 3534 void(const QuicPublicResetPacket&)); | 3719 void(const QuicPublicResetPacket&)); |
| 3535 | 3720 |
| 3536 MOCK_METHOD1(OnVersionNegotiationPacket, | 3721 MOCK_METHOD1(OnVersionNegotiationPacket, |
| 3537 void(const QuicVersionNegotiationPacket&)); | 3722 void(const QuicVersionNegotiationPacket&)); |
| 3538 | 3723 |
| 3539 MOCK_METHOD2(OnRevivedPacket, | 3724 MOCK_METHOD2(OnRevivedPacket, |
| 3540 void(const QuicPacketHeader&, StringPiece payload)); | 3725 void(const QuicPacketHeader&, StringPiece payload)); |
| 3541 }; | 3726 }; |
| 3542 | 3727 |
| 3543 TEST_F(QuicConnectionTest, OnPacketHeaderDebugVisitor) { | 3728 TEST_P(QuicConnectionTest, OnPacketHeaderDebugVisitor) { |
| 3544 QuicPacketHeader header; | 3729 QuicPacketHeader header; |
| 3545 | 3730 |
| 3546 scoped_ptr<MockQuicConnectionDebugVisitor> | 3731 scoped_ptr<MockQuicConnectionDebugVisitor> |
| 3547 debug_visitor(new StrictMock<MockQuicConnectionDebugVisitor>); | 3732 debug_visitor(new StrictMock<MockQuicConnectionDebugVisitor>); |
| 3548 connection_.set_debug_visitor(debug_visitor.get()); | 3733 connection_.set_debug_visitor(debug_visitor.get()); |
| 3549 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1); | 3734 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1); |
| 3550 connection_.OnPacketHeader(header); | 3735 connection_.OnPacketHeader(header); |
| 3551 } | 3736 } |
| 3552 | 3737 |
| 3553 TEST_F(QuicConnectionTest, Pacing) { | 3738 TEST_P(QuicConnectionTest, Pacing) { |
| 3554 ValueRestore<bool> old_flag(&FLAGS_enable_quic_pacing, true); | 3739 ValueRestore<bool> old_flag(&FLAGS_enable_quic_pacing, true); |
| 3555 | 3740 |
| 3556 TestConnection server(guid_, IPEndPoint(), helper_.get(), writer_.get(), | 3741 TestConnection server(guid_, IPEndPoint(), helper_.get(), writer_.get(), |
| 3557 true); | 3742 true, version()); |
| 3558 TestConnection client(guid_, IPEndPoint(), helper_.get(), writer_.get(), | 3743 TestConnection client(guid_, IPEndPoint(), helper_.get(), writer_.get(), |
| 3559 false); | 3744 false, version()); |
| 3560 EXPECT_TRUE(client.sent_packet_manager().using_pacing()); | 3745 EXPECT_TRUE(client.sent_packet_manager().using_pacing()); |
| 3561 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); | 3746 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); |
| 3562 } | 3747 } |
| 3563 | 3748 |
| 3749 TEST_P(QuicConnectionTest, ControlFramesInstigateAcks) { |
| 3750 if (version() < QUIC_VERSION_14) { |
| 3751 return; |
| 3752 } |
| 3753 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3754 |
| 3755 // Send a WINDOW_UPDATE frame. |
| 3756 QuicWindowUpdateFrame window_update; |
| 3757 window_update.stream_id = 3; |
| 3758 window_update.byte_offset = 1234; |
| 3759 EXPECT_CALL(visitor_, OnWindowUpdateFrames(_)); |
| 3760 ProcessFramePacket(QuicFrame(&window_update)); |
| 3761 |
| 3762 // Ensure that this has caused the ACK alarm to be set. |
| 3763 QuicAlarm* ack_alarm = QuicConnectionPeer::GetAckAlarm(&connection_); |
| 3764 EXPECT_TRUE(ack_alarm->IsSet()); |
| 3765 |
| 3766 // Cancel alarm, and try again with BLOCKED frame. |
| 3767 ack_alarm->Cancel(); |
| 3768 QuicBlockedFrame blocked; |
| 3769 blocked.stream_id = 3; |
| 3770 EXPECT_CALL(visitor_, OnBlockedFrames(_)); |
| 3771 ProcessFramePacket(QuicFrame(&blocked)); |
| 3772 EXPECT_TRUE(ack_alarm->IsSet()); |
| 3773 } |
| 3774 |
| 3564 } // namespace | 3775 } // namespace |
| 3565 } // namespace test | 3776 } // namespace test |
| 3566 } // namespace net | 3777 } // namespace net |
| OLD | NEW |