selftests: net: Test for the IOAM encapsulation with IPv6

This patch adds support for testing the encap (ip6ip6) mode of IOAM.

Signed-off-by: Justin Iurman <justin.iurman@uliege.be>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Justin Iurman 2021-10-03 20:45:39 +02:00 committed by David S. Miller
parent 8cb3bf8bff
commit bf77b1400a

View File

@ -6,7 +6,7 @@
# This script evaluates the IOAM insertion for IPv6 by checking the IOAM data # This script evaluates the IOAM insertion for IPv6 by checking the IOAM data
# consistency directly inside packets on the receiver side. Tests are divided # consistency directly inside packets on the receiver side. Tests are divided
# into three categories: OUTPUT (evaluates the IOAM processing by the sender), # into three categories: OUTPUT (evaluates the IOAM processing by the sender),
# INPUT (evaluates the IOAM processing by the receiver) and GLOBAL (evaluates # INPUT (evaluates the IOAM processing by a receiver) and GLOBAL (evaluates
# wider use cases that do not fall into the other two categories). Both OUTPUT # wider use cases that do not fall into the other two categories). Both OUTPUT
# and INPUT tests only use a two-node topology (alpha and beta), while GLOBAL # and INPUT tests only use a two-node topology (alpha and beta), while GLOBAL
# tests use the entire three-node topology (alpha, beta, gamma). Each test is # tests use the entire three-node topology (alpha, beta, gamma). Each test is
@ -200,7 +200,7 @@ check_kernel_compatibility()
ip -netns ioam-tmp-node link set veth0 up ip -netns ioam-tmp-node link set veth0 up
ip -netns ioam-tmp-node link set veth1 up ip -netns ioam-tmp-node link set veth1 up
ip -netns ioam-tmp-node ioam namespace add 0 &>/dev/null ip -netns ioam-tmp-node ioam namespace add 0
ns_ad=$? ns_ad=$?
ip -netns ioam-tmp-node ioam namespace show | grep -q "namespace 0" ip -netns ioam-tmp-node ioam namespace show | grep -q "namespace 0"
@ -214,11 +214,11 @@ check_kernel_compatibility()
exit 1 exit 1
fi fi
ip -netns ioam-tmp-node route add db02::/64 encap ioam6 trace prealloc \ ip -netns ioam-tmp-node route add db02::/64 encap ioam6 mode inline \
type 0x800000 ns 0 size 4 dev veth0 &>/dev/null trace prealloc type 0x800000 ns 0 size 4 dev veth0
tr_ad=$? tr_ad=$?
ip -netns ioam-tmp-node -6 route | grep -q "encap ioam6 trace" ip -netns ioam-tmp-node -6 route | grep -q "encap ioam6"
tr_sh=$? tr_sh=$?
if [[ $tr_ad != 0 || $tr_sh != 0 ]] if [[ $tr_ad != 0 || $tr_sh != 0 ]]
@ -232,6 +232,30 @@ check_kernel_compatibility()
ip link del veth0 2>/dev/null || true ip link del veth0 2>/dev/null || true
ip netns del ioam-tmp-node || true ip netns del ioam-tmp-node || true
lsmod | grep -q "ip6_tunnel"
ip6tnl_loaded=$?
if [ $ip6tnl_loaded = 0 ]
then
encap_tests=0
else
modprobe ip6_tunnel &>/dev/null
lsmod | grep -q "ip6_tunnel"
encap_tests=$?
if [ $encap_tests != 0 ]
then
ip a | grep -q "ip6tnl0"
encap_tests=$?
if [ $encap_tests != 0 ]
then
echo "Note: ip6_tunnel not found neither as a module nor inside the" \
"kernel, tests that require it (encap mode) will be omitted"
fi
fi
fi
} }
cleanup() cleanup()
@ -242,6 +266,11 @@ cleanup()
ip netns del ioam-node-alpha || true ip netns del ioam-node-alpha || true
ip netns del ioam-node-beta || true ip netns del ioam-node-beta || true
ip netns del ioam-node-gamma || true ip netns del ioam-node-gamma || true
if [ $ip6tnl_loaded != 0 ]
then
modprobe -r ip6_tunnel 2>/dev/null || true
fi
} }
setup() setup()
@ -329,6 +358,12 @@ log_test_failed()
printf "TEST: %-60s [FAIL]\n" "${desc}" printf "TEST: %-60s [FAIL]\n" "${desc}"
} }
log_results()
{
echo "- Tests passed: ${npassed}"
echo "- Tests failed: ${nfailed}"
}
run_test() run_test()
{ {
local name=$1 local name=$1
@ -349,16 +384,26 @@ run_test()
ip netns exec $node_src ping6 -t 64 -c 1 -W 1 $ip6_dst &>/dev/null ip netns exec $node_src ping6 -t 64 -c 1 -W 1 $ip6_dst &>/dev/null
if [ $? != 0 ] if [ $? != 0 ]
then then
nfailed=$((nfailed+1))
log_test_failed "${desc}" log_test_failed "${desc}"
kill -2 $spid &>/dev/null kill -2 $spid &>/dev/null
else else
wait $spid wait $spid
[ $? = 0 ] && log_test_passed "${desc}" || log_test_failed "${desc}" if [ $? = 0 ]
then
npassed=$((npassed+1))
log_test_passed "${desc}"
else
nfailed=$((nfailed+1))
log_test_failed "${desc}"
fi
fi fi
} }
run() run()
{ {
echo
printf "%0.s-" {1..74}
echo echo
echo "OUTPUT tests" echo "OUTPUT tests"
printf "%0.s-" {1..74} printf "%0.s-" {1..74}
@ -369,7 +414,8 @@ run()
for t in $TESTS_OUTPUT for t in $TESTS_OUTPUT
do do
$t $t "inline"
[ $encap_tests = 0 ] && $t "encap"
done done
# clean OUTPUT settings # clean OUTPUT settings
@ -377,6 +423,8 @@ run()
ip -netns ioam-node-alpha route change db01::/64 dev veth0 ip -netns ioam-node-alpha route change db01::/64 dev veth0
echo
printf "%0.s-" {1..74}
echo echo
echo "INPUT tests" echo "INPUT tests"
printf "%0.s-" {1..74} printf "%0.s-" {1..74}
@ -387,7 +435,8 @@ run()
for t in $TESTS_INPUT for t in $TESTS_INPUT
do do
$t $t "inline"
[ $encap_tests = 0 ] && $t "encap"
done done
# clean INPUT settings # clean INPUT settings
@ -396,7 +445,8 @@ run()
ip -netns ioam-node-alpha ioam namespace set 123 schema ${ALPHA[8]} ip -netns ioam-node-alpha ioam namespace set 123 schema ${ALPHA[8]}
ip -netns ioam-node-alpha route change db01::/64 dev veth0 ip -netns ioam-node-alpha route change db01::/64 dev veth0
echo
printf "%0.s-" {1..74}
echo echo
echo "GLOBAL tests" echo "GLOBAL tests"
printf "%0.s-" {1..74} printf "%0.s-" {1..74}
@ -404,8 +454,12 @@ run()
for t in $TESTS_GLOBAL for t in $TESTS_GLOBAL
do do
$t $t "inline"
[ $encap_tests = 0 ] && $t "encap"
done done
echo
log_results
} }
bit2type=( bit2type=(
@ -431,11 +485,16 @@ out_undef_ns()
############################################################################## ##############################################################################
local desc="Unknown IOAM namespace" local desc="Unknown IOAM namespace"
ip -netns ioam-node-alpha route change db01::/64 encap ioam6 trace prealloc \ [ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1"
type 0x800000 ns 0 size 4 dev veth0 [ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 up
run_test ${FUNCNAME[0]} "${desc}" ioam-node-alpha ioam-node-beta db01::2 \ ip -netns ioam-node-alpha route change db01::/64 encap ioam6 mode $mode \
db01::1 veth0 0x800000 0 trace prealloc type 0x800000 ns 0 size 4 dev veth0
run_test ${FUNCNAME[0]} "${desc} ($1 mode)" ioam-node-alpha ioam-node-beta \
db01::2 db01::1 veth0 0x800000 0
[ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 down
} }
out_no_room() out_no_room()
@ -446,11 +505,16 @@ out_no_room()
############################################################################## ##############################################################################
local desc="Missing trace room" local desc="Missing trace room"
ip -netns ioam-node-alpha route change db01::/64 encap ioam6 trace prealloc \ [ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1"
type 0xc00000 ns 123 size 4 dev veth0 [ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 up
run_test ${FUNCNAME[0]} "${desc}" ioam-node-alpha ioam-node-beta db01::2 \ ip -netns ioam-node-alpha route change db01::/64 encap ioam6 mode $mode \
db01::1 veth0 0xc00000 123 trace prealloc type 0xc00000 ns 123 size 4 dev veth0
run_test ${FUNCNAME[0]} "${desc} ($1 mode)" ioam-node-alpha ioam-node-beta \
db01::2 db01::1 veth0 0xc00000 123
[ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 down
} }
out_bits() out_bits()
@ -465,15 +529,21 @@ out_bits()
local tmp=${bit2size[22]} local tmp=${bit2size[22]}
bit2size[22]=$(( $tmp + ${#ALPHA[9]} + ((4 - (${#ALPHA[9]} % 4)) % 4) )) bit2size[22]=$(( $tmp + ${#ALPHA[9]} + ((4 - (${#ALPHA[9]} % 4)) % 4) ))
[ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1"
[ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 up
for i in {0..22} for i in {0..22}
do do
ip -netns ioam-node-alpha route change db01::/64 encap ioam6 trace \ ip -netns ioam-node-alpha route change db01::/64 encap ioam6 mode $mode \
prealloc type ${bit2type[$i]} ns 123 size ${bit2size[$i]} dev veth0 trace prealloc type ${bit2type[$i]} ns 123 size ${bit2size[$i]} \
dev veth0
run_test "out_bit$i" "${desc/<n>/$i}" ioam-node-alpha ioam-node-beta \ run_test "out_bit$i" "${desc/<n>/$i} ($1 mode)" ioam-node-alpha \
db01::2 db01::1 veth0 ${bit2type[$i]} 123 ioam-node-beta db01::2 db01::1 veth0 ${bit2type[$i]} 123
done done
[ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 down
bit2size[22]=$tmp bit2size[22]=$tmp
} }
@ -485,11 +555,16 @@ out_full_supp_trace()
############################################################################## ##############################################################################
local desc="Full supported trace" local desc="Full supported trace"
ip -netns ioam-node-alpha route change db01::/64 encap ioam6 trace prealloc \ [ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1"
type 0xfff002 ns 123 size 100 dev veth0 [ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 up
run_test ${FUNCNAME[0]} "${desc}" ioam-node-alpha ioam-node-beta db01::2 \ ip -netns ioam-node-alpha route change db01::/64 encap ioam6 mode $mode \
db01::1 veth0 0xfff002 123 trace prealloc type 0xfff002 ns 123 size 100 dev veth0
run_test ${FUNCNAME[0]} "${desc} ($1 mode)" ioam-node-alpha ioam-node-beta \
db01::2 db01::1 veth0 0xfff002 123
[ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 down
} }
@ -510,11 +585,16 @@ in_undef_ns()
############################################################################## ##############################################################################
local desc="Unknown IOAM namespace" local desc="Unknown IOAM namespace"
ip -netns ioam-node-alpha route change db01::/64 encap ioam6 trace prealloc \ [ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1"
type 0x800000 ns 0 size 4 dev veth0 [ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 up
run_test ${FUNCNAME[0]} "${desc}" ioam-node-alpha ioam-node-beta db01::2 \ ip -netns ioam-node-alpha route change db01::/64 encap ioam6 mode $mode \
db01::1 veth0 0x800000 0 trace prealloc type 0x800000 ns 0 size 4 dev veth0
run_test ${FUNCNAME[0]} "${desc} ($1 mode)" ioam-node-alpha ioam-node-beta \
db01::2 db01::1 veth0 0x800000 0
[ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 down
} }
in_no_room() in_no_room()
@ -525,11 +605,16 @@ in_no_room()
############################################################################## ##############################################################################
local desc="Missing trace room" local desc="Missing trace room"
ip -netns ioam-node-alpha route change db01::/64 encap ioam6 trace prealloc \ [ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1"
type 0xc00000 ns 123 size 4 dev veth0 [ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 up
run_test ${FUNCNAME[0]} "${desc}" ioam-node-alpha ioam-node-beta db01::2 \ ip -netns ioam-node-alpha route change db01::/64 encap ioam6 mode $mode \
db01::1 veth0 0xc00000 123 trace prealloc type 0xc00000 ns 123 size 4 dev veth0
run_test ${FUNCNAME[0]} "${desc} ($1 mode)" ioam-node-alpha ioam-node-beta \
db01::2 db01::1 veth0 0xc00000 123
[ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 down
} }
in_bits() in_bits()
@ -544,15 +629,21 @@ in_bits()
local tmp=${bit2size[22]} local tmp=${bit2size[22]}
bit2size[22]=$(( $tmp + ${#BETA[9]} + ((4 - (${#BETA[9]} % 4)) % 4) )) bit2size[22]=$(( $tmp + ${#BETA[9]} + ((4 - (${#BETA[9]} % 4)) % 4) ))
[ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1"
[ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 up
for i in {0..22} for i in {0..22}
do do
ip -netns ioam-node-alpha route change db01::/64 encap ioam6 trace \ ip -netns ioam-node-alpha route change db01::/64 encap ioam6 mode $mode \
prealloc type ${bit2type[$i]} ns 123 size ${bit2size[$i]} dev veth0 trace prealloc type ${bit2type[$i]} ns 123 size ${bit2size[$i]} \
dev veth0
run_test "in_bit$i" "${desc/<n>/$i}" ioam-node-alpha ioam-node-beta \ run_test "in_bit$i" "${desc/<n>/$i} ($1 mode)" ioam-node-alpha \
db01::2 db01::1 veth0 ${bit2type[$i]} 123 ioam-node-beta db01::2 db01::1 veth0 ${bit2type[$i]} 123
done done
[ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 down
bit2size[22]=$tmp bit2size[22]=$tmp
} }
@ -569,11 +660,16 @@ in_oflag()
# back the IOAM namespace that was previously configured on the sender. # back the IOAM namespace that was previously configured on the sender.
ip -netns ioam-node-alpha ioam namespace add 123 ip -netns ioam-node-alpha ioam namespace add 123
ip -netns ioam-node-alpha route change db01::/64 encap ioam6 trace prealloc \ [ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1"
type 0xc00000 ns 123 size 4 dev veth0 [ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 up
run_test ${FUNCNAME[0]} "${desc}" ioam-node-alpha ioam-node-beta db01::2 \ ip -netns ioam-node-alpha route change db01::/64 encap ioam6 mode $mode \
db01::1 veth0 0xc00000 123 trace prealloc type 0xc00000 ns 123 size 4 dev veth0
run_test ${FUNCNAME[0]} "${desc} ($1 mode)" ioam-node-alpha ioam-node-beta \
db01::2 db01::1 veth0 0xc00000 123
[ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 down
# And we clean the exception for this test to get things back to normal for # And we clean the exception for this test to get things back to normal for
# other INPUT tests # other INPUT tests
@ -588,11 +684,16 @@ in_full_supp_trace()
############################################################################## ##############################################################################
local desc="Full supported trace" local desc="Full supported trace"
ip -netns ioam-node-alpha route change db01::/64 encap ioam6 trace prealloc \ [ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1"
type 0xfff002 ns 123 size 80 dev veth0 [ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 up
run_test ${FUNCNAME[0]} "${desc}" ioam-node-alpha ioam-node-beta db01::2 \ ip -netns ioam-node-alpha route change db01::/64 encap ioam6 mode $mode \
db01::1 veth0 0xfff002 123 trace prealloc type 0xfff002 ns 123 size 80 dev veth0
run_test ${FUNCNAME[0]} "${desc} ($1 mode)" ioam-node-alpha ioam-node-beta \
db01::2 db01::1 veth0 0xfff002 123
[ "$1" = "encap" ] && ip -netns ioam-node-beta link set ip6tnl0 down
} }
@ -611,11 +712,16 @@ fwd_full_supp_trace()
############################################################################## ##############################################################################
local desc="Forward - Full supported trace" local desc="Forward - Full supported trace"
ip -netns ioam-node-alpha route change db02::/64 encap ioam6 trace prealloc \ [ "$1" = "encap" ] && mode="$1 tundst db02::2" || mode="$1"
type 0xfff002 ns 123 size 244 via db01::1 dev veth0 [ "$1" = "encap" ] && ip -netns ioam-node-gamma link set ip6tnl0 up
run_test ${FUNCNAME[0]} "${desc}" ioam-node-alpha ioam-node-gamma db01::2 \ ip -netns ioam-node-alpha route change db02::/64 encap ioam6 mode $mode \
db02::2 veth0 0xfff002 123 trace prealloc type 0xfff002 ns 123 size 244 via db01::1 dev veth0
run_test ${FUNCNAME[0]} "${desc} ($1 mode)" ioam-node-alpha ioam-node-gamma \
db01::2 db02::2 veth0 0xfff002 123
[ "$1" = "encap" ] && ip -netns ioam-node-gamma link set ip6tnl0 down
} }
@ -625,6 +731,9 @@ fwd_full_supp_trace()
# # # #
################################################################################ ################################################################################
npassed=0
nfailed=0
if [ "$(id -u)" -ne 0 ] if [ "$(id -u)" -ne 0 ]
then then
echo "SKIP: Need root privileges" echo "SKIP: Need root privileges"