Commit 54074929 authored by David S. Miller's avatar David S. Miller

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: default avatarDavid S. Miller <davem@davemloft.net>
parents 82308194 4908e24b
Motivation
==========
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.
Guidelines for Writing Tests
============================
o Where possible, reuse an existing topology for different tests instead
of recreating the same topology.
o Where possible, IPv6 and IPv4 addresses shall conform to RFC 3849 and
RFC 5737, respectively.
o Where possible, tests shall be written so that they can be reused by
multiple topologies and added to lib.sh.
o Checks shall be added to lib.sh for any external dependencies.
o Code shall be checked using ShellCheck [1] prior to submission.
1. https://www.shellcheck.net/
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
NUM_NETIFS=4
source lib.sh
h1_create()
{
simple_if_init $h1 192.0.2.1/24 2001:db8:1::1/64
}
h1_destroy()
{
simple_if_fini $h1 192.0.2.1/24 2001:db8:1::1/64
}
h2_create()
{
simple_if_init $h2 192.0.2.2/24 2001:db8:1::2/64
}
h2_destroy()
{
simple_if_fini $h2 192.0.2.2/24 2001:db8:1::2/64
}
switch_create()
{
# 10 Seconds ageing time.
ip link add dev br0 type bridge vlan_filtering 1 ageing_time 1000 \
mcast_snooping 0
ip link set dev $swp1 master br0
ip link set dev $swp2 master br0
ip link set dev br0 up
ip link set dev $swp1 up
ip link set dev $swp2 up
}
switch_destroy()
{
ip link set dev $swp2 down
ip link set dev $swp1 down
ip link del dev br0
}
setup_prepare()
{
h1=${NETIFS[p1]}
swp1=${NETIFS[p2]}
swp2=${NETIFS[p3]}
h2=${NETIFS[p4]}
vrf_prepare
h1_create
h2_create
switch_create
}
cleanup()
{
pre_cleanup
switch_destroy
h2_destroy
h1_destroy
vrf_cleanup
}
trap cleanup EXIT
setup_prepare
setup_wait
ping_test $h1 192.0.2.2
ping6_test $h1 2001:db8:1::2
learning_test "br0" $swp1 $h1 $h2
flood_test $swp2 $h1 $h2
exit $EXIT_STATUS
CONFIG_BRIDGE=m
CONFIG_VLAN_8021Q=m
CONFIG_BRIDGE_VLAN_FILTERING=y
CONFIG_NET_L3_MASTER_DEV=y
CONFIG_IPV6_MULTIPLE_TABLES=y
CONFIG_NET_VRF=m
CONFIG_BPF_SYSCALL=y
CONFIG_CGROUP_BPF=y
CONFIG_NET_CLS_FLOWER=m
CONFIG_NET_SCH_INGRESS=m
CONFIG_NET_ACT_GACT=m
CONFIG_VETH=m
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
##############################################################################
# Topology description. p1 looped back to p2, p3 to p4 and so on.
declare -A NETIFS
NETIFS[p1]=veth0
NETIFS[p2]=veth1
NETIFS[p3]=veth2
NETIFS[p4]=veth3
NETIFS[p5]=veth4
NETIFS[p6]=veth5
NETIFS[p7]=veth6
NETIFS[p8]=veth7
##############################################################################
# Defines
# IPv4 ping utility name
PING=ping
# IPv6 ping utility name. Some distributions use 'ping' for IPv6.
PING6=ping6
# Packet generator. Some distributions use 'mz'.
MZ=mausezahn
# Time to wait after interfaces participating in the test are all UP
WAIT_TIME=5
# Whether to pause on failure or not.
PAUSE_ON_FAIL=no
# Whether to pause on cleanup or not.
PAUSE_ON_CLEANUP=no
This diff is collapsed.
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
NUM_NETIFS=4
source lib.sh
h1_create()
{
vrf_create "vrf-h1"
ip link set dev $h1 master vrf-h1
ip link set dev vrf-h1 up
ip link set dev $h1 up
ip address add 192.0.2.2/24 dev $h1
ip address add 2001:db8:1::2/64 dev $h1
ip route add 198.51.100.0/24 vrf vrf-h1 nexthop via 192.0.2.1
ip route add 2001:db8:2::/64 vrf vrf-h1 nexthop via 2001:db8:1::1
}
h1_destroy()
{
ip route del 2001:db8:2::/64 vrf vrf-h1
ip route del 198.51.100.0/24 vrf vrf-h1
ip address del 2001:db8:1::2/64 dev $h1
ip address del 192.0.2.2/24 dev $h1
ip link set dev $h1 down
vrf_destroy "vrf-h1"
}
h2_create()
{
vrf_create "vrf-h2"
ip link set dev $h2 master vrf-h2
ip link set dev vrf-h2 up
ip link set dev $h2 up
ip address add 198.51.100.2/24 dev $h2
ip address add 2001:db8:2::2/64 dev $h2
ip route add 192.0.2.0/24 vrf vrf-h2 nexthop via 198.51.100.1
ip route add 2001:db8:1::/64 vrf vrf-h2 nexthop via 2001:db8:2::1
}
h2_destroy()
{
ip route del 2001:db8:1::/64 vrf vrf-h2
ip route del 192.0.2.0/24 vrf vrf-h2
ip address del 2001:db8:2::2/64 dev $h2
ip address del 198.51.100.2/24 dev $h2
ip link set dev $h2 down
vrf_destroy "vrf-h2"
}
router_create()
{
ip link set dev $rp1 up
ip link set dev $rp2 up
ip address add 192.0.2.1/24 dev $rp1
ip address add 2001:db8:1::1/64 dev $rp1
ip address add 198.51.100.1/24 dev $rp2
ip address add 2001:db8:2::1/64 dev $rp2
}
router_destroy()
{
ip address del 2001:db8:2::1/64 dev $rp2
ip address del 198.51.100.1/24 dev $rp2
ip address del 2001:db8:1::1/64 dev $rp1
ip address del 192.0.2.1/24 dev $rp1
ip link set dev $rp2 down
ip link set dev $rp1 down
}
setup_prepare()
{
h1=${NETIFS[p1]}
rp1=${NETIFS[p2]}
rp2=${NETIFS[p3]}
h2=${NETIFS[p4]}
vrf_prepare
h1_create
h2_create
router_create
forwarding_enable
}
cleanup()
{
pre_cleanup
forwarding_restore
router_destroy
h2_destroy
h1_destroy
vrf_cleanup
}
trap cleanup EXIT
setup_prepare
setup_wait
ping_test $h1 198.51.100.2
ping6_test $h1 2001:db8:2::2
exit $EXIT_STATUS
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
NUM_NETIFS=8
source lib.sh
h1_create()
{
vrf_create "vrf-h1"
ip link set dev $h1 master vrf-h1
ip link set dev vrf-h1 up
ip link set dev $h1 up
ip address add 192.0.2.2/24 dev $h1
ip address add 2001:db8:1::2/64 dev $h1
ip route add 198.51.100.0/24 vrf vrf-h1 nexthop via 192.0.2.1
ip route add 2001:db8:2::/64 vrf vrf-h1 nexthop via 2001:db8:1::1
}
h1_destroy()
{
ip route del 2001:db8:2::/64 vrf vrf-h1
ip route del 198.51.100.0/24 vrf vrf-h1
ip address del 2001:db8:1::2/64 dev $h1
ip address del 192.0.2.2/24 dev $h1
ip link set dev $h1 down
vrf_destroy "vrf-h1"
}
h2_create()
{
vrf_create "vrf-h2"
ip link set dev $h2 master vrf-h2
ip link set dev vrf-h2 up
ip link set dev $h2 up
ip address add 198.51.100.2/24 dev $h2
ip address add 2001:db8:2::2/64 dev $h2
ip route add 192.0.2.0/24 vrf vrf-h2 nexthop via 198.51.100.1
ip route add 2001:db8:1::/64 vrf vrf-h2 nexthop via 2001:db8:2::1
}
h2_destroy()
{
ip route del 2001:db8:1::/64 vrf vrf-h2
ip route del 192.0.2.0/24 vrf vrf-h2
ip address del 2001:db8:2::2/64 dev $h2
ip address del 198.51.100.2/24 dev $h2
ip link set dev $h2 down
vrf_destroy "vrf-h2"
}
router1_create()
{
vrf_create "vrf-r1"
ip link set dev $rp11 master vrf-r1
ip link set dev $rp12 master vrf-r1
ip link set dev $rp13 master vrf-r1
ip link set dev vrf-r1 up
ip link set dev $rp11 up
ip link set dev $rp12 up
ip link set dev $rp13 up
ip address add 192.0.2.1/24 dev $rp11
ip address add 2001:db8:1::1/64 dev $rp11
ip address add 169.254.2.12/24 dev $rp12
ip address add fe80:2::12/64 dev $rp12
ip address add 169.254.3.13/24 dev $rp13
ip address add fe80:3::13/64 dev $rp13
ip route add 198.51.100.0/24 vrf vrf-r1 \
nexthop via 169.254.2.22 dev $rp12 \
nexthop via 169.254.3.23 dev $rp13
ip route add 2001:db8:2::/64 vrf vrf-r1 \
nexthop via fe80:2::22 dev $rp12 \
nexthop via fe80:3::23 dev $rp13
}
router1_destroy()
{
ip route del 2001:db8:2::/64 vrf vrf-r1
ip route del 198.51.100.0/24 vrf vrf-r1
ip address del fe80:3::13/64 dev $rp13
ip address del 169.254.3.13/24 dev $rp13
ip address del fe80:2::12/64 dev $rp12
ip address del 169.254.2.12/24 dev $rp12
ip address del 2001:db8:1::1/64 dev $rp11
ip address del 192.0.2.1/24 dev $rp11
ip link set dev $rp13 down
ip link set dev $rp12 down
ip link set dev $rp11 down
vrf_destroy "vrf-r1"
}
router2_create()
{
vrf_create "vrf-r2"
ip link set dev $rp21 master vrf-r2
ip link set dev $rp22 master vrf-r2
ip link set dev $rp23 master vrf-r2
ip link set dev vrf-r2 up
ip link set dev $rp21 up
ip link set dev $rp22 up
ip link set dev $rp23 up
ip address add 198.51.100.1/24 dev $rp21
ip address add 2001:db8:2::1/64 dev $rp21
ip address add 169.254.2.22/24 dev $rp22
ip address add fe80:2::22/64 dev $rp22
ip address add 169.254.3.23/24 dev $rp23
ip address add fe80:3::23/64 dev $rp23
ip route add 192.0.2.0/24 vrf vrf-r2 \
nexthop via 169.254.2.12 dev $rp22 \
nexthop via 169.254.3.13 dev $rp23
ip route add 2001:db8:1::/64 vrf vrf-r2 \
nexthop via fe80:2::12 dev $rp22 \
nexthop via fe80:3::13 dev $rp23
}
router2_destroy()
{
ip route del 2001:db8:1::/64 vrf vrf-r2
ip route del 192.0.2.0/24 vrf vrf-r2
ip address del fe80:3::23/64 dev $rp23
ip address del 169.254.3.23/24 dev $rp23
ip address del fe80:2::22/64 dev $rp22
ip address del 169.254.2.22/24 dev $rp22
ip address del 2001:db8:2::1/64 dev $rp21
ip address del 198.51.100.1/24 dev $rp21
ip link set dev $rp23 down
ip link set dev $rp22 down
ip link set dev $rp21 down
vrf_destroy "vrf-r2"
}
multipath_eval()
{
local weight_rp12=$1
local weight_rp13=$2
local packets_rp12=$3
local packets_rp13=$4
local weights_ratio packets_ratio diff
RET=0
if [[ "$weight_rp12" -gt "$weight_rp13" ]]; then
weights_ratio=$(echo "scale=2; $weight_rp12 / $weight_rp13" \
| bc -l)
packets_ratio=$(echo "scale=2; $packets_rp12 / $packets_rp13" \
| bc -l)
else
weights_ratio=$(echo "scale=2; $weight_rp13 / $weight_rp12" | \
bc -l)
packets_ratio=$(echo "scale=2; $packets_rp13 / $packets_rp12" | \
bc -l)
fi
diff=$(echo $weights_ratio - $packets_ratio | bc -l)
diff=${diff#-}
test "$(echo "$diff / $weights_ratio > 0.1" | bc -l)" -eq 0
check_err $? "Too large discrepancy between expected and measured ratios"
log_test "Multipath"
log_info "Expected ratio $weights_ratio Measured ratio $packets_ratio"
}
multipath4_test()
{
local weight_rp12=$1
local weight_rp13=$2
local t0_rp12 t0_rp13 t1_rp12 t1_rp13
local packets_rp12 packets_rp13
local hash_policy
# Transmit multiple flows from h1 to h2 and make sure they are
# distributed between both multipath links (rp12 and rp13)
# according to the configured weights.
hash_policy=$(sysctl -n net.ipv4.fib_multipath_hash_policy)
sysctl -q -w net.ipv4.fib_multipath_hash_policy=1
ip route replace 198.51.100.0/24 vrf vrf-r1 \
nexthop via 169.254.2.22 dev $rp12 weight $weight_rp12 \
nexthop via 169.254.3.23 dev $rp13 weight $weight_rp13
t0_rp12=$(link_stats_tx_packets_get $rp12)
t0_rp13=$(link_stats_tx_packets_get $rp13)
ip vrf exec vrf-h1 $MZ -q -p 64 -A 192.0.2.2 -B 198.51.100.2 \
-d 1msec -t udp "sp=1024,dp=0-32768"
t1_rp12=$(link_stats_tx_packets_get $rp12)
t1_rp13=$(link_stats_tx_packets_get $rp13)
let "packets_rp12 = $t1_rp12 - $t0_rp12"
let "packets_rp13 = $t1_rp13 - $t0_rp13"
multipath_eval $weight_rp12 $weight_rp13 $packets_rp12 $packets_rp13
# Restore settings.
ip route replace 198.51.100.0/24 vrf vrf-r1 \
nexthop via 169.254.2.22 dev $rp12 \
nexthop via 169.254.3.23 dev $rp13
sysctl -q -w net.ipv4.fib_multipath_hash_policy=$hash_policy
}
multipath6_test()
{
local weight_rp12=$1
local weight_rp13=$2
local t0_rp12 t0_rp13 t1_rp12 t1_rp13
local packets_rp12 packets_rp13
ip route replace 2001:db8:2::/64 vrf vrf-r1 \
nexthop via fe80:2::22 dev $rp12 weight $weight_rp12 \
nexthop via fe80:3::23 dev $rp13 weight $weight_rp13
t0_rp12=$(link_stats_tx_packets_get $rp12)
t0_rp13=$(link_stats_tx_packets_get $rp13)
# Generate 16384 echo requests, each with a random flow label.
for _ in $(seq 1 16384); do
ip vrf exec vrf-h1 ping 2001:db8:2::2 -F 0 -c 1 -q &> /dev/null
done
t1_rp12=$(link_stats_tx_packets_get $rp12)
t1_rp13=$(link_stats_tx_packets_get $rp13)
let "packets_rp12 = $t1_rp12 - $t0_rp12"
let "packets_rp13 = $t1_rp13 - $t0_rp13"
multipath_eval $weight_rp12 $weight_rp13 $packets_rp12 $packets_rp13
ip route replace 2001:db8:2::/64 vrf vrf-r1 \
nexthop via fe80:2::22 dev $rp12 \
nexthop via fe80:3::23 dev $rp13
}
multipath_test()
{
log_info "Running IPv4 multipath tests"
multipath4_test 1 1
multipath4_test 2 1
multipath4_test 11 45
log_info "Running IPv6 multipath tests"
multipath6_test 1 1
multipath6_test 2 1
multipath6_test 11 45
}
setup_prepare()
{
h1=${NETIFS[p1]}
rp11=${NETIFS[p2]}
rp12=${NETIFS[p3]}
rp22=${NETIFS[p4]}
rp13=${NETIFS[p5]}
rp23=${NETIFS[p6]}
rp21=${NETIFS[p7]}
h2=${NETIFS[p8]}
vrf_prepare
h1_create
h2_create
router1_create
router2_create
forwarding_enable
}
cleanup()
{
pre_cleanup
forwarding_restore
router2_destroy
router1_destroy
h2_destroy
h1_destroy
vrf_cleanup
}
trap cleanup EXIT
setup_prepare
setup_wait
ping_test $h1 198.51.100.2
ping6_test $h1 2001:db8:2::2
multipath_test
exit $EXIT_STATUS
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
NUM_NETIFS=4
source lib.sh
source tc_common.sh
tcflags="skip_hw"
h1_create()
{
simple_if_init $h1 192.0.2.1/24
}
h1_destroy()
{
simple_if_fini $h1 192.0.2.1/24
}
h2_create()
{
simple_if_init $h2 192.0.2.2/24
tc qdisc add dev $h2 clsact
}
h2_destroy()
{
tc qdisc del dev $h2 clsact
simple_if_fini $h2 192.0.2.2/24
}
switch_create()
{
simple_if_init $swp1 192.0.2.2/24
tc qdisc add dev $swp1 clsact
simple_if_init $swp2 192.0.2.1/24
}
switch_destroy()
{
simple_if_fini $swp2 192.0.2.1/24
tc qdisc del dev $swp1 clsact
simple_if_fini $swp1 192.0.2.2/24
}
mirred_egress_redirect_test()
{
RET=0
tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
$tcflags dst_ip 192.0.2.2 action drop
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
-t ip -q
tc_check_packets "dev $h2 ingress" 101 1
check_fail $? "Matched without redirect rule inserted"
tc filter add dev $swp1 ingress protocol ip pref 1 handle 101 flower \
$tcflags dst_ip 192.0.2.2 action mirred egress redirect \
dev $swp2
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
-t ip -q
tc_check_packets "dev $h2 ingress" 101 1
check_err $? "Did not match incoming redirected packet"
tc filter del dev $swp1 ingress protocol ip pref 1 handle 101 flower
tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
log_test "mirred egress redirect ($tcflags)"
}
gact_drop_and_ok_test()
{
RET=0
tc filter add dev $swp1 ingress protocol ip pref 2 handle 102 flower \
skip_hw dst_ip 192.0.2.2 action drop
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
-t ip -q
tc_check_packets "dev $swp1 ingress" 102 1
check_err $? "Packet was not dropped"
tc filter add dev $swp1 ingress protocol ip pref 1 handle 101 flower \
$tcflags dst_ip 192.0.2.2 action ok
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
-t ip -q
tc_check_packets "dev $swp1 ingress" 101 1
check_err $? "Did not see trapped packet"
tc filter del dev $swp1 ingress protocol ip pref 2 handle 102 flower
tc filter del dev $swp1 ingress protocol ip pref 1 handle 101 flower
log_test "gact drop and ok ($tcflags)"
}
gact_trap_test()
{
RET=0
tc filter add dev $swp1 ingress protocol ip pref 1 handle 101 flower \
skip_hw dst_ip 192.0.2.2 action drop
tc filter add dev $swp1 ingress protocol ip pref 3 handle 103 flower \
$tcflags dst_ip 192.0.2.2 action mirred egress redirect \
dev $swp2
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
-t ip -q
tc_check_packets "dev $swp1 ingress" 101 1
check_fail $? "Saw packet without trap rule inserted"
tc filter add dev $swp1 ingress protocol ip pref 2 handle 102 flower \
$tcflags dst_ip 192.0.2.2 action trap
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
-t ip -q
tc_check_packets "dev $swp1 ingress" 102 1
check_err $? "Packet was not trapped"
tc_check_packets "dev $swp1 ingress" 101 1
check_err $? "Did not see trapped packet"
tc filter del dev $swp1 ingress protocol ip pref 3 handle 103 flower
tc filter del dev $swp1 ingress protocol ip pref 2 handle 102 flower
tc filter del dev $swp1 ingress protocol ip pref 1 handle 101 flower
log_test "trap ($tcflags)"
}
setup_prepare()
{
h1=${NETIFS[p1]}
swp1=${NETIFS[p2]}
swp2=${NETIFS[p3]}
h2=${NETIFS[p4]}
h1mac=$(mac_get $h1)
h2mac=$(mac_get $h2)
swp1origmac=$(mac_get $swp1)
swp2origmac=$(mac_get $swp2)
ip link set $swp1 address $h2mac
ip link set $swp2 address $h1mac
vrf_prepare
h1_create
h2_create
switch_create
}
cleanup()
{
pre_cleanup
switch_destroy
h2_destroy
h1_destroy
vrf_cleanup
ip link set $swp2 address $swp2origmac
ip link set $swp1 address $swp1origmac
}
trap cleanup EXIT
setup_prepare
setup_wait
gact_drop_and_ok_test
mirred_egress_redirect_test
tc_offload_check
if [[ $? -ne 0 ]]; then
log_info "Could not test offloaded functionality"
else
tcflags="skip_sw"
gact_drop_and_ok_test
mirred_egress_redirect_test
gact_trap_test
fi
exit $EXIT_STATUS
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
NUM_NETIFS=2
source lib.sh
source tc_common.sh
tcflags="skip_hw"
h1_create()
{
simple_if_init $h1 192.0.2.1/24
}
h1_destroy()
{
simple_if_fini $h1 192.0.2.1/24
}
h2_create()
{
simple_if_init $h2 192.0.2.2/24
tc qdisc add dev $h2 clsact
}
h2_destroy()
{
tc qdisc del dev $h2 clsact
simple_if_fini $h2 192.0.2.2/24
}
unreachable_chain_test()
{
RET=0
tc filter add dev $h2 ingress chain 1 protocol ip pref 1 handle 1101 \
flower $tcflags dst_mac $h2mac action drop
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
-t ip -q
tc_check_packets "dev $h2 ingress" 1101 1
check_fail $? "matched on filter in unreachable chain"
tc filter del dev $h2 ingress chain 1 protocol ip pref 1 handle 1101 \
flower
log_test "unreachable chain ($tcflags)"
}
gact_goto_chain_test()
{
RET=0
tc filter add dev $h2 ingress chain 1 protocol ip pref 1 handle 1101 \
flower $tcflags dst_mac $h2mac action drop
tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
$tcflags dst_mac $h2mac action drop
tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
$tcflags dst_mac $h2mac action goto chain 1
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
-t ip -q
tc_check_packets "dev $h2 ingress" 102 1
check_fail $? "Matched on a wrong filter"
tc_check_packets "dev $h2 ingress" 101 1
check_err $? "Did not match on correct filter with goto chain action"
tc_check_packets "dev $h2 ingress" 1101 1
check_err $? "Did not match on correct filter in chain 1"
tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
tc filter del dev $h2 ingress chain 1 protocol ip pref 1 handle 1101 \
flower
log_test "gact goto chain ($tcflags)"
}
setup_prepare()
{
h1=${NETIFS[p1]}
h2=${NETIFS[p2]}
h1mac=$(mac_get $h1)
h2mac=$(mac_get $h2)
vrf_prepare
h1_create
h2_create
}
cleanup()
{
pre_cleanup
h2_destroy
h1_destroy
vrf_cleanup
}
trap cleanup EXIT
setup_prepare
setup_wait
unreachable_chain_test
gact_goto_chain_test
tc_offload_check
if [[ $? -ne 0 ]]; then
log_info "Could not test offloaded functionality"
else
tcflags="skip_sw"
unreachable_chain_test
gact_goto_chain_test
fi
exit $EXIT_STATUS
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
tc_check_packets()
{
local id=$1
local handle=$2
local count=$3
local ret
output="$(tc -j -s filter show $id)"
# workaround the jq bug which causes jq to return 0 in case input is ""
ret=$?
if [[ $ret -ne 0 ]]; then
return $ret
fi
echo $output | \
jq -e ".[] \
| select(.options.handle == $handle) \
| select(.options.actions[0].stats.packets == $count)" \
&> /dev/null
return $?
}
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
NUM_NETIFS=2
source lib.sh
source tc_common.sh
tcflags="skip_hw"
h1_create()
{
simple_if_init $h1 192.0.2.1/24 198.51.100.1/24
}
h1_destroy()
{
simple_if_fini $h1 192.0.2.1/24 198.51.100.1/24
}
h2_create()
{
simple_if_init $h2 192.0.2.2/24 198.51.100.2/24
tc qdisc add dev $h2 clsact
}
h2_destroy()
{
tc qdisc del dev $h2 clsact
simple_if_fini $h2 192.0.2.2/24 198.51.100.2/24
}
match_dst_mac_test()
{
local dummy_mac=de:ad:be:ef:aa:aa
RET=0
tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
$tcflags dst_mac $dummy_mac action drop
tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
$tcflags dst_mac $h2mac action drop
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
-t ip -q
tc_check_packets "dev $h2 ingress" 101 1
check_fail $? "Matched on a wrong filter"
tc_check_packets "dev $h2 ingress" 102 1
check_err $? "Did not match on correct filter"
tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
log_test "dst_mac match ($tcflags)"
}
match_src_mac_test()
{
local dummy_mac=de:ad:be:ef:aa:aa
RET=0
tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
$tcflags src_mac $dummy_mac action drop
tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
$tcflags src_mac $h1mac action drop
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
-t ip -q
tc_check_packets "dev $h2 ingress" 101 1
check_fail $? "Matched on a wrong filter"
tc_check_packets "dev $h2 ingress" 102 1
check_err $? "Did not match on correct filter"
tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
log_test "src_mac match ($tcflags)"
}
match_dst_ip_test()
{
RET=0
tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
$tcflags dst_ip 198.51.100.2 action drop
tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
$tcflags dst_ip 192.0.2.2 action drop
tc filter add dev $h2 ingress protocol ip pref 3 handle 103 flower \
$tcflags dst_ip 192.0.2.0/24 action drop
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
-t ip -q
tc_check_packets "dev $h2 ingress" 101 1
check_fail $? "Matched on a wrong filter"
tc_check_packets "dev $h2 ingress" 102 1
check_err $? "Did not match on correct filter"
tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
-t ip -q
tc_check_packets "dev $h2 ingress" 103 1
check_err $? "Did not match on correct filter with mask"
tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
tc filter del dev $h2 ingress protocol ip pref 3 handle 103 flower
log_test "dst_ip match ($tcflags)"
}
match_src_ip_test()
{
RET=0
tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
$tcflags src_ip 198.51.100.1 action drop
tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
$tcflags src_ip 192.0.2.1 action drop
tc filter add dev $h2 ingress protocol ip pref 3 handle 103 flower \
$tcflags src_ip 192.0.2.0/24 action drop
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
-t ip -q
tc_check_packets "dev $h2 ingress" 101 1
check_fail $? "Matched on a wrong filter"
tc_check_packets "dev $h2 ingress" 102 1
check_err $? "Did not match on correct filter"
tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
-t ip -q
tc_check_packets "dev $h2 ingress" 103 1
check_err $? "Did not match on correct filter with mask"
tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
tc filter del dev $h2 ingress protocol ip pref 3 handle 103 flower
log_test "src_ip match ($tcflags)"
}
setup_prepare()
{
h1=${NETIFS[p1]}
h2=${NETIFS[p2]}
h1mac=$(mac_get $h1)
h2mac=$(mac_get $h2)
vrf_prepare
h1_create
h2_create
}
cleanup()
{
pre_cleanup
h2_destroy
h1_destroy
vrf_cleanup
}
trap cleanup EXIT
setup_prepare
setup_wait
match_dst_mac_test
match_src_mac_test
match_dst_ip_test
match_src_ip_test
tc_offload_check
if [[ $? -ne 0 ]]; then
log_info "Could not test offloaded functionality"
else
tcflags="skip_sw"
match_dst_mac_test
match_src_mac_test
match_dst_ip_test
match_src_ip_test
fi
exit $EXIT_STATUS
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
NUM_NETIFS=4
source lib.sh
source tc_common.sh
tcflags="skip_hw"
h1_create()
{
simple_if_init $h1 192.0.2.1/24
}
h1_destroy()
{
simple_if_fini $h1 192.0.2.1/24
}
h2_create()
{
simple_if_init $h2 192.0.2.1/24
}
h2_destroy()
{
simple_if_fini $h2 192.0.2.1/24
}
switch_create()
{
simple_if_init $swp1 192.0.2.2/24
tc qdisc add dev $swp1 ingress_block 22 egress_block 23 clsact
simple_if_init $swp2 192.0.2.2/24
tc qdisc add dev $swp2 ingress_block 22 egress_block 23 clsact
}
switch_destroy()
{
tc qdisc del dev $swp2 clsact
simple_if_fini $swp2 192.0.2.2/24
tc qdisc del dev $swp1 clsact
simple_if_fini $swp1 192.0.2.2/24
}
shared_block_test()
{
RET=0
tc filter add block 22 protocol ip pref 1 handle 101 flower \
$tcflags dst_ip 192.0.2.2 action drop
$MZ $h1 -c 1 -p 64 -a $h1mac -b $swmac -A 192.0.2.1 -B 192.0.2.2 \
-t ip -q
tc_check_packets "block 22" 101 1
check_err $? "Did not match first incoming packet on a block"
$MZ $h2 -c 1 -p 64 -a $h2mac -b $swmac -A 192.0.2.1 -B 192.0.2.2 \
-t ip -q
tc_check_packets "block 22" 101 2
check_err $? "Did not match second incoming packet on a block"
tc filter del block 22 protocol ip pref 1 handle 101 flower
log_test "shared block ($tcflags)"
}
setup_prepare()
{
h1=${NETIFS[p1]}
swp1=${NETIFS[p2]}
swp2=${NETIFS[p3]}
h2=${NETIFS[p4]}
h1mac=$(mac_get $h1)
h2mac=$(mac_get $h2)
swmac=$(mac_get $swp1)
swp2origmac=$(mac_get $swp2)
ip link set $swp2 address $swmac
vrf_prepare
h1_create
h2_create
switch_create
}
cleanup()
{
pre_cleanup
switch_destroy
h2_destroy
h1_destroy
vrf_cleanup
ip link set $swp2 address $swp2origmac
}
trap cleanup EXIT
setup_prepare
setup_wait
shared_block_test
tc_offload_check
if [[ $? -ne 0 ]]; then
log_info "Could not test offloaded functionality"
else
tcflags="skip_sw"
shared_block_test
fi
exit $EXIT_STATUS
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment