Skip to content

Commit

Permalink
transport_layer: Splitting UDP and TCP
Browse files Browse the repository at this point in the history
Currently, the tcp and udp implementations are bound to each other in a
module called *destiny*. Thus, when using only one of them then the
other one gets also compiled into the binary and initialized,
which results in unnecessary RAM usage and workload for the CPU.

The approach in this PR defines a common module named *socket_base*,
which contains functions used by the posix layer. Compiled by it's own,
those functions return negative error codes, to symbolize upper layers
that they are not supported. When also including the modules *udp* or
*tcp* respectively, functions from *socket_base* get overwritten with the
correct functionality.

Defining *udp* or *tcp* in a Makefile also includes *socket_base*.
Defining *pnet* in a Makefile also includes *socket_base*.
  • Loading branch information
cgundogan committed Aug 21, 2014
1 parent 8538670 commit dde327a
Show file tree
Hide file tree
Showing 41 changed files with 1,777 additions and 1,552 deletions.
17 changes: 15 additions & 2 deletions Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,24 @@ endif

ifneq (,$(filter pnet,$(USEMODULE)))
USEMODULE += posix
USEMODULE += destiny
USEMODULE += socket_base
USEMODULE += net_help
endif

ifneq (,$(filter destiny,$(USEMODULE)))
ifneq (,$(filter transport_layer,$(USEMODULE)))
USEMODULE += tcp
USEMODULE += udp
endif

ifneq (,$(filter udp,$(USEMODULE)))
USEMODULE += socket_base
endif

ifneq (,$(filter tcp,$(USEMODULE)))
USEMODULE += socket_base
endif

ifneq (,$(filter socket_base,$(USEMODULE)))
USEMODULE += sixlowpan
USEMODULE += net_help
USEMODULE += vtimer
Expand Down
1 change: 1 addition & 0 deletions Makefile.pseudomodules
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
PSEUDOMODULES += defaulttransceiver
PSEUDOMODULES += transport_layer
4 changes: 2 additions & 2 deletions examples/rpl_udp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ BOARD_BLACKLIST := arduino-due mbed_lpc1768 msb-430 pttu udoo qemu-i386 stm32f0d

USEMODULE += shell
USEMODULE += shell_commands
USEMODULE += posix
USEMODULE += ps
USEMODULE += vtimer
USEMODULE += defaulttransceiver
USEMODULE += rpl
USEMODULE += destiny
USEMODULE += pnet
USEMODULE += udp

include $(RIOTBASE)/Makefile.include
2 changes: 1 addition & 1 deletion examples/rpl_udp/demo.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

/* RPL shell command handlers */
/**
* @brief Shell command to initializes RPL and Destiny
* @brief Shell command to initializes RPL and the transport layer
*/
void rpl_udp_init(int argc, char **argv);

Expand Down
2 changes: 1 addition & 1 deletion examples/rpl_udp/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "shell.h"
#include "shell_commands.h"
#include "board_uart0.h"
#include "destiny.h"
#include "udp.h"

#include "demo.h"

Expand Down
4 changes: 2 additions & 2 deletions examples/rpl_udp/rpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "thread.h"
#include "net_if.h"
#include "sixlowpan.h"
#include "destiny.h"
#include "udp.h"
#include "rpl.h"
#include "rpl_dodag.h"
#include "demo.h"
Expand Down Expand Up @@ -125,7 +125,7 @@ void rpl_udp_init(int argc, char **argv)
msg_send_receive(&m, &m, transceiver_pid);
printf("Channel set to %u\n", RADIO_CHANNEL);

puts("Destiny initialized");
puts("Transport Layer initialized");
/* start transceiver watchdog */
}

Expand Down
18 changes: 9 additions & 9 deletions examples/rpl_udp/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#include "thread.h"

#include "destiny/socket.h"
#include "socket_base/socket.h"

#include "net_help.h"

Expand Down Expand Up @@ -63,7 +63,7 @@ static void *init_udp_server(void *arg)
char buffer_main[UDP_BUFFER_SIZE];
int32_t recsize;
uint32_t fromlen;
int sock = destiny_socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP);
int sock = transport_layer_socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP);

memset(&sa, 0, sizeof(sa));

Expand All @@ -72,13 +72,13 @@ static void *init_udp_server(void *arg)

fromlen = sizeof(sa);

