blob: c4a83b36c4f83f4d34b337c20d35f758e3cb3060 [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef QUICHE_QUIC_CORE_QUIC_CONSTANTS_H_
6#define QUICHE_QUIC_CORE_QUIC_CONSTANTS_H_
7
8#include <stddef.h>
9
10#include <cstdint>
11#include <limits>
12
QUICHE teama6ef0a62019-03-07 20:34:33 -050013#include "net/third_party/quiche/src/quic/core/quic_types.h"
14#include "net/third_party/quiche/src/quic/platform/api/quic_export.h"
15
16// Definitions of constant values used throughout the QUIC code.
17
18namespace quic {
19
20// Simple time constants.
21const uint64_t kNumSecondsPerMinute = 60;
22const uint64_t kNumSecondsPerHour = kNumSecondsPerMinute * 60;
23const uint64_t kNumSecondsPerWeek = kNumSecondsPerHour * 24 * 7;
dschinazi6cf4d2a2019-04-30 16:20:23 -070024const uint64_t kNumMillisPerSecond = 1000;
QUICHE teama6ef0a62019-03-07 20:34:33 -050025const uint64_t kNumMicrosPerMilli = 1000;
dschinazi6cf4d2a2019-04-30 16:20:23 -070026const uint64_t kNumMicrosPerSecond = kNumMicrosPerMilli * kNumMillisPerSecond;
QUICHE teama6ef0a62019-03-07 20:34:33 -050027
28// Default number of connections for N-connection emulation.
29const uint32_t kDefaultNumConnections = 2;
30// Default initial maximum size in bytes of a QUIC packet.
31const QuicByteCount kDefaultMaxPacketSize = 1350;
32// Default initial maximum size in bytes of a QUIC packet for servers.
33const QuicByteCount kDefaultServerMaxPacketSize = 1000;
34// Maximum transmission unit on Ethernet.
35const QuicByteCount kEthernetMTU = 1500;
dschinazi66dea072019-04-09 11:41:06 -070036// The maximum packet size of any QUIC packet over IPv6, based on ethernet's max
37// size, minus the IP and UDP headers. IPv6 has a 40 byte header, UDP adds an
QUICHE teama6ef0a62019-03-07 20:34:33 -050038// additional 8 bytes. This is a total overhead of 48 bytes. Ethernet's
39// max packet size is 1500 bytes, 1500 - 48 = 1452.
dschinazi66dea072019-04-09 11:41:06 -070040const QuicByteCount kMaxV6PacketSize = 1452;
QUICHE teama6ef0a62019-03-07 20:34:33 -050041// The maximum packet size of any QUIC packet over IPv4.
42// 1500(Ethernet) - 20(IPv4 header) - 8(UDP header) = 1472.
43const QuicByteCount kMaxV4PacketSize = 1472;
dschinazie8d7fa72019-04-05 14:44:40 -070044// The maximum incoming packet size allowed.
45const QuicByteCount kMaxIncomingPacketSize = kMaxV4PacketSize;
dschinazi66dea072019-04-09 11:41:06 -070046// The maximum outgoing packet size allowed.
47const QuicByteCount kMaxOutgoingPacketSize = kMaxV6PacketSize;
QUICHE teama6ef0a62019-03-07 20:34:33 -050048// ETH_MAX_MTU - MAX(sizeof(iphdr), sizeof(ip6_hdr)) - sizeof(udphdr).
49const QuicByteCount kMaxGsoPacketSize = 65535 - 40 - 8;
dschinazicd86dd12019-11-14 10:11:13 -080050// The maximal IETF DATAGRAM frame size we'll accept. Choosing 2^16 ensures
51// that it is greater than the biggest frame we could ever fit in a QUIC packet.
52const QuicByteCount kMaxAcceptedDatagramFrameSize = 65536;
dschinazi4ad1f462020-01-16 11:56:52 -080053// Default value of the max_packet_size transport parameter if it is not
54// transmitted.
55const QuicByteCount kDefaultMaxPacketSizeTransportParam = 65527;
QUICHE teama6ef0a62019-03-07 20:34:33 -050056// Default maximum packet size used in the Linux TCP implementation.
57// Used in QUIC for congestion window computations in bytes.
58const QuicByteCount kDefaultTCPMSS = 1460;
59const QuicByteCount kMaxSegmentSize = kDefaultTCPMSS;
60// The minimum size of a packet which can elicit a version negotiation packet,
61// as per section 8.1 of the QUIC spec.
62const QuicByteCount kMinPacketSizeForVersionNegotiation = 1200;
63
64// We match SPDY's use of 32 (since we'd compete with SPDY).
65const QuicPacketCount kInitialCongestionWindow = 32;
66
fayangbe83ecd2019-04-26 13:58:09 -070067// Do not allow initial congestion window to be greater than 200 packets.
68const QuicPacketCount kMaxInitialCongestionWindow = 200;
69
fayangf1b99dc2019-05-14 06:29:18 -070070// Do not allow initial congestion window to be smaller than 10 packets.
71const QuicPacketCount kMinInitialCongestionWindow = 10;
72
QUICHE teama6ef0a62019-03-07 20:34:33 -050073// Minimum size of initial flow control window, for both stream and session.
dschinazic7036122019-04-30 12:46:34 -070074// This is only enforced when version.AllowsLowFlowControlLimits() is false.
QUICHE teama6ef0a62019-03-07 20:34:33 -050075const uint32_t kMinimumFlowControlSendWindow = 16 * 1024; // 16 KB
dschinazic7036122019-04-30 12:46:34 -070076// Default size of initial flow control window, for both stream and session.
77const uint32_t kDefaultFlowControlSendWindow = 16 * 1024; // 16 KB
QUICHE teama6ef0a62019-03-07 20:34:33 -050078
79// Maximum flow control receive window limits for connection and stream.
80const QuicByteCount kStreamReceiveWindowLimit = 16 * 1024 * 1024; // 16 MB
81const QuicByteCount kSessionReceiveWindowLimit = 24 * 1024 * 1024; // 24 MB
82
bncbdd303e2019-07-09 05:33:17 -070083// Default limit on the size of uncompressed headers,
84// communicated via SETTINGS_MAX_HEADER_LIST_SIZE.
85// TODO(bnc): Move this constant to quic/core/http/.
QUICHE teama6ef0a62019-03-07 20:34:33 -050086const QuicByteCount kDefaultMaxUncompressedHeaderSize = 16 * 1024; // 16 KB
87
88// Minimum size of the CWND, in packets, when doing bandwidth resumption.
89const QuicPacketCount kMinCongestionWindowForBandwidthResumption = 10;
90
QUICHE teama6ef0a62019-03-07 20:34:33 -050091// Default size of the socket receive buffer in bytes.
92const QuicByteCount kDefaultSocketReceiveBuffer = 1024 * 1024;
93
94// Don't allow a client to suggest an RTT shorter than 10ms.
95const uint32_t kMinInitialRoundTripTimeUs = 10 * kNumMicrosPerMilli;
96
97// Don't allow a client to suggest an RTT longer than 15 seconds.
98const uint32_t kMaxInitialRoundTripTimeUs = 15 * kNumMicrosPerSecond;
99
100// Maximum number of open streams per connection.
101const size_t kDefaultMaxStreamsPerConnection = 100;
102
103// Number of bytes reserved for public flags in the packet header.
104const size_t kPublicFlagsSize = 1;
105// Number of bytes reserved for version number in the packet header.
106const size_t kQuicVersionSize = 4;
107
108// Signifies that the QuicPacket will contain version of the protocol.
109const bool kIncludeVersion = true;
110// Signifies that the QuicPacket will include a diversification nonce.
111const bool kIncludeDiversificationNonce = true;
112
113// Header key used to identify final offset on data stream when sending HTTP/2
114// trailing headers over QUIC.
115QUIC_EXPORT_PRIVATE extern const char* const kFinalOffsetHeaderKey;
116
117// Default maximum delayed ack time, in ms.
118// Uses a 25ms delayed ack timer. Helps with better signaling
119// in low-bandwidth (< ~384 kbps), where an ack is sent per packet.
120const int64_t kDefaultDelayedAckTimeMs = 25;
121
fkastenholz4dc4ba32019-07-30 09:55:25 -0700122// Default shift of the ACK delay in the IETF QUIC ACK frame.
123const uint32_t kDefaultAckDelayExponent = 3;
124
QUICHE teama6ef0a62019-03-07 20:34:33 -0500125// Minimum tail loss probe time in ms.
126static const int64_t kMinTailLossProbeTimeoutMs = 10;
127
128// The timeout before the handshake succeeds.
129const int64_t kInitialIdleTimeoutSecs = 5;
130// The default idle timeout.
131const int64_t kDefaultIdleTimeoutSecs = 30;
132// The maximum idle timeout that can be negotiated.
133const int64_t kMaximumIdleTimeoutSecs = 60 * 10; // 10 minutes.
134// The default timeout for a connection until the crypto handshake succeeds.
135const int64_t kMaxTimeForCryptoHandshakeSecs = 10; // 10 secs.
136
137// Default limit on the number of undecryptable packets the connection buffers
138// before the CHLO/SHLO arrive.
139const size_t kDefaultMaxUndecryptablePackets = 10;
140
141// Default ping timeout.
142const int64_t kPingTimeoutSecs = 15; // 15 secs.
143
144// Minimum number of RTTs between Server Config Updates (SCUP) sent to client.
145const int kMinIntervalBetweenServerConfigUpdatesRTTs = 10;
146
147// Minimum time between Server Config Updates (SCUP) sent to client.
148const int kMinIntervalBetweenServerConfigUpdatesMs = 1000;
149
150// Minimum number of packets between Server Config Updates (SCUP).
151const int kMinPacketsBetweenServerConfigUpdates = 100;
152
153// The number of open streams that a server will accept is set to be slightly
154// larger than the negotiated limit. Immediately closing the connection if the
155// client opens slightly too many streams is not ideal: the client may have sent
156// a FIN that was lost, and simultaneously opened a new stream. The number of
157// streams a server accepts is a fixed increment over the negotiated limit, or a
158// percentage increase, whichever is larger.
159const float kMaxStreamsMultiplier = 1.1f;
160const int kMaxStreamsMinimumIncrement = 10;
161
162// Available streams are ones with IDs less than the highest stream that has
163// been opened which have neither been opened or reset. The limit on the number
164// of available streams is 10 times the limit on the number of open streams.
165const int kMaxAvailableStreamsMultiplier = 10;
166
167// Track the number of promises that are not yet claimed by a
168// corresponding get. This must be smaller than
169// kMaxAvailableStreamsMultiplier, because RST on a promised stream my
170// create available streams entries.
171const int kMaxPromisedStreamsMultiplier = kMaxAvailableStreamsMultiplier - 1;
172
173// TCP RFC calls for 1 second RTO however Linux differs from this default and
174// define the minimum RTO to 200ms, we will use the same until we have data to
175// support a higher or lower value.
176static const int64_t kMinRetransmissionTimeMs = 200;
177// The delayed ack time must not be greater than half the min RTO.
178static_assert(kDefaultDelayedAckTimeMs <= kMinRetransmissionTimeMs / 2,
179 "Delayed ack time must be less than or equal half the MinRTO");
180
181// We define an unsigned 16-bit floating point value, inspired by IEEE floats
182// (http://en.wikipedia.org/wiki/Half_precision_floating-point_format),
183// with 5-bit exponent (bias 1), 11-bit mantissa (effective 12 with hidden
184// bit) and denormals, but without signs, transfinites or fractions. Wire format
185// 16 bits (little-endian byte order) are split into exponent (high 5) and
186// mantissa (low 11) and decoded as:
187// uint64_t value;
188// if (exponent == 0) value = mantissa;
189// else value = (mantissa | 1 << 11) << (exponent - 1)
190const int kUFloat16ExponentBits = 5;
191const int kUFloat16MaxExponent = (1 << kUFloat16ExponentBits) - 2; // 30
192const int kUFloat16MantissaBits = 16 - kUFloat16ExponentBits; // 11
193const int kUFloat16MantissaEffectiveBits = kUFloat16MantissaBits + 1; // 12
194const uint64_t kUFloat16MaxValue = // 0x3FFC0000000
195 ((UINT64_C(1) << kUFloat16MantissaEffectiveBits) - 1)
196 << kUFloat16MaxExponent;
197
198// kDiversificationNonceSize is the size, in bytes, of the nonce that a server
199// may set in the packet header to ensure that its INITIAL keys are not
200// duplicated.
201const size_t kDiversificationNonceSize = 32;
202
203// The largest gap in packets we'll accept without closing the connection.
204// This will likely have to be tuned.
205const QuicPacketCount kMaxPacketGap = 5000;
206
207// The maximum number of random padding bytes to add.
208const QuicByteCount kMaxNumRandomPaddingBytes = 256;
209
210// The size of stream send buffer data slice size in bytes. A data slice is
211// piece of stream data stored in contiguous memory, and a stream frame can
212// contain data from multiple data slices.
213const QuicByteCount kQuicStreamSendBufferSliceSize = 4 * 1024;
214
215// For When using Random Initial Packet Numbers, they can start
216// anyplace in the range 1...((2^31)-1) or 0x7fffffff
217QUIC_EXPORT_PRIVATE QuicPacketNumber MaxRandomInitialPacketNumber();
218
219// Used to represent an invalid or no control frame id.
220const QuicControlFrameId kInvalidControlFrameId = 0;
221
222// The max length a stream can have.
223const QuicByteCount kMaxStreamLength = (UINT64_C(1) << 62) - 1;
224
225// The max value that can be encoded using IETF Var Ints.
226const uint64_t kMaxIetfVarInt = UINT64_C(0x3fffffffffffffff);
227
228// The maximum stream id value that is supported - (2^32)-1
QUICHE teama6ef0a62019-03-07 20:34:33 -0500229const QuicStreamId kMaxQuicStreamId = 0xffffffff;
230
fkastenholz3c4eabf2019-04-22 07:49:59 -0700231// The maximum value that can be stored in a 32-bit QuicStreamCount.
232const QuicStreamCount kMaxQuicStreamCount = 0xffffffff;
233
QUICHE teama6ef0a62019-03-07 20:34:33 -0500234// Number of bytes reserved for packet header type.
235const size_t kPacketHeaderTypeSize = 1;
236
237// Number of bytes reserved for connection ID length.
238const size_t kConnectionIdLengthSize = 1;
239
240// Minimum length of random bytes in IETF stateless reset packet.
241const size_t kMinRandomBytesLengthInStatelessReset = 24;
242
243// Maximum length allowed for the token in a NEW_TOKEN frame.
244const size_t kMaxNewTokenTokenLength = 0xffff;
245
fayang14650e42019-06-04 10:30:33 -0700246// Default initial rtt used before any samples are received.
247const int kInitialRttMs = 100;
248
fayangb0c7b4b2019-09-12 06:45:24 -0700249// Default fraction (1/4) of an RTT the algorithm waits before determining a
250// packet is lost due to early retransmission by time based loss detection.
251static const int kDefaultLossDelayShift = 2;
252
fayang01983412019-12-07 05:50:22 -0800253// Default fraction (1/8) of an RTT when doing IETF loss detection.
254static const int kDefaultIetfLossDelayShift = 3;
255
fayang4c908f02019-11-01 07:26:17 -0700256// Maximum number of retransmittable packets received before sending an ack.
257const QuicPacketCount kDefaultRetransmittablePacketsBeforeAck = 2;
258// Wait for up to 10 retransmittable packets before sending an ack.
259const QuicPacketCount kMaxRetransmittablePacketsBeforeAck = 10;
260// Minimum number of packets received before ack decimation is enabled.
261// This intends to avoid the beginning of slow start, when CWNDs may be
262// rapidly increasing.
263const QuicPacketCount kMinReceivedBeforeAckDecimation = 100;
264
ianswett8f90e512019-12-18 10:50:27 -0800265// The default alarm granularity assumed by QUIC code.
266const QuicTime::Delta kAlarmGranularity = QuicTime::Delta::FromMilliseconds(1);
267
QUICHE teama6ef0a62019-03-07 20:34:33 -0500268// Packet number of first sending packet of a connection. Please note, this
269// cannot be used as first received packet because peer can choose its starting
270// packet number.
271QUIC_EXPORT_PRIVATE QuicPacketNumber FirstSendingPacketNumber();
272
273// Used by clients to tell if a public reset is sent from a Google frontend.
274QUIC_EXPORT_PRIVATE extern const char* const kEPIDGoogleFrontEnd;
275QUIC_EXPORT_PRIVATE extern const char* const kEPIDGoogleFrontEnd0;
276
277} // namespace quic
278
279#endif // QUICHE_QUIC_CORE_QUIC_CONSTANTS_H_