Commit 757c828c authored by Geliang Tang's avatar Geliang Tang Committed by Jakub Kicinski

selftests: mptcp: update userspace pm test helpers

This patch adds a new argument namespace to userspace_pm_add_addr() and
userspace_pm_add_sf() to make these two helper more versatile.

Add two more versatile helpers for userspace pm remove subflow or address:
userspace_pm_rm_addr() and userspace_pm_rm_sf(). The original test helpers
userspace_pm_rm_sf_addr_ns1() and userspace_pm_rm_sf_addr_ns2() can be
replaced by these new helpers.
Reviewed-by: default avatarMatthieu Baerts <matttbe@kernel.org>
Signed-off-by: default avatarGeliang Tang <geliang.tang@suse.com>
Signed-off-by: default avatarMat Martineau <martineau@kernel.org>
Link: https://lore.kernel.org/r/20231128-send-net-next-2023107-v4-4-8d6b94150f6b@kernel.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 80775412
......@@ -2848,6 +2848,7 @@ backup_tests()
fi
}
SUB_ESTABLISHED=10 # MPTCP_EVENT_SUB_ESTABLISHED
LISTENER_CREATED=15 #MPTCP_EVENT_LISTENER_CREATED
LISTENER_CLOSED=16 #MPTCP_EVENT_LISTENER_CLOSED
......@@ -3308,75 +3309,70 @@ fail_tests()
fi
}
# $1: ns ; $2: addr ; $3: id
userspace_pm_add_addr()
{
local addr=$1
local id=$2
local evts=$evts_ns1
local tk
tk=$(grep "type:1," "$evts_ns1" |
sed -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q')
ip netns exec $ns1 ./pm_nl_ctl ann $addr token $tk id $id
[ "$1" == "$ns2" ] && evts=$evts_ns2
tk=$(mptcp_lib_evts_get_info token "$evts")
ip netns exec $1 ./pm_nl_ctl ann $2 token $tk id $3
sleep 1
}
userspace_pm_rm_sf_addr_ns1()
# $1: ns ; $2: id
userspace_pm_rm_addr()
{
local addr=$1
local id=$2
local tk sp da dp
local cnt_addr cnt_sf
tk=$(grep "type:1," "$evts_ns1" |
sed -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q')
sp=$(grep "type:10" "$evts_ns1" |
sed -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q')
da=$(grep "type:10" "$evts_ns1" |
sed -n 's/.*\(daddr6:\)\([0-9a-f:.]*\).*$/\2/p;q')
dp=$(grep "type:10" "$evts_ns1" |
sed -n 's/.*\(dport:\)\([[:digit:]]*\).*$/\2/p;q')
cnt_addr=$(rm_addr_count ${ns1})
cnt_sf=$(rm_sf_count ${ns1})
ip netns exec $ns1 ./pm_nl_ctl rem token $tk id $id
ip netns exec $ns1 ./pm_nl_ctl dsf lip "::ffff:$addr" \
lport $sp rip $da rport $dp token $tk
wait_rm_addr $ns1 "${cnt_addr}"
wait_rm_sf $ns1 "${cnt_sf}"
local evts=$evts_ns1
local tk
local cnt
[ "$1" == "$ns2" ] && evts=$evts_ns2
tk=$(mptcp_lib_evts_get_info token "$evts")
cnt=$(rm_addr_count ${1})
ip netns exec $1 ./pm_nl_ctl rem token $tk id $2
wait_rm_addr $1 "${cnt}"
}
# $1: ns ; $2: addr ; $3: id
userspace_pm_add_sf()
{
local addr=$1
local id=$2
local evts=$evts_ns1
local tk da dp
tk=$(sed -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q' "$evts_ns2")
da=$(sed -n 's/.*\(daddr4:\)\([0-9.]*\).*$/\2/p;q' "$evts_ns2")
dp=$(sed -n 's/.*\(dport:\)\([[:digit:]]*\).*$/\2/p;q' "$evts_ns2")
ip netns exec $ns2 ./pm_nl_ctl csf lip $addr lid $id \
[ "$1" == "$ns2" ] && evts=$evts_ns2
tk=$(mptcp_lib_evts_get_info token "$evts")
da=$(mptcp_lib_evts_get_info daddr4 "$evts")
dp=$(mptcp_lib_evts_get_info dport "$evts")
ip netns exec $1 ./pm_nl_ctl csf lip $2 lid $3 \
rip $da rport $dp token $tk
sleep 1
}
userspace_pm_rm_sf_addr_ns2()
# $1: ns ; $2: addr $3: event type
userspace_pm_rm_sf()
{
local addr=$1
local id=$2
local evts=$evts_ns1
local t=${3:-1}
local ip=4
local tk da dp sp
local cnt_addr cnt_sf
tk=$(sed -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q' "$evts_ns2")
da=$(sed -n 's/.*\(daddr4:\)\([0-9.]*\).*$/\2/p;q' "$evts_ns2")
dp=$(sed -n 's/.*\(dport:\)\([[:digit:]]*\).*$/\2/p;q' "$evts_ns2")
sp=$(grep "type:10" "$evts_ns2" |
sed -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q')
cnt_addr=$(rm_addr_count ${ns2})
cnt_sf=$(rm_sf_count ${ns2})
ip netns exec $ns2 ./pm_nl_ctl rem token $tk id $id
ip netns exec $ns2 ./pm_nl_ctl dsf lip $addr lport $sp \
local cnt
[ "$1" == "$ns2" ] && evts=$evts_ns2
if is_v6 $2; then ip=6; fi
tk=$(mptcp_lib_evts_get_info token "$evts")
da=$(mptcp_lib_evts_get_info "daddr$ip" "$evts" $t)
dp=$(mptcp_lib_evts_get_info dport "$evts" $t)
sp=$(mptcp_lib_evts_get_info sport "$evts" $t)
cnt=$(rm_sf_count ${1})
ip netns exec $1 ./pm_nl_ctl dsf lip $2 lport $sp \
rip $da rport $dp token $tk
wait_rm_addr $ns2 "${cnt_addr}"
wait_rm_sf $ns2 "${cnt_sf}"
wait_rm_sf $1 "${cnt}"
}
userspace_tests()
......@@ -3463,13 +3459,14 @@ userspace_tests()
run_tests $ns1 $ns2 10.0.1.1 &
local tests_pid=$!
wait_mpj $ns1
userspace_pm_add_addr 10.0.2.1 10
userspace_pm_add_addr $ns1 10.0.2.1 10
chk_join_nr 1 1 1
chk_add_nr 1 1
chk_mptcp_info subflows 1 subflows 1
chk_subflows_total 2 2
chk_mptcp_info add_addr_signal 1 add_addr_accepted 1
userspace_pm_rm_sf_addr_ns1 10.0.2.1 10
userspace_pm_rm_addr $ns1 10
userspace_pm_rm_sf $ns1 "::ffff:10.0.2.1" $SUB_ESTABLISHED
chk_rm_nr 1 1 invert
chk_mptcp_info subflows 0 subflows 0
chk_subflows_total 1 1
......@@ -3486,11 +3483,12 @@ userspace_tests()
run_tests $ns1 $ns2 10.0.1.1 &
local tests_pid=$!
wait_mpj $ns2
userspace_pm_add_sf 10.0.3.2 20
userspace_pm_add_sf $ns2 10.0.3.2 20
chk_join_nr 1 1 1
chk_mptcp_info subflows 1 subflows 1
chk_subflows_total 2 2
userspace_pm_rm_sf_addr_ns2 10.0.3.2 20
userspace_pm_rm_addr $ns2 20
userspace_pm_rm_sf $ns2 10.0.3.2 $SUB_ESTABLISHED
chk_rm_nr 1 1
chk_mptcp_info subflows 0 subflows 0
chk_subflows_total 1 1
......
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