| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef NET_TOOLS_QUIC_TEST_TOOLS_PACKET_DROPPING_TEST_WRITER_H_ | 5 #ifndef NET_TOOLS_QUIC_TEST_TOOLS_PACKET_DROPPING_TEST_WRITER_H_ |
| 6 #define NET_TOOLS_QUIC_TEST_TOOLS_PACKET_DROPPING_TEST_WRITER_H_ | 6 #define NET_TOOLS_QUIC_TEST_TOOLS_PACKET_DROPPING_TEST_WRITER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 // for the next delayed packet to be written. | 64 // for the next delayed packet to be written. |
| 65 QuicTime ReleaseOldPackets(); | 65 QuicTime ReleaseOldPackets(); |
| 66 | 66 |
| 67 // Sets |delay_alarm_| to fire at |new_deadline|. | 67 // Sets |delay_alarm_| to fire at |new_deadline|. |
| 68 void SetDelayAlarm(QuicTime new_deadline); | 68 void SetDelayAlarm(QuicTime new_deadline); |
| 69 | 69 |
| 70 void OnCanWrite(); | 70 void OnCanWrite(); |
| 71 | 71 |
| 72 // The percent of time a packet is simulated as being lost. | 72 // The percent of time a packet is simulated as being lost. |
| 73 void set_fake_packet_loss_percentage(int32_t fake_packet_loss_percentage) { | 73 void set_fake_packet_loss_percentage(int32_t fake_packet_loss_percentage) { |
| 74 base::AutoLock locked(config_mutex_); | 74 QuicWriterMutexLock lock(&config_mutex_); |
| 75 fake_packet_loss_percentage_ = fake_packet_loss_percentage; | 75 fake_packet_loss_percentage_ = fake_packet_loss_percentage; |
| 76 } | 76 } |
| 77 | 77 |
| 78 // Simulate dropping the first n packets unconditionally. | 78 // Simulate dropping the first n packets unconditionally. |
| 79 // Subsequent packets will be lost at fake_packet_loss_percentage_ if set. | 79 // Subsequent packets will be lost at fake_packet_loss_percentage_ if set. |
| 80 void set_fake_drop_first_n_packets(int32_t fake_drop_first_n_packets) { | 80 void set_fake_drop_first_n_packets(int32_t fake_drop_first_n_packets) { |
| 81 base::AutoLock locked(config_mutex_); | 81 QuicWriterMutexLock lock(&config_mutex_); |
| 82 fake_drop_first_n_packets_ = fake_drop_first_n_packets; | 82 fake_drop_first_n_packets_ = fake_drop_first_n_packets; |
| 83 } | 83 } |
| 84 | 84 |
| 85 // The percent of time WritePacket will block and set WriteResult's status | 85 // The percent of time WritePacket will block and set WriteResult's status |
| 86 // to WRITE_STATUS_BLOCKED. | 86 // to WRITE_STATUS_BLOCKED. |
| 87 void set_fake_blocked_socket_percentage( | 87 void set_fake_blocked_socket_percentage( |
| 88 int32_t fake_blocked_socket_percentage) { | 88 int32_t fake_blocked_socket_percentage) { |
| 89 DCHECK(clock_); | 89 DCHECK(clock_); |
| 90 base::AutoLock locked(config_mutex_); | 90 QuicWriterMutexLock lock(&config_mutex_); |
| 91 fake_blocked_socket_percentage_ = fake_blocked_socket_percentage; | 91 fake_blocked_socket_percentage_ = fake_blocked_socket_percentage; |
| 92 } | 92 } |
| 93 | 93 |
| 94 // The percent of time a packet is simulated as being reordered. | 94 // The percent of time a packet is simulated as being reordered. |
| 95 void set_fake_reorder_percentage(int32_t fake_packet_reorder_percentage) { | 95 void set_fake_reorder_percentage(int32_t fake_packet_reorder_percentage) { |
| 96 DCHECK(clock_); | 96 DCHECK(clock_); |
| 97 base::AutoLock locked(config_mutex_); | 97 QuicWriterMutexLock lock(&config_mutex_); |
| 98 DCHECK(!fake_packet_delay_.IsZero()); | 98 DCHECK(!fake_packet_delay_.IsZero()); |
| 99 fake_packet_reorder_percentage_ = fake_packet_reorder_percentage; | 99 fake_packet_reorder_percentage_ = fake_packet_reorder_percentage; |
| 100 } | 100 } |
| 101 | 101 |
| 102 // The delay before writing this packet. | 102 // The delay before writing this packet. |
| 103 void set_fake_packet_delay(QuicTime::Delta fake_packet_delay) { | 103 void set_fake_packet_delay(QuicTime::Delta fake_packet_delay) { |
| 104 DCHECK(clock_); | 104 DCHECK(clock_); |
| 105 base::AutoLock locked(config_mutex_); | 105 QuicWriterMutexLock lock(&config_mutex_); |
| 106 fake_packet_delay_ = fake_packet_delay; | 106 fake_packet_delay_ = fake_packet_delay; |
| 107 } | 107 } |
| 108 | 108 |
| 109 // The maximum bandwidth and buffer size of the connection. When these are | 109 // The maximum bandwidth and buffer size of the connection. When these are |
| 110 // set, packets will be delayed until a connection with that bandwidth would | 110 // set, packets will be delayed until a connection with that bandwidth would |
| 111 // transmit it. Once the |buffer_size| is reached, all new packets are | 111 // transmit it. Once the |buffer_size| is reached, all new packets are |
| 112 // dropped. | 112 // dropped. |
| 113 void set_max_bandwidth_and_buffer_size(QuicBandwidth fake_bandwidth, | 113 void set_max_bandwidth_and_buffer_size(QuicBandwidth fake_bandwidth, |
| 114 QuicByteCount buffer_size) { | 114 QuicByteCount buffer_size) { |
| 115 DCHECK(clock_); | 115 DCHECK(clock_); |
| 116 base::AutoLock locked(config_mutex_); | 116 QuicWriterMutexLock lock(&config_mutex_); |
| 117 fake_bandwidth_ = fake_bandwidth; | 117 fake_bandwidth_ = fake_bandwidth; |
| 118 buffer_size_ = buffer_size; | 118 buffer_size_ = buffer_size; |
| 119 } | 119 } |
| 120 | 120 |
| 121 // Useful for reproducing very flaky issues. | 121 // Useful for reproducing very flaky issues. |
| 122 void set_seed(uint64_t seed) { simple_random_.set_seed(seed); } | 122 void set_seed(uint64_t seed) { simple_random_.set_seed(seed); } |
| 123 | 123 |
| 124 private: | 124 private: |
| 125 // Writes out the next packet to the contained writer and returns the time | 125 // Writes out the next packet to the contained writer and returns the time |
| 126 // for the next delayed packet to be written. | 126 // for the next delayed packet to be written. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 156 const QuicClock* clock_; | 156 const QuicClock* clock_; |
| 157 std::unique_ptr<QuicAlarm> write_unblocked_alarm_; | 157 std::unique_ptr<QuicAlarm> write_unblocked_alarm_; |
| 158 std::unique_ptr<QuicAlarm> delay_alarm_; | 158 std::unique_ptr<QuicAlarm> delay_alarm_; |
| 159 std::unique_ptr<Delegate> on_can_write_; | 159 std::unique_ptr<Delegate> on_can_write_; |
| 160 net::test::SimpleRandom simple_random_; | 160 net::test::SimpleRandom simple_random_; |
| 161 // Stored packets delayed by fake packet delay or bandwidth restrictions. | 161 // Stored packets delayed by fake packet delay or bandwidth restrictions. |
| 162 DelayedPacketList delayed_packets_; | 162 DelayedPacketList delayed_packets_; |
| 163 QuicByteCount cur_buffer_size_; | 163 QuicByteCount cur_buffer_size_; |
| 164 uint64_t num_calls_to_write_; | 164 uint64_t num_calls_to_write_; |
| 165 | 165 |
| 166 base::Lock config_mutex_; | 166 QuicMutex config_mutex_; |
| 167 int32_t fake_packet_loss_percentage_; | 167 int32_t fake_packet_loss_percentage_ GUARDED_BY(config_mutex_); |
| 168 int32_t fake_drop_first_n_packets_; | 168 int32_t fake_drop_first_n_packets_ GUARDED_BY(config_mutex_); |
| 169 int32_t fake_blocked_socket_percentage_; | 169 int32_t fake_blocked_socket_percentage_ GUARDED_BY(config_mutex_); |
| 170 int32_t fake_packet_reorder_percentage_; | 170 int32_t fake_packet_reorder_percentage_ GUARDED_BY(config_mutex_); |
| 171 QuicTime::Delta fake_packet_delay_; | 171 QuicTime::Delta fake_packet_delay_ GUARDED_BY(config_mutex_); |
| 172 QuicBandwidth fake_bandwidth_; | 172 QuicBandwidth fake_bandwidth_ GUARDED_BY(config_mutex_); |
| 173 QuicByteCount buffer_size_; | 173 QuicByteCount buffer_size_ GUARDED_BY(config_mutex_); |
| 174 | 174 |
| 175 DISALLOW_COPY_AND_ASSIGN(PacketDroppingTestWriter); | 175 DISALLOW_COPY_AND_ASSIGN(PacketDroppingTestWriter); |
| 176 }; | 176 }; |
| 177 | 177 |
| 178 } // namespace test | 178 } // namespace test |
| 179 } // namespace net | 179 } // namespace net |
| 180 | 180 |
| 181 #endif // NET_TOOLS_QUIC_TEST_TOOLS_PACKET_DROPPING_TEST_WRITER_H_ | 181 #endif // NET_TOOLS_QUIC_TEST_TOOLS_PACKET_DROPPING_TEST_WRITER_H_ |
| OLD | NEW |