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 // A test only class to enable simulations of send algorithms. | 5 // A test only class to enable simulations of send algorithms. |
6 | 6 |
7 #ifndef NET_QUIC_CONGESTION_CONTROL_SEND_ALGORITHM_SIMULATOR_H_ | 7 #ifndef NET_QUIC_CONGESTION_CONTROL_SEND_ALGORITHM_SIMULATOR_H_ |
8 #define NET_QUIC_CONGESTION_CONTROL_SEND_ALGORITHM_SIMULATOR_H_ | 8 #define NET_QUIC_CONGESTION_CONTROL_SEND_ALGORITHM_SIMULATOR_H_ |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
15 #include "base/format_macros.h" | 15 #include "base/format_macros.h" |
16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
17 #include "net/quic/congestion_control/send_algorithm_interface.h" | 17 #include "net/quic/congestion_control/send_algorithm_interface.h" |
18 #include "net/quic/quic_protocol.h" | 18 #include "net/quic/quic_protocol.h" |
19 #include "net/quic/quic_time.h" | 19 #include "net/quic/quic_time.h" |
20 #include "net/quic/test_tools/mock_clock.h" | 20 #include "net/quic/test_tools/mock_clock.h" |
21 #include "net/quic/test_tools/quic_test_utils.h" | 21 #include "net/quic/test_tools/quic_test_utils.h" |
22 | 22 |
23 using base::StringPrintf; | 23 using base::StringPrintf; |
24 | 24 |
25 namespace net { | 25 namespace net { |
26 | 26 |
27 class SendAlgorithmSimulator { | 27 class SendAlgorithmSimulator { |
28 public: | 28 public: |
29 struct Sender { | 29 struct Sender { |
30 Sender(SendAlgorithmInterface* send_algorithm, RttStats* rtt_stats); | 30 Sender(SendAlgorithmInterface* send_algorithm, |
| 31 RttStats* rtt_stats); |
| 32 Sender(SendAlgorithmInterface* send_algorithm, |
| 33 RttStats* rtt_stats, |
| 34 QuicTime::Delta additional_rtt); |
31 | 35 |
32 void RecordStats() { | 36 void RecordStats() { |
33 QuicByteCount cwnd = send_algorithm->GetCongestionWindow(); | 37 QuicByteCount cwnd = send_algorithm->GetCongestionWindow(); |
34 max_cwnd = std::max(max_cwnd, cwnd); | 38 max_cwnd = std::max(max_cwnd, cwnd); |
35 min_cwnd = std::min(min_cwnd, cwnd); | 39 min_cwnd = std::min(min_cwnd, cwnd); |
36 if (last_cwnd > cwnd) { | 40 if (last_cwnd > cwnd) { |
37 max_cwnd_drop = std::max(max_cwnd_drop, last_cwnd - cwnd); | 41 max_cwnd_drop = std::max(max_cwnd_drop, last_cwnd - cwnd); |
38 } | 42 } |
39 last_cwnd = cwnd; | 43 last_cwnd = cwnd; |
40 } | 44 } |
41 | 45 |
42 std::string DebugString() { | 46 std::string DebugString() { |
43 return StringPrintf("observed goodput(bytes/s):%" PRId64 | 47 return StringPrintf("observed goodput(bytes/s):%" PRId64 |
44 " loss rate:%f" | 48 " loss rate:%f" |
45 " cwnd:%" PRIu64 | 49 " cwnd:%" PRIu64 |
46 " max_cwnd:%" PRIu64 " min_cwnd:%" PRIu64 | 50 " max_cwnd:%" PRIu64 " min_cwnd:%" PRIu64 |
47 " max_cwnd_drop:%" PRIu64, | 51 " max_cwnd_drop:%" PRIu64, |
48 last_transfer_bandwidth.ToBytesPerSecond(), | 52 last_transfer_bandwidth.ToBytesPerSecond(), |
49 last_transfer_loss_rate, | 53 last_transfer_loss_rate, |
50 send_algorithm->GetCongestionWindow(), | 54 send_algorithm->GetCongestionWindow(), |
51 max_cwnd, min_cwnd, max_cwnd_drop); | 55 max_cwnd, min_cwnd, max_cwnd_drop); |
52 } | 56 } |
53 | 57 |
54 SendAlgorithmInterface* send_algorithm; | 58 SendAlgorithmInterface* send_algorithm; |
55 RttStats* rtt_stats; | 59 RttStats* rtt_stats; |
| 60 QuicTime::Delta additional_rtt; |
56 | 61 |
57 // Last sequence number the sender sent. | 62 // Last sequence number the sender sent. |
58 QuicPacketSequenceNumber last_sent; | 63 QuicPacketSequenceNumber last_sent; |
59 // Last packet sequence number acked. | 64 // Last packet sequence number acked. |
60 QuicPacketSequenceNumber last_acked; | 65 QuicPacketSequenceNumber last_acked; |
61 // Packet sequence number to ack up to. | 66 // Packet sequence number to ack up to. |
62 QuicPacketSequenceNumber next_acked; | 67 QuicPacketSequenceNumber next_acked; |
63 | 68 |
64 // Stats collected for understanding the congestion control. | 69 // Stats collected for understanding the congestion control. |
65 QuicByteCount max_cwnd; | 70 QuicByteCount max_cwnd; |
66 QuicByteCount min_cwnd; | 71 QuicByteCount min_cwnd; |
67 QuicByteCount max_cwnd_drop; | 72 QuicByteCount max_cwnd_drop; |
68 QuicByteCount last_cwnd; | 73 QuicByteCount last_cwnd; |
69 | 74 |
70 QuicBandwidth last_transfer_bandwidth; | 75 QuicBandwidth last_transfer_bandwidth; |
71 float last_transfer_loss_rate; | 76 float last_transfer_loss_rate; |
72 }; | 77 }; |
73 | 78 |
74 struct Transfer { | 79 struct Transfer { |
75 Transfer(Sender* sender, QuicByteCount num_bytes, QuicTime start_time) | 80 Transfer(Sender* sender, |
76 : sender(sender), | 81 QuicByteCount num_bytes, |
77 num_bytes(num_bytes), | 82 QuicTime start_time, |
78 bytes_acked(0), | 83 string name); |
79 bytes_lost(0), | |
80 bytes_in_flight(0), | |
81 start_time(start_time) {} | |
82 | 84 |
83 Sender* sender; | 85 Sender* sender; |
84 QuicByteCount num_bytes; | 86 QuicByteCount num_bytes; |
85 QuicByteCount bytes_acked; | 87 QuicByteCount bytes_acked; |
86 QuicByteCount bytes_lost; | 88 QuicByteCount bytes_lost; |
87 QuicByteCount bytes_in_flight; | 89 QuicByteCount bytes_in_flight; |
88 QuicTime start_time; | 90 QuicTime start_time; |
| 91 string name; |
89 }; | 92 }; |
90 | 93 |
91 struct SentPacket { | 94 struct SentPacket { |
92 SentPacket() | 95 SentPacket() |
93 : sequence_number(0), | 96 : sequence_number(0), |
94 send_time(QuicTime::Zero()), | 97 send_time(QuicTime::Zero()), |
95 ack_time(QuicTime::Zero()), | 98 ack_time(QuicTime::Zero()), |
96 lost(false), | 99 lost(false), |
97 transfer(nullptr) {} | 100 transfer(nullptr) {} |
98 SentPacket(QuicPacketSequenceNumber sequence_number, | 101 SentPacket(QuicPacketSequenceNumber sequence_number, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 } | 150 } |
148 | 151 |
149 // Advance the time by |delta| without sending anything. | 152 // Advance the time by |delta| without sending anything. |
150 void AdvanceTime(QuicTime::Delta delta); | 153 void AdvanceTime(QuicTime::Delta delta); |
151 | 154 |
152 // Adds a pending sender. The send will run when TransferBytes is called. | 155 // Adds a pending sender. The send will run when TransferBytes is called. |
153 // Adding two transfers with the same sender is unsupported. | 156 // Adding two transfers with the same sender is unsupported. |
154 void AddTransfer(Sender* sender, size_t num_bytes); | 157 void AddTransfer(Sender* sender, size_t num_bytes); |
155 | 158 |
156 // Adds a pending sending to start at the specified time. | 159 // Adds a pending sending to start at the specified time. |
157 void AddTransfer(Sender* sender, size_t num_bytes, QuicTime start_time); | 160 void AddTransfer( |
| 161 Sender* sender, size_t num_bytes, QuicTime start_time, string name); |
158 | 162 |
159 // Convenience method to transfer all bytes. | 163 // Convenience method to transfer all bytes. |
160 void TransferBytes(); | 164 void TransferBytes(); |
161 | 165 |
162 // Transfers bytes through the connection until |max_bytes| are reached, | 166 // Transfers bytes through the connection until |max_bytes| are reached, |
163 // |max_time| is reached, or all senders have finished sending. If max_bytes | 167 // |max_time| is reached, or all senders have finished sending. If max_bytes |
164 // is 0, it does not apply, and if |max_time| is Zero, no time limit applies. | 168 // is 0, it does not apply, and if |max_time| is Zero, no time limit applies. |
165 void TransferBytes(QuicByteCount max_bytes, QuicTime::Delta max_time); | 169 void TransferBytes(QuicByteCount max_bytes, QuicTime::Delta max_time); |
166 | 170 |
167 private: | 171 private: |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 QuicTime::Delta rtt_; | 226 QuicTime::Delta rtt_; |
223 size_t buffer_size_; // In bytes. | 227 size_t buffer_size_; // In bytes. |
224 QuicTime::Delta delayed_ack_timer_; | 228 QuicTime::Delta delayed_ack_timer_; |
225 | 229 |
226 DISALLOW_COPY_AND_ASSIGN(SendAlgorithmSimulator); | 230 DISALLOW_COPY_AND_ASSIGN(SendAlgorithmSimulator); |
227 }; | 231 }; |
228 | 232 |
229 } // namespace net | 233 } // namespace net |
230 | 234 |
231 #endif // NET_QUIC_CONGESTION_CONTROL_SEND_ALGORITHM_SIMULATOR_H_ | 235 #endif // NET_QUIC_CONGESTION_CONTROL_SEND_ALGORITHM_SIMULATOR_H_ |
OLD | NEW |