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/quic_unacked_packet_map.h" | 5 #include "net/quic/quic_unacked_packet_map.h" |
6 | 6 |
7 #include "net/quic/test_tools/quic_test_utils.h" | 7 #include "net/quic/test_tools/quic_test_utils.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
| 10 using std::min; |
| 11 |
10 namespace net { | 12 namespace net { |
11 namespace test { | 13 namespace test { |
12 namespace { | 14 namespace { |
13 | 15 |
14 // Default packet length. | 16 // Default packet length. |
15 const uint32 kDefaultAckLength = 50; | 17 const uint32 kDefaultAckLength = 50; |
16 const uint32 kDefaultLength = 1000; | 18 const uint32 kDefaultLength = 1000; |
17 | 19 |
18 class QuicUnackedPacketMapTest : public ::testing::Test { | 20 class QuicUnackedPacketMapTest : public ::testing::Test { |
19 protected: | 21 protected: |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 VerifyUnackedPackets(unacked, arraysize(unacked)); | 108 VerifyUnackedPackets(unacked, arraysize(unacked)); |
107 VerifyInFlightPackets(NULL, 0); | 109 VerifyInFlightPackets(NULL, 0); |
108 VerifyRetransmittablePackets(NULL, 0); | 110 VerifyRetransmittablePackets(NULL, 0); |
109 | 111 |
110 unacked_packets_.IncreaseLargestObserved(1); | 112 unacked_packets_.IncreaseLargestObserved(1); |
111 VerifyUnackedPackets(NULL, 0); | 113 VerifyUnackedPackets(NULL, 0); |
112 VerifyInFlightPackets(NULL, 0); | 114 VerifyInFlightPackets(NULL, 0); |
113 VerifyRetransmittablePackets(NULL, 0); | 115 VerifyRetransmittablePackets(NULL, 0); |
114 } | 116 } |
115 | 117 |
| 118 TEST_F(QuicUnackedPacketMapTest, DiscardOldRttOnly) { |
| 119 // Acks are only tracked for RTT measurement purposes, and are discarded |
| 120 // when more than 200 accumulate. |
| 121 for (int i = 1; i < 400; ++i) { |
| 122 unacked_packets_.AddPacket(CreateNonRetransmittablePacket(i)); |
| 123 unacked_packets_.SetSent(i, now_, kDefaultAckLength, false); |
| 124 unacked_packets_.RemoveObsoletePackets(); |
| 125 EXPECT_EQ(static_cast<size_t>(min(i, 200)), |
| 126 unacked_packets_.GetNumUnackedPacketsDebugOnly()); |
| 127 } |
| 128 } |
| 129 |
116 TEST_F(QuicUnackedPacketMapTest, RetransmittableInflightAndRtt) { | 130 TEST_F(QuicUnackedPacketMapTest, RetransmittableInflightAndRtt) { |
117 // Simulate a retransmittable packet being sent and acked. | 131 // Simulate a retransmittable packet being sent and acked. |
118 unacked_packets_.AddPacket(CreateRetransmittablePacket(1)); | 132 unacked_packets_.AddPacket(CreateRetransmittablePacket(1)); |
119 unacked_packets_.SetSent(1, now_, kDefaultLength, true); | 133 unacked_packets_.SetSent(1, now_, kDefaultLength, true); |
120 | 134 |
121 QuicPacketSequenceNumber unacked[] = { 1 }; | 135 QuicPacketSequenceNumber unacked[] = { 1 }; |
122 VerifyUnackedPackets(unacked, arraysize(unacked)); | 136 VerifyUnackedPackets(unacked, arraysize(unacked)); |
123 VerifyInFlightPackets(unacked, arraysize(unacked)); | 137 VerifyInFlightPackets(unacked, arraysize(unacked)); |
124 VerifyRetransmittablePackets(unacked, arraysize(unacked)); | 138 VerifyRetransmittablePackets(unacked, arraysize(unacked)); |
125 | 139 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 unacked_packets_.RemoveRetransmittability(6); | 241 unacked_packets_.RemoveRetransmittability(6); |
228 unacked_packets_.OnRetransmittedPacket(5, 7, LOSS_RETRANSMISSION); | 242 unacked_packets_.OnRetransmittedPacket(5, 7, LOSS_RETRANSMISSION); |
229 unacked_packets_.SetSent(7, now_, kDefaultLength, true); | 243 unacked_packets_.SetSent(7, now_, kDefaultLength, true); |
230 | 244 |
231 QuicPacketSequenceNumber unacked4[] = { 3, 5, 7 }; | 245 QuicPacketSequenceNumber unacked4[] = { 3, 5, 7 }; |
232 VerifyUnackedPackets(unacked4, arraysize(unacked4)); | 246 VerifyUnackedPackets(unacked4, arraysize(unacked4)); |
233 QuicPacketSequenceNumber pending4[] = { 3, 5, 7 }; | 247 QuicPacketSequenceNumber pending4[] = { 3, 5, 7 }; |
234 VerifyInFlightPackets(pending4, arraysize(pending4)); | 248 VerifyInFlightPackets(pending4, arraysize(pending4)); |
235 QuicPacketSequenceNumber retransmittable4[] = { 7 }; | 249 QuicPacketSequenceNumber retransmittable4[] = { 7 }; |
236 VerifyRetransmittablePackets(retransmittable4, arraysize(retransmittable4)); | 250 VerifyRetransmittablePackets(retransmittable4, arraysize(retransmittable4)); |
| 251 |
| 252 // Remove the older two transmissions from in flight. |
| 253 unacked_packets_.RemoveFromInFlight(3); |
| 254 unacked_packets_.RemoveFromInFlight(5); |
| 255 QuicPacketSequenceNumber pending5[] = { 7 }; |
| 256 VerifyInFlightPackets(pending5, arraysize(pending5)); |
| 257 |
| 258 // Now test ClearAllPreviousTransmissions, leaving one packet. |
| 259 unacked_packets_.ClearAllPreviousRetransmissions(); |
| 260 QuicPacketSequenceNumber unacked5[] = { 7 }; |
| 261 VerifyUnackedPackets(unacked5, arraysize(unacked5)); |
| 262 QuicPacketSequenceNumber retransmittable5[] = { 7 }; |
| 263 VerifyRetransmittablePackets(retransmittable5, arraysize(retransmittable5)); |
| 264 } |
| 265 |
| 266 TEST_F(QuicUnackedPacketMapTest, RestoreInflight) { |
| 267 // Simulate a retransmittable packet being sent, retransmitted, and the first |
| 268 // transmission being acked. |
| 269 unacked_packets_.AddPacket(CreateRetransmittablePacket(1)); |
| 270 unacked_packets_.SetSent(1, now_, kDefaultLength, true); |
| 271 unacked_packets_.OnRetransmittedPacket(1, 2, RTO_RETRANSMISSION); |
| 272 unacked_packets_.RemoveFromInFlight(1); |
| 273 unacked_packets_.SetSent(2, now_, kDefaultLength, true); |
| 274 |
| 275 QuicPacketSequenceNumber unacked[] = { 1, 2 }; |
| 276 VerifyUnackedPackets(unacked, arraysize(unacked)); |
| 277 QuicPacketSequenceNumber retransmittable[] = { 2 }; |
| 278 VerifyInFlightPackets(retransmittable, arraysize(retransmittable)); |
| 279 VerifyRetransmittablePackets(retransmittable, arraysize(retransmittable)); |
| 280 EXPECT_EQ(kDefaultLength, unacked_packets_.bytes_in_flight()); |
| 281 |
| 282 // Simulate an F-RTO, and restore 1 to flight. |
| 283 unacked_packets_.RestoreInFlight(1); |
| 284 VerifyUnackedPackets(unacked, arraysize(unacked)); |
| 285 VerifyInFlightPackets(unacked, arraysize(unacked)); |
| 286 VerifyRetransmittablePackets(retransmittable, arraysize(retransmittable)); |
| 287 EXPECT_EQ(2 * kDefaultLength, unacked_packets_.bytes_in_flight()); |
237 } | 288 } |
238 | 289 |
239 } // namespace | 290 } // namespace |
240 } // namespace test | 291 } // namespace test |
241 } // namespace net | 292 } // namespace net |
OLD | NEW |