Skip to content

Commit 73bae67

Browse files
idoschdavem330
authored andcommitted
selftests: forwarding: Add initial testing framework
Add initial framework to test packet forwarding functionality. The tests can run on actual devices using loop-backed cables or using veth pairs. Signed-off-by: Jiri Pirko <[email protected]> Signed-off-by: Ido Schimmel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8230819 commit 73bae67

File tree

6 files changed

+465
-0
lines changed

6 files changed

+465
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
forwarding.config
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
Motivation
2+
==========
3+
4+
One of the nice things about network namespaces is that they allow one
5+
to easily create and test complex environments.
6+
7+
Unfortunately, these namespaces can not be used with actual switching
8+
ASICs, as their ports can not be migrated to other network namespaces
9+
(NETIF_F_NETNS_LOCAL) and most of them probably do not support the
10+
L1-separation provided by namespaces.
11+
12+
However, a similar kind of flexibility can be achieved by using VRFs and
13+
by looping the switch ports together. For example:
14+
15+
br0
16+
+
17+
vrf-h1 | vrf-h2
18+
+ +---+----+ +
19+
| | | |
20+
192.0.2.1/24 + + + + 192.0.2.2/24
21+
swp1 swp2 swp3 swp4
22+
+ + + +
23+
| | | |
24+
+--------+ +--------+
25+
26+
The VRFs act as lightweight namespaces representing hosts connected to
27+
the switch.
28+
29+
This approach for testing switch ASICs has several advantages over the
30+
traditional method that requires multiple physical machines, to name a
31+
few:
32+
33+
1. Only the device under test (DUT) is being tested without noise from
34+
other system.
35+
36+
2. Ability to easily provision complex topologies. Testing bridging
37+
between 4-ports LAGs or 8-way ECMP requires many physical links that are
38+
not always available. With the VRF-based approach one merely needs to
39+
loopback more ports.
40+
41+
These tests are written with switch ASICs in mind, but they can be run
42+
on any Linux box using veth pairs to emulate physical loopbacks.
43+
44+
Guidelines for Writing Tests
45+
============================
46+
47+
o Where possible, reuse an existing topology for different tests instead
48+
of recreating the same topology.
49+
o Where possible, IPv6 and IPv4 addresses shall conform to RFC 3849 and
50+
RFC 5737, respectively.
51+
o Where possible, tests shall be written so that they can be reused by
52+
multiple topologies and added to lib.sh.
53+
o Checks shall be added to lib.sh for any external dependencies.
54+
o Code shall be checked using ShellCheck [1] prior to submission.
55+
56+
1. https://www.shellcheck.net/
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
NUM_NETIFS=4
5+
source lib.sh
6+
7+
h1_create()
8+
{
9+
simple_if_init $h1 192.0.2.1/24 2001:db8:1::1/64
10+
}
11+
12+
h1_destroy()
13+
{
14+
simple_if_fini $h1 192.0.2.1/24 2001:db8:1::1/64
15+
}
16+
17+
h2_create()
18+
{
19+
simple_if_init $h2 192.0.2.2/24 2001:db8:1::2/64
20+
}
21+
22+
h2_destroy()
23+
{
24+
simple_if_fini $h2 192.0.2.2/24 2001:db8:1::2/64
25+
}
26+
27+
switch_create()
28+
{
29+
ip link add dev br0 type bridge vlan_filtering 1 mcast_snooping 0
30+
31+
ip link set dev $swp1 master br0
32+
ip link set dev $swp2 master br0
33+
34+
ip link set dev br0 up
35+
ip link set dev $swp1 up
36+
ip link set dev $swp2 up
37+
}
38+
39+
switch_destroy()
40+
{
41+
ip link set dev $swp2 down
42+
ip link set dev $swp1 down
43+
44+
ip link del dev br0
45+
}
46+
47+
setup_prepare()
48+
{
49+
h1=${NETIFS[p1]}
50+
swp1=${NETIFS[p2]}
51+
52+
swp2=${NETIFS[p3]}
53+
h2=${NETIFS[p4]}
54+
55+
vrf_prepare
56+
57+
h1_create
58+
h2_create
59+
60+
switch_create
61+
}
62+
63+
cleanup()
64+
{
65+
pre_cleanup
66+
67+
switch_destroy
68+
69+
h2_destroy
70+
h1_destroy
71+
72+
vrf_cleanup
73+
}
74+
75+
trap cleanup EXIT
76+
77+
setup_prepare
78+
setup_wait
79+
80+
ping_test $h1 192.0.2.2
81+
ping6_test $h1 2001:db8:1::2
82+
83+
exit $EXIT_STATUS
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CONFIG_BRIDGE=m
2+
CONFIG_VLAN_8021Q=m
3+
CONFIG_BRIDGE_VLAN_FILTERING=y
4+
CONFIG_NET_L3_MASTER_DEV=y
5+
CONFIG_IPV6_MULTIPLE_TABLES=y
6+
CONFIG_NET_VRF=m
7+
CONFIG_BPF_SYSCALL=y
8+
CONFIG_CGROUP_BPF=y
9+
CONFIG_NET_CLS_FLOWER=m
10+
CONFIG_NET_SCH_INGRESS=m
11+
CONFIG_NET_ACT_GACT=m
12+
CONFIG_VETH=m
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
##############################################################################
5+
# Topology description. p1 looped back to p2, p3 to p4 and so on.
6+
declare -A NETIFS
7+
8+
NETIFS[p1]=veth0
9+
NETIFS[p2]=veth1
10+
NETIFS[p3]=veth2
11+
NETIFS[p4]=veth3
12+
NETIFS[p5]=veth4
13+
NETIFS[p6]=veth5
14+
NETIFS[p7]=veth6
15+
NETIFS[p8]=veth7
16+
17+
##############################################################################
18+
# Defines
19+
20+
# IPv4 ping utility name
21+
PING=ping
22+
# IPv6 ping utility name. Some distributions use 'ping' for IPv6.
23+
PING6=ping6
24+
# Packet generator. Some distributions use 'mz'.
25+
MZ=mausezahn
26+
# Time to wait after interfaces participating in the test are all UP
27+
WAIT_TIME=5
28+
# Whether to pause on failure or not.
29+
PAUSE_ON_FAIL=no
30+
# Whether to pause on cleanup or not.
31+
PAUSE_ON_CLEANUP=no

0 commit comments

Comments
 (0)