Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gnrc/tcp : Expose configurations to Kconfig #14126

Merged
merged 17 commits into from
Jun 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sys/include/net/gnrc/tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ int gnrc_tcp_open_active(gnrc_tcp_tcb_t *tcb, const gnrc_tcp_ep_t *remote,
* or the address in @p local is invalid.
* @return -EISCONN if TCB is already in use.
* @return -ENOMEM if the receive buffer for the TCB could not be allocated.
* Hint: Increase "GNRC_TCP_RCV_BUFFERS".
* Hint: Increase "CONFIG_GNRC_TCP_RCV_BUFFERS".
*/
int gnrc_tcp_open_passive(gnrc_tcp_tcb_t *tcb, const gnrc_tcp_ep_t *local);

Expand Down
95 changes: 64 additions & 31 deletions sys/include/net/gnrc/tcp/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,114 +26,147 @@
extern "C" {
#endif

/**
* @defgroup net_gnrc_tcp_conf GNRC TCP compile configurations
* @ingroup net_gnrc_conf
*
* ## Calculating RTO
* To calculate retransmission timeout (RTO), Round Trip Time (RTT) needs to be
* taken into account. SRTT (smoothed round-trip time) and RTTVAR (round-trip
* time variation) are hence calculated as follows:
*
* RTTVAR <- (1 - beta) * RTTVAR + beta * |SRTT - R'|
* SRTT <- (1 - alpha) * SRTT + alpha * R'
*
* where alpha ( 1 / @ref CONFIG_GNRC_TCP_RTO_A_DIV ) and beta
* ( 1 / @ref CONFIG_GNRC_TCP_RTO_B_DIV) are constants, and R' is the
* instantaneous RTT value.
*
akshaim marked this conversation as resolved.
Show resolved Hide resolved
* RTO is then calculated as :
*
* RTO <- SRTT + max (G, K*RTTVAR)
*
* where K is a constant, and G is clock granularity in seconds
* ( @ref CONFIG_GNRC_TCP_RTO_GRANULARITY).
* For more information refer to https://tools.ietf.org/html/rfc6298
* @{
*/
/**
* @brief Timeout duration for user calls. Default is 2 minutes.
*/
#ifndef GNRC_TCP_CONNECTION_TIMEOUT_DURATION
#define GNRC_TCP_CONNECTION_TIMEOUT_DURATION (120U * US_PER_SEC)
#ifndef CONFIG_GNRC_TCP_CONNECTION_TIMEOUT_DURATION
#define CONFIG_GNRC_TCP_CONNECTION_TIMEOUT_DURATION (120U * US_PER_SEC)
#endif

/**
* @brief Maximum segment lifetime (MSL). Default is 30 seconds.
*/
#ifndef GNRC_TCP_MSL
#define GNRC_TCP_MSL (30U * US_PER_SEC)
#ifndef CONFIG_GNRC_TCP_MSL
#define CONFIG_GNRC_TCP_MSL (30U * US_PER_SEC)
#endif

/**
* @brief Maximum Segment Size (MSS).
*/
#ifndef GNRC_TCP_MSS
#ifndef CONFIG_GNRC_TCP_MSS
#ifdef MODULE_GNRC_IPV6
#define GNRC_TCP_MSS (1220U) /**< If IPv6 is used. Get MSS = 1280 - IPv6 Hdr - TCP Hdr = 1220 */
#define CONFIG_GNRC_TCP_MSS (1220U) /**< If IPv6 is used. Get MSS = 1280 - IPv6 Hdr - TCP Hdr = 1220 */
#else
#define GNRC_TCP_MSS (576U) /**< Default MSS */
#define CONFIG_GNRC_TCP_MSS (576U) /**< Default MSS */
#endif
#endif

/**
akshaim marked this conversation as resolved.
Show resolved Hide resolved
* @brief MSS Multiplicator = Number of MSS sized packets stored in receive buffer
*/
#ifndef GNRC_TCP_MSS_MULTIPLICATOR
#define GNRC_TCP_MSS_MULTIPLICATOR (1U)
#ifndef CONFIG_GNRC_TCP_MSS_MULTIPLICATOR
#define CONFIG_GNRC_TCP_MSS_MULTIPLICATOR (1U)
#endif

/**
* @brief Default receive window size
*/
#ifndef GNRC_TCP_DEFAULT_WINDOW
#define GNRC_TCP_DEFAULT_WINDOW (GNRC_TCP_MSS * GNRC_TCP_MSS_MULTIPLICATOR)
#ifndef CONFIG_GNRC_TCP_DEFAULT_WINDOW
#define CONFIG_GNRC_TCP_DEFAULT_WINDOW (CONFIG_GNRC_TCP_MSS * CONFIG_GNRC_TCP_MSS_MULTIPLICATOR)
#endif

leandrolanzieri marked this conversation as resolved.
Show resolved Hide resolved
/**
* @brief Number of preallocated receive buffers
* @brief Number of preallocated receive buffers.
*
* This value determines how many parallel TCP connections can be active at the
* same time.
*/
#ifndef GNRC_TCP_RCV_BUFFERS
#define GNRC_TCP_RCV_BUFFERS (1U)
#ifndef CONFIG_GNRC_TCP_RCV_BUFFERS
#define CONFIG_GNRC_TCP_RCV_BUFFERS (1U)
#endif

/**
* @brief Default receive buffer size
*/
#ifndef GNRC_TCP_RCV_BUF_SIZE
#define GNRC_TCP_RCV_BUF_SIZE (GNRC_TCP_DEFAULT_WINDOW)
#define GNRC_TCP_RCV_BUF_SIZE (CONFIG_GNRC_TCP_DEFAULT_WINDOW)
#endif

/**
* @brief Lower bound for RTO = 1 sec (see RFC 6298)
*
* @note Retransmission Timeout (RTO) determines how long TCP waits for
* acknowledgment (ACK) of transmitted segment. If the acknowledgment
* isn't received within this time it is considered lost.
*/
#ifndef GNRC_TCP_RTO_LOWER_BOUND
#define GNRC_TCP_RTO_LOWER_BOUND (1U * US_PER_SEC)
#ifndef CONFIG_GNRC_TCP_RTO_LOWER_BOUND
#define CONFIG_GNRC_TCP_RTO_LOWER_BOUND (1U * US_PER_SEC)
#endif

/**
* @brief Upper bound for RTO = 60 sec (see RFC 6298)
*/
#ifndef GNRC_TCP_RTO_UPPER_BOUND
#define GNRC_TCP_RTO_UPPER_BOUND (60U * US_PER_SEC)
#ifndef CONFIG_GNRC_TCP_RTO_UPPER_BOUND
#define CONFIG_GNRC_TCP_RTO_UPPER_BOUND (60U * US_PER_SEC)
#endif

/**
* @brief Assumes clock granularity for TCP of 10 ms (see RFC 6298)
*/
#ifndef GNRC_TCP_RTO_GRANULARITY
#define GNRC_TCP_RTO_GRANULARITY (10U * MS_PER_SEC)
#ifndef CONFIG_GNRC_TCP_RTO_GRANULARITY
#define CONFIG_GNRC_TCP_RTO_GRANULARITY (10U * MS_PER_SEC)
#endif

/**
* @brief Alpha value for RTO calculation, default is 1/8
*/
#ifndef GNRC_TCP_RTO_A_DIV
#define GNRC_TCP_RTO_A_DIV (8U)
#ifndef CONFIG_GNRC_TCP_RTO_A_DIV
#define CONFIG_GNRC_TCP_RTO_A_DIV (8U)
#endif

/**
* @brief Beta value for RTO calculation, default is 1/4
*/
#ifndef GNRC_TCP_RTO_B_DIV
#define GNRC_TCP_RTO_B_DIV (4U)
#ifndef CONFIG_GNRC_TCP_RTO_B_DIV
#define CONFIG_GNRC_TCP_RTO_B_DIV (4U)
#endif

/**
* @brief K value for RTO calculation, default is 4
*/
#ifndef GNRC_TCP_RTO_K
#define GNRC_TCP_RTO_K (4U)
#ifndef CONFIG_GNRC_TCP_RTO_K
#define CONFIG_GNRC_TCP_RTO_K (4U)
#endif

/**
* @brief Lower bound for the duration between probes
*/
#ifndef GNRC_TCP_PROBE_LOWER_BOUND
#define GNRC_TCP_PROBE_LOWER_BOUND (1U * US_PER_SEC)
#ifndef CONFIG_GNRC_TCP_PROBE_LOWER_BOUND
#define CONFIG_GNRC_TCP_PROBE_LOWER_BOUND (1U * US_PER_SEC)
#endif

/**
* @brief Upper bound for the duration between probes
*/
#ifndef GNRC_TCP_PROBE_UPPER_BOUND
#define GNRC_TCP_PROBE_UPPER_BOUND (60U * US_PER_SEC)
#ifndef CONFIG_GNRC_TCP_PROBE_UPPER_BOUND
#define CONFIG_GNRC_TCP_PROBE_UPPER_BOUND (60U * US_PER_SEC)
#endif
/** @} */

#ifdef __cplusplus
}
Expand Down
1 change: 1 addition & 0 deletions sys/net/gnrc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ rsource "netif/Kconfig"
rsource "network_layer/ipv6/Kconfig"
rsource "network_layer/sixlowpan/Kconfig"
rsource "routing/rpl/Kconfig"
rsource "transport_layer/tcp/Kconfig"

endmenu # GNRC Network Stack
115 changes: 115 additions & 0 deletions sys/net/gnrc/transport_layer/tcp/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# Copyright (c) 2020 Freie Universitaet Berlin
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.
#
menuconfig KCONFIG_MODULE_GNRC_TCP
bool "Configure GNRC_TCP"
depends on MODULE_GNRC_TCP
help
Configure the GNRC_TCP using Kconfig.

if KCONFIG_MODULE_GNRC_TCP

config GNRC_TCP_CONNECTION_TIMEOUT_DURATION
int "Timeout duration for user calls in microseconds"
default 120000000
help
Timeout duration for user calls. Default value is 120000000 microseconds
(2 minutes).

config GNRC_TCP_MSL
int "Maximum segment lifetime (MSL) in microseconds"
default 30000000
help
Maximum segment lifetime (MSL) in microseconds. Default value is 30
seconds.

config GNRC_TCP_MSS
int "Maximum Segment Size (MSS)"
default 1220 if MODULE_GNRC_IPV6
default 576

config GNRC_TCP_MSS_MULTIPLICATOR
int "Number of MSS sized packets stored in receive buffer"
default 1
help
Configure MSS Multiplicator i.e. number of MSS sized packets stored in
receive buffer.

config GNRC_TCP_DEFAULT_WINDOW_EN
bool "Enable configuration of TCP window size"
help
Enable configuration of TCP window size. If not enabled, TCP window size
will default to the product of Maximum Segment Size and the number of
MSS sized packets i.e. CONFIG_GNRC_TCP_MSS *
CONFIG_GNRC_TCP_MSS_MULTIPLICATOR.

config GNRC_TCP_DEFAULT_WINDOW
int "TCP receive window size"
default 1220 if MODULE_GNRC_IPV6
default 576
depends on GNRC_TCP_DEFAULT_WINDOW_EN
help
Configure TCP receive window size. This value determines the maximum
amount of bytes that can be received from the peer at a given moment.

config GNRC_TCP_RCV_BUFFERS
int "Number of preallocated receive buffers"
akshaim marked this conversation as resolved.
Show resolved Hide resolved
default 1

config GNRC_TCP_RTO_LOWER_BOUND
int "Lower bound for RTO in microseconds"
default 1000000
help
Lower bound value for retransmission timeout (RTO) in microseconds.
Default value is 1000000 microseconds (1 second). Retransmission
timeout determines how long TCP waits for acknowledgment (ACK) of
transmitted segment. Refer to RFC 6298 for more information.

config GNRC_TCP_RTO_UPPER_BOUND
int "Upper bound for RTO in microseconds"
default 60000000
help
Upper bound value for retransmission timeout (RTO) in microseconds.
Default value is 60000000 microseconds (60 seconds). Refer to RFC 6298
for more information.

config GNRC_TCP_RTO_GRANULARITY
int "Clock granularity for RTO in microseconds"
default 10000
help
Clock granularity for retransmission timeout (RTO) for TCP in
microseconds. Default value is 10000 microseconds (10 milliseconds).
Refer to RFC 6298 for more information.

config GNRC_TCP_RTO_A_DIV
int "Alpha value divisor for RTO calculation"
default 8
help
Alpha value divisor to calculate retransmission timeout (RTO). The
default value for divisor is 8 which would result in an alpha value of
1/8.

config GNRC_TCP_RTO_B_DIV
akshaim marked this conversation as resolved.
Show resolved Hide resolved
int "Beta value divisor for RTO calculation"
default 4
help
Beta value divisor to calculate retransmission timeout (RTO). The
default value for divisor is 4 which would result in a beta value of
1/4.

config GNRC_TCP_RTO_K
int "K value for RTO calculation"
default 4

config GNRC_TCP_PROBE_LOWER_BOUND
int "Lower bound for the duration between probes in microseconds"
default 1000000

config GNRC_TCP_PROBE_UPPER_BOUND
int "Lower bound for the duration between probes in microseconds"
default 60000000

endif # KCONFIG_MODULE_GNRC_TCP
20 changes: 10 additions & 10 deletions sys/net/gnrc/transport_layer/tcp/gnrc_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ static int _gnrc_tcp_open(gnrc_tcp_tcb_t *tcb, const gnrc_tcp_ep_t *remote,
tcb->peer_port = remote->port;

/* Setup connection timeout: Put timeout message in TCBs mbox on expiration */
_setup_timeout(&connection_timeout, GNRC_TCP_CONNECTION_TIMEOUT_DURATION,
_setup_timeout(&connection_timeout, CONFIG_GNRC_TCP_CONNECTION_TIMEOUT_DURATION,
_cb_mbox_put_msg, &connection_timeout_arg);
}

Expand All @@ -211,7 +211,7 @@ static int _gnrc_tcp_open(gnrc_tcp_tcb_t *tcb, const gnrc_tcp_ep_t *remote,
* send SYN+ACK we received upon entering SYN_RCVD is never acknowledged
* by the peer. */
if ((tcb->state == FSM_STATE_SYN_RCVD) && (tcb->status & STATUS_PASSIVE)) {
_setup_timeout(&connection_timeout, GNRC_TCP_CONNECTION_TIMEOUT_DURATION,
_setup_timeout(&connection_timeout, CONFIG_GNRC_TCP_CONNECTION_TIMEOUT_DURATION,
_cb_mbox_put_msg, &connection_timeout_arg);
}
break;
Expand Down Expand Up @@ -493,7 +493,7 @@ ssize_t gnrc_tcp_send(gnrc_tcp_tcb_t *tcb, const void *data, const size_t len,
}

/* Setup connection timeout: Put timeout message in tcb's mbox on expiration */
_setup_timeout(&connection_timeout, GNRC_TCP_CONNECTION_TIMEOUT_DURATION,
_setup_timeout(&connection_timeout, CONFIG_GNRC_TCP_CONNECTION_TIMEOUT_DURATION,
_cb_mbox_put_msg, &connection_timeout_arg);

/* Setup user specified timeout if timeout_us is greater than zero */
Expand Down Expand Up @@ -548,19 +548,19 @@ ssize_t gnrc_tcp_send(gnrc_tcp_tcb_t *tcb, const void *data, const size_t len,
probe_timeout_duration_us += probe_timeout_duration_us;

/* Boundary check for time interval between probes */
if (probe_timeout_duration_us < GNRC_TCP_PROBE_LOWER_BOUND) {
probe_timeout_duration_us = GNRC_TCP_PROBE_LOWER_BOUND;
if (probe_timeout_duration_us < CONFIG_GNRC_TCP_PROBE_LOWER_BOUND) {
probe_timeout_duration_us = CONFIG_GNRC_TCP_PROBE_LOWER_BOUND;
}
else if (probe_timeout_duration_us > GNRC_TCP_PROBE_UPPER_BOUND) {
probe_timeout_duration_us = GNRC_TCP_PROBE_UPPER_BOUND;
else if (probe_timeout_duration_us > CONFIG_GNRC_TCP_PROBE_UPPER_BOUND) {
probe_timeout_duration_us = CONFIG_GNRC_TCP_PROBE_UPPER_BOUND;
}
break;

case MSG_TYPE_NOTIFY_USER:
DEBUG("gnrc_tcp.c : gnrc_tcp_send() : NOTIFY_USER\n");

/* Connection is alive: Reset Connection Timeout */
_setup_timeout(&connection_timeout, GNRC_TCP_CONNECTION_TIMEOUT_DURATION,
_setup_timeout(&connection_timeout, CONFIG_GNRC_TCP_CONNECTION_TIMEOUT_DURATION,
_cb_mbox_put_msg, &connection_timeout_arg);

/* If the window re-opened and we are probing: Stop it */
Expand Down Expand Up @@ -633,7 +633,7 @@ ssize_t gnrc_tcp_recv(gnrc_tcp_tcb_t *tcb, void *data, const size_t max_len,
}

/* Setup connection timeout: Put timeout message in tcb's mbox on expiration */
_setup_timeout(&connection_timeout, GNRC_TCP_CONNECTION_TIMEOUT_DURATION,
_setup_timeout(&connection_timeout, CONFIG_GNRC_TCP_CONNECTION_TIMEOUT_DURATION,
_cb_mbox_put_msg, &connection_timeout_arg);

/* Setup user specified timeout */
Expand Down Expand Up @@ -714,7 +714,7 @@ void gnrc_tcp_close(gnrc_tcp_tcb_t *tcb)
}

/* Setup connection timeout: Put timeout message in tcb's mbox on expiration */
_setup_timeout(&connection_timeout, GNRC_TCP_CONNECTION_TIMEOUT_DURATION,
_setup_timeout(&connection_timeout, CONFIG_GNRC_TCP_CONNECTION_TIMEOUT_DURATION,
_cb_mbox_put_msg, &connection_timeout_arg);

/* Start connection teardown sequence */
Expand Down
Loading