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 "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
10 #include "net/quic/congestion_control/receive_algorithm_interface.h" | 10 #include "net/quic/congestion_control/receive_algorithm_interface.h" |
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 bool expect_revival, bool entropy_flag) { | 563 bool expect_revival, bool entropy_flag) { |
564 if (expect_revival) { | 564 if (expect_revival) { |
565 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillOnce(DoAll( | 565 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillOnce(DoAll( |
566 SaveArg<2>(&revived_header_), Return(accept_packet_))); | 566 SaveArg<2>(&revived_header_), Return(accept_packet_))); |
567 } | 567 } |
568 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillOnce(Return(accept_packet_)) | 568 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillOnce(Return(accept_packet_)) |
569 .RetiresOnSaturation(); | 569 .RetiresOnSaturation(); |
570 return ProcessDataPacket(number, 1, entropy_flag); | 570 return ProcessDataPacket(number, 1, entropy_flag); |
571 } | 571 } |
572 | 572 |
573 // Sends an FEC packet that covers the packets that would have been sent. | 573 // Processes an FEC packet that covers the packets that would have been |
| 574 // received. |
574 size_t ProcessFecPacket(QuicPacketSequenceNumber number, | 575 size_t ProcessFecPacket(QuicPacketSequenceNumber number, |
575 QuicPacketSequenceNumber min_protected_packet, | 576 QuicPacketSequenceNumber min_protected_packet, |
576 bool expect_revival, | 577 bool expect_revival, |
577 bool entropy_flag) { | 578 bool entropy_flag, |
| 579 QuicPacket* packet) { |
578 if (expect_revival) { | 580 if (expect_revival) { |
579 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillOnce(DoAll( | 581 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillOnce(DoAll( |
580 SaveArg<2>(&revived_header_), Return(accept_packet_))); | 582 SaveArg<2>(&revived_header_), Return(accept_packet_))); |
581 } | 583 } |
582 | 584 |
583 // Construct the decrypted data packet so we can compute the correct | 585 // Construct the decrypted data packet so we can compute the correct |
584 // redundancy. | 586 // redundancy. If |packet| has been provided then use that, otherwise |
585 scoped_ptr<QuicPacket> data_packet(ConstructDataPacket(number, 1, | 587 // construct a default data packet. |
586 !kEntropyFlag)); | 588 scoped_ptr<QuicPacket> data_packet; |
| 589 if (packet) { |
| 590 data_packet.reset(packet); |
| 591 } else { |
| 592 data_packet.reset(ConstructDataPacket(number, 1, !kEntropyFlag)); |
| 593 } |
587 | 594 |
588 header_.public_header.guid = guid_; | 595 header_.public_header.guid = guid_; |
589 header_.public_header.reset_flag = false; | 596 header_.public_header.reset_flag = false; |
590 header_.public_header.version_flag = false; | 597 header_.public_header.version_flag = false; |
591 header_.entropy_flag = entropy_flag; | 598 header_.entropy_flag = entropy_flag; |
592 header_.fec_flag = true; | 599 header_.fec_flag = true; |
593 header_.packet_sequence_number = number; | 600 header_.packet_sequence_number = number; |
594 header_.is_in_fec_group = IN_FEC_GROUP; | 601 header_.is_in_fec_group = IN_FEC_GROUP; |
595 header_.fec_group = min_protected_packet; | 602 header_.fec_group = min_protected_packet; |
596 QuicFecData fec_data; | 603 QuicFecData fec_data; |
597 fec_data.fec_group = header_.fec_group; | 604 fec_data.fec_group = header_.fec_group; |
| 605 |
598 // Since all data packets in this test have the same payload, the | 606 // Since all data packets in this test have the same payload, the |
599 // redundancy is either equal to that payload or the xor of that payload | 607 // redundancy is either equal to that payload or the xor of that payload |
600 // with itself, depending on the number of packets. | 608 // with itself, depending on the number of packets. |
601 if (((number - min_protected_packet) % 2) == 0) { | 609 if (((number - min_protected_packet) % 2) == 0) { |
602 for (size_t i = GetStartOfFecProtectedData( | 610 for (size_t i = GetStartOfFecProtectedData( |
603 header_.public_header.guid_length, | 611 header_.public_header.guid_length, |
604 header_.public_header.version_flag, | 612 header_.public_header.version_flag, |
605 header_.public_header.sequence_number_length); | 613 header_.public_header.sequence_number_length); |
606 i < data_packet->length(); ++i) { | 614 i < data_packet->length(); ++i) { |
607 data_packet->mutable_data()[i] ^= data_packet->data()[i]; | 615 data_packet->mutable_data()[i] ^= data_packet->data()[i]; |
608 } | 616 } |
609 } | 617 } |
610 fec_data.redundancy = data_packet->FecProtectedData(); | 618 fec_data.redundancy = data_packet->FecProtectedData(); |
| 619 |
611 scoped_ptr<QuicPacket> fec_packet( | 620 scoped_ptr<QuicPacket> fec_packet( |
612 framer_.BuildFecPacket(header_, fec_data).packet); | 621 framer_.BuildFecPacket(header_, fec_data).packet); |
613 scoped_ptr<QuicEncryptedPacket> encrypted( | 622 scoped_ptr<QuicEncryptedPacket> encrypted( |
614 framer_.EncryptPacket(ENCRYPTION_NONE, number, *fec_packet)); | 623 framer_.EncryptPacket(ENCRYPTION_NONE, number, *fec_packet)); |
615 | 624 |
616 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 625 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); |
617 return encrypted->length(); | 626 return encrypted->length(); |
618 } | 627 } |
619 | 628 |
620 QuicByteCount SendStreamDataToPeer(QuicStreamId id, StringPiece data, | 629 QuicByteCount SendStreamDataToPeer(QuicStreamId id, StringPiece data, |
(...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1591 EXPECT_EQ(3u, last_ack()->sent_info.least_unacked); | 1600 EXPECT_EQ(3u, last_ack()->sent_info.least_unacked); |
1592 | 1601 |
1593 SendStreamDataToPeer(1, "bar", 3, false, NULL); // Packet 4 | 1602 SendStreamDataToPeer(1, "bar", 3, false, NULL); // Packet 4 |
1594 EXPECT_EQ(4u, outgoing_ack()->sent_info.least_unacked); | 1603 EXPECT_EQ(4u, outgoing_ack()->sent_info.least_unacked); |
1595 SendAckPacketToPeer(); // Packet 5 | 1604 SendAckPacketToPeer(); // Packet 5 |
1596 EXPECT_EQ(4u, last_ack()->sent_info.least_unacked); | 1605 EXPECT_EQ(4u, last_ack()->sent_info.least_unacked); |
1597 } | 1606 } |
1598 | 1607 |
1599 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterFecPacket) { | 1608 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterFecPacket) { |
1600 // Don't send missing packet 1. | 1609 // Don't send missing packet 1. |
1601 ProcessFecPacket(2, 1, true, !kEntropyFlag); | 1610 ProcessFecPacket(2, 1, true, !kEntropyFlag, NULL); |
1602 EXPECT_FALSE(revived_header_.entropy_flag); | 1611 EXPECT_FALSE(revived_header_.entropy_flag); |
1603 } | 1612 } |
1604 | 1613 |
1605 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPacketThenFecPacket) { | 1614 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPacketThenFecPacket) { |
1606 ProcessFecProtectedPacket(1, false, kEntropyFlag); | 1615 ProcessFecProtectedPacket(1, false, kEntropyFlag); |
1607 // Don't send missing packet 2. | 1616 // Don't send missing packet 2. |
1608 ProcessFecPacket(3, 1, true, !kEntropyFlag); | 1617 ProcessFecPacket(3, 1, true, !kEntropyFlag, NULL); |
1609 EXPECT_TRUE(revived_header_.entropy_flag); | 1618 EXPECT_TRUE(revived_header_.entropy_flag); |
1610 } | 1619 } |
1611 | 1620 |
1612 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPacketsThenFecPacket) { | 1621 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPacketsThenFecPacket) { |
1613 ProcessFecProtectedPacket(1, false, !kEntropyFlag); | 1622 ProcessFecProtectedPacket(1, false, !kEntropyFlag); |
1614 // Don't send missing packet 2. | 1623 // Don't send missing packet 2. |
1615 ProcessFecProtectedPacket(3, false, !kEntropyFlag); | 1624 ProcessFecProtectedPacket(3, false, !kEntropyFlag); |
1616 ProcessFecPacket(4, 1, true, kEntropyFlag); | 1625 ProcessFecPacket(4, 1, true, kEntropyFlag, NULL); |
1617 EXPECT_TRUE(revived_header_.entropy_flag); | 1626 EXPECT_TRUE(revived_header_.entropy_flag); |
1618 } | 1627 } |
1619 | 1628 |
1620 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPacket) { | 1629 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPacket) { |
1621 // Don't send missing packet 1. | 1630 // Don't send missing packet 1. |
1622 ProcessFecPacket(3, 1, false, !kEntropyFlag); | 1631 ProcessFecPacket(3, 1, false, !kEntropyFlag, NULL); |
1623 // out of order | 1632 // out of order |
1624 ProcessFecProtectedPacket(2, true, !kEntropyFlag); | 1633 ProcessFecProtectedPacket(2, true, !kEntropyFlag); |
1625 EXPECT_FALSE(revived_header_.entropy_flag); | 1634 EXPECT_FALSE(revived_header_.entropy_flag); |
1626 } | 1635 } |
1627 | 1636 |
1628 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPackets) { | 1637 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPackets) { |
1629 ProcessFecProtectedPacket(1, false, !kEntropyFlag); | 1638 ProcessFecProtectedPacket(1, false, !kEntropyFlag); |
1630 // Don't send missing packet 2. | 1639 // Don't send missing packet 2. |
1631 ProcessFecPacket(6, 1, false, kEntropyFlag); | 1640 ProcessFecPacket(6, 1, false, kEntropyFlag, NULL); |
1632 ProcessFecProtectedPacket(3, false, kEntropyFlag); | 1641 ProcessFecProtectedPacket(3, false, kEntropyFlag); |
1633 ProcessFecProtectedPacket(4, false, kEntropyFlag); | 1642 ProcessFecProtectedPacket(4, false, kEntropyFlag); |
1634 ProcessFecProtectedPacket(5, true, !kEntropyFlag); | 1643 ProcessFecProtectedPacket(5, true, !kEntropyFlag); |
1635 EXPECT_TRUE(revived_header_.entropy_flag); | 1644 EXPECT_TRUE(revived_header_.entropy_flag); |
1636 } | 1645 } |
1637 | 1646 |
1638 TEST_F(QuicConnectionTest, TestRetransmit) { | 1647 TEST_F(QuicConnectionTest, TestRetransmit) { |
1639 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( | 1648 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( |
1640 DefaultRetransmissionTime()); | 1649 DefaultRetransmissionTime()); |
1641 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); | 1650 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1892 SendAckPacketToPeer(); | 1901 SendAckPacketToPeer(); |
1893 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _, _)); | 1902 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _, _)); |
1894 ProcessPacket(1); | 1903 ProcessPacket(1); |
1895 } | 1904 } |
1896 | 1905 |
1897 TEST_F(QuicConnectionTest, DontUpdateQuicCongestionFeedbackFrameForRevived) { | 1906 TEST_F(QuicConnectionTest, DontUpdateQuicCongestionFeedbackFrameForRevived) { |
1898 SendAckPacketToPeer(); | 1907 SendAckPacketToPeer(); |
1899 // Process an FEC packet, and revive the missing data packet | 1908 // Process an FEC packet, and revive the missing data packet |
1900 // but only contact the receive_algorithm once. | 1909 // but only contact the receive_algorithm once. |
1901 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _, _)); | 1910 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _, _)); |
1902 ProcessFecPacket(2, 1, true, !kEntropyFlag); | 1911 ProcessFecPacket(2, 1, true, !kEntropyFlag, NULL); |
1903 } | 1912 } |
1904 | 1913 |
1905 TEST_F(QuicConnectionTest, InitialTimeout) { | 1914 TEST_F(QuicConnectionTest, InitialTimeout) { |
1906 EXPECT_TRUE(connection_.connected()); | 1915 EXPECT_TRUE(connection_.connected()); |
1907 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, false)); | 1916 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, false)); |
1908 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)); | 1917 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)); |
1909 | 1918 |
1910 QuicTime default_timeout = clock_.ApproximateNow().Add( | 1919 QuicTime default_timeout = clock_.ApproximateNow().Add( |
1911 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)); | 1920 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)); |
1912 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); | 1921 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); |
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2470 EXPECT_EQ(3u, stats.packets_retransmitted); | 2479 EXPECT_EQ(3u, stats.packets_retransmitted); |
2471 EXPECT_EQ(2u, stats.rto_count); | 2480 EXPECT_EQ(2u, stats.rto_count); |
2472 } | 2481 } |
2473 | 2482 |
2474 TEST_F(QuicConnectionTest, CheckReceiveStats) { | 2483 TEST_F(QuicConnectionTest, CheckReceiveStats) { |
2475 size_t received_bytes = 0; | 2484 size_t received_bytes = 0; |
2476 received_bytes += ProcessFecProtectedPacket(1, false, !kEntropyFlag); | 2485 received_bytes += ProcessFecProtectedPacket(1, false, !kEntropyFlag); |
2477 received_bytes += ProcessFecProtectedPacket(3, false, !kEntropyFlag); | 2486 received_bytes += ProcessFecProtectedPacket(3, false, !kEntropyFlag); |
2478 // Should be counted against dropped packets. | 2487 // Should be counted against dropped packets. |
2479 received_bytes += ProcessDataPacket(3, 1, !kEntropyFlag); | 2488 received_bytes += ProcessDataPacket(3, 1, !kEntropyFlag); |
2480 received_bytes += ProcessFecPacket(4, 1, true, !kEntropyFlag); // Fec packet | 2489 received_bytes += ProcessFecPacket(4, 1, true, !kEntropyFlag, NULL); |
2481 | 2490 |
2482 EXPECT_CALL(*send_algorithm_, SmoothedRtt()).WillOnce( | 2491 EXPECT_CALL(*send_algorithm_, SmoothedRtt()).WillOnce( |
2483 Return(QuicTime::Delta::Zero())); | 2492 Return(QuicTime::Delta::Zero())); |
2484 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillOnce( | 2493 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillOnce( |
2485 Return(QuicBandwidth::Zero())); | 2494 Return(QuicBandwidth::Zero())); |
2486 | 2495 |
2487 const QuicConnectionStats& stats = connection_.GetStats(); | 2496 const QuicConnectionStats& stats = connection_.GetStats(); |
2488 EXPECT_EQ(received_bytes, stats.bytes_received); | 2497 EXPECT_EQ(received_bytes, stats.bytes_received); |
2489 EXPECT_EQ(4u, stats.packets_received); | 2498 EXPECT_EQ(4u, stats.packets_received); |
2490 | 2499 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2605 | 2614 |
2606 TEST_F(QuicConnectionTest, ConnectionCloseWhenNothingPending) { | 2615 TEST_F(QuicConnectionTest, ConnectionCloseWhenNothingPending) { |
2607 helper_->set_blocked(true); | 2616 helper_->set_blocked(true); |
2608 | 2617 |
2609 // Send an erroneous packet to close the connection. | 2618 // Send an erroneous packet to close the connection. |
2610 EXPECT_CALL(visitor_, ConnectionClose(QUIC_INVALID_PACKET_HEADER, false)); | 2619 EXPECT_CALL(visitor_, ConnectionClose(QUIC_INVALID_PACKET_HEADER, false)); |
2611 ProcessDataPacket(6000, 0, !kEntropyFlag); | 2620 ProcessDataPacket(6000, 0, !kEntropyFlag); |
2612 EXPECT_EQ(1u, helper_->packets_write_attempts()); | 2621 EXPECT_EQ(1u, helper_->packets_write_attempts()); |
2613 } | 2622 } |
2614 | 2623 |
| 2624 TEST_F(QuicConnectionTest, AckNotifierTriggerCallback) { |
| 2625 // Create a delegate which we expect to be called. |
| 2626 MockAckNotifierDelegate delegate; |
| 2627 EXPECT_CALL(delegate, OnAckNotification()).Times(1);; |
| 2628 |
| 2629 // Send some data, which will register the delegate to be notified. |
| 2630 connection_.SendStreamDataAndNotifyWhenAcked(1, "foo", 0, !kFin, &delegate); |
| 2631 |
| 2632 // Process an ACK from the server which should trigger the callback. |
| 2633 EXPECT_CALL(visitor_, OnAck(_)).Times(1); |
| 2634 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1); |
| 2635 QuicAckFrame frame(1, QuicTime::Zero(), 0); |
| 2636 ProcessAckPacket(&frame, true); |
| 2637 } |
| 2638 |
| 2639 TEST_F(QuicConnectionTest, AckNotifierFailToTriggerCallback) { |
| 2640 // Create a delegate which we don't expect to be called. |
| 2641 MockAckNotifierDelegate delegate; |
| 2642 EXPECT_CALL(delegate, OnAckNotification()).Times(0);; |
| 2643 |
| 2644 EXPECT_CALL(visitor_, OnAck(_)).Times(1); |
| 2645 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(2); |
| 2646 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); |
| 2647 |
| 2648 // Send some data, which will register the delegate to be notified. This will |
| 2649 // not be ACKed and so the delegate should never be called. |
| 2650 connection_.SendStreamDataAndNotifyWhenAcked(1, "foo", 0, !kFin, &delegate); |
| 2651 |
| 2652 // Send some other data which we will ACK. |
| 2653 connection_.SendStreamData(1, "foo", 0, !kFin); |
| 2654 connection_.SendStreamData(1, "bar", 0, !kFin); |
| 2655 |
| 2656 // Now we receive ACK for packets 2 and 3, but importantly missing packet 1 |
| 2657 // which we registered to be notified about. |
| 2658 QuicAckFrame frame(3, QuicTime::Zero(), 0); |
| 2659 frame.received_info.missing_packets.insert(1); |
| 2660 ProcessAckPacket(&frame, true); |
| 2661 } |
| 2662 |
| 2663 TEST_F(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) { |
| 2664 // Create a delegate which we expect to be called. |
| 2665 MockAckNotifierDelegate delegate; |
| 2666 EXPECT_CALL(delegate, OnAckNotification()).Times(1);; |
| 2667 |
| 2668 // OnAck called twice: once with missing packet, once after retransmit. |
| 2669 EXPECT_CALL(visitor_, OnAck(_)).Times(2); |
| 2670 |
| 2671 // In total expect ACKs for all 4 packets. |
| 2672 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(4); |
| 2673 |
| 2674 // We will lose the second packet. |
| 2675 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); |
| 2676 |
| 2677 // Send four packets, and register to be notified on ACK of packet 2. |
| 2678 connection_.SendStreamData(1, "foo", 0, !kFin); |
| 2679 connection_.SendStreamDataAndNotifyWhenAcked(1, "bar", 0, !kFin, &delegate); |
| 2680 connection_.SendStreamData(1, "baz", 0, !kFin); |
| 2681 connection_.SendStreamData(1, "qux", 0, !kFin); |
| 2682 |
| 2683 // Now we receive ACK for packets 1, 3, and 4. |
| 2684 QuicAckFrame frame(4, QuicTime::Zero(), 0); |
| 2685 frame.received_info.missing_packets.insert(2); |
| 2686 ProcessAckPacket(&frame, true); |
| 2687 |
| 2688 // Advance time to trigger RTO, for packet 2 (which should be retransmitted as |
| 2689 // packet 5). |
| 2690 EXPECT_CALL(*send_algorithm_, AbandoningPacket(2, _)).Times(1); |
| 2691 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).Times(1); |
| 2692 |
| 2693 clock_.AdvanceTime(DefaultRetransmissionTime()); |
| 2694 connection_.OnRetransmissionTimeout(); |
| 2695 |
| 2696 // Now we get an ACK for packet 5 (retransmitted packet 2), which should |
| 2697 // trigger the callback. |
| 2698 QuicAckFrame second_ack_frame(5, QuicTime::Zero(), 0); |
| 2699 ProcessAckPacket(&second_ack_frame, true); |
| 2700 } |
| 2701 |
| 2702 // TODO(rjshade): Add a similar test that FEC recovery on peer (and resulting |
| 2703 // ACK) triggers notification on our end. |
| 2704 TEST_F(QuicConnectionTest, AckNotifierCallbackAfterFECRecovery) { |
| 2705 EXPECT_CALL(visitor_, OnCanWrite()).Times(1).WillOnce(Return(true)); |
| 2706 |
| 2707 // Create a delegate which we expect to be called. |
| 2708 MockAckNotifierDelegate delegate; |
| 2709 EXPECT_CALL(delegate, OnAckNotification()).Times(1);; |
| 2710 |
| 2711 // Expect ACKs for 1 packet. |
| 2712 EXPECT_CALL(visitor_, OnAck(_)).Times(1); |
| 2713 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1); |
| 2714 |
| 2715 // Send one packet, and register to be notified on ACK. |
| 2716 connection_.SendStreamDataAndNotifyWhenAcked(1, "foo", 0, !kFin, &delegate); |
| 2717 |
| 2718 // Ack packet gets dropped, but we receive an FEC packet that covers it. |
| 2719 // Should recover the Ack packet and trigger the notification callback. |
| 2720 QuicFrames frames; |
| 2721 |
| 2722 QuicAckFrame ack_frame(1, QuicTime::Zero(), 0); |
| 2723 frames.push_back(QuicFrame(&ack_frame)); |
| 2724 |
| 2725 // Dummy stream frame to satisfy expectations set elsewhere. |
| 2726 QuicFrame frame(&frame1_); |
| 2727 frames.push_back(frame); |
| 2728 |
| 2729 QuicPacketHeader ack_header; |
| 2730 ack_header.public_header.guid = guid_; |
| 2731 ack_header.public_header.reset_flag = false; |
| 2732 ack_header.public_header.version_flag = false; |
| 2733 ack_header.entropy_flag = !kEntropyFlag; |
| 2734 ack_header.fec_flag = true; |
| 2735 ack_header.packet_sequence_number = 42; |
| 2736 ack_header.is_in_fec_group = IN_FEC_GROUP; |
| 2737 ack_header.fec_group = 1; |
| 2738 |
| 2739 QuicPacket* packet = |
| 2740 framer_.BuildUnsizedDataPacket(ack_header, frames).packet; |
| 2741 |
| 2742 // Take the packet which contains the ACK frame, and construct and deliver an |
| 2743 // FEC packet which allows the ACK packet to be recovered. |
| 2744 ProcessFecPacket(2, 1, true, !kEntropyFlag, packet); |
| 2745 } |
| 2746 |
2615 class MockQuicConnectionDebugVisitor | 2747 class MockQuicConnectionDebugVisitor |
2616 : public QuicConnectionDebugVisitorInterface { | 2748 : public QuicConnectionDebugVisitorInterface { |
2617 public: | 2749 public: |
2618 MOCK_METHOD1(OnFrameAddedToPacket, | 2750 MOCK_METHOD1(OnFrameAddedToPacket, |
2619 void(const QuicFrame&)); | 2751 void(const QuicFrame&)); |
2620 | 2752 |
2621 MOCK_METHOD4(OnPacketSent, | 2753 MOCK_METHOD4(OnPacketSent, |
2622 void(QuicPacketSequenceNumber, | 2754 void(QuicPacketSequenceNumber, |
2623 EncryptionLevel, | 2755 EncryptionLevel, |
2624 const QuicEncryptedPacket&, | 2756 const QuicEncryptedPacket&, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2670 scoped_ptr<MockQuicConnectionDebugVisitor> | 2802 scoped_ptr<MockQuicConnectionDebugVisitor> |
2671 debug_visitor(new StrictMock<MockQuicConnectionDebugVisitor>); | 2803 debug_visitor(new StrictMock<MockQuicConnectionDebugVisitor>); |
2672 connection_.set_debug_visitor(debug_visitor.get()); | 2804 connection_.set_debug_visitor(debug_visitor.get()); |
2673 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1); | 2805 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1); |
2674 connection_.OnPacketHeader(header); | 2806 connection_.OnPacketHeader(header); |
2675 } | 2807 } |
2676 | 2808 |
2677 } // namespace | 2809 } // namespace |
2678 } // namespace test | 2810 } // namespace test |
2679 } // namespace net | 2811 } // namespace net |
OLD | NEW |