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

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

Issue 126983002: QUIC Cleanup to remove pending_packets from QuicSentPacketManager and (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 "base/logging.h" 7 #include "base/logging.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "net/quic/congestion_control/pacing_sender.h" 9 #include "net/quic/congestion_control/pacing_sender.h"
10 #include "net/quic/quic_ack_notifier_manager.h" 10 #include "net/quic/quic_ack_notifier_manager.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 void QuicSentPacketManager::OnRetransmittedPacket( 138 void QuicSentPacketManager::OnRetransmittedPacket(
139 QuicPacketSequenceNumber old_sequence_number, 139 QuicPacketSequenceNumber old_sequence_number,
140 QuicPacketSequenceNumber new_sequence_number) { 140 QuicPacketSequenceNumber new_sequence_number) {
141 DCHECK(ContainsKey(unacked_packets_, old_sequence_number)); 141 DCHECK(ContainsKey(unacked_packets_, old_sequence_number));
142 DCHECK(ContainsKey(pending_retransmissions_, old_sequence_number)); 142 DCHECK(ContainsKey(pending_retransmissions_, old_sequence_number));
143 DCHECK(unacked_packets_.empty() || 143 DCHECK(unacked_packets_.empty() ||
144 unacked_packets_.rbegin()->first < new_sequence_number); 144 unacked_packets_.rbegin()->first < new_sequence_number);
145 145
146 pending_retransmissions_.erase(old_sequence_number); 146 pending_retransmissions_.erase(old_sequence_number);
147 // TODO(ianswett): Discard and lose the packet lazily instead of immediately. 147 // TODO(ianswett): Discard and lose the packet lazily instead of immediately.
148
149 UnackedPacketMap::iterator unacked_it = 148 UnackedPacketMap::iterator unacked_it =
150 unacked_packets_.find(old_sequence_number); 149 unacked_packets_.find(old_sequence_number);
151 RetransmittableFrames* frames = unacked_it->second.retransmittable_frames; 150 TransmissionInfo* transmission_info = &unacked_it->second;
151 RetransmittableFrames* frames = transmission_info->retransmittable_frames;
152 DCHECK(frames); 152 DCHECK(frames);
153 153
154 // A notifier may be waiting to hear about ACKs for the original sequence 154 // A notifier may be waiting to hear about ACKs for the original sequence
155 // number. Inform them that the sequence number has changed. 155 // number. Inform them that the sequence number has changed.
156 ack_notifier_manager_.UpdateSequenceNumber(old_sequence_number, 156 ack_notifier_manager_.UpdateSequenceNumber(old_sequence_number,
157 new_sequence_number); 157 new_sequence_number);
158 158
159 // We keep the old packet in the unacked packet list until it, or one of 159 // We keep the old packet in the unacked packet list until it, or one of
160 // the retransmissions of it are acked. 160 // the retransmissions of it are acked.
161 unacked_it->second.retransmittable_frames = NULL; 161 transmission_info->retransmittable_frames = NULL;
162 unacked_packets_[new_sequence_number] = 162 unacked_packets_[new_sequence_number] =
163 TransmissionInfo(frames, GetSequenceNumberLength(old_sequence_number)); 163 TransmissionInfo(frames, transmission_info->sequence_number_length);
164 164
165 // Keep track of all sequence numbers that this packet 165 // Keep track of all sequence numbers that this packet
166 // has been transmitted as. 166 // has been transmitted as.
167 SequenceNumberSet* previous_transmissions = 167 SequenceNumberSet* previous_transmissions =
168 unacked_it->second.previous_transmissions; 168 transmission_info->previous_transmissions;
169 if (previous_transmissions == NULL) { 169 if (previous_transmissions == NULL) {
170 // This is the first retransmission of this packet, so create a new entry. 170 // This is the first retransmission of this packet, so create a new entry.
171 previous_transmissions = new SequenceNumberSet; 171 previous_transmissions = new SequenceNumberSet;
172 unacked_it->second.previous_transmissions = previous_transmissions; 172 transmission_info->previous_transmissions = previous_transmissions;
173 previous_transmissions->insert(old_sequence_number); 173 previous_transmissions->insert(old_sequence_number);
174 } 174 }
175 previous_transmissions->insert(new_sequence_number); 175 previous_transmissions->insert(new_sequence_number);
176 unacked_packets_[new_sequence_number].previous_transmissions = 176 unacked_packets_[new_sequence_number].previous_transmissions =
177 previous_transmissions; 177 previous_transmissions;
178 178
179 DCHECK(HasRetransmittableFrames(new_sequence_number)); 179 DCHECK(HasRetransmittableFrames(new_sequence_number));
180 } 180 }
181 181
182 bool QuicSentPacketManager::OnIncomingAck( 182 bool QuicSentPacketManager::OnIncomingAck(
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 if (sequence_number == newest_transmission) { 269 if (sequence_number == newest_transmission) {
270 break; 270 break;
271 } 271 }
272 272
273 DCHECK(it->second.retransmittable_frames == NULL); 273 DCHECK(it->second.retransmittable_frames == NULL);
274 previous_transmissions->erase(sequence_number); 274 previous_transmissions->erase(sequence_number);
275 if (previous_transmissions->size() == 1) { 275 if (previous_transmissions->size() == 1) {
276 unacked_packets_[newest_transmission].previous_transmissions = NULL; 276 unacked_packets_[newest_transmission].previous_transmissions = NULL;
277 delete previous_transmissions; 277 delete previous_transmissions;
278 } 278 }
279 DCHECK(!ContainsKey(pending_packets_, it->first)); 279 DCHECK(!it->second.pending);
280 unacked_packets_.erase(it++); 280 unacked_packets_.erase(it++);
281 --num_to_clear; 281 --num_to_clear;
282 } 282 }
283 } 283 }
284 284
285 bool QuicSentPacketManager::HasRetransmittableFrames( 285 bool QuicSentPacketManager::HasRetransmittableFrames(
286 QuicPacketSequenceNumber sequence_number) const { 286 QuicPacketSequenceNumber sequence_number) const {
287 UnackedPacketMap::const_iterator it = unacked_packets_.find(sequence_number); 287 UnackedPacketMap::const_iterator it = unacked_packets_.find(sequence_number);
288 if (it == unacked_packets_.end()) { 288 if (it == unacked_packets_.end()) {
289 return false; 289 return false;
290 } 290 }
291 const TransmissionInfo* transmission_info = &it->second; 291 const TransmissionInfo* transmission_info = &it->second;
292 DCHECK(transmission_info); 292 DCHECK(transmission_info);
293 293
294 return transmission_info->retransmittable_frames != NULL; 294 return transmission_info->retransmittable_frames != NULL;
295 } 295 }
296 296
297 void QuicSentPacketManager::RetransmitUnackedPackets( 297 void QuicSentPacketManager::RetransmitUnackedPackets(
298 RetransmissionType retransmission_type) { 298 RetransmissionType retransmission_type) {
299 if (unacked_packets_.empty()) { 299 if (unacked_packets_.empty()) {
300 return; 300 return;
301 } 301 }
302 302
303 for (UnackedPacketMap::const_iterator unacked_it = unacked_packets_.begin(); 303 for (UnackedPacketMap::iterator unacked_it = unacked_packets_.begin();
304 unacked_it != unacked_packets_.end(); ++unacked_it) { 304 unacked_it != unacked_packets_.end(); ++unacked_it) {
305 const RetransmittableFrames* frames = 305 const RetransmittableFrames* frames =
306 unacked_it->second.retransmittable_frames; 306 unacked_it->second.retransmittable_frames;
307 if (frames == NULL) { 307 if (frames == NULL) {
308 continue; 308 continue;
309 } 309 }
310 if (retransmission_type == ALL_PACKETS || 310 if (retransmission_type == ALL_PACKETS ||
311 frames->encryption_level() == ENCRYPTION_INITIAL) { 311 frames->encryption_level() == ENCRYPTION_INITIAL) {
312 // TODO(satyamshekhar): Think about congestion control here. 312 // TODO(satyamshekhar): Think about congestion control here.
313 // Specifically, about the retransmission count of packets being sent 313 // Specifically, about the retransmission count of packets being sent
314 // proactively to achieve 0 (minimal) RTT. 314 // proactively to achieve 0 (minimal) RTT.
315 if (unacked_it->second.retransmittable_frames) { 315 if (unacked_it->second.retransmittable_frames) {
316 OnPacketAbandoned(unacked_it->first); 316 OnPacketAbandoned(unacked_it);
317 MarkForRetransmission(unacked_it->first, NACK_RETRANSMISSION); 317 MarkForRetransmission(unacked_it->first, NACK_RETRANSMISSION);
318 } else { 318 } else {
319 DiscardUnackedPacket(unacked_it->first); 319 DiscardUnackedPacket(unacked_it->first);
320 } 320 }
321 } 321 }
322 } 322 }
323 } 323 }
324 324
325 void QuicSentPacketManager::MarkForRetransmission( 325 void QuicSentPacketManager::MarkForRetransmission(
326 QuicPacketSequenceNumber sequence_number, 326 QuicPacketSequenceNumber sequence_number,
(...skipping 12 matching lines...) Expand all
339 bool QuicSentPacketManager::HasPendingRetransmissions() const { 339 bool QuicSentPacketManager::HasPendingRetransmissions() const {
340 return !pending_retransmissions_.empty(); 340 return !pending_retransmissions_.empty();
341 } 341 }
342 342
343 QuicSentPacketManager::PendingRetransmission 343 QuicSentPacketManager::PendingRetransmission
344 QuicSentPacketManager::NextPendingRetransmission() { 344 QuicSentPacketManager::NextPendingRetransmission() {
345 DCHECK(!pending_retransmissions_.empty()); 345 DCHECK(!pending_retransmissions_.empty());
346 QuicPacketSequenceNumber sequence_number = 346 QuicPacketSequenceNumber sequence_number =
347 pending_retransmissions_.begin()->first; 347 pending_retransmissions_.begin()->first;
348 DCHECK(ContainsKey(unacked_packets_, sequence_number)); 348 DCHECK(ContainsKey(unacked_packets_, sequence_number));
349 const RetransmittableFrames* retransmittable_frames = 349 UnackedPacketMap::iterator unacked_it =
350 unacked_packets_[sequence_number].retransmittable_frames; 350 unacked_packets_.find(sequence_number);
351 DCHECK(retransmittable_frames); 351 CHECK(unacked_it != unacked_packets_.end());
352 const TransmissionInfo& transmission_info = unacked_it->second;
353 DCHECK(transmission_info.retransmittable_frames);
352 354
353 return PendingRetransmission(sequence_number, 355 return PendingRetransmission(sequence_number,
354 pending_retransmissions_.begin()->second, 356 pending_retransmissions_.begin()->second,
355 *retransmittable_frames, 357 *transmission_info.retransmittable_frames,
356 GetSequenceNumberLength(sequence_number)); 358 transmission_info.sequence_number_length);
357 } 359 }
358 360
359 bool QuicSentPacketManager::IsPreviousTransmission( 361 bool QuicSentPacketManager::IsPreviousTransmission(
360 QuicPacketSequenceNumber sequence_number) const { 362 QuicPacketSequenceNumber sequence_number) const {
361 DCHECK(ContainsKey(unacked_packets_, sequence_number)); 363 DCHECK(ContainsKey(unacked_packets_, sequence_number));
362 364
363 UnackedPacketMap::const_iterator it = unacked_packets_.find(sequence_number); 365 UnackedPacketMap::const_iterator unacked_it =
364 if (it->second.previous_transmissions == NULL) { 366 unacked_packets_.find(sequence_number);
367 if (unacked_it == unacked_packets_.end()) {
368 return false;
369 }
370 const TransmissionInfo* transmission_info = &unacked_it->second;
371 if (transmission_info->previous_transmissions == NULL) {
365 return false; 372 return false;
366 } 373 }
367 374
368 SequenceNumberSet* previous_transmissions = it->second.previous_transmissions; 375 SequenceNumberSet* previous_transmissions =
376 transmission_info->previous_transmissions;
369 DCHECK(!previous_transmissions->empty()); 377 DCHECK(!previous_transmissions->empty());
370 return *previous_transmissions->rbegin() != sequence_number; 378 return *previous_transmissions->rbegin() != sequence_number;
371 } 379 }
372 380
373 // static 381 // static
374 bool QuicSentPacketManager::HasCryptoHandshake( 382 bool QuicSentPacketManager::HasCryptoHandshake(
375 const TransmissionInfo& transmission_info) { 383 const TransmissionInfo& transmission_info) {
376 if (transmission_info.retransmittable_frames == NULL) { 384 if (transmission_info.retransmittable_frames == NULL) {
377 return false; 385 return false;
378 } 386 }
379 return transmission_info.retransmittable_frames->HasCryptoHandshake() == 387 return transmission_info.retransmittable_frames->HasCryptoHandshake() ==
380 IS_HANDSHAKE; 388 IS_HANDSHAKE;
381 } 389 }
382 390
383 QuicSentPacketManager::UnackedPacketMap::iterator 391 QuicSentPacketManager::UnackedPacketMap::iterator
384 QuicSentPacketManager::MarkPacketHandled( 392 QuicSentPacketManager::MarkPacketHandled(
385 QuicPacketSequenceNumber sequence_number, ReceivedByPeer received_by_peer) { 393 QuicPacketSequenceNumber sequence_number, ReceivedByPeer received_by_peer) {
386 DCHECK(ContainsKey(unacked_packets_, sequence_number)); 394 DCHECK(ContainsKey(unacked_packets_, sequence_number));
387 395
388 // If this packet is pending, remove it and inform the send algorithm. 396 // If this packet is pending, remove it and inform the send algorithm.
389 if (pending_packets_.erase(sequence_number)) { 397 UnackedPacketMap::iterator it = unacked_packets_.find(sequence_number);
398 if (it->second.pending) {
390 size_t bytes_sent = packet_history_map_[sequence_number]->bytes_sent(); 399 size_t bytes_sent = packet_history_map_[sequence_number]->bytes_sent();
391 if (received_by_peer == RECEIVED_BY_PEER) { 400 if (received_by_peer == RECEIVED_BY_PEER) {
392 send_algorithm_->OnPacketAcked(sequence_number, bytes_sent, rtt_sample_); 401 send_algorithm_->OnPacketAcked(sequence_number, bytes_sent, rtt_sample_);
393 } else { 402 } else {
394 // It's been abandoned. 403 // It's been abandoned.
395 send_algorithm_->OnPacketAbandoned(sequence_number, bytes_sent); 404 send_algorithm_->OnPacketAbandoned(sequence_number, bytes_sent);
396 } 405 }
406 it->second.pending = false;
397 } 407 }
398 408
399 // If this packet has never been retransmitted, then simply drop it. 409 // If this packet has never been retransmitted, then simply drop it.
400 UnackedPacketMap::iterator previous_it = 410 if (it->second.previous_transmissions == NULL) {
401 unacked_packets_.find(sequence_number); 411 ++it;
402 if (previous_it->second.previous_transmissions == NULL) {
403 ++previous_it;
404 DiscardPacket(sequence_number); 412 DiscardPacket(sequence_number);
405 return previous_it; 413 return it;
406 } 414 }
407 415
408 SequenceNumberSet* previous_transmissions = 416 SequenceNumberSet* previous_transmissions = it->second.previous_transmissions;
409 previous_it->second.previous_transmissions;
410 DCHECK(!previous_transmissions->empty()); 417 DCHECK(!previous_transmissions->empty());
411 SequenceNumberSet::reverse_iterator previous_transmissions_it = 418 SequenceNumberSet::reverse_iterator previous_transmissions_it =
412 previous_transmissions->rbegin(); 419 previous_transmissions->rbegin();
413 QuicPacketSequenceNumber newest_transmission = *previous_transmissions_it; 420 QuicPacketSequenceNumber newest_transmission = *previous_transmissions_it;
414 if (newest_transmission == sequence_number) { 421 if (newest_transmission == sequence_number) {
415 DiscardPacket(newest_transmission); 422 DiscardPacket(newest_transmission);
416 } else { 423 } else {
417 UnackedPacketMap::iterator newest_it = 424 UnackedPacketMap::iterator unacked_it =
418 unacked_packets_.find(newest_transmission); 425 unacked_packets_.find(newest_transmission);
419 if (HasCryptoHandshake(newest_it->second)) { 426 TransmissionInfo* transmission_info = &unacked_it->second;
427 if (HasCryptoHandshake(*transmission_info)) {
420 --pending_crypto_packet_count_; 428 --pending_crypto_packet_count_;
421 } 429 }
422 // If we have received an ack for a previous transmission of a packet, 430 // If we have received an ack for a previous transmission of a packet,
423 // we want to keep the "new" transmission of the packet unacked, 431 // we want to keep the "new" transmission of the packet unacked,
424 // but prevent the data from being retransmitted. 432 // but prevent the data from being retransmitted.
425 delete newest_it->second.retransmittable_frames; 433 delete transmission_info->retransmittable_frames;
426 newest_it->second.retransmittable_frames = NULL; 434 transmission_info->retransmittable_frames = NULL;
427 newest_it->second.previous_transmissions = NULL; 435 transmission_info->previous_transmissions = NULL;
428 } 436 }
429 437
430 // Clear out information all previous transmissions. 438 // Clear out information all previous transmissions.
431 ++previous_transmissions_it; 439 ++previous_transmissions_it;
432 while (previous_transmissions_it != previous_transmissions->rend()) { 440 while (previous_transmissions_it != previous_transmissions->rend()) {
433 QuicPacketSequenceNumber previous_transmission = *previous_transmissions_it; 441 QuicPacketSequenceNumber previous_transmission = *previous_transmissions_it;
434 ++previous_transmissions_it; 442 ++previous_transmissions_it;
435 // If the packet was TLP retransmitted, the old copy was not yet considered 443 // If the packet was TLP retransmitted, the old copy was not yet considered
436 // lost or abandoned, so do that now. 444 // lost or abandoned, so do that now.
437 if (ContainsKey(pending_packets_, previous_transmission)) { 445 if (unacked_packets_[previous_transmission].pending) {
438 send_algorithm_->OnPacketLost(previous_transmission, clock_->Now()); 446 send_algorithm_->OnPacketLost(previous_transmission, clock_->Now());
439 OnPacketAbandoned(previous_transmission); 447 OnPacketAbandoned(unacked_packets_.find(previous_transmission));
440 } 448 }
441 DiscardPacket(previous_transmission); 449 DiscardPacket(previous_transmission);
442 } 450 }
443 451
444 delete previous_transmissions; 452 delete previous_transmissions;
445 453
446 if (ContainsKey(pending_retransmissions_, newest_transmission)) { 454 if (ContainsKey(pending_retransmissions_, newest_transmission)) {
447 pending_retransmissions_.erase(newest_transmission); 455 pending_retransmissions_.erase(newest_transmission);
448 if (!ContainsKey(pending_packets_, newest_transmission)) { 456 if (!unacked_packets_[newest_transmission].pending) {
449 // If the newest transmission has already been marked for retransmission 457 // If the newest transmission has already been marked for retransmission
450 // and has already been abandoned, then we should remove it from 458 // and has already been abandoned, then we should remove it from
451 // unacked_packets_, as well as cancel the retransmission. 459 // unacked_packets_, as well as cancel the retransmission.
452 DCHECK(ContainsKey(unacked_packets_, newest_transmission)); 460 DCHECK(ContainsKey(unacked_packets_, newest_transmission));
453 DCHECK(!unacked_packets_[newest_transmission].previous_transmissions); 461 DCHECK(!unacked_packets_[newest_transmission].previous_transmissions);
454 unacked_packets_.erase(newest_transmission); 462 unacked_packets_.erase(newest_transmission);
455 } 463 }
456 } 464 }
457 465
458 UnackedPacketMap::iterator next_unacked = unacked_packets_.begin(); 466 UnackedPacketMap::iterator next_unacked = unacked_packets_.begin();
459 while (next_unacked != unacked_packets_.end() && 467 while (next_unacked != unacked_packets_.end() &&
460 next_unacked->first < sequence_number) { 468 next_unacked->first < sequence_number) {
461 ++next_unacked; 469 ++next_unacked;
462 } 470 }
463 return next_unacked; 471 return next_unacked;
464 } 472 }
465 473
466 void QuicSentPacketManager::DiscardPacket( 474 void QuicSentPacketManager::DiscardPacket(
467 QuicPacketSequenceNumber sequence_number) { 475 QuicPacketSequenceNumber sequence_number) {
468 UnackedPacketMap::iterator unacked_it = 476 UnackedPacketMap::iterator unacked_it =
469 unacked_packets_.find(sequence_number); 477 unacked_packets_.find(sequence_number);
470 DCHECK(unacked_it != unacked_packets_.end()); 478 DCHECK(unacked_it != unacked_packets_.end());
471 // Ensure the packet is no longer pending when it's discarded. 479 // Ensure the packet is no longer pending when it's discarded.
472 DCHECK(!ContainsKey(pending_packets_, sequence_number)); 480 DCHECK(!unacked_it->second.pending);
473 481
474 RetransmittableFrames* retransmittable_frames = 482 RetransmittableFrames* retransmittable_frames =
475 unacked_it->second.retransmittable_frames; 483 unacked_it->second.retransmittable_frames;
476 if (HasCryptoHandshake(unacked_it->second)) { 484 if (HasCryptoHandshake(unacked_it->second)) {
477 --pending_crypto_packet_count_; 485 --pending_crypto_packet_count_;
478 } 486 }
479 487
480 // Delete the retransmittable frames. 488 // Delete the retransmittable frames.
481 delete retransmittable_frames; 489 delete retransmittable_frames;
482 unacked_packets_.erase(unacked_it); 490 unacked_packets_.erase(unacked_it);
483 pending_retransmissions_.erase(sequence_number); 491 pending_retransmissions_.erase(sequence_number);
484 return; 492 return;
485 } 493 }
486 494
487 bool QuicSentPacketManager::IsUnacked( 495 bool QuicSentPacketManager::IsUnacked(
488 QuicPacketSequenceNumber sequence_number) const { 496 QuicPacketSequenceNumber sequence_number) const {
489 return ContainsKey(unacked_packets_, sequence_number); 497 return ContainsKey(unacked_packets_, sequence_number);
490 } 498 }
491 499
492 QuicSequenceNumberLength QuicSentPacketManager::GetSequenceNumberLength(
493 QuicPacketSequenceNumber sequence_number) const {
494 DCHECK(ContainsKey(unacked_packets_, sequence_number));
495
496 return unacked_packets_.find(sequence_number)->second.sequence_number_length;
497 }
498
499 bool QuicSentPacketManager::HasUnackedPackets() const { 500 bool QuicSentPacketManager::HasUnackedPackets() const {
500 return !unacked_packets_.empty(); 501 return !unacked_packets_.empty();
501 } 502 }
502 503
504 bool QuicSentPacketManager::HasPendingPackets() const {
505 for (UnackedPacketMap::const_reverse_iterator it =
506 unacked_packets_.rbegin(); it != unacked_packets_.rend(); ++it) {
507 if (it->second.pending) {
508 return true;
509 }
510 }
511 return false;
512 }
513
503 size_t QuicSentPacketManager::GetNumRetransmittablePackets() const { 514 size_t QuicSentPacketManager::GetNumRetransmittablePackets() const {
504 size_t num_unacked_packets = 0; 515 size_t num_unacked_packets = 0;
505 for (UnackedPacketMap::const_iterator it = unacked_packets_.begin(); 516 for (UnackedPacketMap::const_iterator it = unacked_packets_.begin();
506 it != unacked_packets_.end(); ++it) { 517 it != unacked_packets_.end(); ++it) {
507 QuicPacketSequenceNumber sequence_number = it->first; 518 QuicPacketSequenceNumber sequence_number = it->first;
508 if (HasRetransmittableFrames(sequence_number)) { 519 if (HasRetransmittableFrames(sequence_number)) {
509 ++num_unacked_packets; 520 ++num_unacked_packets;
510 } 521 }
511 } 522 }
512 return num_unacked_packets; 523 return num_unacked_packets;
(...skipping 19 matching lines...) Expand all
532 return unacked_packets; 543 return unacked_packets;
533 } 544 }
534 545
535 bool QuicSentPacketManager::OnPacketSent( 546 bool QuicSentPacketManager::OnPacketSent(
536 QuicPacketSequenceNumber sequence_number, 547 QuicPacketSequenceNumber sequence_number,
537 QuicTime sent_time, 548 QuicTime sent_time,
538 QuicByteCount bytes, 549 QuicByteCount bytes,
539 TransmissionType transmission_type, 550 TransmissionType transmission_type,
540 HasRetransmittableData has_retransmittable_data) { 551 HasRetransmittableData has_retransmittable_data) {
541 DCHECK_LT(0u, sequence_number); 552 DCHECK_LT(0u, sequence_number);
542 DCHECK(!ContainsKey(pending_packets_, sequence_number));
543 DCHECK(ContainsKey(unacked_packets_, sequence_number)); 553 DCHECK(ContainsKey(unacked_packets_, sequence_number));
554 DCHECK(!unacked_packets_[sequence_number].pending);
544 if (has_retransmittable_data == HAS_RETRANSMITTABLE_DATA) { 555 if (has_retransmittable_data == HAS_RETRANSMITTABLE_DATA) {
545 DCHECK(unacked_packets_[sequence_number].retransmittable_frames); 556 DCHECK(unacked_packets_[sequence_number].retransmittable_frames);
546 } 557 }
558 UnackedPacketMap::iterator it = unacked_packets_.find(sequence_number);
547 559
548 // Only track packets the send algorithm wants us to track. 560 // Only track packets the send algorithm wants us to track.
549 if (!send_algorithm_->OnPacketSent(sent_time, sequence_number, bytes, 561 if (!send_algorithm_->OnPacketSent(sent_time, sequence_number, bytes,
550 transmission_type, 562 transmission_type,
551 has_retransmittable_data)) { 563 has_retransmittable_data)) {
552 DCHECK(unacked_packets_[sequence_number].retransmittable_frames == NULL); 564 DCHECK(it->second.retransmittable_frames == NULL);
553 unacked_packets_.erase(sequence_number); 565 unacked_packets_.erase(it);
554 // Do not reset the retransmission timer, since the packet isn't tracked. 566 // Do not reset the retransmission timer, since the packet isn't tracked.
555 return false; 567 return false;
556 } 568 }
557 569
558 // Set the retransmission timer for the first pending packet. 570 const bool set_retransmission_timer = !HasPendingPackets();
559 const bool set_retransmission_timer = pending_packets_.empty(); 571 it->second.sent_time = sent_time;
560 unacked_packets_[sequence_number].sent_time = sent_time; 572 it->second.pending = true;
561 packet_history_map_[sequence_number] = 573 packet_history_map_[sequence_number] =
562 new SendAlgorithmInterface::SentPacket(bytes, sent_time); 574 new SendAlgorithmInterface::SentPacket(bytes, sent_time);
563 pending_packets_.insert(sequence_number);
564 CleanupPacketHistory(); 575 CleanupPacketHistory();
565 576
566 // Reset the retransmission timer anytime a packet is sent in tail loss probe 577 // Reset the retransmission timer anytime a packet is sent in tail loss probe
567 // mode or before the crypto handshake has completed. 578 // mode or before the crypto handshake has completed.
568 return GetRetransmissionMode() != RTO_MODE || set_retransmission_timer; 579 return set_retransmission_timer || GetRetransmissionMode() != RTO_MODE;
569 } 580 }
570 581
571 void QuicSentPacketManager::OnRetransmissionTimeout() { 582 void QuicSentPacketManager::OnRetransmissionTimeout() {
572 DCHECK(!pending_packets_.empty()); 583 DCHECK(HasPendingPackets());
573 // Handshake retransmission, TLP, and RTO are implemented with a single alarm. 584 // Handshake retransmission, TLP, and RTO are implemented with a single alarm.
574 // The handshake alarm is set when the handshake has not completed, and the 585 // The handshake alarm is set when the handshake has not completed, and the
575 // TLP and RTO alarms are set after that. 586 // TLP and RTO alarms are set after that.
576 // The TLP alarm is always set to run for under an RTO. 587 // The TLP alarm is always set to run for under an RTO.
577 switch (GetRetransmissionMode()) { 588 switch (GetRetransmissionMode()) {
578 case HANDSHAKE_MODE: 589 case HANDSHAKE_MODE:
579 RetransmitCryptoPackets(); 590 RetransmitCryptoPackets();
580 return; 591 return;
581 case TLP_MODE: 592 case TLP_MODE:
582 // If no tail loss probe can be sent, because there are no retransmittable 593 // If no tail loss probe can be sent, because there are no retransmittable
583 // packets, execute a conventional RTO to abandon old packets. 594 // packets, execute a conventional RTO to abandon old packets.
584 RetransmitOldestPacket(); 595 RetransmitOldestPacket();
585 return; 596 return;
586 case RTO_MODE: 597 case RTO_MODE:
587 RetransmitAllPackets(); 598 RetransmitAllPackets();
588 return; 599 return;
589 } 600 }
590 } 601 }
591 602
592 void QuicSentPacketManager::RetransmitCryptoPackets() { 603 void QuicSentPacketManager::RetransmitCryptoPackets() {
593 DCHECK_EQ(HANDSHAKE_MODE, GetRetransmissionMode()); 604 DCHECK_EQ(HANDSHAKE_MODE, GetRetransmissionMode());
594 // TODO(ianswett): Typical TCP implementations only retransmit 5 times. 605 // TODO(ianswett): Typical TCP implementations only retransmit 5 times.
595 consecutive_crypto_retransmission_count_ = 606 consecutive_crypto_retransmission_count_ =
596 min(kMaxHandshakeRetransmissionBackoffs, 607 min(kMaxHandshakeRetransmissionBackoffs,
597 consecutive_crypto_retransmission_count_ + 1); 608 consecutive_crypto_retransmission_count_ + 1);
598 bool packet_retransmitted = false; 609 bool packet_retransmitted = false;
599 for (SequenceNumberSet::iterator it = pending_packets_.begin(); 610 for (UnackedPacketMap::iterator it = unacked_packets_.begin();
600 it != pending_packets_.end(); ) { 611 it != unacked_packets_.end(); ++it) {
601 QuicPacketSequenceNumber sequence_number = *it; 612 QuicPacketSequenceNumber sequence_number = it->first;
602 DCHECK(ContainsKey(packet_history_map_, sequence_number)); 613 DCHECK(ContainsKey(packet_history_map_, sequence_number));
603 DCHECK(ContainsKey(unacked_packets_, sequence_number)); 614 const RetransmittableFrames* frames = it->second.retransmittable_frames;
604 const RetransmittableFrames* frames =
605 unacked_packets_[sequence_number].retransmittable_frames;
606 if (frames == NULL || frames->HasCryptoHandshake() != IS_HANDSHAKE) { 615 if (frames == NULL || frames->HasCryptoHandshake() != IS_HANDSHAKE) {
607 ++it;
608 continue; 616 continue;
609 } 617 }
610 packet_retransmitted = true; 618 packet_retransmitted = true;
611 MarkForRetransmission(sequence_number, TLP_RETRANSMISSION); 619 MarkForRetransmission(sequence_number, TLP_RETRANSMISSION);
612 // Abandon all the crypto retransmissions now so they're not lost later. 620 // Abandon all the crypto retransmissions now so they're not lost later.
613 send_algorithm_->OnPacketAbandoned( 621 OnPacketAbandoned(it);
614 sequence_number, packet_history_map_[sequence_number]->bytes_sent());
615 pending_packets_.erase(it++);
616 } 622 }
617 DCHECK(packet_retransmitted) << "No crypto packets found to retransmit."; 623 DCHECK(packet_retransmitted) << "No crypto packets found to retransmit.";
618 } 624 }
619 625
620 void QuicSentPacketManager::RetransmitOldestPacket() { 626 void QuicSentPacketManager::RetransmitOldestPacket() {
621 DCHECK_EQ(TLP_MODE, GetRetransmissionMode()); 627 DCHECK_EQ(TLP_MODE, GetRetransmissionMode());
622 ++consecutive_tlp_count_; 628 ++consecutive_tlp_count_;
623 for (SequenceNumberSet::const_iterator it = pending_packets_.begin(); 629 for (UnackedPacketMap::const_iterator it = unacked_packets_.begin();
624 it != pending_packets_.end(); ++it) { 630 it != unacked_packets_.end(); ++it) {
625 QuicPacketSequenceNumber sequence_number = *it; 631 QuicPacketSequenceNumber sequence_number = it->first;
626 DCHECK(ContainsKey(unacked_packets_, sequence_number)); 632 const RetransmittableFrames* frames = it->second.retransmittable_frames;
627 const RetransmittableFrames* frames =
628 unacked_packets_[sequence_number].retransmittable_frames;
629 if (frames == NULL) { 633 if (frames == NULL) {
630 continue; 634 continue;
631 } 635 }
632 DCHECK_NE(IS_HANDSHAKE, frames->HasCryptoHandshake()); 636 DCHECK_NE(IS_HANDSHAKE, frames->HasCryptoHandshake());
633 MarkForRetransmission(sequence_number, TLP_RETRANSMISSION); 637 MarkForRetransmission(sequence_number, TLP_RETRANSMISSION);
634 return; 638 return;
635 } 639 }
636 DLOG(FATAL) 640 DLOG(FATAL)
637 << "No retransmittable packets, so RetransmitOldestPacket failed."; 641 << "No retransmittable packets, so RetransmitOldestPacket failed.";
638 } 642 }
639 643
640 void QuicSentPacketManager::RetransmitAllPackets() { 644 void QuicSentPacketManager::RetransmitAllPackets() {
641 // Abandon all retransmittable packets and packets older than the 645 // Abandon all retransmittable packets and packets older than the
642 // retransmission delay. 646 // retransmission delay.
643 647
644 DVLOG(1) << "OnRetransmissionTimeout() fired with " 648 DVLOG(1) << "OnRetransmissionTimeout() fired with "
645 << unacked_packets_.size() << " unacked packets."; 649 << unacked_packets_.size() << " unacked packets.";
646 650
647 // Request retransmission of all retransmittable packets when the RTO 651 // Request retransmission of all retransmittable packets when the RTO
648 // fires, and let the congestion manager decide how many to send 652 // fires, and let the congestion manager decide how many to send
649 // immediately and the remaining packets will be queued. 653 // immediately and the remaining packets will be queued.
650 // Abandon any non-retransmittable packets that are sufficiently old. 654 // Abandon any non-retransmittable packets that are sufficiently old.
651 bool packets_retransmitted = false; 655 bool packets_retransmitted = false;
652 for (UnackedPacketMap::const_iterator it = unacked_packets_.begin(); 656 for (UnackedPacketMap::iterator it = unacked_packets_.begin();
653 it != unacked_packets_.end(); ++it) { 657 it != unacked_packets_.end(); ++it) {
658 it->second.pending = false;
654 if (it->second.retransmittable_frames != NULL) { 659 if (it->second.retransmittable_frames != NULL) {
655 packets_retransmitted = true; 660 packets_retransmitted = true;
656 MarkForRetransmission(it->first, RTO_RETRANSMISSION); 661 MarkForRetransmission(it->first, RTO_RETRANSMISSION);
657 } 662 }
658 } 663 }
659 664
660 pending_packets_.clear();
661 send_algorithm_->OnRetransmissionTimeout(packets_retransmitted); 665 send_algorithm_->OnRetransmissionTimeout(packets_retransmitted);
662 if (packets_retransmitted) { 666 if (packets_retransmitted) {
663 ++consecutive_rto_count_; 667 ++consecutive_rto_count_;
664 } 668 }
665 } 669 }
666 670
667 QuicSentPacketManager::RetransmissionTimeoutMode 671 QuicSentPacketManager::RetransmissionTimeoutMode
668 QuicSentPacketManager::GetRetransmissionMode() const { 672 QuicSentPacketManager::GetRetransmissionMode() const {
669 DCHECK(!pending_packets_.empty()); 673 DCHECK(HasPendingPackets());
670 if (pending_crypto_packet_count_ > 0) { 674 if (pending_crypto_packet_count_ > 0) {
671 return HANDSHAKE_MODE; 675 return HANDSHAKE_MODE;
672 } 676 }
673 if (consecutive_tlp_count_ < max_tail_loss_probes_) { 677 if (consecutive_tlp_count_ < max_tail_loss_probes_) {
674 // Ensure there are retransmittable frames. 678 // Ensure there are retransmittable frames.
675 for (SequenceNumberSet::const_iterator it = pending_packets_.begin(); 679 for (UnackedPacketMap::const_reverse_iterator it =
676 it != pending_packets_.end(); ++it) { 680 unacked_packets_.rbegin(); it != unacked_packets_.rend(); ++it) {
677 if (HasRetransmittableFrames(*it)) { 681 if (it->second.pending && it->second.retransmittable_frames) {
678 return TLP_MODE; 682 return TLP_MODE;
679 } 683 }
680 } 684 }
681 } 685 }
682 return RTO_MODE; 686 return RTO_MODE;
683 } 687 }
684 688
685 void QuicSentPacketManager::OnPacketAbandoned( 689 void QuicSentPacketManager::OnPacketAbandoned(UnackedPacketMap::iterator it) {
686 QuicPacketSequenceNumber sequence_number) { 690 DCHECK(it != unacked_packets_.end());
687 SequenceNumberSet::iterator it = pending_packets_.find(sequence_number); 691 QuicPacketSequenceNumber sequence_number = it->first;
688 if (it != pending_packets_.end()) { 692 DCHECK(ContainsKey(packet_history_map_, sequence_number));
689 DCHECK(ContainsKey(packet_history_map_, sequence_number)); 693 if (it->second.pending) {
690 send_algorithm_->OnPacketAbandoned( 694 send_algorithm_->OnPacketAbandoned(
691 sequence_number, packet_history_map_[sequence_number]->bytes_sent()); 695 sequence_number, packet_history_map_[sequence_number]->bytes_sent());
692 pending_packets_.erase(it); 696 it->second.pending = false;
693 } 697 }
694 } 698 }
695 699
696 void QuicSentPacketManager::OnIncomingQuicCongestionFeedbackFrame( 700 void QuicSentPacketManager::OnIncomingQuicCongestionFeedbackFrame(
697 const QuicCongestionFeedbackFrame& frame, 701 const QuicCongestionFeedbackFrame& frame,
698 const QuicTime& feedback_receive_time) { 702 const QuicTime& feedback_receive_time) {
699 send_algorithm_->OnIncomingQuicCongestionFeedbackFrame( 703 send_algorithm_->OnIncomingQuicCongestionFeedbackFrame(
700 frame, feedback_receive_time, packet_history_map_); 704 frame, feedback_receive_time, packet_history_map_);
701 } 705 }
702 706
703 void QuicSentPacketManager::MaybeRetransmitOnAckFrame( 707 void QuicSentPacketManager::MaybeRetransmitOnAckFrame(
704 const ReceivedPacketInfo& received_info, 708 const ReceivedPacketInfo& received_info,
705 const QuicTime& ack_receive_time) { 709 const QuicTime& ack_receive_time) {
706 // Go through all pending packets up to the largest observed and see if any 710 // Go through all pending packets up to the largest observed and see if any
707 // need to be retransmitted or lost. 711 // need to be retransmitted or lost.
708 SequenceNumberSet::iterator it = pending_packets_.begin();
709 SequenceNumberSet::iterator it_upper =
710 pending_packets_.upper_bound(received_info.largest_observed);
711
712 size_t num_retransmitted = 0; 712 size_t num_retransmitted = 0;
713 SequenceNumberSet lost_packets; 713 UnackedPacketMap::iterator it = unacked_packets_.begin();
714 while (it != it_upper) { 714 while (it != unacked_packets_.end() &&
715 QuicPacketSequenceNumber sequence_number = *it; 715 it->first <= received_info.largest_observed) {
716 if (!it->second.pending) {
717 ++it;
718 continue;
719 }
720 QuicPacketSequenceNumber sequence_number = it->first;
716 DVLOG(1) << "still missing packet " << sequence_number; 721 DVLOG(1) << "still missing packet " << sequence_number;
717 // Acks must be handled previously, so ensure it's missing and not acked. 722 // Acks must be handled previously, so ensure it's missing and not acked.
718 DCHECK(IsAwaitingPacket(received_info, sequence_number)); 723 DCHECK(IsAwaitingPacket(received_info, sequence_number));
719 DCHECK(ContainsKey(packet_history_map_, sequence_number)); 724 DCHECK(ContainsKey(packet_history_map_, sequence_number));
725 const TransmissionInfo& transmission_info = it->second;
720 const SendAlgorithmInterface::SentPacket* sent_packet = 726 const SendAlgorithmInterface::SentPacket* sent_packet =
721 packet_history_map_[sequence_number]; 727 packet_history_map_[sequence_number];
722 const TransmissionInfo& transmission_info =
723 unacked_packets_[sequence_number];
724 728
725 // Consider it multiple nacks when there is a gap between the missing packet 729 // Consider it multiple nacks when there is a gap between the missing packet
726 // and the largest observed, since the purpose of a nack threshold is to 730 // and the largest observed, since the purpose of a nack threshold is to
727 // tolerate re-ordering. This handles both StretchAcks and Forward Acks. 731 // tolerate re-ordering. This handles both StretchAcks and Forward Acks.
728 // TODO(ianswett): This relies heavily on sequential reception of packets, 732 // TODO(ianswett): This relies heavily on sequential reception of packets,
729 // and makes an assumption that the congestion control uses TCP style nacks. 733 // and makes an assumption that the congestion control uses TCP style nacks.
730 size_t min_nacks = received_info.largest_observed - sequence_number; 734 size_t min_nacks = received_info.largest_observed - sequence_number;
731 packet_history_map_[sequence_number]->Nack(min_nacks); 735 packet_history_map_[sequence_number]->Nack(min_nacks);
732 736
733 size_t num_nacks_needed = kNumberOfNacksBeforeRetransmission; 737 size_t num_nacks_needed = kNumberOfNacksBeforeRetransmission;
734 // Check for early retransmit(RFC5827) when the last packet gets acked and 738 // Check for early retransmit(RFC5827) when the last packet gets acked and
735 // the there are fewer than 4 pending packets. 739 // the there are fewer than 4 pending packets.
736 // TODO(ianswett): Consider setting a retransmission timer instead of 740 // TODO(ianswett): Set a retransmission timer instead of losing the packet
737 // losing the packet and retransmitting immediately. Also consider only 741 // and retransmitting immediately. Also consider only invoking OnPacketLost
738 // invoking OnPacketLost and OnPacketAbandoned when they're actually 742 // and OnPacketAbandoned when they're actually retransmitted in case they
739 // retransmitted in case they arrive while queued. 743 // arrive while queued for retransmission.
740 if (pending_packets_.size() <= kNumberOfNacksBeforeRetransmission && 744 if (transmission_info.retransmittable_frames &&
741 transmission_info.retransmittable_frames &&
742 packet_history_map_.rbegin()->first == received_info.largest_observed) { 745 packet_history_map_.rbegin()->first == received_info.largest_observed) {
743 num_nacks_needed = received_info.largest_observed - sequence_number; 746 num_nacks_needed = received_info.largest_observed - sequence_number;
744 } 747 }
745 748
746 if (sent_packet->nack_count() < num_nacks_needed) { 749 if (sent_packet->nack_count() < num_nacks_needed) {
747 ++it; 750 ++it;
748 continue; 751 continue;
749 } 752 }
750 753
751 // If the number of retransmissions has maxed out, don't lose or retransmit 754 // If the number of retransmissions has maxed out, don't lose or retransmit
752 // any more packets. 755 // any more packets.
753 if (num_retransmitted >= kMaxRetransmissionsPerAck) { 756 if (num_retransmitted >= kMaxRetransmissionsPerAck) {
754 ++it; 757 ++it;
755 continue; 758 continue;
756 } 759 }
757 760
758 lost_packets.insert(sequence_number); 761 // TODO(ianswett): OnPacketLost is also called from TCPCubicSender when
762 // an FEC packet is lost, but FEC loss information should be shared among
763 // congestion managers. Additionally, if it's expected the FEC packet may
764 // repair the loss, it should be recorded as a loss to the congestion
765 // manager, but not retransmitted until it's known whether the FEC packet
766 // arrived.
767 send_algorithm_->OnPacketLost(sequence_number, ack_receive_time);
768 OnPacketAbandoned(it);
769
759 if (transmission_info.retransmittable_frames) { 770 if (transmission_info.retransmittable_frames) {
760 ++num_retransmitted; 771 ++num_retransmitted;
761 MarkForRetransmission(sequence_number, NACK_RETRANSMISSION); 772 MarkForRetransmission(sequence_number, NACK_RETRANSMISSION);
773 ++it;
762 } else { 774 } else {
763 // Since we will not retransmit this, we need to remove it from 775 // Since we will not retransmit this, we need to remove it from
764 // unacked_packets_. This is either the current transmission of 776 // unacked_packets_. This is either the current transmission of
765 // a packet whose previous transmission has been acked, or it 777 // a packet whose previous transmission has been acked, or it
766 // is a packet that has been TLP retransmitted. 778 // is a packet that has been TLP retransmitted.
767 RemovePreviousTransmission(sequence_number); 779 RemovePreviousTransmission(sequence_number);
768 unacked_packets_.erase(sequence_number); 780 unacked_packets_.erase(it++);
769 } 781 }
770
771 ++it;
772 }
773 // Abandon packets after the loop over pending packets, because otherwise it
774 // changes the early retransmit logic and iteration.
775 for (SequenceNumberSet::const_iterator it = lost_packets.begin();
776 it != lost_packets.end(); ++it) {
777 // TODO(ianswett): OnPacketLost is also called from TCPCubicSender when
778 // an FEC packet is lost, but FEC loss information should be shared among
779 // congestion managers. Additionally, if it's expected the FEC packet may
780 // repair the loss, it should be recorded as a loss to the congestion
781 // manager, but not retransmitted until it's known whether the FEC packet
782 // arrived.
783 QuicPacketSequenceNumber lost_packet = *it;
784 send_algorithm_->OnPacketLost(lost_packet, ack_receive_time);
785 OnPacketAbandoned(lost_packet);
786 } 782 }
787 } 783 }
788 784
789 void QuicSentPacketManager::MaybeUpdateRTT( 785 void QuicSentPacketManager::MaybeUpdateRTT(
790 const ReceivedPacketInfo& received_info, 786 const ReceivedPacketInfo& received_info,
791 const QuicTime& ack_receive_time) { 787 const QuicTime& ack_receive_time) {
792 // We calculate the RTT based on the highest ACKed sequence number, the lower 788 // We calculate the RTT based on the highest ACKed sequence number, the lower
793 // sequence numbers will include the ACK aggregation delay. 789 // sequence numbers will include the ACK aggregation delay.
794 SendAlgorithmInterface::SentPacketsMap::iterator history_it = 790 UnackedPacketMap::iterator unacked_it =
795 packet_history_map_.find(received_info.largest_observed); 791 unacked_packets_.find(received_info.largest_observed);
796 // TODO(satyamshekhar): largest_observed might be missing. 792 if (unacked_it == unacked_packets_.end()) {
797 if (history_it == packet_history_map_.end()) { 793 return;
794 }
795 const TransmissionInfo* transmission_info = &unacked_it->second;
796 if (transmission_info == NULL) {
798 return; 797 return;
799 } 798 }
800 799
801 QuicTime::Delta send_delta = ack_receive_time.Subtract( 800 QuicTime::Delta send_delta =
802 history_it->second->send_timestamp()); 801 ack_receive_time.Subtract(transmission_info->sent_time);
803 if (send_delta > received_info.delta_time_largest_observed) { 802 if (send_delta > received_info.delta_time_largest_observed) {
804 rtt_sample_ = send_delta.Subtract( 803 rtt_sample_ = send_delta.Subtract(
805 received_info.delta_time_largest_observed); 804 received_info.delta_time_largest_observed);
806 } else if (rtt_sample_.IsInfinite()) { 805 } else if (rtt_sample_.IsInfinite()) {
807 // Even though we received information from the peer suggesting 806 // Even though we received information from the peer suggesting
808 // an invalid (negative) RTT, we can use the send delta as an 807 // an invalid (negative) RTT, we can use the send delta as an
809 // approximation until we get a better estimate. 808 // approximation until we get a better estimate.
810 rtt_sample_ = send_delta; 809 rtt_sample_ = send_delta;
811 } 810 }
812 } 811 }
(...skipping 12 matching lines...) Expand all
825 // delayed ack to get back to the QUIC peer before the sender's 824 // delayed ack to get back to the QUIC peer before the sender's
826 // retransmission timer triggers. Since we do not know the 825 // retransmission timer triggers. Since we do not know the
827 // reverse-path one-way delay, we assume equal delays for forward and 826 // reverse-path one-way delay, we assume equal delays for forward and
828 // reverse paths, and ensure that the timer is set to less than half 827 // reverse paths, and ensure that the timer is set to less than half
829 // of the MinRTO. 828 // of the MinRTO.
830 // There may be a value in making this delay adaptive with the help of 829 // There may be a value in making this delay adaptive with the help of
831 // the sender and a signaling mechanism -- if the sender uses a 830 // the sender and a signaling mechanism -- if the sender uses a
832 // different MinRTO, we may get spurious retransmissions. May not have 831 // different MinRTO, we may get spurious retransmissions. May not have
833 // any benefits, but if the delayed ack becomes a significant source 832 // any benefits, but if the delayed ack becomes a significant source
834 // of (likely, tail) latency, then consider such a mechanism. 833 // of (likely, tail) latency, then consider such a mechanism.
835
836 const QuicTime::Delta QuicSentPacketManager::DelayedAckTime() const { 834 const QuicTime::Delta QuicSentPacketManager::DelayedAckTime() const {
837 return QuicTime::Delta::FromMilliseconds(kMinRetransmissionTimeMs/2); 835 return QuicTime::Delta::FromMilliseconds(kMinRetransmissionTimeMs/2);
838 } 836 }
839 837
840 const QuicTime QuicSentPacketManager::GetRetransmissionTime() const { 838 const QuicTime QuicSentPacketManager::GetRetransmissionTime() const {
841 // There can't be any retransmittable packets if there are none pending. 839 // Don't set the timer if there are no pending packets.
842 if (pending_packets_.empty()) { 840 if (!HasPendingPackets()) {
843 return QuicTime::Zero(); 841 return QuicTime::Zero();
844 } 842 }
845 switch (GetRetransmissionMode()) { 843 switch (GetRetransmissionMode()) {
846 case HANDSHAKE_MODE: 844 case HANDSHAKE_MODE:
847 return clock_->ApproximateNow().Add(GetCryptoRetransmissionDelay()); 845 return clock_->ApproximateNow().Add(GetCryptoRetransmissionDelay());
848 case TLP_MODE: { 846 case TLP_MODE: {
849 // TODO(ianswett): When CWND is available, it would be preferable to 847 // TODO(ianswett): When CWND is available, it would be preferable to
850 // set the timer based on the earliest retransmittable packet. 848 // set the timer based on the earliest retransmittable packet.
851 // Base the updated timer on the send time of the last packet. 849 // Base the updated timer on the send time of the last packet.
852 QuicPacketSequenceNumber last_pending_packet = *pending_packets_.rbegin(); 850 UnackedPacketMap::const_reverse_iterator it = unacked_packets_.rbegin();
853 const QuicTime& sent_time = packet_history_map_.find( 851 while (it != unacked_packets_.rend() &&
854 last_pending_packet)->second->send_timestamp(); 852 (!it->second.pending ||
853 it->second.retransmittable_frames == NULL)) {
854 ++it;
855 }
856 DCHECK(it != unacked_packets_.rend());
857 const QuicTime& sent_time = it->second.sent_time;
855 const QuicTime tlp_time = sent_time.Add(GetTailLossProbeDelay()); 858 const QuicTime tlp_time = sent_time.Add(GetTailLossProbeDelay());
856 // Ensure the tlp timer never gets set to a time in the past. 859 // Ensure the tlp timer never gets set to a time in the past.
857 return QuicTime::Max(clock_->ApproximateNow(), tlp_time); 860 return QuicTime::Max(clock_->ApproximateNow(), tlp_time);
858 } 861 }
859 case RTO_MODE: { 862 case RTO_MODE: {
860 QuicPacketSequenceNumber first_pending_packet = *pending_packets_.begin(); 863 // The RTO is based on the first pending packet.
861 const QuicTime& sent_time = packet_history_map_.find( 864 UnackedPacketMap::const_iterator it = unacked_packets_.begin();
862 first_pending_packet)->second->send_timestamp(); 865 while (it != unacked_packets_.end() && !it->second.pending) {
866 ++it;
867 }
868 DCHECK(it != unacked_packets_.end());
869 const QuicTime& sent_time = it->second.sent_time;
863 // Always wait at least 1.5 * RTT after the first sent packet. 870 // Always wait at least 1.5 * RTT after the first sent packet.
864 QuicTime min_timeout = clock_->ApproximateNow().Add( 871 QuicTime min_timeout = clock_->ApproximateNow().Add(
865 SmoothedRtt().Multiply(1.5)); 872 SmoothedRtt().Multiply(1.5));
866 QuicTime rto_timeout = sent_time.Add(GetRetransmissionDelay()); 873 QuicTime rto_timeout = sent_time.Add(GetRetransmissionDelay());
867
868 return QuicTime::Max(min_timeout, rto_timeout); 874 return QuicTime::Max(min_timeout, rto_timeout);
869 } 875 }
870 default: 876 default:
871 DCHECK(false); 877 DCHECK(false);
872 } 878 }
873 return QuicTime::Zero(); 879 return QuicTime::Zero();
874 } 880 }
875 881
876 const QuicTime::Delta QuicSentPacketManager::GetCryptoRetransmissionDelay() 882 const QuicTime::Delta QuicSentPacketManager::GetCryptoRetransmissionDelay()
877 const { 883 const {
878 // This is equivalent to the TailLossProbeDelay, but slightly more aggressive 884 // This is equivalent to the TailLossProbeDelay, but slightly more aggressive
879 // because crypto handshake messages don't incur a delayed ack time. 885 // because crypto handshake messages don't incur a delayed ack time.
880 int64 delay_ms = max<int64>(kMinHandshakeTimeoutMs, 886 int64 delay_ms = max<int64>(kMinHandshakeTimeoutMs,
881 1.5 * SmoothedRtt().ToMilliseconds()); 887 1.5 * SmoothedRtt().ToMilliseconds());
882 return QuicTime::Delta::FromMilliseconds( 888 return QuicTime::Delta::FromMilliseconds(
883 delay_ms << consecutive_crypto_retransmission_count_); 889 delay_ms << consecutive_crypto_retransmission_count_);
884 } 890 }
885 891
886 const QuicTime::Delta QuicSentPacketManager::GetTailLossProbeDelay() const { 892 const QuicTime::Delta QuicSentPacketManager::GetTailLossProbeDelay() const {
887 QuicTime::Delta srtt = SmoothedRtt(); 893 QuicTime::Delta srtt = SmoothedRtt();
888 if (pending_packets_.size() == 1) { 894 size_t num_pending = 0;
895 for (UnackedPacketMap::const_reverse_iterator it = unacked_packets_.rbegin();
896 it != unacked_packets_.rend(); ++it) {
897 if (it->second.pending) {
898 ++num_pending;
899 if (num_pending > 1) {
900 break;
901 }
902 }
903 }
904 DCHECK_LT(0u, num_pending);
905 if (num_pending == 1) {
889 return QuicTime::Delta::Max( 906 return QuicTime::Delta::Max(
890 srtt.Multiply(1.5).Add(DelayedAckTime()), srtt.Multiply(2)); 907 srtt.Multiply(1.5).Add(DelayedAckTime()), srtt.Multiply(2));
891 } 908 }
892 return QuicTime::Delta::FromMilliseconds( 909 return QuicTime::Delta::FromMilliseconds(
893 max(kMinTailLossProbeTimeoutMs, 910 max(kMinTailLossProbeTimeoutMs,
894 static_cast<int64>(2 * srtt.ToMilliseconds()))); 911 static_cast<int64>(2 * srtt.ToMilliseconds())));
895 } 912 }
896 913
897 const QuicTime::Delta QuicSentPacketManager::GetRetransmissionDelay() const { 914 const QuicTime::Delta QuicSentPacketManager::GetRetransmissionDelay() const {
898 QuicTime::Delta retransmission_delay = send_algorithm_->RetransmissionDelay(); 915 QuicTime::Delta retransmission_delay = send_algorithm_->RetransmissionDelay();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 QuicTime::Delta::FromMilliseconds(kHistoryPeriodMs); 949 QuicTime::Delta::FromMilliseconds(kHistoryPeriodMs);
933 QuicTime now = clock_->ApproximateNow(); 950 QuicTime now = clock_->ApproximateNow();
934 951
935 SendAlgorithmInterface::SentPacketsMap::iterator history_it = 952 SendAlgorithmInterface::SentPacketsMap::iterator history_it =
936 packet_history_map_.begin(); 953 packet_history_map_.begin();
937 for (; history_it != packet_history_map_.end(); ++history_it) { 954 for (; history_it != packet_history_map_.end(); ++history_it) {
938 if (now.Subtract(history_it->second->send_timestamp()) <= kHistoryPeriod) { 955 if (now.Subtract(history_it->second->send_timestamp()) <= kHistoryPeriod) {
939 return; 956 return;
940 } 957 }
941 // Don't remove packets which have not been acked. 958 // Don't remove packets which have not been acked.
942 if (ContainsKey(pending_packets_, history_it->first)) { 959 if (ContainsKey(unacked_packets_, history_it->first)) {
943 continue; 960 continue;
944 } 961 }
945 delete history_it->second; 962 delete history_it->second;
946 packet_history_map_.erase(history_it); 963 packet_history_map_.erase(history_it);
947 history_it = packet_history_map_.begin(); 964 history_it = packet_history_map_.begin();
948 } 965 }
949 } 966 }
950 967
951 void QuicSentPacketManager::MaybeEnablePacing() { 968 void QuicSentPacketManager::MaybeEnablePacing() {
952 if (!FLAGS_enable_quic_pacing) { 969 if (!FLAGS_enable_quic_pacing) {
(...skipping 19 matching lines...) Expand all
972 } 989 }
973 previous_transmissions->erase(sequence_number); 990 previous_transmissions->erase(sequence_number);
974 if (previous_transmissions->size() == 1) { 991 if (previous_transmissions->size() == 1) {
975 QuicPacketSequenceNumber current = *previous_transmissions->begin(); 992 QuicPacketSequenceNumber current = *previous_transmissions->begin();
976 unacked_packets_[current].previous_transmissions = NULL; 993 unacked_packets_[current].previous_transmissions = NULL;
977 delete previous_transmissions; 994 delete previous_transmissions;
978 } 995 }
979 } 996 }
980 997
981 } // namespace net 998 } // 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