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 605CCA0613 for ; Fri, 27 Sep 2019 12:07:20 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 4F9141BEC9; Fri, 27 Sep 2019 12:07:20 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 2F0831BE8E for ; Fri, 27 Sep 2019 12:07:18 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Sep 2019 03:07:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,555,1559545200"; d="scan'208";a="273761488" Received: from dpdk-yuping-tester.sh.intel.com ([10.240.179.40]) by orsmga001.jf.intel.com with ESMTP; 27 Sep 2019 03:07:13 -0700 From: Qimai Xiao To: dts@dpdk.org Cc: Qimai Xiao Date: Fri, 27 Sep 2019 18:05:37 +0000 Message-Id: <20190927180539.2344-1-qimaix.xiao@intel.com> X-Mailer: git-send-email 2.17.1 Subject: [dts] [PATCH V1] tests/: update cases related to new framework 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" update testsuits related to new framework api Signed-off-by: Qimai Xiao --- tests/TestSuite_checksum_offload.py | 35 +- tests/TestSuite_cloud_filter.py | 13 +- tests/TestSuite_ddp_mpls.py | 3 +- tests/TestSuite_dynamic_queue.py | 12 +- tests/TestSuite_etag.py | 2 +- tests/TestSuite_eventdev_pipeline.py | 14 +- tests/TestSuite_floating_veb.py | 4 +- tests/TestSuite_flow_classify_softnic.py | 2 +- tests/TestSuite_generic_flow_api.py | 528 ++++++++++-------- tests/TestSuite_hotplug.py | 2 +- tests/TestSuite_iavf.py | 2 +- tests/TestSuite_ieee1588.py | 9 +- tests/TestSuite_ipfrag.py | 30 +- tests/TestSuite_ipgre.py | 80 +-- tests/TestSuite_ipsec_gw_cryptodev_func.py | 29 +- tests/TestSuite_jumboframes.py | 2 +- tests/TestSuite_kernelpf_iavf.py | 4 +- tests/TestSuite_l2fwd_cryptodev_func.py | 11 +- tests/TestSuite_l3fwdacl.py | 39 +- tests/TestSuite_link_flowctrl.py | 1 + tests/TestSuite_link_status_interrupt.py | 2 +- tests/TestSuite_loadbalancer.py | 14 +- tests/TestSuite_mac_filter.py | 2 +- tests/TestSuite_netmap_compat.py | 6 +- tests/TestSuite_packet_capture.py | 222 +++----- tests/TestSuite_ptype_mapping.py | 2 +- .../TestSuite_pvp_multi_paths_performance.py | 4 +- ...lti_paths_vhost_single_core_performance.py | 4 +- ...ti_paths_virtio_single_core_performance.py | 4 +- ...Suite_pvp_qemu_multi_paths_port_restart.py | 13 +- tests/TestSuite_pvp_vhost_user_reconnect.py | 13 +- tests/TestSuite_pvp_virtio_bonding.py | 9 +- tests/TestSuite_pvp_virtio_user_4k_pages.py | 5 +- tests/TestSuite_queue_region.py | 4 +- tests/TestSuite_queue_start_stop.py | 4 +- tests/TestSuite_quota_watermark.py | 2 +- tests/TestSuite_runtime_vf_queue_number.py | 13 +- ...estSuite_runtime_vf_queue_number_kernel.py | 23 +- tests/TestSuite_rxtx_callbacks.py | 4 +- tests/TestSuite_scatter.py | 4 +- tests/TestSuite_short_live.py | 4 +- tests/TestSuite_skeleton.py | 4 +- tests/TestSuite_sriov_kvm.py | 11 +- tests/TestSuite_uni_pkt.py | 9 +- tests/TestSuite_userspace_ethtool.py | 34 +- tests/TestSuite_veb_switch.py | 4 +- tests/TestSuite_vf_daemon.py | 21 +- tests/TestSuite_vf_interrupt_pmd.py | 2 +- tests/TestSuite_vf_jumboframe.py | 2 +- tests/TestSuite_vf_kernel.py | 13 +- tests/TestSuite_vf_macfilter.py | 9 +- tests/TestSuite_vf_offload.py | 4 +- tests/TestSuite_vf_packet_rxtx.py | 19 +- tests/TestSuite_vf_port_start_stop.py | 86 +-- tests/TestSuite_vf_rss.py | 3 +- tests/TestSuite_vf_vlan.py | 12 +- tests/TestSuite_vhost_enqueue_interrupt.py | 1 + tests/TestSuite_vhost_multi_queue_qemu.py | 15 +- tests/TestSuite_vhost_pmd_xstats.py | 2 +- tests/TestSuite_vhost_virtio_pmd_interrupt.py | 4 +- .../TestSuite_virtio_ipsec_cryptodev_func.py | 12 +- tests/TestSuite_vlan.py | 6 +- tests/TestSuite_vm2vm_virtio_pmd.py | 9 +- tests/TestSuite_vxlan.py | 143 ++--- tests/TestSuite_vxlan_sample.py | 38 +- 65 files changed, 759 insertions(+), 884 deletions(-) diff --git a/tests/TestSuite_checksum_offload.py b/tests/TestSuite_checksum_offload.py index 7176cb9..c890671 100644 --- a/tests/TestSuite_checksum_offload.py +++ b/tests/TestSuite_checksum_offload.py @@ -46,6 +46,7 @@ from test_case import TestCase from pmd_output import PmdOutput from test_capabilities import DRIVER_TEST_LACK_CAPA from pktgen import PacketGeneratorHelper +import packet class TestChecksumOffload(TestCase): @@ -110,7 +111,7 @@ class TestChecksumOffload(TestCase): for packet_type in packets_expected.keys(): self.tester.send_expect("p = %s" % packets_expected[packet_type], ">>>") - out = self.tester.send_expect("p.show2()", ">>>") + out = self.tester.send_command("p.show2()", timeout=1) chksums = checksum_pattern.findall(out) chksum[packet_type] = chksums @@ -122,15 +123,11 @@ class TestChecksumOffload(TestCase): """ Sends packets and check the checksum valid-flags. """ - self.tester.scapy_foreground() self.dut.send_expect("start", "testpmd>") - mac = self.dut.get_mac_address(self.dut_ports[0]) tx_interface = self.tester.get_interface(self.tester.get_local_port(self.dut_ports[0])) - self.tester.scapy_foreground() - for packet_type in packets_sent.keys(): - self.tester.scapy_append('sendp([%s], iface="%s", count=4)' % (packets_sent[packet_type], tx_interface)) - self.tester.scapy_execute() + self.pkt = packet.Packet(pkt_str=packets_sent[packet_type]) + self.pkt.send_pkt(self.tester, tx_interface, count=4) out = self.dut.get_session_output(timeout=1) lines = out.split("\r\n") @@ -173,33 +170,21 @@ class TestChecksumOffload(TestCase): rx_interface = self.tester.get_interface(self.tester.get_local_port(self.dut_ports[0])) sniff_src = self.dut.get_mac_address(self.dut_ports[0]) - checksum_pattern = re.compile("chksum.*=.*(0x[0-9a-z]+)") - - chksum = dict() result = dict() - self.tester.send_expect("scapy", ">>> ") - - for packet_type in packets_expected.keys(): - self.tester.send_expect("p = %s" % packets_expected[packet_type], ">>>") - out = self.tester.send_expect("p.show2()", ">>>") - chksums = checksum_pattern.findall(out) - chksum[packet_type] = chksums - - self.tester.send_expect("exit()", "#") + chksum = self.get_chksum_values(packets_expected) inst = self.tester.tcpdump_sniff_packets(intf=rx_interface, count=len(packets_sent)*4, filters=[{'layer': 'ether', 'config': {'src': sniff_src}}]) + self.pkt = packet.Packet() for packet_type in packets_sent.keys(): - self.tester.scapy_append('sendp([%s], iface="%s", count=4)' % (packets_sent[packet_type], tx_interface)) + self.pkt.append_pkt(packets_sent[packet_type]) + self.pkt.send_pkt(crb=self.tester, tx_port=tx_interface, count=4) - self.tester.scapy_execute() p = self.tester.load_tcpdump_sniff_packets(inst) nr_packets = len(p) - reslist = [p[i].pktgen.pkt.sprintf("%IP.chksum%;%TCP.chksum%;%UDP.chksum%;%SCTP.chksum%") for i in range(nr_packets)] - out = string.join(reslist, ",") - packets_received = out.split(',') + packets_received = [p[i].sprintf("%IP.chksum%;%TCP.chksum%;%UDP.chksum%;%SCTP.chksum%") for i in range(nr_packets)] self.verify(len(packets_sent)*4 == len(packets_received), "Unexpected Packets Drop") for packet_received in packets_received: @@ -272,8 +257,6 @@ class TestChecksumOffload(TestCase): 'IPv6/UDP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IPv6(src="::1")/UDP()/("X"*46)' % mac, 'IPv6/TCP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IPv6(src="::1")/TCP()/("X"*46)' % mac} - result = dict() - self.checksum_enablehw(self.dut_ports[0]) # get the packet checksum value diff --git a/tests/TestSuite_cloud_filter.py b/tests/TestSuite_cloud_filter.py index 74b3be7..51647ef 100644 --- a/tests/TestSuite_cloud_filter.py +++ b/tests/TestSuite_cloud_filter.py @@ -12,7 +12,7 @@ import os from test_case import TestCase from pmd_output import PmdOutput from settings import HEADER_SIZE -from packet import Packet, load_pcapfile +from packet import Packet from scapy.layers.inet import UDP, IP from scapy.packet import split_layers, bind_layers @@ -195,7 +195,7 @@ class CloudFilterConfig(object): self.pkt.config_layer('ether', ether_cfg) self.pkt.config_layer('raw', {'payload': ['01'] * 18}) - self.pkt.send_pkt(tx_port=self.case.tester_intf) + self.pkt.send_pkt(crb=self.case.tester, tx_port=self.case.tester_intf) class TestCloudFilter(TestCase): @@ -311,7 +311,6 @@ class TestCloudFilter(TestCase): if dpdk: cloud_cfg.transmit_packet() out = self.pmdout.get_output() - print out queue = cloud_cfg.cf_rule['queue'] self.verify("queue %d" % queue in out, "Vxlan not received in queue %d" % queue) @@ -341,11 +340,11 @@ class TestCloudFilter(TestCase): time.sleep(2) # copy pcap to tester and then analyze self.dut.session.copy_file_from(tmp_file) - pkts = load_pcapfile( - filename="cloud_filter_%s.pcap" % self.vf_intf) + pkt = Packet() + pkt.read_pcapfile(filename="cloud_filter_%s.pcap" % self.vf_intf) self.verify( - len(pkts) == 1, "%d packet recevied on kernel VF" % len(pkts)) - cap_pkt = pkts[0].pktgen.pkt + len(pkt) == 1, "%d packet recevied on kernel VF" % len(pkt)) + cap_pkt = pkt[0] try: dport = cap_pkt[UDP].dport self.verify(dport == CLOUD_PORT, diff --git a/tests/TestSuite_ddp_mpls.py b/tests/TestSuite_ddp_mpls.py index 547e1c9..599e5cd 100644 --- a/tests/TestSuite_ddp_mpls.py +++ b/tests/TestSuite_ddp_mpls.py @@ -95,11 +95,10 @@ class Testddp_mpls(TestCase): self.vm0_dut_ports = self.vm0_dut.get_ports('any') self.vm0_testpmd = PmdOutput(self.vm0_dut) self.env_done = True - eal_param = '-b %(vf0)s' % {'vf0': self.sriov_vfs_port[0].pci} self.dut_testpmd.start_testpmd( "Default","--port-topology=chained --txq=%s --rxq=%s" - % (PF_MAX_QUEUE, PF_MAX_QUEUE), eal_param=eal_param) + % (PF_MAX_QUEUE, PF_MAX_QUEUE)) self.vm0_testpmd.start_testpmd( VM_CORES_MASK,"--port-topology=chained --txq=%s --rxq=%s" % (VF_MAX_QUEUE, VF_MAX_QUEUE)) diff --git a/tests/TestSuite_dynamic_queue.py b/tests/TestSuite_dynamic_queue.py index dd05eab..1f86d1f 100644 --- a/tests/TestSuite_dynamic_queue.py +++ b/tests/TestSuite_dynamic_queue.py @@ -63,14 +63,10 @@ class TestDynamicQueue(TestCase): Generate packets and send them to dut """ mac = self.dut.get_mac_address(0) - for i in range(self.PF_QUEUE * 4): - j = i /256 - k = i % 256 - pkt = Packet(pkt_type='IP_RAW') - pkt.config_layer('ether', {'dst': mac}) - pkt.config_layer( - 'ipv4', {'dst': '192.168.%d.%d' % (j, k), 'src': '191.168.0.1'}) - pkt.send_pkt(tx_port=self.tester_intf) + pktnum = self.PF_QUEUE * 4 + pkt = Packet() + pkt.generate_random_pkts(mac, pktnum=pktnum, random_type=['IP_RAW']) + pkt.send_pkt(self.tester, tx_port=self.tester_intf) def rxq_setup_test(self, chgflag=0): """ diff --git a/tests/TestSuite_etag.py b/tests/TestSuite_etag.py index 45c5163..8a67222 100644 --- a/tests/TestSuite_etag.py +++ b/tests/TestSuite_etag.py @@ -160,7 +160,7 @@ class TestEtag(TestCase): if pkt_configs: for layer in pkt_configs.keys(): pkt.config_layer(layer, pkt_configs[layer]) - pkt.send_pkt(tx_port=self.src_intf) + pkt.send_pkt(self.tester, tx_port=self.src_intf) # check vm testpmd packet received information if 'vm' in pkt_types[pkt_type].keys(): diff --git a/tests/TestSuite_eventdev_pipeline.py b/tests/TestSuite_eventdev_pipeline.py index cee636a..9f723cd 100644 --- a/tests/TestSuite_eventdev_pipeline.py +++ b/tests/TestSuite_eventdev_pipeline.py @@ -113,8 +113,8 @@ class TestEventdevPipeline(TestCase): pkts = self.tester.load_tcpdump_sniff_packets(inst) i = 0 while len(pkts) != 0 and i <= len(pkts) - 1: - if pkts[i].pktgen.pkt.haslayer('DHCP'): - pkts.remove(pkts[i]) + if pkts[i].haslayer('DHCP'): + pkts.pktgen.pkts.pop(i) i = i - 1 i = i + 1 return pkts @@ -152,7 +152,7 @@ class TestEventdevPipeline(TestCase): time.sleep(5) filt = [{'layer': 'ether', 'config': {'src': '%s' % self.s_mac}}] - inst = self.tester.tcpdump_sniff_packets(self.rx_interface, timeout=15, filters=filt) + inst = self.tester.tcpdump_sniff_packets(self.rx_interface, filters=filt) self.tester.scapy_append('pkt=rdpcap("pipeline.pcap")') self.tester.scapy_append('sendp(pkt, iface="%s")' % self.tx_interface) self.tester.scapy_execute() @@ -169,13 +169,13 @@ class TestEventdevPipeline(TestCase): packet_index = 0 for i in range(len(self.pkts)): pay_load = "0000%.2d" % (packet_index) - if self.pkts[i].pktgen.pkt['IP'].src == src_ip: - print self.pkts[i].pktgen.pkt.show + if self.pkts[i]['IP'].src == src_ip: + print(self.pkts[i].show) # get the start index load info of each queue if packet_index == 0: - packet_index = int(self.pkts[i].pktgen.pkt['Raw'].load[-2:]) + packet_index = int(self.pkts[i]['Raw'].load[-2:]) pay_load = "0000%.2d" % (packet_index) - self.verify(self.pkts[i].pktgen.pkt['Raw'].load == pay_load, + self.verify(self.pkts[i]['Raw'].load == pay_load, "The packets not ordered") packet_index = packet_index + 1 diff --git a/tests/TestSuite_floating_veb.py b/tests/TestSuite_floating_veb.py index 40b0ce2..350d8fa 100644 --- a/tests/TestSuite_floating_veb.py +++ b/tests/TestSuite_floating_veb.py @@ -120,12 +120,12 @@ class TestFloatingVEBSwitching(TestCase): pkt = Packet(pkt_type='VLAN_UDP') pkt.config_layer('ether', {'dst': vf_mac}) pkt.config_layer('vlan', {'vlan': 1}) - pkt.send_pkt(tx_port=itf) + pkt.send_pkt(self.tester, tx_port=itf) time.sleep(.5) else: pkt = Packet(pkt_type='UDP') pkt.config_layer('ether', {'dst': vf_mac}) - pkt.send_pkt(tx_port=itf) + pkt.send_pkt(self.tester, tx_port=itf) time.sleep(.5) # Test cases. diff --git a/tests/TestSuite_flow_classify_softnic.py b/tests/TestSuite_flow_classify_softnic.py index 33f701e..a649a44 100644 --- a/tests/TestSuite_flow_classify_softnic.py +++ b/tests/TestSuite_flow_classify_softnic.py @@ -72,7 +72,7 @@ class TestFlowClassifySoftnic(TestCase): file = 'flow_classify_softnic.tar.gz' src_file = r'./dep/%s' % file dst1 = '/tmp' - dst2 = os.path.join(self.dut.base_dir, 'drivers/net/softnic') + dst2 = '/root/dpdk/drivers/net/softnic' self.dut.session.copy_file_to(src_file, dst1) self.dut.send_expect("tar xf %s/%s -C %s" % (dst1, file, dst2), "#", 30) diff --git a/tests/TestSuite_generic_flow_api.py b/tests/TestSuite_generic_flow_api.py index 61af86c..e0a4aa6 100644 --- a/tests/TestSuite_generic_flow_api.py +++ b/tests/TestSuite_generic_flow_api.py @@ -49,7 +49,7 @@ from crb import Crb from virt_dut import VirtDut from project_dpdk import DPDKdut from dut import Dut -from packet import Packet +import packet import os import random @@ -99,6 +99,7 @@ class TestGeneric_flow_api(TestCase): self.inner_mac = "00:11:22:33:44:66" self.wrong_mac = "00:11:22:33:44:77" self.vf_flag = 0 + self.pkt_obj = packet.Packet() def set_up(self): """ @@ -162,8 +163,8 @@ class TestGeneric_flow_api(TestCase): """ verify the packet to the expected queue or be dropped """ - self.tester.scapy_execute() - time.sleep(2) + # self.tester.scapy_execute() + # time.sleep(2) verify_mac = verify_mac.upper() if self.vf_flag == 1: @@ -207,7 +208,7 @@ class TestGeneric_flow_api(TestCase): queue_index = 0 find_index = False for i in range(len(m)): - cur = out_info.find(m[i], all_queue_index[i-1] + len(m[i-1]) if i > 0 else 0) + cur = out_info.find(m[i], all_queue_index[i - 1] + len(m[i - 1]) if i > 0 else 0) if cur > mac_index: queue_index = i - 1 find_index = True @@ -255,8 +256,8 @@ class TestGeneric_flow_api(TestCase): # caculate the rule number created. rule_created = self.flow_test_process(flow_process, flow_action) if rule_created: - rule_num += 1 - extra_packet.append(flow_process['extrapacket']) + rule_num += 1 + extra_packet.append(flow_process['extrapacket']) # Configure a return value. extrapkt_rulenum = {'extrapacket': extra_packet, 'rulenum': rule_num, 'queue': expected_queue} @@ -286,26 +287,34 @@ class TestGeneric_flow_api(TestCase): if "validate" in flow_cmd: # ethertype invalid or queue id exceeds max queue number. if "86dd" in flow_cmd or "0800" in flow_cmd or "index %s" % str(MAX_QUEUE + 1) in flow_cmd: - if self.nic in ["fortville_eagle", "fortville_spirit", "fortville_spirit_single", "fortpark_TLV", "niantic", "kawela_4", "kawela", "bartonhills", "twinville", "sagepond", "sageville", "powerville"]: + if self.nic in ["fortville_eagle", "fortville_spirit", "fortville_spirit_single", "fortpark_TLV", + "niantic", "kawela_4", "kawela", "bartonhills", "twinville", "sagepond", "sageville", + "powerville"]: self.dut.send_expect(flow_cmd, "error") elif "type is 0x8100" in flow_cmd: if self.nic in ["fortville_eagle", "fortville_spirit", "fortville_spirit_single", "fortpark_TLV"]: self.dut.send_expect(flow_cmd, "error") # vf queue id exceeds max vf queue number. - elif (("vf0" in flow_action['flows']) or ("vf1" in flow_action['flows']) or ("vf0" in flow_action['actions']) or ("vf1" in flow_action['actions'])) and (("index %s" % str(MAX_VFQUEUE + 1)) in flow_cmd): + elif (("vf0" in flow_action['flows']) or ("vf1" in flow_action['flows']) or ( + "vf0" in flow_action['actions']) or ("vf1" in flow_action['actions'])) and ( + ("index %s" % str(MAX_VFQUEUE + 1)) in flow_cmd): self.dut.send_expect(flow_cmd, "error") else: self.dut.send_expect(flow_cmd, "validated") elif "create" in flow_cmd: # ethertype invalid or queue id exceeds max queue number. if "86dd" in flow_cmd or "0800" in flow_cmd or "index %s" % str(MAX_QUEUE + 1) in flow_cmd: - if self.nic in ["fortville_eagle", "fortville_spirit", "fortville_spirit_single", "fortpark_TLV", "niantic", "kawela_4", "kawela", "bartonhills", "twinville", "sagepond", "sageville", "powerville"]: + if self.nic in ["fortville_eagle", "fortville_spirit", "fortville_spirit_single", "fortpark_TLV", + "niantic", "kawela_4", "kawela", "bartonhills", "twinville", "sagepond", "sageville", + "powerville"]: self.dut.send_expect(flow_cmd, "error") elif "type is 0x8100" in flow_cmd: if self.nic in ["fortville_eagle", "fortville_spirit", "fortville_spirit_single", "fortpark_TLV"]: self.dut.send_expect(flow_cmd, "error") # vf queue id exceeds max vf queue number. - elif (("vf0" in flow_action['flows']) or ("vf1" in flow_action['flows']) or ("vf0" in flow_action['actions']) or ("vf1" in flow_action['actions'])) and (("index %s" % str(MAX_VFQUEUE + 1)) in flow_cmd): + elif (("vf0" in flow_action['flows']) or ("vf1" in flow_action['flows']) or ( + "vf0" in flow_action['actions']) or ("vf1" in flow_action['actions'])) and ( + ("index %s" % str(MAX_VFQUEUE + 1)) in flow_cmd): self.dut.send_expect(flow_cmd, "error") else: self.dut.send_expect(flow_cmd, "created") @@ -318,7 +327,7 @@ class TestGeneric_flow_api(TestCase): self.load_module("nvgre") # The rule is created successfully, so send the consistent packet. - self.tester.scapy_append('sendp(%s, iface="%s")' % (flow_pkt, self.tester_itf)) + self.sendpkt(pktstr=flow_pkt) cur_mac = re.search("dst='(\S\S:\S\S:\S\S:\S\S:\S\S:\S\S)'", flow_pkt) cur_mac = cur_mac.group(1) if ("queue" in flow_action['actions']) or ("passthru" in flow_action['actions']): @@ -353,7 +362,7 @@ class TestGeneric_flow_api(TestCase): if is_ipv4 == True: return '.'.join('%s' % random.randint(0, 255) for i in range(4)) else: - return ':'.join('{:x}'.format(random.randint(0, 2**16 - 1)) for i in range(8)) + return ':'.join('{:x}'.format(random.randint(0, 2 ** 16 - 1)) for i in range(8)) def generate_random_int(self, minimum, maximum): return random.randint(minimum, maximum) @@ -376,7 +385,9 @@ class TestGeneric_flow_api(TestCase): cmd_fmt = "flow %(create)s 0 ingress pattern %(flow)s / end actions %(action)s end" # Record the elements of the rule, ready for the configuration # of packets inconsistent to the rule. - extrapacket = {'vlan': '', 'etag': '', 'ipv4': '', 'ipv6': '', 'sip': '', 'dip': '', 'proto': '', 'tos': '', 'ttl': '', 'tcp': '', 'udp': '', 'sctp': '', 'sport': '', 'dport': '', 'vni': '', 'tni': '', 'ineth': '', 'invlan': ''} + extrapacket = {'vlan': '', 'etag': '', 'ipv4': '', 'ipv6': '', 'sip': '', 'dip': '', 'proto': '', 'tos': '', + 'ttl': '', 'tcp': '', 'udp': '', 'sctp': '', 'sport': '', 'dport': '', 'vni': '', 'tni': '', + 'ineth': '', 'invlan': ''} # Define the packet string, which is consistent to the flow rule. if ('vf0' in flows) or ('vf1' in flows) or ('vf0' in actions) or ('vf1' in actions): pkt = "Ether(dst='%s')" % self.wrong_mac @@ -630,14 +641,24 @@ class TestGeneric_flow_api(TestCase): elif action == "mark": act_str += "mark id 3 / " # Configure the whole flow rule. - command = cmd_fmt % { "create": create, - "flow": flow_str, - "action": act_str} + command = cmd_fmt % {"create": create, + "flow": flow_str, + "action": act_str} # Configure the return value. flow_process = {'cmd': command, 'pkt': pkt, 'queue': index, 'extrapacket': extrapacket} return flow_process + def sendpkt(self, pktstr, count=1): + import sys + py_version = sys.version + if py_version.startswith('3.'): + self.pkt_obj.pktgen.pkts.clear() + else: + del self.pkt_obj.pktgen.pkts[:] + self.pkt_obj.append_pkt(pktstr) + self.pkt_obj.send_pkt(self.tester, tx_port=self.tester_itf, count=count) + def test_syn_filter(self): """ Only supported by ixgbe and igb. @@ -653,14 +674,13 @@ class TestGeneric_flow_api(TestCase): # create the flow rules self.dut.send_expect( - "flow create 0 ingress pattern eth / ipv4 / tcp flags spec 0x02 flags mask 0x02 / end actions queue index 3 / end", "created") + "flow create 0 ingress pattern eth / ipv4 / tcp flags spec 0x02 flags mask 0x02 / end actions queue index 3 / end", + "created") # send the packets and verify the results - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2")/TCP(dport=80,flags="S")/Raw("x" * 20)], iface="%s")' % (self.pf_mac, self.tester_itf)) - self.verify_result("pf", expect_rxpkts="1", expect_queue="3", verify_mac=self.pf_mac) + self.sendpkt(pktstr='Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2")/TCP(dport=80,flags="S")/Raw("x" * 20)' % self.pf_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2")/TCP(dport=80,flags="PA")/Raw("x" * 20)], iface="%s")' % (self.pf_mac, self.tester_itf)) + self.verify_result("pf", expect_rxpkts="1", expect_queue="3", verify_mac=self.pf_mac) + self.sendpkt(pktstr='Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2")/TCP(dport=80,flags="PA")/Raw("x" * 20)' % self.pf_mac) self.verify_result("pf", expect_rxpkts="1", expect_queue="0", verify_mac=self.pf_mac) # the ipv6 rule is conflicted with ipv4 rule. @@ -668,14 +688,13 @@ class TestGeneric_flow_api(TestCase): # create the flow rules self.dut.send_expect( - "flow create 0 ingress pattern eth / ipv6 / tcp flags spec 0x02 flags mask 0x02 / end actions queue index 4 / end", "created") + "flow create 0 ingress pattern eth / ipv6 / tcp flags spec 0x02 flags mask 0x02 / end actions queue index 4 / end", + "created") # send the packets and verify the results - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IPv6(src="2001::1", dst="2001::2")/TCP(dport=80,flags="S")/Raw("x" * 20)], iface="%s")' % (self.pf_mac, self.tester_itf)) + self.sendpkt(pktstr='Ether(dst="%s")/IPv6(src="2001::1", dst="2001::2")/TCP(dport=80,flags="S")/Raw("x" * 20)' % self.pf_mac) self.verify_result("pf", expect_rxpkts="1", expect_queue="4", verify_mac=self.pf_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IPv6(src="2001::1", dst="2001::2")/TCP(dport=80,flags="PA")/Raw("x" * 20)], iface="%s")' % (self.pf_mac, self.tester_itf)) + self.sendpkt(pktstr='Ether(dst="%s")/IPv6(src="2001::1", dst="2001::2")/TCP(dport=80,flags="PA")/Raw("x" * 20)' % self.pf_mac) self.verify_result("pf", expect_rxpkts="1", expect_queue="0", verify_mac=self.pf_mac) self.verify_rulenum(1) @@ -695,21 +714,24 @@ class TestGeneric_flow_api(TestCase): # create the flow rules basic_flow_actions = [ {'create': 'create', 'flows': ['ipv4', 'sip', 'dip'], 'actions': ['queue']}, - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'proto', 'udp', 'sport', 'dport'], 'actions': ['queue']}, - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'proto', 'tcp', 'sport', 'dport'], 'actions': ['queue']}, - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'proto', 'sctp', 'sport', 'dport'], 'actions': ['queue']} + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'proto', 'udp', 'sport', 'dport'], + 'actions': ['queue']}, + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'proto', 'tcp', 'sport', 'dport'], + 'actions': ['queue']}, + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'proto', 'sctp', 'sport', 'dport'], + 'actions': ['queue']} ] extrapkt_rulenum = self.all_flows_process(basic_flow_actions) extra_packet = extrapkt_rulenum['extrapacket'] # send the packets inconsistent to the rules. - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP(src="%s", dst="%s")/Raw("x" * 20)], iface="%s")' % (self.pf_mac, extra_packet[0]['dip'], extra_packet[0]['sip'], self.tester_itf)) + self.sendpkt('Ether(dst="%s")/IP(src="%s", dst="%s")/Raw("x" * 20)' % (self.pf_mac, extra_packet[0]['dip'], extra_packet[0]['sip'])) self.verify_result("pf", expect_rxpkts="1", expect_queue="0", verify_mac=self.pf_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP(src="%s", dst="%s")/SCTP(sport=%s,dport=%s)/Raw("x" * 20)], iface="%s")' % (self.pf_mac, extra_packet[3]['dip'], extra_packet[3]['sip'], extra_packet[3]['sport'], extra_packet[3]['dport'], self.tester_itf)) + self.sendpkt('Ether(dst="%s")/IP(src="%s", dst="%s")/SCTP(sport=%s,dport=%s)/Raw("x" * 20)' % ( + self.pf_mac, extra_packet[3]['dip'], extra_packet[3]['sip'], extra_packet[3]['sport'], + extra_packet[3]['dport'])) self.verify_result("pf", expect_rxpkts="1", expect_queue="0", verify_mac=self.pf_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP(src="%s", dst="%s")/SCTP(sport=%s,dport=%s)/Raw("x" * 20)], iface="%s")' % (self.pf_mac, extra_packet[0]['sip'], extra_packet[0]['dip'], extra_packet[3]['sport'], extra_packet[3]['dport'], self.tester_itf)) + self.sendpkt('Ether(dst="%s")/IP(src="%s", dst="%s")/SCTP(sport=%s,dport=%s)/Raw("x" * 20)' % (self.pf_mac, extra_packet[0]['sip'], extra_packet[0]['dip'], extra_packet[3]['sport'], + extra_packet[3]['dport'])) self.verify_result("pf", expect_rxpkts="1", expect_queue=extrapkt_rulenum['queue'][0], verify_mac=self.pf_mac) rule_num = extrapkt_rulenum['rulenum'] @@ -736,11 +758,10 @@ class TestGeneric_flow_api(TestCase): extrapkt_rulenum = self.all_flows_process(basic_flow_actions) extra_packet = extrapkt_rulenum['extrapacket'] # send the packets inconsistent to the rules. - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=22,dport=24)/Raw("x" * 20)], iface="%s")' % (self.pf_mac, self.tester_itf)) + self.sendpkt('Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=22,dport=24)/Raw("x" * 20)' % self.pf_mac) self.verify_result("pf", expect_rxpkts="1", expect_queue="0", verify_mac=self.pf_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2")/TCP(sport=32,dport=34)/Raw("x" * 20)], iface="%s")' % (self.pf_mac, self.tester_itf)) + self.sendpkt( + 'Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2")/TCP(sport=32,dport=34)/Raw("x" * 20)' % self.pf_mac) self.verify_result("pf", expect_rxpkts="1", expect_queue="0", verify_mac=self.pf_mac) rule_num = extrapkt_rulenum['rulenum'] self.verify_rulenum(rule_num) @@ -792,8 +813,8 @@ class TestGeneric_flow_api(TestCase): {'create': 'create', 'flows': ['ether', 'lldp'], 'actions': ['queue']}, ] extrapkt_rulenum = self.all_flows_process(basic_flow_actions) - self.tester.scapy_append( - 'sendp([Ether(dst="%s",type=0x88E5)/Raw("x" * 20)], iface="%s")' % (self.pf_mac, self.tester_itf)) + self.sendpkt(pktstr='Ether(dst="%s",type="0x88E5")/Raw("x" * 20)' % self.pf_mac) + self.verify_result("pf", expect_rxpkts="1", expect_queue="0", verify_mac=self.pf_mac) rule_num = extrapkt_rulenum['rulenum'] self.verify_rulenum(rule_num) @@ -837,8 +858,7 @@ class TestGeneric_flow_api(TestCase): ] extrapkt_rulenum = self.all_flows_process(basic_flow_actions) extra_packet = extrapkt_rulenum['extrapacket'] - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/Dot1BR(GRP=0x2, ECIDbase=%s)/Raw("x" * 20)], iface="%s")' % (self.pf_mac, extra_packet[0]['etag'], self.tester_itf)) + self.sendpkt('Ether(dst="%s")/Dot1BR(GRP=0x2, ECIDbase=%s)/Raw("x" * 20)' % (self.pf_mac, extra_packet[0]['etag'])) self.verify_result("pf", expect_rxpkts="0", expect_queue="NULL", verify_mac=self.pf_mac) rule_num = extrapkt_rulenum['rulenum'] self.verify_rulenum(rule_num) @@ -911,47 +931,45 @@ class TestGeneric_flow_api(TestCase): extrapkt_rulenum = self.all_flows_process(basic_flow_actions) extra_packet = extrapkt_rulenum['extrapacket'] # send the packets with dst/src ip and dst/src port. - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.1", dst="192.168.0.2", proto=3)/Raw("x" * 20)], iface="%s")' % (self.pf_mac, extra_packet[0]['vlan'], self.tester_itf)) + self.sendpkt(pktstr='Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.1", dst="192.168.0.2", proto=3)/Raw("x" * 20)' % (self.pf_mac, extra_packet[0]['vlan'])) self.verify_result("pf", expect_rxpkts="1", expect_queue=extrapkt_rulenum['queue'][0], verify_mac=self.pf_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.1", dst="192.168.0.2", tos=3)/UDP()/Raw("x" * 20)], iface="%s")' % (self.pf_mac, extra_packet[1]['vlan'], self.tester_itf)) + self.sendpkt('Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.1", dst="192.168.0.2", tos=3)/UDP()/Raw("x" * 20)' % (self.pf_mac, extra_packet[1]['vlan'])) self.verify_result("pf", expect_rxpkts="1", expect_queue=extrapkt_rulenum['queue'][1], verify_mac=self.pf_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.1", dst="192.168.0.2", ttl=3)/TCP()/Raw("x" * 20)], iface="%s")' % (self.pf_mac, extra_packet[2]['vlan'], self.tester_itf)) + self.sendpkt('Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.1", dst="192.168.0.2", ttl=3)/TCP()/Raw("x" * 20)' % (self.pf_mac, extra_packet[2]['vlan'])) self.verify_result("pf", expect_rxpkts="1", expect_queue=extrapkt_rulenum['queue'][2], verify_mac=self.pf_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.1", dst="192.168.0.2", tos=3, ttl=3)/SCTP()/Raw("x" * 20)], iface="%s")' % (self.pf_mac, extra_packet[3]['vlan'], self.tester_itf)) + self.sendpkt('Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.1", dst="192.168.0.2", tos=3, ttl=3)/SCTP()/Raw("x" * 20)' % (self.pf_mac, extra_packet[3]['vlan'])) self.verify_result("pf", expect_rxpkts="1", expect_queue=extrapkt_rulenum['queue'][3], verify_mac=self.pf_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.1", dst="192.168.0.2", ttl=3)/TCP()/Raw("x" * 20)], iface="%s")' % (self.pf_mac, extra_packet[3]['vlan'], self.tester_itf)) + self.sendpkt('Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.1", dst="192.168.0.2", ttl=3)/TCP()/Raw("x" * 20)' % (self.pf_mac, extra_packet[3]['vlan'])) self.verify_result("pf", expect_rxpkts="1", expect_queue="0", verify_mac=self.pf_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IP()/UDP()/Raw("x" * 20)], iface="%s")' % (self.pf_mac, extra_packet[2]['vlan'], self.tester_itf)) + self.sendpkt('Ether(dst="%s")/Dot1Q(vlan=%s)/IP()/UDP()/Raw("x" * 20)' % (self.pf_mac, extra_packet[2]['vlan'])) self.verify_result("pf", expect_rxpkts="1", expect_queue="0", verify_mac=self.pf_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.5", dst="192.168.0.6", tos=3, ttl=3)/SCTP(sport=44,dport=45,tag=1)/Raw("x" * 20)], iface="%s")' % (self.pf_mac, extra_packet[6]['vlan'], self.tester_itf)) + self.sendpkt('Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.5", dst="192.168.0.6", tos=3, ttl=3)/SCTP(sport=44,dport=45,tag=1)/Raw("x" * 20)' % (self.pf_mac, extra_packet[6]['vlan'])) self.verify_result("pf", expect_rxpkts="0", expect_queue="NULL", verify_mac=self.pf_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.5", dst="192.168.0.6", tos=3, ttl=3)/UDP(sport=44,dport=45)/SCTPChunkData(data="X" * 20)], iface="%s")' % (self.outer_mac, extra_packet[7]['vlan'], self.tester_itf)) + self.sendpkt( + 'Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.5", dst="192.168.0.6", tos=3, ttl=3)/UDP(sport=44,dport=45)/SCTPChunkData(data="X" * 20)' % ( + self.outer_mac, extra_packet[7]['vlan'])) self.verify_result("vf1", expect_rxpkts="0", expect_queue="NULL", verify_mac=self.outer_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1", dst="2001::2", tc=1, nh=5, hlim=10)/Raw("x" * 20)], iface="%s")' % (self.pf_mac, extra_packet[8]['vlan'], self.tester_itf)) + self.sendpkt( + 'Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1", dst="2001::2", tc=1, nh=5, hlim=10)/Raw("x" * 20)' % ( + self.pf_mac, extra_packet[8]['vlan'])) self.verify_result("pf", expect_rxpkts="1", expect_queue=extrapkt_rulenum['queue'][8], verify_mac=self.pf_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1", dst="2001::2", tc=2, hlim=20)/UDP(sport=22,dport=23)/Raw("x" * 20)], iface="%s")' % (self.pf_mac, extra_packet[9]['vlan'], self.tester_itf)) + self.sendpkt('Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1", dst="2001::2", tc=2, hlim=20)/UDP(sport=22,dport=23)/Raw("x" * 20)' % (self.pf_mac, extra_packet[9]['vlan'])) self.verify_result("pf", expect_rxpkts="1", expect_queue=extrapkt_rulenum['queue'][9], verify_mac=self.pf_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1", dst="2001::2", tc=2, hlim=20)/TCP(sport=32,dport=33)/Raw("x" * 20)], iface="%s")' % (self.pf_mac, extra_packet[10]['vlan'], self.tester_itf)) + self.sendpkt( + 'Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1", dst="2001::2", tc=2, hlim=20)/TCP(sport=32,dport=33)/Raw("x" * 20)' % ( + self.pf_mac, extra_packet[10]['vlan'])) self.verify_result("pf", expect_rxpkts="1", expect_queue=extrapkt_rulenum['queue'][10], verify_mac=self.pf_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1", dst="2001::2", tc=4, nh=132, hlim=40)/SCTP(sport=44,dport=45,tag=1)/SCTPChunkData(data="X" * 20)], iface="%s")' % (self.pf_mac, extra_packet[11]['vlan'], self.tester_itf)) + self.sendpkt( + 'Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1", dst="2001::2", tc=4, nh=132, hlim=40)/SCTP(sport=44,dport=45,tag=1)/SCTPChunkData(data="X" * 20)' % ( + self.pf_mac, extra_packet[11]['vlan'])) self.verify_result("pf", expect_rxpkts="1", expect_queue=extrapkt_rulenum['queue'][11], verify_mac=self.pf_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1", dst="2001::2", tc=4, nh=132, hlim=40)/SCTP(sport=44,dport=45,tag=1)/SCTPChunkData(data="X" * 20)], iface="%s")' % (self.pf_mac, extra_packet[14]['vlan'], self.tester_itf)) + self.sendpkt( + 'Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1", dst="2001::2", tc=4, nh=132, hlim=40)/SCTP(sport=44,dport=45,tag=1)/SCTPChunkData(data="X" * 20)' % ( + self.pf_mac, extra_packet[14]['vlan'])) self.verify_result("pf", expect_rxpkts="0", expect_queue="NULL", verify_mac=self.pf_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1", dst="2001::2", tc=2, hlim=20)/TCP(sport=32,dport=33)/Raw("x" * 20)], iface="%s")' % (self.outer_mac, extra_packet[15]['vlan'], self.tester_itf)) + self.sendpkt( + 'Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1", dst="2001::2", tc=2, hlim=20)/TCP(sport=32,dport=33)/Raw("x" * 20)' % ( + self.outer_mac, extra_packet[15]['vlan'])) self.verify_result("vf1", expect_rxpkts="0", expect_queue="NULL", verify_mac=self.outer_mac) rule_num = extrapkt_rulenum['rulenum'] @@ -963,7 +981,8 @@ class TestGeneric_flow_api(TestCase): """ self.verify(self.nic in ["niantic", "twinville", "sagepond", "sageville", "fortville_eagle", "fortville_spirit", - "fortville_spirit_single", "fortpark_TLV"], "%s nic not support fdir ipv4 filter" % self.nic) + "fortville_spirit_single", "fortpark_TLV"], + "%s nic not support fdir ipv4 filter" % self.nic) # i40e if (self.nic in ["fortville_eagle", "fortville_spirit", "fortville_spirit_single", "fortpark_TLV"]): @@ -990,22 +1009,33 @@ class TestGeneric_flow_api(TestCase): # create the flow rules basic_flow_actions = [ {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'proto'], 'actions': ['queue']}, - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'ttl', 'udp', 'sport', 'dport'], 'actions': ['queue']}, - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'tos', 'tcp', 'sport', 'dport'], 'actions': ['queue']}, - {'create': 'create', 'flows': ['vlan', 'ipv4', 'sip', 'dip', 'tos', 'ttl', 'sctp', 'sport', 'dport', 'tag'], 'actions': ['queue']}, - {'create': 'create', 'flows': ['vlan', 'ipv4', 'sip', 'dip', 'tos', 'ttl', 'sctp', 'sport', 'dport', 'tag'], 'actions': ['drop']}, + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'ttl', 'udp', 'sport', 'dport'], + 'actions': ['queue']}, + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'tos', 'tcp', 'sport', 'dport'], + 'actions': ['queue']}, + {'create': 'create', + 'flows': ['vlan', 'ipv4', 'sip', 'dip', 'tos', 'ttl', 'sctp', 'sport', 'dport', 'tag'], + 'actions': ['queue']}, + {'create': 'create', + 'flows': ['vlan', 'ipv4', 'sip', 'dip', 'tos', 'ttl', 'sctp', 'sport', 'dport', 'tag'], + 'actions': ['drop']}, {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'proto', 'vf0'], 'actions': ['invalid']}, {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'proto', 'vf0'], 'actions': ['queue']}, - {'create': 'create', 'flows': ['vlan', 'ipv4', 'sip', 'dip', 'tos', 'ttl', 'sctp', 'sport', 'dport', 'tag', 'vf1'], 'actions': ['queue']}, - {'create': 'create', 'flows': ['vlan', 'ipv4', 'sip', 'dip', 'tos', 'ttl', 'sctp', 'sport', 'dport', 'tag'], 'actions': ['passthru', 'flag']}, - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'ttl', 'udp', 'sport', 'dport'], 'actions': ['queue', 'flag']}, - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'tos', 'tcp', 'sport', 'dport'], 'actions': ['queue', 'mark']}, + {'create': 'create', + 'flows': ['vlan', 'ipv4', 'sip', 'dip', 'tos', 'ttl', 'sctp', 'sport', 'dport', 'tag', 'vf1'], + 'actions': ['queue']}, + {'create': 'create', + 'flows': ['vlan', 'ipv4', 'sip', 'dip', 'tos', 'ttl', 'sctp', 'sport', 'dport', 'tag'], + 'actions': ['passthru', 'flag']}, + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'ttl', 'udp', 'sport', 'dport'], + 'actions': ['queue', 'flag']}, + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'tos', 'tcp', 'sport', 'dport'], + 'actions': ['queue', 'mark']}, {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'proto'], 'actions': ['passthru', 'mark']} ] extrapkt_rulenum = self.all_flows_process(basic_flow_actions) extra_packet = extrapkt_rulenum['extrapacket'] - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP(src="192.168.0.3", dst="192.168.0.4", proto=%s)/Raw("x" * 20)], iface="%s")' % (self.pf_mac, extra_packet[0]['proto'], self.tester_itf)) + self.sendpkt('Ether(dst="%s")/IP(src="192.168.0.3", dst="192.168.0.4", proto=%s)/Raw("x" * 20)' % (self.pf_mac, extra_packet[0]['proto'])) self.verify_result("pf", expect_rxpkts="1", expect_queue="0", verify_mac=self.pf_mac) rule_num = extrapkt_rulenum['rulenum'] self.verify_rulenum(rule_num) @@ -1021,29 +1051,35 @@ class TestGeneric_flow_api(TestCase): if (self.nic in ["sagepond", "sageville"]): # create the flow rules basic_flow_actions = [ - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'udp', 'sport', 'dport'], 'actions': ['queue']}, - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'tcp', 'sport', 'dport'], 'actions': ['queue']}, - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'sctp', 'sport', 'dport'], 'actions': ['queue']}, - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'sctp', 'sport', 'dport'], 'actions': ['drop']}, + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'udp', 'sport', 'dport'], + 'actions': ['queue']}, + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'tcp', 'sport', 'dport'], + 'actions': ['queue']}, + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'sctp', 'sport', 'dport'], + 'actions': ['queue']}, + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'sctp', 'sport', 'dport'], + 'actions': ['drop']}, ] extrapkt_rulenum = self.all_flows_process(basic_flow_actions) extra_packet = extrapkt_rulenum['extrapacket'] - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP(src="%s", dst="%s")/SCTP(sport=%s,dport=%s)/Raw("x" * 20)], iface="%s")' % (self.pf_mac, extra_packet[2]['sip'], extra_packet[2]['dip'], extra_packet[2]['dport'], extra_packet[2]['sport'], self.tester_itf)) + self.sendpkt('Ether(dst="%s")/IP(src="%s", dst="%s")/SCTP(sport=%s,dport=%s)/Raw("x" * 20)'% ( + self.pf_mac, extra_packet[2]['sip'], extra_packet[2]['dip'], extra_packet[2]['dport'], + extra_packet[2]['sport'])) self.verify_result("pf", expect_rxpkts="1", expect_queue="0", verify_mac=self.pf_mac) rule_num = extrapkt_rulenum['rulenum'] self.verify_rulenum(rule_num) else: basic_flow_actions = [ - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'udp', 'sport', 'dport'], 'actions': ['queue']}, - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'tcp', 'sport', 'dport'], 'actions': ['queue']}, + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'udp', 'sport', 'dport'], + 'actions': ['queue']}, + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'tcp', 'sport', 'dport'], + 'actions': ['queue']}, {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'sctp'], 'actions': ['queue']}, {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'sctp'], 'actions': ['drop']}, ] extrapkt_rulenum = self.all_flows_process(basic_flow_actions) extra_packet = extrapkt_rulenum['extrapacket'] - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP(src="%s", dst="%s")/SCTP()/Raw("x" * 20)], iface="%s")' % (self.pf_mac, extra_packet[2]['dip'], extra_packet[2]['sip'], self.tester_itf)) + self.sendpkt('Ether(dst="%s")/IP(src="%s", dst="%s")/SCTP()/Raw("x" * 20)' % (self.pf_mac, extra_packet[2]['dip'], extra_packet[2]['sip'])) self.verify_result("pf", expect_rxpkts="1", expect_queue="0", verify_mac=self.pf_mac) rule_num = extrapkt_rulenum['rulenum'] self.verify_rulenum(rule_num) @@ -1054,7 +1090,8 @@ class TestGeneric_flow_api(TestCase): """ self.verify(self.nic in ["niantic", "twinville", "sagepond", "sageville", "fortville_eagle", "fortville_spirit", - "fortville_spirit_single", "fortpark_TLV"], "%s nic not support fdir ipv6 filter" % self.nic) + "fortville_spirit_single", "fortpark_TLV"], + "%s nic not support fdir ipv6 filter" % self.nic) # i40e if (self.nic in ["fortville_eagle", "fortville_spirit", "fortville_spirit_single", "fortpark_TLV"]): @@ -1077,19 +1114,30 @@ class TestGeneric_flow_api(TestCase): # create the flow rules basic_flow_actions = [ - {'create': 'create', 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'proto', 'tc', 'hop'], 'actions': ['queue']}, - {'create': 'create', 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'tc', 'hop', 'udp', 'sport', 'dport'], 'actions': ['queue']}, - {'create': 'create', 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'tc', 'hop', 'tcp', 'sport', 'dport'], 'actions': ['queue']}, - {'create': 'create', 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'tc', 'hop', 'sctp', 'sport', 'dport', 'tag'], 'actions': ['queue']}, - {'create': 'create', 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'proto', 'tc', 'hop', 'vf0'], 'actions': ['queue']}, - {'create': 'create', 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'tc', 'hop', 'tcp', 'sport', 'dport', 'vf1'], 'actions': ['queue']}, - {'create': 'create', 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'tc', 'hop', 'sctp', 'sport', 'dport', 'tag'], 'actions': ['drop']}, - {'create': 'create', 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'tc', 'hop', 'tcp', 'sport', 'dport', 'vf1'], 'actions': ['drop']}, + {'create': 'create', 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'proto', 'tc', 'hop'], + 'actions': ['queue']}, + {'create': 'create', 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'tc', 'hop', 'udp', 'sport', 'dport'], + 'actions': ['queue']}, + {'create': 'create', 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'tc', 'hop', 'tcp', 'sport', 'dport'], + 'actions': ['queue']}, + {'create': 'create', + 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'tc', 'hop', 'sctp', 'sport', 'dport', 'tag'], + 'actions': ['queue']}, + {'create': 'create', 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'proto', 'tc', 'hop', 'vf0'], + 'actions': ['queue']}, + {'create': 'create', + 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'tc', 'hop', 'tcp', 'sport', 'dport', 'vf1'], + 'actions': ['queue']}, + {'create': 'create', + 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'tc', 'hop', 'sctp', 'sport', 'dport', 'tag'], + 'actions': ['drop']}, + {'create': 'create', + 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'tc', 'hop', 'tcp', 'sport', 'dport', 'vf1'], + 'actions': ['drop']}, ] extrapkt_rulenum = self.all_flows_process(basic_flow_actions) extra_packet = extrapkt_rulenum['extrapacket'] - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1", dst="2001::2", tc=2, hlim=20)/UDP(sport=22,dport=23)/Raw("x" * 20)], iface="%s")' % (self.pf_mac, extra_packet[1]['vlan'], self.tester_itf)) + self.sendpkt('Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1", dst="2001::2", tc=2, hlim=20)/UDP(sport=22,dport=23)/Raw("x" * 20)' % (self.pf_mac, extra_packet[1]['vlan'])) self.verify_result("pf", expect_rxpkts="1", expect_queue="0", verify_mac=self.pf_mac) rule_num = extrapkt_rulenum['rulenum'] self.verify_rulenum(rule_num) @@ -1106,51 +1154,55 @@ class TestGeneric_flow_api(TestCase): basic_flow_actions = [ {'create': 'create', 'flows': ['fuzzy', 'ipv6', 'sip', 'dip'], 'actions': ['queue']}, {'create': 'create', 'flows': ['fuzzy', 'ipv4', 'sip', 'dip'], 'actions': ['queue']}, - {'create': 'create', 'flows': ['fuzzy', 'ipv4', 'sip', 'dip', 'udp', 'sport', 'dport'], 'actions': ['queue']}, - {'create': 'create', 'flows': ['fuzzy', 'ipv6', 'sip', 'dip', 'tcp', 'sport', 'dport'], 'actions': ['queue']}, - {'create': 'create', 'flows': ['fuzzy', 'ipv4', 'sip', 'dip', 'tcp', 'sport', 'dport'], 'actions': ['queue']}, + {'create': 'create', 'flows': ['fuzzy', 'ipv4', 'sip', 'dip', 'udp', 'sport', 'dport'], + 'actions': ['queue']}, + {'create': 'create', 'flows': ['fuzzy', 'ipv6', 'sip', 'dip', 'tcp', 'sport', 'dport'], + 'actions': ['queue']}, + {'create': 'create', 'flows': ['fuzzy', 'ipv4', 'sip', 'dip', 'tcp', 'sport', 'dport'], + 'actions': ['queue']}, {'create': 'create', 'flows': ['fuzzy', 'ipv6', 'sip', 'dip', 'sctp'], 'actions': ['queue']}, {'create': 'create', 'flows': ['fuzzy', 'ipv4', 'sip', 'dip', 'sctp'], 'actions': ['queue']}, ] extrapkt_rulenum = self.all_flows_process(basic_flow_actions) self.dut.send_expect( - "flow create 0 ingress pattern fuzzy thresh spec 2 thresh last 5 thresh mask 0xffffffff / ipv6 src is 2001::1 dst is 2001::2 / udp src is 22 dst is 23 / end actions queue index 1 / end", "created") + "flow create 0 ingress pattern fuzzy thresh spec 2 thresh last 5 thresh mask 0xffffffff / ipv6 src is 2001::1 dst is 2001::2 / udp src is 22 dst is 23 / end actions queue index 1 / end", + "created") extra_packet = extrapkt_rulenum['extrapacket'] - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IPv6(src="2001::1", dst="2001::2",nh=132)/SCTP()/Raw("x" * 20)], iface="%s")' % (self.pf_mac, self.tester_itf)) + self.sendpkt('Ether(dst="%s")/IPv6(src="2001::1", dst="2001::2",nh=132)/SCTP()/Raw("x" * 20)' % self.pf_mac) self.verify_result("pf", expect_rxpkts="1", expect_queue="0", verify_mac=self.pf_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2")/SCTP()/Raw("x" * 20)], iface="%s")' % (self.pf_mac, self.tester_itf)) + self.sendpkt('Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2")/SCTP()/Raw("x" * 20)' % self.pf_mac) self.verify_result("pf", expect_rxpkts="1", expect_queue="0", verify_mac=self.pf_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IPv6(src="2001::1", dst="2001::2")/UDP(sport=22,dport=23)/Raw("x" * 20)], iface="%s")' % (self.pf_mac, self.tester_itf)) + self.sendpkt('Ether(dst="%s")/IPv6(src="2001::1", dst="2001::2")/UDP(sport=22,dport=23)/Raw("x" * 20)' % self.pf_mac) self.verify_result("pf", expect_rxpkts="1", expect_queue="1", verify_mac=self.pf_mac) rule_num = extrapkt_rulenum['rulenum'] - self.verify_rulenum(rule_num+1) + self.verify_rulenum(rule_num + 1) elif (self.nic in ["sagepond", "sageville"]): # create the flow rules basic_flow_actions = [ - {'create': 'create', 'flows': ['fuzzy', 'ipv4', 'sip', 'dip', 'udp', 'sport', 'dport'], 'actions': ['queue']}, - {'create': 'create', 'flows': ['fuzzy', 'ipv6', 'sip', 'dip', 'tcp', 'sport', 'dport'], 'actions': ['queue']}, - {'create': 'create', 'flows': ['fuzzy', 'ipv4', 'sip', 'dip', 'tcp', 'sport', 'dport'], 'actions': ['queue']}, - {'create': 'create', 'flows': ['fuzzy', 'ipv6', 'sip', 'dip', 'sctp', 'sport', 'dport'], 'actions': ['queue']}, - {'create': 'create', 'flows': ['fuzzy', 'ipv4', 'sip', 'dip', 'sctp', 'sport', 'dport'], 'actions': ['queue']}, + {'create': 'create', 'flows': ['fuzzy', 'ipv4', 'sip', 'dip', 'udp', 'sport', 'dport'], + 'actions': ['queue']}, + {'create': 'create', 'flows': ['fuzzy', 'ipv6', 'sip', 'dip', 'tcp', 'sport', 'dport'], + 'actions': ['queue']}, + {'create': 'create', 'flows': ['fuzzy', 'ipv4', 'sip', 'dip', 'tcp', 'sport', 'dport'], + 'actions': ['queue']}, + {'create': 'create', 'flows': ['fuzzy', 'ipv6', 'sip', 'dip', 'sctp', 'sport', 'dport'], + 'actions': ['queue']}, + {'create': 'create', 'flows': ['fuzzy', 'ipv4', 'sip', 'dip', 'sctp', 'sport', 'dport'], + 'actions': ['queue']}, ] extrapkt_rulenum = self.all_flows_process(basic_flow_actions) self.dut.send_expect( - "flow create 0 ingress pattern fuzzy thresh spec 2 thresh last 5 thresh mask 0xffffffff / ipv6 src is 2001::1 dst is 2001::2 / udp src is 22 dst is 23 / end actions queue index 1 / end", "created") + "flow create 0 ingress pattern fuzzy thresh spec 2 thresh last 5 thresh mask 0xffffffff / ipv6 src is 2001::1 dst is 2001::2 / udp src is 22 dst is 23 / end actions queue index 1 / end", + "created") extra_packet = extrapkt_rulenum['extrapacket'] - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IPv6(src="%s", dst="%s", nh=132)/SCTP(sport=32,dport=33,tag=1)/Raw("x" * 20)], iface="%s")' % (self.pf_mac, extra_packet[3]['sip'], extra_packet[3]['dip'], self.tester_itf)) + self.sendpkt('Ether(dst="%s")/IPv6(src="%s", dst="%s", nh=132)/SCTP(sport=32,dport=33,tag=1)/Raw("x" * 20)' % (self.pf_mac, extra_packet[3]['sip'], extra_packet[3]['dip'])) self.verify_result("pf", expect_rxpkts="1", expect_queue="0", verify_mac=self.pf_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP(src="%s", dst="%s", proto=132)/SCTP(sport=32,dport=33)/Raw("x" * 20)], iface="%s")' % (self.pf_mac, extra_packet[4]['dip'], extra_packet[4]['sip'], self.tester_itf)) + self.sendpkt('Ether(dst="%s")/IP(src="%s", dst="%s", proto=132)/SCTP(sport=32,dport=33)/Raw("x" * 20)' % (self.pf_mac, extra_packet[4]['dip'], extra_packet[4]['sip'])) self.verify_result("pf", expect_rxpkts="1", expect_queue="0", verify_mac=self.pf_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IPv6(src="2001::1", dst="2001::2")/UDP(sport=22,dport=23)/Raw("x" * 20)], iface="%s")' % (self.pf_mac, self.tester_itf)) + self.sendpkt('Ether(dst="%s")/IPv6(src="2001::1", dst="2001::2")/UDP(sport=22,dport=23)/Raw("x" * 20)' % self.pf_mac) self.verify_result("pf", expect_rxpkts="1", expect_queue="1", verify_mac=self.pf_mac) rule_num = extrapkt_rulenum['rulenum'] - self.verify_rulenum(rule_num+1) + self.verify_rulenum(rule_num + 1) def test_fdir_for_flexbytes(self): """ @@ -1158,7 +1210,8 @@ class TestGeneric_flow_api(TestCase): """ self.verify(self.nic in ["niantic", "twinville", "sagepond", "sageville", "fortville_eagle", "fortville_spirit", - "fortville_spirit_single", "fortpark_TLV"], "%s nic not support fdir flexbytes filter" % self.nic) + "fortville_spirit_single", "fortpark_TLV"], + "%s nic not support fdir flexbytes filter" % self.nic) # i40e if (self.nic in ["fortville_eagle", "fortville_spirit", "fortville_spirit_single", "fortpark_TLV"]): @@ -1171,46 +1224,47 @@ class TestGeneric_flow_api(TestCase): # creat the flow rules # l2-payload exceeds the max length of raw match is 16bytes self.dut.send_expect( - "flow create 0 ingress pattern eth type is 0x0807 / raw relative is 1 pattern is abcdefghijklmnopq / end actions queue index 1 / end", "Exceeds maxmial payload limit") + "flow create 0 ingress pattern eth type is 0x0807 / raw relative is 1 pattern is abcdefghijklmnopq / end actions queue index 1 / end", + "Exceeds maxmial payload limit") # l2-payload equal the max length of raw match is 16bytes self.dut.send_expect( - "flow create 0 ingress pattern eth type is 0x0807 / raw relative is 1 pattern is abcdefghijklmnop / end actions queue index 1 / end", "created") + "flow create 0 ingress pattern eth type is 0x0807 / raw relative is 1 pattern is abcdefghijklmnop / end actions queue index 1 / end", + "created") # ipv4-other the most 3 fields can be matched, and the max sum bytes of the three fields is 16 bytes. self.dut.send_expect( - "flow create 0 ingress pattern eth / vlan tci is 4095 / ipv4 proto is 255 ttl is 40 / raw relative is 1 offset is 2 pattern is ab / raw relative is 1 offset is 10 pattern is abcdefghij / raw relative is 1 offset is 0 pattern is abcd / end actions queue index 2 / end", "created") + "flow create 0 ingress pattern eth / vlan tci is 4095 / ipv4 proto is 255 ttl is 40 / raw relative is 1 offset is 2 pattern is ab / raw relative is 1 offset is 10 pattern is abcdefghij / raw relative is 1 offset is 0 pattern is abcd / end actions queue index 2 / end", + "created") # ipv4-udp self.dut.send_expect( - "flow create 0 ingress pattern eth / ipv4 src is 2.2.2.4 dst is 2.2.2.5 / udp src is 22 dst is 23 / raw relative is 1 offset is 2 pattern is fhds / end actions queue index 3 / end", "created") + "flow create 0 ingress pattern eth / ipv4 src is 2.2.2.4 dst is 2.2.2.5 / udp src is 22 dst is 23 / raw relative is 1 offset is 2 pattern is fhds / end actions queue index 3 / end", + "created") # ipv4-tcp self.dut.send_expect( - "flow create 0 ingress pattern eth / ipv4 src is 2.2.2.4 dst is 2.2.2.5 tos is 4 ttl is 3 / tcp src is 32 dst is 33 / raw relative is 1 offset is 2 pattern is hijk / end actions queue index 4 / end", "created") + "flow create 0 ingress pattern eth / ipv4 src is 2.2.2.4 dst is 2.2.2.5 tos is 4 ttl is 3 / tcp src is 32 dst is 33 / raw relative is 1 offset is 2 pattern is hijk / end actions queue index 4 / end", + "created") # ipv4-sctp self.dut.send_expect( - "flow create 0 ingress pattern eth / ipv4 src is 2.2.2.4 dst is 2.2.2.5 / sctp src is 42 / raw relative is 1 offset is 2 pattern is abcd / end actions queue index 5 / end", "created") + "flow create 0 ingress pattern eth / ipv4 src is 2.2.2.4 dst is 2.2.2.5 / sctp src is 42 / raw relative is 1 offset is 2 pattern is abcd / end actions queue index 5 / end", + "created") # send the packets and verify the results - self.tester.scapy_append( - 'sendp([Ether(dst="%s", type=0x0807)/Raw(load="abcdefghijklmnop")], iface="%s")' % (self.pf_mac, self.tester_itf)) + self.sendpkt('Ether(dst="%s", type=0x0807)/Raw(load="abcdefghijklmnop")' % self.pf_mac) self.verify_result("pf", expect_rxpkts="1", expect_queue="1", verify_mac=self.pf_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/Dot1Q(vlan=4095)/IP(src="192.168.0.1", dst="192.168.0.2", proto=255, ttl=40)/Raw(load="xxabxxxxxxxxxxabcdefghijabcdefg")], iface="%s")' % (self.pf_mac, self.tester_itf)) + self.sendpkt('Ether(dst="%s")/Dot1Q(vlan=4095)/IP(src="192.168.0.1", dst="192.168.0.2", proto=255, ttl=40)/Raw(load="xxabxxxxxxxxxxabcdefghijabcdefg")' % self.pf_mac) self.verify_result("pf", expect_rxpkts="1", expect_queue="2", verify_mac=self.pf_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP(src="2.2.2.4", dst="2.2.2.5")/UDP(sport=22,dport=23)/Raw(load="fhfhdsdsfwef")], iface="%s")' % (self.pf_mac, self.tester_itf)) + self.sendpkt('Ether(dst="%s")/IP(src="2.2.2.4", dst="2.2.2.5")/UDP(sport=22,dport=23)/Raw(load="fhfhdsdsfwef")' % self.pf_mac) self.verify_result("pf", expect_rxpkts="1", expect_queue="3", verify_mac=self.pf_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP(src="2.2.2.4", dst="2.2.2.5", tos=4, ttl=3)/TCP(sport=32,dport=33)/Raw(load="fhhijk")], iface="%s")' % (self.pf_mac, self.tester_itf)) + self.sendpkt( + 'Ether(dst="%s")/IP(src="2.2.2.4", dst="2.2.2.5", tos=4, ttl=3)/TCP(sport=32,dport=33)/Raw(load="fhhijk")' % self.pf_mac) self.verify_result("pf", expect_rxpkts="1", expect_queue="4", verify_mac=self.pf_mac) - - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP(src="2.2.2.4", dst="2.2.2.5")/SCTP(sport=42,dport=43,tag=1)/Raw(load="xxabcdefghijklmnopqrst")], iface="%s")' % (self.pf_mac, self.tester_itf)) + self.sendpkt( + 'Ether(dst="%s")/IP(src="2.2.2.4", dst="2.2.2.5")/SCTP(sport=42,dport=43,tag=1)/Raw(load="xxabcdefghijklmnopqrst")' % self.pf_mac) self.verify_result("pf", expect_rxpkts="1", expect_queue="5", verify_mac=self.pf_mac) - - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP(src="2.2.2.4", dst="2.2.2.5")/SCTP(sport=42,dport=43,tag=1)/Raw(load="xxabxxxabcddxxabcdefghijklmn")], iface="%s")' % (self.outer_mac, self.tester_itf)) + self.sendpkt( + 'Ether(dst="%s")/IP(src="2.2.2.4", dst="2.2.2.5")/SCTP(sport=42,dport=43,tag=1)/Raw(load="xxabxxxabcddxxabcdefghijklmn")' % self.outer_mac) self.verify_result("pf", expect_rxpkts="1", expect_queue="0", verify_mac=self.outer_mac) self.verify_rulenum(5) @@ -1226,11 +1280,12 @@ class TestGeneric_flow_api(TestCase): # ipv6-tcp self.dut.send_expect( - "flow create 0 ingress pattern eth / vlan tci is 1 / ipv6 src is 2001::1 dst is 2001::2 tc is 3 hop is 30 / tcp src is 32 dst is 33 / raw relative is 1 offset is 0 pattern is hijk / raw relative is 1 offset is 8 pattern is abcdefgh / end actions queue index 6 / end", "created") + "flow create 0 ingress pattern eth / vlan tci is 1 / ipv6 src is 2001::1 dst is 2001::2 tc is 3 hop is 30 / tcp src is 32 dst is 33 / raw relative is 1 offset is 0 pattern is hijk / raw relative is 1 offset is 8 pattern is abcdefgh / end actions queue index 6 / end", + "created") # send the packet and verify the result - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/Dot1Q(vlan=1)/IPv6(src="2001::1", dst="2001::2", tc=3, hlim=30)/TCP(sport=32,dport=33)/Raw(load="hijkabcdefghabcdefghijklmn")], iface="%s")' % (self.outer_mac, self.tester_itf)) + self.sendpkt( + 'Ether(dst="%s")/Dot1Q(vlan=1)/IPv6(src="2001::1", dst="2001::2", tc=3, hlim=30)/TCP(sport=32,dport=33)/Raw(load="hijkabcdefghabcdefghijklmn")' % self.outer_mac) self.verify_result("pf", expect_rxpkts="1", expect_queue="6", verify_mac=self.outer_mac) # ixgbe @@ -1243,11 +1298,12 @@ class TestGeneric_flow_api(TestCase): # ipv4-udp-flexbytes self.dut.send_expect( - "flow create 0 ingress pattern eth / ipv4 src is 192.168.0.1 dst is 192.168.0.2 / udp src is 24 dst is 25 / raw relative is 0 search is 0 offset is 44 limit is 0 pattern is 86 / end actions queue index 1 / end", "created") + "flow create 0 ingress pattern eth / ipv4 src is 192.168.0.1 dst is 192.168.0.2 / udp src is 24 dst is 25 / raw relative is 0 search is 0 offset is 44 limit is 0 pattern is 86 / end actions queue index 1 / end", + "created") # send the packet and verify the result - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=24,dport=25)/Raw(load="xx86ddef")], iface="%s")' % (self.outer_mac, self.tester_itf)) + self.sendpkt( + 'Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=24,dport=25)/Raw(load="xx86ddef")' % self.outer_mac) self.verify_result("pf", expect_rxpkts="1", expect_queue="1", verify_mac=self.outer_mac) self.dut.send_expect("quit", "# ") @@ -1262,15 +1318,15 @@ class TestGeneric_flow_api(TestCase): # ipv4-tcp-flexbytes spec-mask self.dut.send_expect( - "flow create 0 ingress pattern eth / ipv4 src is 192.168.0.3 dst is 192.168.0.4 / tcp src is 22 dst is 23 / raw relative spec 0 relative mask 1 search spec 0 search mask 1 offset spec 54 offset mask 0xffffffff limit spec 0 limit mask 0xffff pattern is ab pattern is cd / end actions queue index 2 / end", "created") + "flow create 0 ingress pattern eth / ipv4 src is 192.168.0.3 dst is 192.168.0.4 / tcp src is 22 dst is 23 / raw relative spec 0 relative mask 1 search spec 0 search mask 1 offset spec 54 offset mask 0xffffffff limit spec 0 limit mask 0xffff pattern is ab pattern is cd / end actions queue index 2 / end", + "created") # send the packet and verify the result - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP(src="192.168.0.3", dst="192.168.0.4")/TCP(sport=22,dport=23)/Raw(load="abcdxxx")], iface="%s")' % (self.outer_mac, self.tester_itf)) + self.sendpkt( + 'Ether(dst="%s")/IP(src="192.168.0.3", dst="192.168.0.4")/TCP(sport=22,dport=23)/Raw(load="abcdxxx")' % self.outer_mac) self.verify_result("pf", expect_rxpkts="1", expect_queue="0", verify_mac=self.outer_mac) - - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP(src="192.168.0.3", dst="192.168.0.4")/TCP(sport=22,dport=23)/Raw(load="cdcdxxx")], iface="%s")' % (self.outer_mac, self.tester_itf)) + self.sendpkt( + 'Ether(dst="%s")/IP(src="192.168.0.3", dst="192.168.0.4")/TCP(sport=22,dport=23)/Raw(load="cdcdxxx")' % self.outer_mac) self.verify_result("pf", expect_rxpkts="1", expect_queue="2", verify_mac=self.outer_mac) self.dut.send_expect("quit", "# ") @@ -1286,17 +1342,19 @@ class TestGeneric_flow_api(TestCase): # ipv4-sctp-flexbytes if (self.nic in ["sagepond", "sageville"]): self.dut.send_expect( - "flow create 0 ingress pattern fuzzy thresh is 6 / eth / ipv4 src is 192.168.0.1 dst is 192.168.0.2 / sctp src is 24 dst is 25 / raw relative is 0 search is 0 offset is 48 limit is 0 pattern is ab / end actions queue index 3 / end", "created") + "flow create 0 ingress pattern fuzzy thresh is 6 / eth / ipv4 src is 192.168.0.1 dst is 192.168.0.2 / sctp src is 24 dst is 25 / raw relative is 0 search is 0 offset is 48 limit is 0 pattern is ab / end actions queue index 3 / end", + "created") else: self.dut.send_expect( - "flow create 0 ingress pattern fuzzy thresh is 6 / eth / ipv4 src is 192.168.0.1 dst is 192.168.0.2 / sctp / raw relative is 0 search is 0 offset is 48 limit is 0 pattern is ab / end actions queue index 3 / end", "created") + "flow create 0 ingress pattern fuzzy thresh is 6 / eth / ipv4 src is 192.168.0.1 dst is 192.168.0.2 / sctp / raw relative is 0 search is 0 offset is 48 limit is 0 pattern is ab / end actions queue index 3 / end", + "created") # send the packet and verify the result - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2")/SCTP(sport=24,dport=25)/Raw(load="xxabcdef")], iface="%s")' % (self.outer_mac, self.tester_itf)) + self.sendpkt( + 'Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2")/SCTP(sport=24,dport=25)/Raw(load="xxabcdef")' % self.outer_mac) self.verify_result("pf", expect_rxpkts="1", expect_queue="3", verify_mac=self.outer_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2")/SCTP(sport=24,dport=25)/Raw(load="xxaccdef")], iface="%s")' % (self.outer_mac, self.tester_itf)) + self.sendpkt( + 'Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2")/SCTP(sport=24,dport=25)/Raw(load="xxaccdef")' % self.outer_mac) self.verify_result("pf", expect_rxpkts="1", expect_queue="0", verify_mac=self.outer_mac) # ipv6-other-flexbytes @@ -1311,12 +1369,13 @@ class TestGeneric_flow_api(TestCase): time.sleep(2) self.dut.send_expect( - "flow create 0 ingress pattern fuzzy thresh is 6 / ipv6 src is 2001::1 dst is 2001::2 / raw relative is 0 search is 0 offset is 56 limit is 0 pattern is 86 / end actions queue index 4 / end", "created") - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IPv6(src="2001::1", dst="2001::2")/Raw(load="xx86abcd")], iface="%s")' % (self.outer_mac, self.tester_itf)) + "flow create 0 ingress pattern fuzzy thresh is 6 / ipv6 src is 2001::1 dst is 2001::2 / raw relative is 0 search is 0 offset is 56 limit is 0 pattern is 86 / end actions queue index 4 / end", + "created") + self.sendpkt( + 'Ether(dst="%s")/IPv6(src="2001::1", dst="2001::2")/Raw(load="xx86abcd")' % self.outer_mac) self.verify_result("pf", expect_rxpkts="1", expect_queue="4", verify_mac=self.outer_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IPv6(src="2001::1", dst="2001::2")/Raw(load="xxx86abcd")], iface="%s")' % (self.outer_mac, self.tester_itf)) + self.sendpkt( + 'Ether(dst="%s")/IPv6(src="2001::1", dst="2001::2")/Raw(load="xxx86abcd")' % self.outer_mac) self.verify_result("pf", expect_rxpkts="1", expect_queue="0", verify_mac=self.outer_mac) def test_flexbytes_filter(self): @@ -1334,79 +1393,77 @@ class TestGeneric_flow_api(TestCase): # create the flow rules # l2_payload self.dut.send_expect( - "flow create 0 ingress pattern raw relative is 0 offset is 14 pattern is fhds / end actions queue index 1 / end", "created") + "flow create 0 ingress pattern raw relative is 0 offset is 14 pattern is fhds / end actions queue index 1 / end", + "created") # ipv4 packet self.dut.send_expect( - "flow create 0 ingress pattern raw relative is 0 offset is 34 pattern is ab / end actions queue index 2 / end", "created") + "flow create 0 ingress pattern raw relative is 0 offset is 34 pattern is ab / end actions queue index 2 / end", + "created") # ipv6 packet self.dut.send_expect( - "flow create 0 ingress pattern raw relative is 0 offset is 58 pattern is efgh / end actions queue index 3 / end", "created") + "flow create 0 ingress pattern raw relative is 0 offset is 58 pattern is efgh / end actions queue index 3 / end", + "created") # 3 fields relative is 0 self.dut.send_expect( - "flow create 0 ingress pattern raw relative is 0 offset is 38 pattern is ab / raw relative is 0 offset is 34 pattern is cd / raw relative is 0 offset is 42 pattern is efgh / end actions queue index 4 / end", "created") + "flow create 0 ingress pattern raw relative is 0 offset is 38 pattern is ab / raw relative is 0 offset is 34 pattern is cd / raw relative is 0 offset is 42 pattern is efgh / end actions queue index 4 / end", + "created") # 4 fields relative is 0 and 1 self.dut.send_expect( - "flow create 0 ingress pattern raw relative is 0 offset is 48 pattern is ab / raw relative is 1 offset is 0 pattern is cd / raw relative is 0 offset is 44 pattern is efgh / raw relative is 1 offset is 10 pattern is hijklmnopq / end actions queue index 5 / end", "created") + "flow create 0 ingress pattern raw relative is 0 offset is 48 pattern is ab / raw relative is 1 offset is 0 pattern is cd / raw relative is 0 offset is 44 pattern is efgh / raw relative is 1 offset is 10 pattern is hijklmnopq / end actions queue index 5 / end", + "created") # 3 fields offset confilict self.dut.send_expect( - "flow create 0 ingress pattern raw relative is 0 offset is 64 pattern is ab / raw relative is 1 offset is 4 pattern is cdefgh / raw relative is 0 offset is 68 pattern is klmn / end actions queue index 6 / end", "created") + "flow create 0 ingress pattern raw relative is 0 offset is 64 pattern is ab / raw relative is 1 offset is 4 pattern is cdefgh / raw relative is 0 offset is 68 pattern is klmn / end actions queue index 6 / end", + "created") # send the packet and verify the result - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/Raw(load="fhdsab")], iface="%s")' % (self.outer_mac, self.tester_itf)) + self.sendpkt('Ether(dst="%s")/Raw(load="fhdsab")' % self.outer_mac) self.verify_result("pf", expect_rxpkts="1", expect_queue="1", verify_mac=self.outer_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/Raw(load="afhdsb")], iface="%s")' % (self.outer_mac, self.tester_itf)) + self.sendpkt('Ether(dst="%s")/Raw(load="afhdsb")' % self.outer_mac) self.verify_result("pf", expect_rxpkts="1", expect_queue="0", verify_mac=self.outer_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2")/Raw(load="abcdef")], iface="%s")' % (self.outer_mac, self.tester_itf)) + self.sendpkt('Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2")/Raw(load="abcdef")' % self.outer_mac) self.verify_result("pf", expect_rxpkts="1", expect_queue="2", verify_mac=self.outer_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IPv6(src="2001::1", dst="2001::2")/Raw(load="xxxxefgh")], iface="%s")' % (self.outer_mac, self.tester_itf)) + self.sendpkt('Ether(dst="%s")/IPv6(src="2001::1", dst="2001::2")/Raw(load="xxxxefgh")' % self.outer_mac) self.verify_result("pf", expect_rxpkts="1", expect_queue="3", verify_mac=self.outer_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IPv6(src="2001::1", dst="2001::2")/TCP(sport=32,dport=33)/Raw(load="abcdefgh")], iface="%s")' % (self.outer_mac, self.tester_itf)) + self.sendpkt('Ether(dst="%s")/IPv6(src="2001::1", dst="2001::2")/TCP(sport=32,dport=33)/Raw(load="abcdefgh")' % self.outer_mac) self.verify_result("pf", expect_rxpkts="1", expect_queue="0", verify_mac=self.outer_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2")/Raw(load="cdxxabxxefghxxxx")], iface="%s")' % (self.outer_mac, self.tester_itf)) + self.sendpkt('Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2")/Raw(load="cdxxabxxefghxxxx")' % self.outer_mac) self.verify_result("pf", expect_rxpkts="1", expect_queue="4", verify_mac=self.outer_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2", tos=4, ttl=3)/UDP(sport=32,dport=33)/Raw(load="xxefghabcdxxxxxxhijklmnopqxxxx")], iface="%s")' % (self.outer_mac, self.tester_itf)) + self.sendpkt('Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2", tos=4, ttl=3)/UDP(sport=32,dport=33)/Raw(load="xxefghabcdxxxxxxhijklmnopqxxxx")' % self.outer_mac) self.verify_result("pf", expect_rxpkts="1", expect_queue="5", verify_mac=self.outer_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2")/TCP(sport=22,dport=23)/Raw(load="xxxxxxxxxxabxxklmnefgh")], iface="%s")' % (self.outer_mac, self.tester_itf)) + self.sendpkt('Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2")/TCP(sport=22,dport=23)/Raw(load="xxxxxxxxxxabxxklmnefgh")' % self.outer_mac) self.verify_result("pf", expect_rxpkts="1", expect_queue="6", verify_mac=self.outer_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2")/TCP(sport=22,dport=23)/Raw(load="xxxxxxxxxxabxxklcdefgh")], iface="%s")' % (self.outer_mac, self.tester_itf)) + self.sendpkt('Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2")/TCP(sport=22,dport=23)/Raw(load="xxxxxxxxxxabxxklcdefgh")' % self.outer_mac) self.verify_result("pf", expect_rxpkts="1", expect_queue="0", verify_mac=self.outer_mac) self.dut.send_expect("flow flush 0", "testpmd> ", 120) # 1 field 128bytes self.dut.send_expect( - "flow create 0 ingress pattern raw relative is 0 offset is 128 pattern is ab / end actions queue index 1 / end", "Failed to create flow") + "flow create 0 ingress pattern raw relative is 0 offset is 128 pattern is ab / end actions queue index 1 / end", + "Failed to create flow") self.dut.send_expect( - "flow create 0 ingress pattern raw relative is 0 offset is 126 pattern is abcd / end actions queue index 1 / end", "Failed to create flow") + "flow create 0 ingress pattern raw relative is 0 offset is 126 pattern is abcd / end actions queue index 1 / end", + "Failed to create flow") self.dut.send_expect( - "flow create 0 ingress pattern raw relative is 0 offset is 126 pattern is ab / end actions queue index 1 / end", "created") + "flow create 0 ingress pattern raw relative is 0 offset is 126 pattern is ab / end actions queue index 1 / end", + "created") # 2 field 128bytes self.dut.send_expect( - "flow create 0 ingress pattern raw relative is 0 offset is 68 pattern is ab / raw relative is 1 offset is 58 pattern is cd / end actions queue index 2 / end", "Failed to create flow") + "flow create 0 ingress pattern raw relative is 0 offset is 68 pattern is ab / raw relative is 1 offset is 58 pattern is cd / end actions queue index 2 / end", + "Failed to create flow") self.dut.send_expect( - "flow create 0 ingress pattern raw relative is 0 offset is 68 pattern is ab / raw relative is 1 offset is 56 pattern is cd / end actions queue index 2 / end", "created") + "flow create 0 ingress pattern raw relative is 0 offset is 68 pattern is ab / raw relative is 1 offset is 56 pattern is cd / end actions queue index 2 / end", + "created") # send the packet and verify the result - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2")/TCP(sport=22,dport=23)/Raw(load="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxab")], iface="%s")' % (self.outer_mac, self.tester_itf)) + self.sendpkt('Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2")/TCP(sport=22,dport=23)/Raw(load="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxab")' % self.outer_mac) self.verify_result("pf", expect_rxpkts="1", expect_queue="1", verify_mac=self.outer_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2")/TCP(sport=22,dport=23)/Raw(load="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxcb")], iface="%s")' % (self.outer_mac, self.tester_itf)) + self.sendpkt('Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2")/TCP(sport=22,dport=23)/Raw(load="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxcb")' % self.outer_mac) self.verify_result("pf", expect_rxpkts="1", expect_queue="0", verify_mac=self.outer_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2")/TCP(sport=22,dport=23)/Raw(load="xxxxxxxxxxxxxxabxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxcd")], iface="%s")' % (self.outer_mac, self.tester_itf)) + self.sendpkt('Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2")/TCP(sport=22,dport=23)/Raw(load="xxxxxxxxxxxxxxabxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxcd")' % self.outer_mac) self.verify_result("pf", expect_rxpkts="1", expect_queue="2", verify_mac=self.outer_mac) - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2")/TCP(sport=22,dport=23)/Raw(load="xxxxxxxxxxxxxxabxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxce")], iface="%s")' % (self.outer_mac, self.tester_itf)) + self.sendpkt('Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2")/TCP(sport=22,dport=23)/Raw(load="xxxxxxxxxxxxxxabxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxce")' % self.outer_mac) self.verify_result("pf", expect_rxpkts="1", expect_queue="0", verify_mac=self.outer_mac) self.verify_rulenum(2) @@ -1481,7 +1538,8 @@ class TestGeneric_flow_api(TestCase): only supported by i40e """ self.verify(self.nic in ["fortville_eagle", "fortville_spirit", - "fortville_spirit_single", "fortpark_TLV"], "%s nic not support tunnel vxlan filter" % self.nic) + "fortville_spirit_single", "fortpark_TLV"], + "%s nic not support tunnel vxlan filter" % self.nic) self.setup_env() self.pmdout.start_testpmd("%s" % self.pf_cores, "--disable-rss --rxq=%d --txq=%d" % (MAX_QUEUE+1, MAX_QUEUE+1), "-w %s --file-prefix=pf --socket-mem 1024,1024 --legacy-mem" % self.pf_pci) @@ -1506,32 +1564,35 @@ class TestGeneric_flow_api(TestCase): {'create': 'create', 'flows': ['ipv4', 'udp', 'vxlan', 'ineth'], 'actions': ['pf', 'queue']}, {'create': 'create', 'flows': ['ipv4', 'udp', 'vxlan', 'vni', 'ineth'], 'actions': ['pf', 'queue']}, {'create': 'create', 'flows': ['ipv4', 'udp', 'vxlan', 'ineth', 'invlan'], 'actions': ['pf', 'queue']}, - {'create': 'create', 'flows': ['ipv4', 'udp', 'vxlan', 'vni', 'ineth', 'invlan'], 'actions': ['pf', 'queue']}, - {'create': 'create', 'flows': ['dst_mac', 'ipv4', 'udp', 'vxlan', 'vni', 'ineth'], 'actions': ['pf', 'queue']}, - {'create': 'create', 'flows': ['ipv4', 'udp', 'vxlan', 'vni', 'ineth', 'invlan'], 'actions': ['vf0', 'queue']}, - {'create': 'create', 'flows': ['dst_mac', 'ipv4', 'udp', 'vxlan', 'vni', 'ineth'], 'actions': ['vf1', 'queue']}, + {'create': 'create', 'flows': ['ipv4', 'udp', 'vxlan', 'vni', 'ineth', 'invlan'], + 'actions': ['pf', 'queue']}, + {'create': 'create', 'flows': ['dst_mac', 'ipv4', 'udp', 'vxlan', 'vni', 'ineth'], + 'actions': ['pf', 'queue']}, + {'create': 'create', 'flows': ['ipv4', 'udp', 'vxlan', 'vni', 'ineth', 'invlan'], + 'actions': ['vf0', 'queue']}, + {'create': 'create', 'flows': ['dst_mac', 'ipv4', 'udp', 'vxlan', 'vni', 'ineth'], + 'actions': ['vf1', 'queue']}, ] extrapkt_rulenum = self.all_flows_process(basic_flow_actions) extra_packet = extrapkt_rulenum['extrapacket'] self.load_module("vxlan") - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP()/UDP()/VXLAN()/Ether(dst="%s")/Dot1Q(vlan=11)/IP()/TCP()/Raw("x" * 20)], iface="%s")' % (self.outer_mac, self.inner_mac, self.tester_itf)) - self.verify_result("pf", expect_rxpkts="1", expect_queue=extrapkt_rulenum['queue'][0], verify_mac=self.outer_mac) + self.sendpkt('Ether(dst="%s")/IP()/UDP()/VXLAN()/Ether(dst="%s")/Dot1Q(vlan=11)/IP()/TCP()/Raw("x" * 20)' % (self.outer_mac, self.inner_mac)) + self.verify_result("pf", expect_rxpkts="1", expect_queue=extrapkt_rulenum['queue'][0], + verify_mac=self.outer_mac) self.load_module("vxlan") - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP()/UDP()/VXLAN(vni=5)/Ether(dst="%s")/IP()/TCP()/Raw("x" * 20)], iface="%s")' % (self.outer_mac, self.wrong_mac, self.tester_itf)) + self.sendpkt('Ether(dst="%s")/IP()/UDP()/VXLAN(vni=5)/Ether(dst="%s")/IP()/TCP()/Raw("x" * 20)' % (self.outer_mac, self.wrong_mac)) self.verify_result("pf", expect_rxpkts="1", expect_queue="0", verify_mac=self.outer_mac) self.load_module("vxlan") - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP()/UDP()/VXLAN(vni=%s)/Ether(dst="%s")/Dot1Q(vlan=%s)/IP()/TCP()/Raw("x" * 20)], iface="%s")' % (self.outer_mac, extra_packet[5]['vni'], self.wrong_mac, extra_packet[5]['invlan'], self.tester_itf)) + self.sendpkt('Ether(dst="%s")/IP()/UDP()/VXLAN(vni=%s)/Ether(dst="%s")/Dot1Q(vlan=%s)/IP()/TCP()/Raw("x" * 20)' % ( + self.outer_mac, extra_packet[5]['vni'], self.wrong_mac, extra_packet[5]['invlan'])) self.verify_result("vf0", expect_rxpkts="1", expect_queue="0", verify_mac=self.outer_mac) self.load_module("vxlan") - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP()/UDP()/VXLAN(vni=%s)/Ether(dst="%s")/IP()/TCP()/Raw("x" * 20)], iface="%s")' % (self.wrong_mac, extra_packet[6]['vni'], self.inner_mac, self.tester_itf)) + self.sendpkt('Ether(dst="%s")/IP()/UDP()/VXLAN(vni=%s)/Ether(dst="%s")/IP()/TCP()/Raw("x" * 20)' % ( + self.wrong_mac, extra_packet[6]['vni'], self.inner_mac)) self.verify_result("vf1", expect_rxpkts="0", expect_queue="NULL", verify_mac=self.wrong_mac) rule_num = extrapkt_rulenum['rulenum'] self.verify_rulenum(rule_num) @@ -1541,7 +1602,8 @@ class TestGeneric_flow_api(TestCase): only supported by i40e """ self.verify(self.nic in ["fortville_eagle", "fortville_spirit", - "fortville_spirit_single", "fortpark_TLV"], "%s nic not support tunnel nvgre filter" % self.nic) + "fortville_spirit_single", "fortpark_TLV"], + "%s nic not support tunnel nvgre filter" % self.nic) self.setup_env() self.pmdout.start_testpmd("%s" % self.pf_cores, "--disable-rss --rxq=%d --txq=%d" % (MAX_QUEUE+1, MAX_QUEUE+1), "-w %s --file-prefix=pf --socket-mem 1024,1024 --legacy-mem" % self.pf_pci) @@ -1574,23 +1636,23 @@ class TestGeneric_flow_api(TestCase): extra_packet = extrapkt_rulenum['extrapacket'] self.load_module("nvgre") - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP()/NVGRE()/Ether(dst="%s")/Dot1Q(vlan=1)/IP()/TCP()/Raw("x" * 20)], iface="%s")' % (self.outer_mac, self.inner_mac, self.tester_itf)) - self.verify_result("pf", expect_rxpkts="1", expect_queue=extrapkt_rulenum['queue'][0], verify_mac=self.outer_mac) + self.sendpkt('Ether(dst="%s")/IP()/NVGRE()/Ether(dst="%s")/Dot1Q(vlan=1)/IP()/TCP()/Raw("x" * 20)' % (self.outer_mac, self.inner_mac)) + self.verify_result("pf", expect_rxpkts="1", expect_queue=extrapkt_rulenum['queue'][0], + verify_mac=self.outer_mac) self.load_module("nvgre") - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP()/NVGRE(TNI=%s)/Ether(dst="%s")/IP()/TCP()/Raw("x" * 20)], iface="%s")' % (self.outer_mac, extra_packet[4]['tni'], self.wrong_mac, self.tester_itf)) + self.sendpkt('Ether(dst="%s")/IP()/NVGRE(TNI=%s)/Ether(dst="%s")/IP()/TCP()/Raw("x" * 20)' % ( + self.outer_mac, extra_packet[4]['tni'], self.wrong_mac)) self.verify_result("pf", expect_rxpkts="1", expect_queue="0", verify_mac=self.outer_mac) self.load_module("nvgre") - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP()/NVGRE(TNI=%s)/Ether(dst="%s")/Dot1Q(vlan=%s)/IP()/TCP()/Raw("x" * 20)], iface="%s")' % (self.outer_mac, extra_packet[5]['tni'], self.wrong_mac, extra_packet[5]['invlan'], self.tester_itf)) + self.sendpkt('Ether(dst="%s")/IP()/NVGRE(TNI=%s)/Ether(dst="%s")/Dot1Q(vlan=%s)/IP()/TCP()/Raw("x" * 20)' % ( + self.outer_mac, extra_packet[5]['tni'], self.wrong_mac, extra_packet[5]['invlan'])) self.verify_result("vf0", expect_rxpkts="1", expect_queue="0", verify_mac=self.outer_mac) self.load_module("nvgre") - self.tester.scapy_append( - 'sendp([Ether(dst="%s")/IP()/NVGRE(TNI=%s)/Ether(dst="%s")/IP()/TCP()/Raw("x" * 20)], iface="%s")' % (self.wrong_mac, extra_packet[6]['tni'], self.inner_mac, self.tester_itf)) + self.sendpkt('Ether(dst="%s")/IP()/NVGRE(TNI=%s)/Ether(dst="%s")/IP()/TCP()/Raw("x" * 20)' % ( + self.wrong_mac, extra_packet[6]['tni'], self.inner_mac)) self.verify_result("vf1", expect_rxpkts="0", expect_queue="NULL", verify_mac=self.wrong_mac) rule_num = extrapkt_rulenum['rulenum'] self.verify_rulenum(rule_num) diff --git a/tests/TestSuite_hotplug.py b/tests/TestSuite_hotplug.py index a94967a..a7a7228 100644 --- a/tests/TestSuite_hotplug.py +++ b/tests/TestSuite_hotplug.py @@ -121,7 +121,7 @@ class TestPortHotPlug(TestCase): self.txItf = self.tester.get_interface(txport) pkt = Packet(pkt_type='UDP') pkt.config_layer('ether', {'dst': self.dmac,}) - pkt.send_pkt(tx_port=self.txItf) + pkt.send_pkt(self.tester, tx_port=self.txItf) def test_before_attach(self): """ diff --git a/tests/TestSuite_iavf.py b/tests/TestSuite_iavf.py index 9395555..af8c747 100644 --- a/tests/TestSuite_iavf.py +++ b/tests/TestSuite_iavf.py @@ -588,7 +588,7 @@ class TestIavf(TestCase): self.tester.scapy_execute() rec_pkt = self.tester.load_tcpdump_sniff_packets(inst) # collect checksum values for received packet - chksum = rec_pkt[0].pktgen.pkt.sprintf("%IP.chksum%;%TCP.chksum%;%UDP.chksum%;%SCTP.chksum%").split(";") + chksum = rec_pkt[0].sprintf("%IP.chksum%;%TCP.chksum%;%UDP.chksum%;%SCTP.chksum%").split(";") chksum = list(set(chksum)) chksum.remove("??") corrected_checksum_values[packet] = chksum diff --git a/tests/TestSuite_ieee1588.py b/tests/TestSuite_ieee1588.py index 0dd3d6e..f3fea42 100644 --- a/tests/TestSuite_ieee1588.py +++ b/tests/TestSuite_ieee1588.py @@ -91,12 +91,13 @@ class TestIeee1588(TestCase): self.tester.send_expect( "tcpdump -i %s -e ether src %s" % (itf, mac), "tcpdump", 20) - + self.send_session = self.tester.create_session('send_session') + setattr(self.send_session, 'tmp_file', self.tester.tmp_file) pkt = Packet(pkt_type='TIMESYNC') - pkt.config_layer('ether', {'dst': mac, }) - pkt.send_pkt(tx_port=itf) - + pkt.config_layer('ether', {'dst': mac}) + pkt.send_pkt(self.send_session, tx_port=itf) time.sleep(1) + self.send_session.close() out = self.tester.get_session_output(timeout=20) self.tester.send_expect("^C", "# ", 20) diff --git a/tests/TestSuite_ipfrag.py b/tests/TestSuite_ipfrag.py index f6d0373..5edd6c4 100644 --- a/tests/TestSuite_ipfrag.py +++ b/tests/TestSuite_ipfrag.py @@ -168,37 +168,36 @@ l3fwd_ipv4_route_array[] = {\\\n" expPkts = 1 val = 2 - inst = self.tester.tcpdump_sniff_packets(intf=self.rxItf, timeout=5) + inst = self.tester.tcpdump_sniff_packets(intf=self.rxItf) # send packet for times in range(burst): pkt_size = pkt_sizes[pkt_sizes.index(size) + times] pkt = Packet(pkt_type='UDP', pkt_len=pkt_size) - pkt.config_layer('ether', {'dst': self.dmac}) + pkt.config_layer('ether', {'dst': '%s' % self.dmac}) pkt.config_layer('ipv4', {'dst': '100.10.0.1', 'src': '1.2.3.4', 'flags': val}) - pkt.send_pkt(tx_port=self.txItf) + pkt.send_pkt(self.tester, tx_port=self.txItf) # verify normal packet just by number, verify fragment packet by all elements pkts = self.tester.load_tcpdump_sniff_packets(inst) self.verify(len(pkts) == expPkts, "in functional_check_ipv4(): failed on forward packet size " + str(size)) if flag == 'frag': idx = 1 - for pkt in pkts: - # packet index should be same - pkt_id = pkt.strip_element_layer3("id") + for i in range(len(pkts)): + pkt_id = pkts.strip_element_layer3('id', p_index=i) if idx == 1: prev_idx = pkt_id self.verify(prev_idx == pkt_id, "Fragmented packets index not match") prev_idx = pkt_id # last flags should be 0 - flags = pkt.strip_element_layer3("flags") + flags = pkts.strip_element_layer3("flags", p_index=i) if idx == expPkts: self.verify(flags == 0, "Fragmented last packet flags not match") else: self.verify(flags == 1, "Fragmented packets flags not match") # fragment offset should be correct - frag = pkt.strip_element_layer3("frag") + frag = pkts.strip_element_layer3("frag", p_index=i) self.verify((frag == ((idx - 1) * 185)), "Fragment packet frag not match") idx += 1 @@ -218,37 +217,36 @@ l3fwd_ipv4_route_array[] = {\\\n" expPkts = 1 val = 2 - inst = self.tester.tcpdump_sniff_packets(intf=self.rxItf, timeout=5) + inst = self.tester.tcpdump_sniff_packets(intf=self.rxItf) # send packet for times in range(burst): pkt_size = pkt_sizes[pkt_sizes.index(size) + times] pkt = Packet(pkt_type='IPv6_UDP', pkt_len=pkt_size) - pkt.config_layer('ether', {'dst': self.dmac}) + pkt.config_layer('ether', {'dst': '%s' % self.dmac}) pkt.config_layer('ipv6', {'dst': '101:101:101:101:101:101:101:101', 'src': 'ee80:ee80:ee80:ee80:ee80:ee80:ee80:ee80'}) - pkt.send_pkt(tx_port=self.txItf) + pkt.send_pkt(self.tester, tx_port=self.txItf) # verify normal packet just by number, verify fragment packet by all elements pkts = self.tester.load_tcpdump_sniff_packets(inst) self.verify(len(pkts) == expPkts, "In functional_check_ipv6(): failed on forward packet size " + str(size)) if flag == 'frag': idx = 1 - for pkt in pkts: - # packet index should be same - pkt_id = pkt.strip_element_layer4("id") + for i in range(len(pkts)): + pkt_id = pkts.strip_element_layer4('id', p_index=i) if idx == 1: prev_idx = pkt_id self.verify(prev_idx == pkt_id, "Fragmented packets index not match") prev_idx = pkt_id # last flags should be 0 - flags = pkt.strip_element_layer4("m") + flags = pkts.strip_element_layer4("m", p_index=i) if idx == expPkts: self.verify(flags == 0, "Fragmented last packet flags not match") else: self.verify(flags == 1, "Fragmented packets flags not match") # fragment offset should be correct - frag = pkt.strip_element_layer4("offset") + frag = pkts.strip_element_layer4("offset", p_index=i) self.verify((frag == int((idx - 1) * 181)), "Fragment packet frag not match") idx += 1 diff --git a/tests/TestSuite_ipgre.py b/tests/TestSuite_ipgre.py index d08a933..7258db5 100644 --- a/tests/TestSuite_ipgre.py +++ b/tests/TestSuite_ipgre.py @@ -100,11 +100,11 @@ class TestIpgre(TestCase): if layer_configs: for layer in layer_configs.keys(): pkt.config_layer(layer, layer_configs[layer]) - inst = self.tester.tcpdump_sniff_packets(self.tester_iface, count=1, timeout=8) - pkt.send_pkt(tx_port=self.tester_iface, count = 4) + inst = self.tester.tcpdump_sniff_packets(self.tester_iface, count=1) + pkt.send_pkt(crb=self.tester, tx_port=self.tester_iface, count=4) out = self.dut.get_session_output(timeout=2) time.sleep(1) - self.tester.load_tcpdump_sniff_packets(inst) + pkt = self.tester.load_tcpdump_sniff_packets(inst) if self.printFlag: # debug output print out for pkt_layer_name in pkt_names: @@ -116,7 +116,7 @@ class TestIpgre(TestCase): raise VerifyFailure("Failed to detect %s" % pkt_layer_name) else: print utils.GREEN("Detected %s successfully" % pkt_type) - time.sleep(1) + time.sleep(1) if queue == None: # no filter pass else: @@ -124,6 +124,7 @@ class TestIpgre(TestCase): self.verify(("Receive queue=0x%s" % queue) in out, "Failed to enter the right queue.") else: self.verify(("Receive queue=0x%s" % queue) not in out, "Failed to enter the right queue.") + return pkt def save_ref_packet(self, pkt_types, layer_configs=None): @@ -146,13 +147,16 @@ class TestIpgre(TestCase): Skip outer udp for it will be calculated by software """ chk_sums = {} - pkts = rdpcap(pcap) + if isinstance(pcap, str): + pkts = rdpcap(pcap) + else: + pkts = pcap.pktgen.pkts for number in range(len(pkts)): if pkts[number].guess_payload_class(pkts[number]).name == "gre": payload = pkts[number][GRE] else: payload = pkts[number] - + if payload.guess_payload_class(payload).name == "IP": chk_sums['outer_ip'] = hex(payload[IP].chksum) @@ -170,9 +174,9 @@ class TestIpgre(TestCase): return chk_sums - def compare_checksum(self): - chksums_ref = self.get_chksums('/tmp/ref_pkt.pcap') - chksums = self.get_chksums('/tmp/sniff_{0}.pcap'.format(self.tester_iface)) + def compare_checksum(self, pkt): + chksums_ref = self.get_chksums('/tmp/ref_pkt.pcap') + chksums = self.get_chksums(pcap=pkt) self.logger.info("chksums_ref :: %s"%chksums_ref) self.logger.info("chksums :: %s"%chksums) # verify saved pcap checksum same to expected checksum @@ -197,8 +201,8 @@ class TestIpgre(TestCase): 'ipv4': {'proto': 'gre'}} # Start testpmd and enable rxonly forwarding mode testpmd_cmd = "./%s/app/testpmd -c ffff -n 4 -- -i --enable-rx-cksum" % self.target - self.dut.send_expect( testpmd_cmd, - "testpmd>", + self.dut.send_expect( testpmd_cmd, + "testpmd>", 20) self.dut.send_expect("set fwd rxonly", "testpmd>") self.dut.send_expect("set verbose 1", "testpmd>") @@ -233,7 +237,7 @@ class TestIpgre(TestCase): "MAC_IPv6_GRE_IPv6-TUNNEL_SCTP_PKT": ["TUNNEL_GRENAT", "INNER_L4_SCTP"], "MAC_VLAN_IPv6_GRE_IPv6-TUNNEL_SCTP_PKT": ["TUNNEL_GRENAT", "INNER_L4_SCTP", "PKT_RX_VLAN"] } - + # Start testpmd and enable rxonly forwarding mode testpmd_cmd = "./%s/app/testpmd -c ffff -n 4 -- -i --enable-rx-cksum --enable-hw-vlan" % self.target self.dut.send_expect(testpmd_cmd, "testpmd>", 20) @@ -258,7 +262,7 @@ class TestIpgre(TestCase): config_layers = {'ether': {'src': self.outer_mac_src}, 'ipv6': {'nh': 47}, 'gre': {'proto': 0x86dd}, - 'inner_ipv6': {'nh': 132}, + 'inner_ipv6': {'nh': 132}, 'raw': {'payload':['78']*40}} self.check_packet_transmission(pkt_types_ipv6_ipv6_SCTP, config_layers) self.dut.send_expect("quit", "#") @@ -271,7 +275,7 @@ class TestIpgre(TestCase): """ outer_mac = self.tester_iface_mac inner_mac = "10:00:00:00:00:00" - + # Start testpmd with multi queues #testpmd_cmd = "./%s/app/testpmd -c ff -n 3 -- -i --rxq=4 --txq=4" % self.target testpmd_cmd = "./%s/app/testpmd -c ff -n 3 -- -i --enable-rx-cksum --rxq=4 --txq=4" % self.target @@ -284,7 +288,7 @@ class TestIpgre(TestCase): # Add GRE filter that forward inner ip address 0.0.0.0 to queue 3 cmd = "tunnel_filter add 0 %s %s 0.0.0.0 1 ipingre iip 0 3"%(outer_mac, inner_mac) self.dut.send_expect( cmd, "testpmd>") - + # Send packet inner ip address matched and check packet received by queue 3 pkt_types = {"MAC_IP_GRE_IPv4-TUNNEL_UDP_PKT": ["TUNNEL_GRENAT", "INNER_L4_UDP"]} config_layers = {'ether': {'src': self.outer_mac_src}, @@ -298,7 +302,7 @@ class TestIpgre(TestCase): cmd = "tunnel_filter rm 0 %s %s 0.0.0.0 1 ipingre iip 0 3"%(outer_mac, inner_mac) self.dut.send_expect( cmd, "testpmd>") self.check_packet_transmission(pkt_types, config_layers, "3") - + # Add GRE filter that forward outer ip address 0.0.0.0 to queue 3 cmd = "tunnel_filter add 0 %s %s 0.0.0.0 1 ipingre oip 0 3"%(outer_mac, inner_mac) self.dut.send_expect( cmd, "testpmd>") @@ -341,7 +345,7 @@ class TestIpgre(TestCase): # Send packet with wrong outer IP checksum and check forwarded packet IP checksum is correct pkt_types = { "MAC_IP_GRE_IPv4-TUNNEL_TCP_PKT": ["PKT_TX_IP_CKSUM"]} - config_layers = {'ether': {'src': self.outer_mac_src, + config_layers = {'ether': {'src': self.outer_mac_src, 'dst': self.outer_mac_dst}, 'ipv4': {'proto': 'gre', 'src': self.outer_ip_src, @@ -349,7 +353,7 @@ class TestIpgre(TestCase): 'inner_ipv4':{'src':self.inner_ip_src, 'dst':self.inner_ip_dst}} self.save_ref_packet(pkt_types, config_layers) - config_layers = {'ether': {'src': self.outer_mac_src, + config_layers = {'ether': {'src': self.outer_mac_src, 'dst': self.outer_mac_dst}, 'ipv4': {'proto': 'gre', 'src': self.outer_ip_src, @@ -357,12 +361,12 @@ class TestIpgre(TestCase): 'inner_ipv4':{'src':self.inner_ip_src, 'dst':self.inner_ip_dst, 'chksum': 0x0}} - self.check_packet_transmission(pkt_types, config_layers) - self.compare_checksum() + pkt = self.check_packet_transmission(pkt_types, config_layers) + self.compare_checksum(pkt) # Send packet with wrong inner IP checksum and check forwarded packet IP checksum is correct pkt_types = { "MAC_IP_GRE_IPv4-TUNNEL_TCP_PKT": ["PKT_TX_IP_CKSUM"]} - config_layers = {'ether': {'src': self.outer_mac_src, + config_layers = {'ether': {'src': self.outer_mac_src, 'dst': self.outer_mac_dst}, 'ipv4': {'proto': 'gre', 'src': self.outer_ip_src, @@ -370,7 +374,7 @@ class TestIpgre(TestCase): 'inner_ipv4':{'src':self.inner_ip_src, 'dst':self.inner_ip_dst}} self.save_ref_packet(pkt_types, config_layers) - config_layers = {'ether': {'src': self.outer_mac_src, + config_layers = {'ether': {'src': self.outer_mac_src, 'dst': self.outer_mac_dst}, 'ipv4': {'proto': 'gre', 'src': self.outer_ip_src, @@ -378,22 +382,22 @@ class TestIpgre(TestCase): 'chksum': 0x0}, 'inner_ipv4':{'src':self.inner_ip_src, 'dst':self.inner_ip_dst}} - self.check_packet_transmission(pkt_types, config_layers) - self.compare_checksum() - + pkt = self.check_packet_transmission(pkt_types, config_layers) + self.compare_checksum(pkt) + # Send packet with wrong inner TCP checksum and check forwarded packet TCP checksum is correct pkt_types = { "MAC_IP_GRE_IPv4-TUNNEL_TCP_PKT": ["PKT_TX_TCP_CKSUM"]} - config_layers = {'ether': {'src': self.outer_mac_src, + config_layers = {'ether': {'src': self.outer_mac_src, 'dst': self.outer_mac_dst}, 'ipv4': {'proto': 'gre', 'src': self.outer_ip_src, 'dst': self.outer_ip_dst}, 'inner_ipv4':{'src':self.inner_ip_src, 'dst':self.inner_ip_dst}, - 'tcp': {'src': 53, + 'tcp': {'src': 53, 'dst': 53}} self.save_ref_packet(pkt_types, config_layers) - config_layers = {'ether': {'src': self.outer_mac_src, + config_layers = {'ether': {'src': self.outer_mac_src, 'dst': self.outer_mac_dst}, 'ipv4': {'proto': 'gre', 'src': self.outer_ip_src, @@ -401,12 +405,12 @@ class TestIpgre(TestCase): 'inner_ipv4':{'src':self.inner_ip_src, 'dst':self.inner_ip_dst}, 'tcp': {'chksum': 0x0}} - self.check_packet_transmission(pkt_types, config_layers) - self.compare_checksum() + pkt = self.check_packet_transmission(pkt_types, config_layers) + self.compare_checksum(pkt) # Send packet with wrong inner UDP checksum and check forwarded packet UDP checksum is correct pkt_types = { "MAC_IP_GRE_IPv4-TUNNEL_UDP_PKT": ["PKT_TX_UDP_CKSUM"]} - config_layers = {'ether': {'src': self.outer_mac_src, + config_layers = {'ether': {'src': self.outer_mac_src, 'dst': self.outer_mac_dst}, 'ipv4': {'proto': 'gre', 'src': self.outer_ip_src, @@ -414,7 +418,7 @@ class TestIpgre(TestCase): 'inner_ipv4':{'src':self.inner_ip_src, 'dst':self.inner_ip_dst}} self.save_ref_packet(pkt_types, config_layers) - config_layers = {'ether': {'src': self.outer_mac_src, + config_layers = {'ether': {'src': self.outer_mac_src, 'dst': self.outer_mac_dst}, 'ipv4': {'proto': 'gre', 'src': self.outer_ip_src, @@ -422,8 +426,8 @@ class TestIpgre(TestCase): 'inner_ipv4':{'src':self.inner_ip_src, 'dst':self.inner_ip_dst}, 'udp': {'chksum': 0xffff}} - self.check_packet_transmission(pkt_types, config_layers) - self.compare_checksum() + pkt = self.check_packet_transmission(pkt_types, config_layers) + self.compare_checksum(pkt) if self.nic != "cavium_a063": # Send packet with wrong inner SCTP checksum and check forwarded packet SCTP checksum is correct pkt_types = { "MAC_IP_GRE_IPv4-TUNNEL_SCTP_PKT": ["PKT_TX_SCTP_CKSUM"]} @@ -445,20 +449,22 @@ class TestIpgre(TestCase): 'inner_ipv4':{'src':self.inner_ip_src, 'dst':self.inner_ip_dst}, 'sctp': {'chksum': 0x0}} - self.check_packet_transmission(pkt_types, config_layers) - self.compare_checksum() + pkt = self.check_packet_transmission(pkt_types, config_layers) + self.compare_checksum(pkt) self.dut.send_expect("quit", "#") def tear_down(self): """ Run after each test case. + Nothing to do. """ - self.dut.kill_all() + pass def tear_down_all(self): """ Run after each test suite. Nothing to do. """ + self.dut.kill_all() pass diff --git a/tests/TestSuite_ipsec_gw_cryptodev_func.py b/tests/TestSuite_ipsec_gw_cryptodev_func.py index 5b815ad..9800886 100644 --- a/tests/TestSuite_ipsec_gw_cryptodev_func.py +++ b/tests/TestSuite_ipsec_gw_cryptodev_func.py @@ -35,7 +35,7 @@ import binascii import time import utils from test_case import TestCase -from packet import Packet, save_packets +import packet from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes from cryptography.hazmat.primitives.ciphers.aead import AESCCM, AESGCM @@ -723,7 +723,7 @@ class TestIPsecGW(TestCase): self.logger.info("IPsec-gw cmd: " + cmd_str) self.dut.send_expect(cmd_str, "IPSEC:", 30) time.sleep(3) - inst = self.tester.tcpdump_sniff_packets(self.rx_interface, timeout=25) + inst = self.tester.tcpdump_sniff_packets(self.rx_interface) PACKET_COUNT = 65 payload = 256 * ['11'] @@ -735,7 +735,7 @@ class TestIPsecGW(TestCase): expected_src_ip = case_cfgs["expected_src_ip"] expected_spi = case_cfgs["expected_spi"] - pkt = Packet() + pkt = packet.Packet() if len(dst_ip)<=15: pkt.assign_layers(["ether", "ipv4", "udp", "raw"]) pkt.config_layer("ether", {"src": "52:00:00:00:00:00", "dst": "52:00:00:00:00:01"}) @@ -746,38 +746,37 @@ class TestIPsecGW(TestCase): pkt.config_layer("ipv6", {"src": src_ip, "dst": dst_ip}) pkt.config_layer("udp", {"dst": 0}) pkt.config_layer("raw", {"payload": payload}) - pkt.send_pkt(tx_port=self.tx_interface, count=PACKET_COUNT) + pkt.send_pkt(crb=self.tester, tx_port=self.tx_interface, count=PACKET_COUNT) pkt_rec = self.tester.load_tcpdump_sniff_packets(inst) - pcap_filename = "output/{0}.pcap".format(self.pcap_filename) - self.logger.info("Save pkts to {0}".format(pcap_filename)) - save_packets(pkt_rec, pcap_filename) + pcap_filename = "{0}.pcap".format(self.pcap_filename) + self.logger.info("Save pkts to {0}".format(packet.TMP_PATH + pcap_filename)) + pkt_rec.save_pcapfile(self.tester, pcap_filename) self._pcap_idx = self._pcap_idx + 1 if len(pkt_rec) == 0: self.logger.error("IPsec forwarding failed") result = False - - for pkt_r in pkt_rec: - pkt_src_ip = pkt_r.pktgen.strip_layer3("src") + for i in range(len(pkt_rec)): + pkt_src_ip = pkt_rec.pktgen.strip_layer3("src", p_index=i) if pkt_src_ip != expected_src_ip: - pkt_r.pktgen.pkt.show() + pkt_rec[i].show() self.logger.error("SRC IP does not match. Pkt:{0}, Expected:{1}".format( pkt_src_ip, expected_src_ip)) result = False break - pkt_dst_ip = pkt_r.pktgen.strip_layer3("dst") + pkt_dst_ip = pkt_rec.pktgen.strip_layer3("dst", p_index=i) self.logger.debug(pkt_dst_ip) if pkt_dst_ip != expected_dst_ip: - pkt_r.pktgen.pkt.show() + pkt_rec[i].show() self.logger.error("DST IP does not match. Pkt:{0}, Expected:{1}".format( pkt_dst_ip, expected_dst_ip)) result = False break - packet_hex = pkt_r.pktgen.pkt["ESP"].getfieldval("data") + packet_hex = pkt_rec[i]["ESP"].getfieldval("data") if packet_hex is None: self.logger.error("NO Payload !") result = False @@ -785,7 +784,7 @@ class TestIPsecGW(TestCase): payload_str = binascii.b2a_hex(packet_hex) self.logger.debug(payload_str) - pkt_spi = hex(pkt_r.pktgen.pkt["ESP"].getfieldval("spi")) + pkt_spi = hex(pkt_rec[i]["ESP"].getfieldval("spi")) self.logger.debug(pkt_spi) if pkt_spi != expected_spi: self.logger.error("SPI does not match. Pkt:{0}, Expected:{1}".format( diff --git a/tests/TestSuite_jumboframes.py b/tests/TestSuite_jumboframes.py index 1b5aab5..a883e3e 100644 --- a/tests/TestSuite_jumboframes.py +++ b/tests/TestSuite_jumboframes.py @@ -229,7 +229,7 @@ class TestJumboframes(TestCase): """ Run after each test case. """ - pass + self.dut.kill_all() def tear_down_all(self): """ diff --git a/tests/TestSuite_kernelpf_iavf.py b/tests/TestSuite_kernelpf_iavf.py index 476b899..4424ae2 100644 --- a/tests/TestSuite_kernelpf_iavf.py +++ b/tests/TestSuite_kernelpf_iavf.py @@ -423,7 +423,7 @@ class TestKernelpfIavf(TestCase): pkt.config_layer('vlan', {'vlan': vlan}) pkt.config_layer('ether', {'dst': self.vf_mac}) - pkt.send_pkt(tx_port=self.tester_intf) + pkt.send_pkt(self.tester, tx_port=self.tester_intf) out = self.vm_dut.get_session_output(timeout=2) return out @@ -546,7 +546,7 @@ class TestKernelpfIavf(TestCase): pkt = Packet(pkt_type='UDP', pkt_len=pktsize) pkt.config_layer('ether', {'dst': self.vf_mac, 'src': self.tester_mac}) self.vm_testpmd.execute_cmd("clear port stats all") - pkt.send_pkt(tx_port=self.tester_intf) + pkt.send_pkt(self.tester, tx_port=self.tester_intf) time.sleep(1) diff --git a/tests/TestSuite_l2fwd_cryptodev_func.py b/tests/TestSuite_l2fwd_cryptodev_func.py index 7e785dd..e0f0b5b 100644 --- a/tests/TestSuite_l2fwd_cryptodev_func.py +++ b/tests/TestSuite_l2fwd_cryptodev_func.py @@ -760,7 +760,6 @@ class TestL2fwdCrypto(TestCase): payload = self.__format_hex_to_list(test_vector["input"]) inst = self.tester.tcpdump_sniff_packets(self.rx_interface, - timeout=5, filters=[{'layer': 'ether', 'config': {'dst': '52:00:00:00:00:01'}}]) @@ -770,12 +769,12 @@ class TestL2fwdCrypto(TestCase): pkt.config_layer("ether", {"src": "52:00:00:00:00:00", "dst":"52:00:00:00:00:01"}) pkt.config_layer("ipv4", {"src": "192.168.1.1", "dst": "192.168.1.2"}) pkt.config_layer("raw", {"payload": payload}) - pkt.send_pkt(tx_port=self.tx_interface, count=PACKET_COUNT) + pkt.send_pkt(self.tester, tx_port=self.tx_interface, count=PACKET_COUNT) pkt_rec = self.tester.load_tcpdump_sniff_packets(inst) self.logger.info("Receive pkgs: {}".format(len(pkt_rec))) - for pkt_r in pkt_rec: - packet_hex = pkt_r.pktgen.pkt["Raw"].getfieldval("load") + for i in range(len(pkt_rec)): + packet_hex = pkt_rec[i]["Raw"].getfieldval("load") if packet_hex == None: result = False self.logger.info("no payload !") @@ -796,9 +795,9 @@ class TestL2fwdCrypto(TestCase): hash_length = len(test_vector["output_hash"])/2 if hash_length != 0: if test_vector["auth_algo"] == "null": - hash_text = binascii.b2a_hex(pkt_r.pktgen.pkt["Raw"].getfieldval("load")) + hash_text = binascii.b2a_hex(pkt_rec[i]["Raw"].getfieldval("load")) else: - hash_text = binascii.b2a_hex(pkt_r.pktgen.pkt["Padding"].getfieldval("load")) + hash_text = binascii.b2a_hex(pkt_rec[i]["Padding"].getfieldval("load")) if str.lower(hash_text) == str.lower(test_vector["output_hash"]): self.logger.info("Hash Matched") else: diff --git a/tests/TestSuite_l3fwdacl.py b/tests/TestSuite_l3fwdacl.py index 9d1c41e..dce37de 100644 --- a/tests/TestSuite_l3fwdacl.py +++ b/tests/TestSuite_l3fwdacl.py @@ -38,6 +38,7 @@ import re import utils import time from test_case import TestCase +import packet class TestL3fwdacl(TestCase): @@ -268,10 +269,10 @@ class TestL3fwdacl(TestCase): dst_filter = {'layer': 'ether', 'config': {'dst': 'not ff:ff:ff:ff:ff:ff'}} filters = [dst_filter] - inst = self.tester.tcpdump_sniff_packets(rx_interface, timeout=5, filters=filters) - - self.tester.scapy_append('sendp([%s],iface="%s")' % (ethernet_str, tx_interface)) - self.tester.scapy_execute() + inst = self.tester.tcpdump_sniff_packets(rx_interface, filters=filters) + pkt = packet.Packet() + pkt.append_pkt(ethernet_str) + pkt.send_pkt(crb=self.tester, tx_port=tx_interface) out = self.remove_dhcp_from_revpackets(inst) return len(out) @@ -298,11 +299,11 @@ class TestL3fwdacl(TestCase): ethernet_str = self.create_ipv6_rule_string(rule, "Ether") fil = [{'layer': 'ether', 'config': {'dst': 'not ff:ff:ff:ff:ff:ff'}}] - inst = self.tester.tcpdump_sniff_packets(rx_interface, timeout=5, filters=fil) + inst = self.tester.tcpdump_sniff_packets(rx_interface, filters=fil) + pkt = packet.Packet() + pkt.append_pkt(ethernet_str) + pkt.send_pkt(crb=self.tester, tx_port=tx_interface) - self.tester.scapy_append('sendp([%s],iface="%s")' % (ethernet_str, tx_interface)) - self.tester.scapy_execute() - time.sleep(3) out = self.remove_dhcp_from_revpackets(inst) return len(out) @@ -316,10 +317,10 @@ class TestL3fwdacl(TestCase): dst_filter = {'layer': 'ether', 'config': {'dst': 'not ff:ff:ff:ff:ff:ff'}} filters = [dst_filter] - inst = self.tester.tcpdump_sniff_packets(rx_interface, timeout=5, filters=filters) - self.tester.scapy_append('sendp([%s],iface="%s")' % (etherStr, tx_interface)) - self.tester.scapy_execute() - + inst = self.tester.tcpdump_sniff_packets(rx_interface, filters=filters) + pkt = packet.Packet() + pkt.append_pkt(etherStr) + pkt.send_pkt(crb=self.tester, tx_port=tx_interface) out = self.remove_dhcp_from_revpackets(inst) return len(out) @@ -332,20 +333,20 @@ class TestL3fwdacl(TestCase): etherStr = self.create_ipv6_rule_string(rule, "Ether") fil = [{'layer': 'ether', 'config': {'dst': 'not ff:ff:ff:ff:ff:ff'}}] - inst = self.tester.tcpdump_sniff_packets(rx_interface, timeout=5, filters=fil) - - self.tester.scapy_append('sendp([%s],iface="%s")' % (etherStr, tx_interface)) - self.tester.scapy_execute() - time.sleep(3) + inst = self.tester.tcpdump_sniff_packets(rx_interface, filters=fil) + pkt = packet.Packet() + pkt.append_pkt(etherStr) + pkt.send_pkt(crb=self.tester, tx_port=tx_interface) out = self.remove_dhcp_from_revpackets(inst) return len(out) def remove_dhcp_from_revpackets(self, inst): - pkts = self.tester.load_tcpdump_sniff_packets(inst) + p = self.tester.load_tcpdump_sniff_packets(inst) + pkts = p.pktgen.pkts i = 0 while len(pkts) != 0 and i <= len(pkts) - 1: - if pkts[i].pktgen.pkt.haslayer('DHCP'): + if pkts[i].haslayer('DHCP'): pkts.remove(pkts[i]) i = i - 1 i = i + 1 diff --git a/tests/TestSuite_link_flowctrl.py b/tests/TestSuite_link_flowctrl.py index 4229aa4..ed89162 100644 --- a/tests/TestSuite_link_flowctrl.py +++ b/tests/TestSuite_link_flowctrl.py @@ -453,4 +453,5 @@ class TestLinkFlowctrl(TestCase): """ Run after each test case. """ + self.dut.kill_all() self.dut.send_expect("quit", "# ") diff --git a/tests/TestSuite_link_status_interrupt.py b/tests/TestSuite_link_status_interrupt.py index 1d7e67e..3208d71 100644 --- a/tests/TestSuite_link_status_interrupt.py +++ b/tests/TestSuite_link_status_interrupt.py @@ -175,7 +175,7 @@ class TestLinkStatusInterrupt(TestCase): self.txItf = self.tester.get_interface(txport) pkt = Packet(pkt_type='UDP') pkt.config_layer('ether', {'dst': self.dmac}) - pkt.send_pkt(tx_port=self.txItf, count=num) + pkt.send_pkt(self.tester, tx_port=self.txItf, count=num) def tear_down(self): """ diff --git a/tests/TestSuite_loadbalancer.py b/tests/TestSuite_loadbalancer.py index 9152c6c..934e291 100644 --- a/tests/TestSuite_loadbalancer.py +++ b/tests/TestSuite_loadbalancer.py @@ -90,13 +90,13 @@ class TestLoadbalancer(TestCase): for i in range(len(dutPorts)): dstport = self.tester.get_local_port(dutPorts[i]) pkt_count = 10 - inst = self.tester.tcpdump_sniff_packets(intf=self.tester.get_interface(rx_port), timeout=10, count=pkt_count) + inst = self.tester.tcpdump_sniff_packets(intf=self.tester.get_interface(rx_port), count=pkt_count) - pkt = Packet() + pkt = Packet(pkt_type='UDP', pkt_len=64) dst_mac = self.dut.get_mac_address(dutPorts[i]) - pkt.config_layer('ether', {'dst': dst_mac}) - pkt.config_layer('ipv4', {'src': "0.0.0.1", 'dst': trafficFlow[flow][1]}) - pkt.send_pkt(tx_port=self.tester.get_interface(dstport), count=10) + pkt.config_layer('ether', {'dst': '%s' % dst_mac}) + pkt.config_layer('ipv4', {'src': "0.0.0.1", 'dst': '%s' % (trafficFlow[flow][1])}) + pkt.send_pkt(self.tester, tx_port=self.tester.get_interface(dstport), count=10) # Wait for the sniffer to finish. time.sleep(5) @@ -104,8 +104,8 @@ class TestLoadbalancer(TestCase): len_pkts = len(pkts) self.verify(len_pkts == pkt_count, "Packet number is wrong") - for packet in pkts: - result = str(packet.pktgen.pkt.show) + for i in range(len_pkts): + result = str(pkts[i].show) self.verify("Ether" in result, "No packet received") self.verify("src=0.0.0.1" + " dst=" + trafficFlow[flow][1] in result, "Wrong IP address") self.verify("dst=%s" % dst_mac in result, "No packet received or packet missed") diff --git a/tests/TestSuite_mac_filter.py b/tests/TestSuite_mac_filter.py index 7b5eb43..19d250b 100644 --- a/tests/TestSuite_mac_filter.py +++ b/tests/TestSuite_mac_filter.py @@ -88,7 +88,7 @@ class TestMacFilter(TestCase): itf = self.tester.get_interface(self.tester.get_local_port(portid)) pkt = Packet(pkt_type='UDP') pkt.config_layer('ether', {'src': '52:00:00:00:00:00', 'dst': destMac}) - pkt.send_pkt(tx_port=itf, count=4) + pkt.send_pkt(self.tester, tx_port=itf, count=4) def test_add_remove_mac_address(self): """ diff --git a/tests/TestSuite_netmap_compat.py b/tests/TestSuite_netmap_compat.py index 2f8171c..a7a97ca 100644 --- a/tests/TestSuite_netmap_compat.py +++ b/tests/TestSuite_netmap_compat.py @@ -114,9 +114,9 @@ class TestNetmapCompat(TestCase): def get_tcpdump_package(self): pkts = self.tester.load_tcpdump_sniff_packets(self.inst) - dsts = [] - for packet in pkts: - dst = packet.strip_element_layer2("dst") + dsts = [] + for i in range(len(pkts)): + dst = pkts.strip_element_layer2("dst", p_index=i) dsts.append(dst) return dsts diff --git a/tests/TestSuite_packet_capture.py b/tests/TestSuite_packet_capture.py index 6e5b98f..fdaa0d0 100644 --- a/tests/TestSuite_packet_capture.py +++ b/tests/TestSuite_packet_capture.py @@ -39,8 +39,6 @@ import time import re import signal import subprocess -import shutil -import socket from pprint import pformat from scapy.utils import rdpcap @@ -188,37 +186,19 @@ class parsePacket(object): class TestPacketCapture(TestCase): - def get_dts_node_ip(self): - ip_addr = None - try: - socket_inst = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - socket_inst.connect(('8.8.8.8', 80)) - ip_addr = socket_inst.getsockname()[0] - except Exception as e: - msg = "Can't get dts running node ip address" - self.logger.warning(msg) - return ip_addr - return ip_addr - - @property - def is_dts_on_tester(self): - if not self.dts_ip: - return False - # get tester ip to check if dts run on tester - tester_ip = self.tester.get_ip_address() - return self.dts_ip == tester_ip - - @property - def is_dts_on_dut(self): - if not self.dts_ip: - return False - # get dut ip to check if dts run on dut - dut_ip = self.dut.get_ip_address() - return self.dts_ip == dut_ip + def is_existed_on_crb(self, check_path, crb='dut'): + alt_session = self.dut.alt_session \ + if crb == 'dut' else \ + self.tester.alt_session + alt_session.send_expect("ls %s" % check_path, "# ") + cmd = "echo $?" + output = alt_session.send_expect(cmd, "# ") + ret = True if output and output.strip() == "0" else False + return ret @property def is_dut_on_tester(self): - # get dut/tester ip to check if they are in one platform + # get dut/tester ip to check if they are in a platform tester_ip = self.tester.get_ip_address() dut_ip = self.dut.get_ip_address() return tester_ip == dut_ip @@ -231,42 +211,6 @@ class TestPacketCapture(TestCase): self.dut.base_dir return target_dir - def __create_log_dir(self, log_dir): - # create a log directory on dts running node - if not os.path.exists(log_dir): - os.makedirs(log_dir) - # create a log directory on dut node - if not self.is_dts_on_dut and \ - not self.is_existed_on_crb(log_dir): - cmd = "mkdir -p {0}".format(log_dir) - self.dut.alt_session.send_expect(cmd, "# ") - # create a log directory on tester node - if not self.is_dts_on_tester and \ - not self.is_existed_on_crb(log_dir, crb='tester'): - cmd = "mkdir -p {0}".format(log_dir) - self.tester.alt_session.send_expect(cmd, "# ") - - def __clear_log_dir(self, log_dir): - if os.path.exists(log_dir): - shutil.rmtree(log_dir) - os.makedirs(log_dir) - if not self.is_dts_on_dut: - self.dut.alt_session.send_expect( - "rm -fr {0}/*".format(log_dir), "# ", 10) - if not self.is_dts_on_tester: - self.tester.alt_session.send_expect( - "rm -fr {0}/*".format(log_dir), "# ", 10) - - def is_existed_on_crb(self, check_path, crb='dut'): - alt_session = self.dut.alt_session \ - if crb == 'dut' else \ - self.tester.alt_session - alt_session.send_expect("ls %s > /dev/null 2>&1" % check_path, "# ") - cmd = "echo $?" - output = alt_session.send_expect(cmd, "# ") - ret = True if output and output.strip() == "0" else False - return ret - def get_dut_iface_with_kernel_driver(self): # only physical nic support PROMISC cmd = "ip link show | grep BROADCAST,MULTICAST | awk {'print $2'}" @@ -500,6 +444,11 @@ class TestPacketCapture(TestCase): time.sleep(4) def start_testpmd(self): + self.dut.alt_session.send_expect( + "rm -fr {0}/*".format(self.pdump_log), "# ", 10) + if not self.is_dut_on_tester: + self.tester.alt_session.send_expect( + "rm -fr {0}/*".format(self.pdump_log), "# ", 10) param_opt = "--port-topology=chained" eal_param = '--file-prefix=test' self.testpmd.start_testpmd("Default", param=param_opt, @@ -516,14 +465,23 @@ class TestPacketCapture(TestCase): def start_tcpdump_iface(self, option): if option["rx"][0] is not None and option["tx"][0] is not None and \ option["rx"][0] == option["tx"][0]: + if self.is_existed_on_crb(self.rxtx_pcap): + self.dut.alt_session.send_expect( + "rm -f %s" % self.rxtx_pcap, "# ") cmd = self.tcpdump.format(self.rxtx_iface, self.rxtx_pcap) self.session_ex.send_expect(cmd, "# ") else: if option["rx"][0] is not None: + if self.is_existed_on_crb(self.rx_pcap): + self.dut.alt_session.send_expect( + "rm -f %s" % self.rx_pcap, "# ") cmd = self.tcpdump.format(self.rx_iface, self.rx_pcap) self.session_ex.send_expect(cmd, "# ") if option["tx"][0] is not None: + if self.is_existed_on_crb(self.tx_pcap): + self.dut.alt_session.send_expect( + "rm -f %s" % self.tx_pcap, "# ") cmd = self.tcpdump.format(self.tx_iface, self.tx_pcap) self.session_ex.send_expect(cmd, "# ") time.sleep(4) @@ -537,6 +495,11 @@ class TestPacketCapture(TestCase): msg = ('pdump option string length should be less than {}' ).format(length_limit) self.verify(len(option) < length_limit, msg) + self.dut.alt_session.send_expect( + "rm -fr {0}/*".format(self.pdump_log), "# ", 20) + if not self.is_dut_on_tester: + self.tester.alt_session.send_expect( + "rm -fr {0}/*".format(self.pdump_log), "# ", 20) cmd = ';'.join([ "cd %s" % self.target_dir, self.dpdk_pdump + " '%s' >/dev/null 2>&1 &" % (option[0])]) @@ -572,13 +535,18 @@ class TestPacketCapture(TestCase): # check send tx packet by port 0 # send packet to dut and compare dpdk-pdump dump pcap with # scapy pcap file - if self.is_dts_on_tester: - intf = self.tester.get_interface(self.tester.get_local_port(port_1)) - # prepare to catch replay packet in out port - recPkt = os.path.join('/tmp', "sniff_%s.pcap" % intf) - if os.path.exists(recPkt): - os.remove(recPkt) - index = sniff_packets(intf, count=1, timeout=20, pcap=recPkt) + intf = self.tester.get_interface(self.tester.get_local_port(port_1)) + # prepare to catch replay packet in out port + recPkt = os.path.join('/tmp', "sniff_%s.pcap" % intf) + if os.path.exists(recPkt): + os.remove(recPkt) + if pkt_type == 'LLDP': + index = self.tester.tcpdump_sniff_packets(intf=intf, count=1, lldp_forbid=False) + else: + index = self.tester.tcpdump_sniff_packets(intf=intf, count=1) + filename = '{}sniff_{}.pcap'.format(self.tester.tmp_file, intf) + self.tester.session.copy_file_from(filename, recPkt) + # index = sniff_packets(intf, count=1, timeout=20, pcap=recPkt) pkt = Packet(pkt_type=pkt_type) if pkt_type == 'VLAN_UDP': pkt.config_layer('dot1q', {'vlan': 20}) @@ -588,33 +556,34 @@ class TestPacketCapture(TestCase): refPkt = self.send_pcap % (pkt_type, "rx", number) if os.path.exists(refPkt): os.remove(refPkt) - pkt.pktgen.write_pcap(refPkt) + + pkt.save_pcapfile(filename=refPkt) # send out test packet tester_port = self.tester.get_local_port(port_0) intf = self.tester.get_interface(tester_port) - pkt.send_pkt( - crb= None if self.is_dts_on_tester else self.tester, - tx_port=intf) + pkt.send_pkt(self.tester, tx_port=intf) # load pcap file caught by out port time.sleep(1) - # when dts doesn't run on tester, ignore this testing content - if self.is_dts_on_tester: - load_sniff_packets(index) - # compare pcap file received by out port with scapy reference - # packet pcap file - warning = self.compare_pkts(refPkt, recPkt, pkt_type) - msg = "tcpdump rx Receive Packet error: {0}".format(warning) - self.verify(not warning, msg) + pkts = self.tester.load_tcpdump_sniff_packets(index) + pkts.save_pcapfile(filename=recPkt) + # load_sniff_packets(index) + # compare pcap file received by out port with scapy reference + # packet pcap file + warning = self.compare_pkts(refPkt, recPkt, pkt_type) + msg = "tcpdump rx Receive Packet error: {0}".format(warning) + self.verify(not warning, msg) # check send tx packet by port 1 # send packet to dut and compare dpdk-pdump dump pcap # with scapy pcap file - if self.is_dts_on_tester: - intf = self.tester.get_interface(self.tester.get_local_port(port_0)) - # prepare to catch replay packet in out port - recPkt = os.path.join('/tmp', "sniff_%s.pcap" % intf) - if os.path.exists(recPkt): - os.remove(recPkt) - index = sniff_packets(intf, count=1, timeout=20, pcap=recPkt) + intf = self.tester.get_interface(self.tester.get_local_port(port_0)) + # prepare to catch replay packet in out port + recPkt = os.path.join('/tmp', "sniff_%s.pcap" % intf) + if os.path.exists(recPkt): + os.remove(recPkt) + if pkt_type == 'LLDP': + index = self.tester.tcpdump_sniff_packets(intf=intf, count=1, lldp_forbid=False) + else: + index = self.tester.tcpdump_sniff_packets(intf=intf, count=1) pkt = Packet(pkt_type=pkt_type) if pkt_type == 'VLAN_UDP': pkt.config_layer('dot1q', {'vlan': 20}) @@ -624,23 +593,21 @@ class TestPacketCapture(TestCase): refPkt = self.send_pcap % (pkt_type, "tx", number) if os.path.exists(refPkt): os.remove(refPkt) - pkt.pktgen.write_pcap(refPkt) + pkt.save_pcapfile(filename=refPkt) + # pkt.pktgen.write_pcap(refPkt) # send out test packet tester_port = self.tester.get_local_port(port_1) intf = self.tester.get_interface(tester_port) - pkt.send_pkt( - crb= None if self.is_dts_on_tester else self.tester, - tx_port=intf) + pkt.send_pkt(self.tester, tx_port=intf) # load pcap file caught by out port time.sleep(1) - # when dts doesn't run on tester, ignore this testing content - if self.is_dts_on_tester: - load_sniff_packets(index) - # compare pcap file received by out port - # with scapy reference packet pcap file - warning = self.compare_pkts(refPkt, recPkt, pkt_type) - msg = "tcpdump tx Receive Packet error: {0}".format(warning) - self.verify(not warning, msg) + pkts = self.tester.load_tcpdump_sniff_packets(index) + pkts.save_pcapfile(filename=recPkt) + # compare pcap file received by out port + # with scapy reference packet pcap file + warning = self.compare_pkts(refPkt, recPkt, pkt_type) + msg = "tcpdump tx Receive Packet error: {0}".format(warning) + self.verify(not warning, msg) def check_pdump_pcaps(self, pkt_type, number, **kwargs): rx_dump_pcap = kwargs["rx"][0] @@ -686,23 +653,8 @@ class TestPacketCapture(TestCase): msg = "pdump tx {0} packet content is correct".format(pkt_type) self.logger.info(msg) - def sync_dut_dump_file(self): - if self.is_dts_on_dut: - return - # copy rx pdump data from dut - if os.path.exists(self.rx_pcap): - os.remove(self.rx_pcap) - if self.is_existed_on_crb(self.rx_pcap): - self.dut.session.copy_file_from(self.rx_pcap, self.rx_pcap) - # copy tx pdump data from dut - if os.path.exists(self.tx_pcap): - os.remove(self.tx_pcap) - if self.is_existed_on_crb(self.tx_pcap): - self.dut.session.copy_file_from(self.tx_pcap, self.tx_pcap) - def packet_capture_test_packets(self, option): self.clear_ASLR() - self.__clear_log_dir(self.pdump_log) self.start_testpmd() self.start_dpdk_pdump(option) if self.dev_iface_flag: @@ -713,7 +665,17 @@ class TestPacketCapture(TestCase): time.sleep(2) if self.dev_iface_flag: self.stop_tcpdump_iface() - self.sync_dut_dump_file() + if not self.is_dut_on_tester: + # copy rx pdump data from dut + if self.is_existed_on_crb(self.rx_pcap): + if os.path.exists(self.rx_pcap): + os.remove(self.rx_pcap) + self.dut.session.copy_file_from(self.rx_pcap, self.rx_pcap) + # copy tx pdump data from dut + if self.is_existed_on_crb(self.tx_pcap): + if os.path.exists(self.tx_pcap): + os.remove(self.tx_pcap) + self.dut.session.copy_file_from(self.tx_pcap, self.tx_pcap) self.stop_dpdk_pdump() self.stop_testpmd() self.reset_ASLR() @@ -838,8 +800,6 @@ class TestPacketCapture(TestCase): ''' Run at the start of each test suite. ''' - # get dts running node ip address - self.dts_ip = self.get_dts_node_ip() self.verify(self.target == "x86_64-native-linuxapp-gcc", "only support x86_64-native-linuxapp-gcc") self.dut_ports = self.dut.get_ports() @@ -851,7 +811,13 @@ class TestPacketCapture(TestCase): self.dut_skip_compile = self.dut.skip_setup # used for save log self.pdump_log = os.sep.join(["/tmp", 'pdumpLog']) - self.__create_log_dir(self.pdump_log) + if not self.is_existed_on_crb(self.pdump_log): + cmd = "mkdir -p {0}".format(self.pdump_log) + self.dut.alt_session.send_expect(cmd, "# ") + if not self.is_dut_on_tester and \ + not self.is_existed_on_crb(self.pdump_log, crb='tester'): + cmd = "mkdir -p {0}".format(self.pdump_log) + self.tester.alt_session.send_expect(cmd, "# ") self.pcap_SW = "CONFIG_RTE_LIBRTE_PMD_PCAP" self.SW_file = os.path.join(self.target_dir, 'config/common_base') if not (self.dut_skip_compile and self.check_pcap_lib()): @@ -861,19 +827,17 @@ class TestPacketCapture(TestCase): self.dut.skip_setup = False self.dut.build_install_dpdk(self.target) # secondary process (dpdk-pdump) - self.pdump_dir = os.sep.join([ - self.target_dir, - "%s/build/app/pdump/" % self.target]) + self.pdump_dir = self.target_dir + os.sep + \ + "%s/build/app/pdump/" % self.target cmd = "ls {0} -F | grep '*'".format(self.pdump_dir) exe_files = self.dut.alt_session.send_expect(cmd, "# ").splitlines() if len(exe_files) == 1: self.tool_name = exe_files[0][:-1] else: self.verify(False, "tool name exception !") - self.dut_dpdk_pdump_dir = os.sep.join([ - self.target_dir, - "%s/app/%s" % (self.target, self.tool_name)]) self.session_ex = self.dut.new_session(self.tool_name) + self.dut_dpdk_pdump_dir = self.target_dir + os.sep + \ + "%s/app/%s" % (self.target, self.tool_name) self.dpdk_pdump = self.dut_dpdk_pdump_dir + \ " -v --file-prefix=test -- --pdump " self.send_pcap = os.sep.join([self.pdump_log, "scapy_%s_%s_%d.pcap"]) diff --git a/tests/TestSuite_ptype_mapping.py b/tests/TestSuite_ptype_mapping.py index b0dc70a..b352724 100644 --- a/tests/TestSuite_ptype_mapping.py +++ b/tests/TestSuite_ptype_mapping.py @@ -85,7 +85,7 @@ class TestPtype_Mapping(TestCase): else: pkt_names = pkt_types[pkt_type] pkt = Packet(pkt_type=pkt_type) - pkt.send_pkt(tx_port=self.tester_iface,count=4) + pkt.send_pkt(self.tester, tx_port=self.tester_iface,count=4) out = self.dut.get_session_output(timeout=2) if sw_ptype != None: self.verify(sw_ptype in out, diff --git a/tests/TestSuite_pvp_multi_paths_performance.py b/tests/TestSuite_pvp_multi_paths_performance.py index b633b98..65c785a 100644 --- a/tests/TestSuite_pvp_multi_paths_performance.py +++ b/tests/TestSuite_pvp_multi_paths_performance.py @@ -36,7 +36,7 @@ Test PVP performance using virtio_user on 8 tx/rx path. import utils from test_case import TestCase -from packet import Packet, save_packets +from packet import Packet from pktgen import PacketGeneratorHelper @@ -98,7 +98,7 @@ class TestPVPMultiPathPerformance(TestCase): pkt = Packet(pkt_type='UDP', pkt_len=frame_size) pkt.config_layer('ether', {'dst': '%s' % destination_mac}) - save_packets([pkt], "%s/multi_path_%d.pcap" % (self.out_path, port)) + pkt.save_pcapfile(self.tester, "%s/multi_path_%d.pcap" % (self.out_path, port)) tgen_input.append((tx_port, rx_port, "%s/multi_path_%d.pcap" % (self.out_path, port))) self.tester.pktgen.clear_streams() diff --git a/tests/TestSuite_pvp_multi_paths_vhost_single_core_performance.py b/tests/TestSuite_pvp_multi_paths_vhost_single_core_performance.py index fcaadf2..29d87c2 100644 --- a/tests/TestSuite_pvp_multi_paths_vhost_single_core_performance.py +++ b/tests/TestSuite_pvp_multi_paths_vhost_single_core_performance.py @@ -36,7 +36,7 @@ Test PVP vhost single core performance using virtio_user on 8 tx/rx path. import utils from test_case import TestCase -from packet import Packet, save_packets +from packet import Packet from pktgen import PacketGeneratorHelper @@ -95,7 +95,7 @@ class TestPVPMultiPathVhostPerformance(TestCase): pkt = Packet(pkt_type='UDP', pkt_len=frame_size) pkt.config_layer('ether', {'dst': '%s' % destination_mac}) - save_packets([pkt], "%s/multi_path_%d.pcap" % (self.out_path, port)) + pkt.save_pcapfile(self.tester, "%s/multi_path_%d.pcap" % (self.out_path, port)) tgen_input.append((tx_port, rx_port, "%s/multi_path_%d.pcap" % (self.out_path, port))) self.tester.pktgen.clear_streams() diff --git a/tests/TestSuite_pvp_multi_paths_virtio_single_core_performance.py b/tests/TestSuite_pvp_multi_paths_virtio_single_core_performance.py index 6cd3a6d..e8807a7 100644 --- a/tests/TestSuite_pvp_multi_paths_virtio_single_core_performance.py +++ b/tests/TestSuite_pvp_multi_paths_virtio_single_core_performance.py @@ -36,7 +36,7 @@ Test PVP virtio single core performance using virtio_user on 8 tx/rx path. import utils from test_case import TestCase -from packet import Packet, save_packets +from packet import Packet from pktgen import PacketGeneratorHelper @@ -98,7 +98,7 @@ class TestPVPMultiPathVirtioPerformance(TestCase): pkt = Packet(pkt_type='UDP', pkt_len=frame_size) pkt.config_layer('ether', {'dst': '%s' % destination_mac}) - save_packets([pkt], "%s/multi_path_%d.pcap" % (self.out_path, port)) + pkt.save_pcapfile(self.tester, "%s/multi_path_%d.pcap" % (self.out_path, port)) tgen_input.append((tx_port, rx_port, "%s/multi_path_%d.pcap" % (self.out_path, port))) diff --git a/tests/TestSuite_pvp_qemu_multi_paths_port_restart.py b/tests/TestSuite_pvp_qemu_multi_paths_port_restart.py index 0095ce2..ea2e1cd 100644 --- a/tests/TestSuite_pvp_qemu_multi_paths_port_restart.py +++ b/tests/TestSuite_pvp_qemu_multi_paths_port_restart.py @@ -43,7 +43,7 @@ import time import re from virt_common import VM from test_case import TestCase -from packet import Packet, save_packets +from packet import Packet from pktgen import PacketGeneratorHelper @@ -72,7 +72,6 @@ class TestPVPQemuMultiPathPortRestart(TestCase): self.tester.send_expect('mkdir -p %s' % self.out_path, '# ') # create an instance to set stream field setting self.pktgen_helper = PacketGeneratorHelper() - self.base_dir = self.dut.base_dir.replace('~', '/root') def set_up(self): """ @@ -94,14 +93,14 @@ class TestPVPQemuMultiPathPortRestart(TestCase): start testpmd on vhost """ self.dut.send_expect("killall -s INT testpmd", "#") - self.dut.send_expect("rm -rf %s/vhost-net*" % self.base_dir, "#") + self.dut.send_expect("rm -rf ./vhost-net*", "#") command_client = self.dut.target + "/app/testpmd " + \ " -n %d -c %s --socket-mem 1024,1024 " + \ " --legacy-mem --file-prefix=vhost " + \ - " --vdev 'net_vhost0,iface=%s/vhost-net,queues=1' " + \ + " --vdev 'net_vhost0,iface=vhost-net,queues=1' " + \ " -- -i --nb-cores=1 --txd=1024 --rxd=1024" command_line_client = command_client % ( - self.dut.get_memory_channels(), self.core_mask, self.base_dir) + self.dut.get_memory_channels(), self.core_mask) self.vhost.send_expect(command_line_client, "testpmd> ", 120) self.vhost.send_expect("set fwd mac", "testpmd> ", 120) self.vhost.send_expect("start", "testpmd> ", 120) @@ -134,7 +133,7 @@ class TestPVPQemuMultiPathPortRestart(TestCase): self.vm = VM(self.dut, 'vm0', 'vhost_sample') vm_params = {} vm_params['driver'] = 'vhost-user' - vm_params['opt_path'] = '%s/vhost-net' % self.base_dir + vm_params['opt_path'] = './vhost-net' vm_params['opt_mac'] = self.virtio1_mac if modem == 1 and mergeable == 0: vm_params['opt_settings'] = "disable-modern=false,mrg_rxbuf=off,rx_queue_size=1024,tx_queue_size=1024" @@ -206,7 +205,7 @@ class TestPVPQemuMultiPathPortRestart(TestCase): """ pkt = Packet(pkt_type='IP_RAW', pkt_len=frame_size) pkt.config_layer('ether', {'dst': '%s' % self.dst_mac}) - save_packets([pkt], "%s/pvp_multipath.pcap" % (self.out_path)) + pkt.save_pcapfile(self.tester, "%s/pvp_multipath.pcap" % (self.out_path)) tgenInput = [] port = self.tester.get_local_port(self.dut_ports[0]) diff --git a/tests/TestSuite_pvp_vhost_user_reconnect.py b/tests/TestSuite_pvp_vhost_user_reconnect.py index c5c7b96..16a93b0 100644 --- a/tests/TestSuite_pvp_vhost_user_reconnect.py +++ b/tests/TestSuite_pvp_vhost_user_reconnect.py @@ -41,7 +41,7 @@ import utils import time from test_case import TestCase from virt_common import VM -from packet import Packet, save_packets +from packet import Packet from pktgen import PacketGeneratorHelper @@ -83,7 +83,6 @@ class TestPVPVhostUserReconnect(TestCase): self.tester.send_expect('mkdir -p %s' % self.out_path, '# ') # create an instance to set stream field setting self.pktgen_helper = PacketGeneratorHelper() - self.base_dir = self.dut.base_dir.replace('~', '/root') def set_up(self): """ @@ -92,7 +91,7 @@ class TestPVPVhostUserReconnect(TestCase): """ self.dut.send_expect("killall -s INT testpmd", "# ") self.dut.send_expect("killall -s INT qemu-system-x86_64", "# ") - self.dut.send_expect("rm -rf %s/vhost-net*" % self.base_dir, "# ") + self.dut.send_expect("rm -rf ./vhost-net*", "# ") self.vhost_user = self.dut.new_session(suite="vhost-user") def launch_testpmd_as_vhost_user(self): @@ -101,7 +100,7 @@ class TestPVPVhostUserReconnect(TestCase): """ vdev_info = "" for i in range(self.vm_num): - vdev_info += "--vdev 'net_vhost%d,iface=%s/vhost-net%d,client=1,queues=1' " % (i, self.base_dir, i) + vdev_info += "--vdev 'net_vhost%d,iface=vhost-net%d,client=1,queues=1' " % (i, i) self.vhostapp_testcmd = self.dut.base_dir + \ "/%s/app/testpmd -c %s -n %d --socket-mem %s --legacy-mem" + \ " --file-prefix=vhost %s" + \ @@ -120,7 +119,7 @@ class TestPVPVhostUserReconnect(TestCase): """ vdev_info = "" for i in range(self.vm_num): - vdev_info += "--vdev 'net_vhost%d,iface=%s/vhost-net%d,client=1,queues=1' " % (i, self.base_dir, i) + vdev_info += "--vdev 'net_vhost%d,iface=vhost-net%d,client=1,queues=1' " % (i, i) self.vhostapp_testcmd = self.dut.base_dir + \ "/%s/app/testpmd -c %s -n %d --socket-mem %s --legacy-mem" + \ " --no-pci --file-prefix=vhost %s" + \ @@ -181,7 +180,7 @@ class TestPVPVhostUserReconnect(TestCase): vm_info = VM(self.dut, 'vm%d' % i, 'vhost_sample') vm_params = {} vm_params['driver'] = 'vhost-user' - vm_params['opt_path'] = '%s/vhost-net%d' % (self.base_dir, i) + vm_params['opt_path'] = './vhost-net%d' % (i) vm_params['opt_mac'] = '52:54:00:00:00:0%d' % (i+1) vm_params['opt_server'] = 'server' vm_params['opt_settings'] = 'mrg_rxbuf=on,rx_queue_size=1024,tx_queue_size=1024' @@ -273,7 +272,7 @@ class TestPVPVhostUserReconnect(TestCase): pkt = Packet(pkt_type = 'UDP', pkt_len = frame_size) pkt.config_layers([('ether', {'dst': '%s' % self.dst_mac}), ('ipv4', {'dst': '%s' % self.dst1, 'src': '%s' % self.src1})]) - save_packets([pkt], "%s/reconnect.pcap" % self.out_path) + pkt.save_pcapfile(self.tester, "%s/reconnect.pcap" % self.out_path) tgenInput = [] port = self.tester.get_local_port(self.pf) diff --git a/tests/TestSuite_pvp_virtio_bonding.py b/tests/TestSuite_pvp_virtio_bonding.py index 4fb94f2..874c058 100644 --- a/tests/TestSuite_pvp_virtio_bonding.py +++ b/tests/TestSuite_pvp_virtio_bonding.py @@ -40,7 +40,7 @@ import utils from test_case import TestCase from virt_common import VM from pmd_output import PmdOutput -from packet import Packet, save_packets +from packet import Packet from pktgen import PacketGeneratorHelper @@ -69,7 +69,6 @@ class TestPVPVirtIOBonding(TestCase): self.tester.send_expect('mkdir -p %s' % self.out_path, '# ') # create an instance to set stream field setting self.pktgen_helper = PacketGeneratorHelper() - self.base_dir = self.dut.base_dir.replace('~', '/root') def set_up(self): """ @@ -87,7 +86,7 @@ class TestPVPVirtIOBonding(TestCase): """ vdev_info = "" for i in range(self.queues): - vdev_info += "--vdev 'net_vhost%d,iface=%s/vhost-net%d,client=1,queues=1' " % (i, self.base_dir, i) + vdev_info += "--vdev 'net_vhost%d,iface=vhost-net%d,client=1,queues=1' " % (i, i) params = "--port-topology=chained --nb-cores=4 --txd=1024 --rxd=1024" eal_param = "--socket-mem 2048,2048 --legacy-mem --file-prefix=vhost %s " % vdev_info self.vhost_testpmd = PmdOutput(self.dut) @@ -168,7 +167,7 @@ class TestPVPVirtIOBonding(TestCase): tx_port = self.tester.get_local_port(self.dut_ports[0]) pkt = Packet(pkt_type='UDP') pkt.config_layer('ether', {'dst': '%s' % self.dst_mac}) - save_packets([pkt], "%s/bonding.pcap" % self.out_path) + pkt.save_pcapfile(self.tester, "%s/bonding.pcap" % self.out_path) tgen_input.append((tx_port, rx_port, "%s/bonding.pcap" % self.out_path)) self.tester.pktgen.clear_streams() streams = self.pktgen_helper.prepare_stream_from_tginput(tgen_input, 100, None, self.tester.pktgen) @@ -196,7 +195,7 @@ class TestPVPVirtIOBonding(TestCase): for i in range(self.queues): vm_params['opt_server'] = 'server' vm_params['driver'] = 'vhost-user' - vm_params['opt_path'] = '%s/vhost-net%d' % (self.base_dir, i) + vm_params['opt_path'] = './vhost-net%d' % i vm_params['opt_mac'] = "%s%d" % (virtio_mac, i+1) self.vm.set_vm_device(**vm_params) self.set_vm_vcpu() diff --git a/tests/TestSuite_pvp_virtio_user_4k_pages.py b/tests/TestSuite_pvp_virtio_user_4k_pages.py index d2b8df7..95b5494 100644 --- a/tests/TestSuite_pvp_virtio_user_4k_pages.py +++ b/tests/TestSuite_pvp_virtio_user_4k_pages.py @@ -37,7 +37,7 @@ vhost/virtio-user pvp with 4K pages. import utils import time from test_case import TestCase -from packet import Packet, save_packets +from packet import Packet from pktgen import PacketGeneratorHelper @@ -108,7 +108,7 @@ class TestPvpVirtioUser4kPages(TestCase): tx_port = self.tester.get_local_port(self.dut_ports[0]) pkt = Packet(pkt_type='UDP', pkt_len=frame_size) pkt.config_layer('ether', {'dst': '%s' % self.dst_mac}) - save_packets([pkt], "%s/vhost.pcap" % self.out_path) + pkt.save_pcapfile(self.tester, "%s/vhost.pcap" % self.out_path) tgen_input.append((tx_port, rx_port, "%s/vhost.pcap" % self.out_path)) self.tester.pktgen.clear_streams() @@ -138,7 +138,6 @@ class TestPvpVirtioUser4kPages(TestCase): command_line_client = command_line_client % (self.target, self.core_mask_vhost_user, self.mem_channels, self.ports_socket) self.vhost_user.send_expect(command_line_client, "testpmd> ", 120) - self.vhost_user.send_expect("set fwd mac", "testpmd> ", 120) self.vhost_user.send_expect("start", "testpmd> ", 120) def start_testpmd_as_virtio(self): diff --git a/tests/TestSuite_queue_region.py b/tests/TestSuite_queue_region.py index a4d9bf7..eea873e 100644 --- a/tests/TestSuite_queue_region.py +++ b/tests/TestSuite_queue_region.py @@ -148,7 +148,7 @@ class TestQueue_region(TestCase): pkt = Packet() pkt.assign_layers(['ether', 'raw']) pkt.config_layer('ether', {'dst': mac, 'src': self.tester_mac, 'type': ethertype}) - pkt.send_pkt(tx_port=self.tester_intf) + pkt.send_pkt(self.tester, tx_port=self.tester_intf) def send_packet_up(self, mac, pkt_type="udp", prio=0): """ @@ -173,7 +173,7 @@ class TestQueue_region(TestCase): pkt.assign_layers(['ether', 'vlan', 'ipv6', 'udp', 'raw']) pkt.config_layer('ether', {'dst': mac, 'src': self.tester_mac}) pkt.config_layer('vlan', {'vlan': 0, 'prio': prio}) - pkt.send_pkt(tx_port=self.tester_intf) + pkt.send_pkt(self.tester, tx_port=self.tester_intf) def get_and_compare_rules(self, out, QueueRegion_num, FlowType_num, UP_num): """ diff --git a/tests/TestSuite_queue_start_stop.py b/tests/TestSuite_queue_start_stop.py index e91ea91..48f9c1a 100644 --- a/tests/TestSuite_queue_start_stop.py +++ b/tests/TestSuite_queue_start_stop.py @@ -101,11 +101,11 @@ class TestQueueStartStop(TestCase): pkt = Packet(pkt_type="UDP", pkt_len=pktSize) inst = self.tester.tcpdump_sniff_packets(rxitf) pkt.config_layer('ether', {'dst': dmac}) - pkt.send_pkt(tx_port=txitf, count=4) + pkt.send_pkt(self.tester, tx_port=txitf, count=4) sniff_pkts = self.tester.load_tcpdump_sniff_packets(inst) if received: - res = strip_pktload(sniff_pkts[0], layer="L4") + res = strip_pktload(sniff_pkts, layer="L4") self.verify("58 58 58 58 58 58 58 58" in res, "receive queue not work as expected") else: self.verify(len(sniff_pkts) == 0, "stop queue not work as expected") diff --git a/tests/TestSuite_quota_watermark.py b/tests/TestSuite_quota_watermark.py index ad4ec3b..0541eef 100644 --- a/tests/TestSuite_quota_watermark.py +++ b/tests/TestSuite_quota_watermark.py @@ -310,7 +310,7 @@ class TestQuotaWatermark(TestCase, IxiaPacketGenerator): rx_intf = self.tester.get_interface(rev_port) tx_intf = self.tester.get_interface(send_port) # send and sniff packet - rx_inst = self.tester.tcpdump_sniff_packets(rx_intf, timeout=5) + rx_inst = self.tester.tcpdump_sniff_packets(rx_intf) self.send_pcap_pkt_by_scapy(self.tester, tgen_input[0][2], tx_intf) pkts = self.tester.load_tcpdump_sniff_packets(rx_inst) self.verify(len(pkts) == pkt_cnt, "Packet not forwarded as expected") diff --git a/tests/TestSuite_runtime_vf_queue_number.py b/tests/TestSuite_runtime_vf_queue_number.py index 63a5e18..227d815 100644 --- a/tests/TestSuite_runtime_vf_queue_number.py +++ b/tests/TestSuite_runtime_vf_queue_number.py @@ -39,6 +39,7 @@ import re from qemu_kvm import QEMUKvm from test_case import TestCase from pmd_output import PmdOutput +from packet import Packet RSS_KEY = '6EA6A420D5138E712433B813AE45B3C4BECB2B405F31AD6C331835372D15E2D5E49566EE0ED1962AFA1B7932F3549520FD71C75E' PACKET_COUNT = 100 @@ -128,15 +129,9 @@ class TestRuntimeVfQn(TestCase): """ Sends packets. """ - self.tester.scapy_foreground() - time.sleep(2) - for i in range(integer): - quotient = i // 254 - remainder = i % 254 - packet = r'sendp([Ether(dst="%s", src=get_if_hwaddr("%s"))/IP(src="10.0.0.1", dst="192.168.%d.%d")], iface="%s")' % (vf_mac, itf, quotient, remainder + 1, itf) - self.tester.scapy_append(packet) - self.tester.scapy_execute() - time.sleep(2) + pkt = Packet() + pkt.generate_random_pkts(vf_mac, pktnum=integer, random_type=['IP_RAW']) + pkt.send_pkt(self.tester, tx_port=itf) def verify_queue_number(self, outstring, qn, pkt_count): total_rx = [] diff --git a/tests/TestSuite_runtime_vf_queue_number_kernel.py b/tests/TestSuite_runtime_vf_queue_number_kernel.py index 9416f13..73d40c2 100644 --- a/tests/TestSuite_runtime_vf_queue_number_kernel.py +++ b/tests/TestSuite_runtime_vf_queue_number_kernel.py @@ -41,6 +41,7 @@ import utils from pmd_output import PmdOutput from test_case import TestCase from virt_common import VM +from packet import Packet VM_CORES_MASK = 'all' @@ -75,6 +76,7 @@ class TestRuntimeVfQueueNumberKernel(TestCase): def set_up(self): pass + def setup_1pf_2vf_1vm_env(self,driver="default"): self.used_dut_port = self.dut_ports[0] @@ -90,9 +92,7 @@ class TestRuntimeVfQueueNumberKernel(TestCase): if driver == 'igb_uio': # start testpmd without the two VFs on the host self.host_testpmd = PmdOutput(self.dut) - eal_param = '-b %(vf0)s -b %(vf1)s' % {'vf0': self.sriov_vfs_port[0].pci, - 'vf1': self.sriov_vfs_port[1].pci} - self.host_testpmd.start_testpmd("Default", eal_param=eal_param) + self.host_testpmd.start_testpmd("Default") # set up VM0 ENV self.vm0 = VM(self.dut, 'vm0', 'runtime_vf_queue_number_kernel') self.vm0.set_vm_device(driver=self.vf_assign_method, **vf0_prop) @@ -131,15 +131,11 @@ class TestRuntimeVfQueueNumberKernel(TestCase): self.setup_1pf_2vf_1vm_env_flag = 0 - def send_packet2different_queue(self, dts, src, iface, count): - self.tester.scapy_foreground() - for i in range(1,count+1): - j = (i//255)%255 - k = i%255 - pkt = 'sendp([Ether(dst="%s", src="%s")/IP(src="192.168.%d.%d",dst="192.168.13.%d")/("test"*10)],iface="%s")' % ( - dts, src, j,k,k, iface) - self.tester.scapy_append(pkt) - self.tester.scapy_execute() + def send_packet2different_queue(self, dst, src, iface, count): + pkt = Packet() + pkt.generate_random_pkts(pktnum=count, random_type=['IP_RAW'], + options={'layers_config': [('ether', {'dst': '%s' % dst, 'src': '%s' % src})]}) + pkt.send_pkt(self.tester, tx_port=iface) def check_result(self, nr_queue, out, out2, pkts_num, count, misc): if nr_queue == 1: @@ -189,7 +185,7 @@ class TestRuntimeVfQueueNumberKernel(TestCase): self.vm0_testpmd.execute_cmd('set verbose 1') self.vm0_testpmd.execute_cmd('set promisc all off') - #set rss-hash-key to a fixed value instead of default random value on vf + #set rss-hash-key to a fixed value instead of default random value on vf self.vm0_testpmd.execute_cmd('port config 0 rss-hash-key ipv4 6EA6A420D5138E712433B813AE45B3C4BECB2B405F31AD6C331835372D15E2D5E49566EE0ED1962AFA1B7932F3549520FD71C75E') time.sleep(1) self.vm0_testpmd.execute_cmd('set fwd mac') @@ -297,6 +293,7 @@ class TestRuntimeVfQueueNumberKernel(TestCase): def tear_down(self): self.vm0_testpmd.execute_cmd('quit', '# ') + self.dut.kill_all() def tear_down_all(self): self.logger.info("tear_down_all") diff --git a/tests/TestSuite_rxtx_callbacks.py b/tests/TestSuite_rxtx_callbacks.py index 76ad70f..a2da0d9 100644 --- a/tests/TestSuite_rxtx_callbacks.py +++ b/tests/TestSuite_rxtx_callbacks.py @@ -90,8 +90,8 @@ class TestRxtxCallbacks(TestCase): def get_tcpdump_package(self,inst): pkts = self.tester.load_tcpdump_sniff_packets(inst) dsts = [] - for packet in pkts: - dst = packet.strip_element_layer2("dst") + for i in range(len(pkts)): + dst = pkts.strip_element_layer2("dst", p_index=i) dsts.append(dst) return dsts diff --git a/tests/TestSuite_scatter.py b/tests/TestSuite_scatter.py index cc441df..6802f52 100644 --- a/tests/TestSuite_scatter.py +++ b/tests/TestSuite_scatter.py @@ -85,12 +85,12 @@ class TestScatter(TestCase): inst = self.tester.tcpdump_sniff_packets(self.intf) pkt = Packet(pkt_type="IP_RAW", pkt_len=pktsize) pkt.config_layer('ether', {'dst': dmac}) - pkt.send_pkt(tx_port=self.intf) + pkt.send_pkt(self.tester, tx_port=self.intf) sniff_pkts = self.tester.load_tcpdump_sniff_packets(inst) res = "" if len(sniff_pkts): - res = strip_pktload(sniff_pkts[0], layer="L4") + res = strip_pktload(sniff_pkts, layer="L4") return res def set_up(self): diff --git a/tests/TestSuite_short_live.py b/tests/TestSuite_short_live.py index 93ec587..4e1ee15 100644 --- a/tests/TestSuite_short_live.py +++ b/tests/TestSuite_short_live.py @@ -102,7 +102,7 @@ class TestShortLiveApp(TestCase): if (txPort == rxPort): count = 2 - inst = self.tester.tcpdump_sniff_packets(rxitf, count=count, timeout=5) + inst = self.tester.tcpdump_sniff_packets(rxitf, count=count) pktlen = pktSize - 14 padding = pktlen - 20 @@ -112,7 +112,7 @@ class TestShortLiveApp(TestCase): time.sleep(3) pkts = self.tester.load_tcpdump_sniff_packets(inst) - out = str(pkts[0].pktgen.pkt.show) + out = str(pkts[0].show) self.logger.info('SCAPY Result:\n' + out + '\n\n\n') if received: self.verify(('PPP' in out) and 'src=%s'% Dut_tx_mac in out, "Receive test failed") diff --git a/tests/TestSuite_skeleton.py b/tests/TestSuite_skeleton.py index 91cf9c4..38bc523 100644 --- a/tests/TestSuite_skeleton.py +++ b/tests/TestSuite_skeleton.py @@ -93,8 +93,8 @@ class TestSkeleton(TestCase): def get_tcpdump_package(self,inst): pkts = self.tester.load_tcpdump_sniff_packets(inst) dsts = [] - for packet in pkts: - dst = packet.strip_element_layer2("dst") + for i in range(len(pkts)): + dst = pkts.strip_element_layer2("dst", p_index=i) dsts.append(dst) return dsts diff --git a/tests/TestSuite_sriov_kvm.py b/tests/TestSuite_sriov_kvm.py index 3518f8f..6a28129 100644 --- a/tests/TestSuite_sriov_kvm.py +++ b/tests/TestSuite_sriov_kvm.py @@ -359,10 +359,8 @@ class TestSriovKvm(TestCase): if driver == 'igb_uio': # start testpmd with the two VFs on the host self.host_testpmd = PmdOutput(self.dut) - eal_param = '-b %(vf0)s -b %(vf1)s' % {'vf0': self.sriov_vfs_port[0].pci, - 'vf1': self.sriov_vfs_port[1].pci} self.host_testpmd.start_testpmd( - "1S/2C/2T", "--rxq=4 --txq=4", eal_param=eal_param) + "1S/2C/2T", "--rxq=4 --txq=4") self.host_testpmd.execute_cmd('set fwd rxonly') self.host_testpmd.execute_cmd('start') @@ -439,13 +437,8 @@ class TestSriovKvm(TestCase): if driver == 'igb_uio': # start testpmd with the four VFs on the host self.host_testpmd = PmdOutput(self.dut) - eal_param = '-b %(vf0) -b %(vf1)s -b %(vf2)s -b %(vf3)s' % \ - {'vf0': self.sriov_vfs_pci[0], - 'vf1': self.sriov_vfs_pci[1], - 'vf2': self.sriov_vfs_pci[2], - 'vf3': self.sriov_vfs_pci[3]} self.host_testpmd.start_testpmd( - "1S/2C/2T", eal_param=eal_param) + "1S/2C/2T") self.vm0 = VM(self.dut, 'vm0', 'sriov_kvm') self.vm0.set_vm_device(driver=self.vf_assign_method, **vf0_prop) diff --git a/tests/TestSuite_uni_pkt.py b/tests/TestSuite_uni_pkt.py index 9a75061..0310e04 100644 --- a/tests/TestSuite_uni_pkt.py +++ b/tests/TestSuite_uni_pkt.py @@ -81,7 +81,7 @@ class TestUniPacket(TestCase): for pkt_type in pkt_types.keys(): pkt_names = pkt_types[pkt_type] pkt = Packet(pkt_type=pkt_type) - pkt.send_pkt(tx_port=self.tester_iface, count=4) + pkt.send_pkt(self.tester, tx_port=self.tester_iface, count=4) out = self.dut.get_session_output(timeout=2) for pkt_layer_name in pkt_names: if pkt_layer_name not in out: @@ -111,10 +111,10 @@ class TestUniPacket(TestCase): for l2_type in self.L2_types.keys(): pkt_name = self.L2_types[l2_type] pkt = Packet(pkt_type=l2_type) - pkt.send_pkt(tx_port=self.tester_iface) + pkt.send_pkt(self.tester, tx_port=self.tester_iface) out = self.dut.get_session_output(timeout=2) if pkt_name in out: - print utils.GREEN("Detected L2 %s successfully" % l2_type) + print(utils.GREEN("Detected L2 %s successfully" % l2_type)) else: raise VerifyFailure("Failed to detect L2 %s" % l2_type) @@ -347,7 +347,7 @@ class TestUniPacket(TestCase): pkt.config_layers([('ipv6',{'nh':47}), ('inner_ipv6', {'nh': 58})]) else: pkt.config_layers([('ipv6',{'nh':47}),('inner_ipv6', {'nh': 132})]) - pkt.send_pkt(tx_port=self.tester_iface) + pkt.send_pkt(self.tester, tx_port=self.tester_iface) out = self.dut.get_session_output(timeout=2) for pkt_layer_name in pkts[1]: if pkt_layer_name not in out: @@ -445,7 +445,6 @@ class TestUniPacket(TestCase): for packet in nsh_packets: self.tester.scapy_foreground() - self.tester.scapy_append("from scapy.contrib.nsh import *") self.tester.scapy_append("sendp([%s],iface='%s')" % (nsh_packets[packet], self.tester_iface)) self.tester.scapy_execute() out = self.dut.get_session_output(timeout=2) diff --git a/tests/TestSuite_userspace_ethtool.py b/tests/TestSuite_userspace_ethtool.py index 0a4b772..116fd3a 100644 --- a/tests/TestSuite_userspace_ethtool.py +++ b/tests/TestSuite_userspace_ethtool.py @@ -297,7 +297,7 @@ class TestUserspaceEthtool(TestCase, IxiaPacketGenerator): tester_port = self.tester.get_local_port(port) intf = self.tester.get_interface(tester_port) ori_rx_pkts, ori_tx_pkts = self.strip_portstats(port) - pkt.send_pkt(tx_port=intf, count=4) + pkt.send_pkt(self.tester, tx_port=intf, count=4) time.sleep(1) rx_pkts, tx_pkts = self.strip_portstats(port) self.verify((rx_pkts == (ori_rx_pkts + 4)), "Failed to record Rx/Tx packets") @@ -406,10 +406,10 @@ class TestUserspaceEthtool(TestCase, IxiaPacketGenerator): rx_ring, _, tx_ring, _ = self.strip_ringparam(index) self.verify(rx_ring == rx_max, "Userspace tool failed to set Rx ring parameter") self.verify(tx_ring == tx_max, "Userspace tool failed to set Tx ring parameter") - pkt = Packet() + pkt = Packet(pkt_type='UDP') tester_port = self.tester.get_local_port(port) intf = self.tester.get_interface(tester_port) - pkt.send_pkt(tx_port=intf, count=4) + pkt.send_pkt(self.tester, tx_port=intf, count=4) rx_pkts, tx_pkts = self.strip_portstats(index) self.verify(rx_pkts == ori_rx_pkts + 4, "Failed to forward after ring parameter changed") self.dut.send_expect("quit", "# ") @@ -441,7 +441,7 @@ class TestUserspaceEthtool(TestCase, IxiaPacketGenerator): pkt.config_layer('vlan', {'vlan': vlan}) tester_port = self.tester.get_local_port(port) intf = self.tester.get_interface(tester_port) - pkt.send_pkt(tx_port=intf, count=4) + pkt.send_pkt(self.tester, tx_port=intf, count=4) rx_pkts, tx_pkts = self.strip_portstats(port) self.verify(rx_pkts == ori_rx_pkts + 4, "Failed to Rx vlan packet") self.verify(tx_pkts == ori_tx_pkts + 4, "Failed to Tx vlan packet") @@ -449,7 +449,7 @@ class TestUserspaceEthtool(TestCase, IxiaPacketGenerator): # send incorrect vlan packet to port wrong_vlan = (vlan + 1) % 4096 pkt.config_layer('vlan', {'vlan': wrong_vlan}) - pkt.send_pkt(tx_port=intf, count=4) + pkt.send_pkt(self.tester, tx_port=intf, count=4) time.sleep(2) rx_pkts_wrong, tx_pkts_wrong = self.strip_portstats(port) self.verify(tx_pkts_wrong == rx_pkts, "Failed to filter Rx vlan packet") @@ -458,7 +458,7 @@ class TestUserspaceEthtool(TestCase, IxiaPacketGenerator): self.dut.send_expect("vlan %d del %d" % (index, vlan), "EthApp>") # send same packet and make sure not received pkt.config_layer('vlan', {'vlan': vlan}) - pkt.send_pkt(tx_port=intf, count=4) + pkt.send_pkt(self.tester, tx_port=intf, count=4) time.sleep(2) rx_pkts_del, tx_pkts_del = self.strip_portstats(port) self.verify(tx_pkts_del == rx_pkts, "Failed to remove Rx vlan filter") @@ -483,15 +483,15 @@ class TestUserspaceEthtool(TestCase, IxiaPacketGenerator): dump_mac = self.strip_mac(index) self.verify(dump_mac == valid_mac, "Userspace tool failed to set mac") # check forwarded mac has been changed - pkt = Packet() + pkt = Packet(pkt_type='UDP') tester_port = self.tester.get_local_port(port) intf = self.tester.get_interface(tester_port) # send and sniff packet - inst = self.tester.tcpdump_sniff_packets(intf, timeout=5) - pkt.send_pkt(tx_port=intf, count=4) + inst = self.tester.tcpdump_sniff_packets(intf) + pkt.send_pkt(self.tester, tx_port=intf, count=4) pkts = self.tester.load_tcpdump_sniff_packets(inst) self.verify(len(pkts) == 4, "Packet not forwarded as expected") - src_mac = pkts[0].strip_layer_element("layer2", "src") + src_mac = pkts.strip_layer_element("layer2", "src", p_index=0) self.verify(src_mac == valid_mac, "Forwarded packet not match default mac") # check multicast will not be valid mac @@ -519,10 +519,10 @@ class TestUserspaceEthtool(TestCase, IxiaPacketGenerator): self.dut.send_expect("stop %d" % index, "EthApp>") time.sleep(10) # check packet not forwarded when port is stop - pkt = Packet() + pkt = Packet(pkt_type='UDP') tester_port = self.tester.get_local_port(port) intf = self.tester.get_interface(tester_port) - pkt.send_pkt(tx_port=intf, count=4) + pkt.send_pkt(self.tester, tx_port=intf, count=4) rx_pkts, tx_pkts = self.strip_portstats(index) self.verify(rx_pkts == ori_rx_pkts, "Failed to stop port") # restart port and check packet can normally forwarded @@ -531,7 +531,7 @@ class TestUserspaceEthtool(TestCase, IxiaPacketGenerator): # wait few time for port ready rx_pkts, tx_pkts = self.strip_portstats(index) time.sleep(2) - pkt.send_pkt(tx_port=intf, count=4) + pkt.send_pkt(self.tester, tx_port=intf, count=4) rx_pkts_open, tx_pkts_open = self.strip_portstats(index) self.verify(rx_pkts_open == rx_pkts + 4, "Failed to reopen port rx") self.verify(tx_pkts_open == tx_pkts + 4, "Failed to reopen port tx") @@ -568,12 +568,12 @@ class TestUserspaceEthtool(TestCase, IxiaPacketGenerator): time.sleep(5) ori_rx_pkts, _ = self.strip_portstats(index) pkt_size = mtu + HEADER_SIZE['eth'] + offset - pkt = Packet(pkt_len=pkt_size) - pkt.send_pkt(tx_port=intf, count=4) + pkt = Packet(pkt_type='UDP', pkt_len=pkt_size) + pkt.send_pkt(self.tester, tx_port=intf, count=4) rx_pkts, _ = self.strip_portstats(index) self.verify(rx_pkts == ori_rx_pkts + 4, "Packet match mtu not forwarded as expected") - pkt = Packet(pkt_len=mtu + 1 + HEADER_SIZE['eth'] + offset) - pkt.send_pkt(tx_port=intf, count=4) + pkt = Packet(pkt_type='UDP', pkt_len=mtu + 1 + HEADER_SIZE['eth'] + offset) + pkt.send_pkt(self.tester, tx_port=intf, count=4) rx_pkts_over, _ = self.strip_portstats(index) self.verify(rx_pkts == rx_pkts_over, "Packet over mtu should not be forwarded") diff --git a/tests/TestSuite_veb_switch.py b/tests/TestSuite_veb_switch.py index 78fcbbd..e60a618 100644 --- a/tests/TestSuite_veb_switch.py +++ b/tests/TestSuite_veb_switch.py @@ -120,12 +120,12 @@ class TestVEBSwitching(TestCase): pkt = Packet(pkt_type='VLAN_UDP') pkt.config_layer('ether', {'dst': vf_mac}) pkt.config_layer('vlan', {'vlan': 1}) - pkt.send_pkt(tx_port=itf) + pkt.send_pkt(self.tester, tx_port=itf) time.sleep(.5) else: pkt = Packet(pkt_type='UDP') pkt.config_layer('ether', {'dst': vf_mac}) - pkt.send_pkt(tx_port=itf) + pkt.send_pkt(self.tester, tx_port=itf) time.sleep(.5) def count_packet(self, out, mac): diff --git a/tests/TestSuite_vf_daemon.py b/tests/TestSuite_vf_daemon.py index fcbf5b8..5b738c7 100644 --- a/tests/TestSuite_vf_daemon.py +++ b/tests/TestSuite_vf_daemon.py @@ -90,12 +90,9 @@ class TestVfDaemon(TestCase): for port in self.sriov_vfs_port: port.bind_driver(self.vf_driver) time.sleep(1) - eal_param = '-b %(vf0)s -b %(vf1)s' % {'vf0': self.sriov_vfs_port[0].pci, - 'vf1': self.sriov_vfs_port[1].pci} - self.dut_testpmd = PmdOutput(self.dut) self.dut_testpmd.start_testpmd( - "Default", "--rxq=4 --txq=4 --port-topology=chained", eal_param=eal_param) + "Default", "--rxq=4 --txq=4 --port-topology=chained") self.dut_testpmd.execute_cmd("start") time.sleep(5) @@ -166,8 +163,8 @@ class TestVfDaemon(TestCase): pkt.config_layer('vlan', {'vlan': vlan_id}) pkt.config_layer('ether', {'dst': dst_mac}) - inst = self.tester.tcpdump_sniff_packets(self.tester_intf, timeout=30) - pkt.send_pkt(tx_port=self.tester_intf, count=num) + inst = self.tester.tcpdump_sniff_packets(self.tester_intf) + pkt.send_pkt(self.tester, tx_port=self.tester_intf, count=num) return inst def strip_mac(self, inst, element = "src"): @@ -176,8 +173,8 @@ class TestVfDaemon(TestCase): """ pkts = self.tester.load_tcpdump_sniff_packets(inst) macs = [] - for pkt in pkts: - mac = pkt.strip_element_layer2(element) + for i in range(len(pkts)): + mac = pkts.strip_element_layer2(element, p_index=i) macs.append(mac) return macs @@ -187,8 +184,8 @@ class TestVfDaemon(TestCase): """ pkts = self.tester.load_tcpdump_sniff_packets(inst) vlans = [] - for pkt in pkts: - vlan = pkt.strip_element_vlan("vlan") + for i in range(len(pkts)): + vlan = pkts.strip_element_vlan("vlan", p_index=i) vlans.append(vlan) return vlans @@ -434,7 +431,7 @@ class TestVfDaemon(TestCase): self.dut_testpmd.execute_cmd('set tx loopback 0 off') time.sleep(5) - inst = self.tester.tcpdump_sniff_packets(self.tester_intf, timeout=10) + inst = self.tester.tcpdump_sniff_packets(self.tester_intf) self.vm1_testpmd.execute_cmd('set burst 5') self.vm1_testpmd.execute_cmd('start tx_first') @@ -450,7 +447,7 @@ class TestVfDaemon(TestCase): self.dut_testpmd.execute_cmd('set tx loopback 0 on') time.sleep(3) - inst = self.tester.tcpdump_sniff_packets(self.tester_intf, timeout=10) + inst = self.tester.tcpdump_sniff_packets(self.tester_intf) self.vm1_testpmd.execute_cmd('stop') self.vm1_testpmd.execute_cmd('start tx_first') diff --git a/tests/TestSuite_vf_interrupt_pmd.py b/tests/TestSuite_vf_interrupt_pmd.py index cc15ac6..0b1f858 100644 --- a/tests/TestSuite_vf_interrupt_pmd.py +++ b/tests/TestSuite_vf_interrupt_pmd.py @@ -108,7 +108,7 @@ class TestVfInterruptPmd(TestCase): """ pkt = Packet(pkt_type='UDP') pkt.config_layer('ether', {'dst': mac, 'src': self.tester_mac}) - pkt.send_pkt(tx_port=testinterface) + pkt.send_pkt(self.tester, tx_port=testinterface) self.out2 = use_dut.get_session_output(timeout=2) diff --git a/tests/TestSuite_vf_jumboframe.py b/tests/TestSuite_vf_jumboframe.py index f082cec..dd728d9 100644 --- a/tests/TestSuite_vf_jumboframe.py +++ b/tests/TestSuite_vf_jumboframe.py @@ -174,7 +174,7 @@ class TestVfJumboFrame(TestCase): pkt = Packet(pkt_type='UDP', pkt_len=pktsize) pkt.config_layer('ether', {'dst': mac}) - pkt.send_pkt(tx_port=self.tester_intf) + pkt.send_pkt(self.tester, tx_port=self.tester_intf) time.sleep(1) diff --git a/tests/TestSuite_vf_kernel.py b/tests/TestSuite_vf_kernel.py index bee30a0..9a280b1 100644 --- a/tests/TestSuite_vf_kernel.py +++ b/tests/TestSuite_vf_kernel.py @@ -119,12 +119,8 @@ class TestVfKernel(TestCase): time.sleep(1) self.dut_testpmd = PmdOutput(self.dut) - eal_param = '' - for sriov_vf in self.sriov_vfs_port: - eal_param += " -b %s" % sriov_vf.pci self.dut_testpmd.start_testpmd( - "Default", "--rxq=4 --txq=4 --port-topology=chained", - eal_param=eal_param) + "Default", "--rxq=4 --txq=4 --port-topology=chained") # dpdk-2208 # since there is no forward engine on DPDK PF to forward or drop packet in packet pool, # so finally the pool will be full, then no more packet will be @@ -412,12 +408,12 @@ class TestVfKernel(TestCase): if vlan_id == '': pkt = Packet(pkt_type='TCP', pkt_len=pkt_lens) pkt.config_layer('ether', {'dst': mac, 'src': self.tester_mac}) - pkt.send_pkt(tx_port=self.tester_intf, count=num) + pkt.send_pkt(self.tester, tx_port=self.tester_intf, count=num) else: pkt = Packet(pkt_type='VLAN_UDP', pkt_len=pkt_lens) pkt.config_layer('ether', {'dst': mac, 'src': self.tester_mac}) pkt.config_layer('vlan', {'vlan': vlan_id}) - pkt.send_pkt(tx_port=self.tester_intf, count=num) + pkt.send_pkt(self.tester, tx_port=self.tester_intf, count=num) def test_vlan(self): """ @@ -873,8 +869,7 @@ class TestVfKernel(TestCase): # Link down DPDK VF0 and expect no impact on other VFs self.vm0_testpmd.quit() - eal_param = '-b %(vf0)s' % ({'vf0': self.vm0_dut.ports_info[0]['pci']}) - self.vm0_testpmd.start_testpmd("Default", eal_param=eal_param) + self.vm0_testpmd.start_testpmd("Default") self.vm0_testpmd.execute_cmd('set promisc all on') self.vm0_testpmd.execute_cmd('set fwd rxonly') self.vm0_testpmd.execute_cmd('set verbose 1') diff --git a/tests/TestSuite_vf_macfilter.py b/tests/TestSuite_vf_macfilter.py index f7bba1a..01da9b4 100644 --- a/tests/TestSuite_vf_macfilter.py +++ b/tests/TestSuite_vf_macfilter.py @@ -67,12 +67,10 @@ class TestVfMacFilter(TestCase): if driver == 'igb_uio': # start testpmd without the two VFs on the host self.host_testpmd = PmdOutput(self.dut) - eal_param = '-b %(vf0)s -b %(vf1)s' % {'vf0': self.sriov_vfs_port_0[0].pci, - 'vf1': self.sriov_vfs_port_1[0].pci} if (self.nic in ["niantic", "sageville", "sagepond"]): - self.host_testpmd.start_testpmd("1S/9C/1T", "--txq=4 --rxq=4 ", eal_param=eal_param) + self.host_testpmd.start_testpmd("1S/9C/1T", "--txq=4 --rxq=4 ") else: - self.host_testpmd.start_testpmd("1S/2C/2T", eal_param=eal_param) + self.host_testpmd.start_testpmd("1S/2C/2T") # set up VM0 ENV self.vm0 = VM(self.dut, 'vm0', 'vf_macfilter') @@ -158,7 +156,7 @@ class TestVfMacFilter(TestCase): print "\nfirst send packets to the PF set MAC, expected result is RX packets=TX packets\n" result1 = self.tester.check_random_pkts(tgen_ports, pktnum=100, allow_miss=False, params=pkt_param) - print "\nshow port stats in testpmd for double check: \n", self.vm0_testpmd.execute_cmd('show port stats all') + print "\nshow port stats in testpmd for double check: \n", self.vm0_testpmd.execute_cmd('show port stats all') self.verify(result1 != False, "VF0 failed to forward packets to VF1") print "\nSecondly, negative test, send packets to a wrong MAC, expected result is RX packets=0\n" @@ -259,6 +257,7 @@ class TestVfMacFilter(TestCase): if self.setup_2pf_2vf_1vm_env_flag == 1: self.destroy_2pf_2vf_1vm_env() + self.dut.kill_all() def tear_down_all(self): diff --git a/tests/TestSuite_vf_offload.py b/tests/TestSuite_vf_offload.py index dc5cb30..421d9c4 100644 --- a/tests/TestSuite_vf_offload.py +++ b/tests/TestSuite_vf_offload.py @@ -71,9 +71,7 @@ class TestVfOffload(TestCase): if driver == 'igb_uio': # start testpmd without the two VFs on the host self.host_testpmd = PmdOutput(self.dut) - eal_param = '-b %(vf0)s -b %(vf1)s' % {'vf0': self.sriov_vfs_port_0[0].pci, - 'vf1': self.sriov_vfs_port_1[0].pci} - self.host_testpmd.start_testpmd("1S/2C/2T", eal_param=eal_param) + self.host_testpmd.start_testpmd("1S/2C/2T") # set up VM0 ENV self.vm0 = VM(self.dut, 'vm0', 'vf_offload') diff --git a/tests/TestSuite_vf_packet_rxtx.py b/tests/TestSuite_vf_packet_rxtx.py index 8a8816d..c111c9e 100644 --- a/tests/TestSuite_vf_packet_rxtx.py +++ b/tests/TestSuite_vf_packet_rxtx.py @@ -6,6 +6,7 @@ import time from virt_common import VM from test_case import TestCase from pmd_output import PmdOutput +from packet import Packet VM_CORES_MASK = 'all' @@ -64,12 +65,10 @@ class TestVfPacketRxtx(TestCase): if driver == 'igb_uio': # start testpmd without the two VFs on the host self.host_testpmd = PmdOutput(self.dut) - eal_param = '-b %(vf0)s -b %(vf1)s' % {'vf0': self.sriov_vfs_port_0[0].pci, - 'vf1': self.sriov_vfs_port_1[0].pci} if (self.nic in ["niantic", "sageville", "sagepond"]): - self.host_testpmd.start_testpmd("1S/9C/1T", "--txq=4 --rxq=4 ", eal_param=eal_param) + self.host_testpmd.start_testpmd("1S/9C/1T", "--txq=4 --rxq=4 ") else: - self.host_testpmd.start_testpmd("1S/5C/1T", "", eal_param=eal_param) + self.host_testpmd.start_testpmd("1S/5C/1T") # set up VM0 ENV self.vm0 = VM(self.dut, 'vm0', 'vf_packet_rxtx') @@ -189,13 +188,10 @@ class TestVfPacketRxtx(TestCase): if driver == 'igb_uio': self.host_testpmd = PmdOutput(self.dut) - eal_param = '-b %(vf0)s -b %(vf1)s -b %(vf2)s' % {'vf0': self.sriov_vfs_port[0].pci, - 'vf1': self.sriov_vfs_port[1].pci, - 'vf2': self.sriov_vfs_port[2].pci} if (self.nic in ["niantic", "sageville", "sagepond"]): - self.host_testpmd.start_testpmd("1S/9C/1T", "--txq=4 --rxq=4 ", eal_param=eal_param) + self.host_testpmd.start_testpmd("1S/9C/1T", "--txq=4 --rxq=4 ") else: - self.host_testpmd.start_testpmd("1S/2C/2T", eal_param=eal_param) + self.host_testpmd.start_testpmd("1S/2C/2T") # set up VM0 ENV self.vm0 = VM(self.dut, 'vm0', 'vf_packet_rxtx') @@ -290,7 +286,8 @@ class TestVfPacketRxtx(TestCase): dst_mac = pmd0_vf0_mac self.vm0_testpmd.execute_cmd('clear port stats all') - self.tester.sendpkt_bg(tx_port, dst_mac) + pkt = Packet("Ether(dst='%s', src='%s')/IP(len=46)" % (dst_mac, self.tester.get_mac(tx_port))) + filename = pkt.send_pkt_bg(crb=self.tester, tx_port=self.tester.get_interface(tx_port), loop=1) #vf port stop/start can trigger reset action for num in range(1000): @@ -299,7 +296,7 @@ class TestVfPacketRxtx(TestCase): self.vm1_testpmd.execute_cmd('port start all') time.sleep(0.1) - self.tester.stop_sendpkt_bg() + pkt.stop_send_pkt_bg(self.tester, filename) pmd0_vf0_stats = self.vm0_testpmd.get_pmd_stats(port_id_0) pmd0_vf1_stats = self.vm0_testpmd.get_pmd_stats(port_id_1) diff --git a/tests/TestSuite_vf_port_start_stop.py b/tests/TestSuite_vf_port_start_stop.py index 2ff2d1c..dcd799b 100644 --- a/tests/TestSuite_vf_port_start_stop.py +++ b/tests/TestSuite_vf_port_start_stop.py @@ -10,6 +10,7 @@ from utils import RED, GREEN from net_device import NetDevice from crb import Crb from scapy.all import * +from scapy.layers.sctp import SCTP, SCTPChunkData VM_CORES_MASK = 'all' class TestVfPortStartStop(TestCase): @@ -22,7 +23,9 @@ 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) + self.send_pks_session = None # set vf assign method and vf driver self.vf_driver = self.get_suite_cfg()['vf_driver'] if self.vf_driver is None: @@ -38,71 +41,23 @@ class TestVfPortStartStop(TestCase): 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) - def send_and_verify(self, dst_mac, testpmd): """ Generates packets by pktgen """ 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. """ @@ -115,9 +70,14 @@ class TestVfPortStartStop(TestCase): 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("pk=rdpcap('%s')" % filename, ">>>") + self.send_pks_session.send_command(sendp_fmt) + def testpmd_reset_status(self, testpmd): """ Reset testpmd :stop forward & stop port @@ -175,9 +135,7 @@ class TestVfPortStartStop(TestCase): if driver == 'igb_uio': # start testpmd without the two VFs on the host self.host_testpmd = PmdOutput(self.dut) - eal_param = '-b %(vf0)s -b %(vf1)s' % {'vf0': self.sriov_vfs_port[0].pci, - 'vf1': self.sriov_vfs_port[1].pci} - self.host_testpmd.start_testpmd("1S/2C/2T", eal_param=eal_param) + self.host_testpmd.start_testpmd("1S/2C/2T") # set up VM0 ENV self.vm0 = VM(self.dut, 'vm0', 'vf_port_start_stop') @@ -242,13 +200,9 @@ 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) if getattr(self, 'vm0', None): self.vm0.stop() diff --git a/tests/TestSuite_vf_rss.py b/tests/TestSuite_vf_rss.py index 8220926..95d13cd 100644 --- a/tests/TestSuite_vf_rss.py +++ b/tests/TestSuite_vf_rss.py @@ -277,8 +277,7 @@ class TestVfRss(TestCase): if driver == 'igb_uio': # start testpmd without the two VFs on the host self.host_testpmd = PmdOutput(self.dut) - eal_param = '-b %(vf0)s ' % {'vf0': self.sriov_vfs_port_0[0].pci} - self.host_testpmd.start_testpmd("1S/2C/2T", eal_param=eal_param) + self.host_testpmd.start_testpmd("1S/2C/2T") # set up VM0 ENV self.vm0 = VM(self.dut, 'vm0', 'vf_rss') diff --git a/tests/TestSuite_vf_vlan.py b/tests/TestSuite_vf_vlan.py index f50a7e5..7f46aa6 100644 --- a/tests/TestSuite_vf_vlan.py +++ b/tests/TestSuite_vf_vlan.py @@ -173,8 +173,8 @@ class TestVfVlan(TestCase): pkt = Packet(pkt_type='UDP') pkt.config_layer('ether', {'dst': self.vf1_mac}) - inst = self.tester.tcpdump_sniff_packets(self.tester_intf0, timeout=5) - pkt.send_pkt(tx_port=self.tester_intf1) + inst = self.tester.tcpdump_sniff_packets(self.tester_intf0) + pkt.send_pkt(self.tester, tx_port=self.tester_intf1) pkts = self.tester.load_tcpdump_sniff_packets(inst) self.verify(len(pkts), "Not receive expected packet") @@ -194,7 +194,7 @@ class TestVfVlan(TestCase): pkt.config_layer('vlan', {'vlan': vlan}) pkt.config_layer('ether', {'dst': self.vf0_mac}) - pkt.send_pkt(tx_port=self.tester_intf0) + pkt.send_pkt(self.tester, tx_port=self.tester_intf0) out = self.vm_dut_0.get_session_output(timeout=2) return out @@ -258,7 +258,7 @@ class TestVfVlan(TestCase): "ip link set %s vf 0 vlan 0" % (self.host_intf0), "# ") def tx_and_check(self, tx_vlan=1): - inst = self.tester.tcpdump_sniff_packets(self.tester_intf0, timeout=5) + inst = self.tester.tcpdump_sniff_packets(self.tester_intf0) self.vm0_testpmd.execute_cmd('set burst 1') self.vm0_testpmd.execute_cmd('start tx_first') self.vm0_testpmd.execute_cmd('stop') @@ -266,8 +266,8 @@ class TestVfVlan(TestCase): # strip sniffered vlans pkts = self.tester.load_tcpdump_sniff_packets(inst) vlans = [] - for pkt in pkts: - vlan = pkt.strip_element_vlan("vlan") + for i in range(len(pkts)): + vlan = pkts.strip_element_vlan("vlan", p_index=i) vlans.append(vlan) self.verify( diff --git a/tests/TestSuite_vhost_enqueue_interrupt.py b/tests/TestSuite_vhost_enqueue_interrupt.py index 428cf36..5c4c1df 100644 --- a/tests/TestSuite_vhost_enqueue_interrupt.py +++ b/tests/TestSuite_vhost_enqueue_interrupt.py @@ -192,6 +192,7 @@ class TestVhostEnqueueInterrupt(TestCase): self.close_testpmd_and_session() self.dut.send_expect("killall -s INT l3fwd-power", "#") self.dut.send_expect("killall -s INT testpmd", "#") + self.dut.kill_all() def tear_down_all(self): """ diff --git a/tests/TestSuite_vhost_multi_queue_qemu.py b/tests/TestSuite_vhost_multi_queue_qemu.py index f0dbb90..d31eb57 100644 --- a/tests/TestSuite_vhost_multi_queue_qemu.py +++ b/tests/TestSuite_vhost_multi_queue_qemu.py @@ -40,7 +40,7 @@ import utils from test_case import TestCase from settings import HEADER_SIZE from virt_common import VM -from packet import Packet, send_packets, save_packets +from packet import Packet from pmd_output import PmdOutput from pktgen import PacketGeneratorHelper @@ -154,8 +154,7 @@ class TestVhostMultiQueueQemu(TestCase): pkt1.config_layers([('ether', {'dst': '%s' % self.virtio1_mac}), ('ipv4', {'dst': '1.1.1.1'}), ('raw', {'payload': ['01'] * int('%d' % payload_size)})]) - pkt = [pkt1] - save_packets(pkt, "%s/multiqueue.pcap" % self.out_path) + pkt1.save_pcapfile(self.tester, "%s/multiqueue.pcap" % self.out_path) port = self.tester.get_local_port(self.pf) tgenInput.append((port, port, "%s/multiqueue.pcap" % self.out_path)) @@ -185,7 +184,7 @@ class TestVhostMultiQueueQemu(TestCase): self.logger.info(info) self.dut.send_expect("clear port stats all", "testpmd> ", 120) payload_size = frame_size - HEADER_SIZE['eth'] - HEADER_SIZE['ip'] - HEADER_SIZE['udp'] - + pkts = Packet() pkt1 = Packet() pkt1.assign_layers(['ether', 'ipv4', 'udp', 'raw']) pkt1.config_layers([('ether', {'dst': '%s' % self.virtio1_mac}), ('ipv4', {'dst': '1.1.1.1'}), @@ -203,11 +202,13 @@ class TestVhostMultiQueueQemu(TestCase): pkt4.config_layers([('ether', {'dst': '%s' % self.virtio1_mac}), ('ipv4', {'dst': '1.1.1.8'}), ('udp', {'src': 4789, 'dst': 4789}), ('raw', {'payload': ['01'] * int('%d' % payload_size)})]) - pkt = [pkt1, pkt2, pkt3, pkt4] * 10 - send_packets(self.tx_interface, pkt) + pkt = [pkt1, pkt2, pkt3, pkt4] + for i in pkt: + pkts.pktgen.pkts.append(i.pktgen.pkt) + pkts.send_pkt(self.tester, tx_port=self.tx_interface, count=10) out = self.dut.send_expect("show port stats 0", "testpmd> ", 120) - print out + print(out) rx_packet = re.search("RX-packets:\s*(\d*)", out) rx_num = int(rx_packet.group(1)) tx_packet = re.search("TX-packets:\s*(\d*)", out) diff --git a/tests/TestSuite_vhost_pmd_xstats.py b/tests/TestSuite_vhost_pmd_xstats.py index a58c107..1e1a323 100755 --- a/tests/TestSuite_vhost_pmd_xstats.py +++ b/tests/TestSuite_vhost_pmd_xstats.py @@ -126,7 +126,7 @@ class TestVhostPmdXstats(TestCase): self.scapy_num += 1 pkt = Packet(pkt_type='TCP', pkt_len=pktsize) pkt.config_layer('ether', {'dst': dmac, }) - pkt.send_pkt(tx_port=self.txItf, count=num) + pkt.send_pkt(self.tester, tx_port=self.txItf, count=num) def send_verify(self, scope, mun): """ diff --git a/tests/TestSuite_vhost_virtio_pmd_interrupt.py b/tests/TestSuite_vhost_virtio_pmd_interrupt.py index d31122b..0eeb42e 100644 --- a/tests/TestSuite_vhost_virtio_pmd_interrupt.py +++ b/tests/TestSuite_vhost_virtio_pmd_interrupt.py @@ -38,7 +38,7 @@ import utils import time from virt_common import VM from test_case import TestCase -from packet import Packet, save_packets +from packet import Packet from pktgen import PacketGeneratorHelper @@ -234,7 +234,7 @@ class TestVhostVirtioPmdInterrupt(TestCase): else: pkt = Packet(pkt_type='IP_RAW') pkt.config_layer('ether', {'dst': '%s' % self.dst_mac}) - save_packets([pkt], "%s/interrupt.pcap" % self.out_path) + pkt.save_pcapfile(self.tester, "%s/interrupt.pcap" % self.out_path) tgen_input.append((self.tx_port, self.tx_port, "%s/interrupt.pcap" % self.out_path)) self.tester.pktgen.clear_streams() vm_config = self.set_fields() diff --git a/tests/TestSuite_virtio_ipsec_cryptodev_func.py b/tests/TestSuite_virtio_ipsec_cryptodev_func.py index d89a93d..6f6aa19 100644 --- a/tests/TestSuite_virtio_ipsec_cryptodev_func.py +++ b/tests/TestSuite_virtio_ipsec_cryptodev_func.py @@ -247,7 +247,7 @@ class VirtioCryptodevIpsecTest(TestCase): def send_and_dump_pkg(self): status = True - inst = self.tester.tcpdump_sniff_packets(self.rx_interface, timeout=25) + inst = self.tester.tcpdump_sniff_packets(self.rx_interface) PACKET_COUNT = 65 payload = 256 * ['11'] @@ -261,21 +261,19 @@ class VirtioCryptodevIpsecTest(TestCase): pkt.config_layer("ipv4", {"src": src_ip, "dst": dst_ip}) pkt.config_layer("udp", {"dst": 0}) pkt.config_layer("raw", {"payload": payload}) - pkt.send_pkt(tx_port=self.tx_interface, count=PACKET_COUNT) + pkt.send_pkt(self.tester, tx_port=self.tx_interface, count=PACKET_COUNT) pkt_rec = self.tester.load_tcpdump_sniff_packets(inst) self.logger.info("dump: {} packets".format(len(pkt_rec))) if len(pkt_rec) != PACKET_COUNT: self.logger.info("dump pkg: {}, the num of pkg dumped is incorrtct!".format(len(pkt_rec))) status = False - - for pkt_r in pkt_rec: - #pkt_r.pktgen.pkt.show() - if src_ip != pkt_r.pktgen.strip_layer3("src") or dst_ip != pkt_r.pktgen.strip_layer3("dst"): + for i in range(len(pkt_rec)): + if src_ip != pkt_rec.pktgen.strip_layer3("src", p_index=i) or dst_ip != pkt_rec.pktgen.strip_layer3("dst", p_index=i): self.logger.info("the ip of pkg dumped is incorrtct!") status = False - dump_text = binascii.b2a_hex(pkt_r.pktgen.pkt["Raw"].getfieldval("load")) + dump_text = binascii.b2a_hex(pkt_rec[i]["Raw"].getfieldval("load")) if dump_text != ''.join(payload): self.logger.info("the text of pkg dumped is incorrtct!") status = False diff --git a/tests/TestSuite_vlan.py b/tests/TestSuite_vlan.py index 9c58b0c..77c33d0 100644 --- a/tests/TestSuite_vlan.py +++ b/tests/TestSuite_vlan.py @@ -86,8 +86,8 @@ class TestVlan(TestCase): def get_tcpdump_package(self): pkts = self.tester.load_tcpdump_sniff_packets(self.inst) vlans = [] - for packet in pkts: - vlan = packet.strip_element_vlan("vlan") + for i in range(len(pkts)): + vlan = pkts.strip_element_vlan("vlan", p_index=i) vlans.append(vlan) return vlans @@ -116,7 +116,7 @@ class TestVlan(TestCase): pkt.config_layer('ether', {'dst': self.dmac, 'src': self.smac}) pkt.config_layer('vlan', {'vlan': vid}) - pkt.send_pkt(tx_port=self.txItf, count=4) + pkt.send_pkt(self.tester, tx_port=self.txItf, count=4) def set_up(self): """ diff --git a/tests/TestSuite_vm2vm_virtio_pmd.py b/tests/TestSuite_vm2vm_virtio_pmd.py index 2db020f..da8f939 100644 --- a/tests/TestSuite_vm2vm_virtio_pmd.py +++ b/tests/TestSuite_vm2vm_virtio_pmd.py @@ -42,7 +42,7 @@ import time import utils from virt_common import VM from test_case import TestCase -from packet import load_pcapfile +from packet import Packet class TestVM2VMVirtioPMD(TestCase): @@ -211,11 +211,12 @@ class TestVM2VMVirtioPMD(TestCase): vm_dut.send_expect('quit', '#', 60) time.sleep(2) vm_dut.session.copy_file_from(src="%s" % self.dump_pcap, dst="%s" % self.dump_pcap) - pkts = load_pcapfile(self.dump_pcap) + pkt = Packet() + pkts = pkt.read_pcapfile(self.dump_pcap) self.verify(len(pkts) == 10, "The vm0 do not capture all the packets") - data = str(pkts[0].pktgen.pkt['Raw']) + data = str(pkts[0]['Raw']) for i in range(1, 10): - value = str(pkts[i].pktgen.pkt['Raw']) + value = str(pkts[i]['Raw']) self.verify(data == value, "the payload in receive packets has been changed") def stop_all_apps(self): diff --git a/tests/TestSuite_vxlan.py b/tests/TestSuite_vxlan.py index 2be5741..2046abe 100644 --- a/tests/TestSuite_vxlan.py +++ b/tests/TestSuite_vxlan.py @@ -26,6 +26,7 @@ from scapy.route import * from test_case import TestCase from settings import HEADER_SIZE, FOLDERS from etgen import IxiaPacketGenerator +import packet # # @@ -48,6 +49,7 @@ class VxlanTestConfig(object): self.init() for name in kwargs: setattr(self, name, kwargs[name]) + self.pkt_obj = packet.Packet() def init(self): self.packets_config() @@ -56,8 +58,8 @@ class VxlanTestConfig(object): """ Default vxlan packet format """ - self.pcap_file = '/root/vxlan.pcap' - self.capture_file = '/root/vxlan_capture.pcap' + self.pcap_file = packet.TMP_PATH + 'vxlan.pcap' + self.capture_file = packet.TMP_PATH + 'vxlan_capture.pcap' self.outer_mac_src = '00:00:10:00:00:00' self.outer_mac_dst = '11:22:33:44:55:66' self.outer_vlan = 'N/A' @@ -186,29 +188,28 @@ class VxlanTestConfig(object): return self.pkt - def get_chksums(self, pcap=None): + def get_chksums(self, pkt=None): """ get chksum values of Outer and Inner packet L3&L4 Skip outer udp for it will be calculated by software """ chk_sums = {} - if pcap is None: - pkts = rdpcap(self.pcap_file) + if pkt is None: + pkt = rdpcap(self.pcap_file) else: - pkts = rdpcap(pcap) + pkt = pkt.pktgen.pkt time.sleep(1) - - if pkts[0].guess_payload_class(pkts[0]).name == "802.1Q": - payload = pkts[0][Dot1Q] + if pkt[0].guess_payload_class(pkt[0]).name == "802.1Q": + payload = pkt[0][Dot1Q] else: - payload = pkts[0] + payload = pkt[0] if payload.guess_payload_class(payload).name == "IP": chk_sums['outer_ip'] = hex(payload[IP].chksum) - if pkts[0].haslayer('VXLAN') == 1: - inner = pkts[0]['VXLAN'] + if pkt[0].haslayer('VXLAN') == 1: + inner = pkt[0]['VXLAN'] if inner.haslayer(IP) == 1: chk_sums['inner_ip'] = hex(inner[IP].chksum) if inner[IP].proto == 6: @@ -236,16 +237,10 @@ class VxlanTestConfig(object): """ Send vxlan pcap file by iface """ - # load vxlan module to scapy - cwd = os.getcwd() - dir_vxlan_module = cwd + r'/' + FOLDERS['Depends'] - self.test_case.tester.scapy_append("sys.path.append('%s')" % dir_vxlan_module) - self.test_case.tester.scapy_append("from vxlan import VXLAN") - self.test_case.tester.scapy_append( - 'pcap = rdpcap("%s")' % self.pcap_file) - self.test_case.tester.scapy_append( - 'sendp(pcap, iface="%s")' % iface) - self.test_case.tester.scapy_execute() + del self.pkt_obj.pktgen.pkts[:] + self.pkt_obj.pktgen.assign_pkt(self.pkt) + self.pkt_obj.pktgen.update_pkts() + self.pkt_obj.send_pkt(crb=self.test_case.tester, tx_port=iface) def pcap_len(self): """ @@ -262,12 +257,10 @@ class TestVxlan(TestCase, IxiaPacketGenerator): vxlan Prerequisites """ # this feature only enable in FVL now - if self.nic in ["fortville_eagle", "fortville_spirit", "fortville_spirit_single", "fortville_25g", "fortpark_TLV", "carlsville"]: + if self.nic in ["fortville_eagle", "fortville_spirit", "fortville_spirit_single", "fortville_25g", "fortpark_TLV"]: self.compile_switch = 'CONFIG_RTE_LIBRTE_I40E_INC_VECTOR' elif self.nic in ["sageville", "sagepond"]: self.compile_switch = 'CONFIG_RTE_IXGBE_INC_VECTOR' - elif self.nic in ["columbiaville_25g","columbiaville_100g"]: - print "CVL support default none VECTOR" else: self.verify(False, "%s not support this vxlan" % self.nic) # Based on h/w type, choose how many ports to use @@ -448,20 +441,14 @@ class TestVxlan(TestCase, IxiaPacketGenerator): config.outer_mac_dst = self.dut_port_mac config.create_pcap() - # remove tempory files - config.capture_file = "/tmp/sniff_%s.pcap" % self.recv_iface - self.tester.send_expect("rm -rf %s" % config.capture_file, "# ") # save the capture packet into pcap format - self.tester.scapy_background() - - inst = self.tester.tcpdump_sniff_packets(self.recv_iface, timeout=5) + inst = self.tester.tcpdump_sniff_packets(self.recv_iface) config.send_pcap(self.tester_iface) - self.tester.load_tcpdump_sniff_packets(inst) + pkt = self.tester.load_tcpdump_sniff_packets(inst) time.sleep(5) # extract the checksum offload from saved pcap file - chksums = config.get_chksums(pcap=config.capture_file) - os.remove(config.capture_file) + chksums = config.get_chksums(pkt=pkt) self.logger.info("chksums" + str(chksums)) out = self.dut.send_expect("stop", "testpmd>", 10) @@ -535,19 +522,14 @@ class TestVxlan(TestCase, IxiaPacketGenerator): """ verify vxlan packet detection """ - if self.nic in ["columbiaville_25g","columbiaville_100g"]: - print "CVL support default none VECTOR" - src_vec_model = 'n' - else: - out = self.dut.send_expect("cat config/common_base", "]# ", 10) - src_vec_model = re.findall("%s=." % self.compile_switch, out)[0][-1] - if src_vec_model == 'y': - self.dut.send_expect("sed -i -e 's/%s=.*$/" % self.compile_switch - + "%s=n/' config/common_base" % self.compile_switch, "# ", 30) - self.dut.skip_setup = False - self.dut.build_install_dpdk(self.target) + out = self.dut.send_expect("cat config/common_base", "]# ", 10) + src_vec_model = re.search("%s=." % self.compile_switch, out).group()[-1] + if src_vec_model == 'y': + self.dut.send_expect("sed -i -e 's/%s=.*$/" % self.compile_switch + + "%s=n/' config/common_base" % self.compile_switch, "# ", 30) + self.dut.skip_setup = False + self.dut.build_install_dpdk(self.target) - pmd_temp = "./%(TARGET)s/app/testpmd -c %(COREMASK)s -n " + \ "%(CHANNEL)d -- -i --disable-rss --rxq=4 --txq=4" + \ " --nb-cores=4 --portmask=%(PORT)s" @@ -561,8 +543,6 @@ class TestVxlan(TestCase, IxiaPacketGenerator): self.dut.send_expect("set verbose 1", "testpmd>", 10) self.enable_vxlan(self.dut_port) self.enable_vxlan(self.recv_port) - res = self.pmdout.wait_link_status_up("all") - self.verify(res is True, "link is donw") # check normal packet self.send_and_detect(outer_udp_dst=1234) @@ -579,33 +559,26 @@ class TestVxlan(TestCase, IxiaPacketGenerator): out = self.dut.send_expect("stop", "testpmd>", 10) self.dut.send_expect("quit", "#", 10) - if self.nic in ["columbiaville_25g","columbiaville_100g"]: - print "CVL support default none VECTOR" - src_vec_model = 'n' - else: - out = self.dut.send_expect("cat config/common_base", "]# ", 10) - dst_vec_model = re.findall("%s=." % self.compile_switch, out)[0][-1] - if src_vec_model != dst_vec_model: - self.dut.send_expect("sed -i -e 's/%s=.*$/" % self.compile_switch - + "%s=%s/' config/common_base" % (self.compile_switch, src_vec_model), "# ", 30) - self.dut.skip_setup = False - self.dut.build_install_dpdk(self.target) + + out = self.dut.send_expect("cat config/common_base", "]# ", 10) + dst_vec_model = re.findall("%s=." % self.compile_switch, out)[0][-1] + if src_vec_model != dst_vec_model: + self.dut.send_expect("sed -i -e 's/%s=.*$/" % self.compile_switch + + "%s=%s/' config/common_base" % (self.compile_switch, src_vec_model), "# ", 30) + self.dut.skip_setup = False + self.dut.build_install_dpdk(self.target) def test_vxlan_ipv6_detect(self): """ verify vxlan packet detection with ipv6 header """ - if self.nic in ["columbiaville_25g","columbiaville_100g"]: - print "CVL support default none VECTOR" - src_vec_model = 'n' - else: - out = self.dut.send_expect("cat config/common_base", "]# ", 10) - src_vec_model = re.findall("%s=." % self.compile_switch, out)[0][-1] - if src_vec_model == 'y': - self.dut.send_expect("sed -i -e 's/%s=.*$/" % self.compile_switch - + "%s=n/' config/common_base" % self.compile_switch, "# ", 30) - self.dut.skip_setup = False - self.dut.build_install_dpdk(self.target) + out = self.dut.send_expect("cat config/common_base", "]# ", 10) + src_vec_model = re.search("%s=." % self.compile_switch, out).group()[-1] + if src_vec_model == 'y': + self.dut.send_expect("sed -i -e 's/%s=.*$/" % self.compile_switch + + "%s=n/' config/common_base" % self.compile_switch, "# ", 30) + self.dut.skip_setup = False + self.dut.build_install_dpdk(self.target) pmd_temp = "./%(TARGET)s/app/testpmd -c %(COREMASK)s -n " + \ "%(CHANNEL)d -- -i --disable-rss --rxq=4 --txq=4" + \ @@ -620,8 +593,6 @@ class TestVxlan(TestCase, IxiaPacketGenerator): self.dut.send_expect("set verbose 1", "testpmd>", 10) self.enable_vxlan(self.dut_port) self.enable_vxlan(self.recv_port) - res = self.pmdout.wait_link_status_up("all") - self.verify(res is True, "link is donw") # check normal ipv6 packet self.send_and_detect(outer_ip6_src="FE80:0:0:0:0:0:0:0", @@ -642,17 +613,14 @@ class TestVxlan(TestCase, IxiaPacketGenerator): out = self.dut.send_expect("stop", "testpmd>", 10) self.dut.send_expect("quit", "#", 10) - if self.nic in ["columbiaville_25g","columbiaville_100g"]: - print "CVL support default none VECTOR" - src_vec_model = 'n' - else: - out = self.dut.send_expect("cat config/common_base", "]# ", 10) - dst_vec_model = re.findall("%s=." % self.compile_switch, out)[0][-1] - if src_vec_model != dst_vec_model: - self.dut.send_expect("sed -i -e 's/%s=.*$/" % self.compile_switch - + "%s=%s/' config/common_base" % (self.compile_switch, src_vec_model), "# ", 30) - self.dut.skip_setup = False - self.dut.build_install_dpdk(self.target) + + out = self.dut.send_expect("cat config/common_base", "]# ", 10) + dst_vec_model = re.findall("%s=." % self.compile_switch, out)[0][-1] + if src_vec_model != dst_vec_model: + self.dut.send_expect("sed -i -e 's/%s=.*$/" % self.compile_switch + + "%s=%s/' config/common_base" % (self.compile_switch, src_vec_model), "# ", 30) + self.dut.skip_setup = False + self.dut.build_install_dpdk(self.target) def test_vxlan_ipv4_checksum_offload(self): """ @@ -682,9 +650,6 @@ class TestVxlan(TestCase, IxiaPacketGenerator): self.dut.send_expect("port start all", "testpmd>") self.dut.send_expect("csum parse-tunnel on %d" % self.recv_port, "testpmd>", 10) - res = self.pmdout.wait_link_status_up("all") - self.verify(res is True, "link is donw") - self.enable_vxlan(self.dut_port) self.enable_vxlan(self.recv_port) @@ -759,7 +724,6 @@ class TestVxlan(TestCase, IxiaPacketGenerator): self.enable_vxlan(self.dut_port) self.enable_vxlan(self.recv_port) - time.sleep(10) #lwj # check normal ipv6 packet self.send_and_check(outer_ip6_src="FE80:0:0:0:0:0:0:0", @@ -1169,8 +1133,6 @@ class TestVxlan(TestCase, IxiaPacketGenerator): self.dut.send_expect("port start all", "testpmd>") self.verify("Bad arguments" not in out, "Failed to set vxlan csum") self.verify("error" not in out, "Failed to set vxlan csum") - res = self.pmdout.wait_link_status_up("all") - self.verify(res is True, "link is donw") def csum_set_sw(self, proto, port): self.dut.send_expect("port stop all", "testpmd>") @@ -1179,9 +1141,6 @@ class TestVxlan(TestCase, IxiaPacketGenerator): self.dut.send_expect("port start all", "testpmd>") self.verify("Bad arguments" not in out, "Failed to set vxlan csum") self.verify("error" not in out, "Failed to set vxlan csum") - res = self.pmdout.wait_link_status_up("all") - self.verify(res is True, "link is donw") - def tunnel_filter_add(self, *args): # tunnel_filter add port_id outer_mac inner_mac ip inner_vlan diff --git a/tests/TestSuite_vxlan_sample.py b/tests/TestSuite_vxlan_sample.py index 5bc9269..df7bbcf 100644 --- a/tests/TestSuite_vxlan_sample.py +++ b/tests/TestSuite_vxlan_sample.py @@ -48,7 +48,7 @@ from etgen import IxiaPacketGenerator from qemu_kvm import QEMUKvm from TestSuite_vxlan import VxlanTestConfig from pmd_output import PmdOutput -from packet import IncreaseIP, IncreaseIPv6 +from packet import Packet from scapy.utils import wrpcap, rdpcap from scapy.layers.inet import Ether, IP, TCP, UDP @@ -106,7 +106,6 @@ class TestVxlanSample(TestCase): # params for tep_termination self.cores = self.dut.get_core_list("1S/4C/1T", socket=self.socket) - self.capture_file = "/tmp/vxlan_cap.pcap" self.def_mss = 256 # performance measurement, checksum based on encap @@ -266,32 +265,18 @@ class TestVxlanSample(TestCase): self.send_and_verify(vm_id=0, vf_id=0, pkt_type="vxlan_tcp_tso") def start_capture(self, itf, pkt_smac="", pkt_dmac="", count=1): - self.tester.send_expect("rm -f %s" % self.capture_file, "# ") - self.tester.scapy_background() + self.inst = None + filter_param = [] if pkt_smac != "": - self.tester.scapy_append( - 'p = sniff(filter="ether src %s",' % pkt_smac + - 'iface="%s", count=%d, timeout=5)' % (itf, count)) - if pkt_dmac != "": - self.tester.scapy_append( - 'p = sniff(filter="ether dst %s",' % pkt_dmac + - 'iface="%s", count=%d, timeout=5)' % (itf, count)) - self.tester.scapy_append( - 'wrpcap(\"%s\", p)' % self.capture_file) - self.tester.scapy_foreground() + filter_param = [{'layer': 'ether', 'config': {'src': '%s' % pkt_smac}}] + if pkt_dmac != "": + filter_param = [{'layer': 'ether', 'config': {'dst': '%s' % pkt_dmac}}] + self.inst = self.tester.tcpdump_sniff_packets(itf, count, filters=filter_param) def transfer_capture_file(self): # copy capture file from tester - if os.path.isfile('vxlan_cap.pcap'): - os.remove('vxlan_cap.pcap') - self.tester.session.copy_file_from(self.capture_file) - - if os.path.isfile('vxlan_cap.pcap'): - self.verify(os.path.getsize('vxlan_cap.pcap') != 0, "Packets receive error") - pkts = rdpcap('vxlan_cap.pcap') - else: - pkts = [] - return pkts + pkts = self.tester.load_tcpdump_sniff_packets(self.inst) + return pkts.pktgen.pkts def send_and_verify(self, vm_id, vf_id, pkt_type): params = {} @@ -430,7 +415,10 @@ class TestVxlanSample(TestCase): self.verify(len(pkts) >= 1, "Failed to capture packets") self.verify(pkts[0].haslayer('VXLAN') == 1, "Packet not encapsulated") - chksums = vxlan_pkt.get_chksums(pcap='vxlan_cap.pcap') + pk_new = Packet() + pk_new.pktgen.assign_pkt(pkts) + pk_new.pktgen.update_pkts() + chksums = vxlan_pkt.get_chksums(pk_new) print utils.GREEN("Checksum : %s" % chksums) for key in chksums_ref: if 'inner' in key: # only check inner packet chksum -- 2.17.1