Skip to content

Commit b2d6f4a

Browse files
committed
tests: add a test application for gnrc_ipv6_ext
1 parent 6443a2b commit b2d6f4a

File tree

4 files changed

+249
-0
lines changed

4 files changed

+249
-0
lines changed

tests/gnrc_ipv6_ext/Makefile

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# name of your application
2+
APPLICATION = gnrc_ipv6_ext
3+
4+
# If no BOARD is found in the environment, use this default:
5+
BOARD ?= native
6+
7+
# This has to be the absolute path to the RIOT base directory:
8+
RIOTBASE ?= $(CURDIR)/../..
9+
10+
BOARD_INSUFFICIENT_MEMORY := airfy-beacon chronos msb-430 msb-430h nrf51dongle \
11+
nrf6310 nucleo-f103 nucleo-f334 pca10000 pca10005 spark-core \
12+
stm32f0discovery telosb weio wsn430-v1_3b wsn430-v1_4 \
13+
yunjia-nrf51822 z1
14+
15+
# Include packages that pull up and auto-init the link layer.
16+
# NOTE: 6LoWPAN will be included if IEEE802.15.4 devices are present
17+
USEMODULE += gnrc_netif_default
18+
USEMODULE += auto_init_gnrc_netif
19+
# Specify the mandatory networking modules for IPv6
20+
USEMODULE += gnrc_ipv6_router_default
21+
# IPv6 extension headers
22+
USEMODULE += gnrc_ipv6_ext
23+
USEMODULE += gnrc_rpl_srh
24+
# Add also the shell, some shell commands
25+
USEMODULE += shell
26+
USEMODULE += shell_commands
27+
USEMODULE += ps
28+
29+
# Comment this out to disable code in RIOT that does safety checking
30+
# which is not needed in a production environment but helps in the
31+
# development process:
32+
CFLAGS += -DDEVELHELP
33+
34+
# Change this to 0 show compiler invocation lines by default:
35+
QUIET ?= 1
36+
37+
include $(RIOTBASE)/Makefile.include
38+
39+
# This requires ENABLE_DEBUG in gnrc_ipv6.c to be 1
40+
test:
41+
# `testrunner` calls `make term` recursively, results in duplicated `TERMFLAGS`.
42+
# So clears `TERMFLAGS` before run.
43+
TERMFLAGS= tests/01-run.py

tests/gnrc_ipv6_ext/README.md

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# `gnrc_ipv6_ext` test
2+
3+
This test sends a packet to itself with extension headers. This is based on gnrc_networking example.
4+
5+
Enable debug output of `gnrc_ipv6.c` before run. When the test is run, it should show the following debug output:
6+
7+
```
8+
ipv6: Received (src = fd01::1, dst = fd01::2, next header = 0, length = 40)
9+
ipv6: forward nh = 0 to other threads
10+
ipv6: unable to forward packet as no one is interested in it
11+
ipv6: handle extension header (nh = 0)
12+
ipv6: forward nh = 43 to other threads
13+
ipv6: unable to forward packet as no one is interested in it
14+
ipv6: handle extension header (nh = 43)
15+
ipv6: waiting for incoming message.
16+
ipv6: GNRC_NETAPI_MSG_TYPE_RCV received
17+
ipv6: Received (src = fd01::1, dst = fd01::3, next header = 0, length = 40)
18+
ipv6: forward nh = 0 to other threads
19+
ipv6: unable to forward packet as no one is interested in it
20+
ipv6: handle extension header (nh = 0)
21+
ipv6: forward nh = 43 to other threads
22+
ipv6: unable to forward packet as no one is interested in it
23+
ipv6: handle extension header (nh = 43)
24+
ipv6: waiting for incoming message.
25+
ipv6: GNRC_NETAPI_MSG_TYPE_RCV received
26+
ipv6: Received (src = fd01::1, dst = fd01::2, next header = 0, length = 40)
27+
ipv6: forward nh = 0 to other threads
28+
ipv6: unable to forward packet as no one is interested in it
29+
ipv6: handle extension header (nh = 0)
30+
ipv6: forward nh = 43 to other threads
31+
ipv6: unable to forward packet as no one is interested in it
32+
ipv6: handle extension header (nh = 43)
33+
ipv6: forward nh = 17 to other threads
34+
ipv6: Send receive command for 0x1060b8 to 5
35+
ipv6: waiting for incoming message.
36+
pkt->users: 0
37+
```
38+
39+
It configures the network interface with addresses fd01::02 and fd01::03. Then it sends a packet to fd01::02 with a routing extension header containing addresses fd01::03 and fd01::02. So the packet should be forwarded from fd01::02 to fd01::03, then to fd01::02 again.
40+
41+
The packet has a Hop-by-Hop extension header that should be ignored.
42+
43+
The test also asserts that the packet is released.

