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 "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/inter_arrival_sender.h" | 7 #include "net/quic/congestion_control/inter_arrival_sender.h" |
8 #include "net/quic/congestion_control/quic_congestion_manager.h" | 8 #include "net/quic/congestion_control/quic_congestion_manager.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 11 matching lines...) Expand all Loading... |
22 class QuicCongestionManagerPeer : public QuicCongestionManager { | 22 class QuicCongestionManagerPeer : public QuicCongestionManager { |
23 public: | 23 public: |
24 explicit QuicCongestionManagerPeer(const QuicClock* clock, | 24 explicit QuicCongestionManagerPeer(const QuicClock* clock, |
25 CongestionFeedbackType congestion_type) | 25 CongestionFeedbackType congestion_type) |
26 : QuicCongestionManager(clock, congestion_type) { | 26 : QuicCongestionManager(clock, congestion_type) { |
27 } | 27 } |
28 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) { | 28 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) { |
29 this->send_algorithm_.reset(send_algorithm); | 29 this->send_algorithm_.reset(send_algorithm); |
30 } | 30 } |
31 | 31 |
32 using QuicCongestionManager::rtt; | 32 QuicTime::Delta rtt() { |
| 33 return rtt_sample_; |
| 34 } |
| 35 |
33 const SendAlgorithmInterface::SentPacketsMap& packet_history_map() { | 36 const SendAlgorithmInterface::SentPacketsMap& packet_history_map() { |
34 return packet_history_map_; | 37 return packet_history_map_; |
35 } | 38 } |
| 39 |
36 private: | 40 private: |
37 DISALLOW_COPY_AND_ASSIGN(QuicCongestionManagerPeer); | 41 DISALLOW_COPY_AND_ASSIGN(QuicCongestionManagerPeer); |
38 }; | 42 }; |
39 | 43 |
40 class QuicCongestionManagerTest : public ::testing::Test { | 44 class QuicCongestionManagerTest : public ::testing::Test { |
41 protected: | 45 protected: |
42 void SetUpCongestionType(CongestionFeedbackType congestion_type) { | 46 void SetUpCongestionType(CongestionFeedbackType congestion_type) { |
43 manager_.reset(new QuicCongestionManagerPeer(&clock_, congestion_type)); | 47 manager_.reset(new QuicCongestionManagerPeer(&clock_, congestion_type)); |
44 } | 48 } |
45 | 49 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 159 |
156 QuicAckFrame ack; | 160 QuicAckFrame ack; |
157 ack.received_info.largest_observed = sequence_number; | 161 ack.received_info.largest_observed = sequence_number; |
158 ack.received_info.delta_time_largest_observed = | 162 ack.received_info.delta_time_largest_observed = |
159 QuicTime::Delta::FromMilliseconds(5); | 163 QuicTime::Delta::FromMilliseconds(5); |
160 manager_->OnIncomingAckFrame(ack, clock_.Now()); | 164 manager_->OnIncomingAckFrame(ack, clock_.Now()); |
161 EXPECT_EQ(manager_->rtt(), expected_rtt); | 165 EXPECT_EQ(manager_->rtt(), expected_rtt); |
162 } | 166 } |
163 | 167 |
164 TEST_F(QuicCongestionManagerTest, RttWithInvalidDelta) { | 168 TEST_F(QuicCongestionManagerTest, RttWithInvalidDelta) { |
165 // Expect that the RTT is infinite since the delta_time_largest_observed is | 169 // Expect that the RTT is equal to the local time elapsed, since the |
166 // larger than the local time elapsed aka invalid. | 170 // delta_time_largest_observed is larger than the local time elapsed |
| 171 // and is hence invalid. |
167 SetUpCongestionType(kFixRate); | 172 SetUpCongestionType(kFixRate); |
168 | 173 |
169 MockSendAlgorithm* send_algorithm = new StrictMock<MockSendAlgorithm>; | 174 MockSendAlgorithm* send_algorithm = new StrictMock<MockSendAlgorithm>; |
170 manager_->SetSendAlgorithm(send_algorithm); | 175 manager_->SetSendAlgorithm(send_algorithm); |
171 | 176 |
172 QuicPacketSequenceNumber sequence_number = 1; | 177 QuicPacketSequenceNumber sequence_number = 1; |
173 QuicTime::Delta expected_rtt = QuicTime::Delta::Infinite(); | 178 QuicTime::Delta expected_rtt = QuicTime::Delta::FromMilliseconds(10); |
174 | 179 |
175 EXPECT_CALL(*send_algorithm, OnPacketSent(_, _, _, _, _)) | 180 EXPECT_CALL(*send_algorithm, OnPacketSent(_, _, _, _, _)) |
176 .Times(1).WillOnce(Return(true)); | 181 .Times(1).WillOnce(Return(true)); |
177 EXPECT_CALL(*send_algorithm, | 182 EXPECT_CALL(*send_algorithm, |
178 OnIncomingAck(sequence_number, _, expected_rtt)).Times(1); | 183 OnIncomingAck(sequence_number, _, expected_rtt)).Times(1); |
179 | 184 |
180 manager_->OnPacketSent(sequence_number, clock_.Now(), 1000, | 185 manager_->OnPacketSent(sequence_number, clock_.Now(), 1000, |
181 NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA); | 186 NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA); |
182 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(10)); | 187 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(10)); |
183 | 188 |
184 QuicAckFrame ack; | 189 QuicAckFrame ack; |
185 ack.received_info.largest_observed = sequence_number; | 190 ack.received_info.largest_observed = sequence_number; |
186 ack.received_info.delta_time_largest_observed = | 191 ack.received_info.delta_time_largest_observed = |
187 QuicTime::Delta::FromMilliseconds(11); | 192 QuicTime::Delta::FromMilliseconds(11); |
188 manager_->OnIncomingAckFrame(ack, clock_.Now()); | 193 manager_->OnIncomingAckFrame(ack, clock_.Now()); |
189 EXPECT_EQ(manager_->rtt(), expected_rtt); | 194 EXPECT_EQ(manager_->rtt(), expected_rtt); |
190 } | 195 } |
191 | 196 |
192 TEST_F(QuicCongestionManagerTest, RttInfiniteDelta) { | 197 TEST_F(QuicCongestionManagerTest, RttWithInfiniteDelta) { |
193 // Expect that the RTT is infinite since the delta_time_largest_observed is | 198 // Expect that the RTT is equal to the local time elapsed, since the |
194 // infinite aka invalid. | 199 // delta_time_largest_observed is infinite, and is hence invalid. |
195 SetUpCongestionType(kFixRate); | 200 SetUpCongestionType(kFixRate); |
196 | 201 |
197 MockSendAlgorithm* send_algorithm = new StrictMock<MockSendAlgorithm>; | 202 MockSendAlgorithm* send_algorithm = new StrictMock<MockSendAlgorithm>; |
198 manager_->SetSendAlgorithm(send_algorithm); | 203 manager_->SetSendAlgorithm(send_algorithm); |
199 | 204 |
200 QuicPacketSequenceNumber sequence_number = 1; | 205 QuicPacketSequenceNumber sequence_number = 1; |
201 QuicTime::Delta expected_rtt = QuicTime::Delta::Infinite(); | 206 QuicTime::Delta expected_rtt = QuicTime::Delta::FromMilliseconds(10); |
202 | 207 |
203 EXPECT_CALL(*send_algorithm, OnPacketSent(_, _, _, _, _)) | 208 EXPECT_CALL(*send_algorithm, OnPacketSent(_, _, _, _, _)) |
204 .Times(1).WillOnce(Return(true)); | 209 .Times(1).WillOnce(Return(true)); |
205 EXPECT_CALL(*send_algorithm, | 210 EXPECT_CALL(*send_algorithm, |
206 OnIncomingAck(sequence_number, _, expected_rtt)).Times(1); | 211 OnIncomingAck(sequence_number, _, expected_rtt)).Times(1); |
207 | 212 |
208 manager_->OnPacketSent(sequence_number, clock_.Now(), 1000, | 213 manager_->OnPacketSent(sequence_number, clock_.Now(), 1000, |
209 NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA); | 214 NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA); |
210 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(10)); | 215 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(10)); |
211 | 216 |
(...skipping 24 matching lines...) Expand all Loading... |
236 NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA); | 241 NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA); |
237 clock_.AdvanceTime(expected_rtt); | 242 clock_.AdvanceTime(expected_rtt); |
238 | 243 |
239 QuicAckFrame ack; | 244 QuicAckFrame ack; |
240 ack.received_info.largest_observed = sequence_number; | 245 ack.received_info.largest_observed = sequence_number; |
241 ack.received_info.delta_time_largest_observed = QuicTime::Delta::Zero(); | 246 ack.received_info.delta_time_largest_observed = QuicTime::Delta::Zero(); |
242 manager_->OnIncomingAckFrame(ack, clock_.Now()); | 247 manager_->OnIncomingAckFrame(ack, clock_.Now()); |
243 EXPECT_EQ(manager_->rtt(), expected_rtt); | 248 EXPECT_EQ(manager_->rtt(), expected_rtt); |
244 } | 249 } |
245 | 250 |
| 251 TEST_F(QuicCongestionManagerTest, GetTransmissionDelayMin) { |
| 252 SetUpCongestionType(kFixRate); |
| 253 |
| 254 MockSendAlgorithm* send_algorithm = new StrictMock<MockSendAlgorithm>; |
| 255 manager_->SetSendAlgorithm(send_algorithm); |
| 256 |
| 257 QuicTime::Delta delay = QuicTime::Delta::FromMilliseconds(1); |
| 258 EXPECT_CALL(*send_algorithm, RetransmissionDelay()) |
| 259 .WillOnce(Return(delay)); |
| 260 |
| 261 EXPECT_EQ(QuicTime::Delta::FromMilliseconds(200), |
| 262 manager_->GetRetransmissionDelay(1, 1)); |
| 263 } |
| 264 |
| 265 TEST_F(QuicCongestionManagerTest, GetTransmissionDelayMax) { |
| 266 SetUpCongestionType(kFixRate); |
| 267 |
| 268 MockSendAlgorithm* send_algorithm = new StrictMock<MockSendAlgorithm>; |
| 269 manager_->SetSendAlgorithm(send_algorithm); |
| 270 |
| 271 QuicTime::Delta delay = QuicTime::Delta::FromSeconds(500); |
| 272 EXPECT_CALL(*send_algorithm, RetransmissionDelay()) |
| 273 .WillOnce(Return(delay)); |
| 274 |
| 275 EXPECT_EQ(QuicTime::Delta::FromSeconds(60), |
| 276 manager_->GetRetransmissionDelay(1, 1)); |
| 277 } |
| 278 |
| 279 TEST_F(QuicCongestionManagerTest, GetTransmissionDelay) { |
| 280 SetUpCongestionType(kFixRate); |
| 281 |
| 282 MockSendAlgorithm* send_algorithm = new StrictMock<MockSendAlgorithm>; |
| 283 manager_->SetSendAlgorithm(send_algorithm); |
| 284 |
| 285 QuicTime::Delta delay = QuicTime::Delta::FromMilliseconds(500); |
| 286 EXPECT_CALL(*send_algorithm, RetransmissionDelay()) |
| 287 .WillRepeatedly(Return(delay)); |
| 288 |
| 289 const int kUnackedPackets = 6; |
| 290 // Delay should back off exponentially. |
| 291 for (int i = 0; i < 5; ++i) { |
| 292 EXPECT_EQ(delay, manager_->GetRetransmissionDelay(kUnackedPackets, i)); |
| 293 delay = delay.Add(delay); |
| 294 } |
| 295 } |
| 296 |
| 297 TEST_F(QuicCongestionManagerTest, GetTransmissionDelayTailDrop) { |
| 298 SetUpCongestionType(kFixRate); |
| 299 |
| 300 MockSendAlgorithm* send_algorithm = new StrictMock<MockSendAlgorithm>; |
| 301 manager_->SetSendAlgorithm(send_algorithm); |
| 302 |
| 303 QuicTime::Delta delay = QuicTime::Delta::FromMilliseconds(500); |
| 304 EXPECT_CALL(*send_algorithm, RetransmissionDelay()) |
| 305 .WillRepeatedly(Return(delay)); |
| 306 |
| 307 // No backoff for the first 5 retransmission. |
| 308 for (int i = 0; i < 5; ++i) { |
| 309 EXPECT_EQ(delay, manager_->GetRetransmissionDelay(1, i)); |
| 310 } |
| 311 |
| 312 // Then backoff starts |
| 313 EXPECT_EQ(delay.Add(delay), manager_->GetRetransmissionDelay(1, 5)); |
| 314 } |
| 315 |
246 } // namespace test | 316 } // namespace test |
247 } // namespace net | 317 } // namespace net |
OLD | NEW |