| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "net/quic/congestion_control/inter_arrival_sender.h" |
| 7 #include "net/quic/congestion_control/quic_congestion_manager.h" | 8 #include "net/quic/congestion_control/quic_congestion_manager.h" |
| 8 #include "net/quic/quic_protocol.h" | 9 #include "net/quic/quic_protocol.h" |
| 9 #include "net/quic/test_tools/mock_clock.h" | 10 #include "net/quic/test_tools/mock_clock.h" |
| 10 #include "net/quic/test_tools/quic_test_utils.h" | 11 #include "net/quic/test_tools/quic_test_utils.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 14 |
| 14 using testing::_; | 15 using testing::_; |
| 15 using testing::StrictMock; | 16 using testing::StrictMock; |
| 16 | 17 |
| 17 namespace net { | 18 namespace net { |
| 18 namespace test { | 19 namespace test { |
| 19 | 20 |
| 20 class QuicCongestionManagerPeer : public QuicCongestionManager { | 21 class QuicCongestionManagerPeer : public QuicCongestionManager { |
| 21 public: | 22 public: |
| 22 explicit QuicCongestionManagerPeer(const QuicClock* clock, | 23 explicit QuicCongestionManagerPeer(const QuicClock* clock, |
| 23 CongestionFeedbackType congestion_type) | 24 CongestionFeedbackType congestion_type) |
| 24 : QuicCongestionManager(clock, congestion_type) { | 25 : QuicCongestionManager(clock, congestion_type) { |
| 25 } | 26 } |
| 26 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) { | 27 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) { |
| 27 this->send_algorithm_.reset(send_algorithm); | 28 this->send_algorithm_.reset(send_algorithm); |
| 28 } | 29 } |
| 29 | 30 |
| 30 using QuicCongestionManager::rtt; | 31 using QuicCongestionManager::rtt; |
| 31 using QuicCongestionManager::SentBandwidth; | 32 const SendAlgorithmInterface::SentPacketsMap& packet_history_map() { |
| 32 | 33 return packet_history_map_; |
| 34 } |
| 33 private: | 35 private: |
| 34 DISALLOW_COPY_AND_ASSIGN(QuicCongestionManagerPeer); | 36 DISALLOW_COPY_AND_ASSIGN(QuicCongestionManagerPeer); |
| 35 }; | 37 }; |
| 36 | 38 |
| 37 class QuicCongestionManagerTest : public ::testing::Test { | 39 class QuicCongestionManagerTest : public ::testing::Test { |
| 38 protected: | 40 protected: |
| 39 void SetUpCongestionType(CongestionFeedbackType congestion_type) { | 41 void SetUpCongestionType(CongestionFeedbackType congestion_type) { |
| 40 manager_.reset(new QuicCongestionManagerPeer(&clock_, congestion_type)); | 42 manager_.reset(new QuicCongestionManagerPeer(&clock_, congestion_type)); |
| 41 } | 43 } |
| 42 | 44 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 62 clock_.AdvanceTime(advance_time); | 64 clock_.AdvanceTime(advance_time); |
| 63 EXPECT_TRUE(manager_->TimeUntilSend( | 65 EXPECT_TRUE(manager_->TimeUntilSend( |
| 64 clock_.Now(), NOT_RETRANSMISSION, kIgnored).IsZero()); | 66 clock_.Now(), NOT_RETRANSMISSION, kIgnored).IsZero()); |
| 65 manager_->SentPacket(i, clock_.Now(), 1000, NOT_RETRANSMISSION); | 67 manager_->SentPacket(i, clock_.Now(), 1000, NOT_RETRANSMISSION); |
| 66 // Ack the packet we sent. | 68 // Ack the packet we sent. |
| 67 ack.received_info.largest_observed = i; | 69 ack.received_info.largest_observed = i; |
| 68 manager_->OnIncomingAckFrame(ack, clock_.Now()); | 70 manager_->OnIncomingAckFrame(ack, clock_.Now()); |
| 69 } | 71 } |
| 70 EXPECT_EQ(100, manager_->BandwidthEstimate().ToKBytesPerSecond()); | 72 EXPECT_EQ(100, manager_->BandwidthEstimate().ToKBytesPerSecond()); |
| 71 EXPECT_NEAR(100, | 73 EXPECT_NEAR(100, |
| 72 manager_->SentBandwidth(clock_.Now()).ToKBytesPerSecond(), 4); | 74 InterArrivalSender::CalculateSentBandwidth( |
| 75 manager_->packet_history_map(), |
| 76 clock_.Now()).ToKBytesPerSecond(), |
| 77 4); |
| 73 } | 78 } |
| 74 | 79 |
| 75 TEST_F(QuicCongestionManagerTest, BandwidthWith1SecondGap) { | 80 TEST_F(QuicCongestionManagerTest, BandwidthWith1SecondGap) { |
| 76 SetUpCongestionType(kFixRate); | 81 SetUpCongestionType(kFixRate); |
| 77 QuicAckFrame ack; | 82 QuicAckFrame ack; |
| 78 manager_->OnIncomingAckFrame(ack, clock_.Now()); | 83 manager_->OnIncomingAckFrame(ack, clock_.Now()); |
| 79 | 84 |
| 80 QuicCongestionFeedbackFrame feedback; | 85 QuicCongestionFeedbackFrame feedback; |
| 81 feedback.type = kFixRate; | 86 feedback.type = kFixRate; |
| 82 feedback.fix_rate.bitrate = QuicBandwidth::FromKBytesPerSecond(100); | 87 feedback.fix_rate.bitrate = QuicBandwidth::FromKBytesPerSecond(100); |
| 83 manager_->OnIncomingQuicCongestionFeedbackFrame(feedback, clock_.Now()); | 88 manager_->OnIncomingQuicCongestionFeedbackFrame(feedback, clock_.Now()); |
| 84 | 89 |
| 85 for (QuicPacketSequenceNumber sequence_number = 1; sequence_number <= 100; | 90 for (QuicPacketSequenceNumber sequence_number = 1; sequence_number <= 100; |
| 86 ++sequence_number) { | 91 ++sequence_number) { |
| 87 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(10)); | 92 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(10)); |
| 88 EXPECT_TRUE(manager_->TimeUntilSend( | 93 EXPECT_TRUE(manager_->TimeUntilSend( |
| 89 clock_.Now(), NOT_RETRANSMISSION, kIgnored).IsZero()); | 94 clock_.Now(), NOT_RETRANSMISSION, kIgnored).IsZero()); |
| 90 manager_->SentPacket( | 95 manager_->SentPacket( |
| 91 sequence_number, clock_.Now(), 1000, NOT_RETRANSMISSION); | 96 sequence_number, clock_.Now(), 1000, NOT_RETRANSMISSION); |
| 92 // Ack the packet we sent. | 97 // Ack the packet we sent. |
| 93 ack.received_info.largest_observed = sequence_number; | 98 ack.received_info.largest_observed = sequence_number; |
| 94 manager_->OnIncomingAckFrame(ack, clock_.Now()); | 99 manager_->OnIncomingAckFrame(ack, clock_.Now()); |
| 95 } | 100 } |
| 96 EXPECT_EQ(100000, manager_->BandwidthEstimate().ToBytesPerSecond()); | 101 EXPECT_EQ(100000, manager_->BandwidthEstimate().ToBytesPerSecond()); |
| 97 EXPECT_NEAR(100000, | 102 EXPECT_NEAR(100000, |
| 98 manager_->SentBandwidth(clock_.Now()).ToBytesPerSecond(), 2000); | 103 InterArrivalSender::CalculateSentBandwidth( |
| 104 manager_->packet_history_map(), |
| 105 clock_.Now()).ToBytesPerSecond(), |
| 106 2000); |
| 99 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(500)); | 107 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(500)); |
| 100 EXPECT_NEAR(50000, | 108 EXPECT_NEAR(50000, |
| 101 manager_->SentBandwidth(clock_.Now()).ToBytesPerSecond(), 1000); | 109 InterArrivalSender::CalculateSentBandwidth( |
| 110 manager_->packet_history_map(), |
| 111 clock_.Now()).ToBytesPerSecond(), |
| 112 1000); |
| 102 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(501)); | 113 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(501)); |
| 103 EXPECT_NEAR(100000, manager_->BandwidthEstimate().ToBytesPerSecond(), 2000); | 114 EXPECT_NEAR(100000, manager_->BandwidthEstimate().ToBytesPerSecond(), 2000); |
| 104 EXPECT_TRUE(manager_->SentBandwidth(clock_.Now()).IsZero()); | 115 EXPECT_TRUE(InterArrivalSender::CalculateSentBandwidth( |
| 116 manager_->packet_history_map(), |
| 117 clock_.Now()).IsZero()); |
| 105 for (int i = 1; i <= 150; ++i) { | 118 for (int i = 1; i <= 150; ++i) { |
| 106 EXPECT_TRUE(manager_->TimeUntilSend( | 119 EXPECT_TRUE(manager_->TimeUntilSend( |
| 107 clock_.Now(), NOT_RETRANSMISSION, kIgnored).IsZero()); | 120 clock_.Now(), NOT_RETRANSMISSION, kIgnored).IsZero()); |
| 108 manager_->SentPacket(i + 100, clock_.Now(), 1000, NOT_RETRANSMISSION); | 121 manager_->SentPacket(i + 100, clock_.Now(), 1000, NOT_RETRANSMISSION); |
| 109 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(10)); | 122 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(10)); |
| 110 // Ack the packet we sent. | 123 // Ack the packet we sent. |
| 111 ack.received_info.largest_observed = i + 100; | 124 ack.received_info.largest_observed = i + 100; |
| 112 manager_->OnIncomingAckFrame(ack, clock_.Now()); | 125 manager_->OnIncomingAckFrame(ack, clock_.Now()); |
| 113 } | 126 } |
| 114 EXPECT_EQ(100, manager_->BandwidthEstimate().ToKBytesPerSecond()); | 127 EXPECT_EQ(100, manager_->BandwidthEstimate().ToKBytesPerSecond()); |
| 115 EXPECT_NEAR(100, | 128 EXPECT_NEAR(100, |
| 116 manager_->SentBandwidth(clock_.Now()).ToKBytesPerSecond(), 2); | 129 InterArrivalSender::CalculateSentBandwidth( |
| 130 manager_->packet_history_map(), |
| 131 clock_.Now()).ToKBytesPerSecond(), |
| 132 2); |
| 117 } | 133 } |
| 118 | 134 |
| 119 TEST_F(QuicCongestionManagerTest, Rtt) { | 135 TEST_F(QuicCongestionManagerTest, Rtt) { |
| 120 SetUpCongestionType(kFixRate); | 136 SetUpCongestionType(kFixRate); |
| 121 | 137 |
| 122 MockSendAlgorithm* send_algorithm = new StrictMock<MockSendAlgorithm>; | 138 MockSendAlgorithm* send_algorithm = new StrictMock<MockSendAlgorithm>; |
| 123 manager_->SetSendAlgorithm(send_algorithm); | 139 manager_->SetSendAlgorithm(send_algorithm); |
| 124 | 140 |
| 125 QuicPacketSequenceNumber sequence_number = 1; | 141 QuicPacketSequenceNumber sequence_number = 1; |
| 126 QuicTime::Delta expected_rtt = QuicTime::Delta::FromMilliseconds(15); | 142 QuicTime::Delta expected_rtt = QuicTime::Delta::FromMilliseconds(15); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 | 227 |
| 212 QuicAckFrame ack; | 228 QuicAckFrame ack; |
| 213 ack.received_info.largest_observed = sequence_number; | 229 ack.received_info.largest_observed = sequence_number; |
| 214 ack.received_info.delta_time_largest_observed = QuicTime::Delta::Zero(); | 230 ack.received_info.delta_time_largest_observed = QuicTime::Delta::Zero(); |
| 215 manager_->OnIncomingAckFrame(ack, clock_.Now()); | 231 manager_->OnIncomingAckFrame(ack, clock_.Now()); |
| 216 EXPECT_EQ(manager_->rtt(), expected_rtt); | 232 EXPECT_EQ(manager_->rtt(), expected_rtt); |
| 217 } | 233 } |
| 218 | 234 |
| 219 } // namespace test | 235 } // namespace test |
| 220 } // namespace net | 236 } // namespace net |
| OLD | NEW |