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