OLD | NEW |
---|---|
(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 // A test only class to enable simulations of send algorithms. | |
6 | |
7 #ifndef NET_QUIC_CONGESTION_CONTROL_SEND_ALGORITHM_SIMULATOR_H_ | |
8 #define NET_QUIC_CONGESTION_CONTROL_SEND_ALGORITHM_SIMULATOR_H_ | |
9 | |
10 #include <algorithm> | |
11 | |
12 #include "base/basictypes.h" | |
13 #include "net/quic/congestion_control/send_algorithm_interface.h" | |
14 #include "net/quic/quic_protocol.h" | |
15 #include "net/quic/quic_time.h" | |
16 #include "net/quic/test_tools/mock_clock.h" | |
17 #include "net/quic/test_tools/quic_test_utils.h" | |
18 | |
19 namespace net { | |
20 | |
21 class NET_EXPORT_PRIVATE SendAlgorithmSimulator { | |
22 public: | |
23 struct SentPacket { | |
24 SentPacket(QuicPacketSequenceNumber sequence_number, | |
25 QuicTime send_time, | |
26 QuicTime ack_time) : | |
27 sequence_number(sequence_number), | |
28 send_time(send_time), | |
29 ack_time(ack_time) {} | |
30 QuicPacketSequenceNumber sequence_number; | |
31 QuicTime send_time; | |
32 QuicTime ack_time; | |
33 }; | |
34 | |
35 // |rtt_stats| should be the same RttStats used by the |send_algorithm|. | |
36 SendAlgorithmSimulator(SendAlgorithmInterface* send_algorithm, | |
37 MockClock* clock_, | |
38 RttStats* rtt_stats, | |
39 QuicBandwidth bandwidth, | |
40 QuicTime::Delta rtt); | |
41 ~SendAlgorithmSimulator(); | |
42 | |
43 void set_forward_loss_rate(float loss_rate) { | |
44 DCHECK_LT(loss_rate, 1.0f); | |
45 forward_loss_rate_ = loss_rate; | |
46 } | |
47 | |
48 void set_reverse_loss_rate(float loss_rate) { | |
49 DCHECK_LT(loss_rate, 1.0f); | |
50 reverse_loss_rate_ = loss_rate; | |
51 } | |
52 | |
53 void set_loss_correlation(float loss_correlation) { | |
54 DCHECK_LT(loss_correlation, 1.0f); | |
55 loss_correlation_ = loss_correlation; | |
56 } | |
57 | |
58 void set_buffer_size(size_t buffer_size_bytes) { | |
59 buffer_size_ = buffer_size_bytes; | |
60 } | |
61 | |
62 // Sends the specified number of bytes as quickly as possible and returns the | |
63 // average bandwidth in bytes per second. The time elapsed is based on | |
64 // waiting for all acks to arrive. | |
65 QuicBandwidth SendBytes(size_t num_bytes); | |
66 | |
67 const RttStats* rtt_stats() { return rtt_stats_; } | |
wtc
2014/06/16 22:05:53
Nit: this getter method should also be const.
ramant (doing other things)
2014/06/16 23:46:52
Done.
| |
68 | |
69 QuicByteCount max_cwnd() const { return max_cwnd_; } | |
70 QuicByteCount min_cwnd() const { return min_cwnd_; } | |
71 QuicByteCount max_cwnd_drop() const { return max_cwnd_drop_; } | |
72 QuicByteCount last_cwnd() const { return last_cwnd_; } | |
73 | |
74 private: | |
75 // NextAckTime takes into account packet loss in both forward and reverse | |
76 // direction, as well as delayed ack behavior. | |
77 QuicTime::Delta NextAckDelta(); | |
78 | |
79 // Whether all packets in sent_packets_ are lost. | |
80 bool AllPacketsLost(); | |
81 | |
82 // Sets the next acked. | |
83 void FindNextAcked(); | |
84 | |
85 // Process all the acks that should have arrived by the current time, and | |
86 // lose any packets that are missing. Returns the number of bytes acked. | |
87 int HandlePendingAck(); | |
88 | |
89 void SendDataNow(); | |
90 void RecordStats(); | |
91 | |
92 // Advance the time by |delta| without sending anything. | |
93 void AdvanceTime(QuicTime::Delta delta); | |
94 | |
95 // Elapsed time from the start of the connection. | |
96 QuicTime ElapsedTime(); | |
97 | |
98 SendAlgorithmInterface* send_algorithm_; | |
99 MockClock* clock_; | |
100 RttStats* rtt_stats_; | |
101 // Next packet sequence number to send. | |
102 QuicPacketSequenceNumber next_sent_; | |
103 // Last packet sequence number acked. | |
104 QuicPacketSequenceNumber last_acked_; | |
105 // Packet sequence number to ack up to. | |
106 QuicPacketSequenceNumber next_acked_; | |
107 // Whether the next ack should be lost. | |
108 bool lose_next_ack_; | |
109 QuicByteCount bytes_in_flight_; | |
110 // The times acks are expected, assuming acks are not lost and every packet | |
111 // is acked. | |
112 std::list<SentPacket> sent_packets_; | |
113 | |
114 test::SimpleRandom simple_random_; | |
115 float forward_loss_rate_; // Loss rate on the forward path. | |
116 float reverse_loss_rate_; // Loss rate on the reverse path. | |
117 float loss_correlation_; // Likelihood the subsequent packet is lost. | |
118 QuicBandwidth bandwidth_; | |
119 QuicTime::Delta rtt_; | |
120 size_t buffer_size_; // In bytes. | |
121 | |
122 // Stats collected for understanding the congestion control. | |
123 QuicByteCount max_cwnd_; | |
124 QuicByteCount min_cwnd_; | |
125 QuicByteCount max_cwnd_drop_; | |
126 QuicByteCount last_cwnd_; | |
127 | |
128 DISALLOW_COPY_AND_ASSIGN(SendAlgorithmSimulator); | |
129 }; | |
130 | |
131 } // namespace net | |
132 | |
133 #endif // NET_QUIC_CONGESTION_CONTROL_SEND_ALGORITHM_SIMULATOR_H_ | |
OLD | NEW |