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

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

Issue 1660593004: Landing Recent QUIC changes until 01/28/2016 18:41 UTC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Final_0202
Patch Set: Created 4 years, 10 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
« no previous file with comments | « net/quic/quic_connection.cc ('k') | net/quic/quic_flags.h » ('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 <ostream> 7 #include <ostream>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 } 451 }
452 452
453 void SendPacket(EncryptionLevel level, 453 void SendPacket(EncryptionLevel level,
454 QuicPathId path_id, 454 QuicPathId path_id,
455 QuicPacketNumber packet_number, 455 QuicPacketNumber packet_number,
456 QuicPacket* packet, 456 QuicPacket* packet,
457 QuicPacketEntropyHash entropy_hash, 457 QuicPacketEntropyHash entropy_hash,
458 HasRetransmittableData retransmittable, 458 HasRetransmittableData retransmittable,
459 bool has_ack, 459 bool has_ack,
460 bool has_pending_frames) { 460 bool has_pending_frames) {
461 QuicFrames* retransmittable_frames =
462 retransmittable == HAS_RETRANSMITTABLE_DATA ? new QuicFrames()
463 : nullptr;
464 char buffer[kMaxPacketSize]; 461 char buffer[kMaxPacketSize];
465 size_t encrypted_length = 462 size_t encrypted_length =
466 QuicConnectionPeer::GetFramer(this)->EncryptPayload( 463 QuicConnectionPeer::GetFramer(this)->EncryptPayload(
467 ENCRYPTION_NONE, path_id, packet_number, *packet, buffer, 464 ENCRYPTION_NONE, path_id, packet_number, *packet, buffer,
468 kMaxPacketSize); 465 kMaxPacketSize);
469 delete packet; 466 delete packet;
470 SerializedPacket serialized_packet( 467 SerializedPacket serialized_packet(
471 kDefaultPathId, packet_number, PACKET_6BYTE_PACKET_NUMBER, buffer, 468 kDefaultPathId, packet_number, PACKET_6BYTE_PACKET_NUMBER,
472 encrypted_length, false, entropy_hash, retransmittable_frames, false, 469 new QuicEncryptedPacket(buffer, encrypted_length, false), entropy_hash,
473 NOT_HANDSHAKE, has_ack, has_pending_frames, ENCRYPTION_NONE); 470 has_ack, has_pending_frames);
471 if (retransmittable == HAS_RETRANSMITTABLE_DATA) {
472 serialized_packet.retransmittable_frames.push_back(
473 QuicFrame(new QuicStreamFrame()));
474 }
474 OnSerializedPacket(&serialized_packet); 475 OnSerializedPacket(&serialized_packet);
475 } 476 }
476 477
477 QuicConsumedData SendStreamDataWithString( 478 QuicConsumedData SendStreamDataWithString(
478 QuicStreamId id, 479 QuicStreamId id,
479 StringPiece data, 480 StringPiece data,
480 QuicStreamOffset offset, 481 QuicStreamOffset offset,
481 bool fin, 482 bool fin,
482 QuicAckListenerInterface* listener) { 483 QuicAckListenerInterface* listener) {
483 return SendStreamDataWithStringHelper(id, data, offset, fin, 484 return SendStreamDataWithStringHelper(id, data, offset, fin,
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 EXPECT_CALL(visitor_, WillingAndAbleToWrite()).Times(AnyNumber()); 723 EXPECT_CALL(visitor_, WillingAndAbleToWrite()).Times(AnyNumber());
723 EXPECT_CALL(visitor_, HasPendingHandshake()).Times(AnyNumber()); 724 EXPECT_CALL(visitor_, HasPendingHandshake()).Times(AnyNumber());
724 EXPECT_CALL(visitor_, OnCanWrite()).Times(AnyNumber()); 725 EXPECT_CALL(visitor_, OnCanWrite()).Times(AnyNumber());
725 EXPECT_CALL(visitor_, PostProcessAfterData()).Times(AnyNumber()); 726 EXPECT_CALL(visitor_, PostProcessAfterData()).Times(AnyNumber());
726 EXPECT_CALL(visitor_, HasOpenDynamicStreams()) 727 EXPECT_CALL(visitor_, HasOpenDynamicStreams())
727 .WillRepeatedly(Return(false)); 728 .WillRepeatedly(Return(false));
728 EXPECT_CALL(visitor_, OnCongestionWindowChange(_)).Times(AnyNumber()); 729 EXPECT_CALL(visitor_, OnCongestionWindowChange(_)).Times(AnyNumber());
729 730
730 EXPECT_CALL(*loss_algorithm_, GetLossTimeout()) 731 EXPECT_CALL(*loss_algorithm_, GetLossTimeout())
731 .WillRepeatedly(Return(QuicTime::Zero())); 732 .WillRepeatedly(Return(QuicTime::Zero()));
732 if (FLAGS_quic_general_loss_algorithm) { 733 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _)).Times(AnyNumber());
733 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _))
734 .Times(AnyNumber());
735 } else {
736 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
737 .WillRepeatedly(Return(PacketNumberSet()));
738 }
739 // TODO(ianswett): Fix QuicConnectionTests so they don't attempt to write 734 // TODO(ianswett): Fix QuicConnectionTests so they don't attempt to write
740 // non-crypto stream data at ENCRYPTION_NONE. 735 // non-crypto stream data at ENCRYPTION_NONE.
741 FLAGS_quic_never_write_unencrypted_data = false; 736 FLAGS_quic_never_write_unencrypted_data = false;
742 FLAGS_quic_no_unencrypted_fec = false; 737 FLAGS_quic_no_unencrypted_fec = false;
743 } 738 }
744 739
745 QuicVersion version() { return GetParam().version; } 740 QuicVersion version() { return GetParam().version; }
746 741
747 QuicAckFrame* outgoing_ack() { 742 QuicAckFrame* outgoing_ack() {
748 QuicConnectionPeer::PopulateAckFrame(&connection_, &ack_); 743 QuicConnectionPeer::PopulateAckFrame(&connection_, &ack_);
(...skipping 20 matching lines...) Expand all
769 } 764 }
770 765
771 QuicPacketEntropyHash ProcessFramePacket(QuicFrame frame) { 766 QuicPacketEntropyHash ProcessFramePacket(QuicFrame frame) {
772 QuicFrames frames; 767 QuicFrames frames;
773 frames.push_back(QuicFrame(frame)); 768 frames.push_back(QuicFrame(frame));
774 QuicPacketCreatorPeer::SetSendVersionInPacket( 769 QuicPacketCreatorPeer::SetSendVersionInPacket(
775 &peer_creator_, connection_.perspective() == Perspective::IS_SERVER); 770 &peer_creator_, connection_.perspective() == Perspective::IS_SERVER);
776 771
777 char buffer[kMaxPacketSize]; 772 char buffer[kMaxPacketSize];
778 SerializedPacket serialized_packet = 773 SerializedPacket serialized_packet =
779 peer_creator_.SerializeAllFrames(frames, buffer, kMaxPacketSize); 774 QuicPacketCreatorPeer::SerializeAllFrames(&peer_creator_, frames,
775 buffer, kMaxPacketSize);
780 scoped_ptr<QuicEncryptedPacket> encrypted(serialized_packet.packet); 776 scoped_ptr<QuicEncryptedPacket> encrypted(serialized_packet.packet);
781 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted); 777 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted);
782 return serialized_packet.entropy_hash; 778 return serialized_packet.entropy_hash;
783 } 779 }
784 780
785 QuicPacketEntropyHash ProcessFramePacketAtLevel(QuicPathId path_id, 781 QuicPacketEntropyHash ProcessFramePacketAtLevel(QuicPathId path_id,
786 QuicPacketNumber number, 782 QuicPacketNumber number,
787 QuicFrame frame, 783 QuicFrame frame,
788 EncryptionLevel level) { 784 EncryptionLevel level) {
789 QuicPacketHeader header; 785 QuicPacketHeader header;
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
1367 1363
1368 QuicAckFrame frame = InitAckFrame(num_packets); 1364 QuicAckFrame frame = InitAckFrame(num_packets);
1369 PacketNumberSet lost_packets; 1365 PacketNumberSet lost_packets;
1370 // Create an ack with 256 nacks, none adjacent to one another. 1366 // Create an ack with 256 nacks, none adjacent to one another.
1371 for (QuicPacketNumber i = 1; i <= 256; ++i) { 1367 for (QuicPacketNumber i = 1; i <= 256; ++i) {
1372 NackPacket(i * 2, &frame); 1368 NackPacket(i * 2, &frame);
1373 if (i < 256) { // Last packet is nacked, but not lost. 1369 if (i < 256) { // Last packet is nacked, but not lost.
1374 lost_packets.insert(i * 2); 1370 lost_packets.insert(i * 2);
1375 } 1371 }
1376 } 1372 }
1377 if (FLAGS_quic_general_loss_algorithm) { 1373 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _));
1378 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _));
1379 } else {
1380 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
1381 .WillOnce(Return(lost_packets));
1382 }
1383 EXPECT_CALL(entropy_calculator_, EntropyHash(511)) 1374 EXPECT_CALL(entropy_calculator_, EntropyHash(511))
1384 .WillOnce(Return(static_cast<QuicPacketEntropyHash>(0))); 1375 .WillOnce(Return(static_cast<QuicPacketEntropyHash>(0)));
1385 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 1376 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
1386 ProcessAckPacket(&frame); 1377 ProcessAckPacket(&frame);
1387 1378
1388 // A truncated ack will not have the true largest observed. 1379 // A truncated ack will not have the true largest observed.
1389 EXPECT_GT(num_packets, manager_->largest_observed()); 1380 EXPECT_GT(num_packets, manager_->largest_observed());
1390 1381
1391 AckPacket(192, &frame); 1382 AckPacket(192, &frame);
1392 1383
1393 // Removing one missing packet allows us to ack 192 and one more range, but 1384 // Removing one missing packet allows us to ack 192 and one more range, but
1394 // 192 has already been declared lost, so it doesn't register as an ack. 1385 // 192 has already been declared lost, so it doesn't register as an ack.
1395 if (FLAGS_quic_general_loss_algorithm) { 1386 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _));
1396 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _));
1397 } else {
1398 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
1399 .WillOnce(Return(PacketNumberSet()));
1400 }
1401 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 1387 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
1402 ProcessAckPacket(&frame); 1388 ProcessAckPacket(&frame);
1403 EXPECT_EQ(num_packets, manager_->largest_observed()); 1389 EXPECT_EQ(num_packets, manager_->largest_observed());
1404 } 1390 }
1405 1391
1406 TEST_P(QuicConnectionTest, AckReceiptCausesAckSendBadEntropy) { 1392 TEST_P(QuicConnectionTest, AckReceiptCausesAckSendBadEntropy) {
1407 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1393 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1408 1394
1409 ProcessPacket(kDefaultPathId, 1); 1395 ProcessPacket(kDefaultPathId, 1);
1410 // Delay sending, then queue up an ack. 1396 // Delay sending, then queue up an ack.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1467 1453
1468 QuicPacketNumber original; 1454 QuicPacketNumber original;
1469 QuicByteCount packet_size; 1455 QuicByteCount packet_size;
1470 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 1456 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
1471 .WillOnce( 1457 .WillOnce(
1472 DoAll(SaveArg<2>(&original), SaveArg<3>(&packet_size), Return(true))); 1458 DoAll(SaveArg<2>(&original), SaveArg<3>(&packet_size), Return(true)));
1473 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); 1459 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr);
1474 QuicAckFrame frame = InitAckFrame(original); 1460 QuicAckFrame frame = InitAckFrame(original);
1475 NackPacket(original, &frame); 1461 NackPacket(original, &frame);
1476 // First nack triggers early retransmit. 1462 // First nack triggers early retransmit.
1477 if (FLAGS_quic_general_loss_algorithm) { 1463 SendAlgorithmInterface::CongestionVector lost_packets;
1478 SendAlgorithmInterface::CongestionVector lost_packets; 1464 lost_packets.push_back(std::make_pair(1, kMaxPacketSize));
1479 lost_packets.push_back(std::make_pair(1, kMaxPacketSize)); 1465 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _))
1480 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _)) 1466 .WillOnce(SetArgPointee<3>(lost_packets));
1481 .WillOnce(SetArgPointee<3>(lost_packets));
1482 } else {
1483 PacketNumberSet lost_packets;
1484 lost_packets.insert(1);
1485 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
1486 .WillOnce(Return(lost_packets));
1487 }
1488 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 1467 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
1489 QuicPacketNumber retransmission; 1468 QuicPacketNumber retransmission;
1490 EXPECT_CALL(*send_algorithm_, 1469 EXPECT_CALL(*send_algorithm_,
1491 OnPacketSent(_, _, _, packet_size - kQuicVersionSize, _)) 1470 OnPacketSent(_, _, _, packet_size - kQuicVersionSize, _))
1492 .WillOnce(DoAll(SaveArg<2>(&retransmission), Return(true))); 1471 .WillOnce(DoAll(SaveArg<2>(&retransmission), Return(true)));
1493 1472
1494 ProcessAckPacket(&frame); 1473 ProcessAckPacket(&frame);
1495 1474
1496 QuicAckFrame frame2 = InitAckFrame(retransmission); 1475 QuicAckFrame frame2 = InitAckFrame(retransmission);
1497 NackPacket(original, &frame2); 1476 NackPacket(original, &frame2);
1498 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 1477 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
1499 if (FLAGS_quic_general_loss_algorithm) { 1478 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _));
1500 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _));
1501 } else {
1502 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
1503 .WillOnce(Return(PacketNumberSet()));
1504 }
1505 ProcessAckPacket(&frame2); 1479 ProcessAckPacket(&frame2);
1506 1480
1507 // Now if the peer sends an ack which still reports the retransmitted packet 1481 // Now if the peer sends an ack which still reports the retransmitted packet
1508 // as missing, that will bundle an ack with data after two acks in a row 1482 // as missing, that will bundle an ack with data after two acks in a row
1509 // indicate the high water mark needs to be raised. 1483 // indicate the high water mark needs to be raised.
1510 EXPECT_CALL(*send_algorithm_, 1484 EXPECT_CALL(*send_algorithm_,
1511 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)); 1485 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA));
1512 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, nullptr); 1486 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, nullptr);
1513 // No ack sent. 1487 // No ack sent.
1514 EXPECT_EQ(1u, writer_->frame_count()); 1488 EXPECT_EQ(1u, writer_->frame_count());
1515 EXPECT_EQ(1u, writer_->stream_frames().size()); 1489 EXPECT_EQ(1u, writer_->stream_frames().size());
1516 1490
1517 // No more packet loss for the rest of the test. 1491 // No more packet loss for the rest of the test.
1518 if (FLAGS_quic_general_loss_algorithm) { 1492 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _)).Times(AnyNumber());
1519 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _)).Times(AnyNumber());
1520 } else {
1521 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
1522 .WillRepeatedly(Return(PacketNumberSet()));
1523 }
1524 ProcessAckPacket(&frame2); 1493 ProcessAckPacket(&frame2);
1525 EXPECT_CALL(*send_algorithm_, 1494 EXPECT_CALL(*send_algorithm_,
1526 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)); 1495 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA));
1527 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, nullptr); 1496 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, nullptr);
1528 // Ack bundled. 1497 // Ack bundled.
1529 EXPECT_EQ(3u, writer_->frame_count()); 1498 EXPECT_EQ(3u, writer_->frame_count());
1530 EXPECT_EQ(1u, writer_->stream_frames().size()); 1499 EXPECT_EQ(1u, writer_->stream_frames().size());
1531 EXPECT_FALSE(writer_->ack_frames().empty()); 1500 EXPECT_FALSE(writer_->ack_frames().empty());
1532 1501
1533 // But an ack with no missing packets will not send an ack. 1502 // But an ack with no missing packets will not send an ack.
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
1990 // stream frame size, which are absent in the retransmission. 1959 // stream frame size, which are absent in the retransmission.
1991 size_t retransmitted_packet = protected_packet - 3; 1960 size_t retransmitted_packet = protected_packet - 3;
1992 EXPECT_EQ(protected_packet + retransmitted_packet, 1961 EXPECT_EQ(protected_packet + retransmitted_packet,
1993 QuicSentPacketManagerPeer::GetBytesInFlight(manager_)); 1962 QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1994 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet()); 1963 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet());
1995 1964
1996 // Receive ack for the retransmission. No data should be outstanding. 1965 // Receive ack for the retransmission. No data should be outstanding.
1997 QuicAckFrame ack = InitAckFrame(3); 1966 QuicAckFrame ack = InitAckFrame(3);
1998 NackPacket(1, &ack); 1967 NackPacket(1, &ack);
1999 NackPacket(2, &ack); 1968 NackPacket(2, &ack);
2000 if (FLAGS_quic_general_loss_algorithm) { 1969 SendAlgorithmInterface::CongestionVector lost_packets;
2001 SendAlgorithmInterface::CongestionVector lost_packets; 1970 lost_packets.push_back(std::make_pair(1, kMaxPacketSize));
2002 lost_packets.push_back(std::make_pair(1, kMaxPacketSize)); 1971 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _))
2003 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _)) 1972 .WillOnce(SetArgPointee<3>(lost_packets));
2004 .WillOnce(SetArgPointee<3>(lost_packets));
2005 } else {
2006 PacketNumberSet lost_packets;
2007 lost_packets.insert(1);
2008 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
2009 .WillOnce(Return(lost_packets));
2010 }
2011 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 1973 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
2012 ProcessAckPacket(&ack); 1974 ProcessAckPacket(&ack);
2013 1975
2014 // Ensure the alarm is not set since all packets have been acked or abandoned. 1976 // Ensure the alarm is not set since all packets have been acked or abandoned.
2015 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 1977 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2016 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_)); 1978 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
2017 } 1979 }
2018 1980
2019 TEST_P(QuicConnectionTest, RemoveFECFromInflightOnLossRetransmission) { 1981 TEST_P(QuicConnectionTest, RemoveFECFromInflightOnLossRetransmission) {
2020 EXPECT_TRUE(QuicPacketCreatorPeer::IsFecEnabled(creator_)); 1982 EXPECT_TRUE(QuicPacketCreatorPeer::IsFecEnabled(creator_));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2056 EXPECT_EQ(protected_packet + fec_packet + 4 * unprotected_packet, 2018 EXPECT_EQ(protected_packet + fec_packet + 4 * unprotected_packet,
2057 QuicSentPacketManagerPeer::GetBytesInFlight(manager_)); 2019 QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
2058 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet()); 2020 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet());
2059 2021
2060 // Ack data packets, and NACK FEC packet and one data packet. Triggers 2022 // Ack data packets, and NACK FEC packet and one data packet. Triggers
2061 // NACK-based loss detection of both packets, but only data packet is 2023 // NACK-based loss detection of both packets, but only data packet is
2062 // retransmitted and considered outstanding. 2024 // retransmitted and considered outstanding.
2063 QuicAckFrame ack = InitAckFrame(6); 2025 QuicAckFrame ack = InitAckFrame(6);
2064 NackPacket(2, &ack); 2026 NackPacket(2, &ack);
2065 NackPacket(3, &ack); 2027 NackPacket(3, &ack);
2066 if (FLAGS_quic_general_loss_algorithm) { 2028 SendAlgorithmInterface::CongestionVector lost_packets;
2067 SendAlgorithmInterface::CongestionVector lost_packets; 2029 lost_packets.push_back(std::make_pair(2, kMaxPacketSize));
2068 lost_packets.push_back(std::make_pair(2, kMaxPacketSize)); 2030 lost_packets.push_back(std::make_pair(3, kMaxPacketSize));
2069 lost_packets.push_back(std::make_pair(3, kMaxPacketSize)); 2031 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _))
2070 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _)) 2032 .WillOnce(SetArgPointee<3>(lost_packets));
2071 .WillOnce(SetArgPointee<3>(lost_packets));
2072 } else {
2073 PacketNumberSet lost_packets;
2074 lost_packets.insert(2);
2075 lost_packets.insert(3);
2076 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
2077 .WillOnce(Return(lost_packets));
2078 }
2079 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 2033 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
2080 EXPECT_CALL(*send_algorithm_, 2034 EXPECT_CALL(*send_algorithm_,
2081 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)) 2035 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA))
2082 .Times(1); 2036 .Times(1);
2083 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2037 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2084 ProcessAckPacket(&ack); 2038 ProcessAckPacket(&ack);
2085 // On receiving this ack from the server, the client will no longer send 2039 // On receiving this ack from the server, the client will no longer send
2086 // version number in subsequent packets, including in this retransmission. 2040 // version number in subsequent packets, including in this retransmission.
2087 size_t unprotected_packet_no_version = unprotected_packet - 4; 2041 size_t unprotected_packet_no_version = unprotected_packet - 4;
2088 EXPECT_EQ(unprotected_packet_no_version, 2042 EXPECT_EQ(unprotected_packet_no_version,
2089 QuicSentPacketManagerPeer::GetBytesInFlight(manager_)); 2043 QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
2090 2044
2091 // Receive ack for the retransmission. No data should be outstanding. 2045 // Receive ack for the retransmission. No data should be outstanding.
2092 QuicAckFrame ack2 = InitAckFrame(7); 2046 QuicAckFrame ack2 = InitAckFrame(7);
2093 NackPacket(2, &ack2); 2047 NackPacket(2, &ack2);
2094 NackPacket(3, &ack2); 2048 NackPacket(3, &ack2);
2095 if (FLAGS_quic_general_loss_algorithm) { 2049 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _));
2096 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _));
2097 } else {
2098 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
2099 .WillOnce(Return(PacketNumberSet()));
2100 }
2101 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 2050 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
2102 ProcessAckPacket(&ack2); 2051 ProcessAckPacket(&ack2);
2103 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_)); 2052 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
2104 } 2053 }
2105 2054
2106 TEST_P(QuicConnectionTest, FECRemainsInflightOnTLPOfEarlierData) { 2055 TEST_P(QuicConnectionTest, FECRemainsInflightOnTLPOfEarlierData) {
2107 // This test checks if TLP is sent correctly when a data and an FEC packet 2056 // This test checks if TLP is sent correctly when a data and an FEC packet
2108 // are outstanding. TLP should be sent for the data packet when the 2057 // are outstanding. TLP should be sent for the data packet when the
2109 // retransmission alarm fires. 2058 // retransmission alarm fires.
2110 // Turn on TLP for this test. 2059 // Turn on TLP for this test.
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
2481 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2430 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2482 2431
2483 // Don't lose a packet on an ack, and nothing is retransmitted. 2432 // Don't lose a packet on an ack, and nothing is retransmitted.
2484 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 2433 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
2485 QuicAckFrame ack_one = InitAckFrame(1); 2434 QuicAckFrame ack_one = InitAckFrame(1);
2486 ProcessAckPacket(&ack_one); 2435 ProcessAckPacket(&ack_one);
2487 2436
2488 // Lose a packet and ensure it triggers retransmission. 2437 // Lose a packet and ensure it triggers retransmission.
2489 QuicAckFrame nack_two = InitAckFrame(3); 2438 QuicAckFrame nack_two = InitAckFrame(3);
2490 NackPacket(2, &nack_two); 2439 NackPacket(2, &nack_two);
2491 if (FLAGS_quic_general_loss_algorithm) { 2440 SendAlgorithmInterface::CongestionVector lost_packets;
2492 SendAlgorithmInterface::CongestionVector lost_packets; 2441 lost_packets.push_back(std::make_pair(2, kMaxPacketSize));
2493 lost_packets.push_back(std::make_pair(2, kMaxPacketSize)); 2442 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _))
2494 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _)) 2443 .WillOnce(SetArgPointee<3>(lost_packets));
2495 .WillOnce(SetArgPointee<3>(lost_packets));
2496 } else {
2497 PacketNumberSet lost_packets;
2498 lost_packets.insert(2);
2499 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
2500 .WillOnce(Return(lost_packets));
2501 }
2502 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 2444 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
2503 EXPECT_CALL(*send_algorithm_, 2445 EXPECT_CALL(*send_algorithm_,
2504 OnPacketSent(_, _, _, second_packet_size - kQuicVersionSize, _)) 2446 OnPacketSent(_, _, _, second_packet_size - kQuicVersionSize, _))
2505 .Times(1); 2447 .Times(1);
2506 ProcessAckPacket(&nack_two); 2448 ProcessAckPacket(&nack_two);
2507 } 2449 }
2508 2450
2509 TEST_P(QuicConnectionTest, DoNotSendQueuedPacketForResetStream) { 2451 TEST_P(QuicConnectionTest, DoNotSendQueuedPacketForResetStream) {
2510 // Block the connection to queue the packet. 2452 // Block the connection to queue the packet.
2511 BlockOnNextWrite(); 2453 BlockOnNextWrite();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2555 SendStreamDataToPeer(stream_id, "foos", 3, !kFin, &last_packet); 2497 SendStreamDataToPeer(stream_id, "foos", 3, !kFin, &last_packet);
2556 SendStreamDataToPeer(stream_id, "fooos", 7, !kFin, &last_packet); 2498 SendStreamDataToPeer(stream_id, "fooos", 7, !kFin, &last_packet);
2557 2499
2558 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2500 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2559 connection_.SendRstStream(stream_id, QUIC_ERROR_PROCESSING_STREAM, 14); 2501 connection_.SendRstStream(stream_id, QUIC_ERROR_PROCESSING_STREAM, 14);
2560 2502
2561 // Lose a packet and ensure it does not trigger retransmission. 2503 // Lose a packet and ensure it does not trigger retransmission.
2562 QuicAckFrame nack_two = InitAckFrame(last_packet); 2504 QuicAckFrame nack_two = InitAckFrame(last_packet);
2563 NackPacket(last_packet - 1, &nack_two); 2505 NackPacket(last_packet - 1, &nack_two);
2564 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2506 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2565 if (FLAGS_quic_general_loss_algorithm) { 2507 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _));
2566 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _));
2567 } else {
2568 PacketNumberSet lost_packets;
2569 lost_packets.insert(last_packet - 1);
2570 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
2571 .WillOnce(Return(lost_packets));
2572 }
2573 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 2508 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
2574 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); 2509 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0);
2575 ProcessAckPacket(&nack_two); 2510 ProcessAckPacket(&nack_two);
2576 } 2511 }
2577 2512
2578 TEST_P(QuicConnectionTest, RetransmitForQuicRstStreamNoErrorOnNack) { 2513 TEST_P(QuicConnectionTest, RetransmitForQuicRstStreamNoErrorOnNack) {
2579 QuicStreamId stream_id = 2; 2514 QuicStreamId stream_id = 2;
2580 QuicPacketNumber last_packet; 2515 QuicPacketNumber last_packet;
2581 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet); 2516 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet);
2582 SendStreamDataToPeer(stream_id, "foos", 3, !kFin, &last_packet); 2517 SendStreamDataToPeer(stream_id, "foos", 3, !kFin, &last_packet);
2583 SendStreamDataToPeer(stream_id, "fooos", 7, !kFin, &last_packet); 2518 SendStreamDataToPeer(stream_id, "fooos", 7, !kFin, &last_packet);
2584 2519
2585 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2520 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2586 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14); 2521 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14);
2587 2522
2588 // Lose a packet, ensure it triggers retransmission on QUIC_VERSION_29 2523 // Lose a packet, ensure it triggers retransmission on QUIC_VERSION_29
2589 // or later versions. 2524 // or later versions.
2590 QuicAckFrame nack_two = InitAckFrame(last_packet); 2525 QuicAckFrame nack_two = InitAckFrame(last_packet);
2591 NackPacket(last_packet - 1, &nack_two); 2526 NackPacket(last_packet - 1, &nack_two);
2592 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2527 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2593 if (FLAGS_quic_general_loss_algorithm) { 2528 SendAlgorithmInterface::CongestionVector lost_packets;
2594 SendAlgorithmInterface::CongestionVector lost_packets; 2529 lost_packets.push_back(std::make_pair(last_packet - 1, kMaxPacketSize));
2595 lost_packets.push_back(std::make_pair(last_packet - 1, kMaxPacketSize)); 2530 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _))
2596 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _)) 2531 .WillOnce(SetArgPointee<3>(lost_packets));
2597 .WillOnce(SetArgPointee<3>(lost_packets));
2598 } else {
2599 PacketNumberSet lost_packets;
2600 lost_packets.insert(last_packet - 1);
2601 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
2602 .WillOnce(Return(lost_packets));
2603 }
2604 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 2532 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
2605 if (version() > QUIC_VERSION_28) { 2533 if (version() > QUIC_VERSION_28) {
2606 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 2534 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
2607 .Times(AtLeast(1)); 2535 .Times(AtLeast(1));
2608 } else { 2536 } else {
2609 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); 2537 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0);
2610 } 2538 }
2611 ProcessAckPacket(&nack_two); 2539 ProcessAckPacket(&nack_two);
2612 } 2540 }
2613 2541
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2658 SendStreamDataToPeer(stream_id, "foos", 3, !kFin, &last_packet); 2586 SendStreamDataToPeer(stream_id, "foos", 3, !kFin, &last_packet);
2659 BlockOnNextWrite(); 2587 BlockOnNextWrite();
2660 connection_.SendStreamDataWithString(stream_id, "fooos", 7, !kFin, nullptr); 2588 connection_.SendStreamDataWithString(stream_id, "fooos", 7, !kFin, nullptr);
2661 2589
2662 // Lose a packet which will trigger a pending retransmission. 2590 // Lose a packet which will trigger a pending retransmission.
2663 QuicAckFrame ack = InitAckFrame(last_packet); 2591 QuicAckFrame ack = InitAckFrame(last_packet);
2664 NackPacket(last_packet - 1, &ack); 2592 NackPacket(last_packet - 1, &ack);
2665 PacketNumberSet lost_packets; 2593 PacketNumberSet lost_packets;
2666 lost_packets.insert(last_packet - 1); 2594 lost_packets.insert(last_packet - 1);
2667 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2595 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2668 if (FLAGS_quic_general_loss_algorithm) { 2596 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _));
2669 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _));
2670 } else {
2671 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
2672 .WillOnce(Return(lost_packets));
2673 }
2674 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 2597 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
2675 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); 2598 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0);
2676 ProcessAckPacket(&ack); 2599 ProcessAckPacket(&ack);
2677 2600
2678 connection_.SendRstStream(stream_id, QUIC_ERROR_PROCESSING_STREAM, 14); 2601 connection_.SendRstStream(stream_id, QUIC_ERROR_PROCESSING_STREAM, 14);
2679 2602
2680 // Unblock the connection and verify that the RST_STREAM is sent but not the 2603 // Unblock the connection and verify that the RST_STREAM is sent but not the
2681 // second data packet nor a retransmit. 2604 // second data packet nor a retransmit.
2682 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2605 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2683 writer_->SetWritable(); 2606 writer_->SetWritable();
2684 connection_.OnCanWrite(); 2607 connection_.OnCanWrite();
2685 EXPECT_EQ(1u, writer_->frame_count()); 2608 EXPECT_EQ(1u, writer_->frame_count());
2686 EXPECT_EQ(1u, writer_->rst_stream_frames().size()); 2609 EXPECT_EQ(1u, writer_->rst_stream_frames().size());
2687 EXPECT_EQ(stream_id, writer_->rst_stream_frames().front().stream_id); 2610 EXPECT_EQ(stream_id, writer_->rst_stream_frames().front().stream_id);
2688 } 2611 }
2689 2612
2690 TEST_P(QuicConnectionTest, SendPendingRetransmissionForQuicRstStreamNoError) { 2613 TEST_P(QuicConnectionTest, SendPendingRetransmissionForQuicRstStreamNoError) {
2691 QuicStreamId stream_id = 2; 2614 QuicStreamId stream_id = 2;
2692 QuicPacketNumber last_packet; 2615 QuicPacketNumber last_packet;
2693 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet); 2616 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet);
2694 SendStreamDataToPeer(stream_id, "foos", 3, !kFin, &last_packet); 2617 SendStreamDataToPeer(stream_id, "foos", 3, !kFin, &last_packet);
2695 BlockOnNextWrite(); 2618 BlockOnNextWrite();
2696 connection_.SendStreamDataWithString(stream_id, "fooos", 7, !kFin, nullptr); 2619 connection_.SendStreamDataWithString(stream_id, "fooos", 7, !kFin, nullptr);
2697 2620
2698 // Lose a packet which will trigger a pending retransmission. 2621 // Lose a packet which will trigger a pending retransmission.
2699 QuicAckFrame ack = InitAckFrame(last_packet); 2622 QuicAckFrame ack = InitAckFrame(last_packet);
2700 NackPacket(last_packet - 1, &ack); 2623 NackPacket(last_packet - 1, &ack);
2701 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2624 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2702 if (FLAGS_quic_general_loss_algorithm) { 2625 SendAlgorithmInterface::CongestionVector lost_packets;
2703 SendAlgorithmInterface::CongestionVector lost_packets; 2626 lost_packets.push_back(std::make_pair(last_packet - 1, kMaxPacketSize));
2704 lost_packets.push_back(std::make_pair(last_packet - 1, kMaxPacketSize)); 2627 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _))
2705 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _)) 2628 .WillOnce(SetArgPointee<3>(lost_packets));
2706 .WillOnce(SetArgPointee<3>(lost_packets));
2707 } else {
2708 PacketNumberSet lost_packets;
2709 lost_packets.insert(last_packet - 1);
2710 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
2711 .WillOnce(Return(lost_packets));
2712 }
2713 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 2629 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
2714 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); 2630 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0);
2715 ProcessAckPacket(&ack); 2631 ProcessAckPacket(&ack);
2716 2632
2717 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14); 2633 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14);
2718 2634
2719 // Unblock the connection and verify that the RST_STREAM is sent and the 2635 // Unblock the connection and verify that the RST_STREAM is sent and the
2720 // second data packet or a retransmit is only sent on QUIC_VERSION_29 or 2636 // second data packet or a retransmit is only sent on QUIC_VERSION_29 or
2721 // later versions. 2637 // later versions.
2722 if (version() > QUIC_VERSION_28) { 2638 if (version() > QUIC_VERSION_28) {
(...skipping 21 matching lines...) Expand all
2744 2660
2745 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2661 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2746 2662
2747 // Instigate a loss with an ack. 2663 // Instigate a loss with an ack.
2748 QuicAckFrame nack_two = InitAckFrame(3); 2664 QuicAckFrame nack_two = InitAckFrame(3);
2749 NackPacket(2, &nack_two); 2665 NackPacket(2, &nack_two);
2750 // The first nack should trigger a fast retransmission, but we'll be 2666 // The first nack should trigger a fast retransmission, but we'll be
2751 // write blocked, so the packet will be queued. 2667 // write blocked, so the packet will be queued.
2752 BlockOnNextWrite(); 2668 BlockOnNextWrite();
2753 2669
2754 if (FLAGS_quic_general_loss_algorithm) { 2670 SendAlgorithmInterface::CongestionVector lost_packets;
2755 SendAlgorithmInterface::CongestionVector lost_packets; 2671 lost_packets.push_back(std::make_pair(2, kMaxPacketSize));
2756 lost_packets.push_back(std::make_pair(2, kMaxPacketSize)); 2672 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _))
2757 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _)) 2673 .WillOnce(SetArgPointee<3>(lost_packets));
2758 .WillOnce(SetArgPointee<3>(lost_packets));
2759 } else {
2760 PacketNumberSet lost_packets;
2761 lost_packets.insert(2);
2762 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
2763 .WillOnce(Return(lost_packets));
2764 }
2765 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 2674 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
2766 ProcessAckPacket(&nack_two); 2675 ProcessAckPacket(&nack_two);
2767 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2676 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2768 2677
2769 // Now, ack the previous transmission. 2678 // Now, ack the previous transmission.
2770 if (FLAGS_quic_general_loss_algorithm) { 2679 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _));
2771 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _));
2772 } else {
2773 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
2774 .WillOnce(Return(PacketNumberSet()));
2775 }
2776 QuicAckFrame ack_all = InitAckFrame(3); 2680 QuicAckFrame ack_all = InitAckFrame(3);
2777 ProcessAckPacket(&ack_all); 2681 ProcessAckPacket(&ack_all);
2778 2682
2779 // Unblock the socket and attempt to send the queued packets. However, 2683 // Unblock the socket and attempt to send the queued packets. However,
2780 // since the previous transmission has been acked, we will not 2684 // since the previous transmission has been acked, we will not
2781 // send the retransmission. 2685 // send the retransmission.
2782 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); 2686 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0);
2783 2687
2784 writer_->SetWritable(); 2688 writer_->SetWritable();
2785 connection_.OnCanWrite(); 2689 connection_.OnCanWrite();
2786 2690
2787 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2691 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2788 } 2692 }
2789 2693
2790 TEST_P(QuicConnectionTest, RetransmitNackedLargestObserved) { 2694 TEST_P(QuicConnectionTest, RetransmitNackedLargestObserved) {
2791 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2695 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2792 QuicPacketNumber largest_observed; 2696 QuicPacketNumber largest_observed;
2793 QuicByteCount packet_size; 2697 QuicByteCount packet_size;
2794 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 2698 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
2795 .WillOnce(DoAll(SaveArg<2>(&largest_observed), SaveArg<3>(&packet_size), 2699 .WillOnce(DoAll(SaveArg<2>(&largest_observed), SaveArg<3>(&packet_size),
2796 Return(true))); 2700 Return(true)));
2797 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); 2701 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr);
2798 2702
2799 QuicAckFrame frame = InitAckFrame(1); 2703 QuicAckFrame frame = InitAckFrame(1);
2800 NackPacket(largest_observed, &frame); 2704 NackPacket(largest_observed, &frame);
2801 // The first nack should retransmit the largest observed packet. 2705 // The first nack should retransmit the largest observed packet.
2802 if (FLAGS_quic_general_loss_algorithm) { 2706 SendAlgorithmInterface::CongestionVector lost_packets;
2803 SendAlgorithmInterface::CongestionVector lost_packets; 2707 lost_packets.push_back(std::make_pair(1, kMaxPacketSize));
2804 lost_packets.push_back(std::make_pair(1, kMaxPacketSize)); 2708 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _))
2805 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _)) 2709 .WillOnce(SetArgPointee<3>(lost_packets));
2806 .WillOnce(SetArgPointee<3>(lost_packets));
2807 } else {
2808 PacketNumberSet lost_packets;
2809 lost_packets.insert(1);
2810 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
2811 .WillOnce(Return(lost_packets));
2812 }
2813 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 2710 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
2814 EXPECT_CALL(*send_algorithm_, 2711 EXPECT_CALL(*send_algorithm_,
2815 OnPacketSent(_, _, _, packet_size - kQuicVersionSize, _)); 2712 OnPacketSent(_, _, _, packet_size - kQuicVersionSize, _));
2816 ProcessAckPacket(&frame); 2713 ProcessAckPacket(&frame);
2817 } 2714 }
2818 2715
2819 TEST_P(QuicConnectionTest, QueueAfterTwoRTOs) { 2716 TEST_P(QuicConnectionTest, QueueAfterTwoRTOs) {
2820 for (int i = 0; i < 10; ++i) { 2717 for (int i = 0; i < 10; ++i) {
2821 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2718 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2822 connection_.SendStreamDataWithString(3, "foo", i * 3, !kFin, nullptr); 2719 connection_.SendStreamDataWithString(3, "foo", i * 3, !kFin, nullptr);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
2922 } 2819 }
2923 2820
2924 // Ack 15, nack 1-14. 2821 // Ack 15, nack 1-14.
2925 2822
2926 QuicAckFrame nack = InitAckFrame(15); 2823 QuicAckFrame nack = InitAckFrame(15);
2927 for (int i = 1; i < 15; ++i) { 2824 for (int i = 1; i < 15; ++i) {
2928 NackPacket(i, &nack); 2825 NackPacket(i, &nack);
2929 } 2826 }
2930 2827
2931 // 14 packets have been NACK'd and lost. 2828 // 14 packets have been NACK'd and lost.
2932 if (FLAGS_quic_general_loss_algorithm) { 2829 SendAlgorithmInterface::CongestionVector lost_packets;
2933 SendAlgorithmInterface::CongestionVector lost_packets; 2830 for (int i = 1; i < 15; ++i) {
2934 for (int i = 1; i < 15; ++i) { 2831 lost_packets.push_back(std::make_pair(i, kMaxPacketSize));
2935 lost_packets.push_back(std::make_pair(i, kMaxPacketSize));
2936 }
2937 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _))
2938 .WillOnce(SetArgPointee<3>(lost_packets));
2939 } else {
2940 PacketNumberSet lost_packets;
2941 for (int i = 1; i < 15; ++i) {
2942 lost_packets.insert(i);
2943 }
2944 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
2945 .WillOnce(Return(lost_packets));
2946 } 2832 }
2833 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _))
2834 .WillOnce(SetArgPointee<3>(lost_packets));
2947 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 2835 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
2948 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(14); 2836 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(14);
2949 ProcessAckPacket(&nack); 2837 ProcessAckPacket(&nack);
2950 } 2838 }
2951 2839
2952 // Test sending multiple acks from the connection to the session. 2840 // Test sending multiple acks from the connection to the session.
2953 TEST_P(QuicConnectionTest, MultipleAcks) { 2841 TEST_P(QuicConnectionTest, MultipleAcks) {
2954 QuicPacketNumber last_packet; 2842 QuicPacketNumber last_packet;
2955 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 2843 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1
2956 EXPECT_EQ(1u, last_packet); 2844 EXPECT_EQ(1u, last_packet);
(...skipping 1643 matching lines...) Expand 10 before | Expand all | Expand 10 after
4600 4488
4601 TEST_P(QuicConnectionTest, BundleAckWithDataOnIncomingAck) { 4489 TEST_P(QuicConnectionTest, BundleAckWithDataOnIncomingAck) {
4602 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4490 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4603 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, !kFin, 4491 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, !kFin,
4604 nullptr); 4492 nullptr);
4605 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 3, !kFin, 4493 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 3, !kFin,
4606 nullptr); 4494 nullptr);
4607 // Ack the second packet, which will retransmit the first packet. 4495 // Ack the second packet, which will retransmit the first packet.
4608 QuicAckFrame ack = InitAckFrame(2); 4496 QuicAckFrame ack = InitAckFrame(2);
4609 NackPacket(1, &ack); 4497 NackPacket(1, &ack);
4610 if (FLAGS_quic_general_loss_algorithm) { 4498 SendAlgorithmInterface::CongestionVector lost_packets;
4611 SendAlgorithmInterface::CongestionVector lost_packets; 4499 lost_packets.push_back(std::make_pair(1, kMaxPacketSize));
4612 lost_packets.push_back(std::make_pair(1, kMaxPacketSize)); 4500 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _))
4613 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _)) 4501 .WillOnce(SetArgPointee<3>(lost_packets));
4614 .WillOnce(SetArgPointee<3>(lost_packets));
4615 } else {
4616 PacketNumberSet lost_packets;
4617 lost_packets.insert(1);
4618 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
4619 .WillOnce(Return(lost_packets));
4620 }
4621 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 4502 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
4622 ProcessAckPacket(&ack); 4503 ProcessAckPacket(&ack);
4623 EXPECT_EQ(1u, writer_->frame_count()); 4504 EXPECT_EQ(1u, writer_->frame_count());
4624 EXPECT_EQ(1u, writer_->stream_frames().size()); 4505 EXPECT_EQ(1u, writer_->stream_frames().size());
4625 writer_->Reset(); 4506 writer_->Reset();
4626 4507
4627 // Now ack the retransmission, which will both raise the high water mark 4508 // Now ack the retransmission, which will both raise the high water mark
4628 // and see if there is more data to send. 4509 // and see if there is more data to send.
4629 ack = InitAckFrame(3); 4510 ack = InitAckFrame(3);
4630 NackPacket(1, &ack); 4511 NackPacket(1, &ack);
4631 if (FLAGS_quic_general_loss_algorithm) { 4512 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _));
4632 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _));
4633 } else {
4634 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
4635 .WillOnce(Return(PacketNumberSet()));
4636 }
4637 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 4513 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
4638 ProcessAckPacket(&ack); 4514 ProcessAckPacket(&ack);
4639 4515
4640 // Check that no packet is sent and the ack alarm isn't set. 4516 // Check that no packet is sent and the ack alarm isn't set.
4641 EXPECT_EQ(0u, writer_->frame_count()); 4517 EXPECT_EQ(0u, writer_->frame_count());
4642 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 4518 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
4643 writer_->Reset(); 4519 writer_->Reset();
4644 4520
4645 // Send the same ack, but send both data and an ack together. 4521 // Send the same ack, but send both data and an ack together.
4646 ack = InitAckFrame(3); 4522 ack = InitAckFrame(3);
4647 NackPacket(1, &ack); 4523 NackPacket(1, &ack);
4648 if (FLAGS_quic_general_loss_algorithm) { 4524 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _));
4649 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _));
4650 } else {
4651 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
4652 .WillOnce(Return(PacketNumberSet()));
4653 }
4654 EXPECT_CALL(visitor_, OnCanWrite()) 4525 EXPECT_CALL(visitor_, OnCanWrite())
4655 .WillOnce(IgnoreResult(InvokeWithoutArgs( 4526 .WillOnce(IgnoreResult(InvokeWithoutArgs(
4656 &connection_, &TestConnection::EnsureWritableAndSendStreamData5))); 4527 &connection_, &TestConnection::EnsureWritableAndSendStreamData5)));
4657 ProcessAckPacket(&ack); 4528 ProcessAckPacket(&ack);
4658 4529
4659 // Check that ack is bundled with outgoing data and the delayed ack 4530 // Check that ack is bundled with outgoing data and the delayed ack
4660 // alarm is reset. 4531 // alarm is reset.
4661 EXPECT_EQ(3u, writer_->frame_count()); 4532 EXPECT_EQ(3u, writer_->frame_count());
4662 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); 4533 EXPECT_FALSE(writer_->stop_waiting_frames().empty());
4663 EXPECT_FALSE(writer_->ack_frames().empty()); 4534 EXPECT_FALSE(writer_->ack_frames().empty());
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
5006 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3); 4877 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3);
5007 4878
5008 // Retransmit due to RTO. 4879 // Retransmit due to RTO.
5009 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10)); 4880 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10));
5010 connection_.GetRetransmissionAlarm()->Fire(); 4881 connection_.GetRetransmissionAlarm()->Fire();
5011 4882
5012 // Retransmit due to explicit nacks. 4883 // Retransmit due to explicit nacks.
5013 QuicAckFrame nack_three = InitAckFrame(4); 4884 QuicAckFrame nack_three = InitAckFrame(4);
5014 NackPacket(3, &nack_three); 4885 NackPacket(3, &nack_three);
5015 NackPacket(1, &nack_three); 4886 NackPacket(1, &nack_three);
5016 if (FLAGS_quic_general_loss_algorithm) { 4887 SendAlgorithmInterface::CongestionVector lost_packets;
5017 SendAlgorithmInterface::CongestionVector lost_packets; 4888 lost_packets.push_back(std::make_pair(1, kMaxPacketSize));
5018 lost_packets.push_back(std::make_pair(1, kMaxPacketSize)); 4889 lost_packets.push_back(std::make_pair(3, kMaxPacketSize));
5019 lost_packets.push_back(std::make_pair(3, kMaxPacketSize)); 4890 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _))
5020 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _)) 4891 .WillOnce(SetArgPointee<3>(lost_packets));
5021 .WillOnce(SetArgPointee<3>(lost_packets));
5022 } else {
5023 PacketNumberSet lost_packets;
5024 lost_packets.insert(1);
5025 lost_packets.insert(3);
5026 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
5027 .WillOnce(Return(lost_packets));
5028 }
5029 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 4892 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
5030 EXPECT_CALL(visitor_, OnCanWrite()); 4893 EXPECT_CALL(visitor_, OnCanWrite());
5031 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4894 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
5032 ProcessAckPacket(&nack_three); 4895 ProcessAckPacket(&nack_three);
5033 4896
5034 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()) 4897 EXPECT_CALL(*send_algorithm_, BandwidthEstimate())
5035 .WillOnce(Return(QuicBandwidth::Zero())); 4898 .WillOnce(Return(QuicBandwidth::Zero()));
5036 4899
5037 const QuicConnectionStats& stats = connection_.GetStats(); 4900 const QuicConnectionStats& stats = connection_.GetStats();
5038 EXPECT_EQ(3 * first_packet_size + 2 * second_packet_size - kQuicVersionSize, 4901 EXPECT_EQ(3 * first_packet_size + 2 * second_packet_size - kQuicVersionSize,
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
5206 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, listener.get()); 5069 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, listener.get());
5207 5070
5208 // Send some other data which we will ACK. 5071 // Send some other data which we will ACK.
5209 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); 5072 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr);
5210 connection_.SendStreamDataWithString(1, "bar", 0, !kFin, nullptr); 5073 connection_.SendStreamDataWithString(1, "bar", 0, !kFin, nullptr);
5211 5074
5212 // Now we receive ACK for packets 2 and 3, but importantly missing packet 1 5075 // Now we receive ACK for packets 2 and 3, but importantly missing packet 1
5213 // which we registered to be notified about. 5076 // which we registered to be notified about.
5214 QuicAckFrame frame = InitAckFrame(3); 5077 QuicAckFrame frame = InitAckFrame(3);
5215 NackPacket(1, &frame); 5078 NackPacket(1, &frame);
5216 if (FLAGS_quic_general_loss_algorithm) { 5079 SendAlgorithmInterface::CongestionVector lost_packets;
5217 SendAlgorithmInterface::CongestionVector lost_packets; 5080 lost_packets.push_back(std::make_pair(1, kMaxPacketSize));
5218 lost_packets.push_back(std::make_pair(1, kMaxPacketSize)); 5081 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _))
5219 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _)) 5082 .WillOnce(SetArgPointee<3>(lost_packets));
5220 .WillOnce(SetArgPointee<3>(lost_packets));
5221 } else {
5222 PacketNumberSet lost_packets;
5223 lost_packets.insert(1);
5224 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
5225 .WillOnce(Return(lost_packets));
5226 }
5227 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 5083 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
5228 ProcessAckPacket(&frame); 5084 ProcessAckPacket(&frame);
5229 } 5085 }
5230 5086
5231 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) { 5087 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) {
5232 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 5088 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
5233 5089
5234 // Create a listener which we expect to be called. 5090 // Create a listener which we expect to be called.
5235 scoped_refptr<MockAckListener> listener(new MockAckListener); 5091 scoped_refptr<MockAckListener> listener(new MockAckListener);
5236 EXPECT_CALL(*listener, OnPacketRetransmitted(3)).Times(1); 5092 EXPECT_CALL(*listener, OnPacketRetransmitted(3)).Times(1);
5237 EXPECT_CALL(*listener, OnPacketAcked(3, _)).Times(1); 5093 EXPECT_CALL(*listener, OnPacketAcked(3, _)).Times(1);
5238 5094
5239 // Send four packets, and register to be notified on ACK of packet 2. 5095 // Send four packets, and register to be notified on ACK of packet 2.
5240 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); 5096 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr);
5241 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, listener.get()); 5097 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, listener.get());
5242 connection_.SendStreamDataWithString(3, "baz", 0, !kFin, nullptr); 5098 connection_.SendStreamDataWithString(3, "baz", 0, !kFin, nullptr);
5243 connection_.SendStreamDataWithString(3, "qux", 0, !kFin, nullptr); 5099 connection_.SendStreamDataWithString(3, "qux", 0, !kFin, nullptr);
5244 5100
5245 // Now we receive ACK for packets 1, 3, and 4 and lose 2. 5101 // Now we receive ACK for packets 1, 3, and 4 and lose 2.
5246 QuicAckFrame frame = InitAckFrame(4); 5102 QuicAckFrame frame = InitAckFrame(4);
5247 NackPacket(2, &frame); 5103 NackPacket(2, &frame);
5248 if (FLAGS_quic_general_loss_algorithm) { 5104 SendAlgorithmInterface::CongestionVector lost_packets;
5249 SendAlgorithmInterface::CongestionVector lost_packets; 5105 lost_packets.push_back(std::make_pair(2, kMaxPacketSize));
5250 lost_packets.push_back(std::make_pair(2, kMaxPacketSize)); 5106 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _))
5251 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _)) 5107 .WillOnce(SetArgPointee<3>(lost_packets));
5252 .WillOnce(SetArgPointee<3>(lost_packets));
5253 } else {
5254 PacketNumberSet lost_packets;
5255 lost_packets.insert(2);
5256 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
5257 .WillOnce(Return(lost_packets));
5258 }
5259 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 5108 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
5260 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 5109 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
5261 ProcessAckPacket(&frame); 5110 ProcessAckPacket(&frame);
5262 5111
5263 // Now we get an ACK for packet 5 (retransmitted packet 2), which should 5112 // Now we get an ACK for packet 5 (retransmitted packet 2), which should
5264 // trigger the callback. 5113 // trigger the callback.
5265 if (FLAGS_quic_general_loss_algorithm) { 5114 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _));
5266 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _));
5267 } else {
5268 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
5269 .WillOnce(Return(PacketNumberSet()));
5270 }
5271 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 5115 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
5272 QuicAckFrame second_ack_frame = InitAckFrame(5); 5116 QuicAckFrame second_ack_frame = InitAckFrame(5);
5273 ProcessAckPacket(&second_ack_frame); 5117 ProcessAckPacket(&second_ack_frame);
5274 } 5118 }
5275 5119
5276 // AckNotifierCallback is triggered by the ack of a packet that timed 5120 // AckNotifierCallback is triggered by the ack of a packet that timed
5277 // out and was retransmitted, even though the retransmission has a 5121 // out and was retransmitted, even though the retransmission has a
5278 // different packet number. 5122 // different packet number.
5279 TEST_P(QuicConnectionTest, AckNotifierCallbackForAckAfterRTO) { 5123 TEST_P(QuicConnectionTest, AckNotifierCallbackForAckAfterRTO) {
5280 // Create a listener which we expect to be called. 5124 // Create a listener which we expect to be called.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
5321 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); 5165 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr);
5322 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, listener.get()); 5166 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, listener.get());
5323 connection_.SendStreamDataWithString(3, "baz", 0, !kFin, nullptr); 5167 connection_.SendStreamDataWithString(3, "baz", 0, !kFin, nullptr);
5324 connection_.SendStreamDataWithString(3, "qux", 0, !kFin, nullptr); 5168 connection_.SendStreamDataWithString(3, "qux", 0, !kFin, nullptr);
5325 5169
5326 // Now we receive ACK for packets 1, 3, and 4 and lose 2. 5170 // Now we receive ACK for packets 1, 3, and 4 and lose 2.
5327 QuicAckFrame frame = InitAckFrame(4); 5171 QuicAckFrame frame = InitAckFrame(4);
5328 NackPacket(2, &frame); 5172 NackPacket(2, &frame);
5329 EXPECT_CALL(*listener, OnPacketRetransmitted(_)); 5173 EXPECT_CALL(*listener, OnPacketRetransmitted(_));
5330 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 5174 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
5331 if (FLAGS_quic_general_loss_algorithm) { 5175 SendAlgorithmInterface::CongestionVector lost_packets;
5332 SendAlgorithmInterface::CongestionVector lost_packets; 5176 lost_packets.push_back(std::make_pair(2, kMaxPacketSize));
5333 lost_packets.push_back(std::make_pair(2, kMaxPacketSize)); 5177 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _))
5334 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _)) 5178 .WillOnce(SetArgPointee<3>(lost_packets));
5335 .WillOnce(SetArgPointee<3>(lost_packets));
5336 } else {
5337 PacketNumberSet lost_packets;
5338 lost_packets.insert(2);
5339 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
5340 .WillOnce(Return(lost_packets));
5341 }
5342 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 5179 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
5343 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 5180 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
5344 ProcessAckPacket(&frame); 5181 ProcessAckPacket(&frame);
5345 5182
5346 // Now we get an ACK for packet 2, which was previously nacked. 5183 // Now we get an ACK for packet 2, which was previously nacked.
5347 EXPECT_CALL(*listener, OnPacketAcked(3, _)); 5184 EXPECT_CALL(*listener, OnPacketAcked(3, _));
5348 if (FLAGS_quic_general_loss_algorithm) { 5185 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _));
5349 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _));
5350 } else {
5351 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
5352 .WillOnce(Return(PacketNumberSet()));
5353 }
5354 QuicAckFrame second_ack_frame = InitAckFrame(4); 5186 QuicAckFrame second_ack_frame = InitAckFrame(4);
5355 ProcessAckPacket(&second_ack_frame); 5187 ProcessAckPacket(&second_ack_frame);
5356 5188
5357 // Verify that the listener is not notified again when the 5189 // Verify that the listener is not notified again when the
5358 // retransmit is acked. 5190 // retransmit is acked.
5359 if (FLAGS_quic_general_loss_algorithm) { 5191 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _));
5360 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _));
5361 } else {
5362 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
5363 .WillOnce(Return(PacketNumberSet()));
5364 }
5365 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 5192 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
5366 QuicAckFrame third_ack_frame = InitAckFrame(5); 5193 QuicAckFrame third_ack_frame = InitAckFrame(5);
5367 ProcessAckPacket(&third_ack_frame); 5194 ProcessAckPacket(&third_ack_frame);
5368 } 5195 }
5369 5196
5370 TEST_P(QuicConnectionTest, AckNotifierFECTriggerCallback) { 5197 TEST_P(QuicConnectionTest, AckNotifierFECTriggerCallback) {
5371 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 5198 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
5372 5199
5373 // Create a listener which we expect to be called. 5200 // Create a listener which we expect to be called.
5374 scoped_refptr<MockAckListener> listener(new MockAckListener); 5201 scoped_refptr<MockAckListener> listener(new MockAckListener);
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
5594 // Evaluate CanWrite, and have it return a non-Zero value. 5421 // Evaluate CanWrite, and have it return a non-Zero value.
5595 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _)) 5422 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _))
5596 .WillRepeatedly(Return(QuicTime::Delta::FromMilliseconds(1))); 5423 .WillRepeatedly(Return(QuicTime::Delta::FromMilliseconds(1)));
5597 connection_.OnCanWrite(); 5424 connection_.OnCanWrite();
5598 EXPECT_TRUE(connection_.GetSendAlarm()->IsSet()); 5425 EXPECT_TRUE(connection_.GetSendAlarm()->IsSet());
5599 EXPECT_EQ(clock_.Now().Add(QuicTime::Delta::FromMilliseconds(1)), 5426 EXPECT_EQ(clock_.Now().Add(QuicTime::Delta::FromMilliseconds(1)),
5600 connection_.GetSendAlarm()->deadline()); 5427 connection_.GetSendAlarm()->deadline());
5601 5428
5602 // Process an ack and the send alarm will be set to the new 2ms delay. 5429 // Process an ack and the send alarm will be set to the new 2ms delay.
5603 QuicAckFrame ack = InitAckFrame(1); 5430 QuicAckFrame ack = InitAckFrame(1);
5604 if (FLAGS_quic_general_loss_algorithm) { 5431 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _));
5605 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _));
5606 } else {
5607 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
5608 .WillOnce(Return(PacketNumberSet()));
5609 }
5610 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 5432 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
5611 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _)) 5433 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _))
5612 .WillRepeatedly(Return(QuicTime::Delta::FromMilliseconds(2))); 5434 .WillRepeatedly(Return(QuicTime::Delta::FromMilliseconds(2)));
5613 ProcessAckPacket(&ack); 5435 ProcessAckPacket(&ack);
5614 EXPECT_EQ(1u, writer_->frame_count()); 5436 EXPECT_EQ(1u, writer_->frame_count());
5615 EXPECT_EQ(1u, writer_->stream_frames().size()); 5437 EXPECT_EQ(1u, writer_->stream_frames().size());
5616 EXPECT_TRUE(connection_.GetSendAlarm()->IsSet()); 5438 EXPECT_TRUE(connection_.GetSendAlarm()->IsSet());
5617 EXPECT_EQ(clock_.Now().Add(QuicTime::Delta::FromMilliseconds(2)), 5439 EXPECT_EQ(clock_.Now().Add(QuicTime::Delta::FromMilliseconds(2)),
5618 connection_.GetSendAlarm()->deadline()); 5440 connection_.GetSendAlarm()->deadline());
5619 writer_->Reset(); 5441 writer_->Reset();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
5684 QuicStreamFrame stream_frame(1u, false, 0u, StringPiece()); 5506 QuicStreamFrame stream_frame(1u, false, 0u, StringPiece());
5685 EXPECT_DFATAL(ProcessFramePacket(QuicFrame(&stream_frame)), 5507 EXPECT_DFATAL(ProcessFramePacket(QuicFrame(&stream_frame)),
5686 "Received a packet with multipath flag on when multipath is " 5508 "Received a packet with multipath flag on when multipath is "
5687 "not enabled."); 5509 "not enabled.");
5688 EXPECT_FALSE(connection_.connected()); 5510 EXPECT_FALSE(connection_.connected());
5689 } 5511 }
5690 5512
5691 } // namespace 5513 } // namespace
5692 } // namespace test 5514 } // namespace test
5693 } // namespace net 5515 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection.cc ('k') | net/quic/quic_flags.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698