Skip to content

Commit

Permalink
selftests: mptcp: add mptcp_lib_init_ns
Browse files Browse the repository at this point in the history
To unify the namespace name, rename 'ns' in diag.sh to 'ns1', and rename
'ns_sbox' in mptcp_sockopt.sh to 'ns3'. Add a new helper mptcp_lib_init_ns
in mptcp_lib.sh to init all namespaces ns1, ns2, ns3 and ns4. Then every
test script can invoke mptcp_lib_init_ns and use all namespaces.

Signed-off-by: Geliang Tang <[email protected]>
Message-Id: <1fbdbfebd7caa8052b764e3d78fa9fb8f41f03b9.1699086300.git.geliang.tang@suse.com>
  • Loading branch information
geliangtang authored and matttbe committed Nov 6, 2023
1 parent a0f0c3d commit e05a56e
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 61 deletions.
48 changes: 23 additions & 25 deletions tools/testing/selftests/net/mptcp/diag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

. "$(dirname "${0}")/mptcp_lib.sh"

sec=$(date +%s)
rndh=$(printf %x $sec)-$(mktemp -u XXXXXX)
ns="ns1-$rndh"
mptcp_lib_init_ns
ksft_skip=4
test_cnt=1
timeout_poll=100
Expand All @@ -18,19 +16,19 @@ flush_pids()
# give it some time
sleep 1.1

ip netns pids "${ns}" | xargs --no-run-if-empty kill -SIGUSR1 &>/dev/null
ip netns pids "${ns1}" | xargs --no-run-if-empty kill -SIGUSR1 &>/dev/null

for _ in $(seq 10); do
[ -z "$(ip netns pids "${ns}")" ] && break
[ -z "$(ip netns pids "${ns1}")" ] && break
sleep 0.1
done
}

cleanup()
{
ip netns pids "${ns}" | xargs --no-run-if-empty kill -SIGKILL &>/dev/null
ip netns pids "${ns1}" | xargs --no-run-if-empty kill -SIGKILL &>/dev/null

ip netns del $ns
ip netns del $ns1
}

mptcp_lib_check_mptcp
Expand All @@ -48,7 +46,7 @@ fi

get_msk_inuse()
{
ip netns exec $ns cat /proc/net/protocols | awk '$1~/^MPTCP$/{print $3}'
ip netns exec $ns1 cat /proc/net/protocols | awk '$1~/^MPTCP$/{print $3}'
}

__chk_nr()
Expand Down Expand Up @@ -83,7 +81,7 @@ __chk_msk_nr()
local condition=$1
shift 1

__chk_nr "ss -inmHMN $ns | $condition" "$@"
__chk_nr "ss -inmHMN $ns1 | $condition" "$@"
}

chk_msk_nr()
Expand All @@ -104,7 +102,7 @@ wait_msk_nr()
msg=$*

while [ $i -lt $timeout ]; do
nr=$(ss -inmHMN $ns | $condition)
nr=$(ss -inmHMN $ns1 | $condition)
[ $nr == $expected ] && break;
[ $nr -gt $max ] && max=$nr
i=$((i + 1))
Expand Down Expand Up @@ -143,7 +141,7 @@ __chk_listen()
local expected=$2
local msg="$3"

__chk_nr "ss -N $ns -Ml '$filter' | grep -c LISTEN" "$expected" "$msg" 0
__chk_nr "ss -N $ns1 -Ml '$filter' | grep -c LISTEN" "$expected" "$msg" 0
}

chk_msk_listen()
Expand All @@ -169,7 +167,7 @@ chk_msk_inuse()
local msg="$2"
local listen_nr

listen_nr=$(ss -N "${ns}" -Ml | grep -c LISTEN)
listen_nr=$(ss -N "${ns1}" -Ml | grep -c LISTEN)
expected=$((expected + listen_nr))

for _ in $(seq 10); do
Expand Down Expand Up @@ -197,24 +195,24 @@ wait_connected()
}

trap cleanup EXIT
ip netns add $ns
ip -n $ns link set dev lo up
ip netns add $ns1
ip -n $ns1 link set dev lo up

