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

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

Issue 326403006: Enables PacketGenerator's use of PacketCreator's FEC primitives. (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/net.gypi ('k') | net/quic/quic_packet_creator.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"
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"
25 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" 26 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h"
26 #include "net/quic/test_tools/quic_test_utils.h" 27 #include "net/quic/test_tools/quic_test_utils.h"
27 #include "net/quic/test_tools/simple_quic_framer.h" 28 #include "net/quic/test_tools/simple_quic_framer.h"
28 #include "testing/gmock/include/gmock/gmock.h" 29 #include "testing/gmock/include/gmock/gmock.h"
29 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
30 31
31 using base::StringPiece; 32 using base::StringPiece;
32 using std::map; 33 using std::map;
33 using std::vector; 34 using std::vector;
34 using testing::AnyNumber; 35 using testing::AnyNumber;
(...skipping 1418 matching lines...) Expand 10 before | Expand all | Expand 10 after
1453 // packet length. The size of the offset field in a stream frame is 0 for 1454 // packet length. The size of the offset field in a stream frame is 0 for
1454 // offset 0, and 2 for non-zero offsets up through 64K. Increase 1455 // offset 0, and 2 for non-zero offsets up through 64K. Increase
1455 // max_packet_length by 2 so that subsequent packets containing subsequent 1456 // max_packet_length by 2 so that subsequent packets containing subsequent
1456 // stream frames with non-zero offets will fit within the packet length. 1457 // stream frames with non-zero offets will fit within the packet length.
1457 size_t length = 2 + GetPacketLengthForOneStream( 1458 size_t length = 2 + GetPacketLengthForOneStream(
1458 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, 1459 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER,
1459 IN_FEC_GROUP, &payload_length); 1460 IN_FEC_GROUP, &payload_length);
1460 creator->set_max_packet_length(length); 1461 creator->set_max_packet_length(length);
1461 1462
1462 // And send FEC every two packets. 1463 // And send FEC every two packets.
1463 EXPECT_TRUE(QuicPacketCreatorPeer::SwitchFecProtectionOn(creator, 2)); 1464 QuicPacketGeneratorPeer::SwitchFecProtectionOn(
1465 QuicConnectionPeer::GetPacketGenerator(&connection_), 2);
1464 1466
1465 // Send 4 data packets and 2 FEC packets. 1467 // Send 4 data packets and 2 FEC packets.
1466 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); 1468 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6);
1467 // The first stream frame will have 2 fewer overhead bytes than the other 3. 1469 // The first stream frame will have 2 fewer overhead bytes than the other 3.
1468 const string payload(payload_length * 4 + 2, 'a'); 1470 const string payload(payload_length * 4 + 2, 'a');
1469 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL); 1471 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL);
1470 // Expect the FEC group to be closed after SendStreamDataWithString. 1472 // Expect the FEC group to be closed after SendStreamDataWithString.
1471 EXPECT_FALSE(creator->ShouldSendFec(true)); 1473 EXPECT_FALSE(creator->ShouldSendFec(true));
1472 EXPECT_TRUE(creator->IsFecProtected()); 1474 EXPECT_TRUE(creator->IsFecProtected());
1473 } 1475 }
1474 1476
1475 TEST_P(QuicConnectionTest, FECQueueing) { 1477 TEST_P(QuicConnectionTest, FECQueueing) {
1476 // All packets carry version info till version is negotiated. 1478 // All packets carry version info till version is negotiated.
1477 size_t payload_length; 1479 size_t payload_length;
1478 QuicPacketCreator* creator = 1480 QuicPacketCreator* creator =
1479 QuicConnectionPeer::GetPacketCreator(&connection_); 1481 QuicConnectionPeer::GetPacketCreator(&connection_);
1480 size_t length = GetPacketLengthForOneStream( 1482 size_t length = GetPacketLengthForOneStream(
1481 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, 1483 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER,
1482 IN_FEC_GROUP, &payload_length); 1484 IN_FEC_GROUP, &payload_length);
1483 creator->set_max_packet_length(length); 1485 creator->set_max_packet_length(length);
1484 // And send FEC every two packets. 1486 // And send FEC every two packets.
1485 EXPECT_TRUE(QuicPacketCreatorPeer::SwitchFecProtectionOn(creator, 2)); 1487 QuicPacketGeneratorPeer::SwitchFecProtectionOn(
1488 QuicConnectionPeer::GetPacketGenerator(&connection_), 1);
1486 1489
1487 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1490 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1488 BlockOnNextWrite(); 1491 BlockOnNextWrite();
1489 const string payload(payload_length, 'a'); 1492 const string payload(payload_length, 'a');
1490 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL); 1493 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL);
1491 EXPECT_FALSE(creator->ShouldSendFec(true)); 1494 EXPECT_FALSE(creator->ShouldSendFec(true));
1492 EXPECT_TRUE(creator->IsFecProtected()); 1495 EXPECT_TRUE(creator->IsFecProtected());
1493 // Expect the first data packet and the fec packet to be queued. 1496 // Expect the first data packet and the fec packet to be queued.
1494 EXPECT_EQ(2u, connection_.NumQueuedPackets()); 1497 EXPECT_EQ(2u, connection_.NumQueuedPackets());
1495 } 1498 }
1496 1499
1497 TEST_P(QuicConnectionTest, AbandonFECFromCongestionWindow) { 1500 TEST_P(QuicConnectionTest, AbandonFECFromCongestionWindow) {
1498 EXPECT_TRUE(QuicPacketCreatorPeer::SwitchFecProtectionOn( 1501 QuicPacketGeneratorPeer::SwitchFecProtectionOn(
1499 QuicConnectionPeer::GetPacketCreator(&connection_), 1)); 1502 QuicConnectionPeer::GetPacketGenerator(&connection_), 1);
1500 1503
1501 // 1 Data and 1 FEC packet. 1504 // 1 Data and 1 FEC packet.
1502 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); 1505 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
1503 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); 1506 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL);
1504 1507
1505 const QuicTime::Delta retransmission_time = 1508 const QuicTime::Delta retransmission_time =
1506 QuicTime::Delta::FromMilliseconds(5000); 1509 QuicTime::Delta::FromMilliseconds(5000);
1507 clock_.AdvanceTime(retransmission_time); 1510 clock_.AdvanceTime(retransmission_time);
1508 1511
1509 // Abandon FEC packet and data packet. 1512 // Abandon FEC packet and data packet.
1510 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 1513 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
1511 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 1514 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
1512 EXPECT_CALL(visitor_, OnCanWrite()); 1515 EXPECT_CALL(visitor_, OnCanWrite());
1513 connection_.OnRetransmissionTimeout(); 1516 connection_.OnRetransmissionTimeout();
1514 } 1517 }
1515 1518
1516 TEST_P(QuicConnectionTest, DontAbandonAckedFEC) { 1519 TEST_P(QuicConnectionTest, DontAbandonAckedFEC) {
1517 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1520 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1518 EXPECT_TRUE(QuicPacketCreatorPeer::SwitchFecProtectionOn( 1521 QuicPacketGeneratorPeer::SwitchFecProtectionOn(
1519 QuicConnectionPeer::GetPacketCreator(&connection_), 1)); 1522 QuicConnectionPeer::GetPacketGenerator(&connection_), 1);
1520 1523
1521 // 1 Data and 1 FEC packet. 1524 // 1 Data and 1 FEC packet.
1522 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); 1525 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6);
1523 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); 1526 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL);
1524 // Send some more data afterwards to ensure early retransmit doesn't trigger. 1527 // Send some more data afterwards to ensure early retransmit doesn't trigger.
1525 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL); 1528 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL);
1526 connection_.SendStreamDataWithString(3, "foo", 6, !kFin, NULL); 1529 connection_.SendStreamDataWithString(3, "foo", 6, !kFin, NULL);
1527 1530
1528 QuicAckFrame ack_fec = InitAckFrame(2, 1); 1531 QuicAckFrame ack_fec = InitAckFrame(2, 1);
1529 // Data packet missing. 1532 // Data packet missing.
1530 // TODO(ianswett): Note that this is not a sensible ack, since if the FEC was 1533 // TODO(ianswett): Note that this is not a sensible ack, since if the FEC was
1531 // received, it would cause the covered packet to be acked as well. 1534 // received, it would cause the covered packet to be acked as well.
1532 NackPacket(1, &ack_fec); 1535 NackPacket(1, &ack_fec);
1533 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 1536 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
1534 ProcessAckPacket(&ack_fec); 1537 ProcessAckPacket(&ack_fec);
1535 clock_.AdvanceTime(DefaultRetransmissionTime()); 1538 clock_.AdvanceTime(DefaultRetransmissionTime());
1536 1539
1537 // Don't abandon the acked FEC packet, but it will abandon 2 the subsequent 1540 // Don't abandon the acked FEC packet, but it will abandon 2 the subsequent
1538 // FEC packets. 1541 // FEC packets.
1539 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 1542 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
1540 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3); 1543 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3);
1541 connection_.GetRetransmissionAlarm()->Fire(); 1544 connection_.GetRetransmissionAlarm()->Fire();
1542 } 1545 }
1543 1546
1544 TEST_P(QuicConnectionTest, AbandonAllFEC) { 1547 TEST_P(QuicConnectionTest, AbandonAllFEC) {
1545 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1548 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1546 EXPECT_TRUE(QuicPacketCreatorPeer::SwitchFecProtectionOn( 1549 QuicPacketGeneratorPeer::SwitchFecProtectionOn(
1547 QuicConnectionPeer::GetPacketCreator(&connection_), 1)); 1550 QuicConnectionPeer::GetPacketGenerator(&connection_), 1);
1548 1551
1549 // 1 Data and 1 FEC packet. 1552 // 1 Data and 1 FEC packet.
1550 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); 1553 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6);
1551 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); 1554 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL);
1552 // 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.
1553 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL); 1556 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL);
1554 // Advance the time so not all the FEC packets are abandoned. 1557 // Advance the time so not all the FEC packets are abandoned.
1555 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); 1558 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1));
1556 connection_.SendStreamDataWithString(3, "foo", 6, !kFin, NULL); 1559 connection_.SendStreamDataWithString(3, "foo", 6, !kFin, NULL);
1557 1560
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1653 EXPECT_FALSE(connection_.HasQueuedData()); 1656 EXPECT_FALSE(connection_.HasQueuedData());
1654 1657
1655 // Parse the last packet and ensure it's the stream frame from stream 3. 1658 // Parse the last packet and ensure it's the stream frame from stream 3.
1656 EXPECT_EQ(1u, writer_->frame_count()); 1659 EXPECT_EQ(1u, writer_->frame_count());
1657 ASSERT_EQ(1u, writer_->stream_frames().size()); 1660 ASSERT_EQ(1u, writer_->stream_frames().size());
1658 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0].stream_id); 1661 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0].stream_id);
1659 } 1662 }
1660 1663
1661 TEST_P(QuicConnectionTest, FramePackingFEC) { 1664 TEST_P(QuicConnectionTest, FramePackingFEC) {
1662 // Enable fec. 1665 // Enable fec.
1663 EXPECT_TRUE(QuicPacketCreatorPeer::SwitchFecProtectionOn( 1666 QuicPacketGeneratorPeer::SwitchFecProtectionOn(
1664 QuicConnectionPeer::GetPacketCreator(&connection_), 6)); 1667 QuicConnectionPeer::GetPacketGenerator(&connection_), 6);
1665 1668
1666 CongestionBlockWrites(); 1669 CongestionBlockWrites();
1667 1670
1668 // Send an ack and two stream frames in 1 packet by queueing them. 1671 // Send an ack and two stream frames in 1 packet by queueing them.
1669 connection_.SendAck(); 1672 connection_.SendAck();
1670 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( 1673 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll(
1671 IgnoreResult(InvokeWithoutArgs(&connection_, 1674 IgnoreResult(InvokeWithoutArgs(&connection_,
1672 &TestConnection::SendStreamData3)), 1675 &TestConnection::SendStreamData3)),
1673 IgnoreResult(InvokeWithoutArgs(&connection_, 1676 IgnoreResult(InvokeWithoutArgs(&connection_,
1674 &TestConnection::SendStreamData5)))); 1677 &TestConnection::SendStreamData5))));
(...skipping 2289 matching lines...) Expand 10 before | Expand all | Expand 10 after
3964 QuicBlockedFrame blocked; 3967 QuicBlockedFrame blocked;
3965 blocked.stream_id = 3; 3968 blocked.stream_id = 3;
3966 EXPECT_CALL(visitor_, OnBlockedFrames(_)); 3969 EXPECT_CALL(visitor_, OnBlockedFrames(_));
3967 ProcessFramePacket(QuicFrame(&blocked)); 3970 ProcessFramePacket(QuicFrame(&blocked));
3968 EXPECT_TRUE(ack_alarm->IsSet()); 3971 EXPECT_TRUE(ack_alarm->IsSet());
3969 } 3972 }
3970 3973
3971 } // namespace 3974 } // namespace
3972 } // namespace test 3975 } // namespace test
3973 } // namespace net 3976 } // namespace net
OLDNEW
« no previous file with comments | « net/net.gypi ('k') | net/quic/quic_packet_creator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698