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

Side by Side Diff: net/quic/congestion_control/tcp_cubic_sender_test.cc

Issue 14816006: Land Recent QUIC changes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added missing NET_PRIVATE_EXPORT to QuicWallTime Created 7 years, 7 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
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 "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/tcp_cubic_sender.h" 7 #include "net/quic/congestion_control/tcp_cubic_sender.h"
8 #include "net/quic/congestion_control/tcp_receiver.h" 8 #include "net/quic/congestion_control/tcp_receiver.h"
9 #include "net/quic/test_tools/mock_clock.h" 9 #include "net/quic/test_tools/mock_clock.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 26 matching lines...) Expand all
37 } 37 }
38 void SendAvailableCongestionWindow() { 38 void SendAvailableCongestionWindow() {
39 QuicByteCount bytes_to_send = sender_->AvailableCongestionWindow(); 39 QuicByteCount bytes_to_send = sender_->AvailableCongestionWindow();
40 while (bytes_to_send > 0) { 40 while (bytes_to_send > 0) {
41 QuicByteCount bytes_in_packet = std::min(kMaxPacketSize, bytes_to_send); 41 QuicByteCount bytes_in_packet = std::min(kMaxPacketSize, bytes_to_send);
42 sender_->SentPacket(clock_.Now(), sequence_number_++, bytes_in_packet, 42 sender_->SentPacket(clock_.Now(), sequence_number_++, bytes_in_packet,
43 NOT_RETRANSMISSION); 43 NOT_RETRANSMISSION);
44 bytes_to_send -= bytes_in_packet; 44 bytes_to_send -= bytes_in_packet;
45 if (bytes_to_send > 0) { 45 if (bytes_to_send > 0) {
46 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), NOT_RETRANSMISSION, 46 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), NOT_RETRANSMISSION,
47 NO_RETRANSMITTABLE_DATA).IsZero()); 47 HAS_RETRANSMITTABLE_DATA).IsZero());
48 } 48 }
49 } 49 }
50 } 50 }
51 // Normal is that TCP acks every other segment. 51 // Normal is that TCP acks every other segment.
52 void AckNPackets(int n) { 52 void AckNPackets(int n) {
53 for (int i = 0; i < n; ++i) { 53 for (int i = 0; i < n; ++i) {
54 acked_sequence_number_++; 54 acked_sequence_number_++;
55 sender_->OnIncomingAck(acked_sequence_number_, kMaxPacketSize, rtt_); 55 sender_->OnIncomingAck(acked_sequence_number_, kMaxPacketSize, rtt_);
56 } 56 }
57 clock_.AdvanceTime(one_ms_); // 1 millisecond. 57 clock_.AdvanceTime(one_ms_); // 1 millisecond.
(...skipping 10 matching lines...) Expand all
68 QuicPacketSequenceNumber acked_sequence_number_; 68 QuicPacketSequenceNumber acked_sequence_number_;
69 }; 69 };
70 70
71 TEST_F(TcpCubicSenderTest, SimpleSender) { 71 TEST_F(TcpCubicSenderTest, SimpleSender) {
72 QuicCongestionFeedbackFrame feedback; 72 QuicCongestionFeedbackFrame feedback;
73 // At startup make sure we are at the default. 73 // At startup make sure we are at the default.
74 EXPECT_EQ(kDefaultWindowTCP, 74 EXPECT_EQ(kDefaultWindowTCP,
75 sender_->AvailableCongestionWindow()); 75 sender_->AvailableCongestionWindow());
76 // At startup make sure we can send. 76 // At startup make sure we can send.
77 EXPECT_TRUE(sender_->TimeUntilSend( 77 EXPECT_TRUE(sender_->TimeUntilSend(
78 clock_.Now(), NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA).IsZero()); 78 clock_.Now(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA).IsZero());
79 // Get default QuicCongestionFeedbackFrame from receiver. 79 // Get default QuicCongestionFeedbackFrame from receiver.
80 ASSERT_TRUE(receiver_->GenerateCongestionFeedback(&feedback)); 80 ASSERT_TRUE(receiver_->GenerateCongestionFeedback(&feedback));
81 sender_->OnIncomingQuicCongestionFeedbackFrame(feedback, clock_.Now(), 81 sender_->OnIncomingQuicCongestionFeedbackFrame(feedback, clock_.Now(),
82 fake_bandwidth_, not_used_); 82 fake_bandwidth_, not_used_);
83 // Make sure we can send. 83 // Make sure we can send.
84 EXPECT_TRUE(sender_->TimeUntilSend( 84 EXPECT_TRUE(sender_->TimeUntilSend(
85 clock_.Now(), NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA).IsZero()); 85 clock_.Now(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA).IsZero());
86 // And that window is un-affected. 86 // And that window is un-affected.
87 EXPECT_EQ(kDefaultWindowTCP, sender_->AvailableCongestionWindow()); 87 EXPECT_EQ(kDefaultWindowTCP, sender_->AvailableCongestionWindow());
88 88
89 // A retransmitt should always retun 0. 89 // A retransmitt should always retun 0.
90 EXPECT_TRUE(sender_->TimeUntilSend( 90 EXPECT_TRUE(sender_->TimeUntilSend(
91 clock_.Now(), IS_RETRANSMISSION, NO_RETRANSMITTABLE_DATA).IsZero()); 91 clock_.Now(), IS_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA).IsZero());
92 } 92 }
93 93
94 TEST_F(TcpCubicSenderTest, ExponentialSlowStart) { 94 TEST_F(TcpCubicSenderTest, ExponentialSlowStart) {
95 const int kNumberOfAck = 20; 95 const int kNumberOfAck = 20;
96 QuicCongestionFeedbackFrame feedback; 96 QuicCongestionFeedbackFrame feedback;
97 // At startup make sure we can send. 97 // At startup make sure we can send.
98 EXPECT_TRUE(sender_->TimeUntilSend( 98 EXPECT_TRUE(sender_->TimeUntilSend(
99 clock_.Now(), NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA).IsZero()); 99 clock_.Now(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA).IsZero());
100 // Get default QuicCongestionFeedbackFrame from receiver. 100 // Get default QuicCongestionFeedbackFrame from receiver.
101 ASSERT_TRUE(receiver_->GenerateCongestionFeedback(&feedback)); 101 ASSERT_TRUE(receiver_->GenerateCongestionFeedback(&feedback));
102 sender_->OnIncomingQuicCongestionFeedbackFrame(feedback, clock_.Now(), 102 sender_->OnIncomingQuicCongestionFeedbackFrame(feedback, clock_.Now(),
103 fake_bandwidth_, not_used_); 103 fake_bandwidth_, not_used_);
104 // Make sure we can send. 104 // Make sure we can send.
105 EXPECT_TRUE(sender_->TimeUntilSend( 105 EXPECT_TRUE(sender_->TimeUntilSend(
106 clock_.Now(), NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA).IsZero()); 106 clock_.Now(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA).IsZero());
107 107
108 for (int n = 0; n < kNumberOfAck; ++n) { 108 for (int n = 0; n < kNumberOfAck; ++n) {
109 // Send our full congestion window. 109 // Send our full congestion window.
110 SendAvailableCongestionWindow(); 110 SendAvailableCongestionWindow();
111 AckNPackets(2); 111 AckNPackets(2);
112 } 112 }
113 QuicByteCount bytes_to_send = sender_->CongestionWindow(); 113 QuicByteCount bytes_to_send = sender_->CongestionWindow();
114 EXPECT_EQ(kDefaultWindowTCP + kMaxPacketSize * 2 * kNumberOfAck, 114 EXPECT_EQ(kDefaultWindowTCP + kMaxPacketSize * 2 * kNumberOfAck,
115 bytes_to_send); 115 bytes_to_send);
116 } 116 }
117 117
118 TEST_F(TcpCubicSenderTest, SlowStartAckTrain) { 118 TEST_F(TcpCubicSenderTest, SlowStartAckTrain) {
119 // Make sure that we fall out of slow start when we send ACK train longer 119 // Make sure that we fall out of slow start when we send ACK train longer
120 // than half the RTT, in this test case 30ms, which is more than 30 calls to 120 // than half the RTT, in this test case 30ms, which is more than 30 calls to
121 // Ack2Packets in one round. 121 // Ack2Packets in one round.
122 // Since we start at 10 packet first round will be 5 second round 10 etc 122 // Since we start at 10 packet first round will be 5 second round 10 etc
123 // Hence we should pass 30 at 65 = 5 + 10 + 20 + 30 123 // Hence we should pass 30 at 65 = 5 + 10 + 20 + 30
124 const int kNumberOfAck = 65; 124 const int kNumberOfAck = 65;
125 QuicCongestionFeedbackFrame feedback; 125 QuicCongestionFeedbackFrame feedback;
126 // At startup make sure we can send. 126 // At startup make sure we can send.
127 EXPECT_TRUE(sender_->TimeUntilSend( 127 EXPECT_TRUE(sender_->TimeUntilSend(
128 clock_.Now(), NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA).IsZero()); 128 clock_.Now(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA).IsZero());
129 // Get default QuicCongestionFeedbackFrame from receiver. 129 // Get default QuicCongestionFeedbackFrame from receiver.
130 ASSERT_TRUE(receiver_->GenerateCongestionFeedback(&feedback)); 130 ASSERT_TRUE(receiver_->GenerateCongestionFeedback(&feedback));
131 sender_->OnIncomingQuicCongestionFeedbackFrame(feedback, clock_.Now(), 131 sender_->OnIncomingQuicCongestionFeedbackFrame(feedback, clock_.Now(),
132 fake_bandwidth_, not_used_); 132 fake_bandwidth_, not_used_);
133 // Make sure we can send. 133 // Make sure we can send.
134 EXPECT_TRUE(sender_->TimeUntilSend( 134 EXPECT_TRUE(sender_->TimeUntilSend(
135 clock_.Now(), NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA).IsZero()); 135 clock_.Now(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA).IsZero());
136 136
137 for (int n = 0; n < kNumberOfAck; ++n) { 137 for (int n = 0; n < kNumberOfAck; ++n) {
138 // Send our full congestion window. 138 // Send our full congestion window.
139 SendAvailableCongestionWindow(); 139 SendAvailableCongestionWindow();
140 AckNPackets(2); 140 AckNPackets(2);
141 } 141 }
142 QuicByteCount expected_congestion_window = kDefaultWindowTCP + 142 QuicByteCount expected_congestion_window = kDefaultWindowTCP +
143 (kMaxPacketSize * 2 * kNumberOfAck); 143 (kMaxPacketSize * 2 * kNumberOfAck);
144 EXPECT_EQ(expected_congestion_window, sender_->CongestionWindow()); 144 EXPECT_EQ(expected_congestion_window, sender_->CongestionWindow());
145 // We should now have fallen out of slow start. 145 // We should now have fallen out of slow start.
(...skipping 15 matching lines...) Expand all
161 expected_congestion_window += kMaxPacketSize; 161 expected_congestion_window += kMaxPacketSize;
162 EXPECT_EQ(expected_congestion_window, sender_->CongestionWindow()); 162 EXPECT_EQ(expected_congestion_window, sender_->CongestionWindow());
163 } 163 }
164 164
165 TEST_F(TcpCubicSenderTest, SlowStartPacketLoss) { 165 TEST_F(TcpCubicSenderTest, SlowStartPacketLoss) {
166 // Make sure that we fall out of slow start when we encounter a packet loss. 166 // Make sure that we fall out of slow start when we encounter a packet loss.
167 const int kNumberOfAck = 10; 167 const int kNumberOfAck = 10;
168 QuicCongestionFeedbackFrame feedback; 168 QuicCongestionFeedbackFrame feedback;
169 // At startup make sure we can send. 169 // At startup make sure we can send.
170 EXPECT_TRUE(sender_->TimeUntilSend( 170 EXPECT_TRUE(sender_->TimeUntilSend(
171 clock_.Now(), NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA).IsZero()); 171 clock_.Now(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA).IsZero());
172 // Get default QuicCongestionFeedbackFrame from receiver. 172 // Get default QuicCongestionFeedbackFrame from receiver.
173 ASSERT_TRUE(receiver_->GenerateCongestionFeedback(&feedback)); 173 ASSERT_TRUE(receiver_->GenerateCongestionFeedback(&feedback));
174 sender_->OnIncomingQuicCongestionFeedbackFrame(feedback, clock_.Now(), 174 sender_->OnIncomingQuicCongestionFeedbackFrame(feedback, clock_.Now(),
175 fake_bandwidth_, not_used_); 175 fake_bandwidth_, not_used_);
176 // Make sure we can send. 176 // Make sure we can send.
177 EXPECT_TRUE(sender_->TimeUntilSend( 177 EXPECT_TRUE(sender_->TimeUntilSend(
178 clock_.Now(), NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA).IsZero()); 178 clock_.Now(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA).IsZero());
179 179
180 for (int i = 0; i < kNumberOfAck; ++i) { 180 for (int i = 0; i < kNumberOfAck; ++i) {
181 // Send our full congestion window. 181 // Send our full congestion window.
182 SendAvailableCongestionWindow(); 182 SendAvailableCongestionWindow();
183 AckNPackets(2); 183 AckNPackets(2);
184 } 184 }
185 SendAvailableCongestionWindow(); 185 SendAvailableCongestionWindow();
186 QuicByteCount expected_congestion_window = kDefaultWindowTCP + 186 QuicByteCount expected_congestion_window = kDefaultWindowTCP +
187 (kMaxPacketSize * 2 * kNumberOfAck); 187 (kMaxPacketSize * 2 * kNumberOfAck);
188 EXPECT_EQ(expected_congestion_window, sender_->CongestionWindow()); 188 EXPECT_EQ(expected_congestion_window, sender_->CongestionWindow());
189 189
190 sender_->OnIncomingLoss(clock_.Now()); 190 sender_->OnIncomingLoss(clock_.Now());
191 191
192 // Make sure that we should not send right now. 192 // Make sure that we should not send right now.
193 EXPECT_TRUE(sender_->TimeUntilSend( 193 EXPECT_TRUE(sender_->TimeUntilSend(
194 clock_.Now(), NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA).IsInfinite()); 194 clock_.Now(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA).IsInfinite());
195 195
196 // We should now have fallen out of slow start. 196 // We should now have fallen out of slow start.
197 // We expect window to be cut in half. 197 // We expect window to be cut in half.
198 expected_congestion_window /= 2; 198 expected_congestion_window /= 2;
199 EXPECT_EQ(expected_congestion_window, sender_->CongestionWindow()); 199 EXPECT_EQ(expected_congestion_window, sender_->CongestionWindow());
200 200
201 // Testing Reno phase. 201 // Testing Reno phase.
202 // We need to ack half of the pending packet before we can send agin. 202 // We need to ack half of the pending packet before we can send agin.
203 int number_of_packets_in_window = expected_congestion_window / kMaxPacketSize; 203 int number_of_packets_in_window = expected_congestion_window / kMaxPacketSize;
204 AckNPackets(number_of_packets_in_window); 204 AckNPackets(number_of_packets_in_window);
(...skipping 13 matching lines...) Expand all
218 EXPECT_EQ(expected_congestion_window, sender_->CongestionWindow()); 218 EXPECT_EQ(expected_congestion_window, sender_->CongestionWindow());
219 } 219 }
220 SendAvailableCongestionWindow(); 220 SendAvailableCongestionWindow();
221 AckNPackets(1); 221 AckNPackets(1);
222 expected_congestion_window += kMaxPacketSize; 222 expected_congestion_window += kMaxPacketSize;
223 EXPECT_EQ(expected_congestion_window, sender_->CongestionWindow()); 223 EXPECT_EQ(expected_congestion_window, sender_->CongestionWindow());
224 } 224 }
225 225
226 } // namespace test 226 } // namespace test
227 } // namespace net 227 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/congestion_control/tcp_cubic_sender.cc ('k') | net/quic/crypto/aes_128_gcm_decrypter_openssl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698