Commit 0d16ed0c authored by Geliang Tang's avatar Geliang Tang Committed by David S. Miller

selftests: mptcp: add {get,format}_endpoint(s) helpers

The output formats of 'ip mptcp' commands are much different from that
of 'pm_nl_ctl' commands.

This patch adds a new helper format_endpoints() to format the outputs of
'ip mptcp' and 'pm_nl_ctl' with 'endpoints' arguments to hide these
differences.

A new helper named get_endpoint() has also been added to show a specific
endpoint identified by the given address ID, similar to mptcp_join.sh's
pm_nl_show_endpoints() helper, but showing all entries.

Use these two helpers in mptcp_join.sh and pm_netlink.sh to replace all
'pm_nl_ctl get' commands and outputs of 'pm_nl_ctl dump/get'.
Suggested-by: default avatarMatthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: default avatarGeliang Tang <tanggeliang@kylinos.cn>
Reviewed-by: default avatarMatthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: default avatarMatthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 3188309c
...@@ -712,12 +712,9 @@ pm_nl_check_endpoint() ...@@ -712,12 +712,9 @@ pm_nl_check_endpoint()
local ns=$2 local ns=$2
local addr=$3 local addr=$3
local _flags="" local _flags=""
local flags
local _port local _port
local port
local dev local dev
local _id local _id
local id
print_check "${msg}" print_check "${msg}"
...@@ -725,48 +722,29 @@ pm_nl_check_endpoint() ...@@ -725,48 +722,29 @@ pm_nl_check_endpoint()
while [ -n "$1" ]; do while [ -n "$1" ]; do
if [ $1 = "flags" ]; then if [ $1 = "flags" ]; then
_flags=$2 _flags=$2
[ -n "$_flags" ]; flags="flags $_flags"
shift shift
elif [ $1 = "dev" ]; then elif [ $1 = "dev" ]; then
[ -n "$2" ]; dev="dev $2" [ -n "$2" ]; dev="$2"
shift shift
elif [ $1 = "id" ]; then elif [ $1 = "id" ]; then
_id=$2 _id=$2
[ -n "$_id" ]; id="id $_id"
shift shift
elif [ $1 = "port" ]; then elif [ $1 = "port" ]; then
_port=$2 _port=$2
[ -n "$_port" ]; port=" port $_port"
shift shift
fi fi
shift shift
done done
if [ -z "$id" ]; then if [ -z "${_id}" ]; then
test_fail "bad test - missing endpoint id" test_fail "bad test - missing endpoint id"
return return
fi fi
if mptcp_lib_is_ip_mptcp; then line=$(mptcp_lib_pm_nl_get_endpoint "${ns}" "${_id}")
# get line and trim trailing whitespace expected_line=$(mptcp_lib_pm_nl_format_endpoints \
line=$(ip -n $ns mptcp endpoint show $id) "${_id},${addr},${_flags//","/" "},${dev},${_port}")
line="${line% }"
# the dump order is: address id flags port dev
[ -n "$addr" ] && expected_line="$addr"
expected_line+=" $id"
[ -n "$_flags" ] && expected_line+=" ${_flags//","/" "}"
[ -n "$dev" ] && expected_line+=" $dev"
[ -n "$port" ] && 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+=" $flags"
[ -n "$dev" ] && expected_line+=" $dev"
[ -n "$addr" ] && expected_line+=" $addr"
[ -n "$_port" ] && expected_line+=" $_port"
fi
if [ "$line" = "$expected_line" ]; then if [ "$line" = "$expected_line" ]; then
print_ok print_ok
else else
......
...@@ -520,3 +520,38 @@ mptcp_lib_set_ip_mptcp() { ...@@ -520,3 +520,38 @@ mptcp_lib_set_ip_mptcp() {
mptcp_lib_is_ip_mptcp() { mptcp_lib_is_ip_mptcp() {
[ "${MPTCP_LIB_IP_MPTCP}" = "1" ] [ "${MPTCP_LIB_IP_MPTCP}" = "1" ]
} }
# format: <id>,<ip>,<flags>,<dev>
mptcp_lib_pm_nl_format_endpoints() {
local entry id ip flags dev port
for entry in "${@}"; do
IFS=, read -r id ip flags dev port <<< "${entry}"
if mptcp_lib_is_ip_mptcp; then
echo -n "${ip}"
[ -n "${port}" ] && echo -n " port ${port}"
echo -n " id ${id}"
[ -n "${flags}" ] && echo -n " ${flags}"
[ -n "${dev}" ] && echo -n " dev ${dev}"
echo " " # always a space at the end
else
echo -n "id ${id}"
echo -n " flags ${flags//" "/","}"
[ -n "${dev}" ] && echo -n " dev ${dev}"
echo -n " ${ip}"
[ -n "${port}" ] && echo -n " ${port}"
echo ""
fi
done
}
mptcp_lib_pm_nl_get_endpoint() {
local ns=${1}
local id=${2}
if mptcp_lib_is_ip_mptcp; then
ip -n "${ns}" mptcp endpoint show id "${id}"
else
ip netns exec "${ns}" ./pm_nl_ctl get "${id}"
fi
}
...@@ -66,6 +66,15 @@ get_limits() { ...@@ -66,6 +66,15 @@ get_limits() {
fi fi
} }
format_endpoints() {
mptcp_lib_pm_nl_format_endpoints "${@}"
}
get_endpoint() {
# shellcheck disable=SC2317 # invoked indirectly
mptcp_lib_pm_nl_get_endpoint "${ns1}" "${@}"
}
check() check()
{ {
local cmd="$1" local cmd="$1"
...@@ -97,43 +106,44 @@ fi ...@@ -97,43 +106,44 @@ fi
ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.1 ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.1
ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.2 flags subflow dev lo ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.2 flags subflow dev lo
ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.3 flags signal,backup ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.3 flags signal,backup
check "ip netns exec $ns1 ./pm_nl_ctl get 1" "id 1 flags 10.0.1.1" "simple add/get addr" check "get_endpoint 1" "$(format_endpoints "1,10.0.1.1")" "simple add/get addr"
check "ip netns exec $ns1 ./pm_nl_ctl dump" \ check "ip netns exec $ns1 ./pm_nl_ctl dump" \
"id 1 flags 10.0.1.1 "$(format_endpoints "1,10.0.1.1" \
id 2 flags subflow dev lo 10.0.1.2 "2,10.0.1.2,subflow,lo" \
id 3 flags signal,backup 10.0.1.3" "dump addrs" "3,10.0.1.3,signal backup")" "dump addrs"
ip netns exec $ns1 ./pm_nl_ctl del 2 ip netns exec $ns1 ./pm_nl_ctl del 2
check "ip netns exec $ns1 ./pm_nl_ctl get 2" "" "simple del addr" check "get_endpoint 2" "" "simple del addr"
check "ip netns exec $ns1 ./pm_nl_ctl dump" \ check "ip netns exec $ns1 ./pm_nl_ctl dump" \
"id 1 flags 10.0.1.1 "$(format_endpoints "1,10.0.1.1" \
id 3 flags signal,backup 10.0.1.3" "dump addrs after del" "3,10.0.1.3,signal backup")" "dump addrs after del"
ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.3 2>/dev/null ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.3 2>/dev/null
check "ip netns exec $ns1 ./pm_nl_ctl get 4" "" "duplicate addr" check "get_endpoint 4" "" "duplicate addr"
ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.4 flags signal ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.4 flags signal
check "ip netns exec $ns1 ./pm_nl_ctl get 4" "id 4 flags signal 10.0.1.4" "id addr increment" check "get_endpoint 4" "$(format_endpoints "4,10.0.1.4,signal")" "id addr increment"
for i in $(seq 5 9); do for i in $(seq 5 9); do
ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.$i flags signal >/dev/null 2>&1 ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.$i flags signal >/dev/null 2>&1
done done
check "ip netns exec $ns1 ./pm_nl_ctl get 9" "id 9 flags signal 10.0.1.9" "hard addr limit" check "get_endpoint 9" "$(format_endpoints "9,10.0.1.9,signal")" "hard addr limit"
check "ip netns exec $ns1 ./pm_nl_ctl get 10" "" "above hard addr limit" check "get_endpoint 10" "" "above hard addr limit"
ip netns exec $ns1 ./pm_nl_ctl del 9 ip netns exec $ns1 ./pm_nl_ctl del 9
for i in $(seq 10 255); do for i in $(seq 10 255); do
ip netns exec $ns1 ./pm_nl_ctl add 10.0.0.9 id $i ip netns exec $ns1 ./pm_nl_ctl add 10.0.0.9 id $i
ip netns exec $ns1 ./pm_nl_ctl del $i ip netns exec $ns1 ./pm_nl_ctl del $i
done done
check "ip netns exec $ns1 ./pm_nl_ctl dump" "id 1 flags 10.0.1.1 check "ip netns exec $ns1 ./pm_nl_ctl dump" \
id 3 flags signal,backup 10.0.1.3 "$(format_endpoints "1,10.0.1.1" \
id 4 flags signal 10.0.1.4 "3,10.0.1.3,signal backup" \
id 5 flags signal 10.0.1.5 "4,10.0.1.4,signal" \
id 6 flags signal 10.0.1.6 "5,10.0.1.5,signal" \
id 7 flags signal 10.0.1.7 "6,10.0.1.6,signal" \
id 8 flags signal 10.0.1.8" "id limit" "7,10.0.1.7,signal" \
"8,10.0.1.8,signal")" "id limit"
ip netns exec $ns1 ./pm_nl_ctl flush ip netns exec $ns1 ./pm_nl_ctl flush
check "ip netns exec $ns1 ./pm_nl_ctl dump" "" "flush addrs" check "ip netns exec $ns1 ./pm_nl_ctl dump" "" "flush addrs"
...@@ -156,14 +166,15 @@ ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.5 id 254 ...@@ -156,14 +166,15 @@ ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.5 id 254
ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.6 ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.6
ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.7 ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.7
ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.8 ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.8
check "ip netns exec $ns1 ./pm_nl_ctl dump" "id 1 flags 10.0.1.1 check "ip netns exec $ns1 ./pm_nl_ctl dump" \
id 2 flags 10.0.1.2 "$(format_endpoints "1,10.0.1.1" \
id 3 flags 10.0.1.7 "2,10.0.1.2" \
id 4 flags 10.0.1.8 "3,10.0.1.7" \
id 100 flags 10.0.1.3 "4,10.0.1.8" \
id 101 flags 10.0.1.4 "100,10.0.1.3" \
id 254 flags 10.0.1.5 "101,10.0.1.4" \
id 255 flags 10.0.1.6" "set ids" "254,10.0.1.5" \
"255,10.0.1.6")" "set ids"
ip netns exec $ns1 ./pm_nl_ctl flush ip netns exec $ns1 ./pm_nl_ctl flush
ip netns exec $ns1 ./pm_nl_ctl add 10.0.0.1 ip netns exec $ns1 ./pm_nl_ctl add 10.0.0.1
...@@ -174,36 +185,39 @@ ip netns exec $ns1 ./pm_nl_ctl add 10.0.0.5 id 253 ...@@ -174,36 +185,39 @@ ip netns exec $ns1 ./pm_nl_ctl add 10.0.0.5 id 253
ip netns exec $ns1 ./pm_nl_ctl add 10.0.0.6 ip netns exec $ns1 ./pm_nl_ctl add 10.0.0.6
ip netns exec $ns1 ./pm_nl_ctl add 10.0.0.7 ip netns exec $ns1 ./pm_nl_ctl add 10.0.0.7
ip netns exec $ns1 ./pm_nl_ctl add 10.0.0.8 ip netns exec $ns1 ./pm_nl_ctl add 10.0.0.8
check "ip netns exec $ns1 ./pm_nl_ctl dump" "id 1 flags 10.0.0.1 check "ip netns exec $ns1 ./pm_nl_ctl dump" \
id 2 flags 10.0.0.4 "$(format_endpoints "1,10.0.0.1" \
id 3 flags 10.0.0.6 "2,10.0.0.4" \
id 4 flags 10.0.0.7 "3,10.0.0.6" \
id 5 flags 10.0.0.8 "4,10.0.0.7" \
id 253 flags 10.0.0.5 "5,10.0.0.8" \
id 254 flags 10.0.0.2 "253,10.0.0.5" \
id 255 flags 10.0.0.3" "wrap-around ids" "254,10.0.0.2" \
"255,10.0.0.3")" "wrap-around ids"
ip netns exec $ns1 ./pm_nl_ctl flush ip netns exec $ns1 ./pm_nl_ctl flush
ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.1 flags subflow ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.1 flags subflow
ip netns exec $ns1 ./pm_nl_ctl set 10.0.1.1 flags backup ip netns exec $ns1 ./pm_nl_ctl set 10.0.1.1 flags backup
check "ip netns exec $ns1 ./pm_nl_ctl dump" "id 1 flags \ check "ip netns exec $ns1 ./pm_nl_ctl dump" "$(format_endpoints "1,10.0.1.1,subflow backup")" \
subflow,backup 10.0.1.1" "set flags (backup)" "set flags (backup)"
ip netns exec $ns1 ./pm_nl_ctl set 10.0.1.1 flags nobackup ip netns exec $ns1 ./pm_nl_ctl set 10.0.1.1 flags nobackup
check "ip netns exec $ns1 ./pm_nl_ctl dump" "id 1 flags \ check "ip netns exec $ns1 ./pm_nl_ctl dump" "$(format_endpoints "1,10.0.1.1,subflow")" \
subflow 10.0.1.1" " (nobackup)" " (nobackup)"
# fullmesh support has been added later # fullmesh support has been added later
ip netns exec $ns1 ./pm_nl_ctl set id 1 flags fullmesh 2>/dev/null ip netns exec $ns1 ./pm_nl_ctl set id 1 flags fullmesh 2>/dev/null
if ip netns exec $ns1 ./pm_nl_ctl dump | grep -q "fullmesh" || if ip netns exec $ns1 ./pm_nl_ctl dump | grep -q "fullmesh" ||
mptcp_lib_expect_all_features; then mptcp_lib_expect_all_features; then
check "ip netns exec $ns1 ./pm_nl_ctl dump" "id 1 flags \ check "ip netns exec $ns1 ./pm_nl_ctl dump" \
subflow,fullmesh 10.0.1.1" " (fullmesh)" "$(format_endpoints "1,10.0.1.1,subflow fullmesh")" \
" (fullmesh)"
ip netns exec $ns1 ./pm_nl_ctl set id 1 flags nofullmesh ip netns exec $ns1 ./pm_nl_ctl set id 1 flags nofullmesh
check "ip netns exec $ns1 ./pm_nl_ctl dump" "id 1 flags \ check "ip netns exec $ns1 ./pm_nl_ctl dump" "$(format_endpoints "1,10.0.1.1,subflow")" \
subflow 10.0.1.1" " (nofullmesh)" " (nofullmesh)"
ip netns exec $ns1 ./pm_nl_ctl set id 1 flags backup,fullmesh ip netns exec $ns1 ./pm_nl_ctl set id 1 flags backup,fullmesh
check "ip netns exec $ns1 ./pm_nl_ctl dump" "id 1 flags \ check "ip netns exec $ns1 ./pm_nl_ctl dump" \
subflow,backup,fullmesh 10.0.1.1" " (backup,fullmesh)" "$(format_endpoints "1,10.0.1.1,subflow backup fullmesh")" \
" (backup,fullmesh)"
else else
for st in fullmesh nofullmesh backup,fullmesh; do for st in fullmesh nofullmesh backup,fullmesh; do
st=" (${st})" st=" (${st})"
......
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