Skip to content

Commit 4908e24

Browse files
jpirkodavem330
authored andcommitted
selftests: forwarding: Introduce basic shared blocks tests
Test shared block infrastructure. This is a basic test that shares TC block in between 2 clsact qdiscs. Signed-off-by: Jiri Pirko <[email protected]> Signed-off-by: Ido Schimmel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b13f245 commit 4908e24

File tree

2 files changed

+128
-0
lines changed

2 files changed

+128
-0
lines changed

tools/testing/selftests/net/forwarding/lib.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ if [[ $? -ne 0 ]]; then
3030
exit 0
3131
fi
3232

33+
tc filter help 2>&1 | grep block &> /dev/null
34+
if [[ $? -ne 0 ]]; then
35+
echo "SKIP: iproute2 too old, missing shared block support"
36+
exit 0
37+
fi
38+
3339
if [[ ! -x "$(command -v jq)" ]]; then
3440
echo "SKIP: jq not installed"
3541
exit 0
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
NUM_NETIFS=4
5+
source lib.sh
6+
source tc_common.sh
7+
8+
tcflags="skip_hw"
9+
10+
h1_create()
11+
{
12+
simple_if_init $h1 192.0.2.1/24
13+
}
14+
15+
h1_destroy()
16+
{
17+
simple_if_fini $h1 192.0.2.1/24
18+
}
19+
20+
h2_create()
21+
{
22+
simple_if_init $h2 192.0.2.1/24
23+
}
24+
25+
h2_destroy()
26+
{
27+
simple_if_fini $h2 192.0.2.1/24
28+
}
29+
30+
switch_create()
31+
{
32+
simple_if_init $swp1 192.0.2.2/24
33+
tc qdisc add dev $swp1 ingress_block 22 egress_block 23 clsact
34+
35+
simple_if_init $swp2 192.0.2.2/24
36+
tc qdisc add dev $swp2 ingress_block 22 egress_block 23 clsact
37+
}
38+
39+
switch_destroy()
40+
{
41+
tc qdisc del dev $swp2 clsact
42+
simple_if_fini $swp2 192.0.2.2/24
43+
44+
tc qdisc del dev $swp1 clsact
45+
simple_if_fini $swp1 192.0.2.2/24
46+
}
47+
48+
shared_block_test()
49+
{
50+
RET=0
51+
52+
tc filter add block 22 protocol ip pref 1 handle 101 flower \
53+
$tcflags dst_ip 192.0.2.2 action drop
54+
55+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $swmac -A 192.0.2.1 -B 192.0.2.2 \
56+
-t ip -q
57+
58+
tc_check_packets "block 22" 101 1
59+
check_err $? "Did not match first incoming packet on a block"
60+
61+
$MZ $h2 -c 1 -p 64 -a $h2mac -b $swmac -A 192.0.2.1 -B 192.0.2.2 \
62+
-t ip -q
63+
64+
tc_check_packets "block 22" 101 2
65+
check_err $? "Did not match second incoming packet on a block"
66+
67+
tc filter del block 22 protocol ip pref 1 handle 101 flower
68+
69+
log_test "shared block ($tcflags)"
70+
}
71+
72+
setup_prepare()
73+
{
74+
h1=${NETIFS[p1]}
75+
swp1=${NETIFS[p2]}
76+
77+
swp2=${NETIFS[p3]}
78+
h2=${NETIFS[p4]}
79+
80+
h1mac=$(mac_get $h1)
81+
h2mac=$(mac_get $h2)
82+
83+
swmac=$(mac_get $swp1)
84+
swp2origmac=$(mac_get $swp2)
85+
ip link set $swp2 address $swmac
86+
87+
vrf_prepare
88+
89+
h1_create
90+
h2_create
91+
switch_create
92+
}
93+
94+
cleanup()
95+
{
96+
pre_cleanup
97+
98+
switch_destroy
99+
h2_destroy
100+
h1_destroy
101+
102+
vrf_cleanup
103+
104+
ip link set $swp2 address $swp2origmac
105+
}
106+
107+
trap cleanup EXIT
108+
109+
setup_prepare
110+
setup_wait
111+
112+
shared_block_test
113+
114+
tc_offload_check
115+
if [[ $? -ne 0 ]]; then
116+
log_info "Could not test offloaded functionality"
117+
else
118+
tcflags="skip_sw"
119+
shared_block_test
120+
fi
121+
122+
exit $EXIT_STATUS

0 commit comments

Comments
 (0)