Merge pull request #12966 from gschorcht/tests/lwip_ipv4
tests/lwip: enable IPv4
This commit is contained in:
commit
f7d6dd2337
@ -1,10 +1,25 @@
|
|||||||
include ../Makefile.tests_common
|
include ../Makefile.tests_common
|
||||||
|
|
||||||
|
LWIP_IPV4 ?= 0
|
||||||
|
|
||||||
|
ifneq (0, $(LWIP_IPV4))
|
||||||
|
USEMODULE += ipv4_addr
|
||||||
|
USEMODULE += lwip_arp
|
||||||
|
USEMODULE += lwip_ipv4
|
||||||
|
USEMODULE += lwip_dhcp_auto
|
||||||
|
CFLAGS += -DETHARP_SUPPORT_STATIC_ENTRIES=1
|
||||||
|
LWIP_IPV6 ?= 0
|
||||||
|
else
|
||||||
|
USEMODULE += ipv6_addr
|
||||||
|
USEMODULE += lwip_ipv6
|
||||||
|
USEMODULE += lwip_ipv6_autoconfig
|
||||||
|
LWIP_IPV6 ?= 1
|
||||||
|
endif
|
||||||
|
|
||||||
# including lwip_ipv6_mld would currently break this test on at86rf2xx radios
|
# including lwip_ipv6_mld would currently break this test on at86rf2xx radios
|
||||||
USEMODULE += lwip lwip_ipv6_autoconfig lwip_sock_ip lwip_netdev
|
USEMODULE += lwip lwip_sock_ip lwip_netdev
|
||||||
USEMODULE += lwip_udp lwip_sock_udp
|
USEMODULE += lwip_udp lwip_sock_udp
|
||||||
USEMODULE += lwip_tcp lwip_sock_tcp
|
USEMODULE += lwip_tcp lwip_sock_tcp
|
||||||
USEMODULE += ipv6_addr
|
|
||||||
USEMODULE += shell
|
USEMODULE += shell
|
||||||
USEMODULE += shell_commands
|
USEMODULE += shell_commands
|
||||||
USEMODULE += ps
|
USEMODULE += ps
|
||||||
|
|||||||
@ -24,11 +24,18 @@
|
|||||||
#include "od.h"
|
#include "od.h"
|
||||||
#include "net/af.h"
|
#include "net/af.h"
|
||||||
#include "net/sock/ip.h"
|
#include "net/sock/ip.h"
|
||||||
#include "net/ipv6.h"
|
|
||||||
#include "shell.h"
|
#include "shell.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "xtimer.h"
|
#include "xtimer.h"
|
||||||
|
|
||||||
|
#ifdef MODULE_LWIP_IPV6
|
||||||
|
#include "net/ipv6.h"
|
||||||
|
#define SOCK_IP_EP_ANY SOCK_IPV6_EP_ANY
|
||||||
|
#else
|
||||||
|
#include "net/ipv4.h"
|
||||||
|
#define SOCK_IP_EP_ANY SOCK_IPV4_EP_ANY
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef MODULE_SOCK_IP
|
#ifdef MODULE_SOCK_IP
|
||||||
static char sock_inbuf[SOCK_INBUF_SIZE];
|
static char sock_inbuf[SOCK_INBUF_SIZE];
|
||||||
static bool server_running;
|
static bool server_running;
|
||||||
@ -38,7 +45,7 @@ static msg_t server_msg_queue[SERVER_MSG_QUEUE_SIZE];
|
|||||||
|
|
||||||
static void *_server_thread(void *args)
|
static void *_server_thread(void *args)
|
||||||
{
|
{
|
||||||
sock_ip_ep_t server_addr = SOCK_IPV6_EP_ANY;
|
sock_ip_ep_t server_addr = SOCK_IP_EP_ANY;
|
||||||
uint8_t protocol;
|
uint8_t protocol;
|
||||||
|
|
||||||
msg_init_queue(server_msg_queue, SERVER_MSG_QUEUE_SIZE);
|
msg_init_queue(server_msg_queue, SERVER_MSG_QUEUE_SIZE);
|
||||||
@ -63,9 +70,15 @@ static void *_server_thread(void *args)
|
|||||||
else {
|
else {
|
||||||
char addrstr[IPV6_ADDR_MAX_STR_LEN];
|
char addrstr[IPV6_ADDR_MAX_STR_LEN];
|
||||||
|
|
||||||
|
#ifdef MODULE_LWIP_IPV6
|
||||||
printf("Received IP data from [%s]:\n",
|
printf("Received IP data from [%s]:\n",
|
||||||
ipv6_addr_to_str(addrstr, (ipv6_addr_t *)&src.addr.ipv6,
|
ipv6_addr_to_str(addrstr, (ipv6_addr_t *)&src.addr.ipv6,
|
||||||
sizeof(addrstr)));
|
sizeof(addrstr)));
|
||||||
|
#else
|
||||||
|
printf("Received IP data from [%s]:\n",
|
||||||
|
ipv4_addr_to_str(addrstr, (ipv4_addr_t *)&src.addr.ipv4,
|
||||||
|
sizeof(addrstr)));
|
||||||
|
#endif
|
||||||
od_hex_dump(sock_inbuf, res, 0);
|
od_hex_dump(sock_inbuf, res, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -75,13 +88,17 @@ static void *_server_thread(void *args)
|
|||||||
static int ip_send(char *addr_str, char *port_str, char *data, unsigned int num,
|
static int ip_send(char *addr_str, char *port_str, char *data, unsigned int num,
|
||||||
unsigned int delay)
|
unsigned int delay)
|
||||||
{
|
{
|
||||||
sock_ip_ep_t dst = SOCK_IPV6_EP_ANY;
|
sock_ip_ep_t dst = SOCK_IP_EP_ANY;
|
||||||
uint8_t protocol;
|
uint8_t protocol;
|
||||||
uint8_t byte_data[SHELL_DEFAULT_BUFSIZE / 2];
|
uint8_t byte_data[SHELL_DEFAULT_BUFSIZE / 2];
|
||||||
size_t data_len;
|
size_t data_len;
|
||||||
|
|
||||||
/* parse destination address */
|
/* parse destination address */
|
||||||
|
#ifdef MODULE_LWIP_IPV6
|
||||||
if (ipv6_addr_from_str((ipv6_addr_t *)&dst.addr.ipv6, addr_str) == NULL) {
|
if (ipv6_addr_from_str((ipv6_addr_t *)&dst.addr.ipv6, addr_str) == NULL) {
|
||||||
|
#else
|
||||||
|
if (ipv4_addr_from_str((ipv4_addr_t *)&dst.addr.ipv4, addr_str) == NULL) {
|
||||||
|
#endif
|
||||||
puts("Error: unable to parse destination address");
|
puts("Error: unable to parse destination address");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -98,8 +115,13 @@ static int ip_send(char *addr_str, char *port_str, char *data, unsigned int num,
|
|||||||
puts("could not send");
|
puts("could not send");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
#ifdef MODULE_LWIP_IPV6
|
||||||
printf("Success: send %u byte over IPv6 to %s (next header: %u)\n",
|
printf("Success: send %u byte over IPv6 to %s (next header: %u)\n",
|
||||||
(unsigned)data_len, addr_str, protocol);
|
(unsigned)data_len, addr_str, protocol);
|
||||||
|
#else
|
||||||
|
printf("Success: send %u byte over IPv4 to %s (next header: %u)\n",
|
||||||
|
(unsigned)data_len, addr_str, protocol);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
xtimer_usleep(delay);
|
xtimer_usleep(delay);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,7 +25,11 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "lwip.h"
|
#include "lwip.h"
|
||||||
#include "lwip/netif.h"
|
#include "lwip/netif.h"
|
||||||
|
#if LWIP_IPV4
|
||||||
#include "net/ipv6/addr.h"
|
#include "net/ipv6/addr.h"
|
||||||
|
#else
|
||||||
|
#include "net/ipv4/addr.h"
|
||||||
|
#endif
|
||||||
#include "shell.h"
|
#include "shell.h"
|
||||||
|
|
||||||
static int ifconfig(int argc, char **argv)
|
static int ifconfig(int argc, char **argv)
|
||||||
@ -42,6 +46,11 @@ static int ifconfig(int argc, char **argv)
|
|||||||
sizeof(addrstr)));
|
sizeof(addrstr)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef MODULE_LWIP_IPV4
|
||||||
|
char addrstr[IPV4_ADDR_MAX_STR_LEN];
|
||||||
|
printf(" inet %s\n", ipv4_addr_to_str(addrstr, (ipv4_addr_t *)&iface->ip_addr,
|
||||||
|
sizeof(addrstr)));
|
||||||
#endif
|
#endif
|
||||||
puts("");
|
puts("");
|
||||||
}
|
}
|
||||||
@ -61,6 +70,7 @@ static const shell_command_t shell_commands[] = {
|
|||||||
{ "ifconfig", "Shows assigned IPv6 addresses", ifconfig },
|
{ "ifconfig", "Shows assigned IPv6 addresses", ifconfig },
|
||||||
{ NULL, NULL, NULL }
|
{ NULL, NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
static char line_buf[SHELL_DEFAULT_BUFSIZE];
|
static char line_buf[SHELL_DEFAULT_BUFSIZE];
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
|
|||||||
@ -24,11 +24,18 @@
|
|||||||
#include "od.h"
|
#include "od.h"
|
||||||
#include "net/af.h"
|
#include "net/af.h"
|
||||||
#include "net/sock/tcp.h"
|
#include "net/sock/tcp.h"
|
||||||
#include "net/ipv6.h"
|
|
||||||
#include "shell.h"
|
#include "shell.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "xtimer.h"
|
#include "xtimer.h"
|
||||||
|
|
||||||
|
#ifdef MODULE_LWIP_IPV6
|
||||||
|
#include "net/ipv6.h"
|
||||||
|
#define SOCK_IP_EP_ANY SOCK_IPV6_EP_ANY
|
||||||
|
#else
|
||||||
|
#include "net/ipv4.h"
|
||||||
|
#define SOCK_IP_EP_ANY SOCK_IPV4_EP_ANY
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef MODULE_SOCK_TCP
|
#ifdef MODULE_SOCK_TCP
|
||||||
static char sock_inbuf[SOCK_INBUF_SIZE];
|
static char sock_inbuf[SOCK_INBUF_SIZE];
|
||||||
static bool server_running = false, client_running = false;
|
static bool server_running = false, client_running = false;
|
||||||
@ -39,7 +46,7 @@ static msg_t server_msg_queue[SERVER_MSG_QUEUE_SIZE];
|
|||||||
|
|
||||||
static void *_server_thread(void *args)
|
static void *_server_thread(void *args)
|
||||||
{
|
{
|
||||||
sock_tcp_ep_t server_addr = SOCK_IPV6_EP_ANY;
|
sock_tcp_ep_t server_addr = SOCK_IP_EP_ANY;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
msg_init_queue(server_msg_queue, SERVER_MSG_QUEUE_SIZE);
|
msg_init_queue(server_msg_queue, SERVER_MSG_QUEUE_SIZE);
|
||||||
@ -68,8 +75,13 @@ static void *_server_thread(void *args)
|
|||||||
sock_tcp_ep_t client;
|
sock_tcp_ep_t client;
|
||||||
|
|
||||||
sock_tcp_get_remote(sock, &client);
|
sock_tcp_get_remote(sock, &client);
|
||||||
|
#ifdef MODULE_LWIP_IPV6
|
||||||
ipv6_addr_to_str(client_addr, (ipv6_addr_t *)&client.addr.ipv6,
|
ipv6_addr_to_str(client_addr, (ipv6_addr_t *)&client.addr.ipv6,
|
||||||
sizeof(client_addr));
|
sizeof(client_addr));
|
||||||
|
#else
|
||||||
|
ipv4_addr_to_str(client_addr, (ipv4_addr_t *)&client.addr.ipv4,
|
||||||
|
sizeof(client_addr));
|
||||||
|
#endif
|
||||||
client_port = client.port;
|
client_port = client.port;
|
||||||
printf("TCP client [%s]:%u connected\n",
|
printf("TCP client [%s]:%u connected\n",
|
||||||
client_addr, client_port);
|
client_addr, client_port);
|
||||||
@ -96,7 +108,7 @@ static void *_server_thread(void *args)
|
|||||||
|
|
||||||
static int tcp_connect(char *addr_str, char *port_str, char *local_port_str)
|
static int tcp_connect(char *addr_str, char *port_str, char *local_port_str)
|
||||||
{
|
{
|
||||||
sock_tcp_ep_t dst = SOCK_IPV6_EP_ANY;
|
sock_tcp_ep_t dst = SOCK_IP_EP_ANY;
|
||||||
uint16_t local_port = 0;
|
uint16_t local_port = 0;
|
||||||
|
|
||||||
if (client_running) {
|
if (client_running) {
|
||||||
@ -104,7 +116,11 @@ static int tcp_connect(char *addr_str, char *port_str, char *local_port_str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* parse destination address */
|
/* parse destination address */
|
||||||
|
#ifdef MODULE_LWIP_IPV6
|
||||||
if (ipv6_addr_from_str((ipv6_addr_t *)&dst.addr.ipv6, addr_str) == NULL) {
|
if (ipv6_addr_from_str((ipv6_addr_t *)&dst.addr.ipv6, addr_str) == NULL) {
|
||||||
|
#else
|
||||||
|
if (ipv4_addr_from_str((ipv4_addr_t *)&dst.addr.ipv4, addr_str) == NULL) {
|
||||||
|
#endif
|
||||||
puts("Error: unable to parse destination address");
|
puts("Error: unable to parse destination address");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,11 +24,18 @@
|
|||||||
#include "od.h"
|
#include "od.h"
|
||||||
#include "net/af.h"
|
#include "net/af.h"
|
||||||
#include "net/sock/udp.h"
|
#include "net/sock/udp.h"
|
||||||
#include "net/ipv6.h"
|
|
||||||
#include "shell.h"
|
#include "shell.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "xtimer.h"
|
#include "xtimer.h"
|
||||||
|
|
||||||
|
#ifdef MODULE_LWIP_IPV6
|
||||||
|
#include "net/ipv6.h"
|
||||||
|
#define SOCK_IP_EP_ANY SOCK_IPV6_EP_ANY
|
||||||
|
#else
|
||||||
|
#include "net/ipv4.h"
|
||||||
|
#define SOCK_IP_EP_ANY SOCK_IPV4_EP_ANY
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef MODULE_SOCK_UDP
|
#ifdef MODULE_SOCK_UDP
|
||||||
static char sock_inbuf[SOCK_INBUF_SIZE];
|
static char sock_inbuf[SOCK_INBUF_SIZE];
|
||||||
static bool server_running;
|
static bool server_running;
|
||||||
@ -38,7 +45,7 @@ static msg_t server_msg_queue[SERVER_MSG_QUEUE_SIZE];
|
|||||||
|
|
||||||
static void *_server_thread(void *args)
|
static void *_server_thread(void *args)
|
||||||
{
|
{
|
||||||
sock_udp_ep_t server_addr = SOCK_IPV6_EP_ANY;
|
sock_udp_ep_t server_addr = SOCK_IP_EP_ANY;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
msg_init_queue(server_msg_queue, SERVER_MSG_QUEUE_SIZE);
|
msg_init_queue(server_msg_queue, SERVER_MSG_QUEUE_SIZE);
|
||||||
@ -66,9 +73,15 @@ static void *_server_thread(void *args)
|
|||||||
else {
|
else {
|
||||||
char addrstr[IPV6_ADDR_MAX_STR_LEN];
|
char addrstr[IPV6_ADDR_MAX_STR_LEN];
|
||||||
|
|
||||||
|
#ifdef MODULE_LWIP_IPV6
|
||||||
printf("Received UDP data from [%s]:%" PRIu16 ":\n",
|
printf("Received UDP data from [%s]:%" PRIu16 ":\n",
|
||||||
ipv6_addr_to_str(addrstr, (ipv6_addr_t *)&src.addr.ipv6,
|
ipv6_addr_to_str(addrstr, (ipv6_addr_t *)&src.addr.ipv6,
|
||||||
sizeof(addrstr)), src.port);
|
sizeof(addrstr)), src.port);
|
||||||
|
#else
|
||||||
|
printf("Received UDP data from [%s]:%" PRIu16 ":\n",
|
||||||
|
ipv4_addr_to_str(addrstr, (ipv4_addr_t *)&src.addr.ipv4,
|
||||||
|
sizeof(addrstr)), src.port);
|
||||||
|
#endif
|
||||||
od_hex_dump(sock_inbuf, res, 0);
|
od_hex_dump(sock_inbuf, res, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -78,12 +91,16 @@ static void *_server_thread(void *args)
|
|||||||
static int udp_send(char *addr_str, char *port_str, char *data, unsigned int num,
|
static int udp_send(char *addr_str, char *port_str, char *data, unsigned int num,
|
||||||
unsigned int delay)
|
unsigned int delay)
|
||||||
{
|
{
|
||||||
sock_udp_ep_t dst = SOCK_IPV6_EP_ANY;
|
sock_udp_ep_t dst = SOCK_IP_EP_ANY;
|
||||||
uint8_t byte_data[SHELL_DEFAULT_BUFSIZE / 2];
|
uint8_t byte_data[SHELL_DEFAULT_BUFSIZE / 2];
|
||||||
size_t data_len;
|
size_t data_len;
|
||||||
|
|
||||||
/* parse destination address */
|
/* parse destination address */
|
||||||
|
#ifdef MODULE_LWIP_IPV6
|
||||||
if (ipv6_addr_from_str((ipv6_addr_t *)&dst.addr.ipv6, addr_str) == NULL) {
|
if (ipv6_addr_from_str((ipv6_addr_t *)&dst.addr.ipv6, addr_str) == NULL) {
|
||||||
|
#else
|
||||||
|
if (ipv4_addr_from_str((ipv4_addr_t *)&dst.addr.ipv4, addr_str) == NULL) {
|
||||||
|
#endif
|
||||||
puts("Error: unable to parse destination address");
|
puts("Error: unable to parse destination address");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user