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