Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Side by Side Diff: net/quic/congestion_control/time_loss_algorithm_test.cc

Issue 182523002: Land Recent QUIC Changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed rch's comments in Patch set 1 of CL 181463007 Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/quic/congestion_control/time_loss_algorithm.cc ('k') | net/quic/crypto/crypto_handshake.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/tcp_loss_algorithm.h"
6
7 #include <algorithm> 5 #include <algorithm>
8 6
9 #include "base/logging.h" 7 #include "base/logging.h"
10 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "net/quic/congestion_control/time_loss_algorithm.h"
11 #include "net/quic/quic_unacked_packet_map.h" 10 #include "net/quic/quic_unacked_packet_map.h"
11 #include "net/quic/test_tools/mock_clock.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace net { 14 namespace net {
15 namespace test { 15 namespace test {
16 namespace { 16 namespace {
17 17
18 class TcpLossAlgorithmTest : public ::testing::Test { 18 class TimeLossAlgorithmTest : public ::testing::Test {
19 protected: 19 protected:
20 TcpLossAlgorithmTest() 20 TimeLossAlgorithmTest()
21 : unacked_packets_(true), 21 : unacked_packets_(true),
22 srtt_(QuicTime::Delta::FromMilliseconds(10)) { } 22 srtt_(QuicTime::Delta::FromMilliseconds(100)) { }
23 23
24 void SendDataPacket(QuicPacketSequenceNumber sequence_number) { 24 void SendDataPacket(QuicPacketSequenceNumber sequence_number) {
25 SerializedPacket packet(sequence_number, PACKET_1BYTE_SEQUENCE_NUMBER, 25 SerializedPacket packet(sequence_number, PACKET_1BYTE_SEQUENCE_NUMBER,
26 NULL, 0, new RetransmittableFrames()); 26 NULL, 0, new RetransmittableFrames());
27 unacked_packets_.AddPacket(packet); 27 unacked_packets_.AddPacket(packet);
28 unacked_packets_.SetPending(sequence_number, QuicTime::Zero(), 1000); 28 unacked_packets_.SetPending(sequence_number, clock_.Now(), 1000);
29 } 29 }
30 30
31 void VerifyLosses(QuicPacketSequenceNumber largest_observed, 31 void VerifyLosses(QuicPacketSequenceNumber largest_observed,
32 QuicPacketSequenceNumber* losses_expected, 32 QuicPacketSequenceNumber* losses_expected,
33 size_t num_losses) { 33 size_t num_losses) {
34 SequenceNumberSet lost_packets = 34 SequenceNumberSet lost_packets =
35 loss_algorithm_.DetectLostPackets( 35 loss_algorithm_.DetectLostPackets(
36 unacked_packets_, QuicTime::Zero(), largest_observed, srtt_); 36 unacked_packets_, clock_.Now(), largest_observed, srtt_, srtt_);
37 EXPECT_EQ(num_losses, lost_packets.size()); 37 EXPECT_EQ(num_losses, lost_packets.size());
38 for (size_t i = 0; i < num_losses; ++i) { 38 for (size_t i = 0; i < num_losses; ++i) {
39 EXPECT_TRUE(ContainsKey(lost_packets, losses_expected[i])); 39 EXPECT_TRUE(ContainsKey(lost_packets, losses_expected[i]));
40 } 40 }
41 } 41 }
42 42
43 QuicUnackedPacketMap unacked_packets_; 43 QuicUnackedPacketMap unacked_packets_;
44 TCPLossAlgorithm loss_algorithm_; 44 TimeLossAlgorithm loss_algorithm_;
45 QuicTime::Delta srtt_; 45 QuicTime::Delta srtt_;
46 MockClock clock_;
46 }; 47 };
47 48
48 TEST_F(TcpLossAlgorithmTest, NackRetransmit1Packet) { 49 TEST_F(TimeLossAlgorithmTest, NoLossFor500Nacks) {
49 const size_t kNumSentPackets = 5; 50 const size_t kNumSentPackets = 5;
50 // Transmit 5 packets. 51 // Transmit 5 packets.
51 for (size_t i = 1; i <= kNumSentPackets; ++i) { 52 for (size_t i = 1; i <= kNumSentPackets; ++i) {
52 SendDataPacket(i); 53 SendDataPacket(i);
53 } 54 }
54 // No loss on one ack.
55 unacked_packets_.SetNotPending(2); 55 unacked_packets_.SetNotPending(2);
56 unacked_packets_.NackPacket(1, 1); 56 for (size_t i = 0; i < 500; ++i) {
57 VerifyLosses(2, NULL, 0); 57 unacked_packets_.NackPacket(1, i);
58 // No loss on two acks. 58 VerifyLosses(2, NULL, 0);
59 unacked_packets_.SetNotPending(3); 59 }
60 unacked_packets_.NackPacket(1, 2); 60 EXPECT_EQ(srtt_.Multiply(1.25),
61 VerifyLosses(3, NULL, 0); 61 loss_algorithm_.GetLossTimeout().Subtract(clock_.Now()));
62 // Loss on three acks.
63 unacked_packets_.SetNotPending(4);
64 unacked_packets_.NackPacket(1, 3);
65 QuicPacketSequenceNumber lost[] = { 1 };
66 VerifyLosses(4, lost, arraysize(lost));
67 } 62 }
68 63
69 // A stretch ack is an ack that covers more than 1 packet of previously 64 TEST_F(TimeLossAlgorithmTest, NoLossUntilTimeout) {
70 // unacknowledged data.
71 TEST_F(TcpLossAlgorithmTest, NackRetransmit1PacketWith1StretchAck) {
72 const size_t kNumSentPackets = 10; 65 const size_t kNumSentPackets = 10;
73 // Transmit 10 packets. 66 // Transmit 10 packets at 1/10th an RTT interval.
67 for (size_t i = 1; i <= kNumSentPackets; ++i) {
68 SendDataPacket(i);
69 clock_.AdvanceTime(srtt_.Multiply(0.1));
70 }
71 // Expect the timer to not be set.
72 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout());
73 // The packet should not be lost until 1.25 RTTs pass.
74 unacked_packets_.NackPacket(1, 1);
75 unacked_packets_.SetNotPending(2);
76 VerifyLosses(2, NULL, 0);
77 // Expect the timer to be set to 0.25 RTT's in the future.
78 EXPECT_EQ(srtt_.Multiply(0.25),
79 loss_algorithm_.GetLossTimeout().Subtract(clock_.Now()));
80 unacked_packets_.NackPacket(1, 5);
81 VerifyLosses(2, NULL, 0);
82 clock_.AdvanceTime(srtt_.Multiply(0.25));
83 QuicPacketSequenceNumber lost[] = { 1 };
84 VerifyLosses(2, lost, arraysize(lost));
85 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout());
86 }
87
88 TEST_F(TimeLossAlgorithmTest, NoLossWithoutNack) {
89 const size_t kNumSentPackets = 10;
90 // Transmit 10 packets at 1/10th an RTT interval.
91 for (size_t i = 1; i <= kNumSentPackets; ++i) {
92 SendDataPacket(i);
93 clock_.AdvanceTime(srtt_.Multiply(0.1));
94 }
95 // Expect the timer to not be set.
96 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout());
97 // The packet should not be lost without a nack.
98 unacked_packets_.SetNotPending(1);
99 VerifyLosses(1, NULL, 0);
100 // The timer should still not be set.
101 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout());
102 clock_.AdvanceTime(srtt_.Multiply(0.25));
103 VerifyLosses(1, NULL, 0);
104 clock_.AdvanceTime(srtt_);
105 VerifyLosses(1, NULL, 0);
106
107 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout());
108 }
109
110 TEST_F(TimeLossAlgorithmTest, MultipleLossesAtOnce) {
111 const size_t kNumSentPackets = 10;
112 // Transmit 10 packets at once and then go forward an RTT.
74 for (size_t i = 1; i <= kNumSentPackets; ++i) { 113 for (size_t i = 1; i <= kNumSentPackets; ++i) {
75 SendDataPacket(i); 114 SendDataPacket(i);
76 } 115 }
77 116 clock_.AdvanceTime(srtt_);
78 // Nack the first packet 3 times in a single StretchAck. 117 // Expect the timer to not be set.
79 unacked_packets_.NackPacket(1, 3); 118 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout());
80 unacked_packets_.SetNotPending(2); 119 // The packet should not be lost until 1.25 RTTs pass.
81 unacked_packets_.SetNotPending(3); 120 for (size_t i = 1; i < kNumSentPackets; ++i) {
82 unacked_packets_.SetNotPending(4); 121 unacked_packets_.NackPacket(i, 1);
83 QuicPacketSequenceNumber lost[] = { 1 };
84 VerifyLosses(4, lost, arraysize(lost));
85 }
86
87 // Ack a packet 3 packets ahead, causing a retransmit.
88 TEST_F(TcpLossAlgorithmTest, NackRetransmit1PacketSingleAck) {
89 const size_t kNumSentPackets = 10;
90 // Transmit 10 packets.
91 for (size_t i = 1; i <= kNumSentPackets; ++i) {
92 SendDataPacket(i);
93 } 122 }
94 123 unacked_packets_.SetNotPending(10);
95 // Nack the first packet 3 times in an AckFrame with three missing packets. 124 VerifyLosses(10, NULL, 0);
96 unacked_packets_.NackPacket(1, 3); 125 // Expect the timer to be set to 0.25 RTT's in the future.
97 unacked_packets_.NackPacket(2, 2); 126 EXPECT_EQ(srtt_.Multiply(0.25),
98 unacked_packets_.NackPacket(3, 1); 127 loss_algorithm_.GetLossTimeout().Subtract(clock_.Now()));
99 unacked_packets_.SetNotPending(4); 128 clock_.AdvanceTime(srtt_.Multiply(0.25));
100 QuicPacketSequenceNumber lost[] = { 1 }; 129 QuicPacketSequenceNumber lost[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
101 VerifyLosses(4, lost, arraysize(lost)); 130 VerifyLosses(10, lost, arraysize(lost));
102 } 131 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout());
103
104 TEST_F(TcpLossAlgorithmTest, EarlyRetransmit1Packet) {
105 const size_t kNumSentPackets = 2;
106 // Transmit 2 packets.
107 for (size_t i = 1; i <= kNumSentPackets; ++i) {
108 SendDataPacket(i);
109 }
110 // Early retransmit when the final packet gets acked and the first is nacked.
111 unacked_packets_.SetNotPending(2);
112 unacked_packets_.NackPacket(1, 1);
113 QuicPacketSequenceNumber lost[] = { 1 };
114 VerifyLosses(2, lost, arraysize(lost));
115 }
116
117 TEST_F(TcpLossAlgorithmTest, EarlyRetransmitAllPackets) {
118 const size_t kNumSentPackets = 5;
119 for (size_t i = 1; i <= kNumSentPackets; ++i) {
120 SendDataPacket(i);
121 }
122 // Early retransmit when the final packet gets acked and the first 4 are
123 // nacked multiple times via FACK.
124 unacked_packets_.SetNotPending(kNumSentPackets);
125 for (size_t i = 1; i < kNumSentPackets; ++i) {
126 unacked_packets_.NackPacket(i, kNumSentPackets - i);
127 }
128 QuicPacketSequenceNumber lost[] = { 1, 2, 3, 4 };
129 VerifyLosses(kNumSentPackets, lost, arraysize(lost));
130 }
131
132 TEST_F(TcpLossAlgorithmTest, DontEarlyRetransmitNeuteredPacket) {
133 const size_t kNumSentPackets = 2;
134 // Transmit 2 packets.
135 for (size_t i = 1; i <= kNumSentPackets; ++i) {
136 SendDataPacket(i);
137 }
138 // Early retransmit when the final packet gets acked and the first is nacked.
139 unacked_packets_.SetNotPending(2);
140 unacked_packets_.NackPacket(1, 1);
141 unacked_packets_.NeuterPacket(1);
142 VerifyLosses(2, NULL, 0);
143 } 132 }
144 133
145 } // namespace 134 } // namespace
146 } // namespace test 135 } // namespace test
147 } // namespace net 136 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/congestion_control/time_loss_algorithm.cc ('k') | net/quic/crypto/crypto_handshake.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698