echo "a" | \
timeout ${timeout_test} \
ip netns exec $ns \
ip netns exec $ns1 \
./mptcp_connect -p 10000 -l -t ${timeout_poll} -w 20 \
0.0.0.0 >/dev/null &
mptcp_lib_wait_local_port_listen $ns 10000
mptcp_lib_wait_local_port_listen $ns1 10000
chk_msk_nr 0 "no msk on netns creation"
chk_msk_listen 10000

echo "b" | \
timeout ${timeout_test} \
ip netns exec $ns \
ip netns exec $ns1 \
./mptcp_connect -p 10000 -r 0 -t ${timeout_poll} -w 20 \
127.0.0.1 >/dev/null &
wait_connected $ns 10000
wait_connected $ns1 10000
chk_msk_nr 2 "after MPC handshake "
chk_msk_remote_key_nr 2 "....chk remote_key"
chk_msk_fallback_nr 0 "....chk no fallback"
Expand All @@ -225,16 +223,16 @@ chk_msk_inuse 0 "....chk 0 msk in use after flush"

echo "a" | \
timeout ${timeout_test} \
ip netns exec $ns \
ip netns exec $ns1 \
./mptcp_connect -p 10001 -l -s TCP -t ${timeout_poll} -w 20 \
0.0.0.0 >/dev/null &
mptcp_lib_wait_local_port_listen $ns 10001
mptcp_lib_wait_local_port_listen $ns1 10001
echo "b" | \
timeout ${timeout_test} \
ip netns exec $ns \
ip netns exec $ns1 \
./mptcp_connect -p 10001 -r 0 -t ${timeout_poll} -w 20 \
127.0.0.1 >/dev/null &
wait_connected $ns 10001
wait_connected $ns1 10001
chk_msk_fallback_nr 1 "check fallback"
chk_msk_inuse 1 "....chk 1 msk in use"
flush_pids
Expand All @@ -245,16 +243,16 @@ NR_CLIENTS=100
for I in `seq 1 $NR_CLIENTS`; do
echo "a" | \
timeout ${timeout_test} \
ip netns exec $ns \
ip netns exec $ns1 \
./mptcp_connect -p $((I+10001)) -l -w 20 \
-t ${timeout_poll} 0.0.0.0 >/dev/null &
done
mptcp_lib_wait_local_port_listen $ns $((NR_CLIENTS + 10001))
mptcp_lib_wait_local_port_listen $ns1 $((NR_CLIENTS + 10001))

for I in `seq 1 $NR_CLIENTS`; do
echo "b" | \
timeout ${timeout_test} \
ip netns exec $ns \
ip netns exec $ns1 \
./mptcp_connect -p $((I+10001)) -w 20 \
-t ${timeout_poll} 127.0.0.1 >/dev/null &
done
Expand Down
7 changes: 1 addition & 6 deletions tools/testing/selftests/net/mptcp/mptcp_connect.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,7 @@ while getopts "$optstring" option;do
esac
done

sec=$(date +%s)
rndh=$(printf %x $sec)-$(mktemp -u XXXXXX)
ns1="ns1-$rndh"
ns2="ns2-$rndh"
ns3="ns3-$rndh"
ns4="ns4-$rndh"
mptcp_lib_init_ns

