idnits 2.17.1 draft-ietf-quic-recovery-31.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- == There are 3 instances of lines with non-ascii characters in the document. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- No issues found here. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year -- The document date (25 September 2020) is 1302 days in the past. Is this intentional? -- Found something which looks like a code comment -- if you have code sections in the document, please surround them with '' and '' lines. Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) == Missing Reference: 'Initial' is mentioned on line 1658, but not defined == Outdated reference: A later version (-34) exists of draft-ietf-quic-tls-31 == Outdated reference: A later version (-34) exists of draft-ietf-quic-transport-31 == Outdated reference: A later version (-15) exists of draft-ietf-tcpm-rack-10 -- Obsolete informational reference (is this intentional?): RFC 8312 (Obsoleted by RFC 9438) Summary: 0 errors (**), 0 flaws (~~), 6 warnings (==), 3 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 QUIC J. Iyengar, Ed. 3 Internet-Draft Fastly 4 Intended status: Standards Track I. Swett, Ed. 5 Expires: 29 March 2021 Google 6 25 September 2020 8 QUIC Loss Detection and Congestion Control 9 draft-ietf-quic-recovery-31 11 Abstract 13 This document describes loss detection and congestion control 14 mechanisms for QUIC. 16 Note to Readers 18 Discussion of this draft takes place on the QUIC working group 19 mailing list (quic@ietf.org (mailto:quic@ietf.org)), which is 20 archived at https://mailarchive.ietf.org/arch/ 21 search/?email_list=quic. 23 Working Group information can be found at https://github.com/quicwg; 24 source code and issues list for this draft can be found at 25 https://github.com/quicwg/base-drafts/labels/-recovery. 27 Status of This Memo 29 This Internet-Draft is submitted in full conformance with the 30 provisions of BCP 78 and BCP 79. 32 Internet-Drafts are working documents of the Internet Engineering 33 Task Force (IETF). Note that other groups may also distribute 34 working documents as Internet-Drafts. The list of current Internet- 35 Drafts is at https://datatracker.ietf.org/drafts/current/. 37 Internet-Drafts are draft documents valid for a maximum of six months 38 and may be updated, replaced, or obsoleted by other documents at any 39 time. It is inappropriate to use Internet-Drafts as reference 40 material or to cite them other than as "work in progress." 42 This Internet-Draft will expire on 29 March 2021. 44 Copyright Notice 46 Copyright (c) 2020 IETF Trust and the persons identified as the 47 document authors. All rights reserved. 49 This document is subject to BCP 78 and the IETF Trust's Legal 50 Provisions Relating to IETF Documents (https://trustee.ietf.org/ 51 license-info) in effect on the date of publication of this document. 52 Please review these documents carefully, as they describe your rights 53 and restrictions with respect to this document. Code Components 54 extracted from this document must include Simplified BSD License text 55 as described in Section 4.e of the Trust Legal Provisions and are 56 provided without warranty as described in the Simplified BSD License. 58 Table of Contents 60 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 4 61 2. Conventions and Definitions . . . . . . . . . . . . . . . . . 4 62 3. Design of the QUIC Transmission Machinery . . . . . . . . . . 5 63 4. Relevant Differences Between QUIC and TCP . . . . . . . . . . 5 64 4.1. Separate Packet Number Spaces . . . . . . . . . . . . . . 6 65 4.2. Monotonically Increasing Packet Numbers . . . . . . . . . 6 66 4.3. Clearer Loss Epoch . . . . . . . . . . . . . . . . . . . 6 67 4.4. No Reneging . . . . . . . . . . . . . . . . . . . . . . . 7 68 4.5. More ACK Ranges . . . . . . . . . . . . . . . . . . . . . 7 69 4.6. Explicit Correction For Delayed Acknowledgements . . . . 7 70 4.7. Probe Timeout Replaces RTO and TLP . . . . . . . . . . . 7 71 4.8. The Minimum Congestion Window is Two Packets . . . . . . 8 72 5. Estimating the Round-Trip Time . . . . . . . . . . . . . . . 8 73 5.1. Generating RTT samples . . . . . . . . . . . . . . . . . 8 74 5.2. Estimating min_rtt . . . . . . . . . . . . . . . . . . . 9 75 5.3. Estimating smoothed_rtt and rttvar . . . . . . . . . . . 10 76 6. Loss Detection . . . . . . . . . . . . . . . . . . . . . . . 12 77 6.1. Acknowledgement-Based Detection . . . . . . . . . . . . . 12 78 6.1.1. Packet Threshold . . . . . . . . . . . . . . . . . . 13 79 6.1.2. Time Threshold . . . . . . . . . . . . . . . . . . . 13 80 6.2. Probe Timeout . . . . . . . . . . . . . . . . . . . . . . 14 81 6.2.1. Computing PTO . . . . . . . . . . . . . . . . . . . . 14 82 6.2.2. Handshakes and New Paths . . . . . . . . . . . . . . 16 83 6.2.3. Speeding Up Handshake Completion . . . . . . . . . . 17 84 6.2.4. Sending Probe Packets . . . . . . . . . . . . . . . . 17 85 6.3. Handling Retry Packets . . . . . . . . . . . . . . . . . 18 86 6.4. Discarding Keys and Packet State . . . . . . . . . . . . 19 87 7. Congestion Control . . . . . . . . . . . . . . . . . . . . . 19 88 7.1. Explicit Congestion Notification . . . . . . . . . . . . 20 89 7.2. Initial and Minimum Congestion Window . . . . . . . . . . 20 90 7.3. Congestion Control States . . . . . . . . . . . . . . . . 20 91 7.3.1. Slow Start . . . . . . . . . . . . . . . . . . . . . 21 92 7.3.2. Recovery . . . . . . . . . . . . . . . . . . . . . . 21 93 7.3.3. Congestion Avoidance . . . . . . . . . . . . . . . . 22 94 7.4. Ignoring Loss of Undecryptable Packets . . . . . . . . . 22 95 7.5. Probe Timeout . . . . . . . . . . . . . . . . . . . . . . 23 96 7.6. Persistent Congestion . . . . . . . . . . . . . . . . . . 23 97 7.6.1. Duration . . . . . . . . . . . . . . . . . . . . . . 23 98 7.6.2. Establishing Persistent Congestion . . . . . . . . . 24 99 7.6.3. Example . . . . . . . . . . . . . . . . . . . . . . . 24 100 7.7. Pacing . . . . . . . . . . . . . . . . . . . . . . . . . 25 101 7.8. Under-utilizing the Congestion Window . . . . . . . . . . 27 102 8. Security Considerations . . . . . . . . . . . . . . . . . . . 27 103 8.1. Congestion Signals . . . . . . . . . . . . . . . . . . . 27 104 8.2. Traffic Analysis . . . . . . . . . . . . . . . . . . . . 27 105 8.3. Misreporting ECN Markings . . . . . . . . . . . . . . . . 27 106 9. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 28 107 10. References . . . . . . . . . . . . . . . . . . . . . . . . . 28 108 10.1. Normative References . . . . . . . . . . . . . . . . . . 28 109 10.2. Informative References . . . . . . . . . . . . . . . . . 29 110 Appendix A. Loss Recovery Pseudocode . . . . . . . . . . . . . . 30 111 A.1. Tracking Sent Packets . . . . . . . . . . . . . . . . . . 30 112 A.1.1. Sent Packet Fields . . . . . . . . . . . . . . . . . 31 113 A.2. Constants of Interest . . . . . . . . . . . . . . . . . . 31 114 A.3. Variables of interest . . . . . . . . . . . . . . . . . . 32 115 A.4. Initialization . . . . . . . . . . . . . . . . . . . . . 33 116 A.5. On Sending a Packet . . . . . . . . . . . . . . . . . . . 33 117 A.6. On Receiving a Datagram . . . . . . . . . . . . . . . . . 33 118 A.7. On Receiving an Acknowledgment . . . . . . . . . . . . . 34 119 A.8. Setting the Loss Detection Timer . . . . . . . . . . . . 35 120 A.9. On Timeout . . . . . . . . . . . . . . . . . . . . . . . 37 121 A.10. Detecting Lost Packets . . . . . . . . . . . . . . . . . 38 122 Appendix B. Congestion Control Pseudocode . . . . . . . . . . . 39 123 B.1. Constants of interest . . . . . . . . . . . . . . . . . . 39 124 B.2. Variables of interest . . . . . . . . . . . . . . . . . . 40 125 B.3. Initialization . . . . . . . . . . . . . . . . . . . . . 40 126 B.4. On Packet Sent . . . . . . . . . . . . . . . . . . . . . 41 127 B.5. On Packet Acknowledgement . . . . . . . . . . . . . . . . 41 128 B.6. On New Congestion Event . . . . . . . . . . . . . . . . . 42 129 B.7. Process ECN Information . . . . . . . . . . . . . . . . . 43 130 B.8. On Packets Lost . . . . . . . . . . . . . . . . . . . . . 43 131 B.9. Upon dropping Initial or Handshake keys . . . . . . . . . 43 132 Appendix C. Change Log . . . . . . . . . . . . . . . . . . . . . 44 133 C.1. Since draft-ietf-quic-recovery-30 . . . . . . . . . . . . 44 134 C.2. Since draft-ietf-quic-recovery-29 . . . . . . . . . . . . 44 135 C.3. Since draft-ietf-quic-recovery-28 . . . . . . . . . . . . 44 136 C.4. Since draft-ietf-quic-recovery-27 . . . . . . . . . . . . 45 137 C.5. Since draft-ietf-quic-recovery-26 . . . . . . . . . . . . 45 138 C.6. Since draft-ietf-quic-recovery-25 . . . . . . . . . . . . 45 139 C.7. Since draft-ietf-quic-recovery-24 . . . . . . . . . . . . 45 140 C.8. Since draft-ietf-quic-recovery-23 . . . . . . . . . . . . 45 141 C.9. Since draft-ietf-quic-recovery-22 . . . . . . . . . . . . 46 142 C.10. Since draft-ietf-quic-recovery-21 . . . . . . . . . . . . 46 143 C.11. Since draft-ietf-quic-recovery-20 . . . . . . . . . . . . 46 144 C.12. Since draft-ietf-quic-recovery-19 . . . . . . . . . . . . 46 145 C.13. Since draft-ietf-quic-recovery-18 . . . . . . . . . . . . 47 146 C.14. Since draft-ietf-quic-recovery-17 . . . . . . . . . . . . 47 147 C.15. Since draft-ietf-quic-recovery-16 . . . . . . . . . . . . 47 148 C.16. Since draft-ietf-quic-recovery-14 . . . . . . . . . . . . 48 149 C.17. Since draft-ietf-quic-recovery-13 . . . . . . . . . . . . 48 150 C.18. Since draft-ietf-quic-recovery-12 . . . . . . . . . . . . 48 151 C.19. Since draft-ietf-quic-recovery-11 . . . . . . . . . . . . 49 152 C.20. Since draft-ietf-quic-recovery-10 . . . . . . . . . . . . 49 153 C.21. Since draft-ietf-quic-recovery-09 . . . . . . . . . . . . 49 154 C.22. Since draft-ietf-quic-recovery-08 . . . . . . . . . . . . 49 155 C.23. Since draft-ietf-quic-recovery-07 . . . . . . . . . . . . 49 156 C.24. Since draft-ietf-quic-recovery-06 . . . . . . . . . . . . 49 157 C.25. Since draft-ietf-quic-recovery-05 . . . . . . . . . . . . 49 158 C.26. Since draft-ietf-quic-recovery-04 . . . . . . . . . . . . 50 159 C.27. Since draft-ietf-quic-recovery-03 . . . . . . . . . . . . 50 160 C.28. Since draft-ietf-quic-recovery-02 . . . . . . . . . . . . 50 161 C.29. Since draft-ietf-quic-recovery-01 . . . . . . . . . . . . 50 162 C.30. Since draft-ietf-quic-recovery-00 . . . . . . . . . . . . 50 163 C.31. Since draft-iyengar-quic-loss-recovery-01 . . . . . . . . 50 164 Appendix D. Contributors . . . . . . . . . . . . . . . . . . . . 51 165 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . 51 166 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 51 168 1. Introduction 170 QUIC is a new multiplexed and secure transport protocol atop UDP, 171 specified in [QUIC-TRANSPORT]. This document describes congestion 172 control and loss recovery for QUIC. Mechanisms described in this 173 document follow the spirit of existing TCP congestion control and 174 loss recovery mechanisms, described in RFCs, various Internet-drafts, 175 or academic papers, and also those prevalent in TCP implementations. 177 2. Conventions and Definitions 179 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 180 "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and 181 "OPTIONAL" in this document are to be interpreted as described in 182 BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all 183 capitals, as shown here. 185 Definitions of terms that are used in this document: 187 Ack-eliciting frames: All frames other than ACK, PADDING, and 188 CONNECTION_CLOSE are considered ack-eliciting. 190 Ack-eliciting packets: Packets that contain ack-eliciting frames 191 elicit an ACK from the receiver within the maximum acknowledgement 192 delay and are called ack-eliciting packets. 194 In-flight: Packets are considered in-flight when they are ack- 195 eliciting or contain a PADDING frame, and they have been sent but 196 are not acknowledged, declared lost, or discarded along with old 197 keys. 199 3. Design of the QUIC Transmission Machinery 201 All transmissions in QUIC are sent with a packet-level header, which 202 indicates the encryption level and includes a packet sequence number 203 (referred to below as a packet number). The encryption level 204 indicates the packet number space, as described in [QUIC-TRANSPORT]. 205 Packet numbers never repeat within a packet number space for the 206 lifetime of a connection. Packet numbers are sent in monotonically 207 increasing order within a space, preventing ambiguity. 209 This design obviates the need for disambiguating between 210 transmissions and retransmissions; this eliminates significant 211 complexity from QUIC's interpretation of TCP loss detection 212 mechanisms. 214 QUIC packets can contain multiple frames of different types. The 215 recovery mechanisms ensure that data and frames that need reliable 216 delivery are acknowledged or declared lost and sent in new packets as 217 necessary. The types of frames contained in a packet affect recovery 218 and congestion control logic: 220 * All packets are acknowledged, though packets that contain no ack- 221 eliciting frames are only acknowledged along with ack-eliciting 222 packets. 224 * Long header packets that contain CRYPTO frames are critical to the 225 performance of the QUIC handshake and use shorter timers for 226 acknowledgement. 228 * Packets containing frames besides ACK or CONNECTION_CLOSE frames 229 count toward congestion control limits and are considered in- 230 flight. 232 * PADDING frames cause packets to contribute toward bytes in flight 233 without directly causing an acknowledgment to be sent. 235 4. Relevant Differences Between QUIC and TCP 237 Readers familiar with TCP's loss detection and congestion control 238 will find algorithms here that parallel well-known TCP ones. 239 However, protocol differences between QUIC and TCP contribute to 240 algorithmic differences. These protocol differences are briefly 241 described below. 243 4.1. Separate Packet Number Spaces 245 QUIC uses separate packet number spaces for each encryption level, 246 except 0-RTT and all generations of 1-RTT keys use the same packet 247 number space. Separate packet number spaces ensures acknowledgement 248 of packets sent with one level of encryption will not cause spurious 249 retransmission of packets sent with a different encryption level. 250 Congestion control and round-trip time (RTT) measurement are unified 251 across packet number spaces. 253 4.2. Monotonically Increasing Packet Numbers 255 TCP conflates transmission order at the sender with delivery order at 256 the receiver, which results in retransmissions of the same data 257 carrying the same sequence number, and consequently leads to 258 "retransmission ambiguity". QUIC separates the two. QUIC uses a 259 packet number to indicate transmission order. Application data is 260 sent in one or more streams and delivery order is determined by 261 stream offsets encoded within STREAM frames. 263 QUIC's packet number is strictly increasing within a packet number 264 space, and directly encodes transmission order. A higher packet 265 number signifies that the packet was sent later, and a lower packet 266 number signifies that the packet was sent earlier. When a packet 267 containing ack-eliciting frames is detected lost, QUIC includes 268 necessary frames in a new packet with a new packet number, removing 269 ambiguity about which packet is acknowledged when an ACK is received. 270 Consequently, more accurate RTT measurements can be made, spurious 271 retransmissions are trivially detected, and mechanisms such as Fast 272 Retransmit can be applied universally, based only on packet number. 274 This design point significantly simplifies loss detection mechanisms 275 for QUIC. Most TCP mechanisms implicitly attempt to infer 276 transmission ordering based on TCP sequence numbers - a non-trivial 277 task, especially when TCP timestamps are not available. 279 4.3. Clearer Loss Epoch 281 QUIC starts a loss epoch when a packet is lost and ends one when any 282 packet sent after the epoch starts is acknowledged. TCP waits for 283 the gap in the sequence number space to be filled, and so if a 284 segment is lost multiple times in a row, the loss epoch may not end 285 for several round trips. Because both should reduce their congestion 286 windows only once per epoch, QUIC will do it once for every round 287 trip that experiences loss, while TCP may only do it once across 288 multiple round trips. 290 4.4. No Reneging 292 QUIC ACKs contain information that is similar to TCP SACK, but QUIC 293 does not allow any acknowledged packet to be reneged, greatly 294 simplifying implementations on both sides and reducing memory 295 pressure on the sender. 297 4.5. More ACK Ranges 299 QUIC supports many ACK ranges, opposed to TCP's 3 SACK ranges. In 300 high loss environments, this speeds recovery, reduces spurious 301 retransmits, and ensures forward progress without relying on 302 timeouts. 304 4.6. Explicit Correction For Delayed Acknowledgements 306 QUIC endpoints measure the delay incurred between when a packet is 307 received and when the corresponding acknowledgment is sent, allowing 308 a peer to maintain a more accurate round-trip time estimate; see 309 Section 13.2 of [QUIC-TRANSPORT]. 311 4.7. Probe Timeout Replaces RTO and TLP 313 QUIC uses a probe timeout (PTO; see Section 6.2), with a timer based 314 on TCP's RTO computation. QUIC's PTO includes the peer's maximum 315 expected acknowledgement delay instead of using a fixed minimum 316 timeout. QUIC does not collapse the congestion window until 317 persistent congestion (Section 7.6) is declared, unlike TCP, which 318 collapses the congestion window upon expiry of an RTO. Instead of 319 collapsing the congestion window and declaring everything in-flight 320 lost, QUIC allows probe packets to temporarily exceed the congestion 321 window whenever the timer expires. 323 In doing this, QUIC avoids unnecessary congestion window reductions, 324 obviating the need for correcting mechanisms such as F-RTO 325 ([RFC5682]). Since QUIC does not collapse the congestion window on a 326 PTO expiration, a QUIC sender is not limited from sending more in- 327 flight packets after a PTO expiration if it still has available 328 congestion window. This occurs when a sender is application-limited 329 and the PTO timer expires. This is more aggressive than TCP's RTO 330 mechanism when application-limited, but identical when not 331 application-limited. 333 A single packet loss at the tail does not indicate persistent 334 congestion, so QUIC specifies a time-based definition to ensure one 335 or more packets are sent prior to a dramatic decrease in congestion 336 window; see Section 7.6. 338 4.8. The Minimum Congestion Window is Two Packets 340 TCP uses a minimum congestion window of one packet. However, loss of 341 that single packet means that the sender needs to waiting for a PTO 342 (Section 6.2) to recover, which can be much longer than a round-trip 343 time. Sending a single ack-eliciting packet also increases the 344 chances of incurring additional latency when a receiver delays its 345 acknowledgement. 347 QUIC therefore recommends that the minimum congestion window be two 348 packets. While this increases network load, it is considered safe, 349 since the sender will still reduce its sending rate exponentially 350 under persistent congestion (Section 6.2). 352 5. Estimating the Round-Trip Time 354 At a high level, an endpoint measures the time from when a packet was 355 sent to when it is acknowledged as a round-trip time (RTT) sample. 356 The endpoint uses RTT samples and peer-reported host delays (see 357 Section 13.2 of [QUIC-TRANSPORT]) to generate a statistical 358 description of the network path's RTT. An endpoint computes the 359 following three values for each path: the minimum value observed over 360 the lifetime of the path (min_rtt), an exponentially-weighted moving 361 average (smoothed_rtt), and the mean deviation (referred to as 362 "variation" in the rest of this document) in the observed RTT samples 363 (rttvar). 365 5.1. Generating RTT samples 367 An endpoint generates an RTT sample on receiving an ACK frame that 368 meets the following two conditions: 370 * the largest acknowledged packet number is newly acknowledged, and 372 * at least one of the newly acknowledged packets was ack-eliciting. 374 The RTT sample, latest_rtt, is generated as the time elapsed since 375 the largest acknowledged packet was sent: 377 latest_rtt = ack_time - send_time_of_largest_acked 379 An RTT sample is generated using only the largest acknowledged packet 380 in the received ACK frame. This is because a peer reports 381 acknowledgment delays for only the largest acknowledged packet in an 382 ACK frame. While the reported acknowledgment delay is not used by 383 the RTT sample measurement, it is used to adjust the RTT sample in 384 subsequent computations of smoothed_rtt and rttvar (Section 5.3). 386 To avoid generating multiple RTT samples for a single packet, an ACK 387 frame SHOULD NOT be used to update RTT estimates if it does not newly 388 acknowledge the largest acknowledged packet. 390 An RTT sample MUST NOT be generated on receiving an ACK frame that 391 does not newly acknowledge at least one ack-eliciting packet. A peer 392 usually does not send an ACK frame when only non-ack-eliciting 393 packets are received. Therefore an ACK frame that contains 394 acknowledgements for only non-ack-eliciting packets could include an 395 arbitrarily large ACK Delay value. Ignoring such ACK frames avoids 396 complications in subsequent smoothed_rtt and rttvar computations. 398 A sender might generate multiple RTT samples per RTT when multiple 399 ACK frames are received within an RTT. As suggested in [RFC6298], 400 doing so might result in inadequate history in smoothed_rtt and 401 rttvar. Ensuring that RTT estimates retain sufficient history is an 402 open research question. 404 5.2. Estimating min_rtt 406 min_rtt is the sender's estimate of the minimum RTT observed for a 407 given network path. In this document, min_rtt is used by loss 408 detection to reject implausibly small rtt samples. 410 min_rtt MUST be set to the latest_rtt on the first RTT sample. 411 min_rtt MUST be set to the lesser of min_rtt and latest_rtt 412 (Section 5.1) on all other samples. 414 An endpoint uses only locally observed times in computing the min_rtt 415 and does not adjust for acknowledgment delays reported by the peer. 416 Doing so allows the endpoint to set a lower bound for the 417 smoothed_rtt based entirely on what it observes (see Section 5.3), 418 and limits potential underestimation due to erroneously-reported 419 delays by the peer. 421 The RTT for a network path may change over time. If a path's actual 422 RTT decreases, the min_rtt will adapt immediately on the first low 423 sample. If the path's actual RTT increases however, the min_rtt will 424 not adapt to it, allowing future RTT samples that are smaller than 425 the new RTT to be included in smoothed_rtt. 427 Endpoints SHOULD set the min_rtt to the newest RTT sample after 428 persistent congestion is established. This is to allow a connection 429 to reset its estimate of min_rtt and smoothed_rtt (Section 5.3) after 430 a disruptive network event, and because it is possible that an 431 increase in path delay resulted in persistent congestion being 432 incorrectly declared. 434 Endpoints MAY re-establish the min_rtt at other times in the 435 connection, such as when traffic volume is low and an acknowledgement 436 is received with a low acknowledgement delay. Implementations SHOULD 437 NOT refresh the min_rtt value too often, since the actual minimum RTT 438 of the path is not frequently observable. 440 5.3. Estimating smoothed_rtt and rttvar 442 smoothed_rtt is an exponentially-weighted moving average of an 443 endpoint's RTT samples, and rttvar is the variation in the RTT 444 samples, estimated using a mean variation. 446 The calculation of smoothed_rtt uses RTT samples after adjusting them 447 for acknowledgement delays. These delays are computed using the ACK 448 Delay field of the ACK frame as described in Section 19.3 of 449 [QUIC-TRANSPORT]. 451 The peer might report acknowledgement delays that are larger than the 452 peer's max_ack_delay during the handshake (Section 13.2.1 of 453 [QUIC-TRANSPORT]). To account for this, the endpoint SHOULD ignore 454 max_ack_delay until the handshake is confirmed (Section 4.1.2 of 455 [QUIC-TLS]). When they occur, these large acknowledgement delays are 456 likely to be non-repeating and limited to the handshake. The 457 endpoint can therefore use them without limiting them to the 458 max_ack_delay, avoiding unnecessary inflation of the RTT estimate. 460 Note however that a large acknowledgement delay can result in a 461 substantially inflated smoothed_rtt, if there is either an error in 462 the peer's reporting of the acknowledgement delay or in the 463 endpoint's min_rtt estimate. Therefore, prior to handshake 464 confirmation, an endpoint MAY ignore RTT samples if adjusting the RTT 465 sample for acknowledgement delay causes the sample to be less than 466 the min_rtt. 468 After the handshake is confirmed, any acknowledgement delays reported 469 by the peer that are greater than the peer's max_ack_delay are 470 attributed to unintentional but potentially repeating delays, such as 471 scheduler latency at the peer or loss of previous acknowledgements. 472 Therefore, these extra delays are considered effectively part of path 473 delay and incorporated into the RTT estimate. 475 Therefore, when adjusting an RTT sample using peer-reported 476 acknowledgement delays, an endpoint: 478 * MAY ignore the acknowledgement delay for Initial packets, since 479 these acknowledgements are not delayed by the peer (Section 13.2.1 480 of [QUIC-TRANSPORT]); 482 * SHOULD ignore the peer's max_ack_delay until the handshake is 483 confirmed; 485 * MUST use the lesser of the acknowledgement delay and the peer's 486 max_ack_delay after the handshake is confirmed; and 488 * MUST NOT subtract the acknowledgement delay from the RTT sample if 489 the resulting value is smaller than the min_rtt. This limits the 490 underestimation of the smoothed_rtt due to a misreporting peer. 492 Additionally, an endpoint might postpone the processing of 493 acknowledgements when the corresponding decryption keys are not 494 immediately available. For example, a client might receive an 495 acknowledgement for a 0-RTT packet that it cannot decrypt because 496 1-RTT packet protection keys are not yet available to it. In such 497 cases, an endpoint SHOULD subtract such local delays from its RTT 498 sample until the handshake is confirmed. 500 smoothed_rtt and rttvar are computed as follows, similar to 501 [RFC6298]. 503 When there are no samples for a network path, and on the first RTT 504 sample for the network path: 506 smoothed_rtt = rtt_sample 507 rttvar = rtt_sample / 2 509 Before any RTT samples are available, the initial RTT is used as 510 rtt_sample. On the first RTT sample for the network path, that 511 sample is used as rtt_sample. This ensures that the first 512 measurement erases the history of any persisted or default values. 514 On subsequent RTT samples, smoothed_rtt and rttvar evolve as follows: 516 ack_delay = decoded acknowledgement delay from ACK frame 517 if (handshake confirmed): 518 ack_delay = min(ack_delay, max_ack_delay) 519 adjusted_rtt = latest_rtt 520 if (min_rtt + ack_delay < latest_rtt): 521 adjusted_rtt = latest_rtt - ack_delay 522 smoothed_rtt = 7/8 * smoothed_rtt + 1/8 * adjusted_rtt 523 rttvar_sample = abs(smoothed_rtt - adjusted_rtt) 524 rttvar = 3/4 * rttvar + 1/4 * rttvar_sample 526 6. Loss Detection 528 QUIC senders use acknowledgements to detect lost packets, and a probe 529 time out (see Section 6.2) to ensure acknowledgements are received. 530 This section provides a description of these algorithms. 532 If a packet is lost, the QUIC transport needs to recover from that 533 loss, such as by retransmitting the data, sending an updated frame, 534 or discarding the frame. For more information, see Section 13.3 of 535 [QUIC-TRANSPORT]. 537 Loss detection is separate per packet number space, unlike RTT 538 measurement and congestion control, because RTT and congestion 539 control are properties of the path, whereas loss detection also 540 relies upon key availability. 542 6.1. Acknowledgement-Based Detection 544 Acknowledgement-based loss detection implements the spirit of TCP's 545 Fast Retransmit ([RFC5681]), Early Retransmit ([RFC5827]), FACK 546 ([FACK]), SACK loss recovery ([RFC6675]), and RACK ([RACK]). This 547 section provides an overview of how these algorithms are implemented 548 in QUIC. 550 A packet is declared lost if it meets all the following conditions: 552 * The packet is unacknowledged, in-flight, and was sent prior to an 553 acknowledged packet. 555 * Either its packet number is kPacketThreshold smaller than an 556 acknowledged packet (Section 6.1.1), or it was sent long enough in 557 the past (Section 6.1.2). 559 The acknowledgement indicates that a packet sent later was delivered, 560 and the packet and time thresholds provide some tolerance for packet 561 reordering. 563 Spuriously declaring packets as lost leads to unnecessary 564 retransmissions and may result in degraded performance due to the 565 actions of the congestion controller upon detecting loss. 566 Implementations can detect spurious retransmissions and increase the 567 reordering threshold in packets or time to reduce future spurious 568 retransmissions and loss events. Implementations with adaptive time 569 thresholds MAY choose to start with smaller initial reordering 570 thresholds to minimize recovery latency. 572 6.1.1. Packet Threshold 574 The RECOMMENDED initial value for the packet reordering threshold 575 (kPacketThreshold) is 3, based on best practices for TCP loss 576 detection ([RFC5681], [RFC6675]). In order to remain similar to TCP, 577 implementations SHOULD NOT use a packet threshold less than 3; see 578 [RFC5681]. 580 Some networks may exhibit higher degrees of packet reordering, 581 causing a sender to detect spurious losses. Additionally, packet 582 reordering could be more common with QUIC than TCP, because network 583 elements that could observe and reorder TCP packets cannot do that 584 for QUIC, because QUIC packet numbers are encrypted. Algorithms that 585 increase the reordering threshold after spuriously detecting losses, 586 such as RACK [RACK], have proven to be useful in TCP and are expected 587 to be at least as useful in QUIC. 589 6.1.2. Time Threshold 591 Once a later packet within the same packet number space has been 592 acknowledged, an endpoint SHOULD declare an earlier packet lost if it 593 was sent a threshold amount of time in the past. To avoid declaring 594 packets as lost too early, this time threshold MUST be set to at 595 least the local timer granularity, as indicated by the kGranularity 596 constant. The time threshold is: 598 max(kTimeThreshold * max(smoothed_rtt, latest_rtt), kGranularity) 600 If packets sent prior to the largest acknowledged packet cannot yet 601 be declared lost, then a timer SHOULD be set for the remaining time. 603 Using max(smoothed_rtt, latest_rtt) protects from the two following 604 cases: 606 * the latest RTT sample is lower than the smoothed RTT, perhaps due 607 to reordering where the acknowledgement encountered a shorter 608 path; 610 * the latest RTT sample is higher than the smoothed RTT, perhaps due 611 to a sustained increase in the actual RTT, but the smoothed RTT 612 has not yet caught up. 614 The RECOMMENDED time threshold (kTimeThreshold), expressed as a 615 round-trip time multiplier, is 9/8. The RECOMMENDED value of the 616 timer granularity (kGranularity) is 1ms. 618 Note: TCP's RACK ([RACK]) specifies a slightly larger threshold, 619 equivalent to 5/4, for a similar purpose. Experience with QUIC 620 shows that 9/8 works well. 622 Implementations MAY experiment with absolute thresholds, thresholds 623 from previous connections, adaptive thresholds, or including RTT 624 variation. Smaller thresholds reduce reordering resilience and 625 increase spurious retransmissions, and larger thresholds increase 626 loss detection delay. 628 6.2. Probe Timeout 630 A Probe Timeout (PTO) triggers sending one or two probe datagrams 631 when ack-eliciting packets are not acknowledged within the expected 632 period of time or the server may not have validated the client's 633 address. A PTO enables a connection to recover from loss of tail 634 packets or acknowledgements. 636 As with loss detection, the probe timeout is per packet number space. 637 That is, a PTO value is computed per packet number space. 639 A PTO timer expiration event does not indicate packet loss and MUST 640 NOT cause prior unacknowledged packets to be marked as lost. When an 641 acknowledgement is received that newly acknowledges packets, loss 642 detection proceeds as dictated by packet and time threshold 643 mechanisms; see Section 6.1. 645 The PTO algorithm used in QUIC implements the reliability functions 646 of Tail Loss Probe [RACK], RTO [RFC5681], and F-RTO algorithms for 647 TCP [RFC5682]. The timeout computation is based on TCP's 648 retransmission timeout period [RFC6298]. 650 6.2.1. Computing PTO 652 When an ack-eliciting packet is transmitted, the sender schedules a 653 timer for the PTO period as follows: 655 PTO = smoothed_rtt + max(4*rttvar, kGranularity) + max_ack_delay 657 The PTO period is the amount of time that a sender ought to wait for 658 an acknowledgement of a sent packet. This time period includes the 659 estimated network roundtrip-time (smoothed_rtt), the variation in the 660 estimate (4*rttvar), and max_ack_delay, to account for the maximum 661 time by which a receiver might delay sending an acknowledgement. 663 When the PTO is armed for Initial or Handshake packet number spaces, 664 the max_ack_delay in the PTO period computation is set to 0, since 665 the peer is expected to not delay these packets intentionally; see 666 13.2.1 of [QUIC-TRANSPORT]. 668 The PTO period MUST be at least kGranularity, to avoid the timer 669 expiring immediately. 671 When ack-eliciting packets in multiple packet number spaces are in 672 flight, the timer MUST be set to the earlier value of the Initial and 673 Handshake packet number spaces. 675 An endpoint MUST NOT set its PTO timer for the application data 676 packet number space until the handshake is confirmed. Doing so 677 prevents the endpoint from retransmitting information in packets when 678 either the peer does not yet have the keys to process them or the 679 endpoint does not yet have the keys to process their 680 acknowledgements. For example, this can happen when a client sends 681 0-RTT packets to the server; it does so without knowing whether the 682 server will be able to decrypt them. Similarly, this can happen when 683 a server sends 1-RTT packets before confirming that the client has 684 verified the server's certificate and can therefore read these 1-RTT 685 packets. 687 A sender SHOULD restart its PTO timer every time an ack-eliciting 688 packet is sent or acknowledged, when the handshake is confirmed 689 (Section 4.1.2 of [QUIC-TLS]), or when Initial or Handshake keys are 690 discarded (Section 9 of [QUIC-TLS]). This ensures the PTO is always 691 set based on the latest estimate of the round-trip time and for the 692 correct packet across packet number spaces. 694 When a PTO timer expires, the PTO backoff MUST be increased, 695 resulting in the PTO period being set to twice its current value. 696 The PTO backoff factor is reset when an acknowledgement is received, 697 except in the following case. A server might take longer to respond 698 to packets during the handshake than otherwise. To protect such a 699 server from repeated client probes, the PTO backoff is not reset at a 700 client that is not yet certain that the server has finished 701 validating the client's address. That is, a client does not reset 702 the PTO backoff factor on receiving acknowledgements until the 703 handshake is confirmed; see Section 4.1.2 of [QUIC-TLS]. 705 This exponential reduction in the sender's rate is important because 706 consecutive PTOs might be caused by loss of packets or 707 acknowledgements due to severe congestion. Even when there are ack- 708 eliciting packets in-flight in multiple packet number spaces, the 709 exponential increase in probe timeout occurs across all spaces to 710 prevent excess load on the network. For example, a timeout in the 711 Initial packet number space doubles the length of the timeout in the 712 Handshake packet number space. 714 The total length of time over which consecutive PTOs expire is 715 limited by the idle timeout. 717 The probe timer MUST NOT be set if the time threshold (Section 6.1.2) 718 loss detection timer is set. The time threshold loss detection timer 719 is expected to both expire earlier than the PTO and be less likely to 720 spuriously retransmit data. 722 6.2.2. Handshakes and New Paths 724 Resumed connections over the same network MAY use the previous 725 connection's final smoothed RTT value as the resumed connection's 726 initial RTT. When no previous RTT is available, the initial RTT 727 SHOULD be set to 333ms, resulting in a 1 second initial timeout, as 728 recommended in [RFC6298]. 730 A connection MAY use the delay between sending a PATH_CHALLENGE and 731 receiving a PATH_RESPONSE to set the initial RTT (see kInitialRtt in 732 Appendix A.2) for a new path, but the delay SHOULD NOT be considered 733 an RTT sample. 735 Initial packets and Handshake packets could be never acknowledged, 736 but they are removed from bytes in flight when the Initial and 737 Handshake keys are discarded, as described below in Section 6.4. 738 When Initial or Handshake keys are discarded, the PTO and loss 739 detection timers MUST be reset, because discarding keys indicates 740 forward progress and the loss detection timer might have been set for 741 a now discarded packet number space. 743 6.2.2.1. Before Address Validation 745 Until the server has validated the client's address on the path, the 746 amount of data it can send is limited to three times the amount of 747 data received, as specified in Section 8.1 of [QUIC-TRANSPORT]. If 748 no additional data can be sent, the server's PTO timer MUST NOT be 749 armed until datagrams have been received from the client, because 750 packets sent on PTO count against the anti-amplification limit. Note 751 that the server could fail to validate the client's address even if 752 0-RTT is accepted. 754 Since the server could be blocked until more datagrams are received 755 from the client, it is the client's responsibility to send packets to 756 unblock the server until it is certain that the server has finished 757 its address validation (see Section 8 of [QUIC-TRANSPORT]). That is, 758 the client MUST set the probe timer if the client has not received an 759 acknowledgement for one of its Handshake packets and the handshake is 760 not confirmed (see Section 4.1.2 of [QUIC-TLS]), even if there are no 761 packets in flight. When the PTO fires, the client MUST send a 762 Handshake packet if it has Handshake keys, otherwise it MUST send an 763 Initial packet in a UDP datagram with a payload of at least 1200 764 bytes. 766 6.2.3. Speeding Up Handshake Completion 768 When a server receives an Initial packet containing duplicate CRYPTO 769 data, it can assume the client did not receive all of the server's 770 CRYPTO data sent in Initial packets, or the client's estimated RTT is 771 too small. When a client receives Handshake or 1-RTT packets prior 772 to obtaining Handshake keys, it may assume some or all of the 773 server's Initial packets were lost. 775 To speed up handshake completion under these conditions, an endpoint 776 MAY send a packet containing unacknowledged CRYPTO data earlier than 777 the PTO expiry, subject to the address validation limits in 778 Section 8.1 of [QUIC-TRANSPORT]. 780 Endpoints can also use coalesced packets (see Section 12.2 of 781 [QUIC-TRANSPORT]) to ensure that each datagram elicits at least one 782 acknowledgement. For example, a client can coalesce an Initial 783 packet containing PING and PADDING frames with a 0-RTT data packet 784 and a server can coalesce an Initial packet containing a PING frame 785 with one or more packets in its first flight. 787 6.2.4. Sending Probe Packets 789 When a PTO timer expires, a sender MUST send at least one ack- 790 eliciting packet in the packet number space as a probe. An endpoint 791 MAY send up to two full-sized datagrams containing ack-eliciting 792 packets, to avoid an expensive consecutive PTO expiration due to a 793 single lost datagram or transmit data from multiple packet number 794 spaces. All probe packets sent on a PTO MUST be ack-eliciting. 796 In addition to sending data in the packet number space for which the 797 timer expired, the sender SHOULD send ack-eliciting packets from 798 other packet number spaces with in-flight data, coalescing packets if 799 possible. This is particularly valuable when the server has both 800 Initial and Handshake data in-flight or the client has both Handshake 801 and Application Data in-flight, because the peer might only have 802 receive keys for one of the two packet number spaces. 804 If the sender wants to elicit a faster acknowledgement on PTO, it can 805 skip a packet number to eliminate the acknowledgment delay. 807 When the PTO timer expires, an ack-eliciting packet MUST be sent. An 808 endpoint SHOULD include new data in this packet. Previously sent 809 data MAY be sent if no new data can be sent. Implementations MAY use 810 alternative strategies for determining the content of probe packets, 811 including sending new or retransmitted data based on the 812 application's priorities. 814 It is possible the sender has no new or previously-sent data to send. 815 As an example, consider the following sequence of events: new 816 application data is sent in a STREAM frame, deemed lost, then 817 retransmitted in a new packet, and then the original transmission is 818 acknowledged. When there is no data to send, the sender SHOULD send 819 a PING or other ack-eliciting frame in a single packet, re-arming the 820 PTO timer. 822 Alternatively, instead of sending an ack-eliciting packet, the sender 823 MAY mark any packets still in flight as lost. Doing so avoids 824 sending an additional packet, but increases the risk that loss is 825 declared too aggressively, resulting in an unnecessary rate reduction 826 by the congestion controller. 828 Consecutive PTO periods increase exponentially, and as a result, 829 connection recovery latency increases exponentially as packets 830 continue to be dropped in the network. Sending two packets on PTO 831 expiration increases resilience to packet drops, thus reducing the 832 probability of consecutive PTO events. 834 When the PTO timer expires multiple times and new data cannot be 835 sent, implementations must choose between sending the same payload 836 every time or sending different payloads. Sending the same payload 837 may be simpler and ensures the highest priority frames arrive first. 838 Sending different payloads each time reduces the chances of spurious 839 retransmission. 841 6.3. Handling Retry Packets 843 A Retry packet causes a client to send another Initial packet, 844 effectively restarting the connection process. A Retry packet 845 indicates that the Initial was received, but not processed. A Retry 846 packet cannot be treated as an acknowledgment, because it does not 847 indicate that a packet was processed or specify the packet number. 849 Clients that receive a Retry packet reset congestion control and loss 850 recovery state, including resetting any pending timers. Other 851 connection state, in particular cryptographic handshake messages, is 852 retained; see Section 17.2.5 of [QUIC-TRANSPORT]. 854 The client MAY compute an RTT estimate to the server as the time 855 period from when the first Initial was sent to when a Retry or a 856 Version Negotiation packet is received. The client MAY use this 857 value in place of its default for the initial RTT estimate. 859 6.4. Discarding Keys and Packet State 861 When packet protection keys are discarded (see Section 4.8 of 862 [QUIC-TLS]), all packets that were sent with those keys can no longer 863 be acknowledged because their acknowledgements cannot be processed 864 anymore. The sender MUST discard all recovery state associated with 865 those packets and MUST remove them from the count of bytes in flight. 867 Endpoints stop sending and receiving Initial packets once they start 868 exchanging Handshake packets; see Section 17.2.2.1 of 869 [QUIC-TRANSPORT]. At this point, recovery state for all in-flight 870 Initial packets is discarded. 872 When 0-RTT is rejected, recovery state for all in-flight 0-RTT 873 packets is discarded. 875 If a server accepts 0-RTT, but does not buffer 0-RTT packets that 876 arrive before Initial packets, early 0-RTT packets will be declared 877 lost, but that is expected to be infrequent. 879 It is expected that keys are discarded after packets encrypted with 880 them would be acknowledged or declared lost. However, Initial 881 secrets are discarded as soon as handshake keys are proven to be 882 available to both client and server; see Section 4.9.1 of [QUIC-TLS]. 884 7. Congestion Control 886 This document specifies a congestion controller for QUIC similar to 887 TCP NewReno ([RFC6582]). 889 The signals QUIC provides for congestion control are generic and are 890 designed to support different algorithms. Endpoints can unilaterally 891 choose a different algorithm to use, such as Cubic ([RFC8312]). 893 If an endpoint uses a different controller than that specified in 894 this document, the chosen controller MUST conform to the congestion 895 control guidelines specified in Section 3.1 of [RFC8085]. 897 Similar to TCP, packets containing only ACK frames do not count 898 towards bytes in flight and are not congestion controlled. Unlike 899 TCP, QUIC can detect the loss of these packets and MAY use that 900 information to adjust the congestion controller or the rate of ACK- 901 only packets being sent, but this document does not describe a 902 mechanism for doing so. 904 The algorithm in this document specifies and uses the controller's 905 congestion window in bytes. 907 An endpoint MUST NOT send a packet if it would cause bytes_in_flight 908 (see Appendix B.2) to be larger than the congestion window, unless 909 the packet is sent on a PTO timer expiration (see Section 6.2) or 910 when entering recovery (see Section 7.3.2). 912 7.1. Explicit Congestion Notification 914 If a path has been validated to support ECN ([RFC3168], [RFC8311]), 915 QUIC treats a Congestion Experienced (CE) codepoint in the IP header 916 as a signal of congestion. This document specifies an endpoint's 917 response when its peer receives packets with the ECN-CE codepoint. 919 7.2. Initial and Minimum Congestion Window 921 QUIC begins every connection in slow start with the congestion window 922 set to an initial value. Endpoints SHOULD use an initial congestion 923 window of 10 times the maximum datagram size (max_datagram_size), 924 limited to the larger of 14720 bytes or twice the maximum datagram 925 size. This follows the analysis and recommendations in [RFC6928], 926 increasing the byte limit to account for the smaller 8 byte overhead 927 of UDP compared to the 20 byte overhead for TCP. 929 If the maximum datagram size changes during the connection, the 930 initial congestion window SHOULD be recalculated with the new size. 931 If the maximum datagram size is decreased in order to complete the 932 handshake, the congestion window SHOULD be set to the new initial 933 congestion window. 935 Prior to validating the client's address, the server can be further 936 limited by the anti-amplification limit as specified in Section 8.1 937 of [QUIC-TRANSPORT]. Though the anti-amplification limit can prevent 938 the congestion window from being fully utilized and therefore slow 939 down the increase in congestion window, it does not directly affect 940 the congestion window. 942 The minimum congestion window is the smallest value the congestion 943 window can decrease to as a response to loss, ECN-CE, or persistent 944 congestion. The RECOMMENDED value is 2 * max_datagram_size. 946 7.3. Congestion Control States 948 The NewReno congestion controller described in this document has 949 three distinct states, as shown in Figure 1. 951 New Path or +------------+ 952 persistent congestion | Slow | 953 (O)---------------------->| Start | 954 +------------+ 955 | 956 Loss or | 957 ECN-CE increase | 958 v 959 +------------+ Loss or +------------+ 960 | Congestion | ECN-CE increase | Recovery | 961 | Avoidance |------------------>| Period | 962 +------------+ +------------+ 963 ^ | 964 | | 965 +----------------------------+ 966 Acknowledgment of packet 967 sent during recovery 969 Figure 1: Congestion Control States and Transitions 971 These states and the transitions between them are described in 972 subsequent sections. 974 7.3.1. Slow Start 976 A NewReno sender is in slow start any time the congestion window is 977 below the slow start threshold. A sender begins in slow start 978 because the slow start threshold is initialized to an infinite value. 980 While a sender is in slow start, the congestion window increases by 981 the number of bytes acknowledged when each acknowledgment is 982 processed. This results in exponential growth of the congestion 983 window. 985 The sender MUST exit slow start and enter a recovery period when a 986 packet is lost or when the ECN-CE count reported by its peer 987 increases. 989 A sender re-enters slow start any time the congestion window is less 990 than the slow start threshold, which only occurs after persistent 991 congestion is declared. 993 7.3.2. Recovery 995 A NewReno sender enters a recovery period when it detects the loss of 996 a packet or the ECN-CE count reported by its peer increases. A 997 sender that is already in a recovery period stays in it and does not 998 re-enter it. 1000 On entering a recovery period, a sender MUST set the slow start 1001 threshold to half the value of the congestion window when loss is 1002 detected. The congestion window MUST be set to the reduced value of 1003 the slow start threshold before exiting the recovery period. 1005 Implementations MAY reduce the congestion window immediately upon 1006 entering a recovery period or use other mechanisms, such as 1007 Proportional Rate Reduction ([PRR]), to reduce the congestion window 1008 more gradually. If the congestion window is reduced immediately, a 1009 single packet can be sent prior to reduction. This speeds up loss 1010 recovery if the data in the lost packet is retransmitted and is 1011 similar to TCP as described in Section 5 of [RFC6675]. 1013 The recovery period aims to limit congestion window reduction to once 1014 per round trip. Therefore during a recovery period, the congestion 1015 window does not change in response to new losses or increases in the 1016 ECN-CE count. 1018 A recovery period ends and the sender enters congestion avoidance 1019 when a packet sent during the recovery period is acknowledged. This 1020 is slightly different from TCP's definition of recovery, which ends 1021 when the lost segment that started recovery is acknowledged 1022 ([RFC5681]). 1024 7.3.3. Congestion Avoidance 1026 A NewReno sender is in congestion avoidance any time the congestion 1027 window is at or above the slow start threshold and not in a recovery 1028 period. 1030 A sender in congestion avoidance uses an Additive Increase 1031 Multiplicative Decrease (AIMD) approach that MUST limit the increase 1032 to the congestion window to at most one maximum datagram size for 1033 each congestion window that is acknowledged. 1035 The sender exits congestion avoidance and enters a recovery period 1036 when a packet is lost or when the ECN-CE count reported by its peer 1037 increases. 1039 7.4. Ignoring Loss of Undecryptable Packets 1041 During the handshake, some packet protection keys might not be 1042 available when a packet arrives and the receiver can choose to drop 1043 the packet. In particular, Handshake and 0-RTT packets cannot be 1044 processed until the Initial packets arrive and 1-RTT packets cannot 1045 be processed until the handshake completes. Endpoints MAY ignore the 1046 loss of Handshake, 0-RTT, and 1-RTT packets that might have arrived 1047 before the peer had packet protection keys to process those packets. 1049 Endpoints MUST NOT ignore the loss of packets that were sent after 1050 the earliest acknowledged packet in a given packet number space. 1052 7.5. Probe Timeout 1054 Probe packets MUST NOT be blocked by the congestion controller. A 1055 sender MUST however count these packets as being additionally in 1056 flight, since these packets add network load without establishing 1057 packet loss. Note that sending probe packets might cause the 1058 sender's bytes in flight to exceed the congestion window until an 1059 acknowledgement is received that establishes loss or delivery of 1060 packets. 1062 7.6. Persistent Congestion 1064 When a sender establishes loss of all in-flight packets sent over a 1065 long enough duration, the network is considered to be experiencing 1066 persistent congestion. 1068 7.6.1. Duration 1070 The persistent congestion duration is computed as follows: 1072 (smoothed_rtt + max(4*rttvar, kGranularity) + max_ack_delay) * 1073 kPersistentCongestionThreshold 1075 Unlike the PTO computation in Section 6.2, this duration includes the 1076 max_ack_delay irrespective of the packet number spaces in which 1077 losses are established. 1079 This duration allows a sender to send as many packets before 1080 establishing persistent congestion, including some in response to PTO 1081 expiration, as TCP does with Tail Loss Probes ([RACK]) and a 1082 Retransmission Timeout ([RFC5681]). 1084 The RECOMMENDED value for kPersistentCongestionThreshold is 3, which 1085 is approximately equivalent to two TLPs before an RTO in TCP. 1087 This design does not use consecutive PTO events to establish 1088 persistent congestion, since application patterns impact PTO 1089 expirations. For example, a sender that sends small amounts of data 1090 with silence periods between them restarts the PTO timer every time 1091 it sends, potentially preventing the PTO timer from expiring for a 1092 long period of time, even when no acknowledgments are being received. 1093 The use of a duration enables a sender to establish persistent 1094 congestion without depending on PTO expiration. 1096 7.6.2. Establishing Persistent Congestion 1098 A sender establishes persistent congestion on receiving an 1099 acknowledgement if at least two ack-eliciting packets are declared 1100 lost, and: 1102 * all packets, across all packet number spaces, sent between these 1103 two send times are declared lost; 1105 * the duration between the send times of these two packets exceeds 1106 the persistent congestion duration (Section 7.6.1); and 1108 * a prior RTT sample existed when both packets were sent. 1110 The persistent congestion period SHOULD NOT start until there is at 1111 least one RTT sample. Before the first RTT sample, a sender arms its 1112 PTO timer based on the initial RTT (Section 6.2.2), which could be 1113 substantially larger than the actual RTT. Requiring a prior RTT 1114 sample prevents a sender from establishing persistent congestion with 1115 potentially too few probes. 1117 Since network congestion is not affected by packet number spaces, 1118 persistent congestion SHOULD consider packets sent across packet 1119 number spaces. A sender that does not have state for all packet 1120 number spaces or an implementation that cannot compare send times 1121 across packet number spaces MAY use state for just the packet number 1122 space that was acknowledged. 1124 When persistent congestion is declared, the sender's congestion 1125 window MUST be reduced to the minimum congestion window 1126 (kMinimumWindow), similar to a TCP sender's response on an RTO 1127 ([RFC5681]). 1129 7.6.3. Example 1131 The following example illustrates how a sender might establish 1132 persistent congestion. Assume: 1134 smoothed_rtt + max(4*rttvar, kGranularity) + max_ack_delay = 2 1135 kPersistentCongestionThreshold = 3 1137 Consider the following sequence of events: 1139 +========+============================+ 1140 | Time | Action | 1141 +========+============================+ 1142 | t=0 | Send packet #1 (app data) | 1143 +--------+----------------------------+ 1144 | t=1 | Send packet #2 (app data) | 1145 +--------+----------------------------+ 1146 | t=1.2 | Recv acknowledgement of #1 | 1147 +--------+----------------------------+ 1148 | t=2 | Send packet #3 (app data) | 1149 +--------+----------------------------+ 1150 | t=3 | Send packet #4 (app data) | 1151 +--------+----------------------------+ 1152 | t=4 | Send packet #5 (app data) | 1153 +--------+----------------------------+ 1154 | t=5 | Send packet #6 (app data) | 1155 +--------+----------------------------+ 1156 | t=6 | Send packet #7 (app data) | 1157 +--------+----------------------------+ 1158 | t=8 | Send packet #8 (PTO 1) | 1159 +--------+----------------------------+ 1160 | t=12 | Send packet #9 (PTO 2) | 1161 +--------+----------------------------+ 1162 | t=12.2 | Recv acknowledgement of #9 | 1163 +--------+----------------------------+ 1165 Table 1 1167 Packets 2 through 8 are declared lost when the acknowledgement for 1168 packet 9 is received at t = 12.2. 1170 The congestion period is calculated as the time between the oldest 1171 and newest lost packets: 8 - 1 = 7. The persistent congestion 1172 duration is: 2 * 3 = 6. Because the threshold was reached and 1173 because none of the packets between the oldest and the newest lost 1174 packets were acknowledged, the network is considered to have 1175 experienced persistent congestion. 1177 While this example shows PTO expiration, they are not required for 1178 persistent congestion to be established. 1180 7.7. Pacing 1182 A sender SHOULD pace sending of all in-flight packets based on input 1183 from the congestion controller. 1185 Sending multiple packets into the network without any delay between 1186 them creates a packet burst that might cause short-term congestion 1187 and losses. Senders MUST either use pacing or limit such bursts. 1188 Senders SHOULD limit bursts to the initial congestion window; see 1189 Section 7.2. A sender with knowledge that the network path to the 1190 receiver can absorb larger bursts MAY use a higher limit. 1192 An implementation should take care to architect its congestion 1193 controller to work well with a pacer. For instance, a pacer might 1194 wrap the congestion controller and control the availability of the 1195 congestion window, or a pacer might pace out packets handed to it by 1196 the congestion controller. 1198 Timely delivery of ACK frames is important for efficient loss 1199 recovery. Packets containing only ACK frames SHOULD therefore not be 1200 paced, to avoid delaying their delivery to the peer. 1202 Endpoints can implement pacing as they choose. A perfectly paced 1203 sender spreads packets exactly evenly over time. For a window-based 1204 congestion controller, such as the one in this document, that rate 1205 can be computed by averaging the congestion window over the round- 1206 trip time. Expressed as a rate in bytes: 1208 rate = N * congestion_window / smoothed_rtt 1210 Or, expressed as an inter-packet interval: 1212 interval = smoothed_rtt * packet_size / congestion_window / N 1214 Using a value for "N" that is small, but at least 1 (for example, 1215 1.25) ensures that variations in round-trip time do not result in 1216 under-utilization of the congestion window. 1218 Practical considerations, such as packetization, scheduling delays, 1219 and computational efficiency, can cause a sender to deviate from this 1220 rate over time periods that are much shorter than a round-trip time. 1222 One possible implementation strategy for pacing uses a leaky bucket 1223 algorithm, where the capacity of the "bucket" is limited to the 1224 maximum burst size and the rate the "bucket" fills is determined by 1225 the above function. 1227 7.8. Under-utilizing the Congestion Window 1229 When bytes in flight is smaller than the congestion window and 1230 sending is not pacing limited, the congestion window is under- 1231 utilized. When this occurs, the congestion window SHOULD NOT be 1232 increased in either slow start or congestion avoidance. This can 1233 happen due to insufficient application data or flow control limits. 1235 A sender MAY use the pipeACK method described in Section 4.3 of 1236 [RFC7661] to determine if the congestion window is sufficiently 1237 utilized. 1239 A sender that paces packets (see Section 7.7) might delay sending 1240 packets and not fully utilize the congestion window due to this 1241 delay. A sender SHOULD NOT consider itself application limited if it 1242 would have fully utilized the congestion window without pacing delay. 1244 A sender MAY implement alternative mechanisms to update its 1245 congestion window after periods of under-utilization, such as those 1246 proposed for TCP in [RFC7661]. 1248 8. Security Considerations 1250 8.1. Congestion Signals 1252 Congestion control fundamentally involves the consumption of signals 1253 - both loss and ECN codepoints - from unauthenticated entities. On- 1254 path attackers can spoof or alter these signals. An attacker can 1255 cause endpoints to reduce their sending rate by dropping packets, or 1256 alter send rate by changing ECN codepoints. 1258 8.2. Traffic Analysis 1260 Packets that carry only ACK frames can be heuristically identified by 1261 observing packet size. Acknowledgement patterns may expose 1262 information about link characteristics or application behavior. To 1263 reduce leaked information, endpoints can bundle acknowledgments with 1264 other frames, or they can use PADDING frames at a potential cost to 1265 performance. 1267 8.3. Misreporting ECN Markings 1269 A receiver can misreport ECN markings to alter the congestion 1270 response of a sender. Suppressing reports of ECN-CE markings could 1271 cause a sender to increase their send rate. This increase could 1272 result in congestion and loss. 1274 A sender MAY attempt to detect suppression of reports by marking 1275 occasional packets that they send with ECN-CE. If a packet sent with 1276 ECN-CE is not reported as having been CE marked when the packet is 1277 acknowledged, then the sender SHOULD disable ECN for that path. 1279 Reporting additional ECN-CE markings will cause a sender to reduce 1280 their sending rate, which is similar in effect to advertising reduced 1281 connection flow control limits and so no advantage is gained by doing 1282 so. 1284 Endpoints choose the congestion controller that they use. Congestion 1285 controllers respond to reports of ECN-CE by reducing their rate, but 1286 the response may vary. Markings can be treated as equivalent to loss 1287 ([RFC3168]), but other responses can be specified, such as 1288 ([RFC8511]) or ([RFC8311]). 1290 9. IANA Considerations 1292 This document has no IANA actions. 1294 10. References 1296 10.1. Normative References 1298 [QUIC-TLS] Thomson, M., Ed. and S. Turner, Ed., "Using TLS to Secure 1299 QUIC", Work in Progress, Internet-Draft, draft-ietf-quic- 1300 tls-31, 25 September 2020, 1301 . 1303 [QUIC-TRANSPORT] 1304 Iyengar, J., Ed. and M. Thomson, Ed., "QUIC: A UDP-Based 1305 Multiplexed and Secure Transport", Work in Progress, 1306 Internet-Draft, draft-ietf-quic-transport-31, 25 September 1307 2020, . 1310 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 1311 Requirement Levels", BCP 14, RFC 2119, 1312 DOI 10.17487/RFC2119, March 1997, 1313 . 1315 [RFC8085] Eggert, L., Fairhurst, G., and G. Shepherd, "UDP Usage 1316 Guidelines", BCP 145, RFC 8085, DOI 10.17487/RFC8085, 1317 March 2017, . 1319 [RFC8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 1320 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, 1321 May 2017, . 1323 10.2. Informative References 1325 [FACK] Mathis, M. and J. Mahdavi, "Forward Acknowledgement: 1326 Refining TCP Congestion Control", ACM SIGCOMM , August 1327 1996. 1329 [PRR] Mathis, M., Dukkipati, N., and Y. Cheng, "Proportional 1330 Rate Reduction for TCP", RFC 6937, DOI 10.17487/RFC6937, 1331 May 2013, . 1333 [RACK] Cheng, Y., Cardwell, N., Dukkipati, N., and P. Jha, "The 1334 RACK-TLP loss detection algorithm for TCP", Work in 1335 Progress, Internet-Draft, draft-ietf-tcpm-rack-10, 22 1336 August 2020, . 1339 [RFC3168] Ramakrishnan, K., Floyd, S., and D. Black, "The Addition 1340 of Explicit Congestion Notification (ECN) to IP", 1341 RFC 3168, DOI 10.17487/RFC3168, September 2001, 1342 . 1344 [RFC3465] Allman, M., "TCP Congestion Control with Appropriate Byte 1345 Counting (ABC)", RFC 3465, DOI 10.17487/RFC3465, February 1346 2003, . 1348 [RFC5681] Allman, M., Paxson, V., and E. Blanton, "TCP Congestion 1349 Control", RFC 5681, DOI 10.17487/RFC5681, September 2009, 1350 . 1352 [RFC5682] Sarolahti, P., Kojo, M., Yamamoto, K., and M. Hata, 1353 "Forward RTO-Recovery (F-RTO): An Algorithm for Detecting 1354 Spurious Retransmission Timeouts with TCP", RFC 5682, 1355 DOI 10.17487/RFC5682, September 2009, 1356 . 1358 [RFC5827] Allman, M., Avrachenkov, K., Ayesta, U., Blanton, J., and 1359 P. Hurtig, "Early Retransmit for TCP and Stream Control 1360 Transmission Protocol (SCTP)", RFC 5827, 1361 DOI 10.17487/RFC5827, May 2010, 1362 . 1364 [RFC6298] Paxson, V., Allman, M., Chu, J., and M. Sargent, 1365 "Computing TCP's Retransmission Timer", RFC 6298, 1366 DOI 10.17487/RFC6298, June 2011, 1367 . 1369 [RFC6582] Henderson, T., Floyd, S., Gurtov, A., and Y. Nishida, "The 1370 NewReno Modification to TCP's Fast Recovery Algorithm", 1371 RFC 6582, DOI 10.17487/RFC6582, April 2012, 1372 . 1374 [RFC6675] Blanton, E., Allman, M., Wang, L., Jarvinen, I., Kojo, M., 1375 and Y. Nishida, "A Conservative Loss Recovery Algorithm 1376 Based on Selective Acknowledgment (SACK) for TCP", 1377 RFC 6675, DOI 10.17487/RFC6675, August 2012, 1378 . 1380 [RFC6928] Chu, J., Dukkipati, N., Cheng, Y., and M. Mathis, 1381 "Increasing TCP's Initial Window", RFC 6928, 1382 DOI 10.17487/RFC6928, April 2013, 1383 . 1385 [RFC7661] Fairhurst, G., Sathiaseelan, A., and R. Secchi, "Updating 1386 TCP to Support Rate-Limited Traffic", RFC 7661, 1387 DOI 10.17487/RFC7661, October 2015, 1388 . 1390 [RFC8311] Black, D., "Relaxing Restrictions on Explicit Congestion 1391 Notification (ECN) Experimentation", RFC 8311, 1392 DOI 10.17487/RFC8311, January 2018, 1393 . 1395 [RFC8312] Rhee, I., Xu, L., Ha, S., Zimmermann, A., Eggert, L., and 1396 R. Scheffenegger, "CUBIC for Fast Long-Distance Networks", 1397 RFC 8312, DOI 10.17487/RFC8312, February 2018, 1398 . 1400 [RFC8511] Khademi, N., Welzl, M., Armitage, G., and G. Fairhurst, 1401 "TCP Alternative Backoff with ECN (ABE)", RFC 8511, 1402 DOI 10.17487/RFC8511, December 2018, 1403 . 1405 Appendix A. Loss Recovery Pseudocode 1407 We now describe an example implementation of the loss detection 1408 mechanisms described in Section 6. 1410 A.1. Tracking Sent Packets 1412 To correctly implement congestion control, a QUIC sender tracks every 1413 ack-eliciting packet until the packet is acknowledged or lost. It is 1414 expected that implementations will be able to access this information 1415 by packet number and crypto context and store the per-packet fields 1416 (Appendix A.1.1) for loss recovery and congestion control. 1418 After a packet is declared lost, the endpoint can still maintain 1419 state for it for an amount of time to allow for packet reordering; 1420 see Section 13.3 of [QUIC-TRANSPORT]. This enables a sender to 1421 detect spurious retransmissions. 1423 Sent packets are tracked for each packet number space, and ACK 1424 processing only applies to a single space. 1426 A.1.1. Sent Packet Fields 1428 packet_number: The packet number of the sent packet. 1430 ack_eliciting: A boolean that indicates whether a packet is ack- 1431 eliciting. If true, it is expected that an acknowledgement will 1432 be received, though the peer could delay sending the ACK frame 1433 containing it by up to the max_ack_delay. 1435 in_flight: A boolean that indicates whether the packet counts 1436 towards bytes in flight. 1438 sent_bytes: The number of bytes sent in the packet, not including 1439 UDP or IP overhead, but including QUIC framing overhead. 1441 time_sent: The time the packet was sent. 1443 A.2. Constants of Interest 1445 Constants used in loss recovery are based on a combination of RFCs, 1446 papers, and common practice. 1448 kPacketThreshold: Maximum reordering in packets before packet 1449 threshold loss detection considers a packet lost. The value 1450 recommended in Section 6.1.1 is 3. 1452 kTimeThreshold: Maximum reordering in time before time threshold 1453 loss detection considers a packet lost. Specified as an RTT 1454 multiplier. The value recommended in Section 6.1.2 is 9/8. 1456 kGranularity: Timer granularity. This is a system-dependent value, 1457 and Section 6.1.2 recommends a value of 1ms. 1459 kInitialRtt: The RTT used before an RTT sample is taken. The value 1460 recommended in Section 6.2.2 is 333ms. 1462 kPacketNumberSpace: An enum to enumerate the three packet number 1463 spaces. 1465 enum kPacketNumberSpace { 1466 Initial, 1467 Handshake, 1468 ApplicationData, 1469 } 1471 A.3. Variables of interest 1473 Variables required to implement the congestion control mechanisms are 1474 described in this section. 1476 latest_rtt: The most recent RTT measurement made when receiving an 1477 ack for a previously unacked packet. 1479 smoothed_rtt: The smoothed RTT of the connection, computed as 1480 described in Section 5.3. 1482 rttvar: The RTT variation, computed as described in Section 5.3. 1484 min_rtt: The minimum RTT seen in the connection, ignoring 1485 acknowledgment delay, as described in Section 5.2. 1487 max_ack_delay: The maximum amount of time by which the receiver 1488 intends to delay acknowledgments for packets in the Application 1489 Data packet number space, as defined by the eponymous transport 1490 parameter (Section 18.2 of [QUIC-TRANSPORT]). Note that the 1491 actual ack_delay in a received ACK frame may be larger due to late 1492 timers, reordering, or loss. 1494 loss_detection_timer: Multi-modal timer used for loss detection. 1496 pto_count: The number of times a PTO has been sent without receiving 1497 an ack. 1499 time_of_last_ack_eliciting_packet[kPacketNumberSpace]: The time the 1500 most recent ack-eliciting packet was sent. 1502 largest_acked_packet[kPacketNumberSpace]: The largest packet number 1503 acknowledged in the packet number space so far. 1505 loss_time[kPacketNumberSpace]: The time at which the next packet in 1506 that packet number space will be considered lost based on 1507 exceeding the reordering window in time. 1509 sent_packets[kPacketNumberSpace]: An association of packet numbers 1510 in a packet number space to information about them. Described in 1511 detail above in Appendix A.1. 1513 A.4. Initialization 1515 At the beginning of the connection, initialize the loss detection 1516 variables as follows: 1518 loss_detection_timer.reset() 1519 pto_count = 0 1520 latest_rtt = 0 1521 smoothed_rtt = kInitialRtt 1522 rttvar = kInitialRtt / 2 1523 min_rtt = 0 1524 for pn_space in [ Initial, Handshake, ApplicationData ]: 1525 largest_acked_packet[pn_space] = infinite 1526 time_of_last_ack_eliciting_packet[pn_space] = 0 1527 loss_time[pn_space] = 0 1529 A.5. On Sending a Packet 1531 After a packet is sent, information about the packet is stored. The 1532 parameters to OnPacketSent are described in detail above in 1533 Appendix A.1.1. 1535 Pseudocode for OnPacketSent follows: 1537 OnPacketSent(packet_number, pn_space, ack_eliciting, 1538 in_flight, sent_bytes): 1539 sent_packets[pn_space][packet_number].packet_number = 1540 packet_number 1541 sent_packets[pn_space][packet_number].time_sent = now() 1542 sent_packets[pn_space][packet_number].ack_eliciting = 1543 ack_eliciting 1544 sent_packets[pn_space][packet_number].in_flight = in_flight 1545 if (in_flight): 1546 if (ack_eliciting): 1547 time_of_last_ack_eliciting_packet[pn_space] = now() 1548 OnPacketSentCC(sent_bytes) 1549 sent_packets[pn_space][packet_number].sent_bytes = 1550 sent_bytes 1551 SetLossDetectionTimer() 1553 A.6. On Receiving a Datagram 1555 When a server is blocked by anti-amplification limits, receiving a 1556 datagram unblocks it, even if none of the packets in the datagram are 1557 successfully processed. In such a case, the PTO timer will need to 1558 be re-armed. 1560 Pseudocode for OnDatagramReceived follows: 1562 OnDatagramReceived(datagram): 1563 // If this datagram unblocks the server, arm the 1564 // PTO timer to avoid deadlock. 1565 if (server was at anti-amplification limit): 1566 SetLossDetectionTimer() 1568 A.7. On Receiving an Acknowledgment 1570 When an ACK frame is received, it may newly acknowledge any number of 1571 packets. 1573 Pseudocode for OnAckReceived and UpdateRtt follow: 1575 IncludesAckEliciting(packets): 1576 for packet in packets: 1577 if (packet.ack_eliciting): 1578 return true 1579 return false 1581 OnAckReceived(ack, pn_space): 1582 if (largest_acked_packet[pn_space] == infinite): 1583 largest_acked_packet[pn_space] = ack.largest_acked 1584 else: 1585 largest_acked_packet[pn_space] = 1586 max(largest_acked_packet[pn_space], ack.largest_acked) 1588 // DetectAndRemoveAckedPackets finds packets that are newly 1589 // acknowledged and removes them from sent_packets. 1590 newly_acked_packets = 1591 DetectAndRemoveAckedPackets(ack, pn_space) 1592 // Nothing to do if there are no newly acked packets. 1593 if (newly_acked_packets.empty()): 1594 return 1596 // Update the RTT if the largest acknowledged is newly acked 1597 // and at least one ack-eliciting was newly acked. 1598 if (newly_acked_packets.largest().packet_number == 1599 ack.largest_acked && 1600 IncludesAckEliciting(newly_acked_packets)): 1601 latest_rtt = 1602 now() - newly_acked_packets.largest().time_sent 1603 UpdateRtt(ack.ack_delay) 1605 // Process ECN information if present. 1606 if (ACK frame contains ECN information): 1607 ProcessECN(ack, pn_space) 1609 lost_packets = DetectAndRemoveLostPackets(pn_space) 1610 if (!lost_packets.empty()): 1611 OnPacketsLost(lost_packets) 1612 OnPacketsAcked(newly_acked_packets) 1614 // Reset pto_count unless the client is unsure if 1615 // the server has validated the client's address. 1616 if (PeerCompletedAddressValidation()): 1617 pto_count = 0 1618 SetLossDetectionTimer() 1620 UpdateRtt(ack_delay): 1621 if (is first RTT sample): 1622 min_rtt = latest_rtt 1623 smoothed_rtt = latest_rtt 1624 rttvar = latest_rtt / 2 1625 return 1627 // min_rtt ignores acknowledgment delay. 1628 min_rtt = min(min_rtt, latest_rtt) 1629 // Limit ack_delay by max_ack_delay after handshake 1630 // confirmation. Note that ack_delay is 0 for 1631 // acknowledgements of Initial and Handshake packets. 1632 if (handshake confirmed): 1633 ack_delay = min(ack_delay, max_ack_delay) 1635 // Adjust for acknowledgment delay if plausible. 1636 adjusted_rtt = latest_rtt 1637 if (latest_rtt > min_rtt + ack_delay): 1638 adjusted_rtt = latest_rtt - ack_delay 1640 rttvar = 3/4 * rttvar + 1/4 * abs(smoothed_rtt - adjusted_rtt) 1641 smoothed_rtt = 7/8 * smoothed_rtt + 1/8 * adjusted_rtt 1643 A.8. Setting the Loss Detection Timer 1645 QUIC loss detection uses a single timer for all timeout loss 1646 detection. The duration of the timer is based on the timer's mode, 1647 which is set in the packet and timer events further below. The 1648 function SetLossDetectionTimer defined below shows how the single 1649 timer is set. 1651 This algorithm may result in the timer being set in the past, 1652 particularly if timers wake up late. Timers set in the past fire 1653 immediately. 1655 Pseudocode for SetLossDetectionTimer follows: 1657 GetLossTimeAndSpace(): 1658 time = loss_time[Initial] 1659 space = Initial 1660 for pn_space in [ Handshake, ApplicationData ]: 1661 if (time == 0 || loss_time[pn_space] < time): 1662 time = loss_time[pn_space]; 1663 space = pn_space 1664 return time, space 1666 GetPtoTimeAndSpace(): 1667 duration = (smoothed_rtt + max(4 * rttvar, kGranularity)) 1668 * (2 ^ pto_count) 1669 // Arm PTO from now when there are no inflight packets. 1670 if (no in-flight packets): 1671 assert(!PeerCompletedAddressValidation()) 1672 if (has handshake keys): 1673 return (now() + duration), Handshake 1674 else: 1675 return (now() + duration), Initial 1676 pto_timeout = infinite 1677 pto_space = Initial 1678 for space in [ Initial, Handshake, ApplicationData ]: 1679 if (no in-flight packets in space): 1680 continue; 1681 if (space == ApplicationData): 1682 // Skip Application Data until handshake confirmed. 1683 if (handshake is not confirmed): 1684 return pto_timeout, pto_space 1685 // Include max_ack_delay and backoff for Application Data. 1686 duration += max_ack_delay * (2 ^ pto_count) 1688 t = time_of_last_ack_eliciting_packet[space] + duration 1689 if (t < pto_timeout): 1690 pto_timeout = t 1691 pto_space = space 1692 return pto_timeout, pto_space 1694 PeerCompletedAddressValidation(): 1695 // Assume clients validate the server's address implicitly. 1696 if (endpoint is server): 1697 return true 1698 // Servers complete address validation when a 1699 // protected packet is received. 1700 return has received Handshake ACK || 1701 handshake confirmed 1703 SetLossDetectionTimer(): 1704 earliest_loss_time, _ = GetLossTimeAndSpace() 1705 if (earliest_loss_time != 0): 1706 // Time threshold loss detection. 1707 loss_detection_timer.update(earliest_loss_time) 1708 return 1710 if (server is at anti-amplification limit): 1711 // The server's timer is not set if nothing can be sent. 1712 loss_detection_timer.cancel() 1713 return 1715 if (no ack-eliciting packets in flight && 1716 PeerCompletedAddressValidation()): 1717 // There is nothing to detect lost, so no timer is set. 1718 // However, the client needs to arm the timer if the 1719 // server might be blocked by the anti-amplification limit. 1720 loss_detection_timer.cancel() 1721 return 1723 // Determine which PN space to arm PTO for. 1724 timeout, _ = GetPtoTimeAndSpace() 1725 loss_detection_timer.update(timeout) 1727 A.9. On Timeout 1729 When the loss detection timer expires, the timer's mode determines 1730 the action to be performed. 1732 Pseudocode for OnLossDetectionTimeout follows: 1734 OnLossDetectionTimeout(): 1735 earliest_loss_time, pn_space = GetLossTimeAndSpace() 1736 if (earliest_loss_time != 0): 1737 // Time threshold loss Detection 1738 lost_packets = DetectAndRemoveLostPackets(pn_space) 1739 assert(!lost_packets.empty()) 1740 OnPacketsLost(lost_packets) 1741 SetLossDetectionTimer() 1742 return 1744 if (bytes_in_flight > 0): 1745 // PTO. Send new data if available, else retransmit old data. 1746 // If neither is available, send a single PING frame. 1747 _, pn_space = GetPtoTimeAndSpace() 1748 SendOneOrTwoAckElicitingPackets(pn_space) 1749 else: 1750 assert(!PeerCompletedAddressValidation()) 1751 // Client sends an anti-deadlock packet: Initial is padded 1752 // to earn more anti-amplification credit, 1753 // a Handshake packet proves address ownership. 1754 if (has Handshake keys): 1755 SendOneAckElicitingHandshakePacket() 1756 else: 1757 SendOneAckElicitingPaddedInitialPacket() 1759 pto_count++ 1760 SetLossDetectionTimer() 1762 A.10. Detecting Lost Packets 1764 DetectAndRemoveLostPackets is called every time an ACK is received or 1765 the time threshold loss detection timer expires. This function 1766 operates on the sent_packets for that packet number space and returns 1767 a list of packets newly detected as lost. 1769 Pseudocode for DetectAndRemoveLostPackets follows: 1771 DetectAndRemoveLostPackets(pn_space): 1772 assert(largest_acked_packet[pn_space] != infinite) 1773 loss_time[pn_space] = 0 1774 lost_packets = {} 1775 loss_delay = kTimeThreshold * max(latest_rtt, smoothed_rtt) 1777 // Minimum time of kGranularity before packets are deemed lost. 1778 loss_delay = max(loss_delay, kGranularity) 1780 // Packets sent before this time are deemed lost. 1781 lost_send_time = now() - loss_delay 1783 foreach unacked in sent_packets[pn_space]: 1784 if (unacked.packet_number > largest_acked_packet[pn_space]): 1785 continue 1787 // Mark packet as lost, or set time when it should be marked. 1788 if (unacked.time_sent <= lost_send_time || 1789 largest_acked_packet[pn_space] >= 1790 unacked.packet_number + kPacketThreshold): 1791 sent_packets[pn_space].remove(unacked.packet_number) 1792 if (unacked.in_flight): 1793 lost_packets.insert(unacked) 1794 else: 1795 if (loss_time[pn_space] == 0): 1796 loss_time[pn_space] = unacked.time_sent + loss_delay 1797 else: 1798 loss_time[pn_space] = min(loss_time[pn_space], 1799 unacked.time_sent + loss_delay) 1800 return lost_packets 1802 Appendix B. Congestion Control Pseudocode 1804 We now describe an example implementation of the congestion 1805 controller described in Section 7. 1807 B.1. Constants of interest 1809 Constants used in congestion control are based on a combination of 1810 RFCs, papers, and common practice. 1812 kInitialWindow: Default limit on the initial bytes in flight as 1813 described in Section 7.2. 1815 kMinimumWindow: Minimum congestion window in bytes as described in 1816 Section 7.2. 1818 kLossReductionFactor: Reduction in congestion window when a new loss 1819 event is detected. Section 7 recommends a value is 0.5. 1821 kPersistentCongestionThreshold: Period of time for persistent 1822 congestion to be established, specified as a PTO multiplier. 1823 Section 7.6 recommends a value of 3. 1825 B.2. Variables of interest 1827 Variables required to implement the congestion control mechanisms are 1828 described in this section. 1830 max_datagram_size: The sender's current maximum payload size. Does 1831 not include UDP or IP overhead. The max datagram size is used for 1832 congestion window computations. An endpoint sets the value of 1833 this variable based on its PMTU (see Section 14.1 of 1834 [QUIC-TRANSPORT]), with a minimum value of 1200 bytes. 1836 ecn_ce_counters[kPacketNumberSpace]: The highest value reported for 1837 the ECN-CE counter in the packet number space by the peer in an 1838 ACK frame. This value is used to detect increases in the reported 1839 ECN-CE counter. 1841 bytes_in_flight: The sum of the size in bytes of all sent packets 1842 that contain at least one ack-eliciting or PADDING frame, and have 1843 not been acknowledged or declared lost. The size does not include 1844 IP or UDP overhead, but does include the QUIC header and AEAD 1845 overhead. Packets only containing ACK frames do not count towards 1846 bytes_in_flight to ensure congestion control does not impede 1847 congestion feedback. 1849 congestion_window: Maximum number of bytes-in-flight that may be 1850 sent. 1852 congestion_recovery_start_time: The time when QUIC first detects 1853 congestion due to loss or ECN, causing it to enter congestion 1854 recovery. When a packet sent after this time is acknowledged, 1855 QUIC exits congestion recovery. 1857 ssthresh: Slow start threshold in bytes. When the congestion window 1858 is below ssthresh, the mode is slow start and the window grows by 1859 the number of bytes acknowledged. 1861 first_rtt_sample: The time that the first RTT sample was obtained. 1863 B.3. Initialization 1865 At the beginning of the connection, initialize the congestion control 1866 variables as follows: 1868 congestion_window = kInitialWindow 1869 bytes_in_flight = 0 1870 congestion_recovery_start_time = 0 1871 ssthresh = infinite 1872 first_rtt_sample = 0 1873 for pn_space in [ Initial, Handshake, ApplicationData ]: 1874 ecn_ce_counters[pn_space] = 0 1876 B.4. On Packet Sent 1878 Whenever a packet is sent, and it contains non-ACK frames, the packet 1879 increases bytes_in_flight. 1881 OnPacketSentCC(bytes_sent): 1882 bytes_in_flight += bytes_sent 1884 B.5. On Packet Acknowledgement 1886 Invoked from loss detection's OnAckReceived and is supplied with the 1887 newly acked_packets from sent_packets. 1889 In congestion avoidance, implementers that use an integer 1890 representation for congestion_window should be careful with division, 1891 and can use the alternative approach suggested in Section 2.1 of 1892 [RFC3465]. 1894 InCongestionRecovery(sent_time): 1895 return sent_time <= congestion_recovery_start_time 1897 OnPacketsAcked(acked_packets): 1898 if (first_rtt_sample == 0): 1899 first_rtt_sample = now() 1901 for acked_packet in acked_packets: 1902 OnPacketAcked(acked_packet) 1904 OnPacketAcked(acked_packet): 1905 // Remove from bytes_in_flight. 1906 bytes_in_flight -= acked_packet.sent_bytes 1907 // Do not increase congestion_window if application 1908 // limited or flow control limited. 1909 if (IsAppOrFlowControlLimited()) 1910 return 1911 // Do not increase congestion window in recovery period. 1912 if (InCongestionRecovery(acked_packet.time_sent)): 1913 return 1914 if (congestion_window < ssthresh): 1915 // Slow start. 1916 congestion_window += acked_packet.sent_bytes 1917 else: 1918 // Congestion avoidance. 1919 congestion_window += 1920 max_datagram_size * acked_packet.sent_bytes 1921 / congestion_window 1923 B.6. On New Congestion Event 1925 Invoked from ProcessECN and OnPacketsLost when a new congestion event 1926 is detected. If not already in recovery, this starts a recovery 1927 period and reduces the slow start threshold and congestion window 1928 immediately. 1930 OnCongestionEvent(sent_time): 1931 // No reaction if already in a recovery period. 1932 if (InCongestionRecovery(sent_time)): 1933 return 1935 // Enter recovery period. 1936 congestion_recovery_start_time = now() 1937 ssthresh = congestion_window * kLossReductionFactor 1938 congestion_window = max(ssthresh, kMinimumWindow) 1939 // A packet can be sent to speed up loss recovery. 1940 MaybeSendOnePacket() 1942 B.7. Process ECN Information 1944 Invoked when an ACK frame with an ECN section is received from the 1945 peer. 1947 ProcessECN(ack, pn_space): 1948 // If the ECN-CE counter reported by the peer has increased, 1949 // this could be a new congestion event. 1950 if (ack.ce_counter > ecn_ce_counters[pn_space]): 1951 ecn_ce_counters[pn_space] = ack.ce_counter 1952 sent_time = sent_packets[ack.largest_acked].time_sent 1953 OnCongestionEvent(sent_time) 1955 B.8. On Packets Lost 1957 Invoked when DetectAndRemoveLostPackets deems packets lost. 1959 OnPacketsLost(lost_packets): 1960 // Remove lost packets from bytes_in_flight. 1961 for lost_packet in lost_packets: 1962 bytes_in_flight -= lost_packet.sent_bytes 1963 OnCongestionEvent(lost_packets.largest().time_sent) 1965 // Reset the congestion window if the loss of these 1966 // packets indicates persistent congestion. 1967 // Only consider packets sent after getting an RTT sample. 1968 assert(first_rtt_sample != 0) 1969 pc_lost = {} 1970 for lost in lost_packets: 1971 if lost.time_sent > first_rtt_sample: 1972 pc_lost.insert(lost) 1973 if (InPersistentCongestion(pc_lost)): 1974 congestion_window = kMinimumWindow 1975 congestion_recovery_start_time = 0 1977 B.9. Upon dropping Initial or Handshake keys 1979 When Initial or Handshake keys are discarded, packets from the space 1980 are discarded and loss detection state is updated. 1982 Pseudocode for OnPacketNumberSpaceDiscarded follows: 1984 OnPacketNumberSpaceDiscarded(pn_space): 1985 assert(pn_space != ApplicationData) 1986 // Remove any unacknowledged packets from flight. 1987 foreach packet in sent_packets[pn_space]: 1988 if packet.in_flight 1989 bytes_in_flight -= size 1990 sent_packets[pn_space].clear() 1991 // Reset the loss detection and PTO timer 1992 time_of_last_ack_eliciting_packet[pn_space] = 0 1993 loss_time[pn_space] = 0 1994 pto_count = 0 1995 SetLossDetectionTimer() 1997 Appendix C. Change Log 1999 *RFC Editor's Note:* Please remove this section prior to 2000 publication of a final version of this document. 2002 Issue and pull request numbers are listed with a leading octothorp. 2004 C.1. Since draft-ietf-quic-recovery-30 2006 Editorial changes only. 2008 C.2. Since draft-ietf-quic-recovery-29 2010 * Allow caching of packets that can't be decrypted, by allowing the 2011 reported acknowledgment delay to exceed max_ack_delay prior to 2012 confirming the handshake (#3821, #3980, #4035, #3874) 2014 * Persistent congestion cannot include packets sent before the first 2015 RTT sample for the path (#3875, #3889) 2017 * Recommend reset of min_rtt in persistent congestion (#3927, #3975) 2019 * Persistent congestion is independent of packet number space 2020 (#3939, #3961) 2022 * Only limit bursts to the initial window without information about 2023 the path (#3892, #3936) 2025 * Add normative requirements for increasing and reducing the 2026 congestion window (#3944, #3978, #3997, #3998) 2028 C.3. Since draft-ietf-quic-recovery-28 2030 * Refactored pseudocode to correct PTO calculation (#3564, #3674, 2031 #3681) 2033 C.4. Since draft-ietf-quic-recovery-27 2035 * Added recommendations for speeding up handshake under some loss 2036 conditions (#3078, #3080) 2038 * PTO count is reset when handshake progress is made (#3272, #3415) 2040 * PTO count is not reset by a client when the server might be 2041 awaiting address validation (#3546, #3551) 2043 * Recommend repairing losses immediately after entering the recovery 2044 period (#3335, #3443) 2046 * Clarified what loss conditions can be ignored during the handshake 2047 (#3456, #3450) 2049 * Allow, but don't recommend, using RTT from previous connection to 2050 seed RTT (#3464, #3496) 2052 * Recommend use of adaptive loss detection thresholds (#3571, #3572) 2054 C.5. Since draft-ietf-quic-recovery-26 2056 No changes. 2058 C.6. Since draft-ietf-quic-recovery-25 2060 No significant changes. 2062 C.7. Since draft-ietf-quic-recovery-24 2064 * Require congestion control of some sort (#3247, #3244, #3248) 2066 * Set a minimum reordering threshold (#3256, #3240) 2068 * PTO is specific to a packet number space (#3067, #3074, #3066) 2070 C.8. Since draft-ietf-quic-recovery-23 2072 * Define under-utilizing the congestion window (#2630, #2686, #2675) 2074 * PTO MUST send data if possible (#3056, #3057) 2076 * Connection Close is not ack-eliciting (#3097, #3098) 2078 * MUST limit bursts to the initial congestion window (#3160) 2079 * Define the current max_datagram_size for congestion control 2080 (#3041, #3167) 2082 C.9. Since draft-ietf-quic-recovery-22 2084 * PTO should always send an ack-eliciting packet (#2895) 2086 * Unify the Handshake Timer with the PTO timer (#2648, #2658, #2886) 2088 * Move ACK generation text to transport draft (#1860, #2916) 2090 C.10. Since draft-ietf-quic-recovery-21 2092 * No changes 2094 C.11. Since draft-ietf-quic-recovery-20 2096 * Path validation can be used as initial RTT value (#2644, #2687) 2098 * max_ack_delay transport parameter defaults to 0 (#2638, #2646) 2100 * ACK delay only measures intentional delays induced by the 2101 implementation (#2596, #2786) 2103 C.12. Since draft-ietf-quic-recovery-19 2105 * Change kPersistentThreshold from an exponent to a multiplier 2106 (#2557) 2108 * Send a PING if the PTO timer fires and there's nothing to send 2109 (#2624) 2111 * Set loss delay to at least kGranularity (#2617) 2113 * Merge application limited and sending after idle sections. Always 2114 limit burst size instead of requiring resetting CWND to initial 2115 CWND after idle (#2605) 2117 * Rewrite RTT estimation, allow RTT samples where a newly acked 2118 packet is ack-eliciting but the largest_acked is not (#2592) 2120 * Don't arm the handshake timer if there is no handshake data 2121 (#2590) 2123 * Clarify that the time threshold loss alarm takes precedence over 2124 the crypto handshake timer (#2590, #2620) 2126 * Change initial RTT to 500ms to align with RFC6298 (#2184) 2128 C.13. Since draft-ietf-quic-recovery-18 2130 * Change IW byte limit to 14720 from 14600 (#2494) 2132 * Update PTO calculation to match RFC6298 (#2480, #2489, #2490) 2134 * Improve loss detection's description of multiple packet number 2135 spaces and pseudocode (#2485, #2451, #2417) 2137 * Declare persistent congestion even if non-probe packets are sent 2138 and don't make persistent congestion more aggressive than RTO 2139 verified was (#2365, #2244) 2141 * Move pseudocode to the appendices (#2408) 2143 * What to send on multiple PTOs (#2380) 2145 C.14. Since draft-ietf-quic-recovery-17 2147 * After Probe Timeout discard in-flight packets or send another 2148 (#2212, #1965) 2150 * Endpoints discard initial keys as soon as handshake keys are 2151 available (#1951, #2045) 2153 * 0-RTT state is discarded when 0-RTT is rejected (#2300) 2155 * Loss detection timer is cancelled when ack-eliciting frames are in 2156 flight (#2117, #2093) 2158 * Packets are declared lost if they are in flight (#2104) 2160 * After becoming idle, either pace packets or reset the congestion 2161 controller (#2138, 2187) 2163 * Process ECN counts before marking packets lost (#2142) 2165 * Mark packets lost before resetting crypto_count and pto_count 2166 (#2208, #2209) 2168 * Congestion and loss recovery state are discarded when keys are 2169 discarded (#2327) 2171 C.15. Since draft-ietf-quic-recovery-16 2173 * Unify TLP and RTO into a single PTO; eliminate min RTO, min TLP 2174 and min crypto timeouts; eliminate timeout validation (#2114, 2175 #2166, #2168, #1017) 2177 * Redefine how congestion avoidance in terms of when the period 2178 starts (#1928, #1930) 2180 * Document what needs to be tracked for packets that are in flight 2181 (#765, #1724, #1939) 2183 * Integrate both time and packet thresholds into loss detection 2184 (#1969, #1212, #934, #1974) 2186 * Reduce congestion window after idle, unless pacing is used (#2007, 2187 #2023) 2189 * Disable RTT calculation for packets that don't elicit 2190 acknowledgment (#2060, #2078) 2192 * Limit ack_delay by max_ack_delay (#2060, #2099) 2194 * Initial keys are discarded once Handshake keys are available 2195 (#1951, #2045) 2197 * Reorder ECN and loss detection in pseudocode (#2142) 2199 * Only cancel loss detection timer if ack-eliciting packets are in 2200 flight (#2093, #2117) 2202 C.16. Since draft-ietf-quic-recovery-14 2204 * Used max_ack_delay from transport params (#1796, #1782) 2206 * Merge ACK and ACK_ECN (#1783) 2208 C.17. Since draft-ietf-quic-recovery-13 2210 * Corrected the lack of ssthresh reduction in CongestionEvent 2211 pseudocode (#1598) 2213 * Considerations for ECN spoofing (#1426, #1626) 2215 * Clarifications for PADDING and congestion control (#837, #838, 2216 #1517, #1531, #1540) 2218 * Reduce early retransmission timer to RTT/8 (#945, #1581) 2220 * Packets are declared lost after an RTO is verified (#935, #1582) 2222 C.18. Since draft-ietf-quic-recovery-12 2223 * Changes to manage separate packet number spaces and encryption 2224 levels (#1190, #1242, #1413, #1450) 2226 * Added ECN feedback mechanisms and handling; new ACK_ECN frame 2227 (#804, #805, #1372) 2229 C.19. Since draft-ietf-quic-recovery-11 2231 No significant changes. 2233 C.20. Since draft-ietf-quic-recovery-10 2235 * Improved text on ack generation (#1139, #1159) 2237 * Make references to TCP recovery mechanisms informational (#1195) 2239 * Define time_of_last_sent_handshake_packet (#1171) 2241 * Added signal from TLS the data it includes needs to be sent in a 2242 Retry packet (#1061, #1199) 2244 * Minimum RTT (min_rtt) is initialized with an infinite value 2245 (#1169) 2247 C.21. Since draft-ietf-quic-recovery-09 2249 No significant changes. 2251 C.22. Since draft-ietf-quic-recovery-08 2253 * Clarified pacing and RTO (#967, #977) 2255 C.23. Since draft-ietf-quic-recovery-07 2257 * Include ACK delay in RTO(and TLP) computations (#981) 2259 * ACK delay in SRTT computation (#961) 2261 * Default RTT and Slow Start (#590) 2263 * Many editorial fixes. 2265 C.24. Since draft-ietf-quic-recovery-06 2267 No significant changes. 2269 C.25. Since draft-ietf-quic-recovery-05 2270 * Add more congestion control text (#776) 2272 C.26. Since draft-ietf-quic-recovery-04 2274 No significant changes. 2276 C.27. Since draft-ietf-quic-recovery-03 2278 No significant changes. 2280 C.28. Since draft-ietf-quic-recovery-02 2282 * Integrate F-RTO (#544, #409) 2284 * Add congestion control (#545, #395) 2286 * Require connection abort if a skipped packet was acknowledged 2287 (#415) 2289 * Simplify RTO calculations (#142, #417) 2291 C.29. Since draft-ietf-quic-recovery-01 2293 * Overview added to loss detection 2295 * Changes initial default RTT to 100ms 2297 * Added time-based loss detection and fixes early retransmit 2299 * Clarified loss recovery for handshake packets 2301 * Fixed references and made TCP references informative 2303 C.30. Since draft-ietf-quic-recovery-00 2305 * Improved description of constants and ACK behavior 2307 C.31. Since draft-iyengar-quic-loss-recovery-01 2309 * Adopted as base for draft-ietf-quic-recovery 2311 * Updated authors/editors list 2313 * Added table of contents 2315 Appendix D. Contributors 2317 The IETF QUIC Working Group received an enormous amount of support 2318 from many people. The following people provided substantive 2319 contributions to this document: 2321 * Alessandro Ghedini 2323 * Benjamin Saunders 2325 * Gorry Fairhurst 2327 * 山本和彦 (Kazu Yamamoto) 2329 * 奥 一穂 (Kazuho Oku) 2331 * Lars Eggert 2333 * Magnus Westerlund 2335 * Marten Seemann 2337 * Martin Duke 2339 * Martin Thomson 2341 * Mirja Kühlewind 2343 * Nick Banks 2345 * Praveen Balasubramanian 2347 Acknowledgments 2349 Authors' Addresses 2351 Jana Iyengar (editor) 2352 Fastly 2354 Email: jri.ietf@gmail.com 2356 Ian Swett (editor) 2357 Google 2359 Email: ianswett@google.com