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

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

Issue 351133002: Adds an internal server and chromium's flag for disabling/enabling FEC (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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_config_test.cc ('k') | net/quic/quic_flags.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/quic/quic_connection.h" 5 #include "net/quic/quic_connection.h"
6 6
7 #include "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"
(...skipping 1466 matching lines...) Expand 10 before | Expand all | Expand 10 after
1477 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining 1477 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining
1478 // packet length. The size of the offset field in a stream frame is 0 for 1478 // packet length. The size of the offset field in a stream frame is 0 for
1479 // offset 0, and 2 for non-zero offsets up through 64K. Increase 1479 // offset 0, and 2 for non-zero offsets up through 64K. Increase
1480 // max_packet_length by 2 so that subsequent packets containing subsequent 1480 // max_packet_length by 2 so that subsequent packets containing subsequent
1481 // stream frames with non-zero offets will fit within the packet length. 1481 // stream frames with non-zero offets will fit within the packet length.
1482 size_t length = 2 + GetPacketLengthForOneStream( 1482 size_t length = 2 + GetPacketLengthForOneStream(
1483 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, 1483 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER,
1484 IN_FEC_GROUP, &payload_length); 1484 IN_FEC_GROUP, &payload_length);
1485 creator->set_max_packet_length(length); 1485 creator->set_max_packet_length(length);
1486 1486
1487 // Enable FEC. 1487 // Send 4 protected data packets, which should also trigger 1 FEC packet.
1488 creator->set_max_packets_per_fec_group(2); 1488 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(5);
1489
1490 // Send 4 protected data packets, which will also trigger 2 FEC packets.
1491 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6);
1492 // The first stream frame will have 2 fewer overhead bytes than the other 3. 1489 // The first stream frame will have 2 fewer overhead bytes than the other 3.
1493 const string payload(payload_length * 4 + 2, 'a'); 1490 const string payload(payload_length * 4 + 2, 'a');
1494 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, NULL); 1491 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, NULL);
1495 // Expect the FEC group to be closed after SendStreamDataWithString. 1492 // Expect the FEC group to be closed after SendStreamDataWithString.
1496 EXPECT_FALSE(creator->IsFecGroupOpen()); 1493 EXPECT_FALSE(creator->IsFecGroupOpen());
1497 EXPECT_FALSE(creator->IsFecProtected()); 1494 EXPECT_FALSE(creator->IsFecProtected());
1498 } 1495 }
1499 1496
1500 TEST_P(QuicConnectionTest, FECQueueing) { 1497 TEST_P(QuicConnectionTest, FECQueueing) {
1501 // All packets carry version info till version is negotiated. 1498 // All packets carry version info till version is negotiated.
1502 size_t payload_length; 1499 size_t payload_length;
1503 QuicPacketCreator* creator = 1500 QuicPacketCreator* creator =
1504 QuicConnectionPeer::GetPacketCreator(&connection_); 1501 QuicConnectionPeer::GetPacketCreator(&connection_);
1505 size_t length = GetPacketLengthForOneStream( 1502 size_t length = GetPacketLengthForOneStream(
1506 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, 1503 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER,
1507 IN_FEC_GROUP, &payload_length); 1504 IN_FEC_GROUP, &payload_length);
1508 creator->set_max_packet_length(length); 1505 creator->set_max_packet_length(length);
1509 // Enable FEC. 1506 EXPECT_TRUE(creator->IsFecEnabled());
1510 creator->set_max_packets_per_fec_group(1);
1511 1507
1512 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1508 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1513 BlockOnNextWrite(); 1509 BlockOnNextWrite();
1514 const string payload(payload_length, 'a'); 1510 const string payload(payload_length, 'a');
1515 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, NULL); 1511 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, NULL);
1516 EXPECT_FALSE(creator->IsFecGroupOpen()); 1512 EXPECT_FALSE(creator->IsFecGroupOpen());
1517 EXPECT_FALSE(creator->IsFecProtected()); 1513 EXPECT_FALSE(creator->IsFecProtected());
1518 // Expect the first data packet and the fec packet to be queued. 1514 // Expect the first data packet and the fec packet to be queued.
1519 EXPECT_EQ(2u, connection_.NumQueuedPackets()); 1515 EXPECT_EQ(2u, connection_.NumQueuedPackets());
1520 } 1516 }
1521 1517
1522 TEST_P(QuicConnectionTest, AbandonFECFromCongestionWindow) { 1518 TEST_P(QuicConnectionTest, AbandonFECFromCongestionWindow) {
1523 // Enable FEC. 1519 EXPECT_TRUE(QuicConnectionPeer::GetPacketCreator(
1524 QuicConnectionPeer::GetPacketCreator( 1520 &connection_)->IsFecEnabled());
1525 &connection_)->set_max_packets_per_fec_group(1);
1526 1521
1527 // 1 Data and 1 FEC packet. 1522 // 1 Data and 1 FEC packet.
1528 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); 1523 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
1529 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, NULL); 1524 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, NULL);
1530 1525
1531 const QuicTime::Delta retransmission_time = 1526 const QuicTime::Delta retransmission_time =
1532 QuicTime::Delta::FromMilliseconds(5000); 1527 QuicTime::Delta::FromMilliseconds(5000);
1533 clock_.AdvanceTime(retransmission_time); 1528 clock_.AdvanceTime(retransmission_time);
1534 1529
1535 // Abandon FEC packet and data packet. 1530 // Abandon FEC packet and data packet.
1536 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 1531 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
1537 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 1532 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
1538 EXPECT_CALL(visitor_, OnCanWrite()); 1533 EXPECT_CALL(visitor_, OnCanWrite());
1539 connection_.OnRetransmissionTimeout(); 1534 connection_.OnRetransmissionTimeout();
1540 } 1535 }
1541 1536
1542 TEST_P(QuicConnectionTest, DontAbandonAckedFEC) { 1537 TEST_P(QuicConnectionTest, DontAbandonAckedFEC) {
1543 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1538 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1544 // Enable FEC. 1539 EXPECT_TRUE(QuicConnectionPeer::GetPacketCreator(
1545 QuicConnectionPeer::GetPacketCreator( 1540 &connection_)->IsFecEnabled());
1546 &connection_)->set_max_packets_per_fec_group(1);
1547 1541
1548 // 1 Data and 1 FEC packet. 1542 // 1 Data and 1 FEC packet.
1549 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); 1543 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6);
1550 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, NULL); 1544 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, NULL);
1551 // Send some more data afterwards to ensure early retransmit doesn't trigger. 1545 // Send some more data afterwards to ensure early retransmit doesn't trigger.
1552 connection_.SendStreamDataWithStringWithFec(3, "foo", 3, !kFin, NULL); 1546 connection_.SendStreamDataWithStringWithFec(3, "foo", 3, !kFin, NULL);
1553 connection_.SendStreamDataWithStringWithFec(3, "foo", 6, !kFin, NULL); 1547 connection_.SendStreamDataWithStringWithFec(3, "foo", 6, !kFin, NULL);
1554 1548
1555 QuicAckFrame ack_fec = InitAckFrame(2, 1); 1549 QuicAckFrame ack_fec = InitAckFrame(2, 1);
1556 // Data packet missing. 1550 // Data packet missing.
1557 // TODO(ianswett): Note that this is not a sensible ack, since if the FEC was 1551 // TODO(ianswett): Note that this is not a sensible ack, since if the FEC was
1558 // received, it would cause the covered packet to be acked as well. 1552 // received, it would cause the covered packet to be acked as well.
1559 NackPacket(1, &ack_fec); 1553 NackPacket(1, &ack_fec);
1560 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 1554 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
1561 ProcessAckPacket(&ack_fec); 1555 ProcessAckPacket(&ack_fec);
1562 clock_.AdvanceTime(DefaultRetransmissionTime()); 1556 clock_.AdvanceTime(DefaultRetransmissionTime());
1563 1557
1564 // Don't abandon the acked FEC packet, but it will abandon 2 the subsequent 1558 // Don't abandon the acked FEC packet, but it will abandon 2 the subsequent
1565 // FEC packets. 1559 // FEC packets.
1566 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 1560 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
1567 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3); 1561 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3);
1568 connection_.GetRetransmissionAlarm()->Fire(); 1562 connection_.GetRetransmissionAlarm()->Fire();
1569 } 1563 }
1570 1564
1571 TEST_P(QuicConnectionTest, AbandonAllFEC) { 1565 TEST_P(QuicConnectionTest, AbandonAllFEC) {
1572 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1566 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1573 // Enable FEC. 1567 EXPECT_TRUE(QuicConnectionPeer::GetPacketCreator(
1574 QuicConnectionPeer::GetPacketCreator( 1568 &connection_)->IsFecEnabled());
1575 &connection_)->set_max_packets_per_fec_group(1);
1576 1569
1577 // 1 Data and 1 FEC packet. 1570 // 1 Data and 1 FEC packet.
1578 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); 1571 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6);
1579 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, NULL); 1572 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, NULL);
1580 // Send some more data afterwards to ensure early retransmit doesn't trigger. 1573 // Send some more data afterwards to ensure early retransmit doesn't trigger.
1581 connection_.SendStreamDataWithStringWithFec(3, "foo", 3, !kFin, NULL); 1574 connection_.SendStreamDataWithStringWithFec(3, "foo", 3, !kFin, NULL);
1582 // Advance the time so not all the FEC packets are abandoned. 1575 // Advance the time so not all the FEC packets are abandoned.
1583 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); 1576 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1));
1584 connection_.SendStreamDataWithStringWithFec(3, "foo", 6, !kFin, NULL); 1577 connection_.SendStreamDataWithStringWithFec(3, "foo", 6, !kFin, NULL);
1585 1578
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1680 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1673 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1681 EXPECT_FALSE(connection_.HasQueuedData()); 1674 EXPECT_FALSE(connection_.HasQueuedData());
1682 1675
1683 // Parse the last packet and ensure it's the stream frame from stream 3. 1676 // Parse the last packet and ensure it's the stream frame from stream 3.
1684 EXPECT_EQ(1u, writer_->frame_count()); 1677 EXPECT_EQ(1u, writer_->frame_count());
1685 ASSERT_EQ(1u, writer_->stream_frames().size()); 1678 ASSERT_EQ(1u, writer_->stream_frames().size());
1686 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0].stream_id); 1679 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0].stream_id);
1687 } 1680 }
1688 1681
1689 TEST_P(QuicConnectionTest, FramePackingFEC) { 1682 TEST_P(QuicConnectionTest, FramePackingFEC) {
1690 // Enable FEC. 1683 EXPECT_TRUE(QuicConnectionPeer::GetPacketCreator(
1691 QuicConnectionPeer::GetPacketCreator( 1684 &connection_)->IsFecEnabled());
1692 &connection_)->set_max_packets_per_fec_group(6);
1693 1685
1694 CongestionBlockWrites(); 1686 CongestionBlockWrites();
1695 1687
1696 // Queue an ack and two stream frames. Ack gets flushed when FEC is turned on 1688 // Queue an ack and two stream frames. Ack gets flushed when FEC is turned on
1697 // for sending protected data; two stream frames are packing in 1 packet. 1689 // for sending protected data; two stream frames are packing in 1 packet.
1698 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( 1690 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll(
1699 IgnoreResult(InvokeWithoutArgs( 1691 IgnoreResult(InvokeWithoutArgs(
1700 &connection_, &TestConnection::SendStreamData3WithFec)), 1692 &connection_, &TestConnection::SendStreamData3WithFec)),
1701 IgnoreResult(InvokeWithoutArgs( 1693 IgnoreResult(InvokeWithoutArgs(
1702 &connection_, &TestConnection::SendStreamData5WithFec)))); 1694 &connection_, &TestConnection::SendStreamData5WithFec))));
(...skipping 2331 matching lines...) Expand 10 before | Expand all | Expand 10 after
4034 QuicBlockedFrame blocked; 4026 QuicBlockedFrame blocked;
4035 blocked.stream_id = 3; 4027 blocked.stream_id = 3;
4036 EXPECT_CALL(visitor_, OnBlockedFrames(_)); 4028 EXPECT_CALL(visitor_, OnBlockedFrames(_));
4037 ProcessFramePacket(QuicFrame(&blocked)); 4029 ProcessFramePacket(QuicFrame(&blocked));
4038 EXPECT_TRUE(ack_alarm->IsSet()); 4030 EXPECT_TRUE(ack_alarm->IsSet());
4039 } 4031 }
4040 4032
4041 } // namespace 4033 } // namespace
4042 } // namespace test 4034 } // namespace test
4043 } // namespace net 4035 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_config_test.cc ('k') | net/quic/quic_flags.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698