| 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" |
| 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 Loading... |
| 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 962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1453 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining | 1483 // 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 | 1484 // 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 | 1485 // offset 0, and 2 for non-zero offsets up through 64K. Increase |
| 1456 // max_packet_length by 2 so that subsequent packets containing subsequent | 1486 // max_packet_length by 2 so that subsequent packets containing subsequent |
| 1457 // stream frames with non-zero offets will fit within the packet length. | 1487 // stream frames with non-zero offets will fit within the packet length. |
| 1458 size_t length = 2 + GetPacketLengthForOneStream( | 1488 size_t length = 2 + GetPacketLengthForOneStream( |
| 1459 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, | 1489 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, |
| 1460 IN_FEC_GROUP, &payload_length); | 1490 IN_FEC_GROUP, &payload_length); |
| 1461 creator->set_max_packet_length(length); | 1491 creator->set_max_packet_length(length); |
| 1462 | 1492 |
| 1463 // And send FEC every two packets. | 1493 // Enable FEC. |
| 1464 QuicPacketGeneratorPeer::SwitchFecProtectionOn( | 1494 creator->set_max_packets_per_fec_group(2); |
| 1465 QuicConnectionPeer::GetPacketGenerator(&connection_), 2); | |
| 1466 | 1495 |
| 1467 // Send 4 data packets and 2 FEC packets. | 1496 // Send 4 protected data packets, which will also trigger 2 FEC packets. |
| 1468 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); | 1497 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); |
| 1469 // The first stream frame will have 2 fewer overhead bytes than the other 3. | 1498 // The first stream frame will have 2 fewer overhead bytes than the other 3. |
| 1470 const string payload(payload_length * 4 + 2, 'a'); | 1499 const string payload(payload_length * 4 + 2, 'a'); |
| 1471 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL); | 1500 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, NULL); |
| 1472 // Expect the FEC group to be closed after SendStreamDataWithString. | 1501 // Expect the FEC group to be closed after SendStreamDataWithString. |
| 1473 EXPECT_FALSE(creator->ShouldSendFec(true)); | 1502 EXPECT_FALSE(creator->IsFecGroupOpen()); |
| 1474 EXPECT_TRUE(creator->IsFecProtected()); | 1503 EXPECT_FALSE(creator->IsFecProtected()); |
| 1475 } | 1504 } |
| 1476 | 1505 |
| 1477 TEST_P(QuicConnectionTest, FECQueueing) { | 1506 TEST_P(QuicConnectionTest, FECQueueing) { |
| 1478 // All packets carry version info till version is negotiated. | 1507 // All packets carry version info till version is negotiated. |
| 1479 size_t payload_length; | 1508 size_t payload_length; |
| 1480 QuicPacketCreator* creator = | 1509 QuicPacketCreator* creator = |
| 1481 QuicConnectionPeer::GetPacketCreator(&connection_); | 1510 QuicConnectionPeer::GetPacketCreator(&connection_); |
| 1482 size_t length = GetPacketLengthForOneStream( | 1511 size_t length = GetPacketLengthForOneStream( |
| 1483 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, | 1512 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, |
| 1484 IN_FEC_GROUP, &payload_length); | 1513 IN_FEC_GROUP, &payload_length); |
| 1485 creator->set_max_packet_length(length); | 1514 creator->set_max_packet_length(length); |
| 1486 // And send FEC every two packets. | 1515 // Enable FEC. |
| 1487 QuicPacketGeneratorPeer::SwitchFecProtectionOn( | 1516 creator->set_max_packets_per_fec_group(1); |
| 1488 QuicConnectionPeer::GetPacketGenerator(&connection_), 1); | |
| 1489 | 1517 |
| 1490 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1518 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 1491 BlockOnNextWrite(); | 1519 BlockOnNextWrite(); |
| 1492 const string payload(payload_length, 'a'); | 1520 const string payload(payload_length, 'a'); |
| 1493 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL); | 1521 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, NULL); |
| 1494 EXPECT_FALSE(creator->ShouldSendFec(true)); | 1522 EXPECT_FALSE(creator->IsFecGroupOpen()); |
| 1495 EXPECT_TRUE(creator->IsFecProtected()); | 1523 EXPECT_FALSE(creator->IsFecProtected()); |
| 1496 // Expect the first data packet and the fec packet to be queued. | 1524 // Expect the first data packet and the fec packet to be queued. |
| 1497 EXPECT_EQ(2u, connection_.NumQueuedPackets()); | 1525 EXPECT_EQ(2u, connection_.NumQueuedPackets()); |
| 1498 } | 1526 } |
| 1499 | 1527 |
| 1500 TEST_P(QuicConnectionTest, AbandonFECFromCongestionWindow) { | 1528 TEST_P(QuicConnectionTest, AbandonFECFromCongestionWindow) { |
| 1501 QuicPacketGeneratorPeer::SwitchFecProtectionOn( | 1529 // Enable FEC. |
| 1502 QuicConnectionPeer::GetPacketGenerator(&connection_), 1); | 1530 QuicConnectionPeer::GetPacketCreator( |
| 1531 &connection_)->set_max_packets_per_fec_group(1); |
| 1503 | 1532 |
| 1504 // 1 Data and 1 FEC packet. | 1533 // 1 Data and 1 FEC packet. |
| 1505 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); | 1534 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); |
| 1506 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); | 1535 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, NULL); |
| 1507 | 1536 |
| 1508 const QuicTime::Delta retransmission_time = | 1537 const QuicTime::Delta retransmission_time = |
| 1509 QuicTime::Delta::FromMilliseconds(5000); | 1538 QuicTime::Delta::FromMilliseconds(5000); |
| 1510 clock_.AdvanceTime(retransmission_time); | 1539 clock_.AdvanceTime(retransmission_time); |
| 1511 | 1540 |
| 1512 // Abandon FEC packet and data packet. | 1541 // Abandon FEC packet and data packet. |
| 1513 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); | 1542 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
| 1514 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 1543 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
| 1515 EXPECT_CALL(visitor_, OnCanWrite()); | 1544 EXPECT_CALL(visitor_, OnCanWrite()); |
| 1516 connection_.OnRetransmissionTimeout(); | 1545 connection_.OnRetransmissionTimeout(); |
| 1517 } | 1546 } |
| 1518 | 1547 |
| 1519 TEST_P(QuicConnectionTest, DontAbandonAckedFEC) { | 1548 TEST_P(QuicConnectionTest, DontAbandonAckedFEC) { |
| 1520 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1549 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1521 QuicPacketGeneratorPeer::SwitchFecProtectionOn( | 1550 // Enable FEC. |
| 1522 QuicConnectionPeer::GetPacketGenerator(&connection_), 1); | 1551 QuicConnectionPeer::GetPacketCreator( |
| 1552 &connection_)->set_max_packets_per_fec_group(1); |
| 1523 | 1553 |
| 1524 // 1 Data and 1 FEC packet. | 1554 // 1 Data and 1 FEC packet. |
| 1525 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); | 1555 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); |
| 1526 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); | 1556 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, NULL); |
| 1527 // Send some more data afterwards to ensure early retransmit doesn't trigger. | 1557 // Send some more data afterwards to ensure early retransmit doesn't trigger. |
| 1528 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL); | 1558 connection_.SendStreamDataWithStringWithFec(3, "foo", 3, !kFin, NULL); |
| 1529 connection_.SendStreamDataWithString(3, "foo", 6, !kFin, NULL); | 1559 connection_.SendStreamDataWithStringWithFec(3, "foo", 6, !kFin, NULL); |
| 1530 | 1560 |
| 1531 QuicAckFrame ack_fec = InitAckFrame(2, 1); | 1561 QuicAckFrame ack_fec = InitAckFrame(2, 1); |
| 1532 // Data packet missing. | 1562 // Data packet missing. |
| 1533 // TODO(ianswett): Note that this is not a sensible ack, since if the FEC was | 1563 // 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. | 1564 // received, it would cause the covered packet to be acked as well. |
| 1535 NackPacket(1, &ack_fec); | 1565 NackPacket(1, &ack_fec); |
| 1536 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 1566 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 1537 ProcessAckPacket(&ack_fec); | 1567 ProcessAckPacket(&ack_fec); |
| 1538 clock_.AdvanceTime(DefaultRetransmissionTime()); | 1568 clock_.AdvanceTime(DefaultRetransmissionTime()); |
| 1539 | 1569 |
| 1540 // Don't abandon the acked FEC packet, but it will abandon 2 the subsequent | 1570 // Don't abandon the acked FEC packet, but it will abandon 2 the subsequent |
| 1541 // FEC packets. | 1571 // FEC packets. |
| 1542 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); | 1572 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
| 1543 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3); | 1573 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3); |
| 1544 connection_.GetRetransmissionAlarm()->Fire(); | 1574 connection_.GetRetransmissionAlarm()->Fire(); |
| 1545 } | 1575 } |
| 1546 | 1576 |
| 1547 TEST_P(QuicConnectionTest, AbandonAllFEC) { | 1577 TEST_P(QuicConnectionTest, AbandonAllFEC) { |
| 1548 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1578 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1549 QuicPacketGeneratorPeer::SwitchFecProtectionOn( | 1579 // Enable FEC. |
| 1550 QuicConnectionPeer::GetPacketGenerator(&connection_), 1); | 1580 QuicConnectionPeer::GetPacketCreator( |
| 1581 &connection_)->set_max_packets_per_fec_group(1); |
| 1551 | 1582 |
| 1552 // 1 Data and 1 FEC packet. | 1583 // 1 Data and 1 FEC packet. |
| 1553 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); | 1584 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); |
| 1554 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); | 1585 connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, NULL); |
| 1555 // Send some more data afterwards to ensure early retransmit doesn't trigger. | 1586 // Send some more data afterwards to ensure early retransmit doesn't trigger. |
| 1556 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL); | 1587 connection_.SendStreamDataWithStringWithFec(3, "foo", 3, !kFin, NULL); |
| 1557 // Advance the time so not all the FEC packets are abandoned. | 1588 // Advance the time so not all the FEC packets are abandoned. |
| 1558 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); | 1589 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); |
| 1559 connection_.SendStreamDataWithString(3, "foo", 6, !kFin, NULL); | 1590 connection_.SendStreamDataWithStringWithFec(3, "foo", 6, !kFin, NULL); |
| 1560 | 1591 |
| 1561 QuicAckFrame ack_fec = InitAckFrame(5, 1); | 1592 QuicAckFrame ack_fec = InitAckFrame(5, 1); |
| 1562 // Ack all data packets, but no fec packets. | 1593 // Ack all data packets, but no fec packets. |
| 1563 NackPacket(2, &ack_fec); | 1594 NackPacket(2, &ack_fec); |
| 1564 NackPacket(4, &ack_fec); | 1595 NackPacket(4, &ack_fec); |
| 1565 | 1596 |
| 1566 // Lose the first FEC packet and ack the three data packets. | 1597 // Lose the first FEC packet and ack the three data packets. |
| 1567 SequenceNumberSet lost_packets; | 1598 SequenceNumberSet lost_packets; |
| 1568 lost_packets.insert(2); | 1599 lost_packets.insert(2); |
| 1569 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) | 1600 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1655 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1686 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 1656 EXPECT_FALSE(connection_.HasQueuedData()); | 1687 EXPECT_FALSE(connection_.HasQueuedData()); |
| 1657 | 1688 |
| 1658 // Parse the last packet and ensure it's the stream frame from stream 3. | 1689 // Parse the last packet and ensure it's the stream frame from stream 3. |
| 1659 EXPECT_EQ(1u, writer_->frame_count()); | 1690 EXPECT_EQ(1u, writer_->frame_count()); |
| 1660 ASSERT_EQ(1u, writer_->stream_frames().size()); | 1691 ASSERT_EQ(1u, writer_->stream_frames().size()); |
| 1661 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0].stream_id); | 1692 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0].stream_id); |
| 1662 } | 1693 } |
| 1663 | 1694 |
| 1664 TEST_P(QuicConnectionTest, FramePackingFEC) { | 1695 TEST_P(QuicConnectionTest, FramePackingFEC) { |
| 1665 // Enable fec. | 1696 // Enable FEC. |
| 1666 QuicPacketGeneratorPeer::SwitchFecProtectionOn( | 1697 QuicConnectionPeer::GetPacketCreator( |
| 1667 QuicConnectionPeer::GetPacketGenerator(&connection_), 6); | 1698 &connection_)->set_max_packets_per_fec_group(6); |
| 1668 | 1699 |
| 1669 CongestionBlockWrites(); | 1700 CongestionBlockWrites(); |
| 1670 | 1701 |
| 1671 // Send an ack and two stream frames in 1 packet by queueing them. | 1702 // Queue an ack and two stream frames. Ack gets flushed when FEC is turned on |
| 1703 // for sending protected data; two stream frames are packing in 1 packet. |
| 1704 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( |
| 1705 IgnoreResult(InvokeWithoutArgs( |
| 1706 &connection_, &TestConnection::SendStreamData3WithFec)), |
| 1707 IgnoreResult(InvokeWithoutArgs( |
| 1708 &connection_, &TestConnection::SendStreamData5WithFec)))); |
| 1672 connection_.SendAck(); | 1709 connection_.SendAck(); |
| 1673 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( | |
| 1674 IgnoreResult(InvokeWithoutArgs(&connection_, | |
| 1675 &TestConnection::SendStreamData3)), | |
| 1676 IgnoreResult(InvokeWithoutArgs(&connection_, | |
| 1677 &TestConnection::SendStreamData5)))); | |
| 1678 | 1710 |
| 1679 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); | 1711 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3); |
| 1680 CongestionUnblockWrites(); | 1712 CongestionUnblockWrites(); |
| 1681 connection_.GetSendAlarm()->Fire(); | 1713 connection_.GetSendAlarm()->Fire(); |
| 1682 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1714 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 1683 EXPECT_FALSE(connection_.HasQueuedData()); | 1715 EXPECT_FALSE(connection_.HasQueuedData()); |
| 1684 | 1716 |
| 1685 // Parse the last packet and ensure it's in an fec group. | 1717 // Parse the last packet and ensure it's in an fec group. |
| 1686 EXPECT_EQ(1u, writer_->header().fec_group); | 1718 EXPECT_EQ(2u, writer_->header().fec_group); |
| 1687 EXPECT_EQ(0u, writer_->frame_count()); | 1719 EXPECT_EQ(0u, writer_->frame_count()); |
| 1688 } | 1720 } |
| 1689 | 1721 |
| 1690 TEST_P(QuicConnectionTest, FramePackingAckResponse) { | 1722 TEST_P(QuicConnectionTest, FramePackingAckResponse) { |
| 1691 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1723 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1692 // Process a data packet to queue up a pending ack. | 1724 // Process a data packet to queue up a pending ack. |
| 1693 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); | 1725 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); |
| 1694 ProcessDataPacket(1, 1, kEntropyFlag); | 1726 ProcessDataPacket(1, 1, kEntropyFlag); |
| 1695 | 1727 |
| 1696 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( | 1728 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1725 | 1757 |
| 1726 TEST_P(QuicConnectionTest, FramePackingSendv) { | 1758 TEST_P(QuicConnectionTest, FramePackingSendv) { |
| 1727 // Send data in 1 packet by writing multiple blocks in a single iovector | 1759 // Send data in 1 packet by writing multiple blocks in a single iovector |
| 1728 // using writev. | 1760 // using writev. |
| 1729 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 1761 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| 1730 | 1762 |
| 1731 char data[] = "ABCD"; | 1763 char data[] = "ABCD"; |
| 1732 IOVector data_iov; | 1764 IOVector data_iov; |
| 1733 data_iov.AppendNoCoalesce(data, 2); | 1765 data_iov.AppendNoCoalesce(data, 2); |
| 1734 data_iov.AppendNoCoalesce(data + 2, 2); | 1766 data_iov.AppendNoCoalesce(data + 2, 2); |
| 1735 connection_.SendStreamData(1, data_iov, 0, !kFin, NULL); | 1767 connection_.SendStreamData(1, data_iov, 0, !kFin, MAY_FEC_PROTECT, NULL); |
| 1736 | 1768 |
| 1737 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1769 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 1738 EXPECT_FALSE(connection_.HasQueuedData()); | 1770 EXPECT_FALSE(connection_.HasQueuedData()); |
| 1739 | 1771 |
| 1740 // Parse the last packet and ensure multiple iovector blocks have | 1772 // Parse the last packet and ensure multiple iovector blocks have |
| 1741 // been packed into a single stream frame from one stream. | 1773 // been packed into a single stream frame from one stream. |
| 1742 EXPECT_EQ(1u, writer_->frame_count()); | 1774 EXPECT_EQ(1u, writer_->frame_count()); |
| 1743 EXPECT_EQ(1u, writer_->stream_frames().size()); | 1775 EXPECT_EQ(1u, writer_->stream_frames().size()); |
| 1744 QuicStreamFrame frame = writer_->stream_frames()[0]; | 1776 QuicStreamFrame frame = writer_->stream_frames()[0]; |
| 1745 EXPECT_EQ(1u, frame.stream_id); | 1777 EXPECT_EQ(1u, frame.stream_id); |
| 1746 EXPECT_EQ("ABCD", string(static_cast<char*> | 1778 EXPECT_EQ("ABCD", string(static_cast<char*> |
| 1747 (frame.data.iovec()[0].iov_base), | 1779 (frame.data.iovec()[0].iov_base), |
| 1748 (frame.data.iovec()[0].iov_len))); | 1780 (frame.data.iovec()[0].iov_len))); |
| 1749 } | 1781 } |
| 1750 | 1782 |
| 1751 TEST_P(QuicConnectionTest, FramePackingSendvQueued) { | 1783 TEST_P(QuicConnectionTest, FramePackingSendvQueued) { |
| 1752 // Try to send two stream frames in 1 packet by using writev. | 1784 // Try to send two stream frames in 1 packet by using writev. |
| 1753 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 1785 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| 1754 | 1786 |
| 1755 BlockOnNextWrite(); | 1787 BlockOnNextWrite(); |
| 1756 char data[] = "ABCD"; | 1788 char data[] = "ABCD"; |
| 1757 IOVector data_iov; | 1789 IOVector data_iov; |
| 1758 data_iov.AppendNoCoalesce(data, 2); | 1790 data_iov.AppendNoCoalesce(data, 2); |
| 1759 data_iov.AppendNoCoalesce(data + 2, 2); | 1791 data_iov.AppendNoCoalesce(data + 2, 2); |
| 1760 connection_.SendStreamData(1, data_iov, 0, !kFin, NULL); | 1792 connection_.SendStreamData(1, data_iov, 0, !kFin, MAY_FEC_PROTECT, NULL); |
| 1761 | 1793 |
| 1762 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 1794 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 1763 EXPECT_TRUE(connection_.HasQueuedData()); | 1795 EXPECT_TRUE(connection_.HasQueuedData()); |
| 1764 | 1796 |
| 1765 // Unblock the writes and actually send. | 1797 // Unblock the writes and actually send. |
| 1766 writer_->SetWritable(); | 1798 writer_->SetWritable(); |
| 1767 connection_.OnCanWrite(); | 1799 connection_.OnCanWrite(); |
| 1768 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1800 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 1769 | 1801 |
| 1770 // Parse the last packet and ensure it's one stream frame from one stream. | 1802 // Parse the last packet and ensure it's one stream frame from one stream. |
| 1771 EXPECT_EQ(1u, writer_->frame_count()); | 1803 EXPECT_EQ(1u, writer_->frame_count()); |
| 1772 EXPECT_EQ(1u, writer_->stream_frames().size()); | 1804 EXPECT_EQ(1u, writer_->stream_frames().size()); |
| 1773 EXPECT_EQ(1u, writer_->stream_frames()[0].stream_id); | 1805 EXPECT_EQ(1u, writer_->stream_frames()[0].stream_id); |
| 1774 } | 1806 } |
| 1775 | 1807 |
| 1776 TEST_P(QuicConnectionTest, SendingZeroBytes) { | 1808 TEST_P(QuicConnectionTest, SendingZeroBytes) { |
| 1777 // Send a zero byte write with a fin using writev. | 1809 // Send a zero byte write with a fin using writev. |
| 1778 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 1810 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| 1779 IOVector empty_iov; | 1811 IOVector empty_iov; |
| 1780 connection_.SendStreamData(1, empty_iov, 0, kFin, NULL); | 1812 connection_.SendStreamData(1, empty_iov, 0, kFin, MAY_FEC_PROTECT, NULL); |
| 1781 | 1813 |
| 1782 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1814 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 1783 EXPECT_FALSE(connection_.HasQueuedData()); | 1815 EXPECT_FALSE(connection_.HasQueuedData()); |
| 1784 | 1816 |
| 1785 // Parse the last packet and ensure it's one stream frame from one stream. | 1817 // Parse the last packet and ensure it's one stream frame from one stream. |
| 1786 EXPECT_EQ(1u, writer_->frame_count()); | 1818 EXPECT_EQ(1u, writer_->frame_count()); |
| 1787 EXPECT_EQ(1u, writer_->stream_frames().size()); | 1819 EXPECT_EQ(1u, writer_->stream_frames().size()); |
| 1788 EXPECT_EQ(1u, writer_->stream_frames()[0].stream_id); | 1820 EXPECT_EQ(1u, writer_->stream_frames()[0].stream_id); |
| 1789 EXPECT_TRUE(writer_->stream_frames()[0].fin); | 1821 EXPECT_TRUE(writer_->stream_frames()[0].fin); |
| 1790 } | 1822 } |
| (...skipping 2197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3988 QuicBlockedFrame blocked; | 4020 QuicBlockedFrame blocked; |
| 3989 blocked.stream_id = 3; | 4021 blocked.stream_id = 3; |
| 3990 EXPECT_CALL(visitor_, OnBlockedFrames(_)); | 4022 EXPECT_CALL(visitor_, OnBlockedFrames(_)); |
| 3991 ProcessFramePacket(QuicFrame(&blocked)); | 4023 ProcessFramePacket(QuicFrame(&blocked)); |
| 3992 EXPECT_TRUE(ack_alarm->IsSet()); | 4024 EXPECT_TRUE(ack_alarm->IsSet()); |
| 3993 } | 4025 } |
| 3994 | 4026 |
| 3995 } // namespace | 4027 } // namespace |
| 3996 } // namespace test | 4028 } // namespace test |
| 3997 } // namespace net | 4029 } // namespace net |
| OLD | NEW |