summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEelco Chaudron <echaudro@redhat.com>2022-09-01 18:02:04 +0200
committerIlya Maximets <i.maximets@ovn.org>2022-09-09 19:08:12 +0200
commitb2151d8fd16f299cc9c916fad44a3ff2518806cd (patch)
tree2fb166c0b0aee23ee1d1409fac23b7f11b893a58
parent49efc63ad8c9ef14248c82dceecf39377619c515 (diff)
downloadopenvswitch-b2151d8fd16f299cc9c916fad44a3ff2518806cd.tar.gz
tests: Use _DAEMONIZE macro's to start tcpdump.
Using [NETNS|OVS]_DAEMONIZE will start tcpdump in the background, and it will also make sure it gets killed in corner cases. For the check_pkt_len tests, we also kill tcpdump between individual tests in the same test case to avoid confusion when analyzing results. This also required some changes to the awk expressions, as an extra newline is added to the output when tcpdump gets stopped. Fixes: 02dabb21f243 ("tests: Add check_pkt_len action test to system-offload-traffic.") Suggested-by: David Marchand <david.marchand@redhat.com> Signed-off-by: Eelco Chaudron <echaudro@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
-rw-r--r--tests/ovs-macros.at9
-rw-r--r--tests/system-ipsec.at6
-rw-r--r--tests/system-offloads-traffic.at28
-rw-r--r--tests/system-traffic.at40
4 files changed, 47 insertions, 36 deletions
diff --git a/tests/ovs-macros.at b/tests/ovs-macros.at
index ebb75ef83..6c61723b2 100644
--- a/tests/ovs-macros.at
+++ b/tests/ovs-macros.at
@@ -313,6 +313,15 @@ m4_define([OVS_APP_EXIT_AND_WAIT_BY_TARGET],
AT_CHECK([ovs-appctl --target=$1 exit])
OVS_WAIT_WHILE([kill -0 $TMPPID 2>/dev/null])])
+dnl OVS_DAEMONIZE([command], [pidfile])
+dnl
+dnl Run 'command' as a background process and record its pid to 'pidfile' to
+dnl allow cleanup on exit.
+m4_define([OVS_DAEMONIZE],
+ [$1 & echo $! > $2
+ on_exit "kill `cat $2`"
+ ])
+
dnl on_exit "COMMAND"
dnl
dnl Add the shell COMMAND to a collection executed when the current test
diff --git a/tests/system-ipsec.at b/tests/system-ipsec.at
index f45a153ed..07f2b8fd0 100644
--- a/tests/system-ipsec.at
+++ b/tests/system-ipsec.at
@@ -133,10 +133,8 @@ m4_define([CHECK_ESP_TRAFFIC],
NS_EXEC([right], [ip link set dev br-ipsec up])
dnl Capture any underlay esp packets
- tcpdump -l -nn -i ovs-p0 esp > $ovs_base/left/tcpdump.log &
- on_exit "kill $!"
- tcpdump -l -nn -i ovs-p1 esp > $ovs_base/right/tcpdump.log &
- on_exit "kill $!"
+ OVS_DAEMONIZE([tcpdump -l -nn -i ovs-p0 esp > $ovs_base/left/tcpdump.log], [tcpdump0.pid])
+ OVS_DAEMONIZE([tcpdump -l -nn -i ovs-p1 esp > $ovs_base/right/tcpdump.log], [tcpdump1.pid])
dnl Wait for all loaded connections to be active
OVS_WAIT_UNTIL([test `IPSEC_STATUS_LOADED(left)` -eq `IPSEC_STATUS_ACTIVE(left)`])
diff --git a/tests/system-offloads-traffic.at b/tests/system-offloads-traffic.at
index 1e1012965..d9b815a5d 100644
--- a/tests/system-offloads-traffic.at
+++ b/tests/system-offloads-traffic.at
@@ -297,8 +297,8 @@ table=4,in_port=1,reg0=0x0 actions=output:4
])
AT_CHECK([ovs-ofctl --protocols=OpenFlow10 add-flows br0 flows.txt])
-NS_CHECK_EXEC([at_ns3], [tcpdump -l -n -U -i p3 dst 10.1.1.2 and icmp > p3.pcap 2>/dev/null &])
-NS_CHECK_EXEC([at_ns4], [tcpdump -l -n -U -i p4 dst 10.1.1.2 and icmp > p4.pcap 2>/dev/null &])
+NETNS_DAEMONIZE([at_ns3], [tcpdump -l -n -U -i p3 dst 10.1.1.2 and icmp > p3.pcap 2>/dev/null], [tcpdump3.pid])
+NETNS_DAEMONIZE([at_ns4], [tcpdump -l -n -U -i p4 dst 10.1.1.2 and icmp > p4.pcap 2>/dev/null], [tcpdump4.pid])
sleep 1
NS_CHECK_EXEC([at_ns1], [ping -q -c 10 -i 0.1 -w 2 -s 64 10.1.1.2 | FORMAT_PING], [0], [dnl
@@ -325,10 +325,10 @@ AT_CHECK([test $(ovs-appctl upcall/show | grep -c "offloaded flows") -eq 0], [0]
OVS_TRAFFIC_VSWITCHD_STOP
-AT_CHECK([cat p3.pcap | awk '{print $NF}' | uniq -c | awk '{$1=$1;print}'], [0], [dnl
+AT_CHECK([cat p3.pcap | awk 'NF{print $NF}' | uniq -c | awk '{$1=$1;print}'], [0], [dnl
10 1032
])
-AT_CHECK([cat p4.pcap | awk '{print $NF}' | uniq -c | awk '{$1=$1;print}'], [0], [dnl
+AT_CHECK([cat p4.pcap | awk 'NF{print $NF}' | uniq -c | awk '{$1=$1;print}'], [0], [dnl
10 72
])
@@ -355,8 +355,8 @@ table=4,in_port=1,reg0=0x0 actions=output:4
])
AT_CHECK([ovs-ofctl --protocols=OpenFlow10 add-flows br0 flows.txt])
-NS_CHECK_EXEC([at_ns3], [tcpdump -l -n -U -i p3 dst 10.1.1.2 and icmp > p3.pcap 2>/dev/null &])
-NS_CHECK_EXEC([at_ns4], [tcpdump -l -n -U -i p4 dst 10.1.1.2 and icmp > p4.pcap 2>/dev/null &])
+NETNS_DAEMONIZE([at_ns3], [tcpdump -l -n -U -i p3 dst 10.1.1.2 and icmp > p3.pcap 2>/dev/null], [tcpdump3.pid])
+NETNS_DAEMONIZE([at_ns4], [tcpdump -l -n -U -i p4 dst 10.1.1.2 and icmp > p4.pcap 2>/dev/null], [tcpdump4.pid])
sleep 1
NS_CHECK_EXEC([at_ns1], [ping -q -c 10 -i 0.1 -w 2 -s 64 10.1.1.2 | FORMAT_PING], [0], [dnl
@@ -382,10 +382,12 @@ in_port(3),eth(),eth_type(0x0800),ipv4(frag=no), packets:19, bytes:11614, used:0
AT_CHECK([ovs-appctl upcall/show | grep -E "offloaded flows : [[1-9]]"], [0], [ignore])
sleep 1
-AT_CHECK([cat p3.pcap | awk '{print $NF}' | uniq -c | awk '{$1=$1;print}'], [0], [dnl
+kill $(cat tcpdump3.pid)
+kill $(cat tcpdump4.pid)
+AT_CHECK([cat p3.pcap | awk 'NF{print $NF}' | uniq -c | awk '{$1=$1;print}'], [0], [dnl
10 1032
])
-AT_CHECK([cat p4.pcap | awk '{print $NF}' | uniq -c | awk '{$1=$1;print}'], [0], [dnl
+AT_CHECK([cat p4.pcap | awk 'NF{print $NF}' | uniq -c | awk '{$1=$1;print}'], [0], [dnl
10 72
])
@@ -501,8 +503,8 @@ table=4,in_port=1,reg0=0x0 actions=mod_nw_tos:8,output:4
AT_CHECK([ovs-ofctl --protocols=OpenFlow10 add-flows br0 flows.txt])
-NS_CHECK_EXEC([at_ns3], [tcpdump -l -n -U -i p3 dst 10.1.1.2 and icmp > p3_2.pcap 2>/dev/null &])
-NS_CHECK_EXEC([at_ns4], [tcpdump -l -n -U -i p4 dst 10.1.1.2 and icmp > p4_2.pcap 2>/dev/null &])
+NETNS_DAEMONIZE([at_ns3], [tcpdump -l -n -U -i p3 dst 10.1.1.2 and icmp > p3_2.pcap 2>/dev/null], [tcpdump3_2.pid])
+NETNS_DAEMONIZE([at_ns4], [tcpdump -l -n -U -i p4 dst 10.1.1.2 and icmp > p4_2.pcap 2>/dev/null], [tcpdump4_2.pid])
sleep 1
NS_CHECK_EXEC([at_ns1], [ping -q -c 10 -i 0.1 -w 2 -s 64 10.1.1.2 | FORMAT_PING], [0], [dnl
@@ -519,10 +521,12 @@ in_port(3),eth(),eth_type(0x0800),ipv4(frag=no), packets:20, bytes:11720, used:0
])
sleep 1
-AT_CHECK([cat p3_2.pcap | awk '{print $NF}' | uniq -c | awk '{$1=$1;print}'], [0], [dnl
+kill $(cat tcpdump3_2.pid)
+kill $(cat tcpdump4_2.pid)
+AT_CHECK([cat p3_2.pcap | awk 'NF{print $NF}' | uniq -c | awk '{$1=$1;print}'], [0], [dnl
10 1032
])
-AT_CHECK([cat p4_2.pcap | awk '{print $NF}' | uniq -c | awk '{$1=$1;print}'], [0], [dnl
+AT_CHECK([cat p4_2.pcap | awk 'NF{print $NF}' | uniq -c | awk '{$1=$1;print}'], [0], [dnl
10 72
])
diff --git a/tests/system-traffic.at b/tests/system-traffic.at
index f7f885036..2785994d5 100644
--- a/tests/system-traffic.at
+++ b/tests/system-traffic.at
@@ -878,7 +878,7 @@ ADD_OVS_TUNNEL([gre], [br0], [at_gre0], [172.31.1.1], [10.1.1.100/24])
IPTABLES_ACCEPT([br-underlay])
-ip netns exec at_ns0 tcpdump -n -i p0 dst host 172.31.1.1 -l > p0.pcap &
+NETNS_DAEMONIZE([at_ns0], [tcpdump -n -i p0 dst host 172.31.1.1 -l > p0.pcap 2>/dev/null], [tcpdump.pid])
sleep 1
dnl First, check the underlay.
@@ -926,7 +926,7 @@ ADD_OVS_TUNNEL([erspan], [br0], [at_erspan0], [172.31.1.1], [10.1.1.100/24], [op
IPTABLES_ACCEPT([br-underlay])
-ip netns exec at_ns0 tcpdump -n -x -i p0 dst host 172.31.1.1 -l > p0.pcap &
+NETNS_DAEMONIZE([at_ns0], [tcpdump -n -x -i p0 dst host 172.31.1.1 -l > p0.pcap 2>/dev/null], [tcpdump.pid])
sleep 1
dnl First, check the underlay
@@ -979,7 +979,7 @@ dnl around it.
iptables -I INPUT 1 -i br-underlay -j ACCEPT
on_exit 'iptables -D INPUT 1'
-ip netns exec at_ns0 tcpdump -n -x -i p0 dst host 172.31.1.1 -l > p0.pcap &
+NETNS_DAEMONIZE([at_ns0], [tcpdump -n -x -i p0 dst host 172.31.1.1 -l > p0.pcap 2>/dev/null], [tcpdump.pid])
sleep 1
dnl First, check the underlay.
@@ -1036,7 +1036,7 @@ dnl around it.
ip6tables -I INPUT 1 -i br-underlay -j ACCEPT
on_exit 'ip6tables -D INPUT 1'
-ip netns exec at_ns0 tcpdump -n -x -i p0 dst host fc00:100::1 -l > p0.pcap &
+NETNS_DAEMONIZE([at_ns0], [tcpdump -n -x -i p0 dst host fc00:100::1 -l > p0.pcap 2>/dev/null], [tcpdump.pid])
sleep 1
dnl First, check the underlay.
@@ -1092,7 +1092,7 @@ dnl around it.
ip6tables -I INPUT 1 -i br-underlay -j ACCEPT
on_exit 'ip6tables -D INPUT 1'
-ip netns exec at_ns0 tcpdump -n -x -i p0 dst host fc00:100::1 -l > p0.pcap &
+NETNS_DAEMONIZE([at_ns0], [tcpdump -n -x -i p0 dst host fc00:100::1 -l > p0.pcap 2>/dev/null], [tcpdump.pid])
sleep 1
dnl First, check the underlay.
@@ -1894,7 +1894,7 @@ dnl eth/ip/icmp --> OVS --> eth/mpls/eth/ip/icmp
AT_CHECK([ovs-ofctl -Oopenflow13 add-flow br0 "table=0,priority=100,dl_type=0x0800 actions=encap(mpls),set_mpls_label:2,encap(ethernet),set_field:00:00:00:00:00:02->dl_dst,set_field:00:00:00:00:00:01->dl_src,ovs-p1"])
rm -rf p1.pcap
-NS_CHECK_EXEC([at_ns1], [tcpdump -l -n -xx -U -i p1 > p1.pcap &])
+NETNS_DAEMONIZE([at_ns1], [tcpdump -l -n -xx -U -i p1 > p1.pcap], [tcpdump.pid])
sleep 1
dnl The hex dump is a icmp packet. pkt=eth/ip/icmp
@@ -1926,7 +1926,7 @@ dnl eth/ip/icmp --> OVS --> eth/mpls/eth/ip/icmp
AT_CHECK([ovs-ofctl -Oopenflow13 add-flow br0 "table=0,priority=100,dl_type=0x0800 actions=encap(mpls),set_mpls_label:2,encap(ethernet),set_field:00:00:00:00:00:02->dl_dst,set_field:00:00:00:00:00:01->dl_src,ovs-p1"])
rm -rf p1.pcap
-NS_CHECK_EXEC([at_ns1], [tcpdump -l -n -xx -U -i p1 > p1.pcap &])
+NETNS_DAEMONIZE([at_ns1], [tcpdump -l -n -xx -U -i p1 > p1.pcap], [tcpdump.pid])
sleep 1
dnl The hex dump is a icmp packet. pkt=eth/ip/icmp
@@ -1959,7 +1959,7 @@ dnl eth/ip/icmp --> OVS --> eth/mpls/eth/ip/icmp
AT_CHECK([ovs-ofctl -Oopenflow13 add-flow br0 "table=0,priority=100,dl_type=0x0800 actions=encap(mpls_mc),set_mpls_label:2,encap(ethernet),set_field:00:00:00:00:00:02->dl_dst,set_field:00:00:00:00:00:01->dl_src,ovs-p1"])
rm -rf p1.pcap
-NS_CHECK_EXEC([at_ns1], [tcpdump -l -n -xx -U -i p1 > p1.pcap &])
+NETNS_DAEMONIZE([at_ns1], [tcpdump -l -n -xx -U -i p1 > p1.pcap], [tcpdump.pid])
sleep 1
dnl The hex dump is a icmp packet. pkt=eth/ip/icmp
@@ -1991,7 +1991,7 @@ dnl eth/ip/icmp --> OVS --> eth/mpls/eth/ip/icmp
AT_CHECK([ovs-ofctl -Oopenflow13 add-flow br0 "table=0,priority=100,dl_type=0x0800 actions=encap(mpls_mc),set_mpls_label:2,encap(ethernet),set_field:00:00:00:00:00:02->dl_dst,set_field:00:00:00:00:00:01->dl_src,ovs-p1"])
rm -rf p1.pcap
-NS_CHECK_EXEC([at_ns1], [tcpdump -l -n -xx -U -i p1 > p1.pcap &])
+NETNS_DAEMONIZE([at_ns1], [tcpdump -l -n -xx -U -i p1 > p1.pcap], [tcpdump.pid])
sleep 1
dnl The hex dump is a icmp packet. pkt=eth/ip/icmp
@@ -2025,7 +2025,7 @@ dnl eth/mpls/eth/ip/icmp --> OVS --> eth/ip/icmp
AT_CHECK([ovs-ofctl -Oopenflow13 add-flow br0 "table=0,priority=100,dl_type=0x8847,mpls_label=2 actions=decap(),decap(packet_type(ns=0,type=0)),ovs-p1"])
rm -rf p1.pcap
-NS_CHECK_EXEC([at_ns1], [tcpdump -l -n -xx -U -i p1 > p1.pcap &])
+NETNS_DAEMONIZE([at_ns1], [tcpdump -l -n -xx -U -i p1 > p1.pcap], [tcpdump.pid])
sleep 1
dnl The hex dump is an mpls packet encapsulating ethernet packet. pkt=eth/mpls/eth/ip/icmp
@@ -2062,7 +2062,7 @@ dnl eth/mpls/eth/ip/icmp --> OVS --> eth/ip/icmp
AT_CHECK([ovs-ofctl -Oopenflow13 add-flow br0 "table=0,priority=100,dl_type=0x8847,mpls_label=2 actions=decap(),decap(packet_type(ns=0,type=0)),ovs-p1"])
rm -rf p1.pcap
-NS_CHECK_EXEC([at_ns1], [tcpdump -l -n -xx -U -i p1 > p1.pcap &])
+NETNS_DAEMONIZE([at_ns1], [tcpdump -l -n -xx -U -i p1 > p1.pcap], [tcpdump.pid])
sleep 1
dnl The hex dump is an mpls packet encapsulating ethernet packet. pkt=eth/mpls/eth/ip/icmp
@@ -4071,8 +4071,8 @@ NS_CHECK_EXEC([at_ns0], [ip route add 10.1.1.0/24 via 10.2.1.2])
NS_CHECK_EXEC([at_ns1], [ip route add 10.1.1.0/24 via 10.2.1.1])
dnl Solely for debugging when things go wrong
-NS_EXEC([at_ns0], [tcpdump -l -n -xx -U -i p0 -w p0.pcap >tcpdump.out 2>/dev/null &])
-NS_EXEC([at_ns1], [tcpdump -l -n -xx -U -i p1 -w p1.pcap >tcpdump.out 2>/dev/null &])
+NETNS_DAEMONIZE([at_ns0], [tcpdump -l -n -xx -U -i p0 -w p0.pcap >tcpdump.out 2>/dev/null], [tcpdump_0.pid])
+NETNS_DAEMONIZE([at_ns1], [tcpdump -l -n -xx -U -i p1 -w p1.pcap >tcpdump.out 2>/dev/null], [tcpdump_1.pid])
AT_DATA([flows.txt], [dnl
table=0,arp,actions=normal
@@ -5512,7 +5512,7 @@ table=10 priority=0 action=drop
AT_CHECK([ovs-ofctl --bundle add-flows br0 flows.txt])
rm p0.pcap
-tcpdump -U -i ovs-p0 -w p0.pcap &
+OVS_DAEMONIZE([tcpdump -U -i ovs-p0 -w p0.pcap], [tcpdump.pid])
sleep 1
dnl UDP packets from ns0->ns1 should solicit "destination unreachable" response.
@@ -6280,7 +6280,7 @@ OVS_WAIT_UNTIL([ip netns exec at_ns0 ping6 -c 1 fc00::2])
AT_CHECK([ovs-appctl dpctl/flush-conntrack])
rm p0.pcap
-tcpdump -U -i ovs-p0 -w p0.pcap &
+OVS_DAEMONIZE([tcpdump -U -i ovs-p0 -w p0.pcap], [tcpdump.pid])
sleep 1
dnl UDP packets from ns0->ns1 should solicit "destination unreachable" response.
@@ -7276,7 +7276,7 @@ dnl The flow will encap a nsh header to the TCP syn packet
dnl eth/ip/tcp --> OVS --> eth/nsh/eth/ip/tcp
AT_CHECK([ovs-ofctl -Oopenflow13 add-flow br0 "table=0,priority=100,in_port=ovs-p0,ip,actions=encap(nsh(md_type=1)),set_field:0x1234->nsh_spi,set_field:0x11223344->nsh_c1,encap(ethernet),set_field:f2:ff:00:00:00:02->dl_dst,set_field:f2:ff:00:00:00:01->dl_src,ovs-p1"])
-NS_CHECK_EXEC([at_ns1], [tcpdump -l -n -xx -U -i p1 > p1.pcap &])
+NETNS_DAEMONIZE([at_ns1], [tcpdump -l -n -xx -U -i p1 > p1.pcap], [tcpdump.pid])
sleep 1
dnl The hex dump is a TCP syn packet. pkt=eth/ip/tcp
@@ -7308,7 +7308,7 @@ dnl The flow will decap a nsh header which in turn carries a TCP syn packet
dnl eth/nsh/eth/ip/tcp --> OVS --> eth/ip/tcp
AT_CHECK([ovs-ofctl -Oopenflow13 add-flow br0 "table=0,priority=100,in_port=ovs-p0,dl_type=0x894f, actions=decap(),decap(), ovs-p1"])
-NS_CHECK_EXEC([at_ns1], [tcpdump -l -n -xx -U -i p1 > p1.pcap &])
+NETNS_DAEMONIZE([at_ns1], [tcpdump -l -n -xx -U -i p1 > p1.pcap], [tcpdump.pid])
sleep 1
dnl The hex dump is NSH packet with TCP syn payload. pkt=eth/nsh/eth/ip/tcp
@@ -7340,7 +7340,7 @@ dnl The flow will add another NSH header with nsh_spi=0x101, nsh_si=4,
dnl nsh_ttl=7 and change the md1 context
AT_CHECK([ovs-ofctl -Oopenflow13 add-flow br0 "table=0,priority=100,in_port=ovs-p0,dl_type=0x894f,nsh_spi=0x100,nsh_si=0x03,actions=decap(),decap(),encap(nsh(md_type=1)),set_field:0x07->nsh_ttl,set_field:0x0101->nsh_spi,set_field:0x04->nsh_si,set_field:0x100f0e0d->nsh_c1,set_field:0x0c0b0a09->nsh_c2,set_field:0x08070605->nsh_c3,set_field:0x04030201->nsh_c4,encap(ethernet),set_field:f2:ff:00:00:00:02->dl_dst,set_field:f2:ff:00:00:00:01->dl_src,ovs-p1"])
-NS_CHECK_EXEC([at_ns1], [tcpdump -l -n -xx -U -i p1 > p1.pcap &])
+NETNS_DAEMONIZE([at_ns1], [tcpdump -l -n -xx -U -i p1 > p1.pcap], [tcpdump.pid])
sleep 1
dnl The hex dump is NSH packet with TCP syn payload. pkt=eth/nsh/eth/ip/tcp
@@ -7376,8 +7376,8 @@ dnl packet to to at_ns2.
AT_CHECK([ovs-ofctl -Oopenflow13 add-flow br0 "table=0,priority=100,dl_type=0x894f,nsh_spi=0x100,nsh_si=0x02,actions=ovs-p1"])
AT_CHECK([ovs-ofctl -Oopenflow13 add-flow br0 "table=0,priority=100,dl_type=0x894f,nsh_spi=0x100,nsh_si=0x01,actions=ovs-p2"])
-NS_CHECK_EXEC([at_ns1], [tcpdump -l -n -xx -U -i p1 > p1.pcap &])
-NS_CHECK_EXEC([at_ns2], [tcpdump -l -n -xx -U -i p2 > p2.pcap &])
+NETNS_DAEMONIZE([at_ns1], [tcpdump -l -n -xx -U -i p1 > p1.pcap], [tcpdump.pid])
+NETNS_DAEMONIZE([at_ns2], [tcpdump -l -n -xx -U -i p2 > p2.pcap], [tcpdump2.pid])
sleep 1
dnl First send packet from at_ns0 --> OVS with SPI=0x100 and SI=2