if (-1 == destiny_socket_bind(sock, &sa, sizeof(sa))) {
if (-1 == transport_layer_socket_bind(sock, &sa, sizeof(sa))) {
printf("Error bind failed!\n");
destiny_socket_close(sock);
transport_layer_socket_close(sock);
}

while (1) {
recsize = destiny_socket_recvfrom(sock, (void *)buffer_main, UDP_BUFFER_SIZE, 0,
recsize = transport_layer_socket_recvfrom(sock, (void *)buffer_main, UDP_BUFFER_SIZE, 0,
&sa, &fromlen);

if (recsize < 0) {
Expand All @@ -88,7 +88,7 @@ static void *init_udp_server(void *arg)
printf("UDP packet received, payload: %s\n", buffer_main);
}

destiny_socket_close(sock);
transport_layer_socket_close(sock);

return NULL;
}
Expand All @@ -113,7 +113,7 @@ void udp_send(int argc, char **argv)
strncpy(text, argv[2], sizeof(text));
text[sizeof(text) - 1] = 0;

sock = destiny_socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP);
sock = transport_layer_socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP);

if (-1 == sock) {
printf("Error Creating Socket!");
Expand All @@ -128,7 +128,7 @@ void udp_send(int argc, char **argv)
memcpy(&sa.sin6_addr, &ipaddr, 16);
sa.sin6_port = HTONS(SERVER_PORT);

bytes_sent = destiny_socket_sendto(sock, (char *)text,
bytes_sent = transport_layer_socket_sendto(sock, (char *)text,
strlen(text) + 1, 0, &sa,
sizeof(sa));

Expand All @@ -141,5 +141,5 @@ void udp_send(int argc, char **argv)
&ipaddr));
}

destiny_socket_close(sock);
transport_layer_socket_close(sock);
}
2 changes: 1 addition & 1 deletion pkg/libcoap/0001-Add-RIOT-Makefile.patch
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ index 0000000..f90baa1
+++ b/Makefile
@@ -0,0 +1,5 @@
+MODULE:=$(shell basename $(CURDIR))
+INCLUDES += -I$(RIOTBASE) -I$(RIOTBASE)/sys/include -I$(RIOTBASE)/core/include -I$(RIOTBASE)/drivers/include -I$(RIOTBASE)/drivers/cc110x_ng/include -I$(RIOTBASE)/cpu/arm_common/include -I$(RIOTBASE)/sys/net/destiny/include -I$(RIOTBASE)/sys/net/sixlowpan/include/ -I$(RIOTBASE)/sys/net/ieee802154/include -I$(RIOTBASE)/sys/net/net_help -I$(RIOTBASE)/sys/posix/include -I$(RIOTBASE)/sys/posix/pnet/include
+INCLUDES += -I$(RIOTBASE) -I$(RIOTBASE)/sys/include -I$(RIOTBASE)/core/include -I$(RIOTBASE)/drivers/include -I$(RIOTBASE)/drivers/cc110x_ng/include -I$(RIOTBASE)/cpu/arm_common/include -I$(RIOTBASE)/sys/net/transport_layer/include -I$(RIOTBASE)/sys/net/sixlowpan/include/ -I$(RIOTBASE)/sys/net/ieee802154/include -I$(RIOTBASE)/sys/net/net_help -I$(RIOTBASE)/sys/posix/include -I$(RIOTBASE)/sys/posix/pnet/include
+CFLAGS += -DWITH_POSIX
+
+include $(RIOTBASE)/Makefile.base
Expand Down
4 changes: 2 additions & 2 deletions pkg/oonf_api/0001-add-RIOT-support.patch
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ index 78fd5b4..cfba7a9 100644
#endif

