Commit 6e51d914 authored by David S. Miller's avatar David S. Miller

Merge branch 'mptcp-selftests'

Matthieu Baerts says:

====================
selftests: mptcp: cleanups and 'ip mptcp' support

Here are some patches from Geliang, doing different cleanups, and
supporting 'ip mptcp' in more MPTCP selftests.

Patch 1 checks that TC is available in selftests requiring it.

Patch 2 adds 'ms' units in TC commands, to avoid confusions.

Patches 3-9 are some prerequisites for patch 10: some export code from
mptcp_join.sh to mptcp_lib.sh, to be re-used in pm_netlink.sh,
mptcp_sockopt.sh and simult_flows.sh ; and others add helpers to
pm_netlink.sh to easily support both 'ip mptcp' and 'pm_nl_ctl' tools to
interact with the in-kernel MPTCP path-manager.

Patch 10 adds a '-i' parameter in mptcp_sockopt.sh, pm_netlink.sh, and
simult_flows.sh to use 'ip mptcp' tool instead of 'pm_nl_ctl'.

Patch 11 fixes some ShellCheck warnings in pm_netlink.sh, in order to
drop a ShellCheck's 'disable' instruction.
====================
Signed-off-by: default avatarMatthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents d2c3a7eb 6eaeda12
...@@ -147,7 +147,7 @@ cleanup() ...@@ -147,7 +147,7 @@ cleanup()
mptcp_lib_check_mptcp mptcp_lib_check_mptcp
mptcp_lib_check_kallsyms mptcp_lib_check_kallsyms
mptcp_lib_check_tools ip mptcp_lib_check_tools ip tc
sin=$(mktemp) sin=$(mktemp)
sout=$(mktemp) sout=$(mktemp)
......
...@@ -31,7 +31,6 @@ timeout_poll=30 ...@@ -31,7 +31,6 @@ timeout_poll=30
timeout_test=$((timeout_poll * 2 + 1)) timeout_test=$((timeout_poll * 2 + 1))
capture=false capture=false
checksum=false checksum=false
ip_mptcp=0
check_invert=0 check_invert=0
validate_checksum=false validate_checksum=false
init=0 init=0
...@@ -125,8 +124,8 @@ init_shapers() ...@@ -125,8 +124,8 @@ init_shapers()
{ {
local i local i
for i in $(seq 1 4); do for i in $(seq 1 4); do
tc -n $ns1 qdisc add dev ns1eth$i root netem rate 20mbit delay 1 tc -n $ns1 qdisc add dev ns1eth$i root netem rate 20mbit delay 1ms
tc -n $ns2 qdisc add dev ns2eth$i root netem rate 20mbit delay 1 tc -n $ns2 qdisc add dev ns2eth$i root netem rate 20mbit delay 1ms
done done
} }
...@@ -142,7 +141,7 @@ init() { ...@@ -142,7 +141,7 @@ init() {
mptcp_lib_check_mptcp mptcp_lib_check_mptcp
mptcp_lib_check_kallsyms mptcp_lib_check_kallsyms
mptcp_lib_check_tools ip ss "${iptables}" "${ip6tables}" mptcp_lib_check_tools ip tc ss "${iptables}" "${ip6tables}"
sin=$(mktemp) sin=$(mktemp)
sout=$(mktemp) sout=$(mktemp)
...@@ -606,173 +605,65 @@ kill_events_pids() ...@@ -606,173 +605,65 @@ kill_events_pids()
pm_nl_set_limits() pm_nl_set_limits()
{ {
local ns=$1 mptcp_lib_pm_nl_set_limits "${@}"
local addrs=$2
local subflows=$3
if [ $ip_mptcp -eq 1 ]; then
ip -n $ns mptcp limits set add_addr_accepted $addrs subflows $subflows
else
ip netns exec $ns ./pm_nl_ctl limits $addrs $subflows
fi
} }
pm_nl_add_endpoint() pm_nl_add_endpoint()
{ {
local ns=$1 mptcp_lib_pm_nl_add_endpoint "${@}"
local addr=$2
local flags _flags
local port _port
local dev _dev
local id _id
local nr=2
local p
for p in "${@}"
do
if [ $p = "flags" ]; then
eval _flags=\$"$nr"
[ -n "$_flags" ]; flags="flags $_flags"
fi
if [ $p = "dev" ]; then
eval _dev=\$"$nr"
[ -n "$_dev" ]; dev="dev $_dev"
fi
if [ $p = "id" ]; then
eval _id=\$"$nr"
[ -n "$_id" ]; id="id $_id"
fi
if [ $p = "port" ]; then
eval _port=\$"$nr"
[ -n "$_port" ]; port="port $_port"
fi
nr=$((nr + 1))
done
if [ $ip_mptcp -eq 1 ]; then
ip -n $ns mptcp endpoint add $addr ${_flags//","/" "} $dev $id $port
else
ip netns exec $ns ./pm_nl_ctl add $addr $flags $dev $id $port
fi
} }
pm_nl_del_endpoint() pm_nl_del_endpoint()
{ {
local ns=$1 mptcp_lib_pm_nl_del_endpoint "${@}"
local id=$2
local addr=$3
if [ $ip_mptcp -eq 1 ]; then
[ $id -ne 0 ] && addr=''
ip -n $ns mptcp endpoint delete id $id $addr
else
ip netns exec $ns ./pm_nl_ctl del $id $addr
fi
} }
pm_nl_flush_endpoint() pm_nl_flush_endpoint()
{ {
local ns=$1 mptcp_lib_pm_nl_flush_endpoint "${@}"
if [ $ip_mptcp -eq 1 ]; then
ip -n $ns mptcp endpoint flush
else
ip netns exec $ns ./pm_nl_ctl flush
fi
} }
pm_nl_show_endpoints() pm_nl_show_endpoints()
{ {
local ns=$1 mptcp_lib_pm_nl_show_endpoints "${@}"
if [ $ip_mptcp -eq 1 ]; then
ip -n $ns mptcp endpoint show
else
ip netns exec $ns ./pm_nl_ctl dump
fi
} }
pm_nl_change_endpoint() pm_nl_change_endpoint()
{ {
local ns=$1 mptcp_lib_pm_nl_change_endpoint "${@}"
local id=$2
local flags=$3
if [ $ip_mptcp -eq 1 ]; then
ip -n $ns mptcp endpoint change id $id ${flags//","/" "}
else
ip netns exec $ns ./pm_nl_ctl set id $id flags $flags
fi
} }
pm_nl_check_endpoint() pm_nl_check_endpoint()
{ {
local line expected_line
local msg="$1" local msg="$1"
local ns=$2 local ns=$2
local addr=$3 local addr=$3
local _flags="" local flags dev id port
local flags
local _port
local port
local dev
local _id
local id
print_check "${msg}" print_check "${msg}"
shift 3 shift 3
while [ -n "$1" ]; do while [ -n "$1" ]; do
if [ $1 = "flags" ]; then case "${1}" in
_flags=$2 "flags" | "dev" | "id" | "port")
[ -n "$_flags" ]; flags="flags $_flags" eval "${1}"="${2}"
shift
elif [ $1 = "dev" ]; then
[ -n "$2" ]; dev="dev $2"
shift shift
elif [ $1 = "id" ]; then ;;
_id=$2 *)
[ -n "$_id" ]; id="id $_id" ;;
shift esac
elif [ $1 = "port" ]; then
_port=$2
[ -n "$_port" ]; port=" port $_port"
shift
fi
shift shift
done done
if [ -z "$id" ]; then if [ -z "${id}" ]; then
test_fail "bad test - missing endpoint id" test_fail "bad test - missing endpoint id"
return return
fi fi
if [ $ip_mptcp -eq 1 ]; then check_output "mptcp_lib_pm_nl_get_endpoint ${ns} ${id}" \
# get line and trim trailing whitespace "$(mptcp_lib_pm_nl_format_endpoints \
line=$(ip -n $ns mptcp endpoint show $id) "${id},${addr},${flags//","/" "},${dev},${port}")"
line="${line% }"
# the dump order is: address id flags port dev
[ -n "$addr" ] && expected_line="$addr"
expected_line+=" $id"
[ -n "$_flags" ] && expected_line+=" ${_flags//","/" "}"
[ -n "$dev" ] && expected_line+=" $dev"
[ -n "$port" ] && expected_line+=" $port"
else
line=$(ip netns exec $ns ./pm_nl_ctl get $_id)
# the dump order is: id flags dev address port
expected_line="$id"
[ -n "$flags" ] && expected_line+=" $flags"
[ -n "$dev" ] && expected_line+=" $dev"
[ -n "$addr" ] && expected_line+=" $addr"
[ -n "$_port" ] && expected_line+=" $_port"
fi
if [ "$line" = "$expected_line" ]; then
print_ok
else
fail_test "expected '$expected_line' found '$line'"
fi
} }
pm_nl_set_endpoint() pm_nl_set_endpoint()
...@@ -3212,7 +3103,7 @@ fail_tests() ...@@ -3212,7 +3103,7 @@ fail_tests()
# multiple subflows # multiple subflows
if reset_with_fail "MP_FAIL MP_RST" 2; then if reset_with_fail "MP_FAIL MP_RST" 2; then
tc -n $ns2 qdisc add dev ns2eth1 root netem rate 1mbit delay 5 tc -n $ns2 qdisc add dev ns2eth1 root netem rate 1mbit delay 5ms
pm_nl_set_limits $ns1 0 1 pm_nl_set_limits $ns1 0 1
pm_nl_set_limits $ns2 0 1 pm_nl_set_limits $ns2 0 1
pm_nl_add_endpoint $ns2 10.0.2.2 dev ns2eth2 flags subflow pm_nl_add_endpoint $ns2 10.0.2.2 dev ns2eth2 flags subflow
...@@ -3702,7 +3593,7 @@ while getopts "${all_tests_args}cCih" opt; do ...@@ -3702,7 +3593,7 @@ while getopts "${all_tests_args}cCih" opt; do
checksum=true checksum=true
;; ;;
i) i)
ip_mptcp=1 mptcp_lib_set_ip_mptcp
;; ;;
h) h)
usage usage
......
...@@ -23,6 +23,7 @@ MPTCP_LIB_SUBTESTS=() ...@@ -23,6 +23,7 @@ MPTCP_LIB_SUBTESTS=()
MPTCP_LIB_SUBTESTS_DUPLICATED=0 MPTCP_LIB_SUBTESTS_DUPLICATED=0
MPTCP_LIB_TEST_COUNTER=0 MPTCP_LIB_TEST_COUNTER=0
MPTCP_LIB_TEST_FORMAT="%02u %-50s" MPTCP_LIB_TEST_FORMAT="%02u %-50s"
MPTCP_LIB_IP_MPTCP=0
# only if supported (or forced) and not disabled, see no-color.org # only if supported (or forced) and not disabled, see no-color.org
if { [ -t 1 ] || [ "${SELFTESTS_MPTCP_LIB_COLOR_FORCE:-}" = "1" ]; } && if { [ -t 1 ] || [ "${SELFTESTS_MPTCP_LIB_COLOR_FORCE:-}" = "1" ]; } &&
...@@ -384,6 +385,12 @@ mptcp_lib_check_tools() { ...@@ -384,6 +385,12 @@ mptcp_lib_check_tools() {
exit ${KSFT_SKIP} exit ${KSFT_SKIP}
fi fi
;; ;;
"tc")
if ! tc -help &> /dev/null; then
mptcp_lib_pr_skip "Could not run test without tc tool"
exit ${KSFT_SKIP}
fi
;;
"ss") "ss")
if ! ss -h | grep -q MPTCP; then if ! ss -h | grep -q MPTCP; then
mptcp_lib_pr_skip "ss tool does not support MPTCP" mptcp_lib_pr_skip "ss tool does not support MPTCP"
...@@ -505,3 +512,131 @@ mptcp_lib_verify_listener_events() { ...@@ -505,3 +512,131 @@ mptcp_lib_verify_listener_events() {
mptcp_lib_check_expected "type" "family" "saddr" "sport" || rc="${?}" mptcp_lib_check_expected "type" "family" "saddr" "sport" || rc="${?}"
return "${rc}" return "${rc}"
} }
mptcp_lib_set_ip_mptcp() {
MPTCP_LIB_IP_MPTCP=1
}
mptcp_lib_is_ip_mptcp() {
[ "${MPTCP_LIB_IP_MPTCP}" = "1" ]
}
# format: <id>,<ip>,<flags>,<dev>
mptcp_lib_pm_nl_format_endpoints() {
local entry id ip flags dev port
for entry in "${@}"; do
IFS=, read -r id ip flags dev port <<< "${entry}"
if mptcp_lib_is_ip_mptcp; then
echo -n "${ip}"
[ -n "${port}" ] && echo -n " port ${port}"
echo -n " id ${id}"
[ -n "${flags}" ] && echo -n " ${flags}"
[ -n "${dev}" ] && echo -n " dev ${dev}"
echo " " # always a space at the end
else
echo -n "id ${id}"
echo -n " flags ${flags//" "/","}"
[ -n "${dev}" ] && echo -n " dev ${dev}"
echo -n " ${ip}"
[ -n "${port}" ] && echo -n " ${port}"
echo ""
fi
done
}
mptcp_lib_pm_nl_get_endpoint() {
local ns=${1}
local id=${2}
if mptcp_lib_is_ip_mptcp; then
ip -n "${ns}" mptcp endpoint show id "${id}"
else
ip netns exec "${ns}" ./pm_nl_ctl get "${id}"
fi
}
mptcp_lib_pm_nl_set_limits() {
local ns=${1}
local addrs=${2}
local subflows=${3}
if mptcp_lib_is_ip_mptcp; then
ip -n "${ns}" mptcp limits set add_addr_accepted "${addrs}" subflows "${subflows}"
else
ip netns exec "${ns}" ./pm_nl_ctl limits "${addrs}" "${subflows}"
fi
}
mptcp_lib_pm_nl_add_endpoint() {
local ns=${1}
local addr=${2}
local flags dev id port
local nr=2
local p
for p in "${@}"; do
case "${p}" in
"flags" | "dev" | "id" | "port")
eval "${p}"=\$"${nr}"
;;
esac
nr=$((nr + 1))
done
if mptcp_lib_is_ip_mptcp; then
# shellcheck disable=SC2086 # blanks in flags, no double quote
ip -n "${ns}" mptcp endpoint add "${addr}" ${flags//","/" "} \
${dev:+dev "${dev}"} ${id:+id "${id}"} ${port:+port "${port}"}
else
ip netns exec "${ns}" ./pm_nl_ctl add "${addr}" ${flags:+flags "${flags}"} \
${dev:+dev "${dev}"} ${id:+id "${id}"} ${port:+port "${port}"}
fi
}
mptcp_lib_pm_nl_del_endpoint() {
local ns=${1}
local id=${2}
local addr=${3}
if mptcp_lib_is_ip_mptcp; then
[ "${id}" -ne 0 ] && addr=''
ip -n "${ns}" mptcp endpoint delete id "${id}" ${addr:+"${addr}"}
else
ip netns exec "${ns}" ./pm_nl_ctl del "${id}" "${addr}"
fi
}
mptcp_lib_pm_nl_flush_endpoint() {
local ns=${1}
if mptcp_lib_is_ip_mptcp; then
ip -n "${ns}" mptcp endpoint flush
else
ip netns exec "${ns}" ./pm_nl_ctl flush
fi
}
mptcp_lib_pm_nl_show_endpoints() {
local ns=${1}
if mptcp_lib_is_ip_mptcp; then
ip -n "${ns}" mptcp endpoint show
else
ip netns exec "${ns}" ./pm_nl_ctl dump
fi
}
mptcp_lib_pm_nl_change_endpoint() {
local ns=${1}
local id=${2}
local flags=${3}
if mptcp_lib_is_ip_mptcp; then
# shellcheck disable=SC2086 # blanks in flags, no double quote
ip -n "${ns}" mptcp endpoint change id "${id}" ${flags//","/" "}
else
ip netns exec "${ns}" ./pm_nl_ctl set id "${id}" flags "${flags}"
fi
}
...@@ -22,6 +22,28 @@ ns1="" ...@@ -22,6 +22,28 @@ ns1=""
ns2="" ns2=""
ns_sbox="" ns_sbox=""
usage() {
echo "Usage: $0 [ -i ] [ -h ]"
echo -e "\t-i: use 'ip mptcp' instead of 'pm_nl_ctl'"
echo -e "\t-h: help"
}
while getopts "hi" option;do
case "$option" in
"h")
usage "$0"
exit ${KSFT_PASS}
;;
"i")
mptcp_lib_set_ip_mptcp
;;
"?")
usage "$0"
exit ${KSFT_FAIL}
;;
esac
done
add_mark_rules() add_mark_rules()
{ {
local ns=$1 local ns=$1
...@@ -58,15 +80,15 @@ init() ...@@ -58,15 +80,15 @@ init()
# let $ns2 reach any $ns1 address from any interface # let $ns2 reach any $ns1 address from any interface
ip -net "$ns2" route add default via 10.0.$i.1 dev ns2eth$i metric 10$i ip -net "$ns2" route add default via 10.0.$i.1 dev ns2eth$i metric 10$i
ip netns exec $ns1 ./pm_nl_ctl add 10.0.$i.1 flags signal mptcp_lib_pm_nl_add_endpoint "${ns1}" "10.0.${i}.1" flags signal
ip netns exec $ns1 ./pm_nl_ctl add dead:beef:$i::1 flags signal mptcp_lib_pm_nl_add_endpoint "${ns1}" "dead:beef:${i}::1" flags signal
ip netns exec $ns2 ./pm_nl_ctl add 10.0.$i.2 flags signal mptcp_lib_pm_nl_add_endpoint "${ns2}" "10.0.${i}.2" flags signal
ip netns exec $ns2 ./pm_nl_ctl add dead:beef:$i::2 flags signal mptcp_lib_pm_nl_add_endpoint "${ns2}" "dead:beef:${i}::2" flags signal
done done
ip netns exec $ns1 ./pm_nl_ctl limits 8 8 mptcp_lib_pm_nl_set_limits "${ns1}" 8 8
ip netns exec $ns2 ./pm_nl_ctl limits 8 8 mptcp_lib_pm_nl_set_limits "${ns2}" 8 8
add_mark_rules $ns1 1 add_mark_rules $ns1 1
add_mark_rules $ns2 2 add_mark_rules $ns2 2
......
...@@ -27,10 +27,11 @@ capout="" ...@@ -27,10 +27,11 @@ capout=""
size=0 size=0
usage() { usage() {
echo "Usage: $0 [ -b ] [ -c ] [ -d ]" echo "Usage: $0 [ -b ] [ -c ] [ -d ] [ -i]"
echo -e "\t-b: bail out after first error, otherwise runs al testcases" echo -e "\t-b: bail out after first error, otherwise runs al testcases"
echo -e "\t-c: capture packets for each test using tcpdump (default: no capture)" echo -e "\t-c: capture packets for each test using tcpdump (default: no capture)"
echo -e "\t-d: debug this script" echo -e "\t-d: debug this script"
echo -e "\t-i: use 'ip mptcp' instead of 'pm_nl_ctl'"
} }
# This function is used in the cleanup trap # This function is used in the cleanup trap
...@@ -45,7 +46,7 @@ cleanup() ...@@ -45,7 +46,7 @@ cleanup()
} }
mptcp_lib_check_mptcp mptcp_lib_check_mptcp
mptcp_lib_check_tools ip mptcp_lib_check_tools ip tc
# "$ns1" ns2 ns3 # "$ns1" ns2 ns3
# ns1eth1 ns2eth1 ns2eth3 ns3eth1 # ns1eth1 ns2eth1 ns2eth3 ns3eth1
...@@ -85,8 +86,8 @@ setup() ...@@ -85,8 +86,8 @@ setup()
ip -net "$ns1" route add default via 10.0.2.2 metric 101 ip -net "$ns1" route add default via 10.0.2.2 metric 101
ip -net "$ns1" route add default via dead:beef:2::2 metric 101 ip -net "$ns1" route add default via dead:beef:2::2 metric 101
ip netns exec "$ns1" ./pm_nl_ctl limits 1 1 mptcp_lib_pm_nl_set_limits "${ns1}" 1 1
ip netns exec "$ns1" ./pm_nl_ctl add 10.0.2.1 dev ns1eth2 flags subflow mptcp_lib_pm_nl_add_endpoint "${ns1}" 10.0.2.1 dev ns1eth2 flags subflow
ip -net "$ns2" addr add 10.0.1.2/24 dev ns2eth1 ip -net "$ns2" addr add 10.0.1.2/24 dev ns2eth1
ip -net "$ns2" addr add dead:beef:1::2/64 dev ns2eth1 nodad ip -net "$ns2" addr add dead:beef:1::2/64 dev ns2eth1 nodad
...@@ -108,7 +109,7 @@ setup() ...@@ -108,7 +109,7 @@ setup()
ip -net "$ns3" route add default via 10.0.3.2 ip -net "$ns3" route add default via 10.0.3.2
ip -net "$ns3" route add default via dead:beef:3::2 ip -net "$ns3" route add default via dead:beef:3::2
ip netns exec "$ns3" ./pm_nl_ctl limits 1 1 mptcp_lib_pm_nl_set_limits "${ns3}" 1 1
# debug build can slow down measurably the test program # debug build can slow down measurably the test program
# we use quite tight time limit on the run-time, to ensure # we use quite tight time limit on the run-time, to ensure
...@@ -216,8 +217,8 @@ run_test() ...@@ -216,8 +217,8 @@ run_test()
shift 4 shift 4
local msg=$* local msg=$*
[ $delay1 -gt 0 ] && delay1="delay $delay1" || delay1="" [ $delay1 -gt 0 ] && delay1="delay ${delay1}ms" || delay1=""
[ $delay2 -gt 0 ] && delay2="delay $delay2" || delay2="" [ $delay2 -gt 0 ] && delay2="delay ${delay2}ms" || delay2=""
for dev in ns1eth1 ns1eth2; do for dev in ns1eth1 ns1eth2; do
tc -n $ns1 qdisc del dev $dev root >/dev/null 2>&1 tc -n $ns1 qdisc del dev $dev root >/dev/null 2>&1
...@@ -259,7 +260,7 @@ run_test() ...@@ -259,7 +260,7 @@ run_test()
fi fi
} }
while getopts "bcdh" option;do while getopts "bcdhi" option;do
case "$option" in case "$option" in
"h") "h")
usage $0 usage $0
...@@ -274,6 +275,9 @@ while getopts "bcdh" option;do ...@@ -274,6 +275,9 @@ while getopts "bcdh" option;do
"d") "d")
set -x set -x
;; ;;
"i")
mptcp_lib_set_ip_mptcp
;;
"?") "?")
usage $0 usage $0
exit ${KSFT_FAIL} exit ${KSFT_FAIL}
......
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