| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/core/congestion_control/pacing_sender.h" | 5 #include "net/quic/core/congestion_control/pacing_sender.h" |
| 6 | 6 |
| 7 #include <string> |
| 8 |
| 7 #include "net/quic/core/quic_flags.h" | 9 #include "net/quic/core/quic_flags.h" |
| 8 | 10 |
| 9 using std::min; | 11 using std::min; |
| 10 | 12 |
| 11 namespace net { | 13 namespace net { |
| 12 namespace { | 14 namespace { |
| 13 | 15 |
| 14 // The estimated system alarm granularity. | 16 // The estimated system alarm granularity. |
| 15 static const QuicTime::Delta kAlarmGranularity = | 17 static const QuicTime::Delta kAlarmGranularity = |
| 16 QuicTime::Delta::FromMilliseconds(1); | 18 QuicTime::Delta::FromMilliseconds(1); |
| 17 | 19 |
| 18 // Configured maximum size of the burst coming out of quiescence. The burst | 20 // Configured maximum size of the burst coming out of quiescence. The burst |
| 19 // is never larger than the current CWND in packets. | 21 // is never larger than the current CWND in packets. |
| 20 static const uint32_t kInitialUnpacedBurst = 10; | 22 static const uint32_t kInitialUnpacedBurst = 10; |
| 21 | 23 |
| 22 } // namespace | 24 } // namespace |
| 23 | 25 |
| 24 PacingSender::PacingSender() | 26 PacingSender::PacingSender() |
| 25 : sender_(nullptr), | 27 : sender_(nullptr), |
| 26 max_pacing_rate_(QuicBandwidth::Zero()), | 28 max_pacing_rate_(QuicBandwidth::Zero()), |
| 27 burst_tokens_(kInitialUnpacedBurst), | 29 burst_tokens_(kInitialUnpacedBurst), |
| 28 last_delayed_packet_sent_time_(QuicTime::Zero()), | 30 last_delayed_packet_sent_time_(QuicTime::Zero()), |
| 29 ideal_next_packet_send_time_(QuicTime::Zero()), | 31 ideal_next_packet_send_time_(QuicTime::Zero()), |
| 30 was_last_send_delayed_(false), | 32 was_last_send_delayed_(false) {} |
| 31 owns_sender_(false) {} | |
| 32 | 33 |
| 33 PacingSender::~PacingSender() { | 34 PacingSender::~PacingSender() {} |
| 34 if (owns_sender_) { | 35 |
| 35 delete sender_; | 36 void PacingSender::set_sender(SendAlgorithmInterface* sender) { |
| 36 } | 37 DCHECK(sender != nullptr); |
| 38 sender_ = sender; |
| 37 } | 39 } |
| 38 | 40 |
| 39 void PacingSender::SetFromConfig(const QuicConfig& config, | 41 void PacingSender::OnCongestionEvent( |
| 40 Perspective perspective) { | 42 bool rtt_updated, |
| 41 sender_->SetFromConfig(config, perspective); | 43 QuicByteCount bytes_in_flight, |
| 42 } | 44 const SendAlgorithmInterface::CongestionVector& acked_packets, |
| 43 | 45 const SendAlgorithmInterface::CongestionVector& lost_packets) { |
| 44 void PacingSender::ResumeConnectionState( | 46 DCHECK(sender_ != nullptr); |
| 45 const CachedNetworkParameters& cached_network_params, | |
| 46 bool max_bandwidth_resumption) { | |
| 47 sender_->ResumeConnectionState(cached_network_params, | |
| 48 max_bandwidth_resumption); | |
| 49 } | |
| 50 | |
| 51 void PacingSender::SetNumEmulatedConnections(int num_connections) { | |
| 52 sender_->SetNumEmulatedConnections(num_connections); | |
| 53 } | |
| 54 | |
| 55 void PacingSender::SetMaxPacingRate(QuicBandwidth max_pacing_rate) { | |
| 56 max_pacing_rate_ = max_pacing_rate; | |
| 57 } | |
| 58 | |
| 59 void PacingSender::SetSender(SendAlgorithmInterface* sender, bool owns_sender) { | |
| 60 if (owns_sender_) { | |
| 61 delete sender_; | |
| 62 } | |
| 63 sender_ = sender; | |
| 64 owns_sender_ = owns_sender; | |
| 65 } | |
| 66 | |
| 67 void PacingSender::OnCongestionEvent(bool rtt_updated, | |
| 68 QuicByteCount bytes_in_flight, | |
| 69 const CongestionVector& acked_packets, | |
| 70 const CongestionVector& lost_packets) { | |
| 71 if (!lost_packets.empty()) { | 47 if (!lost_packets.empty()) { |
| 72 // Clear any burst tokens when entering recovery. | 48 // Clear any burst tokens when entering recovery. |
| 73 burst_tokens_ = 0; | 49 burst_tokens_ = 0; |
| 74 } | 50 } |
| 75 sender_->OnCongestionEvent(rtt_updated, bytes_in_flight, acked_packets, | 51 sender_->OnCongestionEvent(rtt_updated, bytes_in_flight, acked_packets, |
| 76 lost_packets); | 52 lost_packets); |
| 77 } | 53 } |
| 78 | 54 |
| 79 bool PacingSender::OnPacketSent( | 55 bool PacingSender::OnPacketSent( |
| 80 QuicTime sent_time, | 56 QuicTime sent_time, |
| 81 QuicByteCount bytes_in_flight, | 57 QuicByteCount bytes_in_flight, |
| 82 QuicPacketNumber packet_number, | 58 QuicPacketNumber packet_number, |
| 83 QuicByteCount bytes, | 59 QuicByteCount bytes, |
| 84 HasRetransmittableData has_retransmittable_data) { | 60 HasRetransmittableData has_retransmittable_data) { |
| 61 DCHECK(sender_ != nullptr); |
| 85 const bool in_flight = | 62 const bool in_flight = |
| 86 sender_->OnPacketSent(sent_time, bytes_in_flight, packet_number, bytes, | 63 sender_->OnPacketSent(sent_time, bytes_in_flight, packet_number, bytes, |
| 87 has_retransmittable_data); | 64 has_retransmittable_data); |
| 88 if (has_retransmittable_data != HAS_RETRANSMITTABLE_DATA) { | 65 if (has_retransmittable_data != HAS_RETRANSMITTABLE_DATA) { |
| 89 return in_flight; | 66 return in_flight; |
| 90 } | 67 } |
| 91 // If in recovery, the connection is not coming out of quiescence. | 68 // If in recovery, the connection is not coming out of quiescence. |
| 92 if (bytes_in_flight == 0 && !sender_->InRecovery()) { | 69 if (bytes_in_flight == 0 && !sender_->InRecovery()) { |
| 93 // Add more burst tokens anytime the connection is leaving quiescence, but | 70 // Add more burst tokens anytime the connection is leaving quiescence, but |
| 94 // limit it to the equivalent of a single bulk write, not exceeding the | 71 // limit it to the equivalent of a single bulk write, not exceeding the |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 was_last_send_delayed_ = false; | 105 was_last_send_delayed_ = false; |
| 129 last_delayed_packet_sent_time_ = QuicTime::Zero(); | 106 last_delayed_packet_sent_time_ = QuicTime::Zero(); |
| 130 } | 107 } |
| 131 } else { | 108 } else { |
| 132 ideal_next_packet_send_time_ = | 109 ideal_next_packet_send_time_ = |
| 133 std::max(ideal_next_packet_send_time_ + delay, sent_time + delay); | 110 std::max(ideal_next_packet_send_time_ + delay, sent_time + delay); |
| 134 } | 111 } |
| 135 return in_flight; | 112 return in_flight; |
| 136 } | 113 } |
| 137 | 114 |
| 138 void PacingSender::OnRetransmissionTimeout(bool packets_retransmitted) { | |
| 139 sender_->OnRetransmissionTimeout(packets_retransmitted); | |
| 140 } | |
| 141 | |
| 142 void PacingSender::OnConnectionMigration() { | |
| 143 sender_->OnConnectionMigration(); | |
| 144 } | |
| 145 | |
| 146 QuicTime::Delta PacingSender::TimeUntilSend( | 115 QuicTime::Delta PacingSender::TimeUntilSend( |
| 147 QuicTime now, | 116 QuicTime now, |
| 148 QuicByteCount bytes_in_flight) const { | 117 QuicByteCount bytes_in_flight) const { |
| 118 DCHECK(sender_ != nullptr); |
| 149 QuicTime::Delta time_until_send = | 119 QuicTime::Delta time_until_send = |
| 150 sender_->TimeUntilSend(now, bytes_in_flight); | 120 sender_->TimeUntilSend(now, bytes_in_flight); |
| 151 if (burst_tokens_ > 0 || bytes_in_flight == 0) { | 121 if (burst_tokens_ > 0 || bytes_in_flight == 0) { |
| 152 // Don't pace if we have burst tokens available or leaving quiescence. | 122 // Don't pace if we have burst tokens available or leaving quiescence. |
| 153 return time_until_send; | 123 return time_until_send; |
| 154 } | 124 } |
| 155 | 125 |
| 156 if (!time_until_send.IsZero()) { | 126 if (!time_until_send.IsZero()) { |
| 157 DCHECK(time_until_send.IsInfinite()); | 127 DCHECK(time_until_send.IsInfinite()); |
| 158 // The underlying sender prevents sending. | 128 // The underlying sender prevents sending. |
| 159 return time_until_send; | 129 return time_until_send; |
| 160 } | 130 } |
| 161 | 131 |
| 162 // If the next send time is within the alarm granularity, send immediately. | 132 // If the next send time is within the alarm granularity, send immediately. |
| 163 if (ideal_next_packet_send_time_ > now + kAlarmGranularity) { | 133 if (ideal_next_packet_send_time_ > now + kAlarmGranularity) { |
| 164 DVLOG(1) << "Delaying packet: " | 134 DVLOG(1) << "Delaying packet: " |
| 165 << (ideal_next_packet_send_time_ - now).ToMicroseconds(); | 135 << (ideal_next_packet_send_time_ - now).ToMicroseconds(); |
| 166 was_last_send_delayed_ = true; | 136 was_last_send_delayed_ = true; |
| 167 return ideal_next_packet_send_time_ - now; | 137 return ideal_next_packet_send_time_ - now; |
| 168 } | 138 } |
| 169 | 139 |
| 170 DVLOG(1) << "Sending packet now"; | 140 DVLOG(1) << "Sending packet now"; |
| 171 return QuicTime::Delta::Zero(); | 141 return QuicTime::Delta::Zero(); |
| 172 } | 142 } |
| 173 | 143 |
| 174 QuicBandwidth PacingSender::PacingRate(QuicByteCount bytes_in_flight) const { | 144 QuicBandwidth PacingSender::PacingRate(QuicByteCount bytes_in_flight) const { |
| 145 DCHECK(sender_ != nullptr); |
| 175 if (!max_pacing_rate_.IsZero()) { | 146 if (!max_pacing_rate_.IsZero()) { |
| 176 return QuicBandwidth::FromBitsPerSecond( | 147 return QuicBandwidth::FromBitsPerSecond( |
| 177 min(max_pacing_rate_.ToBitsPerSecond(), | 148 min(max_pacing_rate_.ToBitsPerSecond(), |
| 178 sender_->PacingRate(bytes_in_flight).ToBitsPerSecond())); | 149 sender_->PacingRate(bytes_in_flight).ToBitsPerSecond())); |
| 179 } | 150 } |
| 180 return sender_->PacingRate(bytes_in_flight); | 151 return sender_->PacingRate(bytes_in_flight); |
| 181 } | 152 } |
| 182 | 153 |
| 183 QuicBandwidth PacingSender::BandwidthEstimate() const { | |
| 184 return sender_->BandwidthEstimate(); | |
| 185 } | |
| 186 | |
| 187 QuicTime::Delta PacingSender::RetransmissionDelay() const { | |
| 188 return sender_->RetransmissionDelay(); | |
| 189 } | |
| 190 | |
| 191 QuicByteCount PacingSender::GetCongestionWindow() const { | |
| 192 return sender_->GetCongestionWindow(); | |
| 193 } | |
| 194 | |
| 195 bool PacingSender::InSlowStart() const { | |
| 196 return sender_->InSlowStart(); | |
| 197 } | |
| 198 | |
| 199 bool PacingSender::InRecovery() const { | |
| 200 return sender_->InRecovery(); | |
| 201 } | |
| 202 | |
| 203 QuicByteCount PacingSender::GetSlowStartThreshold() const { | |
| 204 return sender_->GetSlowStartThreshold(); | |
| 205 } | |
| 206 | |
| 207 CongestionControlType PacingSender::GetCongestionControlType() const { | |
| 208 return sender_->GetCongestionControlType(); | |
| 209 } | |
| 210 | |
| 211 } // namespace net | 154 } // namespace net |
| OLD | NEW |