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 <list> | 8 #include <list> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
14 #include "net/quic/quic_alarm.h" | 14 #include "net/quic/quic_alarm.h" |
15 #include "net/quic/quic_blocked_writer_interface.h" | |
16 #include "net/tools/quic/quic_epoll_clock.h" | 15 #include "net/tools/quic/quic_epoll_clock.h" |
17 #include "net/tools/quic/quic_packet_writer_wrapper.h" | 16 #include "net/tools/quic/quic_packet_writer_wrapper.h" |
18 #include "net/tools/quic/test_tools/quic_test_client.h" | 17 #include "net/tools/quic/test_tools/quic_test_client.h" |
19 #include "net/tools/quic/test_tools/quic_test_utils.h" | 18 #include "net/tools/quic/test_tools/quic_test_utils.h" |
20 | 19 |
21 namespace net { | 20 namespace net { |
22 namespace tools { | 21 namespace tools { |
23 namespace test { | 22 namespace test { |
24 | 23 |
25 // Simulates a connection that drops packets a configured percentage of the time | 24 // Simulates a connection that drops packets a configured percentage of the time |
26 // and has a blocked socket a configured percentage of the time. Also provides | 25 // and has a blocked socket a configured percentage of the time. Also provides |
27 // the options to delay packets and reorder packets if delay is enabled. | 26 // the options to delay packets and reorder packets if delay is enabled. |
28 class PacketDroppingTestWriter : public QuicPacketWriterWrapper { | 27 class PacketDroppingTestWriter : public QuicPacketWriterWrapper { |
29 public: | 28 public: |
| 29 class Delegate { |
| 30 public: |
| 31 virtual ~Delegate() {} |
| 32 virtual void OnCanWrite() = 0; |
| 33 }; |
| 34 |
30 PacketDroppingTestWriter(); | 35 PacketDroppingTestWriter(); |
31 | 36 |
32 virtual ~PacketDroppingTestWriter(); | 37 virtual ~PacketDroppingTestWriter(); |
33 | 38 |
34 void SetConnectionHelper(QuicEpollConnectionHelper* helper); | 39 // Must be called before blocking, reordering or delaying (loss is OK). May be |
| 40 // called after connecting if the helper is not available before. |
| 41 // |on_can_write| will be triggered when fake-unblocking; ownership will be |
| 42 // assumed. |
| 43 void Initialize(QuicEpollConnectionHelper* helper, Delegate* on_can_write); |
35 | 44 |
36 // QuicPacketWriter methods: | 45 // QuicPacketWriter methods: |
37 virtual WriteResult WritePacket( | 46 virtual WriteResult WritePacket( |
38 const char* buffer, | 47 const char* buffer, |
39 size_t buf_len, | 48 size_t buf_len, |
40 const IPAddressNumber& self_address, | 49 const IPAddressNumber& self_address, |
41 const IPEndPoint& peer_address, | 50 const IPEndPoint& peer_address) OVERRIDE; |
42 QuicBlockedWriterInterface* blocked_writer) OVERRIDE; | |
43 | 51 |
44 virtual bool IsWriteBlocked() const OVERRIDE; | 52 virtual bool IsWriteBlocked() const OVERRIDE; |
45 | 53 |
46 virtual void SetWritable() OVERRIDE; | 54 virtual void SetWritable() OVERRIDE; |
47 | 55 |
48 // Writes out any packet which should have been sent by now | 56 // Writes out any packet which should have been sent by now |
49 // to the contained writer and returns the time | 57 // to the contained writer and returns the time |
50 // for the next delayed packet to be written. | 58 // for the next delayed packet to be written. |
51 QuicTime ReleaseOldPackets(); | 59 QuicTime ReleaseOldPackets(); |
52 | 60 |
53 QuicBlockedWriterInterface* blocked_writer() { return blocked_writer_; } | 61 void OnCanWrite(); |
54 | 62 |
55 // The percent of time a packet is simulated as being lost. | 63 // The percent of time a packet is simulated as being lost. |
56 void set_fake_packet_loss_percentage(int32 fake_packet_loss_percentage) { | 64 void set_fake_packet_loss_percentage(int32 fake_packet_loss_percentage) { |
57 base::AutoLock locked(config_mutex_); | 65 base::AutoLock locked(config_mutex_); |
58 fake_packet_loss_percentage_ = fake_packet_loss_percentage; | 66 fake_packet_loss_percentage_ = fake_packet_loss_percentage; |
59 } | 67 } |
60 | 68 |
61 // The percent of time WritePacket will block and set WriteResult's status | 69 // The percent of time WritePacket will block and set WriteResult's status |
62 // to WRITE_STATUS_BLOCKED. | 70 // to WRITE_STATUS_BLOCKED. |
63 void set_fake_blocked_socket_percentage( | 71 void set_fake_blocked_socket_percentage( |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 const IPAddressNumber self_address; | 126 const IPAddressNumber self_address; |
119 const IPEndPoint peer_address; | 127 const IPEndPoint peer_address; |
120 QuicTime send_time; | 128 QuicTime send_time; |
121 }; | 129 }; |
122 | 130 |
123 typedef std::list<DelayedWrite> DelayedPacketList; | 131 typedef std::list<DelayedWrite> DelayedPacketList; |
124 | 132 |
125 const QuicClock* clock_; | 133 const QuicClock* clock_; |
126 scoped_ptr<QuicAlarm> write_unblocked_alarm_; | 134 scoped_ptr<QuicAlarm> write_unblocked_alarm_; |
127 scoped_ptr<QuicAlarm> delay_alarm_; | 135 scoped_ptr<QuicAlarm> delay_alarm_; |
128 QuicBlockedWriterInterface* blocked_writer_; | 136 scoped_ptr<Delegate> on_can_write_; |
129 SimpleRandom simple_random_; | 137 SimpleRandom simple_random_; |
130 // Stored packets delayed by fake packet delay or bandwidth restrictions. | 138 // Stored packets delayed by fake packet delay or bandwidth restrictions. |
131 DelayedPacketList delayed_packets_; | 139 DelayedPacketList delayed_packets_; |
132 QuicByteCount cur_buffer_size_; | 140 QuicByteCount cur_buffer_size_; |
133 | 141 |
134 base::Lock config_mutex_; | 142 base::Lock config_mutex_; |
135 int32 fake_packet_loss_percentage_; | 143 int32 fake_packet_loss_percentage_; |
136 int32 fake_blocked_socket_percentage_; | 144 int32 fake_blocked_socket_percentage_; |
137 int32 fake_packet_reorder_percentage_; | 145 int32 fake_packet_reorder_percentage_; |
138 QuicTime::Delta fake_packet_delay_; | 146 QuicTime::Delta fake_packet_delay_; |
139 QuicBandwidth fake_bandwidth_; | 147 QuicBandwidth fake_bandwidth_; |
140 QuicByteCount buffer_size_; | 148 QuicByteCount buffer_size_; |
141 | 149 |
142 DISALLOW_COPY_AND_ASSIGN(PacketDroppingTestWriter); | 150 DISALLOW_COPY_AND_ASSIGN(PacketDroppingTestWriter); |
143 }; | 151 }; |
144 | 152 |
145 } // namespace test | 153 } // namespace test |
146 } // namespace tools | 154 } // namespace tools |
147 } // namespace net | 155 } // namespace net |
148 | 156 |
149 #endif // NET_TOOLS_QUIC_TEST_TOOLS_PACKET_DROPPING_TEST_WRITER_H_ | 157 #endif // NET_TOOLS_QUIC_TEST_TOOLS_PACKET_DROPPING_TEST_WRITER_H_ |
OLD | NEW |