Skip to content

Commit

Permalink
tests: add test application for CongURE implementations with SFR
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed May 6, 2021
1 parent 33e287a commit e7d6a44
Show file tree
Hide file tree
Showing 6 changed files with 355 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/gnrc_sixlowpan_frag_sfr_congure_impl/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
include ../Makefile.tests_common

USEMODULE += gnrc_netdev_default
USEMODULE += auto_init_gnrc_netif
USEMODULE += gnrc_ipv6_router_default
USEMODULE += gnrc_sixlowpan_frag_sfr
USEMODULE += gnrc_pktbuf_cmd
USEMODULE += gnrc_udp
USEMODULE += gnrc_rpl
USEMODULE += auto_init_gnrc_rpl
USEMODULE += gnrc_pktdump
USEMODULE += gnrc_icmpv6_echo
USEMODULE += shell
USEMODULE += shell_commands
USEMODULE += ps
USEMODULE += netstats_l2
USEMODULE += netstats_ipv6
USEMODULE += netstats_rpl

ifeq (,$(CONGURE_IMPL))
USEMODULE += gnrc_sixlowpan_frag_sfr_congure_sfr
else
ifeq (congure_sfr,$(CONGURE_IMPL))
USEMODULE += gnrc_sixlowpan_frag_sfr_congure_sfr
else
$(error "Unknown CongURE implementation `$(CONGURE_IMPL)`")
endif
endif

include $(RIOTBASE)/Makefile.include

# Set a custom channel if needed
include $(RIOTMAKE)/default-radio-settings.inc.mk
53 changes: 53 additions & 0 deletions tests/gnrc_sixlowpan_frag_sfr_congure_impl/Makefile.ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
BOARD_INSUFFICIENT_MEMORY := \
airfy-beacon \
arduino-duemilanove \
arduino-leonardo \
arduino-mega2560 \
arduino-nano \
arduino-uno \
atmega1284p \
atmega328p \
blackpill \
bluepill \
bluepill-stm32f030c8 \
calliope-mini \
derfmega128 \
hifive1 \
hifive1b \
i-nucleo-lrwan1 \
im880b \
mega-xplained \
microbit \
microduino-corerf \
msb-430 \
msb-430h \
nrf51dongle \
nrf6310 \
nucleo-f030r8 \
nucleo-f031k6 \
nucleo-f042k6 \
nucleo-f070rb \
nucleo-f072rb \
nucleo-f103rb \
nucleo-f302r8 \
nucleo-f303k8 \
nucleo-f334r8 \
nucleo-l011k4 \
nucleo-l031k6 \
nucleo-l053r8 \
samd10-xmini \
saml10-xpro \
saml11-xpro \
slstk3400a \
spark-core \
stk3200 \
stm32f030f4-demo \
stm32f0discovery \
stm32l0538-disco \
stm32mp157c-dk2 \
telosb \
waspmote-pro \
yunjia-nrf51822 \
z1 \
zigduino \
#
8 changes: 8 additions & 0 deletions tests/gnrc_sixlowpan_frag_sfr_congure_impl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
SFR CongURE implementation test
===============================
This test is largely based on the [`gnrc_networking`][1] example but is changed
so SFR with different CongURE implementations can be tested. When `CONGURE_IMPL`
is not set in the environment, `gnrc_sixlowpan_frag_sfr_congure_sfr` is used,
other implementations can be used with `congure_<impl>`.

[1]: https://github.com/RIOT-OS/RIOT/tree/master/examples/gnrc_networking
46 changes: 46 additions & 0 deletions tests/gnrc_sixlowpan_frag_sfr_congure_impl/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (C) 2015-21 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup tests
* @{
*
* @file
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
* @author Martine Lenders <m.lenders@fu-berlin.de>
*
* @}
*/

#include <stdio.h>

#include "fmt.h"
#include "shell.h"
#include "msg.h"

#define MAIN_QUEUE_SIZE (8)
static msg_t _main_msg_queue[MAIN_QUEUE_SIZE];

extern int udp_cmd(int argc, char **argv);

static const shell_command_t shell_commands[] = {
{ "udp", "send data over UDP and listen on UDP ports", udp_cmd },
{ NULL, NULL, NULL }
};

int main(void)
{
msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE);

char line_buf[SHELL_DEFAULT_BUFSIZE];
shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);

/* should be never reached */
return 0;
}
20 changes: 20 additions & 0 deletions tests/gnrc_sixlowpan_frag_sfr_congure_impl/tests/01-run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python3

# Copyright (C) 2021 Freie Universität Berlin
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.


import sys
from testrunner import run


def testfunc(child):
child.sendline('udp send fe80::1 1337 abcde')
child.expect_exact('Success: sent 5 byte(s) to [fe80::1]:1337')


if __name__ == "__main__":
sys.exit(run(testfunc))
195 changes: 195 additions & 0 deletions tests/gnrc_sixlowpan_frag_sfr_congure_impl/udp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
/*
* Copyright (C) 2015-17 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup examples
* @{
*
* @file
* @brief Demonstrating the sending and receiving of UDP data
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
* @author Martine Lenders <m.lenders@fu-berlin.de>
*
* @}
*/

