From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id BB5DD42941; Fri, 14 Apr 2023 14:53:20 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B5FDB42D0D; Fri, 14 Apr 2023 14:53:20 +0200 (CEST) Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) by mails.dpdk.org (Postfix) with ESMTP id 0B1FC400D5 for ; Fri, 14 Apr 2023 14:53:20 +0200 (CEST) Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-2465836870fso1161414a91.2 for ; Fri, 14 Apr 2023 05:53:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1681476799; x=1684068799; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lwpY87yLmwKundUPrfY8XU5xxvrpDaLGTe1UFFQfLHs=; b=WMwRwhaOv4SO3cUGIEjPU69t4Y8nplSEnuxWdexNPDSTXiIeTUcIk3G6v35VP4yuGO xBx5XFqD/bogbYJECi59UGrwubryc7BBoOfveU5yAoJzADRkOEGTkbgEylidS5BBitTq vxG5e18h89FEr3W4QQQ07RbJE6zcdQY64kQx2P0aV5AgwGvg8/FZFtoKRnB68G5SqrAm 03r3JmdJX7BSdT5cze9+ZvPf5I5Ge58nXA4mcnjGRgduhq5hhWbfE/bQlBcs33sgwK7K 6uaGDHfbNVhXorj08XzooeDr9EVgVhARh47syqoE1XZ/peA+gnxCMAw4bSLglHZI3lfK CqKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681476799; x=1684068799; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lwpY87yLmwKundUPrfY8XU5xxvrpDaLGTe1UFFQfLHs=; b=gsvk79xRmqRjomC3TBa3+JrYgqxq7gsGvwofec1ytUITOG3tPRjZbMsv75IzE0uYqP ACiWRzGQdAUngUYwAijnYGITCPFkxKJDM7jjkHIwzeJo/txTVNBK2oorvcPiHzTYiDa1 tXToMagrz6fQsnKmRrYbR3vi0xitT1/h7q3ZOkhsIJi51pxdovcyP9qdaEd1297Vk2RV 6Iskb26NXfKHAtynpgwrXSLVIzAYJc7Q00Q4C8tfAj/J2B+iXWMC8t2w79rRP57ht0TC KaukZJUyZP6KNaNLhuVMxZvB+UNmpjszbFq7B4hEx9eQhR08Il82YmLopoAbhXgp64bh Eg4A== X-Gm-Message-State: AAQBX9fAZsSaeoWTHmoizq40pPgJbOdvinXmP4eTCcsXx2hlv7dvRZMT YYgrwzj3bk9s5Syl7O1Y8qoBSnvyQEQI3dR6HiI= X-Google-Smtp-Source: AKy350b664z0fdGZRKo5HWCCMLcaxxaYBAX3v/+ro99xybpEvQl0CETeY4c7IEA3H8AsukPbMC8rSQ== X-Received: by 2002:a05:6a00:1147:b0:635:c8e4:ed0f with SMTP id b7-20020a056a00114700b00635c8e4ed0fmr7478137pfm.11.1681476799007; Fri, 14 Apr 2023 05:53:19 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:4457:c267:5e09:481b]) by smtp.gmail.com with ESMTPSA id u21-20020a62ed15000000b00627df85cd72sm2961787pfh.199.2023.04.14.05.53.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Apr 2023 05:53:18 -0700 (PDT) From: Akihiko Odaki To: Cc: dts@dpdk.org, Akihiko Odaki Subject: [PATCH 7/7] tests/ip_pipeline: Use common tcpdump methods Date: Fri, 14 Apr 2023 21:52:55 +0900 Message-Id: <20230414125255.67812-8-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230414125255.67812-1-akihiko.odaki@daynix.com> References: <20230414125255.67812-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dts@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: test suite reviews and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dts-bounces@dpdk.org Signed-off-by: Akihiko Odaki --- 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