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

[sys net destiny]

- fixed a bug where the tcp retransmit timer triggered even before
beeing ready to receive an ACK
- fixed a bug where MSS option was added by mistake because checking for
the appropriate flag was broken
This commit is contained in:
Oliver 2012-02-12 04:26:55 +01:00
parent fef556dd66
commit bb580d1c4f
10 changed files with 50 additions and 34 deletions

View File

@ -228,7 +228,7 @@ void send_tcp_thread (void)
{
printf("Could not send %s!\n", current_message.tcp_string_msg);
}
printf("Finished sending!\n");
// printf("Finished sending!\n");
msg_reply(&recv_msg, &send_msg);
}
}

View File

@ -8,7 +8,7 @@
#ifndef DESTINY_H_
#define DESTINY_H_
#define TCP_HC
//#define TCP_HC
void init_transport_layer(void);

View File

@ -396,8 +396,9 @@ int send_tcp(socket_internal_t *current_socket, tcp_hdr_t *current_tcp_packet, i
{
socket_t *current_tcp_socket = &current_socket->socket_values;
uint8_t header_length = TCP_HDR_LEN/4;
if (IS_TCP_SYN(current_tcp_packet->reserved_flags) || IS_TCP_SYN_ACK(current_tcp_packet->reserved_flags))
if (IS_TCP_SYN(flags) || IS_TCP_SYN_ACK(flags))
{
printf("Sending with MSS Option! flags: %u\n", flags);
tcp_mss_option_t current_mss_option;
header_length += sizeof(tcp_mss_option_t)/4;
@ -422,6 +423,7 @@ int send_tcp(socket_internal_t *current_socket, tcp_hdr_t *current_tcp_packet, i
uint16_t compressed_size;
compressed_size = compress_tcp_packet(current_socket, (uint8_t *) current_tcp_packet, temp_ipv6_header, flags, payload_length);
// printArrayRange(((uint8_t *)temp_ipv6_header), IPV6_HDR_LEN+compressed_size, "Outgoing2");
if (compressed_size == 0)
{
// Error in compressing tcp packet header
@ -611,7 +613,7 @@ int32_t send(int s, void *msg, uint64_t len, int flags)
while (recv_msg.type != TCP_ACK)
{
// Add packet data
printf("Send Window: %u, MSS: %u\n", current_tcp_socket->tcp_control.send_wnd, current_tcp_socket->tcp_control.mss);
// printf("Send Window: %u, MSS: %u\n", current_tcp_socket->tcp_control.send_wnd, current_tcp_socket->tcp_control.mss);
if (current_tcp_socket->tcp_control.send_wnd > current_tcp_socket->tcp_control.mss)
{
// Window size > Maximum Segment Size
@ -648,7 +650,7 @@ int32_t send(int s, void *msg, uint64_t len, int flags)
current_tcp_socket->tcp_control.send_nxt += sent_bytes;
current_tcp_socket->tcp_control.send_wnd -= sent_bytes;
printf("Sent bytes: %li\n", sent_bytes);
// printf("Sent bytes: %li\n", sent_bytes);
if (send_tcp(current_int_tcp_socket, current_tcp_packet, temp_ipv6_header, 0, sent_bytes) != 1)
{
// Error while sending tcp data
@ -665,13 +667,13 @@ int32_t send(int s, void *msg, uint64_t len, int flags)
// Remember current time
current_tcp_socket->tcp_control.last_packet_time = vtimer_now();
printf("Waiting for Message in send()!\n");
// printf("Waiting for Message in send()!\n");
net_msg_receive(&recv_msg);
switch (recv_msg.type)
{
case TCP_ACK:
{
printf("Got ACK in send()!\n");
// printf("Got ACK in send()!\n");
tcp_hdr_t *tcp_header = ((tcp_hdr_t*)(recv_msg.content.ptr));
if ((current_tcp_socket->tcp_control.send_nxt == tcp_header->ack_nr) && (total_sent_bytes == len))
{
@ -679,7 +681,7 @@ int32_t send(int s, void *msg, uint64_t len, int flags)
current_tcp_socket->tcp_control.send_nxt = tcp_header->ack_nr;
current_tcp_socket->tcp_control.send_wnd = tcp_header->window;
// Got ACK for every sent byte
printf("Everything sent, returning!\n");
// printf("Everything sent, returning!\n");
#ifdef TCP_HC
current_tcp_socket->tcp_control.tcp_context.hc_type = COMPRESSED_HEADER;
#endif

View File

@ -14,7 +14,7 @@
#include "in.h"
#include "sys/net/sixlowpan/sixlowip.h"
#define TCP_HC
//#define TCP_HC
/*
* Types

View File

@ -123,7 +123,7 @@ void handle_tcp_ack_packet(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header, socke
{
if (check_tcp_consistency(&tcp_socket->socket_values, tcp_header) == PACKET_OK)
{
printf("Packet consistency OK!\n");
// printf("Packet consistency OK!\n");
m_send_tcp.content.ptr = (char*)tcp_header;
net_msg_send(&m_send_tcp, tcp_socket->send_pid, 0, TCP_ACK);
return;
@ -232,9 +232,7 @@ void handle_tcp_no_flags_packet(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header,
if (tcp_payload_len > 0)
{
#ifdef TCP_HC
current_tcp_socket->tcp_control.tcp_context.hc_type = COMPRESSED_HEADER;
#endif
if (check_tcp_consistency(current_tcp_socket, tcp_header) == PACKET_OK)
{
read_bytes = handle_payload(ipv6_header, tcp_header, tcp_socket, payload);
@ -248,14 +246,21 @@ void handle_tcp_no_flags_packet(ipv6_hdr_t *ipv6_header, tcp_hdr_t *tcp_header,
current_tcp_socket->tcp_control.send_nxt,
current_tcp_socket->tcp_control.send_una,
current_tcp_socket->tcp_control.send_wnd);
// Send packet
block_continue_thread();
#ifdef TCP_HC
current_tcp_socket->tcp_control.tcp_context.hc_type = COMPRESSED_HEADER;
#endif
send_tcp(tcp_socket, current_tcp_packet, temp_ipv6_header, TCP_ACK, 0);
}
// ACK packet probably got lost
else
{
block_continue_thread();
#ifdef TCP_HC
current_tcp_socket->tcp_control.tcp_context.hc_type = MOSTLY_COMPRESSED_HEADER;
#endif
send_tcp(tcp_socket, current_tcp_packet, temp_ipv6_header, TCP_ACK, 0);
}
}
@ -276,7 +281,7 @@ void tcp_packet_handler (void)
ipv6_header = ((ipv6_hdr_t*)m_recv_ip.content.ptr);
tcp_header = ((tcp_hdr_t*)(m_recv_ip.content.ptr + IPV6_HDR_LEN));
printArrayRange(((uint8_t *)ipv6_header), IPV6_HDR_LEN+ipv6_header->length, "Incoming");
// printArrayRange(((uint8_t *)ipv6_header), IPV6_HDR_LEN+ipv6_header->length, "Incoming");
#ifdef TCP_HC
tcp_socket = decompress_tcp_packet(ipv6_header);
#else
@ -288,7 +293,7 @@ void tcp_packet_handler (void)
payload = (uint8_t*)(m_recv_ip.content.ptr + IPV6_HDR_LEN + tcp_header->dataOffset_reserved*4);
print_tcp_status(INC_PACKET, ipv6_header, tcp_header, &tcp_socket->socket_values);
// print_tcp_status(INC_PACKET, ipv6_header, tcp_header, &tcp_socket->socket_values);
if ((chksum == 0xffff) && (tcp_socket != NULL))
{
@ -351,7 +356,7 @@ void tcp_packet_handler (void)
{
printf("Wrong checksum (%x) or no corresponding socket found!\n", chksum);
// printArrayRange(((uint8_t *)ipv6_header), IPV6_HDR_LEN+ipv6_header->length, "Incoming");
// print_tcp_status(INC_PACKET, ipv6_header, tcp_header, &tcp_socket->socket_values);
print_tcp_status(INC_PACKET, ipv6_header, tcp_header, &tcp_socket->socket_values);
}
msg_reply(&m_recv_ip, &m_send_ip);

View File

@ -8,7 +8,7 @@
#ifndef TCP_H_
#define TCP_H_
#define TCP_HC
//#define TCP_HC
#define TCP_HDR_LEN 20
@ -57,12 +57,12 @@ enum tcp_codes
#define REMOVE_RESERVED 0xFC
#define IS_TCP_ACK(a) ((a & TCP_ACK) > 0) // Test for ACK flag only, ignore URG und PSH flag
#define IS_TCP_RST(a) ((a & TCP_RST) > 0)
#define IS_TCP_SYN(a) ((a & TCP_SYN) > 0)
#define IS_TCP_SYN_ACK(a) ((a & TCP_SYN_ACK) > 0)
#define IS_TCP_FIN(a) ((a & TCP_FIN) > 0)
#define IS_TCP_FIN_ACK(a) ((a & TCP_FIN_ACK) > 0)
#define IS_TCP_ACK(a) ((a & TCP_ACK) == TCP_ACK) // Test for ACK flag only, ignore URG und PSH flag
#define IS_TCP_RST(a) ((a & TCP_RST) == TCP_RST)
#define IS_TCP_SYN(a) ((a & TCP_SYN) == TCP_SYN)
#define IS_TCP_SYN_ACK(a) ((a & TCP_SYN_ACK) == TCP_SYN_ACK)
#define IS_TCP_FIN(a) ((a & TCP_FIN) == TCP_FIN)
#define IS_TCP_FIN_ACK(a) ((a & TCP_FIN_ACK) == TCP_FIN_ACK)
#define SET_TCP_ACK(a) a = ((a & 0x00) | TCP_ACK)
#define SET_TCP_RST(a) a = ((a & 0x00) | TCP_RST)

View File

@ -58,7 +58,7 @@ uint16_t compress_tcp_packet(socket_internal_t *current_socket, uint8_t *current
tcp_cb_t *tcp_cb = &current_tcp_socket->tcp_control;
tcp_hdr_t full_tcp_header;
uint16_t packet_size = 0;
// printArrayRange(((uint8_t *)temp_ipv6_header), IPV6_HDR_LEN+temp_ipv6_header->length, "Outgoing");
// Connection establisment phase, use FULL_HEADER TCP
if (tcp_cb->state != ESTABLISHED)
{
@ -80,10 +80,11 @@ uint16_t compress_tcp_packet(socket_internal_t *current_socket, uint8_t *current
// Update the tcp context fields
update_tcp_hc_context(false, current_socket, (tcp_hdr_t *)(current_tcp_packet+3));
print_tcp_status(OUT_PACKET, temp_ipv6_header, (tcp_hdr_t *)(current_tcp_packet+3), current_tcp_socket);
// print_tcp_status(OUT_PACKET, temp_ipv6_header, (tcp_hdr_t *)(current_tcp_packet+3), current_tcp_socket);
// Convert TCP packet to network byte order
switch_tcp_packet_byte_order((tcp_hdr_t *)(current_tcp_packet+3));
// printArrayRange(((uint8_t *)temp_ipv6_header), IPV6_HDR_LEN+temp_ipv6_header->length, "Outgoing1");
return packet_size;
}
@ -275,7 +276,10 @@ uint16_t compress_tcp_packet(socket_internal_t *current_socket, uint8_t *current
packet_size += payload_length;
update_tcp_hc_context(false, current_socket, &full_tcp_header);
print_tcp_status(OUT_PACKET, temp_ipv6_header, &full_tcp_header, current_tcp_socket);
// print_tcp_status(OUT_PACKET, temp_ipv6_header, &full_tcp_header, current_tcp_socket);
// printf("packet Size2: %u\n", packet_size);
return packet_size;
}
// Check for header compression type: MOSTLY_COMPRESSED_HEADER
@ -369,10 +373,11 @@ uint16_t compress_tcp_packet(socket_internal_t *current_socket, uint8_t *current
// Adding TCP payload length to TCP_HC header length
packet_size += payload_length;
printf("TCP Payload length: %u\n", payload_length);
// printf("packet Size2: %u\n", packet_size);
update_tcp_hc_context(false, current_socket, &full_tcp_header);
print_tcp_status(OUT_PACKET, temp_ipv6_header, &full_tcp_header, current_tcp_socket);
// print_tcp_status(OUT_PACKET, temp_ipv6_header, &full_tcp_header, current_tcp_socket);
// printArrayRange(((uint8_t *)temp_ipv6_header), IPV6_HDR_LEN+temp_ipv6_header->length, "Outgoing3");
return packet_size;
}
return 0;
@ -384,7 +389,7 @@ socket_internal_t *decompress_tcp_packet(ipv6_hdr_t *temp_ipv6_header)
uint16_t tcp_hc_header;
socket_internal_t *current_socket = NULL;
uint16_t packet_size = 0;
// printArrayRange(((uint8_t *)temp_ipv6_header), IPV6_HDR_LEN+temp_ipv6_header->length, "Incoming");
// Full header TCP segment
if (*(((uint8_t *)temp_ipv6_header)+IPV6_HDR_LEN) == 0x01)
{
@ -599,7 +604,7 @@ socket_internal_t *decompress_tcp_packet(ipv6_hdr_t *temp_ipv6_header)
// Set IPV6 header length
temp_ipv6_header->length = temp_ipv6_header->length - packet_size + TCP_HDR_LEN;
// printArrayRange(((uint8_t *)temp_ipv6_header), IPV6_HDR_LEN+temp_ipv6_header->length, "Incoming");
return current_socket;
}
}

View File

@ -8,7 +8,7 @@
#ifndef TCP_HC_H_
#define TCP_HC_H_
#define TCP_HC
//#define TCP_HC
#include "tcp.h"
#include "sys/net/sixlowpan/sixlowip.h"

View File

@ -48,7 +48,8 @@ void handle_established(socket_internal_t *current_socket)
msg_t send;
uint32_t current_timeout = TCP_ACK_TIMEOUT;
uint8_t i;
if (current_socket->socket_values.tcp_control.send_nxt > current_socket->socket_values.tcp_control.send_una)
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++)
{
@ -64,7 +65,10 @@ void handle_established(socket_internal_t *current_socket)
{
current_socket->socket_values.tcp_control.no_of_retry++;
net_msg_send(&send, current_socket->send_pid, 0, TCP_RETRY);
printf("GOT NO ACK YET, %i. RETRY!\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_retry,
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);
}
}
}

View File

@ -19,7 +19,7 @@ void printArrayRange(uint8_t *array, uint16_t len, char *str)
{
printf("%#x ", *(array+i));
}
printf("\n--------------------------\n");
printf("\n-----------%u-------------\n", len);
}
uint16_t csum(uint16_t sum, uint8_t *buf, uint16_t len)