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

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

Issue 127633002: Land Recent QUIC Changes. (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 const RetransmittableFrames* frames = it->second.retransmittable_frames;
603 DCHECK(ContainsKey(unacked_packets_, sequence_number)); 614 // Only retransmit frames which are pending, and therefore have been sent.
604 const RetransmittableFrames* frames = 615 if (!it->second.pending || frames == NULL ||
605 unacked_packets_[sequence_number].retransmittable_frames; 616 frames->HasCryptoHandshake() != IS_HANDSHAKE) {
606 if (frames == NULL || frames->HasCryptoHandshake() != IS_HANDSHAKE) {
607 ++it;
608 continue; 617 continue;
609 } 618 }
619 DCHECK(ContainsKey(packet_history_map_, sequence_number));
610 packet_retransmitted = true; 620 packet_retransmitted = true;
611 MarkForRetransmission(sequence_number, TLP_RETRANSMISSION); 621 MarkForRetransmission(sequence_number, TLP_RETRANSMISSION);
612 // Abandon all the crypto retransmissions now so they're not lost later. 622 // Abandon all the crypto retransmissions now so they're not lost later.
613 send_algorithm_->OnPacketAbandoned( 623 OnPacketAbandoned(it);
614 sequence_number, packet_history_map_[sequence_number]->bytes_sent());
615 pending_packets_.erase(it++);
616 } 624 }
617 DCHECK(packet_retransmitted) << "No crypto packets found to retransmit."; 625 DCHECK(packet_retransmitted) << "No crypto packets found to retransmit.";
618 } 626 }
619 627
620 void QuicSentPacketManager::RetransmitOldestPacket() { 628 void QuicSentPacketManager::RetransmitOldestPacket() {
621 DCHECK_EQ(TLP_MODE, GetRetransmissionMode()); 629 DCHECK_EQ(TLP_MODE, GetRetransmissionMode());
622 ++consecutive_tlp_count_; 630 ++consecutive_tlp_count_;
623 for (SequenceNumberSet::const_iterator it = pending_packets_.begin(); 631 for (UnackedPacketMap::const_iterator it = unacked_packets_.begin();
624 it != pending_packets_.end(); ++it) { 632 it != unacked_packets_.end(); ++it) {
625 QuicPacketSequenceNumber sequence_number = *it; 633 QuicPacketSequenceNumber sequence_number = it->first;
626 DCHECK(ContainsKey(unacked_packets_, sequence_number)); 634 const RetransmittableFrames* frames = it->second.retransmittable_frames;
627 const RetransmittableFrames* frames = 635 // Only retransmit frames which are pending, and therefore have been sent.
628 unacked_packets_[sequence_number].retransmittable_frames; 636 if (!it->second.pending || frames == NULL) {
629 if (frames == NULL) {
630 continue; 637 continue;
631 } 638 }
632 DCHECK_NE(IS_HANDSHAKE, frames->HasCryptoHandshake()); 639 DCHECK_NE(IS_HANDSHAKE, frames->HasCryptoHandshake());
633 MarkForRetransmission(sequence_number, TLP_RETRANSMISSION); 640 MarkForRetransmission(sequence_number, TLP_RETRANSMISSION);
634 return; 641 return;
635 } 642 }
636 DLOG(FATAL) 643 DLOG(FATAL)
637 << "No retransmittable packets, so RetransmitOldestPacket failed."; 644 << "No retransmittable packets, so RetransmitOldestPacket failed.";
638 } 645 }
639 646
640 void QuicSentPacketManager::RetransmitAllPackets() { 647 void QuicSentPacketManager::RetransmitAllPackets() {
641 // Abandon all retransmittable packets and packets older than the 648 // Abandon all retransmittable packets and packets older than the
642 // retransmission delay. 649 // retransmission delay.
643 650
644 DVLOG(1) << "OnRetransmissionTimeout() fired with " 651 DVLOG(1) << "OnRetransmissionTimeout() fired with "
645 << unacked_packets_.size() << " unacked packets."; 652 << unacked_packets_.size() << " unacked packets.";
646 653
647 // Request retransmission of all retransmittable packets when the RTO 654 // Request retransmission of all retransmittable packets when the RTO
648 // fires, and let the congestion manager decide how many to send 655 // fires, and let the congestion manager decide how many to send
649 // immediately and the remaining packets will be queued. 656 // immediately and the remaining packets will be queued.
650 // Abandon any non-retransmittable packets that are sufficiently old. 657 // Abandon any non-retransmittable packets that are sufficiently old.
651 bool packets_retransmitted = false; 658 bool packets_retransmitted = false;
652 for (UnackedPacketMap::const_iterator it = unacked_packets_.begin(); 659 for (UnackedPacketMap::iterator it = unacked_packets_.begin();
653 it != unacked_packets_.end(); ++it) { 660 it != unacked_packets_.end(); ++it) {
661 it->second.pending = false;
654 if (it->second.retransmittable_frames != NULL) { 662 if (it->second.retransmittable_frames != NULL) {
655 packets_retransmitted = true; 663 packets_retransmitted = true;
656 MarkForRetransmission(it->first, RTO_RETRANSMISSION); 664 MarkForRetransmission(it->first, RTO_RETRANSMISSION);
657 } 665 }
658 } 666 }
659 667
660 pending_packets_.clear();
661 send_algorithm_->OnRetransmissionTimeout(packets_retransmitted); 668 send_algorithm_->OnRetransmissionTimeout(packets_retransmitted);
662 if (packets_retransmitted) { 669 if (packets_retransmitted) {
663 ++consecutive_rto_count_; 670 ++consecutive_rto_count_;
664 } 671 }
665 } 672 }
666 673
667 QuicSentPacketManager::RetransmissionTimeoutMode 674 QuicSentPacketManager::RetransmissionTimeoutMode
668 QuicSentPacketManager::GetRetransmissionMode() const { 675 QuicSentPacketManager::GetRetransmissionMode() const {
669 DCHECK(!pending_packets_.empty()); 676 DCHECK(HasPendingPackets());
670 if (pending_crypto_packet_count_ > 0) { 677 if (pending_crypto_packet_count_ > 0) {
671 return HANDSHAKE_MODE; 678 return HANDSHAKE_MODE;
672 } 679 }
673 if (consecutive_tlp_count_ < max_tail_loss_probes_) { 680 if (consecutive_tlp_count_ < max_tail_loss_probes_) {
674 // Ensure there are retransmittable frames. 681 // Ensure there are retransmittable frames.
675 for (SequenceNumberSet::const_iterator it = pending_packets_.begin(); 682 for (UnackedPacketMap::const_reverse_iterator it =
676 it != pending_packets_.end(); ++it) { 683 unacked_packets_.rbegin(); it != unacked_packets_.rend(); ++it) {
677 if (HasRetransmittableFrames(*it)) { 684 if (it->second.pending && it->second.retransmittable_frames) {
678 return TLP_MODE; 685 return TLP_MODE;
679 } 686 }
680 } 687 }
681 } 688 }
682 return RTO_MODE; 689 return RTO_MODE;
683 } 690 }
684 691
685 void QuicSentPacketManager::OnPacketAbandoned( 692 void QuicSentPacketManager::OnPacketAbandoned(UnackedPacketMap::iterator it) {
686 QuicPacketSequenceNumber sequence_number) { 693 DCHECK(it != unacked_packets_.end());
687 SequenceNumberSet::iterator it = pending_packets_.find(sequence_number); 694 QuicPacketSequenceNumber sequence_number = it->first;
688 if (it != pending_packets_.end()) { 695 DCHECK(ContainsKey(packet_history_map_, sequence_number));
689 DCHECK(ContainsKey(packet_history_map_, sequence_number)); 696 if (it->second.pending) {
690 send_algorithm_->OnPacketAbandoned( 697 send_algorithm_->OnPacketAbandoned(
691 sequence_number, packet_history_map_[sequence_number]->bytes_sent()); 698 sequence_number, packet_history_map_[sequence_number]->bytes_sent());
692 pending_packets_.erase(it); 699 it->second.pending = false;
693 } 700 }
694 } 701 }
695 702
696 void QuicSentPacketManager::OnIncomingQuicCongestionFeedbackFrame( 703 void QuicSentPacketManager::OnIncomingQuicCongestionFeedbackFrame(
697 const QuicCongestionFeedbackFrame& frame, 704 const QuicCongestionFeedbackFrame& frame,
698 const QuicTime& feedback_receive_time) { 705 const QuicTime& feedback_receive_time) {
699 send_algorithm_->OnIncomingQuicCongestionFeedbackFrame( 706 send_algorithm_->OnIncomingQuicCongestionFeedbackFrame(
700 frame, feedback_receive_time, packet_history_map_); 707 frame, feedback_receive_time, packet_history_map_);
701 } 708 }
702 709
703 void QuicSentPacketManager::MaybeRetransmitOnAckFrame( 710 void QuicSentPacketManager::MaybeRetransmitOnAckFrame(
704 const ReceivedPacketInfo& received_info, 711 const ReceivedPacketInfo& received_info,
705 const QuicTime& ack_receive_time) { 712 const QuicTime& ack_receive_time) {
706 // Go through all pending packets up to the largest observed and see if any 713 // Go through all pending packets up to the largest observed and see if any
707 // need to be retransmitted or lost. 714 // 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; 715 size_t num_retransmitted = 0;
713 SequenceNumberSet lost_packets; 716 UnackedPacketMap::iterator it = unacked_packets_.begin();
714 while (it != it_upper) { 717 while (it != unacked_packets_.end() &&
715 QuicPacketSequenceNumber sequence_number = *it; 718 it->first <= received_info.largest_observed) {
719 if (!it->second.pending) {
720 ++it;
721 continue;
722 }
723 QuicPacketSequenceNumber sequence_number = it->first;
716 DVLOG(1) << "still missing packet " << sequence_number; 724 DVLOG(1) << "still missing packet " << sequence_number;
717 // Acks must be handled previously, so ensure it's missing and not acked. 725 // Acks must be handled previously, so ensure it's missing and not acked.
718 DCHECK(IsAwaitingPacket(received_info, sequence_number)); 726 DCHECK(IsAwaitingPacket(received_info, sequence_number));
719 DCHECK(ContainsKey(packet_history_map_, sequence_number)); 727 DCHECK(ContainsKey(packet_history_map_, sequence_number));
720 const SendAlgorithmInterface::SentPacket* sent_packet = 728 const TransmissionInfo& transmission_info = it->second;
729 SendAlgorithmInterface::SentPacket* sent_packet =
721 packet_history_map_[sequence_number]; 730 packet_history_map_[sequence_number];
722 const TransmissionInfo& transmission_info =
723 unacked_packets_[sequence_number];
724 731
725 // Consider it multiple nacks when there is a gap between the missing packet 732 // 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 733 // and the largest observed, since the purpose of a nack threshold is to
727 // tolerate re-ordering. This handles both StretchAcks and Forward Acks. 734 // tolerate re-ordering. This handles both StretchAcks and Forward Acks.
728 // TODO(ianswett): This relies heavily on sequential reception of packets, 735 // TODO(ianswett): This relies heavily on sequential reception of packets,
729 // and makes an assumption that the congestion control uses TCP style nacks. 736 // and makes an assumption that the congestion control uses TCP style nacks.
730 size_t min_nacks = received_info.largest_observed - sequence_number; 737 size_t min_nacks = received_info.largest_observed - sequence_number;
731 packet_history_map_[sequence_number]->Nack(min_nacks); 738 sent_packet->Nack(min_nacks);
732 739
733 size_t num_nacks_needed = kNumberOfNacksBeforeRetransmission; 740 size_t num_nacks_needed = kNumberOfNacksBeforeRetransmission;
734 // Check for early retransmit(RFC5827) when the last packet gets acked and 741 // Check for early retransmit(RFC5827) when the last packet gets acked and
735 // the there are fewer than 4 pending packets. 742 // the there are fewer than 4 pending packets.
736 // TODO(ianswett): Consider setting a retransmission timer instead of 743 // TODO(ianswett): Set a retransmission timer instead of losing the packet
737 // losing the packet and retransmitting immediately. Also consider only 744 // and retransmitting immediately. Also consider only invoking OnPacketLost
738 // invoking OnPacketLost and OnPacketAbandoned when they're actually 745 // and OnPacketAbandoned when they're actually retransmitted in case they
739 // retransmitted in case they arrive while queued. 746 // arrive while queued for retransmission.
740 if (pending_packets_.size() <= kNumberOfNacksBeforeRetransmission && 747 if (transmission_info.retransmittable_frames &&
741 transmission_info.retransmittable_frames &&
742 packet_history_map_.rbegin()->first == received_info.largest_observed) { 748 packet_history_map_.rbegin()->first == received_info.largest_observed) {
743 num_nacks_needed = received_info.largest_observed - sequence_number; 749 num_nacks_needed = received_info.largest_observed - sequence_number;
744 } 750 }
745 751
746 if (sent_packet->nack_count() < num_nacks_needed) { 752 if (sent_packet->nack_count() < num_nacks_needed) {
747 ++it; 753 ++it;
748 continue; 754 continue;
749 } 755 }
750 756
751 // If the number of retransmissions has maxed out, don't lose or retransmit 757 // If the number of retransmissions has maxed out, don't lose or retransmit
752 // any more packets. 758 // any more packets.
753 if (num_retransmitted >= kMaxRetransmissionsPerAck) { 759 if (num_retransmitted >= kMaxRetransmissionsPerAck) {
754 ++it; 760 ++it;
755 continue; 761 continue;
756 } 762 }
757 763
758 lost_packets.insert(sequence_number); 764 // TODO(ianswett): OnPacketLost is also called from TCPCubicSender when
765 // an FEC packet is lost, but FEC loss information should be shared among
766 // congestion managers. Additionally, if it's expected the FEC packet may
767 // repair the loss, it should be recorded as a loss to the congestion
768 // manager, but not retransmitted until it's known whether the FEC packet
769 // arrived.
770 send_algorithm_->OnPacketLost(sequence_number, ack_receive_time);
771 OnPacketAbandoned(it);
772
759 if (transmission_info.retransmittable_frames) { 773 if (transmission_info.retransmittable_frames) {
760 ++num_retransmitted; 774 ++num_retransmitted;
761 MarkForRetransmission(sequence_number, NACK_RETRANSMISSION); 775 MarkForRetransmission(sequence_number, NACK_RETRANSMISSION);
776 ++it;
762 } else { 777 } else {
763 // Since we will not retransmit this, we need to remove it from 778 // Since we will not retransmit this, we need to remove it from
764 // unacked_packets_. This is either the current transmission of 779 // unacked_packets_. This is either the current transmission of
765 // a packet whose previous transmission has been acked, or it 780 // a packet whose previous transmission has been acked, or it
766 // is a packet that has been TLP retransmitted. 781 // is a packet that has been TLP retransmitted.
767 RemovePreviousTransmission(sequence_number); 782 RemovePreviousTransmission(sequence_number);
768 unacked_packets_.erase(sequence_number); 783 unacked_packets_.erase(it++);
769 } 784 }
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 } 785 }
787 } 786 }
788 787
789 void QuicSentPacketManager::MaybeUpdateRTT( 788 void QuicSentPacketManager::MaybeUpdateRTT(
790 const ReceivedPacketInfo& received_info, 789 const ReceivedPacketInfo& received_info,
791 const QuicTime& ack_receive_time) { 790 const QuicTime& ack_receive_time) {
792 // We calculate the RTT based on the highest ACKed sequence number, the lower 791 // We calculate the RTT based on the highest ACKed sequence number, the lower
793 // sequence numbers will include the ACK aggregation delay. 792 // sequence numbers will include the ACK aggregation delay.
794 SendAlgorithmInterface::SentPacketsMap::iterator history_it = 793 UnackedPacketMap::iterator unacked_it =
795 packet_history_map_.find(received_info.largest_observed); 794 unacked_packets_.find(received_info.largest_observed);
796 // TODO(satyamshekhar): largest_observed might be missing. 795 if (unacked_it == unacked_packets_.end()) {
797 if (history_it == packet_history_map_.end()) { 796 return;
797 }
798 const TransmissionInfo* transmission_info = &unacked_it->second;
799 if (transmission_info == NULL) {
798 return; 800 return;
799 } 801 }
800 802
801 QuicTime::Delta send_delta = ack_receive_time.Subtract( 803 QuicTime::Delta send_delta =
802 history_it->second->send_timestamp()); 804 ack_receive_time.Subtract(transmission_info->sent_time);
803 if (send_delta > received_info.delta_time_largest_observed) { 805 if (send_delta > received_info.delta_time_largest_observed) {
804 rtt_sample_ = send_delta.Subtract( 806 rtt_sample_ = send_delta.Subtract(
805 received_info.delta_time_largest_observed); 807 received_info.delta_time_largest_observed);
806 } else if (rtt_sample_.IsInfinite()) { 808 } else if (rtt_sample_.IsInfinite()) {
807 // Even though we received information from the peer suggesting 809 // Even though we received information from the peer suggesting
808 // an invalid (negative) RTT, we can use the send delta as an 810 // an invalid (negative) RTT, we can use the send delta as an
809 // approximation until we get a better estimate. 811 // approximation until we get a better estimate.
810 rtt_sample_ = send_delta; 812 rtt_sample_ = send_delta;
811 } 813 }
812 } 814 }
(...skipping 12 matching lines...) Expand all
825 // delayed ack to get back to the QUIC peer before the sender's 827 // delayed ack to get back to the QUIC peer before the sender's
826 // retransmission timer triggers. Since we do not know the 828 // retransmission timer triggers. Since we do not know the
827 // reverse-path one-way delay, we assume equal delays for forward and 829 // 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 830 // reverse paths, and ensure that the timer is set to less than half
829 // of the MinRTO. 831 // of the MinRTO.
830 // There may be a value in making this delay adaptive with the help of 832 // 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 833 // the sender and a signaling mechanism -- if the sender uses a
832 // different MinRTO, we may get spurious retransmissions. May not have 834 // different MinRTO, we may get spurious retransmissions. May not have
833 // any benefits, but if the delayed ack becomes a significant source 835 // any benefits, but if the delayed ack becomes a significant source
834 // of (likely, tail) latency, then consider such a mechanism. 836 // of (likely, tail) latency, then consider such a mechanism.
835
836 const QuicTime::Delta QuicSentPacketManager::DelayedAckTime() const { 837 const QuicTime::Delta QuicSentPacketManager::DelayedAckTime() const {
837 return QuicTime::Delta::FromMilliseconds(kMinRetransmissionTimeMs/2); 838 return QuicTime::Delta::FromMilliseconds(kMinRetransmissionTimeMs/2);
838 } 839 }
839 840
840 const QuicTime QuicSentPacketManager::GetRetransmissionTime() const { 841 const QuicTime QuicSentPacketManager::GetRetransmissionTime() const {
841 // There can't be any retransmittable packets if there are none pending. 842 // Don't set the timer if there are no pending packets.
842 if (pending_packets_.empty()) { 843 if (!HasPendingPackets()) {
843 return QuicTime::Zero(); 844 return QuicTime::Zero();
844 } 845 }
845 switch (GetRetransmissionMode()) { 846 switch (GetRetransmissionMode()) {
846 case HANDSHAKE_MODE: 847 case HANDSHAKE_MODE:
847 return clock_->ApproximateNow().Add(GetCryptoRetransmissionDelay()); 848 return clock_->ApproximateNow().Add(GetCryptoRetransmissionDelay());
848 case TLP_MODE: { 849 case TLP_MODE: {
849 // TODO(ianswett): When CWND is available, it would be preferable to 850 // TODO(ianswett): When CWND is available, it would be preferable to
850 // set the timer based on the earliest retransmittable packet. 851 // set the timer based on the earliest retransmittable packet.
851 // Base the updated timer on the send time of the last packet. 852 // Base the updated timer on the send time of the last packet.
852 QuicPacketSequenceNumber last_pending_packet = *pending_packets_.rbegin(); 853 UnackedPacketMap::const_reverse_iterator it = unacked_packets_.rbegin();
853 const QuicTime& sent_time = packet_history_map_.find( 854 while (it != unacked_packets_.rend() &&
854 last_pending_packet)->second->send_timestamp(); 855 (!it->second.pending ||
856 it->second.retransmittable_frames == NULL)) {
857 ++it;
858 }
859 DCHECK(it != unacked_packets_.rend());
860 const QuicTime& sent_time = it->second.sent_time;
855 const QuicTime tlp_time = sent_time.Add(GetTailLossProbeDelay()); 861 const QuicTime tlp_time = sent_time.Add(GetTailLossProbeDelay());
856 // Ensure the tlp timer never gets set to a time in the past. 862 // Ensure the tlp timer never gets set to a time in the past.
857 return QuicTime::Max(clock_->ApproximateNow(), tlp_time); 863 return QuicTime::Max(clock_->ApproximateNow(), tlp_time);
858 } 864 }
859 case RTO_MODE: { 865 case RTO_MODE: {
860 QuicPacketSequenceNumber first_pending_packet = *pending_packets_.begin(); 866 // The RTO is based on the first pending packet.
861 const QuicTime& sent_time = packet_history_map_.find( 867 UnackedPacketMap::const_iterator it = unacked_packets_.begin();
862 first_pending_packet)->second->send_timestamp(); 868 while (it != unacked_packets_.end() && !it->second.pending) {
869 ++it;
870 }
871 DCHECK(it != unacked_packets_.end());
872 const QuicTime& sent_time = it->second.sent_time;
863 // Always wait at least 1.5 * RTT after the first sent packet. 873 // Always wait at least 1.5 * RTT after the first sent packet.
864 QuicTime min_timeout = clock_->ApproximateNow().Add( 874 QuicTime min_timeout = clock_->ApproximateNow().Add(
865 SmoothedRtt().Multiply(1.5)); 875 SmoothedRtt().Multiply(1.5));
866 QuicTime rto_timeout = sent_time.Add(GetRetransmissionDelay()); 876 QuicTime rto_timeout = sent_time.Add(GetRetransmissionDelay());
867
868 return QuicTime::Max(min_timeout, rto_timeout); 877 return QuicTime::Max(min_timeout, rto_timeout);
869 } 878 }
870 default: 879 default:
871 DCHECK(false); 880 DCHECK(false);
872 } 881 }
873 return QuicTime::Zero(); 882 return QuicTime::Zero();
874 } 883 }
875 884
876 const QuicTime::Delta QuicSentPacketManager::GetCryptoRetransmissionDelay() 885 const QuicTime::Delta QuicSentPacketManager::GetCryptoRetransmissionDelay()
877 const { 886 const {
878 // This is equivalent to the TailLossProbeDelay, but slightly more aggressive 887 // This is equivalent to the TailLossProbeDelay, but slightly more aggressive
879 // because crypto handshake messages don't incur a delayed ack time. 888 // because crypto handshake messages don't incur a delayed ack time.
880 int64 delay_ms = max<int64>(kMinHandshakeTimeoutMs, 889 int64 delay_ms = max<int64>(kMinHandshakeTimeoutMs,
881 1.5 * SmoothedRtt().ToMilliseconds()); 890 1.5 * SmoothedRtt().ToMilliseconds());
882 return QuicTime::Delta::FromMilliseconds( 891 return QuicTime::Delta::FromMilliseconds(
883 delay_ms << consecutive_crypto_retransmission_count_); 892 delay_ms << consecutive_crypto_retransmission_count_);
884 } 893 }
885 894
886 const QuicTime::Delta QuicSentPacketManager::GetTailLossProbeDelay() const { 895 const QuicTime::Delta QuicSentPacketManager::GetTailLossProbeDelay() const {
887 QuicTime::Delta srtt = SmoothedRtt(); 896 QuicTime::Delta srtt = SmoothedRtt();
888 if (pending_packets_.size() == 1) { 897 size_t num_pending = 0;
898 for (UnackedPacketMap::const_reverse_iterator it = unacked_packets_.rbegin();
899 it != unacked_packets_.rend(); ++it) {
900 if (it->second.pending) {
901 ++num_pending;
902 if (num_pending > 1) {
903 break;
904 }
905 }
906 }
907 DCHECK_LT(0u, num_pending);
908 if (num_pending == 1) {
889 return QuicTime::Delta::Max( 909 return QuicTime::Delta::Max(
890 srtt.Multiply(1.5).Add(DelayedAckTime()), srtt.Multiply(2)); 910 srtt.Multiply(1.5).Add(DelayedAckTime()), srtt.Multiply(2));
891 } 911 }
892 return QuicTime::Delta::FromMilliseconds( 912 return QuicTime::Delta::FromMilliseconds(
893 max(kMinTailLossProbeTimeoutMs, 913 max(kMinTailLossProbeTimeoutMs,
894 static_cast<int64>(2 * srtt.ToMilliseconds()))); 914 static_cast<int64>(2 * srtt.ToMilliseconds())));
895 } 915 }
896 916
897 const QuicTime::Delta QuicSentPacketManager::GetRetransmissionDelay() const { 917 const QuicTime::Delta QuicSentPacketManager::GetRetransmissionDelay() const {
898 QuicTime::Delta retransmission_delay = send_algorithm_->RetransmissionDelay(); 918 QuicTime::Delta retransmission_delay = send_algorithm_->RetransmissionDelay();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 QuicTime::Delta::FromMilliseconds(kHistoryPeriodMs); 952 QuicTime::Delta::FromMilliseconds(kHistoryPeriodMs);
933 QuicTime now = clock_->ApproximateNow(); 953 QuicTime now = clock_->ApproximateNow();
934 954
935 SendAlgorithmInterface::SentPacketsMap::iterator history_it = 955 SendAlgorithmInterface::SentPacketsMap::iterator history_it =
936 packet_history_map_.begin(); 956 packet_history_map_.begin();
937 for (; history_it != packet_history_map_.end(); ++history_it) { 957 for (; history_it != packet_history_map_.end(); ++history_it) {
938 if (now.Subtract(history_it->second->send_timestamp()) <= kHistoryPeriod) { 958 if (now.Subtract(history_it->second->send_timestamp()) <= kHistoryPeriod) {
939 return; 959 return;
940 } 960 }
941 // Don't remove packets which have not been acked. 961 // Don't remove packets which have not been acked.
942 if (ContainsKey(pending_packets_, history_it->first)) { 962 if (ContainsKey(unacked_packets_, history_it->first)) {
943 continue; 963 continue;
944 } 964 }
945 delete history_it->second; 965 delete history_it->second;
946 packet_history_map_.erase(history_it); 966 packet_history_map_.erase(history_it);
947 history_it = packet_history_map_.begin(); 967 history_it = packet_history_map_.begin();
948 } 968 }
949 } 969 }
950 970
951 void QuicSentPacketManager::MaybeEnablePacing() { 971 void QuicSentPacketManager::MaybeEnablePacing() {
952 if (!FLAGS_enable_quic_pacing) { 972 if (!FLAGS_enable_quic_pacing) {
(...skipping 19 matching lines...) Expand all
972 } 992 }
973 previous_transmissions->erase(sequence_number); 993 previous_transmissions->erase(sequence_number);
974 if (previous_transmissions->size() == 1) { 994 if (previous_transmissions->size() == 1) {
975 QuicPacketSequenceNumber current = *previous_transmissions->begin(); 995 QuicPacketSequenceNumber current = *previous_transmissions->begin();
976 unacked_packets_[current].previous_transmissions = NULL; 996 unacked_packets_[current].previous_transmissions = NULL;
977 delete previous_transmissions; 997 delete previous_transmissions;
978 } 998 }
979 } 999 }
980 1000
981 } // namespace net 1001 } // 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