2020-09-14 08:01:19 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
2024-03-06 09:43:00 +00:00
|
|
|
# Double quotes to prevent globbing and word splitting is recommended in new
|
|
|
|
# code but we accept it, especially because there were too many before having
|
|
|
|
# address all other issues detected by shellcheck.
|
|
|
|
#shellcheck disable=SC2086
|
|
|
|
|
2023-05-28 17:35:31 +00:00
|
|
|
. "$(dirname "${0}")/mptcp_lib.sh"
|
|
|
|
|
2024-03-06 09:42:53 +00:00
|
|
|
ns1=""
|
|
|
|
ns2=""
|
|
|
|
ns3=""
|
2020-09-14 08:01:19 +00:00
|
|
|
capture=false
|
2021-04-01 23:19:45 +00:00
|
|
|
timeout_poll=30
|
|
|
|
timeout_test=$((timeout_poll * 2 + 1))
|
2020-09-14 08:01:19 +00:00
|
|
|
ret=0
|
|
|
|
bail=0
|
2022-07-08 17:14:09 +00:00
|
|
|
slack=50
|
2024-02-23 20:17:58 +00:00
|
|
|
large=""
|
|
|
|
small=""
|
|
|
|
sout=""
|
|
|
|
cout=""
|
|
|
|
capout=""
|
|
|
|
size=0
|
2020-09-14 08:01:19 +00:00
|
|
|
|
|
|
|
usage() {
|
|
|
|
echo "Usage: $0 [ -b ] [ -c ] [ -d ]"
|
|
|
|
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-d: debug this script"
|
|
|
|
}
|
|
|
|
|
2024-03-06 09:43:00 +00:00
|
|
|
# This function is used in the cleanup trap
|
|
|
|
#shellcheck disable=SC2317
|
2020-09-14 08:01:19 +00:00
|
|
|
cleanup()
|
|
|
|
{
|
2021-09-01 17:15:37 +00:00
|
|
|
rm -f "$cout" "$sout"
|
|
|
|
rm -f "$large" "$small"
|
2020-09-14 08:01:19 +00:00
|
|
|
rm -f "$capout"
|
|
|
|
|
2024-03-06 09:42:53 +00:00
|
|
|
mptcp_lib_ns_exit "${ns1}" "${ns2}" "${ns3}"
|
2020-09-14 08:01:19 +00:00
|
|
|
}
|
|
|
|
|
2023-05-28 17:35:31 +00:00
|
|
|
mptcp_lib_check_mptcp
|
2024-03-06 09:42:51 +00:00
|
|
|
mptcp_lib_check_tools ip
|
2020-09-14 08:01:19 +00:00
|
|
|
|
|
|
|
# "$ns1" ns2 ns3
|
|
|
|
# ns1eth1 ns2eth1 ns2eth3 ns3eth1
|
|
|
|
# netem
|
|
|
|
# ns1eth2 ns2eth2
|
|
|
|
# netem
|
|
|
|
|
|
|
|
setup()
|
|
|
|
{
|
|
|
|
large=$(mktemp)
|
|
|
|
small=$(mktemp)
|
|
|
|
sout=$(mktemp)
|
|
|
|
cout=$(mktemp)
|
|
|
|
capout=$(mktemp)
|
2021-10-29 23:55:59 +00:00
|
|
|
size=$((2 * 2048 * 4096))
|
2022-07-08 17:14:09 +00:00
|
|
|
|
2020-09-14 08:01:19 +00:00
|
|
|
dd if=/dev/zero of=$small bs=4096 count=20 >/dev/null 2>&1
|
|
|
|
dd if=/dev/zero of=$large bs=4096 count=$((size / 4096)) >/dev/null 2>&1
|
|
|
|
|
|
|
|
trap cleanup EXIT
|
|
|
|
|
2024-03-06 09:42:53 +00:00
|
|
|
mptcp_lib_ns_init ns1 ns2 ns3
|
2020-09-14 08:01:19 +00:00
|
|
|
|
|
|
|
ip link add ns1eth1 netns "$ns1" type veth peer name ns2eth1 netns "$ns2"
|
|
|
|
ip link add ns1eth2 netns "$ns1" type veth peer name ns2eth2 netns "$ns2"
|
|
|
|
ip link add ns2eth3 netns "$ns2" type veth peer name ns3eth1 netns "$ns3"
|
|
|
|
|
|
|
|
ip -net "$ns1" addr add 10.0.1.1/24 dev ns1eth1
|
|
|
|
ip -net "$ns1" addr add dead:beef:1::1/64 dev ns1eth1 nodad
|
|
|
|
ip -net "$ns1" link set ns1eth1 up mtu 1500
|
|
|
|
ip -net "$ns1" route add default via 10.0.1.2
|
|
|
|
ip -net "$ns1" route add default via dead:beef:1::2
|
|
|
|
|
|
|
|
ip -net "$ns1" addr add 10.0.2.1/24 dev ns1eth2
|
|
|
|
ip -net "$ns1" addr add dead:beef:2::1/64 dev ns1eth2 nodad
|
|
|
|
ip -net "$ns1" link set ns1eth2 up mtu 1500
|
|
|
|
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 netns exec "$ns1" ./pm_nl_ctl limits 1 1
|
|
|
|
ip netns exec "$ns1" ./pm_nl_ctl add 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 dead:beef:1::2/64 dev ns2eth1 nodad
|
|
|
|
ip -net "$ns2" link set ns2eth1 up mtu 1500
|
|
|
|
|
|
|
|
ip -net "$ns2" addr add 10.0.2.2/24 dev ns2eth2
|
|
|
|
ip -net "$ns2" addr add dead:beef:2::2/64 dev ns2eth2 nodad
|
|
|
|
ip -net "$ns2" link set ns2eth2 up mtu 1500
|
|
|
|
|
|
|
|
ip -net "$ns2" addr add 10.0.3.2/24 dev ns2eth3
|
|
|
|
ip -net "$ns2" addr add dead:beef:3::2/64 dev ns2eth3 nodad
|
|
|
|
ip -net "$ns2" link set ns2eth3 up mtu 1500
|
|
|
|
ip netns exec "$ns2" sysctl -q net.ipv4.ip_forward=1
|
|
|
|
ip netns exec "$ns2" sysctl -q net.ipv6.conf.all.forwarding=1
|
|
|
|
|
|
|
|
ip -net "$ns3" addr add 10.0.3.3/24 dev ns3eth1
|
|
|
|
ip -net "$ns3" addr add dead:beef:3::3/64 dev ns3eth1 nodad
|
|
|
|
ip -net "$ns3" link set ns3eth1 up mtu 1500
|
|
|
|
ip -net "$ns3" route add default via 10.0.3.2
|
|
|
|
ip -net "$ns3" route add default via dead:beef:3::2
|
|
|
|
|
|
|
|
ip netns exec "$ns3" ./pm_nl_ctl limits 1 1
|
2022-07-08 17:14:09 +00:00
|
|
|
|
|
|
|
# debug build can slow down measurably the test program
|
|
|
|
# we use quite tight time limit on the run-time, to ensure
|
|
|
|
# maximum B/W usage.
|
|
|
|
# Use kmemleak/lockdep/kasan/prove_locking presence as a rough
|
|
|
|
# estimate for this being a debug kernel and increase the
|
|
|
|
# maximum run-time accordingly. Observed run times for CI builds
|
|
|
|
# running selftests, including kbuild, were used to determine the
|
|
|
|
# amount of time to add.
|
|
|
|
grep -q ' kmemleak_init$\| lockdep_init$\| kasan_init$\| prove_locking$' /proc/kallsyms && slack=$((slack+550))
|
2020-09-14 08:01:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
do_transfer()
|
|
|
|
{
|
|
|
|
local cin=$1
|
|
|
|
local sin=$2
|
|
|
|
local max_time=$3
|
|
|
|
local port
|
2024-03-08 22:10:12 +00:00
|
|
|
port=$((10000+MPTCP_LIB_TEST_COUNTER))
|
|
|
|
MPTCP_LIB_TEST_COUNTER=$((MPTCP_LIB_TEST_COUNTER+1))
|
2020-09-14 08:01:19 +00:00
|
|
|
|
|
|
|
:> "$cout"
|
|
|
|
:> "$sout"
|
|
|
|
:> "$capout"
|
|
|
|
|
|
|
|
if $capture; then
|
|
|
|
local capuser
|
2024-03-06 09:42:52 +00:00
|
|
|
local rndh="${ns1:4}"
|
2020-09-14 08:01:19 +00:00
|
|
|
if [ -z $SUDO_USER ] ; then
|
|
|
|
capuser=""
|
|
|
|
else
|
|
|
|
capuser="-Z $SUDO_USER"
|
|
|
|
fi
|
|
|
|
|
|
|
|
local capfile="${rndh}-${port}"
|
|
|
|
local capopt="-i any -s 65535 -B 32768 ${capuser}"
|
|
|
|
|
|
|
|
ip netns exec ${ns3} tcpdump ${capopt} -w "${capfile}-listener.pcap" >> "${capout}" 2>&1 &
|
|
|
|
local cappid_listener=$!
|
|
|
|
|
|
|
|
ip netns exec ${ns1} tcpdump ${capopt} -w "${capfile}-connector.pcap" >> "${capout}" 2>&1 &
|
|
|
|
local cappid_connector=$!
|
|
|
|
|
|
|
|
sleep 1
|
|
|
|
fi
|
|
|
|
|
2021-04-01 23:19:45 +00:00
|
|
|
timeout ${timeout_test} \
|
|
|
|
ip netns exec ${ns3} \
|
2022-11-10 23:23:21 +00:00
|
|
|
./mptcp_connect -jt ${timeout_poll} -l -p $port -T $max_time \
|
2021-04-01 23:19:45 +00:00
|
|
|
0.0.0.0 < "$sin" > "$sout" &
|
2020-09-14 08:01:19 +00:00
|
|
|
local spid=$!
|
|
|
|
|
2023-11-28 23:18:59 +00:00
|
|
|
mptcp_lib_wait_local_port_listen "${ns3}" "${port}"
|
2020-09-14 08:01:19 +00:00
|
|
|
|
2021-04-01 23:19:45 +00:00
|
|
|
timeout ${timeout_test} \
|
|
|
|
ip netns exec ${ns1} \
|
2022-11-10 23:23:21 +00:00
|
|
|
./mptcp_connect -jt ${timeout_poll} -p $port -T $max_time \
|
2021-04-01 23:19:45 +00:00
|
|
|
10.0.3.3 < "$cin" > "$cout" &
|
2020-09-14 08:01:19 +00:00
|
|
|
local cpid=$!
|
|
|
|
|
|
|
|
wait $cpid
|
|
|
|
local retc=$?
|
|
|
|
wait $spid
|
|
|
|
local rets=$?
|
|
|
|
|
|
|
|
if $capture; then
|
|
|
|
sleep 1
|
|
|
|
kill ${cappid_listener}
|
|
|
|
kill ${cappid_connector}
|
|
|
|
fi
|
|
|
|
|
|
|
|
cmp $sin $cout > /dev/null 2>&1
|
|
|
|
local cmps=$?
|
|
|
|
cmp $cin $sout > /dev/null 2>&1
|
|
|
|
local cmpc=$?
|
|
|
|
|
2021-10-29 23:55:59 +00:00
|
|
|
printf "%-16s" " max $max_time "
|
2020-09-14 08:01:19 +00:00
|
|
|
if [ $retc -eq 0 ] && [ $rets -eq 0 ] && \
|
2021-10-29 23:55:59 +00:00
|
|
|
[ $cmpc -eq 0 ] && [ $cmps -eq 0 ]; then
|
2020-09-14 08:01:19 +00:00
|
|
|
echo "[ OK ]"
|
|
|
|
cat "$capout"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo " [ fail ]"
|
|
|
|
echo "client exit code $retc, server $rets" 1>&2
|
2020-10-06 16:06:30 +00:00
|
|
|
echo -e "\nnetns ${ns3} socket stat for $port:" 1>&2
|
2020-09-14 08:01:19 +00:00
|
|
|
ip netns exec ${ns3} ss -nita 1>&2 -o "sport = :$port"
|
2020-10-06 16:06:30 +00:00
|
|
|
echo -e "\nnetns ${ns1} socket stat for $port:" 1>&2
|
2020-09-14 08:01:19 +00:00
|
|
|
ip netns exec ${ns1} ss -nita 1>&2 -o "dport = :$port"
|
|
|
|
ls -l $sin $cout
|
|
|
|
ls -l $cin $sout
|
|
|
|
|
|
|
|
cat "$capout"
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
run_test()
|
|
|
|
{
|
|
|
|
local rate1=$1
|
|
|
|
local rate2=$2
|
|
|
|
local delay1=$3
|
|
|
|
local delay2=$4
|
|
|
|
local lret
|
|
|
|
local dev
|
|
|
|
shift 4
|
|
|
|
local msg=$*
|
|
|
|
|
|
|
|
[ $delay1 -gt 0 ] && delay1="delay $delay1" || delay1=""
|
|
|
|
[ $delay2 -gt 0 ] && delay2="delay $delay2" || delay2=""
|
|
|
|
|
|
|
|
for dev in ns1eth1 ns1eth2; do
|
|
|
|
tc -n $ns1 qdisc del dev $dev root >/dev/null 2>&1
|
|
|
|
done
|
|
|
|
for dev in ns2eth1 ns2eth2; do
|
|
|
|
tc -n $ns2 qdisc del dev $dev root >/dev/null 2>&1
|
|
|
|
done
|
|
|
|
tc -n $ns1 qdisc add dev ns1eth1 root netem rate ${rate1}mbit $delay1
|
|
|
|
tc -n $ns1 qdisc add dev ns1eth2 root netem rate ${rate2}mbit $delay2
|
|
|
|
tc -n $ns2 qdisc add dev ns2eth1 root netem rate ${rate1}mbit $delay1
|
|
|
|
tc -n $ns2 qdisc add dev ns2eth2 root netem rate ${rate2}mbit $delay2
|
|
|
|
|
2022-11-15 22:10:46 +00:00
|
|
|
# time is measured in ms, account for transfer size, aggregated link speed
|
2021-10-29 23:55:59 +00:00
|
|
|
# and header overhead (10%)
|
2022-11-15 22:10:46 +00:00
|
|
|
# ms byte -> bit 10% mbit -> kbit -> bit 10%
|
|
|
|
local time=$((1000 * size * 8 * 10 / ((rate1 + rate2) * 1000 * 1000 * 9) ))
|
2020-09-14 08:01:19 +00:00
|
|
|
|
|
|
|
# mptcp_connect will do some sleeps to allow the mp_join handshake
|
2021-10-29 23:55:59 +00:00
|
|
|
# completion (see mptcp_connect): 200ms on each side, add some slack
|
2022-07-08 17:14:09 +00:00
|
|
|
time=$((time + 400 + slack))
|
2020-09-14 08:01:19 +00:00
|
|
|
|
2021-10-29 23:55:59 +00:00
|
|
|
printf "%-60s" "$msg"
|
|
|
|
do_transfer $small $large $time
|
2020-09-14 08:01:19 +00:00
|
|
|
lret=$?
|
2023-07-17 13:21:31 +00:00
|
|
|
mptcp_lib_result_code "${lret}" "${msg}"
|
2020-09-14 08:01:19 +00:00
|
|
|
if [ $lret -ne 0 ]; then
|
|
|
|
ret=$lret
|
|
|
|
[ $bail -eq 0 ] || exit $ret
|
|
|
|
fi
|
|
|
|
|
2024-02-15 18:25:37 +00:00
|
|
|
msg+=" - reverse direction"
|
|
|
|
printf "%-60s" "${msg}"
|
2021-10-29 23:55:59 +00:00
|
|
|
do_transfer $large $small $time
|
2020-09-14 08:01:19 +00:00
|
|
|
lret=$?
|
2023-07-17 13:21:31 +00:00
|
|
|
mptcp_lib_result_code "${lret}" "${msg}"
|
2020-09-14 08:01:19 +00:00
|
|
|
if [ $lret -ne 0 ]; then
|
|
|
|
ret=$lret
|
|
|
|
[ $bail -eq 0 ] || exit $ret
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
while getopts "bcdh" option;do
|
|
|
|
case "$option" in
|
|
|
|
"h")
|
|
|
|
usage $0
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
"b")
|
|
|
|
bail=1
|
|
|
|
;;
|
|
|
|
"c")
|
|
|
|
capture=true
|
|
|
|
;;
|
|
|
|
"d")
|
|
|
|
set -x
|
|
|
|
;;
|
|
|
|
"?")
|
|
|
|
usage $0
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
setup
|
|
|
|
run_test 10 10 0 0 "balanced bwidth"
|
2024-01-31 21:49:51 +00:00
|
|
|
run_test 10 10 1 25 "balanced bwidth with unbalanced delay"
|
2020-09-14 08:01:19 +00:00
|
|
|
|
|
|
|
# we still need some additional infrastructure to pass the following test-cases
|
2024-01-31 21:49:51 +00:00
|
|
|
run_test 10 3 0 0 "unbalanced bwidth"
|
|
|
|
run_test 10 3 1 25 "unbalanced bwidth with unbalanced delay"
|
|
|
|
run_test 10 3 25 1 "unbalanced bwidth with opposed, unbalanced delay"
|
2023-07-17 13:21:31 +00:00
|
|
|
|
|
|
|
mptcp_lib_result_print_all_tap
|
2020-09-14 08:01:19 +00:00
|
|
|
exit $ret
|