| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/quic/quic_sent_packet_manager.h" | 5 #include "net/quic/quic_sent_packet_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 ContainsQuicTag(config.ReceivedConnectionOptions(), tag)) { | 141 ContainsQuicTag(config.ReceivedConnectionOptions(), tag)) { |
| 142 return true; | 142 return true; |
| 143 } | 143 } |
| 144 } else if (config.HasSendConnectionOptions() && | 144 } else if (config.HasSendConnectionOptions() && |
| 145 ContainsQuicTag(config.SendConnectionOptions(), tag)) { | 145 ContainsQuicTag(config.SendConnectionOptions(), tag)) { |
| 146 return true; | 146 return true; |
| 147 } | 147 } |
| 148 return false; | 148 return false; |
| 149 } | 149 } |
| 150 | 150 |
| 151 void QuicSentPacketManager::OnRetransmittedPacket( | |
| 152 QuicPacketSequenceNumber old_sequence_number, | |
| 153 QuicPacketSequenceNumber new_sequence_number) { | |
| 154 TransmissionType transmission_type; | |
| 155 PendingRetransmissionMap::iterator it = | |
| 156 pending_retransmissions_.find(old_sequence_number); | |
| 157 if (it != pending_retransmissions_.end()) { | |
| 158 transmission_type = it->second; | |
| 159 pending_retransmissions_.erase(it); | |
| 160 } else { | |
| 161 DLOG(DFATAL) << "Expected sequence number to be in " | |
| 162 "pending_retransmissions_. sequence_number: " << old_sequence_number; | |
| 163 transmission_type = NOT_RETRANSMISSION; | |
| 164 } | |
| 165 | |
| 166 // A notifier may be waiting to hear about ACKs for the original sequence | |
| 167 // number. Inform them that the sequence number has changed. | |
| 168 ack_notifier_manager_.UpdateSequenceNumber(old_sequence_number, | |
| 169 new_sequence_number); | |
| 170 | |
| 171 unacked_packets_.OnRetransmittedPacket(old_sequence_number, | |
| 172 new_sequence_number, | |
| 173 transmission_type); | |
| 174 } | |
| 175 | |
| 176 void QuicSentPacketManager::OnIncomingAck(const QuicAckFrame& ack_frame, | 151 void QuicSentPacketManager::OnIncomingAck(const QuicAckFrame& ack_frame, |
| 177 QuicTime ack_receive_time) { | 152 QuicTime ack_receive_time) { |
| 178 QuicByteCount bytes_in_flight = unacked_packets_.bytes_in_flight(); | 153 QuicByteCount bytes_in_flight = unacked_packets_.bytes_in_flight(); |
| 179 | 154 |
| 180 UpdatePacketInformationReceivedByPeer(ack_frame); | 155 UpdatePacketInformationReceivedByPeer(ack_frame); |
| 181 // We rely on delta_time_largest_observed to compute an RTT estimate, so | 156 // We rely on delta_time_largest_observed to compute an RTT estimate, so |
| 182 // we only update rtt when the largest observed gets acked. | 157 // we only update rtt when the largest observed gets acked. |
| 183 bool largest_observed_acked = MaybeUpdateRTT(ack_frame, ack_receive_time); | 158 bool largest_observed_acked = MaybeUpdateRTT(ack_frame, ack_receive_time); |
| 184 DCHECK_GE(ack_frame.largest_observed, unacked_packets_.largest_observed()); | 159 DCHECK_GE(ack_frame.largest_observed, unacked_packets_.largest_observed()); |
| 185 unacked_packets_.IncreaseLargestObserved(ack_frame.largest_observed); | 160 unacked_packets_.IncreaseLargestObserved(ack_frame.largest_observed); |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 } | 419 } |
| 445 | 420 |
| 446 unacked_packets_.RemoveRetransmittability(sequence_number); | 421 unacked_packets_.RemoveRetransmittability(sequence_number); |
| 447 } | 422 } |
| 448 | 423 |
| 449 void QuicSentPacketManager::MarkPacketHandled( | 424 void QuicSentPacketManager::MarkPacketHandled( |
| 450 QuicPacketSequenceNumber sequence_number, | 425 QuicPacketSequenceNumber sequence_number, |
| 451 const TransmissionInfo& info, | 426 const TransmissionInfo& info, |
| 452 QuicTime::Delta delta_largest_observed) { | 427 QuicTime::Delta delta_largest_observed) { |
| 453 QuicPacketSequenceNumber newest_transmission = | 428 QuicPacketSequenceNumber newest_transmission = |
| 454 info.all_transmissions == nullptr ? sequence_number | 429 info.all_transmissions == nullptr ? |
| 455 : *info.all_transmissions->rbegin(); | 430 sequence_number : *info.all_transmissions->rbegin(); |
| 456 // Remove the most recent packet, if it is pending retransmission. | 431 // Remove the most recent packet, if it is pending retransmission. |
| 457 pending_retransmissions_.erase(newest_transmission); | 432 pending_retransmissions_.erase(newest_transmission); |
| 458 | 433 |
| 459 // The AckNotifierManager needs to be notified about the most recent | 434 // The AckNotifierManager needs to be notified about the most recent |
| 460 // transmission, since that's the one only one it tracks. | 435 // transmission, since that's the one only one it tracks. |
| 461 ack_notifier_manager_.OnPacketAcked(newest_transmission, | 436 ack_notifier_manager_.OnPacketAcked(newest_transmission, |
| 462 delta_largest_observed); | 437 delta_largest_observed); |
| 463 if (newest_transmission != sequence_number) { | 438 if (newest_transmission != sequence_number) { |
| 464 RecordSpuriousRetransmissions(*info.all_transmissions, sequence_number); | 439 RecordSpuriousRetransmissions(*info.all_transmissions, sequence_number); |
| 465 // Remove the most recent packet from flight if it's a crypto handshake | 440 // Remove the most recent packet from flight if it's a crypto handshake |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 HasRetransmittableData has_retransmittable_data) { | 476 HasRetransmittableData has_retransmittable_data) { |
| 502 QuicPacketSequenceNumber sequence_number = serialized_packet->sequence_number; | 477 QuicPacketSequenceNumber sequence_number = serialized_packet->sequence_number; |
| 503 DCHECK_LT(0u, sequence_number); | 478 DCHECK_LT(0u, sequence_number); |
| 504 DCHECK(!unacked_packets_.IsUnacked(sequence_number)); | 479 DCHECK(!unacked_packets_.IsUnacked(sequence_number)); |
| 505 LOG_IF(DFATAL, bytes == 0) << "Cannot send empty packets."; | 480 LOG_IF(DFATAL, bytes == 0) << "Cannot send empty packets."; |
| 506 | 481 |
| 507 if (original_sequence_number == 0) { | 482 if (original_sequence_number == 0) { |
| 508 if (serialized_packet->retransmittable_frames) { | 483 if (serialized_packet->retransmittable_frames) { |
| 509 ack_notifier_manager_.OnSerializedPacket(*serialized_packet); | 484 ack_notifier_manager_.OnSerializedPacket(*serialized_packet); |
| 510 } | 485 } |
| 511 unacked_packets_.AddPacket(*serialized_packet); | |
| 512 serialized_packet->retransmittable_frames = nullptr; | |
| 513 } else { | 486 } else { |
| 514 OnRetransmittedPacket(original_sequence_number, sequence_number); | 487 PendingRetransmissionMap::iterator it = |
| 488 pending_retransmissions_.find(original_sequence_number); |
| 489 if (it != pending_retransmissions_.end()) { |
| 490 pending_retransmissions_.erase(it); |
| 491 } else { |
| 492 DLOG(DFATAL) << "Expected sequence number to be in " |
| 493 << "pending_retransmissions_. sequence_number: " |
| 494 << original_sequence_number; |
| 495 } |
| 496 // A notifier may be waiting to hear about ACKs for the original sequence |
| 497 // number. Inform them that the sequence number has changed. |
| 498 ack_notifier_manager_.UpdateSequenceNumber(original_sequence_number, |
| 499 sequence_number); |
| 515 } | 500 } |
| 516 | 501 |
| 517 if (pending_timer_transmission_count_ > 0) { | 502 if (pending_timer_transmission_count_ > 0) { |
| 518 --pending_timer_transmission_count_; | 503 --pending_timer_transmission_count_; |
| 519 } | 504 } |
| 520 | 505 |
| 521 if (unacked_packets_.bytes_in_flight() == 0) { | 506 if (unacked_packets_.bytes_in_flight() == 0) { |
| 522 // TODO(ianswett): Consider being less aggressive to force a new | 507 // TODO(ianswett): Consider being less aggressive to force a new |
| 523 // recent_min_rtt, likely by not discarding a relatively new sample. | 508 // recent_min_rtt, likely by not discarding a relatively new sample. |
| 524 DVLOG(1) << "Sampling a new recent min rtt within 2 samples. currently:" | 509 DVLOG(1) << "Sampling a new recent min rtt within 2 samples. currently:" |
| 525 << rtt_stats_.recent_min_rtt().ToMilliseconds() << "ms"; | 510 << rtt_stats_.recent_min_rtt().ToMilliseconds() << "ms"; |
| 526 rtt_stats_.SampleNewRecentMinRtt(kNumMinRttSamplesAfterQuiescence); | 511 rtt_stats_.SampleNewRecentMinRtt(kNumMinRttSamplesAfterQuiescence); |
| 527 } | 512 } |
| 528 | 513 |
| 529 // Only track packets as in flight that the send algorithm wants us to track. | 514 // Only track packets as in flight that the send algorithm wants us to track. |
| 530 const bool in_flight = | 515 const bool in_flight = |
| 531 send_algorithm_->OnPacketSent(sent_time, | 516 send_algorithm_->OnPacketSent(sent_time, |
| 532 unacked_packets_.bytes_in_flight(), | 517 unacked_packets_.bytes_in_flight(), |
| 533 sequence_number, | 518 sequence_number, |
| 534 bytes, | 519 bytes, |
| 535 has_retransmittable_data); | 520 has_retransmittable_data); |
| 536 unacked_packets_.SetSent(sequence_number, sent_time, bytes, in_flight); | 521 unacked_packets_.AddSentPacket(*serialized_packet, |
| 522 original_sequence_number, |
| 523 transmission_type, |
| 524 sent_time, |
| 525 bytes, |
| 526 in_flight); |
| 537 | 527 |
| 528 // Take ownership of the retransmittable frames before exiting. |
| 529 serialized_packet->retransmittable_frames = nullptr; |
| 538 // Reset the retransmission timer anytime a pending packet is sent. | 530 // Reset the retransmission timer anytime a pending packet is sent. |
| 539 return in_flight; | 531 return in_flight; |
| 540 } | 532 } |
| 541 | 533 |
| 542 void QuicSentPacketManager::OnRetransmissionTimeout() { | 534 void QuicSentPacketManager::OnRetransmissionTimeout() { |
| 543 DCHECK(unacked_packets_.HasInFlightPackets()); | 535 DCHECK(unacked_packets_.HasInFlightPackets()); |
| 544 DCHECK_EQ(0u, pending_timer_transmission_count_); | 536 DCHECK_EQ(0u, pending_timer_transmission_count_); |
| 545 // Handshake retransmission, timer based loss detection, TLP, and RTO are | 537 // Handshake retransmission, timer based loss detection, TLP, and RTO are |
| 546 // implemented with a single alarm. The handshake alarm is set when the | 538 // implemented with a single alarm. The handshake alarm is set when the |
| 547 // handshake has not completed, the loss alarm is set when the loss detection | 539 // handshake has not completed, the loss alarm is set when the loss detection |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 876 // Set up a pacing sender with a 1 millisecond alarm granularity, the same as | 868 // Set up a pacing sender with a 1 millisecond alarm granularity, the same as |
| 877 // the default granularity of the Linux kernel's FQ qdisc. | 869 // the default granularity of the Linux kernel's FQ qdisc. |
| 878 using_pacing_ = true; | 870 using_pacing_ = true; |
| 879 send_algorithm_.reset( | 871 send_algorithm_.reset( |
| 880 new PacingSender(send_algorithm_.release(), | 872 new PacingSender(send_algorithm_.release(), |
| 881 QuicTime::Delta::FromMilliseconds(1), | 873 QuicTime::Delta::FromMilliseconds(1), |
| 882 kInitialUnpacedBurst)); | 874 kInitialUnpacedBurst)); |
| 883 } | 875 } |
| 884 | 876 |
| 885 } // namespace net | 877 } // namespace net |
| OLD | NEW |