| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/time_loss_algorithm.h" | 5 #include "net/quic/congestion_control/time_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 "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "net/quic/congestion_control/rtt_stats.h" | 11 #include "net/quic/congestion_control/rtt_stats.h" |
| 12 #include "net/quic/quic_unacked_packet_map.h" | 12 #include "net/quic/quic_unacked_packet_map.h" |
| 13 #include "net/quic/test_tools/mock_clock.h" | 13 #include "net/quic/test_tools/mock_clock.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 using std::vector; | 16 using std::vector; |
| 17 | 17 |
| 18 namespace net { | 18 namespace net { |
| 19 namespace test { | 19 namespace test { |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 // Default packet length. | 22 // Default packet length. |
| 23 const uint32 kDefaultLength = 1000; | 23 const uint32_t kDefaultLength = 1000; |
| 24 | 24 |
| 25 class TimeLossAlgorithmTest : public ::testing::Test { | 25 class TimeLossAlgorithmTest : public ::testing::Test { |
| 26 protected: | 26 protected: |
| 27 TimeLossAlgorithmTest() { | 27 TimeLossAlgorithmTest() { |
| 28 rtt_stats_.UpdateRtt(QuicTime::Delta::FromMilliseconds(100), | 28 rtt_stats_.UpdateRtt(QuicTime::Delta::FromMilliseconds(100), |
| 29 QuicTime::Delta::Zero(), clock_.Now()); | 29 QuicTime::Delta::Zero(), clock_.Now()); |
| 30 } | 30 } |
| 31 | 31 |
| 32 ~TimeLossAlgorithmTest() override { STLDeleteElements(&packets_); } | 32 ~TimeLossAlgorithmTest() override { STLDeleteElements(&packets_); } |
| 33 | 33 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 58 MockClock clock_; | 58 MockClock clock_; |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 TEST_F(TimeLossAlgorithmTest, NoLossFor500Nacks) { | 61 TEST_F(TimeLossAlgorithmTest, NoLossFor500Nacks) { |
| 62 const size_t kNumSentPackets = 5; | 62 const size_t kNumSentPackets = 5; |
| 63 // Transmit 5 packets. | 63 // Transmit 5 packets. |
| 64 for (size_t i = 1; i <= kNumSentPackets; ++i) { | 64 for (size_t i = 1; i <= kNumSentPackets; ++i) { |
| 65 SendDataPacket(i); | 65 SendDataPacket(i); |
| 66 } | 66 } |
| 67 unacked_packets_.RemoveFromInFlight(2); | 67 unacked_packets_.RemoveFromInFlight(2); |
| 68 for (uint16 i = 1; i < 500; ++i) { | 68 for (uint16_t i = 1; i < 500; ++i) { |
| 69 unacked_packets_.NackPacket(1, i); | 69 unacked_packets_.NackPacket(1, i); |
| 70 VerifyLosses(2, nullptr, 0); | 70 VerifyLosses(2, nullptr, 0); |
| 71 } | 71 } |
| 72 EXPECT_EQ(rtt_stats_.smoothed_rtt().Multiply(1.25), | 72 EXPECT_EQ(rtt_stats_.smoothed_rtt().Multiply(1.25), |
| 73 loss_algorithm_.GetLossTimeout().Subtract(clock_.Now())); | 73 loss_algorithm_.GetLossTimeout().Subtract(clock_.Now())); |
| 74 } | 74 } |
| 75 | 75 |
| 76 TEST_F(TimeLossAlgorithmTest, NoLossUntilTimeout) { | 76 TEST_F(TimeLossAlgorithmTest, NoLossUntilTimeout) { |
| 77 const size_t kNumSentPackets = 10; | 77 const size_t kNumSentPackets = 10; |
| 78 // Transmit 10 packets at 1/10th an RTT interval. | 78 // Transmit 10 packets at 1/10th an RTT interval. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 loss_algorithm_.GetLossTimeout().Subtract(clock_.Now())); | 139 loss_algorithm_.GetLossTimeout().Subtract(clock_.Now())); |
| 140 clock_.AdvanceTime(rtt_stats_.smoothed_rtt().Multiply(0.25)); | 140 clock_.AdvanceTime(rtt_stats_.smoothed_rtt().Multiply(0.25)); |
| 141 QuicPacketNumber lost[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; | 141 QuicPacketNumber lost[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; |
| 142 VerifyLosses(10, lost, arraysize(lost)); | 142 VerifyLosses(10, lost, arraysize(lost)); |
| 143 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); | 143 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); |
| 144 } | 144 } |
| 145 | 145 |
| 146 } // namespace | 146 } // namespace |
| 147 } // namespace test | 147 } // namespace test |
| 148 } // namespace net | 148 } // namespace net |
| OLD | NEW |