From 122616ae7daa568fa507558cd5d4e5727f35a86f Mon Sep 17 00:00:00 2001 From: Simon Brummer Date: Tue, 16 Jun 2020 13:26:43 +0200 Subject: [PATCH] gnrc_tcp: add retransmission timer --- sys/include/net/gnrc/tcp/tcb.h | 6 ++-- sys/net/gnrc/transport_layer/tcp/gnrc_tcp.c | 33 ++++++++++--------- .../gnrc/transport_layer/tcp/gnrc_tcp_fsm.c | 11 ++++--- .../gnrc/transport_layer/tcp/gnrc_tcp_pkt.c | 8 ++--- 4 files changed, 32 insertions(+), 26 deletions(-) diff --git a/sys/include/net/gnrc/tcp/tcb.h b/sys/include/net/gnrc/tcp/tcb.h index b33494976d..7a3b2596e6 100644 --- a/sys/include/net/gnrc/tcp/tcb.h +++ b/sys/include/net/gnrc/tcp/tcb.h @@ -67,8 +67,10 @@ typedef struct _transmission_control_block { int32_t srtt; /**< Smoothed round trip time */ int32_t rto; /**< Retransmission timeout duration */ uint8_t retries; /**< Number of retransmissions */ - xtimer_t tim_tout; /**< Timer struct for timeouts */ - msg_t msg_tout; /**< Message, sent on timeouts */ + xtimer_t timer_retransmit; /**< Retransmission timer */ + xtimer_t timer_misc; /**< General purpose timer */ + msg_t msg_retransmit; /**< Retransmission timer message */ + msg_t msg_misc; /**< General purpose timer message */ gnrc_pktsnip_t *pkt_retransmit; /**< Pointer to packet in "retransmit queue" */ mbox_t *mbox; /**< TCB mbox for synchronization */ uint8_t *rcv_buf_raw; /**< Pointer to the receive buffer */ diff --git a/sys/net/gnrc/transport_layer/tcp/gnrc_tcp.c b/sys/net/gnrc/transport_layer/tcp/gnrc_tcp.c index 0e79efc62a..f373c65e96 100644 --- a/sys/net/gnrc/transport_layer/tcp/gnrc_tcp.c +++ b/sys/net/gnrc/transport_layer/tcp/gnrc_tcp.c @@ -124,7 +124,6 @@ static int _gnrc_tcp_open(gnrc_tcp_tcb_t *tcb, const gnrc_tcp_ep_t *remote, msg_t msg; msg_t msg_queue[TCP_MSG_QUEUE_SIZE]; mbox_t mbox = MBOX_INIT(msg_queue, TCP_MSG_QUEUE_SIZE); - xtimer_t connection_timeout; cb_arg_t connection_timeout_arg = {MSG_TYPE_CONNECTION_TIMEOUT, &mbox}; int ret = 0; @@ -187,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, CONFIG_GNRC_TCP_CONNECTION_TIMEOUT_DURATION, + _setup_timeout(&(tcb->timer_misc), CONFIG_GNRC_TCP_CONNECTION_TIMEOUT_DURATION, _cb_mbox_put_msg, &connection_timeout_arg); } @@ -212,8 +211,9 @@ 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, CONFIG_GNRC_TCP_CONNECTION_TIMEOUT_DURATION, - _cb_mbox_put_msg, &connection_timeout_arg); + _setup_timeout(&(tcb->timer_misc), + CONFIG_GNRC_TCP_CONNECTION_TIMEOUT_DURATION, _cb_mbox_put_msg, + &connection_timeout_arg); } break; @@ -241,7 +241,7 @@ static int _gnrc_tcp_open(gnrc_tcp_tcb_t *tcb, const gnrc_tcp_ep_t *remote, /* Cleanup */ _fsm_set_mbox(tcb, NULL); - xtimer_remove(&connection_timeout); + xtimer_remove(&(tcb->timer_misc)); if (tcb->state == FSM_STATE_CLOSED && ret == 0) { ret = -ECONNREFUSED; } @@ -468,7 +468,6 @@ ssize_t gnrc_tcp_send(gnrc_tcp_tcb_t *tcb, const void *data, const size_t len, msg_t msg; msg_t msg_queue[TCP_MSG_QUEUE_SIZE]; mbox_t mbox = MBOX_INIT(msg_queue, TCP_MSG_QUEUE_SIZE); - xtimer_t connection_timeout; cb_arg_t connection_timeout_arg = {MSG_TYPE_CONNECTION_TIMEOUT, &mbox}; xtimer_t user_timeout; cb_arg_t user_timeout_arg = {MSG_TYPE_USER_SPEC_TIMEOUT, &mbox}; @@ -489,7 +488,9 @@ ssize_t gnrc_tcp_send(gnrc_tcp_tcb_t *tcb, const void *data, const size_t len, /* Setup messaging */ _fsm_set_mbox(tcb, &mbox); - _setup_timeout(&connection_timeout, CONFIG_GNRC_TCP_CONNECTION_TIMEOUT_DURATION, + + /* Setup connection timeout: Put timeout message in tcb's mbox on expiration */ + _setup_timeout(&(tcb->timer_misc), CONFIG_GNRC_TCP_CONNECTION_TIMEOUT_DURATION, _cb_mbox_put_msg, &connection_timeout_arg); if (timeout_duration_us > 0) { @@ -555,7 +556,7 @@ ssize_t gnrc_tcp_send(gnrc_tcp_tcb_t *tcb, const void *data, const size_t len, DEBUG("gnrc_tcp.c : gnrc_tcp_send() : NOTIFY_USER\n"); /* Connection is alive: Reset Connection Timeout */ - _setup_timeout(&connection_timeout, CONFIG_GNRC_TCP_CONNECTION_TIMEOUT_DURATION, + _setup_timeout(&(tcb->timer_misc), CONFIG_GNRC_TCP_CONNECTION_TIMEOUT_DURATION, _cb_mbox_put_msg, &connection_timeout_arg); /* If the window re-opened and we are probing: Stop it */ @@ -572,8 +573,8 @@ ssize_t gnrc_tcp_send(gnrc_tcp_tcb_t *tcb, const void *data, const size_t len, /* Cleanup */ _fsm_set_mbox(tcb, NULL); + xtimer_remove(&(tcb->timer_misc)); xtimer_remove(&probe_timeout); - xtimer_remove(&connection_timeout); xtimer_remove(&user_timeout); mutex_unlock(&(tcb->function_lock)); return ret; @@ -588,7 +589,6 @@ ssize_t gnrc_tcp_recv(gnrc_tcp_tcb_t *tcb, void *data, const size_t max_len, msg_t msg; msg_t msg_queue[TCP_MSG_QUEUE_SIZE]; mbox_t mbox = MBOX_INIT(msg_queue, TCP_MSG_QUEUE_SIZE); - xtimer_t connection_timeout; cb_arg_t connection_timeout_arg = {MSG_TYPE_CONNECTION_TIMEOUT, &mbox}; xtimer_t user_timeout; cb_arg_t user_timeout_arg = {MSG_TYPE_USER_SPEC_TIMEOUT, &mbox}; @@ -624,7 +624,9 @@ ssize_t gnrc_tcp_recv(gnrc_tcp_tcb_t *tcb, void *data, const size_t max_len, /* Setup messaging */ _fsm_set_mbox(tcb, &mbox); - _setup_timeout(&connection_timeout, CONFIG_GNRC_TCP_CONNECTION_TIMEOUT_DURATION, + + /* Setup connection timeout: Put timeout message in tcb's mbox on expiration */ + _setup_timeout(&(tcb->timer_misc), CONFIG_GNRC_TCP_CONNECTION_TIMEOUT_DURATION, _cb_mbox_put_msg, &connection_timeout_arg); _setup_timeout(&user_timeout, timeout_duration_us, _cb_mbox_put_msg, &user_timeout_arg); @@ -672,7 +674,7 @@ ssize_t gnrc_tcp_recv(gnrc_tcp_tcb_t *tcb, void *data, const size_t max_len, /* Cleanup */ _fsm_set_mbox(tcb, NULL); - xtimer_remove(&connection_timeout); + xtimer_remove(&(tcb->timer_misc)); xtimer_remove(&user_timeout); mutex_unlock(&(tcb->function_lock)); return ret; @@ -685,7 +687,6 @@ void gnrc_tcp_close(gnrc_tcp_tcb_t *tcb) msg_t msg; msg_t msg_queue[TCP_MSG_QUEUE_SIZE]; mbox_t mbox = MBOX_INIT(msg_queue, TCP_MSG_QUEUE_SIZE); - xtimer_t connection_timeout; cb_arg_t connection_timeout_arg = {MSG_TYPE_CONNECTION_TIMEOUT, &mbox}; /* Lock the TCB for this function call */ @@ -699,7 +700,9 @@ void gnrc_tcp_close(gnrc_tcp_tcb_t *tcb) /* Setup messaging */ _fsm_set_mbox(tcb, &mbox); - _setup_timeout(&connection_timeout, CONFIG_GNRC_TCP_CONNECTION_TIMEOUT_DURATION, + + /* Setup connection timeout: Put timeout message in tcb's mbox on expiration */ + _setup_timeout(&(tcb->timer_misc), CONFIG_GNRC_TCP_CONNECTION_TIMEOUT_DURATION, _cb_mbox_put_msg, &connection_timeout_arg); /* Start connection teardown sequence */ @@ -725,7 +728,7 @@ void gnrc_tcp_close(gnrc_tcp_tcb_t *tcb) /* Cleanup */ _fsm_set_mbox(tcb, NULL); - xtimer_remove(&connection_timeout); + xtimer_remove(&(tcb->timer_misc)); mutex_unlock(&(tcb->function_lock)); } diff --git a/sys/net/gnrc/transport_layer/tcp/gnrc_tcp_fsm.c b/sys/net/gnrc/transport_layer/tcp/gnrc_tcp_fsm.c index 7ae6378970..bc42707d77 100644 --- a/sys/net/gnrc/transport_layer/tcp/gnrc_tcp_fsm.c +++ b/sys/net/gnrc/transport_layer/tcp/gnrc_tcp_fsm.c @@ -85,7 +85,7 @@ static int _clear_retransmit(gnrc_tcp_tcb_t *tcb) { if (tcb->pkt_retransmit != NULL) { gnrc_pktbuf_release(tcb->pkt_retransmit); - xtimer_remove(&(tcb->tim_tout)); + xtimer_remove(&(tcb->timer_retransmit)); tcb->pkt_retransmit = NULL; } return 0; @@ -100,10 +100,11 @@ static int _clear_retransmit(gnrc_tcp_tcb_t *tcb) */ static int _restart_timewait_timer(gnrc_tcp_tcb_t *tcb) { - xtimer_remove(&tcb->tim_tout); - tcb->msg_tout.type = MSG_TYPE_TIMEWAIT; - tcb->msg_tout.content.ptr = (void *)tcb; - xtimer_set_msg(&tcb->tim_tout, 2 * CONFIG_GNRC_TCP_MSL, &tcb->msg_tout, gnrc_tcp_pid); + xtimer_remove(&tcb->timer_retransmit); + tcb->msg_retransmit.type = MSG_TYPE_TIMEWAIT; + tcb->msg_retransmit.content.ptr = (void *)tcb; + xtimer_set_msg(&(tcb->timer_retransmit), 2 * CONFIG_GNRC_TCP_MSL, &(tcb->msg_retransmit), + gnrc_tcp_pid); return 0; } diff --git a/sys/net/gnrc/transport_layer/tcp/gnrc_tcp_pkt.c b/sys/net/gnrc/transport_layer/tcp/gnrc_tcp_pkt.c index bafc7d2c10..67d53ea40f 100644 --- a/sys/net/gnrc/transport_layer/tcp/gnrc_tcp_pkt.c +++ b/sys/net/gnrc/transport_layer/tcp/gnrc_tcp_pkt.c @@ -412,9 +412,9 @@ int _pkt_setup_retransmit(gnrc_tcp_tcb_t *tcb, gnrc_pktsnip_t *pkt, const bool r } /* Setup retransmission timer, msg to TCP thread with ptr to TCB */ - tcb->msg_tout.type = MSG_TYPE_RETRANSMISSION; - tcb->msg_tout.content.ptr = (void *) tcb; - xtimer_set_msg(&tcb->tim_tout, tcb->rto, &tcb->msg_tout, gnrc_tcp_pid); + tcb->msg_retransmit.type = MSG_TYPE_RETRANSMISSION; + tcb->msg_retransmit.content.ptr = (void *) tcb; + xtimer_set_msg(&tcb->timer_retransmit, tcb->rto, &tcb->msg_retransmit, gnrc_tcp_pid); return 0; } @@ -438,7 +438,7 @@ int _pkt_acknowledge(gnrc_tcp_tcb_t *tcb, const uint32_t ack) /* If segment can be acknowledged -> stop timer, release packet from pktbuf and update rto. */ if (LSS_32_BIT(seg, ack)) { - xtimer_remove(&(tcb->tim_tout)); + xtimer_remove(&(tcb->timer_retransmit)); gnrc_pktbuf_release(tcb->pkt_retransmit); tcb->pkt_retransmit = NULL;