+#ifdef RIOT
+#include "destiny/socket.h"
+#include "transport_layer/socket.h"
+#define INET_ADDRSTRLEN (16)
+#define INET6_ADDRSTRLEN (48)
+#endif
Expand Down Expand Up @@ -466,7 +466,7 @@ index 4b3e04d..6b52f72 100644
#include <stdio.h>
#include <stdlib.h>
+#ifdef RIOT
+#include "destiny/socket.h"
+#include "transport_layer/socket.h"
+#include "inet_ntop.h"
+#else
#include <sys/socket.h>
Expand Down
17 changes: 15 additions & 2 deletions sys/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,21 @@ endif
ifneq (,$(filter net_if,$(USEMODULE)))
DIRS += net/link_layer/net_if
endif
ifneq (,$(filter destiny,$(USEMODULE)))
DIRS += net/transport_layer/destiny
ifneq (,$(filter transport_layer,$(USEMODULE)))
DIRS += net/transport_layer/socket_base
DIRS += net/transport_layer/tcp
DIRS += net/transport_layer/udp
endif
ifneq (,$(filter socket_base,$(USEMODULE)))
DIRS += net/transport_layer/socket_base
endif
ifneq (,$(filter udp,$(USEMODULE)))
DIRS += net/transport_layer/socket_base
DIRS += net/transport_layer/udp
endif
ifneq (,$(filter tcp,$(USEMODULE)))
DIRS += net/transport_layer/socket_base
DIRS += net/transport_layer/tcp
endif
ifneq (,$(filter net_help,$(USEMODULE)))
DIRS += net/crosslayer/net_help
Expand Down
13 changes: 12 additions & 1 deletion sys/Makefile.include
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
ifneq (,$(filter destiny,$(USEMODULE)))
ifneq (,$(filter transport_layer,$(USEMODULE)))
USEMODULE_INCLUDES += $(RIOTBASE)/sys/net/include
endif
ifneq (,$(filter socket_base,$(USEMODULE)))
USEMODULE_INCLUDES += $(RIOTBASE)/sys/net/include
endif
ifneq (,$(filter tcp,$(USEMODULE)))
USEMODULE_INCLUDES += $(RIOTBASE)/sys/net/transport_layer/socket_base
USEMODULE_INCLUDES += $(RIOTBASE)/sys/net/include
endif
ifneq (,$(filter udp,$(USEMODULE)))
USEMODULE_INCLUDES += $(RIOTBASE)/sys/net/transport_layer/socket_base
USEMODULE_INCLUDES += $(RIOTBASE)/sys/net/include
endif
ifneq (,$(filter net_help,$(USEMODULE)))
Expand Down
19 changes: 14 additions & 5 deletions sys/auto_init/auto_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@
#include "sixlowpan.h"
#endif

#ifdef MODULE_DESTINY
#include "destiny.h"
#ifdef MODULE_UDP
#include "udp.h"
#endif

#ifdef MODULE_TCP
#include "tcp.h"
#endif

#ifdef MODULE_NET_IF
Expand Down Expand Up @@ -180,8 +184,13 @@ void auto_init(void)
extern void profiling_init(void);
profiling_init();
#endif
#ifdef MODULE_DESTINY
DEBUG("Auto init transport layer [destiny] module.\n");
destiny_init_transport_layer();
#ifdef MODULE_UDP
DEBUG("Auto init transport layer module: [udp].\n");
udp_init_transport_layer();
#endif

#ifdef MODULE_TCP
DEBUG("Auto init transport layer module: [tcp].\n");
tcp_init_transport_layer();
#endif
}
27 changes: 10 additions & 17 deletions sys/net/include/destiny.h → sys/net/include/socket_base.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* destiny.h - Wraps all API types, constants and functions of the transport
* socket_base.h - Wraps all API types, constants and functions of the transport
* layer implementation.
*
* Copyright (C) 2013 INRIA.
Expand All @@ -10,9 +10,9 @@
*/

/**
* @defgroup destiny DESTiny - Transport layer implementation
* @defgroup socket_base Transport layer implementation
* @ingroup net
* @brief DESTiny module implements the transport layer. This includes
* @brief This module implements the transport layer. This includes
* 6LoWPAN UDP header compression and (experimental) 6LoWPAN TCP header
* compression.
* @see <a href="http://tools.ietf.org/html/rfc6282#section-4.3">
Expand All @@ -25,23 +25,16 @@
* </a>
* @{
* @file
* @brief destiny functions
* @brief transport_layer functions
* @author Oliver Gesch <oliver.gesch@googlemail.com>
* @author Martin Lenders <mlenders@inf.fu-berlin.de>
*/

#ifndef DESTINY_H
#define DESTINY_H
#ifndef SOCKET_BASE_H
#define SOCKET_BASE_H

#include "destiny/in.h"
#include "destiny/socket.h"
#include "destiny/types.h"
#include "socket_base/in.h"
#include "socket_base/socket.h"
#include "socket_base/types.h"

/**
* Initializes transport layer.
*
* @return 0 on success, other else.
*/
int destiny_init_transport_layer(void);

#endif /* DESTINY_H */
#endif /* SOCKET_BASE_H */
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* destiny/in.h - Constants defined by the internet system, per RFC 790,
* socket_base/in.h - Constants defined by the internet system, per RFC 790,
* September 1981, and numerous additions, inspired by
* netinet/in.h definitions.
* @{
Expand All @@ -18,8 +18,8 @@
* @author Martin Lenders <mlenders@inf.fu-berlin.de>
*/

#ifndef DESTINY_IN_H
#define DESTINY_IN_H
#ifndef SOCKET_BASE_IN_H
#define SOCKET_BASE_IN_H

/*
* Protocols (RFC 1700) TODO: may be deleted due to some double definition
Expand Down Expand Up @@ -141,4 +141,4 @@

#define IN_LOOPBACKNET (127) ///< official!

#endif /* DESTINY_IN_H */
#endif /* SOCKET_BASE_IN_H */
Loading

0 comments on commit dde327a

Please sign in to comment.