From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id E43A7A0613 for ; Tue, 24 Sep 2019 08:57:40 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B84772BF1; Tue, 24 Sep 2019 08:57:40 +0200 (CEST) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by dpdk.org (Postfix) with ESMTP id 6EECC2B93 for ; Tue, 24 Sep 2019 08:57:39 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Sep 2019 23:57:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,543,1559545200"; d="scan'208";a="213587782" Received: from dpdk-lihong-ub1604.sh.intel.com ([10.67.119.134]) by fmsmga004.fm.intel.com with ESMTP; 23 Sep 2019 23:57:36 -0700 From: lihong To: dts@dpdk.org Cc: lihong Date: Tue, 24 Sep 2019 07:32:57 +0800 Message-Id: <1569281577-24766-1-git-send-email-lihongx.ma@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [dts] [PATCH V2] tests/vf_port_start_stop: use scapy instead of pktgen send pkts X-BeenThere: dts@dpdk.org X-Mailman-Version: 2.1.15 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 Sender: "dts" Signed-off-by: lihong --- tests/TestSuite_vf_port_start_stop.py | 99 +++++++++-------------------------- 1 file changed, 25 insertions(+), 74 deletions(-) diff --git a/tests/TestSuite_vf_port_start_stop.py b/tests/TestSuite_vf_port_start_stop.py index 2ff2d1c..7be5116 100644 --- a/tests/TestSuite_vf_port_start_stop.py +++ b/tests/TestSuite_vf_port_start_stop.py @@ -9,7 +9,6 @@ from pmd_output import PmdOutput from utils import RED, GREEN from net_device import NetDevice from crb import Crb -from scapy.all import * VM_CORES_MASK = 'all' class TestVfPortStartStop(TestCase): @@ -22,6 +21,8 @@ class TestVfPortStartStop(TestCase): self.verify(len(self.dut_ports) >= 1, "Insufficient ports") self.vm0 = None self.filename = "/tmp/vf.pcap" + self.tester_tx_port = self.tester.get_local_port(self.dut_ports[0]) + self.tester_tintf = self.tester.get_interface(self.tester_tx_port) # set vf assign method and vf driver self.vf_driver = self.get_suite_cfg()['vf_driver'] @@ -37,86 +38,39 @@ class TestVfPortStartStop(TestCase): def set_up(self): self.setup_1pf_2vf_1vm_env_flag = 0 - - def pktgen_prerequisites(self): - """ - igb_uio.ko should be put in ~ before you using pktgen - """ - out = self.tester.send_expect("ls", "#") - self.verify("igb_uio.ko" in out, "No file igb_uio.ko, please add it in ~") - self.tester.send_expect("modprobe uio", "#", 70) - out = self.tester.send_expect("lsmod | grep igb_uio", "#") - if "igb_uio" in out: - self.tester.send_expect("rmmod -f igb_uio", "#", 70) - self.tester.send_expect("insmod ~/igb_uio.ko", "#", 60) - out = self.tester.send_expect("lsmod | grep igb_uio", "#") - assert ("igb_uio" in out), "Failed to insmod igb_uio" - - total_huge_pages = self.tester.get_total_huge_pages() - if total_huge_pages == 0: - self.tester.mount_huge_pages() - self.tester.set_huge_pages(2048) - - def pktgen_kill(self): - """ - Kill all pktgen on tester. - """ - pids = [] - pid_reg = r'p(\d+)' - out = self.tester.alt_session.send_expect("lsof -Fp /var/run/.pg_config", "#", 20) - if len(out): - lines = out.split('\r\n') - for line in lines: - m = re.match(pid_reg, line) - if m: - pids.append(m.group(1)) - for pid in pids: - self.tester.alt_session.send_expect('kill -9 %s' % pid, '# ', 20) + self.send_pks_session = None def send_and_verify(self, dst_mac, testpmd): """ - Generates packets by pktgen + Generates packets and verify """ self.testpmd_reset_status(testpmd) - self.pktgen_prerequisites() - # bind ports - self.tester_tx_port = self.tester.get_local_port(self.dut_ports[0]) - self.tester_tx_pci = self.tester.ports_info[self.tester_tx_port]['pci'] - port = self.tester.ports_info[self.tester_tx_port]['port'] - self.tester_port_driver = port.get_nic_driver() - self.tester.send_expect("./dpdk-devbind.py --force --bind=igb_uio %s" % self.tester_tx_pci, "#") - - src_mac = self.tester.get_mac(self.tester_tx_port) + src_mac = self.tester.get_mac(self.tester_tx_port) if src_mac == 'N/A': src_mac = "02:00:00:00:01" - - self.create_pcap_file(self.filename, dst_mac, src_mac) - - self.tester.send_expect("./pktgen -c 0x1f -n 2 --proc-type auto --socket-mem 128,128 --file-prefix pg -- -P -T -m '1.0' -s 0:%s" % self.filename, "Pktgen >", 100) - time.sleep(1) - self.tester.send_expect("start all", "Pktgen>") + self.send_pkts(self.filename, dst_mac, src_mac) time.sleep(1) self.check_port_start_stop(testpmd) - # quit pktgen - self.tester.send_expect("stop all", "Pktgen>") - self.tester.send_expect("quit", "# ") + self.tester.send_expect('killall -s INT scapy', '# ') + self.tester.destroy_session(self.send_pks_session) + self.send_pks_session = None - def create_pcap_file(self, filename, dst_mac, src_mac): + def send_pkts(self, filename, dst_mac, src_mac): """ Generates a valid PCAP file with the given configuration. """ - def_pkts = {'IP/UDP': Ether(dst="%s" % dst_mac, src="%s" % src_mac)/IP(src="127.0.0.2")/UDP()/("X"*46), - 'IP/TCP': Ether(dst="%s" % dst_mac, src="%s" % src_mac)/IP(src="127.0.0.2")/TCP()/("X"*46), - 'IP/SCTP': Ether(dst="%s" % dst_mac, src="%s" % src_mac)/IP(src="127.0.0.2")/SCTP()/("X"*48), - 'IPv6/UDP': Ether(dst="%s" % dst_mac, src="%s" % src_mac)/IPv6(src="::2")/UDP()/("X"*46), - 'IPv6/TCP': Ether(dst="%s" % dst_mac, src="%s" % src_mac)/IPv6(src="::2")/TCP()/("X"*46),} - - pkts = [] - for key in def_pkts.keys(): - pkts.append(def_pkts[key]) - - wrpcap(filename, pkts) + sendp_fmt = "sendp(pk, iface='%s', loop=1)" % (self.tester_tintf) + self.send_pks_session = self.tester.create_session("scapy1") + self.send_pks_session.send_expect("scapy", ">>>") + self.send_pks_session.send_expect("from scapy.layers.sctp import SCTP, SCTPChunkData", ">>>") + self.send_pks_session.send_expect('pk1=[Ether(dst="%s", src="%s")/IP(src="127.0.0.2")/UDP()/("X"*46)]'%(dst_mac, src_mac), '>>>') + self.send_pks_session.send_expect('pk2=[Ether(dst="%s", src="%s")/IP(src="127.0.0.2")/TCP()/("X"*46)]'%(dst_mac, src_mac), '>>>') + self.send_pks_session.send_expect('pk3=[Ether(dst="%s", src="%s")/IP(src="127.0.0.2")/SCTP()/("X"*48)]'%(dst_mac, src_mac), '>>>') + self.send_pks_session.send_expect('pk4=[Ether(dst="%s", src="%s")/IPv6(src="::2")/UDP()/("X"*46)]'%(dst_mac, src_mac), '>>>') + self.send_pks_session.send_expect('pk5=[Ether(dst="%s", src="%s")/IPv6(src="::2")/TCP()/("X"*46)]'%(dst_mac, src_mac), '>>>') + self.send_pks_session.send_expect('pk = pk1+pk2+pk3+pk4+pk5', '>>>') + self.send_pks_session.send_command(sendp_fmt) def testpmd_reset_status(self, testpmd): """ @@ -242,13 +196,10 @@ class TestVfPortStartStop(TestCase): def tear_down_all(self): - self.pktgen_kill() - if getattr(self, 'tester_port_driver', None) and \ - getattr(self, 'tester_tx_pci', None): - self.tester.send_expect("./dpdk-devbind.py --bind=%s %s" \ - %(self.tester_port_driver, self.tester_tx_pci), "#") - tx_interface = self.tester.get_interface(self.tester_tx_port) - self.tester.send_expect("ifconfig %s up" % tx_interface, "#") + if self.send_pks_session: + self.tester.send_expect('killall -s INT scapy', '# ') + self.tester.destroy_session(self.send_pks_session) + self.send_pks_session = None if getattr(self, 'vm0', None): self.vm0.stop() -- 2.7.4