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

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

Issue 131743009: Land Recent QUIC Changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use size_t instead of int to fix win_x64 compile error Created 6 years, 11 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
« no previous file with comments | « net/quic/congestion_control/tcp_cubic_sender.cc ('k') | net/quic/crypto/crypto_server_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <algorithm> 5 #include <algorithm>
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "net/quic/congestion_control/tcp_cubic_sender.h" 9 #include "net/quic/congestion_control/tcp_cubic_sender.h"
10 #include "net/quic/congestion_control/tcp_receiver.h" 10 #include "net/quic/congestion_control/tcp_receiver.h"
(...skipping 17 matching lines...) Expand all
28 QuicTcpCongestionWindow max_tcp_congestion_window) 28 QuicTcpCongestionWindow max_tcp_congestion_window)
29 : TcpCubicSender(clock, reno, max_tcp_congestion_window) { 29 : TcpCubicSender(clock, reno, max_tcp_congestion_window) {
30 } 30 }
31 31
32 QuicTcpCongestionWindow congestion_window() { 32 QuicTcpCongestionWindow congestion_window() {
33 return congestion_window_; 33 return congestion_window_;
34 } 34 }
35 35
36 using TcpCubicSender::AvailableSendWindow; 36 using TcpCubicSender::AvailableSendWindow;
37 using TcpCubicSender::SendWindow; 37 using TcpCubicSender::SendWindow;
38 using TcpCubicSender::AckAccounting;
39 }; 38 };
40 39
41 class TcpCubicSenderTest : public ::testing::Test { 40 class TcpCubicSenderTest : public ::testing::Test {
42 protected: 41 protected:
43 TcpCubicSenderTest() 42 TcpCubicSenderTest()
44 : rtt_(QuicTime::Delta::FromMilliseconds(60)), 43 : one_ms_(QuicTime::Delta::FromMilliseconds(1)),
45 one_ms_(QuicTime::Delta::FromMilliseconds(1)),
46 sender_(new TcpCubicSenderPeer(&clock_, true, 44 sender_(new TcpCubicSenderPeer(&clock_, true,
47 kDefaultMaxCongestionWindowTCP)), 45 kDefaultMaxCongestionWindowTCP)),
48 receiver_(new TcpReceiver()), 46 receiver_(new TcpReceiver()),
49 sequence_number_(1), 47 sequence_number_(1),
50 acked_sequence_number_(0) { 48 acked_sequence_number_(0) {
51 } 49 }
52 50
53 void SendAvailableSendWindow() { 51 void SendAvailableSendWindow() {
54 QuicByteCount bytes_to_send = sender_->AvailableSendWindow(); 52 QuicByteCount bytes_to_send = sender_->AvailableSendWindow();
55 while (bytes_to_send > 0) { 53 while (bytes_to_send > 0) {
56 QuicByteCount bytes_in_packet = min(kDefaultTCPMSS, bytes_to_send); 54 QuicByteCount bytes_in_packet = min(kDefaultTCPMSS, bytes_to_send);
57 sender_->OnPacketSent(clock_.Now(), sequence_number_++, bytes_in_packet, 55 sender_->OnPacketSent(clock_.Now(), sequence_number_++, bytes_in_packet,
58 NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA); 56 NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA);
59 bytes_to_send -= bytes_in_packet; 57 bytes_to_send -= bytes_in_packet;
60 if (bytes_to_send > 0) { 58 if (bytes_to_send > 0) {
61 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), NOT_RETRANSMISSION, 59 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), NOT_RETRANSMISSION,
62 HAS_RETRANSMITTABLE_DATA, NOT_HANDSHAKE).IsZero()); 60 HAS_RETRANSMITTABLE_DATA, NOT_HANDSHAKE).IsZero());
63 } 61 }
64 } 62 }
65 } 63 }
66 // Normal is that TCP acks every other segment. 64 // Normal is that TCP acks every other segment.
67 void AckNPackets(int n) { 65 void AckNPackets(int n) {
68 for (int i = 0; i < n; ++i) { 66 for (int i = 0; i < n; ++i) {
69 acked_sequence_number_++; 67 acked_sequence_number_++;
70 sender_->OnPacketAcked(acked_sequence_number_, kDefaultTCPMSS, rtt_); 68 sender_->UpdateRtt(QuicTime::Delta::FromMilliseconds(60));
69 sender_->OnPacketAcked(acked_sequence_number_, kDefaultTCPMSS);
71 } 70 }
72 clock_.AdvanceTime(one_ms_); // 1 millisecond. 71 clock_.AdvanceTime(one_ms_); // 1 millisecond.
73 } 72 }
74 73
75 const QuicTime::Delta rtt_;
76 const QuicTime::Delta one_ms_; 74 const QuicTime::Delta one_ms_;
77 MockClock clock_; 75 MockClock clock_;
78 SendAlgorithmInterface::SentPacketsMap not_used_; 76 SendAlgorithmInterface::SentPacketsMap not_used_;
79 scoped_ptr<TcpCubicSenderPeer> sender_; 77 scoped_ptr<TcpCubicSenderPeer> sender_;
80 scoped_ptr<TcpReceiver> receiver_; 78 scoped_ptr<TcpReceiver> receiver_;
81 QuicPacketSequenceNumber sequence_number_; 79 QuicPacketSequenceNumber sequence_number_;
82 QuicPacketSequenceNumber acked_sequence_number_; 80 QuicPacketSequenceNumber acked_sequence_number_;
83 }; 81 };
84 82
85 TEST_F(TcpCubicSenderTest, SimpleSender) { 83 TEST_F(TcpCubicSenderTest, SimpleSender) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 149
152 for (int n = 0; n < kNumberOfAck; ++n) { 150 for (int n = 0; n < kNumberOfAck; ++n) {
153 // Send our full send window. 151 // Send our full send window.
154 SendAvailableSendWindow(); 152 SendAvailableSendWindow();
155 AckNPackets(2); 153 AckNPackets(2);
156 } 154 }
157 QuicByteCount expected_send_window = 155 QuicByteCount expected_send_window =
158 kDefaultWindowTCP + (kDefaultTCPMSS * 2 * kNumberOfAck); 156 kDefaultWindowTCP + (kDefaultTCPMSS * 2 * kNumberOfAck);
159 EXPECT_EQ(expected_send_window, sender_->SendWindow()); 157 EXPECT_EQ(expected_send_window, sender_->SendWindow());
160 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); 158 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow());
159
161 // We should now have fallen out of slow start. 160 // We should now have fallen out of slow start.
162 SendAvailableSendWindow();
163 AckNPackets(2);
164 expected_send_window += kDefaultTCPMSS;
165 EXPECT_EQ(expected_send_window, sender_->SendWindow());
166
167 // Testing Reno phase. 161 // Testing Reno phase.
168 // We should need 141(65*2+1+10) ACK:ed packets before increasing window by 162 // We should need 141(65*2+1+10) ACK:ed packets before increasing window by
169 // one. 163 // one.
170 for (int m = 0; m < 70; ++m) { 164 for (int m = 0; m < 70; ++m) {
171 SendAvailableSendWindow(); 165 SendAvailableSendWindow();
172 AckNPackets(2); 166 AckNPackets(2);
173 EXPECT_EQ(expected_send_window, sender_->SendWindow()); 167 EXPECT_EQ(expected_send_window, sender_->SendWindow());
174 } 168 }
175 SendAvailableSendWindow(); 169 SendAvailableSendWindow();
176 AckNPackets(2); 170 AckNPackets(2);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 // packets are retransmitted. 248 // packets are retransmitted.
255 sender_->OnRetransmissionTimeout(false); 249 sender_->OnRetransmissionTimeout(false);
256 EXPECT_EQ(kDefaultWindowTCP, sender_->SendWindow()); 250 EXPECT_EQ(kDefaultWindowTCP, sender_->SendWindow());
257 } 251 }
258 252
259 TEST_F(TcpCubicSenderTest, RetransmissionDelay) { 253 TEST_F(TcpCubicSenderTest, RetransmissionDelay) {
260 const int64 kRttMs = 10; 254 const int64 kRttMs = 10;
261 const int64 kDeviationMs = 3; 255 const int64 kDeviationMs = 3;
262 EXPECT_EQ(QuicTime::Delta::Zero(), sender_->RetransmissionDelay()); 256 EXPECT_EQ(QuicTime::Delta::Zero(), sender_->RetransmissionDelay());
263 257
264 sender_->AckAccounting(QuicTime::Delta::FromMilliseconds(kRttMs)); 258 sender_->UpdateRtt(QuicTime::Delta::FromMilliseconds(kRttMs));
265 259
266 // Initial value is to set the median deviation to half of the initial 260 // Initial value is to set the median deviation to half of the initial
267 // rtt, the median in then multiplied by a factor of 4 and finally the 261 // rtt, the median in then multiplied by a factor of 4 and finally the
268 // smoothed rtt is added which is the initial rtt. 262 // smoothed rtt is added which is the initial rtt.
269 QuicTime::Delta expected_delay = 263 QuicTime::Delta expected_delay =
270 QuicTime::Delta::FromMilliseconds(kRttMs + kRttMs / 2 * 4); 264 QuicTime::Delta::FromMilliseconds(kRttMs + kRttMs / 2 * 4);
271 EXPECT_EQ(expected_delay, sender_->RetransmissionDelay()); 265 EXPECT_EQ(expected_delay, sender_->RetransmissionDelay());
272 266
273 for (int i = 0; i < 100; ++i) { 267 for (int i = 0; i < 100; ++i) {
274 // Run to make sure that we converge. 268 // Run to make sure that we converge.
275 sender_->AckAccounting( 269 sender_->UpdateRtt(
276 QuicTime::Delta::FromMilliseconds(kRttMs + kDeviationMs)); 270 QuicTime::Delta::FromMilliseconds(kRttMs + kDeviationMs));
277 sender_->AckAccounting( 271 sender_->UpdateRtt(
278 QuicTime::Delta::FromMilliseconds(kRttMs - kDeviationMs)); 272 QuicTime::Delta::FromMilliseconds(kRttMs - kDeviationMs));
279 } 273 }
280 expected_delay = QuicTime::Delta::FromMilliseconds(kRttMs + kDeviationMs * 4); 274 expected_delay = QuicTime::Delta::FromMilliseconds(kRttMs + kDeviationMs * 4);
281 275
282 EXPECT_NEAR(kRttMs, sender_->SmoothedRtt().ToMilliseconds(), 1); 276 EXPECT_NEAR(kRttMs, sender_->SmoothedRtt().ToMilliseconds(), 1);
283 EXPECT_NEAR(expected_delay.ToMilliseconds(), 277 EXPECT_NEAR(expected_delay.ToMilliseconds(),
284 sender_->RetransmissionDelay().ToMilliseconds(), 278 sender_->RetransmissionDelay().ToMilliseconds(),
285 1); 279 1);
286 EXPECT_EQ(static_cast<int64>( 280 EXPECT_EQ(static_cast<int64>(
287 sender_->GetCongestionWindow() * kNumMicrosPerSecond / 281 sender_->GetCongestionWindow() * kNumMicrosPerSecond /
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 config.set_server_initial_congestion_window(2 * congestion_window, 418 config.set_server_initial_congestion_window(2 * congestion_window,
425 2 * congestion_window); 419 2 * congestion_window);
426 EXPECT_EQ(2 * congestion_window, config.server_initial_congestion_window()); 420 EXPECT_EQ(2 * congestion_window, config.server_initial_congestion_window());
427 421
428 sender_->SetFromConfig(config, true); 422 sender_->SetFromConfig(config, true);
429 EXPECT_EQ(2 * congestion_window, sender_->congestion_window()); 423 EXPECT_EQ(2 * congestion_window, sender_->congestion_window());
430 } 424 }
431 425
432 } // namespace test 426 } // namespace test
433 } // namespace net 427 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/congestion_control/tcp_cubic_sender.cc ('k') | net/quic/crypto/crypto_server_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698