#include <stdio.h>
#include <inttypes.h>

#include "net/gnrc.h"
#include "net/gnrc/ipv6.h"
#include "net/gnrc/netif.h"
#include "net/gnrc/netif/hdr.h"
#include "net/gnrc/udp.h"
#include "net/gnrc/pktdump.h"
#include "timex.h"
#include "utlist.h"
#include "xtimer.h"

static gnrc_netreg_entry_t server = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL,
KERNEL_PID_UNDEF);


static void send(char *addr_str, char *port_str, char *data, unsigned int num,
unsigned int delay)
{
gnrc_netif_t *netif = NULL;
char *iface;
uint16_t port;
ipv6_addr_t addr;

iface = ipv6_addr_split_iface(addr_str);
if ((!iface) && (gnrc_netif_numof() == 1)) {
netif = gnrc_netif_iter(NULL);
}
else if (iface) {
netif = gnrc_netif_get_by_pid(atoi(iface));
}

/* parse destination address */
if (ipv6_addr_from_str(&addr, addr_str) == NULL) {
puts("Error: unable to parse destination address");
return;
}
/* parse port */
port = atoi(port_str);
if (port == 0) {
puts("Error: unable to parse destination port");
return;
}

for (unsigned int i = 0; i < num; i++) {
gnrc_pktsnip_t *payload, *udp, *ip;
unsigned payload_size;
/* allocate payload */
payload = gnrc_pktbuf_add(NULL, data, strlen(data), GNRC_NETTYPE_UNDEF);
if (payload == NULL) {
puts("Error: unable to copy data to packet buffer");
return;
}
/* store size for output */
payload_size = (unsigned)payload->size;
/* allocate UDP header, set source port := destination port */
udp = gnrc_udp_hdr_build(payload, port, port);
if (udp == NULL) {
puts("Error: unable to allocate UDP header");
gnrc_pktbuf_release(payload);
return;
}
/* allocate IPv6 header */
ip = gnrc_ipv6_hdr_build(udp, NULL, &addr);
if (ip == NULL) {
puts("Error: unable to allocate IPv6 header");
gnrc_pktbuf_release(udp);
return;
}
/* add netif header, if interface was given */
if (netif != NULL) {
gnrc_pktsnip_t *netif_hdr = gnrc_netif_hdr_build(NULL, 0, NULL, 0);

gnrc_netif_hdr_set_netif(netif_hdr->data, netif);
ip = gnrc_pkt_prepend(ip, netif_hdr);
}
/* send packet */
if (!gnrc_netapi_dispatch_send(GNRC_NETTYPE_UDP, GNRC_NETREG_DEMUX_CTX_ALL, ip)) {
puts("Error: unable to locate UDP thread");
gnrc_pktbuf_release(ip);
return;
}
/* access to `payload` was implicitly given up with the send operation above
* => use temporary variable for output */
printf("Success: sent %u byte(s) to [%s]:%u\n", payload_size, addr_str,
port);
xtimer_usleep(delay);
}
}

static void start_server(char *port_str)
{
uint16_t port;

/* check if server is already running */
if (server.target.pid != KERNEL_PID_UNDEF) {
printf("Error: server already running on port %" PRIu32 "\n",
server.demux_ctx);
return;
}
/* parse port */
port = atoi(port_str);
if (port == 0) {
puts("Error: invalid port specified");
return;
}
/* start server (which means registering pktdump for the chosen port) */
server.target.pid = gnrc_pktdump_pid;
server.demux_ctx = (uint32_t)port;
gnrc_netreg_register(GNRC_NETTYPE_UDP, &server);
printf("Success: started UDP server on port %" PRIu16 "\n", port);
}

static void stop_server(void)
{
/* check if server is running at all */
if (server.target.pid == KERNEL_PID_UNDEF) {
printf("Error: server was not running\n");
return;
}
/* stop server */
gnrc_netreg_unregister(GNRC_NETTYPE_UDP, &server);
server.target.pid = KERNEL_PID_UNDEF;
puts("Success: stopped UDP server");
}

int udp_cmd(int argc, char **argv)
{
if (argc < 2) {
printf("usage: %s [send|server]\n", argv[0]);
return 1;
}

if (strcmp(argv[1], "send") == 0) {
uint32_t num = 1;
uint32_t delay = 1000000;
if (argc < 5) {
printf("usage: %s send <addr> <port> <data> [<num> [<delay in us>]]\n",
argv[0]);
return 1;
}
if (argc > 5) {
num = atoi(argv[5]);
}
if (argc > 6) {
delay = atoi(argv[6]);
}
send(argv[2], argv[3], argv[4], num, delay);
}
else if (strcmp(argv[1], "server") == 0) {
if (argc < 3) {
printf("usage: %s server [start|stop]\n", argv[0]);
return 1;
}
if (strcmp(argv[2], "start") == 0) {
if (argc < 4) {
printf("usage %s server start <port>\n", argv[0]);
return 1;
}
start_server(argv[3]);
}
else if (strcmp(argv[2], "stop") == 0) {
stop_server();
}
else {
puts("error: invalid command");
}
}
else {
puts("error: invalid command");
}
return 0;
}

0 comments on commit e7d6a44

Please sign in to comment.