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

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

Issue 331573002: Land Recent QUIC Changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix compiler error - use push_back to initialize vectors Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/quic/quic_connection.cc ('k') | net/quic/quic_data_stream_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/quic/quic_connection.h" 5 #include "net/quic/quic_connection.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
11 #include "net/quic/congestion_control/loss_detection_interface.h" 11 #include "net/quic/congestion_control/loss_detection_interface.h"
12 #include "net/quic/congestion_control/receive_algorithm_interface.h" 12 #include "net/quic/congestion_control/receive_algorithm_interface.h"
13 #include "net/quic/congestion_control/send_algorithm_interface.h" 13 #include "net/quic/congestion_control/send_algorithm_interface.h"
14 #include "net/quic/crypto/null_encrypter.h" 14 #include "net/quic/crypto/null_encrypter.h"
15 #include "net/quic/crypto/quic_decrypter.h" 15 #include "net/quic/crypto/quic_decrypter.h"
16 #include "net/quic/crypto/quic_encrypter.h" 16 #include "net/quic/crypto/quic_encrypter.h"
17 #include "net/quic/quic_flags.h" 17 #include "net/quic/quic_flags.h"
18 #include "net/quic/quic_protocol.h" 18 #include "net/quic/quic_protocol.h"
19 #include "net/quic/quic_utils.h" 19 #include "net/quic/quic_utils.h"
20 #include "net/quic/test_tools/mock_clock.h" 20 #include "net/quic/test_tools/mock_clock.h"
21 #include "net/quic/test_tools/mock_random.h" 21 #include "net/quic/test_tools/mock_random.h"
22 #include "net/quic/test_tools/quic_connection_peer.h" 22 #include "net/quic/test_tools/quic_connection_peer.h"
23 #include "net/quic/test_tools/quic_framer_peer.h" 23 #include "net/quic/test_tools/quic_framer_peer.h"
24 #include "net/quic/test_tools/quic_packet_creator_peer.h" 24 #include "net/quic/test_tools/quic_packet_creator_peer.h"
25 #include "net/quic/test_tools/quic_packet_generator_peer.h"
26 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" 25 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h"
27 #include "net/quic/test_tools/quic_test_utils.h" 26 #include "net/quic/test_tools/quic_test_utils.h"
28 #include "net/quic/test_tools/simple_quic_framer.h" 27 #include "net/quic/test_tools/simple_quic_framer.h"
29 #include "testing/gmock/include/gmock/gmock.h" 28 #include "testing/gmock/include/gmock/gmock.h"
30 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
31 30
32 using base::StringPiece; 31 using base::StringPiece;
33 using std::map; 32 using std::map;
34 using std::vector; 33 using std::vector;
35 using testing::AnyNumber; 34 using testing::AnyNumber;
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 SerializedPacket(sequence_number, PACKET_6BYTE_SEQUENCE_NUMBER, 453 SerializedPacket(sequence_number, PACKET_6BYTE_SEQUENCE_NUMBER,
455 packet, entropy_hash, retransmittable_frames)); 454 packet, entropy_hash, retransmittable_frames));
456 } 455 }
457 456
458 QuicConsumedData SendStreamDataWithString( 457 QuicConsumedData SendStreamDataWithString(
459 QuicStreamId id, 458 QuicStreamId id,
460 StringPiece data, 459 StringPiece data,
461 QuicStreamOffset offset, 460 QuicStreamOffset offset,
462 bool fin, 461 bool fin,
463 QuicAckNotifier::DelegateInterface* delegate) { 462 QuicAckNotifier::DelegateInterface* delegate) {
463 return SendStreamDataWithStringHelper(id, data, offset, fin,
464 MAY_FEC_PROTECT, delegate);
465 }
466
467 QuicConsumedData SendStreamDataWithStringWithFec(
468 QuicStreamId id,
469 StringPiece data,
470 QuicStreamOffset offset,
471 bool fin,
472 QuicAckNotifier::DelegateInterface* delegate) {
473 return SendStreamDataWithStringHelper(id, data, offset, fin,
474 MUST_FEC_PROTECT, delegate);
475 }
476
477 QuicConsumedData SendStreamDataWithStringHelper(
478 QuicStreamId id,
479 StringPiece data,
480 QuicStreamOffset offset,
481 bool fin,
482 FecProtection fec_protection,
483 QuicAckNotifier::DelegateInterface* delegate) {
464 IOVector data_iov; 484 IOVector data_iov;
465 if (!data.empty()) { 485 if (!data.empty()) {
466 data_iov.Append(const_cast<char*>(data.data()), data.size()); 486 data_iov.Append(const_cast<char*>(data.data()), data.size());
467 } 487 }
468 return QuicConnection::SendStreamData(id, data_iov, offset, fin, delegate); 488 return QuicConnection::SendStreamData(id, data_iov, offset, fin,
489 fec_protection, delegate);
469 } 490 }
470 491
471 QuicConsumedData SendStreamData3() { 492 QuicConsumedData SendStreamData3() {
472 return SendStreamDataWithString(kClientDataStreamId1, "food", 0, !kFin, 493 return SendStreamDataWithString(kClientDataStreamId1, "food", 0, !kFin,
473 NULL); 494 NULL);
474 } 495 }
475 496
497 QuicConsumedData SendStreamData3WithFec() {
498 return SendStreamDataWithStringWithFec(kClientDataStreamId1, "food", 0,
499 !kFin, NULL);
500 }
501
476 QuicConsumedData SendStreamData5() { 502 QuicConsumedData SendStreamData5() {
477 return SendStreamDataWithString(kClientDataStreamId2, "food2", 0, 503 return SendStreamDataWithString(kClientDataStreamId2, "food2", 0,
478 !kFin, NULL); 504 !kFin, NULL);
479 } 505 }
480 506
507 QuicConsumedData SendStreamData5WithFec() {
508 return SendStreamDataWithStringWithFec(kClientDataStreamId2, "food2", 0,
509 !kFin, NULL);
510 }
481 // Ensures the connection can write stream data before writing. 511 // Ensures the connection can write stream data before writing.
482 QuicConsumedData EnsureWritableAndSendStreamData5() { 512 QuicConsumedData EnsureWritableAndSendStreamData5() {
483 EXPECT_TRUE(CanWriteStreamData()); 513 EXPECT_TRUE(CanWriteStreamData());
484 return SendStreamData5(); 514 return SendStreamData5();
485 } 515 }
486 516
487 // The crypto stream has special semantics so that it is not blocked by a 517 // The crypto stream has special semantics so that it is not blocked by a
488 // congestion window limitation, and also so that it gets put into a separate 518 // congestion window limitation, and also so that it gets put into a separate
489 // packet (so that it is easier to reason about a crypto frame not being 519 // packet (so that it is easier to reason about a crypto frame not being
490 // split needlessly across packet boundaries). As a result, we have separate 520 // split needlessly across packet boundaries). As a result, we have separate
(...skipping 14 matching lines...) Expand all
505 QuicConnectionPeer::GetFramer(this)->set_version(version); 535 QuicConnectionPeer::GetFramer(this)->set_version(version);
506 } 536 }
507 537
508 void SetSupportedVersions(const QuicVersionVector& versions) { 538 void SetSupportedVersions(const QuicVersionVector& versions) {
509 QuicConnectionPeer::GetFramer(this)->SetSupportedVersions(versions); 539 QuicConnectionPeer::GetFramer(this)->SetSupportedVersions(versions);
510 writer_->SetSupportedVersions(versions); 540 writer_->SetSupportedVersions(versions);
511 } 541 }
512 542
513 void set_is_server(bool is_server) { 543 void set_is_server(bool is_server) {
514 writer_->set_is_server(is_server); 544 writer_->set_is_server(is_server);
515 QuicPacketCreatorPeer::SetIsServer(
516 QuicConnectionPeer::GetPacketCreator(this), is_server);
517 QuicConnectionPeer::SetIsServer(this, is_server); 545 QuicConnectionPeer::SetIsServer(this, is_server);
518 } 546 }
519 547
520 TestConnectionHelper::TestAlarm* GetAckAlarm() { 548 TestConnectionHelper::TestAlarm* GetAckAlarm() {
521 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( 549 return reinterpret_cast<TestConnectionHelper::TestAlarm*>(
522 QuicConnectionPeer::GetAckAlarm(this)); 550 QuicConnectionPeer::GetAckAlarm(this));
523 } 551 }
524 552
525 TestConnectionHelper::TestAlarm* GetPingAlarm() { 553 TestConnectionHelper::TestAlarm* GetPingAlarm() {
526 return reinterpret_cast<TestConnectionHelper::TestAlarm*>( 554 return reinterpret_cast<TestConnectionHelper::TestAlarm*>(
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 599
572 private: 600 private:
573 QuicPacketHeader revived_header_; 601 QuicPacketHeader revived_header_;
574 }; 602 };
575 603
576 class QuicConnectionTest : public ::testing::TestWithParam<QuicVersion> { 604 class QuicConnectionTest : public ::testing::TestWithParam<QuicVersion> {
577 protected: 605 protected:
578 QuicConnectionTest() 606 QuicConnectionTest()
579 : connection_id_(42), 607 : connection_id_(42),
580 framer_(SupportedVersions(version()), QuicTime::Zero(), false), 608 framer_(SupportedVersions(version()), QuicTime::Zero(), false),
581 peer_creator_(connection_id_, &framer_, &random_generator_, false), 609 peer_creator_(connection_id_, &framer_, &random_generator_),
582 send_algorithm_(new StrictMock<MockSendAlgorithm>), 610 send_algorithm_(new StrictMock<MockSendAlgorithm>),
583 loss_algorithm_(new MockLossAlgorithm()), 611 loss_algorithm_(new MockLossAlgorithm()),
584 helper_(new TestConnectionHelper(&clock_, &random_generator_)), 612 helper_(new TestConnectionHelper(&clock_, &random_generator_)),
585 writer_(new TestPacketWriter(version())), 613 writer_(new TestPacketWriter(version())),
586 connection_(connection_id_, IPEndPoint(), helper_.get(), 614 connection_(connection_id_, IPEndPoint(), helper_.get(),
587 writer_.get(), false, version()), 615 writer_.get(), false, version()),
588 frame1_(1, false, 0, MakeIOVector(data1)), 616 frame1_(1, false, 0, MakeIOVector(data1)),
589 frame2_(1, false, 3, MakeIOVector(data2)), 617 frame2_(1, false, 3, MakeIOVector(data2)),
590 sequence_number_length_(PACKET_6BYTE_SEQUENCE_NUMBER), 618 sequence_number_length_(PACKET_6BYTE_SEQUENCE_NUMBER),
591 connection_id_length_(PACKET_8BYTE_CONNECTION_ID) { 619 connection_id_length_(PACKET_8BYTE_CONNECTION_ID) {
(...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after
1453 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining 1481 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining
1454 // packet length. The size of the offset field in a stream frame is 0 for 1482 // packet length. The size of the offset field in a stream frame is 0 for
1455 // offset 0, and 2 for non-zero offsets up through 64K. Increase 1483 // offset 0, and 2 for non-zero offsets up through 64K. Increase
1456 // max_packet_length by 2 so that subsequent packets containing subsequent 1484 // max_packet_length by 2 so that subsequent packets containing subsequent
1457 // stream frames with non-zero offets will fit within the packet length. 1485 // stream frames with non-zero offets will fit within the packet length.
1458 size_t length = 2 + GetPacketLengthForOneStream( 1486 size_t length = 2 + GetPacketLengthForOneStream(
1459 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, 1487 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER,
1460 IN_FEC_GROUP, &payload_length); 1488 IN_FEC_GROUP, &payload_length);
1461 creator->set_max_packet_length(length); 1489 creator->set_max_packet_length(length);
1462 1490
1463 // And send FEC every two packets. 1491 // Enable FEC.
1464 QuicPacketGeneratorPeer::SwitchFecProtectionOn( 1492 creator->set_max_packets_per_fec_group(2);
1465 QuicConnectionPeer::GetPacketGenerator(&connection_), 2);
1466 1493
1467 // Send 4 data packets and 2 FEC packets. 1494 // Send 4 protected data packets, which will also trigger 2 FEC packets.
1468 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); 1495 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6);
1469 // The first stream frame will have 2 fewer overhead bytes than the other 3. 1496 // The first stream frame will have 2 fewer overhead bytes than the other 3.
1470 const string payload(payload_length * 4 + 2, 'a'); 1497 const string payload(payload_length * 4 + 2, 'a');
1471 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL); 1498 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, NULL);
1472 // Expect the FEC group to be closed after SendStreamDataWithString. 1499 // Expect the FEC group to be closed after SendStreamDataWithString.
1473 EXPECT_FALSE(creator->ShouldSendFec(true)); 1500 EXPECT_FALSE(creator->IsFecGroupOpen());
1474 EXPECT_TRUE(creator->IsFecProtected()); 1501 EXPECT_FALSE(creator->IsFecProtected());
1475 } 1502 }
1476 1503
1477 TEST_P(QuicConnectionTest, FECQueueing) { 1504 TEST_P(QuicConnectionTest, FECQueueing) {
1478 // All packets carry version info till version is negotiated. 1505 // All packets carry version info till version is negotiated.
1479 size_t payload_length; 1506 size_t payload_length;
1480 QuicPacketCreator* creator = 1507 QuicPacketCreator* creator =
1481 QuicConnectionPeer::GetPacketCreator(&connection_); 1508 QuicConnectionPeer::GetPacketCreator(&connection_);
1482 size_t length = GetPacketLengthForOneStream( 1509 size_t length = GetPacketLengthForOneStream(
1483 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, 1510 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER,
1484 IN_FEC_GROUP, &payload_length); 1511 IN_FEC_GROUP, &payload_length);
1485 creator->set_max_packet_length(length); 1512 creator->set_max_packet_length(length);
1486 // And send FEC every two packets. 1513 // Enable FEC.
1487 QuicPacketGeneratorPeer::SwitchFecProtectionOn( 1514 creator->set_max_packets_per_fec_group(1);
1488 QuicConnectionPeer::GetPacketGenerator(&connection_), 1);
1489 1515
1490 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1516 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1491 BlockOnNextWrite(); 1517 BlockOnNextWrite();
1492 const string payload(payload_length, 'a'); 1518 const string payload(payload_length, 'a');
1493 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL); 1519 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, NULL);
1494 EXPECT_FALSE(creator->ShouldSendFec(true)); 1520 EXPECT_FALSE(creator->IsFecGroupOpen());
1495 EXPECT_TRUE(creator->IsFecProtected()); 1521 EXPECT_FALSE(creator->IsFecProtected());
1496 // Expect the first data packet and the fec packet to be queued. 1522 // Expect the first data packet and the fec packet to be queued.
1497 EXPECT_EQ(2u, connection_.NumQueuedPackets()); 1523 EXPECT_EQ(2u, connection_.NumQueuedPackets());
1498 } 1524 }
1499 1525
1500 TEST_P(QuicConnectionTest, AbandonFECFromCongestionWindow) { 1526 TEST_P(QuicConnectionTest, AbandonFECFromCongestionWindow) {
1501 QuicPacketGeneratorPeer::SwitchFecProtectionOn( 1527 // Enable FEC.
1502 QuicConnectionPeer::GetPacketGenerator(&connection_), 1); 1528 QuicConnectionPeer::GetPacketCreator(
1529 &connection_)->set_max_packets_per_fec_group(1);
1503 1530
1504 // 1 Data and 1 FEC packet. 1531 // 1 Data and 1 FEC packet.
1505 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); 1532 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
1506 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); 1533 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, NULL);
1507 1534
1508 const QuicTime::Delta retransmission_time = 1535 const QuicTime::Delta retransmission_time =
1509 QuicTime::Delta::FromMilliseconds(5000); 1536 QuicTime::Delta::FromMilliseconds(5000);
1510 clock_.AdvanceTime(retransmission_time); 1537 clock_.AdvanceTime(retransmission_time);
1511 1538
1512 // Abandon FEC packet and data packet. 1539 // Abandon FEC packet and data packet.
1513 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 1540 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
1514 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 1541 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
1515 EXPECT_CALL(visitor_, OnCanWrite()); 1542 EXPECT_CALL(visitor_, OnCanWrite());
1516 connection_.OnRetransmissionTimeout(); 1543 connection_.OnRetransmissionTimeout();
1517 } 1544 }
1518 1545
1519 TEST_P(QuicConnectionTest, DontAbandonAckedFEC) { 1546 TEST_P(QuicConnectionTest, DontAbandonAckedFEC) {
1520 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1547 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1521 QuicPacketGeneratorPeer::SwitchFecProtectionOn( 1548 // Enable FEC.
1522 QuicConnectionPeer::GetPacketGenerator(&connection_), 1); 1549 QuicConnectionPeer::GetPacketCreator(
1550 &connection_)->set_max_packets_per_fec_group(1);
1523 1551
1524 // 1 Data and 1 FEC packet. 1552 // 1 Data and 1 FEC packet.
1525 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); 1553 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6);
1526 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); 1554 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, NULL);
1527 // Send some more data afterwards to ensure early retransmit doesn't trigger. 1555 // Send some more data afterwards to ensure early retransmit doesn't trigger.
1528 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL); 1556 connection_.SendStreamDataWithStringWithFec(3, "foo", 3, !kFin, NULL);
1529 connection_.SendStreamDataWithString(3, "foo", 6, !kFin, NULL); 1557 connection_.SendStreamDataWithStringWithFec(3, "foo", 6, !kFin, NULL);
1530 1558
1531 QuicAckFrame ack_fec = InitAckFrame(2, 1); 1559 QuicAckFrame ack_fec = InitAckFrame(2, 1);
1532 // Data packet missing. 1560 // Data packet missing.
1533 // TODO(ianswett): Note that this is not a sensible ack, since if the FEC was 1561 // TODO(ianswett): Note that this is not a sensible ack, since if the FEC was
1534 // received, it would cause the covered packet to be acked as well. 1562 // received, it would cause the covered packet to be acked as well.
1535 NackPacket(1, &ack_fec); 1563 NackPacket(1, &ack_fec);
1536 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 1564 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
1537 ProcessAckPacket(&ack_fec); 1565 ProcessAckPacket(&ack_fec);
1538 clock_.AdvanceTime(DefaultRetransmissionTime()); 1566 clock_.AdvanceTime(DefaultRetransmissionTime());
1539 1567
1540 // Don't abandon the acked FEC packet, but it will abandon 2 the subsequent 1568 // Don't abandon the acked FEC packet, but it will abandon 2 the subsequent
1541 // FEC packets. 1569 // FEC packets.
1542 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 1570 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
1543 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3); 1571 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3);
1544 connection_.GetRetransmissionAlarm()->Fire(); 1572 connection_.GetRetransmissionAlarm()->Fire();
1545 } 1573 }
1546 1574
1547 TEST_P(QuicConnectionTest, AbandonAllFEC) { 1575 TEST_P(QuicConnectionTest, AbandonAllFEC) {
1548 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1576 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1549 QuicPacketGeneratorPeer::SwitchFecProtectionOn( 1577 // Enable FEC.
1550 QuicConnectionPeer::GetPacketGenerator(&connection_), 1); 1578 QuicConnectionPeer::GetPacketCreator(
1579 &connection_)->set_max_packets_per_fec_group(1);
1551 1580
1552 // 1 Data and 1 FEC packet. 1581 // 1 Data and 1 FEC packet.
1553 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); 1582 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6);
1554 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); 1583 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, NULL);
1555 // Send some more data afterwards to ensure early retransmit doesn't trigger. 1584 // Send some more data afterwards to ensure early retransmit doesn't trigger.
1556 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL); 1585 connection_.SendStreamDataWithStringWithFec(3, "foo", 3, !kFin, NULL);
1557 // Advance the time so not all the FEC packets are abandoned. 1586 // Advance the time so not all the FEC packets are abandoned.
1558 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); 1587 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1));
1559 connection_.SendStreamDataWithString(3, "foo", 6, !kFin, NULL); 1588 connection_.SendStreamDataWithStringWithFec(3, "foo", 6, !kFin, NULL);
1560 1589
1561 QuicAckFrame ack_fec = InitAckFrame(5, 1); 1590 QuicAckFrame ack_fec = InitAckFrame(5, 1);
1562 // Ack all data packets, but no fec packets. 1591 // Ack all data packets, but no fec packets.
1563 NackPacket(2, &ack_fec); 1592 NackPacket(2, &ack_fec);
1564 NackPacket(4, &ack_fec); 1593 NackPacket(4, &ack_fec);
1565 1594
1566 // Lose the first FEC packet and ack the three data packets. 1595 // Lose the first FEC packet and ack the three data packets.
1567 SequenceNumberSet lost_packets; 1596 SequenceNumberSet lost_packets;
1568 lost_packets.insert(2); 1597 lost_packets.insert(2);
1569 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 1598 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1655 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1684 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1656 EXPECT_FALSE(connection_.HasQueuedData()); 1685 EXPECT_FALSE(connection_.HasQueuedData());
1657 1686
1658 // Parse the last packet and ensure it's the stream frame from stream 3. 1687 // Parse the last packet and ensure it's the stream frame from stream 3.
1659 EXPECT_EQ(1u, writer_->frame_count()); 1688 EXPECT_EQ(1u, writer_->frame_count());
1660 ASSERT_EQ(1u, writer_->stream_frames().size()); 1689 ASSERT_EQ(1u, writer_->stream_frames().size());
1661 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0].stream_id); 1690 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0].stream_id);
1662 } 1691 }
1663 1692
1664 TEST_P(QuicConnectionTest, FramePackingFEC) { 1693 TEST_P(QuicConnectionTest, FramePackingFEC) {
1665 // Enable fec. 1694 // Enable FEC.
1666 QuicPacketGeneratorPeer::SwitchFecProtectionOn( 1695 QuicConnectionPeer::GetPacketCreator(
1667 QuicConnectionPeer::GetPacketGenerator(&connection_), 6); 1696 &connection_)->set_max_packets_per_fec_group(6);
1668 1697
1669 CongestionBlockWrites(); 1698 CongestionBlockWrites();
1670 1699
1671 // Send an ack and two stream frames in 1 packet by queueing them. 1700 // Queue an ack and two stream frames. Ack gets flushed when FEC is turned on
1701 // for sending protected data; two stream frames are packing in 1 packet.
1702 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll(
1703 IgnoreResult(InvokeWithoutArgs(
1704 &connection_, &TestConnection::SendStreamData3WithFec)),
1705 IgnoreResult(InvokeWithoutArgs(
1706 &connection_, &TestConnection::SendStreamData5WithFec))));
1672 connection_.SendAck(); 1707 connection_.SendAck();
1673 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll(
1674 IgnoreResult(InvokeWithoutArgs(&connection_,
1675 &TestConnection::SendStreamData3)),
1676 IgnoreResult(InvokeWithoutArgs(&connection_,
1677 &TestConnection::SendStreamData5))));
1678 1708
1679 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); 1709 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3);
1680 CongestionUnblockWrites(); 1710 CongestionUnblockWrites();
1681 connection_.GetSendAlarm()->Fire(); 1711 connection_.GetSendAlarm()->Fire();
1682 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1712 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1683 EXPECT_FALSE(connection_.HasQueuedData()); 1713 EXPECT_FALSE(connection_.HasQueuedData());
1684 1714
1685 // Parse the last packet and ensure it's in an fec group. 1715 // Parse the last packet and ensure it's in an fec group.
1686 EXPECT_EQ(1u, writer_->header().fec_group); 1716 EXPECT_EQ(2u, writer_->header().fec_group);
1687 EXPECT_EQ(0u, writer_->frame_count()); 1717 EXPECT_EQ(0u, writer_->frame_count());
1688 } 1718 }
1689 1719
1690 TEST_P(QuicConnectionTest, FramePackingAckResponse) { 1720 TEST_P(QuicConnectionTest, FramePackingAckResponse) {
1691 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1721 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1692 // Process a data packet to queue up a pending ack. 1722 // Process a data packet to queue up a pending ack.
1693 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); 1723 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1);
1694 ProcessDataPacket(1, 1, kEntropyFlag); 1724 ProcessDataPacket(1, 1, kEntropyFlag);
1695 1725
1696 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( 1726 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll(
(...skipping 28 matching lines...) Expand all
1725 1755
1726 TEST_P(QuicConnectionTest, FramePackingSendv) { 1756 TEST_P(QuicConnectionTest, FramePackingSendv) {
1727 // Send data in 1 packet by writing multiple blocks in a single iovector 1757 // Send data in 1 packet by writing multiple blocks in a single iovector
1728 // using writev. 1758 // using writev.
1729 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 1759 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
1730 1760
1731 char data[] = "ABCD"; 1761 char data[] = "ABCD";
1732 IOVector data_iov; 1762 IOVector data_iov;
1733 data_iov.AppendNoCoalesce(data, 2); 1763 data_iov.AppendNoCoalesce(data, 2);
1734 data_iov.AppendNoCoalesce(data + 2, 2); 1764 data_iov.AppendNoCoalesce(data + 2, 2);
1735 connection_.SendStreamData(1, data_iov, 0, !kFin, NULL); 1765 connection_.SendStreamData(1, data_iov, 0, !kFin, MAY_FEC_PROTECT, NULL);
1736 1766
1737 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1767 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1738 EXPECT_FALSE(connection_.HasQueuedData()); 1768 EXPECT_FALSE(connection_.HasQueuedData());
1739 1769
1740 // Parse the last packet and ensure multiple iovector blocks have 1770 // Parse the last packet and ensure multiple iovector blocks have
1741 // been packed into a single stream frame from one stream. 1771 // been packed into a single stream frame from one stream.
1742 EXPECT_EQ(1u, writer_->frame_count()); 1772 EXPECT_EQ(1u, writer_->frame_count());
1743 EXPECT_EQ(1u, writer_->stream_frames().size()); 1773 EXPECT_EQ(1u, writer_->stream_frames().size());
1744 QuicStreamFrame frame = writer_->stream_frames()[0]; 1774 QuicStreamFrame frame = writer_->stream_frames()[0];
1745 EXPECT_EQ(1u, frame.stream_id); 1775 EXPECT_EQ(1u, frame.stream_id);
1746 EXPECT_EQ("ABCD", string(static_cast<char*> 1776 EXPECT_EQ("ABCD", string(static_cast<char*>
1747 (frame.data.iovec()[0].iov_base), 1777 (frame.data.iovec()[0].iov_base),
1748 (frame.data.iovec()[0].iov_len))); 1778 (frame.data.iovec()[0].iov_len)));
1749 } 1779 }
1750 1780
1751 TEST_P(QuicConnectionTest, FramePackingSendvQueued) { 1781 TEST_P(QuicConnectionTest, FramePackingSendvQueued) {
1752 // Try to send two stream frames in 1 packet by using writev. 1782 // Try to send two stream frames in 1 packet by using writev.
1753 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 1783 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
1754 1784
1755 BlockOnNextWrite(); 1785 BlockOnNextWrite();
1756 char data[] = "ABCD"; 1786 char data[] = "ABCD";
1757 IOVector data_iov; 1787 IOVector data_iov;
1758 data_iov.AppendNoCoalesce(data, 2); 1788 data_iov.AppendNoCoalesce(data, 2);
1759 data_iov.AppendNoCoalesce(data + 2, 2); 1789 data_iov.AppendNoCoalesce(data + 2, 2);
1760 connection_.SendStreamData(1, data_iov, 0, !kFin, NULL); 1790 connection_.SendStreamData(1, data_iov, 0, !kFin, MAY_FEC_PROTECT, NULL);
1761 1791
1762 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 1792 EXPECT_EQ(1u, connection_.NumQueuedPackets());
1763 EXPECT_TRUE(connection_.HasQueuedData()); 1793 EXPECT_TRUE(connection_.HasQueuedData());
1764 1794
1765 // Unblock the writes and actually send. 1795 // Unblock the writes and actually send.
1766 writer_->SetWritable(); 1796 writer_->SetWritable();
1767 connection_.OnCanWrite(); 1797 connection_.OnCanWrite();
1768 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1798 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1769 1799
1770 // Parse the last packet and ensure it's one stream frame from one stream. 1800 // Parse the last packet and ensure it's one stream frame from one stream.
1771 EXPECT_EQ(1u, writer_->frame_count()); 1801 EXPECT_EQ(1u, writer_->frame_count());
1772 EXPECT_EQ(1u, writer_->stream_frames().size()); 1802 EXPECT_EQ(1u, writer_->stream_frames().size());
1773 EXPECT_EQ(1u, writer_->stream_frames()[0].stream_id); 1803 EXPECT_EQ(1u, writer_->stream_frames()[0].stream_id);
1774 } 1804 }
1775 1805
1776 TEST_P(QuicConnectionTest, SendingZeroBytes) { 1806 TEST_P(QuicConnectionTest, SendingZeroBytes) {
1777 // Send a zero byte write with a fin using writev. 1807 // Send a zero byte write with a fin using writev.
1778 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 1808 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
1779 IOVector empty_iov; 1809 IOVector empty_iov;
1780 connection_.SendStreamData(1, empty_iov, 0, kFin, NULL); 1810 connection_.SendStreamData(1, empty_iov, 0, kFin, MAY_FEC_PROTECT, NULL);
1781 1811
1782 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1812 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1783 EXPECT_FALSE(connection_.HasQueuedData()); 1813 EXPECT_FALSE(connection_.HasQueuedData());
1784 1814
1785 // Parse the last packet and ensure it's one stream frame from one stream. 1815 // Parse the last packet and ensure it's one stream frame from one stream.
1786 EXPECT_EQ(1u, writer_->frame_count()); 1816 EXPECT_EQ(1u, writer_->frame_count());
1787 EXPECT_EQ(1u, writer_->stream_frames().size()); 1817 EXPECT_EQ(1u, writer_->stream_frames().size());
1788 EXPECT_EQ(1u, writer_->stream_frames()[0].stream_id); 1818 EXPECT_EQ(1u, writer_->stream_frames()[0].stream_id);
1789 EXPECT_TRUE(writer_->stream_frames()[0].fin); 1819 EXPECT_TRUE(writer_->stream_frames()[0].fin);
1790 } 1820 }
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
2132 PACKET_4BYTE_SEQUENCE_NUMBER, 2162 PACKET_4BYTE_SEQUENCE_NUMBER,
2133 PACKET_2BYTE_SEQUENCE_NUMBER, 2163 PACKET_2BYTE_SEQUENCE_NUMBER,
2134 PACKET_1BYTE_SEQUENCE_NUMBER}; 2164 PACKET_1BYTE_SEQUENCE_NUMBER};
2135 // For each sequence number length size, revive a packet and check sequence 2165 // For each sequence number length size, revive a packet and check sequence
2136 // number length in the revived packet. 2166 // number length in the revived packet.
2137 for (size_t i = 0; i < arraysize(lengths); ++i) { 2167 for (size_t i = 0; i < arraysize(lengths); ++i) {
2138 // Set sequence_number_length_ (for data and FEC packets). 2168 // Set sequence_number_length_ (for data and FEC packets).
2139 sequence_number_length_ = lengths[i]; 2169 sequence_number_length_ = lengths[i];
2140 fec_packet += 2; 2170 fec_packet += 2;
2141 // Don't send missing packet, but send fec packet right after it. 2171 // Don't send missing packet, but send fec packet right after it.
2142 ProcessFecPacket(/*seq_num=*/fec_packet, /*fec_group=*/fec_packet - 1, 2172 ProcessFecPacket(fec_packet, fec_packet - 1, true, !kEntropyFlag, NULL);
2143 true, !kEntropyFlag, NULL);
2144 // Sequence number length in the revived header should be the same as 2173 // Sequence number length in the revived header should be the same as
2145 // in the original data/fec packet headers. 2174 // in the original data/fec packet headers.
2146 EXPECT_EQ(sequence_number_length_, fec_visitor->revived_header(). 2175 EXPECT_EQ(sequence_number_length_, fec_visitor->revived_header().
2147 public_header.sequence_number_length); 2176 public_header.sequence_number_length);
2148 } 2177 }
2149 } 2178 }
2150 2179
2151 TEST_P(QuicConnectionTest, ReviveMissingPacketWithVaryingConnectionIdLengths) { 2180 TEST_P(QuicConnectionTest, ReviveMissingPacketWithVaryingConnectionIdLengths) {
2152 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2181 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2153 2182
2154 // Set up a debug visitor to the connection. 2183 // Set up a debug visitor to the connection.
2155 scoped_ptr<FecQuicConnectionDebugVisitor> 2184 scoped_ptr<FecQuicConnectionDebugVisitor>
2156 fec_visitor(new FecQuicConnectionDebugVisitor); 2185 fec_visitor(new FecQuicConnectionDebugVisitor);
2157 connection_.set_debug_visitor(fec_visitor.get()); 2186 connection_.set_debug_visitor(fec_visitor.get());
2158 2187
2159 QuicPacketSequenceNumber fec_packet = 0; 2188 QuicPacketSequenceNumber fec_packet = 0;
2160 QuicConnectionIdLength lengths[] = {PACKET_8BYTE_CONNECTION_ID, 2189 QuicConnectionIdLength lengths[] = {PACKET_8BYTE_CONNECTION_ID,
2161 PACKET_4BYTE_CONNECTION_ID, 2190 PACKET_4BYTE_CONNECTION_ID,
2162 PACKET_1BYTE_CONNECTION_ID, 2191 PACKET_1BYTE_CONNECTION_ID,
2163 PACKET_0BYTE_CONNECTION_ID}; 2192 PACKET_0BYTE_CONNECTION_ID};
2164 // For each connection id length size, revive a packet and check connection 2193 // For each connection id length size, revive a packet and check connection
2165 // id length in the revived packet. 2194 // id length in the revived packet.
2166 for (size_t i = 0; i < arraysize(lengths); ++i) { 2195 for (size_t i = 0; i < arraysize(lengths); ++i) {
2167 // Set connection id length (for data and FEC packets). 2196 // Set connection id length (for data and FEC packets).
2168 connection_id_length_ = lengths[i]; 2197 connection_id_length_ = lengths[i];
2169 fec_packet += 2; 2198 fec_packet += 2;
2170 // Don't send missing packet, but send fec packet right after it. 2199 // Don't send missing packet, but send fec packet right after it.
2171 ProcessFecPacket(/*seq_num=*/fec_packet, /*fec_group=*/fec_packet - 1, 2200 ProcessFecPacket(fec_packet, fec_packet - 1, true, !kEntropyFlag, NULL);
2172 true, !kEntropyFlag, NULL);
2173 // Connection id length in the revived header should be the same as 2201 // Connection id length in the revived header should be the same as
2174 // in the original data/fec packet headers. 2202 // in the original data/fec packet headers.
2175 EXPECT_EQ(connection_id_length_, 2203 EXPECT_EQ(connection_id_length_,
2176 fec_visitor->revived_header().public_header.connection_id_length); 2204 fec_visitor->revived_header().public_header.connection_id_length);
2177 } 2205 }
2178 } 2206 }
2179 2207
2180 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPacketThenFecPacket) { 2208 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPacketThenFecPacket) {
2181 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2209 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2182 2210
(...skipping 1805 matching lines...) Expand 10 before | Expand all | Expand 10 after
3988 QuicBlockedFrame blocked; 4016 QuicBlockedFrame blocked;
3989 blocked.stream_id = 3; 4017 blocked.stream_id = 3;
3990 EXPECT_CALL(visitor_, OnBlockedFrames(_)); 4018 EXPECT_CALL(visitor_, OnBlockedFrames(_));
3991 ProcessFramePacket(QuicFrame(&blocked)); 4019 ProcessFramePacket(QuicFrame(&blocked));
3992 EXPECT_TRUE(ack_alarm->IsSet()); 4020 EXPECT_TRUE(ack_alarm->IsSet());
3993 } 4021 }
3994 4022
3995 } // namespace 4023 } // namespace
3996 } // namespace test 4024 } // namespace test
3997 } // namespace net 4025 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection.cc ('k') | net/quic/quic_data_stream_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698