From 5bc1d919279a4c93cca3f0e97dac523a910efa1a Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Mon, 13 May 2024 14:58:35 +0200 Subject: [PATCH] [DROP ME] examples/gnrc_networking: add fragmentation test --- examples/gnrc_networking/Makefile | 14 +++++--- examples/gnrc_networking/main.c | 56 +++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 4 deletions(-) diff --git a/examples/gnrc_networking/Makefile b/examples/gnrc_networking/Makefile index 555b89eee55e2..736f4b5274115 100644 --- a/examples/gnrc_networking/Makefile +++ b/examples/gnrc_networking/Makefile @@ -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 @@ -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 diff --git a/examples/gnrc_networking/main.c b/examples/gnrc_networking/main.c index 734ae420671ea..b3b2a71830e6b 100644 --- a/examples/gnrc_networking/main.c +++ b/examples/gnrc_networking/main.c @@ -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 \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