Skip to content

Commit

Permalink
[DROP ME] examples/gnrc_networking: add fragmentation test
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed May 13, 2024
1 parent d77c5b9 commit 5bc1d91
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 4 deletions.
14 changes: 10 additions & 4 deletions examples/gnrc_networking/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ USEMODULE += auto_init_gnrc_netif
# Activate ICMPv6 error messages
USEMODULE += gnrc_icmpv6_error
# Specify the mandatory networking module for a IPv6 routing node
USEMODULE += gnrc_ipv6_router_default
USEMODULE += gnrc_ipv6_default
# Add a routing protocol
USEMODULE += gnrc_rpl
USEMODULE += auto_init_gnrc_rpl
#USEMODULE += gnrc_rpl
#USEMODULE += auto_init_gnrc_rpl
# Additional networking modules that can be dropped if not needed
USEMODULE += gnrc_icmpv6_echo
USEMODULE += shell_cmd_gnrc_udp
Expand All @@ -27,7 +27,13 @@ USEMODULE += shell_cmds_default
USEMODULE += ps
USEMODULE += netstats_l2
USEMODULE += netstats_ipv6
USEMODULE += netstats_rpl

USEMODULE += sock_udp
USEMODULE += gnrc_ipv6_ext_frag
USEMODULE += gnrc_netif_single
USEMODULE += gnrc_netif_pktq
CFLAGS += -DCONFIG_GNRC_PKTBUF_SIZE=65536


# Optionally include DNS support. This includes resolution of names at an
# upstream DNS server and the handling of RDNSS options in Router Advertisements
Expand Down
56 changes: 56 additions & 0 deletions examples/gnrc_networking/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,62 @@
#define MAIN_QUEUE_SIZE (8)
static msg_t _main_msg_queue[MAIN_QUEUE_SIZE];

#include "net/sock/udp.h"

static void _fill_buffer(void *buffer, size_t len)
{
void *end = (char *)buffer + len;
uint16_t *b16 = buffer;
uint16_t count = 0;
while ((void *)b16 < end) {
*b16++ = count++;
}
}

static int _udp_cmd(int argc, char **argv)
{
if (argc < 2) {
goto usage;
}

int len = atoi(argv[1]);
if (!len) {
goto usage;
}

if (len & 1) {
++len;
}

static uint8_t _buf[65536];
if (len > (int)sizeof(_buf)) {
puts("too big");
return -ENOBUFS;
}

const sock_udp_ep_t remote = {
.family = AF_INET6,
.addr = IPV6_ADDR_ALL_NODES_LINK_LOCAL,
.port = 1234,
};

_fill_buffer(_buf, len);
int res = sock_udp_send(NULL, _buf, len, &remote);
if (res > 0) {
printf("%d bytes sent\n", res);
} else {
printf("error: %d\n", -res);
}

return 0;

usage:
printf("usage: %s <bytes>\n", argv[0]);
return 1;
}

SHELL_COMMAND(udp2, "send large UDP packets", _udp_cmd);

int main(void)
{
/* we need a message queue for the thread running the shell in order to
Expand Down

0 comments on commit 5bc1d91

Please sign in to comment.