[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 | #ifndef NET_QUIC_QUIC_SENT_PACKET_MANAGER_H_ |
| 6 | #define NET_QUIC_QUIC_SENT_PACKET_MANAGER_H_ |
| 7 | |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 8 | #include <stddef.h> |
| 9 | |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 10 | #include <map> |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 11 | #include <memory> |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 12 | #include <set> |
| 13 | #include <utility> |
| 14 | #include <vector> |
| 15 | |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 16 | #include "base/macros.h" |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 17 | #include "net/base/linked_hash_map.h" |
[email protected] | 93dd91f | 2014-02-27 00:09:03 | [diff] [blame] | 18 | #include "net/quic/congestion_control/loss_detection_interface.h" |
[email protected] | ffc34bf | 2014-03-07 02:42:02 | [diff] [blame] | 19 | #include "net/quic/congestion_control/rtt_stats.h" |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 20 | #include "net/quic/congestion_control/send_algorithm_interface.h" |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 21 | #include "net/quic/quic_protocol.h" |
[email protected] | ca4e0d9 | 2014-08-22 16:33:22 | [diff] [blame] | 22 | #include "net/quic/quic_sustained_bandwidth_recorder.h" |
[email protected] | cb23a92 | 2014-02-20 17:42:38 | [diff] [blame] | 23 | #include "net/quic/quic_unacked_packet_map.h" |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 24 | |
| 25 | namespace net { |
| 26 | |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 27 | namespace test { |
| 28 | class QuicConnectionPeer; |
| 29 | class QuicSentPacketManagerPeer; |
| 30 | } // namespace test |
| 31 | |
| 32 | class QuicClock; |
| 33 | class QuicConfig; |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 34 | struct QuicConnectionStats; |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 35 | |
| 36 | // Class which tracks the set of packets sent on a QUIC connection and contains |
| 37 | // a send algorithm to decide when to send new packets. It keeps track of any |
| 38 | // retransmittable data associated with each packet. If a packet is |
| 39 | // retransmitted, it will keep track of each version of a packet so that if a |
| 40 | // previous transmission is acked, the data will not be retransmitted. |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 41 | class NET_EXPORT_PRIVATE QuicSentPacketManager { |
| 42 | public: |
jri | c533399b | 2016-01-29 07:36:01 | [diff] [blame] | 43 | // A delegate interface which manages pending retransmissions. |
| 44 | class MultipathDelegateInterface { |
| 45 | public: |
| 46 | virtual ~MultipathDelegateInterface() {} |
| 47 | |
| 48 | // Called when unencrypted |packet_number| is requested to be neutered. |
| 49 | virtual void OnUnencryptedPacketsNeutered( |
| 50 | QuicPathId path_id, |
| 51 | QuicPacketNumber packet_number) = 0; |
| 52 | // Called when |packet_number| is requested to be retransmitted. |
| 53 | virtual void OnRetransmissionMarked(QuicPathId path_id, |
| 54 | QuicPacketNumber packet_number, |
| 55 | TransmissionType transmission_type) = 0; |
| 56 | // Called when |packet_number| is marked as not retransmittable. |
| 57 | virtual void OnPacketMarkedNotRetransmittable( |
| 58 | QuicPathId path_id, |
| 59 | QuicPacketNumber packet_number, |
| 60 | QuicTime::Delta delta_largest_observed) = 0; |
| 61 | // Called when any transmission of |packet_number| is handled. |
| 62 | virtual void OnPacketMarkedHandled( |
| 63 | QuicPathId path_id, |
| 64 | QuicPacketNumber packet_number, |
| 65 | QuicTime::Delta delta_largest_observed) = 0; |
| 66 | }; |
| 67 | |
[email protected] | 730b35d7 | 2014-06-05 03:23:22 | [diff] [blame] | 68 | // Interface which gets callbacks from the QuicSentPacketManager at |
| 69 | // interesting points. Implementations must not mutate the state of |
| 70 | // the packet manager or connection as a result of these callbacks. |
| 71 | class NET_EXPORT_PRIVATE DebugDelegate { |
| 72 | public: |
| 73 | virtual ~DebugDelegate() {} |
| 74 | |
| 75 | // Called when a spurious retransmission is detected. |
rtenneti | 5d9c02c | 2015-01-16 00:45:32 | [diff] [blame] | 76 | virtual void OnSpuriousPacketRetransmission( |
[email protected] | 730b35d7 | 2014-06-05 03:23:22 | [diff] [blame] | 77 | TransmissionType transmission_type, |
| 78 | QuicByteCount byte_size) {} |
[email protected] | ccb3421 | 2014-07-18 09:27:50 | [diff] [blame] | 79 | |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 80 | virtual void OnIncomingAck(const QuicAckFrame& ack_frame, |
| 81 | QuicTime ack_receive_time, |
| 82 | QuicPacketNumber largest_observed, |
| 83 | bool rtt_updated, |
| 84 | QuicPacketNumber least_unacked_sent_packet) {} |
rch | caec424 | 2016-01-22 20:49:52 | [diff] [blame] | 85 | |
| 86 | virtual void OnPacketLoss(QuicPacketNumber lost_packet_number, |
| 87 | TransmissionType transmission_type, |
| 88 | QuicTime detection_time) {} |
[email protected] | 730b35d7 | 2014-06-05 03:23:22 | [diff] [blame] | 89 | }; |
| 90 | |
[email protected] | a692ad9d | 2014-07-18 21:35:24 | [diff] [blame] | 91 | // Interface which gets callbacks from the QuicSentPacketManager when |
| 92 | // network-related state changes. Implementations must not mutate the |
| 93 | // state of the packet manager as a result of these callbacks. |
| 94 | class NET_EXPORT_PRIVATE NetworkChangeVisitor { |
| 95 | public: |
| 96 | virtual ~NetworkChangeVisitor() {} |
| 97 | |
ckrasic | a7fd124 | 2016-05-14 20:36:01 | [diff] [blame] | 98 | // Called when congestion window or RTT may have changed. |
| 99 | virtual void OnCongestionChange() = 0; |
jri | aeec2fb | 2016-02-05 02:05:36 | [diff] [blame] | 100 | |
| 101 | // Called with the path may be degrading. Note that the path may only be |
| 102 | // temporarily degrading. |
| 103 | // TODO(jri): With multipath, this method should probably have a path_id |
| 104 | // parameter, and should maybe result in the path being marked as inactive. |
| 105 | virtual void OnPathDegrading() = 0; |
[email protected] | a692ad9d | 2014-07-18 21:35:24 | [diff] [blame] | 106 | }; |
| 107 | |
rtenneti | 6f48aa9 | 2015-03-16 02:18:48 | [diff] [blame] | 108 | QuicSentPacketManager(Perspective perspective, |
fayang | a31a74b | 2015-12-28 17:27:14 | [diff] [blame] | 109 | QuicPathId path_id, |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 110 | const QuicClock* clock, |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 111 | QuicConnectionStats* stats, |
[email protected] | a692ad9d | 2014-07-18 21:35:24 | [diff] [blame] | 112 | CongestionControlType congestion_control_type, |
jri | c533399b | 2016-01-29 07:36:01 | [diff] [blame] | 113 | LossDetectionType loss_type, |
| 114 | MultipathDelegateInterface* delegate); |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 115 | virtual ~QuicSentPacketManager(); |
| 116 | |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 117 | virtual void SetFromConfig(const QuicConfig& config); |
| 118 | |
rtenneti | 85d8971 | 2014-11-20 03:32:24 | [diff] [blame] | 119 | // Pass the CachedNetworkParameters to the send algorithm. |
rtenneti | 581b6ae8 | 2015-07-20 20:48:01 | [diff] [blame] | 120 | void ResumeConnectionState( |
rtenneti | b346cb0 | 2015-03-25 19:50:06 | [diff] [blame] | 121 | const CachedNetworkParameters& cached_network_params, |
| 122 | bool max_bandwidth_resumption); |
rtenneti | 85d8971 | 2014-11-20 03:32:24 | [diff] [blame] | 123 | |
rtenneti | 33da8ab | 2014-11-04 04:17:00 | [diff] [blame] | 124 | void SetNumOpenStreams(size_t num_streams); |
| 125 | |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 126 | void SetMaxPacingRate(QuicBandwidth max_pacing_rate); |
| 127 | |
[email protected] | 9693157b | 2014-08-08 11:13:49 | [diff] [blame] | 128 | void SetHandshakeConfirmed() { handshake_confirmed_ = true; } |
| 129 | |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 130 | // Processes the incoming ack. |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 131 | void OnIncomingAck(const QuicAckFrame& ack_frame, QuicTime ack_receive_time); |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 132 | |
rjshade | d069aaee | 2016-03-11 20:42:17 | [diff] [blame] | 133 | // Returns true if packet |packet_number| is unacked. |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 134 | bool IsUnacked(QuicPacketNumber packet_number) const; |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 135 | |
[email protected] | 41fb637 | 2013-12-10 05:26:40 | [diff] [blame] | 136 | // Requests retransmission of all unacked packets of |retransmission_type|. |
rtenneti | 85d8971 | 2014-11-20 03:32:24 | [diff] [blame] | 137 | // The behavior of this method depends on the value of |retransmission_type|: |
| 138 | // ALL_UNACKED_RETRANSMISSION - All unacked packets will be retransmitted. |
| 139 | // This can happen, for example, after a version negotiation packet has been |
| 140 | // received and all packets needs to be retransmitted with the new version. |
| 141 | // ALL_INITIAL_RETRANSMISSION - Only initially encrypted packets will be |
| 142 | // retransmitted. This can happen, for example, when a CHLO has been rejected |
| 143 | // and the previously encrypted data needs to be encrypted with a new key. |
rtenneti | 31e9fd6 | 2014-09-16 05:22:15 | [diff] [blame] | 144 | void RetransmitUnackedPackets(TransmissionType retransmission_type); |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 145 | |
[email protected] | d8bbef6 | 2014-06-12 08:02:50 | [diff] [blame] | 146 | // Retransmits the oldest pending packet there is still a tail loss probe |
| 147 | // pending. Invoked after OnRetransmissionTimeout. |
| 148 | bool MaybeRetransmitTailLossProbe(); |
| 149 | |
[email protected] | 82168ee2 | 2014-04-30 22:25:48 | [diff] [blame] | 150 | // Removes the retransmittable frames from all unencrypted packets to ensure |
| 151 | // they don't get retransmitted. |
[email protected] | 6d9ca3b7 | 2014-05-13 07:44:22 | [diff] [blame] | 152 | void NeuterUnencryptedPackets(); |
[email protected] | 82168ee2 | 2014-04-30 22:25:48 | [diff] [blame] | 153 | |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 154 | // Returns true if the unacked packet |packet_number| has retransmittable |
[email protected] | c67a82cb | 2013-09-24 02:53:21 | [diff] [blame] | 155 | // frames. This will only return false if the packet has been acked, if a |
| 156 | // previous transmission of this packet was ACK'd, or if this packet has been |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 157 | // retransmitted as with different packet number. |
| 158 | bool HasRetransmittableFrames(QuicPacketNumber packet_number) const; |
[email protected] | c67a82cb | 2013-09-24 02:53:21 | [diff] [blame] | 159 | |
[email protected] | 45a3e15 | 2013-09-25 16:35:11 | [diff] [blame] | 160 | // Returns true if there are pending retransmissions. |
danzh | 1401f0a | 2016-05-19 13:41:10 | [diff] [blame] | 161 | // Not const because retransmissions may be cancelled before returning. |
[email protected] | 45a3e15 | 2013-09-25 16:35:11 | [diff] [blame] | 162 | bool HasPendingRetransmissions() const; |
| 163 | |
rtenneti | fbf7d6b | 2015-01-05 23:45:36 | [diff] [blame] | 164 | // Retrieves the next pending retransmission. You must ensure that |
| 165 | // there are pending retransmissions prior to calling this function. |
[email protected] | 45a3e15 | 2013-09-25 16:35:11 | [diff] [blame] | 166 | PendingRetransmission NextPendingRetransmission(); |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 167 | |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 168 | bool HasUnackedPackets() const; |
| 169 | |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 170 | // Returns the smallest packet number of a serialized packet which has not |
rtenneti | 16142b6 | 2014-09-03 21:52:11 | [diff] [blame] | 171 | // been acked by the peer. |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 172 | QuicPacketNumber GetLeastUnacked() const; |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 173 | |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 174 | // Called when we have sent bytes to the peer. This informs the manager both |
[email protected] | 2115d33ba | 2014-01-02 21:53:52 | [diff] [blame] | 175 | // the number of bytes sent and if they were retransmitted. Returns true if |
| 176 | // the sender should reset the retransmission timer. |
rtenneti | a4dcff9 | 2014-09-29 18:16:08 | [diff] [blame] | 177 | virtual bool OnPacketSent(SerializedPacket* serialized_packet, |
ckrasic | a7fd124 | 2016-05-14 20:36:01 | [diff] [blame] | 178 | QuicPathId /*original_path_id*/, |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 179 | QuicPacketNumber original_packet_number, |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 180 | QuicTime sent_time, |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 181 | TransmissionType transmission_type, |
| 182 | HasRetransmittableData has_retransmittable_data); |
| 183 | |
| 184 | // Called when the retransmission timer expires. |
| 185 | virtual void OnRetransmissionTimeout(); |
| 186 | |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 187 | // Calculate the time until we can send the next packet to the wire. |
| 188 | // Note 1: When kUnknownWaitTime is returned, there is no need to poll |
| 189 | // TimeUntilSend again until we receive an OnIncomingAckFrame event. |
| 190 | // Note 2: Send algorithms may or may not use |retransmit| in their |
| 191 | // calculations. |
| 192 | virtual QuicTime::Delta TimeUntilSend(QuicTime now, |
[email protected] | 9bb57c7 | 2014-03-31 20:36:04 | [diff] [blame] | 193 | HasRetransmittableData retransmittable); |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 194 | |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 195 | // Returns amount of time for delayed ack timer. |
[email protected] | 2115d33ba | 2014-01-02 21:53:52 | [diff] [blame] | 196 | const QuicTime::Delta DelayedAckTime() const; |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 197 | |
[email protected] | c068020 | 2013-12-18 04:52:34 | [diff] [blame] | 198 | // Returns the current delay for the retransmission timer, which may send |
[email protected] | 2115d33ba | 2014-01-02 21:53:52 | [diff] [blame] | 199 | // either a tail loss probe or do a full RTO. Returns QuicTime::Zero() if |
| 200 | // there are no retransmittable packets. |
[email protected] | c068020 | 2013-12-18 04:52:34 | [diff] [blame] | 201 | const QuicTime GetRetransmissionTime() const; |
| 202 | |
[email protected] | fb35b0a | 2014-04-15 21:06:49 | [diff] [blame] | 203 | const RttStats* GetRttStats() const; |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 204 | |
| 205 | // Returns the estimated bandwidth calculated by the congestion algorithm. |
| 206 | QuicBandwidth BandwidthEstimate() const; |
| 207 | |
[email protected] | ca4e0d9 | 2014-08-22 16:33:22 | [diff] [blame] | 208 | const QuicSustainedBandwidthRecorder& SustainedBandwidthRecorder() const; |
| 209 | |
rtenneti | 4a5df26 | 2014-11-07 00:43:58 | [diff] [blame] | 210 | // Returns the size of the current congestion window in number of |
| 211 | // kDefaultTCPMSS-sized segments. Note, this is not the *available* window. |
| 212 | // Some send algorithms may not use a congestion window and will return 0. |
| 213 | QuicPacketCount GetCongestionWindowInTcpMss() const; |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 214 | |
rtenneti | 4a5df26 | 2014-11-07 00:43:58 | [diff] [blame] | 215 | // Returns the number of packets of length |max_packet_length| which fit in |
| 216 | // the current congestion window. More packets may end up in flight if the |
| 217 | // congestion window has been recently reduced, of if non-full packets are |
| 218 | // sent. |
| 219 | QuicPacketCount EstimateMaxPacketsInFlight( |
| 220 | QuicByteCount max_packet_length) const; |
| 221 | |
rtenneti | 9bd5d4b | 2015-08-21 05:44:52 | [diff] [blame] | 222 | // Returns the size of the current congestion window size in bytes. |
| 223 | QuicByteCount GetCongestionWindowInBytes() const; |
| 224 | |
rtenneti | 4a5df26 | 2014-11-07 00:43:58 | [diff] [blame] | 225 | // Returns the size of the slow start congestion window in nume of 1460 byte |
| 226 | // TCP segments, aka ssthresh. Some send algorithms do not define a slow |
| 227 | // start threshold and will return 0. |
| 228 | QuicPacketCount GetSlowStartThresholdInTcpMss() const; |
[email protected] | ccb3421 | 2014-07-18 09:27:50 | [diff] [blame] | 229 | |
rtenneti | fb3fa6c | 2015-03-16 23:04:55 | [diff] [blame] | 230 | // No longer retransmit data for |stream_id|. |
| 231 | void CancelRetransmissionsForStream(QuicStreamId stream_id); |
| 232 | |
[email protected] | 2f9fb93 | 2014-08-20 19:42:44 | [diff] [blame] | 233 | // Enables pacing if it has not already been enabled. |
| 234 | void EnablePacing(); |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 235 | |
rjshade | c86dbfa | 2015-11-12 20:16:25 | [diff] [blame] | 236 | // Called when peer address changes and the connection migrates. |
| 237 | void OnConnectionMigration(PeerAddressChangeType type); |
| 238 | |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 239 | bool using_pacing() const { return using_pacing_; } |
| 240 | |
ckrasic | a7fd124 | 2016-05-14 20:36:01 | [diff] [blame] | 241 | bool handshake_confirmed() const { return handshake_confirmed_; } |
| 242 | |
[email protected] | 730b35d7 | 2014-06-05 03:23:22 | [diff] [blame] | 243 | void set_debug_delegate(DebugDelegate* debug_delegate) { |
| 244 | debug_delegate_ = debug_delegate; |
| 245 | } |
| 246 | |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 247 | QuicPacketNumber largest_observed() const { |
[email protected] | ca4e0d9 | 2014-08-22 16:33:22 | [diff] [blame] | 248 | return unacked_packets_.largest_observed(); |
| 249 | } |
| 250 | |
rtenneti | a8fb60cb | 2015-09-10 18:17:57 | [diff] [blame] | 251 | QuicPacketNumber largest_sent_packet() const { |
| 252 | return unacked_packets_.largest_sent_packet(); |
| 253 | } |
| 254 | |
| 255 | QuicPacketNumber least_packet_awaited_by_peer() const { |
[email protected] | ca4e0d9 | 2014-08-22 16:33:22 | [diff] [blame] | 256 | return least_packet_awaited_by_peer_; |
[email protected] | 0c6b10ad | 2014-07-02 19:47:00 | [diff] [blame] | 257 | } |
| 258 | |
[email protected] | a692ad9d | 2014-07-18 21:35:24 | [diff] [blame] | 259 | void set_network_change_visitor(NetworkChangeVisitor* visitor) { |
| 260 | DCHECK(!network_change_visitor_); |
| 261 | DCHECK(visitor); |
| 262 | network_change_visitor_ = visitor; |
| 263 | } |
| 264 | |
rch | caec424 | 2016-01-22 20:49:52 | [diff] [blame] | 265 | bool InSlowStart() const; |
| 266 | |
rtenneti | ae5ac43 | 2015-03-03 06:36:50 | [diff] [blame] | 267 | // Used in Chromium, but not in the server. |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 268 | size_t consecutive_rto_count() const { return consecutive_rto_count_; } |
[email protected] | d117e528 | 2014-08-16 06:18:54 | [diff] [blame] | 269 | |
rtenneti | ae5ac43 | 2015-03-03 06:36:50 | [diff] [blame] | 270 | // Used in Chromium, but not in the server. |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 271 | size_t consecutive_tlp_count() const { return consecutive_tlp_count_; } |
[email protected] | d117e528 | 2014-08-16 06:18:54 | [diff] [blame] | 272 | |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 273 | private: |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 274 | friend class test::QuicConnectionPeer; |
| 275 | friend class test::QuicSentPacketManagerPeer; |
| 276 | |
[email protected] | 3aa9ca7 | 2014-02-27 19:39:43 | [diff] [blame] | 277 | // The retransmission timer is a single timer which switches modes depending |
| 278 | // upon connection state. |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 279 | enum RetransmissionTimeoutMode { |
[email protected] | 3aa9ca7 | 2014-02-27 19:39:43 | [diff] [blame] | 280 | // A conventional TCP style RTO. |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 281 | RTO_MODE, |
[email protected] | 3aa9ca7 | 2014-02-27 19:39:43 | [diff] [blame] | 282 | // A tail loss probe. By default, QUIC sends up to two before RTOing. |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 283 | TLP_MODE, |
[email protected] | 3aa9ca7 | 2014-02-27 19:39:43 | [diff] [blame] | 284 | // Retransmission of handshake packets prior to handshake completion. |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 285 | HANDSHAKE_MODE, |
[email protected] | 3aa9ca7 | 2014-02-27 19:39:43 | [diff] [blame] | 286 | // Re-invoke the loss detection when a packet is not acked before the |
| 287 | // loss detection algorithm expects. |
| 288 | LOSS_MODE, |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 289 | }; |
| 290 | |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 291 | typedef linked_hash_map<QuicPacketNumber, TransmissionType> |
| 292 | PendingRetransmissionMap; |
[email protected] | c67a82cb | 2013-09-24 02:53:21 | [diff] [blame] | 293 | |
[email protected] | ca4e0d9 | 2014-08-22 16:33:22 | [diff] [blame] | 294 | // Updates the least_packet_awaited_by_peer. |
| 295 | void UpdatePacketInformationReceivedByPeer(const QuicAckFrame& ack_frame); |
| 296 | |
[email protected] | c67a82cb | 2013-09-24 02:53:21 | [diff] [blame] | 297 | // Process the incoming ack looking for newly ack'd data packets. |
[email protected] | 310d37b | 2014-08-02 06:15:37 | [diff] [blame] | 298 | void HandleAckForSentPackets(const QuicAckFrame& ack_frame); |
[email protected] | c67a82cb | 2013-09-24 02:53:21 | [diff] [blame] | 299 | |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 300 | // Returns the current retransmission mode. |
| 301 | RetransmissionTimeoutMode GetRetransmissionMode() const; |
| 302 | |
| 303 | // Retransmits all crypto stream packets. |
| 304 | void RetransmitCryptoPackets(); |
| 305 | |
rtenneti | 5d9c02c | 2015-01-16 00:45:32 | [diff] [blame] | 306 | // Retransmits two packets for an RTO and removes any non-retransmittable |
| 307 | // packets from flight. |
| 308 | void RetransmitRtoPackets(); |
| 309 | |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 310 | // Returns the timer for retransmitting crypto handshake packets. |
| 311 | const QuicTime::Delta GetCryptoRetransmissionDelay() const; |
| 312 | |
| 313 | // Returns the timer for a new tail loss probe. |
| 314 | const QuicTime::Delta GetTailLossProbeDelay() const; |
| 315 | |
| 316 | // Returns the retransmission timeout, after which a full RTO occurs. |
| 317 | const QuicTime::Delta GetRetransmissionDelay() const; |
| 318 | |
zhongyi | 1fb9bc5 | 2015-11-24 23:09:42 | [diff] [blame] | 319 | // Returns the newest transmission associated with a packet. |
| 320 | QuicPacketNumber GetNewestRetransmission( |
| 321 | QuicPacketNumber packet_number, |
| 322 | const TransmissionInfo& transmission_info) const; |
| 323 | |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 324 | // Update the RTT if the ack is for the largest acked packet number. |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 325 | // Returns true if the rtt was updated. |
fnk | f57804c | 2016-03-17 20:57:07 | [diff] [blame] | 326 | bool MaybeUpdateRTT(const QuicAckFrame& ack_frame, QuicTime ack_receive_time); |
[email protected] | 41fb637 | 2013-12-10 05:26:40 | [diff] [blame] | 327 | |
[email protected] | 93dd91f | 2014-02-27 00:09:03 | [diff] [blame] | 328 | // Invokes the loss detection algorithm and loses and retransmits packets if |
| 329 | // necessary. |
| 330 | void InvokeLossDetection(QuicTime time); |
| 331 | |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 332 | // Invokes OnCongestionEvent if |rtt_updated| is true, there are pending acks, |
| 333 | // or pending losses. Clears pending acks and pending losses afterwards. |
| 334 | // |bytes_in_flight| is the number of bytes in flight before the losses or |
| 335 | // acks. |
| 336 | void MaybeInvokeCongestionEvent(bool rtt_updated, |
| 337 | QuicByteCount bytes_in_flight); |
| 338 | |
jri | c533399b | 2016-01-29 07:36:01 | [diff] [blame] | 339 | // Called when frames of |packet_number| has been received but the packet |
rjshade | d069aaee | 2016-03-11 20:42:17 | [diff] [blame] | 340 | // itself has not been received by the peer. Currently, this method is not |
| 341 | // used. |
| 342 | // TODO(fayang): Update the comment when multipath sent packet manager is |
| 343 | // landed. |
jri | c533399b | 2016-01-29 07:36:01 | [diff] [blame] | 344 | // The packet needs no longer to be retransmitted, but the packet remains |
| 345 | // pending if it is and the congestion control does not consider the packet |
| 346 | // acked. |
| 347 | void MarkPacketNotRetransmittable(QuicPacketNumber packet_number, |
| 348 | QuicTime::Delta ack_delay_time); |
[email protected] | 2d43c4012 | 2014-04-21 14:51:27 | [diff] [blame] | 349 | |
zhongyi | 1fb9bc5 | 2015-11-24 23:09:42 | [diff] [blame] | 350 | // Removes the retransmittability and in flight properties from the packet at |
| 351 | // |info| due to receipt by the peer. |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 352 | void MarkPacketHandled(QuicPacketNumber packet_number, |
zhongyi | 1fb9bc5 | 2015-11-24 23:09:42 | [diff] [blame] | 353 | TransmissionInfo* info, |
rch | caec424 | 2016-01-22 20:49:52 | [diff] [blame] | 354 | QuicTime::Delta ack_delay_time); |
[email protected] | c068020 | 2013-12-18 04:52:34 | [diff] [blame] | 355 | |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 356 | // Request that |packet_number| be retransmitted after the other pending |
[email protected] | c068020 | 2013-12-18 04:52:34 | [diff] [blame] | 357 | // retransmissions. Does not add it to the retransmissions if it's already |
| 358 | // a pending retransmission. |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 359 | void MarkForRetransmission(QuicPacketNumber packet_number, |
[email protected] | 41fb637 | 2013-12-10 05:26:40 | [diff] [blame] | 360 | TransmissionType transmission_type); |
| 361 | |
zhongyi | 4a9d27b | 2016-01-12 20:08:31 | [diff] [blame] | 362 | // Notify observers that packet with TransmissionInfo |info| is a spurious |
| 363 | // retransmission. It is caller's responsibility to guarantee the packet with |
| 364 | // TransmissionInfo |info| is a spurious retransmission before calling this |
| 365 | // function. |
| 366 | void RecordOneSpuriousRetransmission(const TransmissionInfo& info); |
| 367 | |
| 368 | // Notify observers about spurious retransmits of packet with TransmissionInfo |
| 369 | // |info|. |
zhongyi | 1fb9bc5 | 2015-11-24 23:09:42 | [diff] [blame] | 370 | void RecordSpuriousRetransmissions(const TransmissionInfo& info, |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 371 | QuicPacketNumber acked_packet_number); |
[email protected] | 730b35d7 | 2014-06-05 03:23:22 | [diff] [blame] | 372 | |
jri | c533399b | 2016-01-29 07:36:01 | [diff] [blame] | 373 | // Returns mutable TransmissionInfo associated with |packet_number|, which |
| 374 | // must be unacked. |
| 375 | TransmissionInfo* GetMutableTransmissionInfo(QuicPacketNumber packet_number); |
| 376 | |
| 377 | // Remove any packets no longer needed for retransmission, congestion, or |
| 378 | // RTT measurement purposes. |
| 379 | void RemoveObsoletePackets(); |
| 380 | |
rjshade | d069aaee | 2016-03-11 20:42:17 | [diff] [blame] | 381 | // Newly serialized retransmittable packets are added to this map, which |
| 382 | // contains owning pointers to any contained frames. If a packet is |
[email protected] | 457d695 | 2013-12-13 09:24:58 | [diff] [blame] | 383 | // retransmitted, this map will contain entries for both the old and the new |
rtenneti | be635737 | 2014-10-02 22:51:42 | [diff] [blame] | 384 | // packet. The old packet's retransmittable frames entry will be nullptr, |
| 385 | // while the new packet's entry will contain the frames to retransmit. |
[email protected] | c67a82cb | 2013-09-24 02:53:21 | [diff] [blame] | 386 | // If the old packet is acked before the new packet, then the old entry will |
| 387 | // be removed from the map and the new entry's retransmittable frames will be |
rtenneti | be635737 | 2014-10-02 22:51:42 | [diff] [blame] | 388 | // set to nullptr. |
[email protected] | cb23a92 | 2014-02-20 17:42:38 | [diff] [blame] | 389 | QuicUnackedPacketMap unacked_packets_; |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 390 | |
[email protected] | 45a3e15 | 2013-09-25 16:35:11 | [diff] [blame] | 391 | // Pending retransmissions which have not been packetized and sent yet. |
| 392 | PendingRetransmissionMap pending_retransmissions_; |
| 393 | |
rtenneti | 6f48aa9 | 2015-03-16 02:18:48 | [diff] [blame] | 394 | // Tracks if the connection was created by the server or the client. |
| 395 | Perspective perspective_; |
[email protected] | c67a82cb | 2013-09-24 02:53:21 | [diff] [blame] | 396 | |
fayang | a31a74b | 2015-12-28 17:27:14 | [diff] [blame] | 397 | QuicPathId path_id_; |
| 398 | |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 399 | const QuicClock* clock_; |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 400 | QuicConnectionStats* stats_; |
jri | c533399b | 2016-01-29 07:36:01 | [diff] [blame] | 401 | |
| 402 | // Pending retransmissions are managed by delegate_ if it is not null. |
| 403 | MultipathDelegateInterface* delegate_; // Not owned. |
| 404 | |
[email protected] | 730b35d7 | 2014-06-05 03:23:22 | [diff] [blame] | 405 | DebugDelegate* debug_delegate_; |
[email protected] | a692ad9d | 2014-07-18 21:35:24 | [diff] [blame] | 406 | NetworkChangeVisitor* network_change_visitor_; |
rtenneti | 3fe4ebbc | 2014-11-16 16:43:47 | [diff] [blame] | 407 | const QuicPacketCount initial_congestion_window_; |
[email protected] | ffc34bf | 2014-03-07 02:42:02 | [diff] [blame] | 408 | RttStats rtt_stats_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 409 | std::unique_ptr<SendAlgorithmInterface> send_algorithm_; |
| 410 | std::unique_ptr<LossDetectionInterface> loss_algorithm_; |
rtenneti | 33da8ab | 2014-11-04 04:17:00 | [diff] [blame] | 411 | bool n_connection_simulation_; |
[email protected] | ffc34bf | 2014-03-07 02:42:02 | [diff] [blame] | 412 | |
rtenneti | 2318668 | 2014-10-30 01:49:33 | [diff] [blame] | 413 | // Receiver side buffer in bytes. |
| 414 | QuicByteCount receive_buffer_bytes_; |
| 415 | |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 416 | // Least packet number which the peer is still waiting for. |
| 417 | QuicPacketNumber least_packet_awaited_by_peer_; |
[email protected] | cc1aa27 | 2014-06-30 19:48:22 | [diff] [blame] | 418 | |
| 419 | // Tracks the first RTO packet. If any packet before that packet gets acked, |
| 420 | // it indicates the RTO was spurious and should be reversed(F-RTO). |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 421 | QuicPacketNumber first_rto_transmission_; |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 422 | // Number of times the RTO timer has fired in a row without receiving an ack. |
| 423 | size_t consecutive_rto_count_; |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 424 | // Number of times the tail loss probe has been sent. |
| 425 | size_t consecutive_tlp_count_; |
| 426 | // Number of times the crypto handshake has been retransmitted. |
| 427 | size_t consecutive_crypto_retransmission_count_; |
rtenneti | 5d9c02c | 2015-01-16 00:45:32 | [diff] [blame] | 428 | // Number of pending transmissions of TLP, RTO, or crypto packets. |
[email protected] | 2f9fb93 | 2014-08-20 19:42:44 | [diff] [blame] | 429 | size_t pending_timer_transmission_count_; |
[email protected] | 066d818 | 2014-01-04 02:02:45 | [diff] [blame] | 430 | // Maximum number of tail loss probes to send before firing an RTO. |
| 431 | size_t max_tail_loss_probes_; |
rtenneti | f8a6a21 | 2015-08-24 20:13:16 | [diff] [blame] | 432 | // If true, send the TLP at 0.5 RTT. |
| 433 | bool enable_half_rtt_tail_loss_probe_; |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 434 | bool using_pacing_; |
rtenneti | cf54a52c | 2015-01-26 17:01:54 | [diff] [blame] | 435 | // If true, use the new RTO with loss based CWND reduction instead of the send |
| 436 | // algorithms's OnRetransmissionTimeout to reduce the congestion window. |
| 437 | bool use_new_rto_; |
danzh | 1401f0a | 2016-05-19 13:41:10 | [diff] [blame] | 438 | // If true, cancel pending retransmissions if they're larger than |
| 439 | // largest_newly_acked. |
| 440 | bool undo_pending_retransmits_; |
[email protected] | 2adef90e | 2013-12-02 20:26:57 | [diff] [blame] | 441 | |
rtenneti | 16142b6 | 2014-09-03 21:52:11 | [diff] [blame] | 442 | // Vectors packets acked and lost as a result of the last congestion event. |
| 443 | SendAlgorithmInterface::CongestionVector packets_acked_; |
| 444 | SendAlgorithmInterface::CongestionVector packets_lost_; |
alyssar | c2f70a5 | 2016-05-04 13:15:49 | [diff] [blame] | 445 | // Largest newly acknowledged packet. |
| 446 | QuicPacketNumber largest_newly_acked_; |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 447 | |
[email protected] | 9693157b | 2014-08-08 11:13:49 | [diff] [blame] | 448 | // Set to true after the crypto handshake has successfully completed. After |
| 449 | // this is true we no longer use HANDSHAKE_MODE, and further frames sent on |
| 450 | // the crypto stream (i.e. SCUP messages) are treated like normal |
| 451 | // retransmittable frames. |
| 452 | bool handshake_confirmed_; |
| 453 | |
[email protected] | ca4e0d9 | 2014-08-22 16:33:22 | [diff] [blame] | 454 | // Records bandwidth from server to client in normal operation, over periods |
| 455 | // of time with no loss events. |
| 456 | QuicSustainedBandwidthRecorder sustained_bandwidth_recorder_; |
| 457 | |
[email protected] | 4d1789c3 | 2013-09-18 23:54:36 | [diff] [blame] | 458 | DISALLOW_COPY_AND_ASSIGN(QuicSentPacketManager); |
| 459 | }; |
| 460 | |
| 461 | } // namespace net |
| 462 | |
| 463 | #endif // NET_QUIC_QUIC_SENT_PACKET_MANAGER_H_ |