Usrsctp - Manual - MD at Master Sctplab - Usrsctp GitHub
Usrsctp - Manual - MD at Master Sctplab - Usrsctp GitHub
master
usrsctp / Manual.md
6 contributors
Raw Blame
Like 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.
In this manual the socket API for the SCTP User-land implementation will be described.
It is based on RFC 6458. 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. Questions about SCTP itself can
hopefully be answered by RFC 4960.
Getting Started
The 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. 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.
$ ./bootstrap
$ ./configure
$ make
Now, the library libusrsctp.la has been built in the subdirectory usrsctplib , and the
example programs are ready to run from the subdirectory programs .
If 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
Windows
On 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
$ nmake -f Makefile.nmake
CMake
Create a directory outside the usrsctp directory, enter it and generate files by typing
$ cmake <path-to-usrsctp-sources>
$ cmake --build .
For UDP encapsulation the ports have to be specified. The local and remote
encapsulation ports can be arbitrarily set. For example, you can call
on a Unix-like OS and
on Windows.
The client needs two additional parameters, the server's address and its port. Its usage
is
The 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
The 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.
Basic Operations
All 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.
usrsctp_init()
Every 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
usrsctp_finish()
At the end of the program usrsctp_finish() should be called to free all the memory
that has been allocated before. The function prototype is
int usrsctp_finish(void)
usrsctp_socket()
A representation of an SCTP endpoint is a socket. Is it created with usrsctp_socket() .
The function prototype is:
struct socket *
usrsctp_socket(int domain,
inttype,
intprotocol,
int(*receive_cb)(struct socket *sock,
union sctp_sockstore addr,
void *data,
size_t datalen,
struct sctp_rcvinfo,
int flags,
void *ulp_info),
int (*send_cb)(struct socket *sock,
uint32_t sb_free,
void *ulp_info),
uint32_t sb_threshold,
void *ulp_info)
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 .
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.
Additional data may be passed along within the ulp_info parameter. This value
will be passed to the receive_cb when it is invoked.
On 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.
usrsctp_close()
The function prototype of usrsctp_close() is
usrsctp_bind()
int
usrsctp_bind(struct socket *so,
struct sockaddr *addr,
socklen_t addrlen)
int
usrsctp_listen(struct socket *so,
int backlog)
usrsctp_accept()
struct socket *
usrsctp_accept(struct socket *so,
struct sockaddr * addr,
socklen_t * addrlen)
usrsctp_accept() returns the accepted socket on success and NULL in case of an error.
usrsctp_connect()
int
usrsctp_connect(struct socket *so,
struct sockaddr *name,
socklen_t addrlen)
usrsctp_shutdown()
int
usrsctp_shutdown(struct socket *so, int how)
so: Pointer to the socket of the association to be closed
how: Specifies the type of shutdown. The values are as follows:
SHUT_RD: Disables further receive operations. No SCTP protocol action is
taken.
SHUT_WR: Disables further send operations, and initiates the SCTP shutdown
sequence.
SHUT_RDWR: Disables further send and receive operations, and initiates the
SCTP shutdown sequence.
usrsctp_sendv()
ssize_t
usrsctp_sendv(struct socket *so,
const void *data,
size_t len,
struct sockaddr *addrs,
int addrcnt,
void *info,
socklen_t infolen,
unsigned int infotype,
int flags)
usrsctp_recvv()
ssize_t
usrsctp_recvv(struct socket *so,
void *dbuf,
size_t len,
struct sockaddr *from,
socklen_t * fromlen,
void *info,
socklen_t *infolen,
unsigned int *infotype,
int *msg_flags)
Socket Options
Socket options are used to change the default behavior of socket calls. Their behavior is
specified in RFC 6458. The functions to get or set them are
int
usrsctp_getsockopt(struct socket *so,
int level,
int optname,
void *optval,
socklen_t *optlen)
and
int
usrsctp_setsockopt(struct socket *so,
int level,
int optname,
const void *optval,
socklen_t optlen)
SCTP_GET_ASSOC_NUMBER uint32_t r
Further usage details are described in RFC 6458, RFC 6525, and draft-ietf-tsvwg-sctp-
udp-encaps-03 (work in progress).
Sysctl variables
In kernel implementations like for instance FreeBSD, it is possible to change parameters
in the operating system. These parameters are called sysctl variables.
In usrsctp applications can set or retrieve these variables with the functions
and
Manipulate Memory
usrsctp_sysctl_set_sctp_sendspace()
The 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.
usrsctp_sysctl_set_sctp_recvspace()
The 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.
usrsctp_sysctl_set_sctp_hashtblsize()
The 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.
usrsctp_sysctl_set_sctp_pcbtblsize()
The 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.
usrsctp_sysctl_set_sctp_system_free_resc_limit()
This 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.
usrsctp_sysctl_set_sctp_asoc_free_resc_limit()
usrsctp_sysctl_set_sctp_mbuf_threshold_count()
Data 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.
usrsctp_sysctl_set_sctp_add_more_threshold()
TBD This parameter configures the threshold below which more space should be added
to a socket send buffer. The default value is 1452 bytes.
Configure RTO
The 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.
usrsctp_sysctl_set_sctp_rto_max_default()
The default value for the maximum retransmission timeout in ms is 60,000 (60secs).
usrsctp_sysctl_set_sctp_rto_min_default()
The default value for the minimum retransmission timeout in ms is 1,000 (1sec).
usrsctp_sysctl_set_sctp_rto_initial_default()
The 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.
usrsctp_sysctl_set_sctp_init_rto_max_default()
The default value for the maximum retransmission timeout for an INIT chunk in ms is
60,000 (60secs).
Set Timers
usrsctp_sysctl_set_sctp_valid_cookie_life_default()
A 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).
usrsctp_sysctl_set_sctp_heartbeat_interval_default()
Set the default time between two heartbeats. The default is 30,000ms.
usrsctp_sysctl_set_sctp_shutdown_guard_time_default()
usrsctp_sysctl_set_sctp_pmtu_raise_time_default()
TBD To 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.
usrsctp_sysctl_set_sctp_secret_lifetime_default()
usrsctp_sysctl_set_sctp_vtag_time_wait()
usrsctp_sysctl_set_sctp_init_rtx_max_default()
usrsctp_sysctl_set_sctp_assoc_rtx_max_default()
This parameter sets the maximum number of failed retransmissions before the
association is aborted. The default value is 10.
usrsctp_sysctl_set_sctp_path_rtx_max_default()
This 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.
usrsctp_sysctl_set_sctp_max_retran_chunk()
The parameter configures how many times an unlucky chunk can be retransmitted
before the association aborts. The default is set to 30.
usrsctp_sysctl_set_sctp_path_pf_threshold()
usrsctp_sysctl_set_sctp_abort_if_one_2_one_hits_limit()
usrsctp_sysctl_set_sctp_sack_freq_default()
The SACK frequency defines the number of packets that are awaited, before a SACK is
sent. The default value is 2.
usrsctp_sysctl_set_sctp_delayed_sack_time_default()
As 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.
usrsctp_sysctl_set_sctp_strict_sacks()
TBD This is a flag to turn the controlling of the coherence of SACKs on or off. The
default value is 1 (on).
usrsctp_sysctl_set_sctp_nr_sack_on_off()
If 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.
usrsctp_sysctl_set_sctp_enable_sack_immediately()
In 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) can be set to provoke the instant sending of a SACK. The default is to
turn it off.
usrsctp_sysctl_set_sctp_L2_abc_variable()
usrsctp_sysctl_set_sctp_max_burst_default()
The 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.
usrsctp_sysctl_set_sctp_use_cwnd_based_maxburst()
The use of max burst is based on the size of the congestion window (cwnd). This
parameter is set by default.
usrsctp_sysctl_set_sctp_hb_maxburst()
Heartbeats are mostly used to verify a path. Their number can be limited. The default is
4.
usrsctp_sysctl_set_sctp_fr_max_burst_default()
In the state of fast retransmission the number of packet bursts can be limited. The
default value is 4.
Handle Chunks
usrsctp_sysctl_set_sctp_peer_chunk_oh()
In 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.
usrsctp_sysctl_set_sctp_max_chunks_on_queue()
This parameter sets the maximum number of chunks that can be queued per
association. The default value is 512.
usrsctp_sysctl_set_sctp_min_split_point()
TBD The minimum size when splitting a chunk is 2904 bytes by default.
usrsctp_sysctl_set_sctp_chunkscale()
TBD This parameter can be tuned for scaling of number of chunks and messages. The
default is10.
usrsctp_sysctl_set_sctp_min_residual()
TBD This parameter configures the minimum size of the residual data chunk in the
second part of the split. The default is 1452.
Calculate RTT
The calculation of the round trip time (RTT) depends on several parameters.
usrsctp_sysctl_set_sctp_rttvar_bw()
usrsctp_sysctl_set_sctp_rttvar_rtt()
TBD Shift amount for rtt smoothing on rtt calc. Default: 5
usrsctp_sysctl_set_sctp_rttvar_eqret()
usrsctp_sysctl_set_sctp_ecn_enable
usrsctp_sysctl_set_sctp_default_cc_module()
This parameter sets the default algorithm for the congestion control. Default is 0, i.e.
the one specified in RFC 4960.
usrsctp_sysctl_set_sctp_initial_cwnd()
usrsctp_sysctl_set_sctp_use_dccc_ecn()
usrsctp_sysctl_set_sctp_steady_step()
TBD How many the sames it takes to try step down of cwnd. Default: 20
usrsctp_sysctl_set_sctp_auto_asconf()
usrsctp_sysctl_set_sctp_multiple_asconfs()
usrsctp_sysctl_set_sctp_auth_enable()
The use of AUTH, which is normally turned on, can be disabled by setting this
parameter to 0.
usrsctp_sysctl_set_sctp_asconf_auth_nochk()
It is also possible to disable the requirement to use AUTH in conjunction with ADD-IP
by setting this parameter to 1.
usrsctp_sysctl_set_sctp_cmt_on_off()
usrsctp_sysctl_set_sctp_cmt_use_dac()
usrsctp_sysctl_set_sctp_buffer_splitting()
For CMT it makes sense to split the send and receive buffer to have shares for each
path. By default buffer splitting is turned off.
usrsctp_sysctl_set_sctp_nat_friendly()
usrsctp_sysctl_set_sctp_inits_include_nat_friendly()
usrsctp_sysctl_set_sctp_udp_tunneling_port()
SCTP Mobility
usrsctp_sysctl_set_sctp_mobility_base()
TBD Enable SCTP base mobility. Default: 0
usrsctp_sysctl_set_sctp_mobility_fasthandoff()
Miscellaneous
usrsctp_sysctl_set_sctp_no_csum_on_loopback()
Calculating the checksum for packets sent on loopback is turned off by default. To turn
it on, set this parameter to 0.
usrsctp_sysctl_set_sctp_nr_outgoing_streams_default()
The peer is notified about the number of outgoing streams in the INIT or INIT-ACK
chunk. The default is 10.
usrsctp_sysctl_set_sctp_do_drain()
usrsctp_sysctl_set_sctp_strict_data_order()
TBD Enforce strict data ordering, abort if control inside data. Default: 0
usrsctp_sysctl_set_sctp_default_ss_module()
SCTP_SS_DEFAULT
SCTP_SS_ROUND_ROBIN
SCTP_SS_ROUND_ROBIN_PACKET
SCTP_SS_PRIORITY
SCTP_SS_FAIR_BANDWITH
SCTP_SS_FIRST_COME
usrsctp_sysctl_set_sctp_default_frag_interleave()
usrsctp_sysctl_set_sctp_blackhole()
usrsctp_sysctl_set_sctp_logging_level()
Set the logging level. The default is 0.
usrsctp_sysctl_set_sctp_debug_on()
Default
Parameter Meaning
Value
Cashed resources in an
sctp_asoc_free_resc_limit 10
association
Examples
See https://github.com/sctplab/usrsctp/tree/master/programs
References
SCTP
R. Stewart:
Stream Control Transmission Protocol .
RFC 4960, September 2007.
auth
addip
socketAPI
streamReset
R. Stewart, M. Tüxen, and P. Lei:
Stream Control Transmission Protocol (SCTP) Stream Reconfiguration .
RFC 6525, February 2012.
udpencaps
sack-imm