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 "net/quic/congestion_control/pacing_sender.h" | 5 #include "net/quic/congestion_control/pacing_sender.h" |
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/quic_protocol.h" | 9 #include "net/quic/quic_protocol.h" |
10 #include "net/quic/test_tools/mock_clock.h" | 10 #include "net/quic/test_tools/mock_clock.h" |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 HAS_RETRANSMITTABLE_DATA)) | 126 HAS_RETRANSMITTABLE_DATA)) |
127 .WillOnce(Return(zero_time_)); | 127 .WillOnce(Return(zero_time_)); |
128 EXPECT_EQ(zero_time_, | 128 EXPECT_EQ(zero_time_, |
129 pacing_sender_->TimeUntilSend(clock_.Now(), | 129 pacing_sender_->TimeUntilSend(clock_.Now(), |
130 kBytesInFlight, | 130 kBytesInFlight, |
131 HAS_RETRANSMITTABLE_DATA)); | 131 HAS_RETRANSMITTABLE_DATA)); |
132 } | 132 } |
133 } | 133 } |
134 | 134 |
135 TEST_F(PacingSenderTest, VariousSending) { | 135 TEST_F(PacingSenderTest, VariousSending) { |
| 136 // Start the test in slow start. |
| 137 EXPECT_CALL(*mock_sender_, InSlowStart()).WillRepeatedly(Return(true)); |
| 138 |
136 // Configure bandwith of 1 packet per 2 ms, for which the pacing rate | 139 // Configure bandwith of 1 packet per 2 ms, for which the pacing rate |
137 // will be 1 packet per 1 ms. | 140 // will be 1 packet per 1 ms. |
138 EXPECT_CALL(*mock_sender_, BandwidthEstimate()) | 141 EXPECT_CALL(*mock_sender_, BandwidthEstimate()) |
139 .WillRepeatedly(Return(QuicBandwidth::FromBytesAndTimeDelta( | 142 .WillRepeatedly(Return(QuicBandwidth::FromBytesAndTimeDelta( |
140 kMaxPacketSize, QuicTime::Delta::FromMilliseconds(2)))); | 143 kMaxPacketSize, QuicTime::Delta::FromMilliseconds(2)))); |
141 | 144 |
142 // Send a whole pile of packets, and verify that they are not paced. | 145 // Send a whole pile of packets, and verify that they are not paced. |
143 for (int i = 0 ; i < 1000; ++i) { | 146 for (int i = 0 ; i < 1000; ++i) { |
144 CheckPacketIsSentImmediately(); | 147 CheckPacketIsSentImmediately(); |
145 } | 148 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 | 200 |
198 // Wake up too early. | 201 // Wake up too early. |
199 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); | 202 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
200 | 203 |
201 // Wake up early, but after enough time has passed to permit a send. | 204 // Wake up early, but after enough time has passed to permit a send. |
202 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); | 205 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); |
203 CheckPacketIsSentImmediately(); | 206 CheckPacketIsSentImmediately(); |
204 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); | 207 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
205 } | 208 } |
206 | 209 |
| 210 TEST_F(PacingSenderTest, CongestionAvoidanceSending) { |
| 211 // Start the test in congestion avoidance. |
| 212 EXPECT_CALL(*mock_sender_, InSlowStart()).WillRepeatedly(Return(false)); |
| 213 |
| 214 // Configure bandwith of 1 packet per 2 ms, for which the pacing rate |
| 215 // will be 1 packet per 1 ms. |
| 216 EXPECT_CALL(*mock_sender_, BandwidthEstimate()) |
| 217 .WillRepeatedly(Return(QuicBandwidth::FromBytesAndTimeDelta( |
| 218 kMaxPacketSize, QuicTime::Delta::FromMilliseconds(2)))); |
| 219 |
| 220 // Send a whole pile of packets, and verify that they are not paced. |
| 221 for (int i = 0 ; i < 1000; ++i) { |
| 222 CheckPacketIsSentImmediately(); |
| 223 } |
| 224 |
| 225 // Now update the RTT and verify that packets are actually paced. |
| 226 EXPECT_CALL(*mock_sender_, OnCongestionEvent(true, kBytesInFlight, _, _)); |
| 227 SendAlgorithmInterface::CongestionMap empty_map; |
| 228 pacing_sender_->OnCongestionEvent(true, kBytesInFlight, empty_map, empty_map); |
| 229 |
| 230 CheckPacketIsSentImmediately(); |
| 231 CheckPacketIsSentImmediately(); |
| 232 |
| 233 // The first packet was a "make up", then we sent two packets "into the |
| 234 // future", so the delay should be 2200us. |
| 235 CheckPacketIsDelayed(QuicTime::Delta::FromMicroseconds(2200)); |
| 236 |
| 237 // Wake up on time. |
| 238 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(2200)); |
| 239 CheckPacketIsSentImmediately(); |
| 240 CheckPacketIsDelayed(QuicTime::Delta::FromMicroseconds(1600)); |
| 241 CheckAckIsSentImmediately(); |
| 242 |
| 243 // Wake up late. |
| 244 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(4)); |
| 245 CheckPacketIsSentImmediately(); |
| 246 CheckPacketIsSentImmediately(); |
| 247 CheckPacketIsSentImmediately(); |
| 248 CheckPacketIsDelayed(QuicTime::Delta::FromMicroseconds(2400)); |
| 249 |
| 250 // Wake up really late. |
| 251 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(8)); |
| 252 CheckPacketIsSentImmediately(); |
| 253 CheckPacketIsSentImmediately(); |
| 254 CheckPacketIsSentImmediately(); |
| 255 CheckPacketIsSentImmediately(); |
| 256 CheckPacketIsSentImmediately(); |
| 257 CheckPacketIsDelayed(QuicTime::Delta::FromMicroseconds(2400)); |
| 258 |
| 259 // Wake up really late again, but application pause partway through. |
| 260 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(8)); |
| 261 CheckPacketIsSentImmediately(); |
| 262 CheckPacketIsSentImmediately(); |
| 263 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(100)); |
| 264 CheckPacketIsSentImmediately(); |
| 265 CheckPacketIsSentImmediately(); |
| 266 CheckPacketIsSentImmediately(); |
| 267 CheckPacketIsDelayed(QuicTime::Delta::FromMicroseconds(2200)); |
| 268 |
| 269 // Wake up too early. |
| 270 CheckPacketIsDelayed(QuicTime::Delta::FromMicroseconds(2200)); |
| 271 |
| 272 // Wake up early, but after enough time has passed to permit a send. |
| 273 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1200)); |
| 274 CheckPacketIsSentImmediately(); |
| 275 CheckPacketIsDelayed(QuicTime::Delta::FromMicroseconds(2600)); |
| 276 } |
| 277 |
207 TEST_F(PacingSenderTest, InitialBurst) { | 278 TEST_F(PacingSenderTest, InitialBurst) { |
208 pacing_sender_.reset(); | 279 pacing_sender_.reset(); |
209 mock_sender_ = new StrictMock<MockSendAlgorithm>(); | 280 mock_sender_ = new StrictMock<MockSendAlgorithm>(); |
210 pacing_sender_.reset(new PacingSender(mock_sender_, | 281 pacing_sender_.reset(new PacingSender(mock_sender_, |
211 QuicTime::Delta::FromMilliseconds(1), | 282 QuicTime::Delta::FromMilliseconds(1), |
212 10)); | 283 10)); |
| 284 // Start the test in slow start. |
| 285 EXPECT_CALL(*mock_sender_, InSlowStart()).WillRepeatedly(Return(true)); |
213 | 286 |
214 // Configure bandwith of 1 packet per 2 ms, for which the pacing rate | 287 // Configure bandwith of 1 packet per 2 ms, for which the pacing rate |
215 // will be 1 packet per 1 ms. | 288 // will be 1 packet per 1 ms. |
216 EXPECT_CALL(*mock_sender_, BandwidthEstimate()) | 289 EXPECT_CALL(*mock_sender_, BandwidthEstimate()) |
217 .WillRepeatedly(Return(QuicBandwidth::FromBytesAndTimeDelta( | 290 .WillRepeatedly(Return(QuicBandwidth::FromBytesAndTimeDelta( |
218 kMaxPacketSize, QuicTime::Delta::FromMilliseconds(2)))); | 291 kMaxPacketSize, QuicTime::Delta::FromMilliseconds(2)))); |
219 | 292 |
220 // Update the RTT and verify that the first 10 packets aren't paced. | 293 // Update the RTT and verify that the first 10 packets aren't paced. |
221 EXPECT_CALL(*mock_sender_, OnCongestionEvent(true, kBytesInFlight, _, _)); | 294 EXPECT_CALL(*mock_sender_, OnCongestionEvent(true, kBytesInFlight, _, _)); |
222 SendAlgorithmInterface::CongestionMap empty_map; | 295 SendAlgorithmInterface::CongestionMap empty_map; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 | 327 |
255 CheckPacketIsSentImmediately(); | 328 CheckPacketIsSentImmediately(); |
256 CheckPacketIsSentImmediately(); | 329 CheckPacketIsSentImmediately(); |
257 CheckPacketIsSentImmediately(); | 330 CheckPacketIsSentImmediately(); |
258 | 331 |
259 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); | 332 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
260 } | 333 } |
261 | 334 |
262 } // namespace test | 335 } // namespace test |
263 } // namespace net | 336 } // namespace net |
OLD | NEW |