Skip to content

Commit 5407492

Browse files
committed
Merge branch 'selftests-forwarding-Add-VRF-based-tests'
Ido Schimmel says: ==================== selftests: forwarding: Add VRF-based tests One of the nice things about network namespaces is that they allow one to easily create and test complex environments. Unfortunately, these namespaces can not be used with actual switching ASICs, as their ports can not be migrated to other network namespaces (NETIF_F_NETNS_LOCAL) and most of them probably do not support the L1-separation provided by namespaces. However, a similar kind of flexibility can be achieved by using VRFs and by looping the switch ports together. For example: br0 + vrf-h1 | vrf-h2 + +---+----+ + | | | | 192.0.2.1/24 + + + + 192.0.2.2/24 swp1 swp2 swp3 swp4 + + + + | | | | +--------+ +--------+ The VRFs act as lightweight namespaces representing hosts connected to the switch. This approach for testing switch ASICs has several advantages over the traditional method that requires multiple physical machines, to name a few: 1. Only the device under test (DUT) is being tested without noise from other system. 2. Ability to easily provision complex topologies. Testing bridging between 4-ports LAGs or 8-way ECMP requires many physical links that are not always available. With the VRF-based approach one merely needs to loopback more ports. These tests are written with switch ASICs in mind, but they can be run on any Linux box using veth pairs to emulate physical loopbacks. v2: * Order local variables declaration according to function arguments order (Petr) v1: * Change location to net/forwarding instead of forwarding/ * Add ability to pause on failure * Add ability to pause on cleanup * Make configuration file optional * Make ping/ping6/mz configurable * Add more tc tests ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 8230819 + 4908e24 commit 5407492

File tree

13 files changed

+1825
-0
lines changed

13 files changed

+1825
-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: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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+
# 10 Seconds ageing time.
30+
ip link add dev br0 type bridge vlan_filtering 1 ageing_time 1000 \
31+
mcast_snooping 0
32+
33+
ip link set dev $swp1 master br0
34+
ip link set dev $swp2 master br0
35+
36+
ip link set dev br0 up
37+
ip link set dev $swp1 up
38+
ip link set dev $swp2 up
39+
}
40+
41+
switch_destroy()
42+
{
43+
ip link set dev $swp2 down
44+
ip link set dev $swp1 down
45+
46+
ip link del dev br0
47+
}
48+
49+
setup_prepare()
50+
{
51+
h1=${NETIFS[p1]}
52+
swp1=${NETIFS[p2]}
53+
54+
swp2=${NETIFS[p3]}
55+
h2=${NETIFS[p4]}
56+
57+
vrf_prepare
58+
59+
h1_create
60+
h2_create
61+
62+
switch_create
63+
}
64+
65+
cleanup()
66+
{
67+
pre_cleanup
68+
69+
switch_destroy
70+
71+
h2_destroy
72+
h1_destroy
73+
74+
vrf_cleanup
75+
}
76+
77+
trap cleanup EXIT
78+
79+
setup_prepare
80+
setup_wait
81+
82+
ping_test $h1 192.0.2.2
83+
ping6_test $h1 2001:db8:1::2
84+
learning_test "br0" $swp1 $h1 $h2
85+
flood_test $swp2 $h1 $h2
86+
87+
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)