blob: 913c063432c03d5fdde6b5d94712c59505e4b406 [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;
50// Default maximum packet size used in the Linux TCP implementation.
51// Used in QUIC for congestion window computations in bytes.
52const QuicByteCount kDefaultTCPMSS = 1460;
53const QuicByteCount kMaxSegmentSize = kDefaultTCPMSS;
54// The minimum size of a packet which can elicit a version negotiation packet,
55// as per section 8.1 of the QUIC spec.
56const QuicByteCount kMinPacketSizeForVersionNegotiation = 1200;
57
58// We match SPDY's use of 32 (since we'd compete with SPDY).
59const QuicPacketCount kInitialCongestionWindow = 32;
60
fayangbe83ecd2019-04-26 13:58:09 -070061// Do not allow initial congestion window to be greater than 200 packets.
62const QuicPacketCount kMaxInitialCongestionWindow = 200;
63
fayangf1b99dc2019-05-14 06:29:18 -070064// Do not allow initial congestion window to be smaller than 10 packets.
65const QuicPacketCount kMinInitialCongestionWindow = 10;
66
QUICHE teama6ef0a62019-03-07 20:34:33 -050067// Minimum size of initial flow control window, for both stream and session.
dschinazic7036122019-04-30 12:46:34 -070068// This is only enforced when version.AllowsLowFlowControlLimits() is false.
QUICHE teama6ef0a62019-03-07 20:34:33 -050069const uint32_t kMinimumFlowControlSendWindow = 16 * 1024; // 16 KB
dschinazic7036122019-04-30 12:46:34 -070070// Default size of initial flow control window, for both stream and session.
71const uint32_t kDefaultFlowControlSendWindow = 16 * 1024; // 16 KB
QUICHE teama6ef0a62019-03-07 20:34:33 -050072
73// Maximum flow control receive window limits for connection and stream.
74const QuicByteCount kStreamReceiveWindowLimit = 16 * 1024 * 1024; // 16 MB
75const QuicByteCount kSessionReceiveWindowLimit = 24 * 1024 * 1024; // 24 MB
76
77// Default limit on the size of uncompressed headers.
78const QuicByteCount kDefaultMaxUncompressedHeaderSize = 16 * 1024; // 16 KB
79
80// Minimum size of the CWND, in packets, when doing bandwidth resumption.
81const QuicPacketCount kMinCongestionWindowForBandwidthResumption = 10;
82
83// Maximum number of tracked packets.
84const QuicPacketCount kMaxTrackedPackets = 10000;
85
86// Default size of the socket receive buffer in bytes.
87const QuicByteCount kDefaultSocketReceiveBuffer = 1024 * 1024;
88
89// Don't allow a client to suggest an RTT shorter than 10ms.
90const uint32_t kMinInitialRoundTripTimeUs = 10 * kNumMicrosPerMilli;
91
92// Don't allow a client to suggest an RTT longer than 15 seconds.
93const uint32_t kMaxInitialRoundTripTimeUs = 15 * kNumMicrosPerSecond;
94
95// Maximum number of open streams per connection.
96const size_t kDefaultMaxStreamsPerConnection = 100;
97
98// Number of bytes reserved for public flags in the packet header.
99const size_t kPublicFlagsSize = 1;
100// Number of bytes reserved for version number in the packet header.
101const size_t kQuicVersionSize = 4;
102
103// Signifies that the QuicPacket will contain version of the protocol.
104const bool kIncludeVersion = true;
105// Signifies that the QuicPacket will include a diversification nonce.
106const bool kIncludeDiversificationNonce = true;
107
108// Header key used to identify final offset on data stream when sending HTTP/2
109// trailing headers over QUIC.
110QUIC_EXPORT_PRIVATE extern const char* const kFinalOffsetHeaderKey;
111
112// Default maximum delayed ack time, in ms.
113// Uses a 25ms delayed ack timer. Helps with better signaling
114// in low-bandwidth (< ~384 kbps), where an ack is sent per packet.
115const int64_t kDefaultDelayedAckTimeMs = 25;
116
117// Minimum tail loss probe time in ms.
118static const int64_t kMinTailLossProbeTimeoutMs = 10;
119
120// The timeout before the handshake succeeds.
121const int64_t kInitialIdleTimeoutSecs = 5;
122// The default idle timeout.
123const int64_t kDefaultIdleTimeoutSecs = 30;
124// The maximum idle timeout that can be negotiated.
125const int64_t kMaximumIdleTimeoutSecs = 60 * 10; // 10 minutes.
126// The default timeout for a connection until the crypto handshake succeeds.
127const int64_t kMaxTimeForCryptoHandshakeSecs = 10; // 10 secs.
128
129// Default limit on the number of undecryptable packets the connection buffers
130// before the CHLO/SHLO arrive.
131const size_t kDefaultMaxUndecryptablePackets = 10;
132
133// Default ping timeout.
134const int64_t kPingTimeoutSecs = 15; // 15 secs.
135
136// Minimum number of RTTs between Server Config Updates (SCUP) sent to client.
137const int kMinIntervalBetweenServerConfigUpdatesRTTs = 10;
138
139// Minimum time between Server Config Updates (SCUP) sent to client.
140const int kMinIntervalBetweenServerConfigUpdatesMs = 1000;
141
142// Minimum number of packets between Server Config Updates (SCUP).
143const int kMinPacketsBetweenServerConfigUpdates = 100;
144
145// The number of open streams that a server will accept is set to be slightly
146// larger than the negotiated limit. Immediately closing the connection if the
147// client opens slightly too many streams is not ideal: the client may have sent
148// a FIN that was lost, and simultaneously opened a new stream. The number of
149// streams a server accepts is a fixed increment over the negotiated limit, or a
150// percentage increase, whichever is larger.
151const float kMaxStreamsMultiplier = 1.1f;
152const int kMaxStreamsMinimumIncrement = 10;
153
154// Available streams are ones with IDs less than the highest stream that has
155// been opened which have neither been opened or reset. The limit on the number
156// of available streams is 10 times the limit on the number of open streams.
157const int kMaxAvailableStreamsMultiplier = 10;
158
159// Track the number of promises that are not yet claimed by a
160// corresponding get. This must be smaller than
161// kMaxAvailableStreamsMultiplier, because RST on a promised stream my
162// create available streams entries.
163const int kMaxPromisedStreamsMultiplier = kMaxAvailableStreamsMultiplier - 1;
164
165// TCP RFC calls for 1 second RTO however Linux differs from this default and
166// define the minimum RTO to 200ms, we will use the same until we have data to
167// support a higher or lower value.
168static const int64_t kMinRetransmissionTimeMs = 200;
169// The delayed ack time must not be greater than half the min RTO.
170static_assert(kDefaultDelayedAckTimeMs <= kMinRetransmissionTimeMs / 2,
171 "Delayed ack time must be less than or equal half the MinRTO");
172
173// We define an unsigned 16-bit floating point value, inspired by IEEE floats
174// (http://en.wikipedia.org/wiki/Half_precision_floating-point_format),
175// with 5-bit exponent (bias 1), 11-bit mantissa (effective 12 with hidden
176// bit) and denormals, but without signs, transfinites or fractions. Wire format
177// 16 bits (little-endian byte order) are split into exponent (high 5) and
178// mantissa (low 11) and decoded as:
179// uint64_t value;
180// if (exponent == 0) value = mantissa;
181// else value = (mantissa | 1 << 11) << (exponent - 1)
182const int kUFloat16ExponentBits = 5;
183const int kUFloat16MaxExponent = (1 << kUFloat16ExponentBits) - 2; // 30
184const int kUFloat16MantissaBits = 16 - kUFloat16ExponentBits; // 11
185const int kUFloat16MantissaEffectiveBits = kUFloat16MantissaBits + 1; // 12
186const uint64_t kUFloat16MaxValue = // 0x3FFC0000000
187 ((UINT64_C(1) << kUFloat16MantissaEffectiveBits) - 1)
188 << kUFloat16MaxExponent;
189
190// kDiversificationNonceSize is the size, in bytes, of the nonce that a server
191// may set in the packet header to ensure that its INITIAL keys are not
192// duplicated.
193const size_t kDiversificationNonceSize = 32;
194
195// The largest gap in packets we'll accept without closing the connection.
196// This will likely have to be tuned.
197const QuicPacketCount kMaxPacketGap = 5000;
198
199// The maximum number of random padding bytes to add.
200const QuicByteCount kMaxNumRandomPaddingBytes = 256;
201
202// The size of stream send buffer data slice size in bytes. A data slice is
203// piece of stream data stored in contiguous memory, and a stream frame can
204// contain data from multiple data slices.
205const QuicByteCount kQuicStreamSendBufferSliceSize = 4 * 1024;
206
207// For When using Random Initial Packet Numbers, they can start
208// anyplace in the range 1...((2^31)-1) or 0x7fffffff
209QUIC_EXPORT_PRIVATE QuicPacketNumber MaxRandomInitialPacketNumber();
210
211// Used to represent an invalid or no control frame id.
212const QuicControlFrameId kInvalidControlFrameId = 0;
213
214// The max length a stream can have.
215const QuicByteCount kMaxStreamLength = (UINT64_C(1) << 62) - 1;
216
217// The max value that can be encoded using IETF Var Ints.
218const uint64_t kMaxIetfVarInt = UINT64_C(0x3fffffffffffffff);
219
220// The maximum stream id value that is supported - (2^32)-1
221// TODO(fkastenholz): Should update this to 64 bits for IETF Quic.
222const QuicStreamId kMaxQuicStreamId = 0xffffffff;
223
fkastenholz3c4eabf2019-04-22 07:49:59 -0700224// The maximum value that can be stored in a 32-bit QuicStreamCount.
225const QuicStreamCount kMaxQuicStreamCount = 0xffffffff;
226
QUICHE teama6ef0a62019-03-07 20:34:33 -0500227// Number of bytes reserved for packet header type.
228const size_t kPacketHeaderTypeSize = 1;
229
230// Number of bytes reserved for connection ID length.
231const size_t kConnectionIdLengthSize = 1;
232
233// Minimum length of random bytes in IETF stateless reset packet.
234const size_t kMinRandomBytesLengthInStatelessReset = 24;
235
236// Maximum length allowed for the token in a NEW_TOKEN frame.
237const size_t kMaxNewTokenTokenLength = 0xffff;
238
fayang14650e42019-06-04 10:30:33 -0700239// Default initial rtt used before any samples are received.
240const int kInitialRttMs = 100;
241
QUICHE teama6ef0a62019-03-07 20:34:33 -0500242// Packet number of first sending packet of a connection. Please note, this
243// cannot be used as first received packet because peer can choose its starting
244// packet number.
245QUIC_EXPORT_PRIVATE QuicPacketNumber FirstSendingPacketNumber();
246
247// Used by clients to tell if a public reset is sent from a Google frontend.
248QUIC_EXPORT_PRIVATE extern const char* const kEPIDGoogleFrontEnd;
249QUIC_EXPORT_PRIVATE extern const char* const kEPIDGoogleFrontEnd0;
250
251} // namespace quic
252
253#endif // QUICHE_QUIC_CORE_QUIC_CONSTANTS_H_