OLD | NEW |
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 1423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1434 } | 1434 } |
1435 | 1435 |
1436 TEST_P(QuicConnectionTest, FECSending) { | 1436 TEST_P(QuicConnectionTest, FECSending) { |
1437 // All packets carry version info till version is negotiated. | 1437 // All packets carry version info till version is negotiated. |
1438 size_t payload_length; | 1438 size_t payload_length; |
1439 connection_.options()->max_packet_length = | 1439 connection_.options()->max_packet_length = |
1440 GetPacketLengthForOneStream( | 1440 GetPacketLengthForOneStream( |
1441 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, | 1441 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, |
1442 IN_FEC_GROUP, &payload_length); | 1442 IN_FEC_GROUP, &payload_length); |
1443 // And send FEC every two packets. | 1443 // And send FEC every two packets. |
1444 connection_.options()->max_packets_per_fec_group = 2; | 1444 EXPECT_TRUE(QuicPacketCreatorPeer::SwitchFecProtectionOn( |
| 1445 QuicConnectionPeer::GetPacketCreator(&connection_), 2)); |
1445 | 1446 |
1446 // Send 4 data packets and 2 FEC packets. | 1447 // Send 4 data packets and 2 FEC packets. |
1447 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); | 1448 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); |
1448 // The first stream frame will consume 2 fewer bytes than the other three. | 1449 // The first stream frame will consume 2 fewer bytes than the other three. |
1449 const string payload(payload_length * 4 - 6, 'a'); | 1450 const string payload(payload_length * 4 - 6, 'a'); |
1450 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL); | 1451 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL); |
1451 // Expect the FEC group to be closed after SendStreamDataWithString. | 1452 // Expect the FEC group to be closed after SendStreamDataWithString. |
1452 EXPECT_FALSE(creator_.ShouldSendFec(true)); | 1453 EXPECT_FALSE(creator_.ShouldSendFec(true)); |
1453 } | 1454 } |
1454 | 1455 |
1455 TEST_P(QuicConnectionTest, FECQueueing) { | 1456 TEST_P(QuicConnectionTest, FECQueueing) { |
1456 // All packets carry version info till version is negotiated. | 1457 // All packets carry version info till version is negotiated. |
1457 size_t payload_length; | 1458 size_t payload_length; |
1458 connection_.options()->max_packet_length = | 1459 connection_.options()->max_packet_length = |
1459 GetPacketLengthForOneStream( | 1460 GetPacketLengthForOneStream( |
1460 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, | 1461 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, |
1461 IN_FEC_GROUP, &payload_length); | 1462 IN_FEC_GROUP, &payload_length); |
1462 // And send FEC every two packets. | 1463 // And send FEC every two packets. |
1463 connection_.options()->max_packets_per_fec_group = 2; | 1464 EXPECT_TRUE(QuicPacketCreatorPeer::SwitchFecProtectionOn( |
| 1465 QuicConnectionPeer::GetPacketCreator(&connection_), 2)); |
1464 | 1466 |
1465 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1467 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
1466 BlockOnNextWrite(); | 1468 BlockOnNextWrite(); |
1467 const string payload(payload_length, 'a'); | 1469 const string payload(payload_length, 'a'); |
1468 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL); | 1470 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL); |
1469 EXPECT_FALSE(creator_.ShouldSendFec(true)); | 1471 EXPECT_FALSE(creator_.ShouldSendFec(true)); |
1470 // Expect the first data packet and the fec packet to be queued. | 1472 // Expect the first data packet and the fec packet to be queued. |
1471 EXPECT_EQ(2u, connection_.NumQueuedPackets()); | 1473 EXPECT_EQ(2u, connection_.NumQueuedPackets()); |
1472 } | 1474 } |
1473 | 1475 |
1474 TEST_P(QuicConnectionTest, AbandonFECFromCongestionWindow) { | 1476 TEST_P(QuicConnectionTest, AbandonFECFromCongestionWindow) { |
1475 connection_.options()->max_packets_per_fec_group = 1; | 1477 EXPECT_TRUE(QuicPacketCreatorPeer::SwitchFecProtectionOn( |
| 1478 QuicConnectionPeer::GetPacketCreator(&connection_), 1)); |
| 1479 |
1476 // 1 Data and 1 FEC packet. | 1480 // 1 Data and 1 FEC packet. |
1477 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); | 1481 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); |
1478 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); | 1482 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); |
1479 | 1483 |
1480 const QuicTime::Delta retransmission_time = | 1484 const QuicTime::Delta retransmission_time = |
1481 QuicTime::Delta::FromMilliseconds(5000); | 1485 QuicTime::Delta::FromMilliseconds(5000); |
1482 clock_.AdvanceTime(retransmission_time); | 1486 clock_.AdvanceTime(retransmission_time); |
1483 | 1487 |
1484 // Abandon FEC packet and data packet. | 1488 // Abandon FEC packet and data packet. |
1485 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); | 1489 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
1486 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 1490 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
1487 EXPECT_CALL(visitor_, OnCanWrite()); | 1491 EXPECT_CALL(visitor_, OnCanWrite()); |
1488 connection_.OnRetransmissionTimeout(); | 1492 connection_.OnRetransmissionTimeout(); |
1489 } | 1493 } |
1490 | 1494 |
1491 TEST_P(QuicConnectionTest, DontAbandonAckedFEC) { | 1495 TEST_P(QuicConnectionTest, DontAbandonAckedFEC) { |
1492 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1496 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
1493 connection_.options()->max_packets_per_fec_group = 1; | 1497 EXPECT_TRUE(QuicPacketCreatorPeer::SwitchFecProtectionOn( |
| 1498 QuicConnectionPeer::GetPacketCreator(&connection_), 1)); |
1494 | 1499 |
1495 // 1 Data and 1 FEC packet. | 1500 // 1 Data and 1 FEC packet. |
1496 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); | 1501 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); |
1497 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); | 1502 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); |
1498 // Send some more data afterwards to ensure early retransmit doesn't trigger. | 1503 // Send some more data afterwards to ensure early retransmit doesn't trigger. |
1499 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL); | 1504 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL); |
1500 connection_.SendStreamDataWithString(3, "foo", 6, !kFin, NULL); | 1505 connection_.SendStreamDataWithString(3, "foo", 6, !kFin, NULL); |
1501 | 1506 |
1502 QuicAckFrame ack_fec = InitAckFrame(2, 1); | 1507 QuicAckFrame ack_fec = InitAckFrame(2, 1); |
1503 // Data packet missing. | 1508 // Data packet missing. |
1504 // TODO(ianswett): Note that this is not a sensible ack, since if the FEC was | 1509 // TODO(ianswett): Note that this is not a sensible ack, since if the FEC was |
1505 // received, it would cause the covered packet to be acked as well. | 1510 // received, it would cause the covered packet to be acked as well. |
1506 NackPacket(1, &ack_fec); | 1511 NackPacket(1, &ack_fec); |
1507 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 1512 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
1508 ProcessAckPacket(&ack_fec); | 1513 ProcessAckPacket(&ack_fec); |
1509 clock_.AdvanceTime(DefaultRetransmissionTime()); | 1514 clock_.AdvanceTime(DefaultRetransmissionTime()); |
1510 | 1515 |
1511 // Don't abandon the acked FEC packet, but it will abandon 2 the subsequent | 1516 // Don't abandon the acked FEC packet, but it will abandon 2 the subsequent |
1512 // FEC packets. | 1517 // FEC packets. |
1513 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); | 1518 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
1514 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3); | 1519 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3); |
1515 connection_.GetRetransmissionAlarm()->Fire(); | 1520 connection_.GetRetransmissionAlarm()->Fire(); |
1516 } | 1521 } |
1517 | 1522 |
1518 TEST_P(QuicConnectionTest, AbandonAllFEC) { | 1523 TEST_P(QuicConnectionTest, AbandonAllFEC) { |
1519 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1524 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
1520 connection_.options()->max_packets_per_fec_group = 1; | 1525 EXPECT_TRUE(QuicPacketCreatorPeer::SwitchFecProtectionOn( |
| 1526 QuicConnectionPeer::GetPacketCreator(&connection_), 1)); |
1521 | 1527 |
1522 // 1 Data and 1 FEC packet. | 1528 // 1 Data and 1 FEC packet. |
1523 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); | 1529 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); |
1524 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); | 1530 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); |
1525 // Send some more data afterwards to ensure early retransmit doesn't trigger. | 1531 // Send some more data afterwards to ensure early retransmit doesn't trigger. |
1526 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL); | 1532 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL); |
1527 // Advance the time so not all the FEC packets are abandoned. | 1533 // Advance the time so not all the FEC packets are abandoned. |
1528 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); | 1534 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); |
1529 connection_.SendStreamDataWithString(3, "foo", 6, !kFin, NULL); | 1535 connection_.SendStreamDataWithString(3, "foo", 6, !kFin, NULL); |
1530 | 1536 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1635 EXPECT_EQ(1u, writer_->frame_count()); | 1641 EXPECT_EQ(1u, writer_->frame_count()); |
1636 EXPECT_EQ(1u, writer_->stream_frames().size()); | 1642 EXPECT_EQ(1u, writer_->stream_frames().size()); |
1637 EXPECT_EQ(kStreamId3, writer_->stream_frames()[0].stream_id); | 1643 EXPECT_EQ(kStreamId3, writer_->stream_frames()[0].stream_id); |
1638 } | 1644 } |
1639 | 1645 |
1640 TEST_P(QuicConnectionTest, FramePackingFEC) { | 1646 TEST_P(QuicConnectionTest, FramePackingFEC) { |
1641 if (version() < QUIC_VERSION_15) { | 1647 if (version() < QUIC_VERSION_15) { |
1642 return; | 1648 return; |
1643 } | 1649 } |
1644 // Enable fec. | 1650 // Enable fec. |
1645 connection_.options()->max_packets_per_fec_group = 6; | 1651 EXPECT_TRUE(QuicPacketCreatorPeer::SwitchFecProtectionOn( |
| 1652 QuicConnectionPeer::GetPacketCreator(&connection_), 6)); |
| 1653 |
1646 // Block the connection. | 1654 // Block the connection. |
1647 connection_.GetSendAlarm()->Set( | 1655 connection_.GetSendAlarm()->Set( |
1648 clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(1))); | 1656 clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(1))); |
1649 | 1657 |
1650 // Send an ack and two stream frames in 1 packet by queueing them. | 1658 // Send an ack and two stream frames in 1 packet by queueing them. |
1651 connection_.SendAck(); | 1659 connection_.SendAck(); |
1652 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( | 1660 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( |
1653 IgnoreResult(InvokeWithoutArgs(&connection_, | 1661 IgnoreResult(InvokeWithoutArgs(&connection_, |
1654 &TestConnection::SendStreamData3)), | 1662 &TestConnection::SendStreamData3)), |
1655 IgnoreResult(InvokeWithoutArgs(&connection_, | 1663 IgnoreResult(InvokeWithoutArgs(&connection_, |
(...skipping 2315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3971 QuicBlockedFrame blocked; | 3979 QuicBlockedFrame blocked; |
3972 blocked.stream_id = 3; | 3980 blocked.stream_id = 3; |
3973 EXPECT_CALL(visitor_, OnBlockedFrames(_)); | 3981 EXPECT_CALL(visitor_, OnBlockedFrames(_)); |
3974 ProcessFramePacket(QuicFrame(&blocked)); | 3982 ProcessFramePacket(QuicFrame(&blocked)); |
3975 EXPECT_TRUE(ack_alarm->IsSet()); | 3983 EXPECT_TRUE(ack_alarm->IsSet()); |
3976 } | 3984 } |
3977 | 3985 |
3978 } // namespace | 3986 } // namespace |
3979 } // namespace test | 3987 } // namespace test |
3980 } // namespace net | 3988 } // namespace net |
OLD | NEW |