Skip to content

Commit

Permalink
selftests: mptcp: add implicit endpoint test case
Browse files Browse the repository at this point in the history
Ensure implicit endpoint are created when expected and
that the user-space can update them

Reviewed-by: Mat Martineau <[email protected]>
Reviewed-by: Matthieu Baerts <[email protected]>
Signed-off-by: Paolo Abeni <[email protected]>
  • Loading branch information
Paolo Abeni authored and matttbe committed Feb 19, 2022
1 parent 9e1c868 commit 7532760
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 1 deletion.
115 changes: 114 additions & 1 deletion tools/testing/selftests/net/mptcp/mptcp_join.sh
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,76 @@ pm_nl_change_endpoint()
fi
}

pm_nl_check_endpoint()
{
local line expected_line
local msg="$1"
local addr=$3
local ns=$2
local _flags=""
local flags
local _port
local port
local dev
local _id
local id

TEST_COUNT=$((TEST_COUNT + 1))
printf "%03u %-40s" "$TEST_COUNT" "$msg"

shift 3
while [ -n "$1" ]; do
if [ $1 = "flags" ]; then
_flags=$2
[ ! -z $_flags ]; flags="flags $_flags"
shift
elif [ $1 = "dev" ]; then
[ ! -z $2 ]; dev="dev $1"
shift
elif [ $1 = "id" ]; then
_id=$2
[ ! -z $_id ]; id="id $_id"
shift
elif [ $1 = "port" ]; then
_port=$2
[ ! -z $_port ]; port=" port $_port"
shift
fi

shift
done

if [ -z "$id" ]; then
echo "[skip] bad test - missing endpoint id"
return
fi

if [ $ip_mptcp -eq 1 ]; then
line=$(ip -n $ns mptcp endpoint show $id)
# the dump order is: address id flags port dev
expected_line="$addr"
[ -n "$addr" ] && expected_line="$expected_line $addr"
expected_line="$expected_line $id"
[ -n "$_flags" ] && expected_line="$expected_line ${_flags//","/" "}"
[ -n "$dev" ] && expected_line="$expected_line $dev"
[ -n "$port" ] && expected_line="$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="$expected_line $flags"
[ -n "$dev" ] && expected_line="$expected_line $dev"
[ -n "$addr" ] && expected_line="$expected_line $addr"
[ -n "$_port" ] && expected_line="$expected_line $_port"
fi
if [ "$line" = "$expected_line" ]; then
echo "[ ok ]"
else
echo "[fail] expected '$expected_line' found '$line'"
ret=1
fi
}

do_transfer()
{
listener_ns="$1"
Expand Down Expand Up @@ -2202,6 +2272,44 @@ userspace_tests()
chk_rm_nr 0 0
}

wait_mpj()
{
local ns="${1}"
local cnt old_cnt

old_cnt=$(ip netns exec ${ns} nstat -as | grep MPJoinAckRx | awk '{print $2}')

local i
for i in $(seq 10); do
cnt=$(ip netns exec ${ns} nstat -as | grep MPJoinAckRx | awk '{print $2}')
[ "$cnt" = "${old_cnt}" ] || break
sleep 0.1
done
}

implicit_tests()
{
# userspace pm type prevents add_addr
reset
pm_nl_set_limits $ns1 2 2
pm_nl_set_limits $ns2 2 2
pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow &

wait_mpj $ns1
pm_nl_check_endpoint "implicit EP creation" \
$ns2 10.0.2.2 id 1 flags implicit

pm_nl_add_endpoint $ns2 10.0.2.2 id 33
pm_nl_check_endpoint "implicit EP ID change is prevented" \
$ns2 10.0.2.2 id 1 flags implicit

pm_nl_add_endpoint $ns2 10.0.2.2 flags signal
pm_nl_check_endpoint "implicit EP modification is allowed" \
$ns2 10.0.2.2 id 1 flags signal
wait
}

all_tests()
{
subflows_tests
Expand All @@ -2220,6 +2328,7 @@ all_tests()
deny_join_id0_tests
fullmesh_tests
userspace_tests
implicit_tests
}

# [$1: error message]
Expand Down Expand Up @@ -2247,6 +2356,7 @@ usage()
echo " -d deny_join_id0_tests"
echo " -m fullmesh_tests"
echo " -u userspace_tests"
echo " -I implicit_tests"
echo " -c capture pcap files"
echo " -C enable data checksum"
echo " -i use ip mptcp"
Expand Down Expand Up @@ -2278,7 +2388,7 @@ if [ $do_all_tests -eq 1 ]; then
exit $ret
fi

while getopts 'fesltra64bpkdmuchCSi' opt; do
while getopts 'fesltra64bpkdmuchCSiI' opt; do
case $opt in
f)
subflows_tests
Expand Down Expand Up @@ -2334,6 +2444,9 @@ while getopts 'fesltra64bpkdmuchCSi' opt; do
;;
i)
;;
I)
implicit_tests
;;
h)
usage
;;
Expand Down
7 changes: 7 additions & 0 deletions tools/testing/selftests/net/mptcp/pm_nl_ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,13 @@ static void print_addr(struct rtattr *attrs, int len)
printf(",");
}

if (flags & MPTCP_PM_ADDR_FLAG_IMPLICIT) {
printf("implicit");
flags &= ~MPTCP_PM_ADDR_FLAG_IMPLICIT;
if (flags)
printf(",");
}

/* bump unknown flags, if any */
if (flags)
printf("0x%x", flags);
Expand Down

0 comments on commit 7532760

Please sign in to comment.