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 B8B00A04F3; Fri, 3 Jan 2020 09:44:54 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A1DC71C1C9; Fri, 3 Jan 2020 09:44:54 +0100 (CET) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id EB8081BEDE for ; Fri, 3 Jan 2020 09:44:52 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Jan 2020 00:44:52 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,390,1571727600"; d="scan'208";a="270535697" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by FMSMGA003.fm.intel.com with ESMTP; 03 Jan 2020 00:44:52 -0800 Received: from fmsmsx101.amr.corp.intel.com (10.18.124.199) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 3 Jan 2020 00:44:51 -0800 Received: from shsmsx105.ccr.corp.intel.com (10.239.4.158) by fmsmsx101.amr.corp.intel.com (10.18.124.199) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 3 Jan 2020 00:44:51 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.202]) by SHSMSX105.ccr.corp.intel.com ([169.254.11.28]) with mapi id 14.03.0439.000; Fri, 3 Jan 2020 16:44:49 +0800 From: "Zhao, XinfengX" To: "dts@dpdk.org" , "Wang, Yinan" Thread-Topic: [dts][PATCH V1] tests: add new suite for af_xdp_2 test Thread-Index: AQHVwhH4eJSed0Hn50OU6CnznXpxKqfYn9TA Date: Fri, 3 Jan 2020 08:44:48 +0000 Message-ID: <44051B25D8C8784BB77FFB604D6A70CA120B78E3@shsmsx102.ccr.corp.intel.com> References: <1578009713-146934-1-git-send-email-xinfengx.zhao@intel.com> In-Reply-To: <1578009713-146934-1-git-send-email-xinfengx.zhao@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dts] [PATCH V1] tests: add new suite for af_xdp_2 test 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" Tested-by: Zhao, Xinfeng -----Original Message----- From: Zhao, XinfengX=20 Sent: Friday, January 3, 2020 8:02 AM To: dts@dpdk.org Cc: Zhao, XinfengX Subject: [dts][PATCH V1] tests: add new suite for af_xdp_2 test Signed-off-by: Xinfeng Zhao --- tests/TestSuite_af_xdp_2.py | 437 ++++++++++++++++++++++++++++++++++++ 1 file changed, 437 insertions(+) create mode 100644 tests/TestSuite_af_xdp_2.py diff --git a/tests/TestSuite_af_xdp_2.py b/tests/TestSuite_af_xdp_2.py new = file mode 100644 index 0000000..4397597 --- /dev/null +++ b/tests/TestSuite_af_xdp_2.py @@ -0,0 +1,437 @@ +# BSD LICENSE +# +# Copyright(c) 2019-2020 Intel Corporation. All rights reserved. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without #=20 +modification, are permitted provided that the following conditions #=20 +are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Intel Corporation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS #=20 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT #=20 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR #=20 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT #=20 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, #=20 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT #=20 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, #=20 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY #=20 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT #=20 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE #=20 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import os +import re +import time +from settings import HEADER_SIZE +from test_case import TestCase +from packet import Packet +from pktgen import PacketGeneratorHelper + + +class TestAfXdp(TestCase): + + def set_up_all(self): + """ + Run at the start of each test suite. + """ + #self.verify(self.nic in ("fortville_spirit"), "the port can not r= un this suite") + self.tester.extend_external_packet_generator(TestAfXdp, self) + self.frame_sizes =3D [64, 128, 256, 512, 1024, 1518] + self.dut_ports =3D self.dut.get_ports() + self.verify(len(self.dut_ports) >=3D 2, "Insufficient ports for=20 + testing") + + self.ports_socket =3D self.dut.get_numa_id(self.dut_ports[0]) + + self.header_size =3D HEADER_SIZE['eth'] + HEADER_SIZE['ip'] +=20 + HEADER_SIZE['udp'] + + self.logger.info("you can config packet_size in file %s.cfg," % se= lf.suite_name + \ + "in region 'suite' like packet_sizes=3D[64, 128, 256]"= ) + # get the frame_sizes from cfg file + if 'packet_sizes' in self.get_suite_cfg(): + self.frame_sizes =3D self.get_suite_cfg()['packet_sizes'] + + self.out_path =3D '/tmp' + out =3D self.tester.send_expect('ls -d %s' % self.out_path, '# ') + if 'No such file or directory' in out: + self.tester.send_expect('mkdir -p %s' % self.out_path, '# ') + self.base_dir =3D self.dut.base_dir.replace('~', '/root') + self.pktgen_helper =3D PacketGeneratorHelper() + + self.prepare_dpdk() + self.dut.restore_interfaces() + self.irqs_set =3D self.dut.new_session(suite=3D"irqs-set") + + def set_up(self): + pass + + def prepare_dpdk(self): + self.dut.send_expect( + "sed -i 's/CONFIG_RTE_LIBRTE_PMD_AF_XDP=3Dn$/CONFIG_RTE_LIBRTE= _PMD_AF_XDP=3Dy/' config/common_base", "# ") + self.dut.build_install_dpdk(self.dut.target) + + def set_port_queue(self, intf): + self.dut.send_expect("ethtool -L %s combined %d" % (intf,=20 + self.nb_cores/self.port_num), "# ") + + def config_stream(self, rx_port, frame_size): + payload =3D frame_size - self.header_size + tgen_input =3D [] + + dst_mac =3D self.dut.get_mac_address(self.dut_ports[rx_port]) + flow =3D 'Ether(dst=3D"%s")/IP(dst=3D"192.168.%d.1", proto=3D255)/= UDP()/("X"*%d)' % (dst_mac, rx_port+1, payload) + pkt =3D Packet(pkt_str=3Dflow) + pcap =3D os.path.join(self.out_path, "af_xdp_%d_%d_%d.pcap" % + (self.port_num, rx_port, frame_size)) + pkt.save_pcapfile(None, pcap) + tgen_input.append((rx_port, rx_port, pcap)) + + return tgen_input + + def config_rule_stream(self, rule_index, frame_size): + payload =3D frame_size - self.header_size + tgen_input =3D [] + + rule =3D self.rule[rule_index] + flow =3D 'Ether()/IP()/UDP(sport=3D%d, dport=3D%d)/("X"*%d)' % (ru= le[-2], rule[-1], payload) + pkt =3D Packet(pkt_str=3Dflow) + pcap =3D os.path.join(self.out_path, "af_xdp_%d_%d.pcap" % + (rule[-2], frame_size)) + pkt.save_pcapfile(None, pcap) + tgen_input.append((rule[0], rule[0], pcap)) + + return tgen_input + + def ethtool_set_rule(self): + rule_id, rule =3D 1, [] + for i in range(self.port_num): + intf =3D self.dut.ports_info[i]['port'].get_interface_name() + self.irqs_set.send_expect("ethtool -N %s rx-flow-hash udp4 fn"= % intf, "# ") + self.irqs_set.send_expect("ethtool -N %s flow-type udp4 src-po= rt 4243 dst-port 4243 action 0 loc %d" + % (intf, rule_id), "# ") + self.irqs_set.send_expect("ethtool -N %s flow-type udp4 src-po= rt 4242 dst-port 4242 action 1 loc %d" + % (intf, rule_id + 1), "# ") + rule.append((i, intf, rule_id, 4243, 4243)) + rule.append((i, intf, rule_id+1, 4242, 4242)) + rule_id +=3D 2 + time.sleep(1) + self.rule =3Drule + + def ethtool_del_rule(self): + for each in self.rule: + self.irqs_set.send_expect("ethtool -N %s delete %d" %=20 + (each[1], each[2]), "# ") + + def get_core_list(self): + core_config =3D "1S/%dC/1T" % (self.nb_cores + 1 + max(self.port_n= um, self.vdev_num) * self.queue_number) + self.core_list =3D self.dut.get_core_list( + core_config, socket=3Dself.ports_socket) + + def assign_port_core(self, separate=3DTrue): + if separate: + core_list =3D self.core_list[-max(self.port_num, self.vdev_num= ) * self.queue_number:] + else: + core_list =3D self.core_list[:-max(self.port_num, self.vdev_nu= m) * self.queue_number]\ + [-max(self.port_num,=20 + self.vdev_num) * self.queue_number:] + + for i in range(self.port_num): + intf =3D self.dut.ports_info[i]['port'].get_interface_name() + cores =3D ','.join(core_list[i * self.queue_number: (i+1) * se= lf.queue_number]) + if self.port_num =3D=3D 1 and self.vdev_num =3D=3D 2: + cores =3D ','.join(core_list) + command =3D "%s/set_irq_affinity %s %s" % ("/root", cores, int= f) + out =3D self.irqs_set.send_expect(command, "# ") + self.verify("No such file or directory" not in out, "can not f= ind the set_irq_affinity in dut root") + time.sleep(1) + + def get_vdev_list(self): + vdev_list =3D [] + + if self.port_num =3D=3D 1: + intf =3D self.dut.ports_info[0]['port'].get_interface_name() + self.set_port_queue(intf) + time.sleep(1) + for i in range(self.vdev_num): + vdev =3D '' + vdev =3D "net_af_xdp%d,iface=3D%s,start_queue=3D%d,queue_c= ount=3D%d" % (i, intf, i * self.queue_number, self.queue_number) + vdev_list.append(vdev) + else: + for i in range(self.port_num): + vdev =3D '' + intf =3D self.dut.ports_info[i]['port'].get_interface_name= () + self.set_port_queue(intf) + vdev =3D "net_af_xdp%d,iface=3D%s" % (i, intf) + vdev_list.append(vdev) + + return vdev_list + + def launch_testpmd(self, fwd_mode=3D'', topology=3D'', rss_ip=3DFalse)= : + self.get_core_list() + + vdev =3D self.get_vdev_list() + + if topology: + topology =3D "--port-topology=3D%s" % topology + if fwd_mode: + fwd_mode =3D "--forward-mode=3D%s" % fwd_mode + if rss_ip: + rss_ip =3D "--rss-ip" + else: + rss_ip =3D "" + + eal_params =3D self.dut.create_eal_parameters(cores=3Dself.core_li= st[:-max(self.port_num, self.vdev_num) * self.queue_number], + vdevs=3Dvdev, no_pci=3DTrue) + command_line =3D "./%s/app/testpmd %s --log-level=3Dpmd.net.af_xdp= :8 -- -i %s %s --auto-start --nb-cores=3D%d --rxq=3D%d --txq=3D%d %s" + command =3D command_line % (self.dut.target, eal_params, fwd_mode,= rss_ip, + self.nb_cores, self.queue_number, self.queue_number,=20 + topology) + + self.logger.info('start testpmd') + self.dut.send_expect(command, "testpmd> ", 120) + + def create_table(self, index=3D1): + if self.port_num =3D=3D2 or index =3D=3D 2: + self.table_header =3D ["FrameSize(B)", "Queue number", "Port0 = Throughput(Mpps)", + "Port0 % linerate", "Port1 Throughput(Mpps)", "Port1 %= linerate"] + else: + self.table_header =3D ["FrameSize(B)", "Queue number", "Port T= hroughput(Mpps)", + "Port % linerate"] + self.result_table_create(self.table_header) + + def update_table_info(self, *param): + for each in param: + self.result_table_add(each) + + def calculate_avg_throughput(self, frame_size, tgen_input, fwd_mode): + """ + send packet and get the throughput + """ + # set traffic option + traffic_opt =3D {'delay': 5} + + # clear streams before add new streams + self.tester.pktgen.clear_streams() + + # run packet generator + fields_config =3D {'ip': {'dst': {'action': 'random'}, }, } + streams =3D self.pktgen_helper.prepare_stream_from_tginput(tgen_in= put, 100, + fields_config, self.tester.pkt= gen) + _, pps =3D=20 + self.tester.pktgen.measure_throughput(stream_ids=3Dstreams,=20 + options=3Dtraffic_opt) + + Mpps =3D pps / 1000000.0 + + if fwd_mode !=3D "rxonly": + self.verify(Mpps > 0, "can not receive packets of frame size %= d" % (frame_size)) + throughput =3D Mpps * 100 / \ + float(self.wirespeed(self.nic, frame_size, 1)) + + return Mpps, throughput + + def check_packets_of_each_port(self, port_index): + """ + check each port has receive packets + """ + info =3D re.findall("Forward statistics for port %d" % + port_index, self.out) + index =3D self.out.find(info[0]) + rx =3D re.search("RX-packets:\s*(\d*)", self.out[index:]) + tx =3D re.search("TX-packets:\s*(\d*)", self.out[index:]) + rx_packets =3D int(rx.group(1)) + tx_packets =3D int(tx.group(1)) + self.verify(rx_packets > 0 and tx_packets > 0, + "rx-packets:%d, tx-packets:%d" % + (rx_packets, tx_packets)) + + def check_packets_of_each_queue(self, port_index): + """ + check port queue has receive packets + """ + for queue_index in range(0, self.queue_number): + queue_info =3D re.findall("RX\s*Port=3D\s*%d/Queue=3D\s*%d" % + (port_index, queue_index), self.out) + queue =3D queue_info[0] + index =3D self.out.find(queue) + rx =3D re.search("RX-packets:\s*(\d*)", self.out[index:]) + tx =3D re.search("TX-packets:\s*(\d*)", self.out[index:]) + rx_packets =3D int(rx.group(1)) + tx_packets =3D int(tx.group(1)) + self.verify(rx_packets > 0 and tx_packets > 0, + "The port %s queue %d, rx-packets:%d, tx-packets:%d" % + (port_index, queue_index, rx_packets, tx_packets)) + + def check_packets_of_all_queue(self, port_num): + """ + check all queue has receive packets + """ + for port_index in range(0, port_num): + self.check_packets_of_each_queue(port_index) + + def send_and_verify_throughput(self, pkt_type=3D'', fwd_mode=3D""): + for frame_size in self.frame_sizes: + info =3D "Running test %s, and %d frame size." % (self.running= _case, frame_size) + self.logger.info(info) + + result =3D [frame_size, self.queue_number] + + if pkt_type.lower() =3D=3D "udp": + num =3D len(self.rule) + else: + num =3D self.port_num + + for i in range(num): + if pkt_type.lower() =3D=3D "udp": + tgen_input =3D self.config_rule_stream(i, frame_size) + else: + tgen_input =3D self.config_stream(i, frame_size) + + Mpps, throughput =3D self.calculate_avg_throughput(frame_s= ize, tgen_input, fwd_mode) + result.append(Mpps) + result.append(throughput) + + self.out =3D self.dut.send_expect("stop", "testpmd> ",=20 + 60) + + if self.queue_number =3D=3D 1: + self.check_packets_of_each_port(i) + elif self.vdev_num =3D=3D 2: + self.check_packets_of_all_queue(2) + else: + self.check_packets_of_each_queue(i) + + self.dut.send_expect("start", "testpmd> ", 60) + + self.update_table_info(result) + + # check the throughput between two port + if len(result) =3D=3D 6: + self.verify(round((result[-2] - result[-4])/result[-4], 2)= <=3D 0.1, + "The gap is too big btween two port's=20 + throughput") + + def test_perf_one_port_single_queue_and_separate_irqs(self): + """ + single port test with PMD and IRQs are pinned to separate cores + """ + self.nb_cores =3D 1 + self.queue_number =3D 1 + self.port_num =3D 1 + self.vdev_num =3D 1 + + self.create_table() + self.launch_testpmd(topology=3D"loop") + self.assign_port_core() + self.send_and_verify_throughput() + + self.result_table_print() + + def test_perf_one_port_multiqueue_and_separate_irqs(self): + """ + multiqueue test with PMD and IRQs are pinned to separate cores + """ + self.nb_cores =3D 2 + self.queue_number =3D 2 + self.port_num =3D 1 + self.vdev_num =3D 1 + + self.create_table() + self.launch_testpmd(topology=3D"loop") + self.assign_port_core() + self.send_and_verify_throughput() + + self.result_table_print() + + def test_perf_one_port_multiqueue_and_same_irqs(self): + """ + multiqueue test with PMD and IRQs pinned to same cores + """ + self.nb_cores =3D 2 + self.queue_number =3D 2 + self.port_num =3D 1 + self.vdev_num =3D 1 + + self.create_table() + self.launch_testpmd(topology=3D"loop") + self.assign_port_core(separate=3DFalse) + self.send_and_verify_throughput() + + self.result_table_print() + + def test_perf_two_port_and_separate_irqs(self): + """ + two port test with PMD and IRQs are pinned to separate cores + """ + self.nb_cores =3D 2 + self.queue_number =3D 1 + self.port_num =3D 2 + self.vdev_num =3D 2 + + self.create_table() + self.launch_testpmd(topology=3D"loop") + self.assign_port_core() + self.send_and_verify_throughput() + + self.result_table_print() + + def test_perf_two_port_and_same_irqs(self): + """ + two ports test with PMD and IRQs pinned to same cores + """ + self.nb_cores =3D 2 + self.queue_number =3D 1 + self.port_num =3D 2 + self.vdev_num =3D 2 + + self.create_table() + self.launch_testpmd(topology=3D"loop") + self.assign_port_core(separate=3DFalse) + self.send_and_verify_throughput() + + self.result_table_print() + + def test_perf_one_port_single_queue_with_two_vdev(self): + """ + one port with two vdev and single queue test + """ + self.nb_cores =3D 2 + self.queue_number =3D 1 + self.port_num =3D 1 + self.vdev_num =3D 2 + + self.create_table(2) + self.launch_testpmd(topology=3D"loop") + self.assign_port_core() + self.ethtool_set_rule() + self.send_and_verify_throughput(pkt_type=3D'udp') + self.ethtool_del_rule() + + self.result_table_print() + + def test_perf_one_port_multiqueues_with_two_vdev(self): + """ + one port with two vdev and multi-queues test + """ + self.nb_cores =3D 8 + self.queue_number =3D 4 + self.port_num =3D 1 + self.vdev_num =3D 2 + + self.create_table() + self.launch_testpmd(topology=3D"loop", rss_ip=3DTrue) + self.assign_port_core() + self.send_and_verify_throughput() + + self.result_table_print() + + def tear_down(self): + self.dut.send_expect("quit", "#", 60) + + def tear_down_all(self): + self.dut.kill_all() + + self.dut.send_expect( + "sed -i 's/CONFIG_RTE_LIBRTE_PMD_AF_XDP=3Dy$/CONFIG_RTE_LIBRTE= _PMD_AF_XDP=3Dn/' config/common_base", "# ") + self.dut.build_install_dpdk(self.dut.target) -- 2.17.1