Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1031)

Side by Side Diff: net/tools/quic/test_tools/packet_dropping_test_writer.h

Issue 1535363003: Switch to standard integer types in net/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: stddef Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
9 #include <stdint.h>
10
8 #include <list> 11 #include <list>
9 #include <string> 12 #include <string>
10 13
11 #include "base/basictypes.h"
12 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
14 #include "base/synchronization/lock.h" 17 #include "base/synchronization/lock.h"
15 #include "net/quic/quic_alarm.h" 18 #include "net/quic/quic_alarm.h"
16 #include "net/quic/test_tools/quic_test_utils.h" 19 #include "net/quic/test_tools/quic_test_utils.h"
17 #include "net/tools/quic/quic_epoll_clock.h" 20 #include "net/tools/quic/quic_epoll_clock.h"
18 #include "net/tools/quic/quic_packet_writer_wrapper.h" 21 #include "net/tools/quic/quic_packet_writer_wrapper.h"
19 #include "net/tools/quic/test_tools/quic_test_client.h" 22 #include "net/tools/quic/test_tools/quic_test_client.h"
20 23
21 namespace net { 24 namespace net {
22 namespace tools { 25 namespace tools {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 void SetWritable() override; 58 void SetWritable() override;
56 59
57 // Writes out any packet which should have been sent by now 60 // Writes out any packet which should have been sent by now
58 // to the contained writer and returns the time 61 // to the contained writer and returns the time
59 // for the next delayed packet to be written. 62 // for the next delayed packet to be written.
60 QuicTime ReleaseOldPackets(); 63 QuicTime ReleaseOldPackets();
61 64
62 void OnCanWrite(); 65 void OnCanWrite();
63 66
64 // The percent of time a packet is simulated as being lost. 67 // The percent of time a packet is simulated as being lost.
65 void set_fake_packet_loss_percentage(int32 fake_packet_loss_percentage) { 68 void set_fake_packet_loss_percentage(int32_t fake_packet_loss_percentage) {
66 base::AutoLock locked(config_mutex_); 69 base::AutoLock locked(config_mutex_);
67 fake_packet_loss_percentage_ = fake_packet_loss_percentage; 70 fake_packet_loss_percentage_ = fake_packet_loss_percentage;
68 } 71 }
69 72
70 // Simulate dropping the first n packets unconditionally. 73 // Simulate dropping the first n packets unconditionally.
71 // Subsequent packets will be lost at fake_packet_loss_percentage_ if set. 74 // Subsequent packets will be lost at fake_packet_loss_percentage_ if set.
72 void set_fake_drop_first_n_packets(int32 fake_drop_first_n_packets) { 75 void set_fake_drop_first_n_packets(int32_t fake_drop_first_n_packets) {
73 base::AutoLock locked(config_mutex_); 76 base::AutoLock locked(config_mutex_);
74 fake_drop_first_n_packets_ = fake_drop_first_n_packets; 77 fake_drop_first_n_packets_ = fake_drop_first_n_packets;
75 } 78 }
76 79
77 // The percent of time WritePacket will block and set WriteResult's status 80 // The percent of time WritePacket will block and set WriteResult's status
78 // to WRITE_STATUS_BLOCKED. 81 // to WRITE_STATUS_BLOCKED.
79 void set_fake_blocked_socket_percentage( 82 void set_fake_blocked_socket_percentage(
80 int32 fake_blocked_socket_percentage) { 83 int32_t fake_blocked_socket_percentage) {
81 DCHECK(clock_); 84 DCHECK(clock_);
82 base::AutoLock locked(config_mutex_); 85 base::AutoLock locked(config_mutex_);
83 fake_blocked_socket_percentage_ = fake_blocked_socket_percentage; 86 fake_blocked_socket_percentage_ = fake_blocked_socket_percentage;
84 } 87 }
85 88
86 // The percent of time a packet is simulated as being reordered. 89 // The percent of time a packet is simulated as being reordered.
87 void set_fake_reorder_percentage(int32 fake_packet_reorder_percentage) { 90 void set_fake_reorder_percentage(int32_t fake_packet_reorder_percentage) {
88 DCHECK(clock_); 91 DCHECK(clock_);
89 base::AutoLock locked(config_mutex_); 92 base::AutoLock locked(config_mutex_);
90 DCHECK(!fake_packet_delay_.IsZero()); 93 DCHECK(!fake_packet_delay_.IsZero());
91 fake_packet_reorder_percentage_ = fake_packet_reorder_percentage; 94 fake_packet_reorder_percentage_ = fake_packet_reorder_percentage;
92 } 95 }
93 96
94 // The delay before writing this packet. 97 // The delay before writing this packet.
95 void set_fake_packet_delay(QuicTime::Delta fake_packet_delay) { 98 void set_fake_packet_delay(QuicTime::Delta fake_packet_delay) {
96 DCHECK(clock_); 99 DCHECK(clock_);
97 base::AutoLock locked(config_mutex_); 100 base::AutoLock locked(config_mutex_);
98 fake_packet_delay_ = fake_packet_delay; 101 fake_packet_delay_ = fake_packet_delay;
99 } 102 }
100 103
101 // The maximum bandwidth and buffer size of the connection. When these are 104 // The maximum bandwidth and buffer size of the connection. When these are
102 // set, packets will be delayed until a connection with that bandwidth would 105 // set, packets will be delayed until a connection with that bandwidth would
103 // transmit it. Once the |buffer_size| is reached, all new packets are 106 // transmit it. Once the |buffer_size| is reached, all new packets are
104 // dropped. 107 // dropped.
105 void set_max_bandwidth_and_buffer_size(QuicBandwidth fake_bandwidth, 108 void set_max_bandwidth_and_buffer_size(QuicBandwidth fake_bandwidth,
106 QuicByteCount buffer_size) { 109 QuicByteCount buffer_size) {
107 DCHECK(clock_); 110 DCHECK(clock_);
108 base::AutoLock locked(config_mutex_); 111 base::AutoLock locked(config_mutex_);
109 fake_bandwidth_ = fake_bandwidth; 112 fake_bandwidth_ = fake_bandwidth;
110 buffer_size_ = buffer_size; 113 buffer_size_ = buffer_size;
111 } 114 }
112 115
113 // Useful for reproducing very flaky issues. 116 // Useful for reproducing very flaky issues.
114 void set_seed(uint64 seed) { simple_random_.set_seed(seed); } 117 void set_seed(uint64_t seed) { simple_random_.set_seed(seed); }
115 118
116 private: 119 private:
117 // Writes out the next packet to the contained writer and returns the time 120 // Writes out the next packet to the contained writer and returns the time
118 // for the next delayed packet to be written. 121 // for the next delayed packet to be written.
119 QuicTime ReleaseNextPacket(); 122 QuicTime ReleaseNextPacket();
120 123
121 // A single packet which will be sent at the supplied send_time. 124 // A single packet which will be sent at the supplied send_time.
122 struct DelayedWrite { 125 struct DelayedWrite {
123 public: 126 public:
124 DelayedWrite(const char* buffer, 127 DelayedWrite(const char* buffer,
(...skipping 12 matching lines...) Expand all
137 typedef std::list<DelayedWrite> DelayedPacketList; 140 typedef std::list<DelayedWrite> DelayedPacketList;
138 141
139 const QuicClock* clock_; 142 const QuicClock* clock_;
140 scoped_ptr<QuicAlarm> write_unblocked_alarm_; 143 scoped_ptr<QuicAlarm> write_unblocked_alarm_;
141 scoped_ptr<QuicAlarm> delay_alarm_; 144 scoped_ptr<QuicAlarm> delay_alarm_;
142 scoped_ptr<Delegate> on_can_write_; 145 scoped_ptr<Delegate> on_can_write_;
143 net::test::SimpleRandom simple_random_; 146 net::test::SimpleRandom simple_random_;
144 // Stored packets delayed by fake packet delay or bandwidth restrictions. 147 // Stored packets delayed by fake packet delay or bandwidth restrictions.
145 DelayedPacketList delayed_packets_; 148 DelayedPacketList delayed_packets_;
146 QuicByteCount cur_buffer_size_; 149 QuicByteCount cur_buffer_size_;
147 uint64 num_calls_to_write_; 150 uint64_t num_calls_to_write_;
148 151
149 base::Lock config_mutex_; 152 base::Lock config_mutex_;
150 int32 fake_packet_loss_percentage_; 153 int32_t fake_packet_loss_percentage_;
151 int32 fake_drop_first_n_packets_; 154 int32_t fake_drop_first_n_packets_;
152 int32 fake_blocked_socket_percentage_; 155 int32_t fake_blocked_socket_percentage_;
153 int32 fake_packet_reorder_percentage_; 156 int32_t fake_packet_reorder_percentage_;
154 QuicTime::Delta fake_packet_delay_; 157 QuicTime::Delta fake_packet_delay_;
155 QuicBandwidth fake_bandwidth_; 158 QuicBandwidth fake_bandwidth_;
156 QuicByteCount buffer_size_; 159 QuicByteCount buffer_size_;
157 160
158 DISALLOW_COPY_AND_ASSIGN(PacketDroppingTestWriter); 161 DISALLOW_COPY_AND_ASSIGN(PacketDroppingTestWriter);
159 }; 162 };
160 163
161 } // namespace test 164 } // namespace test
162 } // namespace tools 165 } // namespace tools
163 } // namespace net 166 } // namespace net
164 167
165 #endif // NET_TOOLS_QUIC_TEST_TOOLS_PACKET_DROPPING_TEST_WRITER_H_ 168 #endif // NET_TOOLS_QUIC_TEST_TOOLS_PACKET_DROPPING_TEST_WRITER_H_
OLDNEW
« no previous file with comments | « net/tools/quic/test_tools/mock_quic_server_session_visitor.h ('k') | net/tools/quic/test_tools/packet_dropping_test_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698