tests/gnrc_ipv6_ext/main.c

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*
2+
* Copyright (C) 2015 Freie Universität Berlin
3+
*
4+
* This file is subject to the terms and conditions of the GNU Lesser
5+
* General Public License v2.1. See the file LICENSE in the top level
6+
* directory for more details.
7+
*/
8+
9+
/**
10+
* @ingroup tests
11+
* @{
12+
*
13+
* @file
14+
* @brief Tests extension header handling of gnrc stack.
15+
*
16+
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
17+
* @author Takuo Yonezawa <Yonezawa-T2@mail.dnp.co.jp>
18+
*
19+
* @}
20+
*/
21+
22+
#include <stdio.h>
23+
24+
#include "shell.h"
25+
#include "msg.h"
26+
#include "net/ipv6/addr.h"
27+
#include "net/gnrc/ipv6/netif.h"
28+
#include "net/gnrc/pkt.h"
29+
#include "net/gnrc/pktbuf.h"
30+
#include "net/gnrc/netreg.h"
31+
#include "net/gnrc/netapi.h"
32+
#include "net/gnrc/netif.h"
33+
34+
#define MAIN_QUEUE_SIZE (8)
35+
static msg_t _main_msg_queue[MAIN_QUEUE_SIZE];
36+
37+
static void _send_packet(void) {
38+
kernel_pid_t ifs[GNRC_NETIF_NUMOF];
39+
ipv6_addr_t addr = IPV6_ADDR_UNSPECIFIED;
40+
41+
gnrc_netif_get(ifs);
42+
43+
addr.u8[0] = 0xfd;
44+
addr.u8[1] = 0x01;
45+
addr.u8[15] = 0x02;
46+
/* fd01::02 */
47+
gnrc_ipv6_netif_add_addr(ifs[0], &addr, 64, GNRC_IPV6_NETIF_ADDR_FLAGS_UNICAST);
48+
49+
addr.u8[15] = 0x03;
50+
/* fd01::03 */
51+
gnrc_ipv6_netif_add_addr(ifs[0], &addr, 64, GNRC_IPV6_NETIF_ADDR_FLAGS_UNICAST);
52+
53+
uint8_t data[] = {
54+
/* IPv6 Header */
55+
0x60, 0x00, 0x00, 0x00, /* version, traffic class, flow label */
56+
0x00, 0x28, /* payload length: 40 */
57+
0x00, /* next header: Hop-by-Hop Option */
58+
0x10, /* hop limit: 16 */
59+
/* source address: fd01::1 */
60+
0xfd, 0x01, 0x00, 0x00,
61+
0x00, 0x00, 0x00, 0x00,
62+
0x00, 0x00, 0x00, 0x00,
63+
0x00, 0x00, 0x00, 0x01,
64+
/* destination address: fd01::2 */
65+
0xfd, 0x01, 0x00, 0x00,
66+
0x00, 0x00, 0x00, 0x00,
67+
0x00, 0x00, 0x00, 0x00,
68+
0x00, 0x00, 0x00, 0x02,
69+
70+
/* Hop-by-Hop Options Header */
71+
/* https://tools.ietf.org/html/rfc6553 */
72+
0x2b, /* next header: IPv6-Route */
73+
0x00, /* hdr ext len: 0 * 8 + 8 = 8 */
74+
0x63, /* option type: RPL Option */
75+
0x04, /* opt data len: 4 */
76+
0x80, /* flags, Down: 1, Rank-Error: 0, Forwarding-Error: 0 */
77+
0x00, /* RPLInstanceID */
78+
0x80, 0x00, /* SenderRank */
79+
80+
/* RPL Routing Header */
81+
/* https://tools.ietf.org/html/rfc6554 */
82+
0x11, /* next header: UDP */
83+
0x02, /* hdr ext len: 2 * 8 + 8 = 24 */
84+
0x03, /* routing type: SRH */
85+
0x02, /* segments left: 2 */
86+
0xef, /* ComprI: 14, ComprE: 15 */
87+
0xd0, 0x00, 0x00, /* pad and reserved */
88+
/* address: fd01::3, fd01::2 */
89+
0x00, 0x03, 0x02, 0x00,
90+
0x00, 0x00, 0x00, 0x00,
91+
0x00, 0x00, 0x00, 0x00,
92+
0x00, 0x00, 0x00, 0x00,
93+
94+
/* UDP (ignored) */
95+
0x1f, 0x90, /* source port: 8080 */
96+
0x1f, 0x90, /* destination port: 8080 */
97+
0x00, 0x08, /* length: 8 */
98+
0xff, 0xff, /* checksum */
99+
};
100+
101+
gnrc_pktsnip_t *pkt = gnrc_pktbuf_add(NULL, data, sizeof(data), GNRC_NETTYPE_UNDEF);
102+
103+
gnrc_netapi_dispatch_receive(GNRC_NETTYPE_IPV6, GNRC_NETREG_DEMUX_CTX_ALL, pkt);
104+
105+
printf("pkt->users: %d\n", pkt->users);
106+
assert(pkt->users == 0);
107+
}
108+
109+
int main(void)
110+
{
111+
/* we need a message queue for the thread running the shell in order to
112+
* receive potentially fast incoming networking packets */
113+
msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE);
114+
puts("RIOT network stack example application");
115+
116+
_send_packet();
117+
118+
/* start shell */
119+
puts("All up, running the shell now");
120+
char line_buf[SHELL_DEFAULT_BUFSIZE];
121+
shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE);
122+
123+
/* should be never reached */
124+
return 0;
125+
}

