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

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

Issue 23597045: Land Recent QUIC changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged QuicPriority to RequestPriority changes Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/quic/quic_connection_logger.cc ('k') | net/quic/quic_crypto_stream.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "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 "net/base/net_errors.h" 9 #include "net/base/net_errors.h"
10 #include "net/quic/congestion_control/receive_algorithm_interface.h" 10 #include "net/quic/congestion_control/receive_algorithm_interface.h"
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 } 382 }
383 383
384 void SetReceiveAlgorithm(TestReceiveAlgorithm* receive_algorithm) { 384 void SetReceiveAlgorithm(TestReceiveAlgorithm* receive_algorithm) {
385 QuicConnectionPeer::SetReceiveAlgorithm(this, receive_algorithm); 385 QuicConnectionPeer::SetReceiveAlgorithm(this, receive_algorithm);
386 } 386 }
387 387
388 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) { 388 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) {
389 QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm); 389 QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm);
390 } 390 }
391 391
392 QuicConsumedData SendStreamData(QuicStreamId id,
393 StringPiece data,
394 QuicStreamOffset offset,
395 bool fin) {
396 struct iovec iov = {const_cast<char*>(data.data()),
397 static_cast<size_t>(data.size())};
398 return SendvStreamData(id, &iov, 1, offset, fin);
399 }
400
392 QuicConsumedData SendStreamData3() { 401 QuicConsumedData SendStreamData3() {
393 return SendStreamData(kStreamId3, "food", 0, !kFin); 402 return SendStreamData(kStreamId3, "food", 0, !kFin);
394 } 403 }
395 404
396 QuicConsumedData SendStreamData5() { 405 QuicConsumedData SendStreamData5() {
397 return SendStreamData(kStreamId5, "food2", 0, !kFin); 406 return SendStreamData(kStreamId5, "food2", 0, !kFin);
398 } 407 }
399 408
400 // The crypto stream has special semantics so that it is not blocked by a 409 // The crypto stream has special semantics so that it is not blocked by a
401 // congestion window limitation, and also so that it gets put into a separate 410 // congestion window limitation, and also so that it gets put into a separate
402 // packet (so that it is easier to reason about a crypto frame not being 411 // packet (so that it is easier to reason about a crypto frame not being
403 // split needlessly across packet boundaries). As a result, we have separate 412 // split needlessly across packet boundaries). As a result, we have separate
404 // tests for some cases for this stream. 413 // tests for some cases for this stream.
405 QuicConsumedData SendCryptoStreamData() { 414 QuicConsumedData SendCryptoStreamData() {
406 return SendStreamData(kCryptoStreamId, "chlo", 0, !kFin); 415 this->Flush();
416 QuicConsumedData consumed =
417 SendStreamData(kCryptoStreamId, "chlo", 0, !kFin);
418 this->Flush();
419 return consumed;
407 } 420 }
408 421
409 bool is_server() { 422 bool is_server() {
410 return QuicConnectionPeer::IsServer(this); 423 return QuicConnectionPeer::IsServer(this);
411 } 424 }
412 425
413 void set_version(QuicVersion version) { 426 void set_version(QuicVersion version) {
414 framer_.set_version(version); 427 framer_.set_version(version);
415 } 428 }
416 429
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 accept_packet_(true) { 473 accept_packet_(true) {
461 connection_.set_visitor(&visitor_); 474 connection_.set_visitor(&visitor_);
462 connection_.SetSendAlgorithm(send_algorithm_); 475 connection_.SetSendAlgorithm(send_algorithm_);
463 // Simplify tests by not sending feedback unless specifically configured. 476 // Simplify tests by not sending feedback unless specifically configured.
464 SetFeedback(NULL); 477 SetFeedback(NULL);
465 EXPECT_CALL( 478 EXPECT_CALL(
466 *send_algorithm_, TimeUntilSend(_, _, _, _)).WillRepeatedly(Return( 479 *send_algorithm_, TimeUntilSend(_, _, _, _)).WillRepeatedly(Return(
467 QuicTime::Delta::Zero())); 480 QuicTime::Delta::Zero()));
468 EXPECT_CALL(*receive_algorithm_, 481 EXPECT_CALL(*receive_algorithm_,
469 RecordIncomingPacket(_, _, _, _)).Times(AnyNumber()); 482 RecordIncomingPacket(_, _, _, _)).Times(AnyNumber());
470 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).Times(AnyNumber()); 483 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _)).Times(AnyNumber());
471 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly( 484 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly(
472 Return(QuicTime::Delta::Zero())); 485 Return(QuicTime::Delta::Zero()));
473 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillRepeatedly(Return( 486 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillRepeatedly(Return(
474 QuicBandwidth::FromKBitsPerSecond(100))); 487 QuicBandwidth::FromKBitsPerSecond(100)));
475 EXPECT_CALL(*send_algorithm_, SmoothedRtt()).WillRepeatedly(Return( 488 EXPECT_CALL(*send_algorithm_, SmoothedRtt()).WillRepeatedly(Return(
476 QuicTime::Delta::FromMilliseconds(100))); 489 QuicTime::Delta::FromMilliseconds(100)));
490 ON_CALL(*send_algorithm_, SentPacket(_, _, _, _, _))
491 .WillByDefault(Return(true));
477 // TODO(rch): remove this. 492 // TODO(rch): remove this.
478 QuicConnection::g_acks_do_not_instigate_acks = true; 493 QuicConnection::g_acks_do_not_instigate_acks = true;
479 } 494 }
480 495
481 ~QuicConnectionTest() { 496 ~QuicConnectionTest() {
482 // TODO(rch): remove this. 497 // TODO(rch): remove this.
483 QuicConnection::g_acks_do_not_instigate_acks = false; 498 QuicConnection::g_acks_do_not_instigate_acks = false;
484 } 499 }
485 500
486 QuicAckFrame* outgoing_ack() { 501 QuicAckFrame* outgoing_ack() {
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 framer_.EncryptPacket(ENCRYPTION_NONE, number, *fec_packet)); 638 framer_.EncryptPacket(ENCRYPTION_NONE, number, *fec_packet));
624 639
625 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); 640 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted);
626 return encrypted->length(); 641 return encrypted->length();
627 } 642 }
628 643
629 QuicByteCount SendStreamDataToPeer(QuicStreamId id, StringPiece data, 644 QuicByteCount SendStreamDataToPeer(QuicStreamId id, StringPiece data,
630 QuicStreamOffset offset, bool fin, 645 QuicStreamOffset offset, bool fin,
631 QuicPacketSequenceNumber* last_packet) { 646 QuicPacketSequenceNumber* last_packet) {
632 QuicByteCount packet_size; 647 QuicByteCount packet_size;
633 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).WillOnce( 648 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _))
634 SaveArg<2>(&packet_size)); 649 .WillOnce(DoAll(SaveArg<2>(&packet_size), Return(true)));
635 connection_.SendStreamData(id, data, offset, fin); 650 connection_.SendStreamData(id, data, offset, fin);
636 if (last_packet != NULL) { 651 if (last_packet != NULL) {
637 *last_packet = 652 *last_packet =
638 QuicConnectionPeer::GetPacketCreator(&connection_)->sequence_number(); 653 QuicConnectionPeer::GetPacketCreator(&connection_)->sequence_number();
639 } 654 }
640 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).Times(AnyNumber()); 655 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _)).Times(AnyNumber());
641 return packet_size; 656 return packet_size;
642 } 657 }
643 658
644 void SendAckPacketToPeer() { 659 void SendAckPacketToPeer() {
645 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).Times(1); 660 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _)).Times(1);
646 connection_.SendAck(); 661 connection_.SendAck();
647 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).Times(AnyNumber()); 662 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _)).Times(AnyNumber());
648 } 663 }
649 664
650 QuicPacketEntropyHash ProcessAckPacket(QuicAckFrame* frame, 665 QuicPacketEntropyHash ProcessAckPacket(QuicAckFrame* frame,
651 bool expect_writes) { 666 bool expect_writes) {
652 if (expect_writes) { 667 if (expect_writes) {
653 EXPECT_CALL(visitor_, OnCanWrite()).Times(1).WillOnce(Return(true)); 668 EXPECT_CALL(visitor_, OnCanWrite()).Times(1).WillOnce(Return(true));
654 } 669 }
655 return ProcessFramePacket(QuicFrame(frame)); 670 return ProcessFramePacket(QuicFrame(frame));
656 } 671 }
657 672
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 QuicStreamFrame frame1_; 749 QuicStreamFrame frame1_;
735 QuicStreamFrame frame2_; 750 QuicStreamFrame frame2_;
736 scoped_ptr<QuicAckFrame> outgoing_ack_; 751 scoped_ptr<QuicAckFrame> outgoing_ack_;
737 bool accept_packet_; 752 bool accept_packet_;
738 753
739 private: 754 private:
740 DISALLOW_COPY_AND_ASSIGN(QuicConnectionTest); 755 DISALLOW_COPY_AND_ASSIGN(QuicConnectionTest);
741 }; 756 };
742 757
743 TEST_F(QuicConnectionTest, PacketsInOrder) { 758 TEST_F(QuicConnectionTest, PacketsInOrder) {
759 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
760
744 ProcessPacket(1); 761 ProcessPacket(1);
745 EXPECT_EQ(1u, outgoing_ack()->received_info.largest_observed); 762 EXPECT_EQ(1u, outgoing_ack()->received_info.largest_observed);
746 EXPECT_EQ(0u, outgoing_ack()->received_info.missing_packets.size()); 763 EXPECT_EQ(0u, outgoing_ack()->received_info.missing_packets.size());
747 764
748 ProcessPacket(2); 765 ProcessPacket(2);
749 EXPECT_EQ(2u, outgoing_ack()->received_info.largest_observed); 766 EXPECT_EQ(2u, outgoing_ack()->received_info.largest_observed);
750 EXPECT_EQ(0u, outgoing_ack()->received_info.missing_packets.size()); 767 EXPECT_EQ(0u, outgoing_ack()->received_info.missing_packets.size());
751 768
752 ProcessPacket(3); 769 ProcessPacket(3);
753 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); 770 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed);
754 EXPECT_EQ(0u, outgoing_ack()->received_info.missing_packets.size()); 771 EXPECT_EQ(0u, outgoing_ack()->received_info.missing_packets.size());
755 } 772 }
756 773
757 TEST_F(QuicConnectionTest, PacketsRejected) { 774 TEST_F(QuicConnectionTest, PacketsRejected) {
775 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
776
758 ProcessPacket(1); 777 ProcessPacket(1);
759 EXPECT_EQ(1u, outgoing_ack()->received_info.largest_observed); 778 EXPECT_EQ(1u, outgoing_ack()->received_info.largest_observed);
760 EXPECT_EQ(0u, outgoing_ack()->received_info.missing_packets.size()); 779 EXPECT_EQ(0u, outgoing_ack()->received_info.missing_packets.size());
761 780
762 accept_packet_ = false; 781 accept_packet_ = false;
763 ProcessPacket(2); 782 ProcessPacket(2);
764 // We should not have an ack for two. 783 // We should not have an ack for two.
765 EXPECT_EQ(1u, outgoing_ack()->received_info.largest_observed); 784 EXPECT_EQ(1u, outgoing_ack()->received_info.largest_observed);
766 EXPECT_EQ(0u, outgoing_ack()->received_info.missing_packets.size()); 785 EXPECT_EQ(0u, outgoing_ack()->received_info.missing_packets.size());
767 } 786 }
768 787
769 TEST_F(QuicConnectionTest, PacketsOutOfOrder) { 788 TEST_F(QuicConnectionTest, PacketsOutOfOrder) {
789 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
790
770 ProcessPacket(3); 791 ProcessPacket(3);
771 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); 792 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed);
772 EXPECT_TRUE(IsMissing(2)); 793 EXPECT_TRUE(IsMissing(2));
773 EXPECT_TRUE(IsMissing(1)); 794 EXPECT_TRUE(IsMissing(1));
774 795
775 ProcessPacket(2); 796 ProcessPacket(2);
776 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); 797 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed);
777 EXPECT_FALSE(IsMissing(2)); 798 EXPECT_FALSE(IsMissing(2));
778 EXPECT_TRUE(IsMissing(1)); 799 EXPECT_TRUE(IsMissing(1));
779 800
780 ProcessPacket(1); 801 ProcessPacket(1);
781 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); 802 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed);
782 EXPECT_FALSE(IsMissing(2)); 803 EXPECT_FALSE(IsMissing(2));
783 EXPECT_FALSE(IsMissing(1)); 804 EXPECT_FALSE(IsMissing(1));
784 } 805 }
785 806
786 TEST_F(QuicConnectionTest, DuplicatePacket) { 807 TEST_F(QuicConnectionTest, DuplicatePacket) {
808 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
809
787 ProcessPacket(3); 810 ProcessPacket(3);
788 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); 811 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed);
789 EXPECT_TRUE(IsMissing(2)); 812 EXPECT_TRUE(IsMissing(2));
790 EXPECT_TRUE(IsMissing(1)); 813 EXPECT_TRUE(IsMissing(1));
791 814
792 // Send packet 3 again, but do not set the expectation that 815 // Send packet 3 again, but do not set the expectation that
793 // the visitor OnPacket() will be called. 816 // the visitor OnPacket() will be called.
794 ProcessDataPacket(3, 0, !kEntropyFlag); 817 ProcessDataPacket(3, 0, !kEntropyFlag);
795 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); 818 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed);
796 EXPECT_TRUE(IsMissing(2)); 819 EXPECT_TRUE(IsMissing(2));
797 EXPECT_TRUE(IsMissing(1)); 820 EXPECT_TRUE(IsMissing(1));
798 } 821 }
799 822
800 TEST_F(QuicConnectionTest, PacketsOutOfOrderWithAdditionsAndLeastAwaiting) { 823 TEST_F(QuicConnectionTest, PacketsOutOfOrderWithAdditionsAndLeastAwaiting) {
824 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
825
801 ProcessPacket(3); 826 ProcessPacket(3);
802 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); 827 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed);
803 EXPECT_TRUE(IsMissing(2)); 828 EXPECT_TRUE(IsMissing(2));
804 EXPECT_TRUE(IsMissing(1)); 829 EXPECT_TRUE(IsMissing(1));
805 830
806 ProcessPacket(2); 831 ProcessPacket(2);
807 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); 832 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed);
808 EXPECT_TRUE(IsMissing(1)); 833 EXPECT_TRUE(IsMissing(1));
809 834
810 ProcessPacket(5); 835 ProcessPacket(5);
(...skipping 15 matching lines...) Expand all
826 } 851 }
827 852
828 TEST_F(QuicConnectionTest, RejectPacketTooFarOut) { 853 TEST_F(QuicConnectionTest, RejectPacketTooFarOut) {
829 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a 854 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a
830 // packet call to the visitor. 855 // packet call to the visitor.
831 EXPECT_CALL(visitor_, ConnectionClose(QUIC_INVALID_PACKET_HEADER, false)); 856 EXPECT_CALL(visitor_, ConnectionClose(QUIC_INVALID_PACKET_HEADER, false));
832 ProcessDataPacket(6000, 0, !kEntropyFlag); 857 ProcessDataPacket(6000, 0, !kEntropyFlag);
833 } 858 }
834 859
835 TEST_F(QuicConnectionTest, TruncatedAck) { 860 TEST_F(QuicConnectionTest, TruncatedAck) {
861 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
836 EXPECT_CALL(visitor_, OnAck(_)).Times(testing::AnyNumber()); 862 EXPECT_CALL(visitor_, OnAck(_)).Times(testing::AnyNumber());
837 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(2); 863 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(2);
838 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); 864 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1);
839 for (int i = 0; i < 200; ++i) { 865 for (int i = 0; i < 200; ++i) {
840 SendStreamDataToPeer(1, "foo", i * 3, !kFin, NULL); 866 SendStreamDataToPeer(1, "foo", i * 3, !kFin, NULL);
841 } 867 }
842 868
843 QuicAckFrame frame(0, QuicTime::Zero(), 1); 869 QuicAckFrame frame(0, QuicTime::Zero(), 1);
844 frame.received_info.largest_observed = 193; 870 frame.received_info.largest_observed = 193;
845 InsertMissingPacketsBetween(&frame.received_info, 1, 193); 871 InsertMissingPacketsBetween(&frame.received_info, 1, 193);
846 frame.received_info.entropy_hash = 872 frame.received_info.entropy_hash =
847 QuicConnectionPeer::GetSentEntropyHash(&connection_, 193) ^ 873 QuicConnectionPeer::GetSentEntropyHash(&connection_, 193) ^
848 QuicConnectionPeer::GetSentEntropyHash(&connection_, 192); 874 QuicConnectionPeer::GetSentEntropyHash(&connection_, 192);
849 875
850 ProcessAckPacket(&frame, true); 876 ProcessAckPacket(&frame, true);
851 877
852 EXPECT_TRUE(QuicConnectionPeer::GetReceivedTruncatedAck(&connection_)); 878 EXPECT_TRUE(QuicConnectionPeer::GetReceivedTruncatedAck(&connection_));
853 879
854 frame.received_info.missing_packets.erase(192); 880 frame.received_info.missing_packets.erase(192);
855 frame.received_info.entropy_hash = 881 frame.received_info.entropy_hash =
856 QuicConnectionPeer::GetSentEntropyHash(&connection_, 193) ^ 882 QuicConnectionPeer::GetSentEntropyHash(&connection_, 193) ^
857 QuicConnectionPeer::GetSentEntropyHash(&connection_, 191); 883 QuicConnectionPeer::GetSentEntropyHash(&connection_, 191);
858 884
859 ProcessAckPacket(&frame, true); 885 ProcessAckPacket(&frame, true);
860 EXPECT_FALSE(QuicConnectionPeer::GetReceivedTruncatedAck(&connection_)); 886 EXPECT_FALSE(QuicConnectionPeer::GetReceivedTruncatedAck(&connection_));
861 } 887 }
862 888
863 TEST_F(QuicConnectionTest, AckReceiptCausesAckSendBadEntropy) { 889 TEST_F(QuicConnectionTest, AckReceiptCausesAckSendBadEntropy) {
890 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
891
864 ProcessPacket(1); 892 ProcessPacket(1);
865 // Delay sending, then queue up an ack. 893 // Delay sending, then queue up an ack.
866 EXPECT_CALL(*send_algorithm_, 894 EXPECT_CALL(*send_algorithm_,
867 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( 895 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce(
868 testing::Return(QuicTime::Delta::FromMicroseconds(1))); 896 testing::Return(QuicTime::Delta::FromMicroseconds(1)));
869 QuicConnectionPeer::SendAck(&connection_); 897 QuicConnectionPeer::SendAck(&connection_);
870 898
871 // Process an ack with a least unacked of the received ack. 899 // Process an ack with a least unacked of the received ack.
872 // This causes an ack to be sent when TimeUntilSend returns 0. 900 // This causes an ack to be sent when TimeUntilSend returns 0.
873 EXPECT_CALL(*send_algorithm_, 901 EXPECT_CALL(*send_algorithm_,
874 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillRepeatedly( 902 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillRepeatedly(
875 testing::Return(QuicTime::Delta::Zero())); 903 testing::Return(QuicTime::Delta::Zero()));
876 // Skip a packet and then record an ack. 904 // Skip a packet and then record an ack.
877 creator_.set_sequence_number(2); 905 creator_.set_sequence_number(2);
878 QuicAckFrame frame(0, QuicTime::Zero(), 3); 906 QuicAckFrame frame(0, QuicTime::Zero(), 3);
879 ProcessAckPacket(&frame, true); 907 ProcessAckPacket(&frame, true);
880 } 908 }
881 909
882 TEST_F(QuicConnectionTest, AckReceiptCausesAckSend) { 910 TEST_F(QuicConnectionTest, AckReceiptCausesAckSend) {
911 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
883 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); 912 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1);
884 QuicPacketSequenceNumber largest_observed; 913 QuicPacketSequenceNumber largest_observed;
885 QuicByteCount packet_size; 914 QuicByteCount packet_size;
886 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, NOT_RETRANSMISSION)) 915 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, NOT_RETRANSMISSION, _))
887 .WillOnce(DoAll(SaveArg<1>(&largest_observed), SaveArg<2>(&packet_size))); 916 .WillOnce(DoAll(SaveArg<1>(&largest_observed), SaveArg<2>(&packet_size),
917 Return(true)));
888 EXPECT_CALL(*send_algorithm_, AbandoningPacket(1, _)).Times(1); 918 EXPECT_CALL(*send_algorithm_, AbandoningPacket(1, _)).Times(1);
889 connection_.SendStreamData(1, "foo", 0, !kFin); 919 connection_.SendStreamData(1, "foo", 0, !kFin);
890 QuicAckFrame frame(1, QuicTime::Zero(), largest_observed); 920 QuicAckFrame frame(1, QuicTime::Zero(), largest_observed);
891 frame.received_info.missing_packets.insert(largest_observed); 921 frame.received_info.missing_packets.insert(largest_observed);
892 frame.received_info.entropy_hash = QuicConnectionPeer::GetSentEntropyHash( 922 frame.received_info.entropy_hash = QuicConnectionPeer::GetSentEntropyHash(
893 &connection_, largest_observed - 1); 923 &connection_, largest_observed - 1);
894 ProcessAckPacket(&frame, true); 924 ProcessAckPacket(&frame, true);
895 ProcessAckPacket(&frame, true); 925 ProcessAckPacket(&frame, true);
896 // Third nack should retransmit the largest observed packet. 926 // Third nack should retransmit the largest observed packet.
897 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, packet_size - kQuicVersionSize, 927 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, packet_size - kQuicVersionSize,
898 IS_RETRANSMISSION)); 928 IS_RETRANSMISSION, _));
899 ProcessAckPacket(&frame, true); 929 ProcessAckPacket(&frame, true);
900 930
901 // Now if the peer sends an ack which still reports the retransmitted packet 931 // Now if the peer sends an ack which still reports the retransmitted packet
902 // as missing, then that will count as a packet which instigates an ack. 932 // as missing, then that will count as a packet which instigates an ack.
903 ProcessAckPacket(&frame, true); 933 ProcessAckPacket(&frame, true);
904 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, NOT_RETRANSMISSION)); 934 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, NOT_RETRANSMISSION, _));
905 ProcessAckPacket(&frame, true); 935 ProcessAckPacket(&frame, true);
906 936
907 // But an ack with no new missing packest will not send an ack. 937 // But an ack with no new missing packest will not send an ack.
908 frame.received_info.missing_packets.clear(); 938 frame.received_info.missing_packets.clear();
909 ProcessAckPacket(&frame, true); 939 ProcessAckPacket(&frame, true);
910 ProcessAckPacket(&frame, true); 940 ProcessAckPacket(&frame, true);
911 } 941 }
912 942
913 TEST_F(QuicConnectionTest, LeastUnackedLower) { 943 TEST_F(QuicConnectionTest, LeastUnackedLower) {
944 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
945
914 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); 946 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL);
915 SendStreamDataToPeer(1, "bar", 3, !kFin, NULL); 947 SendStreamDataToPeer(1, "bar", 3, !kFin, NULL);
916 SendStreamDataToPeer(1, "eep", 6, !kFin, NULL); 948 SendStreamDataToPeer(1, "eep", 6, !kFin, NULL);
917 949
918 // Start out saying the least unacked is 2 950 // Start out saying the least unacked is 2
919 creator_.set_sequence_number(5); 951 creator_.set_sequence_number(5);
920 QuicAckFrame frame(0, QuicTime::Zero(), 2); 952 QuicAckFrame frame(0, QuicTime::Zero(), 2);
921 ProcessAckPacket(&frame, true); 953 ProcessAckPacket(&frame, true);
922 954
923 // Change it to 1, but lower the sequence number to fake out-of-order packets. 955 // Change it to 1, but lower the sequence number to fake out-of-order packets.
924 // This should be fine. 956 // This should be fine.
925 creator_.set_sequence_number(1); 957 creator_.set_sequence_number(1);
926 QuicAckFrame frame2(0, QuicTime::Zero(), 1); 958 QuicAckFrame frame2(0, QuicTime::Zero(), 1);
927 // The scheduler will not process out of order acks. 959 // The scheduler will not process out of order acks.
928 ProcessAckPacket(&frame2, false); 960 ProcessAckPacket(&frame2, false);
929 961
930 // Now claim it's one, but set the ordering so it was sent "after" the first 962 // Now claim it's one, but set the ordering so it was sent "after" the first
931 // one. This should cause a connection error. 963 // one. This should cause a connection error.
932 EXPECT_CALL(visitor_, ConnectionClose(QUIC_INVALID_ACK_DATA, false)); 964 EXPECT_CALL(visitor_, ConnectionClose(QUIC_INVALID_ACK_DATA, false));
933 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)); 965 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _));
934 creator_.set_sequence_number(7); 966 creator_.set_sequence_number(7);
935 ProcessAckPacket(&frame2, false); 967 ProcessAckPacket(&frame2, false);
936 } 968 }
937 969
938 TEST_F(QuicConnectionTest, LargestObservedLower) { 970 TEST_F(QuicConnectionTest, LargestObservedLower) {
971 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
972
939 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); 973 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL);
940 SendStreamDataToPeer(1, "bar", 3, !kFin, NULL); 974 SendStreamDataToPeer(1, "bar", 3, !kFin, NULL);
941 SendStreamDataToPeer(1, "eep", 6, !kFin, NULL); 975 SendStreamDataToPeer(1, "eep", 6, !kFin, NULL);
942 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(2); 976 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(2);
943 977
944 // Start out saying the largest observed is 2. 978 // Start out saying the largest observed is 2.
945 QuicAckFrame frame(2, QuicTime::Zero(), 0); 979 QuicAckFrame frame(2, QuicTime::Zero(), 0);
946 frame.received_info.entropy_hash = QuicConnectionPeer::GetSentEntropyHash( 980 frame.received_info.entropy_hash = QuicConnectionPeer::GetSentEntropyHash(
947 &connection_, 2); 981 &connection_, 2);
948 EXPECT_CALL(visitor_, OnAck(_)); 982 EXPECT_CALL(visitor_, OnAck(_));
949 ProcessAckPacket(&frame, true); 983 ProcessAckPacket(&frame, true);
950 984
951 // Now change it to 1, and it should cause a connection error. 985 // Now change it to 1, and it should cause a connection error.
952 QuicAckFrame frame2(1, QuicTime::Zero(), 0); 986 QuicAckFrame frame2(1, QuicTime::Zero(), 0);
953 EXPECT_CALL(visitor_, ConnectionClose(QUIC_INVALID_ACK_DATA, false)); 987 EXPECT_CALL(visitor_, ConnectionClose(QUIC_INVALID_ACK_DATA, false));
954 ProcessAckPacket(&frame2, false); 988 ProcessAckPacket(&frame2, false);
955 } 989 }
956 990
957 TEST_F(QuicConnectionTest, LeastUnackedGreaterThanPacketSequenceNumber) { 991 TEST_F(QuicConnectionTest, LeastUnackedGreaterThanPacketSequenceNumber) {
992 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
958 EXPECT_CALL(visitor_, ConnectionClose(QUIC_INVALID_ACK_DATA, false)); 993 EXPECT_CALL(visitor_, ConnectionClose(QUIC_INVALID_ACK_DATA, false));
959 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)); 994 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _));
960 // Create an ack with least_unacked is 2 in packet number 1. 995 // Create an ack with least_unacked is 2 in packet number 1.
961 creator_.set_sequence_number(0); 996 creator_.set_sequence_number(0);
962 QuicAckFrame frame(0, QuicTime::Zero(), 2); 997 QuicAckFrame frame(0, QuicTime::Zero(), 2);
963 ProcessAckPacket(&frame, false); 998 ProcessAckPacket(&frame, false);
964 } 999 }
965 1000
966 TEST_F(QuicConnectionTest, 1001 TEST_F(QuicConnectionTest,
967 NackSequenceNumberGreaterThanLargestReceived) { 1002 NackSequenceNumberGreaterThanLargestReceived) {
1003 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1004
968 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); 1005 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL);
969 SendStreamDataToPeer(1, "bar", 3, !kFin, NULL); 1006 SendStreamDataToPeer(1, "bar", 3, !kFin, NULL);
970 SendStreamDataToPeer(1, "eep", 6, !kFin, NULL); 1007 SendStreamDataToPeer(1, "eep", 6, !kFin, NULL);
971 1008
972 EXPECT_CALL(visitor_, ConnectionClose(QUIC_INVALID_ACK_DATA, false)); 1009 EXPECT_CALL(visitor_, ConnectionClose(QUIC_INVALID_ACK_DATA, false));
973 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)); 1010 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _));
974 QuicAckFrame frame(0, QuicTime::Zero(), 1); 1011 QuicAckFrame frame(0, QuicTime::Zero(), 1);
975 frame.received_info.missing_packets.insert(3); 1012 frame.received_info.missing_packets.insert(3);
976 ProcessAckPacket(&frame, false); 1013 ProcessAckPacket(&frame, false);
977 } 1014 }
978 1015
979 TEST_F(QuicConnectionTest, AckUnsentData) { 1016 TEST_F(QuicConnectionTest, AckUnsentData) {
980 // Ack a packet which has not been sent. 1017 // Ack a packet which has not been sent.
981 EXPECT_CALL(visitor_, ConnectionClose(QUIC_INVALID_ACK_DATA, false)); 1018 EXPECT_CALL(visitor_, ConnectionClose(QUIC_INVALID_ACK_DATA, false));
982 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)); 1019 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1020 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _));
983 QuicAckFrame frame(1, QuicTime::Zero(), 0); 1021 QuicAckFrame frame(1, QuicTime::Zero(), 0);
984 ProcessAckPacket(&frame, false); 1022 ProcessAckPacket(&frame, false);
985 } 1023 }
986 1024
987 TEST_F(QuicConnectionTest, AckAll) { 1025 TEST_F(QuicConnectionTest, AckAll) {
1026 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
988 ProcessPacket(1); 1027 ProcessPacket(1);
989 1028
990 creator_.set_sequence_number(1); 1029 creator_.set_sequence_number(1);
991 QuicAckFrame frame1(0, QuicTime::Zero(), 1); 1030 QuicAckFrame frame1(0, QuicTime::Zero(), 1);
992 ProcessAckPacket(&frame1, true); 1031 ProcessAckPacket(&frame1, true);
993 } 1032 }
994 1033
995 TEST_F(QuicConnectionTest, SendingDifferentSequenceNumberLengthsBandwidth) { 1034 TEST_F(QuicConnectionTest, SendingDifferentSequenceNumberLengthsBandwidth) {
996 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillOnce(Return( 1035 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillOnce(Return(
997 QuicBandwidth::FromKBitsPerSecond(1000))); 1036 QuicBandwidth::FromKBitsPerSecond(1000)));
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 100 * 256 * 256 * 256); 1125 100 * 256 * 256 * 256);
1087 1126
1088 SendStreamDataToPeer(1u, "foo", 12, !kFin, &last_packet); 1127 SendStreamDataToPeer(1u, "foo", 12, !kFin, &last_packet);
1089 EXPECT_EQ(PACKET_6BYTE_SEQUENCE_NUMBER, 1128 EXPECT_EQ(PACKET_6BYTE_SEQUENCE_NUMBER,
1090 connection_.options()->send_sequence_number_length); 1129 connection_.options()->send_sequence_number_length);
1091 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, 1130 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER,
1092 last_header()->public_header.sequence_number_length); 1131 last_header()->public_header.sequence_number_length);
1093 } 1132 }
1094 1133
1095 TEST_F(QuicConnectionTest, BasicSending) { 1134 TEST_F(QuicConnectionTest, BasicSending) {
1135 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1096 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(6); 1136 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(6);
1097 QuicPacketSequenceNumber last_packet; 1137 QuicPacketSequenceNumber last_packet;
1098 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 1138 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1
1099 EXPECT_EQ(1u, last_packet); 1139 EXPECT_EQ(1u, last_packet);
1100 SendAckPacketToPeer(); // Packet 2 1140 SendAckPacketToPeer(); // Packet 2
1101 1141
1102 EXPECT_EQ(1u, last_ack()->sent_info.least_unacked); 1142 EXPECT_EQ(1u, last_ack()->sent_info.least_unacked);
1103 1143
1104 SendAckPacketToPeer(); // Packet 3 1144 SendAckPacketToPeer(); // Packet 3
1105 EXPECT_EQ(1u, last_ack()->sent_info.least_unacked); 1145 EXPECT_EQ(1u, last_ack()->sent_info.least_unacked);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 // All packets carry version info till version is negotiated. 1195 // All packets carry version info till version is negotiated.
1156 size_t payload_length; 1196 size_t payload_length;
1157 connection_.options()->max_packet_length = 1197 connection_.options()->max_packet_length =
1158 GetPacketLengthForOneStream( 1198 GetPacketLengthForOneStream(
1159 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, 1199 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER,
1160 IN_FEC_GROUP, &payload_length); 1200 IN_FEC_GROUP, &payload_length);
1161 // And send FEC every two packets. 1201 // And send FEC every two packets.
1162 connection_.options()->max_packets_per_fec_group = 2; 1202 connection_.options()->max_packets_per_fec_group = 2;
1163 1203
1164 // Send 4 data packets and 2 FEC packets. 1204 // Send 4 data packets and 2 FEC packets.
1165 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).Times(6); 1205 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _)).Times(6);
1166 // The first stream frame will consume 2 fewer bytes than the other three. 1206 // The first stream frame will consume 2 fewer bytes than the other three.
1167 const string payload(payload_length * 4 - 6, 'a'); 1207 const string payload(payload_length * 4 - 6, 'a');
1168 connection_.SendStreamData(1, payload, 0, !kFin); 1208 connection_.SendStreamData(1, payload, 0, !kFin);
1169 // Expect the FEC group to be closed after SendStreamData. 1209 // Expect the FEC group to be closed after SendStreamData.
1170 EXPECT_FALSE(creator_.ShouldSendFec(true)); 1210 EXPECT_FALSE(creator_.ShouldSendFec(true));
1171 } 1211 }
1172 1212
1173 TEST_F(QuicConnectionTest, FECQueueing) { 1213 TEST_F(QuicConnectionTest, FECQueueing) {
1174 // All packets carry version info till version is negotiated. 1214 // All packets carry version info till version is negotiated.
1175 size_t payload_length; 1215 size_t payload_length;
1176 connection_.options()->max_packet_length = 1216 connection_.options()->max_packet_length =
1177 GetPacketLengthForOneStream( 1217 GetPacketLengthForOneStream(
1178 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, 1218 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER,
1179 IN_FEC_GROUP, &payload_length); 1219 IN_FEC_GROUP, &payload_length);
1180 // And send FEC every two packets. 1220 // And send FEC every two packets.
1181 connection_.options()->max_packets_per_fec_group = 2; 1221 connection_.options()->max_packets_per_fec_group = 2;
1182 1222
1183 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1223 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1184 helper_->set_blocked(true); 1224 helper_->set_blocked(true);
1185 const string payload(payload_length, 'a'); 1225 const string payload(payload_length, 'a');
1186 connection_.SendStreamData(1, payload, 0, !kFin); 1226 connection_.SendStreamData(1, payload, 0, !kFin);
1187 EXPECT_FALSE(creator_.ShouldSendFec(true)); 1227 EXPECT_FALSE(creator_.ShouldSendFec(true));
1188 // Expect the first data packet and the fec packet to be queued. 1228 // Expect the first data packet and the fec packet to be queued.
1189 EXPECT_EQ(2u, connection_.NumQueuedPackets()); 1229 EXPECT_EQ(2u, connection_.NumQueuedPackets());
1190 } 1230 }
1191 1231
1192 TEST_F(QuicConnectionTest, AbandonFECFromCongestionWindow) { 1232 TEST_F(QuicConnectionTest, AbandonFECFromCongestionWindow) {
1193 connection_.options()->max_packets_per_fec_group = 1; 1233 connection_.options()->max_packets_per_fec_group = 1;
1194 // 1 Data and 1 FEC packet. 1234 // 1 Data and 1 FEC packet.
1195 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).Times(2); 1235 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _)).Times(2);
1196 connection_.SendStreamData(1, "foo", 0, !kFin); 1236 connection_.SendStreamData(1, "foo", 0, !kFin);
1197 1237
1198 // Larger timeout for FEC bytes to expire. 1238 // Larger timeout for FEC bytes to expire.
1199 const QuicTime::Delta retransmission_time = 1239 const QuicTime::Delta retransmission_time =
1200 QuicTime::Delta::FromMilliseconds(5000); 1240 QuicTime::Delta::FromMilliseconds(5000);
1201 clock_.AdvanceTime(retransmission_time); 1241 clock_.AdvanceTime(retransmission_time);
1202 1242
1203 // Send only data packet. 1243 // Send only data packet.
1204 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).Times(1); 1244 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _)).Times(1);
1205 // Abandon both FEC and data packet. 1245 // Abandon both FEC and data packet.
1206 EXPECT_CALL(*send_algorithm_, AbandoningPacket(_, _)).Times(2); 1246 EXPECT_CALL(*send_algorithm_, AbandoningPacket(_, _)).Times(2);
1207 1247
1208 connection_.OnRetransmissionTimeout(); 1248 connection_.OnRetransmissionTimeout();
1209 } 1249 }
1210 1250
1211 TEST_F(QuicConnectionTest, DontAbandonAckedFEC) { 1251 TEST_F(QuicConnectionTest, DontAbandonAckedFEC) {
1252 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1212 connection_.options()->max_packets_per_fec_group = 1; 1253 connection_.options()->max_packets_per_fec_group = 1;
1213 const QuicPacketSequenceNumber sequence_number = 1254 const QuicPacketSequenceNumber sequence_number =
1214 QuicConnectionPeer::GetPacketCreator(&connection_)->sequence_number() + 1; 1255 QuicConnectionPeer::GetPacketCreator(&connection_)->sequence_number() + 1;
1215 1256
1216 // 1 Data and 1 FEC packet. 1257 // 1 Data and 1 FEC packet.
1217 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).Times(2); 1258 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _)).Times(2);
1218 connection_.SendStreamData(1, "foo", 0, !kFin); 1259 connection_.SendStreamData(1, "foo", 0, !kFin);
1219 1260
1220 QuicAckFrame ack_fec(2, QuicTime::Zero(), 1); 1261 QuicAckFrame ack_fec(2, QuicTime::Zero(), 1);
1221 // Data packet missing. 1262 // Data packet missing.
1222 ack_fec.received_info.missing_packets.insert(1); 1263 ack_fec.received_info.missing_packets.insert(1);
1223 ack_fec.received_info.entropy_hash = 1264 ack_fec.received_info.entropy_hash =
1224 QuicConnectionPeer::GetSentEntropyHash(&connection_, 2) ^ 1265 QuicConnectionPeer::GetSentEntropyHash(&connection_, 2) ^
1225 QuicConnectionPeer::GetSentEntropyHash(&connection_, 1); 1266 QuicConnectionPeer::GetSentEntropyHash(&connection_, 1);
1226 1267
1227 EXPECT_CALL(visitor_, OnAck(_)).Times(1); 1268 EXPECT_CALL(visitor_, OnAck(_)).Times(1);
1228 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1); 1269 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1);
1229 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); 1270 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1);
1230 1271
1231 ProcessAckPacket(&ack_fec, true); 1272 ProcessAckPacket(&ack_fec, true);
1232 1273
1233 clock_.AdvanceTime(DefaultRetransmissionTime()); 1274 clock_.AdvanceTime(DefaultRetransmissionTime());
1234 1275
1235 // Abandon only data packet, FEC has been acked. 1276 // Abandon only data packet, FEC has been acked.
1236 EXPECT_CALL(*send_algorithm_, AbandoningPacket(sequence_number, _)).Times(1); 1277 EXPECT_CALL(*send_algorithm_, AbandoningPacket(sequence_number, _)).Times(1);
1237 // Send only data packet. 1278 // Send only data packet.
1238 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).Times(1); 1279 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _)).Times(1);
1239 connection_.OnRetransmissionTimeout(); 1280 connection_.OnRetransmissionTimeout();
1240 } 1281 }
1241 1282
1242 TEST_F(QuicConnectionTest, FramePacking) { 1283 TEST_F(QuicConnectionTest, FramePacking) {
1243 // Block the connection. 1284 // Block the connection.
1244 connection_.GetSendAlarm()->Set( 1285 connection_.GetSendAlarm()->Set(
1245 clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(1))); 1286 clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(1)));
1246 1287
1247 // Send an ack and two stream frames in 1 packet by queueing them. 1288 // Send an ack and two stream frames in 1 packet by queueing them.
1248 connection_.SendAck(); 1289 connection_.SendAck();
1249 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( 1290 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll(
1250 IgnoreResult(InvokeWithoutArgs(&connection_, 1291 IgnoreResult(InvokeWithoutArgs(&connection_,
1251 &TestConnection::SendStreamData3)), 1292 &TestConnection::SendStreamData3)),
1252 IgnoreResult(InvokeWithoutArgs(&connection_, 1293 IgnoreResult(InvokeWithoutArgs(&connection_,
1253 &TestConnection::SendStreamData5)), 1294 &TestConnection::SendStreamData5)),
1254 Return(true))); 1295 Return(true)));
1255 1296
1256 // Unblock the connection. 1297 // Unblock the connection.
1257 connection_.GetSendAlarm()->Cancel(); 1298 connection_.GetSendAlarm()->Cancel();
1258 EXPECT_CALL(*send_algorithm_, 1299 EXPECT_CALL(*send_algorithm_,
1259 SentPacket(_, _, _, NOT_RETRANSMISSION)) 1300 SentPacket(_, _, _, NOT_RETRANSMISSION, _))
1260 .Times(1); 1301 .Times(1);
1261 connection_.OnCanWrite(); 1302 connection_.OnCanWrite();
1262 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1303 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1263 EXPECT_FALSE(connection_.HasQueuedData()); 1304 EXPECT_FALSE(connection_.HasQueuedData());
1264 1305
1265 // Parse the last packet and ensure it's an ack and two stream frames from 1306 // Parse the last packet and ensure it's an ack and two stream frames from
1266 // two different streams. 1307 // two different streams.
1267 EXPECT_EQ(3u, helper_->frame_count()); 1308 EXPECT_EQ(3u, helper_->frame_count());
1268 EXPECT_TRUE(helper_->ack()); 1309 EXPECT_TRUE(helper_->ack());
1269 EXPECT_EQ(2u, helper_->stream_frames()->size()); 1310 EXPECT_EQ(2u, helper_->stream_frames()->size());
(...skipping 12 matching lines...) Expand all
1282 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( 1323 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll(
1283 IgnoreResult(InvokeWithoutArgs(&connection_, 1324 IgnoreResult(InvokeWithoutArgs(&connection_,
1284 &TestConnection::SendStreamData3)), 1325 &TestConnection::SendStreamData3)),
1285 IgnoreResult(InvokeWithoutArgs(&connection_, 1326 IgnoreResult(InvokeWithoutArgs(&connection_,
1286 &TestConnection::SendCryptoStreamData)), 1327 &TestConnection::SendCryptoStreamData)),
1287 Return(true))); 1328 Return(true)));
1288 1329
1289 // Unblock the connection. 1330 // Unblock the connection.
1290 connection_.GetSendAlarm()->Cancel(); 1331 connection_.GetSendAlarm()->Cancel();
1291 EXPECT_CALL(*send_algorithm_, 1332 EXPECT_CALL(*send_algorithm_,
1292 SentPacket(_, _, _, NOT_RETRANSMISSION)) 1333 SentPacket(_, _, _, NOT_RETRANSMISSION, _))
1293 .Times(2); 1334 .Times(2);
1294 connection_.OnCanWrite(); 1335 connection_.OnCanWrite();
1295 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1336 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1296 EXPECT_FALSE(connection_.HasQueuedData()); 1337 EXPECT_FALSE(connection_.HasQueuedData());
1297 1338
1298 // Parse the last packet and ensure it's the crypto stream frame. 1339 // Parse the last packet and ensure it's the crypto stream frame.
1299 EXPECT_EQ(1u, helper_->frame_count()); 1340 EXPECT_EQ(1u, helper_->frame_count());
1300 EXPECT_TRUE(helper_->ack()); 1341 EXPECT_TRUE(helper_->ack());
1301 EXPECT_EQ(1u, helper_->stream_frames()->size()); 1342 EXPECT_EQ(1u, helper_->stream_frames()->size());
1302 EXPECT_EQ(kCryptoStreamId, (*helper_->stream_frames())[0].stream_id); 1343 EXPECT_EQ(kCryptoStreamId, (*helper_->stream_frames())[0].stream_id);
(...skipping 10 matching lines...) Expand all
1313 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( 1354 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll(
1314 IgnoreResult(InvokeWithoutArgs(&connection_, 1355 IgnoreResult(InvokeWithoutArgs(&connection_,
1315 &TestConnection::SendCryptoStreamData)), 1356 &TestConnection::SendCryptoStreamData)),
1316 IgnoreResult(InvokeWithoutArgs(&connection_, 1357 IgnoreResult(InvokeWithoutArgs(&connection_,
1317 &TestConnection::SendStreamData3)), 1358 &TestConnection::SendStreamData3)),
1318 Return(true))); 1359 Return(true)));
1319 1360
1320 // Unblock the connection. 1361 // Unblock the connection.
1321 connection_.GetSendAlarm()->Cancel(); 1362 connection_.GetSendAlarm()->Cancel();
1322 EXPECT_CALL(*send_algorithm_, 1363 EXPECT_CALL(*send_algorithm_,
1323 SentPacket(_, _, _, NOT_RETRANSMISSION)) 1364 SentPacket(_, _, _, NOT_RETRANSMISSION, _))
1324 .Times(3); 1365 .Times(3);
1325 connection_.OnCanWrite(); 1366 connection_.OnCanWrite();
1326 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1367 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1327 EXPECT_FALSE(connection_.HasQueuedData()); 1368 EXPECT_FALSE(connection_.HasQueuedData());
1328 1369
1329 // Parse the last packet and ensure it's the stream frame from stream 3. 1370 // Parse the last packet and ensure it's the stream frame from stream 3.
1330 EXPECT_EQ(1u, helper_->frame_count()); 1371 EXPECT_EQ(1u, helper_->frame_count());
1331 EXPECT_TRUE(helper_->ack()); 1372 EXPECT_TRUE(helper_->ack());
1332 EXPECT_EQ(1u, helper_->stream_frames()->size()); 1373 EXPECT_EQ(1u, helper_->stream_frames()->size());
1333 EXPECT_EQ(kStreamId3, (*helper_->stream_frames())[0].stream_id); 1374 EXPECT_EQ(kStreamId3, (*helper_->stream_frames())[0].stream_id);
(...skipping 11 matching lines...) Expand all
1345 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( 1386 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll(
1346 IgnoreResult(InvokeWithoutArgs(&connection_, 1387 IgnoreResult(InvokeWithoutArgs(&connection_,
1347 &TestConnection::SendStreamData3)), 1388 &TestConnection::SendStreamData3)),
1348 IgnoreResult(InvokeWithoutArgs(&connection_, 1389 IgnoreResult(InvokeWithoutArgs(&connection_,
1349 &TestConnection::SendStreamData5)), 1390 &TestConnection::SendStreamData5)),
1350 Return(true))); 1391 Return(true)));
1351 1392
1352 // Unblock the connection. 1393 // Unblock the connection.
1353 connection_.GetSendAlarm()->Cancel(); 1394 connection_.GetSendAlarm()->Cancel();
1354 EXPECT_CALL(*send_algorithm_, 1395 EXPECT_CALL(*send_algorithm_,
1355 SentPacket(_, _, _, NOT_RETRANSMISSION)).Times(2); 1396 SentPacket(_, _, _, NOT_RETRANSMISSION, _)).Times(2);
1356 connection_.OnCanWrite(); 1397 connection_.OnCanWrite();
1357 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1398 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1358 EXPECT_FALSE(connection_.HasQueuedData()); 1399 EXPECT_FALSE(connection_.HasQueuedData());
1359 1400
1360 // Parse the last packet and ensure it's in an fec group. 1401 // Parse the last packet and ensure it's in an fec group.
1361 EXPECT_EQ(1u, helper_->header()->fec_group); 1402 EXPECT_EQ(1u, helper_->header()->fec_group);
1362 EXPECT_EQ(0u, helper_->frame_count()); 1403 EXPECT_EQ(0u, helper_->frame_count());
1363 } 1404 }
1364 1405
1406 TEST_F(QuicConnectionTest, FramePackingSendv) {
1407 // Send two stream frames in 1 packet by using writev.
1408 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, NOT_RETRANSMISSION, _));
1409
1410 char data[] = "ABCD";
1411 iovec iov[2] = { {static_cast<void*>(data), 2},
1412 {static_cast<void*>(data + 2), 2} };
1413 connection_.SendvStreamData(1, iov, 2, 0, !kFin);
1414
1415 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1416 EXPECT_FALSE(connection_.HasQueuedData());
1417
1418 // Parse the last packet and ensure it's two stream frames from one stream.
1419 // TODO(ianswett): Ideally this would arrive in one frame in the future.
1420 EXPECT_EQ(2u, helper_->frame_count());
1421 EXPECT_EQ(2u, helper_->stream_frames()->size());
1422 EXPECT_EQ(1u, (*helper_->stream_frames())[0].stream_id);
1423 EXPECT_EQ(1u, (*helper_->stream_frames())[1].stream_id);
1424 }
1425
1426 TEST_F(QuicConnectionTest, FramePackingSendvQueued) {
1427 // Try to send two stream frames in 1 packet by using writev.
1428 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, NOT_RETRANSMISSION, _));
1429
1430 helper_->set_blocked(true);
1431 char data[] = "ABCD";
1432 iovec iov[2] = { {static_cast<void*>(data), 2},
1433 {static_cast<void*>(data + 2), 2} };
1434 connection_.SendvStreamData(1, iov, 2, 0, !kFin);
1435
1436 EXPECT_EQ(1u, connection_.NumQueuedPackets());
1437 EXPECT_TRUE(connection_.HasQueuedData());
1438
1439 // Attempt to send all packets, but since we're actually still
1440 // blocked, they should all remain queued.
1441 EXPECT_FALSE(connection_.OnCanWrite());
1442 EXPECT_EQ(1u, connection_.NumQueuedPackets());
1443
1444 // Unblock the writes and actually send.
1445 helper_->set_blocked(false);
1446 EXPECT_CALL(visitor_, OnCanWrite());
1447 EXPECT_TRUE(connection_.OnCanWrite());
1448 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1449
1450 // Parse the last packet and ensure it's two stream frames from one stream.
1451 // TODO(ianswett): Ideally this would arrive in one frame in the future.
1452 EXPECT_EQ(2u, helper_->frame_count());
1453 EXPECT_EQ(2u, helper_->stream_frames()->size());
1454 EXPECT_EQ(1u, (*helper_->stream_frames())[0].stream_id);
1455 EXPECT_EQ(1u, (*helper_->stream_frames())[1].stream_id);
1456 }
1457
1458 TEST_F(QuicConnectionTest, SendingZeroBytes) {
1459 // Send a zero byte write with a fin using writev.
1460 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, NOT_RETRANSMISSION, _));
1461
1462 iovec iov[1];
1463 connection_.SendvStreamData(1, iov, 0, 0, kFin);
1464
1465 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1466 EXPECT_FALSE(connection_.HasQueuedData());
1467
1468 // Parse the last packet and ensure it's two stream frames from one stream.
1469 // TODO(ianswett): Ideally this would arrive in one frame in the future.
1470 EXPECT_EQ(1u, helper_->frame_count());
1471 EXPECT_EQ(1u, helper_->stream_frames()->size());
1472 EXPECT_EQ(1u, (*helper_->stream_frames())[0].stream_id);
1473 EXPECT_TRUE((*helper_->stream_frames())[0].fin);
1474 }
1475
1365 TEST_F(QuicConnectionTest, OnCanWrite) { 1476 TEST_F(QuicConnectionTest, OnCanWrite) {
1366 // Visitor's OnCanWill send data, but will return false. 1477 // Visitor's OnCanWill send data, but will return false.
1367 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( 1478 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll(
1368 IgnoreResult(InvokeWithoutArgs(&connection_, 1479 IgnoreResult(InvokeWithoutArgs(&connection_,
1369 &TestConnection::SendStreamData3)), 1480 &TestConnection::SendStreamData3)),
1370 IgnoreResult(InvokeWithoutArgs(&connection_, 1481 IgnoreResult(InvokeWithoutArgs(&connection_,
1371 &TestConnection::SendStreamData5)), 1482 &TestConnection::SendStreamData5)),
1372 Return(false))); 1483 Return(false)));
1373 1484
1374 EXPECT_CALL(*send_algorithm_, 1485 EXPECT_CALL(*send_algorithm_,
(...skipping 17 matching lines...) Expand all
1392 QuicPacketSequenceNumber last_packet; 1503 QuicPacketSequenceNumber last_packet;
1393 QuicByteCount second_packet_size; 1504 QuicByteCount second_packet_size;
1394 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 1505 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1
1395 second_packet_size = 1506 second_packet_size =
1396 SendStreamDataToPeer(1, "foos", 3, !kFin, &last_packet); // Packet 2 1507 SendStreamDataToPeer(1, "foos", 3, !kFin, &last_packet); // Packet 2
1397 SendStreamDataToPeer(1, "fooos", 7, !kFin, &last_packet); // Packet 3 1508 SendStreamDataToPeer(1, "fooos", 7, !kFin, &last_packet); // Packet 3
1398 1509
1399 SequenceNumberSet expected_acks; 1510 SequenceNumberSet expected_acks;
1400 expected_acks.insert(1); 1511 expected_acks.insert(1);
1401 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); 1512 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks)));
1513 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1402 1514
1403 // Peer acks one but not two or three. Right now we only retransmit on 1515 // Peer acks one but not two or three. Right now we only retransmit on
1404 // explicit nack, so it should not trigger a retransimission. 1516 // explicit nack, so it should not trigger a retransimission.
1405 QuicAckFrame ack_one(1, QuicTime::Zero(), 0); 1517 QuicAckFrame ack_one(1, QuicTime::Zero(), 0);
1406 ack_one.received_info.entropy_hash = 1518 ack_one.received_info.entropy_hash =
1407 QuicConnectionPeer::GetSentEntropyHash(&connection_, 1); 1519 QuicConnectionPeer::GetSentEntropyHash(&connection_, 1);
1408 ProcessAckPacket(&ack_one, true); 1520 ProcessAckPacket(&ack_one, true);
1409 ProcessAckPacket(&ack_one, true); 1521 ProcessAckPacket(&ack_one, true);
1410 ProcessAckPacket(&ack_one, true); 1522 ProcessAckPacket(&ack_one, true);
1411 1523
1412 expected_acks.clear(); 1524 expected_acks.clear();
1413 expected_acks.insert(3); 1525 expected_acks.insert(3);
1414 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); 1526 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks)));
1415 1527
1416 // Peer acks up to 3 with two explicitly missing. Two nacks should cause no 1528 // Peer acks up to 3 with two explicitly missing. Two nacks should cause no
1417 // change. 1529 // change.
1418 QuicAckFrame nack_two(3, QuicTime::Zero(), 0); 1530 QuicAckFrame nack_two(3, QuicTime::Zero(), 0);
1419 nack_two.received_info.missing_packets.insert(2); 1531 nack_two.received_info.missing_packets.insert(2);
1420 nack_two.received_info.entropy_hash = 1532 nack_two.received_info.entropy_hash =
1421 QuicConnectionPeer::GetSentEntropyHash(&connection_, 3) ^ 1533 QuicConnectionPeer::GetSentEntropyHash(&connection_, 3) ^
1422 QuicConnectionPeer::GetSentEntropyHash(&connection_, 2) ^ 1534 QuicConnectionPeer::GetSentEntropyHash(&connection_, 2) ^
1423 QuicConnectionPeer::GetSentEntropyHash(&connection_, 1); 1535 QuicConnectionPeer::GetSentEntropyHash(&connection_, 1);
1424 ProcessAckPacket(&nack_two, true); 1536 ProcessAckPacket(&nack_two, true);
1425 ProcessAckPacket(&nack_two, true); 1537 ProcessAckPacket(&nack_two, true);
1426 1538
1427 // The third nack should trigger a retransimission. 1539 // The third nack should trigger a retransimission.
1428 EXPECT_CALL(*send_algorithm_, 1540 EXPECT_CALL(*send_algorithm_,
1429 SentPacket(_, _, second_packet_size - kQuicVersionSize, 1541 SentPacket(_, _, second_packet_size - kQuicVersionSize,
1430 IS_RETRANSMISSION)).Times(1); 1542 IS_RETRANSMISSION, _)).Times(1);
1431 ProcessAckPacket(&nack_two, true); 1543 ProcessAckPacket(&nack_two, true);
1432 } 1544 }
1433 1545
1434 TEST_F(QuicConnectionTest, RetransmitNackedLargestObserved) { 1546 TEST_F(QuicConnectionTest, RetransmitNackedLargestObserved) {
1547 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1435 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); 1548 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1);
1436 QuicPacketSequenceNumber largest_observed; 1549 QuicPacketSequenceNumber largest_observed;
1437 QuicByteCount packet_size; 1550 QuicByteCount packet_size;
1438 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, NOT_RETRANSMISSION)) 1551 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, NOT_RETRANSMISSION, _))
1439 .WillOnce(DoAll(SaveArg<1>(&largest_observed), SaveArg<2>(&packet_size))); 1552 .WillOnce(DoAll(SaveArg<1>(&largest_observed), SaveArg<2>(&packet_size),
1553 Return(true)));
1440 EXPECT_CALL(*send_algorithm_, AbandoningPacket(1, _)).Times(1); 1554 EXPECT_CALL(*send_algorithm_, AbandoningPacket(1, _)).Times(1);
1441 connection_.SendStreamData(1, "foo", 0, !kFin); 1555 connection_.SendStreamData(1, "foo", 0, !kFin);
1442 QuicAckFrame frame(1, QuicTime::Zero(), largest_observed); 1556 QuicAckFrame frame(1, QuicTime::Zero(), largest_observed);
1443 frame.received_info.missing_packets.insert(largest_observed); 1557 frame.received_info.missing_packets.insert(largest_observed);
1444 frame.received_info.entropy_hash = QuicConnectionPeer::GetSentEntropyHash( 1558 frame.received_info.entropy_hash = QuicConnectionPeer::GetSentEntropyHash(
1445 &connection_, largest_observed - 1); 1559 &connection_, largest_observed - 1);
1446 ProcessAckPacket(&frame, true); 1560 ProcessAckPacket(&frame, true);
1447 ProcessAckPacket(&frame, true); 1561 ProcessAckPacket(&frame, true);
1448 // Third nack should retransmit the largest observed packet. 1562 // Third nack should retransmit the largest observed packet.
1449 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, packet_size - kQuicVersionSize, 1563 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, packet_size - kQuicVersionSize,
1450 IS_RETRANSMISSION)); 1564 IS_RETRANSMISSION, _));
1451 ProcessAckPacket(&frame, true); 1565 ProcessAckPacket(&frame, true);
1452 } 1566 }
1453 1567
1454 TEST_F(QuicConnectionTest, RetransmitNackedPacketsOnTruncatedAck) { 1568 TEST_F(QuicConnectionTest, RetransmitNackedPacketsOnTruncatedAck) {
1455 for (int i = 0; i < 200; ++i) { 1569 for (int i = 0; i < 200; ++i) {
1456 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).Times(1); 1570 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _)).Times(1);
1457 connection_.SendStreamData(1, "foo", i * 3, !kFin); 1571 connection_.SendStreamData(1, "foo", i * 3, !kFin);
1458 } 1572 }
1459 1573
1460 // Make a truncated ack frame. 1574 // Make a truncated ack frame.
1461 QuicAckFrame frame(0, QuicTime::Zero(), 1); 1575 QuicAckFrame frame(0, QuicTime::Zero(), 1);
1462 frame.received_info.largest_observed = 193; 1576 frame.received_info.largest_observed = 193;
1463 InsertMissingPacketsBetween(&frame.received_info, 1, 193); 1577 InsertMissingPacketsBetween(&frame.received_info, 1, 193);
1464 frame.received_info.entropy_hash = 1578 frame.received_info.entropy_hash =
1465 QuicConnectionPeer::GetSentEntropyHash(&connection_, 193) ^ 1579 QuicConnectionPeer::GetSentEntropyHash(&connection_, 193) ^
1466 QuicConnectionPeer::GetSentEntropyHash(&connection_, 192); 1580 QuicConnectionPeer::GetSentEntropyHash(&connection_, 192);
1467 1581
1468 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1); 1582 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1);
1469 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); 1583 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1);
1470 EXPECT_CALL(visitor_, OnAck(_)).Times(1); 1584 EXPECT_CALL(visitor_, OnAck(_)).Times(1);
1585 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1471 ProcessAckPacket(&frame, true); 1586 ProcessAckPacket(&frame, true);
1472 EXPECT_TRUE(QuicConnectionPeer::GetReceivedTruncatedAck(&connection_)); 1587 EXPECT_TRUE(QuicConnectionPeer::GetReceivedTruncatedAck(&connection_));
1473 1588
1474 QuicConnectionPeer::SetMaxPacketsPerRetransmissionAlarm(&connection_, 200); 1589 QuicConnectionPeer::SetMaxPacketsPerRetransmissionAlarm(&connection_, 200);
1475 clock_.AdvanceTime(DefaultRetransmissionTime()); 1590 clock_.AdvanceTime(DefaultRetransmissionTime());
1476 // Only packets that are less than largest observed should be retransmitted. 1591 // Only packets that are less than largest observed should be retransmitted.
1477 EXPECT_CALL(*send_algorithm_, AbandoningPacket(_, _)).Times(192); 1592 EXPECT_CALL(*send_algorithm_, AbandoningPacket(_, _)).Times(192);
1478 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).Times(192); 1593 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _)).Times(192);
1479 connection_.OnRetransmissionTimeout(); 1594 connection_.OnRetransmissionTimeout();
1480 1595
1481 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds( 1596 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(
1482 2 * DefaultRetransmissionTime().ToMicroseconds())); 1597 2 * DefaultRetransmissionTime().ToMicroseconds()));
1483 // Retransmit already retransmitted packets event though the sequence number 1598 // Retransmit already retransmitted packets event though the sequence number
1484 // greater than the largest observed. 1599 // greater than the largest observed.
1485 EXPECT_CALL(*send_algorithm_, AbandoningPacket(_, _)).Times(192); 1600 EXPECT_CALL(*send_algorithm_, AbandoningPacket(_, _)).Times(192);
1486 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).Times(192); 1601 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _)).Times(192);
1487 connection_.OnRetransmissionTimeout(); 1602 connection_.OnRetransmissionTimeout();
1488 } 1603 }
1489 1604
1490 TEST_F(QuicConnectionTest, LimitPacketsPerNack) { 1605 TEST_F(QuicConnectionTest, LimitPacketsPerNack) {
1606 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1491 EXPECT_CALL(*send_algorithm_, OnIncomingAck(12, _, _)).Times(1); 1607 EXPECT_CALL(*send_algorithm_, OnIncomingAck(12, _, _)).Times(1);
1492 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); 1608 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1);
1493 EXPECT_CALL(*send_algorithm_, AbandoningPacket(_, _)).Times(11); 1609 EXPECT_CALL(*send_algorithm_, AbandoningPacket(_, _)).Times(11);
1494 int offset = 0; 1610 int offset = 0;
1495 // Send packets 1 to 12 1611 // Send packets 1 to 12
1496 for (int i = 0; i < 12; ++i) { 1612 for (int i = 0; i < 12; ++i) {
1497 SendStreamDataToPeer(1, "foo", offset, !kFin, NULL); 1613 SendStreamDataToPeer(1, "foo", offset, !kFin, NULL);
1498 offset += 3; 1614 offset += 3;
1499 } 1615 }
1500 1616
1501 // Ack 12, nack 1-11 1617 // Ack 12, nack 1-11
1502 QuicAckFrame nack(12, QuicTime::Zero(), 0); 1618 QuicAckFrame nack(12, QuicTime::Zero(), 0);
1503 for (int i = 1; i < 12; ++i) { 1619 for (int i = 1; i < 12; ++i) {
1504 nack.received_info.missing_packets.insert(i); 1620 nack.received_info.missing_packets.insert(i);
1505 } 1621 }
1506 1622
1507 nack.received_info.entropy_hash = 1623 nack.received_info.entropy_hash =
1508 QuicConnectionPeer::GetSentEntropyHash(&connection_, 12) ^ 1624 QuicConnectionPeer::GetSentEntropyHash(&connection_, 12) ^
1509 QuicConnectionPeer::GetSentEntropyHash(&connection_, 11); 1625 QuicConnectionPeer::GetSentEntropyHash(&connection_, 11);
1510 SequenceNumberSet expected_acks; 1626 SequenceNumberSet expected_acks;
1511 expected_acks.insert(12); 1627 expected_acks.insert(12);
1512 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); 1628 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks)));
1513 1629
1514 // Nack three times. 1630 // Nack three times.
1515 ProcessAckPacket(&nack, true); 1631 ProcessAckPacket(&nack, true);
1516 ProcessAckPacket(&nack, true); 1632 ProcessAckPacket(&nack, true);
1517 // The third call should trigger retransmitting 10 packets. 1633 // The third call should trigger retransmitting 10 packets.
1518 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).Times(10); 1634 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _)).Times(10);
1519 ProcessAckPacket(&nack, true); 1635 ProcessAckPacket(&nack, true);
1520 1636
1521 // The fourth call should trigger retransmitting the 11th packet. 1637 // The fourth call should trigger retransmitting the 11th packet.
1522 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).Times(1); 1638 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _)).Times(1);
1523 ProcessAckPacket(&nack, true); 1639 ProcessAckPacket(&nack, true);
1524 } 1640 }
1525 1641
1526 // Test sending multiple acks from the connection to the session. 1642 // Test sending multiple acks from the connection to the session.
1527 TEST_F(QuicConnectionTest, MultipleAcks) { 1643 TEST_F(QuicConnectionTest, MultipleAcks) {
1528 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(6); 1644 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(6);
1529 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); 1645 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1);
1530 QuicPacketSequenceNumber last_packet; 1646 QuicPacketSequenceNumber last_packet;
1531 SendStreamDataToPeer(1u, "foo", 0, !kFin, &last_packet); // Packet 1 1647 SendStreamDataToPeer(1u, "foo", 0, !kFin, &last_packet); // Packet 1
1532 EXPECT_EQ(1u, last_packet); 1648 EXPECT_EQ(1u, last_packet);
(...skipping 16 matching lines...) Expand all
1549 QuicConnectionPeer::GetSentEntropyHash(&connection_, 1); 1665 QuicConnectionPeer::GetSentEntropyHash(&connection_, 1);
1550 1666
1551 // The connection should pass up acks for 1, 4, 5. 2 is not acked, and 3 was 1667 // The connection should pass up acks for 1, 4, 5. 2 is not acked, and 3 was
1552 // an ackframe so should not be passed up. 1668 // an ackframe so should not be passed up.
1553 SequenceNumberSet expected_acks; 1669 SequenceNumberSet expected_acks;
1554 expected_acks.insert(1); 1670 expected_acks.insert(1);
1555 expected_acks.insert(4); 1671 expected_acks.insert(4);
1556 expected_acks.insert(5); 1672 expected_acks.insert(5);
1557 1673
1558 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); 1674 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks)));
1675 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1676
1559 ProcessAckPacket(&frame1, true); 1677 ProcessAckPacket(&frame1, true);
1560 1678
1561 // Now the client implicitly acks 2, and explicitly acks 6 1679 // Now the client implicitly acks 2, and explicitly acks 6
1562 QuicAckFrame frame2(6, QuicTime::Zero(), 0); 1680 QuicAckFrame frame2(6, QuicTime::Zero(), 0);
1563 frame2.received_info.entropy_hash = 1681 frame2.received_info.entropy_hash =
1564 QuicConnectionPeer::GetSentEntropyHash(&connection_, 6); 1682 QuicConnectionPeer::GetSentEntropyHash(&connection_, 6);
1565 expected_acks.clear(); 1683 expected_acks.clear();
1566 // Both acks should be passed up. 1684 // Both acks should be passed up.
1567 expected_acks.insert(2); 1685 expected_acks.insert(2);
1568 expected_acks.insert(6); 1686 expected_acks.insert(6);
1569 1687
1570 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); 1688 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks)));
1571 ProcessAckPacket(&frame2, true); 1689 ProcessAckPacket(&frame2, true);
1572 } 1690 }
1573 1691
1574 TEST_F(QuicConnectionTest, DontLatchUnackedPacket) { 1692 TEST_F(QuicConnectionTest, DontLatchUnackedPacket) {
1575 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1); 1693 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1);
1576 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); // Packet 1; 1694 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); // Packet 1;
1577 SendAckPacketToPeer(); // Packet 2 1695 SendAckPacketToPeer(); // Packet 2
1578 1696
1579 // This sets least unacked to 3 (unsent packet), since we don't need 1697 // This sets least unacked to 3 (unsent packet), since we don't need
1580 // an ack for Packet 2 (ack packet). 1698 // an ack for Packet 2 (ack packet).
1581 SequenceNumberSet expected_acks; 1699 SequenceNumberSet expected_acks;
1582 expected_acks.insert(1); 1700 expected_acks.insert(1);
1583 // Peer acks packet 1. 1701 // Peer acks packet 1.
1584 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); 1702 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks)));
1703 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1585 QuicAckFrame frame(1, QuicTime::Zero(), 0); 1704 QuicAckFrame frame(1, QuicTime::Zero(), 0);
1586 frame.received_info.entropy_hash = QuicConnectionPeer::GetSentEntropyHash( 1705 frame.received_info.entropy_hash = QuicConnectionPeer::GetSentEntropyHash(
1587 &connection_, 1); 1706 &connection_, 1);
1588 ProcessAckPacket(&frame, true); 1707 ProcessAckPacket(&frame, true);
1589 1708
1590 // Verify that our internal state has least-unacked as 3. 1709 // Verify that our internal state has least-unacked as 3.
1591 EXPECT_EQ(3u, outgoing_ack()->sent_info.least_unacked); 1710 EXPECT_EQ(3u, outgoing_ack()->sent_info.least_unacked);
1592 1711
1593 // When we send an ack, we make sure our least-unacked makes sense. In this 1712 // When we send an ack, we make sure our least-unacked makes sense. In this
1594 // case since we're not waiting on an ack for 2 and all packets are acked, we 1713 // case since we're not waiting on an ack for 2 and all packets are acked, we
1595 // set it to 3. 1714 // set it to 3.
1596 SendAckPacketToPeer(); // Packet 3 1715 SendAckPacketToPeer(); // Packet 3
1597 // Since this was an ack packet, we set least_unacked to 4. 1716 // Since this was an ack packet, we set least_unacked to 4.
1598 EXPECT_EQ(4u, outgoing_ack()->sent_info.least_unacked); 1717 EXPECT_EQ(4u, outgoing_ack()->sent_info.least_unacked);
1599 // Check that the outgoing ack had its sequence number as least_unacked. 1718 // Check that the outgoing ack had its sequence number as least_unacked.
1600 EXPECT_EQ(3u, last_ack()->sent_info.least_unacked); 1719 EXPECT_EQ(3u, last_ack()->sent_info.least_unacked);
1601 1720
1602 SendStreamDataToPeer(1, "bar", 3, false, NULL); // Packet 4 1721 SendStreamDataToPeer(1, "bar", 3, false, NULL); // Packet 4
1603 EXPECT_EQ(4u, outgoing_ack()->sent_info.least_unacked); 1722 EXPECT_EQ(4u, outgoing_ack()->sent_info.least_unacked);
1604 SendAckPacketToPeer(); // Packet 5 1723 SendAckPacketToPeer(); // Packet 5
1605 EXPECT_EQ(4u, last_ack()->sent_info.least_unacked); 1724 EXPECT_EQ(4u, last_ack()->sent_info.least_unacked);
1606 } 1725 }
1607 1726
1608 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterFecPacket) { 1727 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterFecPacket) {
1728 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1729
1609 // Don't send missing packet 1. 1730 // Don't send missing packet 1.
1610 ProcessFecPacket(2, 1, true, !kEntropyFlag, NULL); 1731 ProcessFecPacket(2, 1, true, !kEntropyFlag, NULL);
1611 EXPECT_FALSE(revived_header_.entropy_flag); 1732 EXPECT_FALSE(revived_header_.entropy_flag);
1612 } 1733 }
1613 1734
1614 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPacketThenFecPacket) { 1735 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPacketThenFecPacket) {
1736 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1737
1615 ProcessFecProtectedPacket(1, false, kEntropyFlag); 1738 ProcessFecProtectedPacket(1, false, kEntropyFlag);
1616 // Don't send missing packet 2. 1739 // Don't send missing packet 2.
1617 ProcessFecPacket(3, 1, true, !kEntropyFlag, NULL); 1740 ProcessFecPacket(3, 1, true, !kEntropyFlag, NULL);
1618 EXPECT_TRUE(revived_header_.entropy_flag); 1741 EXPECT_TRUE(revived_header_.entropy_flag);
1619 } 1742 }
1620 1743
1621 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPacketsThenFecPacket) { 1744 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPacketsThenFecPacket) {
1745 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1746
1622 ProcessFecProtectedPacket(1, false, !kEntropyFlag); 1747 ProcessFecProtectedPacket(1, false, !kEntropyFlag);
1623 // Don't send missing packet 2. 1748 // Don't send missing packet 2.
1624 ProcessFecProtectedPacket(3, false, !kEntropyFlag); 1749 ProcessFecProtectedPacket(3, false, !kEntropyFlag);
1625 ProcessFecPacket(4, 1, true, kEntropyFlag, NULL); 1750 ProcessFecPacket(4, 1, true, kEntropyFlag, NULL);
1626 EXPECT_TRUE(revived_header_.entropy_flag); 1751 EXPECT_TRUE(revived_header_.entropy_flag);
1627 } 1752 }
1628 1753
1629 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPacket) { 1754 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPacket) {
1755 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1756
1630 // Don't send missing packet 1. 1757 // Don't send missing packet 1.
1631 ProcessFecPacket(3, 1, false, !kEntropyFlag, NULL); 1758 ProcessFecPacket(3, 1, false, !kEntropyFlag, NULL);
1632 // out of order 1759 // out of order
1633 ProcessFecProtectedPacket(2, true, !kEntropyFlag); 1760 ProcessFecProtectedPacket(2, true, !kEntropyFlag);
1634 EXPECT_FALSE(revived_header_.entropy_flag); 1761 EXPECT_FALSE(revived_header_.entropy_flag);
1635 } 1762 }
1636 1763
1637 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPackets) { 1764 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPackets) {
1765 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1766
1638 ProcessFecProtectedPacket(1, false, !kEntropyFlag); 1767 ProcessFecProtectedPacket(1, false, !kEntropyFlag);
1639 // Don't send missing packet 2. 1768 // Don't send missing packet 2.
1640 ProcessFecPacket(6, 1, false, kEntropyFlag, NULL); 1769 ProcessFecPacket(6, 1, false, kEntropyFlag, NULL);
1641 ProcessFecProtectedPacket(3, false, kEntropyFlag); 1770 ProcessFecProtectedPacket(3, false, kEntropyFlag);
1642 ProcessFecProtectedPacket(4, false, kEntropyFlag); 1771 ProcessFecProtectedPacket(4, false, kEntropyFlag);
1643 ProcessFecProtectedPacket(5, true, !kEntropyFlag); 1772 ProcessFecProtectedPacket(5, true, !kEntropyFlag);
1644 EXPECT_TRUE(revived_header_.entropy_flag); 1773 EXPECT_TRUE(revived_header_.entropy_flag);
1645 } 1774 }
1646 1775
1647 TEST_F(QuicConnectionTest, TestRetransmit) { 1776 TEST_F(QuicConnectionTest, TestRetransmit) {
1648 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( 1777 QuicTime default_retransmission_time = clock_.ApproximateNow().Add(
1649 DefaultRetransmissionTime()); 1778 DefaultRetransmissionTime());
1650 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); 1779 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL);
1651 EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked); 1780 EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked);
1652 1781
1653 EXPECT_EQ(1u, last_header()->packet_sequence_number); 1782 EXPECT_EQ(1u, last_header()->packet_sequence_number);
1654 EXPECT_EQ(default_retransmission_time, 1783 EXPECT_EQ(default_retransmission_time,
1655 connection_.GetRetransmissionAlarm()->deadline()); 1784 connection_.GetRetransmissionAlarm()->deadline());
1656 // Simulate the retransimission alarm firing 1785 // Simulate the retransimission alarm firing
1657 clock_.AdvanceTime(DefaultRetransmissionTime()); 1786 clock_.AdvanceTime(DefaultRetransmissionTime());
1658 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)); 1787 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _));
1659 EXPECT_CALL(*send_algorithm_, AbandoningPacket(1, _)).Times(1); 1788 EXPECT_CALL(*send_algorithm_, AbandoningPacket(1, _)).Times(1);
1660 connection_.RetransmitPacket(1); 1789 connection_.RetransmitPacket(1);
1661 EXPECT_EQ(2u, last_header()->packet_sequence_number); 1790 EXPECT_EQ(2u, last_header()->packet_sequence_number);
1662 EXPECT_EQ(2u, outgoing_ack()->sent_info.least_unacked); 1791 EXPECT_EQ(2u, outgoing_ack()->sent_info.least_unacked);
1663 } 1792 }
1664 1793
1665 TEST_F(QuicConnectionTest, RetransmitWithSameEncryptionLevel) { 1794 TEST_F(QuicConnectionTest, RetransmitWithSameEncryptionLevel) {
1666 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( 1795 QuicTime default_retransmission_time = clock_.ApproximateNow().Add(
1667 DefaultRetransmissionTime()); 1796 DefaultRetransmissionTime());
1668 use_tagging_decrypter(); 1797 use_tagging_decrypter();
1669 1798
1670 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at 1799 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at
1671 // the end of the packet. We can test this to check which encrypter was used. 1800 // the end of the packet. We can test this to check which encrypter was used.
1672 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); 1801 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01));
1673 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); 1802 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL);
1674 EXPECT_EQ(0x01010101u, final_bytes_of_last_packet()); 1803 EXPECT_EQ(0x01010101u, final_bytes_of_last_packet());
1675 1804
1676 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); 1805 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02));
1677 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); 1806 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
1678 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); 1807 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL);
1679 EXPECT_EQ(0x02020202u, final_bytes_of_last_packet()); 1808 EXPECT_EQ(0x02020202u, final_bytes_of_last_packet());
1680 1809
1681 EXPECT_EQ(default_retransmission_time, 1810 EXPECT_EQ(default_retransmission_time,
1682 connection_.GetRetransmissionAlarm()->deadline()); 1811 connection_.GetRetransmissionAlarm()->deadline());
1683 // Simulate the retransimission alarm firing 1812 // Simulate the retransimission alarm firing
1684 clock_.AdvanceTime(DefaultRetransmissionTime()); 1813 clock_.AdvanceTime(DefaultRetransmissionTime());
1685 EXPECT_CALL(*send_algorithm_, AbandoningPacket(_, _)).Times(2); 1814 EXPECT_CALL(*send_algorithm_, AbandoningPacket(_, _)).Times(2);
1686 1815
1687 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)); 1816 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _));
1688 connection_.RetransmitPacket(1); 1817 connection_.RetransmitPacket(1);
1689 // Packet should have been sent with ENCRYPTION_NONE. 1818 // Packet should have been sent with ENCRYPTION_NONE.
1690 EXPECT_EQ(0x01010101u, final_bytes_of_last_packet()); 1819 EXPECT_EQ(0x01010101u, final_bytes_of_last_packet());
1691 1820
1692 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)); 1821 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _));
1693 connection_.RetransmitPacket(2); 1822 connection_.RetransmitPacket(2);
1694 // Packet should have been sent with ENCRYPTION_INITIAL. 1823 // Packet should have been sent with ENCRYPTION_INITIAL.
1695 EXPECT_EQ(0x02020202u, final_bytes_of_last_packet()); 1824 EXPECT_EQ(0x02020202u, final_bytes_of_last_packet());
1696 } 1825 }
1697 1826
1698 TEST_F(QuicConnectionTest, 1827 TEST_F(QuicConnectionTest,
1699 DropRetransmitsForNullEncryptedPacketAfterForwardSecure) { 1828 DropRetransmitsForNullEncryptedPacketAfterForwardSecure) {
1700 use_tagging_decrypter(); 1829 use_tagging_decrypter();
1701 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); 1830 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01));
1702 QuicPacketSequenceNumber sequence_number; 1831 QuicPacketSequenceNumber sequence_number;
1703 SendStreamDataToPeer(1, "foo", 0, !kFin, &sequence_number); 1832 SendStreamDataToPeer(1, "foo", 0, !kFin, &sequence_number);
1704 1833
1705 connection_.SetEncrypter(ENCRYPTION_FORWARD_SECURE, 1834 connection_.SetEncrypter(ENCRYPTION_FORWARD_SECURE,
1706 new TaggingEncrypter(0x02)); 1835 new TaggingEncrypter(0x02));
1707 connection_.SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); 1836 connection_.SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE);
1708 1837
1709 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).Times(0); 1838 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _)).Times(0);
1710 EXPECT_CALL(*send_algorithm_, AbandoningPacket(sequence_number, _)).Times(1); 1839 EXPECT_CALL(*send_algorithm_, AbandoningPacket(sequence_number, _)).Times(1);
1711 1840
1712 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( 1841 QuicTime default_retransmission_time = clock_.ApproximateNow().Add(
1713 DefaultRetransmissionTime()); 1842 DefaultRetransmissionTime());
1714 1843
1715 EXPECT_EQ(default_retransmission_time, 1844 EXPECT_EQ(default_retransmission_time,
1716 connection_.GetRetransmissionAlarm()->deadline()); 1845 connection_.GetRetransmissionAlarm()->deadline());
1717 // Simulate the retransimission alarm firing 1846 // Simulate the retransimission alarm firing
1718 clock_.AdvanceTime(DefaultRetransmissionTime()); 1847 clock_.AdvanceTime(DefaultRetransmissionTime());
1719 connection_.OnRetransmissionTimeout(); 1848 connection_.OnRetransmissionTimeout();
1720 } 1849 }
1721 1850
1722 TEST_F(QuicConnectionTest, RetransmitPacketsWithInitialEncryption) { 1851 TEST_F(QuicConnectionTest, RetransmitPacketsWithInitialEncryption) {
1723 use_tagging_decrypter(); 1852 use_tagging_decrypter();
1724 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); 1853 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01));
1725 connection_.SetDefaultEncryptionLevel(ENCRYPTION_NONE); 1854 connection_.SetDefaultEncryptionLevel(ENCRYPTION_NONE);
1726 1855
1727 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); 1856 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL);
1728 1857
1729 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); 1858 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02));
1730 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); 1859 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
1731 1860
1732 SendStreamDataToPeer(2, "bar", 0, !kFin, NULL); 1861 SendStreamDataToPeer(2, "bar", 0, !kFin, NULL);
1733 1862
1734 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).Times(1); 1863 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _)).Times(1);
1735 EXPECT_CALL(*send_algorithm_, AbandoningPacket(_, _)).Times(1); 1864 EXPECT_CALL(*send_algorithm_, AbandoningPacket(_, _)).Times(1);
1736 1865
1737 connection_.RetransmitUnackedPackets(QuicConnection::INITIAL_ENCRYPTION_ONLY); 1866 connection_.RetransmitUnackedPackets(QuicConnection::INITIAL_ENCRYPTION_ONLY);
1738 } 1867 }
1739 1868
1740 TEST_F(QuicConnectionTest, BufferNonDecryptablePackets) { 1869 TEST_F(QuicConnectionTest, BufferNonDecryptablePackets) {
1870 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1741 use_tagging_decrypter(); 1871 use_tagging_decrypter();
1742 1872
1743 const uint8 tag = 0x07; 1873 const uint8 tag = 0x07;
1744 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); 1874 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
1745 1875
1746 // Process an encrypted packet which can not yet be decrypted 1876 // Process an encrypted packet which can not yet be decrypted
1747 // which should result in the packet being buffered. 1877 // which should result in the packet being buffered.
1748 ProcessDataPacketAtLevel(1, false, kEntropyFlag, ENCRYPTION_INITIAL); 1878 ProcessDataPacketAtLevel(1, false, kEntropyFlag, ENCRYPTION_INITIAL);
1749 1879
1750 // Transition to the new encryption state and process another 1880 // Transition to the new encryption state and process another
1751 // encrypted packet which should result in the original packet being 1881 // encrypted packet which should result in the original packet being
1752 // processed. 1882 // processed.
1753 connection_.SetDecrypter(new StrictTaggingDecrypter(tag)); 1883 connection_.SetDecrypter(new StrictTaggingDecrypter(tag));
1754 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); 1884 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
1755 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); 1885 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
1756 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).Times(2).WillRepeatedly( 1886 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).Times(2).WillRepeatedly(
1757 Return(true)); 1887 Return(true));
1758 ProcessDataPacketAtLevel(2, false, kEntropyFlag, ENCRYPTION_INITIAL); 1888 ProcessDataPacketAtLevel(2, false, kEntropyFlag, ENCRYPTION_INITIAL);
1759 1889
1760 // Finally, process a third packet and note that we do not 1890 // Finally, process a third packet and note that we do not
1761 // reprocess the buffered packet. 1891 // reprocess the buffered packet.
1762 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillOnce(Return(true)); 1892 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillOnce(Return(true));
1763 ProcessDataPacketAtLevel(3, false, kEntropyFlag, ENCRYPTION_INITIAL); 1893 ProcessDataPacketAtLevel(3, false, kEntropyFlag, ENCRYPTION_INITIAL);
1764 } 1894 }
1765 1895
1766 TEST_F(QuicConnectionTest, TestRetransmitOrder) { 1896 TEST_F(QuicConnectionTest, TestRetransmitOrder) {
1767 QuicByteCount first_packet_size; 1897 QuicByteCount first_packet_size;
1768 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).WillOnce( 1898 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _)).WillOnce(
1769 SaveArg<2>(&first_packet_size)); 1899 DoAll(SaveArg<2>(&first_packet_size), Return(true)));
1770 EXPECT_CALL(*send_algorithm_, AbandoningPacket(_, _)).Times(2); 1900 EXPECT_CALL(*send_algorithm_, AbandoningPacket(_, _)).Times(2);
1771 1901
1772 connection_.SendStreamData(1, "first_packet", 0, !kFin); 1902 connection_.SendStreamData(1, "first_packet", 0, !kFin);
1773 QuicByteCount second_packet_size; 1903 QuicByteCount second_packet_size;
1774 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).WillOnce( 1904 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _)).WillOnce(
1775 SaveArg<2>(&second_packet_size)); 1905 DoAll(SaveArg<2>(&second_packet_size), Return(true)));
1776 connection_.SendStreamData(1, "second_packet", 12, !kFin); 1906 connection_.SendStreamData(1, "second_packet", 12, !kFin);
1777 EXPECT_NE(first_packet_size, second_packet_size); 1907 EXPECT_NE(first_packet_size, second_packet_size);
1778 // Advance the clock by huge time to make sure packets will be retransmitted. 1908 // Advance the clock by huge time to make sure packets will be retransmitted.
1779 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10)); 1909 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10));
1780 { 1910 {
1781 InSequence s; 1911 InSequence s;
1782 EXPECT_CALL(*send_algorithm_, 1912 EXPECT_CALL(*send_algorithm_,
1783 SentPacket(_, _, first_packet_size, _)); 1913 SentPacket(_, _, first_packet_size, _, _));
1784 EXPECT_CALL(*send_algorithm_, 1914 EXPECT_CALL(*send_algorithm_,
1785 SentPacket(_, _, second_packet_size, _)); 1915 SentPacket(_, _, second_packet_size, _, _));
1786 } 1916 }
1787 connection_.OnRetransmissionTimeout(); 1917 connection_.OnRetransmissionTimeout();
1788 } 1918 }
1789 1919
1790 TEST_F(QuicConnectionTest, TestRetransmissionCountCalculation) { 1920 TEST_F(QuicConnectionTest, TestRetransmissionCountCalculation) {
1921 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1791 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); 1922 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1);
1792 EXPECT_CALL(*send_algorithm_, AbandoningPacket(_, _)).Times(2); 1923 EXPECT_CALL(*send_algorithm_, AbandoningPacket(_, _)).Times(2);
1793 QuicPacketSequenceNumber original_sequence_number; 1924 QuicPacketSequenceNumber original_sequence_number;
1794 EXPECT_CALL(*send_algorithm_, 1925 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, NOT_RETRANSMISSION, _))
1795 SentPacket(_, _, _, NOT_RETRANSMISSION)) 1926 .WillOnce(DoAll(SaveArg<1>(&original_sequence_number), Return(true)));
1796 .WillOnce(SaveArg<1>(&original_sequence_number));
1797 connection_.SendStreamData(1, "foo", 0, !kFin); 1927 connection_.SendStreamData(1, "foo", 0, !kFin);
1798 EXPECT_TRUE(QuicConnectionPeer::IsSavedForRetransmission( 1928 EXPECT_TRUE(QuicConnectionPeer::IsSavedForRetransmission(
1799 &connection_, original_sequence_number)); 1929 &connection_, original_sequence_number));
1800 EXPECT_EQ(0u, QuicConnectionPeer::GetRetransmissionCount( 1930 EXPECT_EQ(0u, QuicConnectionPeer::GetRetransmissionCount(
1801 &connection_, original_sequence_number)); 1931 &connection_, original_sequence_number));
1802 // Force retransmission due to RTO. 1932 // Force retransmission due to RTO.
1803 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10)); 1933 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10));
1804 QuicPacketSequenceNumber rto_sequence_number; 1934 QuicPacketSequenceNumber rto_sequence_number;
1805 EXPECT_CALL(*send_algorithm_, 1935 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, IS_RETRANSMISSION, _))
1806 SentPacket(_, _, _, IS_RETRANSMISSION)) 1936 .WillOnce(DoAll(SaveArg<1>(&rto_sequence_number), Return(true)));
1807 .WillOnce(SaveArg<1>(&rto_sequence_number));
1808 connection_.OnRetransmissionTimeout(); 1937 connection_.OnRetransmissionTimeout();
1809 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission( 1938 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission(
1810 &connection_, original_sequence_number)); 1939 &connection_, original_sequence_number));
1811 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission( 1940 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission(
1812 &connection_, rto_sequence_number)); 1941 &connection_, rto_sequence_number));
1813 EXPECT_EQ(1u, QuicConnectionPeer::GetRetransmissionCount( 1942 EXPECT_EQ(1u, QuicConnectionPeer::GetRetransmissionCount(
1814 &connection_, rto_sequence_number)); 1943 &connection_, rto_sequence_number));
1815 // Once by explicit nack. 1944 // Once by explicit nack.
1816 QuicPacketSequenceNumber nack_sequence_number; 1945 QuicPacketSequenceNumber nack_sequence_number;
1817 // Ack packets might generate some other packets, which are not 1946 // Ack packets might generate some other packets, which are not
1818 // retransmissions. (More ack packets). 1947 // retransmissions. (More ack packets).
1819 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, NOT_RETRANSMISSION)) 1948 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, NOT_RETRANSMISSION, _))
1820 .Times(AnyNumber()); 1949 .Times(AnyNumber());
1821 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, IS_RETRANSMISSION)) 1950 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, IS_RETRANSMISSION, _))
1822 .WillOnce(SaveArg<1>(&nack_sequence_number)); 1951 .WillOnce(DoAll(SaveArg<1>(&nack_sequence_number), Return(true)));
1823 QuicAckFrame ack(rto_sequence_number, QuicTime::Zero(), 0); 1952 QuicAckFrame ack(rto_sequence_number, QuicTime::Zero(), 0);
1824 // Ack the retransmitted packet. 1953 // Ack the retransmitted packet.
1825 ack.received_info.missing_packets.insert(rto_sequence_number); 1954 ack.received_info.missing_packets.insert(rto_sequence_number);
1826 ack.received_info.entropy_hash = QuicConnectionPeer::GetSentEntropyHash( 1955 ack.received_info.entropy_hash = QuicConnectionPeer::GetSentEntropyHash(
1827 &connection_, rto_sequence_number - 1); 1956 &connection_, rto_sequence_number - 1);
1828 for (int i = 0; i < 3; i++) { 1957 for (int i = 0; i < 3; i++) {
1829 ProcessAckPacket(&ack, true); 1958 ProcessAckPacket(&ack, true);
1830 } 1959 }
1831 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission( 1960 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission(
1832 &connection_, rto_sequence_number)); 1961 &connection_, rto_sequence_number));
(...skipping 28 matching lines...) Expand all
1861 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 1990 EXPECT_EQ(1u, connection_.NumQueuedPackets());
1862 1991
1863 // Unblock the writes and actually send. 1992 // Unblock the writes and actually send.
1864 helper_->set_blocked(false); 1993 helper_->set_blocked(false);
1865 EXPECT_CALL(visitor_, OnCanWrite()); 1994 EXPECT_CALL(visitor_, OnCanWrite());
1866 EXPECT_TRUE(connection_.OnCanWrite()); 1995 EXPECT_TRUE(connection_.OnCanWrite());
1867 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1996 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1868 } 1997 }
1869 1998
1870 TEST_F(QuicConnectionTest, CloseFecGroup) { 1999 TEST_F(QuicConnectionTest, CloseFecGroup) {
2000 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1871 // Don't send missing packet 1 2001 // Don't send missing packet 1
1872 // Don't send missing packet 2 2002 // Don't send missing packet 2
1873 ProcessFecProtectedPacket(3, false, !kEntropyFlag); 2003 ProcessFecProtectedPacket(3, false, !kEntropyFlag);
1874 // Don't send missing FEC packet 3 2004 // Don't send missing FEC packet 3
1875 ASSERT_EQ(1u, connection_.NumFecGroups()); 2005 ASSERT_EQ(1u, connection_.NumFecGroups());
1876 2006
1877 // Now send non-fec protected ack packet and close the group 2007 // Now send non-fec protected ack packet and close the group
1878 QuicAckFrame frame(0, QuicTime::Zero(), 5); 2008 QuicAckFrame frame(0, QuicTime::Zero(), 5);
1879 creator_.set_sequence_number(4); 2009 creator_.set_sequence_number(4);
1880 ProcessAckPacket(&frame, true); 2010 ProcessAckPacket(&frame, true);
(...skipping 12 matching lines...) Expand all
1893 SetFeedback(&info); 2023 SetFeedback(&info);
1894 2024
1895 SendAckPacketToPeer(); 2025 SendAckPacketToPeer();
1896 EXPECT_EQ(kFixRate, last_feedback()->type); 2026 EXPECT_EQ(kFixRate, last_feedback()->type);
1897 EXPECT_EQ(info.fix_rate.bitrate, last_feedback()->fix_rate.bitrate); 2027 EXPECT_EQ(info.fix_rate.bitrate, last_feedback()->fix_rate.bitrate);
1898 } 2028 }
1899 2029
1900 TEST_F(QuicConnectionTest, UpdateQuicCongestionFeedbackFrame) { 2030 TEST_F(QuicConnectionTest, UpdateQuicCongestionFeedbackFrame) {
1901 SendAckPacketToPeer(); 2031 SendAckPacketToPeer();
1902 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _, _)); 2032 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _, _));
2033 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1903 ProcessPacket(1); 2034 ProcessPacket(1);
1904 } 2035 }
1905 2036
1906 TEST_F(QuicConnectionTest, DontUpdateQuicCongestionFeedbackFrameForRevived) { 2037 TEST_F(QuicConnectionTest, DontUpdateQuicCongestionFeedbackFrameForRevived) {
2038 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1907 SendAckPacketToPeer(); 2039 SendAckPacketToPeer();
1908 // Process an FEC packet, and revive the missing data packet 2040 // Process an FEC packet, and revive the missing data packet
1909 // but only contact the receive_algorithm once. 2041 // but only contact the receive_algorithm once.
1910 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _, _)); 2042 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _, _));
1911 ProcessFecPacket(2, 1, true, !kEntropyFlag, NULL); 2043 ProcessFecPacket(2, 1, true, !kEntropyFlag, NULL);
1912 } 2044 }
1913 2045
1914 TEST_F(QuicConnectionTest, InitialTimeout) { 2046 TEST_F(QuicConnectionTest, InitialTimeout) {
1915 EXPECT_TRUE(connection_.connected()); 2047 EXPECT_TRUE(connection_.connected());
1916 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, false)); 2048 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, false));
1917 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)); 2049 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _));
1918 2050
1919 QuicTime default_timeout = clock_.ApproximateNow().Add( 2051 QuicTime default_timeout = clock_.ApproximateNow().Add(
1920 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)); 2052 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs));
1921 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); 2053 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
1922 2054
1923 // Simulate the timeout alarm firing 2055 // Simulate the timeout alarm firing
1924 clock_.AdvanceTime( 2056 clock_.AdvanceTime(
1925 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)); 2057 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs));
1926 EXPECT_TRUE(connection_.CheckForTimeout()); 2058 EXPECT_TRUE(connection_.CheckForTimeout());
1927 EXPECT_FALSE(connection_.connected()); 2059 EXPECT_FALSE(connection_.connected());
(...skipping 18 matching lines...) Expand all
1946 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds( 2078 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(
1947 kDefaultInitialTimeoutSecs * 1000000 - 5000)); 2079 kDefaultInitialTimeoutSecs * 1000000 - 5000));
1948 EXPECT_EQ(default_timeout, clock_.ApproximateNow()); 2080 EXPECT_EQ(default_timeout, clock_.ApproximateNow());
1949 EXPECT_FALSE(connection_.CheckForTimeout()); 2081 EXPECT_FALSE(connection_.CheckForTimeout());
1950 EXPECT_TRUE(connection_.connected()); 2082 EXPECT_TRUE(connection_.connected());
1951 EXPECT_EQ(default_timeout.Add(QuicTime::Delta::FromMilliseconds(5)), 2083 EXPECT_EQ(default_timeout.Add(QuicTime::Delta::FromMilliseconds(5)),
1952 connection_.GetTimeoutAlarm()->deadline()); 2084 connection_.GetTimeoutAlarm()->deadline());
1953 2085
1954 // This time, we should time out. 2086 // This time, we should time out.
1955 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, false)); 2087 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, false));
1956 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)); 2088 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _));
1957 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); 2089 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5));
1958 EXPECT_EQ(default_timeout.Add(QuicTime::Delta::FromMilliseconds(5)), 2090 EXPECT_EQ(default_timeout.Add(QuicTime::Delta::FromMilliseconds(5)),
1959 clock_.ApproximateNow()); 2091 clock_.ApproximateNow());
1960 EXPECT_TRUE(connection_.CheckForTimeout()); 2092 EXPECT_TRUE(connection_.CheckForTimeout());
1961 EXPECT_FALSE(connection_.connected()); 2093 EXPECT_FALSE(connection_.connected());
1962 } 2094 }
1963 2095
1964 // TODO(ianswett): Add scheduler tests when should_retransmit is false. 2096 // TODO(ianswett): Add scheduler tests when should_retransmit is false.
1965 TEST_F(QuicConnectionTest, SendScheduler) { 2097 TEST_F(QuicConnectionTest, SendScheduler) {
1966 // Test that if we send a packet without delay, it is not queued. 2098 // Test that if we send a packet without delay, it is not queued.
1967 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); 2099 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag);
1968 EXPECT_CALL(*send_algorithm_, 2100 EXPECT_CALL(*send_algorithm_,
1969 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( 2101 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce(
1970 testing::Return(QuicTime::Delta::Zero())); 2102 testing::Return(QuicTime::Delta::Zero()));
1971 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)); 2103 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _));
1972 connection_.SendOrQueuePacket( 2104 connection_.SendOrQueuePacket(
1973 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); 2105 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA);
1974 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2106 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1975 } 2107 }
1976 2108
1977 TEST_F(QuicConnectionTest, SendSchedulerDelay) { 2109 TEST_F(QuicConnectionTest, SendSchedulerDelay) {
1978 // Test that if we send a packet with a delay, it ends up queued. 2110 // Test that if we send a packet with a delay, it ends up queued.
1979 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); 2111 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag);
1980 EXPECT_CALL(*send_algorithm_, 2112 EXPECT_CALL(*send_algorithm_,
1981 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( 2113 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce(
1982 testing::Return(QuicTime::Delta::FromMicroseconds(1))); 2114 testing::Return(QuicTime::Delta::FromMicroseconds(1)));
1983 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, _)).Times(0); 2115 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, _, _)).Times(0);
1984 connection_.SendOrQueuePacket( 2116 connection_.SendOrQueuePacket(
1985 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); 2117 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA);
1986 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2118 EXPECT_EQ(1u, connection_.NumQueuedPackets());
1987 } 2119 }
1988 2120
1989 TEST_F(QuicConnectionTest, SendSchedulerForce) { 2121 TEST_F(QuicConnectionTest, SendSchedulerForce) {
1990 // Test that if we force send a packet, it is not queued. 2122 // Test that if we force send a packet, it is not queued.
1991 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); 2123 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag);
1992 EXPECT_CALL(*send_algorithm_, 2124 EXPECT_CALL(*send_algorithm_,
1993 TimeUntilSend(_, IS_RETRANSMISSION, _, _)).Times(0); 2125 TimeUntilSend(_, IS_RETRANSMISSION, _, _)).Times(0);
1994 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)); 2126 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _));
1995 connection_.SendOrQueuePacket( 2127 connection_.SendOrQueuePacket(
1996 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); 2128 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA);
1997 // XXX: fixme. was: connection_.SendOrQueuePacket(1, packet, kForce); 2129 // XXX: fixme. was: connection_.SendOrQueuePacket(1, packet, kForce);
1998 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2130 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1999 } 2131 }
2000 2132
2001 TEST_F(QuicConnectionTest, SendSchedulerEAGAIN) { 2133 TEST_F(QuicConnectionTest, SendSchedulerEAGAIN) {
2002 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); 2134 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag);
2003 helper_->set_blocked(true); 2135 helper_->set_blocked(true);
2004 EXPECT_CALL(*send_algorithm_, 2136 EXPECT_CALL(*send_algorithm_,
2005 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( 2137 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce(
2006 testing::Return(QuicTime::Delta::Zero())); 2138 testing::Return(QuicTime::Delta::Zero()));
2007 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, _)).Times(0); 2139 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, _, _)).Times(0);
2008 connection_.SendOrQueuePacket( 2140 connection_.SendOrQueuePacket(
2009 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); 2141 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA);
2010 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2142 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2011 } 2143 }
2012 2144
2013 TEST_F(QuicConnectionTest, SendSchedulerDelayThenSend) { 2145 TEST_F(QuicConnectionTest, SendSchedulerDelayThenSend) {
2014 // Test that if we send a packet with a delay, it ends up queued. 2146 // Test that if we send a packet with a delay, it ends up queued.
2015 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); 2147 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag);
2016 EXPECT_CALL(*send_algorithm_, 2148 EXPECT_CALL(*send_algorithm_,
2017 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( 2149 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce(
2018 testing::Return(QuicTime::Delta::FromMicroseconds(1))); 2150 testing::Return(QuicTime::Delta::FromMicroseconds(1)));
2019 connection_.SendOrQueuePacket( 2151 connection_.SendOrQueuePacket(
2020 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); 2152 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA);
2021 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2153 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2022 2154
2023 // Advance the clock to fire the alarm, and configure the scheduler 2155 // Advance the clock to fire the alarm, and configure the scheduler
2024 // to permit the packet to be sent. 2156 // to permit the packet to be sent.
2025 EXPECT_CALL(*send_algorithm_, 2157 EXPECT_CALL(*send_algorithm_,
2026 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillRepeatedly( 2158 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillRepeatedly(
2027 testing::Return(QuicTime::Delta::Zero())); 2159 testing::Return(QuicTime::Delta::Zero()));
2028 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1)); 2160 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1));
2029 connection_.GetSendAlarm()->Cancel(); 2161 connection_.GetSendAlarm()->Cancel();
2030 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)); 2162 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _));
2031 EXPECT_CALL(visitor_, OnCanWrite()); 2163 EXPECT_CALL(visitor_, OnCanWrite());
2032 connection_.OnCanWrite(); 2164 connection_.OnCanWrite();
2033 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2165 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2034 } 2166 }
2035 2167
2036 TEST_F(QuicConnectionTest, SendSchedulerDelayThenRetransmit) { 2168 TEST_F(QuicConnectionTest, SendSchedulerDelayThenRetransmit) {
2037 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, NOT_RETRANSMISSION, _, _)) 2169 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, NOT_RETRANSMISSION, _, _))
2038 .WillRepeatedly(testing::Return(QuicTime::Delta::Zero())); 2170 .WillRepeatedly(testing::Return(QuicTime::Delta::Zero()));
2039 EXPECT_CALL(*send_algorithm_, AbandoningPacket(1, _)).Times(1); 2171 EXPECT_CALL(*send_algorithm_, AbandoningPacket(1, _)).Times(1);
2040 EXPECT_CALL(*send_algorithm_, 2172 EXPECT_CALL(*send_algorithm_,
2041 SentPacket(_, 1, _, NOT_RETRANSMISSION)); 2173 SentPacket(_, 1, _, NOT_RETRANSMISSION, _));
2042 connection_.SendStreamData(1, "foo", 0, !kFin); 2174 connection_.SendStreamData(1, "foo", 0, !kFin);
2043 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2175 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2044 // Advance the time for retransmission of lost packet. 2176 // Advance the time for retransmission of lost packet.
2045 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(501)); 2177 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(501));
2046 // Test that if we send a retransmit with a delay, it ends up queued. 2178 // Test that if we send a retransmit with a delay, it ends up queued.
2047 EXPECT_CALL(*send_algorithm_, 2179 EXPECT_CALL(*send_algorithm_,
2048 TimeUntilSend(_, IS_RETRANSMISSION, _, _)).WillOnce( 2180 TimeUntilSend(_, IS_RETRANSMISSION, _, _)).WillOnce(
2049 testing::Return(QuicTime::Delta::FromMicroseconds(1))); 2181 testing::Return(QuicTime::Delta::FromMicroseconds(1)));
2050 connection_.OnRetransmissionTimeout(); 2182 connection_.OnRetransmissionTimeout();
2051 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2183 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2052 2184
2053 // Advance the clock to fire the alarm, and configure the scheduler 2185 // Advance the clock to fire the alarm, and configure the scheduler
2054 // to permit the packet to be sent. 2186 // to permit the packet to be sent.
2055 EXPECT_CALL(*send_algorithm_, 2187 EXPECT_CALL(*send_algorithm_,
2056 TimeUntilSend(_, IS_RETRANSMISSION, _, _)).WillOnce( 2188 TimeUntilSend(_, IS_RETRANSMISSION, _, _)).WillOnce(
2057 testing::Return(QuicTime::Delta::Zero())); 2189 testing::Return(QuicTime::Delta::Zero()));
2058 2190
2059 // Ensure the scheduler is notified this is a retransmit. 2191 // Ensure the scheduler is notified this is a retransmit.
2060 EXPECT_CALL(*send_algorithm_, 2192 EXPECT_CALL(*send_algorithm_,
2061 SentPacket(_, _, _, IS_RETRANSMISSION)); 2193 SentPacket(_, _, _, IS_RETRANSMISSION, _));
2062 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1)); 2194 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1));
2063 connection_.GetSendAlarm()->Cancel(); 2195 connection_.GetSendAlarm()->Cancel();
2064 EXPECT_CALL(visitor_, OnCanWrite()); 2196 EXPECT_CALL(visitor_, OnCanWrite());
2065 connection_.OnCanWrite(); 2197 connection_.OnCanWrite();
2066 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2198 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2067 } 2199 }
2068 2200
2069 TEST_F(QuicConnectionTest, SendSchedulerDelayAndQueue) { 2201 TEST_F(QuicConnectionTest, SendSchedulerDelayAndQueue) {
2070 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); 2202 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag);
2071 EXPECT_CALL(*send_algorithm_, 2203 EXPECT_CALL(*send_algorithm_,
2072 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( 2204 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce(
2073 testing::Return(QuicTime::Delta::FromMicroseconds(1))); 2205 testing::Return(QuicTime::Delta::FromMicroseconds(1)));
2074 connection_.SendOrQueuePacket( 2206 connection_.SendOrQueuePacket(
2075 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); 2207 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA);
2076 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2208 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2077 2209
2078 // Attempt to send another packet and make sure that it gets queued. 2210 // Attempt to send another packet and make sure that it gets queued.
2079 packet = ConstructDataPacket(2, 0, !kEntropyFlag); 2211 packet = ConstructDataPacket(2, 0, !kEntropyFlag);
2080 connection_.SendOrQueuePacket( 2212 connection_.SendOrQueuePacket(
2081 ENCRYPTION_NONE, 2, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); 2213 ENCRYPTION_NONE, 2, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA);
2082 EXPECT_EQ(2u, connection_.NumQueuedPackets()); 2214 EXPECT_EQ(2u, connection_.NumQueuedPackets());
2083 } 2215 }
2084 2216
2085 TEST_F(QuicConnectionTest, SendSchedulerDelayThenAckAndSend) { 2217 TEST_F(QuicConnectionTest, SendSchedulerDelayThenAckAndSend) {
2218 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2086 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); 2219 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag);
2087 EXPECT_CALL(*send_algorithm_, 2220 EXPECT_CALL(*send_algorithm_,
2088 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( 2221 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce(
2089 testing::Return(QuicTime::Delta::FromMicroseconds(10))); 2222 testing::Return(QuicTime::Delta::FromMicroseconds(10)));
2090 connection_.SendOrQueuePacket( 2223 connection_.SendOrQueuePacket(
2091 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); 2224 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA);
2092 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2225 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2093 2226
2094 // Now send non-retransmitting information, that we're not going to 2227 // Now send non-retransmitting information, that we're not going to
2095 // retransmit 3. The far end should stop waiting for it. 2228 // retransmit 3. The far end should stop waiting for it.
2096 QuicAckFrame frame(0, QuicTime::Zero(), 1); 2229 QuicAckFrame frame(0, QuicTime::Zero(), 1);
2097 EXPECT_CALL(*send_algorithm_, 2230 EXPECT_CALL(*send_algorithm_,
2098 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillRepeatedly( 2231 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillRepeatedly(
2099 testing::Return(QuicTime::Delta::Zero())); 2232 testing::Return(QuicTime::Delta::Zero()));
2100 EXPECT_CALL(*send_algorithm_, 2233 EXPECT_CALL(*send_algorithm_,
2101 SentPacket(_, _, _, _)); 2234 SentPacket(_, _, _, _, _));
2102 ProcessAckPacket(&frame, true); 2235 ProcessAckPacket(&frame, true);
2103 2236
2104 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2237 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2105 // Ensure alarm is not set 2238 // Ensure alarm is not set
2106 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet()); 2239 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet());
2107 } 2240 }
2108 2241
2109 TEST_F(QuicConnectionTest, SendSchedulerDelayThenAckAndHold) { 2242 TEST_F(QuicConnectionTest, SendSchedulerDelayThenAckAndHold) {
2243 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2110 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); 2244 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag);
2111 EXPECT_CALL(*send_algorithm_, 2245 EXPECT_CALL(*send_algorithm_,
2112 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( 2246 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce(
2113 testing::Return(QuicTime::Delta::FromMicroseconds(10))); 2247 testing::Return(QuicTime::Delta::FromMicroseconds(10)));
2114 connection_.SendOrQueuePacket( 2248 connection_.SendOrQueuePacket(
2115 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); 2249 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA);
2116 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2250 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2117 2251
2118 // Now send non-retransmitting information, that we're not going to 2252 // Now send non-retransmitting information, that we're not going to
2119 // retransmit 3. The far end should stop waiting for it. 2253 // retransmit 3. The far end should stop waiting for it.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2161 2295
2162 TEST_F(QuicConnectionTest, LoopThroughSendingPackets) { 2296 TEST_F(QuicConnectionTest, LoopThroughSendingPackets) {
2163 // All packets carry version info till version is negotiated. 2297 // All packets carry version info till version is negotiated.
2164 size_t payload_length; 2298 size_t payload_length;
2165 connection_.options()->max_packet_length = 2299 connection_.options()->max_packet_length =
2166 GetPacketLengthForOneStream( 2300 GetPacketLengthForOneStream(
2167 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, 2301 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER,
2168 NOT_IN_FEC_GROUP, &payload_length); 2302 NOT_IN_FEC_GROUP, &payload_length);
2169 2303
2170 // Queue the first packet. 2304 // Queue the first packet.
2171 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).Times(7); 2305 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _)).Times(7);
2172 // The first stream frame will consume 2 fewer bytes than the other six. 2306 // The first stream frame will consume 2 fewer bytes than the other six.
2173 const string payload(payload_length * 7 - 12, 'a'); 2307 const string payload(payload_length * 7 - 12, 'a');
2174 EXPECT_EQ(payload.size(), 2308 EXPECT_EQ(payload.size(),
2175 connection_.SendStreamData(1, payload, 0, !kFin).bytes_consumed); 2309 connection_.SendStreamData(1, payload, 0, !kFin).bytes_consumed);
2176 } 2310 }
2177 2311
2178 TEST_F(QuicConnectionTest, NoAckForClose) { 2312 TEST_F(QuicConnectionTest, NoAckForClose) {
2313 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2179 ProcessPacket(1); 2314 ProcessPacket(1);
2180 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(0); 2315 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(0);
2181 EXPECT_CALL(visitor_, ConnectionClose(QUIC_PEER_GOING_AWAY, true)); 2316 EXPECT_CALL(visitor_, ConnectionClose(QUIC_PEER_GOING_AWAY, true));
2182 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).Times(0); 2317 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _)).Times(0);
2183 ProcessClosePacket(2, 0); 2318 ProcessClosePacket(2, 0);
2184 } 2319 }
2185 2320
2186 TEST_F(QuicConnectionTest, SendWhenDisconnected) { 2321 TEST_F(QuicConnectionTest, SendWhenDisconnected) {
2187 EXPECT_TRUE(connection_.connected()); 2322 EXPECT_TRUE(connection_.connected());
2188 EXPECT_CALL(visitor_, ConnectionClose(QUIC_PEER_GOING_AWAY, false)); 2323 EXPECT_CALL(visitor_, ConnectionClose(QUIC_PEER_GOING_AWAY, false));
2189 connection_.CloseConnection(QUIC_PEER_GOING_AWAY, false); 2324 connection_.CloseConnection(QUIC_PEER_GOING_AWAY, false);
2190 EXPECT_FALSE(connection_.connected()); 2325 EXPECT_FALSE(connection_.connected());
2191 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); 2326 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag);
2192 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, _)).Times(0); 2327 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, _, _)).Times(0);
2193 connection_.SendOrQueuePacket( 2328 connection_.SendOrQueuePacket(
2194 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); 2329 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA);
2195 } 2330 }
2196 2331
2197 TEST_F(QuicConnectionTest, PublicReset) { 2332 TEST_F(QuicConnectionTest, PublicReset) {
2198 QuicPublicResetPacket header; 2333 QuicPublicResetPacket header;
2199 header.public_header.guid = guid_; 2334 header.public_header.guid = guid_;
2200 header.public_header.reset_flag = true; 2335 header.public_header.reset_flag = true;
2201 header.public_header.version_flag = false; 2336 header.public_header.version_flag = false;
2202 header.rejected_sequence_number = 10101; 2337 header.rejected_sequence_number = 10101;
2203 scoped_ptr<QuicEncryptedPacket> packet( 2338 scoped_ptr<QuicEncryptedPacket> packet(
2204 framer_.BuildPublicResetPacket(header)); 2339 framer_.BuildPublicResetPacket(header));
2205 EXPECT_CALL(visitor_, ConnectionClose(QUIC_PUBLIC_RESET, true)); 2340 EXPECT_CALL(visitor_, ConnectionClose(QUIC_PUBLIC_RESET, true));
2206 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *packet); 2341 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *packet);
2207 } 2342 }
2208 2343
2209 TEST_F(QuicConnectionTest, GoAway) { 2344 TEST_F(QuicConnectionTest, GoAway) {
2345 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2346
2210 QuicGoAwayFrame goaway; 2347 QuicGoAwayFrame goaway;
2211 goaway.last_good_stream_id = 1; 2348 goaway.last_good_stream_id = 1;
2212 goaway.error_code = QUIC_PEER_GOING_AWAY; 2349 goaway.error_code = QUIC_PEER_GOING_AWAY;
2213 goaway.reason_phrase = "Going away."; 2350 goaway.reason_phrase = "Going away.";
2214 EXPECT_CALL(visitor_, OnGoAway(_)); 2351 EXPECT_CALL(visitor_, OnGoAway(_));
2215 ProcessGoAwayPacket(&goaway); 2352 ProcessGoAwayPacket(&goaway);
2216 } 2353 }
2217 2354
2218 TEST_F(QuicConnectionTest, MissingPacketsBeforeLeastUnacked) { 2355 TEST_F(QuicConnectionTest, MissingPacketsBeforeLeastUnacked) {
2219 QuicAckFrame ack(0, QuicTime::Zero(), 4); 2356 QuicAckFrame ack(0, QuicTime::Zero(), 4);
2220 // Set the sequence number of the ack packet to be least unacked (4) 2357 // Set the sequence number of the ack packet to be least unacked (4)
2221 creator_.set_sequence_number(3); 2358 creator_.set_sequence_number(3);
2359 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2222 ProcessAckPacket(&ack, true); 2360 ProcessAckPacket(&ack, true);
2223 EXPECT_TRUE(outgoing_ack()->received_info.missing_packets.empty()); 2361 EXPECT_TRUE(outgoing_ack()->received_info.missing_packets.empty());
2224 } 2362 }
2225 2363
2226 TEST_F(QuicConnectionTest, ReceivedEntropyHashCalculation) { 2364 TEST_F(QuicConnectionTest, ReceivedEntropyHashCalculation) {
2227 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillRepeatedly(Return(true)); 2365 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillRepeatedly(Return(true));
2366 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2228 ProcessDataPacket(1, 1, kEntropyFlag); 2367 ProcessDataPacket(1, 1, kEntropyFlag);
2229 ProcessDataPacket(4, 1, kEntropyFlag); 2368 ProcessDataPacket(4, 1, kEntropyFlag);
2230 ProcessDataPacket(3, 1, !kEntropyFlag); 2369 ProcessDataPacket(3, 1, !kEntropyFlag);
2231 ProcessDataPacket(7, 1, kEntropyFlag); 2370 ProcessDataPacket(7, 1, kEntropyFlag);
2232 EXPECT_EQ(146u, outgoing_ack()->received_info.entropy_hash); 2371 EXPECT_EQ(146u, outgoing_ack()->received_info.entropy_hash);
2233 } 2372 }
2234 2373
2235 TEST_F(QuicConnectionTest, UpdateEntropyForReceivedPackets) { 2374 TEST_F(QuicConnectionTest, UpdateEntropyForReceivedPackets) {
2236 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillRepeatedly(Return(true)); 2375 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillRepeatedly(Return(true));
2376 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2237 ProcessDataPacket(1, 1, kEntropyFlag); 2377 ProcessDataPacket(1, 1, kEntropyFlag);
2238 ProcessDataPacket(5, 1, kEntropyFlag); 2378 ProcessDataPacket(5, 1, kEntropyFlag);
2239 ProcessDataPacket(4, 1, !kEntropyFlag); 2379 ProcessDataPacket(4, 1, !kEntropyFlag);
2240 EXPECT_EQ(34u, outgoing_ack()->received_info.entropy_hash); 2380 EXPECT_EQ(34u, outgoing_ack()->received_info.entropy_hash);
2241 // Make 4th packet my least unacked, and update entropy for 2, 3 packets. 2381 // Make 4th packet my least unacked, and update entropy for 2, 3 packets.
2242 QuicAckFrame ack(0, QuicTime::Zero(), 4); 2382 QuicAckFrame ack(0, QuicTime::Zero(), 4);
2243 QuicPacketEntropyHash kRandomEntropyHash = 129u; 2383 QuicPacketEntropyHash kRandomEntropyHash = 129u;
2244 ack.sent_info.entropy_hash = kRandomEntropyHash; 2384 ack.sent_info.entropy_hash = kRandomEntropyHash;
2245 creator_.set_sequence_number(5); 2385 creator_.set_sequence_number(5);
2246 QuicPacketEntropyHash six_packet_entropy_hash = 0; 2386 QuicPacketEntropyHash six_packet_entropy_hash = 0;
2247 if (ProcessAckPacket(&ack, true)) { 2387 if (ProcessAckPacket(&ack, true)) {
2248 six_packet_entropy_hash = 1 << 6; 2388 six_packet_entropy_hash = 1 << 6;
2249 } 2389 }
2250 2390
2251 EXPECT_EQ((kRandomEntropyHash + (1 << 5) + six_packet_entropy_hash), 2391 EXPECT_EQ((kRandomEntropyHash + (1 << 5) + six_packet_entropy_hash),
2252 outgoing_ack()->received_info.entropy_hash); 2392 outgoing_ack()->received_info.entropy_hash);
2253 } 2393 }
2254 2394
2255 TEST_F(QuicConnectionTest, UpdateEntropyHashUptoCurrentPacket) { 2395 TEST_F(QuicConnectionTest, UpdateEntropyHashUptoCurrentPacket) {
2256 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillRepeatedly(Return(true)); 2396 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillRepeatedly(Return(true));
2397 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2257 ProcessDataPacket(1, 1, kEntropyFlag); 2398 ProcessDataPacket(1, 1, kEntropyFlag);
2258 ProcessDataPacket(5, 1, !kEntropyFlag); 2399 ProcessDataPacket(5, 1, !kEntropyFlag);
2259 ProcessDataPacket(22, 1, kEntropyFlag); 2400 ProcessDataPacket(22, 1, kEntropyFlag);
2260 EXPECT_EQ(66u, outgoing_ack()->received_info.entropy_hash); 2401 EXPECT_EQ(66u, outgoing_ack()->received_info.entropy_hash);
2261 creator_.set_sequence_number(22); 2402 creator_.set_sequence_number(22);
2262 QuicPacketEntropyHash kRandomEntropyHash = 85u; 2403 QuicPacketEntropyHash kRandomEntropyHash = 85u;
2263 // Current packet is the least unacked packet. 2404 // Current packet is the least unacked packet.
2264 QuicAckFrame ack(0, QuicTime::Zero(), 23); 2405 QuicAckFrame ack(0, QuicTime::Zero(), 23);
2265 ack.sent_info.entropy_hash = kRandomEntropyHash; 2406 ack.sent_info.entropy_hash = kRandomEntropyHash;
2266 QuicPacketEntropyHash ack_entropy_hash = ProcessAckPacket(&ack, true); 2407 QuicPacketEntropyHash ack_entropy_hash = ProcessAckPacket(&ack, true);
2267 EXPECT_EQ((kRandomEntropyHash + ack_entropy_hash), 2408 EXPECT_EQ((kRandomEntropyHash + ack_entropy_hash),
2268 outgoing_ack()->received_info.entropy_hash); 2409 outgoing_ack()->received_info.entropy_hash);
2269 ProcessDataPacket(25, 1, kEntropyFlag); 2410 ProcessDataPacket(25, 1, kEntropyFlag);
2270 EXPECT_EQ((kRandomEntropyHash + ack_entropy_hash + (1 << (25 % 8))), 2411 EXPECT_EQ((kRandomEntropyHash + ack_entropy_hash + (1 << (25 % 8))),
2271 outgoing_ack()->received_info.entropy_hash); 2412 outgoing_ack()->received_info.entropy_hash);
2272 } 2413 }
2273 2414
2274 TEST_F(QuicConnectionTest, EntropyCalculationForTruncatedAck) { 2415 TEST_F(QuicConnectionTest, EntropyCalculationForTruncatedAck) {
2275 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillRepeatedly(Return(true)); 2416 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillRepeatedly(Return(true));
2417 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2276 QuicPacketEntropyHash entropy[51]; 2418 QuicPacketEntropyHash entropy[51];
2277 entropy[0] = 0; 2419 entropy[0] = 0;
2278 for (int i = 1; i < 51; ++i) { 2420 for (int i = 1; i < 51; ++i) {
2279 bool should_send = i % 10 != 0; 2421 bool should_send = i % 10 != 0;
2280 bool entropy_flag = (i & (i - 1)) != 0; 2422 bool entropy_flag = (i & (i - 1)) != 0;
2281 if (!should_send) { 2423 if (!should_send) {
2282 entropy[i] = entropy[i - 1]; 2424 entropy[i] = entropy[i - 1];
2283 continue; 2425 continue;
2284 } 2426 }
2285 if (entropy_flag) { 2427 if (entropy_flag) {
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
2390 // Now force another packet. The connection should transition into 2532 // Now force another packet. The connection should transition into
2391 // NEGOTIATED_VERSION state and tell the packet creator to StopSendingVersion. 2533 // NEGOTIATED_VERSION state and tell the packet creator to StopSendingVersion.
2392 header.public_header.version_flag = false; 2534 header.public_header.version_flag = false;
2393 QuicFrames frames; 2535 QuicFrames frames;
2394 QuicFrame frame(&frame1_); 2536 QuicFrame frame(&frame1_);
2395 frames.push_back(frame); 2537 frames.push_back(frame);
2396 scoped_ptr<QuicPacket> packet( 2538 scoped_ptr<QuicPacket> packet(
2397 framer_.BuildUnsizedDataPacket(header, frames).packet); 2539 framer_.BuildUnsizedDataPacket(header, frames).packet);
2398 encrypted.reset(framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); 2540 encrypted.reset(framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet));
2399 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).Times(1); 2541 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).Times(1);
2542 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2400 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); 2543 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted);
2401 2544
2402 ASSERT_FALSE(QuicPacketCreatorPeer::SendVersionInPacket( 2545 ASSERT_FALSE(QuicPacketCreatorPeer::SendVersionInPacket(
2403 QuicConnectionPeer::GetPacketCreator(&connection_))); 2546 QuicConnectionPeer::GetPacketCreator(&connection_)));
2404 } 2547 }
2405 2548
2406 TEST_F(QuicConnectionTest, BadVersionNegotiation) { 2549 TEST_F(QuicConnectionTest, BadVersionNegotiation) {
2407 QuicPacketHeader header; 2550 QuicPacketHeader header;
2408 header.public_header.guid = guid_; 2551 header.public_header.guid = guid_;
2409 header.public_header.reset_flag = false; 2552 header.public_header.reset_flag = false;
(...skipping 14 matching lines...) Expand all
2424 false)); 2567 false));
2425 scoped_ptr<QuicEncryptedPacket> encrypted( 2568 scoped_ptr<QuicEncryptedPacket> encrypted(
2426 framer_.BuildVersionNegotiationPacket( 2569 framer_.BuildVersionNegotiationPacket(
2427 header.public_header, supported_versions)); 2570 header.public_header, supported_versions));
2428 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); 2571 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted);
2429 } 2572 }
2430 2573
2431 TEST_F(QuicConnectionTest, CheckSendStats) { 2574 TEST_F(QuicConnectionTest, CheckSendStats) {
2432 EXPECT_CALL(*send_algorithm_, AbandoningPacket(_, _)).Times(3); 2575 EXPECT_CALL(*send_algorithm_, AbandoningPacket(_, _)).Times(3);
2433 EXPECT_CALL(*send_algorithm_, 2576 EXPECT_CALL(*send_algorithm_,
2434 SentPacket(_, _, _, NOT_RETRANSMISSION)); 2577 SentPacket(_, _, _, NOT_RETRANSMISSION, _));
2435 connection_.SendStreamData(1u, "first", 0, !kFin); 2578 connection_.SendStreamData(1u, "first", 0, !kFin);
2436 size_t first_packet_size = last_sent_packet_size(); 2579 size_t first_packet_size = last_sent_packet_size();
2437 2580
2438 EXPECT_CALL(*send_algorithm_, 2581 EXPECT_CALL(*send_algorithm_,
2439 SentPacket(_, _, _, NOT_RETRANSMISSION)); 2582 SentPacket(_, _, _, NOT_RETRANSMISSION, _));
2440 connection_.SendStreamData(1u, "second", 0, !kFin); 2583 connection_.SendStreamData(1u, "second", 0, !kFin);
2441 size_t second_packet_size = last_sent_packet_size(); 2584 size_t second_packet_size = last_sent_packet_size();
2442 2585
2443 // 2 retransmissions due to rto, 1 due to explicit nack. 2586 // 2 retransmissions due to rto, 1 due to explicit nack.
2444 EXPECT_CALL(*send_algorithm_, 2587 EXPECT_CALL(*send_algorithm_,
2445 SentPacket(_, _, _, IS_RETRANSMISSION)).Times(3); 2588 SentPacket(_, _, _, IS_RETRANSMISSION, _)).Times(3);
2446 2589
2447 // Retransmit due to RTO. 2590 // Retransmit due to RTO.
2448 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10)); 2591 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10));
2449 connection_.OnRetransmissionTimeout(); 2592 connection_.OnRetransmissionTimeout();
2450 2593
2451 // Retransmit due to explicit nacks 2594 // Retransmit due to explicit nacks
2452 QuicAckFrame nack_three(4, QuicTime::Zero(), 0); 2595 QuicAckFrame nack_three(4, QuicTime::Zero(), 0);
2453 nack_three.received_info.missing_packets.insert(3); 2596 nack_three.received_info.missing_packets.insert(3);
2454 nack_three.received_info.entropy_hash = 2597 nack_three.received_info.entropy_hash =
2455 QuicConnectionPeer::GetSentEntropyHash(&connection_, 4) ^ 2598 QuicConnectionPeer::GetSentEntropyHash(&connection_, 4) ^
2456 QuicConnectionPeer::GetSentEntropyHash(&connection_, 3) ^ 2599 QuicConnectionPeer::GetSentEntropyHash(&connection_, 3) ^
2457 QuicConnectionPeer::GetSentEntropyHash(&connection_, 2); 2600 QuicConnectionPeer::GetSentEntropyHash(&connection_, 2);
2458 QuicFrame frame(&nack_three); 2601 QuicFrame frame(&nack_three);
2459 EXPECT_CALL(visitor_, OnAck(_)); 2602 EXPECT_CALL(visitor_, OnAck(_));
2460 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1); 2603 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1);
2461 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); 2604 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1);
2462 EXPECT_CALL(visitor_, OnCanWrite()).Times(3).WillRepeatedly(Return(true)); 2605 EXPECT_CALL(visitor_, OnCanWrite()).Times(3).WillRepeatedly(Return(true));
2606 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2463 2607
2464 ProcessFramePacket(frame); 2608 ProcessFramePacket(frame);
2465 ProcessFramePacket(frame); 2609 ProcessFramePacket(frame);
2466 ProcessFramePacket(frame); 2610 ProcessFramePacket(frame);
2467 2611
2468 EXPECT_CALL(*send_algorithm_, SmoothedRtt()).WillOnce( 2612 EXPECT_CALL(*send_algorithm_, SmoothedRtt()).WillOnce(
2469 Return(QuicTime::Delta::Zero())); 2613 Return(QuicTime::Delta::Zero()));
2470 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillOnce( 2614 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillOnce(
2471 Return(QuicBandwidth::Zero())); 2615 Return(QuicBandwidth::Zero()));
2472 2616
2473 const QuicConnectionStats& stats = connection_.GetStats(); 2617 const QuicConnectionStats& stats = connection_.GetStats();
2474 EXPECT_EQ(3 * first_packet_size + 2 * second_packet_size - kQuicVersionSize, 2618 EXPECT_EQ(3 * first_packet_size + 2 * second_packet_size - kQuicVersionSize,
2475 stats.bytes_sent); 2619 stats.bytes_sent);
2476 EXPECT_EQ(5u, stats.packets_sent); 2620 EXPECT_EQ(5u, stats.packets_sent);
2477 EXPECT_EQ(2 * first_packet_size + second_packet_size - kQuicVersionSize, 2621 EXPECT_EQ(2 * first_packet_size + second_packet_size - kQuicVersionSize,
2478 stats.bytes_retransmitted); 2622 stats.bytes_retransmitted);
2479 EXPECT_EQ(3u, stats.packets_retransmitted); 2623 EXPECT_EQ(3u, stats.packets_retransmitted);
2480 EXPECT_EQ(2u, stats.rto_count); 2624 EXPECT_EQ(2u, stats.rto_count);
2481 } 2625 }
2482 2626
2483 TEST_F(QuicConnectionTest, CheckReceiveStats) { 2627 TEST_F(QuicConnectionTest, CheckReceiveStats) {
2628 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2629
2484 size_t received_bytes = 0; 2630 size_t received_bytes = 0;
2485 received_bytes += ProcessFecProtectedPacket(1, false, !kEntropyFlag); 2631 received_bytes += ProcessFecProtectedPacket(1, false, !kEntropyFlag);
2486 received_bytes += ProcessFecProtectedPacket(3, false, !kEntropyFlag); 2632 received_bytes += ProcessFecProtectedPacket(3, false, !kEntropyFlag);
2487 // Should be counted against dropped packets. 2633 // Should be counted against dropped packets.
2488 received_bytes += ProcessDataPacket(3, 1, !kEntropyFlag); 2634 received_bytes += ProcessDataPacket(3, 1, !kEntropyFlag);
2489 received_bytes += ProcessFecPacket(4, 1, true, !kEntropyFlag, NULL); 2635 received_bytes += ProcessFecPacket(4, 1, true, !kEntropyFlag, NULL);
2490 2636
2491 EXPECT_CALL(*send_algorithm_, SmoothedRtt()).WillOnce( 2637 EXPECT_CALL(*send_algorithm_, SmoothedRtt()).WillOnce(
2492 Return(QuicTime::Delta::Zero())); 2638 Return(QuicTime::Delta::Zero()));
2493 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillOnce( 2639 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillOnce(
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
2543 frames.push_back(stream_frame); 2689 frames.push_back(stream_frame);
2544 frames.push_back(close_frame); 2690 frames.push_back(close_frame);
2545 scoped_ptr<QuicPacket> packet( 2691 scoped_ptr<QuicPacket> packet(
2546 framer_.BuildUnsizedDataPacket(header_, frames).packet); 2692 framer_.BuildUnsizedDataPacket(header_, frames).packet);
2547 EXPECT_TRUE(NULL != packet.get()); 2693 EXPECT_TRUE(NULL != packet.get());
2548 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPacket( 2694 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPacket(
2549 ENCRYPTION_NONE, 1, *packet)); 2695 ENCRYPTION_NONE, 1, *packet));
2550 2696
2551 EXPECT_CALL(visitor_, ConnectionClose(QUIC_PEER_GOING_AWAY, true)); 2697 EXPECT_CALL(visitor_, ConnectionClose(QUIC_PEER_GOING_AWAY, true));
2552 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).Times(0); 2698 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).Times(0);
2699 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2553 2700
2554 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); 2701 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted);
2555 } 2702 }
2556 2703
2557 TEST_F(QuicConnectionTest, SelectMutualVersion) { 2704 TEST_F(QuicConnectionTest, SelectMutualVersion) {
2558 // Set the connection to speak the lowest quic version. 2705 // Set the connection to speak the lowest quic version.
2559 connection_.set_version(QuicVersionMin()); 2706 connection_.set_version(QuicVersionMin());
2560 EXPECT_EQ(QuicVersionMin(), connection_.version()); 2707 EXPECT_EQ(QuicVersionMin(), connection_.version());
2561 2708
2562 // Pass in available versions which includes a higher mutually supported 2709 // Pass in available versions which includes a higher mutually supported
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2615 TEST_F(QuicConnectionTest, ConnectionCloseWhenNothingPending) { 2762 TEST_F(QuicConnectionTest, ConnectionCloseWhenNothingPending) {
2616 helper_->set_blocked(true); 2763 helper_->set_blocked(true);
2617 2764
2618 // Send an erroneous packet to close the connection. 2765 // Send an erroneous packet to close the connection.
2619 EXPECT_CALL(visitor_, ConnectionClose(QUIC_INVALID_PACKET_HEADER, false)); 2766 EXPECT_CALL(visitor_, ConnectionClose(QUIC_INVALID_PACKET_HEADER, false));
2620 ProcessDataPacket(6000, 0, !kEntropyFlag); 2767 ProcessDataPacket(6000, 0, !kEntropyFlag);
2621 EXPECT_EQ(1u, helper_->packets_write_attempts()); 2768 EXPECT_EQ(1u, helper_->packets_write_attempts());
2622 } 2769 }
2623 2770
2624 TEST_F(QuicConnectionTest, AckNotifierTriggerCallback) { 2771 TEST_F(QuicConnectionTest, AckNotifierTriggerCallback) {
2772 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2773
2625 // Create a delegate which we expect to be called. 2774 // Create a delegate which we expect to be called.
2626 MockAckNotifierDelegate delegate; 2775 MockAckNotifierDelegate delegate;
2627 EXPECT_CALL(delegate, OnAckNotification()).Times(1);; 2776 EXPECT_CALL(delegate, OnAckNotification()).Times(1);;
2628 2777
2629 // Send some data, which will register the delegate to be notified. 2778 // Send some data, which will register the delegate to be notified.
2630 connection_.SendStreamDataAndNotifyWhenAcked(1, "foo", 0, !kFin, &delegate); 2779 connection_.SendStreamDataAndNotifyWhenAcked(1, "foo", 0, !kFin, &delegate);
2631 2780
2632 // Process an ACK from the server which should trigger the callback. 2781 // Process an ACK from the server which should trigger the callback.
2633 EXPECT_CALL(visitor_, OnAck(_)).Times(1); 2782 EXPECT_CALL(visitor_, OnAck(_)).Times(1);
2634 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1); 2783 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1);
2635 QuicAckFrame frame(1, QuicTime::Zero(), 0); 2784 QuicAckFrame frame(1, QuicTime::Zero(), 0);
2636 ProcessAckPacket(&frame, true); 2785 ProcessAckPacket(&frame, true);
2637 } 2786 }
2638 2787
2639 TEST_F(QuicConnectionTest, AckNotifierFailToTriggerCallback) { 2788 TEST_F(QuicConnectionTest, AckNotifierFailToTriggerCallback) {
2789 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2790
2640 // Create a delegate which we don't expect to be called. 2791 // Create a delegate which we don't expect to be called.
2641 MockAckNotifierDelegate delegate; 2792 MockAckNotifierDelegate delegate;
2642 EXPECT_CALL(delegate, OnAckNotification()).Times(0);; 2793 EXPECT_CALL(delegate, OnAckNotification()).Times(0);;
2643 2794
2644 EXPECT_CALL(visitor_, OnAck(_)).Times(1); 2795 EXPECT_CALL(visitor_, OnAck(_)).Times(1);
2645 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(2); 2796 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(2);
2646 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); 2797 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1);
2647 2798
2648 // Send some data, which will register the delegate to be notified. This will 2799 // Send some data, which will register the delegate to be notified. This will
2649 // not be ACKed and so the delegate should never be called. 2800 // not be ACKed and so the delegate should never be called.
2650 connection_.SendStreamDataAndNotifyWhenAcked(1, "foo", 0, !kFin, &delegate); 2801 connection_.SendStreamDataAndNotifyWhenAcked(1, "foo", 0, !kFin, &delegate);
2651 2802
2652 // Send some other data which we will ACK. 2803 // Send some other data which we will ACK.
2653 connection_.SendStreamData(1, "foo", 0, !kFin); 2804 connection_.SendStreamData(1, "foo", 0, !kFin);
2654 connection_.SendStreamData(1, "bar", 0, !kFin); 2805 connection_.SendStreamData(1, "bar", 0, !kFin);
2655 2806
2656 // Now we receive ACK for packets 2 and 3, but importantly missing packet 1 2807 // Now we receive ACK for packets 2 and 3, but importantly missing packet 1
2657 // which we registered to be notified about. 2808 // which we registered to be notified about.
2658 QuicAckFrame frame(3, QuicTime::Zero(), 0); 2809 QuicAckFrame frame(3, QuicTime::Zero(), 0);
2659 frame.received_info.missing_packets.insert(1); 2810 frame.received_info.missing_packets.insert(1);
2660 ProcessAckPacket(&frame, true); 2811 ProcessAckPacket(&frame, true);
2661 } 2812 }
2662 2813
2663 TEST_F(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) { 2814 TEST_F(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) {
2815 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2816
2664 // Create a delegate which we expect to be called. 2817 // Create a delegate which we expect to be called.
2665 MockAckNotifierDelegate delegate; 2818 MockAckNotifierDelegate delegate;
2666 EXPECT_CALL(delegate, OnAckNotification()).Times(1);; 2819 EXPECT_CALL(delegate, OnAckNotification()).Times(1);;
2667 2820
2668 // OnAck called twice: once with missing packet, once after retransmit. 2821 // OnAck called twice: once with missing packet, once after retransmit.
2669 EXPECT_CALL(visitor_, OnAck(_)).Times(2); 2822 EXPECT_CALL(visitor_, OnAck(_)).Times(2);
2670 2823
2671 // In total expect ACKs for all 4 packets. 2824 // In total expect ACKs for all 4 packets.
2672 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(4); 2825 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(4);
2673 2826
2674 // We will lose the second packet. 2827 // We will lose the second packet.
2675 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); 2828 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1);
2676 2829
2677 // Send four packets, and register to be notified on ACK of packet 2. 2830 // Send four packets, and register to be notified on ACK of packet 2.
2678 connection_.SendStreamData(1, "foo", 0, !kFin); 2831 connection_.SendStreamData(1, "foo", 0, !kFin);
2679 connection_.SendStreamDataAndNotifyWhenAcked(1, "bar", 0, !kFin, &delegate); 2832 connection_.SendStreamDataAndNotifyWhenAcked(1, "bar", 0, !kFin, &delegate);
2680 connection_.SendStreamData(1, "baz", 0, !kFin); 2833 connection_.SendStreamData(1, "baz", 0, !kFin);
2681 connection_.SendStreamData(1, "qux", 0, !kFin); 2834 connection_.SendStreamData(1, "qux", 0, !kFin);
2682 2835
2683 // Now we receive ACK for packets 1, 3, and 4. 2836 // Now we receive ACK for packets 1, 3, and 4.
2684 QuicAckFrame frame(4, QuicTime::Zero(), 0); 2837 QuicAckFrame frame(4, QuicTime::Zero(), 0);
2685 frame.received_info.missing_packets.insert(2); 2838 frame.received_info.missing_packets.insert(2);
2686 ProcessAckPacket(&frame, true); 2839 ProcessAckPacket(&frame, true);
2687 2840
2688 // Advance time to trigger RTO, for packet 2 (which should be retransmitted as 2841 // Advance time to trigger RTO, for packet 2 (which should be retransmitted as
2689 // packet 5). 2842 // packet 5).
2690 EXPECT_CALL(*send_algorithm_, AbandoningPacket(2, _)).Times(1); 2843 EXPECT_CALL(*send_algorithm_, AbandoningPacket(2, _)).Times(1);
2691 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).Times(1); 2844 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _)).Times(1);
2692 2845
2693 clock_.AdvanceTime(DefaultRetransmissionTime()); 2846 clock_.AdvanceTime(DefaultRetransmissionTime());
2694 connection_.OnRetransmissionTimeout(); 2847 connection_.OnRetransmissionTimeout();
2695 2848
2696 // Now we get an ACK for packet 5 (retransmitted packet 2), which should 2849 // Now we get an ACK for packet 5 (retransmitted packet 2), which should
2697 // trigger the callback. 2850 // trigger the callback.
2698 QuicAckFrame second_ack_frame(5, QuicTime::Zero(), 0); 2851 QuicAckFrame second_ack_frame(5, QuicTime::Zero(), 0);
2699 ProcessAckPacket(&second_ack_frame, true); 2852 ProcessAckPacket(&second_ack_frame, true);
2700 } 2853 }
2701 2854
2702 // TODO(rjshade): Add a similar test that FEC recovery on peer (and resulting 2855 // TODO(rjshade): Add a similar test that FEC recovery on peer (and resulting
2703 // ACK) triggers notification on our end. 2856 // ACK) triggers notification on our end.
2704 TEST_F(QuicConnectionTest, AckNotifierCallbackAfterFECRecovery) { 2857 TEST_F(QuicConnectionTest, AckNotifierCallbackAfterFECRecovery) {
2858 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2705 EXPECT_CALL(visitor_, OnCanWrite()).Times(1).WillOnce(Return(true)); 2859 EXPECT_CALL(visitor_, OnCanWrite()).Times(1).WillOnce(Return(true));
2706 2860
2707 // Create a delegate which we expect to be called. 2861 // Create a delegate which we expect to be called.
2708 MockAckNotifierDelegate delegate; 2862 MockAckNotifierDelegate delegate;
2709 EXPECT_CALL(delegate, OnAckNotification()).Times(1);; 2863 EXPECT_CALL(delegate, OnAckNotification()).Times(1);;
2710 2864
2711 // Expect ACKs for 1 packet. 2865 // Expect ACKs for 1 packet.
2712 EXPECT_CALL(visitor_, OnAck(_)).Times(1); 2866 EXPECT_CALL(visitor_, OnAck(_)).Times(1);
2713 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1); 2867 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1);
2714 2868
2715 // Send one packet, and register to be notified on ACK. 2869 // Send one packet, and register to be notified on ACK.
2716 connection_.SendStreamDataAndNotifyWhenAcked(1, "foo", 0, !kFin, &delegate); 2870 connection_.SendStreamDataAndNotifyWhenAcked(1, "foo", 0, !kFin, &delegate);
2717 2871
2718 // Ack packet gets dropped, but we receive an FEC packet that covers it. 2872 // Ack packet gets dropped, but we receive an FEC packet that covers it.
2719 // Should recover the Ack packet and trigger the notification callback. 2873 // Should recover the Ack packet and trigger the notification callback.
2720 QuicFrames frames; 2874 QuicFrames frames;
2721 2875
2722 QuicAckFrame ack_frame(1, QuicTime::Zero(), 0); 2876 QuicAckFrame ack_frame(1, QuicTime::Zero(), 0);
2723 frames.push_back(QuicFrame(&ack_frame)); 2877 frames.push_back(QuicFrame(&ack_frame));
2724 2878
2725 // Dummy stream frame to satisfy expectations set elsewhere. 2879 // Dummy stream frame to satisfy expectations set elsewhere.
2726 QuicFrame frame(&frame1_); 2880 frames.push_back(QuicFrame(&frame1_));
2727 frames.push_back(frame);
2728 2881
2729 QuicPacketHeader ack_header; 2882 QuicPacketHeader ack_header;
2730 ack_header.public_header.guid = guid_; 2883 ack_header.public_header.guid = guid_;
2731 ack_header.public_header.reset_flag = false; 2884 ack_header.public_header.reset_flag = false;
2732 ack_header.public_header.version_flag = false; 2885 ack_header.public_header.version_flag = false;
2733 ack_header.entropy_flag = !kEntropyFlag; 2886 ack_header.entropy_flag = !kEntropyFlag;
2734 ack_header.fec_flag = true; 2887 ack_header.fec_flag = true;
2735 ack_header.packet_sequence_number = 42; 2888 ack_header.packet_sequence_number = 42;
2736 ack_header.is_in_fec_group = IN_FEC_GROUP; 2889 ack_header.is_in_fec_group = IN_FEC_GROUP;
2737 ack_header.fec_group = 1; 2890 ack_header.fec_group = 1;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
2802 scoped_ptr<MockQuicConnectionDebugVisitor> 2955 scoped_ptr<MockQuicConnectionDebugVisitor>
2803 debug_visitor(new StrictMock<MockQuicConnectionDebugVisitor>); 2956 debug_visitor(new StrictMock<MockQuicConnectionDebugVisitor>);
2804 connection_.set_debug_visitor(debug_visitor.get()); 2957 connection_.set_debug_visitor(debug_visitor.get());
2805 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1); 2958 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1);
2806 connection_.OnPacketHeader(header); 2959 connection_.OnPacketHeader(header);
2807 } 2960 }
2808 2961
2809 } // namespace 2962 } // namespace
2810 } // namespace test 2963 } // namespace test
2811 } // namespace net 2964 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection_logger.cc ('k') | net/quic/quic_crypto_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698