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 #include "net/tools/quic/test_tools/packet_dropping_test_writer.h" | 5 #include "net/tools/quic/test_tools/packet_dropping_test_writer.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
10 #include "net/tools/quic/quic_epoll_connection_helper.h" | 10 #include "net/tools/quic/quic_epoll_connection_helper.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 write_unblocked_alarm_.reset( | 67 write_unblocked_alarm_.reset( |
68 helper->CreateAlarm(new WriteUnblockedAlarm(this))); | 68 helper->CreateAlarm(new WriteUnblockedAlarm(this))); |
69 delay_alarm_.reset(helper->CreateAlarm(new DelayAlarm(this))); | 69 delay_alarm_.reset(helper->CreateAlarm(new DelayAlarm(this))); |
70 on_can_write_.reset(on_can_write); | 70 on_can_write_.reset(on_can_write); |
71 } | 71 } |
72 | 72 |
73 WriteResult PacketDroppingTestWriter::WritePacket( | 73 WriteResult PacketDroppingTestWriter::WritePacket( |
74 const char* buffer, | 74 const char* buffer, |
75 size_t buf_len, | 75 size_t buf_len, |
76 const net::IPAddressNumber& self_address, | 76 const net::IPAddressNumber& self_address, |
77 const net::IPEndPoint& peer_address) { | 77 const net::IPEndPoint& peer_address, |
| 78 PerPacketOptions* options) { |
78 ++num_calls_to_write_; | 79 ++num_calls_to_write_; |
79 ReleaseOldPackets(); | 80 ReleaseOldPackets(); |
80 | 81 |
81 base::AutoLock locked(config_mutex_); | 82 base::AutoLock locked(config_mutex_); |
82 if (fake_drop_first_n_packets_ > 0 && | 83 if (fake_drop_first_n_packets_ > 0 && |
83 num_calls_to_write_ <= | 84 num_calls_to_write_ <= |
84 static_cast<uint64_t>(fake_drop_first_n_packets_)) { | 85 static_cast<uint64_t>(fake_drop_first_n_packets_)) { |
85 DVLOG(1) << "Dropping first " << fake_drop_first_n_packets_ | 86 DVLOG(1) << "Dropping first " << fake_drop_first_n_packets_ |
86 << " packets (packet number " << num_calls_to_write_ << ")"; | 87 << " packets (packet number " << num_calls_to_write_ << ")"; |
87 return WriteResult(WRITE_STATUS_OK, buf_len); | 88 return WriteResult(WRITE_STATUS_OK, buf_len); |
(...skipping 26 matching lines...) Expand all Loading... |
114 // Queue it to be sent. | 115 // Queue it to be sent. |
115 QuicTime send_time = clock_->ApproximateNow().Add(fake_packet_delay_); | 116 QuicTime send_time = clock_->ApproximateNow().Add(fake_packet_delay_); |
116 if (!fake_bandwidth_.IsZero()) { | 117 if (!fake_bandwidth_.IsZero()) { |
117 // Calculate a time the bandwidth limit would impose. | 118 // Calculate a time the bandwidth limit would impose. |
118 QuicTime::Delta bandwidth_delay = QuicTime::Delta::FromMicroseconds( | 119 QuicTime::Delta bandwidth_delay = QuicTime::Delta::FromMicroseconds( |
119 (buf_len * kNumMicrosPerSecond) / fake_bandwidth_.ToBytesPerSecond()); | 120 (buf_len * kNumMicrosPerSecond) / fake_bandwidth_.ToBytesPerSecond()); |
120 send_time = delayed_packets_.empty() | 121 send_time = delayed_packets_.empty() |
121 ? send_time.Add(bandwidth_delay) | 122 ? send_time.Add(bandwidth_delay) |
122 : delayed_packets_.back().send_time.Add(bandwidth_delay); | 123 : delayed_packets_.back().send_time.Add(bandwidth_delay); |
123 } | 124 } |
| 125 std::unique_ptr<PerPacketOptions> delayed_options; |
| 126 if (options != nullptr) { |
| 127 delayed_options.reset(options->Clone()); |
| 128 } |
124 delayed_packets_.push_back( | 129 delayed_packets_.push_back( |
125 DelayedWrite(buffer, buf_len, self_address, peer_address, send_time)); | 130 DelayedWrite(buffer, buf_len, self_address, peer_address, |
| 131 std::move(delayed_options), send_time)); |
126 cur_buffer_size_ += buf_len; | 132 cur_buffer_size_ += buf_len; |
127 | 133 |
128 // Set the alarm if it's not yet set. | 134 // Set the alarm if it's not yet set. |
129 if (!delay_alarm_->IsSet()) { | 135 if (!delay_alarm_->IsSet()) { |
130 delay_alarm_->Set(send_time); | 136 delay_alarm_->Set(send_time); |
131 } | 137 } |
132 | 138 |
133 return WriteResult(WRITE_STATUS_OK, buf_len); | 139 return WriteResult(WRITE_STATUS_OK, buf_len); |
134 } | 140 } |
135 | 141 |
136 return QuicPacketWriterWrapper::WritePacket(buffer, buf_len, self_address, | 142 return QuicPacketWriterWrapper::WritePacket(buffer, buf_len, self_address, |
137 peer_address); | 143 peer_address, options); |
138 } | 144 } |
139 | 145 |
140 bool PacketDroppingTestWriter::IsWriteBlocked() const { | 146 bool PacketDroppingTestWriter::IsWriteBlocked() const { |
141 if (write_unblocked_alarm_.get() != nullptr && | 147 if (write_unblocked_alarm_.get() != nullptr && |
142 write_unblocked_alarm_->IsSet()) { | 148 write_unblocked_alarm_->IsSet()) { |
143 return true; | 149 return true; |
144 } | 150 } |
145 return QuicPacketWriterWrapper::IsWriteBlocked(); | 151 return QuicPacketWriterWrapper::IsWriteBlocked(); |
146 } | 152 } |
147 | 153 |
(...skipping 17 matching lines...) Expand all Loading... |
165 static_cast<uint64_t>(fake_packet_reorder_percentage_)) { | 171 static_cast<uint64_t>(fake_packet_reorder_percentage_)) { |
166 DVLOG(1) << "Reordering packets."; | 172 DVLOG(1) << "Reordering packets."; |
167 ++iter; | 173 ++iter; |
168 // Swap the send times when re-ordering packets. | 174 // Swap the send times when re-ordering packets. |
169 delayed_packets_.begin()->send_time = iter->send_time; | 175 delayed_packets_.begin()->send_time = iter->send_time; |
170 } | 176 } |
171 | 177 |
172 DVLOG(1) << "Releasing packet. " << (delayed_packets_.size() - 1) | 178 DVLOG(1) << "Releasing packet. " << (delayed_packets_.size() - 1) |
173 << " remaining."; | 179 << " remaining."; |
174 // Grab the next one off the queue and send it. | 180 // Grab the next one off the queue and send it. |
175 QuicPacketWriterWrapper::WritePacket(iter->buffer.data(), | 181 QuicPacketWriterWrapper::WritePacket( |
176 iter->buffer.length(), | 182 iter->buffer.data(), iter->buffer.length(), iter->self_address, |
177 iter->self_address, iter->peer_address); | 183 iter->peer_address, iter->options.get()); |
178 DCHECK_GE(cur_buffer_size_, iter->buffer.length()); | 184 DCHECK_GE(cur_buffer_size_, iter->buffer.length()); |
179 cur_buffer_size_ -= iter->buffer.length(); | 185 cur_buffer_size_ -= iter->buffer.length(); |
180 delayed_packets_.erase(iter); | 186 delayed_packets_.erase(iter); |
181 | 187 |
182 // If there are others, find the time for the next to be sent. | 188 // If there are others, find the time for the next to be sent. |
183 if (delayed_packets_.empty()) { | 189 if (delayed_packets_.empty()) { |
184 return QuicTime::Zero(); | 190 return QuicTime::Zero(); |
185 } | 191 } |
186 return delayed_packets_.begin()->send_time; | 192 return delayed_packets_.begin()->send_time; |
187 } | 193 } |
(...skipping 11 matching lines...) Expand all Loading... |
199 | 205 |
200 void PacketDroppingTestWriter::OnCanWrite() { | 206 void PacketDroppingTestWriter::OnCanWrite() { |
201 on_can_write_->OnCanWrite(); | 207 on_can_write_->OnCanWrite(); |
202 } | 208 } |
203 | 209 |
204 PacketDroppingTestWriter::DelayedWrite::DelayedWrite( | 210 PacketDroppingTestWriter::DelayedWrite::DelayedWrite( |
205 const char* buffer, | 211 const char* buffer, |
206 size_t buf_len, | 212 size_t buf_len, |
207 const net::IPAddressNumber& self_address, | 213 const net::IPAddressNumber& self_address, |
208 const net::IPEndPoint& peer_address, | 214 const net::IPEndPoint& peer_address, |
| 215 std::unique_ptr<PerPacketOptions> options, |
209 QuicTime send_time) | 216 QuicTime send_time) |
210 : buffer(buffer, buf_len), | 217 : buffer(buffer, buf_len), |
211 self_address(self_address), | 218 self_address(self_address), |
212 peer_address(peer_address), | 219 peer_address(peer_address), |
| 220 options(std::move(options)), |
213 send_time(send_time) {} | 221 send_time(send_time) {} |
214 | 222 |
| 223 // TODO(rtenneti): on windows RValue reference gives errors. |
| 224 PacketDroppingTestWriter::DelayedWrite::DelayedWrite( |
| 225 PacketDroppingTestWriter::DelayedWrite&& other) = default; |
| 226 |
| 227 // TODO(rtenneti): on windows RValue reference gives errors. |
| 228 // IPAddressNumber has no move assignment operator. |
| 229 // |
| 230 // PacketDroppingTestWriter::DelayedWrite& |
| 231 // PacketDroppingTestWriter::DelayedWrite::operator=( |
| 232 // PacketDroppingTestWriter::DelayedWrite&& other) = default; |
| 233 |
215 PacketDroppingTestWriter::DelayedWrite::~DelayedWrite() {} | 234 PacketDroppingTestWriter::DelayedWrite::~DelayedWrite() {} |
216 | 235 |
217 } // namespace test | 236 } // namespace test |
218 } // namespace net | 237 } // namespace net |
OLD | NEW |