tests/gnrc_ipv6_ext/tests/01-run.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env python3
2+
3+
# Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.de>
4+
# Copyright (C) 2016 Takuo Yonezawa <Yonezawa-T2@mail.dnp.co.jp>
5+
#
6+
# This file is subject to the terms and conditions of the GNU Lesser
7+
# General Public License v2.1. See the file LICENSE in the top level
8+
# directory for more details.
9+
10+
import os
11+
import sys
12+
13+
sys.path.append(os.path.join(os.environ['RIOTBASE'], 'dist/tools/testrunner'))
14+
import testrunner
15+
16+
def testfunc(child):
17+
index = child.expect_exact([
18+
"ipv6: Received (src = fd01::1, dst = fd01::2, next header = 0, length = 40)",
19+
"pkt->users: 0"
20+
])
21+
22+
if index == 1:
23+
# debug is disabled
24+
return
25+
26+
child.expect_exact("ipv6: handle extension header (nh = 0)")
27+
child.expect_exact("ipv6: handle extension header (nh = 43)")
28+
child.expect_exact("ipv6: Received (src = fd01::1, dst = fd01::3, next header = 0, length = 40)")
29+
child.expect_exact("ipv6: handle extension header (nh = 0)")
30+
child.expect_exact("ipv6: handle extension header (nh = 43)")
31+
child.expect_exact("ipv6: Received (src = fd01::1, dst = fd01::2, next header = 0, length = 40)")
32+
child.expect_exact("ipv6: handle extension header (nh = 0)")
33+
child.expect_exact("ipv6: handle extension header (nh = 43)")
34+
child.expect_exact("ipv6: forward nh = 17 to other threads")
35+
child.expect_exact("pkt->users: 0")
36+
37+
if __name__ == "__main__":
38+
sys.exit(testrunner.run(testfunc))

0 commit comments

Comments
 (0)