Skip to content

Commit 4b1cbb8

Browse files
committed
tests: net: Application for automatic network testing
This is a simple network application that is used by automatic testing scripts. The application currently enables IPv6 and IPv4, TCP and UDP, VLAN and traffic class support, and echo-server service. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
1 parent 7eee992 commit 4b1cbb8

File tree

14 files changed

+1607
-0
lines changed

14 files changed

+1607
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
set(KCONFIG_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/Kconfig)
2+
3+
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
4+
project(NONE)
5+
6+
target_sources(app PRIVATE src/main.c)
7+
target_sources(app PRIVATE src/echo-server.c)
8+
target_sources_ifdef(CONFIG_NET_TCP app PRIVATE src/tcp.c)
9+
target_sources_ifdef(CONFIG_NET_UDP app PRIVATE src/udp.c)
10+
target_sources_ifdef(CONFIG_NET_VLAN app PRIVATE src/vlan.c)
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Kconfig - Private config options for network testing app
2+
3+
#
4+
# Copyright (c) 2018 Intel Corporation
5+
#
6+
# SPDX-License-Identifier: Apache-2.0
7+
#
8+
9+
mainmenu "Networking test application"
10+
11+
config ZEPHYR_BASE
12+
string
13+
option env="ZEPHYR_BASE"
14+
15+
source "$ZEPHYR_BASE/Kconfig.zephyr"
16+
17+
config NET_DEBUG_TEST_APP
18+
bool "Enable debugging for this test application"
19+
default n
20+
depends on NET_LOG
21+
help
22+
Enable debugging output from this test application.
23+
The used log level is the CONFIG_SYS_LOG_NET_LEVEL option.
24+
25+
config SAMPLE_VLAN_TAG_1
26+
int "Virtual lan tag used in this app"
27+
default 100
28+
range 0 4094
29+
depends on NET_VLAN
30+
help
31+
Set virtual lan tag (id) that is used in this application.
32+
33+
config SAMPLE_VLAN_TAG_2
34+
int "Second VLAN tag used in this app"
35+
default 200
36+
range 0 4094
37+
depends on NET_VLAN
38+
help
39+
Set virtual lan tag (id) that is used in this application.
40+
41+
config SAMPLE_IPV6_ADDR_1
42+
string "My IPv6 address for a network interface"
43+
help
44+
The value depends on your network setup.
45+
46+
config SAMPLE_IPV4_ADDR_1
47+
string "My IPv4 address for a network interface"
48+
help
49+
The value depends on your network setup.
50+
51+
config SAMPLE_IPV4_GW_1
52+
string "My IPv4 gateway for a network interface"
53+
help
54+
The value depends on your network setup.
55+
56+
config SAMPLE_IPV4_NETMASK_1
57+
string "My IPv4 netmask for a network interface"
58+
default "255.255.255.0"
59+
help
60+
Static netmask to use if not overridden by DHCP. Use empty value to
61+
skip setting static value.
62+
63+
config SAMPLE_IPV6_ADDR_2
64+
string "My IPv6 address for another network interface"
65+
help
66+
The value depends on your network setup.
67+
68+
config SAMPLE_IPV4_ADDR_2
69+
string "My IPv4 address for another network interface"
70+
help
71+
The value depends on your network setup.
72+
73+
config SAMPLE_IPV4_GW_2
74+
string "My IPv4 gateway for another network interface"
75+
help
76+
The value depends on your network setup.
77+
78+
config SAMPLE_IPV4_NETMASK_2
79+
string "My IPv4 netmask for another network interface"
80+
default "255.255.255.0"
81+
help
82+
Static netmask to use if not overridden by DHCP. Use empty value to
83+
skip setting static value.
84+
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
.. _network-automatic-testing:
2+
3+
Network Automatic Testing
4+
#########################
5+
6+
Overview
7+
********
8+
9+
This test application for Zephyr will setup two virtual LAN networks
10+
and provides echo-server service for normal and encrypted UDP and
11+
TCP connections. The test application also enables net-shell.
12+
13+
The source code for this test application can be found at:
14+
:file:`tests/net/automatic_testing`.
15+
16+
Requirements
17+
************
18+
19+
- :ref:`networking_with_qemu`
20+
21+
Building and Running
22+
********************
23+
24+
Normally this test application is launched by automatic test system.
25+
It is also possible to run this testing application with QEMU as described in
26+
:ref:`networking_with_qemu`, with native-posix board or with real hardware.
27+
Note that VLAN is only supported for boards that have ethernet port.
28+
29+
Follow these steps to build the testing application:
30+
31+
.. zephyr-app-commands::
32+
:zephyr-app: tests/net/automatic_testing
33+
:board: <board to use>
34+
:conf: prj.conf
35+
:goals: build
36+
:compact:
37+
38+
If this application is run in native_posix board, then normally one needs extra
39+
priviliges to create and configure the TAP device in the host system.
40+
Use sudo command to execute the Zephyr process with admin privileges, like this:
41+
42+
.. code-block:: console
43+
44+
sudo --preserve-env=ZEPHYR_BASE make run
45+
46+
If the sudo command reports an error, then try to execute it like this:
47+
48+
.. code-block:: console
49+
50+
sudo --preserve-env make run
51+
52+
The default configuration file prj.conf creates two virtual LAN networks
53+
with these settings and one normal ethernet interface:
54+
55+
- VLAN tag 100: IPv4 198.51.100.1 and IPv6 2001:db8:100::1
56+
- VLAN tag 200: IPv4 203.0.113.1 and IPv6 2001:db8:200::1
57+
- IPv4 192.0.2.1 and IPv6 2001:db8::1
58+
59+
Setting up Linux Host
60+
=====================
61+
62+
The :file:`samples/net/vlan/vlan-setup-linux.sh` provides a script that can be
63+
executed on the Linux host. It creates two VLAN on the Linux host and
64+
suitable IP routes to Zephyr. This script is not needed for native-posix board
65+
as host IP address setup is done automatically for it.
66+
67+
If everything is configured correctly, you will be able to successfully execute
68+
the following commands on the Linux host.
69+
70+
.. code-block:: console
71+
72+
ping -c 1 2001:db8:100::1
73+
ping -c 1 198.51.100.1
74+
ping -c 1 2001:db8:200::1
75+
ping -c 1 203.0.113.1
76+
ping -c 1 192.0.2.1
77+
ping -c 1 2001:db8::1
78+
79+
It is also possible to execute echo-client program that can be found in
80+
`net-tools`_ project.
81+
82+
.. code-block:: console
83+
84+
./echo-client 2001:db8::1
85+
./echo-client 2001:db8:100::1
86+
./echo-client 2001:db8:200::1
87+
88+
.. _`net-tools`: https://github.com/zephyrproject-rtos/net-tools
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2018 Intel Corporation
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# This script is called by native-posix board when TAP network interface
18+
# is taken up by Zephyr. The script should setup the host system so that
19+
# connectivity will work with Zephyr.
20+
21+
while [ $# -gt 0 ]; do
22+
case "$1" in
23+
-f|--file)
24+
CONF_FILE="$2"
25+
shift
26+
shift;;
27+
-i|--interface)
28+
# Only first -i option is taken into account. This way
29+
# the driver added -i option is ignored if user has specified
30+
# the -i option to host setup script command.
31+
if [ -z "$IFACE" ]; then
32+
IFACE="$2"
33+
fi
34+
shift
35+
shift;;
36+
*)
37+
shift;;
38+
esac
39+
done
40+
41+
if [ `id -u` != 0 ]; then
42+
echo "Warning: This script will need admin rights to setup \
43+
network interface!"
44+
fi
45+
46+
if [ -z "$IFACE" ]; then
47+
IFACE="zeth"
48+
fi
49+
50+
if [ -z "$CONF_FILE" ]; then
51+
DIR=`dirname $0`
52+
CONF_FILE="$DIR/net_setup_host.conf"
53+
fi
54+
55+
if [ -f "$CONF_FILE" ]; then
56+
. $CONF_FILE
57+
else
58+
echo "Warning: config file $CONF_FILE does not exist!"
59+
fi
60+
61+
ip link set dev $IFACE up
62+
63+
if [ ! -z "$HWADDR" ]; then
64+
ip link set dev $IFACE address $HWADDR
65+
fi
66+
67+
if [ ! -z "$IPV6_ADDR_1" ]; then
68+
ip -6 address add $IPV6_ADDR_1 dev $IFACE
69+
fi
70+
71+
if [ ! -z "$IPV6_ROUTE_1" ]; then
72+
ip -6 route add $IPV6_ROUTE_1 dev $IFACE
73+
fi
74+
75+
if [ ! -z "$IPV4_ADDR_1" ]; then
76+
ip address add $IPV4_ADDR_1 dev $IFACE
77+
fi
78+
79+
if [ ! -z "$IPV4_ROUTE_1" ]; then
80+
ip route add $IPV4_ROUTE_1 dev $IFACE
81+
fi
82+
83+
if [ ! -z "$VLAN_NAME_PREFIX" ]; then
84+
if [ ! -z "$VLAN_TAG_1" ]; then
85+
ip link add link ${IFACE} name \
86+
${VLAN_NAME_PREFIX}.${VLAN_TAG_1} type vlan id ${VLAN_TAG_1}
87+
ip link set ${VLAN_NAME_PREFIX}.${VLAN_TAG_1} up
88+
89+
if [ ! -z "$VLAN_ADDR_1_IPV6" ]; then
90+
ip -6 addr add ${VLAN_ADDR_1_IPV6} \
91+
dev ${VLAN_NAME_PREFIX}.${VLAN_TAG_1}
92+
fi
93+
94+
if [ ! -z "$VLAN_ROUTE_1_IPV6" ]; then
95+
ip -6 route add ${VLAN_ROUTE_1_IPV6} \
96+
dev ${VLAN_NAME_PREFIX}.${VLAN_TAG_1}
97+
fi
98+
99+
if [ ! -z "$VLAN_ADDR_1_IPV4" ]; then
100+
ip addr add ${VLAN_ADDR_1_IPV4} \
101+
dev ${VLAN_NAME_PREFIX}.${VLAN_TAG_1}
102+
fi
103+
104+
if [ ! -z "$VLAN_ROUTE_1_IPV4" ]; then
105+
ip route add ${VLAN_ROUTE_1_IPV4} \
106+
dev ${VLAN_NAME_PREFIX}.${VLAN_TAG_1}
107+
fi
108+
fi
109+
110+
if [ ! -z "$VLAN_TAG_2" ]; then
111+
ip link add link ${IFACE} name \
112+
${VLAN_NAME_PREFIX}.${VLAN_TAG_2} type vlan id ${VLAN_TAG_2}
113+
ip link set ${VLAN_NAME_PREFIX}.${VLAN_TAG_2} up
114+
115+
if [ ! -z "$VLAN_ADDR_2_IPV6" ]; then
116+
ip -6 addr add ${VLAN_ADDR_2_IPV6} \
117+
dev ${VLAN_NAME_PREFIX}.${VLAN_TAG_2}
118+
fi
119+
120+
if [ ! -z "$VLAN_ROUTE_2_IPV6" ]; then
121+
ip -6 route add ${VLAN_ROUTE_2_IPV6} \
122+
dev ${VLAN_NAME_PREFIX}.${VLAN_TAG_2}
123+
fi
124+
125+
if [ ! -z "$VLAN_ADDR_2_IPV4" ]; then
126+
ip addr add ${VLAN_ADDR_2_IPV4} \
127+
dev ${VLAN_NAME_PREFIX}.${VLAN_TAG_2}
128+
fi
129+
130+
if [ ! -z "$VLAN_ROUTE_2_IPV4" ]; then
131+
ip route add ${VLAN_ROUTE_2_IPV4} \
132+
dev ${VLAN_NAME_PREFIX}.${VLAN_TAG_2}
133+
fi
134+
fi
135+
fi
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# Configuration options for setting up the host network interface
3+
#
4+
5+
HWADDR="00:00:5e:00:53:99"
6+
7+
IPV6_ADDR_1="2001:db8::2"
8+
IPV6_ROUTE_1="2001:db8::/64"
9+
10+
IPV4_ADDR_1="192.0.2.2"
11+
IPV4_ROUTE_1="192.0.2.0/24"
12+
13+
VLAN_NAME_PREFIX="vlan"
14+
VLAN_TAG_1=100
15+
VLAN_TAG_2=200
16+
17+
VLAN_ADDR_1_IPV6="2001:db8:100::2"
18+
VLAN_ROUTE_1_IPV6="2001:db8:100::/64"
19+
VLAN_ADDR_2_IPV6="2001:db8:200::2"
20+
VLAN_ROUTE_2_IPV6="2001:db8:200::/64"
21+
22+
# Documentation addresses from RFC 5737
23+
VLAN_ADDR_1_IPV4="198.51.100.2"
24+
VLAN_ROUTE_1_IPV4="198.51.100.0/24"
25+
VLAN_ADDR_2_IPV4="203.0.113.2"
26+
VLAN_ROUTE_2_IPV4="203.0.113.0/24"

0 commit comments

Comments
 (0)