| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 is_server_(is_server), | 71 is_server_(is_server), |
| 72 clock_(clock), | 72 clock_(clock), |
| 73 stats_(stats), | 73 stats_(stats), |
| 74 debug_delegate_(NULL), | 74 debug_delegate_(NULL), |
| 75 network_change_visitor_(NULL), | 75 network_change_visitor_(NULL), |
| 76 send_algorithm_(SendAlgorithmInterface::Create(clock, | 76 send_algorithm_(SendAlgorithmInterface::Create(clock, |
| 77 &rtt_stats_, | 77 &rtt_stats_, |
| 78 congestion_control_type, | 78 congestion_control_type, |
| 79 stats)), | 79 stats)), |
| 80 loss_algorithm_(LossDetectionInterface::Create(loss_type)), | 80 loss_algorithm_(LossDetectionInterface::Create(loss_type)), |
| 81 largest_observed_(0), | 81 least_packet_awaited_by_peer_(1), |
| 82 first_rto_transmission_(0), | 82 first_rto_transmission_(0), |
| 83 consecutive_rto_count_(0), | 83 consecutive_rto_count_(0), |
| 84 consecutive_tlp_count_(0), | 84 consecutive_tlp_count_(0), |
| 85 consecutive_crypto_retransmission_count_(0), | 85 consecutive_crypto_retransmission_count_(0), |
| 86 pending_timer_transmission_count_(0), | 86 pending_timer_transmission_count_(0), |
| 87 max_tail_loss_probes_(kDefaultMaxTailLossProbes), | 87 max_tail_loss_probes_(kDefaultMaxTailLossProbes), |
| 88 using_pacing_(false), | 88 using_pacing_(false), |
| 89 handshake_confirmed_(false) { | 89 handshake_confirmed_(false) { |
| 90 } | 90 } |
| 91 | 91 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 106 QuicTime::Delta::FromSeconds(FLAGS_quic_recent_min_rtt_window_s)); | 106 QuicTime::Delta::FromSeconds(FLAGS_quic_recent_min_rtt_window_s)); |
| 107 } | 107 } |
| 108 send_algorithm_.reset( | 108 send_algorithm_.reset( |
| 109 SendAlgorithmInterface::Create(clock_, &rtt_stats_, kBBR, stats_)); | 109 SendAlgorithmInterface::Create(clock_, &rtt_stats_, kBBR, stats_)); |
| 110 } | 110 } |
| 111 if (config.HasReceivedConnectionOptions() && | 111 if (config.HasReceivedConnectionOptions() && |
| 112 ContainsQuicTag(config.ReceivedConnectionOptions(), kRENO)) { | 112 ContainsQuicTag(config.ReceivedConnectionOptions(), kRENO)) { |
| 113 send_algorithm_.reset( | 113 send_algorithm_.reset( |
| 114 SendAlgorithmInterface::Create(clock_, &rtt_stats_, kReno, stats_)); | 114 SendAlgorithmInterface::Create(clock_, &rtt_stats_, kReno, stats_)); |
| 115 } | 115 } |
| 116 if (config.HasReceivedConnectionOptions() && | 116 if (is_server_) { |
| 117 ContainsQuicTag(config.ReceivedConnectionOptions(), kPACE)) { | 117 if (config.HasReceivedConnectionOptions() && |
| 118 ContainsQuicTag(config.ReceivedConnectionOptions(), kPACE)) { |
| 119 EnablePacing(); |
| 120 } |
| 121 } else if (config.HasSendConnectionOptions() && |
| 122 ContainsQuicTag(config.SendConnectionOptions(), kPACE)) { |
| 118 EnablePacing(); | 123 EnablePacing(); |
| 119 } | 124 } |
| 120 // TODO(ianswett): Remove the "HasReceivedLossDetection" branch once | 125 // TODO(ianswett): Remove the "HasReceivedLossDetection" branch once |
| 121 // the ConnectionOptions code is live everywhere. | 126 // the ConnectionOptions code is live everywhere. |
| 122 if ((config.HasReceivedLossDetection() && | 127 if ((config.HasReceivedLossDetection() && |
| 123 config.ReceivedLossDetection() == kTIME) || | 128 config.ReceivedLossDetection() == kTIME) || |
| 124 (config.HasReceivedConnectionOptions() && | 129 (config.HasReceivedConnectionOptions() && |
| 125 ContainsQuicTag(config.ReceivedConnectionOptions(), kTIME))) { | 130 ContainsQuicTag(config.ReceivedConnectionOptions(), kTIME))) { |
| 126 loss_algorithm_.reset(LossDetectionInterface::Create(kTime)); | 131 loss_algorithm_.reset(LossDetectionInterface::Create(kTime)); |
| 127 } | 132 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 new_sequence_number, | 177 new_sequence_number, |
| 173 transmission_type, | 178 transmission_type, |
| 174 clock_->ApproximateNow()); | 179 clock_->ApproximateNow()); |
| 175 } | 180 } |
| 176 } | 181 } |
| 177 | 182 |
| 178 void QuicSentPacketManager::OnIncomingAck(const QuicAckFrame& ack_frame, | 183 void QuicSentPacketManager::OnIncomingAck(const QuicAckFrame& ack_frame, |
| 179 QuicTime ack_receive_time) { | 184 QuicTime ack_receive_time) { |
| 180 QuicByteCount bytes_in_flight = unacked_packets_.bytes_in_flight(); | 185 QuicByteCount bytes_in_flight = unacked_packets_.bytes_in_flight(); |
| 181 | 186 |
| 187 UpdatePacketInformationReceivedByPeer(ack_frame); |
| 182 // We rely on delta_time_largest_observed to compute an RTT estimate, so | 188 // We rely on delta_time_largest_observed to compute an RTT estimate, so |
| 183 // we only update rtt when the largest observed gets acked. | 189 // we only update rtt when the largest observed gets acked. |
| 184 bool largest_observed_acked = MaybeUpdateRTT(ack_frame, ack_receive_time); | 190 bool largest_observed_acked = MaybeUpdateRTT(ack_frame, ack_receive_time); |
| 185 if (largest_observed_ < ack_frame.largest_observed) { | 191 DCHECK_GE(ack_frame.largest_observed, unacked_packets_.largest_observed()); |
| 186 largest_observed_ = ack_frame.largest_observed; | 192 unacked_packets_.IncreaseLargestObserved(ack_frame.largest_observed); |
| 187 unacked_packets_.IncreaseLargestObserved(largest_observed_); | 193 |
| 188 } | |
| 189 HandleAckForSentPackets(ack_frame); | 194 HandleAckForSentPackets(ack_frame); |
| 190 InvokeLossDetection(ack_receive_time); | 195 InvokeLossDetection(ack_receive_time); |
| 191 MaybeInvokeCongestionEvent(largest_observed_acked, bytes_in_flight); | 196 MaybeInvokeCongestionEvent(largest_observed_acked, bytes_in_flight); |
| 192 | 197 |
| 198 sustained_bandwidth_recorder_.RecordEstimate( |
| 199 send_algorithm_->InRecovery(), |
| 200 send_algorithm_->InSlowStart(), |
| 201 send_algorithm_->BandwidthEstimate(), |
| 202 ack_receive_time, |
| 203 clock_->WallNow(), |
| 204 rtt_stats_.SmoothedRtt()); |
| 205 |
| 193 // If we have received a truncated ack, then we need to clear out some | 206 // If we have received a truncated ack, then we need to clear out some |
| 194 // previous transmissions to allow the peer to actually ACK new packets. | 207 // previous transmissions to allow the peer to actually ACK new packets. |
| 195 if (ack_frame.is_truncated) { | 208 if (ack_frame.is_truncated) { |
| 196 unacked_packets_.ClearPreviousRetransmissions( | 209 unacked_packets_.ClearPreviousRetransmissions( |
| 197 ack_frame.missing_packets.size() / 2); | 210 ack_frame.missing_packets.size() / 2); |
| 198 } | 211 } |
| 199 | 212 |
| 200 // Anytime we are making forward progress and have a new RTT estimate, reset | 213 // Anytime we are making forward progress and have a new RTT estimate, reset |
| 201 // the backoff counters. | 214 // the backoff counters. |
| 202 if (largest_observed_acked) { | 215 if (largest_observed_acked) { |
| 203 // Reset all retransmit counters any time a new packet is acked. | 216 // Reset all retransmit counters any time a new packet is acked. |
| 204 consecutive_rto_count_ = 0; | 217 consecutive_rto_count_ = 0; |
| 205 consecutive_tlp_count_ = 0; | 218 consecutive_tlp_count_ = 0; |
| 206 consecutive_crypto_retransmission_count_ = 0; | 219 consecutive_crypto_retransmission_count_ = 0; |
| 207 } | 220 } |
| 208 | 221 |
| 209 if (debug_delegate_ != NULL) { | 222 if (debug_delegate_ != NULL) { |
| 210 debug_delegate_->OnIncomingAck(ack_frame, | 223 debug_delegate_->OnIncomingAck(ack_frame, |
| 211 ack_receive_time, | 224 ack_receive_time, |
| 212 largest_observed_, | 225 unacked_packets_.largest_observed(), |
| 213 largest_observed_acked, | 226 largest_observed_acked, |
| 214 GetLeastUnackedSentPacket()); | 227 GetLeastUnackedSentPacket()); |
| 215 } | 228 } |
| 216 } | 229 } |
| 217 | 230 |
| 231 void QuicSentPacketManager::UpdatePacketInformationReceivedByPeer( |
| 232 const QuicAckFrame& ack_frame) { |
| 233 if (ack_frame.missing_packets.empty()) { |
| 234 least_packet_awaited_by_peer_ = ack_frame.largest_observed + 1; |
| 235 } else { |
| 236 least_packet_awaited_by_peer_ = *(ack_frame.missing_packets.begin()); |
| 237 } |
| 238 } |
| 239 |
| 218 void QuicSentPacketManager::MaybeInvokeCongestionEvent( | 240 void QuicSentPacketManager::MaybeInvokeCongestionEvent( |
| 219 bool rtt_updated, QuicByteCount bytes_in_flight) { | 241 bool rtt_updated, QuicByteCount bytes_in_flight) { |
| 220 if (!rtt_updated && packets_acked_.empty() && packets_lost_.empty()) { | 242 if (!rtt_updated && packets_acked_.empty() && packets_lost_.empty()) { |
| 221 return; | 243 return; |
| 222 } | 244 } |
| 223 send_algorithm_->OnCongestionEvent(rtt_updated, bytes_in_flight, | 245 send_algorithm_->OnCongestionEvent(rtt_updated, bytes_in_flight, |
| 224 packets_acked_, packets_lost_); | 246 packets_acked_, packets_lost_); |
| 225 packets_acked_.clear(); | 247 packets_acked_.clear(); |
| 226 packets_lost_.clear(); | 248 packets_lost_.clear(); |
| 227 if (network_change_visitor_ != NULL) { | 249 if (network_change_visitor_ != NULL) { |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 return unacked_packets_.GetLeastUnackedSentPacket(); | 516 return unacked_packets_.GetLeastUnackedSentPacket(); |
| 495 } | 517 } |
| 496 | 518 |
| 497 bool QuicSentPacketManager::OnPacketSent( | 519 bool QuicSentPacketManager::OnPacketSent( |
| 498 QuicPacketSequenceNumber sequence_number, | 520 QuicPacketSequenceNumber sequence_number, |
| 499 QuicTime sent_time, | 521 QuicTime sent_time, |
| 500 QuicByteCount bytes, | 522 QuicByteCount bytes, |
| 501 TransmissionType transmission_type, | 523 TransmissionType transmission_type, |
| 502 HasRetransmittableData has_retransmittable_data) { | 524 HasRetransmittableData has_retransmittable_data) { |
| 503 DCHECK_LT(0u, sequence_number); | 525 DCHECK_LT(0u, sequence_number); |
| 526 DCHECK(unacked_packets_.IsUnacked(sequence_number)); |
| 504 LOG_IF(DFATAL, bytes == 0) << "Cannot send empty packets."; | 527 LOG_IF(DFATAL, bytes == 0) << "Cannot send empty packets."; |
| 505 if (pending_timer_transmission_count_ > 0) { | 528 if (pending_timer_transmission_count_ > 0) { |
| 506 --pending_timer_transmission_count_; | 529 --pending_timer_transmission_count_; |
| 507 } | 530 } |
| 508 // In rare circumstances, the packet could be serialized, sent, and then acked | |
| 509 // before OnPacketSent is called. | |
| 510 if (!unacked_packets_.IsUnacked(sequence_number)) { | |
| 511 return false; | |
| 512 } | |
| 513 | 531 |
| 514 if (unacked_packets_.bytes_in_flight() == 0) { | 532 if (unacked_packets_.bytes_in_flight() == 0) { |
| 515 // TODO(ianswett): Consider being less aggressive to force a new | 533 // TODO(ianswett): Consider being less aggressive to force a new |
| 516 // recent_min_rtt, likely by not discarding a relatively new sample. | 534 // recent_min_rtt, likely by not discarding a relatively new sample. |
| 517 DVLOG(1) << "Sampling a new recent min rtt within 2 samples. currently:" | 535 DVLOG(1) << "Sampling a new recent min rtt within 2 samples. currently:" |
| 518 << rtt_stats_.recent_min_rtt().ToMilliseconds() << "ms"; | 536 << rtt_stats_.recent_min_rtt().ToMilliseconds() << "ms"; |
| 519 rtt_stats_.SampleNewRecentMinRtt(kNumMinRttSamplesAfterQuiescence); | 537 rtt_stats_.SampleNewRecentMinRtt(kNumMinRttSamplesAfterQuiescence); |
| 520 } | 538 } |
| 521 | 539 |
| 522 // Only track packets as in flight that the send algorithm wants us to track. | 540 // Only track packets as in flight that the send algorithm wants us to track. |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 const QuicCongestionFeedbackFrame& frame, | 691 const QuicCongestionFeedbackFrame& frame, |
| 674 const QuicTime& feedback_receive_time) { | 692 const QuicTime& feedback_receive_time) { |
| 675 send_algorithm_->OnIncomingQuicCongestionFeedbackFrame( | 693 send_algorithm_->OnIncomingQuicCongestionFeedbackFrame( |
| 676 frame, feedback_receive_time); | 694 frame, feedback_receive_time); |
| 677 } | 695 } |
| 678 | 696 |
| 679 void QuicSentPacketManager::InvokeLossDetection(QuicTime time) { | 697 void QuicSentPacketManager::InvokeLossDetection(QuicTime time) { |
| 680 SequenceNumberSet lost_packets = | 698 SequenceNumberSet lost_packets = |
| 681 loss_algorithm_->DetectLostPackets(unacked_packets_, | 699 loss_algorithm_->DetectLostPackets(unacked_packets_, |
| 682 time, | 700 time, |
| 683 largest_observed_, | 701 unacked_packets_.largest_observed(), |
| 684 rtt_stats_); | 702 rtt_stats_); |
| 685 for (SequenceNumberSet::const_iterator it = lost_packets.begin(); | 703 for (SequenceNumberSet::const_iterator it = lost_packets.begin(); |
| 686 it != lost_packets.end(); ++it) { | 704 it != lost_packets.end(); ++it) { |
| 687 QuicPacketSequenceNumber sequence_number = *it; | 705 QuicPacketSequenceNumber sequence_number = *it; |
| 688 const TransmissionInfo& transmission_info = | 706 const TransmissionInfo& transmission_info = |
| 689 unacked_packets_.GetTransmissionInfo(sequence_number); | 707 unacked_packets_.GetTransmissionInfo(sequence_number); |
| 690 // TODO(ianswett): If it's expected the FEC packet may repair the loss, it | 708 // TODO(ianswett): If it's expected the FEC packet may repair the loss, it |
| 691 // should be recorded as a loss to the send algorithm, but not retransmitted | 709 // should be recorded as a loss to the send algorithm, but not retransmitted |
| 692 // until it's known whether the FEC packet arrived. | 710 // until it's known whether the FEC packet arrived. |
| 693 ++stats_->packets_lost; | 711 ++stats_->packets_lost; |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 } | 862 } |
| 845 | 863 |
| 846 QuicBandwidth QuicSentPacketManager::BandwidthEstimate() const { | 864 QuicBandwidth QuicSentPacketManager::BandwidthEstimate() const { |
| 847 return send_algorithm_->BandwidthEstimate(); | 865 return send_algorithm_->BandwidthEstimate(); |
| 848 } | 866 } |
| 849 | 867 |
| 850 bool QuicSentPacketManager::HasReliableBandwidthEstimate() const { | 868 bool QuicSentPacketManager::HasReliableBandwidthEstimate() const { |
| 851 return send_algorithm_->HasReliableBandwidthEstimate(); | 869 return send_algorithm_->HasReliableBandwidthEstimate(); |
| 852 } | 870 } |
| 853 | 871 |
| 872 const QuicSustainedBandwidthRecorder& |
| 873 QuicSentPacketManager::SustainedBandwidthRecorder() const { |
| 874 return sustained_bandwidth_recorder_; |
| 875 } |
| 876 |
| 854 QuicByteCount QuicSentPacketManager::GetCongestionWindow() const { | 877 QuicByteCount QuicSentPacketManager::GetCongestionWindow() const { |
| 855 return send_algorithm_->GetCongestionWindow(); | 878 return send_algorithm_->GetCongestionWindow(); |
| 856 } | 879 } |
| 857 | 880 |
| 858 QuicByteCount QuicSentPacketManager::GetSlowStartThreshold() const { | 881 QuicByteCount QuicSentPacketManager::GetSlowStartThreshold() const { |
| 859 return send_algorithm_->GetSlowStartThreshold(); | 882 return send_algorithm_->GetSlowStartThreshold(); |
| 860 } | 883 } |
| 861 | 884 |
| 862 void QuicSentPacketManager::EnablePacing() { | 885 void QuicSentPacketManager::EnablePacing() { |
| 863 if (using_pacing_) { | 886 if (using_pacing_) { |
| 864 return; | 887 return; |
| 865 } | 888 } |
| 866 | 889 |
| 867 // Set up a pacing sender with a 5 millisecond alarm granularity. | 890 // Set up a pacing sender with a 5 millisecond alarm granularity. |
| 868 using_pacing_ = true; | 891 using_pacing_ = true; |
| 869 send_algorithm_.reset( | 892 send_algorithm_.reset( |
| 870 new PacingSender(send_algorithm_.release(), | 893 new PacingSender(send_algorithm_.release(), |
| 871 QuicTime::Delta::FromMilliseconds(5), | 894 QuicTime::Delta::FromMilliseconds(5), |
| 872 kInitialUnpacedBurst)); | 895 kInitialUnpacedBurst)); |
| 873 } | 896 } |
| 874 | 897 |
| 875 } // namespace net | 898 } // namespace net |
| OLD | NEW |