mptcp: selftests: Add capture option
Subsystems (3)
Mat Martineau
PATCH 1/1 mptcp: selftests: Add capture option
Added a "-c" command line option for mptcp_connect.sh to make it easier to capture packets from each test. The script will use tcpdump to create one .pcap file per test case, named according to the namespaces, protocols, and connect address in use. For example, the first test case writes the capture to ns1-ns1-MPTCP-MPTCP-10.0.1.1.pcap
The stderr output from tcpdump is printed after the test completes to show tcpdump's "packets dropped by kernel" information.
--- .../selftests/net/mptcp/mptcp_connect.sh | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+)
tools/testing/selftests/net/mptcp/mptcp_connect.sh +33 -0
@@ -6,6 +6,7 @@ sout="" cin="" cout="" ksft_skip=4 +capture=0 TEST_COUNT=0
@@ -13,12 +14,19 @@ cleanup() { rm -f "$cin" "$cout" rm -f "$sin" "$sout" + rm -f "$capout" for i in 1 2 3 4; do ip netns del ns$i done } +for arg in "$@"; do + if [ "$arg" = "-c" ]; then + capture=1 + fi +done + ip -Version > /dev/null 2>&1 if [ $? -ne 0 ];then echo "SKIP: Could not run test without ip tool"
@@ -29,6 +37,7 @@ sin=$(mktemp) sout=$(mktemp) cin=$(mktemp) cout=$(mktemp) +capout=$(mktemp) trap cleanup EXIT for i in 1 2 3 4;do
@@ -105,6 +114,7 @@ do_transfer() :> "$cout" :> "$sout" + :> "$capout" ip netns exec ${connector_ns} ping -q -c 1 $connect_addr >/dev/null if [ $? -ne 0 ] ; then echo "$listener_ns -> $connect_addr connectivity [ FAIL ]" 1>&2
@@ -113,6 +123,21 @@ do_transfer() printf "%-4s %-5s -> %-4s (%s:%d) %-5s\t" ${connector_ns} ${cl_proto} ${listener_ns} ${connect_addr} ${port} ${srv_proto} + if [ $capture -eq 1 ]; then + if [ -z $SUDO_USER ] ; then + capuser="" + else + capuser="-Z $SUDO_USER" + fi + + capfile="${listener_ns}-${connector_ns}-${cl_proto}-${srv_proto}-${connect_addr}.pcap" + + ip netns exec ${listener_ns} tcpdump -i any -s 65535 -B 32768 $capuser -w $capfile > "$capout" 2>&1 & + cappid=$! + + sleep 1 + fi + ip netns exec ${listener_ns} ./mptcp_connect -t 10 -l -p $port -s ${srv_proto} 0.0.0.0 < "$sin" > "$sout" & spid=$!
@@ -126,6 +151,11 @@ do_transfer() wait $spid rets=$? + if [ $capture -eq 1 ]; then + sleep 1 + kill $cappid + fi + if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then echo "[ FAIL ] client exit code $retc, server $rets" 1>&2 echo "\nnetns ${listener_ns} socket stat for $port:" 1>&2
@@ -133,6 +163,7 @@ do_transfer() echo "\nnetns ${connector_ns} socket stat for $port:" 1>&2 ip netns exec ${connector_ns} ss -nita 1>&2 -o "dport = :$port" + cat "$capout" ret=$rets return 1 fi
@@ -144,9 +175,11 @@ do_transfer() if [ $retc -eq 0 ] && [ $rets -eq 0 ];then echo "[ OK ]" + cat "$capout" return 0 fi + cat "$capout" return 1 }
Signature · 1 line
2.21.0
Matthieu Baerts
Hi Florian, Paolo,
Does this patch look good to you?
The patch is OK for me but I would prefer to wait for your review as your are the main contributors of this script and Mat added you in the "to" field of this patch :)
If it is OK for you, can I append it at the end of the series or do you want me to squash it in another commit?
Thank you!
Hi Mat,
Quoted 8 lines · Mat Martineau
Added a "-c" command line option for
mptcp_connect.shto make it easier to capture packets from each test. The script will use tcpdump to create one .pcap file per test case, named according to the namespaces, protocols, and connect address in use. For example, the first test case writes the capture to ns1-ns1-MPTCP-MPTCP-10.0.1.1.pcapThe stderr output from tcpdump is printed after the test completes to show tcpdump's "packets dropped by kernel" information.
Thank you for the patch! :)
Cheers,
Matthieu
Quoted 108 lines
Signed-off-by Mat Martineau <mathew.j.martineau(a)linux.intel.com>--- .../selftests/net/mptcp/mptcp_connect.sh | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+)tools/testing/selftests/net/mptcp/mptcp_connect.sh +33
-0@@ -6,6 +6,7 @@ sout="" cin="" cout="" ksft_skip=4 +capture=0 TEST_COUNT=0@@ -13,12 +14,19 @@ cleanup() { rm -f "$cin" "$cout" rm -f "$sin" "$sout" + rm -f "$capout" for i in 1 2 3 4; do ip netns del ns$i done } +for arg in "$@"; do + if [ "$arg" = "-c" ]; then + capture=1 + fi +done + ip -Version > /dev/null 2>&1 if [ $? -ne 0 ];then echo "SKIP: Could not run test without ip tool"@@ -29,6 +37,7 @@ sin=$(mktemp) sout=$(mktemp) cin=$(mktemp) cout=$(mktemp) +capout=$(mktemp) trap cleanup EXIT for i in 1 2 3 4;do@@ -105,6 +114,7 @@ do_transfer() :> "$cout" :> "$sout" + :> "$capout" ip netns exec ${connector_ns} ping -q -c 1 $connect_addr >/dev/null if [ $? -ne 0 ] ; then echo "$listener_ns -> $connect_addr connectivity [ FAIL ]" 1>&2@@ -113,6 +123,21 @@ do_transfer() printf "%-4s %-5s -> %-4s (%s:%d) %-5s\t" ${connector_ns} ${cl_proto} ${listener_ns} ${connect_addr} ${port} ${srv_proto} + if [ $capture -eq 1 ]; then + if [ -z $SUDO_USER ] ; then + capuser="" + else + capuser="-Z $SUDO_USER" + fi + + capfile="${listener_ns}-${connector_ns}-${cl_proto}-${srv_proto}-${connect_addr}.pcap" + + ip netns exec ${listener_ns} tcpdump -i any -s 65535 -B 32768 $capuser -w $capfile > "$capout" 2>&1 & + cappid=$! + + sleep 1 + fi + ip netns exec ${listener_ns} ./mptcp_connect -t 10 -l -p $port -s ${srv_proto} 0.0.0.0 < "$sin" > "$sout" & spid=$!@@ -126,6 +151,11 @@ do_transfer() wait $spid rets=$? + if [ $capture -eq 1 ]; then + sleep 1 + kill $cappid + fi + if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then echo "[ FAIL ] client exit code $retc, server $rets" 1>&2 echo "\nnetns ${listener_ns} socket stat for $port:" 1>&2@@ -133,6 +163,7 @@ do_transfer() echo "\nnetns ${connector_ns} socket stat for $port:" 1>&2 ip netns exec ${connector_ns} ss -nita 1>&2 -o "dport = :$port" + cat "$capout" ret=$rets return 1 fi@@ -144,9 +175,11 @@ do_transfer() if [ $retc -eq 0 ] && [ $rets -eq 0 ];then echo "[ OK ]" + cat "$capout" return 0 fi + cat "$capout" return 1 }
Signature · 5 lines
Matthieu Baerts | R&D Engineer matthieu.baerts(a)tessares.net Tessares SA | Hybrid Access Solutions www.tessares.net 1 Avenue Jean Monnet, 1348 Louvain-la-Neuve, Belgium
Florian Westphal
Quoted 1 line · Matthieu Baerts
Does this patch look good to you?
Yes, it does, thanks a lot for adding this.
Quoted 2 lines
If it is OK for you, can I append it at the end of the series or do you want me to squash it in another commit?
I don't mind either way, whatever works best for you.
Paolo Abeni
Quoted 1 line · Matthieu Baerts
Does this patch look good to you?
Yep! Thanks for doing this.
On a side note, running tcpdump in background usually hides most of the existing races, at least in my experiments :(
Quoted 2 lines
If it is OK for you, can I append it at the end of the series or do you want me to squash it in another commit?
I'm fine either way, too.
Cheers,
Paolo
Matthieu Baerts
Hi Paolo, Florian,
Quoted 4 lines · Paolo Abeni
Quoted 1 line · Matthieu Baerts
Does this patch look good to you?
Yep! Thanks for doing this.
Thank you both for the quick review!
Quoted 2 lines
On a side note, running tcpdump in background usually hides most of the existing races, at least in my experiments :(
Good to know! Thank you for sharing this!
Quoted 4 lines
Quoted 2 lines
If it is OK for you, can I append it at the end of the series or do you want me to squash it in another commit?
I'm fine either way, too.
Thank you. I just added the commit at the end of the series. Of course I can change that easily if needed.
Cheers,
Matthieu
Signature · 5 lines
Matthieu Baerts | R&D Engineer matthieu.baerts(a)tessares.net Tessares SA | Hybrid Access Solutions www.tessares.net 1 Avenue Jean Monnet, 1348 Louvain-la-Neuve, Belgium