TEST_COUNT=0
TEST_GROUP=""
Expand Down
9 changes: 1 addition & 8 deletions tools/testing/selftests/net/mptcp/mptcp_join.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ cinsent=""
tmpfile=""
cout=""
capout=""
ns1=""
ns2=""
ksft_skip=4
iptables="iptables"
ip6tables="ip6tables"
Expand Down Expand Up @@ -79,12 +77,7 @@ init_partial()
{
capout=$(mktemp)

local sec rndh
sec=$(date +%s)
rndh=$(printf %x $sec)-$(mktemp -u XXXXXX)

ns1="ns1-$rndh"
ns2="ns2-$rndh"
mptcp_lib_init_ns

local netns
for netns in "$ns1" "$ns2"; do
Expand Down
18 changes: 18 additions & 0 deletions tools/testing/selftests/net/mptcp/mptcp_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ MPTCP_LIB_LISTENER_CLOSED=16 #MPTCP_EVENT_LISTENER_CLOSED
readonly AF_INET=2
readonly AF_INET6=10

rndh=""
ns1=""
ns2=""
ns3=""
ns4=""

MPTCP_LIB_SUBTESTS=()

# only if supported (or forced) and not disabled, see no-color.org
Expand Down Expand Up @@ -443,3 +449,15 @@ mptcp_lib_verify_listener_events() {

mptcp_lib_check_expected "type" "family" "saddr" "sport"
}

mptcp_lib_init_ns() {
local sec

sec=$(date +%s)
rndh=$(printf %x $sec)-$(mktemp -u XXXXXX)

ns1="ns1-$rndh"
ns2="ns2-$rndh"
ns3="ns3-$rndh"
ns4="ns4-$rndh"
}
16 changes: 6 additions & 10 deletions tools/testing/selftests/net/mptcp/mptcp_sockopt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ timeout_test=$((timeout_poll * 2 + 1))
iptables="iptables"
ip6tables="ip6tables"

sec=$(date +%s)
rndh=$(printf %x $sec)-$(mktemp -u XXXXXX)
ns1="ns1-$rndh"
ns2="ns2-$rndh"
ns_sbox="ns_sbox-$rndh"
mptcp_lib_init_ns

add_mark_rules()
{
Expand All @@ -41,7 +37,7 @@ add_mark_rules()
init()
{
local netns
for netns in "$ns1" "$ns2" "$ns_sbox";do
for netns in "$ns1" "$ns2" "$ns3";do
ip netns add $netns || exit $ksft_skip
ip -net $netns link set lo up
ip netns exec $netns sysctl -q net.mptcp.enabled=1
Expand Down Expand Up @@ -80,7 +76,7 @@ init()
cleanup()
{
local netns
for netns in "$ns1" "$ns2" "$ns_sbox"; do
for netns in "$ns1" "$ns2" "$ns3"; do
ip netns del $netns
done
rm -f "$cin" "$cout"
Expand Down Expand Up @@ -240,7 +236,7 @@ do_mptcp_sockopt_tests()
return
fi

ip netns exec "$ns_sbox" ./mptcp_sockopt
ip netns exec "$ns3" ./mptcp_sockopt
lret=$?

if [ $lret -ne 0 ]; then
Expand All @@ -251,7 +247,7 @@ do_mptcp_sockopt_tests()
fi
mptcp_lib_result_pass "sockopt v4"

ip netns exec "$ns_sbox" ./mptcp_sockopt -6
ip netns exec "$ns3" ./mptcp_sockopt -6
lret=$?

if [ $lret -ne 0 ]; then
Expand Down Expand Up @@ -282,7 +278,7 @@ run_tests()

do_tcpinq_test()
{
ip netns exec "$ns_sbox" ./mptcp_inq "$@"
ip netns exec "$ns3" ./mptcp_inq "$@"
local lret=$?
if [ $lret -ne 0 ];then
ret=$lret
Expand Down
4 changes: 1 addition & 3 deletions tools/testing/selftests/net/mptcp/pm_netlink.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ while getopts "$optstring" option;do
esac
done

sec=$(date +%s)
rndh=$(printf %x $sec)-$(mktemp -u XXXXXX)
ns1="ns1-$rndh"
mptcp_lib_init_ns
err=$(mktemp)
ret=0

Expand Down
6 changes: 1 addition & 5 deletions tools/testing/selftests/net/mptcp/simult_flows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@

. "$(dirname "${0}")/mptcp_lib.sh"

sec=$(date +%s)
rndh=$(printf %x $sec)-$(mktemp -u XXXXXX)
ns1="ns1-$rndh"
ns2="ns2-$rndh"
ns3="ns3-$rndh"
mptcp_lib_init_ns
capture=false
ksft_skip=4
timeout_poll=30
Expand Down
5 changes: 1 addition & 4 deletions tools/testing/selftests/net/mptcp/userspace_pm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ app6_port=50004
client_addr_id=${RANDOM:0:2}
server_addr_id=${RANDOM:0:2}

sec=$(date +%s)
rndh=$(printf %x "$sec")-$(mktemp -u XXXXXX)
ns1="ns1-$rndh"
ns2="ns2-$rndh"
mptcp_lib_init_ns
ret=0
test_name=""

Expand Down

0 comments on commit e05a56e

Please sign in to comment.