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 <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "net/quic/congestion_control/rtt_stats.h" | 9 #include "net/quic/congestion_control/rtt_stats.h" |
10 #include "net/quic/congestion_control/tcp_loss_algorithm.h" | 10 #include "net/quic/congestion_control/tcp_loss_algorithm.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 TEST_F(TcpLossAlgorithmTest, EarlyRetransmit1Packet) { | 111 TEST_F(TcpLossAlgorithmTest, EarlyRetransmit1Packet) { |
112 const size_t kNumSentPackets = 2; | 112 const size_t kNumSentPackets = 2; |
113 // Transmit 2 packets. | 113 // Transmit 2 packets. |
114 for (size_t i = 1; i <= kNumSentPackets; ++i) { | 114 for (size_t i = 1; i <= kNumSentPackets; ++i) { |
115 SendDataPacket(i); | 115 SendDataPacket(i); |
116 } | 116 } |
117 // Early retransmit when the final packet gets acked and the first is nacked. | 117 // Early retransmit when the final packet gets acked and the first is nacked. |
118 unacked_packets_.RemoveFromInFlight(2); | 118 unacked_packets_.RemoveFromInFlight(2); |
119 unacked_packets_.NackPacket(1, 1); | 119 unacked_packets_.NackPacket(1, 1); |
120 VerifyLosses(2, nullptr, 0); | 120 VerifyLosses(2, nullptr, 0); |
121 EXPECT_EQ(clock_.Now().Add(rtt_stats_.SmoothedRtt().Multiply(1.25)), | 121 EXPECT_EQ(clock_.Now().Add(rtt_stats_.smoothed_rtt().Multiply(1.25)), |
122 loss_algorithm_.GetLossTimeout()); | 122 loss_algorithm_.GetLossTimeout()); |
123 | 123 |
124 clock_.AdvanceTime(rtt_stats_.latest_rtt().Multiply(1.25)); | 124 clock_.AdvanceTime(rtt_stats_.latest_rtt().Multiply(1.25)); |
125 QuicPacketSequenceNumber lost[] = { 1 }; | 125 QuicPacketSequenceNumber lost[] = { 1 }; |
126 VerifyLosses(2, lost, arraysize(lost)); | 126 VerifyLosses(2, lost, arraysize(lost)); |
127 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); | 127 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); |
128 } | 128 } |
129 | 129 |
130 TEST_F(TcpLossAlgorithmTest, EarlyRetransmitAllPackets) { | 130 TEST_F(TcpLossAlgorithmTest, EarlyRetransmitAllPackets) { |
131 const size_t kNumSentPackets = 5; | 131 const size_t kNumSentPackets = 5; |
132 for (size_t i = 1; i <= kNumSentPackets; ++i) { | 132 for (size_t i = 1; i <= kNumSentPackets; ++i) { |
133 SendDataPacket(i); | 133 SendDataPacket(i); |
134 // Advance the time 1/4 RTT between 3 and 4. | 134 // Advance the time 1/4 RTT between 3 and 4. |
135 if (i == 3) { | 135 if (i == 3) { |
136 clock_.AdvanceTime(rtt_stats_.SmoothedRtt().Multiply(0.25)); | 136 clock_.AdvanceTime(rtt_stats_.smoothed_rtt().Multiply(0.25)); |
137 } | 137 } |
138 } | 138 } |
139 | 139 |
140 // Early retransmit when the final packet gets acked and 1.25 RTTs have | 140 // Early retransmit when the final packet gets acked and 1.25 RTTs have |
141 // elapsed since the packets were sent. | 141 // elapsed since the packets were sent. |
142 unacked_packets_.RemoveFromInFlight(kNumSentPackets); | 142 unacked_packets_.RemoveFromInFlight(kNumSentPackets); |
143 // This simulates a single ack following multiple missing packets with FACK. | 143 // This simulates a single ack following multiple missing packets with FACK. |
144 for (size_t i = 1; i < kNumSentPackets; ++i) { | 144 for (size_t i = 1; i < kNumSentPackets; ++i) { |
145 unacked_packets_.NackPacket(i, kNumSentPackets - i); | 145 unacked_packets_.NackPacket(i, kNumSentPackets - i); |
146 } | 146 } |
147 QuicPacketSequenceNumber lost[] = { 1, 2 }; | 147 QuicPacketSequenceNumber lost[] = { 1, 2 }; |
148 VerifyLosses(kNumSentPackets, lost, arraysize(lost)); | 148 VerifyLosses(kNumSentPackets, lost, arraysize(lost)); |
149 // The time has already advanced 1/4 an RTT, so ensure the timeout is set | 149 // The time has already advanced 1/4 an RTT, so ensure the timeout is set |
150 // 1.25 RTTs after the earliest pending packet(3), not the last(4). | 150 // 1.25 RTTs after the earliest pending packet(3), not the last(4). |
151 EXPECT_EQ(clock_.Now().Add(rtt_stats_.SmoothedRtt()), | 151 EXPECT_EQ(clock_.Now().Add(rtt_stats_.smoothed_rtt()), |
152 loss_algorithm_.GetLossTimeout()); | 152 loss_algorithm_.GetLossTimeout()); |
153 | 153 |
154 clock_.AdvanceTime(rtt_stats_.SmoothedRtt()); | 154 clock_.AdvanceTime(rtt_stats_.smoothed_rtt()); |
155 QuicPacketSequenceNumber lost2[] = { 1, 2, 3 }; | 155 QuicPacketSequenceNumber lost2[] = { 1, 2, 3 }; |
156 VerifyLosses(kNumSentPackets, lost2, arraysize(lost2)); | 156 VerifyLosses(kNumSentPackets, lost2, arraysize(lost2)); |
157 EXPECT_EQ(clock_.Now().Add(rtt_stats_.SmoothedRtt().Multiply(0.25)), | 157 EXPECT_EQ(clock_.Now().Add(rtt_stats_.smoothed_rtt().Multiply(0.25)), |
158 loss_algorithm_.GetLossTimeout()); | 158 loss_algorithm_.GetLossTimeout()); |
159 clock_.AdvanceTime(rtt_stats_.SmoothedRtt().Multiply(0.25)); | 159 clock_.AdvanceTime(rtt_stats_.smoothed_rtt().Multiply(0.25)); |
160 QuicPacketSequenceNumber lost3[] = { 1, 2, 3, 4 }; | 160 QuicPacketSequenceNumber lost3[] = { 1, 2, 3, 4 }; |
161 VerifyLosses(kNumSentPackets, lost3, arraysize(lost3)); | 161 VerifyLosses(kNumSentPackets, lost3, arraysize(lost3)); |
162 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); | 162 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); |
163 } | 163 } |
164 | 164 |
165 TEST_F(TcpLossAlgorithmTest, DontEarlyRetransmitNeuteredPacket) { | 165 TEST_F(TcpLossAlgorithmTest, DontEarlyRetransmitNeuteredPacket) { |
166 const size_t kNumSentPackets = 2; | 166 const size_t kNumSentPackets = 2; |
167 // Transmit 2 packets. | 167 // Transmit 2 packets. |
168 for (size_t i = 1; i <= kNumSentPackets; ++i) { | 168 for (size_t i = 1; i <= kNumSentPackets; ++i) { |
169 SendDataPacket(i); | 169 SendDataPacket(i); |
170 } | 170 } |
171 // Neuter packet 1. | 171 // Neuter packet 1. |
172 unacked_packets_.RemoveRetransmittability(1); | 172 unacked_packets_.RemoveRetransmittability(1); |
173 | 173 |
174 // Early retransmit when the final packet gets acked and the first is nacked. | 174 // Early retransmit when the final packet gets acked and the first is nacked. |
175 unacked_packets_.IncreaseLargestObserved(2); | 175 unacked_packets_.IncreaseLargestObserved(2); |
176 unacked_packets_.RemoveFromInFlight(2); | 176 unacked_packets_.RemoveFromInFlight(2); |
177 unacked_packets_.NackPacket(1, 1); | 177 unacked_packets_.NackPacket(1, 1); |
178 VerifyLosses(2, nullptr, 0); | 178 VerifyLosses(2, nullptr, 0); |
179 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); | 179 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout()); |
180 } | 180 } |
181 | 181 |
182 } // namespace test | 182 } // namespace test |
183 } // namespace net | 183 } // namespace net |
OLD | NEW |