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

Side by Side Diff: net/quic/quic_sent_packet_manager.cc

Issue 300683008: Land Recent QUIC Changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months 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 | Annotate | Revision Log
« no previous file with comments | « net/quic/quic_sent_packet_manager.h ('k') | net/quic/quic_sent_packet_manager_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "net/quic/quic_sent_packet_manager.h" 5 #include "net/quic/quic_sent_packet_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 new_sequence_number); 119 new_sequence_number);
120 } 120 }
121 121
122 void QuicSentPacketManager::OnIncomingAck( 122 void QuicSentPacketManager::OnIncomingAck(
123 const ReceivedPacketInfo& received_info, 123 const ReceivedPacketInfo& received_info,
124 QuicTime ack_receive_time) { 124 QuicTime ack_receive_time) {
125 QuicByteCount bytes_in_flight = unacked_packets_.bytes_in_flight(); 125 QuicByteCount bytes_in_flight = unacked_packets_.bytes_in_flight();
126 126
127 // We rely on delta_time_largest_observed to compute an RTT estimate, so 127 // We rely on delta_time_largest_observed to compute an RTT estimate, so
128 // we only update rtt when the largest observed gets acked. 128 // we only update rtt when the largest observed gets acked.
129 largest_observed_ = received_info.largest_observed;
130 bool largest_observed_acked = MaybeUpdateRTT(received_info, ack_receive_time); 129 bool largest_observed_acked = MaybeUpdateRTT(received_info, ack_receive_time);
130 if (largest_observed_ < received_info.largest_observed) {
131 largest_observed_ = received_info.largest_observed;
132 unacked_packets_.IncreaseLargestObserved(largest_observed_);
133 }
131 HandleAckForSentPackets(received_info); 134 HandleAckForSentPackets(received_info);
132 InvokeLossDetection(ack_receive_time); 135 InvokeLossDetection(ack_receive_time);
133 MaybeInvokeCongestionEvent(largest_observed_acked, bytes_in_flight); 136 MaybeInvokeCongestionEvent(largest_observed_acked, bytes_in_flight);
134 137
135 // If we have received a truncated ack, then we need to clear out some 138 // If we have received a truncated ack, then we need to clear out some
136 // previous transmissions to allow the peer to actually ACK new packets. 139 // previous transmissions to allow the peer to actually ACK new packets.
137 if (received_info.is_truncated) { 140 if (received_info.is_truncated) {
138 unacked_packets_.ClearPreviousRetransmissions( 141 unacked_packets_.ClearPreviousRetransmissions(
139 received_info.missing_packets.size() / 2); 142 received_info.missing_packets.size() / 2);
140 } 143 }
(...skipping 27 matching lines...) Expand all
168 received_info.delta_time_largest_observed; 171 received_info.delta_time_largest_observed;
169 QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); 172 QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin();
170 while (it != unacked_packets_.end()) { 173 while (it != unacked_packets_.end()) {
171 QuicPacketSequenceNumber sequence_number = it->first; 174 QuicPacketSequenceNumber sequence_number = it->first;
172 if (sequence_number > received_info.largest_observed) { 175 if (sequence_number > received_info.largest_observed) {
173 // These packets are still in flight. 176 // These packets are still in flight.
174 break; 177 break;
175 } 178 }
176 179
177 if (IsAwaitingPacket(received_info, sequence_number)) { 180 if (IsAwaitingPacket(received_info, sequence_number)) {
178 // Remove any rtt only packets less than or equal to the largest observed, 181 // Consider it multiple nacks when there is a gap between the missing
179 // since they will not produce an RTT measurement. 182 // packet and the largest observed, since the purpose of a nack
180 if (QuicUnackedPacketMap::IsForRttOnly(it->second)) { 183 // threshold is to tolerate re-ordering. This handles both StretchAcks
181 ++it; 184 // and Forward Acks.
182 unacked_packets_.RemoveRttOnlyPacket(sequence_number); 185 // The nack count only increases when the largest observed increases.
183 } else { 186 size_t min_nacks = received_info.largest_observed - sequence_number;
184 // Consider it multiple nacks when there is a gap between the missing 187 // Truncated acks can nack the largest observed, so use a min of 1.
185 // packet and the largest observed, since the purpose of a nack 188 if (min_nacks == 0) {
186 // threshold is to tolerate re-ordering. This handles both StretchAcks 189 min_nacks = 1;
187 // and Forward Acks.
188 // The nack count only increases when the largest observed increases.
189 size_t min_nacks = received_info.largest_observed - sequence_number;
190 // Truncated acks can nack the largest observed, so use a min of 1.
191 if (min_nacks == 0) {
192 min_nacks = 1;
193 }
194 unacked_packets_.NackPacket(sequence_number, min_nacks);
195 ++it;
196 } 190 }
191 unacked_packets_.NackPacket(sequence_number, min_nacks);
192 ++it;
197 continue; 193 continue;
198 } 194 }
199
200 // Packet was acked, so remove it from our unacked packet list. 195 // Packet was acked, so remove it from our unacked packet list.
201 DVLOG(1) << ENDPOINT << "Got an ack for packet " << sequence_number; 196 DVLOG(1) << ENDPOINT << "Got an ack for packet " << sequence_number;
202 // If data is associated with the most recent transmission of this 197 // If data is associated with the most recent transmission of this
203 // packet, then inform the caller. 198 // packet, then inform the caller.
204 if (it->second.pending) { 199 if (it->second.in_flight) {
205 packets_acked_[sequence_number] = it->second; 200 packets_acked_[sequence_number] = it->second;
206 } 201 }
207 it = MarkPacketHandled(sequence_number, delta_largest_observed); 202 it = MarkPacketHandled(it, delta_largest_observed);
208 } 203 }
209 204
210 // Discard any retransmittable frames associated with revived packets. 205 // Discard any retransmittable frames associated with revived packets.
211 for (SequenceNumberSet::const_iterator revived_it = 206 for (SequenceNumberSet::const_iterator revived_it =
212 received_info.revived_packets.begin(); 207 received_info.revived_packets.begin();
213 revived_it != received_info.revived_packets.end(); ++revived_it) { 208 revived_it != received_info.revived_packets.end(); ++revived_it) {
214 MarkPacketRevived(*revived_it, delta_largest_observed); 209 MarkPacketRevived(*revived_it, delta_largest_observed);
215 } 210 }
216 } 211 }
217 212
218 bool QuicSentPacketManager::HasRetransmittableFrames( 213 bool QuicSentPacketManager::HasRetransmittableFrames(
219 QuicPacketSequenceNumber sequence_number) const { 214 QuicPacketSequenceNumber sequence_number) const {
220 return unacked_packets_.HasRetransmittableFrames(sequence_number); 215 return unacked_packets_.HasRetransmittableFrames(sequence_number);
221 } 216 }
222 217
223 void QuicSentPacketManager::RetransmitUnackedPackets( 218 void QuicSentPacketManager::RetransmitUnackedPackets(
224 RetransmissionType retransmission_type) { 219 RetransmissionType retransmission_type) {
225 QuicUnackedPacketMap::const_iterator unacked_it = unacked_packets_.begin(); 220 QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin();
226 while (unacked_it != unacked_packets_.end()) { 221 while (it != unacked_packets_.end()) {
227 const RetransmittableFrames* frames = 222 const RetransmittableFrames* frames = it->second.retransmittable_frames;
228 unacked_it->second.retransmittable_frames;
229 // Only mark it as handled if it can't be retransmitted and there are no
230 // pending retransmissions which would be cleared.
231 if (frames == NULL && unacked_it->second.all_transmissions->size() == 1 &&
232 retransmission_type == ALL_PACKETS) {
233 unacked_it = MarkPacketHandled(unacked_it->first,
234 QuicTime::Delta::Zero());
235 continue;
236 }
237 // If it had no other transmissions, we handle it above. If it has
238 // other transmissions, one of them must have retransmittable frames,
239 // so that gets resolved the same way as other retransmissions.
240 // TODO(ianswett): Consider adding a new retransmission type which removes 223 // TODO(ianswett): Consider adding a new retransmission type which removes
241 // all these old packets from unacked and retransmits them as new sequence 224 // all these old packets from unacked and retransmits them as new sequence
242 // numbers with no connection to the previous ones. 225 // numbers with no connection to the previous ones.
243 if (frames != NULL && (retransmission_type == ALL_PACKETS || 226 if (frames != NULL && (retransmission_type == ALL_PACKETS ||
244 frames->encryption_level() == ENCRYPTION_INITIAL)) { 227 frames->encryption_level() == ENCRYPTION_INITIAL)) {
245 MarkForRetransmission(unacked_it->first, ALL_UNACKED_RETRANSMISSION); 228 MarkForRetransmission(it->first, ALL_UNACKED_RETRANSMISSION);
246 } 229 }
247 ++unacked_it; 230 ++it;
248 } 231 }
249 } 232 }
250 233
251 void QuicSentPacketManager::NeuterUnencryptedPackets() { 234 void QuicSentPacketManager::NeuterUnencryptedPackets() {
252 for (QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); 235 QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin();
253 it != unacked_packets_.end(); ++it) { 236 while (it != unacked_packets_.end()) {
254 const RetransmittableFrames* frames = 237 const RetransmittableFrames* frames = it->second.retransmittable_frames;
255 it->second.retransmittable_frames; 238 QuicPacketSequenceNumber sequence_number = it->first;
239 ++it;
256 if (frames != NULL && frames->encryption_level() == ENCRYPTION_NONE) { 240 if (frames != NULL && frames->encryption_level() == ENCRYPTION_NONE) {
257 // Once you're forward secure, no unencrypted packets will be sent, crypto 241 // Once you're forward secure, no unencrypted packets will be sent, crypto
258 // or otherwise. Unencrypted packets are neutered and abandoned, to ensure 242 // or otherwise. Unencrypted packets are neutered and abandoned, to ensure
259 // they are not retransmitted or considered lost from a congestion control 243 // they are not retransmitted or considered lost from a congestion control
260 // perspective. 244 // perspective.
261 pending_retransmissions_.erase(it->first); 245 pending_retransmissions_.erase(sequence_number);
262 unacked_packets_.RemoveRetransmittability(it->first, largest_observed_); 246 unacked_packets_.RemoveFromInFlight(sequence_number);
263 unacked_packets_.SetNotPending(it->first); 247 // RemoveRetransmittibility is safe because only the newest sequence
248 // number can have frames.
249 unacked_packets_.RemoveRetransmittability(sequence_number);
264 } 250 }
265 } 251 }
266 } 252 }
267 253
268 void QuicSentPacketManager::MarkForRetransmission( 254 void QuicSentPacketManager::MarkForRetransmission(
269 QuicPacketSequenceNumber sequence_number, 255 QuicPacketSequenceNumber sequence_number,
270 TransmissionType transmission_type) { 256 TransmissionType transmission_type) {
271 const TransmissionInfo& transmission_info = 257 const TransmissionInfo& transmission_info =
272 unacked_packets_.GetTransmissionInfo(sequence_number); 258 unacked_packets_.GetTransmissionInfo(sequence_number);
273 LOG_IF(DFATAL, transmission_info.retransmittable_frames == NULL); 259 LOG_IF(DFATAL, transmission_info.retransmittable_frames == NULL);
274 if (transmission_type != TLP_RETRANSMISSION) { 260 if (transmission_type != TLP_RETRANSMISSION) {
275 unacked_packets_.SetNotPending(sequence_number); 261 unacked_packets_.RemoveFromInFlight(sequence_number);
276 } 262 }
277 // TODO(ianswett): Currently the RTO can fire while there are pending NACK 263 // TODO(ianswett): Currently the RTO can fire while there are pending NACK
278 // retransmissions for the same data, which is not ideal. 264 // retransmissions for the same data, which is not ideal.
279 if (ContainsKey(pending_retransmissions_, sequence_number)) { 265 if (ContainsKey(pending_retransmissions_, sequence_number)) {
280 return; 266 return;
281 } 267 }
282 268
283 pending_retransmissions_[sequence_number] = transmission_type; 269 pending_retransmissions_[sequence_number] = transmission_type;
284 } 270 }
285 271
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 // retransmit it, do not retransmit it anymore. 318 // retransmit it, do not retransmit it anymore.
333 pending_retransmissions_.erase(newest_transmission); 319 pending_retransmissions_.erase(newest_transmission);
334 320
335 // The AckNotifierManager needs to be notified for revived packets, 321 // The AckNotifierManager needs to be notified for revived packets,
336 // since it indicates the packet arrived from the appliction's perspective. 322 // since it indicates the packet arrived from the appliction's perspective.
337 if (transmission_info.retransmittable_frames) { 323 if (transmission_info.retransmittable_frames) {
338 ack_notifier_manager_.OnPacketAcked( 324 ack_notifier_manager_.OnPacketAcked(
339 newest_transmission, delta_largest_observed); 325 newest_transmission, delta_largest_observed);
340 } 326 }
341 327
342 unacked_packets_.RemoveRetransmittability(sequence_number, largest_observed_); 328 unacked_packets_.RemoveRetransmittability(sequence_number);
343 } 329 }
344 330
345 QuicUnackedPacketMap::const_iterator QuicSentPacketManager::MarkPacketHandled( 331 QuicUnackedPacketMap::const_iterator QuicSentPacketManager::MarkPacketHandled(
346 QuicPacketSequenceNumber sequence_number, 332 QuicUnackedPacketMap::const_iterator it,
347 QuicTime::Delta delta_largest_observed) { 333 QuicTime::Delta delta_largest_observed) {
348 if (!unacked_packets_.IsUnacked(sequence_number)) { 334 LOG_IF(DFATAL, it == unacked_packets_.end())
349 LOG(DFATAL) << "Packet is not unacked: " << sequence_number; 335 << "MarkPacketHandled must be passed a valid iterator entry.";
350 return unacked_packets_.end(); 336 const QuicPacketSequenceNumber sequence_number = it->first;
351 } 337 const TransmissionInfo& transmission_info = it->second;
352 const TransmissionInfo& transmission_info =
353 unacked_packets_.GetTransmissionInfo(sequence_number);
354 338
355 QuicPacketSequenceNumber newest_transmission = 339 QuicPacketSequenceNumber newest_transmission =
356 *transmission_info.all_transmissions->rbegin(); 340 *transmission_info.all_transmissions->rbegin();
357 // Remove the most recent packet, if it is pending retransmission. 341 // Remove the most recent packet, if it is pending retransmission.
358 pending_retransmissions_.erase(newest_transmission); 342 pending_retransmissions_.erase(newest_transmission);
359 343
360 // Two cases for MarkPacketHandled: 344 // Two cases for MarkPacketHandled:
361 // 1) Handle the most recent or a crypto packet, so remove all transmissions. 345 // 1) Handle the most recent or a crypto packet, so remove all transmissions.
362 // 2) Handle old transmission, keep all other pending transmissions, 346 // 2) Handle old transmission, keep all other pending transmissions,
363 // but disassociate them from one another. 347 // but disassociate them from one another.
364 if (newest_transmission != sequence_number) { 348 if (newest_transmission != sequence_number) {
365 stats_->bytes_spuriously_retransmitted += transmission_info.bytes_sent; 349 stats_->bytes_spuriously_retransmitted += transmission_info.bytes_sent;
366 ++stats_->packets_spuriously_retransmitted; 350 ++stats_->packets_spuriously_retransmitted;
367 } 351 }
368 352
369 // The AckNotifierManager needs to be notified about the most recent 353 // The AckNotifierManager needs to be notified about the most recent
370 // transmission, since that's the one only one it tracks. 354 // transmission, since that's the one only one it tracks.
371 ack_notifier_manager_.OnPacketAcked(newest_transmission, 355 ack_notifier_manager_.OnPacketAcked(newest_transmission,
372 delta_largest_observed); 356 delta_largest_observed);
373 357
374 // If it's a crypto handshake packet, discard it and all retransmissions, 358 // If it's a crypto handshake packet, discard it and all retransmissions,
375 // since they won't be acked now that one has been processed. 359 // since they won't be acked now that one has been processed.
376 // TODO(ianswett): Instead of handling all crypto packets in a special way, 360 // TODO(ianswett): Instead of handling all crypto packets in a special way,
377 // only handle NULL encrypted packets in a special way. 361 // only handle NULL encrypted packets in a special way.
378 if (HasCryptoHandshake( 362 if (HasCryptoHandshake(
379 unacked_packets_.GetTransmissionInfo(newest_transmission))) { 363 unacked_packets_.GetTransmissionInfo(newest_transmission))) {
380 unacked_packets_.SetNotPending(newest_transmission); 364 unacked_packets_.RemoveFromInFlight(newest_transmission);
381 } 365 }
382 unacked_packets_.SetNotPending(sequence_number); 366 unacked_packets_.RemoveFromInFlight(sequence_number);
383 unacked_packets_.RemoveRetransmittability(sequence_number, largest_observed_); 367 unacked_packets_.RemoveRetransmittability(sequence_number);
384 368
385 QuicUnackedPacketMap::const_iterator next_unacked = unacked_packets_.begin(); 369 QuicUnackedPacketMap::const_iterator next_unacked = unacked_packets_.begin();
386 while (next_unacked != unacked_packets_.end() && 370 while (next_unacked != unacked_packets_.end() &&
387 next_unacked->first <= sequence_number) { 371 next_unacked->first <= sequence_number) {
388 ++next_unacked; 372 ++next_unacked;
389 } 373 }
390 return next_unacked; 374 return next_unacked;
391 } 375 }
392 376
393 bool QuicSentPacketManager::IsUnacked( 377 bool QuicSentPacketManager::IsUnacked(
(...skipping 25 matching lines...) Expand all
419 } 403 }
420 404
421 if (unacked_packets_.bytes_in_flight() == 0) { 405 if (unacked_packets_.bytes_in_flight() == 0) {
422 // TODO(ianswett): Consider being less aggressive to force a new 406 // TODO(ianswett): Consider being less aggressive to force a new
423 // recent_min_rtt, likely by not discarding a relatively new sample. 407 // recent_min_rtt, likely by not discarding a relatively new sample.
424 DVLOG(1) << "Sampling a new recent min rtt within 2 samples. currently:" 408 DVLOG(1) << "Sampling a new recent min rtt within 2 samples. currently:"
425 << rtt_stats_.recent_min_rtt().ToMilliseconds() << "ms"; 409 << rtt_stats_.recent_min_rtt().ToMilliseconds() << "ms";
426 rtt_stats_.SampleNewRecentMinRtt(kNumMinRttSamplesAfterQuiescence); 410 rtt_stats_.SampleNewRecentMinRtt(kNumMinRttSamplesAfterQuiescence);
427 } 411 }
428 412
429 // Only track packets as pending that the send algorithm wants us to track. 413 // Only track packets as in flight that the send algorithm wants us to track.
430 const bool pending = 414 const bool in_flight =
431 send_algorithm_->OnPacketSent(sent_time, 415 send_algorithm_->OnPacketSent(sent_time,
432 unacked_packets_.bytes_in_flight(), 416 unacked_packets_.bytes_in_flight(),
433 sequence_number, 417 sequence_number,
434 bytes, 418 bytes,
435 has_retransmittable_data); 419 has_retransmittable_data);
436 unacked_packets_.SetSent(sequence_number, sent_time, bytes, pending); 420 unacked_packets_.SetSent(sequence_number, sent_time, bytes, in_flight);
437 421
438 // Reset the retransmission timer anytime a pending packet is sent. 422 // Reset the retransmission timer anytime a pending packet is sent.
439 return pending; 423 return in_flight;
440 } 424 }
441 425
442 void QuicSentPacketManager::OnRetransmissionTimeout() { 426 void QuicSentPacketManager::OnRetransmissionTimeout() {
443 DCHECK(unacked_packets_.HasPendingPackets()); 427 DCHECK(unacked_packets_.HasInFlightPackets());
444 // Handshake retransmission, timer based loss detection, TLP, and RTO are 428 // Handshake retransmission, timer based loss detection, TLP, and RTO are
445 // implemented with a single alarm. The handshake alarm is set when the 429 // implemented with a single alarm. The handshake alarm is set when the
446 // handshake has not completed, the loss alarm is set when the loss detection 430 // handshake has not completed, the loss alarm is set when the loss detection
447 // algorithm says to, and the TLP and RTO alarms are set after that. 431 // algorithm says to, and the TLP and RTO alarms are set after that.
448 // The TLP alarm is always set to run for under an RTO. 432 // The TLP alarm is always set to run for under an RTO.
449 switch (GetRetransmissionMode()) { 433 switch (GetRetransmissionMode()) {
450 case HANDSHAKE_MODE: 434 case HANDSHAKE_MODE:
451 ++stats_->crypto_retransmit_count; 435 ++stats_->crypto_retransmit_count;
452 RetransmitCryptoPackets(); 436 RetransmitCryptoPackets();
453 return; 437 return;
(...skipping 21 matching lines...) Expand all
475 DCHECK_EQ(HANDSHAKE_MODE, GetRetransmissionMode()); 459 DCHECK_EQ(HANDSHAKE_MODE, GetRetransmissionMode());
476 // TODO(ianswett): Typical TCP implementations only retransmit 5 times. 460 // TODO(ianswett): Typical TCP implementations only retransmit 5 times.
477 consecutive_crypto_retransmission_count_ = 461 consecutive_crypto_retransmission_count_ =
478 min(kMaxHandshakeRetransmissionBackoffs, 462 min(kMaxHandshakeRetransmissionBackoffs,
479 consecutive_crypto_retransmission_count_ + 1); 463 consecutive_crypto_retransmission_count_ + 1);
480 bool packet_retransmitted = false; 464 bool packet_retransmitted = false;
481 for (QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); 465 for (QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin();
482 it != unacked_packets_.end(); ++it) { 466 it != unacked_packets_.end(); ++it) {
483 QuicPacketSequenceNumber sequence_number = it->first; 467 QuicPacketSequenceNumber sequence_number = it->first;
484 const RetransmittableFrames* frames = it->second.retransmittable_frames; 468 const RetransmittableFrames* frames = it->second.retransmittable_frames;
485 // Only retransmit frames which are pending, and therefore have been sent. 469 // Only retransmit frames which are in flight, and therefore have been sent.
486 if (!it->second.pending || frames == NULL || 470 if (!it->second.in_flight || frames == NULL ||
487 frames->HasCryptoHandshake() != IS_HANDSHAKE) { 471 frames->HasCryptoHandshake() != IS_HANDSHAKE) {
488 continue; 472 continue;
489 } 473 }
490 packet_retransmitted = true; 474 packet_retransmitted = true;
491 MarkForRetransmission(sequence_number, HANDSHAKE_RETRANSMISSION); 475 MarkForRetransmission(sequence_number, HANDSHAKE_RETRANSMISSION);
492 } 476 }
493 DCHECK(packet_retransmitted) << "No crypto packets found to retransmit."; 477 DCHECK(packet_retransmitted) << "No crypto packets found to retransmit.";
494 } 478 }
495 479
496 void QuicSentPacketManager::RetransmitOldestPacket() { 480 void QuicSentPacketManager::RetransmitOldestPacket() {
497 DCHECK_EQ(TLP_MODE, GetRetransmissionMode()); 481 DCHECK_EQ(TLP_MODE, GetRetransmissionMode());
498 ++consecutive_tlp_count_; 482 ++consecutive_tlp_count_;
499 for (QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); 483 for (QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin();
500 it != unacked_packets_.end(); ++it) { 484 it != unacked_packets_.end(); ++it) {
501 QuicPacketSequenceNumber sequence_number = it->first; 485 QuicPacketSequenceNumber sequence_number = it->first;
502 const RetransmittableFrames* frames = it->second.retransmittable_frames; 486 const RetransmittableFrames* frames = it->second.retransmittable_frames;
503 // Only retransmit frames which are pending, and therefore have been sent. 487 // Only retransmit frames which are in flight, and therefore have been sent.
504 if (!it->second.pending || frames == NULL) { 488 if (!it->second.in_flight || frames == NULL) {
505 continue; 489 continue;
506 } 490 }
507 DCHECK_NE(IS_HANDSHAKE, frames->HasCryptoHandshake()); 491 DCHECK_NE(IS_HANDSHAKE, frames->HasCryptoHandshake());
508 MarkForRetransmission(sequence_number, TLP_RETRANSMISSION); 492 MarkForRetransmission(sequence_number, TLP_RETRANSMISSION);
509 return; 493 return;
510 } 494 }
511 DLOG(FATAL) 495 DLOG(FATAL)
512 << "No retransmittable packets, so RetransmitOldestPacket failed."; 496 << "No retransmittable packets, so RetransmitOldestPacket failed.";
513 } 497 }
514 498
515 void QuicSentPacketManager::RetransmitAllPackets() { 499 void QuicSentPacketManager::RetransmitAllPackets() {
516 // Abandon all retransmittable packets and packets older than the 500 // Abandon all retransmittable packets and packets older than the
517 // retransmission delay. 501 // retransmission delay.
518 502
519 DVLOG(1) << "OnRetransmissionTimeout() fired with " 503 DVLOG(1) << "OnRetransmissionTimeout() fired with "
520 << unacked_packets_.GetNumUnackedPackets() << " unacked packets."; 504 << unacked_packets_.GetNumUnackedPackets() << " unacked packets.";
521 505
522 // Request retransmission of all retransmittable packets when the RTO 506 // Request retransmission of all retransmittable packets when the RTO
523 // fires, and let the congestion manager decide how many to send 507 // fires, and let the congestion manager decide how many to send
524 // immediately and the remaining packets will be queued. 508 // immediately and the remaining packets will be queued.
525 // Abandon any non-retransmittable packets that are sufficiently old. 509 // Abandon any non-retransmittable packets that are sufficiently old.
526 bool packets_retransmitted = false; 510 bool packets_retransmitted = false;
527 for (QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); 511 QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin();
528 it != unacked_packets_.end(); ++it) { 512 while (it != unacked_packets_.end()) {
529 if (it->second.retransmittable_frames != NULL) { 513 const RetransmittableFrames* frames = it->second.retransmittable_frames;
514 QuicPacketSequenceNumber sequence_number = it->first;
515 ++it;
516 if (frames != NULL) {
530 packets_retransmitted = true; 517 packets_retransmitted = true;
531 MarkForRetransmission(it->first, RTO_RETRANSMISSION); 518 MarkForRetransmission(sequence_number, RTO_RETRANSMISSION);
532 } else { 519 } else {
533 unacked_packets_.SetNotPending(it->first); 520 unacked_packets_.RemoveFromInFlight(sequence_number);
534 } 521 }
535 } 522 }
536 523
537 send_algorithm_->OnRetransmissionTimeout(packets_retransmitted); 524 send_algorithm_->OnRetransmissionTimeout(packets_retransmitted);
538 if (packets_retransmitted) { 525 if (packets_retransmitted) {
539 ++consecutive_rto_count_; 526 ++consecutive_rto_count_;
540 } 527 }
541 } 528 }
542 529
543 QuicSentPacketManager::RetransmissionTimeoutMode 530 QuicSentPacketManager::RetransmissionTimeoutMode
544 QuicSentPacketManager::GetRetransmissionMode() const { 531 QuicSentPacketManager::GetRetransmissionMode() const {
545 DCHECK(unacked_packets_.HasPendingPackets()); 532 DCHECK(unacked_packets_.HasInFlightPackets());
546 if (unacked_packets_.HasPendingCryptoPackets()) { 533 if (unacked_packets_.HasPendingCryptoPackets()) {
547 return HANDSHAKE_MODE; 534 return HANDSHAKE_MODE;
548 } 535 }
549 if (loss_algorithm_->GetLossTimeout() != QuicTime::Zero()) { 536 if (loss_algorithm_->GetLossTimeout() != QuicTime::Zero()) {
550 return LOSS_MODE; 537 return LOSS_MODE;
551 } 538 }
552 if (consecutive_tlp_count_ < max_tail_loss_probes_) { 539 if (consecutive_tlp_count_ < max_tail_loss_probes_) {
553 if (unacked_packets_.HasUnackedRetransmittableFrames()) { 540 if (unacked_packets_.HasUnackedRetransmittableFrames()) {
554 return TLP_MODE; 541 return TLP_MODE;
555 } 542 }
(...skipping 26 matching lines...) Expand all
582 packets_lost_[sequence_number] = transmission_info; 569 packets_lost_[sequence_number] = transmission_info;
583 DVLOG(1) << ENDPOINT << "Lost packet " << sequence_number; 570 DVLOG(1) << ENDPOINT << "Lost packet " << sequence_number;
584 571
585 if (transmission_info.retransmittable_frames != NULL) { 572 if (transmission_info.retransmittable_frames != NULL) {
586 MarkForRetransmission(sequence_number, LOSS_RETRANSMISSION); 573 MarkForRetransmission(sequence_number, LOSS_RETRANSMISSION);
587 } else { 574 } else {
588 // Since we will not retransmit this, we need to remove it from 575 // Since we will not retransmit this, we need to remove it from
589 // unacked_packets_. This is either the current transmission of 576 // unacked_packets_. This is either the current transmission of
590 // a packet whose previous transmission has been acked, a packet that has 577 // a packet whose previous transmission has been acked, a packet that has
591 // been TLP retransmitted, or an FEC packet. 578 // been TLP retransmitted, or an FEC packet.
592 unacked_packets_.SetNotPending(sequence_number); 579 unacked_packets_.RemoveFromInFlight(sequence_number);
593 if (QuicUnackedPacketMap::IsForRttOnly(transmission_info)) {
594 unacked_packets_.RemoveRttOnlyPacket(sequence_number);
595 }
596 } 580 }
597 } 581 }
598 } 582 }
599 583
600 bool QuicSentPacketManager::MaybeUpdateRTT( 584 bool QuicSentPacketManager::MaybeUpdateRTT(
601 const ReceivedPacketInfo& received_info, 585 const ReceivedPacketInfo& received_info,
602 const QuicTime& ack_receive_time) { 586 const QuicTime& ack_receive_time) {
603 if (!unacked_packets_.IsUnacked(received_info.largest_observed)) { 587 if (!unacked_packets_.IsUnacked(received_info.largest_observed)) {
604 return false; 588 return false;
605 } 589 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 // There may be a value in making this delay adaptive with the help of 626 // There may be a value in making this delay adaptive with the help of
643 // the sender and a signaling mechanism -- if the sender uses a 627 // the sender and a signaling mechanism -- if the sender uses a
644 // different MinRTO, we may get spurious retransmissions. May not have 628 // different MinRTO, we may get spurious retransmissions. May not have
645 // any benefits, but if the delayed ack becomes a significant source 629 // any benefits, but if the delayed ack becomes a significant source
646 // of (likely, tail) latency, then consider such a mechanism. 630 // of (likely, tail) latency, then consider such a mechanism.
647 const QuicTime::Delta QuicSentPacketManager::DelayedAckTime() const { 631 const QuicTime::Delta QuicSentPacketManager::DelayedAckTime() const {
648 return QuicTime::Delta::FromMilliseconds(kMinRetransmissionTimeMs/2); 632 return QuicTime::Delta::FromMilliseconds(kMinRetransmissionTimeMs/2);
649 } 633 }
650 634
651 const QuicTime QuicSentPacketManager::GetRetransmissionTime() const { 635 const QuicTime QuicSentPacketManager::GetRetransmissionTime() const {
652 // Don't set the timer if there are no pending packets. 636 // Don't set the timer if there are no packets in flight.
653 if (!unacked_packets_.HasPendingPackets()) { 637 if (!unacked_packets_.HasInFlightPackets()) {
654 return QuicTime::Zero(); 638 return QuicTime::Zero();
655 } 639 }
656 switch (GetRetransmissionMode()) { 640 switch (GetRetransmissionMode()) {
657 case HANDSHAKE_MODE: 641 case HANDSHAKE_MODE:
658 return clock_->ApproximateNow().Add(GetCryptoRetransmissionDelay()); 642 return clock_->ApproximateNow().Add(GetCryptoRetransmissionDelay());
659 case LOSS_MODE: 643 case LOSS_MODE:
660 return loss_algorithm_->GetLossTimeout(); 644 return loss_algorithm_->GetLossTimeout();
661 case TLP_MODE: { 645 case TLP_MODE: {
662 // TODO(ianswett): When CWND is available, it would be preferable to 646 // TODO(ianswett): When CWND is available, it would be preferable to
663 // set the timer based on the earliest retransmittable packet. 647 // set the timer based on the earliest retransmittable packet.
664 // Base the updated timer on the send time of the last packet. 648 // Base the updated timer on the send time of the last packet.
665 const QuicTime sent_time = unacked_packets_.GetLastPacketSentTime(); 649 const QuicTime sent_time = unacked_packets_.GetLastPacketSentTime();
666 const QuicTime tlp_time = sent_time.Add(GetTailLossProbeDelay()); 650 const QuicTime tlp_time = sent_time.Add(GetTailLossProbeDelay());
667 // Ensure the TLP timer never gets set to a time in the past. 651 // Ensure the TLP timer never gets set to a time in the past.
668 return QuicTime::Max(clock_->ApproximateNow(), tlp_time); 652 return QuicTime::Max(clock_->ApproximateNow(), tlp_time);
669 } 653 }
670 case RTO_MODE: { 654 case RTO_MODE: {
671 // The RTO is based on the first pending packet. 655 // The RTO is based on the first outstanding packet.
672 const QuicTime sent_time = 656 const QuicTime sent_time =
673 unacked_packets_.GetFirstPendingPacketSentTime(); 657 unacked_packets_.GetFirstInFlightPacketSentTime();
674 QuicTime rto_timeout = sent_time.Add(GetRetransmissionDelay()); 658 QuicTime rto_timeout = sent_time.Add(GetRetransmissionDelay());
675 // Always wait at least 1.5 * RTT from now. 659 // Always wait at least 1.5 * RTT from now.
676 QuicTime min_timeout = clock_->ApproximateNow().Add( 660 QuicTime min_timeout = clock_->ApproximateNow().Add(
677 rtt_stats_.SmoothedRtt().Multiply(1.5)); 661 rtt_stats_.SmoothedRtt().Multiply(1.5));
678 662
679 return QuicTime::Max(min_timeout, rto_timeout); 663 return QuicTime::Max(min_timeout, rto_timeout);
680 } 664 }
681 } 665 }
682 DCHECK(false); 666 DCHECK(false);
683 return QuicTime::Zero(); 667 return QuicTime::Zero();
684 } 668 }
685 669
686 const QuicTime::Delta QuicSentPacketManager::GetCryptoRetransmissionDelay() 670 const QuicTime::Delta QuicSentPacketManager::GetCryptoRetransmissionDelay()
687 const { 671 const {
688 // This is equivalent to the TailLossProbeDelay, but slightly more aggressive 672 // This is equivalent to the TailLossProbeDelay, but slightly more aggressive
689 // because crypto handshake messages don't incur a delayed ack time. 673 // because crypto handshake messages don't incur a delayed ack time.
690 int64 delay_ms = max<int64>(kMinHandshakeTimeoutMs, 674 int64 delay_ms = max<int64>(kMinHandshakeTimeoutMs,
691 1.5 * rtt_stats_.SmoothedRtt().ToMilliseconds()); 675 1.5 * rtt_stats_.SmoothedRtt().ToMilliseconds());
692 return QuicTime::Delta::FromMilliseconds( 676 return QuicTime::Delta::FromMilliseconds(
693 delay_ms << consecutive_crypto_retransmission_count_); 677 delay_ms << consecutive_crypto_retransmission_count_);
694 } 678 }
695 679
696 const QuicTime::Delta QuicSentPacketManager::GetTailLossProbeDelay() const { 680 const QuicTime::Delta QuicSentPacketManager::GetTailLossProbeDelay() const {
697 QuicTime::Delta srtt = rtt_stats_.SmoothedRtt(); 681 QuicTime::Delta srtt = rtt_stats_.SmoothedRtt();
698 if (!unacked_packets_.HasMultiplePendingPackets()) { 682 if (!unacked_packets_.HasMultipleInFlightPackets()) {
699 return QuicTime::Delta::Max( 683 return QuicTime::Delta::Max(
700 srtt.Multiply(1.5).Add(DelayedAckTime()), srtt.Multiply(2)); 684 srtt.Multiply(1.5).Add(DelayedAckTime()), srtt.Multiply(2));
701 } 685 }
702 return QuicTime::Delta::FromMilliseconds( 686 return QuicTime::Delta::FromMilliseconds(
703 max(kMinTailLossProbeTimeoutMs, 687 max(kMinTailLossProbeTimeoutMs,
704 static_cast<int64>(2 * srtt.ToMilliseconds()))); 688 static_cast<int64>(2 * srtt.ToMilliseconds())));
705 } 689 }
706 690
707 const QuicTime::Delta QuicSentPacketManager::GetRetransmissionDelay() const { 691 const QuicTime::Delta QuicSentPacketManager::GetRetransmissionDelay() const {
708 QuicTime::Delta retransmission_delay = send_algorithm_->RetransmissionDelay(); 692 QuicTime::Delta retransmission_delay = send_algorithm_->RetransmissionDelay();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 return; 731 return;
748 } 732 }
749 733
750 using_pacing_ = true; 734 using_pacing_ = true;
751 send_algorithm_.reset( 735 send_algorithm_.reset(
752 new PacingSender(send_algorithm_.release(), 736 new PacingSender(send_algorithm_.release(),
753 QuicTime::Delta::FromMicroseconds(1))); 737 QuicTime::Delta::FromMicroseconds(1)));
754 } 738 }
755 739
756 } // namespace net 740 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_sent_packet_manager.h ('k') | net/quic/quic_sent_packet_manager_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698