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

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

Issue 1660593004: Landing Recent QUIC changes until 01/28/2016 18:41 UTC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Final_0202
Patch Set: Created 4 years, 10 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "net/quic/congestion_control/time_loss_algorithm.h"
6
7 #include <algorithm>
8
9 #include "base/logging.h"
10 #include "base/stl_util.h"
11 #include "net/quic/congestion_control/rtt_stats.h"
12 #include "net/quic/quic_unacked_packet_map.h"
13 #include "net/quic/test_tools/mock_clock.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 using std::vector;
17
18 namespace net {
19 namespace test {
20 namespace {
21
22 // Default packet length.
23 const uint32_t kDefaultLength = 1000;
24
25 class TimeLossAlgorithmTest : public ::testing::Test {
26 protected:
27 TimeLossAlgorithmTest() {
28 rtt_stats_.UpdateRtt(QuicTime::Delta::FromMilliseconds(100),
29 QuicTime::Delta::Zero(), clock_.Now());
30 }
31
32 ~TimeLossAlgorithmTest() override { STLDeleteElements(&packets_); }
33
34 void SendDataPacket(QuicPacketNumber packet_number) {
35 packets_.push_back(new QuicEncryptedPacket(nullptr, kDefaultLength));
36 SerializedPacket packet(kDefaultPathId, packet_number,
37 PACKET_1BYTE_PACKET_NUMBER, packets_.back(), 0,
38 new QuicFrames(), false, false);
39 unacked_packets_.AddSentPacket(&packet, 0, NOT_RETRANSMISSION, clock_.Now(),
40 1000, true);
41 }
42
43 void VerifyLosses(QuicPacketNumber largest_observed,
44 QuicPacketNumber* losses_expected,
45 size_t num_losses) {
46 PacketNumberSet lost_packets = loss_algorithm_.DetectLostPackets(
47 unacked_packets_, clock_.Now(), largest_observed, rtt_stats_);
48 EXPECT_EQ(num_losses, lost_packets.size());
49 for (size_t i = 0; i < num_losses; ++i) {
50 EXPECT_TRUE(ContainsKey(lost_packets, losses_expected[i]));
51 }
52 }
53
54 vector<QuicEncryptedPacket*> packets_;
55 QuicUnackedPacketMap unacked_packets_;
56 TimeLossAlgorithm loss_algorithm_;
57 RttStats rtt_stats_;
58 MockClock clock_;
59 };
60
61 TEST_F(TimeLossAlgorithmTest, NoLossFor500Nacks) {
62 const size_t kNumSentPackets = 5;
63 // Transmit 5 packets.
64 for (size_t i = 1; i <= kNumSentPackets; ++i) {
65 SendDataPacket(i);
66 }
67 unacked_packets_.RemoveFromInFlight(2);
68 for (uint16_t i = 1; i < 500; ++i) {
69 unacked_packets_.NackPacket(1, i);
70 VerifyLosses(2, nullptr, 0);
71 }
72 EXPECT_EQ(rtt_stats_.smoothed_rtt().Multiply(1.25),
73 loss_algorithm_.GetLossTimeout().Subtract(clock_.Now()));
74 }
75
76 TEST_F(TimeLossAlgorithmTest, NoLossUntilTimeout) {
77 const size_t kNumSentPackets = 10;
78 // Transmit 10 packets at 1/10th an RTT interval.
79 for (size_t i = 1; i <= kNumSentPackets; ++i) {
80 SendDataPacket(i);
81 clock_.AdvanceTime(rtt_stats_.smoothed_rtt().Multiply(0.1));
82 }
83 // Expect the timer to not be set.
84 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout());
85 // The packet should not be lost until 1.25 RTTs pass.
86 unacked_packets_.NackPacket(1, 1);
87 unacked_packets_.RemoveFromInFlight(2);
88 VerifyLosses(2, nullptr, 0);
89 // Expect the timer to be set to 0.25 RTT's in the future.
90 EXPECT_EQ(rtt_stats_.smoothed_rtt().Multiply(0.25),
91 loss_algorithm_.GetLossTimeout().Subtract(clock_.Now()));
92 unacked_packets_.NackPacket(1, 5);
93 VerifyLosses(2, nullptr, 0);
94 clock_.AdvanceTime(rtt_stats_.smoothed_rtt().Multiply(0.25));
95 QuicPacketNumber lost[] = {1};
96 VerifyLosses(2, lost, arraysize(lost));
97 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout());
98 }
99
100 TEST_F(TimeLossAlgorithmTest, NoLossWithoutNack) {
101 const size_t kNumSentPackets = 10;
102 // Transmit 10 packets at 1/10th an RTT interval.
103 for (size_t i = 1; i <= kNumSentPackets; ++i) {
104 SendDataPacket(i);
105 clock_.AdvanceTime(rtt_stats_.smoothed_rtt().Multiply(0.1));
106 }
107 // Expect the timer to not be set.
108 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout());
109 // The packet should not be lost without a nack.
110 unacked_packets_.RemoveFromInFlight(1);
111 VerifyLosses(1, nullptr, 0);
112 // The timer should still not be set.
113 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout());
114 clock_.AdvanceTime(rtt_stats_.smoothed_rtt().Multiply(0.25));
115 VerifyLosses(1, nullptr, 0);
116 clock_.AdvanceTime(rtt_stats_.smoothed_rtt());
117 VerifyLosses(1, nullptr, 0);
118
119 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout());
120 }
121
122 TEST_F(TimeLossAlgorithmTest, MultipleLossesAtOnce) {
123 const size_t kNumSentPackets = 10;
124 // Transmit 10 packets at once and then go forward an RTT.
125 for (size_t i = 1; i <= kNumSentPackets; ++i) {
126 SendDataPacket(i);
127 }
128 clock_.AdvanceTime(rtt_stats_.smoothed_rtt());
129 // Expect the timer to not be set.
130 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout());
131 // The packet should not be lost until 1.25 RTTs pass.
132 for (size_t i = 1; i < kNumSentPackets; ++i) {
133 unacked_packets_.NackPacket(i, 1);
134 }
135 unacked_packets_.RemoveFromInFlight(10);
136 VerifyLosses(10, nullptr, 0);
137 // Expect the timer to be set to 0.25 RTT's in the future.
138 EXPECT_EQ(rtt_stats_.smoothed_rtt().Multiply(0.25),
139 loss_algorithm_.GetLossTimeout().Subtract(clock_.Now()));
140 clock_.AdvanceTime(rtt_stats_.smoothed_rtt().Multiply(0.25));
141 QuicPacketNumber lost[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
142 VerifyLosses(10, lost, arraysize(lost));
143 EXPECT_EQ(QuicTime::Zero(), loss_algorithm_.GetLossTimeout());
144 }
145
146 } // namespace
147 } // namespace test
148 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/congestion_control/time_loss_algorithm.cc ('k') | net/quic/crypto/aead_base_decrypter_nss.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698