xref: /aosp_15_r20/external/webrtc/net/dcsctp/public/dcsctp_options.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1*d9f75844SAndroid Build Coastguard Worker /*
2*d9f75844SAndroid Build Coastguard Worker  *  Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
3*d9f75844SAndroid Build Coastguard Worker  *
4*d9f75844SAndroid Build Coastguard Worker  *  Use of this source code is governed by a BSD-style license
5*d9f75844SAndroid Build Coastguard Worker  *  that can be found in the LICENSE file in the root of the source
6*d9f75844SAndroid Build Coastguard Worker  *  tree. An additional intellectual property rights grant can be found
7*d9f75844SAndroid Build Coastguard Worker  *  in the file PATENTS.  All contributing project authors may
8*d9f75844SAndroid Build Coastguard Worker  *  be found in the AUTHORS file in the root of the source tree.
9*d9f75844SAndroid Build Coastguard Worker  */
10*d9f75844SAndroid Build Coastguard Worker #ifndef NET_DCSCTP_PUBLIC_DCSCTP_OPTIONS_H_
11*d9f75844SAndroid Build Coastguard Worker #define NET_DCSCTP_PUBLIC_DCSCTP_OPTIONS_H_
12*d9f75844SAndroid Build Coastguard Worker 
13*d9f75844SAndroid Build Coastguard Worker #include <stddef.h>
14*d9f75844SAndroid Build Coastguard Worker #include <stdint.h>
15*d9f75844SAndroid Build Coastguard Worker 
16*d9f75844SAndroid Build Coastguard Worker #include "absl/types/optional.h"
17*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/public/types.h"
18*d9f75844SAndroid Build Coastguard Worker 
19*d9f75844SAndroid Build Coastguard Worker namespace dcsctp {
20*d9f75844SAndroid Build Coastguard Worker struct DcSctpOptions {
21*d9f75844SAndroid Build Coastguard Worker   // The largest safe SCTP packet. Starting from the minimum guaranteed MTU
22*d9f75844SAndroid Build Coastguard Worker   // value of 1280 for IPv6 (which may not support fragmentation), take off 85
23*d9f75844SAndroid Build Coastguard Worker   // bytes for DTLS/TURN/TCP/IP and ciphertext overhead.
24*d9f75844SAndroid Build Coastguard Worker   //
25*d9f75844SAndroid Build Coastguard Worker   // Additionally, it's possible that TURN adds an additional 4 bytes of
26*d9f75844SAndroid Build Coastguard Worker   // overhead after a channel has been established, so an additional 4 bytes is
27*d9f75844SAndroid Build Coastguard Worker   // subtracted
28*d9f75844SAndroid Build Coastguard Worker   //
29*d9f75844SAndroid Build Coastguard Worker   // 1280 IPV6 MTU
30*d9f75844SAndroid Build Coastguard Worker   //  -40 IPV6 header
31*d9f75844SAndroid Build Coastguard Worker   //   -8 UDP
32*d9f75844SAndroid Build Coastguard Worker   //  -24 GCM Cipher
33*d9f75844SAndroid Build Coastguard Worker   //  -13 DTLS record header
34*d9f75844SAndroid Build Coastguard Worker   //   -4 TURN ChannelData
35*d9f75844SAndroid Build Coastguard Worker   // = 1191 bytes.
36*d9f75844SAndroid Build Coastguard Worker   static constexpr size_t kMaxSafeMTUSize = 1191;
37*d9f75844SAndroid Build Coastguard Worker 
38*d9f75844SAndroid Build Coastguard Worker   // The local port for which the socket is supposed to be bound to. Incoming
39*d9f75844SAndroid Build Coastguard Worker   // packets will be verified that they are sent to this port number and all
40*d9f75844SAndroid Build Coastguard Worker   // outgoing packets will have this port number as source port.
41*d9f75844SAndroid Build Coastguard Worker   int local_port = 5000;
42*d9f75844SAndroid Build Coastguard Worker 
43*d9f75844SAndroid Build Coastguard Worker   // The remote port to send packets to. All outgoing packets will have this
44*d9f75844SAndroid Build Coastguard Worker   // port number as destination port.
45*d9f75844SAndroid Build Coastguard Worker   int remote_port = 5000;
46*d9f75844SAndroid Build Coastguard Worker 
47*d9f75844SAndroid Build Coastguard Worker   // The announced maximum number of incoming streams. Note that this value is
48*d9f75844SAndroid Build Coastguard Worker   // constant and can't be currently increased in run-time as "Add Incoming
49*d9f75844SAndroid Build Coastguard Worker   // Streams Request" in RFC6525 isn't supported.
50*d9f75844SAndroid Build Coastguard Worker   //
51*d9f75844SAndroid Build Coastguard Worker   // The socket implementation doesn't have any per-stream fixed costs, which is
52*d9f75844SAndroid Build Coastguard Worker   // why the default value is set to be the maximum value.
53*d9f75844SAndroid Build Coastguard Worker   uint16_t announced_maximum_incoming_streams = 65535;
54*d9f75844SAndroid Build Coastguard Worker 
55*d9f75844SAndroid Build Coastguard Worker   // The announced maximum number of outgoing streams. Note that this value is
56*d9f75844SAndroid Build Coastguard Worker   // constant and can't be currently increased in run-time as "Add Outgoing
57*d9f75844SAndroid Build Coastguard Worker   // Streams Request" in RFC6525 isn't supported.
58*d9f75844SAndroid Build Coastguard Worker   //
59*d9f75844SAndroid Build Coastguard Worker   // The socket implementation doesn't have any per-stream fixed costs, which is
60*d9f75844SAndroid Build Coastguard Worker   // why the default value is set to be the maximum value.
61*d9f75844SAndroid Build Coastguard Worker   uint16_t announced_maximum_outgoing_streams = 65535;
62*d9f75844SAndroid Build Coastguard Worker 
63*d9f75844SAndroid Build Coastguard Worker   // Maximum SCTP packet size. The library will limit the size of generated
64*d9f75844SAndroid Build Coastguard Worker   // packets to be less than or equal to this number. This does not include any
65*d9f75844SAndroid Build Coastguard Worker   // overhead of DTLS, TURN, UDP or IP headers.
66*d9f75844SAndroid Build Coastguard Worker   size_t mtu = kMaxSafeMTUSize;
67*d9f75844SAndroid Build Coastguard Worker 
68*d9f75844SAndroid Build Coastguard Worker   // The largest allowed message payload to be sent. Messages will be rejected
69*d9f75844SAndroid Build Coastguard Worker   // if their payload is larger than this value. Note that this doesn't affect
70*d9f75844SAndroid Build Coastguard Worker   // incoming messages, which may larger than this value (but smaller than
71*d9f75844SAndroid Build Coastguard Worker   // `max_receiver_window_buffer_size`).
72*d9f75844SAndroid Build Coastguard Worker   size_t max_message_size = 256 * 1024;
73*d9f75844SAndroid Build Coastguard Worker 
74*d9f75844SAndroid Build Coastguard Worker   // The default stream priority, if not overridden by
75*d9f75844SAndroid Build Coastguard Worker   // `SctpSocket::SetStreamPriority`. The default value is selected to be
76*d9f75844SAndroid Build Coastguard Worker   // compatible with https://www.w3.org/TR/webrtc-priority/, section 4.2-4.3.
77*d9f75844SAndroid Build Coastguard Worker   StreamPriority default_stream_priority = StreamPriority(256);
78*d9f75844SAndroid Build Coastguard Worker 
79*d9f75844SAndroid Build Coastguard Worker   // Maximum received window buffer size. This should be a bit larger than the
80*d9f75844SAndroid Build Coastguard Worker   // largest sized message you want to be able to receive. This essentially
81*d9f75844SAndroid Build Coastguard Worker   // limits the memory usage on the receive side. Note that memory is allocated
82*d9f75844SAndroid Build Coastguard Worker   // dynamically, and this represents the maximum amount of buffered data. The
83*d9f75844SAndroid Build Coastguard Worker   // actual memory usage of the library will be smaller in normal operation, and
84*d9f75844SAndroid Build Coastguard Worker   // will be larger than this due to other allocations and overhead if the
85*d9f75844SAndroid Build Coastguard Worker   // buffer is fully utilized.
86*d9f75844SAndroid Build Coastguard Worker   size_t max_receiver_window_buffer_size = 5 * 1024 * 1024;
87*d9f75844SAndroid Build Coastguard Worker 
88*d9f75844SAndroid Build Coastguard Worker   // Maximum send buffer size. It will not be possible to queue more data than
89*d9f75844SAndroid Build Coastguard Worker   // this before sending it.
90*d9f75844SAndroid Build Coastguard Worker   size_t max_send_buffer_size = 2'000'000;
91*d9f75844SAndroid Build Coastguard Worker 
92*d9f75844SAndroid Build Coastguard Worker   // A threshold that, when the amount of data in the send buffer goes below
93*d9f75844SAndroid Build Coastguard Worker   // this value, will trigger `DcSctpCallbacks::OnTotalBufferedAmountLow`.
94*d9f75844SAndroid Build Coastguard Worker   size_t total_buffered_amount_low_threshold = 1'800'000;
95*d9f75844SAndroid Build Coastguard Worker 
96*d9f75844SAndroid Build Coastguard Worker   // Max allowed RTT value. When the RTT is measured and it's found to be larger
97*d9f75844SAndroid Build Coastguard Worker   // than this value, it will be discarded and not used for e.g. any RTO
98*d9f75844SAndroid Build Coastguard Worker   // calculation. The default value is an extreme maximum but can be adapted
99*d9f75844SAndroid Build Coastguard Worker   // to better match the environment.
100*d9f75844SAndroid Build Coastguard Worker   DurationMs rtt_max = DurationMs(60'000);
101*d9f75844SAndroid Build Coastguard Worker 
102*d9f75844SAndroid Build Coastguard Worker   // Initial RTO value.
103*d9f75844SAndroid Build Coastguard Worker   DurationMs rto_initial = DurationMs(500);
104*d9f75844SAndroid Build Coastguard Worker 
105*d9f75844SAndroid Build Coastguard Worker   // Maximum RTO value.
106*d9f75844SAndroid Build Coastguard Worker   DurationMs rto_max = DurationMs(60'000);
107*d9f75844SAndroid Build Coastguard Worker 
108*d9f75844SAndroid Build Coastguard Worker   // Minimum RTO value. This must be larger than an expected peer delayed ack
109*d9f75844SAndroid Build Coastguard Worker   // timeout.
110*d9f75844SAndroid Build Coastguard Worker   DurationMs rto_min = DurationMs(400);
111*d9f75844SAndroid Build Coastguard Worker 
112*d9f75844SAndroid Build Coastguard Worker   // T1-init timeout.
113*d9f75844SAndroid Build Coastguard Worker   DurationMs t1_init_timeout = DurationMs(1000);
114*d9f75844SAndroid Build Coastguard Worker 
115*d9f75844SAndroid Build Coastguard Worker   // T1-cookie timeout.
116*d9f75844SAndroid Build Coastguard Worker   DurationMs t1_cookie_timeout = DurationMs(1000);
117*d9f75844SAndroid Build Coastguard Worker 
118*d9f75844SAndroid Build Coastguard Worker   // T2-shutdown timeout.
119*d9f75844SAndroid Build Coastguard Worker   DurationMs t2_shutdown_timeout = DurationMs(1000);
120*d9f75844SAndroid Build Coastguard Worker 
121*d9f75844SAndroid Build Coastguard Worker   // For t1-init, t1-cookie, t2-shutdown, t3-rtx, this value - if set - will be
122*d9f75844SAndroid Build Coastguard Worker   // the upper bound on how large the exponentially backed off timeout can
123*d9f75844SAndroid Build Coastguard Worker   // become. The lower the duration, the faster the connection can recover on
124*d9f75844SAndroid Build Coastguard Worker   // transient network issues. Setting this value may require changing
125*d9f75844SAndroid Build Coastguard Worker   // `max_retransmissions` and `max_init_retransmits` to ensure that the
126*d9f75844SAndroid Build Coastguard Worker   // connection is not closed too quickly.
127*d9f75844SAndroid Build Coastguard Worker   absl::optional<DurationMs> max_timer_backoff_duration = absl::nullopt;
128*d9f75844SAndroid Build Coastguard Worker 
129*d9f75844SAndroid Build Coastguard Worker   // Hearbeat interval (on idle connections only). Set to zero to disable.
130*d9f75844SAndroid Build Coastguard Worker   DurationMs heartbeat_interval = DurationMs(30000);
131*d9f75844SAndroid Build Coastguard Worker 
132*d9f75844SAndroid Build Coastguard Worker   // The maximum time when a SACK will be sent from the arrival of an
133*d9f75844SAndroid Build Coastguard Worker   // unacknowledged packet. Whatever is smallest of RTO/2 and this will be used.
134*d9f75844SAndroid Build Coastguard Worker   DurationMs delayed_ack_max_timeout = DurationMs(200);
135*d9f75844SAndroid Build Coastguard Worker 
136*d9f75844SAndroid Build Coastguard Worker   // The minimum limit for the measured RTT variance
137*d9f75844SAndroid Build Coastguard Worker   //
138*d9f75844SAndroid Build Coastguard Worker   // Setting this below the expected delayed ack timeout (+ margin) of the peer
139*d9f75844SAndroid Build Coastguard Worker   // might result in unnecessary retransmissions, as the maximum time it takes
140*d9f75844SAndroid Build Coastguard Worker   // to ACK a DATA chunk is typically RTT + ATO (delayed ack timeout), and when
141*d9f75844SAndroid Build Coastguard Worker   // the SCTP channel is quite idle, and heartbeats dominate the source of RTT
142*d9f75844SAndroid Build Coastguard Worker   // measurement, the RTO would converge with the smoothed RTT (SRTT). The
143*d9f75844SAndroid Build Coastguard Worker   // default ATO is 200ms in usrsctp, and a 20ms (10%) margin would include the
144*d9f75844SAndroid Build Coastguard Worker   // processing time of received packets and the clock granularity when setting
145*d9f75844SAndroid Build Coastguard Worker   // the delayed ack timer on the peer.
146*d9f75844SAndroid Build Coastguard Worker   //
147*d9f75844SAndroid Build Coastguard Worker   // This is described for TCP in
148*d9f75844SAndroid Build Coastguard Worker   // https://datatracker.ietf.org/doc/html/rfc6298#section-4.
149*d9f75844SAndroid Build Coastguard Worker   DurationMs min_rtt_variance = DurationMs(220);
150*d9f75844SAndroid Build Coastguard Worker 
151*d9f75844SAndroid Build Coastguard Worker   // The initial congestion window size, in number of MTUs.
152*d9f75844SAndroid Build Coastguard Worker   // See https://tools.ietf.org/html/rfc4960#section-7.2.1 which defaults at ~3
153*d9f75844SAndroid Build Coastguard Worker   // and https://research.google/pubs/pub36640/ which argues for at least ten
154*d9f75844SAndroid Build Coastguard Worker   // segments.
155*d9f75844SAndroid Build Coastguard Worker   size_t cwnd_mtus_initial = 10;
156*d9f75844SAndroid Build Coastguard Worker 
157*d9f75844SAndroid Build Coastguard Worker   // The minimum congestion window size, in number of MTUs, upon detection of
158*d9f75844SAndroid Build Coastguard Worker   // packet loss by SACK. Note that if the retransmission timer expires, the
159*d9f75844SAndroid Build Coastguard Worker   // congestion window will be as small as one MTU. See
160*d9f75844SAndroid Build Coastguard Worker   // https://tools.ietf.org/html/rfc4960#section-7.2.3.
161*d9f75844SAndroid Build Coastguard Worker   size_t cwnd_mtus_min = 4;
162*d9f75844SAndroid Build Coastguard Worker 
163*d9f75844SAndroid Build Coastguard Worker   // When the congestion window is at or above this number of MTUs, the
164*d9f75844SAndroid Build Coastguard Worker   // congestion control algorithm will avoid filling the congestion window
165*d9f75844SAndroid Build Coastguard Worker   // fully, if that results in fragmenting large messages into quite small
166*d9f75844SAndroid Build Coastguard Worker   // packets. When the congestion window is smaller than this option, it will
167*d9f75844SAndroid Build Coastguard Worker   // aim to fill the congestion window as much as it can, even if it results in
168*d9f75844SAndroid Build Coastguard Worker   // creating small fragmented packets.
169*d9f75844SAndroid Build Coastguard Worker   size_t avoid_fragmentation_cwnd_mtus = 6;
170*d9f75844SAndroid Build Coastguard Worker 
171*d9f75844SAndroid Build Coastguard Worker   // The number of packets that may be sent at once. This is limited to avoid
172*d9f75844SAndroid Build Coastguard Worker   // bursts that too quickly fill the send buffer. Typically in a a socket in
173*d9f75844SAndroid Build Coastguard Worker   // its "slow start" phase (when it sends as much as it can), it will send
174*d9f75844SAndroid Build Coastguard Worker   // up to three packets for every SACK received, so the default limit is set
175*d9f75844SAndroid Build Coastguard Worker   // just above that, and then mostly applicable for (but not limited to) fast
176*d9f75844SAndroid Build Coastguard Worker   // retransmission scenarios.
177*d9f75844SAndroid Build Coastguard Worker   int max_burst = 4;
178*d9f75844SAndroid Build Coastguard Worker 
179*d9f75844SAndroid Build Coastguard Worker   // Maximum Data Retransmit Attempts (per DATA chunk). Set to absl::nullopt for
180*d9f75844SAndroid Build Coastguard Worker   // no limit.
181*d9f75844SAndroid Build Coastguard Worker   absl::optional<int> max_retransmissions = 10;
182*d9f75844SAndroid Build Coastguard Worker 
183*d9f75844SAndroid Build Coastguard Worker   // Max.Init.Retransmits (https://tools.ietf.org/html/rfc4960#section-15). Set
184*d9f75844SAndroid Build Coastguard Worker   // to absl::nullopt for no limit.
185*d9f75844SAndroid Build Coastguard Worker   absl::optional<int> max_init_retransmits = 8;
186*d9f75844SAndroid Build Coastguard Worker 
187*d9f75844SAndroid Build Coastguard Worker   // RFC3758 Partial Reliability Extension
188*d9f75844SAndroid Build Coastguard Worker   bool enable_partial_reliability = true;
189*d9f75844SAndroid Build Coastguard Worker 
190*d9f75844SAndroid Build Coastguard Worker   // RFC8260 Stream Schedulers and User Message Interleaving
191*d9f75844SAndroid Build Coastguard Worker   bool enable_message_interleaving = false;
192*d9f75844SAndroid Build Coastguard Worker 
193*d9f75844SAndroid Build Coastguard Worker   // If RTO should be added to heartbeat_interval
194*d9f75844SAndroid Build Coastguard Worker   bool heartbeat_interval_include_rtt = true;
195*d9f75844SAndroid Build Coastguard Worker 
196*d9f75844SAndroid Build Coastguard Worker   // Disables SCTP packet crc32 verification. Useful when running with fuzzers.
197*d9f75844SAndroid Build Coastguard Worker   bool disable_checksum_verification = false;
198*d9f75844SAndroid Build Coastguard Worker };
199*d9f75844SAndroid Build Coastguard Worker }  // namespace dcsctp
200*d9f75844SAndroid Build Coastguard Worker 
201*d9f75844SAndroid Build Coastguard Worker #endif  // NET_DCSCTP_PUBLIC_DCSCTP_OPTIONS_H_
202