1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-28 07:51:19 +01:00

[sys net destiny]

- added waiting period after sending ACK at 3-way handshake to
enable a retransmit in case of a lost packet
This commit is contained in:
Oliver 2012-02-12 20:06:12 +01:00
parent bb580d1c4f
commit be14d20042
3 changed files with 61 additions and 29 deletions

View File

@ -75,7 +75,7 @@ void print_tcp_cb(tcp_cb_t *cb)
{
printf("Send_ISS: %lu\nSend_UNA: %lu\nSend_NXT: %lu\nSend_WND: %u\n", cb->send_iss, cb->send_una, cb->send_nxt, cb->send_wnd);
printf("Rcv_IRS: %lu\nRcv_NXT: %lu\nRcv_WND: %u\n", cb->rcv_irs, cb->rcv_nxt, cb->rcv_wnd);
printf("Time difference: %lu, No_of_retries: %u, State: %u\n\n", timex_sub(vtimer_now(), cb->last_packet_time).microseconds, cb->no_of_retry, cb->state);
printf("Time difference: %lu, No_of_retries: %u, State: %u\n\n", timex_sub(vtimer_now(), cb->last_packet_time).microseconds, cb->no_of_retries, cb->state);
}
void print_tcp_status(int in_or_out, ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header, socket_t *tcp_socket)
@ -504,7 +504,7 @@ int connect(int socket, sockaddr6_t *addr, uint32_t addrlen)
// Remember current time
current_tcp_socket->tcp_control.last_packet_time = vtimer_now();
current_tcp_socket->tcp_control.no_of_retry = 0;
current_tcp_socket->tcp_control.no_of_retries = 0;
msg_from_server.type = TCP_RETRY;
@ -557,8 +557,37 @@ int connect(int socket, sockaddr6_t *addr, uint32_t addrlen)
current_tcp_socket->tcp_control.send_una++;
current_tcp_socket->tcp_control.send_nxt++;
// Send packet
send_tcp(current_int_tcp_socket, current_tcp_packet, temp_ipv6_header, TCP_ACK, 0);
msg_from_server.type = UNDEFINED;
// Remember current time
current_tcp_socket->tcp_control.last_packet_time = vtimer_now();
current_tcp_socket->tcp_control.no_of_retries = 0;
#ifdef TCP_HC
// Remember TCP Context for possible TCP_RETRY
tcp_hc_context_t saved_tcp_context;
memcpy(&saved_tcp_context, &current_tcp_socket->tcp_control.tcp_context, sizeof(tcp_hc_context_t));
#endif
while (msg_from_server.type != TCP_RETRY)
{
// Send packet
send_tcp(current_int_tcp_socket, current_tcp_packet, temp_ipv6_header, TCP_ACK, 0);
msg_receive(&msg_from_server);
#ifdef TCP_HC
if (msg_from_server.type == TCP_SYN_ACK)
{
// TCP_SYN_ACK from server arrived again, copy old context and send TCP_ACK again
memcpy(&current_tcp_socket->tcp_control.tcp_context, &saved_tcp_context, sizeof(tcp_hc_context_t));
}
else if (msg_from_server.type == TCP_RETRY)
{
// We waited for RTT, no TCP_SYN_ACK received, so we assume the TCP_ACK packet arrived safely
}
#endif
}
current_tcp_socket->tcp_control.state = ESTABLISHED;
current_int_tcp_socket->recv_pid = 255;
@ -601,7 +630,7 @@ int32_t send(int s, void *msg, uint64_t len, int flags)
while (1)
{
current_tcp_socket->tcp_control.no_of_retry = 0;
current_tcp_socket->tcp_control.no_of_retries = 0;
#ifdef TCP_HC
current_tcp_socket->tcp_control.tcp_context.hc_type = COMPRESSED_HEADER;
@ -1057,7 +1086,7 @@ int handle_new_tcp_connection(socket_internal_t *current_queued_int_socket, sock
// Remember current time
current_queued_int_socket->socket_values.tcp_control.last_packet_time = vtimer_now();
current_queued_int_socket->socket_values.tcp_control.no_of_retry = 0;
current_queued_int_socket->socket_values.tcp_control.no_of_retries = 0;
// Set message type to Retry for while loop
msg_recv_client_ack.type = TCP_RETRY;

View File

@ -153,7 +153,7 @@ typedef struct tcp_control_block
uint32_t rcv_irs;
timex_t last_packet_time;
uint8_t no_of_retry;
uint8_t no_of_retries;
uint16_t mss;
uint8_t state;

View File

@ -17,28 +17,31 @@
void handle_synchro_timeout(socket_internal_t *current_socket)
{
msg_t send;
if ((current_socket->socket_values.tcp_control.no_of_retry == 0) &&
(timex_sub(vtimer_now(), current_socket->socket_values.tcp_control.last_packet_time).microseconds >
TCP_SYN_INITIAL_TIMEOUT))
if (thread_getstatus(current_socket->recv_pid) == STATUS_RECEIVE_BLOCKED)
{
current_socket->socket_values.tcp_control.no_of_retry++;
net_msg_send(&send, current_socket->recv_pid, 0, TCP_RETRY);
printf("FIRST RETRY!\n");
}
else if ((current_socket->socket_values.tcp_control.no_of_retry > 0) &&
(timex_sub(vtimer_now(), current_socket->socket_values.tcp_control.last_packet_time).microseconds >
(current_socket->socket_values.tcp_control.no_of_retry * TCP_SYN_TIMEOUT + TCP_SYN_INITIAL_TIMEOUT)))
{
current_socket->socket_values.tcp_control.no_of_retry++;
if (current_socket->socket_values.tcp_control.no_of_retry > TCP_MAX_SYN_RETRIES)
{
net_msg_send(&send, current_socket->recv_pid, 0, TCP_TIMEOUT);
printf("TCP SYN TIMEOUT!!\n");
}
else
if ((current_socket->socket_values.tcp_control.no_of_retries == 0) &&
(timex_sub(vtimer_now(), current_socket->socket_values.tcp_control.last_packet_time).microseconds >
TCP_SYN_INITIAL_TIMEOUT))
{
current_socket->socket_values.tcp_control.no_of_retries++;
net_msg_send(&send, current_socket->recv_pid, 0, TCP_RETRY);
printf("NEXT RETRY!\n");
printf("FIRST RETRY!\n");
}
else if ((current_socket->socket_values.tcp_control.no_of_retries > 0) &&
(timex_sub(vtimer_now(), current_socket->socket_values.tcp_control.last_packet_time).microseconds >
(current_socket->socket_values.tcp_control.no_of_retries * TCP_SYN_TIMEOUT + TCP_SYN_INITIAL_TIMEOUT)))
{
current_socket->socket_values.tcp_control.no_of_retries++;
if (current_socket->socket_values.tcp_control.no_of_retries > TCP_MAX_SYN_RETRIES)
{
net_msg_send(&send, current_socket->recv_pid, 0, TCP_TIMEOUT);
printf("TCP SYN TIMEOUT!!\n");
}
else
{
net_msg_send(&send, current_socket->recv_pid, 0, TCP_RETRY);
printf("NEXT RETRY!\n");
}
}
}
}
@ -51,7 +54,7 @@ void handle_established(socket_internal_t *current_socket)
if ((current_socket->socket_values.tcp_control.send_nxt > current_socket->socket_values.tcp_control.send_una) &&
(thread_getstatus(current_socket->send_pid) == STATUS_RECEIVE_BLOCKED))
{
for(i = 0; i < current_socket->socket_values.tcp_control.no_of_retry; i++)
for(i = 0; i < current_socket->socket_values.tcp_control.no_of_retries; i++)
{
current_timeout *= 2;
}
@ -63,9 +66,9 @@ void handle_established(socket_internal_t *current_socket)
else if (timex_sub(vtimer_now(), current_socket->socket_values.tcp_control.last_packet_time).microseconds >
current_timeout)
{
current_socket->socket_values.tcp_control.no_of_retry++;
current_socket->socket_values.tcp_control.no_of_retries++;
net_msg_send(&send, current_socket->send_pid, 0, TCP_RETRY);
printf("GOT NO ACK YET, %i. RETRY! Now: %lu Before: %lu, Diff: %lu, Cur Timeout: %lu\n", current_socket->socket_values.tcp_control.no_of_retry,
printf("GOT NO ACK YET, %i. RETRY! Now: %lu Before: %lu, Diff: %lu, Cur Timeout: %lu\n", current_socket->socket_values.tcp_control.no_of_retries,
vtimer_now().microseconds, current_socket->socket_values.tcp_control.last_packet_time.microseconds,
vtimer_now().microseconds - current_socket->socket_values.tcp_control.last_packet_time.microseconds,
current_timeout);