1# SCTP user-land implementation (usrsctp)
2
3SCTP is a message oriented, reliable transport protocol with direct support for multihoming that runs on top of IP or UDP, and supports both v4 and v6 versions.
4
5Like TCP, SCTP provides reliable, connection oriented data delivery with congestion control. Unlike TCP, SCTP also provides message boundary preservation, ordered and unordered message delivery, multi-streaming and multi-homing. Detection of data corruption, loss of data and duplication of data is achieved by using checksums and sequence numbers. A selective retransmission mechanism is applied to correct loss or corruption of data.
6
7In this manual the socket API for the SCTP User-land implementation will be described.  It is based on [RFC 6458](https://tools.ietf.org/html/rfc6458). The main focus of this document is on pointing out the differences to the SCTP Sockets API. For all aspects of the sockets API that are not mentioned in this document, please refer to [RFC 6458](https://tools.ietf.org/html/rfc6458). Questions about SCTP itself can hopefully be answered by [RFC 4960](https://tools.ietf.org/html/rfc4960).
8
9## Getting Started
10The user-land stack has been tested on FreeBSD 10.0, Ubuntu 11.10, Windows 7, Mac OS X 10.6, and Mac OS X 10.7. The current version of the user-land stack is provided on [github](https://github.com/sctplab/usrsctp). Download the tarball and untar it in a folder of your choice. The tarball contains all the sources to build the libusrsctp, which has to be linked to the object file of an example program. In addition there are two applications in the folder `programs` that can be built and run.
11
12### Building the Library and the Applications
13#### Unix-like Operating Systems
14In the folder `usrsctp` type
15
16    $ ./bootstrap
17    $ ./configure
18    $ make
19
20Now, the library `libusrsctp.la` has been built in the subdirectory `usrsctplib`, and the example programs are ready to run from the subdirectory `programs`.
21
22If you have root privileges or are in the sudoer group, you can install the library in `/usr/local/lib` and copy the header file to `/usr/include` with the command
23
24    $ sudo make install
25
26#### Windows
27On Windows you need a compiler like Microsoft Visual Studio. You can build the library and the example programs with the command line tool of the compiler by typing
28
29    $ nmake -f Makefile.nmake
30
31in the directory `usrsctp`.
32
33#### CMake
34Create a directory outside the `usrsctp` directory, enter it and generate files by typing
35
36    $ cmake <path-to-usrsctp-sources>
37    $ cmake --build .
38
39By default CMake generates a DEBUG build with verbose output.
40
41### Running the Test Programs
42
43Several test programs are included, including a discard server and a client. You can run both to send data from the client to the server. The client reads data from stdin and sends them to the server, which prints the message in the terminal and discards it. The sources of the server are also provided [here](https://github.com/sctplab/usrsctp/blob/master/programs/discard_server.c) and those of the client [here](https://github.com/sctplab/usrsctp/blob/master/programs/client.c).
44
45### Using UDP Encapsulation
46
47Both programs can either send data over SCTP directly or use UDP encapsulation, thus encapsulating the SCTP packet in a UDP datagram. The first mode works on loopback or in a protected setup without any NAT boxes involved. In all other cases it is better to use UDP encapsulation.
48
49The usage of the `discard_server` is
50
51    $ discard_server [local_encaps_port remote_encaps_port]
52
53For UDP encapsulation the ports have to be specified. The local and remote encapsulation ports can be arbitrarily set. For example, you can call
54
55    $ ./discard_server 11111 22222
56
57on a Unix-like OS and
58
59    $ discard_server.exe 11111 22222
60
61on Windows.
62
63The client needs two additional parameters, the server's address and its port. Its usage is
64
65    $ client remote_addr remote_port [local_port local_encaps_port remote_encaps_port]
66
67The remote address is the server's address. If client and server are started on the same machine, the loopback address `127.0.0.1` can be used for Unix-like OSs and the local address on Windows. The discard port is 9, thus 9 has to be taken as remote port. The encapsulation ports have to match those of the server, i.e. the server's `local_encaps_port` is the client's `remote_encaps_port` and vice versa. Thus, the client can be started with
68
69    $ ./client 127.0.0.1 9 0 22222 11111
70
71on a Unix-like OS and
72
73    $ client.exe 192.168.0.1 9 0 22222 11111
74
75on Windows provided your local IP address is 192.168.0.1.
76
77### Sending over SCTP
78
79To send data over SCTP directly you might need root privileges because raw sockets are used. Thus instead of specifying the encapsulation ports you have to start the programs prepending `sudo` or in case of Windows start the program from an administrator console.
80
81### Using the Callback API
82
83Instead of asking constantly for new data, a callback API can be used that is triggered by SCTP. A callback function has to be registered that will be called whenever data is ready to be delivered to the application.
84
85The `discard_server` has a flag to switch between the two modi. If  `use_cb` is set to 1, the callback API will be used. To change the setting, just set the flag and compile the program again.
86
87
88## Basic Operations
89
90All system calls start with the prefix `usrsctp_` to distinguish them from the kernel variants. Some of them are changed to account for the different demands in the userland environment.
91
92## Differences to RFC 6458
93
94### usrsctp_init()
95
96Every application has to start with `usrsctp_init()`. This function calls `sctp_init()` and reserves the memory necessary to administer the data transfer. The function prototype is
97
98```c
99void usrsctp_init(uint16_t udp_port)
100```
101
102As it is not always possible to send data directly over SCTP because not all NAT boxes can process SCTP packets, the data can be sent over UDP. To encapsulate SCTP into UDP a UDP port has to be specified, to which the datagrams can be sent. This local UDP port  is set with the parameter `udp_port`. The default value is 9899, the standard UDP encapsulation port. If UDP encapsulation is not necessary, the UDP port has to be set to 0.
103
104### usrsctp_finish()
105
106At the end of the program `usrsctp_finish()` should be called to free all the memory that has been allocated before. The function prototype is
107
108```c
109int usrsctp_finish(void)
110```
111
112The return code is 0 on success and -1 in case of an error.
113
114### usrsctp_socket()
115
116A representation of an SCTP endpoint is a socket. Is it created with `usrsctp_socket()`. The function prototype is:
117
118```c
119struct socket *
120usrsctp_socket(int domain,
121               int type,
122               int protocol,
123               int (*receive_cb)(struct socket *sock,
124                                 union sctp_sockstore addr,
125                                 void *data,
126                                 size_t datalen,
127                                 struct sctp_rcvinfo,
128                                 int flags,
129                                 void *ulp_info),
130               int (*send_cb)(struct socket *sock,
131                              uint32_t sb_free),
132               uint32_t sb_threshold,
133               void *ulp_info)
134```
135
136The arguments taken from [RFC 6458](https://tools.ietf.org/html/rfc6458) are:
137
138* domain: PF_INET or PF_INET6 can be used.
139* type: In case of a one-to-many style socket it is SOCK_SEQPACKET, in case of a one-to-one style
140socket it is SOCK_STREAM. For an explanation of the differences between the socket types please
141refer to [RFC 6458](https://tools.ietf.org/html/rfc6458).
142* protocol: Set IPPROTO_SCTP.
143
144In usrsctp, a callback API can be used.
145
146* The function pointers of the receive and send callbacks are new arguments to the socket call. If no callback API is used, these must be `NULL`.
147* The `sb_threshold` specifies the amount of free space in the send socket buffer before the send function in the application is called. If a send callback function is specified and `sb_threshold` is 0, the function is called whenever there is room in the send socket buffer.
148* Additional data may be passed along within the `ulp_info` parameter. This value will be passed to the `receive_cb` when it is invoked.
149
150On success `usrsctp_socket()` returns the pointer to the new socket in the `struct socket` data type. It will be needed in all other system calls. In case of a failure NULL is returned and errno is set to the appropriate error code.
151
152### usrsctp_close()
153
154The function prototype of `usrsctp_close()` is
155
156```c
157void usrsctp_close(struct socket *so)
158 ```
159Thus the only difference is the absence of a return code.
160
161## Same Functionality as RFC 6458
162
163The following functions have the same functionality as their kernel pendants. There prototypes
164are described in the following subsections. For a detailed description please refer to [RFC 6458](https://tools.ietf.org/html/rfc6458).
165
166### usrsctp_bind()
167
168```c
169int
170usrsctp_bind(struct socket *so,
171             struct sockaddr *addr,
172             socklen_t addrlen)
173```
174
175* so: Pointer to the socket as returned by `usrsctp_socket()`.
176* addr: The address structure (`struct sockaddr_in` for an IPv4 address or `struct sockaddr_in6` for an IPv6 address).
177* addrlen: The size of the address structure.
178
179`usrsctp_bind()` returns 0 on success and -1 in case of an error.
180
181### usrsctp_listen()
182
183```c
184int
185usrsctp_listen(struct socket *so,
186               int backlog)
187```
188
189* so: Pointer to the socket as returned by `usrsctp_socket()`.
190* backlog: If backlog is non-zero, enable listening, else disable listening.
191
192`usrsctp_listen()` returns 0 on success and -1 in case of an error.
193
194### usrsctp_accept()
195
196```c
197struct socket *
198usrsctp_accept(struct socket *so,
199               struct sockaddr * addr,
200               socklen_t * addrlen)
201```
202
203* so: Pointer to the socket as returned by `usrsctp_socket()`.
204* addr: On return,  the primary address of the peer (`struct sockaddr_in` for an IPv4 address or `struct sockaddr_in6` for an IPv6 address).
205* addrlen: Size of the returned address structure.
206
207`usrsctp_accept()` returns the accepted socket on success and NULL in case of an error.
208
209### usrsctp_connect()
210
211```c
212int
213usrsctp_connect(struct socket *so,
214                struct sockaddr *name,
215                socklen_t addrlen)
216```
217
218* so: Pointer to the socket as returned by `usrsctp_socket()`.
219* name: Address of the peer to connect to (`struct sockaddr_in` for an IPv4 address or `struct sockaddr_in6` for an IPv6 address).
220* addrlen: Size of the peer's address.
221
222`usrsctp_connect()` returns 0 on success and -1 in case of an error.
223
224### usrsctp_shutdown()
225
226```c
227int
228usrsctp_shutdown(struct socket *so, int how)
229```
230
231* so: Pointer to the socket of the association to be closed
232* how: Specifies the type of shutdown.  The values are as follows:
233  * SHUT_RD:  Disables further receive operations.  No SCTP protocol action is taken.
234  * SHUT_WR:  Disables further send operations, and initiates the SCTP shutdown sequence.
235  * SHUT_RDWR:  Disables further send and receive operations, and initiates the SCTP shutdown sequence.
236
237`usrsctp_shutdown()` returns 0 on success and -1 in case of an error.
238
239## Sending and Receiving Data
240Since the publication of [RFC 6458](https://tools.ietf.org/html/rfc6458) there is only one function for sending and one for receiving
241that is not deprecated. Therefore, only these two are described here.
242
243### usrsctp_sendv()
244
245```c
246ssize_t
247usrsctp_sendv(struct socket *so,
248              const void *data,
249              size_t len,
250              struct sockaddr *addrs,
251              int addrcnt,
252              void *info,
253              socklen_t infolen,
254              unsigned int infotype,
255              int flags)
256```
257
258* so: The socket to send data on.
259* data: As it is more convenient to send data in a buffer and not a `struct iovec` data structure, we chose to pass the data as a void pointer.
260* len: Length of the data.
261* addrs: In this version of usrsctp at most one destination address is supported. In the case of a connected socket, the parameter `addrs` can be set to NULL.
262* addrcnt: Number of addresses. As at most one address is supported, addrcnt is 0 if addrs is NULL and 1 otherwise.
263* info: Additional information for a message is stored in `void *info`. The data types `struct sctp_sndinfo`, `struct sctp_prinfo`, and `struct sctp_sendv_spa` are supported as defined in [RFC 6458](https://tools.ietf.org/html/rfc6458). Support for `struct sctp_authinfo` is not implemented yet, therefore, errno is set EINVAL and -1 will be returned, if it is used.
264* infolen: Length of info in bytes.
265* infotype: Identifies the type of the information provided in info. Possible values are
266  * SCTP_SENDV_NOINFO
267  * SCTP_SENDV_SNDINFO
268  * SCTP_SENDV_PRINFO
269  * SCTP_SENDV_SPA (For additional information please refer to [RFC 6458](https://tools.ietf.org/html/rfc6458).)
270* flags: Flags as described in [RFC 6458](https://tools.ietf.org/html/rfc6458).
271
272`usrsctp_sendv()` returns the number of bytes sent, or -1 if an error occurred.  The variable errno is then set appropriately.
273
274### usrsctp_recvv()
275
276```c
277ssize_t
278usrsctp_recvv(struct socket *so,
279             void *dbuf,
280             size_t len,
281             struct sockaddr *from,
282             socklen_t * fromlen,
283             void *info,
284             socklen_t *infolen,
285             unsigned int *infotype,
286             int *msg_flags)
287```
288
289* so: The socket to receive data on.
290* dbuf: Analog to `usrsctp_sendv()` the data is returned in a buffer.
291* len: Length of the buffer in bytes.
292* from: A pointer to an address to be filled with the sender of the received message's address.
293* fromlen: An in/out parameter describing the from length.
294* info: A pointer to the buffer to hold the attributes of the received message.  The structure type of info is determined by the infotype parameter. The attributes returned in `info` have to be handled in the same way as specified in [RFC 6458](https://tools.ietf.org/html/rfc6458).
295* infolen:  An in/out parameter describing the size of the info buffer.
296* infotype:  On return, `*infotype` is set to the type of the info buffer.  The current defined values are
297  * SCTP_RECVV_NOINFO
298  * SCTP_RECVV_RCVINFO
299  * SCTP_RECVV_NXTINFO
300  * SCTP_RECVV_RN (A detailed description is given in [RFC 6458](https://tools.ietf.org/html/rfc6458))
301* flags: A pointer to an integer to be filled with any message flags (e.g., `MSG_NOTIFICATION`).  Note that this field is an in/out parameter.  Options for the receive may also be passed into the value (e.g., `MSG_EOR`).  Returning from the call, the flags' value will differ from its original value.
302
303`usrsctp_recvv()` returns the number of bytes received, or -1 if an error occurred.  The variable errno is then set appropriately.
304
305## Socket Options
306Socket options are used to change the default behavior of socket calls.
307Their behavior is specified in [RFC 6458](https://tools.ietf.org/html/rfc6458). The functions to get or set them are
308
309```c
310int
311usrsctp_getsockopt(struct socket *so,
312                     int level,
313                     int optname,
314                     void *optval,
315                     socklen_t *optlen)
316```
317and
318```c
319int
320usrsctp_setsockopt(struct socket *so,
321                     int level,
322                     int optname,
323                     const void *optval,
324                     socklen_t optlen)
325```
326
327and the arguments are
328* so:  The socket of type struct socket.
329* level:  Set to IPPROTO_SCTP for all SCTP options.
330* optname:  The option name as specified in The Socket Options table below.
331* optval: The buffer to store the value of the option as specified in the second column of Socket Options below.
332* optlen:  The size of the buffer (or the length of the option returned in case of `usrsctp_getsockopt`).
333
334These functions return 0 on success and -1 in case of an error.
335
336### Socket Options supported by usrsctp
337
338Option | Datatype | r/w
339------ | -------- | ----
340SCTP_RTOINFO | struct sctp_rtoinfo | r/w
341SCTP_ASSOCINFO | struct sctp_assocparams | r/w
342SCTP_INITMSG | struct sctp_initmsg | r/w
343SCTP_NODELAY | int | r/w
344SCTP_AUTOCLOSE | int | r/w
345SCTP_PRIMARY_ADDR | struct sctp_setprim | r/w
346SCTP_ADAPTATION_LAYER | struct sctp_setadaptation | r/w
347SCTP_DISABLE_FRAGMENTS | int | r/w
348SCTP_PEER_ADDR_PARAMS | struct sctp_paddrparams | r/w
349SCTP_I_WANT_MAPPED_V4_ADDR | int | r/w
350SCTP_MAXSEG | struct sctp_assoc_value | r/w
351SCTP_DELAYED_SACK | struct sctp_sack_info | r/w
352SCTP_FRAGMENT_INTERLEAVE | int | r/w
353SCTP_PARTIAL_DELIVERY_POINT | int | r/w
354SCTP_HMAC_IDENT | struct sctp_hmacalgo | r/w
355SCTP_AUTH_ACTIVE_KEY | struct sctp_authkeyid | r/w
356SCTP_AUTO_ASCONF | int | r/w
357SCTP_MAX_BURST | struct sctp_assoc_value | r/w
358SCTP_CONTEXT | struct sctp_assoc_value | r/w
359SCTP_EXPLICIT_EOR | int | r/w
360SCTP_REUSE_PORT | int | r/w
361SCTP_EVENT | struct sctp_event | r/w
362SCTP_RECVRCVINFO | int | r/w
363SCTP_RECVNXTINFO | int | r/w
364SCTP_DEFAULT_SNDINFO | struct sctp_sndinfo | r/w
365SCTP_DEFAULT_PRINFO | struct sctp_default_prinfo | r/w
366SCTP_REMOTE_UDP_ENCAPS_PORT | int | r/w
367SCTP_ENABLE_STREAM_RESET | struct sctp_assoc_value | r/w
368SCTP_STATUS | struct sctp_status | r
369SCTP_GET_PEER_ADDR_INFO | struct sctp_paddrinfo | r
370SCTP_PEER_AUTH_CHUNKS | struct sctp_authchunks | r
371SCTP_LOCAL_AUTH_CHUNKS | struct sctp_authchunks | r
372SCTP_GET_ASSOC_NUMBER | uint32_t | r
373SCTP_GET_ASSOC_ID_LIST | struct sctp_assoc_ids | r
374SCTP_RESET_STREAMS | struct sctp_reset_streams | w
375SCTP_RESET_ASSOC | struct sctp_assoc_t | w
376SCTP_ADD_STREAMS | struct sctp_add_streams | w
377
378Further usage details are described in [RFC 6458](https://tools.ietf.org/html/rfc6458), [RFC 6525](https://tools.ietf.org/html/rfc6525), and [draft-ietf-tsvwg-sctp-udp-encaps-03](https://tools.ietf.org/html/draft-ietf-tsvwg-sctp-udp-encaps-03) (work in progress).
379
380## Sysctl variables
381
382In kernel implementations like for instance FreeBSD, it is possible to change parameters in the operating system. These parameters are called sysctl variables.
383
384In usrsctp applications can set or retrieve these variables with the functions
385```c
386void usrsctp_sysctl_set_ ## (uint32_t value)
387```
388and
389```c
390uint32_t usrsctp_sysctl_get_ ## (void)
391```
392respectively, where `##` stands for the name of the variable.
393
394In the following paragraphs a short description of the parameters will be given.
395
396## Manipulate Memory
397#### usrsctp_sysctl_set_sctp_sendspace()
398The space of the available send buffer can be changed from its default value of 262,144 bytes to a value between 0 and `2^32 - 1` bytes.
399
400#### usrsctp_sysctl_set_sctp_recvspace()
401The space of the available receive buffer can be changed from its default value of 262,144 bytes to a value between 0 and `2^32 - 1` bytes.
402
403#### usrsctp_sysctl_set_sctp_hashtblsize()
404The TCB (Thread Control Block) hash table sizes, i.e. the size of one TCB in the hash table, can be tuned between 1 and `2^32 - 1` bytes. The default value is 1,024 bytes. A TCB contains for instance pointers to the socket, the endpoint, information about the association and some statistic data.
405
406#### usrsctp_sysctl_set_sctp_pcbtblsize()
407The PCB (Protocol Control Block) hash table sizes, i.e. the size of one PCB in the hash table, can be tuned between 1 and `2^32 - 1` bytes. The default value is 256 bytes. The PCB contains all variables that characterize an endpoint.
408
409#### usrsctp_sysctl_set_sctp_system_free_resc_limit()
410This parameters tunes the maximum number of cached resources in the system. It can be set between 0 and `2^32 - 1`. The default value is 1000.
411
412#### usrsctp_sysctl_set_sctp_asoc_free_resc_limit()
413This parameters tunes the maximum number of cached resources in an association. It can be set between 0 and `2^32 - 1`. The default value is 10.
414
415#### usrsctp_sysctl_set_sctp_mbuf_threshold_count()
416Data is stored in mbufs. Several mbufs can be chained together. The maximum number of small mbufs in a chain can be set with this parameter, before an mbuf cluset is used. The default is 5.
417
418#### usrsctp_sysctl_set_sctp_add_more_threshold()
419TBD
420This parameter configures the threshold below which more space should be added to a socket send buffer. The default value is 1452 bytes.
421
422
423## Configure RTO
424The retransmission timeout (RTO), i.e. the time that controls the retransmission of messages, has several parameters, that can be changed, for example to shorten the time, before a message is retransmitted. The range of these parameters is between 0 and `2^32 - 1`ms.
425
426#### usrsctp_sysctl_set_sctp_rto_max_default()
427The default value for the maximum retransmission timeout in ms is 60,000 (60secs).
428
429#### usrsctp_sysctl_set_sctp_rto_min_default()
430The default value for the minimum retransmission timeout in ms is 1,000 (1sec).
431
432#### usrsctp_sysctl_set_sctp_rto_initial_default()
433The default value for the initial retransmission timeout in ms is 3,000 (3sec). This value is only needed before the first calculation of a round trip time took place.
434
435#### usrsctp_sysctl_set_sctp_init_rto_max_default()
436The default value for the maximum retransmission timeout for an INIT chunk in ms is 60,000 (60secs).
437
438
439## Set Timers
440#### usrsctp_sysctl_set_sctp_valid_cookie_life_default()
441A cookie has a specified life time. If it expires the cookie is not valid any more and an ABORT is sent. The default value in ms is 60,000 (60secs).
442
443#### usrsctp_sysctl_set_sctp_heartbeat_interval_default()
444Set the default time between two heartbeats. The default is 30,000ms.
445
446#### usrsctp_sysctl_set_sctp_shutdown_guard_time_default()
447If a SHUTDOWN is not answered with a SHUTDOWN-ACK while the shutdown guard timer is still running, the association will be aborted after the default of 180secs.
448
449#### usrsctp_sysctl_set_sctp_pmtu_raise_time_default()
450TBD
451To set the size of the packets to the highest value possible, the maximum transfer unit (MTU) of the complete path has to be known. The default time interval for the path mtu discovery is 600secs.
452
453#### usrsctp_sysctl_set_sctp_secret_lifetime_default()
454TBD
455The default secret lifetime of a server is 3600secs.
456
457#### usrsctp_sysctl_set_sctp_vtag_time_wait()
458TBD
459Vtag time wait time, 0 disables it. Default: 60secs
460
461
462## Set Failure Limits
463Transmissions and retransmissions of messages might fail. To protect the system against too many retransmissions, limits have to be defined.
464
465#### usrsctp_sysctl_set_sctp_init_rtx_max_default()
466The default maximum number of retransmissions of an INIT chunks is 8, before an ABORT is sent.
467
468#### usrsctp_sysctl_set_sctp_assoc_rtx_max_default()
469This parameter sets the maximum number of failed retransmissions before the association is aborted. The default value is 10.
470
471#### usrsctp_sysctl_set_sctp_path_rtx_max_default()
472This parameter sets the maximum number of path failures before the association is aborted. The default value is 5. Notice that the number of paths multiplied by this value should be equal to `sctp_assoc_rtx_max_default`. That means that the default configuration is good for two paths.
473
474#### usrsctp_sysctl_set_sctp_max_retran_chunk()
475The parameter configures how many times an unlucky chunk can be retransmitted before the association aborts. The default is set to 30.
476
477#### usrsctp_sysctl_set_sctp_path_pf_threshold()
478TBD
479Default potentially failed threshold. Default: 65535
480
481#### usrsctp_sysctl_set_sctp_abort_if_one_2_one_hits_limit()
482TBD
483When one-2-one hits qlimit abort. Default: 0
484
485
486## Control the Sending of SACKs
487#### usrsctp_sysctl_set_sctp_sack_freq_default()
488The SACK frequency defines the number of packets that are awaited, before a SACK is sent. The default value is 2.
489
490#### usrsctp_sysctl_set_sctp_delayed_sack_time_default()
491As a SACK (Selective Acknowlegment) is sent after every other packet, a timer is set to send a SACK in case another packet does not arrive in due time. The default value for this timer is 200ms.
492
493#### usrsctp_sysctl_set_sctp_strict_sacks()
494TBD
495This is a flag to turn the controlling of the coherence of SACKs on or off. The default value is 1 (on).
496
497#### usrsctp_sysctl_set_sctp_nr_sack_on_off()
498If a slow hosts receives data on a lossy link it is possible that its receiver window is full and new data can only be accepted if one chunk with a higher TSN (Transmission Sequence Number) that has previously been acknowledged is dropped. As a consequence the sender has to store data, even if they have been acknowledged in case they have to be retransmitted. If this behavior is not necessary, non-renegable SACKs can be turned on. By default the use of non-renegable SACKs is turned off.
499
500#### usrsctp_sysctl_set_sctp_enable_sack_immediately()
501In some cases it is not desirable to wait for the SACK timer to expire before a SACK is sent. In these cases a bit called SACK-IMMEDIATELY (see [draft-tuexen-tsvwg-sctp-sack-immediately-09](https://tools.ietf.org/html/draft-tuexen-tsvwg-sctp-sack-immediately-09)) can be set to provoke the instant sending of a SACK. The default is to turn it off.
502
503#### usrsctp_sysctl_set_sctp_L2_abc_variable()
504TBD
505SCTP ABC max increase per SACK (L). Default: 1
506
507## Change Max Burst
508Max burst defines the maximum number of packets that may be sent in one flight.
509
510#### usrsctp_sysctl_set_sctp_max_burst_default()
511The default value for max burst is 0, which means that the number of packets sent as a flight is not limited by this parameter, but may be by another one, see the next paragraph.
512
513#### usrsctp_sysctl_set_sctp_use_cwnd_based_maxburst()
514The use of max burst is based on the size of the congestion window (cwnd). This parameter is set by default.
515
516#### usrsctp_sysctl_set_sctp_hb_maxburst()
517Heartbeats are mostly used to verify a path. Their number can be limited. The default is 4.
518
519#### usrsctp_sysctl_set_sctp_fr_max_burst_default()
520In the state of fast retransmission the number of packet bursts can be limited. The default value is 4.
521
522
523## Handle Chunks
524#### usrsctp_sysctl_set_sctp_peer_chunk_oh()
525In order to keep track of the peer's advertised receiver window, the sender calculates the window by subtracting the amount of data sent. Yet, some OSs reduce the receiver window by the real space needed to store the data. This parameter sets the additional amount to debit the peer's receiver window per chunk sent. The default value is 256, which is the value needed by FreeBSD.
526
527#### usrsctp_sysctl_set_sctp_max_chunks_on_queue()
528This parameter sets the maximum number of chunks that can be queued per association. The default value is 512.
529
530#### usrsctp_sysctl_set_sctp_min_split_point()
531TBD
532The minimum size when splitting a chunk is 2904 bytes by default.
533
534#### usrsctp_sysctl_set_sctp_chunkscale()
535TBD
536This parameter can be tuned for scaling of number of chunks and messages. The default is10.
537
538#### usrsctp_sysctl_set_sctp_min_residual()
539TBD
540This parameter configures the minimum size of the residual data chunk in the second part of the split. The default is 1452.
541
542
543## Calculate RTT
544The calculation of the round trip time (RTT) depends on several parameters.
545
546#### usrsctp_sysctl_set_sctp_rttvar_bw()
547TBD
548Shift amount for bw smoothing on rtt calc. Default: 4
549
550#### usrsctp_sysctl_set_sctp_rttvar_rtt()
551TBD
552Shift amount for rtt smoothing on rtt calc. Default: 5
553
554#### usrsctp_sysctl_set_sctp_rttvar_eqret()
555TBD
556What to return when rtt and bw are unchanged. Default: 0
557
558
559## Influence the Congestion Control
560The congestion control should protect the network against fast senders.
561
562#### usrsctp_sysctl_set_sctp_ecn_enable
563Explicit congestion notifications are turned on by default.
564
565#### usrsctp_sysctl_set_sctp_default_cc_module()
566This parameter sets the default algorithm for the congestion control. Default is 0, i.e. the one specified in [RFC 4960](https://tools.ietf.org/html/rfc4960).
567
568#### usrsctp_sysctl_set_sctp_initial_cwnd()
569Set the initial congestion window in MTUs. The default is 3.
570
571#### usrsctp_sysctl_set_sctp_use_dccc_ecn()
572TBD
573Enable for RTCC CC datacenter ECN. Default: 1
574
575#### usrsctp_sysctl_set_sctp_steady_step()
576TBD
577How many the sames it takes to try step down of cwnd. Default: 20
578
579
580## Configure AUTH and ADD-IP
581An important extension of SCTP is the dynamic address reconfiguration (see [RFC 5061](https://tools.ietf.org/html/rfc5061)), also known as ADD-IP, which allows the changing of addresses during the lifetime of an association. For this feature the AUTH extension (see [RFC 4895](https://tools.ietf.org/html/rfc4895)) is necessary.
582
583#### usrsctp_sysctl_set_sctp_auto_asconf()
584If SCTP Auto-ASCONF is enabled, the peer is informed automatically when a new address
585is added or removed. This feature is enabled by default.
586
587#### usrsctp_sysctl_set_sctp_multiple_asconfs()
588By default the sending of multiple ASCONFs is disabled.
589
590#### usrsctp_sysctl_set_sctp_auth_enable()
591The use of AUTH, which is normally turned on, can be disabled by setting this parameter to 0.
592
593#### usrsctp_sysctl_set_sctp_asconf_auth_nochk()
594It is also possible to disable the requirement to use AUTH in conjunction with ADD-IP by setting this parameter
595to 1.
596
597
598## Concurrent Multipath Transfer (CMT)
599A prominent feature of SCTP is the possibility to use several addresses for the same association. One is the primary path, and the others are needed in case of a path failure. Using CMT the data is sent on several paths to enhance the throughput.
600
601#### usrsctp_sysctl_set_sctp_cmt_on_off()
602To turn CMT on, this parameter has to be set to 1.
603
604#### usrsctp_sysctl_set_sctp_cmt_use_dac()
605To use delayed acknowledgments with CMT this parameter has to be set to 1.
606
607#### usrsctp_sysctl_set_sctp_buffer_splitting()
608For CMT it makes sense to split the send and receive buffer to have shares for each path. By default buffer splitting is turned off.
609
610
611## Network Address Translation (NAT)
612To be able to pass NAT boxes, the boxes have to handle SCTP packets in a specific way.
613
614#### usrsctp_sysctl_set_sctp_nat_friendly()
615SCTP NAT friendly operation. Default:1
616
617#### usrsctp_sysctl_set_sctp_inits_include_nat_friendly()
618Enable sending of the nat-friendly SCTP option on INITs. Default: 0
619
620#### usrsctp_sysctl_set_sctp_udp_tunneling_port()
621Set the SCTP/UDP tunneling port. Default: 9899
622
623## SCTP Mobility
624#### usrsctp_sysctl_set_sctp_mobility_base()
625TBD
626Enable SCTP base mobility. Default: 0
627
628
629#### usrsctp_sysctl_set_sctp_mobility_fasthandoff()
630TBD
631Enable SCTP fast handoff. default: 0
632
633
634## Miscellaneous
635#### usrsctp_sysctl_set_sctp_no_csum_on_loopback()
636Calculating the checksum for packets sent on loopback is turned off by default. To turn it on, set this parameter to 0.
637
638#### usrsctp_sysctl_set_sctp_nr_outgoing_streams_default()
639The peer is notified about the number of outgoing streams in the INIT or INIT-ACK chunk. The default is 10.
640
641#### usrsctp_sysctl_set_sctp_do_drain()
642Determines whether SCTP should respond to the drain calls. Default: 1
643
644#### usrsctp_sysctl_set_sctp_strict_data_order()
645TBD
646Enforce strict data ordering, abort if control inside data. Default: 0
647
648#### usrsctp_sysctl_set_sctp_default_ss_module()
649Set the default stream scheduling module. Implemented modules are:
650* SCTP_SS_DEFAULT
651* SCTP_SS_ROUND_ROBIN
652* SCTP_SS_ROUND_ROBIN_PACKET
653* SCTP_SS_PRIORITY
654* SCTP_SS_FAIR_BANDWITH
655* SCTP_SS_FIRST_COME
656
657#### usrsctp_sysctl_set_sctp_default_frag_interleave()
658TBD
659Default fragment interleave level. Default: 1
660
661#### usrsctp_sysctl_set_sctp_blackhole()
662TBD
663Enable SCTP blackholing. Default: 0
664
665#### usrsctp_sysctl_set_sctp_logging_level()
666Set the logging level. The default is 0.
667
668#### usrsctp_sysctl_set_sctp_debug_on()
669Turn debug output on or off. It is disabled by default. To obtain debug output, `SCTP_DEBUG` has to be set as a compile flag.
670
671
672### sysctl variables supported by usrsctp
673
674Parameter | Meaning | Default Value
675--------- | ------- | -------------
676sctp_sendspace | Send buffer space | 1864135
677sctp_recvspace | Receive buffer space | 1864135
678sctp_hashtblsize | Tunable for TCB hash table sizes | 1024
679sctp_pcbtblsize | Tunable for PCB hash table sizes | 256
680sctp_system_free_resc_limit | Cached resources in the system | 1000
681sctp_asoc_free_resc_limit | Cashed resources in an association | 10
682sctp_rto_max_default | Default value for RTO_max | 60000ms
683sctp_rto_min_default | Default value for RTO_min | 1000ms
684sctp_rto_initial_default | Default value for RTO_initial | 3000ms
685sctp_init_rto_max_default | Default value for the maximum RTO for sending an INIT | 60000ms
686sctp_valid_cookie_life_default | Valid cookie life time | 60000ms
687sctp_init_rtx_max_default | Maximum number of INIT retransmissions | 8
688sctp_assoc_rtx_max_default | Maximum number of failed retransmissions before the association is aborted | 10
689sctp_path_rtx_max_default | Maximum number of failed retransmissions before a path fails | 5
690sctp_ecn_enable | Enabling explicit congestion notifications | 1
691sctp_strict_sacks | Control the coherence of SACKs | 1
692sctp_delayed_sack_time_default | Default delayed SACK timer | 200ms
693sctp_sack_freq_default | Default SACK frequency | 2
694sctp_nr_sack_on_off | Turn non-renegable SACKs on or off | 0
695sctp_enable_sack_immediately | Enable sending of the SACK-IMMEDIATELY bit | 0
696sctp_no_csum_on_loopback | Enable the compilation of the checksum on packets sent on loopback | 1
697sctp_peer_chunk_oh | Amount to debit peers rwnd per chunk sent | 256
698sctp_max_burst_default | Default max burst for SCTP endpoints | 0
699sctp_use_cwnd_based_maxburst | Use max burst based on the size of the congestion window | 1
700sctp_hb_maxburst | Confirmation Heartbeat max burst | 4
701sctp_max_chunks_on_queue | Default max chunks on queue per asoc | 512
702sctp_min_split_point | Minimum size when splitting a chunk | 2904
703sctp_chunkscale | Tunable for Scaling of number of chunks and messages | 10
704sctp_mbuf_threshold_count | Maximum number of small mbufs in a chain | 5
705sctp_heartbeat_interval_default | Deafult time between two Heartbeats | 30000ms
706sctp_pmtu_raise_time_default | Default PMTU raise timer | 600secs
707sctp_shutdown_guard_time_default | Default shutdown guard timer | 180secs
708sctp_secret_lifetime_default | Default secret lifetime | 3600secs
709sctp_add_more_threshold | Threshold when more space should be added to a socket send buffer | 1452
710sctp_nr_outgoing_streams_default | Default number of outgoing streams | 10
711sctp_cmt_on_off | Turn CMT on or off. | 0
712sctp_cmt_use_dac | Use delayed acknowledgment for CMT | 0
713sctp_fr_max_burst_default | Default max burst for SCTP endpoints when fast retransmitting | 4
714sctp_auto_asconf | Enable SCTP Auto-ASCONF | 1
715sctp_multiple_asconfs | Enable SCTP Muliple-ASCONFs | 0
716sctp_asconf_auth_nochk | Disable SCTP ASCONF AUTH requirement | 0
717sctp_auth_disable | Disable SCTP AUTH function | 0
718sctp_nat_friendly | SCTP NAT friendly operation | 1
719sctp_inits_include_nat_friendly | Enable sending of the nat-friendly SCTP option on INITs. | 0
720sctp_udp_tunneling_port | Set the SCTP/UDP tunneling port | 9899
721sctp_do_drain | Determines whether SCTP should respond to the drain calls | 1
722sctp_abort_if_one_2_one_hits_limit | When one-2-one hits qlimit abort | 0
723sctp_strict_data_order | Enforce strict data ordering, abort if control inside data | 0
724sctp_min_residual | Minimum residual data chunk in second part of split | 1452
725sctp_max_retran_chunk | Maximum times an unlucky chunk can be retransmitted before the association aborts | 30
726sctp_default_cc_module | Default congestion control module | 0
727sctp_default_ss_module | Default stream scheduling module | 0
728sctp_default_frag_interleave | Default fragment interleave level | 1
729sctp_mobility_base | Enable SCTP base mobility | 0
730sctp_mobility_fasthandoff | Enable SCTP fast handoff | 0
731sctp_L2_abc_variable | SCTP ABC max increase per SACK (L) | 1
732sctp_vtag_time_wait | Vtag time wait time, 0 disables it. | 60secs
733sctp_blackhole | Enable SCTP blackholing | 0
734sctp_path_pf_threshold | Default potentially failed threshold | 65535
735sctp_rttvar_bw | Shift amount for bw smoothing on rtt calc | 4
736sctp_rttvar_rtt | Shift amount for rtt smoothing on rtt calc | 5
737sctp_rttvar_eqret  | What to return when rtt and bw are unchanged | 0
738sctp_steady_step | How many the sames it takes to try step down of cwnd | 20
739sctp_use_dccc_ecn | Enable for RTCC CC datacenter ECN | 1
740sctp_buffer_splitting | Enable send/receive buffer splitting | 0
741sctp_initial_cwnd | Initial congestion window in MTUs | 3
742sctp_logging_level | Logging level | 0
743sctp_debug_on | Turns debug output on or off. | 0
744
745## Examples
746
747See https://github.com/sctplab/usrsctp/tree/master/programs
748
749
750## References
751
752#### SCTP
753R. Stewart:</br>
754`Stream Control Transmission Protocol`.</br>
755[RFC 4960](https://tools.ietf.org/html/rfc4960), September 2007.
756
757#### auth
758M. Tüxen, R. Stewart, P. Lei, and E. Rescorla:</br>
759`Authenticated Chunks for the Stream Control Transmission Protocol (SCTP)`.</br>
760[RFC 4895](https://tools.ietf.org/html/rfc4895), August 2007.
761
762#### addip
763R. Stewart, Q. Xie, M. Tüxen, S. Maruyama, and M. Kozuka:</br>
764`Stream Control Transmission Protocol (SCTP) Dynamic Address Reconfiguration`.</br>
765[RFC 5061](https://tools.ietf.org/html/rfc5061), September 2007.
766
767#### socketAPI
768R. Stewart, M. Tüxen, K. Poon, and V. Yasevich:</br>
769`Sockets API Extensions for the Stream Control Transmission Protocol (SCTP)`.</br>
770[RFC 6458](https://tools.ietf.org/html/rfc6458), Dezember 2011.
771
772#### streamReset
773R. Stewart, M. Tüxen, and P. Lei:</br>
774`Stream Control Transmission Protocol (SCTP) Stream Reconfiguration`.</br>
775[RFC 6525](https://tools.ietf.org/html/rfc6525), February 2012.
776
777#### udpencaps
778M. Tüxen and R. Stewart</br>
779`UDP Encapsulation of Stream Control Transmission Protocol (SCTP) Packets for End-Host to End-Host Communication`</br>
780[RFC 6951](https://tools.ietf.org/html/rfc6951), May 2013.
781
782#### sack-imm
783M. Tüxen, I. Rüngeler, and R. Stewart:</br>
784`SACK-IMMEDIATELY Extension for the Stream Control Transmission Protocol`</br>
785[RFC 7053](https://tools.ietf.org/html/rfc7053), November 2013.
786