[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "net/quic/quic_sent_packet_manager.h" |
| 6 | |
[email protected] | b9475b58 | 2014-03-20 20:04:33 | [diff] [blame] | 7 | #include <algorithm> |
| 8 | |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 9 | #include "base/logging.h" |
| 10 | #include "base/stl_util.h" |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 11 | #include "net/quic/congestion_control/pacing_sender.h" |
[email protected] | 79d13dcb | 2014-02-05 07:23:13 | [diff] [blame] | 12 | #include "net/quic/crypto/crypto_protocol.h" |
[email protected] | 0741d71 | 2013-10-08 00:10:11 | [diff] [blame] | 13 | #include "net/quic/quic_ack_notifier_manager.h" |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 14 | #include "net/quic/quic_connection_stats.h" |
[email protected] | 9bb57c7 | 2014-03-31 20:36:04 | [diff] [blame] | 15 | #include "net/quic/quic_flags.h" |
[email protected] | cc7ec7f | 2014-01-25 20:32:51 | [diff] [blame] | 16 | #include "net/quic/quic_utils_chromium.h" |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 17 | |
| 18 | using std::make_pair; |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 19 | using std::max; |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 20 | using std::min; |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 21 | |
| 22 | namespace net { |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 23 | namespace { |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 24 | static const int kDefaultRetransmissionTimeMs = 500; |
| 25 | // TCP RFC calls for 1 second RTO however Linux differs from this default and |
| 26 | // define the minimum RTO to 200ms, we will use the same until we have data to |
| 27 | // support a higher or lower value. |
| 28 | static const int kMinRetransmissionTimeMs = 200; |
| 29 | static const int kMaxRetransmissionTimeMs = 60000; |
| 30 | static const size_t kMaxRetransmissions = 10; |
| 31 | |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 32 | // Only exponentially back off the handshake timer 5 times due to a timeout. |
| 33 | static const size_t kMaxHandshakeRetransmissionBackoffs = 5; |
| 34 | static const size_t kMinHandshakeTimeoutMs = 10; |
| 35 | |
| 36 | // Sends up to two tail loss probes before firing an RTO, |
| 37 | // per draft RFC draft-dukkipati-tcpm-tcp-loss-probe. |
| 38 | static const size_t kDefaultMaxTailLossProbes = 2; |
| 39 | static const int64 kMinTailLossProbeTimeoutMs = 10; |
| 40 | |
[email protected] | ce7bb141 | 2014-05-17 15:51:33 | [diff] [blame] | 41 | // Number of samples before we force a new recent min rtt to be captured. |
| 42 | static const size_t kNumMinRttSamplesAfterQuiescence = 2; |
| 43 | |
[email protected] | 0c6b10ad | 2014-07-02 19:47:00 | [diff] [blame^] | 44 | // Number of unpaced packets to send after quiescence. |
| 45 | static const size_t kInitialUnpacedBurst = 10; |
| 46 | |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 47 | bool HasCryptoHandshake(const TransmissionInfo& transmission_info) { |
[email protected] | cb23a92 | 2014-02-20 17:42:38 | [diff] [blame] | 48 | if (transmission_info.retransmittable_frames == NULL) { |
| 49 | return false; |
| 50 | } |
| 51 | return transmission_info.retransmittable_frames->HasCryptoHandshake() == |
| 52 | IS_HANDSHAKE; |
| 53 | } |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 54 | |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 55 | } // namespace |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 56 | |
| 57 | #define ENDPOINT (is_server_ ? "Server: " : " Client: ") |
| 58 | |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 59 | QuicSentPacketManager::QuicSentPacketManager(bool is_server, |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 60 | const QuicClock* clock, |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 61 | QuicConnectionStats* stats, |
[email protected] | c5cc9bd | 2014-03-31 23:17:14 | [diff] [blame] | 62 | CongestionFeedbackType type, |
| 63 | LossDetectionType loss_type) |
[email protected] | ffc34bf | 2014-03-07 02:42:02 | [diff] [blame] | 64 | : unacked_packets_(), |
[email protected] | cb23a92 | 2014-02-20 17:42:38 | [diff] [blame] | 65 | is_server_(is_server), |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 66 | clock_(clock), |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 67 | stats_(stats), |
[email protected] | 730b35d7 | 2014-06-05 03:23:22 | [diff] [blame] | 68 | debug_delegate_(NULL), |
[email protected] | ffc34bf | 2014-03-07 02:42:02 | [diff] [blame] | 69 | send_algorithm_( |
| 70 | SendAlgorithmInterface::Create(clock, &rtt_stats_, type, stats)), |
[email protected] | c5cc9bd | 2014-03-31 23:17:14 | [diff] [blame] | 71 | loss_algorithm_(LossDetectionInterface::Create(loss_type)), |
[email protected] | 93dd91f | 2014-02-27 00:09:03 | [diff] [blame] | 72 | largest_observed_(0), |
[email protected] | cc1aa27 | 2014-06-30 19:48:22 | [diff] [blame] | 73 | first_rto_transmission_(0), |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 74 | consecutive_rto_count_(0), |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 75 | consecutive_tlp_count_(0), |
| 76 | consecutive_crypto_retransmission_count_(0), |
[email protected] | 9cda5fd | 2014-06-03 10:20:28 | [diff] [blame] | 77 | pending_tlp_transmission_(false), |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 78 | max_tail_loss_probes_(kDefaultMaxTailLossProbes), |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 79 | using_pacing_(false) { |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | QuicSentPacketManager::~QuicSentPacketManager() { |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | void QuicSentPacketManager::SetFromConfig(const QuicConfig& config) { |
[email protected] | 2d43c4012 | 2014-04-21 14:51:27 | [diff] [blame] | 86 | if (config.HasReceivedInitialRoundTripTimeUs() && |
| 87 | config.ReceivedInitialRoundTripTimeUs() > 0) { |
| 88 | rtt_stats_.set_initial_rtt_us(min(kMaxInitialRoundTripTimeUs, |
| 89 | config.ReceivedInitialRoundTripTimeUs())); |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 90 | } |
[email protected] | 9cda5fd | 2014-06-03 10:20:28 | [diff] [blame] | 91 | // TODO(ianswett): BBR is currently a server only feature. |
[email protected] | 9dc43a1 | 2014-06-26 23:40:14 | [diff] [blame] | 92 | if (config.HasReceivedConnectionOptions() && |
| 93 | ContainsQuicTag(config.ReceivedConnectionOptions(), kTBBR)) { |
[email protected] | 9cda5fd | 2014-06-03 10:20:28 | [diff] [blame] | 94 | send_algorithm_.reset( |
| 95 | SendAlgorithmInterface::Create(clock_, &rtt_stats_, kTCPBBR, stats_)); |
| 96 | } |
[email protected] | 9dc43a1 | 2014-06-26 23:40:14 | [diff] [blame] | 97 | if (config.congestion_feedback() == kPACE || |
| 98 | (config.HasReceivedConnectionOptions() && |
| 99 | ContainsQuicTag(config.ReceivedConnectionOptions(), kPACE))) { |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 100 | MaybeEnablePacing(); |
| 101 | } |
[email protected] | 9dc43a1 | 2014-06-26 23:40:14 | [diff] [blame] | 102 | // TODO(ianswett): Remove the "HasReceivedLossDetection" branch once |
| 103 | // the ConnectionOptions code is live everywhere. |
| 104 | if ((config.HasReceivedLossDetection() && |
| 105 | config.ReceivedLossDetection() == kTIME) || |
| 106 | (config.HasReceivedConnectionOptions() && |
| 107 | ContainsQuicTag(config.ReceivedConnectionOptions(), kTIME))) { |
[email protected] | c5cc9bd | 2014-03-31 23:17:14 | [diff] [blame] | 108 | loss_algorithm_.reset(LossDetectionInterface::Create(kTime)); |
| 109 | } |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 110 | send_algorithm_->SetFromConfig(config, is_server_); |
| 111 | } |
| 112 | |
[email protected] | c068020 | 2013-12-18 04:52:34 | [diff] [blame] | 113 | // TODO(ianswett): Combine this method with OnPacketSent once packets are always |
| 114 | // sent in order and the connection tracks RetransmittableFrames for longer. |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 115 | void QuicSentPacketManager::OnSerializedPacket( |
[email protected] | 457d695 | 2013-12-13 09:24:58 | [diff] [blame] | 116 | const SerializedPacket& serialized_packet) { |
[email protected] | c068020 | 2013-12-18 04:52:34 | [diff] [blame] | 117 | if (serialized_packet.retransmittable_frames) { |
| 118 | ack_notifier_manager_.OnSerializedPacket(serialized_packet); |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 119 | } |
| 120 | |
[email protected] | cb23a92 | 2014-02-20 17:42:38 | [diff] [blame] | 121 | unacked_packets_.AddPacket(serialized_packet); |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | void QuicSentPacketManager::OnRetransmittedPacket( |
| 125 | QuicPacketSequenceNumber old_sequence_number, |
| 126 | QuicPacketSequenceNumber new_sequence_number) { |
[email protected] | 730b35d7 | 2014-06-05 03:23:22 | [diff] [blame] | 127 | TransmissionType transmission_type; |
| 128 | PendingRetransmissionMap::iterator it = |
| 129 | pending_retransmissions_.find(old_sequence_number); |
| 130 | if (it != pending_retransmissions_.end()) { |
| 131 | transmission_type = it->second; |
| 132 | pending_retransmissions_.erase(it); |
| 133 | } else { |
| 134 | DLOG(DFATAL) << "Expected sequence number to be in " |
| 135 | "pending_retransmissions_. sequence_number: " << old_sequence_number; |
| 136 | transmission_type = NOT_RETRANSMISSION; |
| 137 | } |
[email protected] | 0741d71 | 2013-10-08 00:10:11 | [diff] [blame] | 138 | |
| 139 | // A notifier may be waiting to hear about ACKs for the original sequence |
| 140 | // number. Inform them that the sequence number has changed. |
| 141 | ack_notifier_manager_.UpdateSequenceNumber(old_sequence_number, |
| 142 | new_sequence_number); |
| 143 | |
[email protected] | cb23a92 | 2014-02-20 17:42:38 | [diff] [blame] | 144 | unacked_packets_.OnRetransmittedPacket(old_sequence_number, |
[email protected] | 730b35d7 | 2014-06-05 03:23:22 | [diff] [blame] | 145 | new_sequence_number, |
| 146 | transmission_type); |
[email protected] | c67a82cb | 2013-09-24 02:53:21 | [diff] [blame] | 147 | } |
| 148 | |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 149 | void QuicSentPacketManager::OnIncomingAck( |
[email protected] | 2d43c4012 | 2014-04-21 14:51:27 | [diff] [blame] | 150 | const ReceivedPacketInfo& received_info, |
| 151 | QuicTime ack_receive_time) { |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 152 | QuicByteCount bytes_in_flight = unacked_packets_.bytes_in_flight(); |
| 153 | |
[email protected] | 9f0dcd4e | 2014-01-16 15:58:14 | [diff] [blame] | 154 | // We rely on delta_time_largest_observed to compute an RTT estimate, so |
| 155 | // we only update rtt when the largest observed gets acked. |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 156 | bool largest_observed_acked = MaybeUpdateRTT(received_info, ack_receive_time); |
[email protected] | aa7e4ef | 2014-05-28 03:53:15 | [diff] [blame] | 157 | if (largest_observed_ < received_info.largest_observed) { |
| 158 | largest_observed_ = received_info.largest_observed; |
| 159 | unacked_packets_.IncreaseLargestObserved(largest_observed_); |
| 160 | } |
[email protected] | e6ccc1a6 | 2013-12-02 07:02:12 | [diff] [blame] | 161 | HandleAckForSentPackets(received_info); |
[email protected] | ef0da58 | 2014-05-09 07:16:30 | [diff] [blame] | 162 | InvokeLossDetection(ack_receive_time); |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 163 | MaybeInvokeCongestionEvent(largest_observed_acked, bytes_in_flight); |
[email protected] | 41fb637 | 2013-12-10 05:26:40 | [diff] [blame] | 164 | |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 165 | // If we have received a truncated ack, then we need to clear out some |
| 166 | // previous transmissions to allow the peer to actually ACK new packets. |
| 167 | if (received_info.is_truncated) { |
| 168 | unacked_packets_.ClearPreviousRetransmissions( |
| 169 | received_info.missing_packets.size() / 2); |
| 170 | } |
| 171 | |
[email protected] | 9f0dcd4e | 2014-01-16 15:58:14 | [diff] [blame] | 172 | // Anytime we are making forward progress and have a new RTT estimate, reset |
| 173 | // the backoff counters. |
| 174 | if (largest_observed_acked) { |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 175 | // Reset all retransmit counters any time a new packet is acked. |
[email protected] | 41fb637 | 2013-12-10 05:26:40 | [diff] [blame] | 176 | consecutive_rto_count_ = 0; |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 177 | consecutive_tlp_count_ = 0; |
| 178 | consecutive_crypto_retransmission_count_ = 0; |
[email protected] | 41fb637 | 2013-12-10 05:26:40 | [diff] [blame] | 179 | } |
[email protected] | c67a82cb | 2013-09-24 02:53:21 | [diff] [blame] | 180 | } |
| 181 | |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 182 | void QuicSentPacketManager::MaybeInvokeCongestionEvent( |
| 183 | bool rtt_updated, QuicByteCount bytes_in_flight) { |
| 184 | if (rtt_updated || !packets_acked_.empty() || |
| 185 | !packets_lost_.empty()) { |
| 186 | send_algorithm_->OnCongestionEvent( |
| 187 | rtt_updated, bytes_in_flight, packets_acked_, packets_lost_); |
| 188 | packets_acked_.clear(); |
| 189 | packets_lost_.clear(); |
| 190 | } |
| 191 | } |
| 192 | |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 193 | void QuicSentPacketManager::HandleAckForSentPackets( |
[email protected] | e6ccc1a6 | 2013-12-02 07:02:12 | [diff] [blame] | 194 | const ReceivedPacketInfo& received_info) { |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 195 | // Go through the packets we have not received an ack for and see if this |
| 196 | // incoming_ack shows they've been seen by the peer. |
[email protected] | 2d43c4012 | 2014-04-21 14:51:27 | [diff] [blame] | 197 | QuicTime::Delta delta_largest_observed = |
| 198 | received_info.delta_time_largest_observed; |
[email protected] | cb23a92 | 2014-02-20 17:42:38 | [diff] [blame] | 199 | QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 200 | while (it != unacked_packets_.end()) { |
| 201 | QuicPacketSequenceNumber sequence_number = it->first; |
[email protected] | c67a82cb | 2013-09-24 02:53:21 | [diff] [blame] | 202 | if (sequence_number > received_info.largest_observed) { |
[email protected] | c5cc9bd | 2014-03-31 23:17:14 | [diff] [blame] | 203 | // These packets are still in flight. |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 204 | break; |
| 205 | } |
[email protected] | c67a82cb | 2013-09-24 02:53:21 | [diff] [blame] | 206 | |
[email protected] | 622f9476 | 2013-11-20 21:58:10 | [diff] [blame] | 207 | if (IsAwaitingPacket(received_info, sequence_number)) { |
[email protected] | aa7e4ef | 2014-05-28 03:53:15 | [diff] [blame] | 208 | // Consider it multiple nacks when there is a gap between the missing |
| 209 | // packet and the largest observed, since the purpose of a nack |
| 210 | // threshold is to tolerate re-ordering. This handles both StretchAcks |
| 211 | // and Forward Acks. |
| 212 | // The nack count only increases when the largest observed increases. |
| 213 | size_t min_nacks = received_info.largest_observed - sequence_number; |
| 214 | // Truncated acks can nack the largest observed, so use a min of 1. |
| 215 | if (min_nacks == 0) { |
| 216 | min_nacks = 1; |
[email protected] | c5cc9bd | 2014-03-31 23:17:14 | [diff] [blame] | 217 | } |
[email protected] | aa7e4ef | 2014-05-28 03:53:15 | [diff] [blame] | 218 | unacked_packets_.NackPacket(sequence_number, min_nacks); |
| 219 | ++it; |
[email protected] | c67a82cb | 2013-09-24 02:53:21 | [diff] [blame] | 220 | continue; |
| 221 | } |
[email protected] | 622f9476 | 2013-11-20 21:58:10 | [diff] [blame] | 222 | // Packet was acked, so remove it from our unacked packet list. |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 223 | DVLOG(1) << ENDPOINT << "Got an ack for packet " << sequence_number; |
[email protected] | 622f9476 | 2013-11-20 21:58:10 | [diff] [blame] | 224 | // If data is associated with the most recent transmission of this |
| 225 | // packet, then inform the caller. |
[email protected] | aa7e4ef | 2014-05-28 03:53:15 | [diff] [blame] | 226 | if (it->second.in_flight) { |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 227 | packets_acked_[sequence_number] = it->second; |
| 228 | } |
[email protected] | aa7e4ef | 2014-05-28 03:53:15 | [diff] [blame] | 229 | it = MarkPacketHandled(it, delta_largest_observed); |
[email protected] | c67a82cb | 2013-09-24 02:53:21 | [diff] [blame] | 230 | } |
| 231 | |
[email protected] | bdf2d43 | 2014-02-09 10:45:41 | [diff] [blame] | 232 | // Discard any retransmittable frames associated with revived packets. |
| 233 | for (SequenceNumberSet::const_iterator revived_it = |
| 234 | received_info.revived_packets.begin(); |
| 235 | revived_it != received_info.revived_packets.end(); ++revived_it) { |
[email protected] | 2d43c4012 | 2014-04-21 14:51:27 | [diff] [blame] | 236 | MarkPacketRevived(*revived_it, delta_largest_observed); |
[email protected] | bdf2d43 | 2014-02-09 10:45:41 | [diff] [blame] | 237 | } |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 238 | } |
| 239 | |
[email protected] | c67a82cb | 2013-09-24 02:53:21 | [diff] [blame] | 240 | bool QuicSentPacketManager::HasRetransmittableFrames( |
| 241 | QuicPacketSequenceNumber sequence_number) const { |
[email protected] | cb23a92 | 2014-02-20 17:42:38 | [diff] [blame] | 242 | return unacked_packets_.HasRetransmittableFrames(sequence_number); |
[email protected] | c67a82cb | 2013-09-24 02:53:21 | [diff] [blame] | 243 | } |
| 244 | |
[email protected] | 41fb637 | 2013-12-10 05:26:40 | [diff] [blame] | 245 | void QuicSentPacketManager::RetransmitUnackedPackets( |
| 246 | RetransmissionType retransmission_type) { |
[email protected] | aa7e4ef | 2014-05-28 03:53:15 | [diff] [blame] | 247 | QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); |
| 248 | while (it != unacked_packets_.end()) { |
| 249 | const RetransmittableFrames* frames = it->second.retransmittable_frames; |
[email protected] | 698863af | 2014-02-07 22:32:15 | [diff] [blame] | 250 | // TODO(ianswett): Consider adding a new retransmission type which removes |
| 251 | // all these old packets from unacked and retransmits them as new sequence |
| 252 | // numbers with no connection to the previous ones. |
| 253 | if (frames != NULL && (retransmission_type == ALL_PACKETS || |
| 254 | frames->encryption_level() == ENCRYPTION_INITIAL)) { |
[email protected] | aa7e4ef | 2014-05-28 03:53:15 | [diff] [blame] | 255 | MarkForRetransmission(it->first, ALL_UNACKED_RETRANSMISSION); |
[email protected] | 698863af | 2014-02-07 22:32:15 | [diff] [blame] | 256 | } |
[email protected] | aa7e4ef | 2014-05-28 03:53:15 | [diff] [blame] | 257 | ++it; |
[email protected] | 41fb637 | 2013-12-10 05:26:40 | [diff] [blame] | 258 | } |
| 259 | } |
| 260 | |
[email protected] | 6d9ca3b | 2014-05-13 07:44:22 | [diff] [blame] | 261 | void QuicSentPacketManager::NeuterUnencryptedPackets() { |
[email protected] | aa7e4ef | 2014-05-28 03:53:15 | [diff] [blame] | 262 | QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); |
| 263 | while (it != unacked_packets_.end()) { |
| 264 | const RetransmittableFrames* frames = it->second.retransmittable_frames; |
| 265 | QuicPacketSequenceNumber sequence_number = it->first; |
| 266 | ++it; |
[email protected] | 82168ee2 | 2014-04-30 22:25:48 | [diff] [blame] | 267 | if (frames != NULL && frames->encryption_level() == ENCRYPTION_NONE) { |
[email protected] | 27e16d0 | 2014-05-14 21:28:02 | [diff] [blame] | 268 | // Once you're forward secure, no unencrypted packets will be sent, crypto |
| 269 | // or otherwise. Unencrypted packets are neutered and abandoned, to ensure |
| 270 | // they are not retransmitted or considered lost from a congestion control |
| 271 | // perspective. |
[email protected] | aa7e4ef | 2014-05-28 03:53:15 | [diff] [blame] | 272 | pending_retransmissions_.erase(sequence_number); |
| 273 | unacked_packets_.RemoveFromInFlight(sequence_number); |
| 274 | // RemoveRetransmittibility is safe because only the newest sequence |
| 275 | // number can have frames. |
| 276 | unacked_packets_.RemoveRetransmittability(sequence_number); |
[email protected] | 82168ee2 | 2014-04-30 22:25:48 | [diff] [blame] | 277 | } |
[email protected] | 82168ee2 | 2014-04-30 22:25:48 | [diff] [blame] | 278 | } |
| 279 | } |
| 280 | |
[email protected] | c068020 | 2013-12-18 04:52:34 | [diff] [blame] | 281 | void QuicSentPacketManager::MarkForRetransmission( |
[email protected] | 45a3e15 | 2013-09-25 16:35:11 | [diff] [blame] | 282 | QuicPacketSequenceNumber sequence_number, |
| 283 | TransmissionType transmission_type) { |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 284 | const TransmissionInfo& transmission_info = |
[email protected] | cb23a92 | 2014-02-20 17:42:38 | [diff] [blame] | 285 | unacked_packets_.GetTransmissionInfo(sequence_number); |
| 286 | LOG_IF(DFATAL, transmission_info.retransmittable_frames == NULL); |
[email protected] | 6d9ca3b | 2014-05-13 07:44:22 | [diff] [blame] | 287 | if (transmission_type != TLP_RETRANSMISSION) { |
[email protected] | aa7e4ef | 2014-05-28 03:53:15 | [diff] [blame] | 288 | unacked_packets_.RemoveFromInFlight(sequence_number); |
[email protected] | 6d9ca3b | 2014-05-13 07:44:22 | [diff] [blame] | 289 | } |
[email protected] | c068020 | 2013-12-18 04:52:34 | [diff] [blame] | 290 | // TODO(ianswett): Currently the RTO can fire while there are pending NACK |
| 291 | // retransmissions for the same data, which is not ideal. |
[email protected] | 45a3e15 | 2013-09-25 16:35:11 | [diff] [blame] | 292 | if (ContainsKey(pending_retransmissions_, sequence_number)) { |
[email protected] | c068020 | 2013-12-18 04:52:34 | [diff] [blame] | 293 | return; |
[email protected] | 45a3e15 | 2013-09-25 16:35:11 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | pending_retransmissions_[sequence_number] = transmission_type; |
[email protected] | 45a3e15 | 2013-09-25 16:35:11 | [diff] [blame] | 297 | } |
| 298 | |
[email protected] | 730b35d7 | 2014-06-05 03:23:22 | [diff] [blame] | 299 | void QuicSentPacketManager::RecordSpuriousRetransmissions( |
| 300 | const SequenceNumberSet& all_transmissions, |
| 301 | QuicPacketSequenceNumber acked_sequence_number) { |
[email protected] | cc1aa27 | 2014-06-30 19:48:22 | [diff] [blame] | 302 | if (acked_sequence_number < first_rto_transmission_) { |
| 303 | // Cancel all pending RTO transmissions and restore their in flight status. |
| 304 | // Replace SRTT with latest_rtt and increase the variance to prevent |
| 305 | // a spurious RTO from happening again. |
| 306 | rtt_stats_.ExpireSmoothedMetrics(); |
| 307 | for (PendingRetransmissionMap::const_iterator it = |
| 308 | pending_retransmissions_.begin(); |
| 309 | it != pending_retransmissions_.end(); ++it) { |
| 310 | DCHECK_EQ(it->second, RTO_RETRANSMISSION); |
| 311 | unacked_packets_.RestoreInFlight(it->first); |
| 312 | } |
| 313 | pending_retransmissions_.clear(); |
| 314 | send_algorithm_->RevertRetransmissionTimeout(); |
| 315 | first_rto_transmission_ = 0; |
| 316 | ++stats_->spurious_rto_count; |
| 317 | } |
[email protected] | 730b35d7 | 2014-06-05 03:23:22 | [diff] [blame] | 318 | for (SequenceNumberSet::const_iterator |
| 319 | it = all_transmissions.upper_bound(acked_sequence_number), |
| 320 | end = all_transmissions.end(); |
| 321 | it != end; |
| 322 | ++it) { |
| 323 | const TransmissionInfo& retransmit_info = |
| 324 | unacked_packets_.GetTransmissionInfo(*it); |
| 325 | |
| 326 | stats_->bytes_spuriously_retransmitted += retransmit_info.bytes_sent; |
| 327 | ++stats_->packets_spuriously_retransmitted; |
| 328 | if (debug_delegate_ != NULL) { |
| 329 | debug_delegate_->OnSpuriousPacketRetransmition( |
| 330 | retransmit_info.transmission_type, |
| 331 | retransmit_info.bytes_sent); |
| 332 | } |
| 333 | } |
| 334 | } |
| 335 | |
[email protected] | 45a3e15 | 2013-09-25 16:35:11 | [diff] [blame] | 336 | bool QuicSentPacketManager::HasPendingRetransmissions() const { |
| 337 | return !pending_retransmissions_.empty(); |
| 338 | } |
| 339 | |
| 340 | QuicSentPacketManager::PendingRetransmission |
| 341 | QuicSentPacketManager::NextPendingRetransmission() { |
| 342 | DCHECK(!pending_retransmissions_.empty()); |
| 343 | QuicPacketSequenceNumber sequence_number = |
| 344 | pending_retransmissions_.begin()->first; |
[email protected] | 9bb57c7 | 2014-03-31 20:36:04 | [diff] [blame] | 345 | TransmissionType transmission_type = pending_retransmissions_.begin()->second; |
| 346 | if (unacked_packets_.HasPendingCryptoPackets()) { |
| 347 | // Ensure crypto packets are retransmitted before other packets. |
| 348 | PendingRetransmissionMap::const_iterator it = |
| 349 | pending_retransmissions_.begin(); |
| 350 | do { |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 351 | if (HasCryptoHandshake(unacked_packets_.GetTransmissionInfo(it->first))) { |
[email protected] | 9bb57c7 | 2014-03-31 20:36:04 | [diff] [blame] | 352 | sequence_number = it->first; |
| 353 | transmission_type = it->second; |
| 354 | break; |
| 355 | } |
| 356 | ++it; |
| 357 | } while (it != pending_retransmissions_.end()); |
| 358 | } |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 359 | DCHECK(unacked_packets_.IsUnacked(sequence_number)) << sequence_number; |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 360 | const TransmissionInfo& transmission_info = |
[email protected] | cb23a92 | 2014-02-20 17:42:38 | [diff] [blame] | 361 | unacked_packets_.GetTransmissionInfo(sequence_number); |
[email protected] | 14a9575 | 2014-01-08 19:01:52 | [diff] [blame] | 362 | DCHECK(transmission_info.retransmittable_frames); |
[email protected] | 45a3e15 | 2013-09-25 16:35:11 | [diff] [blame] | 363 | |
| 364 | return PendingRetransmission(sequence_number, |
[email protected] | 9bb57c7 | 2014-03-31 20:36:04 | [diff] [blame] | 365 | transmission_type, |
[email protected] | 14a9575 | 2014-01-08 19:01:52 | [diff] [blame] | 366 | *transmission_info.retransmittable_frames, |
| 367 | transmission_info.sequence_number_length); |
[email protected] | 45a3e15 | 2013-09-25 16:35:11 | [diff] [blame] | 368 | } |
| 369 | |
[email protected] | 2d43c4012 | 2014-04-21 14:51:27 | [diff] [blame] | 370 | void QuicSentPacketManager::MarkPacketRevived( |
| 371 | QuicPacketSequenceNumber sequence_number, |
| 372 | QuicTime::Delta delta_largest_observed) { |
| 373 | if (!unacked_packets_.IsUnacked(sequence_number)) { |
| 374 | return; |
| 375 | } |
[email protected] | 2d43c4012 | 2014-04-21 14:51:27 | [diff] [blame] | 376 | |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 377 | const TransmissionInfo& transmission_info = |
[email protected] | 2d43c4012 | 2014-04-21 14:51:27 | [diff] [blame] | 378 | unacked_packets_.GetTransmissionInfo(sequence_number); |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 379 | QuicPacketSequenceNumber newest_transmission = |
| 380 | *transmission_info.all_transmissions->rbegin(); |
| 381 | // This packet has been revived at the receiver. If we were going to |
| 382 | // retransmit it, do not retransmit it anymore. |
| 383 | pending_retransmissions_.erase(newest_transmission); |
| 384 | |
[email protected] | 2d43c4012 | 2014-04-21 14:51:27 | [diff] [blame] | 385 | // The AckNotifierManager needs to be notified for revived packets, |
| 386 | // since it indicates the packet arrived from the appliction's perspective. |
| 387 | if (transmission_info.retransmittable_frames) { |
| 388 | ack_notifier_manager_.OnPacketAcked( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 389 | newest_transmission, delta_largest_observed); |
[email protected] | 2d43c4012 | 2014-04-21 14:51:27 | [diff] [blame] | 390 | } |
| 391 | |
[email protected] | aa7e4ef | 2014-05-28 03:53:15 | [diff] [blame] | 392 | unacked_packets_.RemoveRetransmittability(sequence_number); |
[email protected] | 2d43c4012 | 2014-04-21 14:51:27 | [diff] [blame] | 393 | } |
| 394 | |
[email protected] | 51cc134 | 2014-04-18 23:44:37 | [diff] [blame] | 395 | QuicUnackedPacketMap::const_iterator QuicSentPacketManager::MarkPacketHandled( |
[email protected] | aa7e4ef | 2014-05-28 03:53:15 | [diff] [blame] | 396 | QuicUnackedPacketMap::const_iterator it, |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 397 | QuicTime::Delta delta_largest_observed) { |
[email protected] | aa7e4ef | 2014-05-28 03:53:15 | [diff] [blame] | 398 | LOG_IF(DFATAL, it == unacked_packets_.end()) |
| 399 | << "MarkPacketHandled must be passed a valid iterator entry."; |
| 400 | const QuicPacketSequenceNumber sequence_number = it->first; |
| 401 | const TransmissionInfo& transmission_info = it->second; |
[email protected] | c068020 | 2013-12-18 04:52:34 | [diff] [blame] | 402 | |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 403 | QuicPacketSequenceNumber newest_transmission = |
| 404 | *transmission_info.all_transmissions->rbegin(); |
[email protected] | 6d9ca3b | 2014-05-13 07:44:22 | [diff] [blame] | 405 | // Remove the most recent packet, if it is pending retransmission. |
| 406 | pending_retransmissions_.erase(newest_transmission); |
| 407 | |
[email protected] | 730b35d7 | 2014-06-05 03:23:22 | [diff] [blame] | 408 | // Notify observers about the ACKed packet. |
| 409 | { |
| 410 | // The AckNotifierManager needs to be notified about the most recent |
| 411 | // transmission, since that's the one only one it tracks. |
| 412 | ack_notifier_manager_.OnPacketAcked(newest_transmission, |
| 413 | delta_largest_observed); |
| 414 | if (newest_transmission != sequence_number) { |
| 415 | RecordSpuriousRetransmissions(*transmission_info.all_transmissions, |
| 416 | sequence_number); |
| 417 | } |
| 418 | } |
| 419 | |
[email protected] | 6d9ca3b | 2014-05-13 07:44:22 | [diff] [blame] | 420 | // Two cases for MarkPacketHandled: |
| 421 | // 1) Handle the most recent or a crypto packet, so remove all transmissions. |
| 422 | // 2) Handle old transmission, keep all other pending transmissions, |
| 423 | // but disassociate them from one another. |
[email protected] | b9475b58 | 2014-03-20 20:04:33 | [diff] [blame] | 424 | |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 425 | // If it's a crypto handshake packet, discard it and all retransmissions, |
| 426 | // since they won't be acked now that one has been processed. |
[email protected] | 6d9ca3b | 2014-05-13 07:44:22 | [diff] [blame] | 427 | // TODO(ianswett): Instead of handling all crypto packets in a special way, |
| 428 | // only handle NULL encrypted packets in a special way. |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 429 | if (HasCryptoHandshake( |
| 430 | unacked_packets_.GetTransmissionInfo(newest_transmission))) { |
[email protected] | aa7e4ef | 2014-05-28 03:53:15 | [diff] [blame] | 431 | unacked_packets_.RemoveFromInFlight(newest_transmission); |
[email protected] | c67a82cb | 2013-09-24 02:53:21 | [diff] [blame] | 432 | } |
[email protected] | aa7e4ef | 2014-05-28 03:53:15 | [diff] [blame] | 433 | unacked_packets_.RemoveFromInFlight(sequence_number); |
| 434 | unacked_packets_.RemoveRetransmittability(sequence_number); |
[email protected] | 7ad98f4 | 2014-01-08 07:11:30 | [diff] [blame] | 435 | |
[email protected] | cb23a92 | 2014-02-20 17:42:38 | [diff] [blame] | 436 | QuicUnackedPacketMap::const_iterator next_unacked = unacked_packets_.begin(); |
[email protected] | c67a82cb | 2013-09-24 02:53:21 | [diff] [blame] | 437 | while (next_unacked != unacked_packets_.end() && |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 438 | next_unacked->first <= sequence_number) { |
[email protected] | 41fb637 | 2013-12-10 05:26:40 | [diff] [blame] | 439 | ++next_unacked; |
| 440 | } |
[email protected] | c67a82cb | 2013-09-24 02:53:21 | [diff] [blame] | 441 | return next_unacked; |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 442 | } |
| 443 | |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 444 | bool QuicSentPacketManager::IsUnacked( |
| 445 | QuicPacketSequenceNumber sequence_number) const { |
[email protected] | cb23a92 | 2014-02-20 17:42:38 | [diff] [blame] | 446 | return unacked_packets_.IsUnacked(sequence_number); |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 447 | } |
| 448 | |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 449 | bool QuicSentPacketManager::HasUnackedPackets() const { |
[email protected] | cb23a92 | 2014-02-20 17:42:38 | [diff] [blame] | 450 | return unacked_packets_.HasUnackedPackets(); |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | QuicPacketSequenceNumber |
| 454 | QuicSentPacketManager::GetLeastUnackedSentPacket() const { |
[email protected] | cb23a92 | 2014-02-20 17:42:38 | [diff] [blame] | 455 | return unacked_packets_.GetLeastUnackedSentPacket(); |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 456 | } |
| 457 | |
[email protected] | 2115d33ba | 2014-01-02 21:53:52 | [diff] [blame] | 458 | bool QuicSentPacketManager::OnPacketSent( |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 459 | QuicPacketSequenceNumber sequence_number, |
| 460 | QuicTime sent_time, |
| 461 | QuicByteCount bytes, |
| 462 | TransmissionType transmission_type, |
| 463 | HasRetransmittableData has_retransmittable_data) { |
| 464 | DCHECK_LT(0u, sequence_number); |
[email protected] | cb23a92 | 2014-02-20 17:42:38 | [diff] [blame] | 465 | LOG_IF(DFATAL, bytes == 0) << "Cannot send empty packets."; |
[email protected] | 9cda5fd | 2014-06-03 10:20:28 | [diff] [blame] | 466 | pending_tlp_transmission_ = false; |
[email protected] | 9f0dcd4e | 2014-01-16 15:58:14 | [diff] [blame] | 467 | // In rare circumstances, the packet could be serialized, sent, and then acked |
| 468 | // before OnPacketSent is called. |
[email protected] | cb23a92 | 2014-02-20 17:42:38 | [diff] [blame] | 469 | if (!unacked_packets_.IsUnacked(sequence_number)) { |
[email protected] | 9f0dcd4e | 2014-01-16 15:58:14 | [diff] [blame] | 470 | return false; |
| 471 | } |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 472 | |
[email protected] | ce7bb141 | 2014-05-17 15:51:33 | [diff] [blame] | 473 | if (unacked_packets_.bytes_in_flight() == 0) { |
| 474 | // TODO(ianswett): Consider being less aggressive to force a new |
| 475 | // recent_min_rtt, likely by not discarding a relatively new sample. |
| 476 | DVLOG(1) << "Sampling a new recent min rtt within 2 samples. currently:" |
| 477 | << rtt_stats_.recent_min_rtt().ToMilliseconds() << "ms"; |
| 478 | rtt_stats_.SampleNewRecentMinRtt(kNumMinRttSamplesAfterQuiescence); |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 479 | } |
[email protected] | c068020 | 2013-12-18 04:52:34 | [diff] [blame] | 480 | |
[email protected] | aa7e4ef | 2014-05-28 03:53:15 | [diff] [blame] | 481 | // Only track packets as in flight that the send algorithm wants us to track. |
| 482 | const bool in_flight = |
[email protected] | ce7bb141 | 2014-05-17 15:51:33 | [diff] [blame] | 483 | send_algorithm_->OnPacketSent(sent_time, |
| 484 | unacked_packets_.bytes_in_flight(), |
| 485 | sequence_number, |
| 486 | bytes, |
| 487 | has_retransmittable_data); |
[email protected] | aa7e4ef | 2014-05-28 03:53:15 | [diff] [blame] | 488 | unacked_packets_.SetSent(sequence_number, sent_time, bytes, in_flight); |
[email protected] | cb23a92 | 2014-02-20 17:42:38 | [diff] [blame] | 489 | |
[email protected] | ce7bb141 | 2014-05-17 15:51:33 | [diff] [blame] | 490 | // Reset the retransmission timer anytime a pending packet is sent. |
[email protected] | aa7e4ef | 2014-05-28 03:53:15 | [diff] [blame] | 491 | return in_flight; |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | void QuicSentPacketManager::OnRetransmissionTimeout() { |
[email protected] | aa7e4ef | 2014-05-28 03:53:15 | [diff] [blame] | 495 | DCHECK(unacked_packets_.HasInFlightPackets()); |
[email protected] | d8bbef6 | 2014-06-12 08:02:50 | [diff] [blame] | 496 | DCHECK(!pending_tlp_transmission_); |
[email protected] | 3aa9ca7 | 2014-02-27 19:39:43 | [diff] [blame] | 497 | // Handshake retransmission, timer based loss detection, TLP, and RTO are |
| 498 | // implemented with a single alarm. The handshake alarm is set when the |
| 499 | // handshake has not completed, the loss alarm is set when the loss detection |
| 500 | // algorithm says to, and the TLP and RTO alarms are set after that. |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 501 | // The TLP alarm is always set to run for under an RTO. |
| 502 | switch (GetRetransmissionMode()) { |
| 503 | case HANDSHAKE_MODE: |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 504 | ++stats_->crypto_retransmit_count; |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 505 | RetransmitCryptoPackets(); |
| 506 | return; |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 507 | case LOSS_MODE: { |
[email protected] | 3aa9ca7 | 2014-02-27 19:39:43 | [diff] [blame] | 508 | ++stats_->loss_timeout_count; |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 509 | QuicByteCount bytes_in_flight = unacked_packets_.bytes_in_flight(); |
[email protected] | 3aa9ca7 | 2014-02-27 19:39:43 | [diff] [blame] | 510 | InvokeLossDetection(clock_->Now()); |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 511 | MaybeInvokeCongestionEvent(false, bytes_in_flight); |
[email protected] | 3aa9ca7 | 2014-02-27 19:39:43 | [diff] [blame] | 512 | return; |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 513 | } |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 514 | case TLP_MODE: |
| 515 | // If no tail loss probe can be sent, because there are no retransmittable |
| 516 | // packets, execute a conventional RTO to abandon old packets. |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 517 | ++stats_->tlp_count; |
[email protected] | d8bbef6 | 2014-06-12 08:02:50 | [diff] [blame] | 518 | ++consecutive_tlp_count_; |
[email protected] | 9cda5fd | 2014-06-03 10:20:28 | [diff] [blame] | 519 | pending_tlp_transmission_ = true; |
[email protected] | d8bbef6 | 2014-06-12 08:02:50 | [diff] [blame] | 520 | // TLPs prefer sending new data instead of retransmitting data, so |
| 521 | // give the connection a chance to write before completing the TLP. |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 522 | return; |
| 523 | case RTO_MODE: |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 524 | ++stats_->rto_count; |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 525 | RetransmitAllPackets(); |
| 526 | return; |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | void QuicSentPacketManager::RetransmitCryptoPackets() { |
| 531 | DCHECK_EQ(HANDSHAKE_MODE, GetRetransmissionMode()); |
| 532 | // TODO(ianswett): Typical TCP implementations only retransmit 5 times. |
| 533 | consecutive_crypto_retransmission_count_ = |
| 534 | min(kMaxHandshakeRetransmissionBackoffs, |
| 535 | consecutive_crypto_retransmission_count_ + 1); |
| 536 | bool packet_retransmitted = false; |
[email protected] | cb23a92 | 2014-02-20 17:42:38 | [diff] [blame] | 537 | for (QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); |
[email protected] | 14a9575 | 2014-01-08 19:01:52 | [diff] [blame] | 538 | it != unacked_packets_.end(); ++it) { |
| 539 | QuicPacketSequenceNumber sequence_number = it->first; |
| 540 | const RetransmittableFrames* frames = it->second.retransmittable_frames; |
[email protected] | aa7e4ef | 2014-05-28 03:53:15 | [diff] [blame] | 541 | // Only retransmit frames which are in flight, and therefore have been sent. |
| 542 | if (!it->second.in_flight || frames == NULL || |
[email protected] | 14a9575 | 2014-01-08 19:01:52 | [diff] [blame] | 543 | frames->HasCryptoHandshake() != IS_HANDSHAKE) { |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 544 | continue; |
| 545 | } |
| 546 | packet_retransmitted = true; |
[email protected] | b9475b58 | 2014-03-20 20:04:33 | [diff] [blame] | 547 | MarkForRetransmission(sequence_number, HANDSHAKE_RETRANSMISSION); |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 548 | } |
| 549 | DCHECK(packet_retransmitted) << "No crypto packets found to retransmit."; |
| 550 | } |
| 551 | |
[email protected] | d8bbef6 | 2014-06-12 08:02:50 | [diff] [blame] | 552 | bool QuicSentPacketManager::MaybeRetransmitTailLossProbe() { |
| 553 | if (!pending_tlp_transmission_) { |
| 554 | return false; |
| 555 | } |
[email protected] | cb23a92 | 2014-02-20 17:42:38 | [diff] [blame] | 556 | for (QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); |
[email protected] | 14a9575 | 2014-01-08 19:01:52 | [diff] [blame] | 557 | it != unacked_packets_.end(); ++it) { |
| 558 | QuicPacketSequenceNumber sequence_number = it->first; |
| 559 | const RetransmittableFrames* frames = it->second.retransmittable_frames; |
[email protected] | aa7e4ef | 2014-05-28 03:53:15 | [diff] [blame] | 560 | // Only retransmit frames which are in flight, and therefore have been sent. |
| 561 | if (!it->second.in_flight || frames == NULL) { |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 562 | continue; |
| 563 | } |
| 564 | DCHECK_NE(IS_HANDSHAKE, frames->HasCryptoHandshake()); |
| 565 | MarkForRetransmission(sequence_number, TLP_RETRANSMISSION); |
[email protected] | d8bbef6 | 2014-06-12 08:02:50 | [diff] [blame] | 566 | return true; |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 567 | } |
| 568 | DLOG(FATAL) |
| 569 | << "No retransmittable packets, so RetransmitOldestPacket failed."; |
[email protected] | d8bbef6 | 2014-06-12 08:02:50 | [diff] [blame] | 570 | return false; |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | void QuicSentPacketManager::RetransmitAllPackets() { |
[email protected] | 9cda5fd | 2014-06-03 10:20:28 | [diff] [blame] | 574 | DVLOG(1) << "RetransmitAllPackets() called with " |
[email protected] | cb23a92 | 2014-02-20 17:42:38 | [diff] [blame] | 575 | << unacked_packets_.GetNumUnackedPackets() << " unacked packets."; |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 576 | // Request retransmission of all retransmittable packets when the RTO |
| 577 | // fires, and let the congestion manager decide how many to send |
| 578 | // immediately and the remaining packets will be queued. |
| 579 | // Abandon any non-retransmittable packets that are sufficiently old. |
[email protected] | 457d695 | 2013-12-13 09:24:58 | [diff] [blame] | 580 | bool packets_retransmitted = false; |
[email protected] | aa7e4ef | 2014-05-28 03:53:15 | [diff] [blame] | 581 | QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); |
| 582 | while (it != unacked_packets_.end()) { |
| 583 | const RetransmittableFrames* frames = it->second.retransmittable_frames; |
| 584 | QuicPacketSequenceNumber sequence_number = it->first; |
| 585 | ++it; |
| 586 | if (frames != NULL) { |
[email protected] | 457d695 | 2013-12-13 09:24:58 | [diff] [blame] | 587 | packets_retransmitted = true; |
[email protected] | aa7e4ef | 2014-05-28 03:53:15 | [diff] [blame] | 588 | MarkForRetransmission(sequence_number, RTO_RETRANSMISSION); |
[email protected] | 6d9ca3b | 2014-05-13 07:44:22 | [diff] [blame] | 589 | } else { |
[email protected] | aa7e4ef | 2014-05-28 03:53:15 | [diff] [blame] | 590 | unacked_packets_.RemoveFromInFlight(sequence_number); |
[email protected] | 41fb637 | 2013-12-10 05:26:40 | [diff] [blame] | 591 | } |
| 592 | } |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 593 | |
[email protected] | 7ad98f4 | 2014-01-08 07:11:30 | [diff] [blame] | 594 | send_algorithm_->OnRetransmissionTimeout(packets_retransmitted); |
[email protected] | 457d695 | 2013-12-13 09:24:58 | [diff] [blame] | 595 | if (packets_retransmitted) { |
[email protected] | cc1aa27 | 2014-06-30 19:48:22 | [diff] [blame] | 596 | if (consecutive_rto_count_ == 0) { |
| 597 | first_rto_transmission_ = unacked_packets_.largest_sent_packet() + 1; |
| 598 | } |
[email protected] | 457d695 | 2013-12-13 09:24:58 | [diff] [blame] | 599 | ++consecutive_rto_count_; |
[email protected] | 41fb637 | 2013-12-10 05:26:40 | [diff] [blame] | 600 | } |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 601 | } |
| 602 | |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 603 | QuicSentPacketManager::RetransmissionTimeoutMode |
| 604 | QuicSentPacketManager::GetRetransmissionMode() const { |
[email protected] | aa7e4ef | 2014-05-28 03:53:15 | [diff] [blame] | 605 | DCHECK(unacked_packets_.HasInFlightPackets()); |
[email protected] | ffc34bf | 2014-03-07 02:42:02 | [diff] [blame] | 606 | if (unacked_packets_.HasPendingCryptoPackets()) { |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 607 | return HANDSHAKE_MODE; |
| 608 | } |
[email protected] | 3aa9ca7 | 2014-02-27 19:39:43 | [diff] [blame] | 609 | if (loss_algorithm_->GetLossTimeout() != QuicTime::Zero()) { |
| 610 | return LOSS_MODE; |
| 611 | } |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 612 | if (consecutive_tlp_count_ < max_tail_loss_probes_) { |
[email protected] | cb23a92 | 2014-02-20 17:42:38 | [diff] [blame] | 613 | if (unacked_packets_.HasUnackedRetransmittableFrames()) { |
| 614 | return TLP_MODE; |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 615 | } |
| 616 | } |
| 617 | return RTO_MODE; |
| 618 | } |
| 619 | |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 620 | void QuicSentPacketManager::OnIncomingQuicCongestionFeedbackFrame( |
[email protected] | 41fb637 | 2013-12-10 05:26:40 | [diff] [blame] | 621 | const QuicCongestionFeedbackFrame& frame, |
| 622 | const QuicTime& feedback_receive_time) { |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 623 | send_algorithm_->OnIncomingQuicCongestionFeedbackFrame( |
[email protected] | cb23a92 | 2014-02-20 17:42:38 | [diff] [blame] | 624 | frame, feedback_receive_time); |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 625 | } |
| 626 | |
[email protected] | 93dd91f | 2014-02-27 00:09:03 | [diff] [blame] | 627 | void QuicSentPacketManager::InvokeLossDetection(QuicTime time) { |
[email protected] | cb23a92 | 2014-02-20 17:42:38 | [diff] [blame] | 628 | SequenceNumberSet lost_packets = |
[email protected] | 93dd91f | 2014-02-27 00:09:03 | [diff] [blame] | 629 | loss_algorithm_->DetectLostPackets(unacked_packets_, |
| 630 | time, |
| 631 | largest_observed_, |
[email protected] | ffc34bf | 2014-03-07 02:42:02 | [diff] [blame] | 632 | rtt_stats_); |
[email protected] | cb23a92 | 2014-02-20 17:42:38 | [diff] [blame] | 633 | for (SequenceNumberSet::const_iterator it = lost_packets.begin(); |
| 634 | it != lost_packets.end(); ++it) { |
| 635 | QuicPacketSequenceNumber sequence_number = *it; |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 636 | const TransmissionInfo& transmission_info = |
| 637 | unacked_packets_.GetTransmissionInfo(sequence_number); |
[email protected] | cb23a92 | 2014-02-20 17:42:38 | [diff] [blame] | 638 | // TODO(ianswett): If it's expected the FEC packet may repair the loss, it |
| 639 | // should be recorded as a loss to the send algorithm, but not retransmitted |
| 640 | // until it's known whether the FEC packet arrived. |
| 641 | ++stats_->packets_lost; |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 642 | packets_lost_[sequence_number] = transmission_info; |
[email protected] | 6d9ca3b | 2014-05-13 07:44:22 | [diff] [blame] | 643 | DVLOG(1) << ENDPOINT << "Lost packet " << sequence_number; |
[email protected] | cb23a92 | 2014-02-20 17:42:38 | [diff] [blame] | 644 | |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 645 | if (transmission_info.retransmittable_frames != NULL) { |
[email protected] | b9475b58 | 2014-03-20 20:04:33 | [diff] [blame] | 646 | MarkForRetransmission(sequence_number, LOSS_RETRANSMISSION); |
[email protected] | cb23a92 | 2014-02-20 17:42:38 | [diff] [blame] | 647 | } else { |
| 648 | // Since we will not retransmit this, we need to remove it from |
| 649 | // unacked_packets_. This is either the current transmission of |
[email protected] | 6d9ca3b | 2014-05-13 07:44:22 | [diff] [blame] | 650 | // a packet whose previous transmission has been acked, a packet that has |
| 651 | // been TLP retransmitted, or an FEC packet. |
[email protected] | aa7e4ef | 2014-05-28 03:53:15 | [diff] [blame] | 652 | unacked_packets_.RemoveFromInFlight(sequence_number); |
[email protected] | cb23a92 | 2014-02-20 17:42:38 | [diff] [blame] | 653 | } |
| 654 | } |
| 655 | } |
| 656 | |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 657 | bool QuicSentPacketManager::MaybeUpdateRTT( |
[email protected] | 41fb637 | 2013-12-10 05:26:40 | [diff] [blame] | 658 | const ReceivedPacketInfo& received_info, |
| 659 | const QuicTime& ack_receive_time) { |
[email protected] | cb23a92 | 2014-02-20 17:42:38 | [diff] [blame] | 660 | if (!unacked_packets_.IsUnacked(received_info.largest_observed)) { |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 661 | return false; |
[email protected] | 41fb637 | 2013-12-10 05:26:40 | [diff] [blame] | 662 | } |
[email protected] | cb23a92 | 2014-02-20 17:42:38 | [diff] [blame] | 663 | // We calculate the RTT based on the highest ACKed sequence number, the lower |
| 664 | // sequence numbers will include the ACK aggregation delay. |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 665 | const TransmissionInfo& transmission_info = |
[email protected] | cb23a92 | 2014-02-20 17:42:38 | [diff] [blame] | 666 | unacked_packets_.GetTransmissionInfo(received_info.largest_observed); |
[email protected] | 9f0dcd4e | 2014-01-16 15:58:14 | [diff] [blame] | 667 | // Don't update the RTT if it hasn't been sent. |
[email protected] | cb23a92 | 2014-02-20 17:42:38 | [diff] [blame] | 668 | if (transmission_info.sent_time == QuicTime::Zero()) { |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 669 | return false; |
[email protected] | 9f0dcd4e | 2014-01-16 15:58:14 | [diff] [blame] | 670 | } |
[email protected] | 41fb637 | 2013-12-10 05:26:40 | [diff] [blame] | 671 | |
[email protected] | 14a9575 | 2014-01-08 19:01:52 | [diff] [blame] | 672 | QuicTime::Delta send_delta = |
[email protected] | cb23a92 | 2014-02-20 17:42:38 | [diff] [blame] | 673 | ack_receive_time.Subtract(transmission_info.sent_time); |
[email protected] | 82168ee2 | 2014-04-30 22:25:48 | [diff] [blame] | 674 | rtt_stats_.UpdateRtt( |
| 675 | send_delta, received_info.delta_time_largest_observed, ack_receive_time); |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 676 | return true; |
[email protected] | 41fb637 | 2013-12-10 05:26:40 | [diff] [blame] | 677 | } |
| 678 | |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 679 | QuicTime::Delta QuicSentPacketManager::TimeUntilSend( |
| 680 | QuicTime now, |
[email protected] | 9bb57c7 | 2014-03-31 20:36:04 | [diff] [blame] | 681 | HasRetransmittableData retransmittable) { |
| 682 | // The TLP logic is entirely contained within QuicSentPacketManager, so the |
| 683 | // send algorithm does not need to be consulted. |
[email protected] | 9cda5fd | 2014-06-03 10:20:28 | [diff] [blame] | 684 | if (pending_tlp_transmission_) { |
[email protected] | 9bb57c7 | 2014-03-31 20:36:04 | [diff] [blame] | 685 | return QuicTime::Delta::Zero(); |
| 686 | } |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 687 | return send_algorithm_->TimeUntilSend( |
| 688 | now, unacked_packets_.bytes_in_flight(), retransmittable); |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 689 | } |
| 690 | |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 691 | // Ensures that the Delayed Ack timer is always set to a value lesser |
| 692 | // than the retransmission timer's minimum value (MinRTO). We want the |
| 693 | // delayed ack to get back to the QUIC peer before the sender's |
| 694 | // retransmission timer triggers. Since we do not know the |
| 695 | // reverse-path one-way delay, we assume equal delays for forward and |
| 696 | // reverse paths, and ensure that the timer is set to less than half |
| 697 | // of the MinRTO. |
| 698 | // There may be a value in making this delay adaptive with the help of |
| 699 | // the sender and a signaling mechanism -- if the sender uses a |
| 700 | // different MinRTO, we may get spurious retransmissions. May not have |
| 701 | // any benefits, but if the delayed ack becomes a significant source |
| 702 | // of (likely, tail) latency, then consider such a mechanism. |
[email protected] | 2115d33ba | 2014-01-02 21:53:52 | [diff] [blame] | 703 | const QuicTime::Delta QuicSentPacketManager::DelayedAckTime() const { |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 704 | return QuicTime::Delta::FromMilliseconds(kMinRetransmissionTimeMs/2); |
| 705 | } |
| 706 | |
[email protected] | c068020 | 2013-12-18 04:52:34 | [diff] [blame] | 707 | const QuicTime QuicSentPacketManager::GetRetransmissionTime() const { |
[email protected] | d8bbef6 | 2014-06-12 08:02:50 | [diff] [blame] | 708 | // Don't set the timer if there are no packets in flight or we've already |
| 709 | // queued a tlp transmission and it hasn't been sent yet. |
| 710 | if (!unacked_packets_.HasInFlightPackets() || pending_tlp_transmission_) { |
[email protected] | c068020 | 2013-12-18 04:52:34 | [diff] [blame] | 711 | return QuicTime::Zero(); |
| 712 | } |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 713 | switch (GetRetransmissionMode()) { |
| 714 | case HANDSHAKE_MODE: |
| 715 | return clock_->ApproximateNow().Add(GetCryptoRetransmissionDelay()); |
[email protected] | 3aa9ca7 | 2014-02-27 19:39:43 | [diff] [blame] | 716 | case LOSS_MODE: |
| 717 | return loss_algorithm_->GetLossTimeout(); |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 718 | case TLP_MODE: { |
| 719 | // TODO(ianswett): When CWND is available, it would be preferable to |
| 720 | // set the timer based on the earliest retransmittable packet. |
| 721 | // Base the updated timer on the send time of the last packet. |
[email protected] | cb23a92 | 2014-02-20 17:42:38 | [diff] [blame] | 722 | const QuicTime sent_time = unacked_packets_.GetLastPacketSentTime(); |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 723 | const QuicTime tlp_time = sent_time.Add(GetTailLossProbeDelay()); |
[email protected] | 6d9ca3b | 2014-05-13 07:44:22 | [diff] [blame] | 724 | // Ensure the TLP timer never gets set to a time in the past. |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 725 | return QuicTime::Max(clock_->ApproximateNow(), tlp_time); |
| 726 | } |
| 727 | case RTO_MODE: { |
[email protected] | aa7e4ef | 2014-05-28 03:53:15 | [diff] [blame] | 728 | // The RTO is based on the first outstanding packet. |
[email protected] | cb23a92 | 2014-02-20 17:42:38 | [diff] [blame] | 729 | const QuicTime sent_time = |
[email protected] | aa7e4ef | 2014-05-28 03:53:15 | [diff] [blame] | 730 | unacked_packets_.GetFirstInFlightPacketSentTime(); |
[email protected] | cc1aa27 | 2014-06-30 19:48:22 | [diff] [blame] | 731 | QuicTime rto_time = sent_time.Add(GetRetransmissionDelay()); |
| 732 | // Wait for TLP packets to be acked before an RTO fires. |
| 733 | QuicTime tlp_time = |
| 734 | unacked_packets_.GetLastPacketSentTime().Add(GetTailLossProbeDelay()); |
| 735 | return QuicTime::Max(tlp_time, rto_time); |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 736 | } |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 737 | } |
[email protected] | 8a15a6c8 | 2014-01-09 13:04:46 | [diff] [blame] | 738 | DCHECK(false); |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 739 | return QuicTime::Zero(); |
| 740 | } |
| 741 | |
[email protected] | 7ad98f4 | 2014-01-08 07:11:30 | [diff] [blame] | 742 | const QuicTime::Delta QuicSentPacketManager::GetCryptoRetransmissionDelay() |
| 743 | const { |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 744 | // This is equivalent to the TailLossProbeDelay, but slightly more aggressive |
| 745 | // because crypto handshake messages don't incur a delayed ack time. |
| 746 | int64 delay_ms = max<int64>(kMinHandshakeTimeoutMs, |
[email protected] | fb35b0a | 2014-04-15 21:06:49 | [diff] [blame] | 747 | 1.5 * rtt_stats_.SmoothedRtt().ToMilliseconds()); |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 748 | return QuicTime::Delta::FromMilliseconds( |
| 749 | delay_ms << consecutive_crypto_retransmission_count_); |
| 750 | } |
| 751 | |
| 752 | const QuicTime::Delta QuicSentPacketManager::GetTailLossProbeDelay() const { |
[email protected] | fb35b0a | 2014-04-15 21:06:49 | [diff] [blame] | 753 | QuicTime::Delta srtt = rtt_stats_.SmoothedRtt(); |
[email protected] | aa7e4ef | 2014-05-28 03:53:15 | [diff] [blame] | 754 | if (!unacked_packets_.HasMultipleInFlightPackets()) { |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 755 | return QuicTime::Delta::Max( |
| 756 | srtt.Multiply(1.5).Add(DelayedAckTime()), srtt.Multiply(2)); |
| 757 | } |
| 758 | return QuicTime::Delta::FromMilliseconds( |
| 759 | max(kMinTailLossProbeTimeoutMs, |
| 760 | static_cast<int64>(2 * srtt.ToMilliseconds()))); |
[email protected] | c068020 | 2013-12-18 04:52:34 | [diff] [blame] | 761 | } |
| 762 | |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 763 | const QuicTime::Delta QuicSentPacketManager::GetRetransmissionDelay() const { |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 764 | QuicTime::Delta retransmission_delay = send_algorithm_->RetransmissionDelay(); |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 765 | // TODO(rch): This code should move to |send_algorithm_|. |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 766 | if (retransmission_delay.IsZero()) { |
| 767 | // We are in the initial state, use default timeout values. |
| 768 | retransmission_delay = |
| 769 | QuicTime::Delta::FromMilliseconds(kDefaultRetransmissionTimeMs); |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 770 | } else if (retransmission_delay.ToMilliseconds() < kMinRetransmissionTimeMs) { |
| 771 | retransmission_delay = |
| 772 | QuicTime::Delta::FromMilliseconds(kMinRetransmissionTimeMs); |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 773 | } |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 774 | |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 775 | // Calculate exponential back off. |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 776 | retransmission_delay = retransmission_delay.Multiply( |
[email protected] | 7ad98f4 | 2014-01-08 07:11:30 | [diff] [blame] | 777 | 1 << min<size_t>(consecutive_rto_count_, kMaxRetransmissions)); |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 778 | |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 779 | if (retransmission_delay.ToMilliseconds() > kMaxRetransmissionTimeMs) { |
| 780 | return QuicTime::Delta::FromMilliseconds(kMaxRetransmissionTimeMs); |
| 781 | } |
| 782 | return retransmission_delay; |
| 783 | } |
| 784 | |
[email protected] | fb35b0a | 2014-04-15 21:06:49 | [diff] [blame] | 785 | const RttStats* QuicSentPacketManager::GetRttStats() const { |
| 786 | return &rtt_stats_; |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 787 | } |
| 788 | |
| 789 | QuicBandwidth QuicSentPacketManager::BandwidthEstimate() const { |
| 790 | return send_algorithm_->BandwidthEstimate(); |
| 791 | } |
| 792 | |
[email protected] | 0c6b10ad | 2014-07-02 19:47:00 | [diff] [blame^] | 793 | bool QuicSentPacketManager::HasReliableBandwidthEstimate() const { |
| 794 | return send_algorithm_->HasReliableBandwidthEstimate(); |
| 795 | } |
| 796 | |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 797 | QuicByteCount QuicSentPacketManager::GetCongestionWindow() const { |
| 798 | return send_algorithm_->GetCongestionWindow(); |
| 799 | } |
| 800 | |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 801 | void QuicSentPacketManager::MaybeEnablePacing() { |
| 802 | if (!FLAGS_enable_quic_pacing) { |
| 803 | return; |
| 804 | } |
| 805 | |
| 806 | if (using_pacing_) { |
| 807 | return; |
| 808 | } |
| 809 | |
[email protected] | 9cda5fd | 2014-06-03 10:20:28 | [diff] [blame] | 810 | // Set up a pacing sender with a 5 millisecond alarm granularity. |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 811 | using_pacing_ = true; |
| 812 | send_algorithm_.reset( |
| 813 | new PacingSender(send_algorithm_.release(), |
[email protected] | 0c6b10ad | 2014-07-02 19:47:00 | [diff] [blame^] | 814 | QuicTime::Delta::FromMilliseconds(5), |
| 815 | kInitialUnpacedBurst)); |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 816 | } |
| 817 | |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 818 | } // namespace net |