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

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

Issue 12806002: Land Recent QUIC Changes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: minor comment fix Created 7 years, 9 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_framer.h » ('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 "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 22 matching lines...) Expand all
33 sender_(new TcpCubicSenderPeer(&clock_, true)), 33 sender_(new TcpCubicSenderPeer(&clock_, true)),
34 receiver_(new TcpReceiver()), 34 receiver_(new TcpReceiver()),
35 sequence_number_(1), 35 sequence_number_(1),
36 acked_sequence_number_(0) { 36 acked_sequence_number_(0) {
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 false, true); 43 false);
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(), false).IsZero()); 46 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), false, true).IsZero());
47 } 47 }
48 } 48 }
49 } 49 }
50 // Normal is that TCP acks every other segment. 50 // Normal is that TCP acks every other segment.
51 void AckNPackets(int n) { 51 void AckNPackets(int n) {
52 for (int i = 0; i < n; ++i) { 52 for (int i = 0; i < n; ++i) {
53 acked_sequence_number_++; 53 acked_sequence_number_++;
54 sender_->OnIncomingAck(acked_sequence_number_, kMaxPacketSize, rtt_); 54 sender_->OnIncomingAck(acked_sequence_number_, kMaxPacketSize, rtt_);
55 } 55 }
56 clock_.AdvanceTime(one_ms_); // 1 millisecond. 56 clock_.AdvanceTime(one_ms_); // 1 millisecond.
57 } 57 }
58 58
59 const QuicTime::Delta rtt_; 59 const QuicTime::Delta rtt_;
60 const QuicTime::Delta one_ms_; 60 const QuicTime::Delta one_ms_;
61 const QuicBandwidth fake_bandwidth_; 61 const QuicBandwidth fake_bandwidth_;
62 MockClock clock_; 62 MockClock clock_;
63 SendAlgorithmInterface::SentPacketsMap not_used_; 63 SendAlgorithmInterface::SentPacketsMap not_used_;
64 scoped_ptr<TcpCubicSenderPeer> sender_; 64 scoped_ptr<TcpCubicSenderPeer> sender_;
65 scoped_ptr<TcpReceiver> receiver_; 65 scoped_ptr<TcpReceiver> receiver_;
66 QuicPacketSequenceNumber sequence_number_; 66 QuicPacketSequenceNumber sequence_number_;
67 QuicPacketSequenceNumber acked_sequence_number_; 67 QuicPacketSequenceNumber acked_sequence_number_;
68 }; 68 };
69 69
70 TEST_F(TcpCubicSenderTest, SimpleSender) { 70 TEST_F(TcpCubicSenderTest, SimpleSender) {
71 QuicCongestionFeedbackFrame feedback; 71 QuicCongestionFeedbackFrame feedback;
72 // At startup make sure we are at the default. 72 // At startup make sure we are at the default.
73 EXPECT_EQ(kDefaultWindowTCP, 73 EXPECT_EQ(kDefaultWindowTCP,
74 sender_->AvailableCongestionWindow()); 74 sender_->AvailableCongestionWindow());
75 // At startup make sure we can send. 75 // At startup make sure we can send.
76 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), false).IsZero()); 76 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), false, true).IsZero());
77 // Get default QuicCongestionFeedbackFrame from receiver. 77 // Get default QuicCongestionFeedbackFrame from receiver.
78 ASSERT_TRUE(receiver_->GenerateCongestionFeedback(&feedback)); 78 ASSERT_TRUE(receiver_->GenerateCongestionFeedback(&feedback));
79 sender_->OnIncomingQuicCongestionFeedbackFrame(feedback, clock_.Now(), 79 sender_->OnIncomingQuicCongestionFeedbackFrame(feedback, clock_.Now(),
80 fake_bandwidth_, not_used_); 80 fake_bandwidth_, not_used_);
81 // Make sure we can send. 81 // Make sure we can send.
82 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), false).IsZero()); 82 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), false, true).IsZero());
83 // And that window is un-affected. 83 // And that window is un-affected.
84 EXPECT_EQ(kDefaultWindowTCP, sender_->AvailableCongestionWindow()); 84 EXPECT_EQ(kDefaultWindowTCP, sender_->AvailableCongestionWindow());
85 85
86 // A retransmitt should always retun 0. 86 // A retransmitt should always retun 0.
87 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), true).IsZero()); 87 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), true, true).IsZero());
88 } 88 }
89 89
90 TEST_F(TcpCubicSenderTest, ExponentialSlowStart) { 90 TEST_F(TcpCubicSenderTest, ExponentialSlowStart) {
91 const int kNumberOfAck = 20; 91 const int kNumberOfAck = 20;
92 QuicCongestionFeedbackFrame feedback; 92 QuicCongestionFeedbackFrame feedback;
93 // At startup make sure we can send. 93 // At startup make sure we can send.
94 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), false).IsZero()); 94 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), false, true).IsZero());
95 // Get default QuicCongestionFeedbackFrame from receiver. 95 // Get default QuicCongestionFeedbackFrame from receiver.
96 ASSERT_TRUE(receiver_->GenerateCongestionFeedback(&feedback)); 96 ASSERT_TRUE(receiver_->GenerateCongestionFeedback(&feedback));
97 sender_->OnIncomingQuicCongestionFeedbackFrame(feedback, clock_.Now(), 97 sender_->OnIncomingQuicCongestionFeedbackFrame(feedback, clock_.Now(),
98 fake_bandwidth_, not_used_); 98 fake_bandwidth_, not_used_);
99 // Make sure we can send. 99 // Make sure we can send.
100 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), false).IsZero()); 100 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), false, true).IsZero());
101 101
102 for (int n = 0; n < kNumberOfAck; ++n) { 102 for (int n = 0; n < kNumberOfAck; ++n) {
103 // Send our full congestion window. 103 // Send our full congestion window.
104 SendAvailableCongestionWindow(); 104 SendAvailableCongestionWindow();
105 AckNPackets(2); 105 AckNPackets(2);
106 } 106 }
107 QuicByteCount bytes_to_send = sender_->CongestionWindow(); 107 QuicByteCount bytes_to_send = sender_->CongestionWindow();
108 EXPECT_EQ(kDefaultWindowTCP + kMaxPacketSize * 2 * kNumberOfAck, 108 EXPECT_EQ(kDefaultWindowTCP + kMaxPacketSize * 2 * kNumberOfAck,
109 bytes_to_send); 109 bytes_to_send);
110 } 110 }
111 111
112 TEST_F(TcpCubicSenderTest, SlowStartAckTrain) { 112 TEST_F(TcpCubicSenderTest, SlowStartAckTrain) {
113 // Make sure that we fall out of slow start when we send ACK train longer 113 // Make sure that we fall out of slow start when we send ACK train longer
114 // than half the RTT, in this test case 30ms, which is more than 30 calls to 114 // than half the RTT, in this test case 30ms, which is more than 30 calls to
115 // Ack2Packets in one round. 115 // Ack2Packets in one round.
116 // Since we start at 10 packet first round will be 5 second round 10 etc 116 // Since we start at 10 packet first round will be 5 second round 10 etc
117 // Hence we should pass 30 at 65 = 5 + 10 + 20 + 30 117 // Hence we should pass 30 at 65 = 5 + 10 + 20 + 30
118 const int kNumberOfAck = 65; 118 const int kNumberOfAck = 65;
119 QuicCongestionFeedbackFrame feedback; 119 QuicCongestionFeedbackFrame feedback;
120 // At startup make sure we can send. 120 // At startup make sure we can send.
121 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), false).IsZero()); 121 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), false, true).IsZero());
122 // Get default QuicCongestionFeedbackFrame from receiver. 122 // Get default QuicCongestionFeedbackFrame from receiver.
123 ASSERT_TRUE(receiver_->GenerateCongestionFeedback(&feedback)); 123 ASSERT_TRUE(receiver_->GenerateCongestionFeedback(&feedback));
124 sender_->OnIncomingQuicCongestionFeedbackFrame(feedback, clock_.Now(), 124 sender_->OnIncomingQuicCongestionFeedbackFrame(feedback, clock_.Now(),
125 fake_bandwidth_, not_used_); 125 fake_bandwidth_, not_used_);
126 // Make sure we can send. 126 // Make sure we can send.
127 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), false).IsZero()); 127 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), false, true).IsZero());
128 128
129 for (int n = 0; n < kNumberOfAck; ++n) { 129 for (int n = 0; n < kNumberOfAck; ++n) {
130 // Send our full congestion window. 130 // Send our full congestion window.
131 SendAvailableCongestionWindow(); 131 SendAvailableCongestionWindow();
132 AckNPackets(2); 132 AckNPackets(2);
133 } 133 }
134 QuicByteCount expected_congestion_window = kDefaultWindowTCP + 134 QuicByteCount expected_congestion_window = kDefaultWindowTCP +
135 (kMaxPacketSize * 2 * kNumberOfAck); 135 (kMaxPacketSize * 2 * kNumberOfAck);
136 EXPECT_EQ(expected_congestion_window, sender_->CongestionWindow()); 136 EXPECT_EQ(expected_congestion_window, sender_->CongestionWindow());
137 // We should now have fallen out of slow start. 137 // We should now have fallen out of slow start.
(...skipping 14 matching lines...) Expand all
152 AckNPackets(2); 152 AckNPackets(2);
153 expected_congestion_window += kMaxPacketSize; 153 expected_congestion_window += kMaxPacketSize;
154 EXPECT_EQ(expected_congestion_window, sender_->CongestionWindow()); 154 EXPECT_EQ(expected_congestion_window, sender_->CongestionWindow());
155 } 155 }
156 156
157 TEST_F(TcpCubicSenderTest, SlowStartPacketLoss) { 157 TEST_F(TcpCubicSenderTest, SlowStartPacketLoss) {
158 // Make sure that we fall out of slow start when we encounter a packet loss. 158 // Make sure that we fall out of slow start when we encounter a packet loss.
159 const int kNumberOfAck = 10; 159 const int kNumberOfAck = 10;
160 QuicCongestionFeedbackFrame feedback; 160 QuicCongestionFeedbackFrame feedback;
161 // At startup make sure we can send. 161 // At startup make sure we can send.
162 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), false).IsZero()); 162 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), false, true).IsZero());
163 // Get default QuicCongestionFeedbackFrame from receiver. 163 // Get default QuicCongestionFeedbackFrame from receiver.
164 ASSERT_TRUE(receiver_->GenerateCongestionFeedback(&feedback)); 164 ASSERT_TRUE(receiver_->GenerateCongestionFeedback(&feedback));
165 sender_->OnIncomingQuicCongestionFeedbackFrame(feedback, clock_.Now(), 165 sender_->OnIncomingQuicCongestionFeedbackFrame(feedback, clock_.Now(),
166 fake_bandwidth_, not_used_); 166 fake_bandwidth_, not_used_);
167 // Make sure we can send. 167 // Make sure we can send.
168 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), false).IsZero()); 168 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), false, true).IsZero());
169 169
170 for (int i = 0; i < kNumberOfAck; ++i) { 170 for (int i = 0; i < kNumberOfAck; ++i) {
171 // Send our full congestion window. 171 // Send our full congestion window.
172 SendAvailableCongestionWindow(); 172 SendAvailableCongestionWindow();
173 AckNPackets(2); 173 AckNPackets(2);
174 } 174 }
175 SendAvailableCongestionWindow(); 175 SendAvailableCongestionWindow();
176 QuicByteCount expected_congestion_window = kDefaultWindowTCP + 176 QuicByteCount expected_congestion_window = kDefaultWindowTCP +
177 (kMaxPacketSize * 2 * kNumberOfAck); 177 (kMaxPacketSize * 2 * kNumberOfAck);
178 EXPECT_EQ(expected_congestion_window, sender_->CongestionWindow()); 178 EXPECT_EQ(expected_congestion_window, sender_->CongestionWindow());
179 179
180 sender_->OnIncomingLoss(clock_.Now()); 180 sender_->OnIncomingLoss(clock_.Now());
181 181
182 // Make sure that we should not send right now. 182 // Make sure that we should not send right now.
183 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), false).IsInfinite()); 183 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), false, true).IsInfinite());
184 184
185 // We should now have fallen out of slow start. 185 // We should now have fallen out of slow start.
186 // We expect window to be cut in half. 186 // We expect window to be cut in half.
187 expected_congestion_window /= 2; 187 expected_congestion_window /= 2;
188 EXPECT_EQ(expected_congestion_window, sender_->CongestionWindow()); 188 EXPECT_EQ(expected_congestion_window, sender_->CongestionWindow());
189 189
190 // Testing Reno phase. 190 // Testing Reno phase.
191 // We need to ack half of the pending packet before we can send agin. 191 // We need to ack half of the pending packet before we can send agin.
192 int number_of_packets_in_window = expected_congestion_window / kMaxPacketSize; 192 int number_of_packets_in_window = expected_congestion_window / kMaxPacketSize;
193 AckNPackets(number_of_packets_in_window); 193 AckNPackets(number_of_packets_in_window);
(...skipping 13 matching lines...) Expand all
207 EXPECT_EQ(expected_congestion_window, sender_->CongestionWindow()); 207 EXPECT_EQ(expected_congestion_window, sender_->CongestionWindow());
208 } 208 }
209 SendAvailableCongestionWindow(); 209 SendAvailableCongestionWindow();
210 AckNPackets(1); 210 AckNPackets(1);
211 expected_congestion_window += kMaxPacketSize; 211 expected_congestion_window += kMaxPacketSize;
212 EXPECT_EQ(expected_congestion_window, sender_->CongestionWindow()); 212 EXPECT_EQ(expected_congestion_window, sender_->CongestionWindow());
213 } 213 }
214 214
215 } // namespace test 215 } // namespace test
216 } // namespace net 216 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/congestion_control/tcp_cubic_sender.cc ('k') | net/quic/crypto/crypto_framer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698