From: Akihiko Odaki <akihiko.odaki@daynix.com>
Cc: dts@dpdk.org, Akihiko Odaki <akihiko.odaki@daynix.com>
Subject: [PATCH 7/7] tests/ip_pipeline: Use common tcpdump methods
Date: Fri, 14 Apr 2023 21:52:55 +0900 [thread overview]
Message-ID: <20230414125255.67812-8-akihiko.odaki@daynix.com> (raw)
In-Reply-To: <20230414125255.67812-1-akihiko.odaki@daynix.com>
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
framework/packet.py | 3 +
tests/TestSuite_ip_pipeline.py | 106 +++++++++------------------------
2 files changed, 32 insertions(+), 77 deletions(-)
diff --git a/framework/packet.py b/framework/packet.py
index 9603ec7b..a53cef34 100644
--- a/framework/packet.py
+++ b/framework/packet.py
@@ -1063,6 +1063,9 @@ def get_filter_cmd(filters=[]):
elif list(pktfilter["config"].keys())[0] == "dstport":
dport = pktfilter["config"]["dstport"]
filter_cmd = "dst port %s" % dport
+ elif list(pktfilter["config"].keys())[0] == "dsthost":
+ dport = pktfilter["config"]["dsthost"]
+ filter_cmd = "dst host %s" % dport
elif pktfilter["layer"] == "userdefined":
if list(pktfilter["config"].keys())[0] == "pcap-filter":
filter_cmd = pktfilter["config"]["pcap-filter"]
diff --git a/tests/TestSuite_ip_pipeline.py b/tests/TestSuite_ip_pipeline.py
index 043516dd..c28622cd 100644
--- a/tests/TestSuite_ip_pipeline.py
+++ b/tests/TestSuite_ip_pipeline.py
@@ -2,7 +2,6 @@
# Copyright(c) 2010-2018 Intel Corporation
#
-import re
import time
from time import sleep
@@ -17,48 +16,6 @@ from framework.test_case import TestCase, skip_unsupported_host_driver
class TestIPPipeline(TestCase):
- def get_flow_direction_param_of_tcpdump(self):
- """
- get flow dirction param depend on tcpdump version
- """
- param = ""
- direct_param = r"(\s+)\[ (\S+) in\|out\|inout \]"
- out = self.tester.send_expect("tcpdump -h", "# ")
- for line in out.split("\n"):
- m = re.match(direct_param, line)
- if m:
- opt = re.search("-Q", m.group(2))
- if opt:
- param = "-Q" + " in"
- else:
- opt = re.search("-P", m.group(2))
- if opt:
- param = "-P" + " in"
- if len(param) == 0:
- self.logger.info("tcpdump not support direction choice!!!")
- return param
-
- def tcpdump_start_sniff(self, interface, filters=""):
- """
- Starts tcpdump in the background to sniff packets that received by interface.
- """
- command = "rm -f /tmp/tcpdump_{0}.pcap".format(interface)
- self.tester.send_expect(command, "#")
- command = "tcpdump -n -e {0} -w /tmp/tcpdump_{1}.pcap -i {1} {2} 2>/tmp/tcpdump_{1}.out &".format(
- self.param_flow_dir, interface, filters
- )
- self.tester.send_expect(command, "# ")
-
- def tcpdump_stop_sniff(self):
- """
- Stops the tcpdump process running in the background.
- """
- self.tester.send_expect("killall tcpdump", "# ")
- # For the [pid]+ Done tcpdump... message after killing the process
- sleep(1)
- self.tester.send_expect('echo "Cleaning buffer"', "# ")
- sleep(1)
-
def write_pcap_file(self, pcap_file, pkts):
try:
wrpcap(pcap_file, pkts)
@@ -74,7 +31,7 @@ class TestIPPipeline(TestCase):
return pcap_pkts
- def send_and_sniff_pkts(self, from_port, to_port, pcap_file, filters="", count=1):
+ def send_and_sniff_pkts(self, from_port, to_port, pcap_file, filters=[], count=1):
"""
Sent pkts that read from the pcap_file.
Return the sniff pkts.
@@ -85,7 +42,7 @@ class TestIPPipeline(TestCase):
tx_interface = self.tester.get_interface(tx_port)
rx_interface = self.tester.get_interface(rx_port)
- self.tcpdump_start_sniff(rx_interface, filters)
+ inst = self.tester.tcpdump_sniff_packets(rx_interface, filters=filters)
# check that the link status of the port sending the packet is up
self.tester.is_interface_up(tx_interface)
@@ -100,9 +57,7 @@ class TestIPPipeline(TestCase):
)
self.tester.scapy_execute()
- self.tcpdump_stop_sniff()
-
- return self.read_pcap_file("/tmp/tcpdump_%s.pcap" % rx_interface)
+ return self.tester.load_tcpdump_sniff_packets(inst).pktgen.pkts
def setup_env(self, port_nums, driver):
"""
@@ -217,7 +172,6 @@ class TestIPPipeline(TestCase):
self.verify("Error" not in out, "Compilation error")
self.app_ip_pipline_path = self.dut.apps_name["ip_pipeline"]
self.app_testpmd_path = self.dut.apps_name["test-pmd"]
- self.param_flow_dir = self.get_flow_direction_param_of_tcpdump()
def set_up(self):
"""
@@ -261,7 +215,7 @@ class TestIPPipeline(TestCase):
pcap_file = "/tmp/route_0.pcap"
pkt = [Ether(dst=self.dut_p0_mac) / IP(dst="100.0.0.1") / Raw(load="X" * 26)]
self.write_pcap_file(pcap_file, pkt)
- filters = "dst host 100.0.0.1"
+ filters = [{"layer": "network", "config": {"dsthost": "100.0.0.1"}}]
sniff_pkts = self.send_and_sniff_pkts(0, 0, pcap_file, filters)
dst_mac_list = []
for packet in sniff_pkts:
@@ -272,7 +226,7 @@ class TestIPPipeline(TestCase):
pcap_file = "/tmp/route_1.pcap"
pkt = [Ether(dst=self.dut_p0_mac) / IP(dst="100.64.0.1") / Raw(load="X" * 26)]
self.write_pcap_file(pcap_file, pkt)
- filters = "dst host 100.64.0.1"
+ filters = [{"layer": "network", "config": {"dsthost": "100.64.0.1"}}]
sniff_pkts = self.send_and_sniff_pkts(0, 1, pcap_file, filters)
dst_mac_list = []
for packet in sniff_pkts:
@@ -283,7 +237,7 @@ class TestIPPipeline(TestCase):
pcap_file = "/tmp/route_2.pcap"
pkt = [Ether(dst=self.dut_p0_mac) / IP(dst="100.128.0.1") / Raw(load="X" * 26)]
self.write_pcap_file(pcap_file, pkt)
- filters = "dst host 100.128.0.1"
+ filters = [{"layer": "network", "config": {"dsthost": "100.128.0.1"}}]
sniff_pkts = self.send_and_sniff_pkts(0, 2, pcap_file, filters)
dst_mac_list = []
for packet in sniff_pkts:
@@ -294,7 +248,7 @@ class TestIPPipeline(TestCase):
pcap_file = "/tmp/route_3.pcap"
pkt = [Ether(dst=self.dut_p0_mac) / IP(dst="100.192.0.1") / Raw(load="X" * 26)]
self.write_pcap_file(pcap_file, pkt)
- filters = "dst host 100.192.0.1"
+ filters = [{"layer": "network", "config": {"dsthost": "100.192.0.1"}}]
sniff_pkts = self.send_and_sniff_pkts(0, 3, pcap_file, filters)
dst_mac_list = []
for packet in sniff_pkts:
@@ -346,7 +300,7 @@ class TestIPPipeline(TestCase):
/ Raw(load="X" * 6)
]
self.write_pcap_file(pcap_file, pkt)
- filters = "dst host 100.0.0.1"
+ filters = [{"layer": "network", "config": {"dsthost": "100.0.0.1"}}]
sniff_pkts = self.send_and_sniff_pkts(0, 0, pcap_file, filters)
dst_ip_list = []
for packet in sniff_pkts:
@@ -362,7 +316,7 @@ class TestIPPipeline(TestCase):
/ Raw(load="X" * 6)
]
self.write_pcap_file(pcap_file, pkt)
- filters = "dst host 100.64.0.1"
+ filters = [{"layer": "network", "config": {"dsthost": "100.64.0.1"}}]
sniff_pkts = self.send_and_sniff_pkts(0, 1, pcap_file, filters)
dst_ip_list = []
for packet in sniff_pkts:
@@ -378,7 +332,7 @@ class TestIPPipeline(TestCase):
/ Raw(load="X" * 6)
]
self.write_pcap_file(pcap_file, pkt)
- filters = "dst host 100.128.0.1"
+ filters = [{"layer": "network", "config": {"dsthost": "100.128.0.1"}}]
sniff_pkts = self.send_and_sniff_pkts(0, 2, pcap_file, filters)
dst_ip_list = []
for packet in sniff_pkts:
@@ -394,7 +348,7 @@ class TestIPPipeline(TestCase):
/ Raw(load="X" * 6)
]
self.write_pcap_file(pcap_file, pkt)
- filters = "dst host 100.192.0.1"
+ filters = [{"layer": "network", "config": {"dsthost": "100.192.0.1"}}]
sniff_pkts = self.send_and_sniff_pkts(0, 3, pcap_file, filters)
dst_ip_list = []
for packet in sniff_pkts:
@@ -446,7 +400,7 @@ class TestIPPipeline(TestCase):
/ Raw(load="X" * 6)
]
self.write_pcap_file(pcap_file, pkt)
- filters = "tcp"
+ filters = [{"layer": "userdefined", "config": {"pcap-filter": "tcp"}}]
sniff_pkts = self.send_and_sniff_pkts(0, 0, pcap_file, filters)
dst_ip_list = []
for packet in sniff_pkts:
@@ -462,7 +416,7 @@ class TestIPPipeline(TestCase):
/ Raw(load="X" * 6)
]
self.write_pcap_file(pcap_file, pkt)
- filters = "tcp"
+ filters = [{"layer": "userdefined", "config": {"pcap-filter": "tcp"}}]
sniff_pkts = self.send_and_sniff_pkts(0, 1, pcap_file, filters)
dst_ip_list = []
for packet in sniff_pkts:
@@ -478,7 +432,7 @@ class TestIPPipeline(TestCase):
/ Raw(load="X" * 6)
]
self.write_pcap_file(pcap_file, pkt)
- filters = "tcp"
+ filters = [{"layer": "userdefined", "config": {"pcap-filter": "tcp"}}]
sniff_pkts = self.send_and_sniff_pkts(0, 2, pcap_file, filters)
dst_ip_list = []
for packet in sniff_pkts:
@@ -494,7 +448,7 @@ class TestIPPipeline(TestCase):
/ Raw(load="X" * 6)
]
self.write_pcap_file(pcap_file, pkt)
- filters = "tcp"
+ filters = [{"layer": "userdefined", "config": {"pcap-filter": "tcp"}}]
sniff_pkts = self.send_and_sniff_pkts(0, 3, pcap_file, filters)
dst_ip_list = []
for packet in sniff_pkts:
@@ -546,7 +500,7 @@ class TestIPPipeline(TestCase):
/ Raw(load="X" * 6)
]
self.write_pcap_file(pcap_file, pkt)
- filters = "tcp"
+ filters = [{"layer": "userdefined", "config": {"pcap-filter": "tcp"}}]
sniff_pkts = self.send_and_sniff_pkts(0, 1, pcap_file, filters)
dst_ip_list = []
for packet in sniff_pkts:
@@ -562,7 +516,7 @@ class TestIPPipeline(TestCase):
/ Raw(load="X" * 6)
]
self.write_pcap_file(pcap_file, pkt)
- filters = "tcp"
+ filters = [{"layer": "userdefined", "config": {"pcap-filter": "tcp"}}]
sniff_pkts = self.send_and_sniff_pkts(1, 0, pcap_file, filters)
dst_ip_list = []
for packet in sniff_pkts:
@@ -578,7 +532,7 @@ class TestIPPipeline(TestCase):
/ Raw(load="X" * 6)
]
self.write_pcap_file(pcap_file, pkt)
- filters = "tcp"
+ filters = [{"layer": "userdefined", "config": {"pcap-filter": "tcp"}}]
sniff_pkts = self.send_and_sniff_pkts(2, 3, pcap_file, filters)
dst_ip_list = []
for packet in sniff_pkts:
@@ -594,7 +548,7 @@ class TestIPPipeline(TestCase):
/ Raw(load="X" * 6)
]
self.write_pcap_file(pcap_file, pkt)
- filters = "tcp"
+ filters = [{"layer": "userdefined", "config": {"pcap-filter": "tcp"}}]
sniff_pkts = self.send_and_sniff_pkts(3, 2, pcap_file, filters)
dst_ip_list = []
for packet in sniff_pkts:
@@ -680,7 +634,7 @@ class TestIPPipeline(TestCase):
/ Raw(load="X" * 6)
]
self.write_pcap_file(pcap_file, pkt)
- filters = "tcp"
+ filters = [{"layer": "userdefined", "config": {"pcap-filter": "tcp"}}]
sniff_pkts = self.send_and_sniff_pkts(0, 1, pcap_file, filters)
dst_ip_list = []
for packet in sniff_pkts:
@@ -696,7 +650,7 @@ class TestIPPipeline(TestCase):
/ Raw(load="X" * 6)
]
self.write_pcap_file(pcap_file, pkt)
- filters = "tcp"
+ filters = [{"layer": "userdefined", "config": {"pcap-filter": "tcp"}}]
sniff_pkts = self.send_and_sniff_pkts(1, 0, pcap_file, filters)
dst_ip_list = []
for packet in sniff_pkts:
@@ -712,7 +666,7 @@ class TestIPPipeline(TestCase):
/ Raw(load="X" * 6)
]
self.write_pcap_file(pcap_file, pkt)
- filters = "tcp"
+ filters = [{"layer": "userdefined", "config": {"pcap-filter": "tcp"}}]
sniff_pkts = self.send_and_sniff_pkts(2, 3, pcap_file, filters)
dst_ip_list = []
for packet in sniff_pkts:
@@ -728,7 +682,7 @@ class TestIPPipeline(TestCase):
/ Raw(load="X" * 6)
]
self.write_pcap_file(pcap_file, pkt)
- filters = "tcp"
+ filters = [{"layer": "userdefined", "config": {"pcap-filter": "tcp"}}]
sniff_pkts = self.send_and_sniff_pkts(3, 2, pcap_file, filters)
dst_ip_list = []
for packet in sniff_pkts:
@@ -792,7 +746,7 @@ class TestIPPipeline(TestCase):
/ Raw(load="X" * 6)
]
self.write_pcap_file(pcap_file, pkt)
- filters = "tcp"
+ filters = [{"layer": "userdefined", "config": {"pcap-filter": "tcp"}}]
sniff_pkts = self.send_and_sniff_pkts(0, 1, pcap_file, filters)
dst_ip_list = []
for packet in sniff_pkts:
@@ -808,7 +762,7 @@ class TestIPPipeline(TestCase):
/ Raw(load="X" * 6)
]
self.write_pcap_file(pcap_file, pkt)
- filters = "tcp"
+ filters = [{"layer": "userdefined", "config": {"pcap-filter": "tcp"}}]
sniff_pkts = self.send_and_sniff_pkts(1, 0, pcap_file, filters)
dst_ip_list = []
for packet in sniff_pkts:
@@ -824,7 +778,7 @@ class TestIPPipeline(TestCase):
/ Raw(load="X" * 6)
]
self.write_pcap_file(pcap_file, pkt)
- filters = "tcp"
+ filters = [{"layer": "userdefined", "config": {"pcap-filter": "tcp"}}]
sniff_pkts = self.send_and_sniff_pkts(2, 3, pcap_file, filters)
dst_ip_list = []
for packet in sniff_pkts:
@@ -840,7 +794,7 @@ class TestIPPipeline(TestCase):
/ Raw(load="X" * 6)
]
self.write_pcap_file(pcap_file, pkt)
- filters = "tcp"
+ filters = [{"layer": "userdefined", "config": {"pcap-filter": "tcp"}}]
sniff_pkts = self.send_and_sniff_pkts(3, 2, pcap_file, filters)
dst_ip_list = []
for packet in sniff_pkts:
@@ -893,7 +847,7 @@ class TestIPPipeline(TestCase):
/ Raw(load="X" * 6)
]
self.write_pcap_file(pcap_file, pkt)
- filters = "tcp"
+ filters = [{"layer": "userdefined", "config": {"pcap-filter": "tcp"}}]
sniff_pkts = self.send_and_sniff_pkts(0, 1, pcap_file, filters)
dst_ip_list = []
for packet in sniff_pkts:
@@ -909,7 +863,7 @@ class TestIPPipeline(TestCase):
/ Raw(load="X" * 6)
]
self.write_pcap_file(pcap_file, pkt)
- filters = "tcp"
+ filters = [{"layer": "userdefined", "config": {"pcap-filter": "tcp"}}]
sniff_pkts = self.send_and_sniff_pkts(1, 0, pcap_file, filters)
dst_ip_list = []
for packet in sniff_pkts:
@@ -1041,8 +995,6 @@ class TestIPPipeline(TestCase):
"""
Run after each test case.
"""
- # kill all tcpdump
- self.tcpdump_stop_sniff()
# close app
self.dut.send_expect("^C", "# ")
self.dut.kill_all()
--
2.40.0
next prev parent reply other threads:[~2023-04-14 12:53 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-14 12:52 [PATCH 0/7] Fix for Fedora 37 Akihiko Odaki
2023-04-14 12:52 ` [PATCH 1/7] Replace Pcapy with Pcapyplus Akihiko Odaki
2023-04-14 12:52 ` [PATCH 2/7] Update numpy from 1.18.5 to 1.24.2 Akihiko Odaki
2023-04-14 12:52 ` [PATCH 3/7] framework/ssh_pexpect: Remove duplicate regex flags Akihiko Odaki
2023-04-14 12:52 ` [PATCH 4/7] framework: Remove unused variable Akihiko Odaki
2023-04-14 12:52 ` [PATCH 5/7] nics/system_info: Accept memory with unknown speed Akihiko Odaki
2023-04-14 12:52 ` [PATCH 6/7] framework/packet: Fix tcpdump help parse Akihiko Odaki
2023-04-14 12:52 ` Akihiko Odaki [this message]
2023-05-25 2:52 ` [PATCH 7/7] tests/ip_pipeline: Use common tcpdump methods lijuan.tu
2023-05-06 7:27 ` [PATCH 0/7] Fix for Fedora 37 Akihiko Odaki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230414125255.67812-8-akihiko.odaki@daynix.com \
--to=akihiko.odaki@daynix.com \
--cc=dts@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).