OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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/congestion_control/tcp_cubic_bytes_sender.h" |
| 6 |
5 #include <algorithm> | 7 #include <algorithm> |
6 | 8 |
7 #include "base/logging.h" | 9 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
9 #include "net/quic/congestion_control/rtt_stats.h" | 11 #include "net/quic/congestion_control/rtt_stats.h" |
10 #include "net/quic/congestion_control/tcp_cubic_sender.h" | |
11 #include "net/quic/crypto/crypto_protocol.h" | 12 #include "net/quic/crypto/crypto_protocol.h" |
12 #include "net/quic/quic_protocol.h" | 13 #include "net/quic/quic_protocol.h" |
13 #include "net/quic/quic_utils.h" | 14 #include "net/quic/quic_utils.h" |
14 #include "net/quic/test_tools/mock_clock.h" | 15 #include "net/quic/test_tools/mock_clock.h" |
15 #include "net/quic/test_tools/quic_config_peer.h" | 16 #include "net/quic/test_tools/quic_config_peer.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 | 18 |
18 using std::min; | |
19 | |
20 namespace net { | 19 namespace net { |
21 namespace test { | 20 namespace test { |
22 | 21 |
23 // TODO(ianswett): A number of theses tests were written with the assumption of | 22 // TODO(ianswett): A number of theses tests were written with the assumption of |
24 // an initial CWND of 10. They have carefully calculated values which should be | 23 // an initial CWND of 10. They have carefully calculated values which should be |
25 // updated to be based on kInitialCongestionWindowInsecure. | 24 // updated to be based on kInitialCongestionWindowInsecure. |
26 const uint32 kInitialCongestionWindowPackets = 10; | 25 const uint32 kInitialCongestionWindowPackets = 10; |
27 const uint32 kDefaultWindowTCP = | 26 const uint32 kDefaultWindowTCP = |
28 kInitialCongestionWindowPackets * kDefaultTCPMSS; | 27 kInitialCongestionWindowPackets * kDefaultTCPMSS; |
29 const float kRenoBeta = 0.7f; // Reno backoff factor. | 28 const float kRenoBeta = 0.7f; // Reno backoff factor. |
30 | 29 |
31 class TcpCubicSenderPeer : public TcpCubicSender { | 30 class TcpCubicBytesSenderPeer : public TcpCubicBytesSender { |
32 public: | 31 public: |
33 TcpCubicSenderPeer(const QuicClock* clock, bool reno) | 32 TcpCubicBytesSenderPeer(const QuicClock* clock, bool reno) |
34 : TcpCubicSender(clock, | 33 : TcpCubicBytesSender(clock, |
35 &rtt_stats_, | 34 &rtt_stats_, |
36 reno, | 35 reno, |
37 kInitialCongestionWindowPackets, | 36 kInitialCongestionWindowPackets, |
38 &stats_) {} | 37 &stats_) {} |
39 | |
40 QuicPacketCount congestion_window() { | |
41 return congestion_window_; | |
42 } | |
43 | |
44 QuicPacketCount slowstart_threshold() { | |
45 return slowstart_threshold_; | |
46 } | |
47 | 38 |
48 const HybridSlowStart& hybrid_slow_start() const { | 39 const HybridSlowStart& hybrid_slow_start() const { |
49 return hybrid_slow_start_; | 40 return hybrid_slow_start_; |
50 } | 41 } |
51 | 42 |
52 float GetRenoBeta() const { | 43 float GetRenoBeta() const { return RenoBeta(); } |
53 return RenoBeta(); | |
54 } | |
55 | 44 |
56 RttStats rtt_stats_; | 45 RttStats rtt_stats_; |
57 QuicConnectionStats stats_; | 46 QuicConnectionStats stats_; |
58 }; | 47 }; |
59 | 48 |
60 class TcpCubicSenderTest : public ::testing::Test { | 49 class TcpCubicBytesSenderTest : public ::testing::Test { |
61 protected: | 50 protected: |
62 TcpCubicSenderTest() | 51 TcpCubicBytesSenderTest() |
63 : one_ms_(QuicTime::Delta::FromMilliseconds(1)), | 52 : one_ms_(QuicTime::Delta::FromMilliseconds(1)), |
64 sender_(new TcpCubicSenderPeer(&clock_, true)), | 53 sender_(new TcpCubicBytesSenderPeer(&clock_, true)), |
65 sequence_number_(1), | 54 sequence_number_(1), |
66 acked_sequence_number_(0), | 55 acked_sequence_number_(0), |
67 bytes_in_flight_(0) { | 56 bytes_in_flight_(0) { |
68 standard_packet_.bytes_sent = kDefaultTCPMSS; | 57 standard_packet_.bytes_sent = kDefaultTCPMSS; |
69 } | 58 } |
70 | 59 |
71 int SendAvailableSendWindow() { | 60 int SendAvailableSendWindow() { |
72 // Send as long as TimeUntilSend returns Zero. | 61 // Send as long as TimeUntilSend returns Zero. |
73 int packets_sent = 0; | 62 int packets_sent = 0; |
74 bool can_send = sender_->TimeUntilSend( | 63 bool can_send = sender_->TimeUntilSend(clock_.Now(), bytes_in_flight_, |
75 clock_.Now(), bytes_in_flight_, HAS_RETRANSMITTABLE_DATA).IsZero(); | 64 HAS_RETRANSMITTABLE_DATA).IsZero(); |
76 while (can_send) { | 65 while (can_send) { |
77 sender_->OnPacketSent(clock_.Now(), bytes_in_flight_, sequence_number_++, | 66 sender_->OnPacketSent(clock_.Now(), bytes_in_flight_, sequence_number_++, |
78 kDefaultTCPMSS, HAS_RETRANSMITTABLE_DATA); | 67 kDefaultTCPMSS, HAS_RETRANSMITTABLE_DATA); |
79 ++packets_sent; | 68 ++packets_sent; |
80 bytes_in_flight_ += kDefaultTCPMSS; | 69 bytes_in_flight_ += kDefaultTCPMSS; |
81 can_send = sender_->TimeUntilSend( | 70 can_send = sender_->TimeUntilSend(clock_.Now(), bytes_in_flight_, |
82 clock_.Now(), bytes_in_flight_, HAS_RETRANSMITTABLE_DATA).IsZero(); | 71 HAS_RETRANSMITTABLE_DATA).IsZero(); |
83 } | 72 } |
84 return packets_sent; | 73 return packets_sent; |
85 } | 74 } |
86 | 75 |
87 // Normal is that TCP acks every other segment. | 76 // Normal is that TCP acks every other segment. |
88 void AckNPackets(int n) { | 77 void AckNPackets(int n) { |
89 sender_->rtt_stats_.UpdateRtt(QuicTime::Delta::FromMilliseconds(60), | 78 sender_->rtt_stats_.UpdateRtt(QuicTime::Delta::FromMilliseconds(60), |
90 QuicTime::Delta::Zero(), | 79 QuicTime::Delta::Zero(), clock_.Now()); |
91 clock_.Now()); | |
92 SendAlgorithmInterface::CongestionVector acked_packets; | 80 SendAlgorithmInterface::CongestionVector acked_packets; |
93 SendAlgorithmInterface::CongestionVector lost_packets; | 81 SendAlgorithmInterface::CongestionVector lost_packets; |
94 for (int i = 0; i < n; ++i) { | 82 for (int i = 0; i < n; ++i) { |
95 ++acked_sequence_number_; | 83 ++acked_sequence_number_; |
96 acked_packets.push_back( | 84 acked_packets.push_back( |
97 std::make_pair(acked_sequence_number_, standard_packet_)); | 85 std::make_pair(acked_sequence_number_, standard_packet_)); |
98 } | 86 } |
99 sender_->OnCongestionEvent( | 87 sender_->OnCongestionEvent(true, bytes_in_flight_, acked_packets, |
100 true, bytes_in_flight_, acked_packets, lost_packets); | 88 lost_packets); |
101 bytes_in_flight_ -= n * kDefaultTCPMSS; | 89 bytes_in_flight_ -= n * kDefaultTCPMSS; |
102 clock_.AdvanceTime(one_ms_); | 90 clock_.AdvanceTime(one_ms_); |
103 } | 91 } |
104 | 92 |
105 void LoseNPackets(int n) { | 93 void LoseNPackets(int n) { |
106 SendAlgorithmInterface::CongestionVector acked_packets; | 94 SendAlgorithmInterface::CongestionVector acked_packets; |
107 SendAlgorithmInterface::CongestionVector lost_packets; | 95 SendAlgorithmInterface::CongestionVector lost_packets; |
108 for (int i = 0; i < n; ++i) { | 96 for (int i = 0; i < n; ++i) { |
109 ++acked_sequence_number_; | 97 ++acked_sequence_number_; |
110 lost_packets.push_back( | 98 lost_packets.push_back( |
111 std::make_pair(acked_sequence_number_, standard_packet_)); | 99 std::make_pair(acked_sequence_number_, standard_packet_)); |
112 } | 100 } |
113 sender_->OnCongestionEvent( | 101 sender_->OnCongestionEvent(false, bytes_in_flight_, acked_packets, |
114 false, bytes_in_flight_, acked_packets, lost_packets); | 102 lost_packets); |
115 bytes_in_flight_ -= n * kDefaultTCPMSS; | 103 bytes_in_flight_ -= n * kDefaultTCPMSS; |
116 } | 104 } |
117 | 105 |
118 // Does not increment acked_sequence_number_. | 106 // Does not increment acked_sequence_number_. |
119 void LosePacket(QuicPacketSequenceNumber sequence_number) { | 107 void LosePacket(QuicPacketSequenceNumber sequence_number) { |
120 SendAlgorithmInterface::CongestionVector acked_packets; | 108 SendAlgorithmInterface::CongestionVector acked_packets; |
121 SendAlgorithmInterface::CongestionVector lost_packets; | 109 SendAlgorithmInterface::CongestionVector lost_packets; |
122 lost_packets.push_back(std::make_pair(sequence_number, standard_packet_)); | 110 lost_packets.push_back(std::make_pair(sequence_number, standard_packet_)); |
123 sender_->OnCongestionEvent( | 111 sender_->OnCongestionEvent(false, bytes_in_flight_, acked_packets, |
124 false, bytes_in_flight_, acked_packets, lost_packets); | 112 lost_packets); |
125 bytes_in_flight_ -= kDefaultTCPMSS; | 113 bytes_in_flight_ -= kDefaultTCPMSS; |
126 } | 114 } |
127 | 115 |
128 const QuicTime::Delta one_ms_; | 116 const QuicTime::Delta one_ms_; |
129 MockClock clock_; | 117 MockClock clock_; |
130 scoped_ptr<TcpCubicSenderPeer> sender_; | 118 scoped_ptr<TcpCubicBytesSenderPeer> sender_; |
131 QuicPacketSequenceNumber sequence_number_; | 119 QuicPacketSequenceNumber sequence_number_; |
132 QuicPacketSequenceNumber acked_sequence_number_; | 120 QuicPacketSequenceNumber acked_sequence_number_; |
133 QuicByteCount bytes_in_flight_; | 121 QuicByteCount bytes_in_flight_; |
134 TransmissionInfo standard_packet_; | 122 TransmissionInfo standard_packet_; |
135 }; | 123 }; |
136 | 124 |
137 TEST_F(TcpCubicSenderTest, SimpleSender) { | 125 TEST_F(TcpCubicBytesSenderTest, SimpleSender) { |
138 // At startup make sure we are at the default. | 126 // At startup make sure we are at the default. |
139 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); | 127 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); |
140 // At startup make sure we can send. | 128 // At startup make sure we can send. |
141 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), | 129 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), 0, HAS_RETRANSMITTABLE_DATA) |
142 0, | 130 .IsZero()); |
143 HAS_RETRANSMITTABLE_DATA).IsZero()); | |
144 // Make sure we can send. | 131 // Make sure we can send. |
145 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), | 132 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), 0, HAS_RETRANSMITTABLE_DATA) |
146 0, | 133 .IsZero()); |
147 HAS_RETRANSMITTABLE_DATA).IsZero()); | |
148 // And that window is un-affected. | 134 // And that window is un-affected. |
149 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); | 135 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); |
150 | 136 |
151 // Fill the send window with data, then verify that we can't send. | 137 // Fill the send window with data, then verify that we can't send. |
152 SendAvailableSendWindow(); | 138 SendAvailableSendWindow(); |
153 EXPECT_FALSE(sender_->TimeUntilSend(clock_.Now(), | 139 EXPECT_FALSE(sender_->TimeUntilSend(clock_.Now(), |
154 sender_->GetCongestionWindow(), | 140 sender_->GetCongestionWindow(), |
155 HAS_RETRANSMITTABLE_DATA).IsZero()); | 141 HAS_RETRANSMITTABLE_DATA).IsZero()); |
156 } | 142 } |
157 | 143 |
158 TEST_F(TcpCubicSenderTest, ApplicationLimitedSlowStart) { | 144 TEST_F(TcpCubicBytesSenderTest, ApplicationLimitedSlowStart) { |
159 // Send exactly 10 packets and ensure the CWND ends at 14 packets. | 145 // Send exactly 10 packets and ensure the CWND ends at 14 packets. |
160 const int kNumberOfAcks = 5; | 146 const int kNumberOfAcks = 5; |
161 // At startup make sure we can send. | 147 // At startup make sure we can send. |
162 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), | 148 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), 0, HAS_RETRANSMITTABLE_DATA) |
163 0, | 149 .IsZero()); |
164 HAS_RETRANSMITTABLE_DATA).IsZero()); | |
165 // Make sure we can send. | 150 // Make sure we can send. |
166 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), | 151 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), 0, HAS_RETRANSMITTABLE_DATA) |
167 0, | 152 .IsZero()); |
168 HAS_RETRANSMITTABLE_DATA).IsZero()); | |
169 | 153 |
170 SendAvailableSendWindow(); | 154 SendAvailableSendWindow(); |
171 for (int i = 0; i < kNumberOfAcks; ++i) { | 155 for (int i = 0; i < kNumberOfAcks; ++i) { |
172 AckNPackets(2); | 156 AckNPackets(2); |
173 } | 157 } |
174 QuicByteCount bytes_to_send = sender_->GetCongestionWindow(); | 158 QuicByteCount bytes_to_send = sender_->GetCongestionWindow(); |
175 // It's expected 2 acks will arrive when the bytes_in_flight are greater than | 159 // It's expected 2 acks will arrive when the bytes_in_flight are greater than |
176 // half the CWND. | 160 // half the CWND. |
177 EXPECT_EQ(kDefaultWindowTCP + kDefaultTCPMSS * 2 * 2, | 161 EXPECT_EQ(kDefaultWindowTCP + kDefaultTCPMSS * 2 * 2, bytes_to_send); |
178 bytes_to_send); | |
179 } | 162 } |
180 | 163 |
181 TEST_F(TcpCubicSenderTest, ExponentialSlowStart) { | 164 TEST_F(TcpCubicBytesSenderTest, ExponentialSlowStart) { |
182 const int kNumberOfAcks = 20; | 165 const int kNumberOfAcks = 20; |
183 // At startup make sure we can send. | 166 // At startup make sure we can send. |
184 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), | 167 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), 0, HAS_RETRANSMITTABLE_DATA) |
185 0, | 168 .IsZero()); |
186 HAS_RETRANSMITTABLE_DATA).IsZero()); | |
187 EXPECT_FALSE(sender_->HasReliableBandwidthEstimate()); | 169 EXPECT_FALSE(sender_->HasReliableBandwidthEstimate()); |
188 EXPECT_EQ(QuicBandwidth::Zero(), sender_->BandwidthEstimate()); | 170 EXPECT_EQ(QuicBandwidth::Zero(), sender_->BandwidthEstimate()); |
189 // Make sure we can send. | 171 // Make sure we can send. |
190 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), | 172 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), 0, HAS_RETRANSMITTABLE_DATA) |
191 0, | 173 .IsZero()); |
192 HAS_RETRANSMITTABLE_DATA).IsZero()); | |
193 | 174 |
194 for (int i = 0; i < kNumberOfAcks; ++i) { | 175 for (int i = 0; i < kNumberOfAcks; ++i) { |
195 // Send our full send window. | 176 // Send our full send window. |
196 SendAvailableSendWindow(); | 177 SendAvailableSendWindow(); |
197 AckNPackets(2); | 178 AckNPackets(2); |
198 } | 179 } |
199 const QuicByteCount cwnd = sender_->GetCongestionWindow(); | 180 const QuicByteCount cwnd = sender_->GetCongestionWindow(); |
200 EXPECT_EQ(kDefaultWindowTCP + kDefaultTCPMSS * 2 * kNumberOfAcks, cwnd); | 181 EXPECT_EQ(kDefaultWindowTCP + kDefaultTCPMSS * 2 * kNumberOfAcks, cwnd); |
201 EXPECT_FALSE(sender_->HasReliableBandwidthEstimate()); | 182 EXPECT_FALSE(sender_->HasReliableBandwidthEstimate()); |
202 EXPECT_EQ(QuicBandwidth::FromBytesAndTimeDelta( | 183 EXPECT_EQ(QuicBandwidth::FromBytesAndTimeDelta( |
203 cwnd, sender_->rtt_stats_.smoothed_rtt()), | 184 cwnd, sender_->rtt_stats_.smoothed_rtt()), |
204 sender_->BandwidthEstimate()); | 185 sender_->BandwidthEstimate()); |
205 } | 186 } |
206 | 187 |
207 TEST_F(TcpCubicSenderTest, SlowStartAckTrain) { | 188 TEST_F(TcpCubicBytesSenderTest, SlowStartAckTrain) { |
208 sender_->SetNumEmulatedConnections(1); | 189 sender_->SetNumEmulatedConnections(1); |
209 | 190 |
210 // Make sure that we fall out of slow start when we send ACK train longer | 191 // Make sure that we fall out of slow start when we send ACK train longer |
211 // than half the RTT, in this test case 30ms, which is more than 30 calls to | 192 // than half the RTT, in this test case 30ms, which is more than 30 calls to |
212 // Ack2Packets in one round. | 193 // Ack2Packets in one round. |
213 // Since we start at 10 packet first round will be 5 second round 10 etc | 194 // Since we start at 10 packet first round will be 5 second round 10 etc |
214 // Hence we should pass 30 at 65 = 5 + 10 + 20 + 30 | 195 // Hence we should pass 30 at 65 = 5 + 10 + 20 + 30. |
215 const int kNumberOfAcks = 65; | 196 const int kNumberOfAcks = 65; |
216 for (int i = 0; i < kNumberOfAcks; ++i) { | 197 for (int i = 0; i < kNumberOfAcks; ++i) { |
217 // Send our full send window. | 198 // Send our full send window. |
218 SendAvailableSendWindow(); | 199 SendAvailableSendWindow(); |
219 AckNPackets(2); | 200 AckNPackets(2); |
220 } | 201 } |
221 QuicByteCount expected_send_window = | 202 QuicByteCount expected_send_window = |
222 kDefaultWindowTCP + (kDefaultTCPMSS * 2 * kNumberOfAcks); | 203 kDefaultWindowTCP + (kDefaultTCPMSS * 2 * kNumberOfAcks); |
223 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 204 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
224 | 205 |
225 // We should now have fallen out of slow start. | 206 // We should now have fallen out of slow start. |
226 // Testing Reno phase. | 207 // Testing Reno phase. |
227 // We should need 140(65*2+10) ACK:ed packets before increasing window by | 208 // We should need 140(65*2+10) ACK:ed packets before increasing window by |
228 // one. | 209 // one. |
229 for (int i = 0; i < 69; ++i) { | 210 for (int i = 0; i < 69; ++i) { |
230 SendAvailableSendWindow(); | 211 SendAvailableSendWindow(); |
231 AckNPackets(2); | 212 AckNPackets(2); |
232 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 213 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
233 } | 214 } |
234 SendAvailableSendWindow(); | 215 SendAvailableSendWindow(); |
235 AckNPackets(2); | 216 AckNPackets(2); |
236 QuicByteCount expected_ss_tresh = expected_send_window; | 217 QuicByteCount expected_ss_tresh = expected_send_window; |
237 expected_send_window += kDefaultTCPMSS; | 218 expected_send_window += kDefaultTCPMSS; |
238 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 219 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
239 EXPECT_EQ(expected_ss_tresh, sender_->GetSlowStartThreshold()); | 220 EXPECT_EQ(expected_ss_tresh, sender_->GetSlowStartThreshold()); |
240 EXPECT_EQ(140u, sender_->slowstart_threshold()); | |
241 | 221 |
242 // Now RTO and ensure slow start gets reset. | 222 // Now RTO and ensure slow start gets reset. |
243 EXPECT_TRUE(sender_->hybrid_slow_start().started()); | 223 EXPECT_TRUE(sender_->hybrid_slow_start().started()); |
244 sender_->OnRetransmissionTimeout(true); | 224 sender_->OnRetransmissionTimeout(true); |
245 EXPECT_FALSE(sender_->hybrid_slow_start().started()); | 225 EXPECT_FALSE(sender_->hybrid_slow_start().started()); |
246 EXPECT_EQ(2 * kDefaultTCPMSS, sender_->GetCongestionWindow()); | 226 EXPECT_EQ(2 * kDefaultTCPMSS, sender_->GetCongestionWindow()); |
247 EXPECT_EQ(expected_send_window / 2 / kDefaultTCPMSS, | 227 EXPECT_EQ(expected_send_window / 2, sender_->GetSlowStartThreshold()); |
248 sender_->slowstart_threshold()); | |
249 } | 228 } |
250 | 229 |
251 TEST_F(TcpCubicSenderTest, SlowStartPacketLoss) { | 230 TEST_F(TcpCubicBytesSenderTest, SlowStartPacketLoss) { |
252 sender_->SetNumEmulatedConnections(1); | 231 sender_->SetNumEmulatedConnections(1); |
253 const int kNumberOfAcks = 10; | 232 const int kNumberOfAcks = 10; |
254 for (int i = 0; i < kNumberOfAcks; ++i) { | 233 for (int i = 0; i < kNumberOfAcks; ++i) { |
255 // Send our full send window. | 234 // Send our full send window. |
256 SendAvailableSendWindow(); | 235 SendAvailableSendWindow(); |
257 AckNPackets(2); | 236 AckNPackets(2); |
258 } | 237 } |
259 SendAvailableSendWindow(); | 238 SendAvailableSendWindow(); |
260 QuicByteCount expected_send_window = kDefaultWindowTCP + | 239 QuicByteCount expected_send_window = |
261 (kDefaultTCPMSS * 2 * kNumberOfAcks); | 240 kDefaultWindowTCP + (kDefaultTCPMSS * 2 * kNumberOfAcks); |
262 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 241 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
263 | 242 |
264 // Lose a packet to exit slow start. | 243 // Lose a packet to exit slow start. |
265 LoseNPackets(1); | 244 LoseNPackets(1); |
266 size_t packets_in_recovery_window = expected_send_window / kDefaultTCPMSS; | 245 size_t packets_in_recovery_window = expected_send_window / kDefaultTCPMSS; |
267 | 246 |
268 // We should now have fallen out of slow start with a reduced window. | 247 // We should now have fallen out of slow start with a reduced window. |
269 expected_send_window *= kRenoBeta; | 248 expected_send_window *= kRenoBeta; |
270 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 249 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
271 | 250 |
(...skipping 14 matching lines...) Expand all Loading... |
286 AckNPackets(1); | 265 AckNPackets(1); |
287 expected_send_window += kDefaultTCPMSS; | 266 expected_send_window += kDefaultTCPMSS; |
288 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 267 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
289 | 268 |
290 // Now RTO and ensure slow start gets reset. | 269 // Now RTO and ensure slow start gets reset. |
291 EXPECT_TRUE(sender_->hybrid_slow_start().started()); | 270 EXPECT_TRUE(sender_->hybrid_slow_start().started()); |
292 sender_->OnRetransmissionTimeout(true); | 271 sender_->OnRetransmissionTimeout(true); |
293 EXPECT_FALSE(sender_->hybrid_slow_start().started()); | 272 EXPECT_FALSE(sender_->hybrid_slow_start().started()); |
294 } | 273 } |
295 | 274 |
296 TEST_F(TcpCubicSenderTest, NoPRRWhenLessThanOnePacketInFlight) { | 275 TEST_F(TcpCubicBytesSenderTest, NoPRRWhenLessThanOnePacketInFlight) { |
297 SendAvailableSendWindow(); | 276 SendAvailableSendWindow(); |
298 LoseNPackets(kInitialCongestionWindowPackets - 1); | 277 LoseNPackets(kInitialCongestionWindowPackets - 1); |
299 AckNPackets(1); | 278 AckNPackets(1); |
300 // PRR will allow 2 packets for every ack during recovery. | 279 // PRR will allow 2 packets for every ack during recovery. |
301 EXPECT_EQ(2, SendAvailableSendWindow()); | 280 EXPECT_EQ(2, SendAvailableSendWindow()); |
302 // Simulate abandoning all packets by supplying a bytes_in_flight of 0. | 281 // Simulate abandoning all packets by supplying a bytes_in_flight of 0. |
303 // PRR should now allow a packet to be sent, even though prr's state | 282 // PRR should now allow a packet to be sent, even though prr's state variables |
304 // variables believe it has sent enough packets. | 283 // believe it has sent enough packets. |
305 EXPECT_EQ(QuicTime::Delta::Zero(), | 284 EXPECT_EQ(QuicTime::Delta::Zero(), |
306 sender_->TimeUntilSend(clock_.Now(), 0, HAS_RETRANSMITTABLE_DATA)); | 285 sender_->TimeUntilSend(clock_.Now(), 0, HAS_RETRANSMITTABLE_DATA)); |
307 } | 286 } |
308 | 287 |
309 TEST_F(TcpCubicSenderTest, SlowStartPacketLossPRR) { | 288 TEST_F(TcpCubicBytesSenderTest, SlowStartPacketLossPRR) { |
310 sender_->SetNumEmulatedConnections(1); | 289 sender_->SetNumEmulatedConnections(1); |
311 // Test based on the first example in RFC6937. | 290 // Test based on the first example in RFC6937. |
312 // Ack 10 packets in 5 acks to raise the CWND to 20, as in the example. | 291 // Ack 10 packets in 5 acks to raise the CWND to 20, as in the example. |
313 const int kNumberOfAcks = 5; | 292 const int kNumberOfAcks = 5; |
314 for (int i = 0; i < kNumberOfAcks; ++i) { | 293 for (int i = 0; i < kNumberOfAcks; ++i) { |
315 // Send our full send window. | 294 // Send our full send window. |
316 SendAvailableSendWindow(); | 295 SendAvailableSendWindow(); |
317 AckNPackets(2); | 296 AckNPackets(2); |
318 } | 297 } |
319 SendAvailableSendWindow(); | 298 SendAvailableSendWindow(); |
320 QuicByteCount expected_send_window = kDefaultWindowTCP + | 299 QuicByteCount expected_send_window = |
321 (kDefaultTCPMSS * 2 * kNumberOfAcks); | 300 kDefaultWindowTCP + (kDefaultTCPMSS * 2 * kNumberOfAcks); |
322 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 301 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
323 | 302 |
324 LoseNPackets(1); | 303 LoseNPackets(1); |
325 | 304 |
326 // We should now have fallen out of slow start with a reduced window. | 305 // We should now have fallen out of slow start with a reduced window. |
327 size_t send_window_before_loss = expected_send_window; | 306 size_t send_window_before_loss = expected_send_window; |
328 expected_send_window *= kRenoBeta; | 307 expected_send_window *= kRenoBeta; |
329 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 308 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
330 | 309 |
331 // Testing TCP proportional rate reduction. | 310 // Testing TCP proportional rate reduction. |
(...skipping 16 matching lines...) Expand all Loading... |
348 AckNPackets(1); | 327 AckNPackets(1); |
349 EXPECT_EQ(1, SendAvailableSendWindow()); | 328 EXPECT_EQ(1, SendAvailableSendWindow()); |
350 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 329 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
351 } | 330 } |
352 | 331 |
353 AckNPackets(1); | 332 AckNPackets(1); |
354 expected_send_window += kDefaultTCPMSS; | 333 expected_send_window += kDefaultTCPMSS; |
355 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 334 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
356 } | 335 } |
357 | 336 |
358 TEST_F(TcpCubicSenderTest, SlowStartBurstPacketLossPRR) { | 337 TEST_F(TcpCubicBytesSenderTest, SlowStartBurstPacketLossPRR) { |
359 sender_->SetNumEmulatedConnections(1); | 338 sender_->SetNumEmulatedConnections(1); |
360 // Test based on the second example in RFC6937, though we also implement | 339 // Test based on the second example in RFC6937, though we also implement |
361 // forward acknowledgements, so the first two incoming acks will trigger | 340 // forward acknowledgements, so the first two incoming acks will trigger |
362 // PRR immediately. | 341 // PRR immediately. |
363 // Ack 20 packets in 10 acks to raise the CWND to 30. | 342 // Ack 20 packets in 10 acks to raise the CWND to 30. |
364 const int kNumberOfAcks = 10; | 343 const int kNumberOfAcks = 10; |
365 for (int i = 0; i < kNumberOfAcks; ++i) { | 344 for (int i = 0; i < kNumberOfAcks; ++i) { |
366 // Send our full send window. | 345 // Send our full send window. |
367 SendAvailableSendWindow(); | 346 SendAvailableSendWindow(); |
368 AckNPackets(2); | 347 AckNPackets(2); |
369 } | 348 } |
370 SendAvailableSendWindow(); | 349 SendAvailableSendWindow(); |
371 QuicByteCount expected_send_window = kDefaultWindowTCP + | 350 QuicByteCount expected_send_window = |
372 (kDefaultTCPMSS * 2 * kNumberOfAcks); | 351 kDefaultWindowTCP + (kDefaultTCPMSS * 2 * kNumberOfAcks); |
373 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 352 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
374 | 353 |
375 // Lose one more than the congestion window reduction, so that after loss, | 354 // Lose one more than the congestion window reduction, so that after loss, |
376 // bytes_in_flight is lesser than the congestion window. | 355 // bytes_in_flight is lesser than the congestion window. |
377 size_t send_window_after_loss = kRenoBeta * expected_send_window; | 356 size_t send_window_after_loss = kRenoBeta * expected_send_window; |
378 size_t num_packets_to_lose = | 357 size_t num_packets_to_lose = |
379 (expected_send_window - send_window_after_loss) / kDefaultTCPMSS + 1; | 358 (expected_send_window - send_window_after_loss) / kDefaultTCPMSS + 1; |
380 LoseNPackets(num_packets_to_lose); | 359 LoseNPackets(num_packets_to_lose); |
381 // Immediately after the loss, ensure at least one packet can be sent. | 360 // Immediately after the loss, ensure at least one packet can be sent. |
382 // Losses without subsequent acks can occur with timer based loss detection. | 361 // Losses without subsequent acks can occur with timer based loss detection. |
383 EXPECT_TRUE(sender_->TimeUntilSend( | 362 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), bytes_in_flight_, |
384 clock_.Now(), bytes_in_flight_, HAS_RETRANSMITTABLE_DATA).IsZero()); | 363 HAS_RETRANSMITTABLE_DATA).IsZero()); |
385 AckNPackets(1); | 364 AckNPackets(1); |
386 | 365 |
387 // We should now have fallen out of slow start with a reduced window. | 366 // We should now have fallen out of slow start with a reduced window. |
388 expected_send_window *= kRenoBeta; | 367 expected_send_window *= kRenoBeta; |
389 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 368 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
390 | 369 |
391 // Only 2 packets should be allowed to be sent, per PRR-SSRB | 370 // Only 2 packets should be allowed to be sent, per PRR-SSRB. |
392 EXPECT_EQ(2, SendAvailableSendWindow()); | 371 EXPECT_EQ(2, SendAvailableSendWindow()); |
393 | 372 |
394 // Ack the next packet, which triggers another loss. | 373 // Ack the next packet, which triggers another loss. |
395 LoseNPackets(1); | 374 LoseNPackets(1); |
396 AckNPackets(1); | 375 AckNPackets(1); |
397 | 376 |
398 // Send 2 packets to simulate PRR-SSRB. | 377 // Send 2 packets to simulate PRR-SSRB. |
399 EXPECT_EQ(2, SendAvailableSendWindow()); | 378 EXPECT_EQ(2, SendAvailableSendWindow()); |
400 | 379 |
401 // Ack the next packet, which triggers another loss. | 380 // Ack the next packet, which triggers another loss. |
402 LoseNPackets(1); | 381 LoseNPackets(1); |
403 AckNPackets(1); | 382 AckNPackets(1); |
404 | 383 |
405 // Send 2 packets to simulate PRR-SSRB. | 384 // Send 2 packets to simulate PRR-SSRB. |
406 EXPECT_EQ(2, SendAvailableSendWindow()); | 385 EXPECT_EQ(2, SendAvailableSendWindow()); |
407 | 386 |
408 // Exit recovery and return to sending at the new rate. | 387 // Exit recovery and return to sending at the new rate. |
409 for (int i = 0; i < kNumberOfAcks; ++i) { | 388 for (int i = 0; i < kNumberOfAcks; ++i) { |
410 AckNPackets(1); | 389 AckNPackets(1); |
411 EXPECT_EQ(1, SendAvailableSendWindow()); | 390 EXPECT_EQ(1, SendAvailableSendWindow()); |
412 } | 391 } |
413 } | 392 } |
414 | 393 |
415 TEST_F(TcpCubicSenderTest, RTOCongestionWindow) { | 394 TEST_F(TcpCubicBytesSenderTest, RTOCongestionWindow) { |
416 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); | 395 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); |
417 // Expect the window to decrease to the minimum once the RTO fires | 396 // Expect the window to decrease to the minimum once the RTO fires and slow |
418 // and slow start threshold to be set to 1/2 of the CWND. | 397 // start threshold to be set to 1/2 of the CWND. |
419 sender_->OnRetransmissionTimeout(true); | 398 sender_->OnRetransmissionTimeout(true); |
420 EXPECT_EQ(2 * kDefaultTCPMSS, sender_->GetCongestionWindow()); | 399 EXPECT_EQ(2 * kDefaultTCPMSS, sender_->GetCongestionWindow()); |
421 EXPECT_EQ(5u, sender_->slowstart_threshold()); | 400 EXPECT_EQ(5u * kDefaultTCPMSS, sender_->GetSlowStartThreshold()); |
422 } | 401 } |
423 | 402 |
424 TEST_F(TcpCubicSenderTest, RTOCongestionWindowNoRetransmission) { | 403 TEST_F(TcpCubicBytesSenderTest, RTOCongestionWindowNoRetransmission) { |
425 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); | 404 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); |
426 | 405 |
427 // Expect the window to remain unchanged if the RTO fires but no | 406 // Expect the window to remain unchanged if the RTO fires but no packets are |
428 // packets are retransmitted. | 407 // retransmitted. |
429 sender_->OnRetransmissionTimeout(false); | 408 sender_->OnRetransmissionTimeout(false); |
430 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); | 409 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); |
431 } | 410 } |
432 | 411 |
433 TEST_F(TcpCubicSenderTest, RetransmissionDelay) { | 412 TEST_F(TcpCubicBytesSenderTest, RetransmissionDelay) { |
434 const int64 kRttMs = 10; | 413 const int64 kRttMs = 10; |
435 const int64 kDeviationMs = 3; | 414 const int64 kDeviationMs = 3; |
436 EXPECT_EQ(QuicTime::Delta::Zero(), sender_->RetransmissionDelay()); | 415 EXPECT_EQ(QuicTime::Delta::Zero(), sender_->RetransmissionDelay()); |
437 | 416 |
438 sender_->rtt_stats_.UpdateRtt(QuicTime::Delta::FromMilliseconds(kRttMs), | 417 sender_->rtt_stats_.UpdateRtt(QuicTime::Delta::FromMilliseconds(kRttMs), |
439 QuicTime::Delta::Zero(), clock_.Now()); | 418 QuicTime::Delta::Zero(), clock_.Now()); |
440 | 419 |
441 // Initial value is to set the median deviation to half of the initial | 420 // Initial value is to set the median deviation to half of the initial rtt, |
442 // rtt, the median in then multiplied by a factor of 4 and finally the | 421 // the median in then multiplied by a factor of 4 and finally the smoothed rtt |
443 // smoothed rtt is added which is the initial rtt. | 422 // is added which is the initial rtt. |
444 QuicTime::Delta expected_delay = | 423 QuicTime::Delta expected_delay = |
445 QuicTime::Delta::FromMilliseconds(kRttMs + kRttMs / 2 * 4); | 424 QuicTime::Delta::FromMilliseconds(kRttMs + kRttMs / 2 * 4); |
446 EXPECT_EQ(expected_delay, sender_->RetransmissionDelay()); | 425 EXPECT_EQ(expected_delay, sender_->RetransmissionDelay()); |
447 | 426 |
448 for (int i = 0; i < 100; ++i) { | 427 for (int i = 0; i < 100; ++i) { |
449 // Run to make sure that we converge. | 428 // Run to make sure that we converge. |
450 sender_->rtt_stats_.UpdateRtt( | 429 sender_->rtt_stats_.UpdateRtt( |
451 QuicTime::Delta::FromMilliseconds(kRttMs + kDeviationMs), | 430 QuicTime::Delta::FromMilliseconds(kRttMs + kDeviationMs), |
452 QuicTime::Delta::Zero(), clock_.Now()); | 431 QuicTime::Delta::Zero(), clock_.Now()); |
453 sender_->rtt_stats_.UpdateRtt( | 432 sender_->rtt_stats_.UpdateRtt( |
454 QuicTime::Delta::FromMilliseconds(kRttMs - kDeviationMs), | 433 QuicTime::Delta::FromMilliseconds(kRttMs - kDeviationMs), |
455 QuicTime::Delta::Zero(), clock_.Now()); | 434 QuicTime::Delta::Zero(), clock_.Now()); |
456 } | 435 } |
457 expected_delay = QuicTime::Delta::FromMilliseconds(kRttMs + kDeviationMs * 4); | 436 expected_delay = QuicTime::Delta::FromMilliseconds(kRttMs + kDeviationMs * 4); |
458 | 437 |
459 EXPECT_NEAR(kRttMs, sender_->rtt_stats_.smoothed_rtt().ToMilliseconds(), 1); | 438 EXPECT_NEAR(kRttMs, sender_->rtt_stats_.smoothed_rtt().ToMilliseconds(), 1); |
460 EXPECT_NEAR(expected_delay.ToMilliseconds(), | 439 EXPECT_NEAR(expected_delay.ToMilliseconds(), |
461 sender_->RetransmissionDelay().ToMilliseconds(), | 440 sender_->RetransmissionDelay().ToMilliseconds(), 1); |
462 1); | 441 EXPECT_EQ( |
463 EXPECT_EQ(static_cast<int64>( | 442 static_cast<int64>(sender_->GetCongestionWindow() * kNumMicrosPerSecond / |
464 sender_->GetCongestionWindow() * kNumMicrosPerSecond / | 443 sender_->rtt_stats_.smoothed_rtt().ToMicroseconds()), |
465 sender_->rtt_stats_.smoothed_rtt().ToMicroseconds()), | 444 sender_->BandwidthEstimate().ToBytesPerSecond()); |
466 sender_->BandwidthEstimate().ToBytesPerSecond()); | |
467 } | 445 } |
468 | 446 |
469 TEST_F(TcpCubicSenderTest, MultipleLossesInOneWindow) { | 447 TEST_F(TcpCubicBytesSenderTest, MultipleLossesInOneWindow) { |
470 SendAvailableSendWindow(); | 448 SendAvailableSendWindow(); |
471 const QuicByteCount initial_window = sender_->GetCongestionWindow(); | 449 const QuicByteCount initial_window = sender_->GetCongestionWindow(); |
472 LosePacket(acked_sequence_number_ + 1); | 450 LosePacket(acked_sequence_number_ + 1); |
473 const QuicByteCount post_loss_window = sender_->GetCongestionWindow(); | 451 const QuicByteCount post_loss_window = sender_->GetCongestionWindow(); |
474 EXPECT_GT(initial_window, post_loss_window); | 452 EXPECT_GT(initial_window, post_loss_window); |
475 LosePacket(acked_sequence_number_ + 3); | 453 LosePacket(acked_sequence_number_ + 3); |
476 EXPECT_EQ(post_loss_window, sender_->GetCongestionWindow()); | 454 EXPECT_EQ(post_loss_window, sender_->GetCongestionWindow()); |
477 LosePacket(sequence_number_ - 1); | 455 LosePacket(sequence_number_ - 1); |
478 EXPECT_EQ(post_loss_window, sender_->GetCongestionWindow()); | 456 EXPECT_EQ(post_loss_window, sender_->GetCongestionWindow()); |
479 | 457 |
480 // Lose a later packet and ensure the window decreases. | 458 // Lose a later packet and ensure the window decreases. |
481 LosePacket(sequence_number_); | 459 LosePacket(sequence_number_); |
482 EXPECT_GT(post_loss_window, sender_->GetCongestionWindow()); | 460 EXPECT_GT(post_loss_window, sender_->GetCongestionWindow()); |
483 } | 461 } |
484 | 462 |
485 TEST_F(TcpCubicSenderTest, DontTrackAckPackets) { | 463 TEST_F(TcpCubicBytesSenderTest, DontTrackAckPackets) { |
486 // Send a packet with no retransmittable data, and ensure it's not tracked. | 464 // Send a packet with no retransmittable data, and ensure it's not tracked. |
487 EXPECT_FALSE(sender_->OnPacketSent(clock_.Now(), bytes_in_flight_, | 465 EXPECT_FALSE(sender_->OnPacketSent(clock_.Now(), bytes_in_flight_, |
488 sequence_number_++, kDefaultTCPMSS, | 466 sequence_number_++, kDefaultTCPMSS, |
489 NO_RETRANSMITTABLE_DATA)); | 467 NO_RETRANSMITTABLE_DATA)); |
490 | 468 |
491 // Send a data packet with retransmittable data, and ensure it is tracked. | 469 // Send a data packet with retransmittable data, and ensure it is tracked. |
492 EXPECT_TRUE(sender_->OnPacketSent(clock_.Now(), bytes_in_flight_, | 470 EXPECT_TRUE(sender_->OnPacketSent(clock_.Now(), bytes_in_flight_, |
493 sequence_number_++, kDefaultTCPMSS, | 471 sequence_number_++, kDefaultTCPMSS, |
494 HAS_RETRANSMITTABLE_DATA)); | 472 HAS_RETRANSMITTABLE_DATA)); |
495 } | 473 } |
496 | 474 |
497 TEST_F(TcpCubicSenderTest, ConfigureMaxInitialWindow) { | 475 TEST_F(TcpCubicBytesSenderTest, ConfigureMaxInitialWindow) { |
498 QuicConfig config; | 476 QuicConfig config; |
499 | 477 |
500 // Verify that kCOPT: kIW10 forces the congestion window to the default of 10. | 478 // Verify that kCOPT: kIW10 forces the congestion window to the default of 10. |
501 QuicTagVector options; | 479 QuicTagVector options; |
502 options.push_back(kIW10); | 480 options.push_back(kIW10); |
503 QuicConfigPeer::SetReceivedConnectionOptions(&config, options); | 481 QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
504 sender_->SetFromConfig(config, Perspective::IS_SERVER, | 482 sender_->SetFromConfig(config, |
| 483 /* is_server= */ Perspective::IS_SERVER, |
505 /* using_pacing= */ false); | 484 /* using_pacing= */ false); |
506 EXPECT_EQ(10u, sender_->congestion_window()); | 485 EXPECT_EQ(10u * kDefaultTCPMSS, sender_->GetCongestionWindow()); |
507 } | 486 } |
508 | 487 |
509 TEST_F(TcpCubicSenderTest, DisableAckTrainDetectionWithPacing) { | 488 TEST_F(TcpCubicBytesSenderTest, DisableAckTrainDetectionWithPacing) { |
510 EXPECT_TRUE(sender_->hybrid_slow_start().ack_train_detection()); | 489 EXPECT_TRUE(sender_->hybrid_slow_start().ack_train_detection()); |
511 | 490 |
512 QuicConfig config; | 491 QuicConfig config; |
513 sender_->SetFromConfig(config, Perspective::IS_SERVER, | 492 sender_->SetFromConfig(config, |
| 493 /* is_server= */ Perspective::IS_SERVER, |
514 /* using_pacing= */ true); | 494 /* using_pacing= */ true); |
515 EXPECT_FALSE(sender_->hybrid_slow_start().ack_train_detection()); | 495 EXPECT_FALSE(sender_->hybrid_slow_start().ack_train_detection()); |
516 } | 496 } |
517 | 497 |
518 TEST_F(TcpCubicSenderTest, 2ConnectionCongestionAvoidanceAtEndOfRecovery) { | 498 TEST_F(TcpCubicBytesSenderTest, 2ConnectionCongestionAvoidanceAtEndOfRecovery) { |
519 sender_->SetNumEmulatedConnections(2); | 499 sender_->SetNumEmulatedConnections(2); |
520 // Ack 10 packets in 5 acks to raise the CWND to 20. | 500 // Ack 10 packets in 5 acks to raise the CWND to 20. |
521 const int kNumberOfAcks = 5; | 501 const int kNumberOfAcks = 5; |
522 for (int i = 0; i < kNumberOfAcks; ++i) { | 502 for (int i = 0; i < kNumberOfAcks; ++i) { |
523 // Send our full send window. | 503 // Send our full send window. |
524 SendAvailableSendWindow(); | 504 SendAvailableSendWindow(); |
525 AckNPackets(2); | 505 AckNPackets(2); |
526 } | 506 } |
527 SendAvailableSendWindow(); | 507 SendAvailableSendWindow(); |
528 QuicByteCount expected_send_window = kDefaultWindowTCP + | 508 QuicByteCount expected_send_window = |
529 (kDefaultTCPMSS * 2 * kNumberOfAcks); | 509 kDefaultWindowTCP + (kDefaultTCPMSS * 2 * kNumberOfAcks); |
530 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 510 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
531 | 511 |
532 LoseNPackets(1); | 512 LoseNPackets(1); |
533 | 513 |
534 // We should now have fallen out of slow start with a reduced window. | 514 // We should now have fallen out of slow start with a reduced window. |
535 expected_send_window = expected_send_window * sender_->GetRenoBeta(); | 515 expected_send_window = expected_send_window * sender_->GetRenoBeta(); |
536 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 516 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
537 | 517 |
538 // No congestion window growth should occur in recovery phase, i.e., until the | 518 // No congestion window growth should occur in recovery phase, i.e., until the |
539 // currently outstanding 20 packets are acked. | 519 // currently outstanding 20 packets are acked. |
(...skipping 24 matching lines...) Expand all Loading... |
564 AckNPackets(packets_in_send_window / 2 - 1); | 544 AckNPackets(packets_in_send_window / 2 - 1); |
565 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 545 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
566 | 546 |
567 // Next ack should cause congestion window to grow by 1MSS. | 547 // Next ack should cause congestion window to grow by 1MSS. |
568 SendAvailableSendWindow(); | 548 SendAvailableSendWindow(); |
569 AckNPackets(2); | 549 AckNPackets(2); |
570 expected_send_window += kDefaultTCPMSS; | 550 expected_send_window += kDefaultTCPMSS; |
571 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 551 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
572 } | 552 } |
573 | 553 |
574 TEST_F(TcpCubicSenderTest, 1ConnectionCongestionAvoidanceAtEndOfRecovery) { | 554 TEST_F(TcpCubicBytesSenderTest, 1ConnectionCongestionAvoidanceAtEndOfRecovery) { |
575 sender_->SetNumEmulatedConnections(1); | 555 sender_->SetNumEmulatedConnections(1); |
576 // Ack 10 packets in 5 acks to raise the CWND to 20. | 556 // Ack 10 packets in 5 acks to raise the CWND to 20. |
577 const int kNumberOfAcks = 5; | 557 const int kNumberOfAcks = 5; |
578 for (int i = 0; i < kNumberOfAcks; ++i) { | 558 for (int i = 0; i < kNumberOfAcks; ++i) { |
579 // Send our full send window. | 559 // Send our full send window. |
580 SendAvailableSendWindow(); | 560 SendAvailableSendWindow(); |
581 AckNPackets(2); | 561 AckNPackets(2); |
582 } | 562 } |
583 SendAvailableSendWindow(); | 563 SendAvailableSendWindow(); |
584 QuicByteCount expected_send_window = kDefaultWindowTCP + | 564 QuicByteCount expected_send_window = |
585 (kDefaultTCPMSS * 2 * kNumberOfAcks); | 565 kDefaultWindowTCP + (kDefaultTCPMSS * 2 * kNumberOfAcks); |
586 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 566 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
587 | 567 |
588 LoseNPackets(1); | 568 LoseNPackets(1); |
589 | 569 |
590 // We should now have fallen out of slow start with a reduced window. | 570 // We should now have fallen out of slow start with a reduced window. |
591 expected_send_window *= kRenoBeta; | 571 expected_send_window *= kRenoBeta; |
592 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 572 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
593 | 573 |
594 // No congestion window growth should occur in recovery phase, i.e., until the | 574 // No congestion window growth should occur in recovery phase, i.e., until the |
595 // currently outstanding 20 packets are acked. | 575 // currently outstanding 20 packets are acked. |
(...skipping 14 matching lines...) Expand all Loading... |
610 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 590 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
611 } | 591 } |
612 | 592 |
613 // Next ack should cause congestion window to grow by 1MSS. | 593 // Next ack should cause congestion window to grow by 1MSS. |
614 SendAvailableSendWindow(); | 594 SendAvailableSendWindow(); |
615 AckNPackets(2); | 595 AckNPackets(2); |
616 expected_send_window += kDefaultTCPMSS; | 596 expected_send_window += kDefaultTCPMSS; |
617 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 597 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
618 } | 598 } |
619 | 599 |
620 TEST_F(TcpCubicSenderTest, BandwidthResumption) { | 600 TEST_F(TcpCubicBytesSenderTest, BandwidthResumption) { |
621 // Test that when provided with CachedNetworkParameters and opted in to the | 601 // Test that when provided with CachedNetworkParameters and opted in to the |
622 // bandwidth resumption experiment, that the TcpCubicSender sets initial CWND | 602 // bandwidth resumption experiment, that the TcpCubicSender sets initial CWND |
623 // appropriately. | 603 // appropriately. |
624 | 604 |
625 // Set some common values. | 605 // Set some common values. |
626 CachedNetworkParameters cached_network_params; | 606 CachedNetworkParameters cached_network_params; |
627 const QuicPacketCount kNumberOfPackets = 123; | 607 const QuicPacketCount kNumberOfPackets = 123; |
628 const int kBandwidthEstimateBytesPerSecond = | 608 const int kBandwidthEstimateBytesPerSecond = |
629 kNumberOfPackets * kMaxPacketSize; | 609 kNumberOfPackets * kDefaultTCPMSS; |
630 cached_network_params.set_bandwidth_estimate_bytes_per_second( | 610 cached_network_params.set_bandwidth_estimate_bytes_per_second( |
631 kBandwidthEstimateBytesPerSecond); | 611 kBandwidthEstimateBytesPerSecond); |
632 cached_network_params.set_min_rtt_ms(1000); | 612 cached_network_params.set_min_rtt_ms(1000); |
633 | 613 |
634 // Ensure that an old estimate is not used for bandwidth resumption. | 614 // Ensure that an old estimate is not used for bandwidth resumption. |
635 cached_network_params.set_timestamp(clock_.WallNow().ToUNIXSeconds() - | 615 cached_network_params.set_timestamp(clock_.WallNow().ToUNIXSeconds() - |
636 (kNumSecondsPerHour + 1)); | 616 (kNumSecondsPerHour + 1)); |
637 EXPECT_FALSE(sender_->ResumeConnectionState(cached_network_params)); | 617 EXPECT_FALSE(sender_->ResumeConnectionState(cached_network_params)); |
638 EXPECT_EQ(10u, sender_->congestion_window()); | 618 EXPECT_EQ(10u * kDefaultTCPMSS, sender_->GetCongestionWindow()); |
639 | 619 |
640 // If the estimate is new enough, make sure it is used. | 620 // If the estimate is new enough, make sure it is used. |
641 cached_network_params.set_timestamp(clock_.WallNow().ToUNIXSeconds() - | 621 cached_network_params.set_timestamp(clock_.WallNow().ToUNIXSeconds() - |
642 (kNumSecondsPerHour - 1)); | 622 (kNumSecondsPerHour - 1)); |
643 EXPECT_TRUE(sender_->ResumeConnectionState(cached_network_params)); | 623 EXPECT_TRUE(sender_->ResumeConnectionState(cached_network_params)); |
644 EXPECT_EQ(kNumberOfPackets, sender_->congestion_window()); | 624 EXPECT_EQ(kNumberOfPackets * kDefaultTCPMSS, sender_->GetCongestionWindow()); |
645 | 625 |
646 // Resumed CWND is limited to be in a sensible range. | 626 // Resumed CWND is limited to be in a sensible range. |
647 cached_network_params.set_bandwidth_estimate_bytes_per_second( | 627 cached_network_params.set_bandwidth_estimate_bytes_per_second( |
648 (kMaxCongestionWindowForBandwidthResumption + 1) * kMaxPacketSize); | 628 (kMaxCongestionWindowForBandwidthResumption + 1) * kDefaultTCPMSS); |
649 EXPECT_TRUE(sender_->ResumeConnectionState(cached_network_params)); | 629 EXPECT_TRUE(sender_->ResumeConnectionState(cached_network_params)); |
650 EXPECT_EQ(kMaxCongestionWindowForBandwidthResumption, | 630 EXPECT_EQ(kMaxCongestionWindowForBandwidthResumption * kDefaultTCPMSS, |
651 sender_->congestion_window()); | 631 sender_->GetCongestionWindow()); |
652 | 632 |
653 cached_network_params.set_bandwidth_estimate_bytes_per_second( | 633 cached_network_params.set_bandwidth_estimate_bytes_per_second( |
654 (kMinCongestionWindowForBandwidthResumption - 1) * kMaxPacketSize); | 634 (kMinCongestionWindowForBandwidthResumption - 1) * kDefaultTCPMSS); |
655 EXPECT_TRUE(sender_->ResumeConnectionState(cached_network_params)); | 635 EXPECT_TRUE(sender_->ResumeConnectionState(cached_network_params)); |
656 EXPECT_EQ(kMinCongestionWindowForBandwidthResumption, | 636 EXPECT_EQ(kMinCongestionWindowForBandwidthResumption * kDefaultTCPMSS, |
657 sender_->congestion_window()); | 637 sender_->GetCongestionWindow()); |
658 } | 638 } |
659 | 639 |
660 } // namespace test | 640 } // namespace test |
661 } // namespace net | 641 } // namespace net |
OLD | NEW |