| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 <list> | 8 #include <list> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/synchronization/lock.h" |
| 12 #include "net/quic/quic_alarm.h" | 13 #include "net/quic/quic_alarm.h" |
| 13 #include "net/quic/quic_blocked_writer_interface.h" | 14 #include "net/quic/quic_blocked_writer_interface.h" |
| 14 #include "net/quic/quic_packet_writer.h" | 15 #include "net/quic/quic_packet_writer.h" |
| 15 #include "net/quic/test_tools/quic_test_writer.h" | 16 #include "net/quic/test_tools/quic_test_writer.h" |
| 16 #include "net/tools/quic/quic_epoll_clock.h" | 17 #include "net/tools/quic/quic_epoll_clock.h" |
| 17 #include "net/tools/quic/test_tools/quic_test_client.h" | 18 #include "net/tools/quic/test_tools/quic_test_client.h" |
| 18 #include "net/tools/quic/test_tools/quic_test_utils.h" | 19 #include "net/tools/quic/test_tools/quic_test_utils.h" |
| 19 | 20 |
| 20 namespace net { | 21 namespace net { |
| 21 namespace tools { | 22 namespace tools { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 42 virtual bool IsWriteBlockedDataBuffered() const OVERRIDE; | 43 virtual bool IsWriteBlockedDataBuffered() const OVERRIDE; |
| 43 | 44 |
| 44 // Writes out the next packet to the contained writer and returns the time | 45 // Writes out the next packet to the contained writer and returns the time |
| 45 // for the next delayed packet to be written. | 46 // for the next delayed packet to be written. |
| 46 QuicTime ReleaseNextPacket(); | 47 QuicTime ReleaseNextPacket(); |
| 47 | 48 |
| 48 QuicBlockedWriterInterface* blocked_writer() { return blocked_writer_; } | 49 QuicBlockedWriterInterface* blocked_writer() { return blocked_writer_; } |
| 49 | 50 |
| 50 // The percent of time a packet is simulated as being lost. | 51 // The percent of time a packet is simulated as being lost. |
| 51 void set_fake_packet_loss_percentage(int32 fake_packet_loss_percentage) { | 52 void set_fake_packet_loss_percentage(int32 fake_packet_loss_percentage) { |
| 53 base::AutoLock locked(config_mutex_); |
| 52 fake_packet_loss_percentage_ = fake_packet_loss_percentage; | 54 fake_packet_loss_percentage_ = fake_packet_loss_percentage; |
| 53 } | 55 } |
| 54 | 56 |
| 55 // The percent of time WritePacket will block and set WriteResult's status | 57 // The percent of time WritePacket will block and set WriteResult's status |
| 56 // to WRITE_STATUS_BLOCKED. | 58 // to WRITE_STATUS_BLOCKED. |
| 57 void set_fake_blocked_socket_percentage( | 59 void set_fake_blocked_socket_percentage( |
| 58 int32 fake_blocked_socket_percentage) { | 60 int32 fake_blocked_socket_percentage) { |
| 59 DCHECK(clock_); | 61 DCHECK(clock_); |
| 62 base::AutoLock locked(config_mutex_); |
| 60 fake_blocked_socket_percentage_ = fake_blocked_socket_percentage; | 63 fake_blocked_socket_percentage_ = fake_blocked_socket_percentage; |
| 61 } | 64 } |
| 62 | 65 |
| 63 // The percent of time a packet is simulated as being reordered. | 66 // The percent of time a packet is simulated as being reordered. |
| 64 void set_fake_reorder_percentage(int32 fake_packet_reorder_percentage) { | 67 void set_fake_reorder_percentage(int32 fake_packet_reorder_percentage) { |
| 65 DCHECK(clock_); | 68 DCHECK(clock_); |
| 69 base::AutoLock locked(config_mutex_); |
| 66 DCHECK(!fake_packet_delay_.IsZero()); | 70 DCHECK(!fake_packet_delay_.IsZero()); |
| 67 fake_packet_reorder_percentage_ = fake_packet_reorder_percentage; | 71 fake_packet_reorder_percentage_ = fake_packet_reorder_percentage; |
| 68 } | 72 } |
| 69 | 73 |
| 70 // The percent of time WritePacket will block and set WriteResult's status | 74 // The percent of time WritePacket will block and set WriteResult's status |
| 71 // to WRITE_STATUS_BLOCKED. | 75 // to WRITE_STATUS_BLOCKED. |
| 72 void set_fake_packet_delay(QuicTime::Delta fake_packet_delay) { | 76 void set_fake_packet_delay(QuicTime::Delta fake_packet_delay) { |
| 73 DCHECK(clock_); | 77 DCHECK(clock_); |
| 78 base::AutoLock locked(config_mutex_); |
| 74 fake_packet_delay_ = fake_packet_delay; | 79 fake_packet_delay_ = fake_packet_delay; |
| 75 } | 80 } |
| 76 | 81 |
| 77 void set_seed(uint64 seed) { | 82 void set_seed(uint64 seed) { |
| 78 simple_random_.set_seed(seed); | 83 simple_random_.set_seed(seed); |
| 79 } | 84 } |
| 80 | 85 |
| 81 private: | 86 private: |
| 82 // A single packet which will be sent at the supplied send_time. | 87 // A single packet which will be sent at the supplied send_time. |
| 83 class DelayedWrite { | 88 class DelayedWrite { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 94 const IPEndPoint peer_address; | 99 const IPEndPoint peer_address; |
| 95 QuicTime send_time; | 100 QuicTime send_time; |
| 96 }; | 101 }; |
| 97 | 102 |
| 98 typedef std::list<DelayedWrite> DelayedPacketList; | 103 typedef std::list<DelayedWrite> DelayedPacketList; |
| 99 | 104 |
| 100 const QuicClock* clock_; | 105 const QuicClock* clock_; |
| 101 scoped_ptr<QuicAlarm> write_unblocked_alarm_; | 106 scoped_ptr<QuicAlarm> write_unblocked_alarm_; |
| 102 scoped_ptr<QuicAlarm> delay_alarm_; | 107 scoped_ptr<QuicAlarm> delay_alarm_; |
| 103 QuicBlockedWriterInterface* blocked_writer_; | 108 QuicBlockedWriterInterface* blocked_writer_; |
| 109 SimpleRandom simple_random_; |
| 110 DelayedPacketList delayed_packets_; |
| 111 |
| 112 base::Lock config_mutex_; |
| 104 int32 fake_packet_loss_percentage_; | 113 int32 fake_packet_loss_percentage_; |
| 105 int32 fake_blocked_socket_percentage_; | 114 int32 fake_blocked_socket_percentage_; |
| 106 int32 fake_packet_reorder_percentage_; | 115 int32 fake_packet_reorder_percentage_; |
| 107 QuicTime::Delta fake_packet_delay_; | 116 QuicTime::Delta fake_packet_delay_; |
| 108 SimpleRandom simple_random_; | |
| 109 DelayedPacketList delayed_packets_; | |
| 110 | 117 |
| 111 DISALLOW_COPY_AND_ASSIGN(PacketDroppingTestWriter); | 118 DISALLOW_COPY_AND_ASSIGN(PacketDroppingTestWriter); |
| 112 }; | 119 }; |
| 113 | 120 |
| 114 } // namespace test | 121 } // namespace test |
| 115 } // namespace tools | 122 } // namespace tools |
| 116 } // namespace net | 123 } // namespace net |
| 117 | 124 |
| 118 #endif // NET_TOOLS_QUIC_TEST_TOOLS_PACKET_DROPPING_TEST_WRITER_H_ | 125 #endif // NET_TOOLS_QUIC_TEST_TOOLS_PACKET_DROPPING_TEST_WRITER_H_ |
| OLD | NEW |