| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 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/general_loss_algorithm.h" | 5 #include "net/quic/congestion_control/general_loss_algorithm.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "net/quic/congestion_control/rtt_stats.h" | 10 #include "net/quic/congestion_control/rtt_stats.h" |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 118 |
| 119 TEST_F(GeneralLossAlgorithmTest, EarlyRetransmit1Packet) { | 119 TEST_F(GeneralLossAlgorithmTest, EarlyRetransmit1Packet) { |
| 120 const size_t kNumSentPackets = 2; | 120 const size_t kNumSentPackets = 2; |
| 121 // Transmit 2 packets. | 121 // Transmit 2 packets. |
| 122 for (size_t i = 1; i <= kNumSentPackets; ++i) { | 122 for (size_t i = 1; i <= kNumSentPackets; ++i) { |
| 123 SendDataPacket(i); | 123 SendDataPacket(i); |
| 124 } | 124 } |
| 125 // Early retransmit when the final packet gets acked and the first is nacked. | 125 // Early retransmit when the final packet gets acked and the first is nacked. |
| 126 unacked_packets_.RemoveFromInFlight(2); | 126 unacked_packets_.RemoveFromInFlight(2); |
| 127 VerifyLosses(2, nullptr, 0); | 127 VerifyLosses(2, nullptr, 0); |
| 128 EXPECT_EQ(clock_.Now().Add(rtt_stats_.smoothed_rtt().Multiply(1.25)), | 128 EXPECT_EQ(clock_.Now() + 1.25 * rtt_stats_.smoothed_rtt(), |
| 129 loss_algorithm_.GetLossTimeout()); | 129 loss_algorithm_.GetLossTimeout()); |
| 130 | 130 |
| 131 clock_.AdvanceTime(rtt_stats_.latest_rtt().Multiply(1.25)); | 131 clock_.AdvanceTime(1.25 * rtt_stats_.latest_rtt()); |
| 132 QuicPacketNumber lost[] = {1}; | 132 QuicPacketNumber lost[] = {1}; |
| 133 VerifyLosses(2, lost, arraysize(lost)); | 133 VerifyLosses(2, lost, arraysize(lost)); |
| 134 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); | 134 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); |
| 135 } | 135 } |
| 136 | 136 |
| 137 TEST_F(GeneralLossAlgorithmTest, EarlyRetransmitAllPackets) { | 137 TEST_F(GeneralLossAlgorithmTest, EarlyRetransmitAllPackets) { |
| 138 const size_t kNumSentPackets = 5; | 138 const size_t kNumSentPackets = 5; |
| 139 for (size_t i = 1; i <= kNumSentPackets; ++i) { | 139 for (size_t i = 1; i <= kNumSentPackets; ++i) { |
| 140 SendDataPacket(i); | 140 SendDataPacket(i); |
| 141 // Advance the time 1/4 RTT between 3 and 4. | 141 // Advance the time 1/4 RTT between 3 and 4. |
| 142 if (i == 3) { | 142 if (i == 3) { |
| 143 clock_.AdvanceTime(rtt_stats_.smoothed_rtt().Multiply(0.25)); | 143 clock_.AdvanceTime(0.25 * rtt_stats_.smoothed_rtt()); |
| 144 } | 144 } |
| 145 } | 145 } |
| 146 | 146 |
| 147 // Early retransmit when the final packet gets acked and 1.25 RTTs have | 147 // Early retransmit when the final packet gets acked and 1.25 RTTs have |
| 148 // elapsed since the packets were sent. | 148 // elapsed since the packets were sent. |
| 149 unacked_packets_.RemoveFromInFlight(kNumSentPackets); | 149 unacked_packets_.RemoveFromInFlight(kNumSentPackets); |
| 150 // This simulates a single ack following multiple missing packets with FACK. | 150 // This simulates a single ack following multiple missing packets with FACK. |
| 151 QuicPacketNumber lost[] = {1, 2}; | 151 QuicPacketNumber lost[] = {1, 2}; |
| 152 VerifyLosses(kNumSentPackets, lost, arraysize(lost)); | 152 VerifyLosses(kNumSentPackets, lost, arraysize(lost)); |
| 153 // The time has already advanced 1/4 an RTT, so ensure the timeout is set | 153 // The time has already advanced 1/4 an RTT, so ensure the timeout is set |
| 154 // 1.25 RTTs after the earliest pending packet(3), not the last(4). | 154 // 1.25 RTTs after the earliest pending packet(3), not the last(4). |
| 155 EXPECT_EQ(clock_.Now().Add(rtt_stats_.smoothed_rtt()), | 155 EXPECT_EQ(clock_.Now() + rtt_stats_.smoothed_rtt(), |
| 156 loss_algorithm_.GetLossTimeout()); | 156 loss_algorithm_.GetLossTimeout()); |
| 157 | 157 |
| 158 clock_.AdvanceTime(rtt_stats_.smoothed_rtt()); | 158 clock_.AdvanceTime(rtt_stats_.smoothed_rtt()); |
| 159 QuicPacketNumber lost2[] = {1, 2, 3}; | 159 QuicPacketNumber lost2[] = {1, 2, 3}; |
| 160 VerifyLosses(kNumSentPackets, lost2, arraysize(lost2)); | 160 VerifyLosses(kNumSentPackets, lost2, arraysize(lost2)); |
| 161 EXPECT_EQ(clock_.Now().Add(rtt_stats_.smoothed_rtt().Multiply(0.25)), | 161 EXPECT_EQ(clock_.Now() + 0.25 * rtt_stats_.smoothed_rtt(), |
| 162 loss_algorithm_.GetLossTimeout()); | 162 loss_algorithm_.GetLossTimeout()); |
| 163 clock_.AdvanceTime(rtt_stats_.smoothed_rtt().Multiply(0.25)); | 163 clock_.AdvanceTime(0.25 * rtt_stats_.smoothed_rtt()); |
| 164 QuicPacketNumber lost3[] = {1, 2, 3, 4}; | 164 QuicPacketNumber lost3[] = {1, 2, 3, 4}; |
| 165 VerifyLosses(kNumSentPackets, lost3, arraysize(lost3)); | 165 VerifyLosses(kNumSentPackets, lost3, arraysize(lost3)); |
| 166 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); | 166 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); |
| 167 } | 167 } |
| 168 | 168 |
| 169 TEST_F(GeneralLossAlgorithmTest, DontEarlyRetransmitNeuteredPacket) { | 169 TEST_F(GeneralLossAlgorithmTest, DontEarlyRetransmitNeuteredPacket) { |
| 170 const size_t kNumSentPackets = 2; | 170 const size_t kNumSentPackets = 2; |
| 171 // Transmit 2 packets. | 171 // Transmit 2 packets. |
| 172 for (size_t i = 1; i <= kNumSentPackets; ++i) { | 172 for (size_t i = 1; i <= kNumSentPackets; ++i) { |
| 173 SendDataPacket(i); | 173 SendDataPacket(i); |
| 174 } | 174 } |
| 175 // Neuter packet 1. | 175 // Neuter packet 1. |
| 176 unacked_packets_.RemoveRetransmittability(1); | 176 unacked_packets_.RemoveRetransmittability(1); |
| 177 | 177 |
| 178 // Early retransmit when the final packet gets acked and the first is nacked. | 178 // Early retransmit when the final packet gets acked and the first is nacked. |
| 179 unacked_packets_.IncreaseLargestObserved(2); | 179 unacked_packets_.IncreaseLargestObserved(2); |
| 180 unacked_packets_.RemoveFromInFlight(2); | 180 unacked_packets_.RemoveFromInFlight(2); |
| 181 VerifyLosses(2, nullptr, 0); | 181 VerifyLosses(2, nullptr, 0); |
| 182 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); | 182 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); |
| 183 } | 183 } |
| 184 | 184 |
| 185 TEST_F(GeneralLossAlgorithmTest, AlwaysLosePacketSent1RTTEarlier) { | 185 TEST_F(GeneralLossAlgorithmTest, AlwaysLosePacketSent1RTTEarlier) { |
| 186 // Transmit 1 packet and then wait an rtt plus 1ms. | 186 // Transmit 1 packet and then wait an rtt plus 1ms. |
| 187 SendDataPacket(1); | 187 SendDataPacket(1); |
| 188 clock_.AdvanceTime( | 188 clock_.AdvanceTime(rtt_stats_.smoothed_rtt() + |
| 189 rtt_stats_.smoothed_rtt().Add(QuicTime::Delta::FromMilliseconds(1))); | 189 QuicTime::Delta::FromMilliseconds(1)); |
| 190 | 190 |
| 191 // Transmit 2 packets. | 191 // Transmit 2 packets. |
| 192 SendDataPacket(2); | 192 SendDataPacket(2); |
| 193 SendDataPacket(3); | 193 SendDataPacket(3); |
| 194 | 194 |
| 195 // Wait another RTT and ack 2. | 195 // Wait another RTT and ack 2. |
| 196 clock_.AdvanceTime(rtt_stats_.smoothed_rtt()); | 196 clock_.AdvanceTime(rtt_stats_.smoothed_rtt()); |
| 197 unacked_packets_.IncreaseLargestObserved(2); | 197 unacked_packets_.IncreaseLargestObserved(2); |
| 198 unacked_packets_.RemoveFromInFlight(2); | 198 unacked_packets_.RemoveFromInFlight(2); |
| 199 QuicPacketNumber lost[] = {1}; | 199 QuicPacketNumber lost[] = {1}; |
| 200 VerifyLosses(2, lost, arraysize(lost)); | 200 VerifyLosses(2, lost, arraysize(lost)); |
| 201 } | 201 } |
| 202 | 202 |
| 203 // Time-based loss detection tests. | 203 // Time-based loss detection tests. |
| 204 TEST_F(GeneralLossAlgorithmTest, NoLossFor500Nacks) { | 204 TEST_F(GeneralLossAlgorithmTest, NoLossFor500Nacks) { |
| 205 loss_algorithm_.SetLossDetectionType(kTime); | 205 loss_algorithm_.SetLossDetectionType(kTime); |
| 206 const size_t kNumSentPackets = 5; | 206 const size_t kNumSentPackets = 5; |
| 207 // Transmit 5 packets. | 207 // Transmit 5 packets. |
| 208 for (size_t i = 1; i <= kNumSentPackets; ++i) { | 208 for (size_t i = 1; i <= kNumSentPackets; ++i) { |
| 209 SendDataPacket(i); | 209 SendDataPacket(i); |
| 210 } | 210 } |
| 211 unacked_packets_.RemoveFromInFlight(2); | 211 unacked_packets_.RemoveFromInFlight(2); |
| 212 for (size_t i = 1; i < 500; ++i) { | 212 for (size_t i = 1; i < 500; ++i) { |
| 213 VerifyLosses(2, nullptr, 0); | 213 VerifyLosses(2, nullptr, 0); |
| 214 } | 214 } |
| 215 EXPECT_EQ(rtt_stats_.smoothed_rtt().Multiply(1.25), | 215 EXPECT_EQ(1.25 * rtt_stats_.smoothed_rtt(), |
| 216 loss_algorithm_.GetLossTimeout().Subtract(clock_.Now())); | 216 loss_algorithm_.GetLossTimeout() - clock_.Now()); |
| 217 } | 217 } |
| 218 | 218 |
| 219 TEST_F(GeneralLossAlgorithmTest, NoLossUntilTimeout) { | 219 TEST_F(GeneralLossAlgorithmTest, NoLossUntilTimeout) { |
| 220 loss_algorithm_.SetLossDetectionType(kTime); | 220 loss_algorithm_.SetLossDetectionType(kTime); |
| 221 const size_t kNumSentPackets = 10; | 221 const size_t kNumSentPackets = 10; |
| 222 // Transmit 10 packets at 1/10th an RTT interval. | 222 // Transmit 10 packets at 1/10th an RTT interval. |
| 223 for (size_t i = 1; i <= kNumSentPackets; ++i) { | 223 for (size_t i = 1; i <= kNumSentPackets; ++i) { |
| 224 SendDataPacket(i); | 224 SendDataPacket(i); |
| 225 clock_.AdvanceTime(rtt_stats_.smoothed_rtt().Multiply(0.1)); | 225 clock_.AdvanceTime(0.1 * rtt_stats_.smoothed_rtt()); |
| 226 } | 226 } |
| 227 // Expect the timer to not be set. | 227 // Expect the timer to not be set. |
| 228 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); | 228 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); |
| 229 // The packet should not be lost until 1.25 RTTs pass. | 229 // The packet should not be lost until 1.25 RTTs pass. |
| 230 unacked_packets_.RemoveFromInFlight(2); | 230 unacked_packets_.RemoveFromInFlight(2); |
| 231 VerifyLosses(2, nullptr, 0); | 231 VerifyLosses(2, nullptr, 0); |
| 232 // Expect the timer to be set to 0.25 RTT's in the future. | 232 // Expect the timer to be set to 0.25 RTT's in the future. |
| 233 EXPECT_EQ(rtt_stats_.smoothed_rtt().Multiply(0.25), | 233 EXPECT_EQ(0.25 * rtt_stats_.smoothed_rtt(), |
| 234 loss_algorithm_.GetLossTimeout().Subtract(clock_.Now())); | 234 loss_algorithm_.GetLossTimeout() - clock_.Now()); |
| 235 VerifyLosses(2, nullptr, 0); | 235 VerifyLosses(2, nullptr, 0); |
| 236 clock_.AdvanceTime(rtt_stats_.smoothed_rtt().Multiply(0.25)); | 236 clock_.AdvanceTime(0.25 * rtt_stats_.smoothed_rtt()); |
| 237 QuicPacketNumber lost[] = {1}; | 237 QuicPacketNumber lost[] = {1}; |
| 238 VerifyLosses(2, lost, arraysize(lost)); | 238 VerifyLosses(2, lost, arraysize(lost)); |
| 239 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); | 239 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); |
| 240 } | 240 } |
| 241 | 241 |
| 242 TEST_F(GeneralLossAlgorithmTest, NoLossWithoutNack) { | 242 TEST_F(GeneralLossAlgorithmTest, NoLossWithoutNack) { |
| 243 loss_algorithm_.SetLossDetectionType(kTime); | 243 loss_algorithm_.SetLossDetectionType(kTime); |
| 244 const size_t kNumSentPackets = 10; | 244 const size_t kNumSentPackets = 10; |
| 245 // Transmit 10 packets at 1/10th an RTT interval. | 245 // Transmit 10 packets at 1/10th an RTT interval. |
| 246 for (size_t i = 1; i <= kNumSentPackets; ++i) { | 246 for (size_t i = 1; i <= kNumSentPackets; ++i) { |
| 247 SendDataPacket(i); | 247 SendDataPacket(i); |
| 248 clock_.AdvanceTime(rtt_stats_.smoothed_rtt().Multiply(0.1)); | 248 clock_.AdvanceTime(0.1 * rtt_stats_.smoothed_rtt()); |
| 249 } | 249 } |
| 250 // Expect the timer to not be set. | 250 // Expect the timer to not be set. |
| 251 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); | 251 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); |
| 252 // The packet should not be lost without a nack. | 252 // The packet should not be lost without a nack. |
| 253 unacked_packets_.RemoveFromInFlight(1); | 253 unacked_packets_.RemoveFromInFlight(1); |
| 254 VerifyLosses(1, nullptr, 0); | 254 VerifyLosses(1, nullptr, 0); |
| 255 // The timer should still not be set. | 255 // The timer should still not be set. |
| 256 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); | 256 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); |
| 257 clock_.AdvanceTime(rtt_stats_.smoothed_rtt().Multiply(0.25)); | 257 clock_.AdvanceTime(0.25 * rtt_stats_.smoothed_rtt()); |
| 258 VerifyLosses(1, nullptr, 0); | 258 VerifyLosses(1, nullptr, 0); |
| 259 clock_.AdvanceTime(rtt_stats_.smoothed_rtt()); | 259 clock_.AdvanceTime(rtt_stats_.smoothed_rtt()); |
| 260 VerifyLosses(1, nullptr, 0); | 260 VerifyLosses(1, nullptr, 0); |
| 261 | 261 |
| 262 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); | 262 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); |
| 263 } | 263 } |
| 264 | 264 |
| 265 TEST_F(GeneralLossAlgorithmTest, MultipleLossesAtOnce) { | 265 TEST_F(GeneralLossAlgorithmTest, MultipleLossesAtOnce) { |
| 266 loss_algorithm_.SetLossDetectionType(kTime); | 266 loss_algorithm_.SetLossDetectionType(kTime); |
| 267 const size_t kNumSentPackets = 10; | 267 const size_t kNumSentPackets = 10; |
| 268 // Transmit 10 packets at once and then go forward an RTT. | 268 // Transmit 10 packets at once and then go forward an RTT. |
| 269 for (size_t i = 1; i <= kNumSentPackets; ++i) { | 269 for (size_t i = 1; i <= kNumSentPackets; ++i) { |
| 270 SendDataPacket(i); | 270 SendDataPacket(i); |
| 271 } | 271 } |
| 272 clock_.AdvanceTime(rtt_stats_.smoothed_rtt()); | 272 clock_.AdvanceTime(rtt_stats_.smoothed_rtt()); |
| 273 // Expect the timer to not be set. | 273 // Expect the timer to not be set. |
| 274 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); | 274 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); |
| 275 // The packet should not be lost until 1.25 RTTs pass. | 275 // The packet should not be lost until 1.25 RTTs pass. |
| 276 unacked_packets_.RemoveFromInFlight(10); | 276 unacked_packets_.RemoveFromInFlight(10); |
| 277 VerifyLosses(10, nullptr, 0); | 277 VerifyLosses(10, nullptr, 0); |
| 278 // Expect the timer to be set to 0.25 RTT's in the future. | 278 // Expect the timer to be set to 0.25 RTT's in the future. |
| 279 EXPECT_EQ(rtt_stats_.smoothed_rtt().Multiply(0.25), | 279 EXPECT_EQ(0.25 * rtt_stats_.smoothed_rtt(), |
| 280 loss_algorithm_.GetLossTimeout().Subtract(clock_.Now())); | 280 loss_algorithm_.GetLossTimeout() - clock_.Now()); |
| 281 clock_.AdvanceTime(rtt_stats_.smoothed_rtt().Multiply(0.25)); | 281 clock_.AdvanceTime(0.25 * rtt_stats_.smoothed_rtt()); |
| 282 QuicPacketNumber lost[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; | 282 QuicPacketNumber lost[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; |
| 283 VerifyLosses(10, lost, arraysize(lost)); | 283 VerifyLosses(10, lost, arraysize(lost)); |
| 284 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); | 284 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); |
| 285 } | 285 } |
| 286 | 286 |
| 287 TEST_F(GeneralLossAlgorithmTest, NoSpuriousLossesFromLargeReordering) { | 287 TEST_F(GeneralLossAlgorithmTest, NoSpuriousLossesFromLargeReordering) { |
| 288 FLAGS_quic_loss_recovery_use_largest_acked = true; | 288 FLAGS_quic_loss_recovery_use_largest_acked = true; |
| 289 loss_algorithm_.SetLossDetectionType(kTime); | 289 loss_algorithm_.SetLossDetectionType(kTime); |
| 290 const size_t kNumSentPackets = 10; | 290 const size_t kNumSentPackets = 10; |
| 291 // Transmit 10 packets at once and then go forward an RTT. | 291 // Transmit 10 packets at once and then go forward an RTT. |
| 292 for (size_t i = 1; i <= kNumSentPackets; ++i) { | 292 for (size_t i = 1; i <= kNumSentPackets; ++i) { |
| 293 SendDataPacket(i); | 293 SendDataPacket(i); |
| 294 } | 294 } |
| 295 clock_.AdvanceTime(rtt_stats_.smoothed_rtt()); | 295 clock_.AdvanceTime(rtt_stats_.smoothed_rtt()); |
| 296 // Expect the timer to not be set. | 296 // Expect the timer to not be set. |
| 297 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); | 297 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); |
| 298 // The packet should not be lost until 1.25 RTTs pass. | 298 // The packet should not be lost until 1.25 RTTs pass. |
| 299 | 299 |
| 300 unacked_packets_.RemoveFromInFlight(10); | 300 unacked_packets_.RemoveFromInFlight(10); |
| 301 VerifyLosses(10, nullptr, 0); | 301 VerifyLosses(10, nullptr, 0); |
| 302 // Expect the timer to be set to 0.25 RTT's in the future. | 302 // Expect the timer to be set to 0.25 RTT's in the future. |
| 303 EXPECT_EQ(rtt_stats_.smoothed_rtt().Multiply(0.25), | 303 EXPECT_EQ(0.25 * rtt_stats_.smoothed_rtt(), |
| 304 loss_algorithm_.GetLossTimeout().Subtract(clock_.Now())); | 304 loss_algorithm_.GetLossTimeout() - clock_.Now()); |
| 305 clock_.AdvanceTime(rtt_stats_.smoothed_rtt().Multiply(0.25)); | 305 clock_.AdvanceTime(0.25 * rtt_stats_.smoothed_rtt()); |
| 306 // Now ack packets 1 to 9 and ensure the timer is no longer set and no packets | 306 // Now ack packets 1 to 9 and ensure the timer is no longer set and no packets |
| 307 // are lost. | 307 // are lost. |
| 308 for (QuicPacketNumber i = 1; i <= 9; ++i) { | 308 for (QuicPacketNumber i = 1; i <= 9; ++i) { |
| 309 unacked_packets_.RemoveFromInFlight(i); | 309 unacked_packets_.RemoveFromInFlight(i); |
| 310 VerifyLosses(i, nullptr, 0); | 310 VerifyLosses(i, nullptr, 0); |
| 311 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); | 311 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); |
| 312 } | 312 } |
| 313 } | 313 } |
| 314 | 314 |
| 315 TEST_F(GeneralLossAlgorithmTest, IncreaseThresholdUponSpuriousLoss) { | 315 TEST_F(GeneralLossAlgorithmTest, IncreaseThresholdUponSpuriousLoss) { |
| 316 loss_algorithm_.SetLossDetectionType(kAdaptiveTime); | 316 loss_algorithm_.SetLossDetectionType(kAdaptiveTime); |
| 317 EXPECT_EQ(4, loss_algorithm_.reordering_shift()); | 317 EXPECT_EQ(4, loss_algorithm_.reordering_shift()); |
| 318 const size_t kNumSentPackets = 10; | 318 const size_t kNumSentPackets = 10; |
| 319 // Transmit 2 packets at 1/10th an RTT interval. | 319 // Transmit 2 packets at 1/10th an RTT interval. |
| 320 for (size_t i = 1; i <= kNumSentPackets; ++i) { | 320 for (size_t i = 1; i <= kNumSentPackets; ++i) { |
| 321 SendDataPacket(i); | 321 SendDataPacket(i); |
| 322 clock_.AdvanceTime(rtt_stats_.smoothed_rtt().Multiply(0.1)); | 322 clock_.AdvanceTime(0.1 * rtt_stats_.smoothed_rtt()); |
| 323 } | 323 } |
| 324 EXPECT_EQ(QuicTime::Zero().Add(rtt_stats_.smoothed_rtt()), clock_.Now()); | 324 EXPECT_EQ(QuicTime::Zero() + rtt_stats_.smoothed_rtt(), clock_.Now()); |
| 325 | 325 |
| 326 // Expect the timer to not be set. | 326 // Expect the timer to not be set. |
| 327 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); | 327 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); |
| 328 // Packet 1 should not be lost until 1/16 RTTs pass. | 328 // Packet 1 should not be lost until 1/16 RTTs pass. |
| 329 unacked_packets_.RemoveFromInFlight(2); | 329 unacked_packets_.RemoveFromInFlight(2); |
| 330 VerifyLosses(2, nullptr, 0); | 330 VerifyLosses(2, nullptr, 0); |
| 331 // Expect the timer to be set to 1/16 RTT's in the future. | 331 // Expect the timer to be set to 1/16 RTT's in the future. |
| 332 EXPECT_EQ(rtt_stats_.smoothed_rtt().Multiply(1.0f / 16), | 332 EXPECT_EQ(rtt_stats_.smoothed_rtt() * (1.0f / 16), |
| 333 loss_algorithm_.GetLossTimeout().Subtract(clock_.Now())); | 333 loss_algorithm_.GetLossTimeout() - clock_.Now()); |
| 334 VerifyLosses(2, nullptr, 0); | 334 VerifyLosses(2, nullptr, 0); |
| 335 clock_.AdvanceTime(rtt_stats_.smoothed_rtt().Multiply(1.0f / 16)); | 335 clock_.AdvanceTime(rtt_stats_.smoothed_rtt() * (1.0f / 16)); |
| 336 QuicPacketNumber lost[] = {1}; | 336 QuicPacketNumber lost[] = {1}; |
| 337 VerifyLosses(2, lost, arraysize(lost)); | 337 VerifyLosses(2, lost, arraysize(lost)); |
| 338 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); | 338 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); |
| 339 // Retransmit packet 1 as 11 and 2 as 12. | 339 // Retransmit packet 1 as 11 and 2 as 12. |
| 340 SendDataPacket(11); | 340 SendDataPacket(11); |
| 341 SendDataPacket(12); | 341 SendDataPacket(12); |
| 342 | 342 |
| 343 // Advance the time 1/4 RTT and indicate the loss was spurious. | 343 // Advance the time 1/4 RTT and indicate the loss was spurious. |
| 344 // The new threshold should be 1/2 RTT. | 344 // The new threshold should be 1/2 RTT. |
| 345 clock_.AdvanceTime(rtt_stats_.smoothed_rtt().Multiply(1.0f / 4)); | 345 clock_.AdvanceTime(rtt_stats_.smoothed_rtt() * (1.0f / 4)); |
| 346 loss_algorithm_.SpuriousRetransmitDetected(unacked_packets_, clock_.Now(), | 346 loss_algorithm_.SpuriousRetransmitDetected(unacked_packets_, clock_.Now(), |
| 347 rtt_stats_, 11); | 347 rtt_stats_, 11); |
| 348 EXPECT_EQ(1, loss_algorithm_.reordering_shift()); | 348 EXPECT_EQ(1, loss_algorithm_.reordering_shift()); |
| 349 | 349 |
| 350 // Detect another spurious retransmit and ensure the threshold doesn't | 350 // Detect another spurious retransmit and ensure the threshold doesn't |
| 351 // increase again. | 351 // increase again. |
| 352 loss_algorithm_.SpuriousRetransmitDetected(unacked_packets_, clock_.Now(), | 352 loss_algorithm_.SpuriousRetransmitDetected(unacked_packets_, clock_.Now(), |
| 353 rtt_stats_, 12); | 353 rtt_stats_, 12); |
| 354 EXPECT_EQ(1, loss_algorithm_.reordering_shift()); | 354 EXPECT_EQ(1, loss_algorithm_.reordering_shift()); |
| 355 } | 355 } |
| 356 | 356 |
| 357 } // namespace | 357 } // namespace |
| 358 } // namespace test | 358 } // namespace test |
| 359 } // namespace net | 359 } // namespace net |
| OLD | NEW |