| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/quic/quic_connection.h" | 5 #include "net/quic/quic_connection.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "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 Loading... |
| 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 bool SendOrQueuePacket(EncryptionLevel level, |
| 393 QuicPacketSequenceNumber sequence_number, |
| 394 QuicPacket* packet, |
| 395 QuicPacketEntropyHash entropy_hash, |
| 396 HasRetransmittableData retransmittable) { |
| 397 return SendOrQueuePacket(level, |
| 398 sequence_number, |
| 399 packet, |
| 400 entropy_hash, |
| 401 retransmittable, |
| 402 NO_FORCE); |
| 403 } |
| 404 |
| 392 QuicConsumedData SendStreamData(QuicStreamId id, | 405 QuicConsumedData SendStreamData(QuicStreamId id, |
| 393 StringPiece data, | 406 StringPiece data, |
| 394 QuicStreamOffset offset, | 407 QuicStreamOffset offset, |
| 395 bool fin) { | 408 bool fin) { |
| 396 struct iovec iov = {const_cast<char*>(data.data()), | 409 struct iovec iov = {const_cast<char*>(data.data()), |
| 397 static_cast<size_t>(data.size())}; | 410 static_cast<size_t>(data.size())}; |
| 398 return SendvStreamData(id, &iov, 1, offset, fin); | 411 return SendvStreamData(id, &iov, 1, offset, fin); |
| 399 } | 412 } |
| 400 | 413 |
| 414 QuicConsumedData SendStreamDataAndNotifyWhenAcked( |
| 415 QuicStreamId id, |
| 416 StringPiece data, |
| 417 QuicStreamOffset offset, |
| 418 bool fin, |
| 419 QuicAckNotifier::DelegateInterface* delegate) { |
| 420 struct iovec iov = {const_cast<char*>(data.data()), |
| 421 static_cast<size_t>(data.size())}; |
| 422 return SendvStreamDataAndNotifyWhenAcked(id, &iov, 1, offset, fin, |
| 423 delegate); |
| 424 } |
| 425 |
| 401 QuicConsumedData SendStreamData3() { | 426 QuicConsumedData SendStreamData3() { |
| 402 return SendStreamData(kStreamId3, "food", 0, !kFin); | 427 return SendStreamData(kStreamId3, "food", 0, !kFin); |
| 403 } | 428 } |
| 404 | 429 |
| 405 QuicConsumedData SendStreamData5() { | 430 QuicConsumedData SendStreamData5() { |
| 406 return SendStreamData(kStreamId5, "food2", 0, !kFin); | 431 return SendStreamData(kStreamId5, "food2", 0, !kFin); |
| 407 } | 432 } |
| 408 | 433 |
| 409 // The crypto stream has special semantics so that it is not blocked by a | 434 // The crypto stream has special semantics so that it is not blocked by a |
| 410 // congestion window limitation, and also so that it gets put into a separate | 435 // congestion window limitation, and also so that it gets put into a separate |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly( | 509 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly( |
| 485 Return(QuicTime::Delta::Zero())); | 510 Return(QuicTime::Delta::Zero())); |
| 486 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillRepeatedly(Return( | 511 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillRepeatedly(Return( |
| 487 QuicBandwidth::FromKBitsPerSecond(100))); | 512 QuicBandwidth::FromKBitsPerSecond(100))); |
| 488 EXPECT_CALL(*send_algorithm_, SmoothedRtt()).WillRepeatedly(Return( | 513 EXPECT_CALL(*send_algorithm_, SmoothedRtt()).WillRepeatedly(Return( |
| 489 QuicTime::Delta::FromMilliseconds(100))); | 514 QuicTime::Delta::FromMilliseconds(100))); |
| 490 ON_CALL(*send_algorithm_, SentPacket(_, _, _, _, _)) | 515 ON_CALL(*send_algorithm_, SentPacket(_, _, _, _, _)) |
| 491 .WillByDefault(Return(true)); | 516 .WillByDefault(Return(true)); |
| 492 // TODO(rch): remove this. | 517 // TODO(rch): remove this. |
| 493 QuicConnection::g_acks_do_not_instigate_acks = true; | 518 QuicConnection::g_acks_do_not_instigate_acks = true; |
| 519 EXPECT_CALL(visitor_, HasPendingHandshake()).Times(AnyNumber()); |
| 494 } | 520 } |
| 495 | 521 |
| 496 ~QuicConnectionTest() { | 522 ~QuicConnectionTest() { |
| 497 // TODO(rch): remove this. | 523 // TODO(rch): remove this. |
| 498 QuicConnection::g_acks_do_not_instigate_acks = false; | 524 QuicConnection::g_acks_do_not_instigate_acks = false; |
| 499 } | 525 } |
| 500 | 526 |
| 501 QuicAckFrame* outgoing_ack() { | 527 QuicAckFrame* outgoing_ack() { |
| 502 outgoing_ack_.reset(QuicConnectionPeer::CreateAckFrame(&connection_)); | 528 outgoing_ack_.reset(QuicConnectionPeer::CreateAckFrame(&connection_)); |
| 503 return outgoing_ack_.get(); | 529 return outgoing_ack_.get(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 521 | 547 |
| 522 uint32 final_bytes_of_last_packet() { | 548 uint32 final_bytes_of_last_packet() { |
| 523 return helper_->final_bytes_of_last_packet(); | 549 return helper_->final_bytes_of_last_packet(); |
| 524 } | 550 } |
| 525 | 551 |
| 526 void use_tagging_decrypter() { | 552 void use_tagging_decrypter() { |
| 527 helper_->use_tagging_decrypter(); | 553 helper_->use_tagging_decrypter(); |
| 528 } | 554 } |
| 529 | 555 |
| 530 void ProcessPacket(QuicPacketSequenceNumber number) { | 556 void ProcessPacket(QuicPacketSequenceNumber number) { |
| 531 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)) | 557 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillOnce(Return(accept_packet_)); |
| 532 .WillOnce(Return(accept_packet_)); | |
| 533 ProcessDataPacket(number, 0, !kEntropyFlag); | 558 ProcessDataPacket(number, 0, !kEntropyFlag); |
| 534 } | 559 } |
| 535 | 560 |
| 536 QuicPacketEntropyHash ProcessFramePacket(QuicFrame frame) { | 561 QuicPacketEntropyHash ProcessFramePacket(QuicFrame frame) { |
| 537 QuicFrames frames; | 562 QuicFrames frames; |
| 538 frames.push_back(QuicFrame(frame)); | 563 frames.push_back(QuicFrame(frame)); |
| 539 QuicPacketCreatorPeer::SetSendVersionInPacket(&creator_, | 564 QuicPacketCreatorPeer::SetSendVersionInPacket(&creator_, |
| 540 connection_.is_server()); | 565 connection_.is_server()); |
| 541 SerializedPacket serialized_packet = creator_.SerializeAllFrames(frames); | 566 SerializedPacket serialized_packet = creator_.SerializeAllFrames(frames); |
| 542 scoped_ptr<QuicPacket> packet(serialized_packet.packet); | 567 scoped_ptr<QuicPacket> packet(serialized_packet.packet); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 570 QuicFecGroupNumber fec_group) { | 595 QuicFecGroupNumber fec_group) { |
| 571 scoped_ptr<QuicPacket> packet(ConstructClosePacket(number, fec_group)); | 596 scoped_ptr<QuicPacket> packet(ConstructClosePacket(number, fec_group)); |
| 572 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPacket( | 597 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPacket( |
| 573 ENCRYPTION_NONE, number, *packet)); | 598 ENCRYPTION_NONE, number, *packet)); |
| 574 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 599 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); |
| 575 } | 600 } |
| 576 | 601 |
| 577 size_t ProcessFecProtectedPacket(QuicPacketSequenceNumber number, | 602 size_t ProcessFecProtectedPacket(QuicPacketSequenceNumber number, |
| 578 bool expect_revival, bool entropy_flag) { | 603 bool expect_revival, bool entropy_flag) { |
| 579 if (expect_revival) { | 604 if (expect_revival) { |
| 580 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillOnce(DoAll( | 605 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillOnce(Return(accept_packet_)); |
| 581 SaveArg<2>(&revived_header_), Return(accept_packet_))); | |
| 582 } | 606 } |
| 583 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillOnce(Return(accept_packet_)) | 607 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillOnce(Return(accept_packet_)) |
| 584 .RetiresOnSaturation(); | 608 .RetiresOnSaturation(); |
| 585 return ProcessDataPacket(number, 1, entropy_flag); | 609 return ProcessDataPacket(number, 1, entropy_flag); |
| 586 } | 610 } |
| 587 | 611 |
| 588 // Processes an FEC packet that covers the packets that would have been | 612 // Processes an FEC packet that covers the packets that would have been |
| 589 // received. | 613 // received. |
| 590 size_t ProcessFecPacket(QuicPacketSequenceNumber number, | 614 size_t ProcessFecPacket(QuicPacketSequenceNumber number, |
| 591 QuicPacketSequenceNumber min_protected_packet, | 615 QuicPacketSequenceNumber min_protected_packet, |
| 592 bool expect_revival, | 616 bool expect_revival, |
| 593 bool entropy_flag, | 617 bool entropy_flag, |
| 594 QuicPacket* packet) { | 618 QuicPacket* packet) { |
| 595 if (expect_revival) { | 619 if (expect_revival) { |
| 596 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillOnce(DoAll( | 620 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillOnce(Return(accept_packet_)); |
| 597 SaveArg<2>(&revived_header_), Return(accept_packet_))); | |
| 598 } | 621 } |
| 599 | 622 |
| 600 // Construct the decrypted data packet so we can compute the correct | 623 // Construct the decrypted data packet so we can compute the correct |
| 601 // redundancy. If |packet| has been provided then use that, otherwise | 624 // redundancy. If |packet| has been provided then use that, otherwise |
| 602 // construct a default data packet. | 625 // construct a default data packet. |
| 603 scoped_ptr<QuicPacket> data_packet; | 626 scoped_ptr<QuicPacket> data_packet; |
| 604 if (packet) { | 627 if (packet) { |
| 605 data_packet.reset(packet); | 628 data_packet.reset(packet); |
| 606 } else { | 629 } else { |
| 607 data_packet.reset(ConstructDataPacket(number, 1, !kEntropyFlag)); | 630 data_packet.reset(ConstructDataPacket(number, 1, !kEntropyFlag)); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 | 761 |
| 739 MockSendAlgorithm* send_algorithm_; | 762 MockSendAlgorithm* send_algorithm_; |
| 740 TestReceiveAlgorithm* receive_algorithm_; | 763 TestReceiveAlgorithm* receive_algorithm_; |
| 741 MockClock clock_; | 764 MockClock clock_; |
| 742 MockRandom random_generator_; | 765 MockRandom random_generator_; |
| 743 TestConnectionHelper* helper_; | 766 TestConnectionHelper* helper_; |
| 744 TestConnection connection_; | 767 TestConnection connection_; |
| 745 StrictMock<MockConnectionVisitor> visitor_; | 768 StrictMock<MockConnectionVisitor> visitor_; |
| 746 | 769 |
| 747 QuicPacketHeader header_; | 770 QuicPacketHeader header_; |
| 748 QuicPacketHeader revived_header_; | |
| 749 QuicStreamFrame frame1_; | 771 QuicStreamFrame frame1_; |
| 750 QuicStreamFrame frame2_; | 772 QuicStreamFrame frame2_; |
| 751 scoped_ptr<QuicAckFrame> outgoing_ack_; | 773 scoped_ptr<QuicAckFrame> outgoing_ack_; |
| 752 bool accept_packet_; | 774 bool accept_packet_; |
| 753 | 775 |
| 754 private: | 776 private: |
| 755 DISALLOW_COPY_AND_ASSIGN(QuicConnectionTest); | 777 DISALLOW_COPY_AND_ASSIGN(QuicConnectionTest); |
| 756 }; | 778 }; |
| 757 | 779 |
| 758 TEST_F(QuicConnectionTest, PacketsInOrder) { | 780 TEST_F(QuicConnectionTest, PacketsInOrder) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 | 828 |
| 807 TEST_F(QuicConnectionTest, DuplicatePacket) { | 829 TEST_F(QuicConnectionTest, DuplicatePacket) { |
| 808 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 830 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 809 | 831 |
| 810 ProcessPacket(3); | 832 ProcessPacket(3); |
| 811 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); | 833 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); |
| 812 EXPECT_TRUE(IsMissing(2)); | 834 EXPECT_TRUE(IsMissing(2)); |
| 813 EXPECT_TRUE(IsMissing(1)); | 835 EXPECT_TRUE(IsMissing(1)); |
| 814 | 836 |
| 815 // Send packet 3 again, but do not set the expectation that | 837 // Send packet 3 again, but do not set the expectation that |
| 816 // the visitor OnPacket() will be called. | 838 // the visitor OnStreamFrames() will be called. |
| 817 ProcessDataPacket(3, 0, !kEntropyFlag); | 839 ProcessDataPacket(3, 0, !kEntropyFlag); |
| 818 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); | 840 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); |
| 819 EXPECT_TRUE(IsMissing(2)); | 841 EXPECT_TRUE(IsMissing(2)); |
| 820 EXPECT_TRUE(IsMissing(1)); | 842 EXPECT_TRUE(IsMissing(1)); |
| 821 } | 843 } |
| 822 | 844 |
| 823 TEST_F(QuicConnectionTest, PacketsOutOfOrderWithAdditionsAndLeastAwaiting) { | 845 TEST_F(QuicConnectionTest, PacketsOutOfOrderWithAdditionsAndLeastAwaiting) { |
| 824 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 846 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 825 | 847 |
| 826 ProcessPacket(3); | 848 ProcessPacket(3); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 852 | 874 |
| 853 TEST_F(QuicConnectionTest, RejectPacketTooFarOut) { | 875 TEST_F(QuicConnectionTest, RejectPacketTooFarOut) { |
| 854 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a | 876 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a |
| 855 // packet call to the visitor. | 877 // packet call to the visitor. |
| 856 EXPECT_CALL(visitor_, ConnectionClose(QUIC_INVALID_PACKET_HEADER, false)); | 878 EXPECT_CALL(visitor_, ConnectionClose(QUIC_INVALID_PACKET_HEADER, false)); |
| 857 ProcessDataPacket(6000, 0, !kEntropyFlag); | 879 ProcessDataPacket(6000, 0, !kEntropyFlag); |
| 858 } | 880 } |
| 859 | 881 |
| 860 TEST_F(QuicConnectionTest, TruncatedAck) { | 882 TEST_F(QuicConnectionTest, TruncatedAck) { |
| 861 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 883 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 862 EXPECT_CALL(visitor_, OnAck(_)).Times(testing::AnyNumber()); | |
| 863 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(2); | 884 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(2); |
| 864 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); | 885 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); |
| 865 for (int i = 0; i < 200; ++i) { | 886 for (int i = 0; i < 200; ++i) { |
| 866 SendStreamDataToPeer(1, "foo", i * 3, !kFin, NULL); | 887 SendStreamDataToPeer(1, "foo", i * 3, !kFin, NULL); |
| 867 } | 888 } |
| 868 | 889 |
| 869 QuicAckFrame frame(0, QuicTime::Zero(), 1); | 890 QuicAckFrame frame(0, QuicTime::Zero(), 1); |
| 870 frame.received_info.largest_observed = 193; | 891 frame.received_info.largest_observed = 193; |
| 871 InsertMissingPacketsBetween(&frame.received_info, 1, 193); | 892 InsertMissingPacketsBetween(&frame.received_info, 1, 193); |
| 872 frame.received_info.entropy_hash = | 893 frame.received_info.entropy_hash = |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 972 | 993 |
| 973 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); | 994 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); |
| 974 SendStreamDataToPeer(1, "bar", 3, !kFin, NULL); | 995 SendStreamDataToPeer(1, "bar", 3, !kFin, NULL); |
| 975 SendStreamDataToPeer(1, "eep", 6, !kFin, NULL); | 996 SendStreamDataToPeer(1, "eep", 6, !kFin, NULL); |
| 976 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(2); | 997 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(2); |
| 977 | 998 |
| 978 // Start out saying the largest observed is 2. | 999 // Start out saying the largest observed is 2. |
| 979 QuicAckFrame frame(2, QuicTime::Zero(), 0); | 1000 QuicAckFrame frame(2, QuicTime::Zero(), 0); |
| 980 frame.received_info.entropy_hash = QuicConnectionPeer::GetSentEntropyHash( | 1001 frame.received_info.entropy_hash = QuicConnectionPeer::GetSentEntropyHash( |
| 981 &connection_, 2); | 1002 &connection_, 2); |
| 982 EXPECT_CALL(visitor_, OnAck(_)); | |
| 983 ProcessAckPacket(&frame, true); | 1003 ProcessAckPacket(&frame, true); |
| 984 | 1004 |
| 985 // Now change it to 1, and it should cause a connection error. | 1005 // Now change it to 1, and it should cause a connection error. |
| 986 QuicAckFrame frame2(1, QuicTime::Zero(), 0); | 1006 QuicAckFrame frame2(1, QuicTime::Zero(), 0); |
| 987 EXPECT_CALL(visitor_, ConnectionClose(QUIC_INVALID_ACK_DATA, false)); | 1007 EXPECT_CALL(visitor_, ConnectionClose(QUIC_INVALID_ACK_DATA, false)); |
| 988 ProcessAckPacket(&frame2, false); | 1008 ProcessAckPacket(&frame2, false); |
| 989 } | 1009 } |
| 990 | 1010 |
| 991 TEST_F(QuicConnectionTest, LeastUnackedGreaterThanPacketSequenceNumber) { | 1011 TEST_F(QuicConnectionTest, LeastUnackedGreaterThanPacketSequenceNumber) { |
| 992 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1012 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1142 EXPECT_EQ(1u, last_ack()->sent_info.least_unacked); | 1162 EXPECT_EQ(1u, last_ack()->sent_info.least_unacked); |
| 1143 | 1163 |
| 1144 SendAckPacketToPeer(); // Packet 3 | 1164 SendAckPacketToPeer(); // Packet 3 |
| 1145 EXPECT_EQ(1u, last_ack()->sent_info.least_unacked); | 1165 EXPECT_EQ(1u, last_ack()->sent_info.least_unacked); |
| 1146 | 1166 |
| 1147 SendStreamDataToPeer(1u, "bar", 3, !kFin, &last_packet); // Packet 4 | 1167 SendStreamDataToPeer(1u, "bar", 3, !kFin, &last_packet); // Packet 4 |
| 1148 EXPECT_EQ(4u, last_packet); | 1168 EXPECT_EQ(4u, last_packet); |
| 1149 SendAckPacketToPeer(); // Packet 5 | 1169 SendAckPacketToPeer(); // Packet 5 |
| 1150 EXPECT_EQ(1u, last_ack()->sent_info.least_unacked); | 1170 EXPECT_EQ(1u, last_ack()->sent_info.least_unacked); |
| 1151 | 1171 |
| 1152 SequenceNumberSet expected_acks; | |
| 1153 expected_acks.insert(1); | |
| 1154 | |
| 1155 // Peer acks up to packet 3. | 1172 // Peer acks up to packet 3. |
| 1156 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); | |
| 1157 QuicAckFrame frame(3, QuicTime::Zero(), 0); | 1173 QuicAckFrame frame(3, QuicTime::Zero(), 0); |
| 1158 frame.received_info.entropy_hash = | 1174 frame.received_info.entropy_hash = |
| 1159 QuicConnectionPeer::GetSentEntropyHash(&connection_, 3); | 1175 QuicConnectionPeer::GetSentEntropyHash(&connection_, 3); |
| 1160 ProcessAckPacket(&frame, true); | 1176 ProcessAckPacket(&frame, true); |
| 1161 SendAckPacketToPeer(); // Packet 6 | 1177 SendAckPacketToPeer(); // Packet 6 |
| 1162 | 1178 |
| 1163 // As soon as we've acked one, we skip ack packets 2 and 3 and note lack of | 1179 // As soon as we've acked one, we skip ack packets 2 and 3 and note lack of |
| 1164 // ack for 4. | 1180 // ack for 4. |
| 1165 EXPECT_EQ(4u, last_ack()->sent_info.least_unacked); | 1181 EXPECT_EQ(4u, last_ack()->sent_info.least_unacked); |
| 1166 | 1182 |
| 1167 expected_acks.clear(); | |
| 1168 expected_acks.insert(4); | |
| 1169 | |
| 1170 // Peer acks up to packet 4, the last packet. | 1183 // Peer acks up to packet 4, the last packet. |
| 1171 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); | |
| 1172 QuicAckFrame frame2(6, QuicTime::Zero(), 0); | 1184 QuicAckFrame frame2(6, QuicTime::Zero(), 0); |
| 1173 frame2.received_info.entropy_hash = | 1185 frame2.received_info.entropy_hash = |
| 1174 QuicConnectionPeer::GetSentEntropyHash(&connection_, 6); | 1186 QuicConnectionPeer::GetSentEntropyHash(&connection_, 6); |
| 1175 ProcessAckPacket(&frame2, true); // Acks don't instigate acks. | 1187 ProcessAckPacket(&frame2, true); // Acks don't instigate acks. |
| 1176 | 1188 |
| 1177 // Verify that we did not send an ack. | 1189 // Verify that we did not send an ack. |
| 1178 EXPECT_EQ(6u, last_header()->packet_sequence_number); | 1190 EXPECT_EQ(6u, last_header()->packet_sequence_number); |
| 1179 | 1191 |
| 1180 // So the last ack has not changed. | 1192 // So the last ack has not changed. |
| 1181 EXPECT_EQ(4u, last_ack()->sent_info.least_unacked); | 1193 EXPECT_EQ(4u, last_ack()->sent_info.least_unacked); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1258 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _)).Times(2); | 1270 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _)).Times(2); |
| 1259 connection_.SendStreamData(1, "foo", 0, !kFin); | 1271 connection_.SendStreamData(1, "foo", 0, !kFin); |
| 1260 | 1272 |
| 1261 QuicAckFrame ack_fec(2, QuicTime::Zero(), 1); | 1273 QuicAckFrame ack_fec(2, QuicTime::Zero(), 1); |
| 1262 // Data packet missing. | 1274 // Data packet missing. |
| 1263 ack_fec.received_info.missing_packets.insert(1); | 1275 ack_fec.received_info.missing_packets.insert(1); |
| 1264 ack_fec.received_info.entropy_hash = | 1276 ack_fec.received_info.entropy_hash = |
| 1265 QuicConnectionPeer::GetSentEntropyHash(&connection_, 2) ^ | 1277 QuicConnectionPeer::GetSentEntropyHash(&connection_, 2) ^ |
| 1266 QuicConnectionPeer::GetSentEntropyHash(&connection_, 1); | 1278 QuicConnectionPeer::GetSentEntropyHash(&connection_, 1); |
| 1267 | 1279 |
| 1268 EXPECT_CALL(visitor_, OnAck(_)).Times(1); | |
| 1269 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1); | 1280 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1); |
| 1270 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); | 1281 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); |
| 1271 | 1282 |
| 1272 ProcessAckPacket(&ack_fec, true); | 1283 ProcessAckPacket(&ack_fec, true); |
| 1273 | 1284 |
| 1274 clock_.AdvanceTime(DefaultRetransmissionTime()); | 1285 clock_.AdvanceTime(DefaultRetransmissionTime()); |
| 1275 | 1286 |
| 1276 // Abandon only data packet, FEC has been acked. | 1287 // Abandon only data packet, FEC has been acked. |
| 1277 EXPECT_CALL(*send_algorithm_, AbandoningPacket(sequence_number, _)).Times(1); | 1288 EXPECT_CALL(*send_algorithm_, AbandoningPacket(sequence_number, _)).Times(1); |
| 1278 // Send only data packet. | 1289 // Send only data packet. |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1500 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(2); | 1511 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(2); |
| 1501 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); | 1512 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); |
| 1502 EXPECT_CALL(*send_algorithm_, AbandoningPacket(2, _)).Times(1); | 1513 EXPECT_CALL(*send_algorithm_, AbandoningPacket(2, _)).Times(1); |
| 1503 QuicPacketSequenceNumber last_packet; | 1514 QuicPacketSequenceNumber last_packet; |
| 1504 QuicByteCount second_packet_size; | 1515 QuicByteCount second_packet_size; |
| 1505 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 | 1516 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 |
| 1506 second_packet_size = | 1517 second_packet_size = |
| 1507 SendStreamDataToPeer(1, "foos", 3, !kFin, &last_packet); // Packet 2 | 1518 SendStreamDataToPeer(1, "foos", 3, !kFin, &last_packet); // Packet 2 |
| 1508 SendStreamDataToPeer(1, "fooos", 7, !kFin, &last_packet); // Packet 3 | 1519 SendStreamDataToPeer(1, "fooos", 7, !kFin, &last_packet); // Packet 3 |
| 1509 | 1520 |
| 1510 SequenceNumberSet expected_acks; | |
| 1511 expected_acks.insert(1); | |
| 1512 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); | |
| 1513 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1521 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1514 | 1522 |
| 1515 // Peer acks one but not two or three. Right now we only retransmit on | 1523 // Peer acks one but not two or three. Right now we only retransmit on |
| 1516 // explicit nack, so it should not trigger a retransimission. | 1524 // explicit nack, so it should not trigger a retransimission. |
| 1517 QuicAckFrame ack_one(1, QuicTime::Zero(), 0); | 1525 QuicAckFrame ack_one(1, QuicTime::Zero(), 0); |
| 1518 ack_one.received_info.entropy_hash = | 1526 ack_one.received_info.entropy_hash = |
| 1519 QuicConnectionPeer::GetSentEntropyHash(&connection_, 1); | 1527 QuicConnectionPeer::GetSentEntropyHash(&connection_, 1); |
| 1520 ProcessAckPacket(&ack_one, true); | 1528 ProcessAckPacket(&ack_one, true); |
| 1521 ProcessAckPacket(&ack_one, true); | 1529 ProcessAckPacket(&ack_one, true); |
| 1522 ProcessAckPacket(&ack_one, true); | 1530 ProcessAckPacket(&ack_one, true); |
| 1523 | 1531 |
| 1524 expected_acks.clear(); | |
| 1525 expected_acks.insert(3); | |
| 1526 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); | |
| 1527 | |
| 1528 // Peer acks up to 3 with two explicitly missing. Two nacks should cause no | 1532 // Peer acks up to 3 with two explicitly missing. Two nacks should cause no |
| 1529 // change. | 1533 // change. |
| 1530 QuicAckFrame nack_two(3, QuicTime::Zero(), 0); | 1534 QuicAckFrame nack_two(3, QuicTime::Zero(), 0); |
| 1531 nack_two.received_info.missing_packets.insert(2); | 1535 nack_two.received_info.missing_packets.insert(2); |
| 1532 nack_two.received_info.entropy_hash = | 1536 nack_two.received_info.entropy_hash = |
| 1533 QuicConnectionPeer::GetSentEntropyHash(&connection_, 3) ^ | 1537 QuicConnectionPeer::GetSentEntropyHash(&connection_, 3) ^ |
| 1534 QuicConnectionPeer::GetSentEntropyHash(&connection_, 2) ^ | 1538 QuicConnectionPeer::GetSentEntropyHash(&connection_, 2) ^ |
| 1535 QuicConnectionPeer::GetSentEntropyHash(&connection_, 1); | 1539 QuicConnectionPeer::GetSentEntropyHash(&connection_, 1); |
| 1536 ProcessAckPacket(&nack_two, true); | 1540 ProcessAckPacket(&nack_two, true); |
| 1537 ProcessAckPacket(&nack_two, true); | 1541 ProcessAckPacket(&nack_two, true); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1574 // Make a truncated ack frame. | 1578 // Make a truncated ack frame. |
| 1575 QuicAckFrame frame(0, QuicTime::Zero(), 1); | 1579 QuicAckFrame frame(0, QuicTime::Zero(), 1); |
| 1576 frame.received_info.largest_observed = 193; | 1580 frame.received_info.largest_observed = 193; |
| 1577 InsertMissingPacketsBetween(&frame.received_info, 1, 193); | 1581 InsertMissingPacketsBetween(&frame.received_info, 1, 193); |
| 1578 frame.received_info.entropy_hash = | 1582 frame.received_info.entropy_hash = |
| 1579 QuicConnectionPeer::GetSentEntropyHash(&connection_, 193) ^ | 1583 QuicConnectionPeer::GetSentEntropyHash(&connection_, 193) ^ |
| 1580 QuicConnectionPeer::GetSentEntropyHash(&connection_, 192); | 1584 QuicConnectionPeer::GetSentEntropyHash(&connection_, 192); |
| 1581 | 1585 |
| 1582 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1); | 1586 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1); |
| 1583 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); | 1587 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); |
| 1584 EXPECT_CALL(visitor_, OnAck(_)).Times(1); | |
| 1585 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1588 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1586 ProcessAckPacket(&frame, true); | 1589 ProcessAckPacket(&frame, true); |
| 1587 EXPECT_TRUE(QuicConnectionPeer::GetReceivedTruncatedAck(&connection_)); | 1590 EXPECT_TRUE(QuicConnectionPeer::GetReceivedTruncatedAck(&connection_)); |
| 1588 | 1591 |
| 1589 QuicConnectionPeer::SetMaxPacketsPerRetransmissionAlarm(&connection_, 200); | 1592 QuicConnectionPeer::SetMaxPacketsPerRetransmissionAlarm(&connection_, 200); |
| 1590 clock_.AdvanceTime(DefaultRetransmissionTime()); | 1593 clock_.AdvanceTime(DefaultRetransmissionTime()); |
| 1591 // Only packets that are less than largest observed should be retransmitted. | 1594 // Only packets that are less than largest observed should be retransmitted. |
| 1592 EXPECT_CALL(*send_algorithm_, AbandoningPacket(_, _)).Times(192); | 1595 EXPECT_CALL(*send_algorithm_, AbandoningPacket(_, _)).Times(192); |
| 1593 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _)).Times(192); | 1596 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _)).Times(192); |
| 1594 connection_.OnRetransmissionTimeout(); | 1597 connection_.OnRetransmissionTimeout(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1616 | 1619 |
| 1617 // Ack 12, nack 1-11 | 1620 // Ack 12, nack 1-11 |
| 1618 QuicAckFrame nack(12, QuicTime::Zero(), 0); | 1621 QuicAckFrame nack(12, QuicTime::Zero(), 0); |
| 1619 for (int i = 1; i < 12; ++i) { | 1622 for (int i = 1; i < 12; ++i) { |
| 1620 nack.received_info.missing_packets.insert(i); | 1623 nack.received_info.missing_packets.insert(i); |
| 1621 } | 1624 } |
| 1622 | 1625 |
| 1623 nack.received_info.entropy_hash = | 1626 nack.received_info.entropy_hash = |
| 1624 QuicConnectionPeer::GetSentEntropyHash(&connection_, 12) ^ | 1627 QuicConnectionPeer::GetSentEntropyHash(&connection_, 12) ^ |
| 1625 QuicConnectionPeer::GetSentEntropyHash(&connection_, 11); | 1628 QuicConnectionPeer::GetSentEntropyHash(&connection_, 11); |
| 1626 SequenceNumberSet expected_acks; | |
| 1627 expected_acks.insert(12); | |
| 1628 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); | |
| 1629 | 1629 |
| 1630 // Nack three times. | 1630 // Nack three times. |
| 1631 ProcessAckPacket(&nack, true); | 1631 ProcessAckPacket(&nack, true); |
| 1632 ProcessAckPacket(&nack, true); | 1632 ProcessAckPacket(&nack, true); |
| 1633 // The third call should trigger retransmitting 10 packets. | 1633 // The third call should trigger retransmitting 10 packets. |
| 1634 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _)).Times(10); | 1634 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _)).Times(10); |
| 1635 ProcessAckPacket(&nack, true); | 1635 ProcessAckPacket(&nack, true); |
| 1636 | 1636 |
| 1637 // The fourth call should trigger retransmitting the 11th packet. | 1637 // The fourth call should trigger retransmitting the 11th packet. |
| 1638 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _)).Times(1); | 1638 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _)).Times(1); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1657 EXPECT_EQ(6u, last_packet); | 1657 EXPECT_EQ(6u, last_packet); |
| 1658 | 1658 |
| 1659 // Client will ack packets 1, [!2], 3, 4, 5 | 1659 // Client will ack packets 1, [!2], 3, 4, 5 |
| 1660 QuicAckFrame frame1(5, QuicTime::Zero(), 0); | 1660 QuicAckFrame frame1(5, QuicTime::Zero(), 0); |
| 1661 frame1.received_info.missing_packets.insert(2); | 1661 frame1.received_info.missing_packets.insert(2); |
| 1662 frame1.received_info.entropy_hash = | 1662 frame1.received_info.entropy_hash = |
| 1663 QuicConnectionPeer::GetSentEntropyHash(&connection_, 5) ^ | 1663 QuicConnectionPeer::GetSentEntropyHash(&connection_, 5) ^ |
| 1664 QuicConnectionPeer::GetSentEntropyHash(&connection_, 2) ^ | 1664 QuicConnectionPeer::GetSentEntropyHash(&connection_, 2) ^ |
| 1665 QuicConnectionPeer::GetSentEntropyHash(&connection_, 1); | 1665 QuicConnectionPeer::GetSentEntropyHash(&connection_, 1); |
| 1666 | 1666 |
| 1667 // The connection should pass up acks for 1, 4, 5. 2 is not acked, and 3 was | |
| 1668 // an ackframe so should not be passed up. | |
| 1669 SequenceNumberSet expected_acks; | |
| 1670 expected_acks.insert(1); | |
| 1671 expected_acks.insert(4); | |
| 1672 expected_acks.insert(5); | |
| 1673 | |
| 1674 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); | |
| 1675 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1667 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1676 | 1668 |
| 1677 ProcessAckPacket(&frame1, true); | 1669 ProcessAckPacket(&frame1, true); |
| 1678 | 1670 |
| 1679 // Now the client implicitly acks 2, and explicitly acks 6 | 1671 // Now the client implicitly acks 2, and explicitly acks 6 |
| 1680 QuicAckFrame frame2(6, QuicTime::Zero(), 0); | 1672 QuicAckFrame frame2(6, QuicTime::Zero(), 0); |
| 1681 frame2.received_info.entropy_hash = | 1673 frame2.received_info.entropy_hash = |
| 1682 QuicConnectionPeer::GetSentEntropyHash(&connection_, 6); | 1674 QuicConnectionPeer::GetSentEntropyHash(&connection_, 6); |
| 1683 expected_acks.clear(); | |
| 1684 // Both acks should be passed up. | |
| 1685 expected_acks.insert(2); | |
| 1686 expected_acks.insert(6); | |
| 1687 | 1675 |
| 1688 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); | |
| 1689 ProcessAckPacket(&frame2, true); | 1676 ProcessAckPacket(&frame2, true); |
| 1690 } | 1677 } |
| 1691 | 1678 |
| 1692 TEST_F(QuicConnectionTest, DontLatchUnackedPacket) { | 1679 TEST_F(QuicConnectionTest, DontLatchUnackedPacket) { |
| 1693 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1); | 1680 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1); |
| 1694 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); // Packet 1; | 1681 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); // Packet 1; |
| 1695 SendAckPacketToPeer(); // Packet 2 | 1682 SendAckPacketToPeer(); // Packet 2 |
| 1696 | 1683 |
| 1697 // This sets least unacked to 3 (unsent packet), since we don't need | |
| 1698 // an ack for Packet 2 (ack packet). | |
| 1699 SequenceNumberSet expected_acks; | |
| 1700 expected_acks.insert(1); | |
| 1701 // Peer acks packet 1. | |
| 1702 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); | |
| 1703 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1684 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1704 QuicAckFrame frame(1, QuicTime::Zero(), 0); | 1685 QuicAckFrame frame(1, QuicTime::Zero(), 0); |
| 1705 frame.received_info.entropy_hash = QuicConnectionPeer::GetSentEntropyHash( | 1686 frame.received_info.entropy_hash = QuicConnectionPeer::GetSentEntropyHash( |
| 1706 &connection_, 1); | 1687 &connection_, 1); |
| 1707 ProcessAckPacket(&frame, true); | 1688 ProcessAckPacket(&frame, true); |
| 1708 | 1689 |
| 1709 // Verify that our internal state has least-unacked as 3. | 1690 // Verify that our internal state has least-unacked as 3. |
| 1710 EXPECT_EQ(3u, outgoing_ack()->sent_info.least_unacked); | 1691 EXPECT_EQ(3u, outgoing_ack()->sent_info.least_unacked); |
| 1711 | 1692 |
| 1712 // When we send an ack, we make sure our least-unacked makes sense. In this | 1693 // When we send an ack, we make sure our least-unacked makes sense. In this |
| 1713 // case since we're not waiting on an ack for 2 and all packets are acked, we | 1694 // case since we're not waiting on an ack for 2 and all packets are acked, we |
| 1714 // set it to 3. | 1695 // set it to 3. |
| 1715 SendAckPacketToPeer(); // Packet 3 | 1696 SendAckPacketToPeer(); // Packet 3 |
| 1716 // Since this was an ack packet, we set least_unacked to 4. | 1697 // Since this was an ack packet, we set least_unacked to 4. |
| 1717 EXPECT_EQ(4u, outgoing_ack()->sent_info.least_unacked); | 1698 EXPECT_EQ(4u, outgoing_ack()->sent_info.least_unacked); |
| 1718 // Check that the outgoing ack had its sequence number as least_unacked. | 1699 // Check that the outgoing ack had its sequence number as least_unacked. |
| 1719 EXPECT_EQ(3u, last_ack()->sent_info.least_unacked); | 1700 EXPECT_EQ(3u, last_ack()->sent_info.least_unacked); |
| 1720 | 1701 |
| 1721 SendStreamDataToPeer(1, "bar", 3, false, NULL); // Packet 4 | 1702 SendStreamDataToPeer(1, "bar", 3, false, NULL); // Packet 4 |
| 1722 EXPECT_EQ(4u, outgoing_ack()->sent_info.least_unacked); | 1703 EXPECT_EQ(4u, outgoing_ack()->sent_info.least_unacked); |
| 1723 SendAckPacketToPeer(); // Packet 5 | 1704 SendAckPacketToPeer(); // Packet 5 |
| 1724 EXPECT_EQ(4u, last_ack()->sent_info.least_unacked); | 1705 EXPECT_EQ(4u, last_ack()->sent_info.least_unacked); |
| 1725 } | 1706 } |
| 1726 | 1707 |
| 1727 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterFecPacket) { | 1708 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterFecPacket) { |
| 1728 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1709 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1729 | 1710 |
| 1730 // Don't send missing packet 1. | 1711 // Don't send missing packet 1. |
| 1731 ProcessFecPacket(2, 1, true, !kEntropyFlag, NULL); | 1712 ProcessFecPacket(2, 1, true, !kEntropyFlag, NULL); |
| 1732 EXPECT_FALSE(revived_header_.entropy_flag); | 1713 // Entropy flag should be false, so entropy should be 0. |
| 1714 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); |
| 1733 } | 1715 } |
| 1734 | 1716 |
| 1735 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPacketThenFecPacket) { | 1717 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPacketThenFecPacket) { |
| 1736 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1718 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1737 | 1719 |
| 1738 ProcessFecProtectedPacket(1, false, kEntropyFlag); | 1720 ProcessFecProtectedPacket(1, false, kEntropyFlag); |
| 1739 // Don't send missing packet 2. | 1721 // Don't send missing packet 2. |
| 1740 ProcessFecPacket(3, 1, true, !kEntropyFlag, NULL); | 1722 ProcessFecPacket(3, 1, true, !kEntropyFlag, NULL); |
| 1741 EXPECT_TRUE(revived_header_.entropy_flag); | 1723 // Entropy flag should be true, so entropy should not be 0. |
| 1724 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); |
| 1742 } | 1725 } |
| 1743 | 1726 |
| 1744 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPacketsThenFecPacket) { | 1727 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPacketsThenFecPacket) { |
| 1745 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1728 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1746 | 1729 |
| 1747 ProcessFecProtectedPacket(1, false, !kEntropyFlag); | 1730 ProcessFecProtectedPacket(1, false, !kEntropyFlag); |
| 1748 // Don't send missing packet 2. | 1731 // Don't send missing packet 2. |
| 1749 ProcessFecProtectedPacket(3, false, !kEntropyFlag); | 1732 ProcessFecProtectedPacket(3, false, !kEntropyFlag); |
| 1750 ProcessFecPacket(4, 1, true, kEntropyFlag, NULL); | 1733 ProcessFecPacket(4, 1, true, kEntropyFlag, NULL); |
| 1751 EXPECT_TRUE(revived_header_.entropy_flag); | 1734 // Entropy flag should be true, so entropy should not be 0. |
| 1735 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); |
| 1752 } | 1736 } |
| 1753 | 1737 |
| 1754 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPacket) { | 1738 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPacket) { |
| 1755 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1739 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1756 | 1740 |
| 1757 // Don't send missing packet 1. | 1741 // Don't send missing packet 1. |
| 1758 ProcessFecPacket(3, 1, false, !kEntropyFlag, NULL); | 1742 ProcessFecPacket(3, 1, false, !kEntropyFlag, NULL); |
| 1759 // out of order | 1743 // out of order |
| 1760 ProcessFecProtectedPacket(2, true, !kEntropyFlag); | 1744 ProcessFecProtectedPacket(2, true, !kEntropyFlag); |
| 1761 EXPECT_FALSE(revived_header_.entropy_flag); | 1745 // Entropy flag should be false, so entropy should be 0. |
| 1746 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); |
| 1762 } | 1747 } |
| 1763 | 1748 |
| 1764 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPackets) { | 1749 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPackets) { |
| 1765 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1750 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1766 | 1751 |
| 1767 ProcessFecProtectedPacket(1, false, !kEntropyFlag); | 1752 ProcessFecProtectedPacket(1, false, !kEntropyFlag); |
| 1768 // Don't send missing packet 2. | 1753 // Don't send missing packet 2. |
| 1769 ProcessFecPacket(6, 1, false, kEntropyFlag, NULL); | 1754 ProcessFecPacket(6, 1, false, kEntropyFlag, NULL); |
| 1770 ProcessFecProtectedPacket(3, false, kEntropyFlag); | 1755 ProcessFecProtectedPacket(3, false, kEntropyFlag); |
| 1771 ProcessFecProtectedPacket(4, false, kEntropyFlag); | 1756 ProcessFecProtectedPacket(4, false, kEntropyFlag); |
| 1772 ProcessFecProtectedPacket(5, true, !kEntropyFlag); | 1757 ProcessFecProtectedPacket(5, true, !kEntropyFlag); |
| 1773 EXPECT_TRUE(revived_header_.entropy_flag); | 1758 // Entropy flag should be true, so entropy should be 0. |
| 1759 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); |
| 1774 } | 1760 } |
| 1775 | 1761 |
| 1776 TEST_F(QuicConnectionTest, TestRetransmit) { | 1762 TEST_F(QuicConnectionTest, TestRetransmit) { |
| 1777 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( | 1763 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( |
| 1778 DefaultRetransmissionTime()); | 1764 DefaultRetransmissionTime()); |
| 1779 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); | 1765 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); |
| 1780 EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked); | 1766 EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked); |
| 1781 | 1767 |
| 1782 EXPECT_EQ(1u, last_header()->packet_sequence_number); | 1768 EXPECT_EQ(1u, last_header()->packet_sequence_number); |
| 1783 EXPECT_EQ(default_retransmission_time, | 1769 EXPECT_EQ(default_retransmission_time, |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1876 // Process an encrypted packet which can not yet be decrypted | 1862 // Process an encrypted packet which can not yet be decrypted |
| 1877 // which should result in the packet being buffered. | 1863 // which should result in the packet being buffered. |
| 1878 ProcessDataPacketAtLevel(1, false, kEntropyFlag, ENCRYPTION_INITIAL); | 1864 ProcessDataPacketAtLevel(1, false, kEntropyFlag, ENCRYPTION_INITIAL); |
| 1879 | 1865 |
| 1880 // Transition to the new encryption state and process another | 1866 // Transition to the new encryption state and process another |
| 1881 // encrypted packet which should result in the original packet being | 1867 // encrypted packet which should result in the original packet being |
| 1882 // processed. | 1868 // processed. |
| 1883 connection_.SetDecrypter(new StrictTaggingDecrypter(tag)); | 1869 connection_.SetDecrypter(new StrictTaggingDecrypter(tag)); |
| 1884 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); | 1870 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); |
| 1885 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 1871 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
| 1886 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).Times(2).WillRepeatedly( | 1872 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(2).WillRepeatedly( |
| 1887 Return(true)); | 1873 Return(true)); |
| 1888 ProcessDataPacketAtLevel(2, false, kEntropyFlag, ENCRYPTION_INITIAL); | 1874 ProcessDataPacketAtLevel(2, false, kEntropyFlag, ENCRYPTION_INITIAL); |
| 1889 | 1875 |
| 1890 // Finally, process a third packet and note that we do not | 1876 // Finally, process a third packet and note that we do not |
| 1891 // reprocess the buffered packet. | 1877 // reprocess the buffered packet. |
| 1892 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillOnce(Return(true)); | 1878 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillOnce(Return(true)); |
| 1893 ProcessDataPacketAtLevel(3, false, kEntropyFlag, ENCRYPTION_INITIAL); | 1879 ProcessDataPacketAtLevel(3, false, kEntropyFlag, ENCRYPTION_INITIAL); |
| 1894 } | 1880 } |
| 1895 | 1881 |
| 1896 TEST_F(QuicConnectionTest, TestRetransmitOrder) { | 1882 TEST_F(QuicConnectionTest, TestRetransmitOrder) { |
| 1897 QuicByteCount first_packet_size; | 1883 QuicByteCount first_packet_size; |
| 1898 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _)).WillOnce( | 1884 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _)).WillOnce( |
| 1899 DoAll(SaveArg<2>(&first_packet_size), Return(true))); | 1885 DoAll(SaveArg<2>(&first_packet_size), Return(true))); |
| 1900 EXPECT_CALL(*send_algorithm_, AbandoningPacket(_, _)).Times(2); | 1886 EXPECT_CALL(*send_algorithm_, AbandoningPacket(_, _)).Times(2); |
| 1901 | 1887 |
| 1902 connection_.SendStreamData(1, "first_packet", 0, !kFin); | 1888 connection_.SendStreamData(1, "first_packet", 0, !kFin); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1971 // Make sure that RTO is not started when the packet is queued. | 1957 // Make sure that RTO is not started when the packet is queued. |
| 1972 EXPECT_EQ(0u, QuicConnectionPeer::GetNumRetransmissionTimeouts(&connection_)); | 1958 EXPECT_EQ(0u, QuicConnectionPeer::GetNumRetransmissionTimeouts(&connection_)); |
| 1973 | 1959 |
| 1974 // Test that RTO is started once we write to the socket. | 1960 // Test that RTO is started once we write to the socket. |
| 1975 helper_->set_blocked(false); | 1961 helper_->set_blocked(false); |
| 1976 EXPECT_CALL(visitor_, OnCanWrite()); | 1962 EXPECT_CALL(visitor_, OnCanWrite()); |
| 1977 connection_.OnCanWrite(); | 1963 connection_.OnCanWrite(); |
| 1978 EXPECT_EQ(1u, QuicConnectionPeer::GetNumRetransmissionTimeouts(&connection_)); | 1964 EXPECT_EQ(1u, QuicConnectionPeer::GetNumRetransmissionTimeouts(&connection_)); |
| 1979 } | 1965 } |
| 1980 | 1966 |
| 1967 TEST_F(QuicConnectionTest, DelayRTOWithAckReceipt) { |
| 1968 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1969 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, NOT_RETRANSMISSION, _)) |
| 1970 .Times(2); |
| 1971 connection_.SendStreamData(1, "foo", 0, !kFin); |
| 1972 connection_.SendStreamData(2, "bar", 0, !kFin); |
| 1973 EXPECT_EQ(2u, QuicConnectionPeer::GetNumRetransmissionTimeouts(&connection_)); |
| 1974 |
| 1975 // Advance the time right before the RTO, then receive an ack for the first |
| 1976 // packet to delay the RTO. |
| 1977 clock_.AdvanceTime(DefaultRetransmissionTime()); |
| 1978 EXPECT_EQ(2u, QuicConnectionPeer::GetNumRetransmissionTimeouts(&connection_)); |
| 1979 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1); |
| 1980 QuicAckFrame ack(1, QuicTime::Zero(), 0); |
| 1981 ProcessAckPacket(&ack, true); |
| 1982 EXPECT_EQ(1u, QuicConnectionPeer::GetNumRetransmissionTimeouts(&connection_)); |
| 1983 |
| 1984 // Move forward past the original RTO and ensure the RTO is still pending. |
| 1985 clock_.AdvanceTime(DefaultRetransmissionTime()); |
| 1986 EXPECT_EQ(1u, QuicConnectionPeer::GetNumRetransmissionTimeouts(&connection_)); |
| 1987 |
| 1988 // Ensure the second packet gets retransmitted when it finally fires. |
| 1989 EXPECT_TRUE( |
| 1990 QuicConnectionPeer::GetRetransmissionAlarm(&connection_)->IsSet()); |
| 1991 EXPECT_GE( |
| 1992 QuicConnectionPeer::GetRetransmissionAlarm(&connection_)->deadline(), |
| 1993 clock_.ApproximateNow()); |
| 1994 clock_.AdvanceTime(DefaultRetransmissionTime()); |
| 1995 EXPECT_LT( |
| 1996 QuicConnectionPeer::GetRetransmissionAlarm(&connection_)->deadline(), |
| 1997 clock_.ApproximateNow()); |
| 1998 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, IS_RETRANSMISSION, _)); |
| 1999 EXPECT_CALL(*send_algorithm_, AbandoningPacket(_, _)); |
| 2000 connection_.OnRetransmissionTimeout(); |
| 2001 |
| 2002 // The new retransmitted sequence number should now be in the timeout queue. |
| 2003 EXPECT_EQ(1u, QuicConnectionPeer::GetNumRetransmissionTimeouts(&connection_)); |
| 2004 } |
| 2005 |
| 1981 TEST_F(QuicConnectionTest, TestQueued) { | 2006 TEST_F(QuicConnectionTest, TestQueued) { |
| 1982 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 2007 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 1983 helper_->set_blocked(true); | 2008 helper_->set_blocked(true); |
| 1984 connection_.SendStreamData(1, "foo", 0, !kFin); | 2009 connection_.SendStreamData(1, "foo", 0, !kFin); |
| 1985 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 2010 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 1986 | 2011 |
| 1987 // Attempt to send all packets, but since we're actually still | 2012 // Attempt to send all packets, but since we're actually still |
| 1988 // blocked, they should all remain queued. | 2013 // blocked, they should all remain queued. |
| 1989 EXPECT_FALSE(connection_.OnCanWrite()); | 2014 EXPECT_FALSE(connection_.OnCanWrite()); |
| 1990 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 2015 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2355 TEST_F(QuicConnectionTest, MissingPacketsBeforeLeastUnacked) { | 2380 TEST_F(QuicConnectionTest, MissingPacketsBeforeLeastUnacked) { |
| 2356 QuicAckFrame ack(0, QuicTime::Zero(), 4); | 2381 QuicAckFrame ack(0, QuicTime::Zero(), 4); |
| 2357 // Set the sequence number of the ack packet to be least unacked (4) | 2382 // Set the sequence number of the ack packet to be least unacked (4) |
| 2358 creator_.set_sequence_number(3); | 2383 creator_.set_sequence_number(3); |
| 2359 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2384 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2360 ProcessAckPacket(&ack, true); | 2385 ProcessAckPacket(&ack, true); |
| 2361 EXPECT_TRUE(outgoing_ack()->received_info.missing_packets.empty()); | 2386 EXPECT_TRUE(outgoing_ack()->received_info.missing_packets.empty()); |
| 2362 } | 2387 } |
| 2363 | 2388 |
| 2364 TEST_F(QuicConnectionTest, ReceivedEntropyHashCalculation) { | 2389 TEST_F(QuicConnectionTest, ReceivedEntropyHashCalculation) { |
| 2365 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillRepeatedly(Return(true)); | 2390 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillRepeatedly(Return(true)); |
| 2366 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2391 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2367 ProcessDataPacket(1, 1, kEntropyFlag); | 2392 ProcessDataPacket(1, 1, kEntropyFlag); |
| 2368 ProcessDataPacket(4, 1, kEntropyFlag); | 2393 ProcessDataPacket(4, 1, kEntropyFlag); |
| 2369 ProcessDataPacket(3, 1, !kEntropyFlag); | 2394 ProcessDataPacket(3, 1, !kEntropyFlag); |
| 2370 ProcessDataPacket(7, 1, kEntropyFlag); | 2395 ProcessDataPacket(7, 1, kEntropyFlag); |
| 2371 EXPECT_EQ(146u, outgoing_ack()->received_info.entropy_hash); | 2396 EXPECT_EQ(146u, outgoing_ack()->received_info.entropy_hash); |
| 2372 } | 2397 } |
| 2373 | 2398 |
| 2374 TEST_F(QuicConnectionTest, UpdateEntropyForReceivedPackets) { | 2399 TEST_F(QuicConnectionTest, UpdateEntropyForReceivedPackets) { |
| 2375 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillRepeatedly(Return(true)); | 2400 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillRepeatedly(Return(true)); |
| 2376 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2401 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2377 ProcessDataPacket(1, 1, kEntropyFlag); | 2402 ProcessDataPacket(1, 1, kEntropyFlag); |
| 2378 ProcessDataPacket(5, 1, kEntropyFlag); | 2403 ProcessDataPacket(5, 1, kEntropyFlag); |
| 2379 ProcessDataPacket(4, 1, !kEntropyFlag); | 2404 ProcessDataPacket(4, 1, !kEntropyFlag); |
| 2380 EXPECT_EQ(34u, outgoing_ack()->received_info.entropy_hash); | 2405 EXPECT_EQ(34u, outgoing_ack()->received_info.entropy_hash); |
| 2381 // Make 4th packet my least unacked, and update entropy for 2, 3 packets. | 2406 // Make 4th packet my least unacked, and update entropy for 2, 3 packets. |
| 2382 QuicAckFrame ack(0, QuicTime::Zero(), 4); | 2407 QuicAckFrame ack(0, QuicTime::Zero(), 4); |
| 2383 QuicPacketEntropyHash kRandomEntropyHash = 129u; | 2408 QuicPacketEntropyHash kRandomEntropyHash = 129u; |
| 2384 ack.sent_info.entropy_hash = kRandomEntropyHash; | 2409 ack.sent_info.entropy_hash = kRandomEntropyHash; |
| 2385 creator_.set_sequence_number(5); | 2410 creator_.set_sequence_number(5); |
| 2386 QuicPacketEntropyHash six_packet_entropy_hash = 0; | 2411 QuicPacketEntropyHash six_packet_entropy_hash = 0; |
| 2387 if (ProcessAckPacket(&ack, true)) { | 2412 if (ProcessAckPacket(&ack, true)) { |
| 2388 six_packet_entropy_hash = 1 << 6; | 2413 six_packet_entropy_hash = 1 << 6; |
| 2389 } | 2414 } |
| 2390 | 2415 |
| 2391 EXPECT_EQ((kRandomEntropyHash + (1 << 5) + six_packet_entropy_hash), | 2416 EXPECT_EQ((kRandomEntropyHash + (1 << 5) + six_packet_entropy_hash), |
| 2392 outgoing_ack()->received_info.entropy_hash); | 2417 outgoing_ack()->received_info.entropy_hash); |
| 2393 } | 2418 } |
| 2394 | 2419 |
| 2395 TEST_F(QuicConnectionTest, UpdateEntropyHashUptoCurrentPacket) { | 2420 TEST_F(QuicConnectionTest, UpdateEntropyHashUptoCurrentPacket) { |
| 2396 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillRepeatedly(Return(true)); | 2421 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillRepeatedly(Return(true)); |
| 2397 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2422 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2398 ProcessDataPacket(1, 1, kEntropyFlag); | 2423 ProcessDataPacket(1, 1, kEntropyFlag); |
| 2399 ProcessDataPacket(5, 1, !kEntropyFlag); | 2424 ProcessDataPacket(5, 1, !kEntropyFlag); |
| 2400 ProcessDataPacket(22, 1, kEntropyFlag); | 2425 ProcessDataPacket(22, 1, kEntropyFlag); |
| 2401 EXPECT_EQ(66u, outgoing_ack()->received_info.entropy_hash); | 2426 EXPECT_EQ(66u, outgoing_ack()->received_info.entropy_hash); |
| 2402 creator_.set_sequence_number(22); | 2427 creator_.set_sequence_number(22); |
| 2403 QuicPacketEntropyHash kRandomEntropyHash = 85u; | 2428 QuicPacketEntropyHash kRandomEntropyHash = 85u; |
| 2404 // Current packet is the least unacked packet. | 2429 // Current packet is the least unacked packet. |
| 2405 QuicAckFrame ack(0, QuicTime::Zero(), 23); | 2430 QuicAckFrame ack(0, QuicTime::Zero(), 23); |
| 2406 ack.sent_info.entropy_hash = kRandomEntropyHash; | 2431 ack.sent_info.entropy_hash = kRandomEntropyHash; |
| 2407 QuicPacketEntropyHash ack_entropy_hash = ProcessAckPacket(&ack, true); | 2432 QuicPacketEntropyHash ack_entropy_hash = ProcessAckPacket(&ack, true); |
| 2408 EXPECT_EQ((kRandomEntropyHash + ack_entropy_hash), | 2433 EXPECT_EQ((kRandomEntropyHash + ack_entropy_hash), |
| 2409 outgoing_ack()->received_info.entropy_hash); | 2434 outgoing_ack()->received_info.entropy_hash); |
| 2410 ProcessDataPacket(25, 1, kEntropyFlag); | 2435 ProcessDataPacket(25, 1, kEntropyFlag); |
| 2411 EXPECT_EQ((kRandomEntropyHash + ack_entropy_hash + (1 << (25 % 8))), | 2436 EXPECT_EQ((kRandomEntropyHash + ack_entropy_hash + (1 << (25 % 8))), |
| 2412 outgoing_ack()->received_info.entropy_hash); | 2437 outgoing_ack()->received_info.entropy_hash); |
| 2413 } | 2438 } |
| 2414 | 2439 |
| 2415 TEST_F(QuicConnectionTest, EntropyCalculationForTruncatedAck) { | 2440 TEST_F(QuicConnectionTest, EntropyCalculationForTruncatedAck) { |
| 2416 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillRepeatedly(Return(true)); | 2441 EXPECT_CALL(visitor_, OnStreamFrames(_)).WillRepeatedly(Return(true)); |
| 2417 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2442 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2418 QuicPacketEntropyHash entropy[51]; | 2443 QuicPacketEntropyHash entropy[51]; |
| 2419 entropy[0] = 0; | 2444 entropy[0] = 0; |
| 2420 for (int i = 1; i < 51; ++i) { | 2445 for (int i = 1; i < 51; ++i) { |
| 2421 bool should_send = i % 10 != 0; | 2446 bool should_send = i % 10 != 0; |
| 2422 bool entropy_flag = (i & (i - 1)) != 0; | 2447 bool entropy_flag = (i & (i - 1)) != 0; |
| 2423 if (!should_send) { | 2448 if (!should_send) { |
| 2424 entropy[i] = entropy[i - 1]; | 2449 entropy[i] = entropy[i - 1]; |
| 2425 continue; | 2450 continue; |
| 2426 } | 2451 } |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2531 | 2556 |
| 2532 // Now force another packet. The connection should transition into | 2557 // Now force another packet. The connection should transition into |
| 2533 // NEGOTIATED_VERSION state and tell the packet creator to StopSendingVersion. | 2558 // NEGOTIATED_VERSION state and tell the packet creator to StopSendingVersion. |
| 2534 header.public_header.version_flag = false; | 2559 header.public_header.version_flag = false; |
| 2535 QuicFrames frames; | 2560 QuicFrames frames; |
| 2536 QuicFrame frame(&frame1_); | 2561 QuicFrame frame(&frame1_); |
| 2537 frames.push_back(frame); | 2562 frames.push_back(frame); |
| 2538 scoped_ptr<QuicPacket> packet( | 2563 scoped_ptr<QuicPacket> packet( |
| 2539 framer_.BuildUnsizedDataPacket(header, frames).packet); | 2564 framer_.BuildUnsizedDataPacket(header, frames).packet); |
| 2540 encrypted.reset(framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); | 2565 encrypted.reset(framer_.EncryptPacket(ENCRYPTION_NONE, 12, *packet)); |
| 2541 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).Times(1); | 2566 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); |
| 2542 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2567 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2543 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 2568 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); |
| 2544 | 2569 |
| 2545 ASSERT_FALSE(QuicPacketCreatorPeer::SendVersionInPacket( | 2570 ASSERT_FALSE(QuicPacketCreatorPeer::SendVersionInPacket( |
| 2546 QuicConnectionPeer::GetPacketCreator(&connection_))); | 2571 QuicConnectionPeer::GetPacketCreator(&connection_))); |
| 2547 } | 2572 } |
| 2548 | 2573 |
| 2549 TEST_F(QuicConnectionTest, BadVersionNegotiation) { | 2574 TEST_F(QuicConnectionTest, BadVersionNegotiation) { |
| 2550 QuicPacketHeader header; | 2575 QuicPacketHeader header; |
| 2551 header.public_header.guid = guid_; | 2576 header.public_header.guid = guid_; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2592 connection_.OnRetransmissionTimeout(); | 2617 connection_.OnRetransmissionTimeout(); |
| 2593 | 2618 |
| 2594 // Retransmit due to explicit nacks | 2619 // Retransmit due to explicit nacks |
| 2595 QuicAckFrame nack_three(4, QuicTime::Zero(), 0); | 2620 QuicAckFrame nack_three(4, QuicTime::Zero(), 0); |
| 2596 nack_three.received_info.missing_packets.insert(3); | 2621 nack_three.received_info.missing_packets.insert(3); |
| 2597 nack_three.received_info.entropy_hash = | 2622 nack_three.received_info.entropy_hash = |
| 2598 QuicConnectionPeer::GetSentEntropyHash(&connection_, 4) ^ | 2623 QuicConnectionPeer::GetSentEntropyHash(&connection_, 4) ^ |
| 2599 QuicConnectionPeer::GetSentEntropyHash(&connection_, 3) ^ | 2624 QuicConnectionPeer::GetSentEntropyHash(&connection_, 3) ^ |
| 2600 QuicConnectionPeer::GetSentEntropyHash(&connection_, 2); | 2625 QuicConnectionPeer::GetSentEntropyHash(&connection_, 2); |
| 2601 QuicFrame frame(&nack_three); | 2626 QuicFrame frame(&nack_three); |
| 2602 EXPECT_CALL(visitor_, OnAck(_)); | |
| 2603 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1); | 2627 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1); |
| 2604 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); | 2628 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); |
| 2605 EXPECT_CALL(visitor_, OnCanWrite()).Times(3).WillRepeatedly(Return(true)); | 2629 EXPECT_CALL(visitor_, OnCanWrite()).Times(3).WillRepeatedly(Return(true)); |
| 2606 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2630 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2607 | 2631 |
| 2608 ProcessFramePacket(frame); | 2632 ProcessFramePacket(frame); |
| 2609 ProcessFramePacket(frame); | 2633 ProcessFramePacket(frame); |
| 2610 ProcessFramePacket(frame); | 2634 ProcessFramePacket(frame); |
| 2611 | 2635 |
| 2612 EXPECT_CALL(*send_algorithm_, SmoothedRtt()).WillOnce( | 2636 EXPECT_CALL(*send_algorithm_, SmoothedRtt()).WillOnce( |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2688 QuicFrames frames; | 2712 QuicFrames frames; |
| 2689 frames.push_back(stream_frame); | 2713 frames.push_back(stream_frame); |
| 2690 frames.push_back(close_frame); | 2714 frames.push_back(close_frame); |
| 2691 scoped_ptr<QuicPacket> packet( | 2715 scoped_ptr<QuicPacket> packet( |
| 2692 framer_.BuildUnsizedDataPacket(header_, frames).packet); | 2716 framer_.BuildUnsizedDataPacket(header_, frames).packet); |
| 2693 EXPECT_TRUE(NULL != packet.get()); | 2717 EXPECT_TRUE(NULL != packet.get()); |
| 2694 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPacket( | 2718 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPacket( |
| 2695 ENCRYPTION_NONE, 1, *packet)); | 2719 ENCRYPTION_NONE, 1, *packet)); |
| 2696 | 2720 |
| 2697 EXPECT_CALL(visitor_, ConnectionClose(QUIC_PEER_GOING_AWAY, true)); | 2721 EXPECT_CALL(visitor_, ConnectionClose(QUIC_PEER_GOING_AWAY, true)); |
| 2698 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).Times(0); | 2722 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(0); |
| 2699 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2723 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2700 | 2724 |
| 2701 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 2725 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); |
| 2702 } | 2726 } |
| 2703 | 2727 |
| 2704 TEST_F(QuicConnectionTest, SelectMutualVersion) { | 2728 TEST_F(QuicConnectionTest, SelectMutualVersion) { |
| 2705 // Set the connection to speak the lowest quic version. | 2729 // Set the connection to speak the lowest quic version. |
| 2706 connection_.set_version(QuicVersionMin()); | 2730 connection_.set_version(QuicVersionMin()); |
| 2707 EXPECT_EQ(QuicVersionMin(), connection_.version()); | 2731 EXPECT_EQ(QuicVersionMin(), connection_.version()); |
| 2708 | 2732 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2772 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2796 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2773 | 2797 |
| 2774 // Create a delegate which we expect to be called. | 2798 // Create a delegate which we expect to be called. |
| 2775 MockAckNotifierDelegate delegate; | 2799 MockAckNotifierDelegate delegate; |
| 2776 EXPECT_CALL(delegate, OnAckNotification()).Times(1);; | 2800 EXPECT_CALL(delegate, OnAckNotification()).Times(1);; |
| 2777 | 2801 |
| 2778 // Send some data, which will register the delegate to be notified. | 2802 // Send some data, which will register the delegate to be notified. |
| 2779 connection_.SendStreamDataAndNotifyWhenAcked(1, "foo", 0, !kFin, &delegate); | 2803 connection_.SendStreamDataAndNotifyWhenAcked(1, "foo", 0, !kFin, &delegate); |
| 2780 | 2804 |
| 2781 // Process an ACK from the server which should trigger the callback. | 2805 // Process an ACK from the server which should trigger the callback. |
| 2782 EXPECT_CALL(visitor_, OnAck(_)).Times(1); | |
| 2783 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1); | 2806 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1); |
| 2784 QuicAckFrame frame(1, QuicTime::Zero(), 0); | 2807 QuicAckFrame frame(1, QuicTime::Zero(), 0); |
| 2785 ProcessAckPacket(&frame, true); | 2808 ProcessAckPacket(&frame, true); |
| 2786 } | 2809 } |
| 2787 | 2810 |
| 2788 TEST_F(QuicConnectionTest, AckNotifierFailToTriggerCallback) { | 2811 TEST_F(QuicConnectionTest, AckNotifierFailToTriggerCallback) { |
| 2789 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2812 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2790 | 2813 |
| 2791 // Create a delegate which we don't expect to be called. | 2814 // Create a delegate which we don't expect to be called. |
| 2792 MockAckNotifierDelegate delegate; | 2815 MockAckNotifierDelegate delegate; |
| 2793 EXPECT_CALL(delegate, OnAckNotification()).Times(0);; | 2816 EXPECT_CALL(delegate, OnAckNotification()).Times(0);; |
| 2794 | 2817 |
| 2795 EXPECT_CALL(visitor_, OnAck(_)).Times(1); | |
| 2796 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(2); | 2818 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(2); |
| 2797 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); | 2819 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); |
| 2798 | 2820 |
| 2799 // Send some data, which will register the delegate to be notified. This will | 2821 // Send some data, which will register the delegate to be notified. This will |
| 2800 // not be ACKed and so the delegate should never be called. | 2822 // not be ACKed and so the delegate should never be called. |
| 2801 connection_.SendStreamDataAndNotifyWhenAcked(1, "foo", 0, !kFin, &delegate); | 2823 connection_.SendStreamDataAndNotifyWhenAcked(1, "foo", 0, !kFin, &delegate); |
| 2802 | 2824 |
| 2803 // Send some other data which we will ACK. | 2825 // Send some other data which we will ACK. |
| 2804 connection_.SendStreamData(1, "foo", 0, !kFin); | 2826 connection_.SendStreamData(1, "foo", 0, !kFin); |
| 2805 connection_.SendStreamData(1, "bar", 0, !kFin); | 2827 connection_.SendStreamData(1, "bar", 0, !kFin); |
| 2806 | 2828 |
| 2807 // Now we receive ACK for packets 2 and 3, but importantly missing packet 1 | 2829 // Now we receive ACK for packets 2 and 3, but importantly missing packet 1 |
| 2808 // which we registered to be notified about. | 2830 // which we registered to be notified about. |
| 2809 QuicAckFrame frame(3, QuicTime::Zero(), 0); | 2831 QuicAckFrame frame(3, QuicTime::Zero(), 0); |
| 2810 frame.received_info.missing_packets.insert(1); | 2832 frame.received_info.missing_packets.insert(1); |
| 2811 ProcessAckPacket(&frame, true); | 2833 ProcessAckPacket(&frame, true); |
| 2812 } | 2834 } |
| 2813 | 2835 |
| 2814 TEST_F(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) { | 2836 TEST_F(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) { |
| 2815 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2837 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2816 | 2838 |
| 2817 // Create a delegate which we expect to be called. | 2839 // Create a delegate which we expect to be called. |
| 2818 MockAckNotifierDelegate delegate; | 2840 MockAckNotifierDelegate delegate; |
| 2819 EXPECT_CALL(delegate, OnAckNotification()).Times(1);; | 2841 EXPECT_CALL(delegate, OnAckNotification()).Times(1);; |
| 2820 | 2842 |
| 2821 // OnAck called twice: once with missing packet, once after retransmit. | |
| 2822 EXPECT_CALL(visitor_, OnAck(_)).Times(2); | |
| 2823 | |
| 2824 // In total expect ACKs for all 4 packets. | 2843 // In total expect ACKs for all 4 packets. |
| 2825 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(4); | 2844 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(4); |
| 2826 | 2845 |
| 2827 // We will lose the second packet. | 2846 // We will lose the second packet. |
| 2828 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); | 2847 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); |
| 2829 | 2848 |
| 2830 // Send four packets, and register to be notified on ACK of packet 2. | 2849 // Send four packets, and register to be notified on ACK of packet 2. |
| 2831 connection_.SendStreamData(1, "foo", 0, !kFin); | 2850 connection_.SendStreamData(1, "foo", 0, !kFin); |
| 2832 connection_.SendStreamDataAndNotifyWhenAcked(1, "bar", 0, !kFin, &delegate); | 2851 connection_.SendStreamDataAndNotifyWhenAcked(1, "bar", 0, !kFin, &delegate); |
| 2833 connection_.SendStreamData(1, "baz", 0, !kFin); | 2852 connection_.SendStreamData(1, "baz", 0, !kFin); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 2856 // ACK) triggers notification on our end. | 2875 // ACK) triggers notification on our end. |
| 2857 TEST_F(QuicConnectionTest, AckNotifierCallbackAfterFECRecovery) { | 2876 TEST_F(QuicConnectionTest, AckNotifierCallbackAfterFECRecovery) { |
| 2858 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2877 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2859 EXPECT_CALL(visitor_, OnCanWrite()).Times(1).WillOnce(Return(true)); | 2878 EXPECT_CALL(visitor_, OnCanWrite()).Times(1).WillOnce(Return(true)); |
| 2860 | 2879 |
| 2861 // Create a delegate which we expect to be called. | 2880 // Create a delegate which we expect to be called. |
| 2862 MockAckNotifierDelegate delegate; | 2881 MockAckNotifierDelegate delegate; |
| 2863 EXPECT_CALL(delegate, OnAckNotification()).Times(1);; | 2882 EXPECT_CALL(delegate, OnAckNotification()).Times(1);; |
| 2864 | 2883 |
| 2865 // Expect ACKs for 1 packet. | 2884 // Expect ACKs for 1 packet. |
| 2866 EXPECT_CALL(visitor_, OnAck(_)).Times(1); | |
| 2867 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1); | 2885 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1); |
| 2868 | 2886 |
| 2869 // Send one packet, and register to be notified on ACK. | 2887 // Send one packet, and register to be notified on ACK. |
| 2870 connection_.SendStreamDataAndNotifyWhenAcked(1, "foo", 0, !kFin, &delegate); | 2888 connection_.SendStreamDataAndNotifyWhenAcked(1, "foo", 0, !kFin, &delegate); |
| 2871 | 2889 |
| 2872 // Ack packet gets dropped, but we receive an FEC packet that covers it. | 2890 // Ack packet gets dropped, but we receive an FEC packet that covers it. |
| 2873 // Should recover the Ack packet and trigger the notification callback. | 2891 // Should recover the Ack packet and trigger the notification callback. |
| 2874 QuicFrames frames; | 2892 QuicFrames frames; |
| 2875 | 2893 |
| 2876 QuicAckFrame ack_frame(1, QuicTime::Zero(), 0); | 2894 QuicAckFrame ack_frame(1, QuicTime::Zero(), 0); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2955 scoped_ptr<MockQuicConnectionDebugVisitor> | 2973 scoped_ptr<MockQuicConnectionDebugVisitor> |
| 2956 debug_visitor(new StrictMock<MockQuicConnectionDebugVisitor>); | 2974 debug_visitor(new StrictMock<MockQuicConnectionDebugVisitor>); |
| 2957 connection_.set_debug_visitor(debug_visitor.get()); | 2975 connection_.set_debug_visitor(debug_visitor.get()); |
| 2958 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1); | 2976 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1); |
| 2959 connection_.OnPacketHeader(header); | 2977 connection_.OnPacketHeader(header); |
| 2960 } | 2978 } |
| 2961 | 2979 |
| 2962 } // namespace | 2980 } // namespace |
| 2963 } // namespace test | 2981 } // namespace test |
| 2964 } // namespace net | 2982 } // namespace net |
| OLD | NEW |