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

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

Issue 2820263005: In QUIC version >= 38, enables random padding of size [1, 256] (Closed)
Patch Set: Created 3 years, 8 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
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/core/quic_connection.h" 5 #include "net/quic/core/quic_connection.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <memory> 8 #include <memory>
9 #include <ostream> 9 #include <ostream>
10 #include <utility> 10 #include <utility>
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 using testing::StrictMock; 52 using testing::StrictMock;
53 using testing::_; 53 using testing::_;
54 54
55 namespace net { 55 namespace net {
56 namespace test { 56 namespace test {
57 namespace { 57 namespace {
58 58
59 const char data1[] = "foo"; 59 const char data1[] = "foo";
60 const char data2[] = "bar"; 60 const char data2[] = "bar";
61 61
62 const bool kFin = true;
63 const bool kHasStopWaiting = true; 62 const bool kHasStopWaiting = true;
64 63
65 const int kDefaultRetransmissionTimeMs = 500; 64 const int kDefaultRetransmissionTimeMs = 500;
66 65
67 const QuicSocketAddress kPeerAddress = 66 const QuicSocketAddress kPeerAddress =
68 QuicSocketAddress(QuicIpAddress::Loopback6(), 67 QuicSocketAddress(QuicIpAddress::Loopback6(),
69 /*port=*/12345); 68 /*port=*/12345);
70 const QuicSocketAddress kSelfAddress = 69 const QuicSocketAddress kSelfAddress =
71 QuicSocketAddress(QuicIpAddress::Loopback6(), 70 QuicSocketAddress(QuicIpAddress::Loopback6(),
72 /*port=*/443); 71 /*port=*/443);
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 serialized_packet.retransmittable_frames.push_back( 507 serialized_packet.retransmittable_frames.push_back(
509 QuicFrame(new QuicStreamFrame())); 508 QuicFrame(new QuicStreamFrame()));
510 } 509 }
511 OnSerializedPacket(&serialized_packet); 510 OnSerializedPacket(&serialized_packet);
512 } 511 }
513 512
514 QuicConsumedData SendStreamDataWithString( 513 QuicConsumedData SendStreamDataWithString(
515 QuicStreamId id, 514 QuicStreamId id,
516 QuicStringPiece data, 515 QuicStringPiece data,
517 QuicStreamOffset offset, 516 QuicStreamOffset offset,
518 bool fin, 517 StreamSendingState state,
519 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener) { 518 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener) {
520 if (id != kCryptoStreamId && this->encryption_level() == ENCRYPTION_NONE) { 519 if (id != kCryptoStreamId && this->encryption_level() == ENCRYPTION_NONE) {
521 this->SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); 520 this->SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE);
522 } 521 }
523 struct iovec iov; 522 struct iovec iov;
524 QuicIOVector data_iov(MakeIOVector(data, &iov)); 523 QuicIOVector data_iov(MakeIOVector(data, &iov));
525 return QuicConnection::SendStreamData(id, data_iov, offset, fin, 524 return QuicConnection::SendStreamData(id, data_iov, offset, state,
526 std::move(ack_listener)); 525 std::move(ack_listener));
527 } 526 }
528 527
529 QuicConsumedData SendStreamData3() { 528 QuicConsumedData SendStreamData3() {
530 return SendStreamDataWithString(kClientDataStreamId1, "food", 0, !kFin, 529 return SendStreamDataWithString(kClientDataStreamId1, "food", 0, NO_FIN,
531 nullptr); 530 nullptr);
532 } 531 }
533 532
534 QuicConsumedData SendStreamData5() { 533 QuicConsumedData SendStreamData5() {
535 return SendStreamDataWithString(kClientDataStreamId2, "food2", 0, !kFin, 534 return SendStreamDataWithString(kClientDataStreamId2, "food2", 0, NO_FIN,
536 nullptr); 535 nullptr);
537 } 536 }
538 537
539 // Ensures the connection can write stream data before writing. 538 // Ensures the connection can write stream data before writing.
540 QuicConsumedData EnsureWritableAndSendStreamData5() { 539 QuicConsumedData EnsureWritableAndSendStreamData5() {
541 EXPECT_TRUE(CanWriteStreamData()); 540 EXPECT_TRUE(CanWriteStreamData());
542 return SendStreamData5(); 541 return SendStreamData5();
543 } 542 }
544 543
545 // The crypto stream has special semantics so that it is not blocked by a 544 // The crypto stream has special semantics so that it is not blocked by a
546 // congestion window limitation, and also so that it gets put into a separate 545 // congestion window limitation, and also so that it gets put into a separate
547 // packet (so that it is easier to reason about a crypto frame not being 546 // packet (so that it is easier to reason about a crypto frame not being
548 // split needlessly across packet boundaries). As a result, we have separate 547 // split needlessly across packet boundaries). As a result, we have separate
549 // tests for some cases for this stream. 548 // tests for some cases for this stream.
550 QuicConsumedData SendCryptoStreamData() { 549 QuicConsumedData SendCryptoStreamData() {
551 return SendStreamDataWithString(kCryptoStreamId, "chlo", 0, !kFin, nullptr); 550 return SendStreamDataWithString(kCryptoStreamId, "chlo", 0, NO_FIN,
551 nullptr);
552 } 552 }
553 553
554 void set_version(QuicVersion version) { 554 void set_version(QuicVersion version) {
555 QuicConnectionPeer::GetFramer(this)->set_version(version); 555 QuicConnectionPeer::GetFramer(this)->set_version(version);
556 } 556 }
557 557
558 void SetSupportedVersions(const QuicVersionVector& versions) { 558 void SetSupportedVersions(const QuicVersionVector& versions) {
559 QuicConnectionPeer::GetFramer(this)->SetSupportedVersions(versions); 559 QuicConnectionPeer::GetFramer(this)->SetSupportedVersions(versions);
560 writer()->SetSupportedVersions(versions); 560 writer()->SetSupportedVersions(versions);
561 } 561 }
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 size_t encrypted_length = peer_framer_.EncryptPayload( 882 size_t encrypted_length = peer_framer_.EncryptPayload(
883 ENCRYPTION_NONE, number, *packet, buffer, kMaxPacketSize); 883 ENCRYPTION_NONE, number, *packet, buffer, kMaxPacketSize);
884 connection_.ProcessUdpPacket( 884 connection_.ProcessUdpPacket(
885 kSelfAddress, kPeerAddress, 885 kSelfAddress, kPeerAddress,
886 QuicReceivedPacket(buffer, encrypted_length, QuicTime::Zero(), false)); 886 QuicReceivedPacket(buffer, encrypted_length, QuicTime::Zero(), false));
887 } 887 }
888 888
889 QuicByteCount SendStreamDataToPeer(QuicStreamId id, 889 QuicByteCount SendStreamDataToPeer(QuicStreamId id,
890 QuicStringPiece data, 890 QuicStringPiece data,
891 QuicStreamOffset offset, 891 QuicStreamOffset offset,
892 bool fin, 892 StreamSendingState state,
893 QuicPacketNumber* last_packet) { 893 QuicPacketNumber* last_packet) {
894 QuicByteCount packet_size; 894 QuicByteCount packet_size;
895 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 895 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
896 .WillOnce(DoAll(SaveArg<3>(&packet_size), Return(true))); 896 .WillOnce(DoAll(SaveArg<3>(&packet_size), Return(true)));
897 connection_.SendStreamDataWithString(id, data, offset, fin, nullptr); 897 connection_.SendStreamDataWithString(id, data, offset, state, nullptr);
898 if (last_packet != nullptr) { 898 if (last_packet != nullptr) {
899 *last_packet = creator_->packet_number(); 899 *last_packet = creator_->packet_number();
900 } 900 }
901 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 901 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
902 .Times(AnyNumber()); 902 .Times(AnyNumber());
903 return packet_size; 903 return packet_size;
904 } 904 }
905 905
906 void SendAckPacketToPeer() { 906 void SendAckPacketToPeer() {
907 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 907 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
1415 EXPECT_EQ(3u, writer_->packets_write_attempts()); 1415 EXPECT_EQ(3u, writer_->packets_write_attempts());
1416 1416
1417 ProcessPacket(4); 1417 ProcessPacket(4);
1418 // Should not cause an ack. 1418 // Should not cause an ack.
1419 EXPECT_EQ(3u, writer_->packets_write_attempts()); 1419 EXPECT_EQ(3u, writer_->packets_write_attempts());
1420 } 1420 }
1421 1421
1422 TEST_P(QuicConnectionTest, OutOfOrderAckReceiptCausesNoAck) { 1422 TEST_P(QuicConnectionTest, OutOfOrderAckReceiptCausesNoAck) {
1423 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1423 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1424 1424
1425 SendStreamDataToPeer(1, "foo", 0, !kFin, nullptr); 1425 SendStreamDataToPeer(1, "foo", 0, NO_FIN, nullptr);
1426 SendStreamDataToPeer(1, "bar", 3, !kFin, nullptr); 1426 SendStreamDataToPeer(1, "bar", 3, NO_FIN, nullptr);
1427 EXPECT_EQ(2u, writer_->packets_write_attempts()); 1427 EXPECT_EQ(2u, writer_->packets_write_attempts());
1428 1428
1429 QuicAckFrame ack1 = InitAckFrame(1); 1429 QuicAckFrame ack1 = InitAckFrame(1);
1430 QuicAckFrame ack2 = InitAckFrame(2); 1430 QuicAckFrame ack2 = InitAckFrame(2);
1431 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 1431 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
1432 ProcessAckPacket(2, &ack2); 1432 ProcessAckPacket(2, &ack2);
1433 // Should ack immediately since we have missing packets. 1433 // Should ack immediately since we have missing packets.
1434 EXPECT_EQ(2u, writer_->packets_write_attempts()); 1434 EXPECT_EQ(2u, writer_->packets_write_attempts());
1435 1435
1436 ProcessAckPacket(1, &ack1); 1436 ProcessAckPacket(1, &ack1);
1437 // Should not ack an ack filling a missing packet. 1437 // Should not ack an ack filling a missing packet.
1438 EXPECT_EQ(2u, writer_->packets_write_attempts()); 1438 EXPECT_EQ(2u, writer_->packets_write_attempts());
1439 } 1439 }
1440 1440
1441 TEST_P(QuicConnectionTest, AckReceiptCausesAckSend) { 1441 TEST_P(QuicConnectionTest, AckReceiptCausesAckSend) {
1442 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1442 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1443 QuicPacketNumber original; 1443 QuicPacketNumber original;
1444 QuicByteCount packet_size; 1444 QuicByteCount packet_size;
1445 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 1445 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
1446 .WillOnce( 1446 .WillOnce(
1447 DoAll(SaveArg<2>(&original), SaveArg<3>(&packet_size), Return(true))); 1447 DoAll(SaveArg<2>(&original), SaveArg<3>(&packet_size), Return(true)));
1448 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); 1448 connection_.SendStreamDataWithString(3, "foo", 0, NO_FIN, nullptr);
1449 QuicAckFrame frame = InitAckFrame(original); 1449 QuicAckFrame frame = InitAckFrame(original);
1450 NackPacket(original, &frame); 1450 NackPacket(original, &frame);
1451 // First nack triggers early retransmit. 1451 // First nack triggers early retransmit.
1452 SendAlgorithmInterface::CongestionVector lost_packets; 1452 SendAlgorithmInterface::CongestionVector lost_packets;
1453 lost_packets.push_back(std::make_pair(1, kMaxPacketSize)); 1453 lost_packets.push_back(std::make_pair(1, kMaxPacketSize));
1454 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)) 1454 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _))
1455 .WillOnce(SetArgPointee<4>(lost_packets)); 1455 .WillOnce(SetArgPointee<4>(lost_packets));
1456 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 1456 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
1457 QuicPacketNumber retransmission; 1457 QuicPacketNumber retransmission;
1458 EXPECT_CALL(*send_algorithm_, 1458 EXPECT_CALL(*send_algorithm_,
1459 OnPacketSent(_, _, _, packet_size - kQuicVersionSize, _)) 1459 OnPacketSent(_, _, _, packet_size - kQuicVersionSize, _))
1460 .WillOnce(DoAll(SaveArg<2>(&retransmission), Return(true))); 1460 .WillOnce(DoAll(SaveArg<2>(&retransmission), Return(true)));
1461 1461
1462 ProcessAckPacket(&frame); 1462 ProcessAckPacket(&frame);
1463 1463
1464 QuicAckFrame frame2 = InitAckFrame(retransmission); 1464 QuicAckFrame frame2 = InitAckFrame(retransmission);
1465 NackPacket(original, &frame2); 1465 NackPacket(original, &frame2);
1466 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 1466 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
1467 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)); 1467 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _));
1468 ProcessAckPacket(&frame2); 1468 ProcessAckPacket(&frame2);
1469 1469
1470 // Now if the peer sends an ack which still reports the retransmitted packet 1470 // Now if the peer sends an ack which still reports the retransmitted packet
1471 // as missing, that will bundle an ack with data after two acks in a row 1471 // as missing, that will bundle an ack with data after two acks in a row
1472 // indicate the high water mark needs to be raised. 1472 // indicate the high water mark needs to be raised.
1473 EXPECT_CALL(*send_algorithm_, 1473 EXPECT_CALL(*send_algorithm_,
1474 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)); 1474 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA));
1475 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, nullptr); 1475 connection_.SendStreamDataWithString(3, "foo", 3, NO_FIN, nullptr);
1476 // No ack sent. 1476 // No ack sent.
1477 EXPECT_EQ(1u, writer_->frame_count()); 1477 EXPECT_EQ(1u, writer_->frame_count());
1478 EXPECT_EQ(1u, writer_->stream_frames().size()); 1478 EXPECT_EQ(1u, writer_->stream_frames().size());
1479 1479
1480 // No more packet loss for the rest of the test. 1480 // No more packet loss for the rest of the test.
1481 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)).Times(AnyNumber()); 1481 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)).Times(AnyNumber());
1482 ProcessAckPacket(&frame2); 1482 ProcessAckPacket(&frame2);
1483 EXPECT_CALL(*send_algorithm_, 1483 EXPECT_CALL(*send_algorithm_,
1484 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)); 1484 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA));
1485 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, nullptr); 1485 connection_.SendStreamDataWithString(3, "foo", 3, NO_FIN, nullptr);
1486 // Ack bundled. 1486 // Ack bundled.
1487 if (GetParam().no_stop_waiting) { 1487 if (GetParam().no_stop_waiting) {
1488 EXPECT_EQ(2u, writer_->frame_count()); 1488 EXPECT_EQ(2u, writer_->frame_count());
1489 } else { 1489 } else {
1490 EXPECT_EQ(3u, writer_->frame_count()); 1490 EXPECT_EQ(3u, writer_->frame_count());
1491 } 1491 }
1492 EXPECT_EQ(1u, writer_->stream_frames().size()); 1492 EXPECT_EQ(1u, writer_->stream_frames().size());
1493 EXPECT_FALSE(writer_->ack_frames().empty()); 1493 EXPECT_FALSE(writer_->ack_frames().empty());
1494 1494
1495 // But an ack with no missing packets will not send an ack. 1495 // But an ack with no missing packets will not send an ack.
1496 AckPacket(original, &frame2); 1496 AckPacket(original, &frame2);
1497 ProcessAckPacket(&frame2); 1497 ProcessAckPacket(&frame2);
1498 ProcessAckPacket(&frame2); 1498 ProcessAckPacket(&frame2);
1499 } 1499 }
1500 1500
1501 TEST_P(QuicConnectionTest, 20AcksCausesAckSend) { 1501 TEST_P(QuicConnectionTest, 20AcksCausesAckSend) {
1502 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1502 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1503 1503
1504 SendStreamDataToPeer(1, "foo", 0, !kFin, nullptr); 1504 SendStreamDataToPeer(1, "foo", 0, NO_FIN, nullptr);
1505 1505
1506 QuicAlarm* ack_alarm = QuicConnectionPeer::GetAckAlarm(&connection_); 1506 QuicAlarm* ack_alarm = QuicConnectionPeer::GetAckAlarm(&connection_);
1507 // But an ack with no missing packets will not send an ack. 1507 // But an ack with no missing packets will not send an ack.
1508 QuicAckFrame frame = InitAckFrame(1); 1508 QuicAckFrame frame = InitAckFrame(1);
1509 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 1509 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
1510 for (int i = 0; i < 19; ++i) { 1510 for (int i = 0; i < 19; ++i) {
1511 ProcessAckPacket(&frame); 1511 ProcessAckPacket(&frame);
1512 EXPECT_FALSE(ack_alarm->IsSet()); 1512 EXPECT_FALSE(ack_alarm->IsSet());
1513 } 1513 }
1514 EXPECT_EQ(1u, writer_->packets_write_attempts()); 1514 EXPECT_EQ(1u, writer_->packets_write_attempts());
1515 // The 20th ack packet will cause an ack to be sent. 1515 // The 20th ack packet will cause an ack to be sent.
1516 ProcessAckPacket(&frame); 1516 ProcessAckPacket(&frame);
1517 EXPECT_EQ(2u, writer_->packets_write_attempts()); 1517 EXPECT_EQ(2u, writer_->packets_write_attempts());
1518 } 1518 }
1519 1519
1520 TEST_P(QuicConnectionTest, LeastUnackedLower) { 1520 TEST_P(QuicConnectionTest, LeastUnackedLower) {
1521 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1521 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1522 1522
1523 SendStreamDataToPeer(1, "foo", 0, !kFin, nullptr); 1523 SendStreamDataToPeer(1, "foo", 0, NO_FIN, nullptr);
1524 SendStreamDataToPeer(1, "bar", 3, !kFin, nullptr); 1524 SendStreamDataToPeer(1, "bar", 3, NO_FIN, nullptr);
1525 SendStreamDataToPeer(1, "eep", 6, !kFin, nullptr); 1525 SendStreamDataToPeer(1, "eep", 6, NO_FIN, nullptr);
1526 1526
1527 // Start out saying the least unacked is 2. 1527 // Start out saying the least unacked is 2.
1528 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 5); 1528 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 5);
1529 QuicStopWaitingFrame frame = InitStopWaitingFrame(2); 1529 QuicStopWaitingFrame frame = InitStopWaitingFrame(2);
1530 ProcessStopWaitingPacket(&frame); 1530 ProcessStopWaitingPacket(&frame);
1531 1531
1532 // Change it to 1, but lower the packet number to fake out-of-order packets. 1532 // Change it to 1, but lower the packet number to fake out-of-order packets.
1533 // This should be fine. 1533 // This should be fine.
1534 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 1); 1534 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 1);
1535 // The scheduler will not process out of order acks, but all packet processing 1535 // The scheduler will not process out of order acks, but all packet processing
(...skipping 14 matching lines...) Expand all
1550 } 1550 }
1551 QuicStopWaitingFrame frame3 = InitStopWaitingFrame(1); 1551 QuicStopWaitingFrame frame3 = InitStopWaitingFrame(1);
1552 ProcessStopWaitingPacket(&frame3); 1552 ProcessStopWaitingPacket(&frame3);
1553 } 1553 }
1554 1554
1555 TEST_P(QuicConnectionTest, TooManySentPackets) { 1555 TEST_P(QuicConnectionTest, TooManySentPackets) {
1556 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1556 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1557 1557
1558 const int num_packets = kMaxTrackedPackets + 100; 1558 const int num_packets = kMaxTrackedPackets + 100;
1559 for (int i = 0; i < num_packets; ++i) { 1559 for (int i = 0; i < num_packets; ++i) {
1560 SendStreamDataToPeer(1, "foo", 3 * i, !kFin, nullptr); 1560 SendStreamDataToPeer(1, "foo", 3 * i, NO_FIN, nullptr);
1561 } 1561 }
1562 1562
1563 // Ack packet 1, which leaves more than the limit outstanding. 1563 // Ack packet 1, which leaves more than the limit outstanding.
1564 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 1564 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
1565 1565
1566 // Nack the first packet and ack the rest, leaving a huge gap. 1566 // Nack the first packet and ack the rest, leaving a huge gap.
1567 QuicAckFrame frame1 = InitAckFrame(num_packets); 1567 QuicAckFrame frame1 = InitAckFrame(num_packets);
1568 NackPacket(1, &frame1); 1568 NackPacket(1, &frame1);
1569 ProcessAckPacket(&frame1); 1569 ProcessAckPacket(&frame1);
1570 } 1570 }
1571 1571
1572 TEST_P(QuicConnectionTest, TooManyReceivedPackets) { 1572 TEST_P(QuicConnectionTest, TooManyReceivedPackets) {
1573 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1573 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1574 // Miss 99 of every 100 packets for 5500 packets. 1574 // Miss 99 of every 100 packets for 5500 packets.
1575 for (QuicPacketNumber i = 1; i < kMaxTrackedPackets + 500; i += 100) { 1575 for (QuicPacketNumber i = 1; i < kMaxTrackedPackets + 500; i += 100) {
1576 ProcessPacket(i); 1576 ProcessPacket(i);
1577 if (!connection_.connected()) { 1577 if (!connection_.connected()) {
1578 break; 1578 break;
1579 } 1579 }
1580 } 1580 }
1581 } 1581 }
1582 1582
1583 TEST_P(QuicConnectionTest, LargestObservedLower) { 1583 TEST_P(QuicConnectionTest, LargestObservedLower) {
1584 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1584 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1585 1585
1586 SendStreamDataToPeer(1, "foo", 0, !kFin, nullptr); 1586 SendStreamDataToPeer(1, "foo", 0, NO_FIN, nullptr);
1587 SendStreamDataToPeer(1, "bar", 3, !kFin, nullptr); 1587 SendStreamDataToPeer(1, "bar", 3, NO_FIN, nullptr);
1588 SendStreamDataToPeer(1, "eep", 6, !kFin, nullptr); 1588 SendStreamDataToPeer(1, "eep", 6, NO_FIN, nullptr);
1589 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 1589 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
1590 1590
1591 // Start out saying the largest observed is 2. 1591 // Start out saying the largest observed is 2.
1592 QuicAckFrame frame1 = InitAckFrame(1); 1592 QuicAckFrame frame1 = InitAckFrame(1);
1593 QuicAckFrame frame2 = InitAckFrame(2); 1593 QuicAckFrame frame2 = InitAckFrame(2);
1594 ProcessAckPacket(&frame2); 1594 ProcessAckPacket(&frame2);
1595 1595
1596 // Now change it to 1, and it should cause a connection error. 1596 // Now change it to 1, and it should cause a connection error.
1597 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_ACK_DATA, _, 1597 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_ACK_DATA, _,
1598 ConnectionCloseSource::FROM_SELF)); 1598 ConnectionCloseSource::FROM_SELF));
(...skipping 17 matching lines...) Expand all
1616 ProcessPacket(1); 1616 ProcessPacket(1);
1617 1617
1618 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 1); 1618 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 1);
1619 QuicAckFrame frame1 = InitAckFrame(0); 1619 QuicAckFrame frame1 = InitAckFrame(0);
1620 ProcessAckPacket(&frame1); 1620 ProcessAckPacket(&frame1);
1621 } 1621 }
1622 1622
1623 TEST_P(QuicConnectionTest, BasicSending) { 1623 TEST_P(QuicConnectionTest, BasicSending) {
1624 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1624 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1625 QuicPacketNumber last_packet; 1625 QuicPacketNumber last_packet;
1626 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 1626 SendStreamDataToPeer(1, "foo", 0, NO_FIN, &last_packet); // Packet 1
1627 EXPECT_EQ(1u, last_packet); 1627 EXPECT_EQ(1u, last_packet);
1628 SendAckPacketToPeer(); // Packet 2 1628 SendAckPacketToPeer(); // Packet 2
1629 1629
1630 if (GetParam().no_stop_waiting) { 1630 if (GetParam().no_stop_waiting) {
1631 // Expect no stop waiting frame is sent. 1631 // Expect no stop waiting frame is sent.
1632 EXPECT_EQ(0u, least_unacked()); 1632 EXPECT_EQ(0u, least_unacked());
1633 } else { 1633 } else {
1634 EXPECT_EQ(1u, least_unacked()); 1634 EXPECT_EQ(1u, least_unacked());
1635 } 1635 }
1636 1636
1637 SendAckPacketToPeer(); // Packet 3 1637 SendAckPacketToPeer(); // Packet 3
1638 if (GetParam().no_stop_waiting) { 1638 if (GetParam().no_stop_waiting) {
1639 // Expect no stop waiting frame is sent. 1639 // Expect no stop waiting frame is sent.
1640 EXPECT_EQ(0u, least_unacked()); 1640 EXPECT_EQ(0u, least_unacked());
1641 } else { 1641 } else {
1642 EXPECT_EQ(1u, least_unacked()); 1642 EXPECT_EQ(1u, least_unacked());
1643 } 1643 }
1644 1644
1645 SendStreamDataToPeer(1, "bar", 3, !kFin, &last_packet); // Packet 4 1645 SendStreamDataToPeer(1, "bar", 3, NO_FIN, &last_packet); // Packet 4
1646 EXPECT_EQ(4u, last_packet); 1646 EXPECT_EQ(4u, last_packet);
1647 SendAckPacketToPeer(); // Packet 5 1647 SendAckPacketToPeer(); // Packet 5
1648 if (GetParam().no_stop_waiting) { 1648 if (GetParam().no_stop_waiting) {
1649 // Expect no stop waiting frame is sent. 1649 // Expect no stop waiting frame is sent.
1650 EXPECT_EQ(0u, least_unacked()); 1650 EXPECT_EQ(0u, least_unacked());
1651 } else { 1651 } else {
1652 EXPECT_EQ(1u, least_unacked()); 1652 EXPECT_EQ(1u, least_unacked());
1653 } 1653 }
1654 1654
1655 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 1655 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1688 // If we force an ack, we shouldn't change our retransmit state. 1688 // If we force an ack, we shouldn't change our retransmit state.
1689 SendAckPacketToPeer(); // Packet 7 1689 SendAckPacketToPeer(); // Packet 7
1690 if (GetParam().no_stop_waiting) { 1690 if (GetParam().no_stop_waiting) {
1691 // Expect no stop waiting frame is sent. 1691 // Expect no stop waiting frame is sent.
1692 EXPECT_EQ(0u, least_unacked()); 1692 EXPECT_EQ(0u, least_unacked());
1693 } else { 1693 } else {
1694 EXPECT_EQ(7u, least_unacked()); 1694 EXPECT_EQ(7u, least_unacked());
1695 } 1695 }
1696 1696
1697 // But if we send more data it should. 1697 // But if we send more data it should.
1698 SendStreamDataToPeer(1, "eep", 6, !kFin, &last_packet); // Packet 8 1698 SendStreamDataToPeer(1, "eep", 6, NO_FIN, &last_packet); // Packet 8
1699 EXPECT_EQ(8u, last_packet); 1699 EXPECT_EQ(8u, last_packet);
1700 SendAckPacketToPeer(); // Packet 9 1700 SendAckPacketToPeer(); // Packet 9
1701 if (GetParam().no_stop_waiting) { 1701 if (GetParam().no_stop_waiting) {
1702 // Expect no stop waiting frame is sent. 1702 // Expect no stop waiting frame is sent.
1703 EXPECT_EQ(0u, least_unacked()); 1703 EXPECT_EQ(0u, least_unacked());
1704 } else { 1704 } else {
1705 EXPECT_EQ(7u, least_unacked()); 1705 EXPECT_EQ(7u, least_unacked());
1706 } 1706 }
1707 } 1707 }
1708 1708
1709 // QuicConnection should record the the packet sent-time prior to sending the 1709 // QuicConnection should record the the packet sent-time prior to sending the
1710 // packet. 1710 // packet.
1711 TEST_P(QuicConnectionTest, RecordSentTimeBeforePacketSent) { 1711 TEST_P(QuicConnectionTest, RecordSentTimeBeforePacketSent) {
1712 // We're using a MockClock for the tests, so we have complete control over the 1712 // We're using a MockClock for the tests, so we have complete control over the
1713 // time. 1713 // time.
1714 // Our recorded timestamp for the last packet sent time will be passed in to 1714 // Our recorded timestamp for the last packet sent time will be passed in to
1715 // the send_algorithm. Make sure that it is set to the correct value. 1715 // the send_algorithm. Make sure that it is set to the correct value.
1716 QuicTime actual_recorded_send_time = QuicTime::Zero(); 1716 QuicTime actual_recorded_send_time = QuicTime::Zero();
1717 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 1717 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
1718 .WillOnce(DoAll(SaveArg<0>(&actual_recorded_send_time), Return(true))); 1718 .WillOnce(DoAll(SaveArg<0>(&actual_recorded_send_time), Return(true)));
1719 1719
1720 // First send without any pause and check the result. 1720 // First send without any pause and check the result.
1721 QuicTime expected_recorded_send_time = clock_.Now(); 1721 QuicTime expected_recorded_send_time = clock_.Now();
1722 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); 1722 connection_.SendStreamDataWithString(1, "foo", 0, NO_FIN, nullptr);
1723 EXPECT_EQ(expected_recorded_send_time, actual_recorded_send_time) 1723 EXPECT_EQ(expected_recorded_send_time, actual_recorded_send_time)
1724 << "Expected time = " << expected_recorded_send_time.ToDebuggingValue() 1724 << "Expected time = " << expected_recorded_send_time.ToDebuggingValue()
1725 << ". Actual time = " << actual_recorded_send_time.ToDebuggingValue(); 1725 << ". Actual time = " << actual_recorded_send_time.ToDebuggingValue();
1726 1726
1727 // Now pause during the write, and check the results. 1727 // Now pause during the write, and check the results.
1728 actual_recorded_send_time = QuicTime::Zero(); 1728 actual_recorded_send_time = QuicTime::Zero();
1729 const QuicTime::Delta write_pause_time_delta = 1729 const QuicTime::Delta write_pause_time_delta =
1730 QuicTime::Delta::FromMilliseconds(5000); 1730 QuicTime::Delta::FromMilliseconds(5000);
1731 SetWritePauseTimeDelta(write_pause_time_delta); 1731 SetWritePauseTimeDelta(write_pause_time_delta);
1732 expected_recorded_send_time = clock_.Now(); 1732 expected_recorded_send_time = clock_.Now();
1733 1733
1734 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 1734 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
1735 .WillOnce(DoAll(SaveArg<0>(&actual_recorded_send_time), Return(true))); 1735 .WillOnce(DoAll(SaveArg<0>(&actual_recorded_send_time), Return(true)));
1736 connection_.SendStreamDataWithString(2, "baz", 0, !kFin, nullptr); 1736 connection_.SendStreamDataWithString(2, "baz", 0, NO_FIN, nullptr);
1737 EXPECT_EQ(expected_recorded_send_time, actual_recorded_send_time) 1737 EXPECT_EQ(expected_recorded_send_time, actual_recorded_send_time)
1738 << "Expected time = " << expected_recorded_send_time.ToDebuggingValue() 1738 << "Expected time = " << expected_recorded_send_time.ToDebuggingValue()
1739 << ". Actual time = " << actual_recorded_send_time.ToDebuggingValue(); 1739 << ". Actual time = " << actual_recorded_send_time.ToDebuggingValue();
1740 } 1740 }
1741 1741
1742 TEST_P(QuicConnectionTest, FramePacking) { 1742 TEST_P(QuicConnectionTest, FramePacking) {
1743 // Send an ack and two stream frames in 1 packet by queueing them. 1743 // Send an ack and two stream frames in 1 packet by queueing them.
1744 { 1744 {
1745 QuicConnection::ScopedPacketBundler bundler(&connection_, 1745 QuicConnection::ScopedPacketBundler bundler(&connection_,
1746 QuicConnection::SEND_ACK); 1746 QuicConnection::SEND_ACK);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1845 // Send data in 1 packet by writing multiple blocks in a single iovector 1845 // Send data in 1 packet by writing multiple blocks in a single iovector
1846 // using writev. 1846 // using writev.
1847 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 1847 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
1848 1848
1849 char data[] = "ABCD"; 1849 char data[] = "ABCD";
1850 struct iovec iov[2]; 1850 struct iovec iov[2];
1851 iov[0].iov_base = data; 1851 iov[0].iov_base = data;
1852 iov[0].iov_len = 2; 1852 iov[0].iov_len = 2;
1853 iov[1].iov_base = data + 2; 1853 iov[1].iov_base = data + 2;
1854 iov[1].iov_len = 2; 1854 iov[1].iov_len = 2;
1855 connection_.SendStreamData(1, QuicIOVector(iov, 2, 4), 0, !kFin, nullptr); 1855 connection_.SendStreamData(1, QuicIOVector(iov, 2, 4), 0, NO_FIN, nullptr);
1856 1856
1857 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1857 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1858 EXPECT_FALSE(connection_.HasQueuedData()); 1858 EXPECT_FALSE(connection_.HasQueuedData());
1859 1859
1860 // Parse the last packet and ensure multiple iovector blocks have 1860 // Parse the last packet and ensure multiple iovector blocks have
1861 // been packed into a single stream frame from one stream. 1861 // been packed into a single stream frame from one stream.
1862 EXPECT_EQ(2u, writer_->frame_count()); 1862 EXPECT_EQ(2u, writer_->frame_count());
1863 EXPECT_EQ(1u, writer_->stream_frames().size()); 1863 EXPECT_EQ(1u, writer_->stream_frames().size());
1864 EXPECT_EQ(1u, writer_->padding_frames().size()); 1864 EXPECT_EQ(1u, writer_->padding_frames().size());
1865 QuicStreamFrame* frame = writer_->stream_frames()[0].get(); 1865 QuicStreamFrame* frame = writer_->stream_frames()[0].get();
1866 EXPECT_EQ(1u, frame->stream_id); 1866 EXPECT_EQ(1u, frame->stream_id);
1867 EXPECT_EQ("ABCD", QuicStringPiece(frame->data_buffer, frame->data_length)); 1867 EXPECT_EQ("ABCD", QuicStringPiece(frame->data_buffer, frame->data_length));
1868 } 1868 }
1869 1869
1870 TEST_P(QuicConnectionTest, FramePackingSendvQueued) { 1870 TEST_P(QuicConnectionTest, FramePackingSendvQueued) {
1871 // Try to send two stream frames in 1 packet by using writev. 1871 // Try to send two stream frames in 1 packet by using writev.
1872 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 1872 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
1873 1873
1874 BlockOnNextWrite(); 1874 BlockOnNextWrite();
1875 char data[] = "ABCD"; 1875 char data[] = "ABCD";
1876 struct iovec iov[2]; 1876 struct iovec iov[2];
1877 iov[0].iov_base = data; 1877 iov[0].iov_base = data;
1878 iov[0].iov_len = 2; 1878 iov[0].iov_len = 2;
1879 iov[1].iov_base = data + 2; 1879 iov[1].iov_base = data + 2;
1880 iov[1].iov_len = 2; 1880 iov[1].iov_len = 2;
1881 connection_.SendStreamData(1, QuicIOVector(iov, 2, 4), 0, !kFin, nullptr); 1881 connection_.SendStreamData(1, QuicIOVector(iov, 2, 4), 0, NO_FIN, nullptr);
1882 1882
1883 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 1883 EXPECT_EQ(1u, connection_.NumQueuedPackets());
1884 EXPECT_TRUE(connection_.HasQueuedData()); 1884 EXPECT_TRUE(connection_.HasQueuedData());
1885 1885
1886 // Unblock the writes and actually send. 1886 // Unblock the writes and actually send.
1887 writer_->SetWritable(); 1887 writer_->SetWritable();
1888 connection_.OnCanWrite(); 1888 connection_.OnCanWrite();
1889 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1889 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1890 1890
1891 // Parse the last packet and ensure it's one stream frame from one stream. 1891 // Parse the last packet and ensure it's one stream frame from one stream.
1892 EXPECT_EQ(2u, writer_->frame_count()); 1892 EXPECT_EQ(2u, writer_->frame_count());
1893 EXPECT_EQ(1u, writer_->stream_frames().size()); 1893 EXPECT_EQ(1u, writer_->stream_frames().size());
1894 EXPECT_EQ(1u, writer_->padding_frames().size()); 1894 EXPECT_EQ(1u, writer_->padding_frames().size());
1895 EXPECT_EQ(1u, writer_->stream_frames()[0]->stream_id); 1895 EXPECT_EQ(1u, writer_->stream_frames()[0]->stream_id);
1896 } 1896 }
1897 1897
1898 TEST_P(QuicConnectionTest, SendingZeroBytes) { 1898 TEST_P(QuicConnectionTest, SendingZeroBytes) {
1899 connection_.SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); 1899 connection_.SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE);
1900 // Send a zero byte write with a fin using writev. 1900 // Send a zero byte write with a fin using writev.
1901 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 1901 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
1902 QuicIOVector empty_iov(nullptr, 0, 0); 1902 QuicIOVector empty_iov(nullptr, 0, 0);
1903 connection_.SendStreamData(kHeadersStreamId, empty_iov, 0, kFin, nullptr); 1903 connection_.SendStreamData(kHeadersStreamId, empty_iov, 0, FIN, nullptr);
1904 1904
1905 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1905 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1906 EXPECT_FALSE(connection_.HasQueuedData()); 1906 EXPECT_FALSE(connection_.HasQueuedData());
1907 1907
1908 // Parse the last packet and ensure it's one stream frame from one stream. 1908 // Parse the last packet and ensure it's one stream frame from one stream.
1909 EXPECT_EQ(1u, writer_->frame_count()); 1909 EXPECT_EQ(1u, writer_->frame_count());
1910 EXPECT_EQ(1u, writer_->stream_frames().size()); 1910 EXPECT_EQ(1u, writer_->stream_frames().size());
1911 EXPECT_EQ(kHeadersStreamId, writer_->stream_frames()[0]->stream_id); 1911 EXPECT_EQ(kHeadersStreamId, writer_->stream_frames()[0]->stream_id);
1912 EXPECT_TRUE(writer_->stream_frames()[0]->fin); 1912 EXPECT_TRUE(writer_->stream_frames()[0]->fin);
1913 } 1913 }
(...skipping 12 matching lines...) Expand all
1926 // Send data and ensure the ack is bundled. 1926 // Send data and ensure the ack is bundled.
1927 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(8); 1927 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(8);
1928 size_t len = 10000; 1928 size_t len = 10000;
1929 std::unique_ptr<char[]> data_array(new char[len]); 1929 std::unique_ptr<char[]> data_array(new char[len]);
1930 memset(data_array.get(), '?', len); 1930 memset(data_array.get(), '?', len);
1931 struct iovec iov; 1931 struct iovec iov;
1932 iov.iov_base = data_array.get(); 1932 iov.iov_base = data_array.get();
1933 iov.iov_len = len; 1933 iov.iov_len = len;
1934 QuicIOVector iovector(&iov, 1, len); 1934 QuicIOVector iovector(&iov, 1, len);
1935 QuicConsumedData consumed = 1935 QuicConsumedData consumed =
1936 connection_.SendStreamData(kHeadersStreamId, iovector, 0, true, nullptr); 1936 connection_.SendStreamData(kHeadersStreamId, iovector, 0, FIN, nullptr);
1937 EXPECT_EQ(len, consumed.bytes_consumed); 1937 EXPECT_EQ(len, consumed.bytes_consumed);
1938 EXPECT_TRUE(consumed.fin_consumed); 1938 EXPECT_TRUE(consumed.fin_consumed);
1939 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1939 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1940 EXPECT_FALSE(connection_.HasQueuedData()); 1940 EXPECT_FALSE(connection_.HasQueuedData());
1941 1941
1942 // Parse the last packet and ensure it's one stream frame with a fin. 1942 // Parse the last packet and ensure it's one stream frame with a fin.
1943 EXPECT_EQ(1u, writer_->frame_count()); 1943 EXPECT_EQ(1u, writer_->frame_count());
1944 EXPECT_EQ(1u, writer_->stream_frames().size()); 1944 EXPECT_EQ(1u, writer_->stream_frames().size());
1945 EXPECT_EQ(kHeadersStreamId, writer_->stream_frames()[0]->stream_id); 1945 EXPECT_EQ(kHeadersStreamId, writer_->stream_frames()[0]->stream_id);
1946 EXPECT_TRUE(writer_->stream_frames()[0]->fin); 1946 EXPECT_TRUE(writer_->stream_frames()[0]->fin);
(...skipping 24 matching lines...) Expand all
1971 // two different streams. 1971 // two different streams.
1972 EXPECT_EQ(2u, writer_->frame_count()); 1972 EXPECT_EQ(2u, writer_->frame_count());
1973 EXPECT_EQ(2u, writer_->stream_frames().size()); 1973 EXPECT_EQ(2u, writer_->stream_frames().size());
1974 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0]->stream_id); 1974 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0]->stream_id);
1975 EXPECT_EQ(kClientDataStreamId2, writer_->stream_frames()[1]->stream_id); 1975 EXPECT_EQ(kClientDataStreamId2, writer_->stream_frames()[1]->stream_id);
1976 } 1976 }
1977 1977
1978 TEST_P(QuicConnectionTest, RetransmitOnNack) { 1978 TEST_P(QuicConnectionTest, RetransmitOnNack) {
1979 QuicPacketNumber last_packet; 1979 QuicPacketNumber last_packet;
1980 QuicByteCount second_packet_size; 1980 QuicByteCount second_packet_size;
1981 SendStreamDataToPeer(3, "foo", 0, !kFin, &last_packet); // Packet 1 1981 SendStreamDataToPeer(3, "foo", 0, NO_FIN, &last_packet); // Packet 1
1982 second_packet_size = 1982 second_packet_size =
1983 SendStreamDataToPeer(3, "foos", 3, !kFin, &last_packet); // Packet 2 1983 SendStreamDataToPeer(3, "foos", 3, NO_FIN, &last_packet); // Packet 2
1984 SendStreamDataToPeer(3, "fooos", 7, !kFin, &last_packet); // Packet 3 1984 SendStreamDataToPeer(3, "fooos", 7, NO_FIN, &last_packet); // Packet 3
1985 1985
1986 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1986 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1987 1987
1988 // Don't lose a packet on an ack, and nothing is retransmitted. 1988 // Don't lose a packet on an ack, and nothing is retransmitted.
1989 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 1989 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
1990 QuicAckFrame ack_one = InitAckFrame(1); 1990 QuicAckFrame ack_one = InitAckFrame(1);
1991 ProcessAckPacket(&ack_one); 1991 ProcessAckPacket(&ack_one);
1992 1992
1993 // Lose a packet and ensure it triggers retransmission. 1993 // Lose a packet and ensure it triggers retransmission.
1994 QuicAckFrame nack_two = InitAckFrame(3); 1994 QuicAckFrame nack_two = InitAckFrame(3);
1995 NackPacket(2, &nack_two); 1995 NackPacket(2, &nack_two);
1996 SendAlgorithmInterface::CongestionVector lost_packets; 1996 SendAlgorithmInterface::CongestionVector lost_packets;
1997 lost_packets.push_back(std::make_pair(2, kMaxPacketSize)); 1997 lost_packets.push_back(std::make_pair(2, kMaxPacketSize));
1998 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)) 1998 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _))
1999 .WillOnce(SetArgPointee<4>(lost_packets)); 1999 .WillOnce(SetArgPointee<4>(lost_packets));
2000 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2000 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
2001 EXPECT_CALL(*send_algorithm_, 2001 EXPECT_CALL(*send_algorithm_,
2002 OnPacketSent(_, _, _, second_packet_size - kQuicVersionSize, _)) 2002 OnPacketSent(_, _, _, second_packet_size - kQuicVersionSize, _))
2003 .Times(1); 2003 .Times(1);
2004 ProcessAckPacket(&nack_two); 2004 ProcessAckPacket(&nack_two);
2005 } 2005 }
2006 2006
2007 TEST_P(QuicConnectionTest, DoNotSendQueuedPacketForResetStream) { 2007 TEST_P(QuicConnectionTest, DoNotSendQueuedPacketForResetStream) {
2008 // Block the connection to queue the packet. 2008 // Block the connection to queue the packet.
2009 BlockOnNextWrite(); 2009 BlockOnNextWrite();
2010 2010
2011 QuicStreamId stream_id = 2; 2011 QuicStreamId stream_id = 2;
2012 connection_.SendStreamDataWithString(stream_id, "foo", 0, !kFin, nullptr); 2012 connection_.SendStreamDataWithString(stream_id, "foo", 0, NO_FIN, nullptr);
2013 2013
2014 // Now that there is a queued packet, reset the stream. 2014 // Now that there is a queued packet, reset the stream.
2015 connection_.SendRstStream(stream_id, QUIC_ERROR_PROCESSING_STREAM, 14); 2015 connection_.SendRstStream(stream_id, QUIC_ERROR_PROCESSING_STREAM, 14);
2016 2016
2017 // Unblock the connection and verify that only the RST_STREAM is sent. 2017 // Unblock the connection and verify that only the RST_STREAM is sent.
2018 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2018 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2019 writer_->SetWritable(); 2019 writer_->SetWritable();
2020 connection_.OnCanWrite(); 2020 connection_.OnCanWrite();
2021 EXPECT_EQ(1u, writer_->frame_count()); 2021 EXPECT_EQ(1u, writer_->frame_count());
2022 EXPECT_EQ(1u, writer_->rst_stream_frames().size()); 2022 EXPECT_EQ(1u, writer_->rst_stream_frames().size());
2023 } 2023 }
2024 2024
2025 TEST_P(QuicConnectionTest, SendQueuedPacketForQuicRstStreamNoError) { 2025 TEST_P(QuicConnectionTest, SendQueuedPacketForQuicRstStreamNoError) {
2026 // Block the connection to queue the packet. 2026 // Block the connection to queue the packet.
2027 BlockOnNextWrite(); 2027 BlockOnNextWrite();
2028 2028
2029 QuicStreamId stream_id = 2; 2029 QuicStreamId stream_id = 2;
2030 connection_.SendStreamDataWithString(stream_id, "foo", 0, !kFin, nullptr); 2030 connection_.SendStreamDataWithString(stream_id, "foo", 0, NO_FIN, nullptr);
2031 2031
2032 // Now that there is a queued packet, reset the stream. 2032 // Now that there is a queued packet, reset the stream.
2033 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14); 2033 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14);
2034 2034
2035 // Unblock the connection and verify that the RST_STREAM is sent and the data 2035 // Unblock the connection and verify that the RST_STREAM is sent and the data
2036 // packet is sent. 2036 // packet is sent.
2037 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AtLeast(2)); 2037 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AtLeast(2));
2038 writer_->SetWritable(); 2038 writer_->SetWritable();
2039 connection_.OnCanWrite(); 2039 connection_.OnCanWrite();
2040 EXPECT_EQ(1u, writer_->frame_count()); 2040 EXPECT_EQ(1u, writer_->frame_count());
2041 EXPECT_EQ(1u, writer_->rst_stream_frames().size()); 2041 EXPECT_EQ(1u, writer_->rst_stream_frames().size());
2042 } 2042 }
2043 2043
2044 TEST_P(QuicConnectionTest, DoNotRetransmitForResetStreamOnNack) { 2044 TEST_P(QuicConnectionTest, DoNotRetransmitForResetStreamOnNack) {
2045 QuicStreamId stream_id = 2; 2045 QuicStreamId stream_id = 2;
2046 QuicPacketNumber last_packet; 2046 QuicPacketNumber last_packet;
2047 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet); 2047 SendStreamDataToPeer(stream_id, "foo", 0, NO_FIN, &last_packet);
2048 SendStreamDataToPeer(stream_id, "foos", 3, !kFin, &last_packet); 2048 SendStreamDataToPeer(stream_id, "foos", 3, NO_FIN, &last_packet);
2049 SendStreamDataToPeer(stream_id, "fooos", 7, !kFin, &last_packet); 2049 SendStreamDataToPeer(stream_id, "fooos", 7, NO_FIN, &last_packet);
2050 2050
2051 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2051 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2052 connection_.SendRstStream(stream_id, QUIC_ERROR_PROCESSING_STREAM, 14); 2052 connection_.SendRstStream(stream_id, QUIC_ERROR_PROCESSING_STREAM, 14);
2053 2053
2054 // Lose a packet and ensure it does not trigger retransmission. 2054 // Lose a packet and ensure it does not trigger retransmission.
2055 QuicAckFrame nack_two = InitAckFrame(last_packet); 2055 QuicAckFrame nack_two = InitAckFrame(last_packet);
2056 NackPacket(last_packet - 1, &nack_two); 2056 NackPacket(last_packet - 1, &nack_two);
2057 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2057 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2058 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)); 2058 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _));
2059 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2059 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
2060 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); 2060 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0);
2061 ProcessAckPacket(&nack_two); 2061 ProcessAckPacket(&nack_two);
2062 } 2062 }
2063 2063
2064 TEST_P(QuicConnectionTest, RetransmitForQuicRstStreamNoErrorOnNack) { 2064 TEST_P(QuicConnectionTest, RetransmitForQuicRstStreamNoErrorOnNack) {
2065 QuicStreamId stream_id = 2; 2065 QuicStreamId stream_id = 2;
2066 QuicPacketNumber last_packet; 2066 QuicPacketNumber last_packet;
2067 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet); 2067 SendStreamDataToPeer(stream_id, "foo", 0, NO_FIN, &last_packet);
2068 SendStreamDataToPeer(stream_id, "foos", 3, !kFin, &last_packet); 2068 SendStreamDataToPeer(stream_id, "foos", 3, NO_FIN, &last_packet);
2069 SendStreamDataToPeer(stream_id, "fooos", 7, !kFin, &last_packet); 2069 SendStreamDataToPeer(stream_id, "fooos", 7, NO_FIN, &last_packet);
2070 2070
2071 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2071 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2072 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14); 2072 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14);
2073 2073
2074 // Lose a packet, ensure it triggers retransmission. 2074 // Lose a packet, ensure it triggers retransmission.
2075 QuicAckFrame nack_two = InitAckFrame(last_packet); 2075 QuicAckFrame nack_two = InitAckFrame(last_packet);
2076 NackPacket(last_packet - 1, &nack_two); 2076 NackPacket(last_packet - 1, &nack_two);
2077 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2077 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2078 SendAlgorithmInterface::CongestionVector lost_packets; 2078 SendAlgorithmInterface::CongestionVector lost_packets;
2079 lost_packets.push_back(std::make_pair(last_packet - 1, kMaxPacketSize)); 2079 lost_packets.push_back(std::make_pair(last_packet - 1, kMaxPacketSize));
2080 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)) 2080 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _))
2081 .WillOnce(SetArgPointee<4>(lost_packets)); 2081 .WillOnce(SetArgPointee<4>(lost_packets));
2082 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2082 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
2083 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AtLeast(1)); 2083 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AtLeast(1));
2084 ProcessAckPacket(&nack_two); 2084 ProcessAckPacket(&nack_two);
2085 } 2085 }
2086 2086
2087 TEST_P(QuicConnectionTest, DoNotRetransmitForResetStreamOnRTO) { 2087 TEST_P(QuicConnectionTest, DoNotRetransmitForResetStreamOnRTO) {
2088 QuicStreamId stream_id = 2; 2088 QuicStreamId stream_id = 2;
2089 QuicPacketNumber last_packet; 2089 QuicPacketNumber last_packet;
2090 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet); 2090 SendStreamDataToPeer(stream_id, "foo", 0, NO_FIN, &last_packet);
2091 2091
2092 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2092 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2093 connection_.SendRstStream(stream_id, QUIC_ERROR_PROCESSING_STREAM, 14); 2093 connection_.SendRstStream(stream_id, QUIC_ERROR_PROCESSING_STREAM, 14);
2094 2094
2095 // Fire the RTO and verify that the RST_STREAM is resent, not stream data. 2095 // Fire the RTO and verify that the RST_STREAM is resent, not stream data.
2096 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2096 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2097 clock_.AdvanceTime(DefaultRetransmissionTime()); 2097 clock_.AdvanceTime(DefaultRetransmissionTime());
2098 connection_.GetRetransmissionAlarm()->Fire(); 2098 connection_.GetRetransmissionAlarm()->Fire();
2099 EXPECT_EQ(1u, writer_->frame_count()); 2099 EXPECT_EQ(1u, writer_->frame_count());
2100 EXPECT_EQ(1u, writer_->rst_stream_frames().size()); 2100 EXPECT_EQ(1u, writer_->rst_stream_frames().size());
2101 EXPECT_EQ(stream_id, writer_->rst_stream_frames().front().stream_id); 2101 EXPECT_EQ(stream_id, writer_->rst_stream_frames().front().stream_id);
2102 } 2102 }
2103 2103
2104 // Ensure that if the only data in flight is non-retransmittable, the 2104 // Ensure that if the only data in flight is non-retransmittable, the
2105 // retransmission alarm is not set. 2105 // retransmission alarm is not set.
2106 TEST_P(QuicConnectionTest, CancelRetransmissionAlarmAfterResetStream) { 2106 TEST_P(QuicConnectionTest, CancelRetransmissionAlarmAfterResetStream) {
2107 QuicStreamId stream_id = 2; 2107 QuicStreamId stream_id = 2;
2108 QuicPacketNumber last_data_packet; 2108 QuicPacketNumber last_data_packet;
2109 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_data_packet); 2109 SendStreamDataToPeer(stream_id, "foo", 0, NO_FIN, &last_data_packet);
2110 2110
2111 // Cancel the stream. 2111 // Cancel the stream.
2112 const QuicPacketNumber rst_packet = last_data_packet + 1; 2112 const QuicPacketNumber rst_packet = last_data_packet + 1;
2113 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, rst_packet, _, _)).Times(1); 2113 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, rst_packet, _, _)).Times(1);
2114 connection_.SendRstStream(stream_id, QUIC_ERROR_PROCESSING_STREAM, 14); 2114 connection_.SendRstStream(stream_id, QUIC_ERROR_PROCESSING_STREAM, 14);
2115 2115
2116 // Ack the RST_STREAM frame (since it's retransmittable), but not the data 2116 // Ack the RST_STREAM frame (since it's retransmittable), but not the data
2117 // packet, which is no longer retransmittable since the stream was cancelled. 2117 // packet, which is no longer retransmittable since the stream was cancelled.
2118 QuicAckFrame nack_stream_data = InitAckFrame(rst_packet); 2118 QuicAckFrame nack_stream_data = InitAckFrame(rst_packet);
2119 NackPacket(last_data_packet, &nack_stream_data); 2119 NackPacket(last_data_packet, &nack_stream_data);
2120 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2120 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2121 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2121 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
2122 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); 2122 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0);
2123 ProcessAckPacket(&nack_stream_data); 2123 ProcessAckPacket(&nack_stream_data);
2124 2124
2125 // Ensure that the data is still in flight, but the retransmission alarm is no 2125 // Ensure that the data is still in flight, but the retransmission alarm is no
2126 // longer set. 2126 // longer set.
2127 EXPECT_GT(QuicSentPacketManagerPeer::GetBytesInFlight(manager_), 0u); 2127 EXPECT_GT(QuicSentPacketManagerPeer::GetBytesInFlight(manager_), 0u);
2128 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 2128 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2129 } 2129 }
2130 2130
2131 TEST_P(QuicConnectionTest, RetransmitForQuicRstStreamNoErrorOnRTO) { 2131 TEST_P(QuicConnectionTest, RetransmitForQuicRstStreamNoErrorOnRTO) {
2132 connection_.SetMaxTailLossProbes(0); 2132 connection_.SetMaxTailLossProbes(0);
2133 2133
2134 QuicStreamId stream_id = 2; 2134 QuicStreamId stream_id = 2;
2135 QuicPacketNumber last_packet; 2135 QuicPacketNumber last_packet;
2136 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet); 2136 SendStreamDataToPeer(stream_id, "foo", 0, NO_FIN, &last_packet);
2137 2137
2138 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2138 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2139 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14); 2139 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14);
2140 2140
2141 // Fire the RTO and verify that the RST_STREAM is resent, the stream data 2141 // Fire the RTO and verify that the RST_STREAM is resent, the stream data
2142 // is sent. 2142 // is sent.
2143 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AtLeast(2)); 2143 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AtLeast(2));
2144 clock_.AdvanceTime(DefaultRetransmissionTime()); 2144 clock_.AdvanceTime(DefaultRetransmissionTime());
2145 connection_.GetRetransmissionAlarm()->Fire(); 2145 connection_.GetRetransmissionAlarm()->Fire();
2146 EXPECT_EQ(1u, writer_->frame_count()); 2146 EXPECT_EQ(1u, writer_->frame_count());
2147 ASSERT_EQ(1u, writer_->rst_stream_frames().size()); 2147 ASSERT_EQ(1u, writer_->rst_stream_frames().size());
2148 EXPECT_EQ(stream_id, writer_->rst_stream_frames().front().stream_id); 2148 EXPECT_EQ(stream_id, writer_->rst_stream_frames().front().stream_id);
2149 } 2149 }
2150 2150
2151 TEST_P(QuicConnectionTest, DoNotSendPendingRetransmissionForResetStream) { 2151 TEST_P(QuicConnectionTest, DoNotSendPendingRetransmissionForResetStream) {
2152 QuicStreamId stream_id = 2; 2152 QuicStreamId stream_id = 2;
2153 QuicPacketNumber last_packet; 2153 QuicPacketNumber last_packet;
2154 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet); 2154 SendStreamDataToPeer(stream_id, "foo", 0, NO_FIN, &last_packet);
2155 SendStreamDataToPeer(stream_id, "foos", 3, !kFin, &last_packet); 2155 SendStreamDataToPeer(stream_id, "foos", 3, NO_FIN, &last_packet);
2156 BlockOnNextWrite(); 2156 BlockOnNextWrite();
2157 connection_.SendStreamDataWithString(stream_id, "fooos", 7, !kFin, nullptr); 2157 connection_.SendStreamDataWithString(stream_id, "fooos", 7, NO_FIN, nullptr);
2158 2158
2159 // Lose a packet which will trigger a pending retransmission. 2159 // Lose a packet which will trigger a pending retransmission.
2160 QuicAckFrame ack = InitAckFrame(last_packet); 2160 QuicAckFrame ack = InitAckFrame(last_packet);
2161 NackPacket(last_packet - 1, &ack); 2161 NackPacket(last_packet - 1, &ack);
2162 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2162 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2163 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)); 2163 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _));
2164 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2164 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
2165 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); 2165 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0);
2166 ProcessAckPacket(&ack); 2166 ProcessAckPacket(&ack);
2167 2167
2168 connection_.SendRstStream(stream_id, QUIC_ERROR_PROCESSING_STREAM, 14); 2168 connection_.SendRstStream(stream_id, QUIC_ERROR_PROCESSING_STREAM, 14);
2169 2169
2170 // Unblock the connection and verify that the RST_STREAM is sent but not the 2170 // Unblock the connection and verify that the RST_STREAM is sent but not the
2171 // second data packet nor a retransmit. 2171 // second data packet nor a retransmit.
2172 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2172 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2173 writer_->SetWritable(); 2173 writer_->SetWritable();
2174 connection_.OnCanWrite(); 2174 connection_.OnCanWrite();
2175 EXPECT_EQ(1u, writer_->frame_count()); 2175 EXPECT_EQ(1u, writer_->frame_count());
2176 EXPECT_EQ(1u, writer_->rst_stream_frames().size()); 2176 EXPECT_EQ(1u, writer_->rst_stream_frames().size());
2177 EXPECT_EQ(stream_id, writer_->rst_stream_frames().front().stream_id); 2177 EXPECT_EQ(stream_id, writer_->rst_stream_frames().front().stream_id);
2178 } 2178 }
2179 2179
2180 TEST_P(QuicConnectionTest, SendPendingRetransmissionForQuicRstStreamNoError) { 2180 TEST_P(QuicConnectionTest, SendPendingRetransmissionForQuicRstStreamNoError) {
2181 QuicStreamId stream_id = 2; 2181 QuicStreamId stream_id = 2;
2182 QuicPacketNumber last_packet; 2182 QuicPacketNumber last_packet;
2183 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet); 2183 SendStreamDataToPeer(stream_id, "foo", 0, NO_FIN, &last_packet);
2184 SendStreamDataToPeer(stream_id, "foos", 3, !kFin, &last_packet); 2184 SendStreamDataToPeer(stream_id, "foos", 3, NO_FIN, &last_packet);
2185 BlockOnNextWrite(); 2185 BlockOnNextWrite();
2186 connection_.SendStreamDataWithString(stream_id, "fooos", 7, !kFin, nullptr); 2186 connection_.SendStreamDataWithString(stream_id, "fooos", 7, NO_FIN, nullptr);
2187 2187
2188 // Lose a packet which will trigger a pending retransmission. 2188 // Lose a packet which will trigger a pending retransmission.
2189 QuicAckFrame ack = InitAckFrame(last_packet); 2189 QuicAckFrame ack = InitAckFrame(last_packet);
2190 NackPacket(last_packet - 1, &ack); 2190 NackPacket(last_packet - 1, &ack);
2191 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2191 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2192 SendAlgorithmInterface::CongestionVector lost_packets; 2192 SendAlgorithmInterface::CongestionVector lost_packets;
2193 lost_packets.push_back(std::make_pair(last_packet - 1, kMaxPacketSize)); 2193 lost_packets.push_back(std::make_pair(last_packet - 1, kMaxPacketSize));
2194 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)) 2194 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _))
2195 .WillOnce(SetArgPointee<4>(lost_packets)); 2195 .WillOnce(SetArgPointee<4>(lost_packets));
2196 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2196 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
2197 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); 2197 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0);
2198 ProcessAckPacket(&ack); 2198 ProcessAckPacket(&ack);
2199 2199
2200 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14); 2200 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14);
2201 2201
2202 // Unblock the connection and verify that the RST_STREAM is sent and the 2202 // Unblock the connection and verify that the RST_STREAM is sent and the
2203 // second data packet or a retransmit is sent. 2203 // second data packet or a retransmit is sent.
2204 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AtLeast(2)); 2204 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AtLeast(2));
2205 writer_->SetWritable(); 2205 writer_->SetWritable();
2206 connection_.OnCanWrite(); 2206 connection_.OnCanWrite();
2207 EXPECT_EQ(1u, writer_->frame_count()); 2207 EXPECT_EQ(1u, writer_->frame_count());
2208 EXPECT_EQ(0u, writer_->rst_stream_frames().size()); 2208 EXPECT_EQ(0u, writer_->rst_stream_frames().size());
2209 } 2209 }
2210 2210
2211 TEST_P(QuicConnectionTest, RetransmitAckedPacket) { 2211 TEST_P(QuicConnectionTest, RetransmitAckedPacket) {
2212 QuicPacketNumber last_packet; 2212 QuicPacketNumber last_packet;
2213 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 2213 SendStreamDataToPeer(1, "foo", 0, NO_FIN, &last_packet); // Packet 1
2214 SendStreamDataToPeer(1, "foos", 3, !kFin, &last_packet); // Packet 2 2214 SendStreamDataToPeer(1, "foos", 3, NO_FIN, &last_packet); // Packet 2
2215 SendStreamDataToPeer(1, "fooos", 7, !kFin, &last_packet); // Packet 3 2215 SendStreamDataToPeer(1, "fooos", 7, NO_FIN, &last_packet); // Packet 3
2216 2216
2217 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2217 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2218 2218
2219 // Instigate a loss with an ack. 2219 // Instigate a loss with an ack.
2220 QuicAckFrame nack_two = InitAckFrame(3); 2220 QuicAckFrame nack_two = InitAckFrame(3);
2221 NackPacket(2, &nack_two); 2221 NackPacket(2, &nack_two);
2222 // The first nack should trigger a fast retransmission, but we'll be 2222 // The first nack should trigger a fast retransmission, but we'll be
2223 // write blocked, so the packet will be queued. 2223 // write blocked, so the packet will be queued.
2224 BlockOnNextWrite(); 2224 BlockOnNextWrite();
2225 2225
(...skipping 22 matching lines...) Expand all
2248 EXPECT_FALSE(QuicConnectionPeer::HasRetransmittableFrames(&connection_, 4)); 2248 EXPECT_FALSE(QuicConnectionPeer::HasRetransmittableFrames(&connection_, 4));
2249 } 2249 }
2250 2250
2251 TEST_P(QuicConnectionTest, RetransmitNackedLargestObserved) { 2251 TEST_P(QuicConnectionTest, RetransmitNackedLargestObserved) {
2252 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2252 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2253 QuicPacketNumber largest_observed; 2253 QuicPacketNumber largest_observed;
2254 QuicByteCount packet_size; 2254 QuicByteCount packet_size;
2255 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 2255 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
2256 .WillOnce(DoAll(SaveArg<2>(&largest_observed), SaveArg<3>(&packet_size), 2256 .WillOnce(DoAll(SaveArg<2>(&largest_observed), SaveArg<3>(&packet_size),
2257 Return(true))); 2257 Return(true)));
2258 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); 2258 connection_.SendStreamDataWithString(3, "foo", 0, NO_FIN, nullptr);
2259 2259
2260 QuicAckFrame frame = InitAckFrame(1); 2260 QuicAckFrame frame = InitAckFrame(1);
2261 NackPacket(largest_observed, &frame); 2261 NackPacket(largest_observed, &frame);
2262 // The first nack should retransmit the largest observed packet. 2262 // The first nack should retransmit the largest observed packet.
2263 SendAlgorithmInterface::CongestionVector lost_packets; 2263 SendAlgorithmInterface::CongestionVector lost_packets;
2264 lost_packets.push_back(std::make_pair(1, kMaxPacketSize)); 2264 lost_packets.push_back(std::make_pair(1, kMaxPacketSize));
2265 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)) 2265 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _))
2266 .WillOnce(SetArgPointee<4>(lost_packets)); 2266 .WillOnce(SetArgPointee<4>(lost_packets));
2267 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2267 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
2268 EXPECT_CALL(*send_algorithm_, 2268 EXPECT_CALL(*send_algorithm_,
2269 OnPacketSent(_, _, _, packet_size - kQuicVersionSize, _)); 2269 OnPacketSent(_, _, _, packet_size - kQuicVersionSize, _));
2270 ProcessAckPacket(&frame); 2270 ProcessAckPacket(&frame);
2271 } 2271 }
2272 2272
2273 TEST_P(QuicConnectionTest, QueueAfterTwoRTOs) { 2273 TEST_P(QuicConnectionTest, QueueAfterTwoRTOs) {
2274 connection_.SetMaxTailLossProbes(0); 2274 connection_.SetMaxTailLossProbes(0);
2275 2275
2276 for (int i = 0; i < 10; ++i) { 2276 for (int i = 0; i < 10; ++i) {
2277 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2277 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2278 connection_.SendStreamDataWithString(3, "foo", i * 3, !kFin, nullptr); 2278 connection_.SendStreamDataWithString(3, "foo", i * 3, NO_FIN, nullptr);
2279 } 2279 }
2280 2280
2281 // Block the writer and ensure they're queued. 2281 // Block the writer and ensure they're queued.
2282 BlockOnNextWrite(); 2282 BlockOnNextWrite();
2283 clock_.AdvanceTime(DefaultRetransmissionTime()); 2283 clock_.AdvanceTime(DefaultRetransmissionTime());
2284 // Only one packet should be retransmitted. 2284 // Only one packet should be retransmitted.
2285 connection_.GetRetransmissionAlarm()->Fire(); 2285 connection_.GetRetransmissionAlarm()->Fire();
2286 EXPECT_TRUE(connection_.HasQueuedData()); 2286 EXPECT_TRUE(connection_.HasQueuedData());
2287 2287
2288 // Unblock the writer. 2288 // Unblock the writer.
2289 writer_->SetWritable(); 2289 writer_->SetWritable();
2290 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds( 2290 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(
2291 2 * DefaultRetransmissionTime().ToMicroseconds())); 2291 2 * DefaultRetransmissionTime().ToMicroseconds()));
2292 // Retransmit already retransmitted packets event though the packet number 2292 // Retransmit already retransmitted packets event though the packet number
2293 // greater than the largest observed. 2293 // greater than the largest observed.
2294 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); 2294 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
2295 connection_.GetRetransmissionAlarm()->Fire(); 2295 connection_.GetRetransmissionAlarm()->Fire();
2296 connection_.OnCanWrite(); 2296 connection_.OnCanWrite();
2297 } 2297 }
2298 2298
2299 TEST_P(QuicConnectionTest, WriteBlockedBufferedThenSent) { 2299 TEST_P(QuicConnectionTest, WriteBlockedBufferedThenSent) {
2300 BlockOnNextWrite(); 2300 BlockOnNextWrite();
2301 writer_->set_is_write_blocked_data_buffered(true); 2301 writer_->set_is_write_blocked_data_buffered(true);
2302 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2302 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2303 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); 2303 connection_.SendStreamDataWithString(1, "foo", 0, NO_FIN, nullptr);
2304 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 2304 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
2305 2305
2306 writer_->SetWritable(); 2306 writer_->SetWritable();
2307 connection_.OnCanWrite(); 2307 connection_.OnCanWrite();
2308 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 2308 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
2309 } 2309 }
2310 2310
2311 TEST_P(QuicConnectionTest, WriteBlockedThenSent) { 2311 TEST_P(QuicConnectionTest, WriteBlockedThenSent) {
2312 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); 2312 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0);
2313 BlockOnNextWrite(); 2313 BlockOnNextWrite();
2314 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); 2314 connection_.SendStreamDataWithString(1, "foo", 0, NO_FIN, nullptr);
2315 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 2315 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2316 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2316 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2317 2317
2318 // The second packet should also be queued, in order to ensure packets are 2318 // The second packet should also be queued, in order to ensure packets are
2319 // never sent out of order. 2319 // never sent out of order.
2320 writer_->SetWritable(); 2320 writer_->SetWritable();
2321 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); 2321 connection_.SendStreamDataWithString(1, "foo", 0, NO_FIN, nullptr);
2322 EXPECT_EQ(2u, connection_.NumQueuedPackets()); 2322 EXPECT_EQ(2u, connection_.NumQueuedPackets());
2323 2323
2324 // Now both are sent in order when we unblock. 2324 // Now both are sent in order when we unblock.
2325 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); 2325 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
2326 connection_.OnCanWrite(); 2326 connection_.OnCanWrite();
2327 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 2327 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
2328 } 2328 }
2329 2329
2330 TEST_P(QuicConnectionTest, RetransmitWriteBlockedAckedOriginalThenSent) { 2330 TEST_P(QuicConnectionTest, RetransmitWriteBlockedAckedOriginalThenSent) {
2331 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2331 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2332 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); 2332 connection_.SendStreamDataWithString(3, "foo", 0, NO_FIN, nullptr);
2333 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 2333 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
2334 2334
2335 BlockOnNextWrite(); 2335 BlockOnNextWrite();
2336 writer_->set_is_write_blocked_data_buffered(true); 2336 writer_->set_is_write_blocked_data_buffered(true);
2337 // Simulate the retransmission alarm firing. 2337 // Simulate the retransmission alarm firing.
2338 clock_.AdvanceTime(DefaultRetransmissionTime()); 2338 clock_.AdvanceTime(DefaultRetransmissionTime());
2339 connection_.GetRetransmissionAlarm()->Fire(); 2339 connection_.GetRetransmissionAlarm()->Fire();
2340 2340
2341 // Ack the sent packet before the callback returns, which happens in 2341 // Ack the sent packet before the callback returns, which happens in
2342 // rare circumstances with write blocked sockets. 2342 // rare circumstances with write blocked sockets.
2343 QuicAckFrame ack = InitAckFrame(1); 2343 QuicAckFrame ack = InitAckFrame(1);
2344 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2344 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
2345 ProcessAckPacket(&ack); 2345 ProcessAckPacket(&ack);
2346 2346
2347 writer_->SetWritable(); 2347 writer_->SetWritable();
2348 connection_.OnCanWrite(); 2348 connection_.OnCanWrite();
2349 // There is now a pending packet, but with no retransmittable frames. 2349 // There is now a pending packet, but with no retransmittable frames.
2350 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 2350 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2351 EXPECT_FALSE(QuicConnectionPeer::HasRetransmittableFrames(&connection_, 2)); 2351 EXPECT_FALSE(QuicConnectionPeer::HasRetransmittableFrames(&connection_, 2));
2352 } 2352 }
2353 2353
2354 TEST_P(QuicConnectionTest, AlarmsWhenWriteBlocked) { 2354 TEST_P(QuicConnectionTest, AlarmsWhenWriteBlocked) {
2355 // Block the connection. 2355 // Block the connection.
2356 BlockOnNextWrite(); 2356 BlockOnNextWrite();
2357 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); 2357 connection_.SendStreamDataWithString(3, "foo", 0, NO_FIN, nullptr);
2358 EXPECT_EQ(1u, writer_->packets_write_attempts()); 2358 EXPECT_EQ(1u, writer_->packets_write_attempts());
2359 EXPECT_TRUE(writer_->IsWriteBlocked()); 2359 EXPECT_TRUE(writer_->IsWriteBlocked());
2360 2360
2361 // Set the send and resumption alarms. Fire the alarms and ensure they don't 2361 // Set the send and resumption alarms. Fire the alarms and ensure they don't
2362 // attempt to write. 2362 // attempt to write.
2363 connection_.GetResumeWritesAlarm()->Set(clock_.ApproximateNow()); 2363 connection_.GetResumeWritesAlarm()->Set(clock_.ApproximateNow());
2364 connection_.GetSendAlarm()->Set(clock_.ApproximateNow()); 2364 connection_.GetSendAlarm()->Set(clock_.ApproximateNow());
2365 connection_.GetResumeWritesAlarm()->Fire(); 2365 connection_.GetResumeWritesAlarm()->Fire();
2366 connection_.GetSendAlarm()->Fire(); 2366 connection_.GetSendAlarm()->Fire();
2367 EXPECT_TRUE(writer_->IsWriteBlocked()); 2367 EXPECT_TRUE(writer_->IsWriteBlocked());
2368 EXPECT_EQ(1u, writer_->packets_write_attempts()); 2368 EXPECT_EQ(1u, writer_->packets_write_attempts());
2369 } 2369 }
2370 2370
2371 TEST_P(QuicConnectionTest, NoLimitPacketsPerNack) { 2371 TEST_P(QuicConnectionTest, NoLimitPacketsPerNack) {
2372 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2372 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2373 int offset = 0; 2373 int offset = 0;
2374 // Send packets 1 to 15. 2374 // Send packets 1 to 15.
2375 for (int i = 0; i < 15; ++i) { 2375 for (int i = 0; i < 15; ++i) {
2376 SendStreamDataToPeer(1, "foo", offset, !kFin, nullptr); 2376 SendStreamDataToPeer(1, "foo", offset, NO_FIN, nullptr);
2377 offset += 3; 2377 offset += 3;
2378 } 2378 }
2379 2379
2380 // Ack 15, nack 1-14. 2380 // Ack 15, nack 1-14.
2381 2381
2382 QuicAckFrame nack = InitAckFrame(15); 2382 QuicAckFrame nack = InitAckFrame(15);
2383 for (int i = 1; i < 15; ++i) { 2383 for (int i = 1; i < 15; ++i) {
2384 NackPacket(i, &nack); 2384 NackPacket(i, &nack);
2385 } 2385 }
2386 2386
2387 // 14 packets have been NACK'd and lost. 2387 // 14 packets have been NACK'd and lost.
2388 SendAlgorithmInterface::CongestionVector lost_packets; 2388 SendAlgorithmInterface::CongestionVector lost_packets;
2389 for (int i = 1; i < 15; ++i) { 2389 for (int i = 1; i < 15; ++i) {
2390 lost_packets.push_back(std::make_pair(i, kMaxPacketSize)); 2390 lost_packets.push_back(std::make_pair(i, kMaxPacketSize));
2391 } 2391 }
2392 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)) 2392 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _))
2393 .WillOnce(SetArgPointee<4>(lost_packets)); 2393 .WillOnce(SetArgPointee<4>(lost_packets));
2394 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2394 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
2395 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(14); 2395 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(14);
2396 ProcessAckPacket(&nack); 2396 ProcessAckPacket(&nack);
2397 } 2397 }
2398 2398
2399 // Test sending multiple acks from the connection to the session. 2399 // Test sending multiple acks from the connection to the session.
2400 TEST_P(QuicConnectionTest, MultipleAcks) { 2400 TEST_P(QuicConnectionTest, MultipleAcks) {
2401 QuicPacketNumber last_packet; 2401 QuicPacketNumber last_packet;
2402 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 2402 SendStreamDataToPeer(1, "foo", 0, NO_FIN, &last_packet); // Packet 1
2403 EXPECT_EQ(1u, last_packet); 2403 EXPECT_EQ(1u, last_packet);
2404 SendStreamDataToPeer(3, "foo", 0, !kFin, &last_packet); // Packet 2 2404 SendStreamDataToPeer(3, "foo", 0, NO_FIN, &last_packet); // Packet 2
2405 EXPECT_EQ(2u, last_packet); 2405 EXPECT_EQ(2u, last_packet);
2406 SendAckPacketToPeer(); // Packet 3 2406 SendAckPacketToPeer(); // Packet 3
2407 SendStreamDataToPeer(5, "foo", 0, !kFin, &last_packet); // Packet 4 2407 SendStreamDataToPeer(5, "foo", 0, NO_FIN, &last_packet); // Packet 4
2408 EXPECT_EQ(4u, last_packet); 2408 EXPECT_EQ(4u, last_packet);
2409 SendStreamDataToPeer(1, "foo", 3, !kFin, &last_packet); // Packet 5 2409 SendStreamDataToPeer(1, "foo", 3, NO_FIN, &last_packet); // Packet 5
2410 EXPECT_EQ(5u, last_packet); 2410 EXPECT_EQ(5u, last_packet);
2411 SendStreamDataToPeer(3, "foo", 3, !kFin, &last_packet); // Packet 6 2411 SendStreamDataToPeer(3, "foo", 3, NO_FIN, &last_packet); // Packet 6
2412 EXPECT_EQ(6u, last_packet); 2412 EXPECT_EQ(6u, last_packet);
2413 2413
2414 // Client will ack packets 1, 2, [!3], 4, 5. 2414 // Client will ack packets 1, 2, [!3], 4, 5.
2415 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2415 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
2416 QuicAckFrame frame1 = InitAckFrame(5); 2416 QuicAckFrame frame1 = InitAckFrame(5);
2417 NackPacket(3, &frame1); 2417 NackPacket(3, &frame1);
2418 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2418 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2419 ProcessAckPacket(&frame1); 2419 ProcessAckPacket(&frame1);
2420 2420
2421 // Now the client implicitly acks 3, and explicitly acks 6. 2421 // Now the client implicitly acks 3, and explicitly acks 6.
2422 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2422 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
2423 QuicAckFrame frame2 = InitAckFrame(6); 2423 QuicAckFrame frame2 = InitAckFrame(6);
2424 ProcessAckPacket(&frame2); 2424 ProcessAckPacket(&frame2);
2425 } 2425 }
2426 2426
2427 TEST_P(QuicConnectionTest, DontLatchUnackedPacket) { 2427 TEST_P(QuicConnectionTest, DontLatchUnackedPacket) {
2428 SendStreamDataToPeer(1, "foo", 0, !kFin, nullptr); // Packet 1; 2428 SendStreamDataToPeer(1, "foo", 0, NO_FIN, nullptr); // Packet 1;
2429 // From now on, we send acks, so the send algorithm won't mark them pending. 2429 // From now on, we send acks, so the send algorithm won't mark them pending.
2430 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 2430 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
2431 .WillByDefault(Return(false)); 2431 .WillByDefault(Return(false));
2432 SendAckPacketToPeer(); // Packet 2 2432 SendAckPacketToPeer(); // Packet 2
2433 2433
2434 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2434 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2435 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2435 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
2436 QuicAckFrame frame = InitAckFrame(1); 2436 QuicAckFrame frame = InitAckFrame(1);
2437 ProcessAckPacket(&frame); 2437 ProcessAckPacket(&frame);
2438 2438
(...skipping 21 matching lines...) Expand all
2460 EXPECT_EQ(3u, least_unacked()); 2460 EXPECT_EQ(3u, least_unacked());
2461 } 2461 }
2462 2462
2463 // Ack the ack, which updates the rtt and raises the least unacked. 2463 // Ack the ack, which updates the rtt and raises the least unacked.
2464 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2464 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
2465 frame = InitAckFrame(3); 2465 frame = InitAckFrame(3);
2466 ProcessAckPacket(&frame); 2466 ProcessAckPacket(&frame);
2467 2467
2468 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 2468 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
2469 .WillByDefault(Return(true)); 2469 .WillByDefault(Return(true));
2470 SendStreamDataToPeer(1, "bar", 3, false, nullptr); // Packet 4 2470 SendStreamDataToPeer(1, "bar", 3, NO_FIN, nullptr); // Packet 4
2471 EXPECT_EQ(4u, stop_waiting()->least_unacked); 2471 EXPECT_EQ(4u, stop_waiting()->least_unacked);
2472 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 2472 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
2473 .WillByDefault(Return(false)); 2473 .WillByDefault(Return(false));
2474 SendAckPacketToPeer(); // Packet 5 2474 SendAckPacketToPeer(); // Packet 5
2475 if (GetParam().no_stop_waiting) { 2475 if (GetParam().no_stop_waiting) {
2476 // Expect no stop waiting frame is sent. 2476 // Expect no stop waiting frame is sent.
2477 EXPECT_EQ(0u, least_unacked()); 2477 EXPECT_EQ(0u, least_unacked());
2478 } else { 2478 } else {
2479 EXPECT_EQ(4u, least_unacked()); 2479 EXPECT_EQ(4u, least_unacked());
2480 } 2480 }
2481 2481
2482 // Send two data packets at the end, and ensure if the last one is acked, 2482 // Send two data packets at the end, and ensure if the last one is acked,
2483 // the least unacked is raised above the ack packets. 2483 // the least unacked is raised above the ack packets.
2484 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 2484 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
2485 .WillByDefault(Return(true)); 2485 .WillByDefault(Return(true));
2486 SendStreamDataToPeer(1, "bar", 6, false, nullptr); // Packet 6 2486 SendStreamDataToPeer(1, "bar", 6, NO_FIN, nullptr); // Packet 6
2487 SendStreamDataToPeer(1, "bar", 9, false, nullptr); // Packet 7 2487 SendStreamDataToPeer(1, "bar", 9, NO_FIN, nullptr); // Packet 7
2488 2488
2489 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2489 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
2490 frame = InitAckFrame(7); 2490 frame = InitAckFrame(7);
2491 NackPacket(5, &frame); 2491 NackPacket(5, &frame);
2492 NackPacket(6, &frame); 2492 NackPacket(6, &frame);
2493 ProcessAckPacket(&frame); 2493 ProcessAckPacket(&frame);
2494 2494
2495 EXPECT_EQ(6u, stop_waiting()->least_unacked); 2495 EXPECT_EQ(6u, stop_waiting()->least_unacked);
2496 } 2496 }
2497 2497
2498 TEST_P(QuicConnectionTest, TLP) { 2498 TEST_P(QuicConnectionTest, TLP) {
2499 connection_.SetMaxTailLossProbes(1); 2499 connection_.SetMaxTailLossProbes(1);
2500 2500
2501 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr); 2501 SendStreamDataToPeer(3, "foo", 0, NO_FIN, nullptr);
2502 EXPECT_EQ(1u, stop_waiting()->least_unacked); 2502 EXPECT_EQ(1u, stop_waiting()->least_unacked);
2503 QuicTime retransmission_time = 2503 QuicTime retransmission_time =
2504 connection_.GetRetransmissionAlarm()->deadline(); 2504 connection_.GetRetransmissionAlarm()->deadline();
2505 EXPECT_NE(QuicTime::Zero(), retransmission_time); 2505 EXPECT_NE(QuicTime::Zero(), retransmission_time);
2506 2506
2507 EXPECT_EQ(1u, writer_->header().packet_number); 2507 EXPECT_EQ(1u, writer_->header().packet_number);
2508 // Simulate the retransmission alarm firing and sending a tlp, 2508 // Simulate the retransmission alarm firing and sending a tlp,
2509 // so send algorithm's OnRetransmissionTimeout is not called. 2509 // so send algorithm's OnRetransmissionTimeout is not called.
2510 clock_.AdvanceTime(retransmission_time - clock_.Now()); 2510 clock_.AdvanceTime(retransmission_time - clock_.Now());
2511 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _)); 2511 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _));
2512 connection_.GetRetransmissionAlarm()->Fire(); 2512 connection_.GetRetransmissionAlarm()->Fire();
2513 EXPECT_EQ(2u, writer_->header().packet_number); 2513 EXPECT_EQ(2u, writer_->header().packet_number);
2514 // We do not raise the high water mark yet. 2514 // We do not raise the high water mark yet.
2515 EXPECT_EQ(1u, stop_waiting()->least_unacked); 2515 EXPECT_EQ(1u, stop_waiting()->least_unacked);
2516 } 2516 }
2517 2517
2518 TEST_P(QuicConnectionTest, RTO) { 2518 TEST_P(QuicConnectionTest, RTO) {
2519 connection_.SetMaxTailLossProbes(0); 2519 connection_.SetMaxTailLossProbes(0);
2520 2520
2521 QuicTime default_retransmission_time = 2521 QuicTime default_retransmission_time =
2522 clock_.ApproximateNow() + DefaultRetransmissionTime(); 2522 clock_.ApproximateNow() + DefaultRetransmissionTime();
2523 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr); 2523 SendStreamDataToPeer(3, "foo", 0, NO_FIN, nullptr);
2524 EXPECT_EQ(1u, stop_waiting()->least_unacked); 2524 EXPECT_EQ(1u, stop_waiting()->least_unacked);
2525 2525
2526 EXPECT_EQ(1u, writer_->header().packet_number); 2526 EXPECT_EQ(1u, writer_->header().packet_number);
2527 EXPECT_EQ(default_retransmission_time, 2527 EXPECT_EQ(default_retransmission_time,
2528 connection_.GetRetransmissionAlarm()->deadline()); 2528 connection_.GetRetransmissionAlarm()->deadline());
2529 // Simulate the retransmission alarm firing. 2529 // Simulate the retransmission alarm firing.
2530 clock_.AdvanceTime(DefaultRetransmissionTime()); 2530 clock_.AdvanceTime(DefaultRetransmissionTime());
2531 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _)); 2531 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _));
2532 connection_.GetRetransmissionAlarm()->Fire(); 2532 connection_.GetRetransmissionAlarm()->Fire();
2533 EXPECT_EQ(2u, writer_->header().packet_number); 2533 EXPECT_EQ(2u, writer_->header().packet_number);
2534 // We do not raise the high water mark yet. 2534 // We do not raise the high water mark yet.
2535 EXPECT_EQ(1u, stop_waiting()->least_unacked); 2535 EXPECT_EQ(1u, stop_waiting()->least_unacked);
2536 } 2536 }
2537 2537
2538 TEST_P(QuicConnectionTest, RetransmitWithSameEncryptionLevel) { 2538 TEST_P(QuicConnectionTest, RetransmitWithSameEncryptionLevel) {
2539 use_tagging_decrypter(); 2539 use_tagging_decrypter();
2540 2540
2541 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at 2541 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at
2542 // the end of the packet. We can test this to check which encrypter was used. 2542 // the end of the packet. We can test this to check which encrypter was used.
2543 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); 2543 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01));
2544 SendStreamDataToPeer(kCryptoStreamId, "foo", 0, !kFin, nullptr); 2544 SendStreamDataToPeer(kCryptoStreamId, "foo", 0, NO_FIN, nullptr);
2545 EXPECT_EQ(0x01010101u, writer_->final_bytes_of_last_packet()); 2545 EXPECT_EQ(0x01010101u, writer_->final_bytes_of_last_packet());
2546 2546
2547 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); 2547 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02));
2548 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); 2548 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
2549 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr); 2549 SendStreamDataToPeer(3, "foo", 0, NO_FIN, nullptr);
2550 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet()); 2550 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet());
2551 2551
2552 { 2552 {
2553 InSequence s; 2553 InSequence s;
2554 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 3, _, _)); 2554 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 3, _, _));
2555 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 4, _, _)); 2555 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 4, _, _));
2556 } 2556 }
2557 2557
2558 // Manually mark both packets for retransmission. 2558 // Manually mark both packets for retransmission.
2559 connection_.RetransmitUnackedPackets(ALL_UNACKED_RETRANSMISSION); 2559 connection_.RetransmitUnackedPackets(ALL_UNACKED_RETRANSMISSION);
2560 2560
2561 // Packet should have been sent with ENCRYPTION_NONE. 2561 // Packet should have been sent with ENCRYPTION_NONE.
2562 EXPECT_EQ(0x01010101u, writer_->final_bytes_of_previous_packet()); 2562 EXPECT_EQ(0x01010101u, writer_->final_bytes_of_previous_packet());
2563 2563
2564 // Packet should have been sent with ENCRYPTION_INITIAL. 2564 // Packet should have been sent with ENCRYPTION_INITIAL.
2565 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet()); 2565 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet());
2566 } 2566 }
2567 2567
2568 TEST_P(QuicConnectionTest, SendHandshakeMessages) { 2568 TEST_P(QuicConnectionTest, SendHandshakeMessages) {
2569 use_tagging_decrypter(); 2569 use_tagging_decrypter();
2570 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at 2570 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at
2571 // the end of the packet. We can test this to check which encrypter was used. 2571 // the end of the packet. We can test this to check which encrypter was used.
2572 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); 2572 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01));
2573 2573
2574 // Attempt to send a handshake message and have the socket block. 2574 // Attempt to send a handshake message and have the socket block.
2575 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _)) 2575 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _))
2576 .WillRepeatedly(testing::Return(QuicTime::Delta::Zero())); 2576 .WillRepeatedly(testing::Return(QuicTime::Delta::Zero()));
2577 BlockOnNextWrite(); 2577 BlockOnNextWrite();
2578 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); 2578 connection_.SendStreamDataWithString(1, "foo", 0, NO_FIN, nullptr);
2579 // The packet should be serialized, but not queued. 2579 // The packet should be serialized, but not queued.
2580 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2580 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2581 2581
2582 // Switch to the new encrypter. 2582 // Switch to the new encrypter.
2583 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); 2583 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02));
2584 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); 2584 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
2585 2585
2586 // Now become writeable and flush the packets. 2586 // Now become writeable and flush the packets.
2587 writer_->SetWritable(); 2587 writer_->SetWritable();
2588 EXPECT_CALL(visitor_, OnCanWrite()); 2588 EXPECT_CALL(visitor_, OnCanWrite());
2589 connection_.OnCanWrite(); 2589 connection_.OnCanWrite();
2590 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2590 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2591 2591
2592 // Verify that the handshake packet went out at the null encryption. 2592 // Verify that the handshake packet went out at the null encryption.
2593 EXPECT_EQ(0x01010101u, writer_->final_bytes_of_last_packet()); 2593 EXPECT_EQ(0x01010101u, writer_->final_bytes_of_last_packet());
2594 } 2594 }
2595 2595
2596 TEST_P(QuicConnectionTest, 2596 TEST_P(QuicConnectionTest,
2597 DropRetransmitsForNullEncryptedPacketAfterForwardSecure) { 2597 DropRetransmitsForNullEncryptedPacketAfterForwardSecure) {
2598 use_tagging_decrypter(); 2598 use_tagging_decrypter();
2599 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); 2599 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01));
2600 QuicPacketNumber packet_number; 2600 QuicPacketNumber packet_number;
2601 SendStreamDataToPeer(kCryptoStreamId, "foo", 0, !kFin, &packet_number); 2601 SendStreamDataToPeer(kCryptoStreamId, "foo", 0, NO_FIN, &packet_number);
2602 2602
2603 // Simulate the retransmission alarm firing and the socket blocking. 2603 // Simulate the retransmission alarm firing and the socket blocking.
2604 BlockOnNextWrite(); 2604 BlockOnNextWrite();
2605 clock_.AdvanceTime(DefaultRetransmissionTime()); 2605 clock_.AdvanceTime(DefaultRetransmissionTime());
2606 connection_.GetRetransmissionAlarm()->Fire(); 2606 connection_.GetRetransmissionAlarm()->Fire();
2607 2607
2608 // Go forward secure. 2608 // Go forward secure.
2609 connection_.SetEncrypter(ENCRYPTION_FORWARD_SECURE, 2609 connection_.SetEncrypter(ENCRYPTION_FORWARD_SECURE,
2610 new TaggingEncrypter(0x02)); 2610 new TaggingEncrypter(0x02));
2611 connection_.SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); 2611 connection_.SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE);
2612 connection_.NeuterUnencryptedPackets(); 2612 connection_.NeuterUnencryptedPackets();
2613 2613
2614 EXPECT_EQ(QuicTime::Zero(), connection_.GetRetransmissionAlarm()->deadline()); 2614 EXPECT_EQ(QuicTime::Zero(), connection_.GetRetransmissionAlarm()->deadline());
2615 // Unblock the socket and ensure that no packets are sent. 2615 // Unblock the socket and ensure that no packets are sent.
2616 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); 2616 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0);
2617 writer_->SetWritable(); 2617 writer_->SetWritable();
2618 connection_.OnCanWrite(); 2618 connection_.OnCanWrite();
2619 } 2619 }
2620 2620
2621 TEST_P(QuicConnectionTest, RetransmitPacketsWithInitialEncryption) { 2621 TEST_P(QuicConnectionTest, RetransmitPacketsWithInitialEncryption) {
2622 use_tagging_decrypter(); 2622 use_tagging_decrypter();
2623 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); 2623 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01));
2624 connection_.SetDefaultEncryptionLevel(ENCRYPTION_NONE); 2624 connection_.SetDefaultEncryptionLevel(ENCRYPTION_NONE);
2625 2625
2626 SendStreamDataToPeer(1, "foo", 0, !kFin, nullptr); 2626 SendStreamDataToPeer(1, "foo", 0, NO_FIN, nullptr);
2627 2627
2628 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); 2628 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02));
2629 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); 2629 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
2630 2630
2631 SendStreamDataToPeer(2, "bar", 0, !kFin, nullptr); 2631 SendStreamDataToPeer(2, "bar", 0, NO_FIN, nullptr);
2632 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2632 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2633 2633
2634 connection_.RetransmitUnackedPackets(ALL_INITIAL_RETRANSMISSION); 2634 connection_.RetransmitUnackedPackets(ALL_INITIAL_RETRANSMISSION);
2635 } 2635 }
2636 2636
2637 TEST_P(QuicConnectionTest, BufferNonDecryptablePackets) { 2637 TEST_P(QuicConnectionTest, BufferNonDecryptablePackets) {
2638 // SetFromConfig is always called after construction from InitializeSession. 2638 // SetFromConfig is always called after construction from InitializeSession.
2639 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); 2639 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _));
2640 QuicConfig config; 2640 QuicConfig config;
2641 connection_.SetFromConfig(config); 2641 connection_.SetFromConfig(config);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2695 ProcessDataPacketAtLevel(102, !kHasStopWaiting, ENCRYPTION_INITIAL); 2695 ProcessDataPacketAtLevel(102, !kHasStopWaiting, ENCRYPTION_INITIAL);
2696 } 2696 }
2697 2697
2698 TEST_P(QuicConnectionTest, TestRetransmitOrder) { 2698 TEST_P(QuicConnectionTest, TestRetransmitOrder) {
2699 connection_.SetMaxTailLossProbes(0); 2699 connection_.SetMaxTailLossProbes(0);
2700 2700
2701 QuicByteCount first_packet_size; 2701 QuicByteCount first_packet_size;
2702 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 2702 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
2703 .WillOnce(DoAll(SaveArg<3>(&first_packet_size), Return(true))); 2703 .WillOnce(DoAll(SaveArg<3>(&first_packet_size), Return(true)));
2704 2704
2705 connection_.SendStreamDataWithString(3, "first_packet", 0, !kFin, nullptr); 2705 connection_.SendStreamDataWithString(3, "first_packet", 0, NO_FIN, nullptr);
2706 QuicByteCount second_packet_size; 2706 QuicByteCount second_packet_size;
2707 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 2707 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
2708 .WillOnce(DoAll(SaveArg<3>(&second_packet_size), Return(true))); 2708 .WillOnce(DoAll(SaveArg<3>(&second_packet_size), Return(true)));
2709 connection_.SendStreamDataWithString(3, "second_packet", 12, !kFin, nullptr); 2709 connection_.SendStreamDataWithString(3, "second_packet", 12, NO_FIN, nullptr);
2710 EXPECT_NE(first_packet_size, second_packet_size); 2710 EXPECT_NE(first_packet_size, second_packet_size);
2711 // Advance the clock by huge time to make sure packets will be retransmitted. 2711 // Advance the clock by huge time to make sure packets will be retransmitted.
2712 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10)); 2712 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10));
2713 { 2713 {
2714 InSequence s; 2714 InSequence s;
2715 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, first_packet_size, _)); 2715 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, first_packet_size, _));
2716 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, second_packet_size, _)); 2716 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, second_packet_size, _));
2717 } 2717 }
2718 connection_.GetRetransmissionAlarm()->Fire(); 2718 connection_.GetRetransmissionAlarm()->Fire();
2719 2719
2720 // Advance again and expect the packets to be sent again in the same order. 2720 // Advance again and expect the packets to be sent again in the same order.
2721 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(20)); 2721 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(20));
2722 { 2722 {
2723 InSequence s; 2723 InSequence s;
2724 EXPECT_CALL(visitor_, OnPathDegrading()); 2724 EXPECT_CALL(visitor_, OnPathDegrading());
2725 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, first_packet_size, _)); 2725 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, first_packet_size, _));
2726 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, second_packet_size, _)); 2726 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, second_packet_size, _));
2727 } 2727 }
2728 connection_.GetRetransmissionAlarm()->Fire(); 2728 connection_.GetRetransmissionAlarm()->Fire();
2729 } 2729 }
2730 2730
2731 TEST_P(QuicConnectionTest, SetRTOAfterWritingToSocket) { 2731 TEST_P(QuicConnectionTest, SetRTOAfterWritingToSocket) {
2732 BlockOnNextWrite(); 2732 BlockOnNextWrite();
2733 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); 2733 connection_.SendStreamDataWithString(1, "foo", 0, NO_FIN, nullptr);
2734 // Make sure that RTO is not started when the packet is queued. 2734 // Make sure that RTO is not started when the packet is queued.
2735 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 2735 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2736 2736
2737 // Test that RTO is started once we write to the socket. 2737 // Test that RTO is started once we write to the socket.
2738 writer_->SetWritable(); 2738 writer_->SetWritable();
2739 connection_.OnCanWrite(); 2739 connection_.OnCanWrite();
2740 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 2740 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
2741 } 2741 }
2742 2742
2743 TEST_P(QuicConnectionTest, DelayRTOWithAckReceipt) { 2743 TEST_P(QuicConnectionTest, DelayRTOWithAckReceipt) {
2744 connection_.SetMaxTailLossProbes(0); 2744 connection_.SetMaxTailLossProbes(0);
2745 2745
2746 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2746 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2747 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); 2747 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
2748 connection_.SendStreamDataWithString(2, "foo", 0, !kFin, nullptr); 2748 connection_.SendStreamDataWithString(2, "foo", 0, NO_FIN, nullptr);
2749 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, nullptr); 2749 connection_.SendStreamDataWithString(3, "bar", 0, NO_FIN, nullptr);
2750 QuicAlarm* retransmission_alarm = connection_.GetRetransmissionAlarm(); 2750 QuicAlarm* retransmission_alarm = connection_.GetRetransmissionAlarm();
2751 EXPECT_TRUE(retransmission_alarm->IsSet()); 2751 EXPECT_TRUE(retransmission_alarm->IsSet());
2752 EXPECT_EQ(clock_.Now() + DefaultRetransmissionTime(), 2752 EXPECT_EQ(clock_.Now() + DefaultRetransmissionTime(),
2753 retransmission_alarm->deadline()); 2753 retransmission_alarm->deadline());
2754 2754
2755 // Advance the time right before the RTO, then receive an ack for the first 2755 // Advance the time right before the RTO, then receive an ack for the first
2756 // packet to delay the RTO. 2756 // packet to delay the RTO.
2757 clock_.AdvanceTime(DefaultRetransmissionTime()); 2757 clock_.AdvanceTime(DefaultRetransmissionTime());
2758 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2758 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
2759 QuicAckFrame ack = InitAckFrame(1); 2759 QuicAckFrame ack = InitAckFrame(1);
(...skipping 21 matching lines...) Expand all
2781 QuicTime expected_rto_time = 2781 QuicTime expected_rto_time =
2782 connection_.sent_packet_manager().GetRetransmissionTime(); 2782 connection_.sent_packet_manager().GetRetransmissionTime();
2783 EXPECT_EQ(next_rto_time, expected_rto_time); 2783 EXPECT_EQ(next_rto_time, expected_rto_time);
2784 } 2784 }
2785 2785
2786 TEST_P(QuicConnectionTest, TestQueued) { 2786 TEST_P(QuicConnectionTest, TestQueued) {
2787 connection_.SetMaxTailLossProbes(0); 2787 connection_.SetMaxTailLossProbes(0);
2788 2788
2789 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2789 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2790 BlockOnNextWrite(); 2790 BlockOnNextWrite();
2791 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); 2791 connection_.SendStreamDataWithString(1, "foo", 0, NO_FIN, nullptr);
2792 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2792 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2793 2793
2794 // Unblock the writes and actually send. 2794 // Unblock the writes and actually send.
2795 writer_->SetWritable(); 2795 writer_->SetWritable();
2796 connection_.OnCanWrite(); 2796 connection_.OnCanWrite();
2797 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2797 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2798 } 2798 }
2799 2799
2800 TEST_P(QuicConnectionTest, InitialTimeout) { 2800 TEST_P(QuicConnectionTest, InitialTimeout) {
2801 EXPECT_TRUE(connection_.connected()); 2801 EXPECT_TRUE(connection_.connected());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2835 connection_.SetNetworkTimeouts(timeout, timeout); 2835 connection_.SetNetworkTimeouts(timeout, timeout);
2836 EXPECT_TRUE(connection_.connected()); 2836 EXPECT_TRUE(connection_.connected());
2837 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber()); 2837 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber());
2838 2838
2839 QuicTime handshake_timeout = 2839 QuicTime handshake_timeout =
2840 clock_.ApproximateNow() + timeout - QuicTime::Delta::FromSeconds(1); 2840 clock_.ApproximateNow() + timeout - QuicTime::Delta::FromSeconds(1);
2841 EXPECT_EQ(handshake_timeout, connection_.GetTimeoutAlarm()->deadline()); 2841 EXPECT_EQ(handshake_timeout, connection_.GetTimeoutAlarm()->deadline());
2842 EXPECT_TRUE(connection_.connected()); 2842 EXPECT_TRUE(connection_.connected());
2843 2843
2844 // Send and ack new data 3 seconds later to lengthen the idle timeout. 2844 // Send and ack new data 3 seconds later to lengthen the idle timeout.
2845 SendStreamDataToPeer(kHeadersStreamId, "GET /", 0, kFin, nullptr); 2845 SendStreamDataToPeer(kHeadersStreamId, "GET /", 0, FIN, nullptr);
2846 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(3)); 2846 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(3));
2847 QuicAckFrame frame = InitAckFrame(1); 2847 QuicAckFrame frame = InitAckFrame(1);
2848 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2848 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2849 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2849 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
2850 ProcessAckPacket(&frame); 2850 ProcessAckPacket(&frame);
2851 2851
2852 // Fire early to verify it wouldn't timeout yet. 2852 // Fire early to verify it wouldn't timeout yet.
2853 connection_.GetTimeoutAlarm()->Fire(); 2853 connection_.GetTimeoutAlarm()->Fire();
2854 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet()); 2854 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet());
2855 EXPECT_TRUE(connection_.connected()); 2855 EXPECT_TRUE(connection_.connected());
(...skipping 17 matching lines...) Expand all
2873 2873
2874 TEST_P(QuicConnectionTest, PingAfterSend) { 2874 TEST_P(QuicConnectionTest, PingAfterSend) {
2875 EXPECT_TRUE(connection_.connected()); 2875 EXPECT_TRUE(connection_.connected());
2876 EXPECT_CALL(visitor_, HasOpenDynamicStreams()).WillRepeatedly(Return(true)); 2876 EXPECT_CALL(visitor_, HasOpenDynamicStreams()).WillRepeatedly(Return(true));
2877 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); 2877 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet());
2878 2878
2879 // Advance to 5ms, and send a packet to the peer, which will set 2879 // Advance to 5ms, and send a packet to the peer, which will set
2880 // the ping alarm. 2880 // the ping alarm.
2881 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); 2881 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5));
2882 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 2882 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2883 SendStreamDataToPeer(kHeadersStreamId, "GET /", 0, kFin, nullptr); 2883 SendStreamDataToPeer(kHeadersStreamId, "GET /", 0, FIN, nullptr);
2884 EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); 2884 EXPECT_TRUE(connection_.GetPingAlarm()->IsSet());
2885 EXPECT_EQ(clock_.ApproximateNow() + QuicTime::Delta::FromSeconds(15), 2885 EXPECT_EQ(clock_.ApproximateNow() + QuicTime::Delta::FromSeconds(15),
2886 connection_.GetPingAlarm()->deadline()); 2886 connection_.GetPingAlarm()->deadline());
2887 2887
2888 // Now recevie and ACK of the previous packet, which will move the 2888 // Now recevie and ACK of the previous packet, which will move the
2889 // ping alarm forward. 2889 // ping alarm forward.
2890 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); 2890 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5));
2891 QuicAckFrame frame = InitAckFrame(1); 2891 QuicAckFrame frame = InitAckFrame(1);
2892 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2892 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2893 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2893 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
(...skipping 24 matching lines...) Expand all
2918 EXPECT_CALL(visitor_, HasOpenDynamicStreams()).WillRepeatedly(Return(true)); 2918 EXPECT_CALL(visitor_, HasOpenDynamicStreams()).WillRepeatedly(Return(true));
2919 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); 2919 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet());
2920 2920
2921 // Use a reduced ping timeout for this connection. 2921 // Use a reduced ping timeout for this connection.
2922 connection_.set_ping_timeout(QuicTime::Delta::FromSeconds(10)); 2922 connection_.set_ping_timeout(QuicTime::Delta::FromSeconds(10));
2923 2923
2924 // Advance to 5ms, and send a packet to the peer, which will set 2924 // Advance to 5ms, and send a packet to the peer, which will set
2925 // the ping alarm. 2925 // the ping alarm.
2926 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); 2926 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5));
2927 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 2927 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2928 SendStreamDataToPeer(kHeadersStreamId, "GET /", 0, kFin, nullptr); 2928 SendStreamDataToPeer(kHeadersStreamId, "GET /", 0, FIN, nullptr);
2929 EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); 2929 EXPECT_TRUE(connection_.GetPingAlarm()->IsSet());
2930 EXPECT_EQ(clock_.ApproximateNow() + QuicTime::Delta::FromSeconds(10), 2930 EXPECT_EQ(clock_.ApproximateNow() + QuicTime::Delta::FromSeconds(10),
2931 connection_.GetPingAlarm()->deadline()); 2931 connection_.GetPingAlarm()->deadline());
2932 2932
2933 // Now recevie and ACK of the previous packet, which will move the 2933 // Now recevie and ACK of the previous packet, which will move the
2934 // ping alarm forward. 2934 // ping alarm forward.
2935 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); 2935 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5));
2936 QuicAckFrame frame = InitAckFrame(1); 2936 QuicAckFrame frame = InitAckFrame(1);
2937 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2937 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2938 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2938 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2972 EXPECT_EQ(new_mtu, mtu_probe_size); 2972 EXPECT_EQ(new_mtu, mtu_probe_size);
2973 EXPECT_EQ(1u, creator_->packet_number()); 2973 EXPECT_EQ(1u, creator_->packet_number());
2974 2974
2975 // Send more than MTU worth of data. No acknowledgement was received so far, 2975 // Send more than MTU worth of data. No acknowledgement was received so far,
2976 // so the MTU should be at its old value. 2976 // so the MTU should be at its old value.
2977 const string data(kDefaultMaxPacketSize + 1, '.'); 2977 const string data(kDefaultMaxPacketSize + 1, '.');
2978 QuicByteCount size_before_mtu_change; 2978 QuicByteCount size_before_mtu_change;
2979 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 2979 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
2980 .WillOnce(DoAll(SaveArg<3>(&size_before_mtu_change), Return(true))) 2980 .WillOnce(DoAll(SaveArg<3>(&size_before_mtu_change), Return(true)))
2981 .WillOnce(Return(true)); 2981 .WillOnce(Return(true));
2982 connection_.SendStreamDataWithString(3, data, 0, kFin, nullptr); 2982 connection_.SendStreamDataWithString(3, data, 0, FIN, nullptr);
2983 EXPECT_EQ(3u, creator_->packet_number()); 2983 EXPECT_EQ(3u, creator_->packet_number());
2984 EXPECT_EQ(kDefaultMaxPacketSize, size_before_mtu_change); 2984 EXPECT_EQ(kDefaultMaxPacketSize, size_before_mtu_change);
2985 2985
2986 // Acknowledge all packets so far. 2986 // Acknowledge all packets so far.
2987 QuicAckFrame probe_ack = InitAckFrame(3); 2987 QuicAckFrame probe_ack = InitAckFrame(3);
2988 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2988 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2989 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2989 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
2990 ProcessAckPacket(&probe_ack); 2990 ProcessAckPacket(&probe_ack);
2991 EXPECT_EQ(new_mtu, connection_.max_packet_length()); 2991 EXPECT_EQ(new_mtu, connection_.max_packet_length());
2992 2992
2993 // Send the same data again. Check that it fits into a single packet now. 2993 // Send the same data again. Check that it fits into a single packet now.
2994 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2994 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2995 connection_.SendStreamDataWithString(3, data, 0, kFin, nullptr); 2995 connection_.SendStreamDataWithString(3, data, 0, FIN, nullptr);
2996 EXPECT_EQ(4u, creator_->packet_number()); 2996 EXPECT_EQ(4u, creator_->packet_number());
2997 } 2997 }
2998 2998
2999 // Tests whether MTU discovery does not happen when it is not explicitly enabled 2999 // Tests whether MTU discovery does not happen when it is not explicitly enabled
3000 // by the connection options. 3000 // by the connection options.
3001 TEST_P(QuicConnectionTest, MtuDiscoveryDisabled) { 3001 TEST_P(QuicConnectionTest, MtuDiscoveryDisabled) {
3002 EXPECT_TRUE(connection_.connected()); 3002 EXPECT_TRUE(connection_.connected());
3003 3003
3004 const QuicPacketCount number_of_packets = kPacketsBetweenMtuProbesBase * 2; 3004 const QuicPacketCount number_of_packets = kPacketsBetweenMtuProbesBase * 2;
3005 for (QuicPacketCount i = 0; i < number_of_packets; i++) { 3005 for (QuicPacketCount i = 0; i < number_of_packets; i++) {
3006 SendStreamDataToPeer(3, ".", i, /*fin=*/false, nullptr); 3006 SendStreamDataToPeer(3, ".", i, NO_FIN, nullptr);
3007 EXPECT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet()); 3007 EXPECT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet());
3008 EXPECT_EQ(0u, connection_.mtu_probe_count()); 3008 EXPECT_EQ(0u, connection_.mtu_probe_count());
3009 } 3009 }
3010 } 3010 }
3011 3011
3012 // Tests whether MTU discovery works when the probe gets acknowledged on the 3012 // Tests whether MTU discovery works when the probe gets acknowledged on the
3013 // first try. 3013 // first try.
3014 TEST_P(QuicConnectionTest, MtuDiscoveryEnabled) { 3014 TEST_P(QuicConnectionTest, MtuDiscoveryEnabled) {
3015 EXPECT_TRUE(connection_.connected()); 3015 EXPECT_TRUE(connection_.connected());
3016 3016
3017 connection_.EnablePathMtuDiscovery(send_algorithm_); 3017 connection_.EnablePathMtuDiscovery(send_algorithm_);
3018 3018
3019 // Send enough packets so that the next one triggers path MTU discovery. 3019 // Send enough packets so that the next one triggers path MTU discovery.
3020 for (QuicPacketCount i = 0; i < kPacketsBetweenMtuProbesBase - 1; i++) { 3020 for (QuicPacketCount i = 0; i < kPacketsBetweenMtuProbesBase - 1; i++) {
3021 SendStreamDataToPeer(3, ".", i, /*fin=*/false, nullptr); 3021 SendStreamDataToPeer(3, ".", i, NO_FIN, nullptr);
3022 ASSERT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet()); 3022 ASSERT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet());
3023 } 3023 }
3024 3024
3025 // Trigger the probe. 3025 // Trigger the probe.
3026 SendStreamDataToPeer(3, "!", kPacketsBetweenMtuProbesBase, 3026 SendStreamDataToPeer(3, "!", kPacketsBetweenMtuProbesBase, NO_FIN, nullptr);
3027 /*fin=*/false, nullptr);
3028 ASSERT_TRUE(connection_.GetMtuDiscoveryAlarm()->IsSet()); 3027 ASSERT_TRUE(connection_.GetMtuDiscoveryAlarm()->IsSet());
3029 QuicByteCount probe_size; 3028 QuicByteCount probe_size;
3030 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 3029 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
3031 .WillOnce(DoAll(SaveArg<3>(&probe_size), Return(true))); 3030 .WillOnce(DoAll(SaveArg<3>(&probe_size), Return(true)));
3032 connection_.GetMtuDiscoveryAlarm()->Fire(); 3031 connection_.GetMtuDiscoveryAlarm()->Fire();
3033 EXPECT_EQ(kMtuDiscoveryTargetPacketSizeHigh, probe_size); 3032 EXPECT_EQ(kMtuDiscoveryTargetPacketSizeHigh, probe_size);
3034 3033
3035 const QuicPacketCount probe_packet_number = kPacketsBetweenMtuProbesBase + 1; 3034 const QuicPacketCount probe_packet_number = kPacketsBetweenMtuProbesBase + 1;
3036 ASSERT_EQ(probe_packet_number, creator_->packet_number()); 3035 ASSERT_EQ(probe_packet_number, creator_->packet_number());
3037 3036
3038 // Acknowledge all packets sent so far. 3037 // Acknowledge all packets sent so far.
3039 QuicAckFrame probe_ack = InitAckFrame(probe_packet_number); 3038 QuicAckFrame probe_ack = InitAckFrame(probe_packet_number);
3040 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3039 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3041 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 3040 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
3042 ProcessAckPacket(&probe_ack); 3041 ProcessAckPacket(&probe_ack);
3043 EXPECT_EQ(kMtuDiscoveryTargetPacketSizeHigh, connection_.max_packet_length()); 3042 EXPECT_EQ(kMtuDiscoveryTargetPacketSizeHigh, connection_.max_packet_length());
3044 EXPECT_EQ(0u, connection_.GetBytesInFlight()); 3043 EXPECT_EQ(0u, connection_.GetBytesInFlight());
3045 3044
3046 // Send more packets, and ensure that none of them sets the alarm. 3045 // Send more packets, and ensure that none of them sets the alarm.
3047 for (QuicPacketCount i = 0; i < 4 * kPacketsBetweenMtuProbesBase; i++) { 3046 for (QuicPacketCount i = 0; i < 4 * kPacketsBetweenMtuProbesBase; i++) {
3048 SendStreamDataToPeer(3, ".", i, /*fin=*/false, nullptr); 3047 SendStreamDataToPeer(3, ".", i, NO_FIN, nullptr);
3049 ASSERT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet()); 3048 ASSERT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet());
3050 } 3049 }
3051 3050
3052 EXPECT_EQ(1u, connection_.mtu_probe_count()); 3051 EXPECT_EQ(1u, connection_.mtu_probe_count());
3053 } 3052 }
3054 3053
3055 // Tests whether MTU discovery works correctly when the probes never get 3054 // Tests whether MTU discovery works correctly when the probes never get
3056 // acknowledged. 3055 // acknowledged.
3057 TEST_P(QuicConnectionTest, MtuDiscoveryFailed) { 3056 TEST_P(QuicConnectionTest, MtuDiscoveryFailed) {
3058 EXPECT_TRUE(connection_.connected()); 3057 EXPECT_TRUE(connection_.connected());
(...skipping 17 matching lines...) Expand all
3076 // get caught as well. 3075 // get caught as well.
3077 const QuicPacketCount number_of_packets = 3076 const QuicPacketCount number_of_packets =
3078 packets_between_probes_base * (1 << (kMtuDiscoveryAttempts + 1)); 3077 packets_between_probes_base * (1 << (kMtuDiscoveryAttempts + 1));
3079 std::vector<QuicPacketNumber> mtu_discovery_packets; 3078 std::vector<QuicPacketNumber> mtu_discovery_packets;
3080 // Called by the first ack. 3079 // Called by the first ack.
3081 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3080 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3082 // Called on many acks. 3081 // Called on many acks.
3083 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)) 3082 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _))
3084 .Times(AnyNumber()); 3083 .Times(AnyNumber());
3085 for (QuicPacketCount i = 0; i < number_of_packets; i++) { 3084 for (QuicPacketCount i = 0; i < number_of_packets; i++) {
3086 SendStreamDataToPeer(3, "!", i, /*fin=*/false, nullptr); 3085 SendStreamDataToPeer(3, "!", i, NO_FIN, nullptr);
3087 clock_.AdvanceTime(rtt); 3086 clock_.AdvanceTime(rtt);
3088 3087
3089 // Receive an ACK, which marks all data packets as received, and all MTU 3088 // Receive an ACK, which marks all data packets as received, and all MTU
3090 // discovery packets as missing. 3089 // discovery packets as missing.
3091 QuicAckFrame ack = InitAckFrame(creator_->packet_number()); 3090 QuicAckFrame ack = InitAckFrame(creator_->packet_number());
3092 for (QuicPacketNumber& packet : mtu_discovery_packets) { 3091 for (QuicPacketNumber& packet : mtu_discovery_packets) {
3093 NackPacket(packet, &ack); 3092 NackPacket(packet, &ack);
3094 } 3093 }
3095 ProcessAckPacket(&ack); 3094 ProcessAckPacket(&ack);
3096 3095
(...skipping 30 matching lines...) Expand all
3127 // packet can be. 3126 // packet can be.
3128 TEST_P(QuicConnectionTest, MtuDiscoveryWriterLimited) { 3127 TEST_P(QuicConnectionTest, MtuDiscoveryWriterLimited) {
3129 EXPECT_TRUE(connection_.connected()); 3128 EXPECT_TRUE(connection_.connected());
3130 3129
3131 const QuicByteCount mtu_limit = kMtuDiscoveryTargetPacketSizeHigh - 1; 3130 const QuicByteCount mtu_limit = kMtuDiscoveryTargetPacketSizeHigh - 1;
3132 writer_->set_max_packet_size(mtu_limit); 3131 writer_->set_max_packet_size(mtu_limit);
3133 connection_.EnablePathMtuDiscovery(send_algorithm_); 3132 connection_.EnablePathMtuDiscovery(send_algorithm_);
3134 3133
3135 // Send enough packets so that the next one triggers path MTU discovery. 3134 // Send enough packets so that the next one triggers path MTU discovery.
3136 for (QuicPacketCount i = 0; i < kPacketsBetweenMtuProbesBase - 1; i++) { 3135 for (QuicPacketCount i = 0; i < kPacketsBetweenMtuProbesBase - 1; i++) {
3137 SendStreamDataToPeer(3, ".", i, /*fin=*/false, nullptr); 3136 SendStreamDataToPeer(3, ".", i, NO_FIN, nullptr);
3138 ASSERT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet()); 3137 ASSERT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet());
3139 } 3138 }
3140 3139
3141 // Trigger the probe. 3140 // Trigger the probe.
3142 SendStreamDataToPeer(3, "!", kPacketsBetweenMtuProbesBase, 3141 SendStreamDataToPeer(3, "!", kPacketsBetweenMtuProbesBase, NO_FIN, nullptr);
3143 /*fin=*/false, nullptr);
3144 ASSERT_TRUE(connection_.GetMtuDiscoveryAlarm()->IsSet()); 3142 ASSERT_TRUE(connection_.GetMtuDiscoveryAlarm()->IsSet());
3145 QuicByteCount probe_size; 3143 QuicByteCount probe_size;
3146 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 3144 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
3147 .WillOnce(DoAll(SaveArg<3>(&probe_size), Return(true))); 3145 .WillOnce(DoAll(SaveArg<3>(&probe_size), Return(true)));
3148 connection_.GetMtuDiscoveryAlarm()->Fire(); 3146 connection_.GetMtuDiscoveryAlarm()->Fire();
3149 EXPECT_EQ(mtu_limit, probe_size); 3147 EXPECT_EQ(mtu_limit, probe_size);
3150 3148
3151 const QuicPacketCount probe_sequence_number = 3149 const QuicPacketCount probe_sequence_number =
3152 kPacketsBetweenMtuProbesBase + 1; 3150 kPacketsBetweenMtuProbesBase + 1;
3153 ASSERT_EQ(probe_sequence_number, creator_->packet_number()); 3151 ASSERT_EQ(probe_sequence_number, creator_->packet_number());
3154 3152
3155 // Acknowledge all packets sent so far. 3153 // Acknowledge all packets sent so far.
3156 QuicAckFrame probe_ack = InitAckFrame(probe_sequence_number); 3154 QuicAckFrame probe_ack = InitAckFrame(probe_sequence_number);
3157 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3155 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3158 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 3156 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
3159 ProcessAckPacket(&probe_ack); 3157 ProcessAckPacket(&probe_ack);
3160 EXPECT_EQ(mtu_limit, connection_.max_packet_length()); 3158 EXPECT_EQ(mtu_limit, connection_.max_packet_length());
3161 EXPECT_EQ(0u, connection_.GetBytesInFlight()); 3159 EXPECT_EQ(0u, connection_.GetBytesInFlight());
3162 3160
3163 // Send more packets, and ensure that none of them sets the alarm. 3161 // Send more packets, and ensure that none of them sets the alarm.
3164 for (QuicPacketCount i = 0; i < 4 * kPacketsBetweenMtuProbesBase; i++) { 3162 for (QuicPacketCount i = 0; i < 4 * kPacketsBetweenMtuProbesBase; i++) {
3165 SendStreamDataToPeer(3, ".", i, /*fin=*/false, nullptr); 3163 SendStreamDataToPeer(3, ".", i, NO_FIN, nullptr);
3166 ASSERT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet()); 3164 ASSERT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet());
3167 } 3165 }
3168 3166
3169 EXPECT_EQ(1u, connection_.mtu_probe_count()); 3167 EXPECT_EQ(1u, connection_.mtu_probe_count());
3170 } 3168 }
3171 3169
3172 // Tests whether MTU discovery works when the writer returns an error despite 3170 // Tests whether MTU discovery works when the writer returns an error despite
3173 // advertising higher packet length. 3171 // advertising higher packet length.
3174 TEST_P(QuicConnectionTest, MtuDiscoveryWriterFailed) { 3172 TEST_P(QuicConnectionTest, MtuDiscoveryWriterFailed) {
3175 EXPECT_TRUE(connection_.connected()); 3173 EXPECT_TRUE(connection_.connected());
3176 3174
3177 const QuicByteCount mtu_limit = kMtuDiscoveryTargetPacketSizeHigh - 1; 3175 const QuicByteCount mtu_limit = kMtuDiscoveryTargetPacketSizeHigh - 1;
3178 const QuicByteCount initial_mtu = connection_.max_packet_length(); 3176 const QuicByteCount initial_mtu = connection_.max_packet_length();
3179 EXPECT_LT(initial_mtu, mtu_limit); 3177 EXPECT_LT(initial_mtu, mtu_limit);
3180 writer_->set_max_packet_size(mtu_limit); 3178 writer_->set_max_packet_size(mtu_limit);
3181 connection_.EnablePathMtuDiscovery(send_algorithm_); 3179 connection_.EnablePathMtuDiscovery(send_algorithm_);
3182 3180
3183 // Send enough packets so that the next one triggers path MTU discovery. 3181 // Send enough packets so that the next one triggers path MTU discovery.
3184 for (QuicPacketCount i = 0; i < kPacketsBetweenMtuProbesBase - 1; i++) { 3182 for (QuicPacketCount i = 0; i < kPacketsBetweenMtuProbesBase - 1; i++) {
3185 SendStreamDataToPeer(3, ".", i, /*fin=*/false, nullptr); 3183 SendStreamDataToPeer(3, ".", i, NO_FIN, nullptr);
3186 ASSERT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet()); 3184 ASSERT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet());
3187 } 3185 }
3188 3186
3189 // Trigger the probe. 3187 // Trigger the probe.
3190 SendStreamDataToPeer(3, "!", kPacketsBetweenMtuProbesBase, 3188 SendStreamDataToPeer(3, "!", kPacketsBetweenMtuProbesBase, NO_FIN, nullptr);
3191 /*fin=*/false, nullptr);
3192 ASSERT_TRUE(connection_.GetMtuDiscoveryAlarm()->IsSet()); 3189 ASSERT_TRUE(connection_.GetMtuDiscoveryAlarm()->IsSet());
3193 writer_->SimulateNextPacketTooLarge(); 3190 writer_->SimulateNextPacketTooLarge();
3194 connection_.GetMtuDiscoveryAlarm()->Fire(); 3191 connection_.GetMtuDiscoveryAlarm()->Fire();
3195 ASSERT_TRUE(connection_.connected()); 3192 ASSERT_TRUE(connection_.connected());
3196 3193
3197 // Send more data. 3194 // Send more data.
3198 QuicPacketNumber probe_number = creator_->packet_number(); 3195 QuicPacketNumber probe_number = creator_->packet_number();
3199 QuicPacketCount extra_packets = kPacketsBetweenMtuProbesBase * 3; 3196 QuicPacketCount extra_packets = kPacketsBetweenMtuProbesBase * 3;
3200 for (QuicPacketCount i = 0; i < extra_packets; i++) { 3197 for (QuicPacketCount i = 0; i < extra_packets; i++) {
3201 connection_.EnsureWritableAndSendStreamData5(); 3198 connection_.EnsureWritableAndSendStreamData5();
(...skipping 18 matching lines...) Expand all
3220 EXPECT_EQ(1u, connection_.mtu_probe_count()); 3217 EXPECT_EQ(1u, connection_.mtu_probe_count());
3221 } 3218 }
3222 3219
3223 TEST_P(QuicConnectionTest, NoMtuDiscoveryAfterConnectionClosed) { 3220 TEST_P(QuicConnectionTest, NoMtuDiscoveryAfterConnectionClosed) {
3224 EXPECT_TRUE(connection_.connected()); 3221 EXPECT_TRUE(connection_.connected());
3225 3222
3226 connection_.EnablePathMtuDiscovery(send_algorithm_); 3223 connection_.EnablePathMtuDiscovery(send_algorithm_);
3227 3224
3228 // Send enough packets so that the next one triggers path MTU discovery. 3225 // Send enough packets so that the next one triggers path MTU discovery.
3229 for (QuicPacketCount i = 0; i < kPacketsBetweenMtuProbesBase - 1; i++) { 3226 for (QuicPacketCount i = 0; i < kPacketsBetweenMtuProbesBase - 1; i++) {
3230 SendStreamDataToPeer(3, ".", i, /*fin=*/false, nullptr); 3227 SendStreamDataToPeer(3, ".", i, NO_FIN, nullptr);
3231 ASSERT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet()); 3228 ASSERT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet());
3232 } 3229 }
3233 3230
3234 SendStreamDataToPeer(3, "!", kPacketsBetweenMtuProbesBase, 3231 SendStreamDataToPeer(3, "!", kPacketsBetweenMtuProbesBase, NO_FIN, nullptr);
3235 /*fin=*/false, nullptr);
3236 EXPECT_TRUE(connection_.GetMtuDiscoveryAlarm()->IsSet()); 3232 EXPECT_TRUE(connection_.GetMtuDiscoveryAlarm()->IsSet());
3237 3233
3238 EXPECT_CALL(visitor_, OnConnectionClosed(_, _, _)); 3234 EXPECT_CALL(visitor_, OnConnectionClosed(_, _, _));
3239 connection_.CloseConnection(QUIC_PEER_GOING_AWAY, "no reason", 3235 connection_.CloseConnection(QUIC_PEER_GOING_AWAY, "no reason",
3240 ConnectionCloseBehavior::SILENT_CLOSE); 3236 ConnectionCloseBehavior::SILENT_CLOSE);
3241 EXPECT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet()); 3237 EXPECT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet());
3242 } 3238 }
3243 3239
3244 TEST_P(QuicConnectionTest, TimeoutAfterSend) { 3240 TEST_P(QuicConnectionTest, TimeoutAfterSend) {
3245 EXPECT_TRUE(connection_.connected()); 3241 EXPECT_TRUE(connection_.connected());
3246 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); 3242 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _));
3247 QuicConfig config; 3243 QuicConfig config;
3248 connection_.SetFromConfig(config); 3244 connection_.SetFromConfig(config);
3249 EXPECT_FALSE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_)); 3245 EXPECT_FALSE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_));
3250 3246
3251 const QuicTime::Delta initial_idle_timeout = 3247 const QuicTime::Delta initial_idle_timeout =
3252 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1); 3248 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1);
3253 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5); 3249 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5);
3254 QuicTime default_timeout = clock_.ApproximateNow() + initial_idle_timeout; 3250 QuicTime default_timeout = clock_.ApproximateNow() + initial_idle_timeout;
3255 3251
3256 // When we send a packet, the timeout will change to 5ms + 3252 // When we send a packet, the timeout will change to 5ms +
3257 // kInitialIdleTimeoutSecs. 3253 // kInitialIdleTimeoutSecs.
3258 clock_.AdvanceTime(five_ms); 3254 clock_.AdvanceTime(five_ms);
3259 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, kFin, nullptr); 3255 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, FIN, nullptr);
3260 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); 3256 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
3261 3257
3262 // Now send more data. This will not move the timeout becase 3258 // Now send more data. This will not move the timeout becase
3263 // no data has been recieved since the previous write. 3259 // no data has been recieved since the previous write.
3264 clock_.AdvanceTime(five_ms); 3260 clock_.AdvanceTime(five_ms);
3265 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, kFin, nullptr); 3261 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, FIN, nullptr);
3266 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); 3262 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
3267 3263
3268 // The original alarm will fire. We should not time out because we had a 3264 // The original alarm will fire. We should not time out because we had a
3269 // network event at t=5ms. The alarm will reregister. 3265 // network event at t=5ms. The alarm will reregister.
3270 clock_.AdvanceTime(initial_idle_timeout - five_ms - five_ms); 3266 clock_.AdvanceTime(initial_idle_timeout - five_ms - five_ms);
3271 EXPECT_EQ(default_timeout, clock_.ApproximateNow()); 3267 EXPECT_EQ(default_timeout, clock_.ApproximateNow());
3272 connection_.GetTimeoutAlarm()->Fire(); 3268 connection_.GetTimeoutAlarm()->Fire();
3273 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet()); 3269 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet());
3274 EXPECT_TRUE(connection_.connected()); 3270 EXPECT_TRUE(connection_.connected());
3275 EXPECT_EQ(default_timeout + five_ms, 3271 EXPECT_EQ(default_timeout + five_ms,
(...skipping 28 matching lines...) Expand all
3304 start_time + DefaultRetransmissionTime(); 3300 start_time + DefaultRetransmissionTime();
3305 3301
3306 ASSERT_LT(default_retransmission_time, default_timeout); 3302 ASSERT_LT(default_retransmission_time, default_timeout);
3307 3303
3308 // When we send a packet, the timeout will change to 5 ms + 3304 // When we send a packet, the timeout will change to 5 ms +
3309 // kInitialIdleTimeoutSecs (but it will not reschedule the alarm). 3305 // kInitialIdleTimeoutSecs (but it will not reschedule the alarm).
3310 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5); 3306 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5);
3311 const QuicTime send_time = start_time + five_ms; 3307 const QuicTime send_time = start_time + five_ms;
3312 clock_.AdvanceTime(five_ms); 3308 clock_.AdvanceTime(five_ms);
3313 ASSERT_EQ(send_time, clock_.Now()); 3309 ASSERT_EQ(send_time, clock_.Now());
3314 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, kFin, nullptr); 3310 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, FIN, nullptr);
3315 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); 3311 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
3316 3312
3317 // Move forward 5 ms and receive a packet, which will move the timeout 3313 // Move forward 5 ms and receive a packet, which will move the timeout
3318 // forward 5 ms more (but will not reschedule the alarm). 3314 // forward 5 ms more (but will not reschedule the alarm).
3319 const QuicTime receive_time = send_time + five_ms; 3315 const QuicTime receive_time = send_time + five_ms;
3320 clock_.AdvanceTime(receive_time - clock_.Now()); 3316 clock_.AdvanceTime(receive_time - clock_.Now());
3321 ASSERT_EQ(receive_time, clock_.Now()); 3317 ASSERT_EQ(receive_time, clock_.Now());
3322 ProcessPacket(1); 3318 ProcessPacket(1);
3323 3319
3324 // Now move forward to the retransmission time and retransmit the 3320 // Now move forward to the retransmission time and retransmit the
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
3386 EXPECT_TRUE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_)); 3382 EXPECT_TRUE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_));
3387 3383
3388 const QuicTime::Delta default_idle_timeout = 3384 const QuicTime::Delta default_idle_timeout =
3389 QuicTime::Delta::FromSeconds(kDefaultIdleTimeoutSecs - 1); 3385 QuicTime::Delta::FromSeconds(kDefaultIdleTimeoutSecs - 1);
3390 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5); 3386 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5);
3391 QuicTime default_timeout = clock_.ApproximateNow() + default_idle_timeout; 3387 QuicTime default_timeout = clock_.ApproximateNow() + default_idle_timeout;
3392 3388
3393 // When we send a packet, the timeout will change to 5ms + 3389 // When we send a packet, the timeout will change to 5ms +
3394 // kInitialIdleTimeoutSecs. 3390 // kInitialIdleTimeoutSecs.
3395 clock_.AdvanceTime(five_ms); 3391 clock_.AdvanceTime(five_ms);
3396 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, kFin, nullptr); 3392 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, FIN, nullptr);
3397 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); 3393 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
3398 3394
3399 // Now send more data. This will not move the timeout becase 3395 // Now send more data. This will not move the timeout becase
3400 // no data has been recieved since the previous write. 3396 // no data has been recieved since the previous write.
3401 clock_.AdvanceTime(five_ms); 3397 clock_.AdvanceTime(five_ms);
3402 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, kFin, nullptr); 3398 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, FIN, nullptr);
3403 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); 3399 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
3404 3400
3405 // The original alarm will fire. We should not time out because we had a 3401 // The original alarm will fire. We should not time out because we had a
3406 // network event at t=5ms. The alarm will reregister. 3402 // network event at t=5ms. The alarm will reregister.
3407 clock_.AdvanceTime(default_idle_timeout - five_ms - five_ms); 3403 clock_.AdvanceTime(default_idle_timeout - five_ms - five_ms);
3408 EXPECT_EQ(default_timeout, clock_.ApproximateNow()); 3404 EXPECT_EQ(default_timeout, clock_.ApproximateNow());
3409 connection_.GetTimeoutAlarm()->Fire(); 3405 connection_.GetTimeoutAlarm()->Fire();
3410 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet()); 3406 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet());
3411 EXPECT_TRUE(connection_.connected()); 3407 EXPECT_TRUE(connection_.connected());
3412 EXPECT_EQ(default_timeout + five_ms, 3408 EXPECT_EQ(default_timeout + five_ms,
(...skipping 15 matching lines...) Expand all
3428 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); 3424 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _));
3429 QuicConfig config; 3425 QuicConfig config;
3430 connection_.SetFromConfig(config); 3426 connection_.SetFromConfig(config);
3431 EXPECT_FALSE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_)); 3427 EXPECT_FALSE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_));
3432 3428
3433 const QuicTime::Delta initial_idle_timeout = 3429 const QuicTime::Delta initial_idle_timeout =
3434 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1); 3430 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1);
3435 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5); 3431 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5);
3436 QuicTime default_timeout = clock_.ApproximateNow() + initial_idle_timeout; 3432 QuicTime default_timeout = clock_.ApproximateNow() + initial_idle_timeout;
3437 3433
3438 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, !kFin, 3434 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, NO_FIN,
3439 nullptr); 3435 nullptr);
3440 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 3, !kFin, 3436 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 3, NO_FIN,
3441 nullptr); 3437 nullptr);
3442 3438
3443 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); 3439 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
3444 clock_.AdvanceTime(five_ms); 3440 clock_.AdvanceTime(five_ms);
3445 3441
3446 // When we receive a packet, the timeout will change to 5ms + 3442 // When we receive a packet, the timeout will change to 5ms +
3447 // kInitialIdleTimeoutSecs. 3443 // kInitialIdleTimeoutSecs.
3448 QuicAckFrame ack = InitAckFrame(2); 3444 QuicAckFrame ack = InitAckFrame(2);
3449 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 3445 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
3450 ProcessAckPacket(&ack); 3446 ProcessAckPacket(&ack);
(...skipping 29 matching lines...) Expand all
3480 3476
3481 const QuicTime::Delta initial_idle_timeout = 3477 const QuicTime::Delta initial_idle_timeout =
3482 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1); 3478 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1);
3483 connection_.SetNetworkTimeouts( 3479 connection_.SetNetworkTimeouts(
3484 QuicTime::Delta::Infinite(), 3480 QuicTime::Delta::Infinite(),
3485 initial_idle_timeout + QuicTime::Delta::FromSeconds(1)); 3481 initial_idle_timeout + QuicTime::Delta::FromSeconds(1));
3486 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5); 3482 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5);
3487 QuicTime default_timeout = clock_.ApproximateNow() + initial_idle_timeout; 3483 QuicTime default_timeout = clock_.ApproximateNow() + initial_idle_timeout;
3488 3484
3489 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 3485 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
3490 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, !kFin, 3486 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, NO_FIN,
3491 nullptr); 3487 nullptr);
3492 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 3488 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
3493 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 3, !kFin, 3489 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 3, NO_FIN,
3494 nullptr); 3490 nullptr);
3495 3491
3496 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); 3492 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
3497 3493
3498 clock_.AdvanceTime(five_ms); 3494 clock_.AdvanceTime(five_ms);
3499 3495
3500 // When we receive a packet, the timeout will change to 5ms + 3496 // When we receive a packet, the timeout will change to 5ms +
3501 // kInitialIdleTimeoutSecs. 3497 // kInitialIdleTimeoutSecs.
3502 QuicAckFrame ack = InitAckFrame(2); 3498 QuicAckFrame ack = InitAckFrame(2);
3503 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 3499 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
3504 ProcessAckPacket(&ack); 3500 ProcessAckPacket(&ack);
3505 3501
3506 // The original alarm will fire. We should not time out because we had a 3502 // The original alarm will fire. We should not time out because we had a
3507 // network event at t=5ms. The alarm will reregister. 3503 // network event at t=5ms. The alarm will reregister.
3508 clock_.AdvanceTime(initial_idle_timeout - five_ms); 3504 clock_.AdvanceTime(initial_idle_timeout - five_ms);
3509 EXPECT_EQ(default_timeout, clock_.ApproximateNow()); 3505 EXPECT_EQ(default_timeout, clock_.ApproximateNow());
3510 connection_.GetTimeoutAlarm()->Fire(); 3506 connection_.GetTimeoutAlarm()->Fire();
3511 EXPECT_TRUE(connection_.connected()); 3507 EXPECT_TRUE(connection_.connected());
3512 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet()); 3508 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet());
3513 EXPECT_EQ(default_timeout + five_ms, 3509 EXPECT_EQ(default_timeout + five_ms,
3514 connection_.GetTimeoutAlarm()->deadline()); 3510 connection_.GetTimeoutAlarm()->deadline());
3515 3511
3516 // Now, send packets while advancing the time and verify that the connection 3512 // Now, send packets while advancing the time and verify that the connection
3517 // eventually times out. 3513 // eventually times out.
3518 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_NETWORK_IDLE_TIMEOUT, _, 3514 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_NETWORK_IDLE_TIMEOUT, _,
3519 ConnectionCloseSource::FROM_SELF)); 3515 ConnectionCloseSource::FROM_SELF));
3520 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber()); 3516 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber());
3521 for (int i = 0; i < 100 && connection_.connected(); ++i) { 3517 for (int i = 0; i < 100 && connection_.connected(); ++i) {
3522 QUIC_LOG(INFO) << "sending data packet"; 3518 QUIC_LOG(INFO) << "sending data packet";
3523 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, !kFin, 3519 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, NO_FIN,
3524 nullptr); 3520 nullptr);
3525 connection_.GetTimeoutAlarm()->Fire(); 3521 connection_.GetTimeoutAlarm()->Fire();
3526 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(1)); 3522 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(1));
3527 } 3523 }
3528 EXPECT_FALSE(connection_.connected()); 3524 EXPECT_FALSE(connection_.connected());
3529 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); 3525 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
3530 } 3526 }
3531 3527
3532 TEST_P(QuicConnectionTest, TimeoutAfter5ClientRTOs) { 3528 TEST_P(QuicConnectionTest, TimeoutAfter5ClientRTOs) {
3533 connection_.SetMaxTailLossProbes(2); 3529 connection_.SetMaxTailLossProbes(2);
3534 EXPECT_TRUE(connection_.connected()); 3530 EXPECT_TRUE(connection_.connected());
3535 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); 3531 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _));
3536 QuicConfig config; 3532 QuicConfig config;
3537 QuicTagVector connection_options; 3533 QuicTagVector connection_options;
3538 connection_options.push_back(k5RTO); 3534 connection_options.push_back(k5RTO);
3539 config.SetConnectionOptionsToSend(connection_options); 3535 config.SetConnectionOptionsToSend(connection_options);
3540 connection_.SetFromConfig(config); 3536 connection_.SetFromConfig(config);
3541 3537
3542 // Send stream data. 3538 // Send stream data.
3543 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, kFin, nullptr); 3539 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, FIN, nullptr);
3544 3540
3545 EXPECT_CALL(visitor_, OnPathDegrading()); 3541 EXPECT_CALL(visitor_, OnPathDegrading());
3546 // Fire the retransmission alarm 6 times, twice for TLP and 4 times for RTO. 3542 // Fire the retransmission alarm 6 times, twice for TLP and 4 times for RTO.
3547 for (int i = 0; i < 6; ++i) { 3543 for (int i = 0; i < 6; ++i) {
3548 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 3544 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
3549 connection_.GetRetransmissionAlarm()->Fire(); 3545 connection_.GetRetransmissionAlarm()->Fire();
3550 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet()); 3546 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet());
3551 EXPECT_TRUE(connection_.connected()); 3547 EXPECT_TRUE(connection_.connected());
3552 } 3548 }
3553 3549
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
3596 size_t length = GetPacketLengthForOneStream( 3592 size_t length = GetPacketLengthForOneStream(
3597 connection_.version(), kIncludeVersion, !kIncludeDiversificationNonce, 3593 connection_.version(), kIncludeVersion, !kIncludeDiversificationNonce,
3598 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_PACKET_NUMBER, &payload_length); 3594 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_PACKET_NUMBER, &payload_length);
3599 connection_.SetMaxPacketLength(length); 3595 connection_.SetMaxPacketLength(length);
3600 3596
3601 // Queue the first packet. 3597 // Queue the first packet.
3602 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _)) 3598 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _))
3603 .WillOnce(testing::Return(QuicTime::Delta::FromMicroseconds(10))); 3599 .WillOnce(testing::Return(QuicTime::Delta::FromMicroseconds(10)));
3604 const string payload(payload_length, 'a'); 3600 const string payload(payload_length, 'a');
3605 EXPECT_EQ(0u, 3601 EXPECT_EQ(0u,
3606 connection_.SendStreamDataWithString(3, payload, 0, !kFin, nullptr) 3602 connection_.SendStreamDataWithString(3, payload, 0, NO_FIN, nullptr)
3607 .bytes_consumed); 3603 .bytes_consumed);
3608 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 3604 EXPECT_EQ(0u, connection_.NumQueuedPackets());
3609 } 3605 }
3610 3606
3611 TEST_P(QuicConnectionTest, LoopThroughSendingPackets) { 3607 TEST_P(QuicConnectionTest, LoopThroughSendingPackets) {
3612 // All packets carry version info till version is negotiated. 3608 // All packets carry version info till version is negotiated.
3613 size_t payload_length; 3609 size_t payload_length;
3614 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining 3610 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining
3615 // packet length. The size of the offset field in a stream frame is 0 for 3611 // packet length. The size of the offset field in a stream frame is 0 for
3616 // offset 0, and 2 for non-zero offsets up through 16K. Increase 3612 // offset 0, and 2 for non-zero offsets up through 16K. Increase
3617 // max_packet_length by 2 so that subsequent packets containing subsequent 3613 // max_packet_length by 2 so that subsequent packets containing subsequent
3618 // stream frames with non-zero offets will fit within the packet length. 3614 // stream frames with non-zero offets will fit within the packet length.
3619 size_t length = 3615 size_t length =
3620 2 + GetPacketLengthForOneStream( 3616 2 + GetPacketLengthForOneStream(
3621 connection_.version(), kIncludeVersion, 3617 connection_.version(), kIncludeVersion,
3622 !kIncludeDiversificationNonce, PACKET_8BYTE_CONNECTION_ID, 3618 !kIncludeDiversificationNonce, PACKET_8BYTE_CONNECTION_ID,
3623 PACKET_1BYTE_PACKET_NUMBER, &payload_length); 3619 PACKET_1BYTE_PACKET_NUMBER, &payload_length);
3624 connection_.SetMaxPacketLength(length); 3620 connection_.SetMaxPacketLength(length);
3625 3621
3626 // Queue the first packet. 3622 // Queue the first packet.
3627 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(7); 3623 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(7);
3628 // The first stream frame will have 2 fewer overhead bytes than the other six. 3624 // The first stream frame will have 2 fewer overhead bytes than the other six.
3629 const string payload(payload_length * 7 + 2, 'a'); 3625 const string payload(payload_length * 7 + 2, 'a');
3630 EXPECT_EQ(payload.size(), 3626 EXPECT_EQ(payload.size(),
3631 connection_.SendStreamDataWithString(1, payload, 0, !kFin, nullptr) 3627 connection_.SendStreamDataWithString(1, payload, 0, NO_FIN, nullptr)
3632 .bytes_consumed); 3628 .bytes_consumed);
3633 } 3629 }
3634 3630
3635 TEST_P(QuicConnectionTest, LoopThroughSendingPacketsWithTruncation) { 3631 TEST_P(QuicConnectionTest, LoopThroughSendingPacketsWithTruncation) {
3636 // Set up a larger payload than will fit in one packet. 3632 // Set up a larger payload than will fit in one packet.
3637 const string payload(connection_.max_packet_length(), 'a'); 3633 const string payload(connection_.max_packet_length(), 'a');
3638 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)).Times(AnyNumber()); 3634 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)).Times(AnyNumber());
3639 3635
3640 // Now send some packets with no truncation. 3636 // Now send some packets with no truncation.
3641 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); 3637 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
3642 EXPECT_EQ(payload.size(), 3638 EXPECT_EQ(payload.size(),
3643 connection_.SendStreamDataWithString(3, payload, 0, !kFin, nullptr) 3639 connection_.SendStreamDataWithString(3, payload, 0, NO_FIN, nullptr)
3644 .bytes_consumed); 3640 .bytes_consumed);
3645 // Track the size of the second packet here. The overhead will be the largest 3641 // Track the size of the second packet here. The overhead will be the largest
3646 // we see in this test, due to the non-truncated connection id. 3642 // we see in this test, due to the non-truncated connection id.
3647 size_t non_truncated_packet_size = writer_->last_packet_size(); 3643 size_t non_truncated_packet_size = writer_->last_packet_size();
3648 3644
3649 // Change to a 0 byte connection id. 3645 // Change to a 0 byte connection id.
3650 QuicConfig config; 3646 QuicConfig config;
3651 QuicConfigPeer::SetReceivedBytesForConnectionId(&config, 0); 3647 QuicConfigPeer::SetReceivedBytesForConnectionId(&config, 0);
3652 connection_.SetFromConfig(config); 3648 connection_.SetFromConfig(config);
3653 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); 3649 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
3654 EXPECT_EQ(payload.size(), 3650 EXPECT_EQ(payload.size(),
3655 connection_.SendStreamDataWithString(3, payload, 0, !kFin, nullptr) 3651 connection_.SendStreamDataWithString(3, payload, 0, NO_FIN, nullptr)
3656 .bytes_consumed); 3652 .bytes_consumed);
3657 // Just like above, we save 8 bytes on payload, and 8 on truncation. 3653 // Just like above, we save 8 bytes on payload, and 8 on truncation.
3658 EXPECT_EQ(non_truncated_packet_size, writer_->last_packet_size() + 8 * 2); 3654 EXPECT_EQ(non_truncated_packet_size, writer_->last_packet_size() + 8 * 2);
3659 } 3655 }
3660 3656
3661 TEST_P(QuicConnectionTest, SendDelayedAck) { 3657 TEST_P(QuicConnectionTest, SendDelayedAck) {
3662 QuicTime ack_time = clock_.ApproximateNow() + DefaultDelayedAckTime(); 3658 QuicTime ack_time = clock_.ApproximateNow() + DefaultDelayedAckTime();
3663 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3659 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3664 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 3660 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
3665 const uint8_t tag = 0x07; 3661 const uint8_t tag = 0x07;
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
4153 writer_->Reset(); 4149 writer_->Reset();
4154 // Now only set the timer on the 6th packet, instead of sending another ack. 4150 // Now only set the timer on the 6th packet, instead of sending another ack.
4155 ProcessPacket(6); 4151 ProcessPacket(6);
4156 EXPECT_EQ(0u, writer_->frame_count()); 4152 EXPECT_EQ(0u, writer_->frame_count());
4157 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); 4153 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
4158 } 4154 }
4159 4155
4160 TEST_P(QuicConnectionTest, SendDelayedAckOnOutgoingPacket) { 4156 TEST_P(QuicConnectionTest, SendDelayedAckOnOutgoingPacket) {
4161 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4157 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4162 ProcessPacket(1); 4158 ProcessPacket(1);
4163 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, !kFin, 4159 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, NO_FIN,
4164 nullptr); 4160 nullptr);
4165 // Check that ack is bundled with outgoing data and that delayed ack 4161 // Check that ack is bundled with outgoing data and that delayed ack
4166 // alarm is reset. 4162 // alarm is reset.
4167 if (GetParam().no_stop_waiting) { 4163 if (GetParam().no_stop_waiting) {
4168 EXPECT_EQ(2u, writer_->frame_count()); 4164 EXPECT_EQ(2u, writer_->frame_count());
4169 EXPECT_TRUE(writer_->stop_waiting_frames().empty()); 4165 EXPECT_TRUE(writer_->stop_waiting_frames().empty());
4170 } else { 4166 } else {
4171 EXPECT_EQ(3u, writer_->frame_count()); 4167 EXPECT_EQ(3u, writer_->frame_count());
4172 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); 4168 EXPECT_FALSE(writer_->stop_waiting_frames().empty());
4173 } 4169 }
4174 EXPECT_FALSE(writer_->ack_frames().empty()); 4170 EXPECT_FALSE(writer_->ack_frames().empty());
4175 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 4171 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
4176 } 4172 }
4177 4173
4178 TEST_P(QuicConnectionTest, SendDelayedAckOnOutgoingCryptoPacket) { 4174 TEST_P(QuicConnectionTest, SendDelayedAckOnOutgoingCryptoPacket) {
4179 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4175 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4180 ProcessPacket(1); 4176 ProcessPacket(1);
4181 connection_.SendStreamDataWithString(kCryptoStreamId, "foo", 0, !kFin, 4177 connection_.SendStreamDataWithString(kCryptoStreamId, "foo", 0, NO_FIN,
4182 nullptr); 4178 nullptr);
4183 // Check that ack is bundled with outgoing crypto data. 4179 // Check that ack is bundled with outgoing crypto data.
4184 if (GetParam().no_stop_waiting) { 4180 if (GetParam().no_stop_waiting) {
4185 EXPECT_EQ(3u, writer_->frame_count()); 4181 EXPECT_EQ(3u, writer_->frame_count());
4186 EXPECT_TRUE(writer_->stop_waiting_frames().empty()); 4182 EXPECT_TRUE(writer_->stop_waiting_frames().empty());
4187 } else { 4183 } else {
4188 EXPECT_EQ(4u, writer_->frame_count()); 4184 EXPECT_EQ(4u, writer_->frame_count());
4189 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); 4185 EXPECT_FALSE(writer_->stop_waiting_frames().empty());
4190 } 4186 }
4191 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 4187 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
4192 } 4188 }
4193 4189
4194 TEST_P(QuicConnectionTest, BlockAndBufferOnFirstCHLOPacketOfTwo) { 4190 TEST_P(QuicConnectionTest, BlockAndBufferOnFirstCHLOPacketOfTwo) {
4195 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4191 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4196 ProcessPacket(1); 4192 ProcessPacket(1);
4197 BlockOnNextWrite(); 4193 BlockOnNextWrite();
4198 writer_->set_is_write_blocked_data_buffered(true); 4194 writer_->set_is_write_blocked_data_buffered(true);
4199 connection_.SendStreamDataWithString(kCryptoStreamId, "foo", 0, !kFin, 4195 connection_.SendStreamDataWithString(kCryptoStreamId, "foo", 0, NO_FIN,
4200 nullptr); 4196 nullptr);
4201 EXPECT_TRUE(writer_->IsWriteBlocked()); 4197 EXPECT_TRUE(writer_->IsWriteBlocked());
4202 EXPECT_FALSE(connection_.HasQueuedData()); 4198 EXPECT_FALSE(connection_.HasQueuedData());
4203 connection_.SendStreamDataWithString(kCryptoStreamId, "bar", 3, !kFin, 4199 connection_.SendStreamDataWithString(kCryptoStreamId, "bar", 3, NO_FIN,
4204 nullptr); 4200 nullptr);
4205 EXPECT_TRUE(writer_->IsWriteBlocked()); 4201 EXPECT_TRUE(writer_->IsWriteBlocked());
4206 EXPECT_TRUE(connection_.HasQueuedData()); 4202 EXPECT_TRUE(connection_.HasQueuedData());
4207 } 4203 }
4208 4204
4209 TEST_P(QuicConnectionTest, BundleAckForSecondCHLO) { 4205 TEST_P(QuicConnectionTest, BundleAckForSecondCHLO) {
4210 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4206 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4211 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 4207 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
4212 EXPECT_CALL(visitor_, OnCanWrite()) 4208 EXPECT_CALL(visitor_, OnCanWrite())
4213 .WillOnce(IgnoreResult(InvokeWithoutArgs( 4209 .WillOnce(IgnoreResult(InvokeWithoutArgs(
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
4255 } 4251 }
4256 EXPECT_EQ(1u, writer_->stream_frames().size()); 4252 EXPECT_EQ(1u, writer_->stream_frames().size());
4257 EXPECT_EQ(1u, writer_->padding_frames().size()); 4253 EXPECT_EQ(1u, writer_->padding_frames().size());
4258 EXPECT_FALSE(writer_->ack_frames().empty()); 4254 EXPECT_FALSE(writer_->ack_frames().empty());
4259 EXPECT_EQ(2u, writer_->ack_frames().front().largest_observed); 4255 EXPECT_EQ(2u, writer_->ack_frames().front().largest_observed);
4260 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 4256 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
4261 } 4257 }
4262 4258
4263 TEST_P(QuicConnectionTest, BundleAckWithDataOnIncomingAck) { 4259 TEST_P(QuicConnectionTest, BundleAckWithDataOnIncomingAck) {
4264 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4260 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4265 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, !kFin, 4261 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, NO_FIN,
4266 nullptr); 4262 nullptr);
4267 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 3, !kFin, 4263 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 3, NO_FIN,
4268 nullptr); 4264 nullptr);
4269 // Ack the second packet, which will retransmit the first packet. 4265 // Ack the second packet, which will retransmit the first packet.
4270 QuicAckFrame ack = InitAckFrame(2); 4266 QuicAckFrame ack = InitAckFrame(2);
4271 NackPacket(1, &ack); 4267 NackPacket(1, &ack);
4272 SendAlgorithmInterface::CongestionVector lost_packets; 4268 SendAlgorithmInterface::CongestionVector lost_packets;
4273 lost_packets.push_back(std::make_pair(1, kMaxPacketSize)); 4269 lost_packets.push_back(std::make_pair(1, kMaxPacketSize));
4274 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)) 4270 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _))
4275 .WillOnce(SetArgPointee<4>(lost_packets)); 4271 .WillOnce(SetArgPointee<4>(lost_packets));
4276 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 4272 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
4277 ProcessAckPacket(&ack); 4273 ProcessAckPacket(&ack);
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
4559 GetPeerInMemoryConnectionId(connection_id_), AllSupportedVersions())); 4555 GetPeerInMemoryConnectionId(connection_id_), AllSupportedVersions()));
4560 std::unique_ptr<QuicReceivedPacket> received( 4556 std::unique_ptr<QuicReceivedPacket> received(
4561 ConstructReceivedPacket(*encrypted, QuicTime::Zero())); 4557 ConstructReceivedPacket(*encrypted, QuicTime::Zero()));
4562 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *received); 4558 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *received);
4563 } 4559 }
4564 4560
4565 TEST_P(QuicConnectionTest, CheckSendStats) { 4561 TEST_P(QuicConnectionTest, CheckSendStats) {
4566 connection_.SetMaxTailLossProbes(0); 4562 connection_.SetMaxTailLossProbes(0);
4567 4563
4568 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 4564 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
4569 connection_.SendStreamDataWithString(3, "first", 0, !kFin, nullptr); 4565 connection_.SendStreamDataWithString(3, "first", 0, NO_FIN, nullptr);
4570 size_t first_packet_size = writer_->last_packet_size(); 4566 size_t first_packet_size = writer_->last_packet_size();
4571 4567
4572 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 4568 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
4573 connection_.SendStreamDataWithString(5, "second", 0, !kFin, nullptr); 4569 connection_.SendStreamDataWithString(5, "second", 0, NO_FIN, nullptr);
4574 size_t second_packet_size = writer_->last_packet_size(); 4570 size_t second_packet_size = writer_->last_packet_size();
4575 4571
4576 // 2 retransmissions due to rto, 1 due to explicit nack. 4572 // 2 retransmissions due to rto, 1 due to explicit nack.
4577 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 4573 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
4578 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3); 4574 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3);
4579 4575
4580 // Retransmit due to RTO. 4576 // Retransmit due to RTO.
4581 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10)); 4577 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10));
4582 connection_.GetRetransmissionAlarm()->Fire(); 4578 connection_.GetRetransmissionAlarm()->Fire();
4583 4579
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
4666 // Shouldn't be able to find a mutually supported version. 4662 // Shouldn't be able to find a mutually supported version.
4667 QuicVersionVector unsupported_version; 4663 QuicVersionVector unsupported_version;
4668 unsupported_version.push_back(QUIC_VERSION_UNSUPPORTED); 4664 unsupported_version.push_back(QUIC_VERSION_UNSUPPORTED);
4669 EXPECT_FALSE(connection_.SelectMutualVersion(unsupported_version)); 4665 EXPECT_FALSE(connection_.SelectMutualVersion(unsupported_version));
4670 } 4666 }
4671 4667
4672 TEST_P(QuicConnectionTest, ConnectionCloseWhenWritable) { 4668 TEST_P(QuicConnectionTest, ConnectionCloseWhenWritable) {
4673 EXPECT_FALSE(writer_->IsWriteBlocked()); 4669 EXPECT_FALSE(writer_->IsWriteBlocked());
4674 4670
4675 // Send a packet. 4671 // Send a packet.
4676 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); 4672 connection_.SendStreamDataWithString(1, "foo", 0, NO_FIN, nullptr);
4677 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 4673 EXPECT_EQ(0u, connection_.NumQueuedPackets());
4678 EXPECT_EQ(1u, writer_->packets_write_attempts()); 4674 EXPECT_EQ(1u, writer_->packets_write_attempts());
4679 4675
4680 TriggerConnectionClose(); 4676 TriggerConnectionClose();
4681 EXPECT_EQ(2u, writer_->packets_write_attempts()); 4677 EXPECT_EQ(2u, writer_->packets_write_attempts());
4682 } 4678 }
4683 4679
4684 TEST_P(QuicConnectionTest, ConnectionCloseGettingWriteBlocked) { 4680 TEST_P(QuicConnectionTest, ConnectionCloseGettingWriteBlocked) {
4685 BlockOnNextWrite(); 4681 BlockOnNextWrite();
4686 TriggerConnectionClose(); 4682 TriggerConnectionClose();
4687 EXPECT_EQ(1u, writer_->packets_write_attempts()); 4683 EXPECT_EQ(1u, writer_->packets_write_attempts());
4688 EXPECT_TRUE(writer_->IsWriteBlocked()); 4684 EXPECT_TRUE(writer_->IsWriteBlocked());
4689 } 4685 }
4690 4686
4691 TEST_P(QuicConnectionTest, ConnectionCloseWhenWriteBlocked) { 4687 TEST_P(QuicConnectionTest, ConnectionCloseWhenWriteBlocked) {
4692 BlockOnNextWrite(); 4688 BlockOnNextWrite();
4693 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); 4689 connection_.SendStreamDataWithString(1, "foo", 0, NO_FIN, nullptr);
4694 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 4690 EXPECT_EQ(1u, connection_.NumQueuedPackets());
4695 EXPECT_EQ(1u, writer_->packets_write_attempts()); 4691 EXPECT_EQ(1u, writer_->packets_write_attempts());
4696 EXPECT_TRUE(writer_->IsWriteBlocked()); 4692 EXPECT_TRUE(writer_->IsWriteBlocked());
4697 TriggerConnectionClose(); 4693 TriggerConnectionClose();
4698 EXPECT_EQ(1u, writer_->packets_write_attempts()); 4694 EXPECT_EQ(1u, writer_->packets_write_attempts());
4699 } 4695 }
4700 4696
4701 TEST_P(QuicConnectionTest, AckNotifierTriggerCallback) { 4697 TEST_P(QuicConnectionTest, AckNotifierTriggerCallback) {
4702 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4698 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4703 4699
4704 // Create a listener which we expect to be called. 4700 // Create a listener which we expect to be called.
4705 QuicReferenceCountedPointer<MockAckListener> listener(new MockAckListener); 4701 QuicReferenceCountedPointer<MockAckListener> listener(new MockAckListener);
4706 EXPECT_CALL(*listener, OnPacketAcked(_, _)).Times(1); 4702 EXPECT_CALL(*listener, OnPacketAcked(_, _)).Times(1);
4707 4703
4708 // Send some data, which will register the listener to be notified. 4704 // Send some data, which will register the listener to be notified.
4709 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, listener); 4705 connection_.SendStreamDataWithString(1, "foo", 0, NO_FIN, listener);
4710 4706
4711 // Process an ACK from the server which should trigger the callback. 4707 // Process an ACK from the server which should trigger the callback.
4712 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 4708 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
4713 QuicAckFrame frame = InitAckFrame(1); 4709 QuicAckFrame frame = InitAckFrame(1);
4714 ProcessAckPacket(&frame); 4710 ProcessAckPacket(&frame);
4715 } 4711 }
4716 4712
4717 TEST_P(QuicConnectionTest, AckNotifierFailToTriggerCallback) { 4713 TEST_P(QuicConnectionTest, AckNotifierFailToTriggerCallback) {
4718 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4714 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4719 4715
4720 // Create a listener which we don't expect to be called. 4716 // Create a listener which we don't expect to be called.
4721 QuicReferenceCountedPointer<MockAckListener> listener(new MockAckListener); 4717 QuicReferenceCountedPointer<MockAckListener> listener(new MockAckListener);
4722 EXPECT_CALL(*listener, OnPacketAcked(_, _)).Times(0); 4718 EXPECT_CALL(*listener, OnPacketAcked(_, _)).Times(0);
4723 4719
4724 // Send some data, which will register the listener to be notified. This will 4720 // Send some data, which will register the listener to be notified. This will
4725 // not be ACKed and so the listener should never be called. 4721 // not be ACKed and so the listener should never be called.
4726 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, listener); 4722 connection_.SendStreamDataWithString(1, "foo", 0, NO_FIN, listener);
4727 4723
4728 // Send some other data which we will ACK. 4724 // Send some other data which we will ACK.
4729 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); 4725 connection_.SendStreamDataWithString(1, "foo", 0, NO_FIN, nullptr);
4730 connection_.SendStreamDataWithString(1, "bar", 0, !kFin, nullptr); 4726 connection_.SendStreamDataWithString(1, "bar", 0, NO_FIN, nullptr);
4731 4727
4732 // Now we receive ACK for packets 2 and 3, but importantly missing packet 1 4728 // Now we receive ACK for packets 2 and 3, but importantly missing packet 1
4733 // which we registered to be notified about. 4729 // which we registered to be notified about.
4734 QuicAckFrame frame = InitAckFrame(3); 4730 QuicAckFrame frame = InitAckFrame(3);
4735 NackPacket(1, &frame); 4731 NackPacket(1, &frame);
4736 SendAlgorithmInterface::CongestionVector lost_packets; 4732 SendAlgorithmInterface::CongestionVector lost_packets;
4737 lost_packets.push_back(std::make_pair(1, kMaxPacketSize)); 4733 lost_packets.push_back(std::make_pair(1, kMaxPacketSize));
4738 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)) 4734 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _))
4739 .WillOnce(SetArgPointee<4>(lost_packets)); 4735 .WillOnce(SetArgPointee<4>(lost_packets));
4740 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 4736 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
4741 ProcessAckPacket(&frame); 4737 ProcessAckPacket(&frame);
4742 } 4738 }
4743 4739
4744 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) { 4740 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) {
4745 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4741 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4746 4742
4747 // Create a listener which we expect to be called. 4743 // Create a listener which we expect to be called.
4748 QuicReferenceCountedPointer<MockAckListener> listener(new MockAckListener); 4744 QuicReferenceCountedPointer<MockAckListener> listener(new MockAckListener);
4749 EXPECT_CALL(*listener, OnPacketRetransmitted(3)).Times(1); 4745 EXPECT_CALL(*listener, OnPacketRetransmitted(3)).Times(1);
4750 EXPECT_CALL(*listener, OnPacketAcked(3, _)).Times(1); 4746 EXPECT_CALL(*listener, OnPacketAcked(3, _)).Times(1);
4751 4747
4752 // Send four packets, and register to be notified on ACK of packet 2. 4748 // Send four packets, and register to be notified on ACK of packet 2.
4753 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); 4749 connection_.SendStreamDataWithString(3, "foo", 0, NO_FIN, nullptr);
4754 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, listener); 4750 connection_.SendStreamDataWithString(3, "bar", 0, NO_FIN, listener);
4755 connection_.SendStreamDataWithString(3, "baz", 0, !kFin, nullptr); 4751 connection_.SendStreamDataWithString(3, "baz", 0, NO_FIN, nullptr);
4756 connection_.SendStreamDataWithString(3, "qux", 0, !kFin, nullptr); 4752 connection_.SendStreamDataWithString(3, "qux", 0, NO_FIN, nullptr);
4757 4753
4758 // Now we receive ACK for packets 1, 3, and 4 and lose 2. 4754 // Now we receive ACK for packets 1, 3, and 4 and lose 2.
4759 QuicAckFrame frame = InitAckFrame(4); 4755 QuicAckFrame frame = InitAckFrame(4);
4760 NackPacket(2, &frame); 4756 NackPacket(2, &frame);
4761 SendAlgorithmInterface::CongestionVector lost_packets; 4757 SendAlgorithmInterface::CongestionVector lost_packets;
4762 lost_packets.push_back(std::make_pair(2, kMaxPacketSize)); 4758 lost_packets.push_back(std::make_pair(2, kMaxPacketSize));
4763 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)) 4759 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _))
4764 .WillOnce(SetArgPointee<4>(lost_packets)); 4760 .WillOnce(SetArgPointee<4>(lost_packets));
4765 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 4761 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
4766 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 4762 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
(...skipping 12 matching lines...) Expand all
4779 // different packet number. 4775 // different packet number.
4780 TEST_P(QuicConnectionTest, AckNotifierCallbackForAckAfterRTO) { 4776 TEST_P(QuicConnectionTest, AckNotifierCallbackForAckAfterRTO) {
4781 connection_.SetMaxTailLossProbes(0); 4777 connection_.SetMaxTailLossProbes(0);
4782 4778
4783 // Create a listener which we expect to be called. 4779 // Create a listener which we expect to be called.
4784 QuicReferenceCountedPointer<MockAckListener> listener( 4780 QuicReferenceCountedPointer<MockAckListener> listener(
4785 new StrictMock<MockAckListener>); 4781 new StrictMock<MockAckListener>);
4786 4782
4787 QuicTime default_retransmission_time = 4783 QuicTime default_retransmission_time =
4788 clock_.ApproximateNow() + DefaultRetransmissionTime(); 4784 clock_.ApproximateNow() + DefaultRetransmissionTime();
4789 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, listener); 4785 connection_.SendStreamDataWithString(3, "foo", 0, NO_FIN, listener);
4790 EXPECT_EQ(1u, stop_waiting()->least_unacked); 4786 EXPECT_EQ(1u, stop_waiting()->least_unacked);
4791 4787
4792 EXPECT_EQ(1u, writer_->header().packet_number); 4788 EXPECT_EQ(1u, writer_->header().packet_number);
4793 EXPECT_EQ(default_retransmission_time, 4789 EXPECT_EQ(default_retransmission_time,
4794 connection_.GetRetransmissionAlarm()->deadline()); 4790 connection_.GetRetransmissionAlarm()->deadline());
4795 // Simulate the retransmission alarm firing. 4791 // Simulate the retransmission alarm firing.
4796 clock_.AdvanceTime(DefaultRetransmissionTime()); 4792 clock_.AdvanceTime(DefaultRetransmissionTime());
4797 EXPECT_CALL(*listener, OnPacketRetransmitted(3)); 4793 EXPECT_CALL(*listener, OnPacketRetransmitted(3));
4798 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _)); 4794 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _));
4799 connection_.GetRetransmissionAlarm()->Fire(); 4795 connection_.GetRetransmissionAlarm()->Fire();
(...skipping 16 matching lines...) Expand all
4816 4812
4817 // AckNotifierCallback is triggered by the ack of a packet that was 4813 // AckNotifierCallback is triggered by the ack of a packet that was
4818 // previously nacked, even though the retransmission has a different 4814 // previously nacked, even though the retransmission has a different
4819 // packet number. 4815 // packet number.
4820 TEST_P(QuicConnectionTest, AckNotifierCallbackForAckOfNackedPacket) { 4816 TEST_P(QuicConnectionTest, AckNotifierCallbackForAckOfNackedPacket) {
4821 // Create a listener which we expect to be called. 4817 // Create a listener which we expect to be called.
4822 QuicReferenceCountedPointer<MockAckListener> listener( 4818 QuicReferenceCountedPointer<MockAckListener> listener(
4823 new StrictMock<MockAckListener>()); 4819 new StrictMock<MockAckListener>());
4824 4820
4825 // Send four packets, and register to be notified on ACK of packet 2. 4821 // Send four packets, and register to be notified on ACK of packet 2.
4826 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); 4822 connection_.SendStreamDataWithString(3, "foo", 0, NO_FIN, nullptr);
4827 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, listener); 4823 connection_.SendStreamDataWithString(3, "bar", 0, NO_FIN, listener);
4828 connection_.SendStreamDataWithString(3, "baz", 0, !kFin, nullptr); 4824 connection_.SendStreamDataWithString(3, "baz", 0, NO_FIN, nullptr);
4829 connection_.SendStreamDataWithString(3, "qux", 0, !kFin, nullptr); 4825 connection_.SendStreamDataWithString(3, "qux", 0, NO_FIN, nullptr);
4830 4826
4831 // Now we receive ACK for packets 1, 3, and 4 and lose 2. 4827 // Now we receive ACK for packets 1, 3, and 4 and lose 2.
4832 QuicAckFrame frame = InitAckFrame(4); 4828 QuicAckFrame frame = InitAckFrame(4);
4833 NackPacket(2, &frame); 4829 NackPacket(2, &frame);
4834 EXPECT_CALL(*listener, OnPacketRetransmitted(_)); 4830 EXPECT_CALL(*listener, OnPacketRetransmitted(_));
4835 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4831 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4836 SendAlgorithmInterface::CongestionVector lost_packets; 4832 SendAlgorithmInterface::CongestionVector lost_packets;
4837 lost_packets.push_back(std::make_pair(2, kMaxPacketSize)); 4833 lost_packets.push_back(std::make_pair(2, kMaxPacketSize));
4838 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)) 4834 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _))
4839 .WillOnce(SetArgPointee<4>(lost_packets)); 4835 .WillOnce(SetArgPointee<4>(lost_packets));
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
4910 QuicAlarm* ack_alarm = QuicConnectionPeer::GetAckAlarm(&connection_); 4906 QuicAlarm* ack_alarm = QuicConnectionPeer::GetAckAlarm(&connection_);
4911 EXPECT_TRUE(ack_alarm->IsSet()); 4907 EXPECT_TRUE(ack_alarm->IsSet());
4912 } 4908 }
4913 4909
4914 TEST_P(QuicConnectionTest, NoDataNoFin) { 4910 TEST_P(QuicConnectionTest, NoDataNoFin) {
4915 // Make sure that a call to SendStreamWithData, with no data and no FIN, does 4911 // Make sure that a call to SendStreamWithData, with no data and no FIN, does
4916 // not result in a QuicAckNotifier being used-after-free (fail under ASAN). 4912 // not result in a QuicAckNotifier being used-after-free (fail under ASAN).
4917 // Regression test for b/18594622 4913 // Regression test for b/18594622
4918 QuicReferenceCountedPointer<MockAckListener> listener(new MockAckListener); 4914 QuicReferenceCountedPointer<MockAckListener> listener(new MockAckListener);
4919 EXPECT_QUIC_BUG( 4915 EXPECT_QUIC_BUG(
4920 connection_.SendStreamDataWithString(3, "", 0, !kFin, listener), 4916 connection_.SendStreamDataWithString(3, "", 0, NO_FIN, listener),
4921 "Attempt to send empty stream frame"); 4917 "Attempt to send empty stream frame");
4922 } 4918 }
4923 4919
4924 TEST_P(QuicConnectionTest, DoNotSendGoAwayTwice) { 4920 TEST_P(QuicConnectionTest, DoNotSendGoAwayTwice) {
4925 EXPECT_FALSE(connection_.goaway_sent()); 4921 EXPECT_FALSE(connection_.goaway_sent());
4926 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 4922 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
4927 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away."); 4923 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away.");
4928 EXPECT_TRUE(connection_.goaway_sent()); 4924 EXPECT_TRUE(connection_.goaway_sent());
4929 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); 4925 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0);
4930 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away."); 4926 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away.");
4931 } 4927 }
4932 4928
4933 TEST_P(QuicConnectionTest, ReevaluateTimeUntilSendOnAck) { 4929 TEST_P(QuicConnectionTest, ReevaluateTimeUntilSendOnAck) {
4934 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4930 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4935 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, !kFin, 4931 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, NO_FIN,
4936 nullptr); 4932 nullptr);
4937 4933
4938 // Evaluate CanWrite, and have it return a non-Zero value. 4934 // Evaluate CanWrite, and have it return a non-Zero value.
4939 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _)) 4935 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _))
4940 .WillRepeatedly(Return(QuicTime::Delta::FromMilliseconds(1))); 4936 .WillRepeatedly(Return(QuicTime::Delta::FromMilliseconds(1)));
4941 connection_.OnCanWrite(); 4937 connection_.OnCanWrite();
4942 EXPECT_TRUE(connection_.GetSendAlarm()->IsSet()); 4938 EXPECT_TRUE(connection_.GetSendAlarm()->IsSet());
4943 EXPECT_EQ(clock_.Now() + QuicTime::Delta::FromMilliseconds(1), 4939 EXPECT_EQ(clock_.Now() + QuicTime::Delta::FromMilliseconds(1),
4944 connection_.GetSendAlarm()->deadline()); 4940 connection_.GetSendAlarm()->deadline());
4945 4941
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
4986 EXPECT_EQ(1u, connection_.GetStats().blocked_frames_sent); 4982 EXPECT_EQ(1u, connection_.GetStats().blocked_frames_sent);
4987 EXPECT_FALSE(connection_.HasQueuedData()); 4983 EXPECT_FALSE(connection_.HasQueuedData());
4988 } 4984 }
4989 4985
4990 TEST_P(QuicConnectionTest, SendingUnencryptedStreamDataFails) { 4986 TEST_P(QuicConnectionTest, SendingUnencryptedStreamDataFails) {
4991 EXPECT_CALL(visitor_, 4987 EXPECT_CALL(visitor_,
4992 OnConnectionClosed(QUIC_ATTEMPT_TO_SEND_UNENCRYPTED_STREAM_DATA, 4988 OnConnectionClosed(QUIC_ATTEMPT_TO_SEND_UNENCRYPTED_STREAM_DATA,
4993 _, ConnectionCloseSource::FROM_SELF)); 4989 _, ConnectionCloseSource::FROM_SELF));
4994 struct iovec iov; 4990 struct iovec iov;
4995 QuicIOVector data_iov(MakeIOVector("", &iov)); 4991 QuicIOVector data_iov(MakeIOVector("", &iov));
4996 EXPECT_QUIC_BUG(connection_.SendStreamData(3, data_iov, 0, kFin, nullptr), 4992 EXPECT_QUIC_BUG(connection_.SendStreamData(3, data_iov, 0, FIN, nullptr),
4997 "Cannot send stream data without encryption."); 4993 "Cannot send stream data without encryption.");
4998 EXPECT_FALSE(connection_.connected()); 4994 EXPECT_FALSE(connection_.connected());
4999 } 4995 }
5000 4996
5001 TEST_P(QuicConnectionTest, OnPathDegrading) { 4997 TEST_P(QuicConnectionTest, OnPathDegrading) {
5002 QuicByteCount packet_size; 4998 QuicByteCount packet_size;
5003 const size_t kMinTimeoutsBeforePathDegrading = 2; 4999 const size_t kMinTimeoutsBeforePathDegrading = 2;
5004 5000
5005 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 5001 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
5006 .WillOnce(DoAll(SaveArg<3>(&packet_size), Return(true))); 5002 .WillOnce(DoAll(SaveArg<3>(&packet_size), Return(true)));
5007 connection_.SendStreamDataWithString(3, "packet", 0, !kFin, nullptr); 5003 connection_.SendStreamDataWithString(3, "packet", 0, NO_FIN, nullptr);
5008 size_t num_timeouts = 5004 size_t num_timeouts =
5009 kMinTimeoutsBeforePathDegrading + 5005 kMinTimeoutsBeforePathDegrading +
5010 QuicSentPacketManagerPeer::GetMaxTailLossProbes( 5006 QuicSentPacketManagerPeer::GetMaxTailLossProbes(
5011 QuicConnectionPeer::GetSentPacketManager(&connection_)); 5007 QuicConnectionPeer::GetSentPacketManager(&connection_));
5012 for (size_t i = 1; i < num_timeouts; ++i) { 5008 for (size_t i = 1; i < num_timeouts; ++i) {
5013 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10 * i)); 5009 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10 * i));
5014 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, packet_size, _)); 5010 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, packet_size, _));
5015 connection_.GetRetransmissionAlarm()->Fire(); 5011 connection_.GetRetransmissionAlarm()->Fire();
5016 } 5012 }
5017 // Next RTO should cause OnPathDegrading to be called before the 5013 // Next RTO should cause OnPathDegrading to be called before the
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
5073 ConnectionCloseSource::FROM_SELF)); 5069 ConnectionCloseSource::FROM_SELF));
5074 ForceProcessFramePacket(QuicFrame(&frame1_)); 5070 ForceProcessFramePacket(QuicFrame(&frame1_));
5075 } 5071 }
5076 5072
5077 TEST_P(QuicConnectionTest, CloseConnectionOnPacketTooLarge) { 5073 TEST_P(QuicConnectionTest, CloseConnectionOnPacketTooLarge) {
5078 SimulateNextPacketTooLarge(); 5074 SimulateNextPacketTooLarge();
5079 // A connection close packet is sent 5075 // A connection close packet is sent
5080 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PACKET_WRITE_ERROR, _, 5076 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PACKET_WRITE_ERROR, _,
5081 ConnectionCloseSource::FROM_SELF)) 5077 ConnectionCloseSource::FROM_SELF))
5082 .Times(1); 5078 .Times(1);
5083 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); 5079 connection_.SendStreamDataWithString(3, "foo", 0, NO_FIN, nullptr);
5084 } 5080 }
5085 5081
5086 TEST_P(QuicConnectionTest, AlwaysGetPacketTooLarge) { 5082 TEST_P(QuicConnectionTest, AlwaysGetPacketTooLarge) {
5087 // Test even we always get packet too large, we do not infinitely try to send 5083 // Test even we always get packet too large, we do not infinitely try to send
5088 // close packet. 5084 // close packet.
5089 AlwaysGetPacketTooLarge(); 5085 AlwaysGetPacketTooLarge();
5090 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PACKET_WRITE_ERROR, _, 5086 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PACKET_WRITE_ERROR, _,
5091 ConnectionCloseSource::FROM_SELF)) 5087 ConnectionCloseSource::FROM_SELF))
5092 .Times(1); 5088 .Times(1);
5093 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); 5089 connection_.SendStreamDataWithString(3, "foo", 0, NO_FIN, nullptr);
5094 } 5090 }
5095 5091
5096 // Verify that if connection has no outstanding data, it notifies the send 5092 // Verify that if connection has no outstanding data, it notifies the send
5097 // algorithm after the write. 5093 // algorithm after the write.
5098 TEST_P(QuicConnectionTest, SendDataAndBecomeApplicationLimited) { 5094 TEST_P(QuicConnectionTest, SendDataAndBecomeApplicationLimited) {
5099 EXPECT_CALL(*send_algorithm_, OnApplicationLimited(_)).Times(1); 5095 EXPECT_CALL(*send_algorithm_, OnApplicationLimited(_)).Times(1);
5100 { 5096 {
5101 InSequence seq; 5097 InSequence seq;
5102 EXPECT_CALL(visitor_, WillingAndAbleToWrite()).WillRepeatedly(Return(true)); 5098 EXPECT_CALL(visitor_, WillingAndAbleToWrite()).WillRepeatedly(Return(true));
5103 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 5099 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
5136 TEST_P(QuicConnectionTest, DonotForceSendingAckOnPacketTooLarge) { 5132 TEST_P(QuicConnectionTest, DonotForceSendingAckOnPacketTooLarge) {
5137 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 5133 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
5138 // Send an ack by simulating delayed ack alarm firing. 5134 // Send an ack by simulating delayed ack alarm firing.
5139 ProcessPacket(1); 5135 ProcessPacket(1);
5140 QuicAlarm* ack_alarm = QuicConnectionPeer::GetAckAlarm(&connection_); 5136 QuicAlarm* ack_alarm = QuicConnectionPeer::GetAckAlarm(&connection_);
5141 EXPECT_TRUE(ack_alarm->IsSet()); 5137 EXPECT_TRUE(ack_alarm->IsSet());
5142 connection_.GetAckAlarm()->Fire(); 5138 connection_.GetAckAlarm()->Fire();
5143 // Simulate data packet causes write error. 5139 // Simulate data packet causes write error.
5144 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PACKET_WRITE_ERROR, _, _)); 5140 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PACKET_WRITE_ERROR, _, _));
5145 SimulateNextPacketTooLarge(); 5141 SimulateNextPacketTooLarge();
5146 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); 5142 connection_.SendStreamDataWithString(3, "foo", 0, NO_FIN, nullptr);
5147 EXPECT_EQ(1u, writer_->frame_count()); 5143 EXPECT_EQ(1u, writer_->frame_count());
5148 EXPECT_FALSE(writer_->connection_close_frames().empty()); 5144 EXPECT_FALSE(writer_->connection_close_frames().empty());
5149 // Ack frame is not bundled in connection close packet. 5145 // Ack frame is not bundled in connection close packet.
5150 EXPECT_TRUE(writer_->ack_frames().empty()); 5146 EXPECT_TRUE(writer_->ack_frames().empty());
5151 } 5147 }
5152 5148
5153 TEST_P(QuicConnectionTest, CloseConnectionForStatelessReject) { 5149 TEST_P(QuicConnectionTest, CloseConnectionForStatelessReject) {
5154 string error_details("stateless reject"); 5150 string error_details("stateless reject");
5155 EXPECT_CALL(visitor_, OnConnectionClosed( 5151 EXPECT_CALL(visitor_, OnConnectionClosed(
5156 QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT, 5152 QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT,
5157 error_details, ConnectionCloseSource::FROM_PEER)); 5153 error_details, ConnectionCloseSource::FROM_PEER));
5158 connection_.set_perspective(Perspective::IS_CLIENT); 5154 connection_.set_perspective(Perspective::IS_CLIENT);
5159 connection_.CloseConnection(QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT, 5155 connection_.CloseConnection(QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT,
5160 error_details, 5156 error_details,
5161 ConnectionCloseBehavior::SILENT_CLOSE); 5157 ConnectionCloseBehavior::SILENT_CLOSE);
5162 } 5158 }
5163 5159
5164 } // namespace 5160 } // namespace
5165 } // namespace test 5161 } // namespace test
5166 } // namespace net 5162 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698