Skip to content

Commit

Permalink
selftests: mptcp: export event macros in mptcp_lib
Browse files Browse the repository at this point in the history
SUB_ESTABLISHED, LISTENER_CREATED, LISTENER_CLOSED AF_INET and AF_INET6
are defined in both mptcp_join.sh and userspace_pm.sh, export them into
mptcp_lib.sh. Add MPTCP_LIB_ prefix for the first three and add readonly
for the last two.

Signed-off-by: Geliang Tang <[email protected]>
  • Loading branch information
geliangtang authored and intel-lab-lkp committed Nov 8, 2023
1 parent 4c6f2a7 commit e254741
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 44 deletions.
21 changes: 8 additions & 13 deletions tools/testing/selftests/net/mptcp/mptcp_join.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2777,13 +2777,6 @@ backup_tests()
fi
}

SUB_ESTABLISHED=10 # MPTCP_EVENT_SUB_ESTABLISHED
LISTENER_CREATED=15 #MPTCP_EVENT_LISTENER_CREATED
LISTENER_CLOSED=16 #MPTCP_EVENT_LISTENER_CLOSED

AF_INET=2
AF_INET6=10

verify_listener_events()
{
local evt=$1
Expand All @@ -2797,9 +2790,9 @@ verify_listener_events()
local sport
local name

if [ $e_type = $LISTENER_CREATED ]; then
if [ $e_type = $MPTCP_LIB_LISTENER_CREATED ]; then
name="LISTENER_CREATED"
elif [ $e_type = $LISTENER_CLOSED ]; then
elif [ $e_type = $MPTCP_LIB_LISTENER_CLOSED ]; then
name="LISTENER_CLOSED "
else
name="$e_type"
Expand Down Expand Up @@ -2866,8 +2859,10 @@ add_addr_ports_tests()
chk_add_nr 1 1 1
chk_rm_nr 1 1 invert

verify_listener_events $server_evts $LISTENER_CREATED $AF_INET 10.0.2.1 10100
verify_listener_events $server_evts $LISTENER_CLOSED $AF_INET 10.0.2.1 10100
verify_listener_events $server_evts $MPTCP_LIB_LISTENER_CREATED \
$AF_INET 10.0.2.1 10100
verify_listener_events $server_evts $MPTCP_LIB_LISTENER_CLOSED \
$AF_INET 10.0.2.1 10100
mptcp_lib_evts_kill
fi

Expand Down Expand Up @@ -3396,7 +3391,7 @@ userspace_tests()
chk_subflows_total 2 2
chk_mptcp_info add_addr_signal 1 add_addr_accepted 1
userspace_pm_rm_addr $ns1 10
userspace_pm_rm_sf $ns1 "::ffff:10.0.2.1" $SUB_ESTABLISHED
userspace_pm_rm_sf $ns1 "::ffff:10.0.2.1" $MPTCP_LIB_SUB_ESTABLISHED
chk_rm_nr 1 1 invert
chk_mptcp_info subflows 0 subflows 0
chk_subflows_total 1 1
Expand All @@ -3419,7 +3414,7 @@ userspace_tests()
chk_mptcp_info subflows 1 subflows 1
chk_subflows_total 2 2
userspace_pm_rm_addr $ns2 20
userspace_pm_rm_sf $ns2 10.0.3.2 $SUB_ESTABLISHED
userspace_pm_rm_sf $ns2 10.0.3.2 $MPTCP_LIB_SUB_ESTABLISHED
chk_rm_nr 1 1
chk_mptcp_info subflows 0 subflows 0
chk_subflows_total 1 1
Expand Down
7 changes: 7 additions & 0 deletions tools/testing/selftests/net/mptcp/mptcp_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ readonly KSFT_SKIP=4
# shellcheck disable=SC2155 # declare and assign separately
readonly KSFT_TEST=$(basename "${0}" | sed 's/\.sh$//g')

MPTCP_LIB_SUB_ESTABLISHED=10 # MPTCP_EVENT_SUB_ESTABLISHED
MPTCP_LIB_LISTENER_CREATED=15 #MPTCP_EVENT_LISTENER_CREATED
MPTCP_LIB_LISTENER_CLOSED=16 #MPTCP_EVENT_LISTENER_CLOSED

readonly AF_INET=2
readonly AF_INET6=10

MPTCP_LIB_SUBTESTS=()

# only if supported (or forced) and not disabled, see no-color.org
Expand Down
60 changes: 29 additions & 31 deletions tools/testing/selftests/net/mptcp/userspace_pm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,7 @@ fi

ANNOUNCED=6 # MPTCP_EVENT_ANNOUNCED
REMOVED=7 # MPTCP_EVENT_REMOVED
SUB_ESTABLISHED=10 # MPTCP_EVENT_SUB_ESTABLISHED
SUB_CLOSED=11 # MPTCP_EVENT_SUB_CLOSED
LISTENER_CREATED=15 #MPTCP_EVENT_LISTENER_CREATED
LISTENER_CLOSED=16 #MPTCP_EVENT_LISTENER_CLOSED

AF_INET=2
AF_INET6=10

file=""
client4_pid=0
Expand Down Expand Up @@ -525,7 +519,7 @@ verify_subflow_events()

info="${e_saddr} (${e_from}) => ${e_daddr} (${e_to})"

if [ "$e_type" = "$SUB_ESTABLISHED" ]
if [ "$e_type" = "$MPTCP_LIB_SUB_ESTABLISHED" ]
then
if [ "$e_family" = "$AF_INET6" ]
then
Expand Down Expand Up @@ -582,14 +576,15 @@ test_subflows()
ip netns exec "$ns1" ./pm_nl_ctl csf lip 10.0.2.1 lid 23 rip 10.0.2.2\
rport "$client4_port" token "$server4_token"
sleep 0.5
verify_subflow_events $server_evts $SUB_ESTABLISHED $server4_token $AF_INET "10.0.2.1" \
"10.0.2.2" "$client4_port" "23" "$client_addr_id" "ns1" "ns2"
verify_subflow_events $server_evts $MPTCP_LIB_SUB_ESTABLISHED $server4_token \
$AF_INET "10.0.2.1" "10.0.2.2" "$client4_port" "23" \
"$client_addr_id" "ns1" "ns2"

# Delete the listener from the client ns, if one was created
mptcp_lib_kill_wait $listener_pid

local sport
sport=$(mptcp_lib_evts_get_info sport "$server_evts" $SUB_ESTABLISHED)
sport=$(mptcp_lib_evts_get_info sport "$server_evts" $MPTCP_LIB_SUB_ESTABLISHED)

# DESTROY_SUBFLOW from server to client machine
:>"$server_evts"
Expand Down Expand Up @@ -620,14 +615,14 @@ test_subflows()
ip netns exec "$ns1" ./pm_nl_ctl csf lip dead:beef:2::1 lid 23 rip\
dead:beef:2::2 rport "$client6_port" token "$server6_token"
sleep 0.5
verify_subflow_events "$server_evts" "$SUB_ESTABLISHED" "$server6_token" "$AF_INET6"\
"dead:beef:2::1" "dead:beef:2::2" "$client6_port" "23"\
"$client_addr_id" "ns1" "ns2"
verify_subflow_events "$server_evts" "$MPTCP_LIB_SUB_ESTABLISHED" "$server6_token" \
"$AF_INET6" "dead:beef:2::1" "dead:beef:2::2" "$client6_port" \
"23" "$client_addr_id" "ns1" "ns2"

# Delete the listener from the client ns, if one was created
mptcp_lib_kill_wait $listener_pid

sport=$(mptcp_lib_evts_get_info sport "$server_evts" $SUB_ESTABLISHED)
sport=$(mptcp_lib_evts_get_info sport "$server_evts" $MPTCP_LIB_SUB_ESTABLISHED)

# DESTROY_SUBFLOW6 from server to client machine
:>"$server_evts"
Expand Down Expand Up @@ -659,14 +654,14 @@ test_subflows()
ip netns exec "$ns1" ./pm_nl_ctl csf lip 10.0.2.1 lid 23 rip 10.0.2.2 rport\
$new4_port token "$server4_token"
sleep 0.5
verify_subflow_events "$server_evts" "$SUB_ESTABLISHED" "$server4_token" "$AF_INET"\
"10.0.2.1" "10.0.2.2" "$new4_port" "23"\
verify_subflow_events "$server_evts" "$MPTCP_LIB_SUB_ESTABLISHED" "$server4_token" \
"$AF_INET" "10.0.2.1" "10.0.2.2" "$new4_port" "23" \
"$client_addr_id" "ns1" "ns2"

# Delete the listener from the client ns, if one was created
mptcp_lib_kill_wait $listener_pid

sport=$(mptcp_lib_evts_get_info sport "$server_evts" $SUB_ESTABLISHED)
sport=$(mptcp_lib_evts_get_info sport "$server_evts" $MPTCP_LIB_SUB_ESTABLISHED)

# DESTROY_SUBFLOW from server to client machine
:>"$server_evts"
Expand Down Expand Up @@ -698,13 +693,13 @@ test_subflows()
ip netns exec "$ns2" ./pm_nl_ctl csf lip 10.0.2.2 lid 23 rip 10.0.2.1 rport\
$app4_port token "$client4_token"
sleep 0.5
verify_subflow_events $client_evts $SUB_ESTABLISHED $client4_token $AF_INET "10.0.2.2"\
"10.0.2.1" "$app4_port" "23" "$server_addr_id" "ns2" "ns1"
verify_subflow_events $client_evts $MPTCP_LIB_SUB_ESTABLISHED $client4_token $AF_INET \
"10.0.2.2" "10.0.2.1" "$app4_port" "23" "$server_addr_id" "ns2" "ns1"

# Delete the listener from the server ns, if one was created
mptcp_lib_kill_wait $listener_pid

sport=$(mptcp_lib_evts_get_info sport "$client_evts" $SUB_ESTABLISHED)
sport=$(mptcp_lib_evts_get_info sport "$client_evts" $MPTCP_LIB_SUB_ESTABLISHED)

# DESTROY_SUBFLOW from client to server machine
:>"$client_evts"
Expand Down Expand Up @@ -735,15 +730,15 @@ test_subflows()
ip netns exec "$ns2" ./pm_nl_ctl csf lip dead:beef:2::2 lid 23 rip\
dead:beef:2::1 rport $app6_port token "$client6_token"
sleep 0.5
verify_subflow_events "$client_evts" "$SUB_ESTABLISHED" "$client6_token"\
verify_subflow_events "$client_evts" "$MPTCP_LIB_SUB_ESTABLISHED" "$client6_token"\
"$AF_INET6" "dead:beef:2::2"\
"dead:beef:2::1" "$app6_port" "23"\
"$server_addr_id" "ns2" "ns1"

# Delete the listener from the server ns, if one was created
mptcp_lib_kill_wait $listener_pid

sport=$(mptcp_lib_evts_get_info sport "$client_evts" $SUB_ESTABLISHED)
sport=$(mptcp_lib_evts_get_info sport "$client_evts" $MPTCP_LIB_SUB_ESTABLISHED)

# DESTROY_SUBFLOW6 from client to server machine
:>"$client_evts"
Expand Down Expand Up @@ -774,13 +769,14 @@ test_subflows()
ip netns exec "$ns2" ./pm_nl_ctl csf lip 10.0.2.2 lid 23 rip 10.0.2.1 rport\
$new4_port token "$client4_token"
sleep 0.5
verify_subflow_events "$client_evts" "$SUB_ESTABLISHED" "$client4_token" "$AF_INET"\
"10.0.2.2" "10.0.2.1" "$new4_port" "23" "$server_addr_id" "ns2" "ns1"
verify_subflow_events "$client_evts" "$MPTCP_LIB_SUB_ESTABLISHED" "$client4_token" \
"$AF_INET" "10.0.2.2" "10.0.2.1" "$new4_port" "23" \
"$server_addr_id" "ns2" "ns1"

# Delete the listener from the server ns, if one was created
mptcp_lib_kill_wait $listener_pid

sport=$(mptcp_lib_evts_get_info sport "$client_evts" $SUB_ESTABLISHED)
sport=$(mptcp_lib_evts_get_info sport "$client_evts" $MPTCP_LIB_SUB_ESTABLISHED)

# DESTROY_SUBFLOW from client to server machine
:>"$client_evts"
Expand Down Expand Up @@ -819,14 +815,14 @@ test_subflows_v4_v6_mix()
ip netns exec "$ns2" ./pm_nl_ctl csf lip 10.0.2.2 lid 23 rip 10.0.2.1 rport\
$app6_port token "$client6_token"
sleep 0.5
verify_subflow_events "$client_evts" "$SUB_ESTABLISHED" "$client6_token"\
verify_subflow_events "$client_evts" "$MPTCP_LIB_SUB_ESTABLISHED" "$client6_token"\
"$AF_INET" "10.0.2.2" "10.0.2.1" "$app6_port" "23"\
"$server_addr_id" "ns2" "ns1"

# Delete the listener from the server ns, if one was created
mptcp_lib_kill_wait $listener_pid

sport=$(mptcp_lib_evts_get_info sport "$client_evts" $SUB_ESTABLISHED)
sport=$(mptcp_lib_evts_get_info sport "$client_evts" $MPTCP_LIB_SUB_ESTABLISHED)

# DESTROY_SUBFLOW from client to server machine
:>"$client_evts"
Expand Down Expand Up @@ -886,9 +882,9 @@ verify_listener_events()
local saddr
local sport

if [ $e_type = $LISTENER_CREATED ]; then
if [ $e_type = $MPTCP_LIB_LISTENER_CREATED ]; then
print_test "CREATE_LISTENER $e_saddr:$e_sport"
elif [ $e_type = $LISTENER_CLOSED ]; then
elif [ $e_type = $MPTCP_LIB_LISTENER_CLOSED ]; then
print_test "CLOSE_LISTENER $e_saddr:$e_sport"
fi

Expand Down Expand Up @@ -923,7 +919,8 @@ test_listener()
local listener_pid=$!

sleep 0.5
verify_listener_events $client_evts $LISTENER_CREATED $AF_INET 10.0.2.2 $client4_port
verify_listener_events $client_evts $MPTCP_LIB_LISTENER_CREATED \
$AF_INET 10.0.2.2 $client4_port

# ADD_ADDR from client to server machine reusing the subflow port
ip netns exec $ns2 ./pm_nl_ctl ann 10.0.2.2 token $client4_token id\
Expand All @@ -939,7 +936,8 @@ test_listener()
mptcp_lib_kill_wait $listener_pid

sleep 0.5
verify_listener_events $client_evts $LISTENER_CLOSED $AF_INET 10.0.2.2 $client4_port
verify_listener_events $client_evts $MPTCP_LIB_LISTENER_CLOSED \
$AF_INET 10.0.2.2 $client4_port
}

print_title "Make connections"
Expand Down

0 comments on commit e254741

Please sign in to comment.