class TestDdpGtp(TestCase): def set_up_all(self): self.verify(self.nic in ['fortville_25g'], 'ddp gtp can not support %s nic' % self.nic) self.dut_ports = self.dut.get_ports(self.nic) self.verify(len(self.dut_ports) >= 1, "Insufficient ports") self.vm0 = None self.env_done = False profile_file = 'dep/gtp.pkgo' profile_dst = "/tmp/" self.dut.session.copy_file_to(profile_file, profile_dst) PF_Q_strip = 'CONFIG_RTE_LIBRTE_I40E_QUEUE_NUM_PER_PF' VF_Q_strip = 'CONFIG_RTE_LIBRTE_I40E_QUEUE_NUM_PER_VF' self.PF_QUEUE = self.search_queue_number(PF_Q_strip) self.VF_QUEUE = self.search_queue_number(VF_Q_strip) def set_up(self): self.setup_vm_env() self.load_profile() def search_queue_number(self, Q_strip): """ Search max queue number from configuration. """ out = self.dut.send_expect("cat config/common_base", "]# ", 10) pattern = "(%s=)(\d*)" % Q_strip s = re.compile(pattern) res = s.search(out) if res is None: print utils.RED('Search no queue number.') return None else: queue = res.group(2) return int(queue) def bind_nic_driver(self, ports, driver=""): if driver == "igb_uio": for port in ports: netdev = self.dut.ports_info[port]['port'] driver = netdev.get_nic_driver() if driver != 'igb_uio': netdev.bind_driver(driver='igb_uio') else: for port in ports: netdev = self.dut.ports_info[port]['port'] driver_now = netdev.get_nic_driver() if driver == "": driver = netdev.default_driver if driver != driver_now: netdev.bind_driver(driver=driver) def setup_vm_env(self, driver='igb_uio'): """ Create testing environment with VF generated from 1PF """ if self.env_done is False: self.bind_nic_driver(self.dut_ports[:1], driver="igb_uio") self.used_dut_port = self.dut_ports[0] tester_port = self.tester.get_local_port(self.used_dut_port) self.tester_intf = self.tester.get_interface(tester_port) self.dut.generate_sriov_vfs_by_port(self.used_dut_port, 1, driver=driver) self.sriov_vfs_port = self.dut.ports_info[ self.used_dut_port]['vfs_port'] for port in self.sriov_vfs_port: port.bind_driver('pci-stub') time.sleep(1) self.dut_testpmd = PmdOutput(self.dut) time.sleep(1) vf0_prop = {'opt_host': self.sriov_vfs_port[0].pci} # set up VM0 ENV self.vm0 = QEMUKvm(self.dut, 'vm0', 'ddp_gtp') self.vm0.set_vm_device(driver='pci-assign', **vf0_prop) try: self.vm0_dut = self.vm0.start() if self.vm0_dut is None: raise Exception("Set up VM0 ENV failed!") except Exception as e: self.destroy_vm_env() raise Exception(e) self.vm0_dut_ports = self.vm0_dut.get_ports('any') self.vm0_testpmd = PmdOutput(self.vm0_dut) self.env_done = True def destroy_vm_env(self): if getattr(self, 'vm0', None): self.vm0_dut.kill_all() self.vm0_testpmd = None self.vm0_dut_ports = None # destroy vm0 self.vm0.stop() self.vm0 = None if getattr(self, 'used_dut_port', None): self.dut.destroy_sriov_vfs_by_port(self.used_dut_port) port = self.dut.ports_info[self.used_dut_port]['port'] self.used_dut_port = None self.env_done = False def load_profile(self): """ Load profile to update FVL configuration tables, profile will be stored in binary file and need to be passed to AQ to program FVL during initialization stage. """ self.dut_testpmd.start_testpmd( "Default", "--pkt-filter-mode=perfect --port-topology=chained \ --txq=%s --rxq=%s" % (self.PF_QUEUE, self.PF_QUEUE)) self.vm0_testpmd.start_testpmd( VM_CORES_MASK, "--port-topology=chained --txq=%s --rxq=%s" % (self.VF_QUEUE, self.VF_QUEUE)) self.dut_testpmd.execute_cmd('port stop all') time.sleep(1) out = self.dut_testpmd.execute_cmd('ddp get list 0') self.dut_testpmd.execute_cmd('ddp add 0 /tmp/gtp.pkgo') out = self.dut_testpmd.execute_cmd('ddp get list 0') self.verify("Profile number is: 1" in out, "Failed to load ddp profile!!!") self.dut_testpmd.execute_cmd('port start all') time.sleep(1) self.dut_testpmd.execute_cmd('set fwd rxonly') self.dut_testpmd.execute_cmd('set verbose 1') self.dut_testpmd.execute_cmd('start') self.vm0_testpmd.execute_cmd('set fwd rxonly') self.vm0_testpmd.execute_cmd('set verbose 1') self.vm0_testpmd.execute_cmd('start') def gtp_packets(self, type='fdir', tunnel_pkt='gtpu', inner_L3='ipv4', match_opt='matched', chk='', teid=0xF): """ Generate different GTP types according to different parameters. Input: filter type: includes flow director and cloud filter tunnel packet: includes GTPC and GTPU inner_L3: GTPC has no inner L3. GTPU has no, IPV4 and IPV6 inner L3. match_opt: PF or VSIs receive match packets to configured queue, but receive not match packets to queue 0. Flow director directs different TEIDs, inner L3 GTP packets to different queues. Cloud filter directs different TEIDs GTP packets to different queues. chk: checksum teid: GTP teid """ pkts = [] pkts_gtpc_pay = { 'IPV4/GTPC': 'Ether()/IP()/UDP(%sdport=2123)/GTP_U_Header(teid=%s)/Raw("X"*20)' % (chk, teid), 'IPV6/GTPC': 'Ether()/IPv6()/UDP(%sdport=2123)/GTP_U_Header(teid=%s)/Raw("X"*20)' % (chk, teid) } pkts_gtpu_pay = { 'IPV4/GTPU': 'Ether()/IP()/UDP(%sdport=2152)/GTP_U_Header(teid=%s)/Raw("X"*20)' % (chk, teid), 'IPV6/GTPU': 'Ether()/IPv6()/UDP(%sdport=2152)/GTP_U_Header(teid=%s)/Raw("X"*20)' % (chk, teid) } pkts_gtpu_ipv4 = { 'IPV4/GTPU/IPV4': 'Ether()/IP()/UDP(%sdport=2152)/GTP_U_Header(teid=%s)/IP()/Raw("X"*20)' % (chk, teid), 'IPV4/GTPU/IPV4/FRAG': 'Ether()/IP()/UDP(%sdport=2152)/GTP_U_Header(teid=%s)/IP(frag=5)/Raw("X"*20)' % (chk, teid), 'IPV4/GTPU/IPV4/UDP': 'Ether()/IP()/UDP(%sdport=2152)/GTP_U_Header(teid=%s)/IP()/UDP()/Raw("X"*20)' % (chk, teid), 'IPV4/GTPU/IPV4/TCP': 'Ether()/IP()/UDP(%sdport=2152)/GTP_U_Header(teid=%s)/IP()/TCP()/Raw("X"*20)' % (chk, teid), 'IPV4/GTPU/IPV4/SCTP': 'Ether()/IP()/UDP(%sdport=2152)/GTP_U_Header(teid=%s)/IP()/SCTP()/Raw("X"*20)' % (chk, teid), 'IPV4/GTPU/IPV4/ICMP': 'Ether()/IP()/UDP(%sdport=2152)/GTP_U_Header(teid=%s)/IP()/ICMP()/Raw("X"*20)' % (chk, teid), 'IPV6/GTPU/IPV4': 'Ether()/IPv6()/UDP(%sdport=2152)/GTP_U_Header(teid=%s)/IP()/Raw("X"*20)' % (chk, teid), 'IPV6/GTPU/IPV4/FRAG': 'Ether()/IPv6()/UDP(%sdport=2152)/GTP_U_Header(teid=%s)/IP(frag=5)/Raw("X"*20)' % (chk, teid), 'IPV6/GTPU/IPV4/UDP': 'Ether()/IPv6()/UDP(%sdport=2152)/GTP_U_Header(teid=%s)/IP()/UDP()/Raw("X"*20)' % (chk, teid), 'IPV6/GTPU/IPV4/TCP': 'Ether()/IPv6()/UDP(%sdport=2152)/GTP_U_Header(teid=%s)/IP()/TCP()/Raw("X"*20)' % (chk, teid), 'IPV6/GTPU/IPV4/SCTP': 'Ether()/IPv6()/UDP(%sdport=2152)/GTP_U_Header(teid=%s)/IP()/SCTP()/Raw("X"*20)' % (chk, teid), 'IPV6/GTPU/IPV4/ICMP': 'Ether()/IPv6()/UDP(%sdport=2152)/GTP_U_Header(teid=%s)/IP()/ICMP()/Raw("X"*20)' % (chk, teid) } pkts_gtpu_ipv6 = { 'IPV4/GTPU/IPV6/FRAG': 'Ether()/IP()/UDP(%sdport=2152)/GTP_U_Header(teid=%s)/IPv6()/IPv6ExtHdrFragment()/Raw("X"*20)' % (chk, teid), 'IPV4/GTPU/IPV6': 'Ether()/IP()/UDP(%sdport=2152)/GTP_U_Header(teid=%s)/IPv6()/Raw("X"*20)' % (chk, teid), 'IPV4/GTPU/IPV6/UDP': 'Ether()/IP()/UDP(%sdport=2152)/GTP_U_Header(teid=%s)/IPv6()/UDP()/Raw("X"*20)' % (chk, teid), 'IPV4/GTPU/IPV6/TCP': 'Ether()/IP()/UDP(%sdport=2152)/GTP_U_Header(teid=%s)/IPv6()/TCP()/Raw("X"*20)' % (chk, teid), 'IPV4/GTPU/IPV6/SCTP': 'Ether()/IP()/UDP(%sdport=2152)/GTP_U_Header(teid=%s)/IPv6()/SCTP()/Raw("X"*20)' % (chk, teid), 'IPV4/GTPU/IPV6/ICMP': 'Ether()/IP()/UDP(%sdport=2152)/GTP_U_Header(teid=%s)/IPv6(nh=58)/ICMP()/Raw("X"*20)' % (chk, teid), 'IPV6/GTPU/IPV6/FRAG': 'Ether()/IPv6()/UDP(%sdport=2152)/GTP_U_Header(teid=%s)/IPv6()/IPv6ExtHdrFragment()/Raw("X"*20)' % (chk, teid), 'IPV6/GTPU/IPV6': 'Ether()/IPv6()/UDP(%sdport=2152)/GTP_U_Header(teid=%s)/IPv6()/Raw("X"*20)' % (chk, teid), 'IPV6/GTPU/IPV6/UDP': 'Ether()/IPv6()/UDP(%sdport=2152)/GTP_U_Header(teid=%s)/IPv6()/UDP()/Raw("X"*20)' % (chk, teid), 'IPV6/GTPU/IPV6/TCP': 'Ether()/IPv6()/UDP(%sdport=2152)/GTP_U_Header(teid=%s)/IPv6()/TCP()/Raw("X"*20)' % (chk, teid), 'IPV6/GTPU/IPV6/SCTP': 'Ether()/IPv6()/UDP(%sdport=2152)/GTP_U_Header(teid=%s)/IPv6()/SCTP()/Raw("X"*20)' % (chk, teid), 'IPV6/GTPU/IPV6/ICMP': 'Ether()/IPv6()/UDP(%sdport=2152)/GTP_U_Header(teid=%s)/IPv6(nh=58)/ICMP()/Raw("X"*20)' % (chk, teid) } if match_opt == 'matched': if tunnel_pkt is 'gtpc' and inner_L3 is None: pkts = pkts_gtpc_pay if tunnel_pkt is 'gtpu' and inner_L3 is None: pkts = pkts_gtpu_pay if tunnel_pkt is 'gtpu' and inner_L3 is 'ipv4': pkts = pkts_gtpu_ipv4 if tunnel_pkt is 'gtpu' and inner_L3 is 'ipv6': pkts = pkts_gtpu_ipv6 if match_opt == 'not matched': if type is 'fdir': if tunnel_pkt is 'gtpc' and inner_L3 is None: pkts = dict(pkts_gtpu_pay.items() + pkts_gtpu_ipv4.items() + pkts_gtpu_ipv6.items()) if tunnel_pkt is 'gtpu' and inner_L3 is None: pkts = dict(pkts_gtpc_pay.items() + pkts_gtpu_ipv4.items() + pkts_gtpu_ipv6.items()) if tunnel_pkt is 'gtpu' and inner_L3 is 'ipv4': pkts = dict(pkts_gtpc_pay.items() + pkts_gtpu_pay.items() + pkts_gtpu_ipv6.items()) if tunnel_pkt is 'gtpu' and inner_L3 is 'ipv6': pkts = dict(pkts_gtpc_pay.items() + pkts_gtpu_pay.items() + pkts_gtpu_ipv4.items()) if type is 'clfter': if tunnel_pkt is 'gtpc': pkts = dict(pkts_gtpu_pay.items() + pkts_gtpu_ipv4.items() + pkts_gtpu_ipv6.items()) if tunnel_pkt is 'gtpu': pkts = pkts_gtpc_pay return pkts def gtp_test(self, type='fdir', port='pf', tunnel_pkt='gtpu', inner_L3='ipv4'): """ Send GTP packet to dut, receive packet from configured queue. Input: filter type, port type, packet type, inner L3 type """ queue = random.randint(1, self.PF_QUEUE - 1) if port != 'pf': queue = random.randint(1, self.VF_QUEUE - 1) random_teid = random.randint(0x0, 0xFFFFFFFF) correct_teid = hex(random_teid) wrong_teid = hex((random_teid + 2) % int(0xFFFFFFFF)) if type is 'fdir': if inner_L3 is None: self.dut_testpmd.execute_cmd( 'flow create 0 ingress pattern eth / ipv4 / udp / \ %s teid is %s / end actions queue index %d / end' % (tunnel_pkt, correct_teid, queue)) else: self.dut_testpmd.execute_cmd( 'flow create 0 ingress pattern eth / ipv4 / udp / \ %s teid is %s / %s / end actions queue index %d / end' % (tunnel_pkt, correct_teid, inner_L3, queue)) if type is 'clfter': self.dut_testpmd.execute_cmd( 'flow create 0 ingress pattern eth / ipv4 / udp / \ %s teid is %s / end actions %s / queue index %d / end' % (tunnel_pkt, correct_teid, port, queue)) for match_opt in ['matched', 'not matched']: teid = correct_teid pkts = [] for teid_opt in ['correct teid', 'wrong teid']: chk = '' for chksum_opt in ['good chksum', 'bad chksum']: pkts = self.gtp_packets(type, tunnel_pkt, inner_L3, match_opt, chk, teid) for packet_type in pkts.keys(): self.tester.scapy_append( 'sendp([%s], iface="%s")' % (pkts[packet_type], self.tester_intf)) self.tester.scapy_execute() if port is 'pf': out = self.dut.get_session_output(timeout=2) else: out = self.vm0_dut.get_session_output(timeout=2) self.verify( "port 0/queue %d" % queue in out, "Failed to receive packet in this queue!!!") if port is 'pf': layerparams = [ 'L3_', 'TUNNEL_', 'INNER_L3_', 'INNER_L4_' ] ptypes = packet_type.split('/') endparams = [ '_EXT_UNKNOWN', '', '_EXT_UNKNOWN', '' ] for layerparam, ptype, endparam in zip( layerparams, ptypes, endparams): layer_type = layerparam + ptype + endparam self.verify( layer_type in out, "Failed to output ptype information!!!") if queue != 0 and type is 'fdir': self.verify("PKT_RX_FDIR" in out, "Failed to test flow director!!!") if teid == wrong_teid or match_opt == 'not matched': break chk = 'chksum=0x1234,' if match_opt == 'not matched': break queue = 0 teid = wrong_teid def test_fdir_gtpc_pf(self): """ GTP is supported by NVM with profile updated. Select flow director to do classfication, send gtpc packet to PF, check PF could receive packet using configured queue, checksum is good. """ self.gtp_test(type='fdir', port='pf', tunnel_pkt='gtpc', inner_L3=None) def test_fdir_gtpu_pf(self): """ GTP is supported by NVM with profile updated. Select flow director to do classfication, send gtpu packet to PF, check PF could receive packet using configured queue, checksum is good. """ self.gtp_test(type='fdir', port='pf', tunnel_pkt='gtpu', inner_L3=None) self.gtp_test(type='fdir', port='pf', tunnel_pkt='gtpu', inner_L3='ipv4') self.gtp_test(type='fdir', port='pf', tunnel_pkt='gtpu', inner_L3='ipv6') def test_clfter_gtpc_pf(self): """ GTP is supported by NVM with profile updated. Select cloud filter, send gtpc packet to PF, check PF could receive packet using configured queue, checksum is good. """ self.gtp_test(type='clfter', port='pf', tunnel_pkt='gtpc', inner_L3=None) def test_clfter_gtpu_pf(self): """ GTP is supported by NVM with profile updated. Select cloud filter, send gtpu packet to PF, check PF could receive packet using configured queue, checksum is good. """ self.gtp_test(type='clfter', port='pf', tunnel_pkt='gtpu', inner_L3=None) self.gtp_test(type='clfter', port='pf', tunnel_pkt='gtpu', inner_L3='ipv4') self.gtp_test(type='clfter', port='pf', tunnel_pkt='gtpu', inner_L3='ipv6') def test_clfter_gtpc_vf(self): """ GTP is supported by NVM with profile updated. Select cloud filter, send gtpc packet to VF, check PF could receive packet using configured queue, checksum is good. """ self.gtp_test(type='clfter', port='vf id 0', tunnel_pkt='gtpc', inner_L3=None) def test_clfter_gtpu_vf(self): """ GTP is supported by NVM with profile updated. Select cloud filter, send gtpu packet to VF, check PF could receive packet using configured queue, checksum is good. """ self.gtp_test(type='clfter', port='vf id 0', tunnel_pkt='gtpu', inner_L3=None) self.gtp_test(type='clfter', port='vf id 0', tunnel_pkt='gtpu', inner_L3='ipv4') self.gtp_test(type='clfter', port='vf id 0', tunnel_pkt='gtpu', inner_L3='ipv6') def tear_down(self): if self.vm0_testpmd: self.dut_testpmd.execute_cmd('write reg 0 0xb8190 1') self.dut_testpmd.execute_cmd('write reg 0 0xb8190 2') self.vm0_testpmd.quit() self.dut_testpmd.quit() def tear_down_all(self): self.destroy_vm_env()
class TestWhitelist(TestCase): def set_up_all(self): """ Run at the start of each test suite. Whitelist Prerequistites: Two Ports testpmd can normally started """ self.frames_to_send = 1 # Based on h/w type, choose how many ports to use self.dutPorts = self.dut.get_ports() # Verify that enough ports are available self.verify(len(self.dutPorts) >= 1, "Insufficient ports") portMask = dts.create_mask(self.dutPorts[:2]) self.pmdout = PmdOutput(self.dut) self.pmdout.start_testpmd("1S/2C/1T", "--portmask=%s" % portMask) self.dut.send_expect("set verbose 1", "testpmd> ") # get dest address from self.target port out = self.dut.send_expect("show port info %d" % self.dutPorts[0], "testpmd> ") self.dest = self.dut.get_mac_address(self.dutPorts[0]) mac_scanner = r"MAC address: (([\dA-F]{2}:){5}[\dA-F]{2})" ret = dts.regexp(out, mac_scanner) self.verify(ret is not None, "MAC address not found") self.verify(cmp(ret.lower(), self.dest) == 0, "MAC address wrong") self.max_mac_addr = dts.regexp( out, "Maximum number of MAC addresses: ([0-9]+)") def set_up(self): """ Run before each test case. Nothing to do. """ pass def whitelist_send_packet(self, portid, destMac="00:11:22:33:44:55"): """ Send 1 packet to portid. """ itf = self.tester.get_interface(self.tester.get_local_port(portid)) self.tester.scapy_foreground() self.tester.scapy_append( 'sendp([Ether(dst="%s", src="52:00:00:00:00:00")], iface="%s", count=%d)' % (destMac, itf, self.frames_to_send)) self.tester.scapy_execute() time.sleep(5) def test_whitelist_add_remove_mac_address(self): """ Add mac address and check packet can received Remove mac address and check packet can't received """ # initialise first port without promiscuous mode fake_mac_addr = "01:01:01:00:00:00" portid = self.dutPorts[0] self.dut.send_expect("set promisc %d off" % portid, "testpmd> ") out = self.dut.send_expect("show port stats %d" % portid, "testpmd> ") pre_rxpkt = dts.regexp(out, "RX-packets: ([0-9]+)") # send one packet with the portid MAC address self.whitelist_send_packet(portid, self.dest) out = self.dut.send_expect("show port stats %d" % portid, "testpmd> ") cur_rxpkt = dts.regexp(out, "RX-packets: ([0-9]+)") # check the packet increase self.verify( int(cur_rxpkt) == int(pre_rxpkt) + self.frames_to_send, "Packet has not been received on default address") # send one packet to a different MAC address # new_mac = self.dut.get_mac_address(portid) self.whitelist_send_packet(portid, fake_mac_addr) pre_rxpkt = cur_rxpkt out = self.dut.send_expect("show port stats %d" % portid, "testpmd> ") cur_rxpkt = dts.regexp(out, "RX-packets: ([0-9]+)") # check the packet DO NOT increase self.verify( int(cur_rxpkt) == int(pre_rxpkt), "Packet has been received on a new MAC address that has not been added yet" ) # add the different MAC address out = self.dut.send_expect( "mac_addr add %d" % portid + " %s" % fake_mac_addr, "testpmd>") # send again one packet to a different MAC address self.whitelist_send_packet(portid, fake_mac_addr) pre_rxpkt = cur_rxpkt out = self.dut.send_expect("show port stats %d" % portid, "testpmd> ") cur_rxpkt = dts.regexp(out, "RX-packets: ([0-9]+)") # check the packet increase self.verify( int(cur_rxpkt) == int(pre_rxpkt) + self.frames_to_send, "Packet has not been received on a new MAC address that has been added to the port" ) # remove the fake MAC address out = self.dut.send_expect( "mac_addr remove %d" % portid + " %s" % fake_mac_addr, "testpmd>") # send again one packet to a different MAC address self.whitelist_send_packet(portid, fake_mac_addr) pre_rxpkt = cur_rxpkt out = self.dut.send_expect("show port stats %d" % portid, "testpmd> ") cur_rxpkt = dts.regexp(out, "RX-packets: ([0-9]+)") # check the packet increase self.verify( int(cur_rxpkt) == int(pre_rxpkt), "Packet has been received on a new MAC address that has been removed from the port" ) self.dut.send_expect("stop", "testpmd> ") def test_whitelist_invalid_addresses(self): """ Invalid operation: Add NULL MAC should not be added Remove using MAC will be failed Add Same MAC twice will be failed Add more than MAX number will be failed """ portid = self.dutPorts[0] fake_mac_addr = "00:00:00:00:00:00" # add an address with all zeroes to the port (-EINVAL) out = self.dut.send_expect( "mac_addr add %d" % portid + " %s" % fake_mac_addr, "testpmd>") self.verify("Invalid argument" in out, "Added a NULL MAC address") # remove the default MAC address (-EADDRINUSE) out = self.dut.send_expect( "mac_addr remove %d" % portid + " %s" % self.dest, "testpmd>") self.verify("Address already in use" in out, "default address removed") # add same address 2 times fake_mac_addr = "00:00:00:00:00:01" out = self.dut.send_expect( "mac_addr add %d" % portid + " %s" % fake_mac_addr, "testpmd>") out = self.dut.send_expect( "mac_addr add %d" % portid + " %s" % fake_mac_addr, "testpmd>") self.verify("error" not in out, "added 2 times the same address with an error") # add 1 address more that max number i = 0 base_addr = "01:00:00:00:00:" while i <= int(self.max_mac_addr): new_addr = base_addr + "%0.2X" % i out = self.dut.send_expect( "mac_addr add %d" % portid + " %s" % new_addr, "testpmd>") i = i + 1 self.verify("No space left on device" in out, "added 1 address more than max MAC addresses") def tear_down(self): """ Run after each test case. Nothing to do. """ pass def tear_down_all(self): """ Run after each test suite. """ self.dut.send_expect("quit", "# ", 10)
class VirtScene(object): def __init__(self, dut, tester, scene_name): self.name = scene_name self.host_dut = dut self.tester_dut = tester self.pre_cmds = [] self.post_cmds = [] self.vm_dut_enable = False self.auto_portmap = True self.vm_type = 'kvm' self.def_target = "x86_64-native-linuxapp-gcc" self.host_bound = False # for vm dut init_log self.host_dut.test_classname = 'dts' def load_config(self): try: self.vm_confs = {} conf = VirtConf(CONFIG_ROOT_PATH + 'scene/' + self.name + '.cfg') self.sections = conf.virt_conf.get_sections() for vm in self.sections: conf.load_virt_config(vm) vm_conf = conf.get_virt_config() self.vm_confs[vm] = vm_conf except: raise VirtConfigParseException def prepare_vm(self): host_cfg = None for conf in self.vm_confs.keys(): if conf == 'scene': for cfg in self.vm_confs['scene']: if 'suite' in cfg.keys(): self.prepare_suite(cfg['suite']) if 'host' in cfg.keys(): self.host_bound = True host_cfg = cfg['host'][0] self.vm_confs.pop('scene') else: vm_name = conf vm_conf = self.vm_confs[vm_name] self.prepare_cpu(vm_name, vm_conf) self.prepare_devices(vm_conf) self.prepare_vmdevice(vm_conf) # dpdk should start after vf devices created if host_cfg: self.prepare_host(**host_cfg) def cleanup_vm(self): # reload config for has been changed when handle config self.load_config() for conf in self.vm_confs.keys(): if conf != 'scene': vm_name = conf vm_conf = self.vm_confs[vm_name] self.cleanup_devices(vm_conf) def prepare_suite(self, conf): for param in conf: if 'dut' in param.keys(): if param['dut'] == 'vm_dut': self.vm_dut_enable = True if 'type' in param.keys(): if param['type'] == 'xen': self.vm_type = 'xen' # not implement yet if param['type'] == 'vmware': self.vm_type = 'vmware' # not implement yet if param['type'] == 'container': self.vm_type = 'container' if 'portmap' in param.keys(): if param['portmap'] == 'cfg': self.auto_portmap = False def prepare_host(self, **opts): if 'dpdk' not in opts.keys(): print utils.RED("Scenario host parameter request dpdk option!!!") raise VirtConfigParamException('host') if 'cores' not in opts.keys(): print utils.RED("Scenario host parameter request cores option!!!") raise VirtConfigParamException('host') if 'target' in opts.keys(): target = opts['target'] else: target = self.def_target self.host_dut.set_target(target, bind_dev=True) if opts['dpdk'] == 'testpmd': self.pmdout = PmdOutput(self.host_dut) cores = opts['cores'].split() out = self.pmdout.start_testpmd(cores) if 'Error' in out: raise VirtHostPrepareException() def prepare_cpu(self, vm_name, conf): cpu_param = {} for params in conf: if 'cpu' in params.keys(): cpu_conf = params['cpu'][0] break if 'skipcores' in cpu_conf.keys(): cpus = cpu_conf['skipcores'].split() # remove invalid configured core for cpu in cpus: if int(cpu) not in self.host_dut.virt_pool.cores: cpus.remove(cpu) # create core mask for reserver cores core_mask = create_mask(cpus) # reserve those skipped cores self.host_dut.virt_pool.reserve_cpu(core_mask) if 'numa' in cpu_conf.keys(): if cpu_conf['numa'] == 'auto': numa = self.host_dut.ports_info[0]['port'].socket else: numa = int(cpu_conf['numa']) else: numa = 0 if 'number' in cpu_conf.keys(): num = int(cpu_conf['number']) else: num = 2 if 'model' in cpu_conf.keys(): model = cpu_conf['model'] else: model = 'host' cpu_topo = '' if 'cpu_topo' in cpu_conf.keys(): cpu_topo = cpu_conf['cpu_topo'] pin_cores = [] if 'cpu_pin' in cpu_conf.keys(): pin_cores = cpu_conf['cpu_pin'].split() if len(pin_cores): cores = self.host_dut.virt_pool.alloc_cpu(vm=vm_name, corelist=pin_cores) else: cores = self.host_dut.virt_pool.alloc_cpu(vm=vm_name, number=num, socket=numa) core_cfg = '' for core in cores: core_cfg += '%s ' % core core_cfg = core_cfg[:-1] cpu_param['number'] = num cpu_param['model'] = model cpu_param['cpupin'] = core_cfg cpu_param['cputopo'] = cpu_topo # replace with allocated cpus params['cpu'] = [cpu_param] def prepare_devices(self, conf): for params in conf: if 'dev_gen' in params.keys(): index = conf.index(params) for param in params['dev_gen']: self.handle_dev_gen(**param) # remove handled 'dev_gen' configuration conf.remove(conf[index]) def cleanup_devices(self, conf): for params in conf: if 'dev_gen' in params.keys(): for param in params['dev_gen']: self.handle_dev_destroy(**param) def prepare_vmdevice(self, conf): for params in conf: if 'device' in params.keys(): for param in params['device']: if 'vf_idx' in param.keys(): new_param = self.prepare_vf_conf(param) index = params['device'].index(param) params['device'][index] = new_param elif 'pf_idx' in param.keys(): new_param = self.prepare_pf_conf(param) index = params['device'].index(param) params['device'][index] = new_param for param in params['device']: netdev = get_netdev(self.host_dut, param['opt_host']) if netdev is not None: netdev.bind_driver('pci-stub') def prepare_pf_conf(self, param): pf_param = {} # strip pf pci id pf = int(param['pf_idx']) if pf >= len(self.host_dut.ports_info): raise VirtDeviceCreateException pf_pci = self.host_dut.ports_info[pf]['pci'] pf_param['driver'] = 'pci-assign' pf_param['opt_host'] = pf_pci if param['guestpci'] != 'auto': pf_param['opt_addr'] = param['guestpci'] return pf_param def prepare_vf_conf(self, param): vf_param = {} # strip vf pci id if 'pf_dev' in param.keys(): pf = int(param['pf_dev']) pf_net = self.host_dut.ports_info[pf]['port'] vfs = self.host_dut.ports_info[pf]['vfs_port'] vf_idx = int(param['vf_idx']) if vf_idx >= len(vfs): raise VirtDeviceCreateException vf_pci = vfs[vf_idx].pci vf_param['driver'] = 'pci-assign' vf_param['opt_host'] = vf_pci if param['guestpci'] != 'auto': vf_param['opt_addr'] = param['guestpci'] if 'mac' in param.keys(): pf_net.set_vf_mac_addr(vf_idx, param['mac']) else: print utils.RED("Invalid vf device config, request pf_dev") return vf_param def reset_pf_cmds(self, port): command = {} command['type'] = 'host' if not self.host_bound: intf = self.host_dut.ports_info[port]['intf'] command['command'] = 'ifconfig %s up' % intf self.reg_postvm_cmds(command) def handle_dev_gen(self, **opts): if 'pf_idx' in opts.keys(): port = int(opts['pf_idx']) if 'vf_num' in opts.keys(): vf_num = int(opts['vf_num']) else: print utils.RED("No vf_num for port %d, assum one VF" % port) vf_num = 1 if 'driver' in opts.keys(): driver = opts['driver'] try: print utils.GREEN("create vf %d %d %s" % (port, vf_num, driver)) self.host_dut.generate_sriov_vfs_by_port(port, vf_num, driver) self.reset_pf_cmds(port) except: print utils.RED("Failed to create vf as requested!!!") raise VirtDeviceCreateException def handle_dev_destroy(self, **opts): if 'pf_idx' in opts.keys(): port = int(opts['pf_idx']) try: print utils.GREEN("destroy vfs on port %d" % port) self.host_dut.destroy_sriov_vfs_by_port(port) except: print utils.RED("Failed to destroy vf as requested!!!") def reg_prevm_cmds(self, command): """ command: {'type':'host/tester/vm', define which crb command progress 'command':'XXX', command send to crb 'expect':'XXX', expected output for command 'timeout': 60, 'verify': True or False check whether command sucessfully } """ self.pre_cmds.append(command) def run_pre_cmds(self): for cmd in self.pre_cmds: if cmd['type'] == 'vm': print utils.RED("Can't run vm command when vm not ready") elif cmd['type'] == 'host': crb = self.host_dut elif cmd['type'] == 'tester': crb = self.tester else: crb = self.host_dut if 'expect' not in cmd.keys(): expect = "# " else: expect = cmd['expect'] if 'verify' not in cmd.keys(): verify = False else: verify = cmd['verify'] if 'timeout' not in cmd.keys(): timeout = 5 else: timeout = cmd['timeout'] ret = crb.send_expect(cmd['command'], expect, timeout=timeout, verify=verify) if type(ret) is int and ret != 0: print utils.RED("Failed to run command %s" % cmd['command']) raise VirtVmOperationException def reg_postvm_cmds(self, command): """ command: {'type':'host/tester/vm', define which crb command progress 'command':'XXX', command send to crb 'expect':'XXX', expected output for command 'verify':'yes or no' check whether command sucessfully """ self.post_cmds.append(command) pass def run_post_cmds(self): for cmd in self.post_cmds: if cmd['type'] == 'vm': crb = self.vm_dut elif cmd['type'] == 'host': crb = self.host_dut elif cmd['type'] == 'tester': crb = self.tester else: crb = self.host_dut if 'expect' not in cmd.keys(): expect = "# " else: expect = cmd['expect'] if 'verify' not in cmd.keys(): verify = False else: verify = cmd['verify'] if 'timeout' not in cmd.keys(): timeout = 5 else: timeout = cmd['timeout'] ret = crb.send_expect(cmd['command'], expect, timeout=timeout, verify=verify) if type(ret) is int and ret != 0: print utils.RED("Failed to run command %s" % cmd['command']) raise VirtVmOperationException def merge_params(self, vm, params): for param in params: index = vm.find_option_index(param.keys()[0]) if index is not None: vm.params[index] = param else: vm.params.append(param) index = vm.find_option_index('name') # update vm name vm.params[index]['name'][0]['name'] = vm.vm_name def get_cputopo(self, params): for param in params: if 'cpu' in param.keys(): cpu_topo = param['cpu'][0]['cputopo'] return cpu_topo def start_vms(self): self.vms = [] if self.vm_type == 'kvm': for vm_name in self.vm_confs.keys(): # tricky here, QEMUKvm based on suite and vm name # suite is virt_global, vm_name just the type vm = QEMUKvm(self.host_dut, self.vm_type.upper(), 'virt_global') vm.load_config() vm.vm_name = vm_name vm.set_vm_default() # merge default config and scene config scene_params = self.vm_confs[vm_name] # reload merged configurations self.merge_params(vm, scene_params) # get cpu topo topo = self.get_cputopo(scene_params) try: vm_dut = vm.start(load_config=False, set_target=False, auto_portmap=self.auto_portmap, cpu_topo=topo) if vm_dut is None: raise Exception("Set up VM ENV failed!") vm_info = {} vm_info[vm_name] = vm vm_info[vm_name + '_session'] = vm_dut self.vms.append(vm_info) except Exception as e: print utils.RED("Failure for %s" % str(e)) def get_vm_duts(self): duts = [] for vm_info in self.vms: for vm_obj in vm_info.keys(): if 'session' in vm_obj: duts.append(vm_info[vm_obj]) return duts def create_scene(self): self.prepare_vm() self.run_pre_cmds() self.start_vms() self.run_post_cmds() pass def set_target(self, target): for vm_info in self.vms: for vm_obj in vm_info.keys(): if 'session' in vm_obj: vm_info[vm_obj].set_target(target) def destroy_scene(self): for vm_info in self.vms: for vm_obj in vm_info.keys(): if 'session' in vm_obj: vm_info[vm_obj].kill_all() vm_info[vm_obj].close() vm_info[vm_obj].logger.logger_exit() for vm_obj in vm_info.keys(): if 'session' not in vm_obj: vm_info[vm_obj].stop() vm_info[vm_obj] = None self.cleanup_vm()
class TestChecksumOffload(TestCase): def set_up_all(self): """ Run at the start of each test suite. Checksum offload prerequisites. """ # Based on h/w type, choose how many ports to use self.dut_ports = self.dut.get_ports(self.nic) # Verify that enough ports are available self.verify(len(self.dut_ports) >= 1, "Insufficient ports for testing") self.pmdout = PmdOutput(self.dut) self.portMask = utils.create_mask([self.dut_ports[0]]) self.ports_socket = self.dut.get_numa_id(self.dut_ports[0]) def set_up(self): """ Run before each test case. """ self.pmdout.start_testpmd("Default", "--portmask=%s " % (self.portMask) + "--disable-hw-vlan --enable-rx-cksum " + "--port-topology=loop", socket=self.ports_socket) self.dut.send_expect("set verbose 1", "testpmd>") self.dut.send_expect("set fwd csum", "testpmd>") def checksum_enablehw(self, port): self.dut.send_expect("csum set ip hw %d" % port, "testpmd>") self.dut.send_expect("csum set udp hw %d" % port, "testpmd>") self.dut.send_expect("csum set tcp hw %d" % port, "testpmd>") self.dut.send_expect("csum set sctp hw %d" % port, "testpmd>") def checksum_enablesw(self, port): self.dut.send_expect("csum set ip sw %d" % port, "testpmd>") self.dut.send_expect("csum set udp sw %d" % port, "testpmd>") self.dut.send_expect("csum set tcp sw %d" % port, "testpmd>") self.dut.send_expect("csum set sctp sw %d" % port, "testpmd>") def get_chksum_values(self, packets_expected): """ Validate the checksum flags. """ checksum_pattern = re.compile("chksum.*=.*(0x[0-9a-z]+)") chksum = 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()", "#") return chksum def checksum_valid_flags(self, packets_sent, flag): """ 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")' % (packets_sent[packet_type], tx_interface)) self.tester.scapy_execute() out = self.dut.get_session_output(timeout=1) lines = out.split("\r\n") # collect the checksum result for line in lines: line = line.strip() if len(line) != 0 and line.startswith("rx"): # IPv6 don't be checksum, so always show "GOOD" if packet_type.startswith("IPv6"): if "PKT_RX_L4_CKSUM" not in line: self.verify( 0, "There is no checksum flags appeared!") else: if (flag == 1): self.verify( "PKT_RX_L4_CKSUM_GOOD" in line, "Packet Rx L4 checksum valid-flags error!") elif (flag == 0): self.verify( "PKT_RX_L4_CKSUM_BAD" in line, "Packet Rx L4 checksum valid-flags error!") else: if "PKT_RX_L4_CKSUM" not in line: self.verify( 0, "There is no L4 checksum flags appeared!") elif "PKT_RX_IP_CKSUM" not in line: self.verify( 0, "There is no IP checksum flags appeared!") else: if (flag == 1): self.verify( "PKT_RX_L4_CKSUM_GOOD" in line, "Packet Rx L4 checksum valid-flags error!") self.verify( "PKT_RX_IP_CKSUM_GOOD" in line, "Packet Rx IP checksum valid-flags error!") elif (flag == 0): self.verify( "PKT_RX_L4_CKSUM_BAD" in line, "Packet Rx L4 checksum valid-flags error!") self.verify( "PKT_RX_IP_CKSUM_BAD" in line, "Packet Rx IP checksum valid-flags error!") self.dut.send_expect("stop", "testpmd>") def checksum_validate(self, packets_sent, packets_expected): """ Validate the checksum. """ tx_interface = self.tester.get_interface( self.tester.get_local_port(self.dut_ports[0])) 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()", "#") inst = sniff_packets(intf=rx_interface, count=len(packets_sent), filters=[{ 'layer': 'ether', 'config': { 'src': sniff_src } }]) for packet_type in packets_sent.keys(): self.tester.scapy_append('sendp([%s], iface="%s")' % (packets_sent[packet_type], tx_interface)) self.tester.scapy_execute() p = load_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(',') self.verify( len(packets_sent) == len(packets_received), "Unexpected Packets Drop") for packet_received in packets_received: ip_checksum, tcp_checksum, udp_checksum, sctp_checksum = packet_received.split( ';') packet_type = '' l4_checksum = '' if tcp_checksum != '??': packet_type = 'TCP' l4_checksum = tcp_checksum elif udp_checksum != '??': packet_type = 'UDP' l4_checksum = udp_checksum elif sctp_checksum != '??': packet_type = 'SCTP' l4_checksum = sctp_checksum if ip_checksum != '??': packet_type = 'IP/' + packet_type if chksum[packet_type] != [ip_checksum, l4_checksum]: result[packet_type] = packet_type + " checksum error" else: packet_type = 'IPv6/' + packet_type if chksum[packet_type] != [l4_checksum]: result[packet_type] = packet_type + " checksum error" return result def test_checksum_offload_with_vlan(self): """ Do not insert IPv4/IPv6 UDP/TCP checksum on the transmit packet. Verify that the same number of packet are correctly received on the traffic generator side. """ mac = self.dut.get_mac_address(self.dut_ports[0]) pktsChkErr = { 'IP/UDP': 'Ether(dst="%s", src="52:00:00:00:00:00")/Dot1Q(vlan=1)/IP(chksum=0x0)/UDP(chksum=0xf)/("X"*46)' % mac, 'IP/TCP': 'Ether(dst="%s", src="52:00:00:00:00:00")/Dot1Q(vlan=1)/IP(chksum=0x0)/TCP(chksum=0xf)/("X"*46)' % mac, 'IP/SCTP': 'Ether(dst="%s", src="52:00:00:00:00:00")/Dot1Q(vlan=1)/IP(chksum=0x0)/SCTP(chksum=0xf)/("X"*48)' % mac, 'IPv6/UDP': 'Ether(dst="%s", src="52:00:00:00:00:00")/Dot1Q(vlan=1)/IPv6(src="::1")/UDP(chksum=0xf)/("X"*46)' % mac, 'IPv6/TCP': 'Ether(dst="%s", src="52:00:00:00:00:00")/Dot1Q(vlan=1)/IPv6(src="::1")/TCP(chksum=0xf)/("X"*46)' % mac } pkts = { 'IP/UDP': 'Ether(dst="02:00:00:00:00:00", src="%s")/Dot1Q(vlan=1)/IP(src="127.0.0.1")/UDP()/("X"*46)' % mac, 'IP/TCP': 'Ether(dst="02:00:00:00:00:00", src="%s")/Dot1Q(vlan=1)/IP(src="127.0.0.1")/TCP()/("X"*46)' % mac, 'IP/SCTP': 'Ether(dst="02:00:00:00:00:00", src="%s")/Dot1Q(vlan=1)/IP(src="127.0.0.1")/SCTP()/("X"*48)' % mac, 'IPv6/UDP': 'Ether(dst="02:00:00:00:00:00", src="%s")/Dot1Q(vlan=1)/IPv6(src="::1")/UDP()/("X"*46)' % mac, 'IPv6/TCP': 'Ether(dst="02:00:00:00:00:00", src="%s")/Dot1Q(vlan=1)/IPv6(src="::1")/TCP()/("X"*46)' % mac } if self.kdriver in DRIVER_TEST_LACK_CAPA['sctp_tx_offload']: del pktsChkErr['IP/SCTP'] del pkts['IP/SCTP'] self.checksum_enablehw(self.dut_ports[0]) self.dut.send_expect("start", "testpmd>") result = self.checksum_validate(pktsChkErr, pkts) self.dut.send_expect("stop", "testpmd>") self.verify(len(result) == 0, string.join(result.values(), ",")) def test_rx_checksum_valid_flags(self): """ Insert right and wrong IPv4/IPv6 UDP/TCP/SCTP checksum on the transmit packet.Enable Checksum offload. Verify the checksum valid-flags. """ mac = self.dut.get_mac_address(self.dut_ports[0]) pkts_ref = { 'IP/UDP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IP()/UDP()/("X"*46)' % mac, 'IP/TCP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IP(src="10.0.0.1")/TCP()/("X"*46)' % mac, 'IP/SCTP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IP(src="10.0.0.1")/SCTP()/("X"*48)' % mac, '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 result = self.get_chksum_values(pkts_ref) # set the expected checksum values same with the actual values pkts_good = { 'IP/UDP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IP(chksum=int(%s))/UDP(chksum=int(%s))/("X"*46)' % (mac, result['IP/UDP'][0], result['IP/UDP'][1]), 'IP/TCP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IP(src="10.0.0.1",chksum=int(%s))/TCP(chksum=int(%s))/("X"*46)' % (mac, result['IP/TCP'][0], result['IP/TCP'][1]), 'IP/SCTP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IP(src="10.0.0.1",chksum=int(%s))/SCTP(chksum=int(%s))/("X"*48)' % (mac, result['IP/SCTP'][0], result['IP/SCTP'][1]), 'IPv6/UDP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IPv6(src="::1")/UDP(chksum=int(%s))/("X"*46)' % (mac, result['IPv6/UDP'][0]), 'IPv6/TCP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IPv6(src="::1")/TCP(chksum=int(%s))/("X"*46)' % (mac, result['IPv6/TCP'][0]) } # set the expected checksum values different from the actual values pkts_bad = { 'IP/UDP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IP(chksum=0x0)/UDP(chksum=0xf)/("X"*46)' % mac, 'IP/TCP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IP(src="10.0.0.1",chksum=0x0)/TCP(chksum=0xf)/("X"*46)' % mac, 'IP/SCTP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IP(src="10.0.0.1",chksum=0x0)/SCTP(chksum=0xf)/("X"*48)' % mac, 'IPv6/UDP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IPv6(src="::1")/UDP(chksum=0xf)/("X"*46)' % mac, 'IPv6/TCP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IPv6(src="::1")/TCP(chksum=0xf)/("X"*46)' % mac } if self.kdriver in DRIVER_TEST_LACK_CAPA['sctp_tx_offload']: del pkts_good['IP/SCTP'] del pkts_bad['IP/SCTP'] del pkts_ref['IP/SCTP'] # send the packet checksum value same with the expected value self.checksum_valid_flags(pkts_good, 1) # send the packet checksum value different from the expected value self.checksum_valid_flags(pkts_bad, 0) def test_checksum_offload_enable(self): """ Insert IPv4/IPv6 UDP/TCP/SCTP checksum on the transmit packet. Enable Checksum offload. Verify that the same number of packet are correctly received on the traffic generator side. """ mac = self.dut.get_mac_address(self.dut_ports[0]) pkts = { 'IP/UDP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IP(chksum=0x0)/UDP(chksum=0xf)/("X"*46)' % mac, 'IP/TCP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IP(chksum=0x0)/TCP(chksum=0xf)/("X"*46)' % mac, 'IP/SCTP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IP(chksum=0x0)/SCTP(chksum=0xf)/("X"*48)' % mac, 'IPv6/UDP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IPv6(src="::1")/UDP(chksum=0xf)/("X"*46)' % mac, 'IPv6/TCP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IPv6(src="::1")/TCP(chksum=0xf)/("X"*46)' % mac } pkts_ref = { 'IP/UDP': 'Ether(dst="02:00:00:00:00:00", src="%s")/IP(src="127.0.0.1")/UDP()/("X"*46)' % mac, 'IP/TCP': 'Ether(dst="02:00:00:00:00:00", src="%s")/IP(src="127.0.0.1")/TCP()/("X"*46)' % mac, 'IP/SCTP': 'Ether(dst="02:00:00:00:00:00", src="%s")/IP(src="127.0.0.1")/SCTP()/("X"*48)' % mac, 'IPv6/UDP': 'Ether(dst="02:00:00:00:00:00", src="%s")/IPv6(src="::1")/UDP()/("X"*46)' % mac, 'IPv6/TCP': 'Ether(dst="02:00:00:00:00:00", src="%s")/IPv6(src="::1")/TCP()/("X"*46)' % mac } if self.kdriver in DRIVER_TEST_LACK_CAPA['sctp_tx_offload']: del pkts['IP/SCTP'] del pkts_ref['IP/SCTP'] self.checksum_enablehw(self.dut_ports[0]) self.dut.send_expect("start", "testpmd>") result = self.checksum_validate(pkts, pkts_ref) self.dut.send_expect("stop", "testpmd>") self.verify(len(result) == 0, string.join(result.values(), ",")) def test_checksum_offload_disable(self): """ Do not insert IPv4/IPv6 UDP/TCP checksum on the transmit packet. Disable Checksum offload. Verify that the same number of packet are correctly received on the traffic generator side. """ mac = self.dut.get_mac_address(self.dut_ports[0]) sndIP = '10.0.0.1' sndIPv6 = '::1' sndPkts = { 'IP/UDP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IP(src="%s",chksum=0x0)/UDP(chksum=0xf)/("X"*46)' % (mac, sndIP), 'IP/TCP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IP(src="%s",chksum=0x0)/TCP(chksum=0xf)/("X"*46)' % (mac, sndIP), 'IPv6/UDP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IPv6(src="%s")/UDP(chksum=0xf)/("X"*46)' % (mac, sndIPv6), 'IPv6/TCP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IPv6(src="%s")/TCP(chksum=0xf)/("X"*46)' % (mac, sndIPv6) } expIP = sndIP expIPv6 = sndIPv6 expPkts = { 'IP/UDP': 'Ether(dst="02:00:00:00:00:00", src="%s")/IP(src="%s")/UDP()/("X"*46)' % (mac, expIP), 'IP/TCP': 'Ether(dst="02:00:00:00:00:00", src="%s")/IP(src="%s")/TCP()/("X"*46)' % (mac, expIP), 'IPv6/UDP': 'Ether(dst="02:00:00:00:00:00", src="%s")/IPv6(src="%s")/UDP()/("X"*46)' % (mac, expIPv6), 'IPv6/TCP': 'Ether(dst="02:00:00:00:00:00", src="%s")/IPv6(src="%s")/TCP()/("X"*46)' % (mac, expIPv6) } self.dut.send_expect("start", "testpmd>") result = self.checksum_validate(sndPkts, expPkts) self.verify(len(result) == 0, string.join(result.values(), ",")) self.dut.send_expect("stop", "testpmd>") def benchmark(self, lcore, ptype, mode, flow_format, size_list, nic): """ Test ans report checksum offload performance for given parameters. """ Bps = dict() Pps = dict() Pct = dict() dmac = self.dut.get_mac_address(self.dut_ports[0]) result = [2, lcore, ptype, mode] for size in size_list: flow = flow_format % (dmac, size) self.tester.scapy_append('wrpcap("test.pcap", [%s])' % flow) self.tester.scapy_execute() tgenInput = [] tgenInput.append( (self.tester.get_local_port(self.dut_ports[0]), self.tester.get_local_port(self.dut_ports[1]), "test.pcap")) tgenInput.append( (self.tester.get_local_port(self.dut_ports[1]), self.tester.get_local_port(self.dut_ports[0]), "test.pcap")) Bps[str(size)], Pps[str( size)] = self.tester.traffic_generator_throughput(tgenInput) self.verify(Pps[str(size)] > 0, "No traffic detected") Pps[str(size)] /= 1E6 Pct[str(size)] = (Pps[str(size)] * 100) / \ self.wirespeed(self.nic, size, 2) result.append(Pps[str(size)]) result.append(Pct[str(size)]) self.result_table_add(result) def test_perf_checksum_throughtput(self): """ Test checksum offload performance. """ # Verify that enough ports are available self.verify(len(self.dut_ports) >= 2, "Insufficient ports for testing") # sizes = [64, 128, 256, 512, 1024] sizes = [64, 128] pkts = { 'IP/UDP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IP()/UDP()/("X"*(%d-46))', 'IP/TCP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IP()/TCP()/("X"*(%d-58))', 'IP/SCTP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IP()/SCTP()/("X"*(%d-50+2))', 'IPv6/UDP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IPv6()/UDP()/("X"* (lambda x: x - 66 if x > 66 else 0)(%d))', 'IPv6/TCP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IPv6()/TCP()/("X"* (lambda x: x - 78 if x > 78 else 0)(%d))' } if self.kdriver in DRIVER_TEST_LACK_CAPA['sctp_tx_offload']: del pkts['IP/SCTP'] lcore = "1S/2C/1T" portMask = utils.create_mask([self.dut_ports[0], self.dut_ports[1]]) for mode in ["sw", "hw"]: self.logger.info("%s performance" % mode) rst.write_text(mode + " Performance" + '\r\n') tblheader = ["Ports", "S/C/T", "Packet Type", "Mode"] for size in sizes: tblheader.append("%sB mpps" % str(size)) tblheader.append("%sB %% " % str(size)) self.result_table_create(tblheader) self.pmdout.start_testpmd(lcore, "--portmask=%s" % self.portMask, socket=self.ports_socket) self.dut.send_expect("set verbose 1", "testpmd> ") self.dut.send_expect("set fwd csum", "testpmd> ") if mode == "hw": self.checksum_enablehw(self.dut_ports[0]) self.checksum_enablehw(self.dut_ports[1]) else: self.checksum_enablesw(self.dut_ports[0]) self.checksum_enablesw(self.dut_ports[1]) self.dut.send_expect("start", "testpmd> ", 3) for ptype in pkts.keys(): self.benchmark(lcore, ptype, mode, pkts[ptype], sizes, self.nic) self.dut.send_expect("stop", "testpmd> ") self.dut.send_expect("quit", "#", 10) self.result_table_print() def tear_down(self): """ Run after each test case. """ self.dut.send_expect("quit", "#") def tear_down_all(self): """ Run after each test suite. """ pass
class TestVfRss(TestCase): supported_vf_driver = ['pci-stub', 'vfio-pci'] def send_packet(self, itf, tran_type): """ Sends packets. """ global reta_lines reta_lines = [] self.tester.scapy_foreground() self.tester.scapy_append('sys.path.append("./")') self.tester.scapy_append('from sctp import *') self.vm_dut_0.send_expect("start", "testpmd>") mac = self.vm0_testpmd.get_port_mac(0) # send packet with different source and dest ip if tran_type == "ipv4-other": for i in range(16): packet = r'sendp([Ether(dst="%s", src="02:00:00:00:00:00")/IP(src="192.168.0.%d", dst="192.168.0.%d")], iface="%s")' % ( mac, i + 1, i + 2, itf) self.tester.scapy_append(packet) self.tester.scapy_execute() time.sleep(.5) elif tran_type == "ipv4-tcp": for i in range(16): packet = r'sendp([Ether(dst="%s", src="02:00:00:00:00:00")/IP(src="192.168.0.%d", dst="192.168.0.%d")/TCP(sport=1024,dport=1024)], iface="%s")' % ( mac, i + 1, i + 2, itf) self.tester.scapy_append(packet) self.tester.scapy_execute() time.sleep(.5) elif tran_type == "ipv4-udp": for i in range(16): packet = r'sendp([Ether(dst="%s", src="02:00:00:00:00:00")/IP(src="192.168.0.%d", dst="192.168.0.%d")/UDP(sport=1024,dport=1024)], iface="%s")' % ( mac, i + 1, i + 2, itf) self.tester.scapy_append(packet) self.tester.scapy_execute() time.sleep(.5) elif tran_type == "ipv4-sctp": for i in range(16): packet = r'sendp([Ether(dst="%s")/IP(src="192.168.0.%d", dst="192.168.0.%d")/SCTP(sport=1024,dport=1025,tag=1)], iface="%s")' % ( mac, i + 1, i + 2, itf) self.tester.scapy_append(packet) self.tester.scapy_execute() time.sleep(.5) packet = r'sendp([Ether(dst="%s")/IP(src="192.168.0.%d", dst="192.168.0.%d")/SCTP(sport=1025,dport=1024,tag=1)], iface="%s")' % ( mac, i + 2, i + 1, itf) self.tester.scapy_append(packet) self.tester.scapy_execute() time.sleep(.5) elif tran_type == "l2_payload": for i in range(16): packet = r'sendp([Ether(src="00:00:00:00:00:%02d",dst="%s")], iface="%s")' % ( i + 1, mac, itf) self.tester.scapy_append(packet) self.tester.scapy_execute() time.sleep(.5) elif tran_type == "ipv6-other": for i in range(16): packet = r'sendp([Ether(dst="%s", src="02:00:00:00:00:00")/IPv6(src="3ffe:2501:200:1fff::%d", dst="3ffe:2501:200:3::%d")], iface="%s")' % ( mac, i + 1, i + 2, itf) self.tester.scapy_append(packet) self.tester.scapy_execute() time.sleep(.5) elif tran_type == "ipv6-tcp": for i in range(16): packet = r'sendp([Ether(dst="%s", src="02:00:00:00:00:00")/IPv6(src="3ffe:2501:200:1fff::%d", dst="3ffe:2501:200:3::%d")/TCP(sport=1024,dport=1024)], iface="%s")' % ( mac, i + 1, i + 2, itf) self.tester.scapy_append(packet) self.tester.scapy_execute() time.sleep(.5) elif tran_type == "ipv6-udp": for i in range(16): packet = r'sendp([Ether(dst="%s", src="02:00:00:00:00:00")/IPv6(src="3ffe:2501:200:1fff::%d", dst="3ffe:2501:200:3::%d")/UDP(sport=1024,dport=1024)], iface="%s")' % ( mac, i + 1, i + 2, itf) self.tester.scapy_append(packet) self.tester.scapy_execute() time.sleep(.5) elif tran_type == "ipv6-sctp": for i in range(16): packet = r'sendp([Ether(dst="%s")/IPv6(src="3ffe:2501:200:1fff::%d", dst="3ffe:2501:200:3::%d", nh=132)/SCTP(sport=1024,dport=1025,tag=1)], iface="%s")' % ( mac, i + 1, i + 2, itf) self.tester.scapy_append(packet) self.tester.scapy_execute() time.sleep(.5) packet = r'sendp([Ether(dst="%s")/IPv6(src="3ffe:2501:200:1fff::%d", dst="3ffe:2501:200:3::%d", nh=132)/SCTP(sport=1025,dport=1024,tag=1)], iface="%s")' % ( mac, i + 2, i + 1, itf) self.tester.scapy_append(packet) self.tester.scapy_execute() time.sleep(.5) else: print "\ntran_type error!\n" #out = self.vm_dut_0.send_expect("stop", "testpmd>") out = self.vm_dut_0.get_session_output() print '*******************************************' print out if not reta_entries: self.verify('RSS hash=' in out, 'rss faied') return lines = out.split("\r\n") out = '' reta_line = {} # collect the hash result of five tuple and the queue id for line in lines: line = line.strip() if len(line) != 0 and line.startswith(("src=", )): for item in line.split("-"): item = item.strip() if (item.startswith("RSS hash")): name, value = item.split("=", 1) print name + "-" + value reta_line[name.strip()] = value.strip() reta_lines.append(reta_line) reta_line = {} elif len(line) != 0 and line.strip().startswith("port "): rexp = r"port (\d)/queue (\d{1,2}): received (\d) packets" m = re.match(rexp, line.strip()) if m: reta_line["port"] = m.group(1) reta_line["queue"] = m.group(2) elif len(line) != 0 and line.startswith("stop"): break else: pass self.verifyResult() def verifyResult(self): """ Verify whether or not the result passes. """ global reta_lines result = [] self.result_table_create([ 'packet index', 'hash value', 'hash index', 'queue id', 'actual queue id', 'pass ' ]) i = 0 for tmp_reta_line in reta_lines: status = "false" if self.kdriver == "fm10k": # compute the hash result of five tuple into the 7 LSBs value. hash_index = int(tmp_reta_line["RSS hash"], 16) % 128 else: # compute the hash result of five tuple into the 7 LSBs value. hash_index = int(tmp_reta_line["RSS hash"], 16) % 512 if (reta_entries[hash_index] == int(tmp_reta_line["queue"])): status = "true" result.insert(i, 0) else: status = "fail" result.insert(i, 1) self.result_table_add([ i, tmp_reta_line["RSS hash"], hash_index, reta_entries[hash_index], tmp_reta_line["queue"], status ]) i = i + 1 self.result_table_print() reta_lines = [] self.verify(sum(result) == 0, "the reta update function failed!") def set_up_all(self): """ Run at the start of each test suite. """ self.verify( self.nic in [ "niantic", "fortville_eagle", "fortville_spirit", "fortville_spirit_single", "fortville_25g" ], "NIC Unsupported: " + str(self.nic)) self.dut_ports = self.dut.get_ports(self.nic) self.verify(len(self.dut_ports) >= 1, "Not enough ports available") # set vf assign method and vf driver self.vf_driver = self.get_suite_cfg()['vf_driver'] if self.vf_driver is None: self.vf_driver = 'pci-stub' self.verify(self.vf_driver in self.supported_vf_driver, "Unspported vf driver") if self.vf_driver == 'pci-stub': self.vf_assign_method = 'pci-assign' else: self.vf_assign_method = 'vfio-pci' self.vm0 = None self.host_testpmd = None self.setup_1pf_1vf_1vm_env_flag = 0 self.setup_1pf_1vf_1vm_env(driver='') def set_up(self): """ Run before each test case. """ pass def setup_1pf_1vf_1vm_env(self, driver='default'): self.used_dut_port_0 = self.dut_ports[0] self.dut.generate_sriov_vfs_by_port(self.used_dut_port_0, 1, driver=driver) self.sriov_vfs_port_0 = self.dut.ports_info[ self.used_dut_port_0]['vfs_port'] try: for port in self.sriov_vfs_port_0: port.bind_driver(self.vf_driver) time.sleep(1) vf0_prot = {'opt_host': self.sriov_vfs_port_0[0].pci} 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 } self.host_testpmd.start_testpmd("1S/2C/2T", eal_param=eal_param) # set up VM0 ENV self.vm0 = QEMUKvm(self.dut, 'vm0', 'vf_rss') self.vm0.set_vm_device(driver=self.vf_assign_method, **vf0_prot) self.vm_dut_0 = self.vm0.start() if self.vm_dut_0 is None: raise Exception("Set up VM0 ENV failed!") self.vm0_testpmd = PmdOutput(self.vm_dut_0) self.setup_1pf_1vf_1vm_env_flag = 1 except Exception as e: self.destroy_1pf_1vf_1vm_env() raise Exception(e) def destroy_1pf_1vf_1vm_env(self): if getattr(self, 'vm0', None): if getattr(self, 'vm0_testpmd', None): self.vm0_testpmd.execute_cmd('quit', '# ') self.vm0_testpmd = None self.vm0_dut_ports = None #destroy vm0 self.vm0.stop() self.dut.virt_exit() self.vm0 = None if getattr(self, 'host_testpmd', None): self.host_testpmd.execute_cmd('quit', '# ') self.host_testpmd = None if getattr(self, 'used_dut_port_0', None) != None: self.dut.destroy_sriov_vfs_by_port(self.used_dut_port_0) port = self.dut.ports_info[self.used_dut_port_0]['port'] port.bind_driver() self.used_dut_port_0 = None for port_id in self.dut_ports: port = self.dut.ports_info[port_id]['port'] port.bind_driver() self.setup_1pf_2vf_1vm_env_flag = 0 def test_vf_pmdrss_reta(self): # niantic kernel host driver not support this case if self.nic is 'niantic' and not self.host_testpmd: self.logger.warning( "niantic kernel host driver not support this case") return vm0dutPorts = self.vm_dut_0.get_ports('any') localPort = self.tester.get_local_port(vm0dutPorts[0]) itf = self.tester.get_interface(localPort) self.vm0_ports_socket = self.vm_dut_0.get_numa_id(vm0dutPorts[0]) iptypes = ['IPV4'] self.vm_dut_0.kill_all() # test with different rss queues eal_param = '' for queue in testQueues: self.vm0_testpmd.start_testpmd("all", "--rxq=%d --txq=%d %s" % (queue, queue, eal_param), socket=self.vm0_ports_socket) for iptype in iptypes: self.vm_dut_0.send_expect("set verbose 8", "testpmd> ") self.vm_dut_0.send_expect("set fwd rxonly", "testpmd> ") self.vm_dut_0.send_expect("set nbcore %d" % (queue + 1), "testpmd> ") # configure the reta with specific mappings. if (self.nic in [ "niantic", "redrockcanyou", "atwood", "boulderrapid" ]): for i in range(128): reta_entries.insert(i, random.randint(0, queue - 1)) self.vm_dut_0.send_expect( "port config 0 rss reta (%d,%d)" % (i, reta_entries[i]), "testpmd> ") else: for i in range(512): reta_entries.insert(i, random.randint(0, queue - 1)) self.vm_dut_0.send_expect( "port config 0 rss reta (%d,%d)" % (i, reta_entries[i]), "testpmd> ") self.send_packet(itf, iptype) self.vm_dut_0.send_expect("quit", "# ", 30) def test_vf_pmdrss(self): vm0dutPorts = self.vm_dut_0.get_ports('any') localPort = self.tester.get_local_port(vm0dutPorts[0]) itf = self.tester.get_interface(localPort) self.vm0_ports_socket = self.vm_dut_0.get_numa_id(vm0dutPorts[0]) iptypes = { 'ipv4-sctp': 'ip', 'ipv4-other': 'ip', 'ipv4-udp': 'udp', 'ipv4-tcp': 'tcp', 'ipv4-sctp': 'sctp', 'ipv6-other': 'ip', 'ipv6-udp': 'udp', 'ipv6-tcp': 'tcp', 'ipv6-sctp': 'sctp', # 'l2_payload':'ether' } self.vm_dut_0.kill_all() eal_param = '' # test with different rss queues for queue in testQueues: self.vm0_testpmd.start_testpmd("all", "--rxq=%d --txq=%d %s" % (queue, queue, eal_param), socket=self.vm0_ports_socket) for iptype, rsstype in iptypes.items(): self.vm_dut_0.send_expect("set verbose 8", "testpmd> ") self.vm_dut_0.send_expect("set fwd rxonly", "testpmd> ") out = self.vm_dut_0.send_expect( "port config all rss %s" % rsstype, "testpmd> ") self.verify("Operation not supported" not in out, "Operation not supported") self.vm_dut_0.send_expect("set nbcore %d" % (queue + 1), "testpmd> ") self.send_packet(itf, iptype) self.vm_dut_0.send_expect("quit", "# ", 30) def tear_down(self): """ Run after each test case. """ pass def tear_down_all(self): """ Run after each test suite. """ #self.vm_dut_0.kill_all() self.destroy_1pf_1vf_1vm_env()
class TestPtype_Mapping(TestCase): def set_up_all(self): """ Run at the start of each test suite. """ self.verify( self.nic in [ 'fortville_eagle', 'fortville_spirit', 'fortville_spirit_single', 'fortville_25g' ], 'ptype mapping test can not support %s nic' % self.nic) ports = self.dut.get_ports() self.verify(len(ports) >= 1, "Insufficient ports for testing") valports = [_ for _ in ports if self.tester.get_local_port(_) != -1] self.dut_port = valports[0] tester_port = self.tester.get_local_port(self.dut_port) self.tester_iface = self.tester.get_interface(tester_port) self.dut.send_expect("sed -i -e '" +\ "/printf(\" - VLAN tci=0x%x\", mb->vlan_tci);" +\ "/a\\\\t\\tprintf(\" - pktype: 0x%x\", mb->packet_type);'" +\ " app/test-pmd/util.c", "# ", 30, verify = True) self.dut.build_install_dpdk(self.dut.target) def set_up(self): """ Run before each test case. """ self.dut_testpmd = PmdOutput(self.dut) self.dut_testpmd.start_testpmd("Default", "--port-topology=chained") self.dut_testpmd.execute_cmd('set fwd rxonly') self.dut_testpmd.execute_cmd('set verbose 1') self.dut_testpmd.execute_cmd('start') def run_test(self, sw_ptype, pkt_types, chk_types): """ Generate and send packet according to packet type, detect each packet layer. """ for pkt_type in pkt_types.keys(): if chk_types != None: pkt_names = chk_types[pkt_type] else: pkt_names = pkt_types[pkt_type] pkt = Packet(pkt_type=pkt_type) pkt.send_pkt(tx_port=self.tester_iface) out = self.dut.get_session_output(timeout=2) self.verify(sw_ptype in out, "Failed to detect correct ptype value") for pkt_layer_name in pkt_names: if pkt_layer_name not in out: print utils.RED("Fail to detect %s" % pkt_layer_name) raise VerifyFailure("Failed to detect %s" % pkt_layer_name) print utils.GREEN("Detected %s successfully" % pkt_type) def strip_ptype(self, table, hw_ptype): """ Strip software packet type from packet mapping table. Input: packet mapping table, hardware ptype Out: 32 bits software ptype or none """ pattern = r"\s(%s)\s0x(0*)([1-9a-f][0-9a-f]*)" % hw_ptype s = re.compile(pattern) res = s.search(table) if res is None: print utils.RED("search none ptype") return None else: ptype = res.group(3) return ptype def run_ptype_test(self, hw_ptype, check_ptype): """ Get ptype mapping table and run ptype test. """ out = self.dut_testpmd.execute_cmd('ptype mapping get 0 0') time.sleep(3) self.verify("255" in out, "Failed to get 255 items ptype mapping table!!!") out = self.dut_testpmd.execute_cmd('ptype mapping get 0 1') time.sleep(3) self.verify("166" in out, "Failed to get 166 items ptype mapping table!!!") sw_ptype = self.strip_ptype(out, hw_ptype) if hw_ptype == 38: pktType = { "MAC_IP_IPv6_UDP_PKT": [ "L2_ETHER", "L3_IPV4_EXT_UNKNOWN", "TUNNEL_IP", "INNER_L3_IPV6_EXT_UNKNOWN", "INNER_L4_UDP" ] } elif hw_ptype == 75: pktType = { "MAC_IP_NVGRE_MAC_VLAN_IP_PKT": [ "L2_ETHER", "L3_IPV4_EXT_UNKNOWN", "TUNNEL_GRENAT", "INNER_L2_ETHER_VLAN", "INNER_L3_IPV4_EXT_UNKNOWN", "INNER_L4_NONFRAG" ] } self.run_test(sw_ptype, pktType, check_ptype) def ptype_mapping_test(self, check_ptype=None): self.run_ptype_test(hw_ptype=38, check_ptype=check_ptype) self.run_ptype_test(hw_ptype=75, check_ptype=check_ptype) def test_ptype_mapping_get(self): """ Get hardware defined ptype to software defined ptype mapping items. """ self.ptype_mapping_test() def test_ptype_mapping_reset(self): """ Reset packet mapping table after changing table. """ self.ptype_mapping_test() self.dut_testpmd.execute_cmd('ptype mapping update 0 38 0x026010e1') chk_types = { "MAC_IP_IPv6_UDP_PKT": [ "L2_ETHER", "L3_IPV6_EXT_UNKNOWN", "TUNNEL_IP", "INNER_L3_IPV6_EXT_UNKNOWN", "INNER_L4_UDP" ], "MAC_IP_NVGRE_MAC_VLAN_IP_PKT": [ "L2_ETHER", "L3_IPV4_EXT_UNKNOWN", "TUNNEL_GRENAT", "INNER_L2_ETHER_VLAN", "INNER_L3_IPV4_EXT_UNKNOWN", "INNER_L4_NONFRAG" ] } self.ptype_mapping_test(check_ptype=chk_types) self.dut_testpmd.execute_cmd('ptype mapping reset 0') self.ptype_mapping_test() def test_ptype_mapping_update(self): """ Update a specific hardware ptype's software ptype as a new one. """ self.ptype_mapping_test() self.dut_testpmd.execute_cmd('ptype mapping update 0 38 0x026010e1') self.dut_testpmd.execute_cmd('ptype mapping update 0 75 0x026010e1') check_types = [ "L2_ETHER", "L3_IPV6_EXT_UNKNOWN", "TUNNEL_IP", "INNER_L3_IPV6_EXT_UNKNOWN", "INNER_L4_UDP" ] chk_types = { "MAC_IP_IPv6_UDP_PKT": check_types, "MAC_IP_NVGRE_MAC_VLAN_IP_PKT": check_types } self.ptype_mapping_test(check_ptype=chk_types) self.dut_testpmd.execute_cmd('ptype mapping reset 0') self.ptype_mapping_test() def test_ptype_mapping_replace(self): """ Replace a specific or a group of software defined ptypes with a new one. """ self.ptype_mapping_test() self.dut_testpmd.execute_cmd( 'ptype mapping replace 0 0x06426091 0 0x06421091') self.dut_testpmd.execute_cmd('ptype mapping update 0 38 0x06421091') check_types = [ "L2_ETHER", "L3_IPV4_EXT_UNKNOWN", "TUNNEL_IP", "INNER_L2_ETHER_VLAN", "INNER_L3_IPV4_EXT_UNKNOWN", "INNER_L4_NONFRAG" ] chk_types = { "MAC_IP_IPv6_UDP_PKT": check_types, "MAC_IP_NVGRE_MAC_VLAN_IP_PKT": check_types } self.ptype_mapping_test(check_ptype=chk_types) self.dut_testpmd.execute_cmd( 'ptype mapping replace 0 0x06421091 1 0x02601091') check_types = [ "L2_ETHER", "L3_IPV4_EXT_UNKNOWN", "TUNNEL_IP", "INNER_L3_IPV6_EXT_UNKNOWN", "INNER_L4_UDP" ] chk_types = { "MAC_IP_IPv6_UDP_PKT": check_types, "MAC_IP_NVGRE_MAC_VLAN_IP_PKT": check_types } self.ptype_mapping_test(check_ptype=chk_types) self.dut_testpmd.execute_cmd('ptype mapping reset 0') self.ptype_mapping_test() def tear_down(self): """ Run after each test case. """ self.dut_testpmd.quit() def tear_down_all(self): """ Run after each test suite. """ self.dut.send_expect("sed -i '/printf(\" - pktype: 0x%x\", " +\ "mb->packet_type);/d' app/test-pmd/util.c", "# ", 30, verify = True) self.dut.build_install_dpdk(self.dut.target) self.dut.kill_all()
class TestBlacklist(TestCase): def set_up_all(self): """ Run at the start of each test suite. Blacklist Prerequisites. Requirements: Two Ports """ self.ports = self.dut.get_ports() self.verify(len(self.ports) >= 2, "Insufficient ports for testing") [arch, machine, self.env, toolchain] = self.target.split('-') if self.env == 'bsdapp': self.regexp_blacklisted_port = "EAL: PCI device 0000:%02x:%s on NUMA socket [-0-9]+[^\n]*\nEAL: probe driver[^\n]*\nEAL: Device is blacklisted, not initializing" else: self.regexp_blacklisted_port = "EAL: PCI device 0000:%s on NUMA socket [-0-9]+[^\n]*\nEAL: probe driver[^\n]*\nEAL: Device is blacklisted, not initializing" self.pmdout = PmdOutput(self.dut) def set_up(self): """ Run before each test case. Nothing to do. """ pass def check_blacklisted_ports(self, output, ports, blacklisted=False): """ Check if any of the ports in `ports` have been blacklisted, if so, raise exception. If `blacklisted` is True, then raise an exception if any of the ports in `ports` have not been blacklisted. """ for port in ports: # Look for the PCI ID of each card followed by # "Device is blacklisted, not initializing" but avoid to consume more # than one device. if self.env == 'bsdapp': pci = self.dut.ports_info[port]['pci'] regexp_blacklisted_port = self.regexp_blacklisted_port % (int(pci.split(':')[0], 16), pci.split(':')[1]) else: regexp_blacklisted_port = self.regexp_blacklisted_port % self.dut.ports_info[port]['pci'] matching_ports = dts.regexp(output, regexp_blacklisted_port, True) if blacklisted: self.verify(len(matching_ports) == 1, "Blacklisted port is being initialized") else: self.verify(len(matching_ports) == 0, "Not blacklisted port is being blacklisted") def test_bl_noblacklisted(self): """ Run testpmd with no blacklisted device. """ out = self.pmdout.start_testpmd("all") rexp = r"Link" match_status = dts.regexp(out, rexp, True) self.check_blacklisted_ports(out, self.ports) def test_bl_oneportblacklisted(self): """ Run testpmd with one port blacklisted. """ self.dut.kill_all() out = self.pmdout.start_testpmd("all", eal_param="-b 0000:%s -- -i" % self.dut.ports_info[0]['pci']) self.check_blacklisted_ports(out, self.ports[1:]) def test_bl_allbutoneportblacklisted(self): """ Run testpmd with all but one port blacklisted. """ self.dut.kill_all() ports_to_blacklist = self.ports[:-1] cmdline = "" for port in ports_to_blacklist: cmdline += " -b 0000:%s" % self.dut.ports_info[port]['pci'] out = self.pmdout.start_testpmd("all", eal_param=cmdline) blacklisted_ports = self.check_blacklisted_ports(out, ports_to_blacklist, True) def tear_down(self): """ Run after each test case. Quit testpmd. """ self.dut.send_expect("quit", "# ", 10) def tear_down_all(self): """ Run after each test suite. Nothing to do. """ pass
class TestGeneric_filter(TestCase): def set_up_all(self): """ Run at the start of each test suite. Generic filter Prerequisites """ # Based on h/w type, choose how many ports to use ports = self.dut.get_ports(self.nic) # Verify that enough ports are available self.verify(len(ports) >= 2, "Insufficient ports") self.cores = "1S/5C/1T" # Based on h/w type, choose how many ports to use global valports valports = [_ for _ in ports if self.tester.get_local_port(_) != -1] global portMask portMask = utils.create_mask(valports[:2]) self.pmdout = PmdOutput(self.dut) self.ethertype_filter = "off" def request_mbufs(self, queue_num): """ default txq/rxq descriptor is 64 """ return 1024 * queue_num + 512 def port_config(self): """ set port queue mapping, fortville not support this function """ if self.nic not in [ "fortville_eagle", "fortville_spirit", "fortville_spirit_single", "fortville_25g", "fortpark_TLV" ]: self.dut.send_expect("set stat_qmap rx %s 0 0" % valports[0], "testpmd> ") self.dut.send_expect("set stat_qmap rx %s 0 0" % valports[1], "testpmd> ") self.dut.send_expect("set stat_qmap rx %s 1 1" % valports[0], "testpmd> ") self.dut.send_expect("set stat_qmap rx %s 1 1" % valports[1], "testpmd> ") self.dut.send_expect("set stat_qmap rx %s 2 2" % valports[0], "testpmd> ") self.dut.send_expect("set stat_qmap rx %s 2 2" % valports[1], "testpmd> ") self.dut.send_expect("set stat_qmap rx %s 3 3" % valports[0], "testpmd> ") self.dut.send_expect("set stat_qmap rx %s 3 3" % valports[1], "testpmd> ") self.dut.send_expect("vlan set strip off %s" % valports[0], "testpmd> ") self.dut.send_expect("vlan set strip off %s" % valports[1], "testpmd> ") #reson dpdk-5315 self.dut.send_expect("vlan set filter on %s" % valports[0], "testpmd> ") self.dut.send_expect("vlan set filter off %s" % valports[0], "testpmd> ") #reson dpdk-5315 self.dut.send_expect("vlan set filter on %s" % valports[1], "testpmd> ") self.dut.send_expect("vlan set filter off %s" % valports[1], "testpmd> ") self.dut.send_expect("set flush_rx on", "testpmd> ") def set_up(self): """ Run before each test case. """ pass def filter_send_packet(self, type): """ Send packet to portid """ port = self.tester.get_local_port(valports[0]) txItf = self.tester.get_interface(port) port = self.tester.get_local_port(valports[1]) rxItf = self.tester.get_interface(port) mac = self.dut.get_mac_address(valports[0]) self.tester.scapy_foreground() if (type == "syn"): self.tester.scapy_append( 'sendp([Ether(dst="%s")/IP(src="2.2.2.5",dst="2.2.2.4")/TCP(dport=80,flags="S")], iface="%s")' % (mac, txItf)) elif (type == "arp"): self.tester.scapy_append( 'sendp([Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst="192.168.1.1")], iface="%s")' % (txItf)) elif (type == "arp_prio"): self.tester.scapy_append( 'sendp([Ether(dst="ff:ff:ff:ff:ff:ff")/Dot1Q(prio=3)/ARP(pdst="192.168.1.1")], iface="%s")' % (txItf)) elif (type == "fivetuple"): if self.nic == "niantic": self.tester.scapy_append( 'sendp([Ether(dst="%s")/Dot1Q(prio=3)/IP(src="2.2.2.4",dst="2.2.2.5")/TCP(sport=1,dport=1,flags=0)], iface="%s")' % (mac, txItf)) else: self.tester.scapy_append( 'sendp([Ether(dst="%s")/Dot1Q(prio=3)/IP(src="2.2.2.4",dst="2.2.2.5")/TCP(sport=1,dport=1)], iface="%s")' % (mac, txItf)) elif (type == "udp"): self.tester.scapy_append( 'sendp([Ether(dst="%s")/IP(src="2.2.2.4",dst="2.2.2.5")/UDP(dport=64)], iface="%s")' % (mac, txItf)) elif (type == "ip"): self.tester.scapy_append( 'sendp([Ether(dst="%s")/IP(src="2.2.2.4",dst="2.2.2.5")/TCP(sport=80,dport=80,flags=0)], iface="%s")' % (mac, txItf)) elif (type == "jumbo"): self.tester.scapy_append( 'sendp([Ether(dst="%s")/IP(src="2.2.2.5",dst="2.2.2.4")/TCP(dport=80,flags="S")/Raw(load="\x50"*1500)], iface="%s")' % (mac, txItf)) elif (type == "packet"): if (filters_index == 0): self.tester.scapy_append( 'sendp([Ether(dst="%s")/IP(src="2.2.2.4",dst="2.2.2.5")/TCP(sport=1,dport=1,flags=0)], iface="%s")' % (mac, txItf)) if (filters_index == 1): self.tester.scapy_append( 'sendp([Ether(dst="%s")/Dot1Q(prio=3)/IP(src="2.2.2.4",dst="2.2.2.5")/TCP(sport=1,dport=2,flags=0)], iface="%s")' % (mac, txItf)) self.tester.scapy_execute() def verify_result(self, outstring, tx_pkts, expect_queue): result_scanner = r"Forward Stats for RX Port= %s/Queue= ([0-9]+)" % valports[ 0] scanner = re.compile(result_scanner, re.DOTALL) m = scanner.search(outstring) queue_id = m.group(1) if self.nic == "niantic" and self.ethertype_filter == "on" and expect_queue == "0": self.ethertype_filter = "off" self.verify(queue_id == "0", "packet pass error") if expect_queue != queue_id: scanner = re.compile(result_scanner, re.DOTALL) m = scanner.search(outstring) queue_id = m.group(1) result_scanner = r"RX-packets: ([0-9]+) \s*" scanner = re.compile(result_scanner, re.DOTALL) m = scanner.search(outstring) p0tx_pkts = m.group(1) else: result_scanner = r"RX-packets: ([0-9]+) \s*" scanner = re.compile(result_scanner, re.DOTALL) m = scanner.search(outstring) p0tx_pkts = m.group(1) self.verify(p0tx_pkts == tx_pkts, "packet pass error") # TODO: failing test even in non-converted version def test_syn_filter(self): """ Enable receipt of SYN packets """ self.verify( self.nic in ["niantic", "kawela_4", "bartonhills", "powerville"], "%s nic not support syn filter" % self.nic) self.pmdout.start_testpmd( "%s" % self.cores, "--disable-rss --rxq=4 --txq=4 --portmask=%s --nb-cores=4 --nb-ports=1" % portMask) self.port_config() self.dut.send_expect( "syn_filter %s add priority high queue 2" % valports[0], "testpmd> ") self.dut.send_expect("start", "testpmd> ", 120) self.filter_send_packet("syn") time.sleep(2) out = self.dut.send_expect("stop", "testpmd> ") self.verify_result(out, tx_pkts="1", expect_queue="2") self.dut.send_expect("clear port stats all", "testpmd> ") self.dut.send_expect("start", "testpmd> ") self.filter_send_packet("arp") time.sleep(2) out = self.dut.send_expect("stop", "testpmd> ") self.verify_result(out, tx_pkts="1", expect_queue="0") self.dut.send_expect( "syn_filter %s del priority high queue 2" % valports[0], "testpmd> ") self.dut.send_expect("clear port stats all", "testpmd> ") self.dut.send_expect("start", "testpmd> ", 120) self.filter_send_packet("syn") time.sleep(2) out = self.dut.send_expect("stop", "testpmd> ") self.verify_result(out, tx_pkts="1", expect_queue="0") self.dut.send_expect("quit", "#") def test_priority_filter(self): """ priority filter """ self.pmdout.start_testpmd( "%s" % self.cores, "--disable-rss --rxq=4 --txq=4 --portmask=%s --nb-cores=4 --nb-ports=1" % portMask) self.port_config() if self.nic == "niantic": cmd = "5tuple_filter %s add dst_ip 2.2.2.5 src_ip 2.2.2.4 dst_port 1 src_port 1 protocol 0x06 mask 0x1f tcp_flags 0x0 priority 3 queue 3 " % ( valports[0]) self.dut.send_expect("%s" % cmd, "testpmd> ") cmd = "5tuple_filter %s add dst_ip 2.2.2.5 src_ip 2.2.2.4 dst_port 2 src_port 1 protocol 0x06 mask 0x18 tcp_flags 0x0 priority 2 queue 2 " % ( valports[0]) self.dut.send_expect("%s" % cmd, "testpmd> ") self.dut.send_expect("start", "testpmd> ", 120) self.filter_send_packet("fivetuple") out = self.dut.send_expect("stop", "testpmd> ") self.verify_result(out, tx_pkts="1", expect_queue="3") cmd = "5tuple_filter %s del dst_ip 2.2.2.5 src_ip 2.2.2.4 dst_port 1 src_port 1 protocol 0x06 mask 0x1f tcp_flags 0x0 priority 3 queue 3 " % ( valports[0]) self.dut.send_expect(cmd, "testpmd> ") self.dut.send_expect("clear port stats all", "testpmd> ") self.dut.send_expect("start", "testpmd> ", 120) self.filter_send_packet("fivetuple") out = self.dut.send_expect("stop", "testpmd> ") self.verify_result(out, tx_pkts="1", expect_queue="2") elif self.nic == "kawela_4": cmd = "5tuple_filter %s add dst_ip 2.2.2.5 src_ip 2.2.2.4 dst_port 1 src_port 1 protocol 0x06 mask 0x1f tcp_flags 0x02 priority 3 queue 3" % ( valports[0]) self.dut.send_expect("%s" % (cmd), "testpmd> ") self.dut.send_expect( "syn_filter %s add priority high queue 2" % valports[0], "testpmd> ") self.dut.send_expect("start", "testpmd> ", 120) self.filter_send_packet("fivetuple") out = self.dut.send_expect("stop", "testpmd> ") self.verify_result(out, tx_pkts="1", expect_queue="2") self.dut.send_expect( "syn_filter %s del priority high queue 2" % valports[0], "testpmd> ") self.dut.send_expect("start", "testpmd> ", 120) self.filter_send_packet("fivetuple") out = self.dut.send_expect("stop", "testpmd> ") self.verify_result(out, tx_pkts="1", expect_queue="3") elif self.nic in ["bartonhills", "powerville"]: self.dut.send_expect( "flex_filter %s add len 16 bytes 0x0123456789abcdef0000000008000000 mask 000C priority 2 queue 1" % (valports[0]), "testpmd> ") self.dut.send_expect( "2tuple_filter %s add dst_port 64 protocol 0x11 mask 1 tcp_flags 0 priority 3 queue 2" % valports[0], "testpmd> ") self.dut.send_expect("start", "testpmd> ", 120) self.filter_send_packet("udp") out = self.dut.send_expect("stop", "testpmd> ") self.verify_result(out, tx_pkts="1", expect_queue="1") self.dut.send_expect( "flex_filter %s del len 16 bytes 0x0123456789abcdef0000000008000000 mask 000C priority 2 queue 1" % valports[0], "testpmd> ") self.dut.send_expect("start", "testpmd> ", 120) self.filter_send_packet("udp") out = self.dut.send_expect("stop", "testpmd> ") self.verify_result(out, tx_pkts="1", expect_queue="2") else: self.verify(False, "%s nic not support this test" % self.nic) def test_five_tuple_filter(self): """ five tuple filter """ if self.nic in ["niantic", "kawela_4"]: self.pmdout.start_testpmd( "%s" % self.cores, "--disable-rss --rxq=4 --txq=4 --portmask=%s --nb-cores=4 --nb-ports=1" % portMask) self.port_config() mask = ['0x1f', '0x0'] for case in mask: if case == "0x1f": if self.nic == "niantic": cmd = "5tuple_filter %s add dst_ip 2.2.2.5 src_ip 2.2.2.4 dst_port 1 src_port 1 protocol 0x06 mask %s tcp_flags 0x0 priority 3 queue 3" % ( valports[0], case) if self.nic == "kawela_4": cmd = "5tuple_filter %s add dst_ip 2.2.2.5 src_ip 2.2.2.4 dst_port 1 src_port 1 protocol 0x06 mask %s tcp_flags 0x02 priority 3 queue 3" % ( valports[0], case) else: if self.nic == "niantic": cmd = "5tuple_filter %s add dst_ip 2.2.2.5 src_ip 2.2.2.4 dst_port 1 src_port 1 protocol 0x06 mask %s tcp_flags 0x0 priority 3 queue 3" % ( valports[0], case) if self.nic == "kawela_4": cmd = "5tuple_filter %s add dst_ip 2.2.2.5 src_ip 2.2.2.4 dst_port 1 src_port 1 protocol 0x06 mask %s tcp_flags 0x02 priority 3 queue 3" % ( valports[0], case) self.dut.send_expect("%s" % (cmd), "testpmd> ") # if case == "0x1f": # out = self.dut.send_expect("get_5tuple_filter %s index 1" % valports[0], "testpmd> ") # self.verify('Destination IP: 0x02020205 mask: 1' in out, "set 5-tuple filter error") # self.verify('Source IP: 0x02020204 mask: 1' in out, "set 5-tuple filter error") self.dut.send_expect("start", "testpmd> ", 120) self.filter_send_packet("fivetuple") out = self.dut.send_expect("stop", "testpmd> ") self.verify_result(out, tx_pkts="1", expect_queue="3") self.dut.send_expect("start", "testpmd> ", 120) self.filter_send_packet("arp") out = self.dut.send_expect("stop", "testpmd> ") self.verify_result(out, tx_pkts="1", expect_queue="0") if case == "0x1f": if self.nic == "niantic": cmd = "5tuple_filter %s del dst_ip 2.2.2.5 src_ip 2.2.2.4 dst_port 1 src_port 1 protocol 0x06 mask %s tcp_flags 0x0 priority 3 queue 3" % ( valports[0], case) if self.nic == "kawela_4": cmd = "5tuple_filter %s del dst_ip 2.2.2.5 src_ip 2.2.2.4 dst_port 1 src_port 1 protocol 0x06 mask %s tcp_flags 0x02 priority 3 queue 3" % ( valports[0], case) else: if self.nic == "niantic": cmd = "5tuple_filter %s del dst_ip 2.2.2.5 src_ip 2.2.2.4 dst_port 1 src_port 1 protocol 0x06 mask %s tcp_flags 0x0 priority 3 queue 3" % ( valports[0], case) if self.nic == "kawela_4": cmd = "5tuple_filter %s del dst_ip 2.2.2.5 src_ip 2.2.2.4 dst_port 1 src_port 1 protocol 0x06 mask %s tcp_flags 0x02 priority 3 queue 3" % ( valports[0], case) self.dut.send_expect("%s" % (cmd), "testpmd> ") self.dut.send_expect("start", "testpmd> ", 120) self.filter_send_packet("fivetuple") out = self.dut.send_expect("stop", "testpmd> ") self.verify_result(out, tx_pkts="1", expect_queue="0") self.dut.send_expect("quit", "#") else: self.verify(False, "%s nic not support syn filter" % self.nic) def test_ethertype_filter(self): self.verify( self.nic in [ "niantic", "kawela_4", "bartonhills", "powerville", "fortville_eagle", "fortville_spirit", "fortville_spirit_single", "fortpark_TLV", "fortville_25g", "cavium_a063" ], "%s nic not support syn filter" % self.nic) self.pmdout.start_testpmd( "%s" % self.cores, "--disable-rss --rxq=4 --txq=4 --portmask=%s --nb-cores=4 --nb-ports=1" % portMask) self.port_config() self.ethertype_filter = "on" ethertype = "0x0806" if self.nic == "cavium_a063": self.dut.send_expect( "flow create %s ingress pattern eth type is %s / end actions queue index 2 / end" % (valports[0], ethertype), "testpmd> ") else: self.dut.send_expect( "ethertype_filter %s add mac_ignr 00:00:00:00:00:00 ethertype %s fwd queue 2" % (valports[0], ethertype), "testpmd> ") self.dut.send_expect("start", "testpmd> ", 120) self.filter_send_packet("arp") time.sleep(2) out = self.dut.send_expect("stop", "testpmd> ") self.dut.send_expect("clear port stats all", "testpmd> ") self.verify_result(out, tx_pkts="1", expect_queue="2") if self.nic == "niantic": self.dut.send_expect("start", "testpmd> ") self.filter_send_packet("arp_prio") time.sleep(2) out = self.dut.send_expect("stop", "testpmd> ") self.dut.send_expect("clear port stats all", "testpmd> ") self.verify_result(out, tx_pkts="1", expect_queue="2") if self.nic == "cavium_a063": self.dut.send_expect("flow flush %s" % (valports[0]), "testpmd> ") else: self.dut.send_expect( "ethertype_filter %s del mac_ignr 00:00:00:00:00:00 ethertype %s fwd queue 2" % (valports[0], ethertype), "testpmd> ") self.dut.send_expect("start", "testpmd> ", 120) self.filter_send_packet("arp") time.sleep(2) out = self.dut.send_expect("stop", "testpmd> ") self.dut.send_expect("clear port stats all", "testpmd> ") self.verify_result(out, tx_pkts="1", expect_queue="0") def test_multiple_filters_10GB(self): if self.nic == "niantic": self.pmdout.start_testpmd( "%s" % self.cores, "--disable-rss --rxq=4 --txq=4 --portmask=%s --nb-cores=4 --nb-ports=1" % portMask) self.port_config() self.dut.send_expect( "syn_filter %s add priority high queue 1" % valports[0], "testpmd> ") self.dut.send_expect( "ethertype_filter %s add mac_ignr 00:00:00:00:00:00 ethertype 0x0806 fwd queue 2" % valports[0], "testpmd> ") self.dut.send_expect( "5tuple_filter %s add dst_ip 2.2.2.5 src_ip 2.2.2.4 dst_port 1 src_port 1 protocol 0x06 mask 0x1f tcp_flags 0x0 priority 3 queue 3 " % (valports[0]), "testpmd> ") self.dut.send_expect("start", "testpmd> ") self.filter_send_packet("syn") out = self.dut.send_expect("stop", "testpmd> ") self.dut.send_expect("clear port stats all", "testpmd> ") self.verify_result(out, tx_pkts="1", expect_queue="1") self.ethertype_filter = "on" self.dut.send_expect("start", "testpmd> ") self.filter_send_packet("arp") out = self.dut.send_expect("stop", "testpmd> ") self.dut.send_expect("clear port stats all", "testpmd> ") self.verify_result(out, tx_pkts="1", expect_queue="2") self.dut.send_expect("start", "testpmd> ") self.filter_send_packet("arp_prio") out = self.dut.send_expect("stop", "testpmd> ") self.dut.send_expect("clear port stats all", "testpmd> ") self.verify_result(out, tx_pkts="1", expect_queue="2") self.dut.send_expect("start", "testpmd> ") self.filter_send_packet("fivetuple") out = self.dut.send_expect("stop", "testpmd> ") self.dut.send_expect("clear port stats all", "testpmd> ") self.verify_result(out, tx_pkts="1", expect_queue="3") self.dut.send_expect( "5tuple_filter %s del dst_ip 2.2.2.5 src_ip 2.2.2.4 dst_port 1 src_port 1 protocol 0x06 mask 0x1f tcp_flags 0x0 priority 3 queue 3 " % (valports[0]), "testpmd> ") self.dut.send_expect("start", "testpmd> ") self.filter_send_packet("syn") out = self.dut.send_expect("stop", "testpmd> ") self.dut.send_expect("clear port stats all", "testpmd> ") self.verify_result(out, tx_pkts="1", expect_queue="1") self.dut.send_expect("start", "testpmd> ") self.filter_send_packet("arp") out = self.dut.send_expect("stop", "testpmd> ") self.dut.send_expect("clear port stats all", "testpmd> ") self.verify_result(out, tx_pkts="1", expect_queue="2") self.dut.send_expect("start", "testpmd> ") self.filter_send_packet("fivetuple") out = self.dut.send_expect("stop", "testpmd> ") self.dut.send_expect("clear port stats all", "testpmd> ") self.verify_result(out, tx_pkts="1", expect_queue="0") self.dut.send_expect( "ethertype_filter %s del mac_ignr 00:00:00:00:00:00 ethertype 0x0806 fwd queue 2" % valports[0], "testpmd> ") self.dut.send_expect("start", "testpmd> ") self.filter_send_packet("arp") out = self.dut.send_expect("stop", "testpmd> ") self.dut.send_expect("clear port stats all", "testpmd> ") self.verify_result(out, tx_pkts="1", expect_queue="0") self.dut.send_expect("start", "testpmd> ") self.filter_send_packet("syn") out = self.dut.send_expect("stop", "testpmd> ") self.dut.send_expect("clear port stats all", "testpmd> ") self.verify_result(out, tx_pkts="1", expect_queue="1") self.dut.send_expect( "syn_filter %s del priority high queue 1" % valports[0], "testpmd> ") self.dut.send_expect("start", "testpmd> ") self.filter_send_packet("syn") out = self.dut.send_expect("stop", "testpmd> ") self.dut.send_expect("clear port stats all", "testpmd> ") self.verify_result(out, tx_pkts="1", expect_queue="0") else: self.verify(False, "%s nic not support this test" % self.nic) def test_twotuple_filter(self): if self.nic in ["powerville", "bartonhills", "cavium_a063"]: self.pmdout.start_testpmd( "%s" % self.cores, "--disable-rss --rxq=4 --txq=4 --portmask=%s --nb-cores=4 --nb-ports=1" % portMask) self.port_config() self.dut.send_expect( "2tuple_filter %s add dst_port 64 protocol 0x11 mask 1 tcp_flags 0 priority 3 queue 1" % valports[0], "testpmd> ") self.dut.send_expect("start", "testpmd> ", 120) self.filter_send_packet("udp") out = self.dut.send_expect("stop", "testpmd> ") self.verify_result(out, tx_pkts="1", expect_queue="1") self.dut.send_expect("start", "testpmd> ") self.filter_send_packet("syn") time.sleep(2) out = self.dut.send_expect("stop", "testpmd> ") self.verify_result(out, tx_pkts="1", expect_queue="0") self.dut.send_expect( "2tuple_filter %s del dst_port 64 protocol 0x11 mask 1 tcp_flags 0 priority 3 queue 1" % valports[0], "testpmd> ") self.dut.send_expect("start", "testpmd> ", 120) self.filter_send_packet("udp") time.sleep(2) out = self.dut.send_expect("stop", "testpmd> ") self.verify_result(out, tx_pkts="1", expect_queue="0") self.dut.send_expect("quit", "#") else: self.verify(False, "%s nic not support two tuple filter" % self.nic) def test_flex_filter(self): self.verify(self.nic in ["powerville", "bartonhills", "cavium_a063"], '%s not support flex filter' % self.nic) masks = ['000C', '000C'] self.pmdout.start_testpmd( "%s" % self.cores, "--disable-rss --rxq=4 --txq=4 --portmask=%s --nb-cores=4 --nb-ports=1" % portMask) self.port_config() for i in [0, 1]: if i == 0: self.dut.send_expect( "flex_filter %s add len 16 bytes 0x0123456789abcdef0000000008060000 mask %s priority 3 queue 1" % (valports[0], masks[i]), "testpmd> ") else: self.dut.send_expect( "flex_filter %s add len 16 bytes 0x0123456789abcdef0000000008000000 mask %s priority 3 queue 1" % (valports[0], masks[i]), "testpmd> ") self.dut.send_expect("start", "testpmd> ", 120) if i == 0: self.filter_send_packet("arp") else: self.filter_send_packet("ip") time.sleep(2) out = self.dut.send_expect("stop", "testpmd> ") self.verify_result(out, tx_pkts="1", expect_queue="1") self.dut.send_expect("start", "testpmd> ") if i == 0: self.filter_send_packet("syn") else: self.filter_send_packet("arp") time.sleep(2) out = self.dut.send_expect("stop", "testpmd> ") self.verify_result(out, tx_pkts="1", expect_queue="0") if i == 0: self.dut.send_expect( "flex_filter %s del len 16 bytes 0x0123456789abcdef0000000008060000 mask %s priority 3 queue 1" % (valports[0], masks[i]), "testpmd> ") else: self.dut.send_expect( "flex_filter %s del len 16 bytes 0x0123456789abcdef0000000008000000 mask %s priority 3 queue 1" % (valports[0], masks[i]), "testpmd> ") self.dut.send_expect("start", "testpmd> ", 120) if i == 0: self.filter_send_packet("arp") else: self.filter_send_packet("ip") out = self.dut.send_expect("stop", "testpmd> ") self.verify_result(out, tx_pkts="1", expect_queue="0") def test_multiple_filters_1GB(self): if self.nic in ["powerville", "kawela_4", "bartonhills"]: self.pmdout.start_testpmd( "%s" % self.cores, "--disable-rss --rxq=4 --txq=4 --portmask=%s --nb-cores=4 --nb-ports=1" % portMask) self.port_config() self.dut.send_expect( "syn_filter %s add priority high queue 1" % valports[0], "testpmd> ") self.dut.send_expect( "ethertype_filter %s add mac_ignr 00:00:00:00:00:00 ethertype 0x0806 fwd queue 3" % (valports[0]), "testpmd> ") self.dut.send_expect("start", "testpmd> ") self.dut.send_expect("start", "testpmd> ") self.filter_send_packet("arp") time.sleep(2) out = self.dut.send_expect("stop", "testpmd> ") self.verify_result(out, tx_pkts="1", expect_queue="3") self.dut.send_expect("start", "testpmd> ") self.filter_send_packet("syn") time.sleep(2) out = self.dut.send_expect("stop", "testpmd> ") self.verify_result(out, tx_pkts="1", expect_queue="1") # remove all filters self.dut.send_expect( "syn_filter %s del priority high queue 1" % valports[0], "testpmd> ") self.dut.send_expect( "ethertype_filter %s del mac_ignr 00:00:00:00:00:00 ethertype 0x0806 fwd queue 3" % valports[0], "testpmd> ") self.dut.send_expect("start", "testpmd> ") self.filter_send_packet("arp") time.sleep(2) out = self.dut.send_expect("stop", "testpmd> ") self.verify_result(out, tx_pkts="1", expect_queue="0") self.dut.send_expect("start", "testpmd> ") self.filter_send_packet("syn") time.sleep(2) out = self.dut.send_expect("stop", "testpmd> ") self.verify_result(out, tx_pkts="1", expect_queue="0") else: self.verify(False, "%s nic not support this test" % self.nic) def test_jumbo_frame_size(self): self.verify( self.nic not in [ "fortville_eagle", "fortville_spirit", "fortville_spirit_single", "fortville_25g", "fortpark_TLV" ], "%s nic not support this test" % self.nic) self.pmdout.start_testpmd( "%s" % self.cores, "--disable-rss --rxq=4 --txq=4 --portmask=%s --nb-cores=4 --nb-ports=1 --mbcache=200 --mbuf-size=2048 --max-pkt-len=9600" % portMask) port = self.tester.get_local_port(valports[0]) txItf = self.tester.get_interface(port) port = self.tester.get_local_port(valports[1]) rxItf = self.tester.get_interface(port) self.tester.send_expect("ifconfig %s mtu %s" % (txItf, 9200), "# ") self.tester.send_expect("ifconfig %s mtu %s" % (rxItf, 9200), "# ") self.dut.send_expect("set stat_qmap rx %s 0 0" % valports[0], "testpmd> ") self.dut.send_expect("set stat_qmap rx %s 0 0" % valports[1], "testpmd> ") self.dut.send_expect("set stat_qmap rx %s 1 1" % valports[0], "testpmd> ") self.dut.send_expect("set stat_qmap rx %s 1 1" % valports[1], "testpmd> ") self.dut.send_expect("set stat_qmap rx %s 2 2" % valports[0], "testpmd> ") self.dut.send_expect("set stat_qmap rx %s 2 2" % valports[1], "testpmd> ") self.dut.send_expect("set stat_qmap rx %s 3 3" % valports[0], "testpmd> ") self.dut.send_expect("set stat_qmap rx %s 3 3" % valports[1], "testpmd> ") self.dut.send_expect("vlan set strip off %s" % valports[0], "testpmd> ") self.dut.send_expect("vlan set strip off %s" % valports[1], "testpmd> ") self.dut.send_expect("vlan set filter off %s" % valports[0], "testpmd> ") self.dut.send_expect("vlan set filter off %s" % valports[1], "testpmd> ") self.dut.send_expect( "syn_filter %s add priority high queue 2" % valports[0], "testpmd> ") self.dut.send_expect("start", "testpmd> ", 120) self.filter_send_packet("jumbo") time.sleep(1) out = self.dut.send_expect("stop", "testpmd> ") self.dut.send_expect("clear port stats all", "testpmd>") self.verify_result(out, tx_pkts="1", expect_queue="2") self.dut.send_expect("start", "testpmd> ") self.filter_send_packet("arp") time.sleep(1) out = self.dut.send_expect("stop", "testpmd> ") self.dut.send_expect("clear port stats all", "testpmd>") self.verify_result(out, tx_pkts="1", expect_queue="0") self.dut.send_expect( "syn_filter %s del priority high queue 2" % valports[0], "testpmd> ") self.dut.send_expect("start", "testpmd> ", 120) self.filter_send_packet("jumbo") time.sleep(1) out = self.dut.send_expect("stop", "testpmd> ") self.dut.send_expect("clear port stats all", "testpmd>") self.verify_result(out, tx_pkts="1", expect_queue="0") self.tester.send_expect("ifconfig %s mtu %s" % (txItf, 1500), "# ") self.tester.send_expect("ifconfig %s mtu %s" % (rxItf, 1500), "# ") def test_128_queues(self): # testpmd can't support assign queue to received packet, so can't test if self.kdriver == "ixgbe": self.dut.send_expect( "sed -i -e 's/#define IXGBE_NONE_MODE_TX_NB_QUEUES 64$/#define IXGBE_NONE_MODE_TX_NB_QUEUES 128/' drivers/net/ixgbe/ixgbe_ethdev.h", "# ", 30) self.dut.build_install_dpdk(self.target) global valports total_mbufs = self.request_mbufs(128) * len(valports) self.pmdout.start_testpmd( "all", "--disable-rss --rxq=128 --txq=128 --portmask=%s --nb-cores=4 --total-num-mbufs=%d" % (portMask, total_mbufs)) self.dut.send_expect("set stat_qmap rx %s 0 0" % valports[0], "testpmd> ") self.dut.send_expect("set stat_qmap rx %s 0 0" % valports[1], "testpmd> ") self.dut.send_expect("vlan set strip off %s" % valports[0], "testpmd> ") self.dut.send_expect("vlan set strip off %s" % valports[1], "testpmd> ") self.dut.send_expect("vlan set filter off %s" % valports[0], "testpmd> ") self.dut.send_expect("vlan set filter off %s" % valports[1], "testpmd> ") frames_to_send = 1 queue = ['64', '127', '128'] for i in [0, 1, 2]: if i == 2: out = self.dut.send_expect( "set stat_qmap rx %s %s %s" % (valports[0], queue[i], (i + 1)), "testpmd> ") self.verify('Invalid RX queue %s' % (queue[i]) in out, "set filters error") out = self.dut.send_expect( "5tuple_filter %s add dst_ip 2.2.2.5 src_ip 2.2.2.4 dst_port %s src_port 1 protocol 0x06 mask 0x1f tcp_flags 0x0 priority 3 queue %s " % (valports[0], (i + 1), queue[i]), "testpmd> ") self.verify('error' in out, "set filters error") continue else: self.dut.send_expect( "set stat_qmap rx %s %s %s" % (valports[0], queue[i], (i + 1)), "testpmd> ") out = self.dut.send_expect( "5tuple_filter %s add dst_ip 2.2.2.5 src_ip 2.2.2.4 dst_port %s src_port 1 protocol 0x06 mask 0x1f tcp_flags 0x0 priority %d queue %s " % (valports[0], (i + 1), (3 - i), queue[i]), "testpmd> ") self.dut.send_expect("start", "testpmd> ", 120) global filters_index filters_index = i self.filter_send_packet("packet") time.sleep(1) out = self.dut.send_expect("stop", "testpmd> ") cmd = "Stats reg %s RX-packets: ([0-9]+)" % (i + 1) result_scanner = r"%s" % cmd scanner = re.compile(result_scanner, re.DOTALL) m = scanner.search(out) cur_pkt = m.group(1) self.verify( int(cur_pkt) == frames_to_send, "packet pass assert error") self.dut.send_expect("quit", "#") else: self.verify(False, "%s not support this test" % self.nic) def test_perf_generic_filter_perf(self): self.pmdout.start_testpmd( "%s" % self.cores, "--disable-rss --rxq=4 --txq=4 --portmask=%s --nb-cores=4 --nb-ports=1" % portMask) self.port_config() print valports[0], valports[1] tx_port = self.tester.get_local_port(valports[0]) tx_mac = self.dut.get_mac_address(valports[0]) txItf = self.tester.get_interface(tx_port) rx_port = self.tester.get_local_port(valports[1]) rxItf = self.tester.get_interface(rx_port) package_sizes = [64, 128, 256, 512, 1024, 1280, 1518] print tx_mac print self.dut.ports_info[valports[0]], self.dut.ports_info[ valports[1]] test_type = { "syn": [ "syn_filter add 0 priority high queue 1", "syn_filter del 0 priority high queue 1" ], "ethertype": [ "add_ethertype_filter 0 ethertype 0x0806 priority disable 0 queue 2 index 1", "remove_ethertype_filter 0 index 1" ], "5tuple": [ "5tuple_filter 0 add dst_ip 2.2.2.5 src_ip 2.2.2.4 dst_port 1 src_port 1 protocol 0x06 mask 0x1f tcp_flags 0x02 priority 3 queue 3", "5tuple_filter 0 add dst_ip 2.2.2.5 src_ip 2.2.2.4 dst_port 1 src_port 1 protocol 0x06 mask 0x1f tcp_flags 0x02 priority 3 queue 3" ] } stream_config = { "syn": 'Ether(dst="%s")/IP(src="2.2.2.5",dst="2.2.2.4")/TCP(dport=80,flags="S")/("X"*64)', "ethertype": 'Ether(dst="%s")/ARP(pdst="192.168.1.1")' % tx_mac, "5tuple": 'flows.append(Ether(dst="%s")/IP(src="2.2.2.4",dst="2.2.2.5")/TCP(sport=1,dport=1,flags=0)/("X"*%d))', } self.result_table_create( ['pack_size', "filter_type", "enable", "disable", "perf_compare"]) for key in test_type.keys(): if "5tuple" != key: pps_lists = [] for i in range(2): self.dut.send_expect(test_type[key][i], "testpmd> ", 15) self.dut.send_expect("start", "testpmd> ", 120) self.tester.scapy_append('flows = []') self.tester.scapy_append('flows.append(%s)' % stream_config[key]) self.tester.scapy_append( 'wrpcap("generic_firlter.pcap",flows)') self.tester.scapy_execute() tgen_input = [] tgen_input.append( (tx_port, rx_port, "generic_firlter.pcap")) _, pps = self.tester.traffic_generator_throughput( tgen_input) pps_lists.append(pps) self.result_table_add([ "defult", key, pps_lists[0], pps_lists[1], (pps_lists[0] - pps_lists[1]) / float(pps_lists[1]) ]) # this is a TCP/IP packet, need to test different payload_size if ("5tuple" == key) and ("niantic" == self.nic): for package_size in package_sizes: payload_size = package_size - \ HEADER_SIZE["tcp"] - HEADER_SIZE[ 'ip'] - HEADER_SIZE['eth'] pps_lists = [] for i in range(2): self.dut.send_expect(test_type[key][i], "testpmd> ", 15) self.dut.send_expect("start", "testpmd> ", 120) self.tester.scapy_append('flows = []') self.tester.scapy_append('flows.append(%s)' % (stream_config[key] % (tx_mac, payload_size))) self.tester.scapy_append( 'wrpcap("generic_firlter.pcap",flows)') self.tester.scapy_execute() tgen_input = [] # tgen_input.append((txItf, rxItf, "generic_firlter.pcap")) tgen_input.append( (tx_port, rx_port, "generic_firlter.pcap")) print tgen_input _, pps = self.tester.traffic_generator_throughput( tgen_input) pps_lists.append(pps) self.result_table_add([ package_size, key, pps_lists[0], pps_lists[1], (pps_lists[0] - pps_lists[1]) / float(pps_lists[1]) ]) self.result_table_print() def tear_down(self): """ Run after each test case. """ self.dut.kill_all() self.dut.send_expect( "sed -i -e 's/#define IXGBE_NONE_MODE_TX_NB_QUEUES 64$/#define IXGBE_NONE_MODE_TX_NB_QUEUES 128/' drivers/net/ixgbe/ixgbe_ethdev.h", "# ", 30) self.dut.build_install_dpdk(self.target)
class TestJumboframes(TestCase): def jumboframes_get_stat(self, portid, rx_tx): """ Get packets number from port statistic """ stats = self.pmdout.get_pmd_stats(portid) if rx_tx == "rx": return [stats['RX-packets'], stats['RX-errors'], stats['RX-bytes']] elif rx_tx == "tx": return [stats['TX-packets'], stats['TX-errors'], stats['TX-bytes']] else: return None def jumboframes_send_packet(self, pktsize, received=True): """ Send 1 packet to portid """ gp0tx_pkts, _, gp0tx_bytes = [int(_) for _ in self.jumboframes_get_stat(self.rx_port, "tx")] gp1rx_pkts, gp1rx_err, gp1rx_bytes = [int(_) for _ in self.jumboframes_get_stat(self.tx_port, "rx")] itf = self.tester.get_interface(self.tester.get_local_port(self.tx_port)) mac = self.dut.get_mac_address(self.tx_port) # The packet total size include ethernet header, ip header, and payload. # ethernet header length is 18 bytes, ip standard header length is 20 bytes. pktlen = pktsize - ETHER_HEADER_LEN padding = pktlen - IP_HEADER_LEN self.tester.scapy_foreground() self.tester.scapy_append('nutmac="%s"' % mac) self.tester.scapy_append('sendp([Ether(dst=nutmac, src="52:00:00:00:00:00")/IP(len=%s)/Raw(load="\x50"*%s)], iface="%s")' % (pktlen, padding, itf)) out = self.tester.scapy_execute() sleep(5) p0tx_pkts, _, p0tx_bytes = [int(_) for _ in self.jumboframes_get_stat(self.rx_port, "tx")] # p0tx_pkts, p0tx_err, p0tx_bytes p1rx_pkts, p1rx_err, p1rx_bytes = [int(_) for _ in self.jumboframes_get_stat(self.tx_port, "rx")] p0tx_pkts -= gp0tx_pkts p0tx_bytes -= gp0tx_bytes p1rx_pkts -= gp1rx_pkts p1rx_bytes -= gp1rx_bytes p1rx_err -= gp1rx_err if received: self.verify(p0tx_pkts == p1rx_pkts and p0tx_bytes == pktsize and p1rx_bytes == pktsize, "packet pass assert error") else: self.verify(p0tx_pkts == p1rx_pkts and (p1rx_err == 1 or p1rx_pkts == 0), "packet drop assert error") return out # # # # Test cases. # def set_up_all(self): """ Prerequisite steps for each test suit. """ self.dut_ports = self.dut.get_ports() self.verify(len(self.dut_ports) >= 2, "Insufficient ports") self.rx_port = self.dut_ports[0] self.tx_port = self.dut_ports[1] cores = self.dut.get_core_list('1S/2C/2T') self.coremask = dts.create_mask(cores) self.port_mask = dts.create_mask([self.rx_port, self.tx_port]) self.tester.send_expect("ifconfig %s mtu %s" % (self.tester.get_interface(self.tester.get_local_port(self.rx_port)), ETHER_JUMBO_FRAME_MTU + 200), "# ") self.tester.send_expect("ifconfig %s mtu %s" % (self.tester.get_interface(self.tester.get_local_port(self.tx_port)), ETHER_JUMBO_FRAME_MTU + 200), "# ") self.pmdout = PmdOutput(self.dut) def set_up(self): """ This is to clear up environment before the case run. """ self.dut.kill_all() def test_jumboframes_normal_nojumbo(self): """ This case aims to test transmitting normal size packet without jumbo frame on testpmd app. """ self.dut.kill_all() self.pmdout.start_testpmd("all", "--max-pkt-len=%d" % (ETHER_STANDARD_MTU)) self.dut.send_expect("start", "testpmd> ") self.jumboframes_send_packet(ETHER_STANDARD_MTU - 1) self.jumboframes_send_packet(ETHER_STANDARD_MTU) self.dut.send_expect("stop", "testpmd> ") self.dut.send_expect("quit", "# ", 30) def test_jumboframes_jumbo_nojumbo(self): """ This case aims to test transmitting jumbo frame packet on testpmd without jumbo frame support. """ self.dut.kill_all() self.pmdout.start_testpmd("all", "--max-pkt-len=%d" % (ETHER_STANDARD_MTU)) self.dut.send_expect("start", "testpmd> ") self.jumboframes_send_packet(ETHER_STANDARD_MTU + 1, False) self.dut.send_expect("stop", "testpmd> ") self.dut.send_expect("quit", "# ", 30) def test_jumboframes_normal_jumbo(self): """ When jumbo frame supported, this case is to verify that the normal size packet forwrding should be support correct. """ self.dut.kill_all() self.pmdout.start_testpmd("all", "--max-pkt-len=%s" % (ETHER_JUMBO_FRAME_MTU)) self.dut.send_expect("start", "testpmd> ") self.jumboframes_send_packet(1517) self.jumboframes_send_packet(1518) self.dut.send_expect("stop", "testpmd> ") self.dut.send_expect("quit", "# ", 30) def test_jumboframes_jumbo_jumbo(self): """ When jumbo frame supported, this case is to verify that jumbo frame packet can be forwarded correct. """ self.dut.kill_all() self.pmdout.start_testpmd("all", "--max-pkt-len=%s" % (ETHER_JUMBO_FRAME_MTU)) self.dut.send_expect("start", "testpmd> ") self.jumboframes_send_packet(ETHER_STANDARD_MTU + 1) self.jumboframes_send_packet(ETHER_JUMBO_FRAME_MTU - 1) self.jumboframes_send_packet(ETHER_JUMBO_FRAME_MTU) self.dut.send_expect("stop", "testpmd> ") self.dut.send_expect("quit", "# ", 30) def test_jumboframes_bigger_jumbo(self): """ When the jubmo frame MTU set as 9000, this case is to verify that the packet which the length bigger than MTU can not be forwarded. """ self.dut.kill_all() self.pmdout.start_testpmd("1S/2C/1T", "--max-pkt-len=%s" % (ETHER_JUMBO_FRAME_MTU)) self.dut.send_expect("start", "testpmd> ") self.jumboframes_send_packet(ETHER_JUMBO_FRAME_MTU + 1, False) self.dut.send_expect("quit", "# ", 30) def tear_down(self): """ Run after each test case. """ pass def tear_down_all(self): """ When the case of this test suite finished, the enviroment should clear up. """ self.tester.send_expect("ifconfig %s mtu %s" % (self.tester.get_interface(self.tester.get_local_port(self.rx_port)), ETHER_STANDARD_MTU), "# ") self.tester.send_expect("ifconfig %s mtu %s" % (self.tester.get_interface(self.tester.get_local_port(self.tx_port)), ETHER_STANDARD_MTU), "# ")
class TestPmd(TestCase): def plot_results(self, number_ports): cores_configs = [] percent_values = [] # Append the percentage results for the all the cores configs for test_cycle in self.test_cycles: cores_configs.append(test_cycle['cores']) config_results = [] for frame_size in self.frame_sizes: config_results.append(test_cycle['pct'][frame_size]) percent_values.append(config_results) image_path = self.plotting.create_bars_plot( 'test_perf_pmd_%sports' % number_ports, 'PMD, %d ports' % number_ports, self.frame_sizes, percent_values, ylabel='% linerate', legend=cores_configs) dts.results_plot_print(image_path) def set_up_all(self): """ Run at the start of each test suite. PMD prerequisites. """ self.frame_sizes = [64, 65, 128, 256, 512, 1024, 1280, 1518] self.rxfreet_values = [0, 8, 16, 32, 64, 128] self.test_cycles = [{'cores': '1S/1C/1T', 'Mpps': {}, 'pct': {}}, {'cores': '1S/1C/2T', 'Mpps': {}, 'pct': {}}, {'cores': '1S/2C/1T', 'Mpps': {}, 'pct': {}}, {'cores': '1S/2C/2T', 'Mpps': {}, 'pct': {}}, {'cores': '1S/4C/2T', 'Mpps': {}, 'pct': {}} ] self.table_header = ['Frame Size'] for test_cycle in self.test_cycles: self.table_header.append("%s Mpps" % test_cycle['cores']) self.table_header.append("% linerate") self.blacklist = "" # Based on h/w type, choose how many ports to use self.dut_ports = self.dut.get_ports() self.headers_size = HEADER_SIZE['eth'] + HEADER_SIZE[ 'ip'] + HEADER_SIZE['udp'] self.ports_socket = self.dut.get_numa_id(self.dut_ports[0]) self.plotting = Plotting(self.dut.crb['name'], self.target, self.nic) self.pmdout = PmdOutput(self.dut) def set_up(self): """ Run before each test case. """ pass def test_perf_pmd_performance_4ports(self): """ PMD Performance Benchmarking with 4 ports. """ all_cores_mask = dts.create_mask(self.dut.get_core_list("all")) # prepare traffic generator input self.verify(len(self.dut_ports) >= 4, "Insufficient ports for 4 ports performance") tgen_input = [] tgen_input.append((self.tester.get_local_port(self.dut_ports[0]), self.tester.get_local_port(self.dut_ports[1]), "test.pcap")) tgen_input.append((self.tester.get_local_port(self.dut_ports[2]), self.tester.get_local_port(self.dut_ports[3]), "test.pcap")) tgen_input.append((self.tester.get_local_port(self.dut_ports[1]), self.tester.get_local_port(self.dut_ports[0]), "test.pcap")) tgen_input.append((self.tester.get_local_port(self.dut_ports[3]), self.tester.get_local_port(self.dut_ports[2]), "test.pcap")) # run testpmd for each core config for test_cycle in self.test_cycles: core_config = test_cycle['cores'] core_list = self.dut.get_core_list(core_config, socket=self.ports_socket) if len(core_list) > 4: queues = len(core_list) / 4 else: queues = 1 core_mask = dts.create_mask(core_list) port_mask = dts.create_mask(self.dut.get_ports()) self.pmdout.start_testpmd("all", "--coremask=%s --rxq=%d --txq=%d --portmask=%s" % (core_mask, queues, queues, port_mask)) info = "Executing PMD (mac fwd) using %s\n" % test_cycle['cores'] dts.report(info, annex=True) self.logger.info(info) dts.report(commandLine + "\n\n", frame=True, annex=True) # self.dut.send_expect("set fwd mac", "testpmd> ", 100) self.dut.send_expect("start", "testpmd> ") for frame_size in self.frame_sizes: wirespeed = self.wirespeed(self.nic, frame_size, 4) # create pcap file self.logger.info("Running with frame size %d " % frame_size) payload_size = frame_size - self.headers_size self.tester.scapy_append( 'wrpcap("test.pcap", [Ether(src="52:00:00:00:00:00")/IP()/UDP()/("X"*%d)])' % payload_size) self.tester.scapy_execute() # run traffic generator _, pps = self.tester.traffic_generator_throughput(tgen_input) pps /= 1000000.0 test_cycle['Mpps'][frame_size] = pps test_cycle['pct'][frame_size] = pps * 100 / wirespeed self.dut.send_expect("stop", "testpmd> ") self.dut.send_expect("quit", "# ", 30) sleep(5) for n in range(len(self.test_cycles)): for frame_size in self.frame_sizes: self.verify(self.test_cycles[n]['Mpps'][ frame_size] is not 0, "No traffic detected") # Print results dts.results_table_add_header(self.table_header) for frame_size in self.frame_sizes: table_row = [frame_size] for test_cycle in self.test_cycles: table_row.append(test_cycle['Mpps'][frame_size]) table_row.append(test_cycle['pct'][frame_size]) dts.results_table_add_row(table_row) self.plot_results(number_ports=4) dts.results_table_print() def test_perf_pmd_performance_2ports(self): """ PMD Performance Benchmarking with 2 ports. """ all_cores_mask = dts.create_mask(self.dut.get_core_list("all")) # prepare traffic generator input tgen_input = [] tgen_input.append((self.tester.get_local_port(self.dut_ports[0]), self.tester.get_local_port(self.dut_ports[1]), "test.pcap")) tgen_input.append((self.tester.get_local_port(self.dut_ports[1]), self.tester.get_local_port(self.dut_ports[0]), "test.pcap")) # run testpmd for each core config for test_cycle in self.test_cycles: core_config = test_cycle['cores'] core_list = self.dut.get_core_list(core_config, socket=self.ports_socket) if len(core_list) > 2: queues = len(core_list) / 2 else: queues = 1 core_mask = dts.create_mask(core_list) port_mask = dts.create_mask([self.dut_ports[0], self.dut_ports[1]]) self.pmdout.start_testpmd("all", "--coremask=%s --rxq=%d --txq=%d --portmask=%s" % (core_mask, queues, queues, port_mask)) command_line = self.pmdout.get_pmd_cmd() info = "Executing PMD using %s\n" % test_cycle['cores'] self.logger.info(info) dts.report(info, annex=True) dts.report(command_line + "\n\n", frame=True, annex=True) self.dut.send_expect("start", "testpmd> ") for frame_size in self.frame_sizes: wirespeed = self.wirespeed(self.nic, frame_size, 2) # create pcap file self.logger.info("Running with frame size %d " % frame_size) payload_size = frame_size - self.headers_size self.tester.scapy_append( 'wrpcap("test.pcap", [Ether(src="52:00:00:00:00:00")/IP()/UDP()/("X"*%d)])' % payload_size) self.tester.scapy_execute() # run traffic generator _, pps = self.tester.traffic_generator_throughput(tgen_input) pps /= 1000000.0 test_cycle['Mpps'][frame_size] = pps test_cycle['pct'][frame_size] = pps * 100 / wirespeed self.dut.send_expect("stop", "testpmd> ") self.dut.send_expect("quit", "# ", 30) sleep(5) for n in range(len(self.test_cycles)): for frame_size in self.frame_sizes: self.verify(self.test_cycles[n]['Mpps'][ frame_size] > 0, "No traffic detected") # Print results dts.results_table_add_header(self.table_header) for frame_size in self.frame_sizes: table_row = [frame_size] for test_cycle in self.test_cycles: table_row.append(test_cycle['Mpps'][frame_size]) table_row.append(test_cycle['pct'][frame_size]) dts.results_table_add_row(table_row) self.plot_results(number_ports=2) dts.results_table_print() def test_checksum_checking(self): """ Packet forwarding checking test """ self.dut.kill_all() all_cores_mask = dts.create_mask(self.dut.get_core_list("all")) core_mask = dts.create_mask(self.dut.get_core_list('1S/1C/1T', socket=self.ports_socket)) port_mask = dts.create_mask([self.dut_ports[0], self.dut_ports[1]]) for rxfreet_value in self.rxfreet_values: self.pmdout.start_testpmd("all", "--coremask=%s --portmask=%s --nb-cores=2 --enable-rx-cksum --disable-hw-vlan --disable-rss --crc-strip --rxd=1024 --txd=1024 --rxfreet=%d" % (core_mask, port_mask, rxfreet_value)) self.dut.send_expect("set fwd csum", "testpmd> ") self.dut.send_expect("start", "testpmd> ") self.send_packet(self.frame_sizes[0], checksum_test=True) l4csum_error = self.stop_and_get_l4csum_errors() # Check the l4 checksum errors reported for Rx port self.verify(1 == int(l4csum_error[1]), "Wrong l4 checksum error count using rxfreet=%d (expected 1, reported %s)" % (rxfreet_value, l4csum_error[1])) self.dut.send_expect("quit", "# ", 30) sleep(5) def test_packet_checking(self): """ Packet forwarding checking test """ self.dut.kill_all() all_cores_mask = dts.create_mask(self.dut.get_core_list("all")) core_mask = dts.create_mask(self.dut.get_core_list('1S/1C/1T', socket=self.ports_socket)) port_mask = dts.create_mask([self.dut_ports[0], self.dut_ports[1]]) self.pmdout.start_testpmd("all", "--coremask=%s --portmask=%s" % (core_mask, port_mask)) self.dut.send_expect("start", "testpmd> ") for size in self.frame_sizes: self.send_packet(size) self.dut.send_expect("stop", "testpmd> ") self.dut.send_expect("quit", "# ", 30) sleep(5) def stop_and_get_l4csum_errors(self): """ Stop forwarding and get Bad-l4csum number from stop statistic """ out = self.dut.send_expect("stop", "testpmd> ") result_scanner = r"Bad-l4csum: ([0-9]+) \s*" scanner = re.compile(result_scanner, re.DOTALL) m = scanner.findall(out) return m def get_stats(self, portid): """ Get packets number from port statistic """ stats = self.pmdout.get_pmd_stats(portid) return stats def send_packet(self, frame_size, checksum_test=False): """ Send 1 packet to portid """ port0_stats = self.get_stats(self.dut_ports[0]) gp0tx_pkts, gp0tx_bytes = [port0_stats['TX-packets'], port0_stats['TX-bytes']] port1_stats = self.get_stats(self.dut_ports[1]) gp1rx_pkts, gp1rx_err, gp1rx_bytes = [port1_stats['RX-packets'], port1_stats['RX-errors'], port1_stats['RX-bytes']] interface = self.tester.get_interface( self.tester.get_local_port(self.dut_ports[1])) mac = self.dut.get_mac_address(self.dut_ports[1]) load_size = frame_size - HEADER_SIZE['eth'] padding = frame_size - HEADER_SIZE['eth'] - HEADER_SIZE['ip'] - \ HEADER_SIZE['udp'] checksum = '' if checksum_test: checksum = 'chksum=0x0' self.tester.scapy_foreground() self.tester.scapy_append('nutmac="%s"' % mac) self.tester.scapy_append('sendp([Ether(dst=nutmac, src="52:00:00:00:00:00")/IP(len=%s)/UDP(%s)/Raw(load="\x50"*%s)], iface="%s")' % ( load_size, checksum, padding, interface)) out = self.tester.scapy_execute() time.sleep(.5) port0_stats = self.get_stats(self.dut_ports[0]) p0tx_pkts, p0tx_bytes = [port0_stats['TX-packets'], port0_stats['TX-bytes']] port1_stats = self.get_stats(self.dut_ports[1]) p1rx_pkts, p1rx_err, p1rx_bytes = [port1_stats['RX-packets'], port1_stats['RX-errors'], port1_stats['RX-bytes']] p0tx_pkts -= gp0tx_pkts p0tx_bytes -= gp0tx_bytes p1rx_pkts -= gp1rx_pkts p1rx_bytes -= gp1rx_bytes p1rx_err -= gp1rx_err time.sleep(5) self.verify(p0tx_pkts == p1rx_pkts, "packet pass assert error, %d RX packets, %d TX packets" % (p1rx_pkts, p0tx_pkts)) if checksum_test: self.verify(p1rx_bytes == frame_size - 4, "packet pass assert error, expected %d RX bytes, actual %d" % (frame_size - 4, p1rx_bytes)) else: self.verify(p1rx_bytes == frame_size, "packet pass assert error, expected %d RX bytes, actual %d" % (frame_size, p1rx_bytes)) self.verify(p0tx_bytes == frame_size, "packet pass assert error, expected %d TX bytes, actual %d" % (frame_size, p0tx_bytes)) return out def tear_down(self): """ Run after each test case. """ pass def tear_down_all(self): """ Run after each test suite. """ self.dut.kill_all()
class TestBlackList(TestCase): def set_up_all(self): """ Run at the start of each test suite. Blacklist Prerequisites. Requirements: Two Ports """ self.ports = self.dut.get_ports() self.verify(len(self.ports) >= 2, "Insufficient ports for testing") [arch, machine, self.env, toolchain] = self.target.split('-') if self.env == 'bsdapp': self.regexp_blacklisted_port = "EAL: PCI device 0000:%02x:%s on NUMA socket [-0-9]+[^\n]*\nEAL: probe driver[^\n]*\nEAL: Device is blacklisted, not initializing" else: self.regexp_blacklisted_port = "EAL: PCI device 0000:%s on NUMA socket [-0-9]+[^\n]*\nEAL: probe driver[^\n]*\nEAL: Device is blacklisted, not initializing" self.pmdout = PmdOutput(self.dut) def set_up(self): """ Run before each test case. Nothing to do. """ pass def check_blacklisted_ports(self, output, ports, blacklisted=False): """ Check if any of the ports in `ports` have been blacklisted, if so, raise exception. If `blacklisted` is True, then raise an exception if any of the ports in `ports` have not been blacklisted. """ for port in ports: # Look for the PCI ID of each card followed by # "Device is blacklisted, not initializing" but avoid to consume more # than one device. if self.env == 'bsdapp': pci = self.dut.ports_info[port]['pci'] regexp_blacklisted_port = self.regexp_blacklisted_port % (int(pci.split(':')[0], 16), pci.split(':')[1]) else: regexp_blacklisted_port = self.regexp_blacklisted_port % self.dut.ports_info[port]['pci'] matching_ports = dts.regexp(output, regexp_blacklisted_port, True) if blacklisted: self.verify(len(matching_ports) == 1, "Blacklisted port is being initialized") else: self.verify(len(matching_ports) == 0, "Not blacklisted port is being blacklisted") def test_bl_noblacklisted(self): """ Run testpmd with no blacklisted device. """ out = self.pmdout.start_testpmd("Default") rexp = r"Link" match_status = dts.regexp(out, rexp, True) self.check_blacklisted_ports(out, self.ports) def test_bl_oneportblacklisted(self): """ Run testpmd with one port blacklisted. """ self.dut.kill_all() out = self.pmdout.start_testpmd("Default", eal_param="-b 0000:%s -- -i" % self.dut.ports_info[0]['pci']) self.check_blacklisted_ports(out, self.ports[1:]) def test_bl_allbutoneportblacklisted(self): """ Run testpmd with all but one port blacklisted. """ self.dut.kill_all() ports_to_blacklist = self.ports[:-1] cmdline = "" for port in ports_to_blacklist: cmdline += " -b 0000:%s" % self.dut.ports_info[port]['pci'] out = self.pmdout.start_testpmd("Default", eal_param=cmdline) blacklisted_ports = self.check_blacklisted_ports(out, ports_to_blacklist, True) def tear_down(self): """ Run after each test case. Quit testpmd. """ self.dut.send_expect("quit", "# ", 10) def tear_down_all(self): """ Run after each test suite. Nothing to do. """ pass
class TestVlan(TestCase): def set_up_all(self): """ Run at the start of each test suite. Vlan Prerequistites """ # Based on h/w type, choose how many ports to use ports = self.dut.get_ports() # Verify that enough ports are available self.verify(len(ports) >= 2, "Insufficient ports") global valports valports = [_ for _ in ports if self.tester.get_local_port(_) != -1] portMask = dts.create_mask(valports[:2]) self.pmdout = PmdOutput(self.dut) self.pmdout.start_testpmd("all", "--portmask=%s" % portMask) self.dut.send_expect("set verbose 1", "testpmd> ") out = self.dut.send_expect("set fwd mac", "testpmd> ") self.dut.send_expect("vlan set strip off %s" % valports[0], "testpmd> ") self.verify('Set mac packet forwarding mode' in out, "set fwd rxonly error") def vlan_send_packet(self, vid, num=1): """ Send $num of packet to portid """ port = self.tester.get_local_port(valports[0]) txItf = self.tester.get_interface(port) port = self.tester.get_local_port(valports[1]) rxItf = self.tester.get_interface(port) mac = self.dut.get_mac_address(valports[0]) # FIXME send a burst with only num packet self.tester.scapy_background() self.tester.scapy_append('p=sniff(iface="%s",count=1,timeout=5)' % rxItf) self.tester.scapy_append('RESULT=str(p)') self.tester.scapy_foreground() self.tester.scapy_append('sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IP(len=46)], iface="%s")' % (mac, vid, txItf)) self.tester.scapy_execute() def set_up(self): """ Run before each test case. """ pass def test_vlan_enable_receipt(self): """ Enable receipt of VLAN packets """ self.dut.send_expect("set promisc all off", "testpmd> ") self.dut.send_expect("rx_vlan add 1 %s" % valports[0], "testpmd> ") self.dut.send_expect("start", "testpmd> ", 120) self.vlan_send_packet(1) out = self.tester.scapy_get_result() self.verify("vlan=1L" in out, "Wrong vlan:" + out) self.dut.send_expect("stop", "testpmd> ") def test_vlan_disable_receipt(self): """ Disable receipt of VLAN packets """ self.dut.send_expect("rx_vlan rm 1 %s" % valports[0], "testpmd> ") self.dut.send_expect("start", "testpmd> ", 120) self.vlan_send_packet(1) out = self.tester.scapy_get_result() self.verify("vlan=1L" not in out, "Wrong vlan:" + out) out = self.dut.send_expect("stop", "testpmd> ") def test_vlan_strip_config_on(self): """ Set vlan strip on """ self.dut.send_expect("vlan set strip on %s" % valports[0], "testpmd> ", 20) self.dut.send_expect("set promisc all off", "testpmd> ", 20) out = self.dut.send_expect("vlan set strip on %s" % valports[0], "testpmd> ", 20) self.verify("strip on" in out, "Wrong strip:" + out) self.dut.send_expect("start", "testpmd> ", 120) self.vlan_send_packet(1) out = self.tester.scapy_get_result() self.verify("vlan=1L" not in out, "Wrong vlan:" + out) out = self.dut.send_expect("quit", "#", 120) def test_vlan_strip_config_off(self): """ Set vlan strip off """ self.dut.send_expect("vlan set strip off %s" % valports[0], "testpmd> ", 20) out = self.dut.send_expect("show port info %s" % valports[0], "testpmd> ", 20) self.verify("strip off" in out, "Wrong strip:" + out) self.dut.send_expect("set nbport 2", "testpmd> ") self.dut.send_expect("start", "testpmd> ", 120) self.vlan_send_packet(1) out = self.tester.scapy_get_result() self.verify("vlan=1L" in out, "Wrong strip vlan:" + out) out = self.dut.send_expect("stop", "testpmd> ", 120) def FAILING_test_vlan_enable_vlan_insertion(self): """ Enable VLAN header insertion in transmitted packets """ port = self.tester.get_local_port(valports[0]) intf = self.tester.get_interface(port) self.dut.send_expect("set nbport 2", "testpmd> ") self.dut.send_expect("tx_vlan set 1 %s" % valports[0], "testpmd> ") self.dut.send_expect("set promisc all on", "testpmd> ") if self.nic == 'hartwell': self.dut.send_expect("vlan set strip on %s" % valports[0], "testpmd> ") self.tester.scapy_background() self.tester.scapy_append('p = sniff(iface="%s", count=1, timeout=5)' % intf) self.tester.scapy_append('RESULT=str(p)') self.tester.scapy_foreground() self.tester.scapy_execute() time.sleep(2) self.dut.send_expect("start tx_first", "testpmd> ") time.sleep(2) out = self.tester.scapy_get_result() self.verify("vlan=1L" in out, "Wrong vlan: " + out) self.dut.send_expect("quit", "# ", 30) def tear_down(self): """ Run after each test case. """ pass def tear_down_all(self): """ Run after each test suite. """ pass
class TestWhitelist(TestCase): def set_up_all(self): """ Run at the start of each test suite. Whitelist Prerequistites: Two Ports testpmd can normally started """ self.frames_to_send = 1 # Based on h/w type, choose how many ports to use self.dutPorts = self.dut.get_ports() # Verify that enough ports are available self.verify(len(self.dutPorts) >= 1, "Insufficient ports") portMask = dts.create_mask(self.dutPorts[:2]) self.pmdout = PmdOutput(self.dut) self.pmdout.start_testpmd("1S/2C/1T", "--portmask=%s" % portMask) self.dut.send_expect("set verbose 1", "testpmd> ") # get dest address from self.target port out = self.dut.send_expect("show port info %d" % self.dutPorts[0], "testpmd> ") self.dest = self.dut.get_mac_address(self.dutPorts[0]) mac_scanner = r"MAC address: (([\dA-F]{2}:){5}[\dA-F]{2})" ret = dts.regexp(out, mac_scanner) self.verify(ret is not None, "MAC address not found") self.verify(cmp(ret.lower(), self.dest) == 0, "MAC address wrong") self.max_mac_addr = dts.regexp(out, "Maximum number of MAC addresses: ([0-9]+)") def set_up(self): """ Run before each test case. Nothing to do. """ pass def whitelist_send_packet(self, portid, destMac="00:11:22:33:44:55"): """ Send 1 packet to portid. """ itf = self.tester.get_interface(self.tester.get_local_port(portid)) self.tester.scapy_foreground() self.tester.scapy_append('sendp([Ether(dst="%s", src="52:00:00:00:00:00")], iface="%s", count=%d)' % (destMac, itf, self.frames_to_send)) self.tester.scapy_execute() time.sleep(5) def test_whitelist_add_remove_mac_address(self): """ Add mac address and check packet can received Remove mac address and check packet can't received """ # initialise first port without promiscuous mode fake_mac_addr = "01:01:01:00:00:00" portid = self.dutPorts[0] self.dut.send_expect("set promisc %d off" % portid, "testpmd> ") out = self.dut.send_expect("show port stats %d" % portid, "testpmd> ") pre_rxpkt = dts.regexp(out, "RX-packets: ([0-9]+)") # send one packet with the portid MAC address self.whitelist_send_packet(portid, self.dest) out = self.dut.send_expect("show port stats %d" % portid, "testpmd> ") cur_rxpkt = dts.regexp(out, "RX-packets: ([0-9]+)") # check the packet increase self.verify(int(cur_rxpkt) == int(pre_rxpkt) + self.frames_to_send, "Packet has not been received on default address") # send one packet to a different MAC address # new_mac = self.dut.get_mac_address(portid) self.whitelist_send_packet(portid, fake_mac_addr) pre_rxpkt = cur_rxpkt out = self.dut.send_expect("show port stats %d" % portid, "testpmd> ") cur_rxpkt = dts.regexp(out, "RX-packets: ([0-9]+)") # check the packet DO NOT increase self.verify(int(cur_rxpkt) == int(pre_rxpkt), "Packet has been received on a new MAC address that has not been added yet") # add the different MAC address out = self.dut.send_expect("mac_addr add %d" % portid + " %s" % fake_mac_addr, "testpmd>") # send again one packet to a different MAC address self.whitelist_send_packet(portid, fake_mac_addr) pre_rxpkt = cur_rxpkt out = self.dut.send_expect("show port stats %d" % portid, "testpmd> ") cur_rxpkt = dts.regexp(out, "RX-packets: ([0-9]+)") # check the packet increase self.verify(int(cur_rxpkt) == int(pre_rxpkt) + self.frames_to_send, "Packet has not been received on a new MAC address that has been added to the port") # remove the fake MAC address out = self.dut.send_expect("mac_addr remove %d" % portid + " %s" % fake_mac_addr, "testpmd>") # send again one packet to a different MAC address self.whitelist_send_packet(portid, fake_mac_addr) pre_rxpkt = cur_rxpkt out = self.dut.send_expect("show port stats %d" % portid, "testpmd> ") cur_rxpkt = dts.regexp(out, "RX-packets: ([0-9]+)") # check the packet increase self.verify(int(cur_rxpkt) == int(pre_rxpkt), "Packet has been received on a new MAC address that has been removed from the port") self.dut.send_expect("stop", "testpmd> ") def test_whitelist_invalid_addresses(self): """ Invalid operation: Add NULL MAC should not be added Remove using MAC will be failed Add Same MAC twice will be failed Add more than MAX number will be failed """ portid = self.dutPorts[0] fake_mac_addr = "00:00:00:00:00:00" # add an address with all zeroes to the port (-EINVAL) out = self.dut.send_expect("mac_addr add %d" % portid + " %s" % fake_mac_addr, "testpmd>") self.verify("Invalid argument" in out, "Added a NULL MAC address") # remove the default MAC address (-EADDRINUSE) out = self.dut.send_expect("mac_addr remove %d" % portid + " %s" % self.dest, "testpmd>") self.verify("Address already in use" in out, "default address removed") # add same address 2 times fake_mac_addr = "00:00:00:00:00:01" out = self.dut.send_expect("mac_addr add %d" % portid + " %s" % fake_mac_addr, "testpmd>") out = self.dut.send_expect("mac_addr add %d" % portid + " %s" % fake_mac_addr, "testpmd>") self.verify("error" not in out, "added 2 times the same address with an error") # add 1 address more that max number i = 0 base_addr = "01:00:00:00:00:" while i <= int(self.max_mac_addr): new_addr = base_addr + "%0.2X" % i out = self.dut.send_expect("mac_addr add %d" % portid + " %s" % new_addr, "testpmd>") i = i + 1 self.verify("No space left on device" in out, "added 1 address more than max MAC addresses") def tear_down(self): """ Run after each test case. Nothing to do. """ pass def tear_down_all(self): """ Run after each test suite. """ self.dut.send_expect("quit", "# ", 10)
class Testddp_mpls(TestCase): def set_up_all(self): self.verify('fortville' in self.nic, 'ddp mpls can not support %s nic' % self.nic) self.dut_ports = self.dut.get_ports(self.nic) self.verify(len(self.dut_ports) >= 1, "Insufficient ports") self.vm0 = None self.env_done = False profile_file = r'dep/mpls.pkgo' profile_dst = "/tmp/" self.dut.session.copy_file_to(profile_file, profile_dst) def set_up(self): self.setup_vm_env() def bind_nic_driver(self, ports, driver=""): if driver == "igb_uio": for port in ports: netdev = self.dut.ports_info[port]['port'] driver = netdev.get_nic_driver() if driver != 'igb_uio': netdev.bind_driver(driver='igb_uio') else: for port in ports: netdev = self.dut.ports_info[port]['port'] driver_now = netdev.get_nic_driver() if driver == "": driver = netdev.default_driver if driver != driver_now: netdev.bind_driver(driver=driver) def setup_vm_env(self, driver='igb_uio'): """ Create testing environment with VF generated from 1PF """ if self.env_done == False: self.bind_nic_driver(self.dut_ports[:1], driver="igb_uio") self.used_dut_port = self.dut_ports[0] tester_port = self.tester.get_local_port(self.used_dut_port) self.tester_intf = self.tester.get_interface(tester_port) self.dut.generate_sriov_vfs_by_port(self.used_dut_port, 1, driver=driver) self.sriov_vfs_port = self.dut.ports_info[ self.used_dut_port]['vfs_port'] for port in self.sriov_vfs_port: port.bind_driver('pci-stub') time.sleep(1) self.dut_testpmd = PmdOutput(self.dut) time.sleep(1) vf0_prop = {'opt_host': self.sriov_vfs_port[0].pci} # set up VM0 ENV self.vm0 = QEMUKvm(self.dut, 'vm0', 'ddp_mpls') self.vm0.set_vm_device(driver='pci-assign', **vf0_prop) try: self.vm0_dut = self.vm0.start() if self.vm0_dut is None: raise Exception("Set up VM0 ENV failed!") except Exception as e: self.destroy_vm_env() raise Exception(e) self.vm0_dut_ports = self.vm0_dut.get_ports('any') self.vm0_testpmd = PmdOutput(self.vm0_dut) self.env_done = True self.dut_testpmd.start_testpmd( "Default", "--port-topology=chained --txq=%s --rxq=%s" % (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)) def destroy_vm_env(self): if getattr(self, 'vm0', None): self.vm0_dut.kill_all() self.vm0_testpmd = None self.vm0_dut_ports = None # destroy vm0 self.vm0.stop() self.vm0 = None if getattr(self, 'used_dut_port', None): self.dut.destroy_sriov_vfs_by_port(self.used_dut_port) port = self.dut.ports_info[self.used_dut_port]['port'] self.used_dut_port = None self.env_done = False def load_profile(self): """ Load profile to update FVL configuration tables, profile will be stored in binary file and need to be passed to AQ to program FVL during initialization stage. """ self.dut_testpmd.execute_cmd('port stop all') time.sleep(1) out = self.dut_testpmd.execute_cmd('ddp get list 0') self.verify("Profile number is: 0" in out, "Failed to get ddp profile info list!!!") self.dut_testpmd.execute_cmd('ddp add 0 /tmp/mpls.pkgo,/tmp/mpls.bak') out = self.dut_testpmd.execute_cmd('ddp get list 0') self.verify("Profile number is: 1" in out, "Failed to load ddp profile!!!") self.dut_testpmd.execute_cmd('port start all') time.sleep(1) def mpls_test(self, port='pf', pkt='udp'): """ Send mpls packet to dut, receive packet from configured queue. Input: port type, packet type """ pkts = [] if port == 'pf': queue = random.randint(1, PF_MAX_QUEUE - 1) self.dut_testpmd.execute_cmd('set fwd rxonly') self.dut_testpmd.execute_cmd('set verbose 1') self.dut_testpmd.execute_cmd('start') else: queue = random.randint(1, VF_MAX_QUEUE - 1) self.vm0_testpmd.execute_cmd('set fwd rxonly') self.vm0_testpmd.execute_cmd('set verbose 1') self.vm0_testpmd.execute_cmd('start') random_label = random.randint(0x0, 0xFFFFF) label = hex(random_label) wrong_label = hex((random_label + 2) % int(0xFFFFF)) self.dut_testpmd.execute_cmd('flow create 0 ingress pattern eth / ipv4\ / %s / mpls label is %s / end actions %s / queue index %d / end' % (pkt, label, port, queue)) for times in range(2): if pkt == 'udp': pkts = { 'mpls/good chksum udp': 'Ether()/IP()/UDP(dport=6635)\ /MPLS(label=%s)/Ether()/IP()/TCP()' % label, 'mpls/bad chksum udp': 'Ether()/IP()/UDP(chksum=0x1234,\ dport=6635)/MPLS(label=%s)/Ether()/IP()/TCP()' % label } else: pkts = { 'mpls/good chksum gre': 'Ether()/IP(proto=47)/GRE(proto=0x8847)\ /MPLS(label=%s)/Ether()/IP()/UDP()' % label, 'mpls/bad chksum gre': 'Ether()/IP(proto=47)/GRE(chksum=0x1234,\ proto=0x8847)/MPLS(label=%s)/Ether()/IP()/UDP()' % label } for packet_type in pkts.keys(): self.tester.scapy_append('sendp([%s], iface="%s")' % (pkts[packet_type], self.tester_intf)) self.tester.scapy_execute() if port == 'pf': out = self.dut.get_session_output(timeout=2) else: out = self.vm0_dut.get_session_output(timeout=2) self.verify("port 0/queue %d" % queue in out, "Failed to receive packet in this queue!!!") self.verify("PKT_RX_L4_CKSUM_GOOD" in out, "Failed to check CKSUM!!!") label = wrong_label queue = 0 def test_load_ddp(self): """ Load profile to update FVL configuration tables. """ self.load_profile() def test_mpls_udp_pf(self): """ MPLS is supported by NVM with profile updated. Send mpls udp packet to PF, check PF could receive packet using configured queue, checksum is good. """ self.load_profile() self.mpls_test(port='pf', pkt='udp') def test_mpls_gre_pf(self): """ MPLS is supported by NVM with profile updated. Send mpls gre packet to PF, check PF could receive packet using configured queue, checksum is good. """ self.load_profile() self.mpls_test(port='pf', pkt='gre') def test_mpls_udp_vf(self): """ MPLS is supported by NVM with profile updated. Send mpls udp packet to VF, check VF could receive packet using configured queue, checksum is good. """ self.load_profile() self.mpls_test(port='vf id 0', pkt='udp') def test_mpls_gre_vf(self): """ MPLS is supported by NVM with profile updated. Send mpls gre packet to VF, check VF could receive packet using configured queue, checksum is good. """ self.load_profile() self.mpls_test(port='vf id 0', pkt='gre') def tear_down(self): self.vm0_testpmd.execute_cmd('stop') self.dut_testpmd.execute_cmd('stop') out = self.dut_testpmd.execute_cmd('ddp get list 0') if "Profile number is: 0" not in out: self.dut_testpmd.execute_cmd('port stop all') time.sleep(1) self.dut_testpmd.execute_cmd('ddp del 0 /tmp/mpls.bak') out = self.dut_testpmd.execute_cmd('ddp get list 0') self.verify("Profile number is: 0" in out, "Failed to delete mpls profile!!!") self.dut_testpmd.execute_cmd('port start all') self.vm0_testpmd.quit() self.dut_testpmd.quit() def tear_down_all(self): self.destroy_vm_env() pass
class TestLinkFlowctrl(TestCase): pause_frame_dst = "01:80:C2:00:00:01" pause_frame_type = "0x8808" pause_frame_opcode = "\\x00\\x01" pause_frame_control = "\\x00\\xFF" pause_frame_paddign = "\\x00" * 42 pause_frame = '[Ether(src="%s",dst="%s",type=%s)/("%s%s%s")]' frames_to_sent = 10 packet_size = 66 # 66 allows frame loss payload_size = packet_size - HEADER_SIZE['eth'] - HEADER_SIZE[ 'ip'] - HEADER_SIZE['udp'] def set_up_all(self): """ Run at the start of each test suite. Link flow control Prerequisites """ self.dutPorts = self.dut.get_ports() self.verify(len(self.dutPorts) > 1, "Insuficient ports") self.rx_port = self.dutPorts[0] self.tester_tx_mac = self.tester.get_mac( self.tester.get_local_port(self.rx_port)) self.tx_port = self.dutPorts[1] self.portMask = utils.create_mask([self.rx_port, self.tx_port]) self.memChannels = self.dut.get_memory_channels() self.pmdout = PmdOutput(self.dut) self.pmdout.start_testpmd("all", "--portmask=%s" % self.portMask) def pause_frame_loss_test(self, rx_flow_control='off', tx_flow_control='off', pause_frame_fwd='off'): tester_tx_port = self.tester.get_local_port(self.rx_port) tester_rx_port = self.tester.get_local_port(self.tx_port) tgenInput = [] tgenInput.append((tester_tx_port, tester_rx_port, "test.pcap")) self.dut.send_expect( "set flow_ctrl rx %s tx %s 300 50 10 1 mac_ctrl_frame_fwd %s autoneg on %d " % (rx_flow_control, tx_flow_control, pause_frame_fwd, self.rx_port), "testpmd> ") self.dut.send_expect("set fwd csum", "testpmd> ") self.dut.send_expect("start", "testpmd> ") self.tester.scapy_append( 'wrpcap("test.pcap",[Ether()/IP()/UDP()/("X"*%d)])' % TestLinkFlowctrl.payload_size) self.tester.scapy_execute() # Run traffic generator result = self.tester.traffic_generator_loss(tgenInput, 100) self.dut.send_expect("stop", "testpmd> ") return result def get_testpmd_port_stats(self, ports): """ Returns the number of packets transmitted and received from testpmd. Uses testpmd show port stats. """ rx_pattern = "RX-packets: (\d*)" tx_pattern = "TX-packets: (\d*)" rx = re.compile(rx_pattern) tx = re.compile(tx_pattern) port_stats = {} for port in ports: out = self.dut.send_expect("show port stats %d" % port, "testpmd> ") rx_packets = int(rx.search(out).group(1)) tx_packets = int(tx.search(out).group(1)) port_stats[port] = (rx_packets, tx_packets) return port_stats def pause_frame_test(self, frame, flow_control='off', pause_frame_fwd='off'): """ Sets testpmd flow control and mac ctrl frame fwd according to the parameters, starts forwarding and clears the stats, then sends the passed frame and stops forwarding. Returns the testpmd port stats. """ tester_tx_port = self.tester.get_local_port(self.rx_port) tx_interface = self.tester.get_interface(tester_tx_port) tester_rx_port = self.tester.get_local_port(self.tx_port) tgenInput = [] tgenInput.append((tester_tx_port, tester_rx_port, "test.pcap")) self.dut.send_expect( "set flow_ctrl rx %s tx %s 300 50 10 1 mac_ctrl_frame_fwd %s autoneg %s %d " % (flow_control, flow_control, pause_frame_fwd, flow_control, self.rx_port), "testpmd> ") self.dut.send_expect("set fwd io", "testpmd> ") self.dut.send_expect("start", "testpmd> ") self.dut.send_expect("clear port stats all", "testpmd> ") self.tester.scapy_foreground() self.tester.scapy_append( 'sendp(%s, iface="%s", count=%d)' % (frame, tx_interface, TestLinkFlowctrl.frames_to_sent)) self.tester.scapy_execute() # The following sleep is needed to allow all the packets to arrive. # 1s works for Crown Pass (FC18) DUT, Lizard Head Pass (FC14) tester # using Niantic. Increase it in case of packet loosing. sleep(1) self.dut.send_expect("stop", "testpmd> ") port_stats = self.get_testpmd_port_stats((self.rx_port, self.tx_port)) return port_stats def check_pause_frame_test_result(self, result, expected_rx=False, expected_fwd=False): """ Verifies the test results (use pause_frame_test before) against the expected behavior. """ print "Result (port, rx, tx) %s, expected rx %s, expected fwd %s" % ( result, expected_rx, expected_fwd) if expected_rx: self.verify( result[self.rx_port][0] == TestLinkFlowctrl.frames_to_sent, "Pause Frames are not being received by testpmd (%d received)" % result[self.rx_port][0]) if expected_fwd: self.verify( result[self.tx_port][1] == TestLinkFlowctrl.frames_to_sent, "Pause Frames are not being forwarded by testpmd (%d sent)" % (result[self.tx_port][1])) else: self.verify( result[self.tx_port][1] == 0, "Pause Frames are being forwarded by testpmd (%d sent)" % (result[self.tx_port][1])) else: self.verify( result[self.rx_port][0] == 0, "Pause Frames are being received by testpmd (%d received)" % result[self.rx_port][0]) def build_pause_frame(self, option=0): """ Build the PAUSE Frame for the tests. 3 available options: 0: Correct frame (correct src and dst addresses and opcode) 1: Wrong source frame (worng src, correct and dst address and opcode) 2: Wrong opcode frame (correct src and dst address and wrong opcode) 3: Wrong destination frame (correct src and opcode, wrong dst address) """ if option == 1: return TestLinkFlowctrl.pause_frame % ( "00:01:02:03:04:05", TestLinkFlowctrl.pause_frame_dst, TestLinkFlowctrl.pause_frame_type, TestLinkFlowctrl.pause_frame_opcode, TestLinkFlowctrl.pause_frame_control, TestLinkFlowctrl.pause_frame_paddign) elif option == 2: return TestLinkFlowctrl.pause_frame % ( self.tester_tx_mac, TestLinkFlowctrl.pause_frame_dst, TestLinkFlowctrl.pause_frame_type, "\\x00\\x02", TestLinkFlowctrl.pause_frame_control, TestLinkFlowctrl.pause_frame_paddign) elif option == 3: return TestLinkFlowctrl.pause_frame % ( self.tester_tx_mac, "01:80:C2:00:AB:10", TestLinkFlowctrl.pause_frame_type, TestLinkFlowctrl.pause_frame_opcode, TestLinkFlowctrl.pause_frame_control, TestLinkFlowctrl.pause_frame_paddign) return TestLinkFlowctrl.pause_frame % ( self.tester_tx_mac, TestLinkFlowctrl.pause_frame_dst, TestLinkFlowctrl.pause_frame_type, TestLinkFlowctrl.pause_frame_opcode, TestLinkFlowctrl.pause_frame_control, TestLinkFlowctrl.pause_frame_paddign) def test_flowctrl_off_pause_fwd_off(self): """ Flow control disabled, MAC PAUSE frame forwarding disabled. PAUSE Frames must not be received by testpmd """ pause_frames = [ self.build_pause_frame(0), self.build_pause_frame(1), self.build_pause_frame(2), self.build_pause_frame(3) ] for frame in pause_frames: port_stats = self.pause_frame_test(frame) self.check_pause_frame_test_result(port_stats) def test_flowctrl_on_pause_fwd_off(self): """ Flow control enabled, MAC PAUSE frame forwarding disabled. PAUSE Frames must not be received by testpmd """ pause_frames = [ self.build_pause_frame(0), self.build_pause_frame(1), self.build_pause_frame(2), self.build_pause_frame(3) ] for frame in pause_frames: port_stats = self.pause_frame_test(frame, flow_control='on') self.check_pause_frame_test_result(port_stats) def test_flowctrl_off_pause_fwd_on(self): """ Flow control disabled, MAC PAUSE frame forwarding enabled. All PAUSE Frames must be forwarded by testpmd. """ # Regular frames, check for no frames received pause_frame = self.build_pause_frame() port_stats = self.pause_frame_test(pause_frame, pause_frame_fwd='on') self.check_pause_frame_test_result(port_stats, True, True) # Wrong src MAC, check for no frames received pause_frame = self.build_pause_frame(1) port_stats = self.pause_frame_test(pause_frame, pause_frame_fwd='on') self.check_pause_frame_test_result(port_stats, True, True) # Unrecognized frames (wrong opcode), check for all frames received and fwd pause_frame = self.build_pause_frame(2) port_stats = self.pause_frame_test(pause_frame, pause_frame_fwd='on') self.check_pause_frame_test_result(port_stats, True, True) # Wrong dst MAC, check for all frames received pause_frame = self.build_pause_frame(3) port_stats = self.pause_frame_test(pause_frame, pause_frame_fwd='on') self.check_pause_frame_test_result(port_stats, True, True) def test_flowctrl_on_pause_fwd_on(self): """ Flow control enabled, MAC PAUSE frame forwarding enabled. Only unrecognized PAUSE Frames must be forwarded by testpmd. """ # Regular frames, check for no frames received pause_frame = self.build_pause_frame() port_stats = self.pause_frame_test(pause_frame, flow_control='on', pause_frame_fwd='on') self.check_pause_frame_test_result(port_stats) # Wrong src MAC, check for no frames received pause_frame = self.build_pause_frame(1) port_stats = self.pause_frame_test(pause_frame, flow_control='on', pause_frame_fwd='on') self.check_pause_frame_test_result(port_stats) # Unrecognized frames (wrong opcode), check for all frames received and fwd pause_frame = self.build_pause_frame(2) port_stats = self.pause_frame_test(pause_frame, flow_control='on', pause_frame_fwd='on') self.check_pause_frame_test_result(port_stats, True, True) # Wrong dst MAC, check for all frames received pause_frame = self.build_pause_frame(3) port_stats = self.pause_frame_test(pause_frame, flow_control='on', pause_frame_fwd='on') self.check_pause_frame_test_result(port_stats, True, True) def test_perf_flowctrl_on_pause_fwd_on(self): """ Disable link flow control and PAUSE frame forwarding """ result = self.pause_frame_loss_test(rx_flow_control='on', tx_flow_control='on', pause_frame_fwd='on') print "Packet loss: %.3f%%" % result self.verify( result <= 0.01, "Link flow control fail, the loss percent is more than 1%") def test_perf_flowctrl_on_pause_fwd_off(self): """ Disable link flow control and enable PAUSE frame forwarding """ result = self.pause_frame_loss_test(rx_flow_control='on', tx_flow_control='on', pause_frame_fwd='off') print "Packet loss: %.3f%%" % result self.verify( result <= 0.01, "Link flow control fail, the loss percent is more than 1%") def test_perf_flowctrl_rx_on(self): """ Enable only rx link flow control """ result = self.pause_frame_loss_test(rx_flow_control='on', tx_flow_control='on', pause_frame_fwd='off') print "Packet loss: %.3f%%" % result self.verify( result <= 0.01, "Link flow control fail, the loss percent is more than 1%") def test_perf_flowctrl_off_pause_fwd_on(self): """ Enable link flow control and disable PAUSE frame forwarding """ result = self.pause_frame_loss_test(rx_flow_control='off', tx_flow_control='off', pause_frame_fwd='on') print "Packet loss: %.3f%%" % result self.verify( result >= 0.5, "Link flow control fail, the loss percent is less than 50%") def test_perf_flowctrl_off_pause_fwd_off(self): """ Disable link flow control and PAUSE frame forwarding """ result = self.pause_frame_loss_test(rx_flow_control='off', tx_flow_control='off', pause_frame_fwd='off') print "Packet loss: %.3f%%" % result self.verify( result >= 0.5, "Link flow control fail, the loss percent is less than 50%") def test_perf_flowctrl_tx_on(self): """ Disable link flow control and PAUSE frame forwarding """ result = self.pause_frame_loss_test(rx_flow_control='off', tx_flow_control='on', pause_frame_fwd='off') print "Packet loss: %.3f%%" % result self.verify( result <= 0.01, "Link flow control fail, the loss percent is more than 1%") def tear_down_all(self): """ Run after each test case. """ self.dut.send_expect("quit", "# ")
class TestShutdownApi(TestCase): # # # # Test cases. # def set_up_all(self): """ Run at the start of each test suite. """ ports = self.dut.get_ports() self.verify(len(ports) >= 1, "Insufficient number of ports.") self.ports = ports[:1] self.ports_socket = self.dut.get_numa_id(self.ports[0]) for port in self.ports: self.tester.send_expect( "ifconfig %s mtu %s" % (self.tester.get_interface( self.tester.get_local_port(port)), 5000), "# ") self.pmdout = PmdOutput(self.dut) def get_stats(self, portid): """ Get packets number from port statistic. @param: stop -- stop forward before get stats """ output = PmdOutput(self.dut) stats = output.get_pmd_stats(portid) return stats def check_forwarding(self, ports=None, pktSize=68, received=True, vlan=False, promisc=False, vlan_strip=False): if ports is None: ports = self.ports if len(ports) == 1: self.send_packet(ports[0], ports[0], pktSize, received, vlan, promisc, vlan_strip) return def send_packet(self, txPort, rxPort, pktSize=68, received=True, vlan=False, promisc=False, vlan_strip=False): """ Send packages according to parameters. """ port0_stats = self.get_stats(txPort) gp0tx_pkts, gp0tx_bytes = [ port0_stats['TX-packets'], port0_stats['TX-bytes'] ] port1_stats = self.get_stats(rxPort) gp1rx_pkts, gp1rx_err, gp1rx_bytes = [ port1_stats['RX-packets'], port1_stats['RX-errors'], port1_stats['RX-bytes'] ] time.sleep(5) itf = self.tester.get_interface(self.tester.get_local_port(rxPort)) smac = self.tester.get_mac(self.tester.get_local_port(rxPort)) dmac = self.dut.get_mac_address(rxPort) # when promisc is true, destination mac should be fake if promisc: dmac = "00:00:00:00:00:01" if vlan: padding = pktSize - HEADER_SIZE['eth'] - HEADER_SIZE['ip'] - 4 pkg = 'Ether(src="%s", dst="%s")/Dot1Q(vlan=1)/IP()/Raw(load="P" * %d)' % ( smac, dmac, padding) else: padding = pktSize - HEADER_SIZE['eth'] - HEADER_SIZE['ip'] pkg = 'Ether(src="%s", dst="%s")/IP()/Raw(load="P" * %d)' % ( smac, dmac, padding) self.tester.scapy_foreground() self.tester.scapy_append('sendp(%s, iface="%s")' % (pkg, itf)) self.tester.scapy_execute() time.sleep(3) port0_stats = self.get_stats(txPort) p0tx_pkts, p0tx_bytes = [ port0_stats['TX-packets'], port0_stats['TX-bytes'] ] port1_stats = self.get_stats(rxPort) p1rx_pkts, p1rx_err, p1rx_bytes = [ port1_stats['RX-packets'], port1_stats['RX-errors'], port1_stats['RX-bytes'] ] time.sleep(5) p0tx_pkts -= gp0tx_pkts p0tx_bytes -= gp0tx_bytes p1rx_pkts -= gp1rx_pkts p1rx_bytes -= gp1rx_bytes rx_bytes_exp = pktSize tx_bytes_exp = pktSize if self.kdriver == "fm10k": # RRC will always strip rx/tx crc rx_bytes_exp -= 4 tx_bytes_exp -= 4 if vlan_strip is True: # RRC will always strip rx/tx vlan rx_bytes_exp -= 4 tx_bytes_exp -= 4 else: # some NIC will always include tx crc rx_bytes_exp -= 4 tx_bytes_exp -= 4 if vlan_strip is True: # vlan strip default is off tx_bytes_exp -= 4 # fortville nic enable send lldp packet function when port setup # now the tx-packets size is lldp_size(110) * n + forward packe size # so use (tx-packets - forward packet size) % lldp_size, if it is 0, it means forward packet size right if received: self.verify( self.pmdout.check_tx_bytes(p0tx_pkts, p1rx_pkts), "Wrong TX pkts p0_tx=%d, p1_rx=%d" % (p0tx_pkts, p1rx_pkts)) self.verify( p1rx_bytes == rx_bytes_exp, "Wrong Rx bytes p1_rx=%d, expect=%d" % (p1rx_bytes, rx_bytes_exp)) self.verify( self.pmdout.check_tx_bytes(p0tx_bytes, tx_bytes_exp), "Wrong Tx bytes p0_tx=%d, expect=%d" % (p0tx_bytes, tx_bytes_exp)) else: self.verify(self.pmdout.check_tx_bytes(p0tx_pkts), "Packet not dropped p0tx_pkts=%d" % p0tx_pkts) def check_ports(self, status=True): """ Check link status of the ports. """ # RRC not support link speed change if self.kdriver == "fm10k": return for port in self.ports: out = self.tester.send_expect( "ethtool %s" % self.tester.get_interface(self.tester.get_local_port(port)), "# ") if status: self.verify("Link detected: yes" in out, "Wrong link status") else: self.verify("Link detected: no" in out, "Wrong link status") def set_up(self): """ Run before each test case. """ pass def test_stop_restart(self): """ Stop and Restar. """ self.pmdout.start_testpmd("Default", "--portmask=%s --port-topology=loop" % utils.create_mask(self.ports), socket=self.ports_socket) self.dut.send_expect("set fwd mac", "testpmd>") self.dut.send_expect("start", "testpmd> ") self.check_forwarding() self.dut.send_expect("stop", "testpmd> ") self.check_forwarding(received=False) self.dut.send_expect("port stop all", "testpmd> ", 100) time.sleep(5) self.check_ports(status=False) self.dut.send_expect("port start all", "testpmd> ", 100) time.sleep(5) self.check_ports(status=True) self.dut.send_expect("start", "testpmd> ") self.check_forwarding() def test_set_promiscuousmode(self): """ Promiscuous mode. """ ports = [self.ports[0]] portmask = utils.create_mask(ports) self.pmdout.start_testpmd("Default", "--portmask=%s --port-topology=loop" % portmask, socket=self.ports_socket) self.dut.send_expect("port stop all", "testpmd> ", 100) self.dut.send_expect("set promisc all off", "testpmd> ") self.dut.send_expect("port start all", "testpmd> ", 100) self.dut.send_expect("show config rxtx", "testpmd> ") self.dut.send_expect("start", "testpmd> ") try: self.check_forwarding(ports) except VerifyFailure as e: print 'promiscuous mode is working correctly' except Exception as e: print " !!! DEBUG IT: " + e.message self.verify(False, e.message) self.dut.send_expect("port stop all", "testpmd> ", 100) self.dut.send_expect("set promisc all on", "testpmd> ") self.dut.send_expect("port start all", "testpmd> ", 100) self.dut.send_expect("show config rxtx", "testpmd> ") self.dut.send_expect("start", "testpmd> ") self.check_forwarding(ports, promisc=True) self.dut.send_expect("port stop all", "testpmd> ", 100) self.dut.send_expect("set promisc all off", "testpmd> ") self.dut.send_expect("start", "testpmd> ") self.dut.send_expect("quit", "# ", 30) def test_reset_queues(self): """ Reset RX/TX Queues. """ testcorelist = self.dut.get_core_list("1S/8C/1T", socket=self.ports_socket) self.pmdout.start_testpmd(testcorelist, "--portmask=%s --port-topology=loop" % utils.create_mask([self.ports[0]]), socket=self.ports_socket) fwdcoremask = utils.create_mask(testcorelist[-3:]) self.dut.send_expect("port stop all", "testpmd> ", 100) self.dut.send_expect("port config all rxq 2", "testpmd> ") self.dut.send_expect("port config all txq 2", "testpmd> ") self.dut.send_expect("set coremask %s" % fwdcoremask, "testpmd> ") self.dut.send_expect("set fwd mac", "testpmd>") self.dut.send_expect("port start all", "testpmd> ", 100) out = self.dut.send_expect("show config rxtx", "testpmd> ") self.verify("RX queue number: 2" in out, "RX queues not reconfigured properly") self.verify("Tx queue number: 2" in out, "TX queues not reconfigured properly") self.dut.send_expect("start", "testpmd> ") self.check_forwarding() self.dut.send_expect("quit", "# ", 30) def test_reconfigure_ports(self): """ Reconfigure All Ports With The Same Configurations (CRC) """ RX_OFFLOAD_KEEP_CRC = 0x10000 self.pmdout.start_testpmd( "Default", "--portmask=%s --port-topology=loop --disable-crc-strip" % utils.create_mask(self.ports), socket=self.ports_socket) out = self.dut.send_expect("show config rxtx", "testpmd> ") Rx_offloads = re.compile('Rx offloads=(.*?)\s+?').findall(out, re.S) crc_keep_temp = [] for i in range(len(self.dut.get_ports())): crc_keep_temp.append(int(Rx_offloads[i], 16) & RX_OFFLOAD_KEEP_CRC) crc_keep = crc_keep_temp[0] crc_keep = crc_keep and crc_keep_temp[i] self.verify(crc_keep == RX_OFFLOAD_KEEP_CRC, "CRC keeping not enabled properly") self.dut.send_expect("port stop all", "testpmd> ", 100) self.dut.send_expect("port config all crc-strip on", "testpmd> ") self.dut.send_expect("set fwd mac", "testpmd>") self.dut.send_expect("port start all", "testpmd> ", 100) out = self.dut.send_expect("show config rxtx", "testpmd> ") Rx_offloads = re.compile('Rx offloads=(.*?)\s+?').findall(out, re.S) crc_strip_temp = [] for i in range(len(self.dut.get_ports())): crc_strip_temp.append( int(Rx_offloads[i], 16) | ~RX_OFFLOAD_KEEP_CRC) crc_strip = crc_strip_temp[0] crc_strip = crc_strip and crc_strip_temp[i] self.verify(crc_strip == ~RX_OFFLOAD_KEEP_CRC, "CRC stripping not enabled properly") self.dut.send_expect("start", "testpmd> ") self.check_forwarding() def test_change_linkspeed(self): """ Change Link Speed. """ if self.kdriver == "fm10k": print utils.RED("RRC not support\n") return self.pmdout.start_testpmd("Default", "--portmask=%s --port-topology=loop" % utils.create_mask(self.ports), socket=self.ports_socket) out = self.tester.send_expect( "ethtool %s" % self.tester.get_interface( self.tester.get_local_port(self.ports[0])), "# ") if 'fortville_spirit' == self.nic: result_scanner = r"([0-9]+)baseSR4/([A-Za-z]+)" else: result_scanner = r"([0-9]+)baseT/([A-Za-z]+)" scanner = re.compile(result_scanner, re.DOTALL) m = scanner.findall(out) configs = m[:-(len(m) / 2)] for config in configs: print config if self.nic in ["ironpond"]: if config[0] != '1000' or '10000': continue elif self.nic in ["fortville_eagle"]: if config[0] != '10000': continue elif self.nic in ["sagepond"]: if config[0] != '1000' and '10000': continue self.dut.send_expect("port stop all", "testpmd> ", 100) for port in self.ports: self.dut.send_expect( "port config %d speed %s duplex %s" % (port, config[0], config[1].lower()), "testpmd> ") self.dut.send_expect("set fwd mac", "testpmd>") self.dut.send_expect("port start all", "testpmd> ", 100) time.sleep(5) # sleep few seconds for link stable for port in self.ports: out = self.tester.send_expect( "ethtool %s" % self.tester.get_interface( self.tester.get_local_port(port)), "# ") self.verify("Speed: %s" % config[0] in out, "Wrong speed reported by the self.tester.") self.verify("Duplex: %s" % config[1] in out, "Wrong link type reported by the self.tester.") self.dut.send_expect("start", "testpmd> ") self.check_forwarding() self.dut.send_expect("stop", "testpmd> ") def test_enable_disablejumbo(self): """ Enable/Disable Jumbo Frames. """ if self.kdriver == "fm10k": print utils.RED("RRC not support\n") return jumbo_size = 2048 self.pmdout.start_testpmd("Default", "--portmask=%s --port-topology=loop" % utils.create_mask(self.ports), socket=self.ports_socket) self.dut.send_expect("port stop all", "testpmd> ", 100) self.dut.send_expect("port config all max-pkt-len %d" % jumbo_size, "testpmd> ") out = self.dut.send_expect("vlan set strip off all", "testpmd> ") if "fail" not in out: for port in self.ports: self.dut.send_expect("vlan set filter on %d" % port, "testpmd> ") self.dut.send_expect("rx_vlan add 1 %d" % port, "testpmd> ") self.dut.send_expect("set fwd mac", "testpmd>") self.dut.send_expect("port start all", "testpmd> ", 100) self.dut.send_expect("start", "testpmd> ") if self.nic in [ 'magnolia_park', 'niantic', 'twinpond', 'kawela_4', 'ironpond', 'springfountain', 'springville', 'powerville', 'sageville', 'sagepond' ]: # nantic vlan length will not be calculated vlan_jumbo_size = jumbo_size + 4 else: vlan_jumbo_size = jumbo_size out = self.dut.send_expect("show port cap %d" % port, "testpmd> ") state = re.findall("VLAN stripped:\s*([a-z]*)", out) if state[0] == 'on': vlan_strip = True else: vlan_strip = False self.check_forwarding(pktSize=vlan_jumbo_size - 1, vlan=True, vlan_strip=vlan_strip) self.check_forwarding(pktSize=vlan_jumbo_size, vlan=True, vlan_strip=vlan_strip) self.check_forwarding(pktSize=vlan_jumbo_size + 1, received=False, vlan=True, vlan_strip=vlan_strip) self.dut.send_expect("stop", "testpmd> ") self.dut.send_expect("port stop all", "testpmd> ", 100) self.dut.send_expect("port config all hw-vlan off", "testpmd> ") self.dut.send_expect("port start all", "testpmd> ", 100) self.dut.send_expect("start", "testpmd> ") """ On 1G NICs, when the jubmo frame MTU set as X, the software adjust it to (X + 4). """ if self.nic in ["powerville", "springville", "kawela_4"]: jumbo_size += 4 self.check_forwarding(pktSize=jumbo_size - 1) self.check_forwarding(pktSize=jumbo_size) self.check_forwarding(pktSize=jumbo_size + 1, received=False) def test_enable_disablerss(self): """ Enable/Disable RSS. """ self.pmdout.start_testpmd("Default", "--portmask=%s --port-topology=loop" % utils.create_mask(self.ports), socket=self.ports_socket) self.dut.send_expect("port stop all", "testpmd> ", 100) self.dut.send_expect("port config rss ip", "testpmd> ") self.dut.send_expect("set fwd mac", "testpmd>") self.dut.send_expect("port start all", "testpmd> ", 100) self.dut.send_expect("start", "testpmd> ") self.check_forwarding() def test_change_numberrxdtxd(self): """ Change numbers of rxd and txd. """ self.pmdout.start_testpmd("Default", "--portmask=%s --port-topology=loop" % utils.create_mask(self.ports), socket=self.ports_socket) self.dut.send_expect("port stop all", "testpmd> ", 100) self.dut.send_expect("port config all rxd 1024", "testpmd> ") self.dut.send_expect("port config all txd 1024", "testpmd> ") self.dut.send_expect("set fwd mac", "testpmd>") self.dut.send_expect("port start all", "testpmd> ", 100) out = self.dut.send_expect("show config rxtx", "testpmd> ") self.verify("RX desc=1024" in out, "RX descriptor not reconfigured properly") self.verify("TX desc=1024" in out, "TX descriptor not reconfigured properly") self.dut.send_expect("start", "testpmd> ") self.check_forwarding() def test_change_numberrxdtxdaftercycle(self): """ Change the Number of rxd/txd. """ self.pmdout.start_testpmd("Default", "--portmask=%s --port-topology=loop" % utils.create_mask(self.ports), socket=self.ports_socket) self.dut.send_expect("port stop all", "testpmd> ", 100) self.dut.send_expect("port config all rxd 1024", "testpmd> ") self.dut.send_expect("port config all txd 1024", "testpmd> ") self.dut.send_expect("set fwd mac", "testpmd>") self.dut.send_expect("port start all", "testpmd> ", 100) out = self.dut.send_expect("show config rxtx", "testpmd> ") self.verify("RX desc=1024" in out, "RX descriptor not reconfigured properly") self.verify("TX desc=1024" in out, "TX descriptor not reconfigured properly") self.dut.send_expect("start", "testpmd> ") self.check_forwarding() self.dut.send_expect("stop", "testpmd> ") self.dut.send_expect("port stop all", "testpmd> ", 100) self.dut.send_expect("port start all", "testpmd> ", 100) out = self.dut.send_expect("show config rxtx", "testpmd> ") self.verify("RX desc=1024" in out, "RX descriptor not reconfigured properly") self.verify("TX desc=1024" in out, "TX descriptor not reconfigured properly") self.dut.send_expect("start", "testpmd> ") self.check_forwarding() def test_change_thresholds(self): """ Change RX/TX thresholds """ self.pmdout.start_testpmd("Default", "--portmask=%s --port-topology=loop" % utils.create_mask(self.ports), socket=self.ports_socket) self.dut.send_expect("port stop all", "testpmd> ", 100) self.dut.send_expect("port config all txfreet 32", "testpmd> ") self.dut.send_expect("port config all txrst 32", "testpmd> ") self.dut.send_expect("port config all rxfreet 32", "testpmd> ") self.dut.send_expect("port config all txpt 64", "testpmd> ") self.dut.send_expect("port config all txht 64", "testpmd> ") self.dut.send_expect("port config all txwt 0", "testpmd> ") self.dut.send_expect("port config all rxpt 64", "testpmd> ") self.dut.send_expect("port config all rxht 64", "testpmd> ") self.dut.send_expect("port config all rxwt 64", "testpmd> ") self.dut.send_expect("port start all", "testpmd> ", 100) out = self.dut.send_expect("show config rxtx", "testpmd> ") self.verify("RX free threshold=32" in out, "RX descriptor not reconfigured properly") self.verify("TX free threshold=32" in out, "TX descriptor not reconfigured properly") self.verify("TX RS bit threshold=32" in out, "TX descriptor not reconfigured properly") self.verify("pthresh=64" in out, "TX descriptor not reconfigured properly") self.verify("hthresh=64" in out, "TX descriptor not reconfigured properly") self.verify("wthresh=64" in out, "TX descriptor not reconfigured properly") self.verify("pthresh=64" in out, "TX descriptor not reconfigured properly") self.verify("hthresh=64" in out, "TX descriptor not reconfigured properly") self.verify("wthresh=64" in out, "TX descriptor not reconfigured properly") self.dut.send_expect("set fwd mac", "testpmd>") self.dut.send_expect("start", "testpmd> ") self.check_forwarding() def test_stress_test(self): """ Start/stop stress test. """ stress_iterations = 10 self.pmdout.start_testpmd("Default", "--portmask=%s --port-topology=loop" % utils.create_mask(self.ports), socket=self.ports_socket) tgenInput = [] for port in self.ports: dmac = self.dut.get_mac_address(port) self.tester.scapy_append( 'wrpcap("test%d.pcap",[Ether(src="02:00:00:00:00:0%d",dst=%s)/IP()/UDP()/()])' % (port, port, dmac)) tgenInput.append( (self.tester.get_local_port(port), self.tester.get_local_port(port), "test%d.pcap" % port)) for _ in range(stress_iterations): self.dut.send_expect("port stop all", "testpmd> ", 100) self.dut.send_expect("set fwd mac", "testpmd>") self.dut.send_expect("port start all", "testpmd> ", 100) self.dut.send_expect("start", "testpmd> ") self.check_forwarding() self.dut.send_expect("stop", "testpmd> ") self.dut.send_expect("quit", "# ") def test_link_stats(self): """ port link stats test """ if self.kdriver == "fm10k": print utils.RED("RRC not support\n") return self.pmdout.start_testpmd("Default", "--portmask=%s --port-topology=loop" % utils.create_mask(self.ports), socket=self.ports_socket) self.dut.send_expect("set fwd mac", "testpmd>") self.dut.send_expect("start", "testpmd>") ports_num = len(self.ports) # link down test for i in range(ports_num): self.dut.send_expect("set link-down port %d" % i, "testpmd>") # leep few seconds for NIC link status update time.sleep(5) self.check_ports(status=False) # link up test for j in range(ports_num): self.dut.send_expect("set link-up port %d" % j, "testpmd>") time.sleep(5) self.check_ports(status=True) self.check_forwarding() def tear_down(self): """ Run after each test case. """ self.dut.kill_all() def tear_down_all(self): """ Run after each test suite. """ self.dut.kill_all()
class TestVfPacketRxtx(TestCase): supported_vf_driver = ['pci-stub', 'vfio-pci'] def set_up_all(self): self.dut_ports = self.dut.get_ports(self.nic) self.verify(len(self.dut_ports) > 1, "Insufficient ports") self.vm0 = None self.vm1 = None # set vf assign method and vf driver self.vf_driver = self.get_suite_cfg()['vf_driver'] if self.vf_driver is None: self.vf_driver = 'pci-stub' self.verify(self.vf_driver in self.supported_vf_driver, "Unspported vf driver") if self.vf_driver == 'pci-stub': self.vf_assign_method = 'pci-assign' else: self.vf_assign_method = 'vfio-pci' self.tester.send_expect('modprobe vfio-pci', '#') def set_up(self): self.setup_2pf_2vf_1vm_env_flag = 0 self.setup_3vf_2vm_env_flag = 0 def setup_2pf_2vf_1vm_env(self, driver='default'): self.used_dut_port_0 = self.dut_ports[0] self.dut.generate_sriov_vfs_by_port(self.used_dut_port_0, 1, driver=driver) self.sriov_vfs_port_0 = self.dut.ports_info[ self.used_dut_port_0]['vfs_port'] self.used_dut_port_1 = self.dut_ports[1] self.dut.generate_sriov_vfs_by_port(self.used_dut_port_1, 1, driver=driver) self.sriov_vfs_port_1 = self.dut.ports_info[ self.used_dut_port_1]['vfs_port'] try: for port in self.sriov_vfs_port_0: port.bind_driver(self.vf_driver) for port in self.sriov_vfs_port_1: port.bind_driver(self.vf_driver) time.sleep(1) vf0_prop = {'opt_host': self.sriov_vfs_port_0[0].pci} vf1_prop = {'opt_host': self.sriov_vfs_port_1[0].pci} 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) else: self.host_testpmd.start_testpmd("1S/5C/1T", "", eal_param=eal_param) # set up VM0 ENV self.vm0 = QEMUKvm(self.dut, 'vm0', 'vf_packet_rxtx') self.vm0.set_vm_device(driver=self.vf_assign_method, **vf0_prop) self.vm0.set_vm_device(driver=self.vf_assign_method, **vf1_prop) self.vm_dut_0 = self.vm0.start() if self.vm_dut_0 is None: raise Exception("Set up VM0 ENV failed!") self.setup_2pf_2vf_1vm_env_flag = 1 except Exception as e: self.destroy_2pf_2vf_1vm_env() raise Exception(e) def destroy_2pf_2vf_1vm_env(self): if getattr(self, 'vm0', None): #destroy testpmd in vm0 if getattr(self, 'vm0_testpmd', None): self.vm0_testpmd.execute_cmd('stop') self.vm0_testpmd.execute_cmd('quit', '# ') self.vm0_testpmd = None self.vm0_dut_ports = None #destroy vm0 self.vm0.stop() self.vm0 = None if getattr(self, 'host_testpmd', None): self.host_testpmd.execute_cmd('quit', '# ') self.host_testpmd = None self.dut.virt_exit() if getattr(self, 'used_dut_port_0', None) != None: self.dut.destroy_sriov_vfs_by_port(self.used_dut_port_0) port = self.dut.ports_info[self.used_dut_port_0]['port'] port.bind_driver() self.used_dut_port_0 = None if getattr(self, 'used_dut_port_1', None) != None: self.dut.destroy_sriov_vfs_by_port(self.used_dut_port_1) port = self.dut.ports_info[self.used_dut_port_1]['port'] port.bind_driver() self.used_dut_port_1 = None for port_id in self.dut_ports: port = self.dut.ports_info[port_id]['port'] port.bind_driver() self.setup_2pf_2vf_1vm_env_flag = 0 def packet_rx_tx(self, driver='default'): if driver == 'igb_uio': self.setup_2pf_2vf_1vm_env(driver='igb_uio') else: self.setup_2pf_2vf_1vm_env(driver='') self.vm0_dut_ports = self.vm_dut_0.get_ports('any') port_id_0 = 0 self.vm0_testpmd = PmdOutput(self.vm_dut_0) out = self.vm0_testpmd.start_testpmd(VM_CORES_MASK) pmd_vf0_mac = self.vm0_testpmd.get_port_mac(port_id_0) self.vm0_testpmd.execute_cmd('set fwd mac') self.vm0_testpmd.execute_cmd('start') time.sleep(2) tgen_ports = [] tx_port = self.tester.get_local_port(self.dut_ports[0]) rx_port = self.tester.get_local_port(self.dut_ports[1]) tgen_ports.append((tx_port, rx_port)) dst_mac = pmd_vf0_mac src_mac = self.tester.get_mac(tx_port) pkt_param = [("ether", {'dst': dst_mac, 'src': src_mac})] result = self.tester.check_random_pkts(tgen_ports, allow_miss=False, params=pkt_param) print self.vm0_testpmd.execute_cmd('show port stats all') self.verify(result != False, "VF0 failed to forward packets to VF1") ######1. test case for kernel pf and dpdk vf 2pf_2vf_1vm scenario packet rx tx. def test_kernel_2pf_2vf_1vm(self): self.packet_rx_tx(driver='') ######2. test case for dpdk pf and dpdk vf 2pf_2vf_1vm scenario packet rx tx. def test_dpdk_2pf_2vf_1vm(self): self.packet_rx_tx(driver='igb_uio') def setup_3vf_2vm_env(self, driver='default'): self.used_dut_port = self.dut_ports[0] self.dut.generate_sriov_vfs_by_port(self.used_dut_port, 3, driver=driver) self.sriov_vfs_port = self.dut.ports_info[ self.used_dut_port]['vfs_port'] try: for port in self.sriov_vfs_port: print port.pci port.bind_driver(self.vf_driver) time.sleep(1) vf0_prop = {'opt_host': self.sriov_vfs_port[0].pci} vf1_prop = {'opt_host': self.sriov_vfs_port[1].pci} vf2_prop = {'opt_host': self.sriov_vfs_port[2].pci} for port_id in self.dut_ports: if port_id == self.used_dut_port: continue port = self.dut.ports_info[port_id]['port'] port.bind_driver() 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 } self.host_testpmd.start_testpmd("1S/2C/2T", eal_param=eal_param) # set up VM0 ENV self.vm0 = QEMUKvm(self.dut, 'vm0', 'vf_packet_rxtx') self.vm0.set_vm_device(driver=self.vf_assign_method, **vf0_prop) self.vm0.set_vm_device(driver=self.vf_assign_method, **vf1_prop) self.vm_dut_0 = self.vm0.start() if self.vm_dut_0 is None: raise Exception("Set up VM0 ENV failed!") # set up VM1 ENV self.vm1 = QEMUKvm(self.dut, 'vm1', 'vf_packet_rxtx') self.vm1.set_vm_device(driver=self.vf_assign_method, **vf2_prop) self.vm_dut_1 = self.vm1.start() if self.vm_dut_1 is None: raise Exception("Set up VM1 ENV failed!") self.setup_3vf_2vm_env_flag = 1 except Exception as e: self.destroy_3vf_2vm_env() raise Exception(e) def destroy_3vf_2vm_env(self): if getattr(self, 'vm0', None): if getattr(self, 'vm0_testpmd', None): self.vm0_testpmd.execute_cmd('stop') self.vm0_testpmd.execute_cmd('quit', '# ') self.vm0_testpmd = None self.vm0_dut_ports = None self.vm_dut_0 = None self.vm0.stop() self.vm0 = None if getattr(self, 'vm1', None): if getattr(self, 'vm1_testpmd', None): self.vm1_testpmd.execute_cmd('stop') self.vm1_testpmd.execute_cmd('quit', '# ') self.vm1_testpmd = None self.vm1_dut_ports = None self.vm_dut_1 = None self.vm1.stop() self.vm1 = None self.dut.virt_exit() if getattr(self, 'host_testpmd', None) != None: self.host_testpmd.execute_cmd('quit', '# ') self.host_testpmd = None if getattr(self, 'used_dut_port', None) != None: self.dut.destroy_sriov_vfs_by_port(self.used_dut_port) port = self.dut.ports_info[self.used_dut_port]['port'] port.bind_driver() self.used_dut_port = None for port_id in self.dut_ports: port = self.dut.ports_info[port_id]['port'] port.bind_driver() self.setup_3vf_2vm_env_flag = 0 def test_vf_reset(self): self.setup_3vf_2vm_env(driver='') self.vm0_dut_ports = self.vm_dut_0.get_ports('any') self.vm1_dut_ports = self.vm_dut_1.get_ports('any') port_id_0 = 0 port_id_1 = 1 self.vm0_testpmd = PmdOutput(self.vm_dut_0) self.vm0_testpmd.start_testpmd(VM_CORES_MASK) self.vm0_testpmd.execute_cmd('show port info all') pmd0_vf0_mac = self.vm0_testpmd.get_port_mac(port_id_0) self.vm0_testpmd.execute_cmd('set fwd mac') self.vm0_testpmd.execute_cmd('start') time.sleep(2) self.vm1_testpmd = PmdOutput(self.vm_dut_1) self.vm1_testpmd.start_testpmd(VM_CORES_MASK) self.vm1_testpmd.execute_cmd('show port info all') tx_port = self.tester.get_local_port(self.dut_ports[0]) rx_port = tx_port dst_mac = pmd0_vf0_mac self.tester.sendpkt_bg(tx_port, dst_mac) #vf port stop/start can trigger reset action for num in range(1000): self.vm1_testpmd.execute_cmd('port stop all') time.sleep(0.1) self.vm1_testpmd.execute_cmd('port start all') time.sleep(0.1) self.tester.stop_sendpkt_bg() pmd0_vf0_stats = self.vm0_testpmd.get_pmd_stats(port_id_0) pmd0_vf1_stats = self.vm0_testpmd.get_pmd_stats(port_id_1) vf0_rx_cnt = pmd0_vf0_stats['RX-packets'] self.verify(vf0_rx_cnt != 0, "no packet was received by vm0_VF0") vf0_rx_err = pmd0_vf0_stats['RX-errors'] self.verify(vf0_rx_err == 0, "vm0_VF0 rx-errors") vf1_tx_cnt = pmd0_vf1_stats['TX-packets'] self.verify(vf1_tx_cnt != 0, "no packet was transmitted by vm0_VF1") vf1_tx_err = pmd0_vf1_stats['TX-errors'] self.verify(vf1_tx_err == 0, "vm0_VF0 tx-errors") self.verify( vf0_rx_cnt == vf1_tx_cnt, "vm0_VF0 failed to forward packets to vm0_VF1 when reset vm1_VF0 frequently" ) def tear_down(self): if self.setup_2pf_2vf_1vm_env_flag == 1: self.destroy_2pf_2vf_1vm_env() if self.setup_3vf_2vm_env_flag == 1: self.destroy_3vf_2vm_env() if getattr(self, 'vm0', None): self.vm0.stop() if getattr(self, 'vm1', None): self.vm1.stop() self.dut.virt_exit() for port_id in self.dut_ports: self.dut.destroy_sriov_vfs_by_port(port_id) # DPDK-1754 intf = self.dut.ports_info[port_id]['intf'] self.dut.send_expect("ethtool -s %s autoneg on" % intf, "# ") def tear_down_all(self): pass
class TestFdir(TestCase): def set_up_all(self): """ Run at the start of each test suite. """ ports = self.dut.get_ports() self.verify(len(ports) >= 2, "Not enough ports available") self.pmdout = PmdOutput(self.dut) def set_up(self): """ Run before each test case. """ pass def send_and_verify(self, condition, packet): """ Send packages and verify behavior. """ self.tester.scapy_foreground() self.tester.scapy_append('sys.path.append("./")') self.tester.scapy_append('from sctp import *') self.tester.scapy_append(packet) self.dut.send_expect("start", "testpmd>") self.tester.scapy_execute() time.sleep(.5) out = self.dut.send_expect("stop", "testpmd>") if condition: self.verify("PKT_RX_FDIR" in out, "FDIR hash not displayed when required") else: self.verify("PKT_RX_FDIR" not in out, "FDIR hash displayed when not required") def test_fdir_space(self): """ Setting memory reserved for FDir filters. """ dutPorts = self.dut.get_ports() self.pmdout.start_testpmd("all", "--rxq=2 --txq=2 --disable-rss --pkt-filter-mode=perfect --pkt-filter-size=64K") out = self.dut.send_expect("show port fdir %s" % dutPorts[0], "testpmd>") self.dut.send_expect("quit", "# ", 30) self.verify("free: 2048" in out, "Free space doesn't match the expected value") self.pmdout.start_testpmd("all", "--rxq=2 --txq=2 --disable-rss --pkt-filter-mode=perfect --pkt-filter-size=128K") out = self.dut.send_expect("show port fdir %s" % dutPorts[0], "testpmd>") self.dut.send_expect("quit", "# ", 30) self.verify("free: 4096" in out, "Free space doesn't match the expected value") self.pmdout.start_testpmd("all", "--rxq=2 --txq=2 --disable-rss --pkt-filter-mode=perfect --pkt-filter-size=256K") out = self.dut.send_expect("show port fdir %s" % dutPorts[0], "testpmd>") self.dut.send_expect("quit", "# ", 30) self.verify("free: 8192" in out, "Free space doesn't match the expected value") def test_fdir_signatures(self): """ FDir signature matching mode. There are three different reporting modes, that can be set in testpmd using the ``--pkt-filter-report-hash`` command line argument: --pkt-filter-report-hash=none --pkt-filter-report-hash=match --pkt-filter-report-hash=always The test for each mode is following the steps below. - Start the ``testpmd`` application by using paramter of each mode. - Send the ``p_udp`` packet with Scapy on the traffic generator and check that FDir information is printed """ dutPorts = self.dut.get_ports() localPort = self.tester.get_local_port(dutPorts[0]) itf = self.tester.get_interface(localPort) self.dut.kill_all() self.pmdout.start_testpmd("all", "--portmask=%s --rxq=2 --txq=2 --disable-rss --pkt-filter-mode=perfect --pkt-filter-report-hash=none" % dts.create_mask([dutPorts[0]])) self.dut.send_expect("set verbose 1", "testpmd>") self.dut.send_expect("set fwd rxonly", "testpmd>") self.dut.send_expect("set nbcore 3", "testpmd>") self.send_and_verify(False, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect("add_perfect_filter %s udp src 192.168.0.1 1024 dst 192.168.0.2 1024 flexbytes 0x800 vlan 0 queue 1 soft 0x14" % dutPorts[0], "testpmd>") self.send_and_verify(False, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect("quit", "# ", 30) self.pmdout.start_testpmd("all", "--portmask=%s --rxq=2 --txq=2 --disable-rss --pkt-filter-mode=perfect --pkt-filter-report-hash=match" % dts.create_mask([dutPorts[0]])) self.dut.send_expect("set verbose 1", "testpmd>") self.dut.send_expect("set fwd rxonly", "testpmd>") self.dut.send_expect("set nbcore 3", "testpmd>") self.send_and_verify(False, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect("add_perfect_filter %s udp src 192.168.0.1 1024 dst 192.168.0.2 1024 flexbytes 0x800 vlan 0 queue 1 soft 0x14" % dutPorts[0], "testpmd>") self.send_and_verify(True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect("upd_perfect_filter %s udp src 192.168.1.1 0 dst 192.168.1.2 0 flexbytes 0x800 vlan 0 queue 1 soft 0x14" % dutPorts[0], "testpmd>") self.send_and_verify(True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.send_and_verify(True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.1.1", dst="192.168.1.2")/UDP(sport=0,dport=0)], iface="%s")' % (itf, itf)) self.dut.send_expect("rm_perfect_filter %s udp src 192.168.1.1 0 dst 192.168.1.2 0 flexbytes 0x800 vlan 0 soft 0x14" % dutPorts[0], "testpmd>") self.send_and_verify(False, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.1.1", dst="192.168.1.2")/UDP(sport=0,dport=0)], iface="%s")' % (itf, itf)) self.dut.send_expect("quit", "# ", 30) self.pmdout.start_testpmd("all", "--portmask=%s --rxq=2 --txq=2 --disable-rss --pkt-filter-mode=perfect --pkt-filter-report-hash=always" % dts.create_mask([dutPorts[0]])) self.dut.send_expect("set verbose 1", "testpmd>") self.dut.send_expect("set fwd rxonly", "testpmd>") self.dut.send_expect("set nbcore 3", "testpmd>") self.send_and_verify(True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect("add_perfect_filter %s udp src 192.168.0.1 1024 dst 192.168.0.2 1024 flexbytes 0x800 vlan 0 queue 1 soft 0x14" % dutPorts[0], "testpmd>") self.send_and_verify(True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect("quit", "# ", 30) def test_fdir_matching(self): """ FDir matching mode This test adds signature filters to the hardware, and then checks whether sent packets match those filters. The test for each mode is following the steps below. - Start the ``testpmd`` application - Add filter with upd, tcp sctp, IP4 or IP6 - Send the packet and validate the filter function. """ dutPorts = self.dut.get_ports() localPort = self.tester.get_local_port(dutPorts[0]) itf = self.tester.get_interface(localPort) self.dut.kill_all() self.pmdout.start_testpmd("all", "--portmask=%s --rxq=2 --txq=2 --disable-rss --pkt-filter-mode=signature --pkt-filter-report-hash=match" % dts.create_mask([dutPorts[0]])) self.dut.send_expect("set verbose 1", "testpmd>") self.dut.send_expect("set fwd rxonly", "testpmd>") self.dut.send_expect("set nbcore 3", "testpmd>") self.send_and_verify(False, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect("add_signature_filter %s udp src 192.168.0.1 1024 dst 192.168.0.2 1024 flexbytes 0x800 vlan 0 queue 1" % dutPorts[0], "testpmd>") self.send_and_verify(True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.send_and_verify(False, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/TCP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect("upd_signature_filter %s udp src 192.168.1.1 0 dst 192.168.1.2 0 flexbytes 0x800 vlan 0 queue 1" % dutPorts[0], "testpmd>") self.send_and_verify(True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.send_and_verify(True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.1.1", dst="192.168.1.2")/UDP(sport=0,dport=0)], iface="%s")' % (itf, itf)) self.dut.send_expect("rm_signature_filter %s udp src 192.168.1.1 0 dst 192.168.1.2 0 flexbytes 0x800 vlan 0" % dutPorts[0], "testpmd>") self.send_and_verify(False, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.1.1", dst="192.168.1.2")/UDP(sport=0,dport=0)], iface="%s")' % (itf, itf)) self.dut.send_expect("add_signature_filter %s tcp src 192.168.0.1 1024 dst 192.168.0.2 1024 flexbytes 0x800 vlan 0 queue 1" % dutPorts[0], "testpmd>") self.send_and_verify(True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/TCP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.send_and_verify(False, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/SCTP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect("add_signature_filter %s sctp src 192.168.0.1 0 dst 192.168.0.2 0 flexbytes 0x800 vlan 0 queue 1" % dutPorts[0], "testpmd>") self.send_and_verify(True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/SCTP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.send_and_verify(False, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")], iface="%s")' % (itf, itf)) self.dut.send_expect("add_signature_filter %s ip src 192.168.0.1 0 dst 192.168.0.2 0 flexbytes 0x800 vlan 0 queue 1" % dutPorts[0], "testpmd>") self.send_and_verify(True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")], iface="%s")' % (itf, itf)) self.send_and_verify(False, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IPv6(src="2001:0db8:85a3:0000:0000:8a2e:0370:7000", dst="2001:0db8:85a3:0000:0000:8a2e:0370:7338")/UDP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect("add_signature_filter %s udp src 2001:0db8:85a3:0000:0000:8a2e:0370:7000 1024 dst 2001:0db8:85a3:0000:0000:8a2e:0370:7338 1024 flexbytes 0x86dd vlan 0 queue 1" % dutPorts[0], "testpmd>") self.send_and_verify(True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IPv6(src="2001:0db8:85a3:0000:0000:8a2e:0370:7000", dst="2001:0db8:85a3:0000:0000:8a2e:0370:7338")/UDP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect("quit", "# ", 30) def test_fdir_perfect_matching(self): """ FDir perfect matching mode. This test adds perfect-match filters to the hardware, and then checks whether sent packets match those filters. The test for each mode is following the steps below. - Start the ``testpmd`` application with perfect match; - Add filter with upd, tcp sctp, IP4; - Send the packet and validate the perfect filter function. """ dutPorts = self.dut.get_ports() localPort = self.tester.get_local_port(dutPorts[0]) itf = self.tester.get_interface(localPort) self.dut.kill_all() self.pmdout.start_testpmd("all", "--portmask=%s --rxq=2 --txq=2 --disable-rss --pkt-filter-mode=perfect --pkt-filter-report-hash=match" % dts.create_mask([dutPorts[0]])) self.dut.send_expect("set verbose 1", "testpmd>") self.dut.send_expect("set fwd rxonly", "testpmd>") self.dut.send_expect("set nbcore 3", "testpmd>") self.dut.send_expect("add_perfect_filter %s udp src 192.168.0.1 1024 dst 192.168.0.2 1024 flexbytes 0x800 vlan 0 queue 1 soft 0x14" % dutPorts[0], "testpmd>") self.send_and_verify(True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect("add_perfect_filter %s tcp src 192.168.0.1 1024 dst 192.168.0.2 1024 flexbytes 0x800 vlan 0 queue 1 soft 0x15" % dutPorts[0], "testpmd>") self.send_and_verify(True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/TCP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect("add_perfect_filter %s sctp src 192.168.0.1 0 dst 192.168.0.2 0 flexbytes 0x800 vlan 0 queue 1 soft 0x16" % dutPorts[0], "testpmd>") self.send_and_verify(True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/SCTP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect("add_perfect_filter %s ip src 192.168.0.1 0 dst 192.168.0.2 0 flexbytes 0x800 vlan 0 queue 1 soft 0x17" % dutPorts[0], "testpmd>") self.send_and_verify(True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")], iface="%s")' % (itf, itf)) self.dut.send_expect("quit", "# ", 30) def test_fdir_filter_masks(self): """ FDir filter masks. This tests the functionality of the setting FDir masks to to affect which fields, or parts of fields are used in the matching process. """ dutPorts = self.dut.get_ports() localPort = self.tester.get_local_port(dutPorts[0]) itf = self.tester.get_interface(localPort) self.dut.kill_all() self.pmdout.start_testpmd("all", "--portmask=%s --rxq=2 --txq=2 --disable-rss --pkt-filter-mode=perfect --pkt-filter-size=64K --pkt-filter-report-hash=match" % dts.create_mask([dutPorts[0]])) self.dut.send_expect("set verbose 1", "testpmd>") self.dut.send_expect("set fwd rxonly", "testpmd>") self.dut.send_expect("set nbcore 3", "testpmd>") self.dut.send_expect("set_masks_filter %s only_ip_flow 0 src_mask 0xffffff00 0xffff dst_mask 0xffffff00 0xffff flexbytes 1 vlan_id 1 vlan_prio 1" % dutPorts[0], "testpmd>") self.dut.send_expect("add_perfect_filter %s udp src 192.168.0.0 1024 dst 192.168.0.0 1024 flexbytes 0x800 vlan 0 queue 1 soft 0x17" % dutPorts[0], "testpmd>") self.send_and_verify(True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.send_and_verify(True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.15", dst="192.168.0.15")/UDP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.send_and_verify(False, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.1.1")/UDP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect("set_masks_filter %s only_ip_flow 0 src_mask 0xffffffff 0xff00 dst_mask 0xffffffff 0xff00 flexbytes 1 vlan_id 1 vlan_prio 1" % dutPorts[0], "testpmd>") self.dut.send_expect("add_perfect_filter %s udp src 10.11.12.1 0x4400 dst 10.11.12.2 0x4500 flexbytes 0x800 vlan 0 queue 1 soft 0x4" % dutPorts[0], "testpmd>") self.send_and_verify(True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="10.11.12.1", dst="10.11.12.2")/UDP(sport=0x4400,dport=0x4500)], iface="%s")' % (itf, itf)) self.send_and_verify(True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="10.11.12.1", dst="10.11.12.2")/UDP(sport=0x4411,dport=0x4517)], iface="%s")' % (itf, itf)) self.send_and_verify(False, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="10.11.12.1", dst="10.11.12.2")/UDP(sport=0x4500,dport=0x5500)], iface="%s")' % (itf, itf)) self.dut.send_expect("set_masks_filter %s only_ip_flow 1 src_mask 0xffffffff 0x0 dst_mask 0xffffffff 0x0 flexbytes 1 vlan_id 1 vlan_prio 1" % dutPorts[0], "testpmd>") self.dut.send_expect("add_perfect_filter %s ip src 192.168.0.1 0 dst 192.168.0.2 0 flexbytes 0x800 vlan 0 queue 1 soft 0x42" % dutPorts[0], "testpmd>") self.send_and_verify(True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=1024, dport=1024)], iface="%s")' % (itf, itf)) self.send_and_verify(True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/TCP(sport=1024, dport=1024)], iface="%s")' % (itf, itf)) self.send_and_verify(True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/SCTP(sport=1024, dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect("quit", "# ", 30) def test_fdir_flexbytes_filtering(self): """ FDir flexbytes filtering The FDir feature supports setting up filters that can match on any two byte field within the first 64 bytes of a packet. Which byte offset to use is set by passing command line arguments to ``testpmd``. In this test a value of ``18`` corresponds to the bytes at offset 36 and 37, as the offset is in 2-byte units """ dutPorts = self.dut.get_ports() localPort = self.tester.get_local_port(dutPorts[0]) itf = self.tester.get_interface(localPort) self.dut.kill_all() self.pmdout.start_testpmd("all", "--portmask=%s --rxq=2 --txq=2 --disable-rss --pkt-filter-mode=perfect --pkt-filter-size=64K --pkt-filter-report-hash=match --pkt-filter-flexbytes-offset=18" % dts.create_mask([dutPorts[0]])) self.dut.send_expect("set verbose 1", "testpmd>") self.dut.send_expect("set fwd rxonly", "testpmd>") self.dut.send_expect("set nbcore 3", "testpmd>") self.dut.send_expect("add_perfect_filter %s ip src 192.168.0.1 0 dst 192.168.0.2 0 flexbytes 0x1 vlan 0 queue 1 soft 0x1" % dutPorts[0], "testpmd>") self.send_and_verify(True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/GRE(proto=0x1)/IP()/UDP()], iface="%s")' % (itf, itf)) self.dut.send_expect("add_perfect_filter %s ip src 192.168.0.1 0 dst 192.168.0.2 0 flexbytes 0xff vlan 0 queue 1 soft 0xff" % dutPorts[0], "testpmd>") self.send_and_verify(True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/GRE(proto=0xff)/IP()/UDP()], iface="%s")' % (itf, itf)) self.dut.send_expect("set_masks_filter %s only_ip_flow 0 src_mask 0xffffffff 0xffff dst_mask 0xffffffff 0xffff flexbytes 0 vlan_id 1 vlan_prio 1" % dutPorts[0], "testpmd>") self.dut.send_expect("add_perfect_filter %s ip src 192.168.0.1 0 dst 192.168.0.2 0 flexbytes 0x0 vlan 0 queue 1 soft 0x42" % dutPorts[0], "testpmd>") self.send_and_verify(True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/GRE(proto=0x1)/IP()/UDP()], iface="%s")' % (itf, itf)) self.send_and_verify(True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/GRE(proto=0xFF)/IP()/UDP()], iface="%s")' % (itf, itf)) self.dut.send_expect("quit", "# ", 30) def test_fdir_vlanfiltering(self): """ FDir VLAN field filtering """ dutPorts = self.dut.get_ports() localPort = self.tester.get_local_port(dutPorts[0]) itf = self.tester.get_interface(localPort) self.dut.kill_all() self.pmdout.start_testpmd("all", "--portmask=%s --nb-cores=2 --rxq=2 --txq=2 --disable-rss --pkt-filter-mode=perfect" % dts.create_mask([dutPorts[0]])) self.dut.send_expect("set verbose 1", "testpmd>") self.dut.send_expect("set fwd rxonly", "testpmd>") # "rx_vlan add all" has been removed from testpmd self.dut.send_expect("rx_vlan add 0xFFF %s" % dutPorts[0], "testpmd>") self.dut.send_expect("rx_vlan add 0x001 %s" % dutPorts[0], "testpmd>") self.dut.send_expect("rx_vlan add 0x017 %s" % dutPorts[0], "testpmd>") self.send_and_verify(False, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/Dot1Q(vlan=0x0FFF)/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=1024, dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect("add_perfect_filter %s udp src 192.168.0.1 1024 dst 192.168.0.2 1024 flexbytes 0x8100 vlan 0xfff queue 1 soft 0x47" % dutPorts[0], "testpmd>") self.send_and_verify(True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/Dot1Q(vlan=0x0FFF)/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=1024, dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect("set_masks_filter %s only_ip_flow 0 src_mask 0xffffffff 0xffff dst_mask 0xffffffff 0xffff flexbytes 1 vlan_id 0 vlan_prio 0" % dutPorts[0], "testpmd>") self.dut.send_expect("add_perfect_filter %s udp src 192.168.0.1 1024 dst 192.168.0.2 1024 flexbytes 0x8100 vlan 0 queue 1 soft 0x47" % dutPorts[0], "testpmd>") self.send_and_verify(True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/Dot1Q(vlan=0x001)/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=1024, dport=1024)], iface="%s")' % (itf, itf)) self.send_and_verify(True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/Dot1Q(vlan=0x0017)/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=1024, dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect("quit", "# ", 30) def tear_down(self): """ Run after each test case. """ pass def tear_down_all(self): """ Run after each test suite. """ pass
class TestIeee1588(TestCase): def set_up_all(self): """ Run at the start of each test suite. IEEE1588 Prerequisites """ dutPorts = self.dut.get_ports() self.verify(len(dutPorts) > 0, "No ports found for " + self.nic) # Change the config file to support IEEE1588 and recompile the package. self.dut.send_expect( "sed -i -e 's/IEEE1588=n$/IEEE1588=y/' config/common_base", "# ", 30) self.dut.skip_setup = False self.dut.build_install_dpdk(self.target) self.pmdout = PmdOutput(self.dut) # For IEEE1588, the full-feature tx path needs to be enabled. # Enabling any tx offload will force DPDK utilize full tx path. # Enabling multiple segment offload is more reasonable for user cases. self.pmdout.start_testpmd( "Default", " --tx-offloads=%s" % DEV_TX_OFFLOAD_MULTI_SEGS) def set_up(self): """ Run before each test case. """ pass def test_ieee1588_enable(self): """ IEEE1588 Enable test case. """ self.dut.send_expect("set fwd ieee1588", "testpmd> ", 10) # Waiting for 'testpmd> ' Fails due to log messages, "Received non PTP # packet", in the output self.dut.send_expect("start", ">", 10) # Allow the output from the "start" command to finish before looking # for a regexp in expect time.sleep(1) # use the first port on that self.nic dutPorts = self.dut.get_ports() mac = self.dut.get_mac_address(dutPorts[0]) port = self.tester.get_local_port(dutPorts[0]) itf = self.tester.get_interface(port) self.tester.send_expect("tcpdump -i %s -e ether src %s" % (itf, mac), "tcpdump", 20) pkt = Packet(pkt_type='TIMESYNC') pkt.config_layer('ether', { 'dst': mac, }) pkt.send_pkt(tx_port=itf) time.sleep(1) out = self.tester.get_session_output(timeout=20) self.tester.send_expect("^C", "# ", 20) self.verify("0x88f7" in out, "Ether type is not PTP") time.sleep(1) out = self.dut.get_session_output() self.dut.send_expect("stop", "testpmd> ") text = utils.regexp(out, "(.*) by hardware") self.verify("IEEE1588 PTP V2 SYNC" in text, "Not filtered " + text) pattern_rx = re.compile("RX timestamp value (\d+) s (\d+) ns") pattern_tx = re.compile("TX timestamp value (\d+) s (\d+) ns") m_rx = pattern_rx.search(out) m_tx = pattern_tx.search(out) if m_rx is not None: rx_time = m_rx.group(2) if m_tx is not None: tx_time = m_tx.group(2) self.verify(rx_time is not None, "RX timestamp error ") self.verify(tx_time is not None, "TX timestamp error ") self.verify(int(tx_time, 16) > int(rx_time, 16), "Timestamp mismatch") def test_ieee1588_disable(self): """ IEEE1588 Disable test case. """ self.dut.send_expect("stop", "testpmd> ", 10) time.sleep(3) # use the first port on that self.nic dutPorts = self.dut.get_ports() mac = self.dut.get_mac_address(dutPorts[0]) port = self.tester.get_local_port(dutPorts[0]) itf = self.tester.get_interface(port) self.tester.scapy_background() self.tester.scapy_append('p = sniff(iface="%s", count=2, timeout=1)' % itf) self.tester.scapy_append('RESULT = p[1].summary()') self.tester.scapy_foreground() self.tester.scapy_append('nutmac="%s"' % mac) self.tester.scapy_append( 'sendp([Ether(dst=nutmac,type=0x88f7)/"\\x00\\x02"], iface="%s")' % itf) self.tester.scapy_execute() time.sleep(2) out = self.tester.scapy_get_result() self.verify("Ether" not in out, "Ether type is not PTP") def tear_down(self): """ Run after each test case. """ pass def tear_down_all(self): """ Run after each test suite. """ self.dut.send_expect("quit", "# ", 30) # Restore the config file and recompile the package. self.dut.send_expect( "sed -i -e 's/IEEE1588=y$/IEEE1588=n/' config/common_base", "# ", 30) self.dut.build_install_dpdk(self.target)
class Testvf_daemon(TestCase): def set_up_all(self): self.dut_ports = self.dut.get_ports(self.nic) self.verify(len(self.dut_ports) >= 1, "Insufficient ports") self.vm0 = None self.vm1 = None self.env_done = False def set_up(self): self.setup_vm_env() def bind_nic_driver(self, ports, driver=""): if driver == "igb_uio": for port in ports: netdev = self.dut.ports_info[port]['port'] driver = netdev.get_nic_driver() if driver != 'igb_uio': netdev.bind_driver(driver='igb_uio') else: for port in ports: netdev = self.dut.ports_info[port]['port'] driver_now = netdev.get_nic_driver() if driver == "": driver = netdev.default_driver if driver != driver_now: netdev.bind_driver(driver=driver) def setup_vm_env(self, driver='igb_uio'): """ Create testing environment with 2VFs generated from 1PF """ if self.env_done: return self.bind_nic_driver(self.dut_ports[:1], driver="igb_uio") self.used_dut_port = self.dut_ports[0] tester_port = self.tester.get_local_port(self.used_dut_port) self.tester_intf = self.tester.get_interface(tester_port) self.dut.generate_sriov_vfs_by_port(self.used_dut_port, 2, driver=driver) self.sriov_vfs_port = self.dut.ports_info[ self.used_dut_port]['vfs_port'] for port in self.sriov_vfs_port: port.bind_driver('pci-stub') time.sleep(1) self.dut_testpmd = PmdOutput(self.dut) time.sleep(1) vf0_prop = {'opt_host': self.sriov_vfs_port[0].pci} # set up VM0 ENV self.vm0 = QEMUKvm(self.dut, 'vm0', 'vf_daemon') self.vm0.set_vm_device(driver='pci-assign', **vf0_prop) try: self.vm0_dut = self.vm0.start() if self.vm0_dut is None: raise Exception("Set up VM0 ENV failed!") except Exception as e: self.destroy_vm_env() raise Exception(e) self.vm0_dut_ports = self.vm0_dut.get_ports('any') self.vm0_testpmd = PmdOutput(self.vm0_dut) vf1_prop = {'opt_host': self.sriov_vfs_port[1].pci} self.vm1 = QEMUKvm(self.dut, 'vm1', 'vf_daemon') self.vm1.set_vm_device(driver='pci-assign', **vf1_prop) try: self.vm1_dut = self.vm1.start() if self.vm1_dut is None: raise Exception("Set up VM1 ENV failed!") except Exception as e: self.destroy_vm_env() raise Exception(e) self.vm1_dut_ports = self.vm1_dut.get_ports('any') self.vm1_testpmd = PmdOutput(self.vm1_dut) self.env_done = True def destroy_vm_env(self): if getattr(self, 'vm0', None): self.vm0_dut.kill_all() self.vm0_testpmd = None self.vm0_dut_ports = None # destroy vm0 self.vm0.stop() self.vm0 = None if getattr(self, 'vm1', None): self.vm1_dut.kill_all() self.vm1_testpmd = None self.vm1_dut_ports = None # destroy vm1 self.vm1.stop() self.vm1 = None if getattr(self, 'used_dut_port', None): self.dut.destroy_sriov_vfs_by_port(self.used_dut_port) port = self.dut.ports_info[self.used_dut_port]['port'] self.used_dut_port = None self.env_done = False def send_packet(self, dst_mac, vlan_id, pktsize, num): """ Generate packets and send them to dut """ if vlan_id == 0: pkt = Packet(pkt_type='UDP', pkt_len=pktsize) else: pkt = Packet(pkt_type='VLAN_UDP', pkt_len=pktsize) pkt.config_layer('vlan', {'vlan': vlan_id}) pkt.config_layer('ether', {'dst': dst_mac}) inst = sniff_packets(self.tester_intf, timeout=5) pkt.send_pkt(tx_port=self.tester_intf, count=num) return inst def strip_mac(self, inst, element="src"): """ Load sniff packets, strip and return mac address from dump message """ pkts = load_sniff_packets(inst) macs = [] for pkt in pkts: mac = pkt.strip_element_layer2(element) macs.append(mac) return macs def strip_vlan(self, inst): """ Load sniff packets, strip and return vlan id from dump message """ pkts = load_sniff_packets(inst) vlans = [] for pkt in pkts: vlan = pkt.strip_element_vlan("vlan") vlans.append(vlan) return vlans def send_and_pmdout(self, dst_mac, vlan_id=0, pktsize=64, num=1): """ Send packets to dut and return testpmd output message Input: dst_mac, vlan_id, packet size, packet number Output: testpmd output message """ inst = self.send_packet(dst_mac, vlan_id, pktsize, num) out = self.vm0_dut.get_session_output(timeout=2) return out def send_and_vlanstrip(self, dst_mac, vlan_id=0, pktsize=64, num=1): """ Send packets to dut, strip and return vlan id from dump message Input: dst_mac, vlan_id, packet size, packet number Output: vlan id stripped from dump message """ inst = self.send_packet(dst_mac, vlan_id, pktsize, num) vlans = self.strip_vlan(inst) return vlans def send_and_macstrip(self, dst_mac, vlan_id=0, pktsize=64, num=1): """ Send packets to dut, strip and return src/dst mac from dump message Input: dst_mac, vlan_id, packet size, packet number Output: src/dst mac stripped from dump message """ inst = self.send_packet(dst_mac, vlan_id, pktsize, num) macs = self.strip_mac(inst) return macs def test_vlan_insert(self): """ Insert a vlan id for a VF from PF If insert vlan id as 0, means disabling vlan id insertion If insert vlan id as 1~4095, means enabling vlan id insertion and vlan id as configured value """ self.dut_testpmd.start_testpmd("Default", "--port-topology=chained") self.vm0_testpmd.start_testpmd(VM_CORES_MASK, '--port-topology=chained') self.vf0_mac = self.vm0_testpmd.get_port_mac(0) self.vm0_testpmd.execute_cmd('set fwd mac') self.vm0_testpmd.execute_cmd('set verbose 1') self.vm0_testpmd.execute_cmd('start') #Disable vlan insert which means insert vlan id as 0 rx_vlan = 0 self.dut_testpmd.execute_cmd('set vf vlan insert 0 0 %s' % rx_vlan) time.sleep(1) vlans = self.send_and_vlanstrip(self.vf0_mac) self.verify(rx_vlan not in vlans, "Failed to disable vlan insert!!!") #Enable vlan insert which means insert vlan id as 1~4095 random_vlan = random.randint(1, MAX_VLAN - 1) rx_vlans = [1, random_vlan, MAX_VLAN] for rx_vlan in rx_vlans: self.dut_testpmd.execute_cmd('set vf vlan insert 0 0 %s' % rx_vlan) time.sleep(1) vlans = self.send_and_vlanstrip(self.vf0_mac) self.verify(rx_vlan in vlans, "Failed to enable vlan insert packet!!!") self.vm0_testpmd.quit() self.dut_testpmd.quit() def test_multicast_mode(self): """ Enable/disable multicast promiscuous mode for a VF from PF """ self.dut_testpmd.start_testpmd("Default", "--port-topology=chained") self.vm0_testpmd.start_testpmd(VM_CORES_MASK, '--port-topology=chained') self.vf0_mac = self.vm0_testpmd.get_port_mac(0) self.vm0_testpmd.execute_cmd('set fwd rxonly') self.vm0_testpmd.execute_cmd('set verbose 1') self.vm0_testpmd.execute_cmd('start') self.dut_testpmd.execute_cmd('set vf promisc 0 0 off') self.dut_testpmd.execute_cmd('set vf allmulti 0 0 off') multi_mac = 'F3:00:33:22:11:00' out = self.send_and_pmdout(multi_mac) self.verify("received" not in out, "Failed to disable vf multicast mode!!!") out = self.send_and_pmdout(self.vf0_mac) self.verify("received" in out, "Failed to disable vf multicast mode!!!") self.verify("dst=%s" % self.vf0_mac in out, "Failed to disable vf multicast mode!!!") self.dut_testpmd.execute_cmd('set vf allmulti 0 0 on') out = self.send_and_pmdout(multi_mac) self.verify("received" in out, "Failed to enable vf multicast mode!!!") self.verify("dst=%s" % multi_mac in out, "Failed to enable vf multicast mode!!!") out = self.send_and_pmdout(self.vf0_mac) self.verify("received" in out, "Failed to enable vf multicast mode!!!") self.verify("dst=%s" % self.vf0_mac in out, "Failed to enable vf multicast mode!!!") self.vm0_testpmd.quit() self.dut_testpmd.quit() def test_promisc_mode(self): """ Enable/disable promiscuous mode for a VF from PF """ self.dut_testpmd.start_testpmd("Default", "--port-topology=chained") self.vm0_testpmd.start_testpmd(VM_CORES_MASK, '--port-topology=chained') self.vf0_mac = self.vm0_testpmd.get_port_mac(0) self.vm0_testpmd.execute_cmd('set fwd rxonly') self.vm0_testpmd.execute_cmd('set verbose 1') self.vm0_testpmd.execute_cmd('start') self.dut_testpmd.execute_cmd('set vf promisc 0 0 off') wrong_mac = '9E:AC:72:49:43:11' out = self.send_and_pmdout(wrong_mac) self.verify("received" not in out, "Failed to disable vf promisc mode!!!") out = self.send_and_pmdout(self.vf0_mac) self.verify("received" in out, "Failed to disable vf promisc mode!!!") self.verify("dst=%s" % self.vf0_mac in out, "Failed to disable vf promisc mode!!!") self.dut_testpmd.execute_cmd('set vf promisc 0 0 on') out = self.send_and_pmdout(wrong_mac) self.verify("received" in out, "Failed to enable vf promisc mode!!!") self.verify("dst=%s" % wrong_mac in out, "Failed to enable vf promisc mode!!!") out = self.send_and_pmdout(self.vf0_mac) self.verify("received" in out, "Failed to enable vf promisc mode!!!") self.verify("dst=%s" % self.vf0_mac in out, "Failed to enable vf promisc mode!!!") self.vm0_testpmd.quit() self.dut_testpmd.quit() def test_broadcast_mode(self): """ Enable/disable broadcast mode for a VF from PF """ self.dut_testpmd.start_testpmd("Default", "--port-topology=chained") self.vm0_testpmd.start_testpmd(VM_CORES_MASK, '--port-topology=chained') self.vf0_mac = self.vm0_testpmd.get_port_mac(0) self.vm0_testpmd.execute_cmd('set fwd rxonly') self.vm0_testpmd.execute_cmd('set verbose 1') self.vm0_testpmd.execute_cmd('start') self.dut_testpmd.execute_cmd('set vf broadcast 0 0 off') dst_mac = 'FF:FF:FF:FF:FF:FF' out = self.send_and_pmdout(dst_mac) self.verify("received" not in out, "Failed to disable vf broadcast mode!!!") self.dut_testpmd.execute_cmd('set vf broadcast 0 0 on') out = self.send_and_pmdout(dst_mac) self.verify("received" in out, "Failed to enable vf broadcast mode!!!") self.verify("dst=%s" % dst_mac in out, "Failed to enable vf broadcast mode!!!") self.vm0_testpmd.quit() self.dut_testpmd.quit() def test_vf_mtu(self): """ Enable VF MTU change """ self.dut.send_expect("ifconfig %s mtu 9000" % self.tester_intf, "#") self.dut_testpmd.start_testpmd("Default", "--port-topology=chained") self.vm0_testpmd.start_testpmd(VM_CORES_MASK, '--port-topology=chained') self.vf0_mac = self.vm0_testpmd.get_port_mac(0) self.vm0_testpmd.execute_cmd('set fwd mac') self.vm0_testpmd.execute_cmd('set verbose 1') self.vm0_testpmd.execute_cmd('start') pktsize = random.randint(1500, 9000) out = self.send_and_macstrip(self.vf0_mac, 0, pktsize) self.vm0_testpmd.execute_cmd('stop') self.verify(self.vf0_mac.lower() not in out, "Failed to receive and forward this length packet!!!") self.vm0_testpmd.execute_cmd('port stop all') self.vm0_testpmd.execute_cmd('port config mtu 0 %s' % (pktsize + 100)) self.vm0_testpmd.execute_cmd('port start all') self.vm0_testpmd.execute_cmd('start') out = self.send_and_macstrip(self.vf0_mac, 0, pktsize) self.vm0_testpmd.execute_cmd('stop') self.verify(self.vf0_mac.lower() in out, "Failed to receive and forward this length packet!!!") self.vm0_testpmd.quit() self.dut_testpmd.quit() self.dut.send_expect("ifconfig %s mtu 1500" % self.tester_intf, "#") def test_vlan_tag(self): """ Enable/disable vlan tag for a VF from PF """ self.dut_testpmd.start_testpmd("Default", "--port-topology=chained") self.vm0_testpmd.start_testpmd(VM_CORES_MASK, '--port-topology=chained') self.vf0_mac = self.vm0_testpmd.get_port_mac(0) random_vlan = random.randint(1, MAX_VLAN - 1) rx_vlans = [1, random_vlan, MAX_VLAN] self.vm0_testpmd.execute_cmd('set fwd mac') self.vm0_testpmd.execute_cmd('set verbose 1') self.vm0_testpmd.execute_cmd('start') for rx_vlan in rx_vlans: self.vm0_testpmd.execute_cmd('rx_vlan add %s 0' % rx_vlan) self.dut_testpmd.execute_cmd('set vf vlan tag 0 0 off') time.sleep(1) out = self.send_and_macstrip(self.vf0_mac, rx_vlan) self.verify(self.vf0_mac.lower() not in out, "Failed to disable vlan tag!!!") self.dut_testpmd.execute_cmd('set vf vlan tag 0 0 on') time.sleep(1) out = self.send_and_macstrip(self.vf0_mac, rx_vlan) self.verify(self.vf0_mac.lower() in out, "Failed to enable vlan tag!!!") self.vm0_testpmd.quit() self.dut_testpmd.quit() def test_tx_loopback(self): """ Enable/disable TX loopback from PF """ self.dut_testpmd.start_testpmd("Default", "--port-topology=chained") self.vm0_testpmd.start_testpmd(VM_CORES_MASK, '--port-topology=chained') self.vf0_mac = self.vm0_testpmd.get_port_mac(0) self.vm1_testpmd.start_testpmd( VM_CORES_MASK, '--port-topology=chained --eth-peer=0,%s' % self.vf0_mac) self.vm0_testpmd.execute_cmd('set fwd rxonly') self.vm0_testpmd.execute_cmd('set verbose 1') self.vm0_testpmd.execute_cmd('start') self.dut_testpmd.execute_cmd('set tx loopback 0 off') inst = sniff_packets(self.tester_intf, timeout=5) self.vm1_testpmd.execute_cmd('set burst 5') self.vm1_testpmd.execute_cmd('start tx_first') dumpout = self.strip_mac(inst, "dst") out = self.vm0_testpmd.execute_cmd('stop') self.verify(self.vf0_mac.lower() in dumpout, "Failed to disable tx loopback!!!") self.verify("RX-packets: 0" in out, "Failed to disable tx loopback!!!") self.vm0_testpmd.execute_cmd('start') self.dut_testpmd.execute_cmd('set tx loopback 0 on') inst = sniff_packets(self.tester_intf, timeout=5) self.vm1_testpmd.execute_cmd('stop') self.vm1_testpmd.execute_cmd('start tx_first') dumpout = self.strip_mac(inst, "dst") out = self.vm0_testpmd.execute_cmd('stop') self.verify(self.vf0_mac.lower() not in dumpout, "Failed to enable tx loopback!!!") self.verify("RX-packets: 5" in out, "Failed to enable tx loopback!!!") self.vm0_testpmd.quit() self.vm1_testpmd.quit() self.dut_testpmd.quit() def test_all_queues_drop(self): """ Enable/disable drop enable bit for all queues from PF """ self.dut_testpmd.start_testpmd("Default", "--port-topology=chained") self.vm0_testpmd.start_testpmd(VM_CORES_MASK, '--port-topology=chained') self.vm1_testpmd.start_testpmd(VM_CORES_MASK, '--port-topology=chained') self.vm0_testpmd.execute_cmd('set fwd rxonly') self.vm0_testpmd.execute_cmd('set verbose 1') self.vm0_testpmd.execute_cmd('start') self.dut_testpmd.execute_cmd('set all queues drop 0 off') self.vf0_mac = self.vm0_testpmd.get_port_mac(0) self.vf1_mac = self.vm1_testpmd.get_port_mac(0) out = self.send_and_pmdout(self.vf1_mac, 0, 64, 200) out = self.vm1_testpmd.execute_cmd('show port stats 0') self.verify("RX-packets: 127" in out, "Failed to let vf1 full of queues!!!") out = self.send_and_pmdout(self.vf0_mac, 0, 64, 20) out = self.vm0_testpmd.execute_cmd('show port stats 0') self.verify("RX-packets: 0" in out, "Failed to disable all queues drop!!!") self.dut_testpmd.execute_cmd('set all queues drop 0 on') out = self.vm0_testpmd.execute_cmd('show port stats 0') self.verify("RX-packets: 20" in out, "Failed to enable all queues drop!!!") out = self.send_and_pmdout(self.vf0_mac, 0, 64, 20) out = self.vm0_testpmd.execute_cmd('show port stats 0') self.verify("RX-packets: 40" in out, "Failed to enable all queues drop!!!") self.vm0_testpmd.quit() self.vm1_testpmd.quit() self.dut_testpmd.quit() def test_mac_antispoof(self): """ Enable/disable mac anti-spoof for a VF from PF """ fake_mac = '00:11:22:33:44:55' self.vm0_dut.send_expect("sed -i -e '/uint64_t ol_flags = 0;/a " +\ "\struct ether_addr fake_mac = {.addr_bytes = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55},};'" +\ " app/test-pmd/macswap.c", "# ", 30) self.vm0_dut.send_expect("sed -i -e '/ether_addr_copy(&addr, ð_hdr->s_addr);/d' " +\ " app/test-pmd/macswap.c", "# ", 30) self.vm0_dut.send_expect("sed -i -e '/ether_addr_copy(ð_hdr->s_addr, ð_hdr->d_addr);/a " +\ "\ether_addr_copy(&fake_mac, ð_hdr->s_addr);' app/test-pmd/macswap.c", "# ", 30) self.vm0_dut.build_install_dpdk(self.target) self.dut_testpmd.start_testpmd("Default", "--port-topology=chained") self.vm0_testpmd.start_testpmd(VM_CORES_MASK, '--port-topology=chained') self.vf0_mac = self.vm0_testpmd.get_port_mac(0) self.vm0_testpmd.execute_cmd('set fwd macswap') self.dut_testpmd.execute_cmd('set vf mac antispoof 0 0 off') self.vm0_testpmd.execute_cmd('start') dumpout = self.send_and_macstrip(self.vf0_mac) out = self.vm0_testpmd.execute_cmd('stop') self.verify(fake_mac in dumpout, "Failed to disable vf mac anspoof!!!") self.verify("RX-packets: 1" in out, "Failed to receive packet!!!") self.verify("TX-packets: 1" in out, "Failed to disable mac antispoof!!!") self.dut_testpmd.execute_cmd('set vf mac antispoof 0 0 on') out = self.vm0_testpmd.execute_cmd('start') dumpout = self.send_and_macstrip(self.vf0_mac) out = self.vm0_testpmd.execute_cmd('stop') self.verify(fake_mac not in dumpout, "Failed to enable vf mac anspoof!!!") self.verify("RX-packets: 1" in out, "Failed to receive packet!!!") self.verify("TX-packets: 0" in out, "Failed to enable mac antispoof!!!") self.vm0_testpmd.quit() self.dut_testpmd.quit() self.vm0_dut.send_expect("sed -i '/struct ether_addr fake_mac = {.addr_bytes = " +\ "{0x00, 0x11, 0x22, 0x33, 0x44, 0x55},};/d' app/test-pmd/macswap.c", "# ", 30) self.vm0_dut.send_expect("sed -i '/ether_addr_copy(&fake_mac, ð_hdr->s_addr);/d' " +\ "app/test-pmd/macswap.c", "# ", 30) self.vm0_dut.send_expect("sed -i '/ether_addr_copy(ð_hdr->s_addr, ð_hdr->d_addr);/a " +\ "\ether_addr_copy(&addr, ð_hdr->s_addr);' app/test-pmd/macswap.c", "# ", 30) self.vm0_dut.build_install_dpdk(self.target) def test_vf_mac_set(self): """ Set MAC address for a VF from PF """ expect_mac = 'A2:22:33:44:55:66' self.dut_testpmd.start_testpmd("Default", "--port-topology=chained") self.dut_testpmd.execute_cmd('set vf mac addr 0 0 %s' % expect_mac) out = self.vm0_testpmd.start_testpmd(VM_CORES_MASK, '--port-topology=chained') self.verify("%s" % expect_mac in out, "Failed to set vf mac!!!") self.vf0_mac = self.vm0_testpmd.get_port_mac(0) self.vm0_testpmd.execute_cmd('set fwd mac') self.vm0_testpmd.execute_cmd('start') out = self.send_and_macstrip(self.vf0_mac) self.verify(expect_mac.lower() in out, "Failed to receive packet on setted vf mac!!!") self.vm0_testpmd.quit() self.dut_testpmd.quit() def test_vlan_antispoof(self): """ Enable/disable vlan antispoof for a VF from PF """ self.dut_testpmd.start_testpmd("Default", "--port-topology=chained") self.vm0_testpmd.start_testpmd(VM_CORES_MASK, '--port-topology=chained') self.vf0_mac = self.vm0_testpmd.get_port_mac(0) vf0_mac_lower = self.vf0_mac.lower() random_vlan = random.randint(1, MAX_VLAN) match_vlan = random_vlan unmatch_vlan = (random_vlan + 2) % 4096 self.vm0_testpmd.execute_cmd('set fwd mac') self.vm0_testpmd.execute_cmd('start') self.dut_testpmd.execute_cmd('rx_vlan add %d port 0 vf 1' % match_vlan) if self.kdriver == "i40e": self.dut_testpmd.execute_cmd('set vf vlan stripq 0 0 off') else: self.dut_testpmd.execute_cmd('vlan set filter off 0') self.dut_testpmd.execute_cmd('vlan set strip off 0') self.vm0_testpmd.execute_cmd('vlan set strip off 0') self.dut_testpmd.execute_cmd('set vf vlan antispoof 0 0 off') time.sleep(1) out = self.send_and_macstrip(self.vf0_mac, match_vlan) self.verify(vf0_mac_lower in out, "Failed to disable vlan antispoof with match vlan!!!") out = self.send_and_macstrip(self.vf0_mac, unmatch_vlan) self.verify(vf0_mac_lower in out, "Failed to disable vlan antispoof with unmatch vlan!!!") out = self.send_and_macstrip(self.vf0_mac) self.verify(vf0_mac_lower in out, "Failed to disable vlan antispoof with no vlan!!!") if self.kdriver == "ixgbe": self.dut_testpmd.execute_cmd('set vf mac antispoof 0 0 on') self.dut_testpmd.execute_cmd('set vf vlan antispoof 0 0 on') time.sleep(1) out = self.send_and_macstrip(self.vf0_mac, match_vlan) self.verify(vf0_mac_lower in out, "Failed to enable vlan antispoof with match vlan!!!") out = self.send_and_macstrip(self.vf0_mac, unmatch_vlan) self.verify(vf0_mac_lower not in out, "Failed to enable vlan antispoof with unmatch vlan!!!") out = self.send_and_macstrip(self.vf0_mac) self.verify(vf0_mac_lower not in out, "Failed to enable vlan antispoof with no vlan!!!") self.vm0_testpmd.quit() self.dut_testpmd.quit() def test_vlan_strip(self): """ Enable/disable the VLAN strip for all queues in a pool for a VF from PF """ self.dut_testpmd.start_testpmd("Default", "--port-topology=chained") self.vm0_testpmd.start_testpmd(VM_CORES_MASK, '--port-topology=chained') self.vf0_mac = self.vm0_testpmd.get_port_mac(0) random_vlan = random.randint(1, MAX_VLAN - 1) rx_vlans = [1, random_vlan, MAX_VLAN] self.vm0_testpmd.execute_cmd('set fwd mac') self.vm0_testpmd.execute_cmd('set verbose 1') self.vm0_testpmd.execute_cmd('start') for rx_vlan in rx_vlans: self.vm0_testpmd.execute_cmd('rx_vlan add %s 0' % rx_vlan) self.dut_testpmd.execute_cmd('set vf vlan stripq 0 0 off') time.sleep(1) out = self.send_and_vlanstrip(self.vf0_mac, rx_vlan) self.verify(rx_vlan in out, "Failed to disable strip vlan!!!") self.dut_testpmd.execute_cmd('set vf vlan stripq 0 0 on') time.sleep(1) out = self.send_and_vlanstrip(self.vf0_mac, rx_vlan) self.verify(rx_vlan not in out, "Failed to disable strip vlan!!!") self.vm0_testpmd.quit() self.dut_testpmd.quit() def test_vlan_filter(self): """ Add/Remove vlan filter for a VF from PF """ self.dut_testpmd.start_testpmd("Default", "--port-topology=chained") self.vm0_testpmd.start_testpmd(VM_CORES_MASK, '--port-topology=chained') self.vm0_testpmd.execute_cmd('set fwd rxonly') self.vm0_testpmd.execute_cmd('set verbose 1') self.vm0_testpmd.execute_cmd('start') wrong_mac = '9E:AC:72:49:43:11' out = self.send_and_pmdout(wrong_mac) self.verify("dst=%s" % wrong_mac in out, "Failed to receive untagged packet!!!") random_vlan = random.randint(1, MAX_VLAN) out = self.send_and_pmdout(wrong_mac, random_vlan) self.verify("dst=%s" % wrong_mac in out, "Failed to receive packet with vlan id!!!") self.verify("VLAN tci=%s" % hex(random_vlan) in out, "Failed to receive packet with vlan id!!!") random_vlan = random.randint(2, MAX_VLAN - 1) rx_vlans = [1, random_vlan, MAX_VLAN] for rx_vlan in rx_vlans: self.dut_testpmd.execute_cmd('rx_vlan add %s port 0 vf 1' % rx_vlan) time.sleep(1) out = self.send_and_pmdout(wrong_mac, rx_vlan) self.verify("dst=%s" % wrong_mac in out, "Failed to enable vlan filter!!!") self.verify("VLAN tci=%s" % hex(rx_vlan) in out, "Failed to receive packet with vlan id!!!") wrong_rx_vlan = (rx_vlan + 1) % 4096 #Packet for vlan id 0 is equal to untagged packet for this case if wrong_rx_vlan == 0: wrong_rx_vlan = random.randint(1, MAX_VLAN - 1) out = self.send_and_pmdout(wrong_mac, wrong_rx_vlan) self.verify("dst=%s" % wrong_mac not in out, "Failed to enable vlan filter!!!") self.dut_testpmd.execute_cmd('rx_vlan rm %s port 0 vf 1' % rx_vlan) out = self.send_and_pmdout(wrong_mac, rx_vlan) self.verify("dst=%s" % wrong_mac in out, "Failed to disable vlan filter!!!") self.verify("VLAN tci=%s" % hex(rx_vlan) in out, "Failed to receive packet with vlan id!!!") out = self.send_and_pmdout(wrong_mac, wrong_rx_vlan) self.verify("dst=%s" % wrong_mac in out, "Failed to disable vlan filter!!!") self.verify("VLAN tci=%s" % hex(wrong_rx_vlan) in out, "Failed to receive packet with vlan id!!!") out = self.send_and_pmdout(wrong_mac) self.verify("dst=%s" % wrong_mac in out, "Failed to receive untagged packet!!!") self.vm0_testpmd.quit() self.dut_testpmd.quit() def tear_down(self): self.vm0_dut.kill_all() self.vm1_dut.kill_all() pass def tear_down_all(self): self.destroy_vm_env() pass
class TestMacFilter(TestCase): def set_up_all(self): """ Run at the start of each test suite. Whitelist Prerequisites: Two Ports testpmd can normally started """ self.frames_to_send = 1 # Based on h/w type, choose how many ports to use self.dutPorts = self.dut.get_ports() # Verify that enough ports are available self.verify(len(self.dutPorts) >= 1, "Insufficient ports") portMask = utils.create_mask(self.dutPorts[:1]) self.pmdout = PmdOutput(self.dut) self.pmdout.start_testpmd("Default", "--portmask=%s" % portMask) self.dut.send_expect("set verbose 1", "testpmd> ") self.dut.send_expect("set fwd rxonly", "testpmd> ") self.dut.send_expect("start", "testpmd> ") # get dest address from self.target port out = self.dut.send_expect("show port info %d" % self.dutPorts[0], "testpmd> ") self.dest = self.dut.get_mac_address(self.dutPorts[0]) mac_scanner = r"MAC address: (([\dA-F]{2}:){5}[\dA-F]{2})" ret = utils.regexp(out, mac_scanner) self.verify(ret is not None, "MAC address not found") self.verify(cmp(ret.lower(), self.dest) == 0, "MAC address wrong") self.max_mac_addr = utils.regexp(out, "Maximum number of MAC addresses: ([0-9]+)") def set_up(self): """ Run before each test case. Nothing to do. """ pass def whitelist_send_packet(self, portid, destMac="00:11:22:33:44:55"): """ Send 1 packet to portid. """ 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) def test_add_remove_mac_address(self): """ Add mac address and check packet can received Remove mac address and check packet can't received """ # initialise first port without promiscuous mode fake_mac_addr = "00:01:01:00:00:00" portid = self.dutPorts[0] self.dut.send_expect("set promisc %d off" % portid, "testpmd> ") self.dut.send_expect("clear port stats all", "testpmd> ") # send one packet with the portid MAC address self.whitelist_send_packet(portid, self.dest) # Niantic and FVL have different packet statistics when using the # "show port stats" command. Packets number is stripped from log. out = self.dut.get_session_output() cur_rxpkt = utils.regexp(out, "received ([0-9]+) packets") # check the packet increase self.verify(int(cur_rxpkt) == self.frames_to_send, "Packet has not been received on default address") # send one packet to a different MAC address # new_mac = self.dut.get_mac_address(portid) self.whitelist_send_packet(portid, fake_mac_addr) out = self.dut.get_session_output() # check the packet DO NOT increase self.verify("received" not in out, "Packet has been received on a new MAC address that has not been added yet") # add the different MAC address self.dut.send_expect("mac_addr add %d" % portid + " %s" % fake_mac_addr, "testpmd>") # send again one packet to a different MAC address self.whitelist_send_packet(portid, fake_mac_addr) out = self.dut.get_session_output() cur_rxpkt = utils.regexp(out, "received ([0-9]+) packets") # check the packet increase self.verify(int(cur_rxpkt) == self.frames_to_send, "Packet has not been received on a new MAC address that has been added to the port") # remove the fake MAC address self.dut.send_expect("mac_addr remove %d" % portid + " %s" % fake_mac_addr, "testpmd>") # send again one packet to a different MAC address self.whitelist_send_packet(portid, fake_mac_addr) out = self.dut.get_session_output() # check the packet increase self.verify("received" not in out, "Packet has been received on a new MAC address that has been removed from the port") self.dut.send_expect("stop", "testpmd> ") def test_invalid_addresses(self): """ Invalid operation: Add NULL MAC should not be added Remove using MAC will be failed Add Same MAC twice will be failed Add more than MAX number will be failed """ portid = self.dutPorts[0] fake_mac_addr = "00:00:00:00:00:00" # add an address with all zeroes to the port (-EINVAL) out = self.dut.send_expect("mac_addr add %d" % portid + " %s" % fake_mac_addr, "testpmd>") self.verify("Invalid argument" in out, "Added a NULL MAC address") # remove the default MAC address (-EADDRINUSE) out = self.dut.send_expect("mac_addr remove %d" % portid + " %s" % self.dest, "testpmd>") self.verify("Address already in use" in out, "default address removed") # add same address 2 times fake_mac_addr = "00:00:00:00:00:01" out = self.dut.send_expect("mac_addr add %d" % portid + " %s" % fake_mac_addr, "testpmd>") out = self.dut.send_expect("mac_addr add %d" % portid + " %s" % fake_mac_addr, "testpmd>") self.verify("error" not in out, "added 2 times the same address with an error") # add 1 address more that max number i = 0 base_addr = "00:01:00:00:00:" while i <= int(self.max_mac_addr): new_addr = base_addr + "%0.2X" % i out = self.dut.send_expect("mac_addr add %d" % portid + " %s" % new_addr, "testpmd>") i = i + 1 self.verify("No space left on device" in out, "added 1 address more than max MAC addresses") def tear_down(self): """ Run after each test case. Nothing to do. """ pass def tear_down_all(self): """ Run after each test suite. """ self.dut.send_expect("quit", "# ", 10)
class TestDynamicQueue(TestCase): def set_up_all(self): self.dut_ports = self.dut.get_ports(self.nic) self.verify(len(self.dut_ports) >= 1, "Insufficient ports") out = self.dut.send_expect("cat config/common_base", "]# ", 10) self.PF_Q_strip = 'CONFIG_RTE_LIBRTE_I40E_QUEUE_NUM_PER_PF' pattern = "%s=(\d*)" % self.PF_Q_strip self.PF_QUEUE = self.element_strip(out, pattern) self.used_dut_port = self.dut_ports[0] tester_port = self.tester.get_local_port(self.used_dut_port) self.tester_intf = self.tester.get_interface(tester_port) self.dut_testpmd = PmdOutput(self.dut) def set_up(self): # Because of fortville spirit limitation,can't use 2 ports for testing if (self.nic in ["fortville_spirit"]): self.dut_testpmd.start_testpmd( "Default", "--port-topology=chained --txq=%s --rxq=%s" % (self.PF_QUEUE, self.PF_QUEUE), eal_param="-w %s" % (self.dut.get_port_pci(self.dut_ports[0]))) elif (self.nic in ["cavium_a063"]): eal_opts = "" for port in self.dut_ports: eal_opts += "-w %s,max_pools=256 " % (self.dut.get_port_pci( self.dut_ports[port])) self.dut_testpmd.start_testpmd( "Default", "--port-topology=chained --txq=%s --rxq=%s" % (self.PF_QUEUE, self.PF_QUEUE), eal_param=eal_opts) else: self.dut_testpmd.start_testpmd( "Default", "--port-topology=chained --txq=%s --rxq=%s" % (self.PF_QUEUE, self.PF_QUEUE)) def element_strip(self, out, pattern): """ Strip and get queue number. """ s = re.compile(pattern, re.DOTALL) res = s.search(out) if res is None: print utils.RED('Fail to search number.') return None else: result = res.group(1) return int(result) def send_packet(self): """ Generate packets and send them to dut """ mac = self.dut.get_mac_address(0) for i in range(self.PF_QUEUE * 2): pkt = Packet(pkt_type='IP_RAW') pkt.config_layer('ether', {'dst': mac}) pkt.config_layer('ipv4', { 'dst': '192.168.0.%d' % i, 'src': '191.168.0.1' }) pkt.send_pkt(tx_port=self.tester_intf) def rxq_setup_test(self, chgflag=0): """ Dynamic to setup rxq and reconfigure ring size at runtime. chgflag: reconfigure ring size flag 1: reconfigure Rx ring size 0: no change on Rx ring size """ queue = list() for i in range(test_loop): queue.append(random.randint(1, self.PF_QUEUE - 1)) self.dut_testpmd.execute_cmd('port 0 rxq %d stop' % queue[i]) self.dut_testpmd.execute_cmd('set fwd rxonly') self.dut_testpmd.execute_cmd('start') self.send_packet() self.dut.get_session_output(timeout=10) out = self.dut_testpmd.execute_cmd('stop') # Check Rx stopped queues can't receive packets for i in range(test_loop): self.verify( "Forward Stats for RX Port= 0/Queue=%2d" % queue[i] not in out, "Fail to verify rxq stop!") if chgflag == 1: for i in range(test_loop): out = self.dut_testpmd.execute_cmd('show rxq info 0 %d' % queue[i]) qring_strip = 'Number of RXDs: ' pattern = "%s([0-9]+)" % qring_strip qringsize = self.element_strip(out, pattern) chg_qringsize = qringsize % 1024 + 256 self.dut_testpmd.execute_cmd( 'port config 0 rxq %d ring_size %d' % (queue[i], chg_qringsize)) self.dut_testpmd.execute_cmd('port 0 rxq %d setup' % queue[i]) out = self.dut_testpmd.execute_cmd('show rxq info 0 %d' % queue[i]) chk_qringsize = self.element_strip(out, pattern) self.verify(chk_qringsize == chg_qringsize, "Fail to change ring size at runtime!") for i in range(test_loop): if chgflag == 0: self.dut_testpmd.execute_cmd('port 0 rxq %d setup' % queue[i]) self.dut_testpmd.execute_cmd('port 0 rxq %d start' % queue[i]) self.dut_testpmd.execute_cmd('start') self.send_packet() self.dut.get_session_output(timeout=10) out = self.dut_testpmd.execute_cmd('stop') # Check Rx setup queues could receive packets for i in range(test_loop): self.verify( "Forward Stats for RX Port= 0/Queue=%2d" % queue[i] in out, "Fail to setup rxq %d at runtime" % queue[i]) def txq_setup_test(self, chgflag=0): """ Dynamic to setup txq and reconfigure ring size at runtime. chgflag: reconfigure ring size flag 1: reconfigure Tx ring size 0: no change on Tx ring size """ for i in range(test_loop): queue = random.randint(1, self.PF_QUEUE - 1) out = self.dut_testpmd.execute_cmd('show txq info 0 %d' % queue) qring_strip = 'Number of TXDs: ' pattern = "%s([0-9]+)" % qring_strip qringsize = self.element_strip(out, pattern) self.dut_testpmd.execute_cmd('port 0 txq %d stop' % queue) self.dut_testpmd.execute_cmd('set fwd txonly') self.dut_testpmd.execute_cmd('start') time.sleep(10) out = self.dut_testpmd.execute_cmd('stop') tx_num = qringsize - 1 # Check Tx stopped queue only transmits qringsize-1 packets self.verify("TX-packets: %d" % tx_num in out, "Fail to stop txq at runtime") if chgflag == 1: chg_qringsize = qringsize % 1024 + 256 self.dut_testpmd.execute_cmd( 'port config 0 txq %d ring_size %d' % (queue, chg_qringsize)) self.dut_testpmd.execute_cmd('port 0 txq %d setup' % queue) out = self.dut_testpmd.execute_cmd('show txq info 0 %d' % queue) chk_qringsize = self.element_strip(out, pattern) self.verify(chk_qringsize == chg_qringsize, "Fail to change ring size at runtime!") if chgflag == 0: self.dut_testpmd.execute_cmd('port 0 txq %d setup' % queue) self.dut_testpmd.execute_cmd('port 0 txq %d start' % queue) self.dut_testpmd.execute_cmd('start') time.sleep(10) out = self.dut_testpmd.execute_cmd('stop') """ Check Tx setup queue could transmit packets normally, not only qringsize-1 packets """ self.verify("TX-packets: %d" % tx_num not in out, "Fail to setup txq at runtime") if chgflag == 1: chgtx_num = chg_qringsize - 1 self.verify("TX-packets: %d" % chgtx_num not in out, "Fail to change txq ring size at runtime") def test_rxq_setup(self): """ Dynamic to setup rxq test """ self.rxq_setup_test() def test_rxq_chgring_setup(self): """ Dynamic to setup rxq and change ring size test """ self.rxq_setup_test(chgflag=1) def test_txq_setup(self): """ Dynamic to setup txq test """ self.txq_setup_test() def test_txq_chgring_setup(self): """ Dynamic to setup txq and change ring size test """ self.txq_setup_test(chgflag=1) def tear_down(self): self.dut_testpmd.quit() def tear_down_all(self): pass
class TestVfVlan(TestCase): supported_vf_driver = ['pci-stub', 'vfio-pci'] def set_up_all(self): self.dut_ports = self.dut.get_ports(self.nic) self.verify(len(self.dut_ports) > 1, "Insufficient ports") self.vm0 = None self.env_done = False # set vf assign method and vf driver self.vf_driver = self.get_suite_cfg()['vf_driver'] if self.vf_driver is None: self.vf_driver = 'pci-stub' self.verify(self.vf_driver in self.supported_vf_driver, "Unspported vf driver") if self.vf_driver == 'pci-stub': self.vf_assign_method = 'pci-assign' else: self.vf_assign_method = 'vfio-pci' self.dut.send_expect('modprobe vfio-pci', '#') def set_up(self): self.setup_vm_env() def bind_nic_driver(self, ports, driver=""): # modprobe vfio driver if driver == "vfio-pci": for port in ports: netdev = self.dut.ports_info[port]['port'] driver = netdev.get_nic_driver() if driver != 'vfio-pci': netdev.bind_driver(driver='vfio-pci') elif driver == "igb_uio": # igb_uio should insmod as default, no need to check for port in ports: netdev = self.dut.ports_info[port]['port'] driver = netdev.get_nic_driver() if driver != 'igb_uio': netdev.bind_driver(driver='igb_uio') else: for port in ports: netdev = self.dut.ports_info[port]['port'] driver_now = netdev.get_nic_driver() if driver == "": driver = netdev.default_driver if driver != driver_now: netdev.bind_driver(driver=driver) def setup_vm_env(self, driver='default'): """ Create testing environment with 2VFs generated from 2PFs """ if self.env_done: return # bind to default driver self.bind_nic_driver(self.dut_ports[:2], driver="") self.used_dut_port_0 = self.dut_ports[0] self.host_intf0 = self.dut.ports_info[self.used_dut_port_0]['intf'] tester_port = self.tester.get_local_port(self.used_dut_port_0) self.tester_intf0 = self.tester.get_interface(tester_port) self.dut.generate_sriov_vfs_by_port(self.used_dut_port_0, 1, driver=driver) self.sriov_vfs_port_0 = self.dut.ports_info[ self.used_dut_port_0]['vfs_port'] self.vf0_mac = "00:10:00:00:00:00" self.dut.send_expect( "ip link set %s vf 0 mac %s" % (self.host_intf0, self.vf0_mac), "# ") self.used_dut_port_1 = self.dut_ports[1] self.host_intf1 = self.dut.ports_info[self.used_dut_port_1]['intf'] self.dut.generate_sriov_vfs_by_port(self.used_dut_port_1, 1, driver=driver) self.sriov_vfs_port_1 = self.dut.ports_info[ self.used_dut_port_1]['vfs_port'] tester_port = self.tester.get_local_port(self.used_dut_port_1) self.tester_intf1 = self.tester.get_interface(tester_port) self.vf1_mac = "00:20:00:00:00:00" self.dut.send_expect( "ip link set %s vf 0 mac %s" % (self.host_intf1, self.vf1_mac), "# ") try: for port in self.sriov_vfs_port_0: port.bind_driver(self.vf_driver) for port in self.sriov_vfs_port_1: port.bind_driver(self.vf_driver) time.sleep(1) vf0_prop = {'opt_host': self.sriov_vfs_port_0[0].pci} vf1_prop = {'opt_host': self.sriov_vfs_port_1[0].pci} # set up VM0 ENV self.vm0 = VM(self.dut, 'vm0', 'vf_vlan') self.vm0.set_vm_device(driver=self.vf_assign_method, **vf0_prop) self.vm0.set_vm_device(driver=self.vf_assign_method, **vf1_prop) self.vm_dut_0 = self.vm0.start() if self.vm_dut_0 is None: raise Exception("Set up VM0 ENV failed!") except Exception as e: self.destroy_vm_env() raise Exception(e) self.env_done = True def destroy_vm_env(self): if getattr(self, 'vm0', None): if getattr(self, 'vm_dut_0', None): self.vm_dut_0.kill_all() self.vm0_testpmd = None self.vm0_dut_ports = None # destroy vm0 self.vm0.stop() self.dut.virt_exit() self.vm0 = None if getattr(self, 'used_dut_port_0', None) != None: self.dut.destroy_sriov_vfs_by_port(self.used_dut_port_0) port = self.dut.ports_info[self.used_dut_port_0]['port'] self.used_dut_port_0 = None if getattr(self, 'used_dut_port_1', None) != None: self.dut.destroy_sriov_vfs_by_port(self.used_dut_port_1) port = self.dut.ports_info[self.used_dut_port_1]['port'] self.used_dut_port_1 = None self.bind_nic_driver(self.dut_ports[:2], driver='default') self.env_done = False def test_pvid_vf_tx(self): """ Add port based vlan on vf device and check vlan tx work """ random_vlan = random.randint(1, MAX_VLAN) self.dut.send_expect( "ip link set %s vf 0 vlan %d" % (self.host_intf0, random_vlan), "# ") out = self.dut.send_expect("ip link show %s" % self.host_intf0, "# ") self.verify("vlan %d" % random_vlan in out, "Failed to add pvid on VF0") self.vm0_dut_ports = self.vm_dut_0.get_ports('any') self.vm0_testpmd = PmdOutput(self.vm_dut_0) self.vm0_testpmd.start_testpmd(VM_CORES_MASK) self.vm0_testpmd.execute_cmd('set fwd mac') self.vm0_testpmd.execute_cmd('start') 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) pkts = self.tester.load_tcpdump_sniff_packets(inst) self.verify(len(pkts), "Not receive expected packet") self.vm0_testpmd.quit() # disable pvid self.dut.send_expect("ip link set %s vf 0 vlan 0" % (self.host_intf0), "# ") def send_and_getout(self, vlan=0, pkt_type="UDP"): if pkt_type == "UDP": pkt = Packet(pkt_type='UDP') pkt.config_layer('ether', {'dst': self.vf0_mac}) elif pkt_type == "VLAN_UDP": pkt = Packet(pkt_type='VLAN_UDP') pkt.config_layer('vlan', {'vlan': vlan}) pkt.config_layer('ether', {'dst': self.vf0_mac}) pkt.send_pkt(tx_port=self.tester_intf0) out = self.vm_dut_0.get_session_output(timeout=2) return out def test_add_pvid_vf(self): random_vlan = random.randint(1, MAX_VLAN) self.dut.send_expect( "ip link set %s vf 0 vlan %d" % (self.host_intf0, random_vlan), "# ") out = self.dut.send_expect("ip link show %s" % self.host_intf0, "# ") self.verify("vlan %d" % random_vlan in out, "Failed to add pvid on VF0") # start testpmd in VM self.vm0_dut_ports = self.vm_dut_0.get_ports('any') self.vm0_testpmd = PmdOutput(self.vm_dut_0) self.vm0_testpmd.start_testpmd(VM_CORES_MASK) self.vm0_testpmd.execute_cmd('set fwd rxonly') self.vm0_testpmd.execute_cmd('set verbose 1') self.vm0_testpmd.execute_cmd('start') out = self.send_and_getout(vlan=random_vlan, pkt_type="VLAN_UDP") self.verify("received" in out, "Failed to received vlan packet!!!") # send packet without vlan out = self.send_and_getout(pkt_type="UDP") self.verify("received" not in out, "Received packet without vlan!!!") # send packet with vlan not matched wrong_vlan = (random_vlan + 1) % 4096 out = self.send_and_getout(vlan=wrong_vlan, pkt_type="VLAN_UDP") self.verify("received" not in out, "Received pacekt with wrong vlan!!!") # remove vlan self.dut.send_expect("ip link set %s vf 0 vlan 0" % self.host_intf0, "# ") # send packet with vlan out = self.send_and_getout(vlan=random_vlan, pkt_type="VLAN_UDP") if self.kdriver == "i40e": self.verify("received" in out, "Failed to received vlan packet!!!") else: self.verify("received" not in out, "Received vlan packet without pvid!!!") # send packet with vlan 0 out = self.send_and_getout(vlan=0, pkt_type="VLAN_UDP") self.verify("received" in out, "Not recevied packet with vlan 0!!!") # send packet without vlan out = self.send_and_getout(vlan=0, pkt_type="UDP") self.verify("received" in out, "Not received packet without vlan!!!") self.vm0_testpmd.quit() # disable pvid self.dut.send_expect("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) self.vm0_testpmd.execute_cmd('set burst 1') self.vm0_testpmd.execute_cmd('start tx_first') self.vm0_testpmd.execute_cmd('stop') # strip sniffered vlans pkts = self.tester.load_tcpdump_sniff_packets(inst) vlans = [] for pkt in pkts: vlan = pkt.strip_element_vlan("vlan") vlans.append(vlan) self.verify(tx_vlan in vlans, "Tx packet with vlan not received!!!") def test_vf_vlan_tx(self): self.verify(self.kdriver not in ["ixgbe"], "NIC Unsupported: " + str(self.nic)) random_vlan = random.randint(1, MAX_VLAN) tx_vlans = [1, random_vlan, MAX_VLAN] # start testpmd in VM self.vm0_dut_ports = self.vm_dut_0.get_ports('any') self.vm0_testpmd = PmdOutput(self.vm_dut_0) self.vm0_testpmd.start_testpmd(VM_CORES_MASK) self.vm0_testpmd.execute_cmd('set verbose 1') for tx_vlan in tx_vlans: # for fortville , # if you want insert tx_vlan, # please enable rx_vlan at the same time if self.kdriver == "i40e": self.vm0_testpmd.execute_cmd('rx_vlan add %d 0' % tx_vlan) self.vm0_testpmd.execute_cmd('stop') self.vm0_testpmd.execute_cmd('port stop all') self.vm0_testpmd.execute_cmd('tx_vlan set 0 %d' % tx_vlan) self.vm0_testpmd.execute_cmd('port start all') self.tx_and_check(tx_vlan=tx_vlan) self.vm0_testpmd.quit() def test_vf_vlan_rx(self): random_vlan = random.randint(1, MAX_VLAN - 1) rx_vlans = [1, random_vlan, MAX_VLAN] # start testpmd in VM self.vm0_dut_ports = self.vm_dut_0.get_ports('any') self.vm0_testpmd = PmdOutput(self.vm_dut_0) self.vm0_testpmd.start_testpmd(VM_CORES_MASK) self.vm0_testpmd.execute_cmd('set fwd rxonly') self.vm0_testpmd.execute_cmd('set verbose 1') self.vm0_testpmd.execute_cmd('vlan set strip on 0') self.vm0_testpmd.execute_cmd('vlan set filter on 0') self.vm0_testpmd.execute_cmd("set promisc all off") self.vm0_testpmd.execute_cmd('start') # send packet without vlan out = self.send_and_getout(vlan=0, pkt_type="UDP") self.verify("received 1 packets" in out, "Not received normal packet as default!!!") # send packet with vlan 0 out = self.send_and_getout(vlan=0, pkt_type="VLAN_UDP") self.verify("VLAN tci=0x0" in out, "Not received vlan 0 packet as default!!!") for rx_vlan in rx_vlans: self.vm0_testpmd.execute_cmd('rx_vlan add %d 0' % rx_vlan) time.sleep(1) # send packet with same vlan out = self.send_and_getout(vlan=rx_vlan, pkt_type="VLAN_UDP") vlan_hex = hex(rx_vlan) self.verify("VLAN tci=%s" % vlan_hex in out, "Not received expected vlan packet!!!") pkt = Packet(pkt_type='VLAN_UDP') if rx_vlan == MAX_VLAN: continue wrong_vlan = (rx_vlan + 1) % 4096 # send packet with wrong vlan out = self.send_and_getout(vlan=wrong_vlan, pkt_type="VLAN_UDP") self.verify("received 1 packets" not in out, "Received filtered vlan packet!!!") for rx_vlan in rx_vlans: self.vm0_testpmd.execute_cmd('rx_vlan rm %d 0' % rx_vlan) # send packet with vlan 0 out = self.send_and_getout(vlan=0, pkt_type="VLAN_UDP") self.verify("VLAN tci=0x0" in out, "Not received vlan 0 packet as default!!!") # send packet without vlan out = self.send_and_getout(pkt_type="UDP") self.verify("received 1 packets" in out, "Not received normal packet after remove vlan filter!!!") # send packet with vlan out = self.send_and_getout(vlan=random_vlan, pkt_type="VLAN_UDP") if self.kdriver == "i40e": self.verify( "received 1 packets" in out, "Received mismatched vlan packet while vlan filter on") else: self.verify( "received 1 packets" not in out, "Received mismatched vlan packet while vlan filter on") self.vm0_testpmd.quit() def test_vf_vlan_strip(self): random_vlan = random.randint(1, MAX_VLAN - 1) rx_vlans = [1, random_vlan, MAX_VLAN] # start testpmd in VM self.vm0_dut_ports = self.vm_dut_0.get_ports('any') self.vm0_testpmd = PmdOutput(self.vm_dut_0) if self.kdriver == "i40e": self.vm0_testpmd.start_testpmd(VM_CORES_MASK, '') else: self.vm0_testpmd.start_testpmd(VM_CORES_MASK) self.vm0_testpmd.execute_cmd('set fwd rxonly') self.vm0_testpmd.execute_cmd('set verbose 1') self.vm0_testpmd.execute_cmd('start') for rx_vlan in rx_vlans: self.vm0_testpmd.execute_cmd('vlan set strip on 0') self.vm0_testpmd.execute_cmd('vlan set filter on 0') self.vm0_testpmd.execute_cmd('rx_vlan add %d 0' % rx_vlan) time.sleep(1) out = self.send_and_getout(vlan=rx_vlan, pkt_type="VLAN_UDP") # enable strip, vlan will be in mbuf vlan_hex = hex(rx_vlan) self.verify("VLAN tci=%s" % vlan_hex in out, "Failed to strip vlan packet!!!") self.verify("PKT_RX_VLAN_STRIPPED" in out, "Failed to strip vlan packet!") self.vm0_testpmd.execute_cmd('vlan set strip off 0') out = self.send_and_getout(vlan=rx_vlan, pkt_type="VLAN_UDP") self.verify("received 1 packets" in out, "Not received vlan packet as expected!!!") self.verify("PKT_RX_VLAN_STRIPPED" not in out, "Failed to disable strip vlan!!!") self.vm0_testpmd.quit() def tear_down(self): self.destroy_vm_env() def tear_down_all(self): self.destroy_vm_env() pass
class TestVfJumboFrame(TestCase): supported_vf_driver = ['pci-stub', 'vfio-pci'] def set_up_all(self): self.dut_ports = self.dut.get_ports(self.nic) self.verify(len(self.dut_ports) >= 1, "Insufficient ports") self.vm0 = None self.env_done = False self.port = self.dut_ports[0] self.vm_port = 0 cores = self.dut.get_core_list("1S/1C/1T") self.port_mask = utils.create_mask([self.port]) # set vf assign method and vf driver self.dut.send_expect('modprobe vfio-pci', '#') self.vf_driver = self.get_suite_cfg()['vf_driver'] if self.vf_driver is None: self.vf_driver = 'pci-stub' self.verify(self.vf_driver in self.supported_vf_driver, "Unspported vf driver") if self.vf_driver == 'pci-stub': self.vf_assign_method = 'pci-assign' else: self.vf_assign_method = 'vfio-pci' self.dut.send_expect('modprobe vfio-pci', '#') # enable tester mtu tester_port = self.tester.get_local_port(self.port) self.netobj = self.tester.ports_info[tester_port]['port'] self.netobj.enable_jumbo(framesize=ETHER_JUMBO_FRAME_MTU + 100) def set_up(self): self.setup_vm_env() def bind_nic_driver(self, ports, driver=""): # modprobe vfio driver if driver == "vfio-pci": for port in ports: netdev = self.dut.ports_info[port]['port'] driver = netdev.get_nic_driver() if driver != 'vfio-pci': netdev.bind_driver(driver='vfio-pci') elif driver == "igb_uio": # igb_uio should insmod as default, no need to check for port in ports: netdev = self.dut.ports_info[port]['port'] driver = netdev.get_nic_driver() if driver != 'igb_uio': netdev.bind_driver(driver='igb_uio') else: for port in ports: netdev = self.dut.ports_info[port]['port'] driver_now = netdev.get_nic_driver() if driver == None: driver = netdev.default_driver if driver != driver_now: netdev.bind_driver(driver=driver) def setup_vm_env(self, driver='default'): """ Create testing environment with 1VF generated from 1PF """ if self.env_done: return # bind to default driver self.bind_nic_driver(self.dut_ports[:1], driver="") self.used_dut_port = self.dut_ports[0] self.host_intf = self.dut.ports_info[self.used_dut_port]['intf'] tester_port = self.tester.get_local_port(self.used_dut_port) self.tester_intf = self.tester.get_interface(tester_port) self.dut.generate_sriov_vfs_by_port(self.used_dut_port, 1, driver=driver) self.sriov_vfs_port = self.dut.ports_info[ self.used_dut_port]['vfs_port'] self.vf_mac = "00:10:00:00:00:00" self.dut.send_expect( "ip link set %s vf 0 mac %s" % (self.host_intf, self.vf_mac), "# ") try: for port in self.sriov_vfs_port: port.bind_driver(self.vf_driver) time.sleep(1) vf_popt = {'opt_host': self.sriov_vfs_port[0].pci} # set up VM ENV self.vm = QEMUKvm(self.dut, 'vm0', 'vf_jumboframe') self.vm.set_vm_device(driver=self.vf_assign_method, **vf_popt) self.vm_dut = self.vm.start() if self.vm_dut is None: raise Exception("Set up VM ENV failed!") TESTPMD_MAIN = "app/test-pmd/testpmd.c" if self.kdriver == "ixgbe": self.vm_dut.send_expect( "sed -i -e 's/.jumbo_frame = .*$/.jumbo_frame = 1,/g' %s" % TESTPMD_MAIN, "# ") self.vm_dut.build_install_dpdk(self.target) self.vm_testpmd = PmdOutput(self.vm_dut) except Exception as e: self.destroy_vm_env() raise Exception(e) self.env_done = True def destroy_vm_env(self): if getattr(self, 'vm', None): if getattr(self, 'vm_dut', None): self.vm_dut.kill_all() self.vm_testpmd = None self.vm_dut_ports = None # destroy vm0 self.vm.stop() self.dut.virt_exit() time.sleep(3) self.vm = None if getattr(self, 'used_dut_port', None) != None: self.dut.destroy_sriov_vfs_by_port(self.used_dut_port) self.used_dut_port = None self.bind_nic_driver(self.dut_ports[:1], driver='default') self.env_done = False def jumboframes_get_stat(self, portid, rx_tx): """ Get packets number from port statistic """ stats = self.vm_testpmd.get_pmd_stats(portid) if rx_tx == "rx": return [stats['RX-packets'], stats['RX-errors'], stats['RX-bytes']] elif rx_tx == "tx": return [stats['TX-packets'], stats['TX-errors'], stats['TX-bytes']] else: return None def jumboframes_send_packet(self, pktsize, received=True): """ Send 1 packet to portid """ tx_pkts_ori, _, tx_bytes_ori = [ int(_) for _ in self.jumboframes_get_stat(self.vm_port, "tx") ] rx_pkts_ori, rx_err_ori, rx_bytes_ori = [ int(_) for _ in self.jumboframes_get_stat(self.vm_port, "rx") ] mac = self.vm_dut.get_mac_address(self.vm_port) pkt = Packet(pkt_type='UDP', pkt_len=pktsize) pkt.config_layer('ether', {'dst': mac}) pkt.send_pkt(tx_port=self.tester_intf) time.sleep(1) tx_pkts, _, tx_bytes = [ int(_) for _ in self.jumboframes_get_stat(self.port, "tx") ] rx_pkts, rx_err, rx_bytes = [ int(_) for _ in self.jumboframes_get_stat(self.vm_port, "rx") ] tx_pkts -= tx_pkts_ori tx_bytes -= tx_bytes_ori rx_pkts -= rx_pkts_ori rx_bytes -= rx_bytes_ori rx_err -= rx_err_ori if received: self.verify((rx_pkts == 1) and (tx_pkts == 1), "Packet forward assert error") if self.kdriver == "ixgbe": self.verify((rx_bytes + 4) == pktsize, "Rx packet size should be packet size - 4") else: self.verify(rx_bytes == pktsize, "Tx packet size should be equal to packet size") if self.kdriver == "igb": self.verify(tx_bytes == pktsize, "Tx packet size should be packet size") else: self.verify((tx_bytes + 4) == pktsize, "Tx packet size should be packet size - 4") else: self.verify(rx_err == 1 or tx_pkts == 0, "Packet drop assert error") def test_vf_normal_nojumbo(self): """ This case aims to test transmitting normal size packet without jumbo enable """ # should enable jumbo on host self.dutobj = self.dut.ports_info[self.port]['port'] self.dutobj.enable_jumbo(framesize=ETHER_STANDARD_MTU) self.vm_testpmd.start_testpmd( "Default", "--max-pkt-len=%d --port-topology=loop --txqflags=0x0" % (ETHER_STANDARD_MTU)) self.vm_testpmd.execute_cmd("set fwd mac") self.vm_testpmd.execute_cmd("start") self.jumboframes_send_packet(ETHER_STANDARD_MTU - 1) self.jumboframes_send_packet(ETHER_STANDARD_MTU) self.vm_testpmd.execute_cmd("stop") self.vm_testpmd.quit() def test_vf_normal_withjumbo(self): """ When jumbo frame supported, this case is to verify that the normal size packet forwrding should be support correct. """ # should enable jumbo on host self.dutobj = self.dut.ports_info[self.port]['port'] self.dutobj.enable_jumbo(framesize=ETHER_JUMBO_FRAME_MTU) self.vm_testpmd.start_testpmd( "Default", "--max-pkt-len=%d --port-topology=loop --txqflags=0x0" % (ETHER_JUMBO_FRAME_MTU)) self.vm_testpmd.execute_cmd("set fwd mac") self.vm_testpmd.execute_cmd("start") self.jumboframes_send_packet(ETHER_STANDARD_MTU - 1) self.jumboframes_send_packet(ETHER_STANDARD_MTU) self.vm_testpmd.execute_cmd("stop") self.vm_testpmd.quit() def test_vf_jumbo_nojumbo(self): """ This case aims to test transmitting jumbo frame packet on testpmd without jumbo frame support. """ # should enable jumbo on host self.dutobj = self.dut.ports_info[self.port]['port'] self.dutobj.enable_jumbo(framesize=ETHER_STANDARD_MTU) self.vm_testpmd.start_testpmd("Default", "--port-topology=loop --txqflags=0x0") self.vm_testpmd.execute_cmd("set fwd mac") self.vm_testpmd.execute_cmd("start") # On igb, for example i350, refer to :DPDK-1117 # For PF, the max-pkt-len = mtu + 18 + 4(VLAN header len). # For VF, the real max-pkt-len = the given max-pkt-len + 4(VLAN header len). # This behavior is levelraged from kernel driver. # And it means max-pkt-len is always 4 bytes longer than assumed. if self.kdriver == "igb": self.jumboframes_send_packet(ETHER_STANDARD_MTU + 1 + 4, False) else: self.jumboframes_send_packet(ETHER_STANDARD_MTU + 1, False) self.vm_testpmd.execute_cmd("stop") self.vm_testpmd.quit() def test_vf_jumbo_withjumbo(self): """ When jumbo frame supported, this case is to verify that jumbo frame packet can be forwarded correct. """ # should enable jumbo on host self.dutobj = self.dut.ports_info[self.port]['port'] self.dutobj.enable_jumbo(framesize=ETHER_JUMBO_FRAME_MTU) self.vm_testpmd.start_testpmd( "Default", "--max-pkt-len=%d --port-topology=loop --txqflags=0x0" % (ETHER_JUMBO_FRAME_MTU)) self.vm_testpmd.execute_cmd("set fwd mac") self.vm_testpmd.execute_cmd("start") self.jumboframes_send_packet(ETHER_STANDARD_MTU + 1) self.jumboframes_send_packet(ETHER_JUMBO_FRAME_MTU - 1) self.jumboframes_send_packet(ETHER_JUMBO_FRAME_MTU) self.vm_testpmd.execute_cmd("stop") self.vm_testpmd.quit() def test_vf_jumbo_overjumbo(self): """ When the jubmo frame MTU set as 9000, this case is to verify that the packet which the length bigger than MTU can not be forwarded. """ # should enable jumbo on host self.dutobj = self.dut.ports_info[self.port]['port'] self.dutobj.enable_jumbo(framesize=ETHER_JUMBO_FRAME_MTU) self.vm_testpmd.start_testpmd( "Default", "--max-pkt-len=%d --port-topology=loop --txqflags=0x0" % (ETHER_JUMBO_FRAME_MTU)) self.vm_testpmd.execute_cmd("set fwd mac") self.vm_testpmd.execute_cmd("start") # On 1G NICs, when the jubmo frame MTU set as 9000, the software adjust it to 9004. if self.kdriver == "igb": self.jumboframes_send_packet(ETHER_JUMBO_FRAME_MTU + 4 + 1, False) else: self.jumboframes_send_packet(ETHER_JUMBO_FRAME_MTU + 1, False) self.vm_testpmd.execute_cmd("stop") self.vm_testpmd.quit() def tear_down(self): """ Run after each test case. """ self.destroy_vm_env() def tear_down_all(self): """ When the case of this test suite finished, the enviroment should clear up. """ self.destroy_vm_env() self.netobj.enable_jumbo(framesize=ETHER_STANDARD_MTU)
class TestVfMacFilter(TestCase): supported_vf_driver = ['pci-stub', 'vfio-pci'] vf0_wrongmac = "00:11:22:33:48:55" vf0_setmac = "00:11:22:33:44:55" def set_up_all(self): self.dut_ports = self.dut.get_ports(self.nic) self.verify(len(self.dut_ports) > 1, "Insufficient ports") self.vm0 = None self.pf0_vf0_mac = "00:12:34:56:78:01" # set vf assign method and vf driver self.vf_driver = self.get_suite_cfg()['vf_driver'] if self.vf_driver is None: self.vf_driver = 'pci-stub' self.verify(self.vf_driver in self.supported_vf_driver, "Unsupported vf driver") if self.vf_driver == 'pci-stub': self.vf_assign_method = 'pci-assign' else: self.vf_assign_method = 'vfio-pci' self.dut.send_expect('modprobe vfio-pci', '#') def set_up(self): self.setup_2pf_2vf_1vm_env_flag = 0 def setup_2pf_2vf_1vm_env(self, set_mac, driver='default'): self.used_dut_port_0 = self.dut_ports[0] self.dut.generate_sriov_vfs_by_port(self.used_dut_port_0, 1, driver=driver) self.sriov_vfs_port_0 = self.dut.ports_info[ self.used_dut_port_0]['vfs_port'] pf_intf0 = self.dut.ports_info[0]['port'].get_interface_name() if set_mac: self.dut.send_expect( "ip link set %s vf 0 mac %s" % (pf_intf0, self.pf0_vf0_mac), "#") self.used_dut_port_1 = self.dut_ports[1] self.dut.generate_sriov_vfs_by_port(self.used_dut_port_1, 1, driver=driver) self.sriov_vfs_port_1 = self.dut.ports_info[ self.used_dut_port_1]['vfs_port'] try: for port in self.sriov_vfs_port_0: port.bind_driver(self.vf_driver) for port in self.sriov_vfs_port_1: port.bind_driver(self.vf_driver) time.sleep(1) vf0_prop = {'opt_host': self.sriov_vfs_port_0[0].pci} vf1_prop = {'opt_host': self.sriov_vfs_port_1[0].pci} 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) else: self.host_testpmd.start_testpmd("1S/2C/2T", eal_param=eal_param) # set up VM0 ENV self.vm0 = VM(self.dut, 'vm0', 'vf_macfilter') self.vm0.set_vm_device(driver=self.vf_assign_method, **vf0_prop) self.vm0.set_vm_device(driver=self.vf_assign_method, **vf1_prop) self.vm_dut_0 = self.vm0.start() if self.vm_dut_0 is None: raise Exception("Set up VM0 ENV failed!") self.setup_2pf_2vf_1vm_env_flag = 1 except Exception as e: self.destroy_2pf_2vf_1vm_env() raise Exception(e) def destroy_2pf_2vf_1vm_env(self): if getattr(self, 'vm0', None): #destroy testpmd in vm0 if getattr(self, 'vm0_testpmd', None): self.vm0_testpmd.execute_cmd('stop') self.vm0_testpmd.execute_cmd('quit', '# ') self.vm0_testpmd = None self.vm0_dut_ports = None #destroy vm0 self.vm0.stop() self.dut.virt_exit() self.vm0 = None if getattr(self, 'host_testpmd', None): self.host_testpmd.execute_cmd('quit', '# ') self.host_testpmd = None if getattr(self, 'used_dut_port_0', None): self.dut.destroy_sriov_vfs_by_port(self.used_dut_port_0) port = self.dut.ports_info[self.used_dut_port_0]['port'] port.bind_driver() self.used_dut_port_0 = None if getattr(self, 'used_dut_port_1', None): self.dut.destroy_sriov_vfs_by_port(self.used_dut_port_1) port = self.dut.ports_info[self.used_dut_port_1]['port'] port.bind_driver() self.used_dut_port_1 = None for port_id in self.dut_ports: port = self.dut.ports_info[port_id]['port'] port.bind_driver() self.setup_2pf_2vf_1vm_env_flag = 0 def test_kernel_2pf_2vf_1vm_iplink_macfilter(self): """ test case for kernel pf and dpdk vf 2pf_2vf_1vm MAC filter scenario. kernel pf will first run 'ip link set pf_interface vf 0 mac xx:xx:xx:xx:xx:xx', then send packets with this MAC to VF, check if the MAC filter works. Also send the packets with wrong MAC address to VF, check the VF will not RX the packets. """ self.setup_2pf_2vf_1vm_env(True, driver='') self.result_verify_iplink(True) def result_verify_iplink(self, set_mac): if set_mac == False: self.host_testpmd.execute_cmd('set vf mac addr 0 0 %s' % self.pf0_vf0_mac) self.vm0_dut_ports = self.vm_dut_0.get_ports('any') self.vm0_testpmd = PmdOutput(self.vm_dut_0) self.vm0_testpmd.start_testpmd(VM_CORES_MASK) # Get VF's MAC pmd_vf0_mac = self.vm0_testpmd.get_port_mac(0) self.vm0_testpmd.execute_cmd('set promisc all off') self.vm0_testpmd.execute_cmd('set fwd mac') self.vm0_testpmd.execute_cmd('start') time.sleep(2) tgen_ports = [] tx_port = self.tester.get_local_port(self.dut_ports[0]) rx_port = self.tester.get_local_port(self.dut_ports[1]) tgen_ports.append((tx_port, rx_port)) dst_mac = self.pf0_vf0_mac src_mac = self.tester.get_mac(tx_port) pkt_param = [("ether", {'dst': dst_mac, 'src': src_mac})] 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') 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" dst_mac = self.vf0_wrongmac pkt_param = [("ether", {'dst': dst_mac, 'src': src_mac})] result2 = 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') self.verify(result2 != True, "VF0 failed to forward packets to VF1") def test_kernel_2pf_2vf_1vm_mac_add_filter(self): """ test case for kernel pf and dpdk vf 2pf_2vf_1vm MAC filter scenario. kernel pf will not set MAC address and the VF will get a random generated MAC in the testpmd in VM, and then add VF mac address in the testpmd, for example, VF_MAC1 then send packets to the VF with the random generated MAC and the new added VF_MAC1 and the expected result is that all packets can be RXed and TXed. What's more, send packets with a wrong MAC address to the VF will not be received by the VF. """ self.setup_2pf_2vf_1vm_env(False, driver='') self.send_packet_and_verify() def test_dpdk_2pf_2vf_1vm_mac_add_filter(self): """ test case for dpdk pf and dpdk vf 2pf_2vf_1vm MAC filter scenario. dpdk pf will not set MAC address and the VF will get a random generated MAC in the testpmd in VM, and then add VF mac address in the testpmd, for example, VF_MAC1 then send packets to the VF with the random generated MAC and the new added VF_MAC1 and the expected result is that all packets can be RXed and TXed. What's more, send packets with a wrong MAC address to the VF, check the VF will not RX packets. """ self.verify( self.nic.startswith('fortville') == True, "NIC is [%s], skip this case" % self.nic) self.setup_2pf_2vf_1vm_env(False, driver='igb_uio') self.send_packet_and_verify() def test_dpdk_2pf_2vf_1vm_iplink_macfilter(self): """ test case for dpdk pf and dpdk vf 2pf_2vf_1vm MAC filter scenario. dpdk pf will not set MAC address and the VF will get a random generated MAC in the testpmd in VM, then send packets with this MAC to VF, check that all packets can be RXed and TXed, send the packets with a wrong MAC address to VF, check the VF will not RX packets. """ self.setup_2pf_2vf_1vm_env(False, driver='igb_uio') self.result_verify_iplink(False) def send_packet_and_verify(self): self.vm0_dut_ports = self.vm_dut_0.get_ports('any') self.vm0_testpmd = PmdOutput(self.vm_dut_0) self.vm0_testpmd.start_testpmd(VM_CORES_MASK) # Get VF0 port MAC address pmd_vf0_mac = self.vm0_testpmd.get_port_mac(0) self.vm0_testpmd.execute_cmd('set promisc all off') ret = self.vm0_testpmd.execute_cmd('mac_addr add 0 %s' % self.vf0_setmac) # check the operation is supported or not. print ret self.vm0_testpmd.execute_cmd('set fwd mac') self.vm0_testpmd.execute_cmd('start') time.sleep(2) tgen_ports = [] tx_port = self.tester.get_local_port(self.dut_ports[0]) rx_port = self.tester.get_local_port(self.dut_ports[1]) tgen_ports.append((tx_port, rx_port)) src_mac = self.tester.get_mac(tx_port) dst_mac = pmd_vf0_mac pkt_param = [("ether", {'dst': dst_mac, 'src': src_mac})] print "\nfirst send packets to the random generated VF 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') self.verify(result1 != False, "VF0 failed to forward packets to VF1") print "\nsecondly, send packets to the new added MAC, expected result is RX packets=TX packets\n" dst_mac = self.vf0_setmac pkt_param = [("ether", {'dst': dst_mac, 'src': src_mac})] result2 = 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') self.verify(result2 != False, "VF0 failed to forward packets to VF1") print "\nThirdly, negative test, send packets to a wrong MAC, expected result is RX packets=0\n" dst_mac = self.vf0_wrongmac pkt_param = [("ether", {'dst': dst_mac, 'src': src_mac})] result3 = 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') self.verify(result3 != True, "VF0 failed to forward packets to VF1") def tear_down(self): if self.setup_2pf_2vf_1vm_env_flag == 1: self.destroy_2pf_2vf_1vm_env() def tear_down_all(self): if getattr(self, 'vm0', None): self.vm0.stop() self.dut.virt_exit() for port_id in self.dut_ports: self.dut.destroy_sriov_vfs_by_port(port_id)
class TestScatter(TestCase): # # # # Test cases. # def set_up_all(self): """ Run at the start of each test suite. Scatter Prerequistites """ dutPorts = self.dut.get_ports(self.nic) # Verify that enough ports are available self.verify(len(dutPorts) >= 1, "Insufficient ports") self.port = dutPorts[0] tester_port = self.tester.get_local_port(self.port) self.intf = self.tester.get_interface(tester_port) self.pmdout = PmdOutput(self.dut) if self.nic in ["magnolia_park", "niantic", "sageville", "fortpark", "fortville_eagle", "fortville_spirit", "fortville_spirit_single", "redrockcanyou", "atwood", "boulderrapid", "ironpond", "twinpond", "springfountain", "fortpark_TLV"]: self.mbsize = 2048 else: self.mbsize = 1024 if self.kdriver == "fm10k": self.dut.ports_info[self.port]['port'].enable_jumbo(framesize=9000) self.tester.send_expect("ifconfig %s mtu 9000" % self.intf, "#") def scatter_pktgen_send_packet(self, pktsize): """ Functional test for scatter packets. """ dmac = self.dut.get_mac_address(self.port) inst = 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) sniff_pkts = load_sniff_packets(inst) res = "" if len(sniff_pkts): res = strip_pktload(sniff_pkts[0], layer="L4") return res def set_up(self): """ Run before each test case. """ pass def test_scatter_mbuf_2048(self): """ Scatter 2048 mbuf """ out = self.pmdout.start_testpmd( "1S/2C/1T", "--mbcache=200 --mbuf-size=%d --portmask=0x1 " "--max-pkt-len=9000 --port-topology=loop" % (self.mbsize)) self.verify("Error" not in out, "launch error 1") self.dut.send_expect("set fwd mac", "testpmd> ", 120) self.dut.send_expect("start", "testpmd> ") for offset in [-1, 0, 1, 4, 5]: ret = self.scatter_pktgen_send_packet(self.mbsize + offset) self.verify( "58 58 58 58 58 58 58 58" in ret, "packet receive error") self.dut.send_expect("stop", "testpmd> ") self.dut.send_expect("quit", "# ", 30) def tear_down(self): """ Run after each test case. """ pass def tear_down_all(self): """ Run after each test suite. """ if self.kdriver == "fm10k": self.dut.ports_info[self.port]['port'].enable_jumbo(framesize=1518) self.tester.send_expect("ifconfig %s mtu 1500" % self.intf, "#") pass
class TestExternalMempool(TestCase): def set_up_all(self): """ Run at the start of each test suite. """ self.dut_ports = self.dut.get_ports() self.verify(len(self.dut_ports) >= 2, "Not enough ports") self.pmdout = PmdOutput(self.dut) def set_up(self): """ Run before each test case. """ pass def change_mempool_ops(self, ops=''): self.dut.send_expect( "sed -i 's/CONFIG_RTE_MBUF_DEFAULT_MEMPOOL_OPS=.*$/CONFIG_RTE_MBUF_DEFAULT_MEMPOOL_OPS=\"%s\"/' ./config/common_base" % ops, "# ") self.dut.build_install_dpdk(self.target) def verify_unit_func(self): self.dut.send_expect("./%s/app/test -n 4 -c f" % self.target, "R.*T.*E.*>.*>", 60) out = self.dut.send_expect("mempool_autotest", "RTE>>", 120) self.dut.send_expect("quit", "# ") self.verify("Test OK" in out, "Mempool autotest failed") def verify_unit_perf(self): self.dut.send_expect("./%s/app/test -n 4 -c f" % self.target, "R.*T.*E.*>.*>", 60) out = self.dut.send_expect("mempool_perf_autotest", "RTE>>", 1200) self.dut.send_expect("quit", "# ") # may need to compare performance self.verify("Test OK" in out, "Mempool performance autotest failed") def verify_app_func(self): # start testpmd self.pmdout.start_testpmd("1S/2C/1T", "--portmask=0x3") self.pmdout.execute_cmd("set fwd mac") self.pmdout.execute_cmd("start") tgen_input = [] tx_port = self.tester.get_local_port(self.dut_ports[0]) rx_port = self.tester.get_local_port(self.dut_ports[1]) tgen_input.append((tx_port, rx_port)) tx_port = self.tester.get_local_port(self.dut_ports[1]) rx_port = self.tester.get_local_port(self.dut_ports[0]) tgen_input.append((tx_port, rx_port)) result = self.tester.check_random_pkts(tgen_input, allow_miss=False) self.pmdout.quit() self.verify(result is True, "Mempool function check failed with testpmd") def test_mempool_handler_default(self): """ Verify default mempool ops """ self.verify_unit_func() self.verify_app_func() def test_mempool_handler_sp_sc(self): """ Verify mempool single produce single customer ops """ self.change_mempool_ops(ops='ring_sp_sc') self.verify_unit_func() self.verify_app_func() def test_mempool_handler_sp_mc(self): """ Verify mempool single produce multiple customer ops """ self.change_mempool_ops(ops='ring_sp_mc') self.verify_unit_func() self.verify_app_func() def test_mempool_handler_mp_sc(self): """ Verify mempool multiple produce single customer ops """ self.change_mempool_ops(ops='ring_mp_sc') self.verify_unit_func() self.verify_app_func() def test_mempool_handler_stack(self): """ Verify external mempool handler stack ops """ self.change_mempool_ops(ops='stack') self.verify_unit_func() self.verify_app_func() def tear_down(self): """ Run after each test case. """ self.dut.kill_all() pass def tear_down_all(self): """ Run after each test suite. """ self.change_mempool_ops(ops='ring_mp_mc')
class TestFdir(TestCase): def set_up_all(self): """ Run at the start of each test suite. """ ports = self.dut.get_ports() self.verify(len(ports) >= 2, "Not enough ports available") self.pmdout = PmdOutput(self.dut) def set_up(self): """ Run before each test case. """ pass def send_and_verify(self, condition, packet): """ Send packages and verify behavior. """ self.tester.scapy_foreground() self.tester.scapy_append('sys.path.append("./")') self.tester.scapy_append('from sctp import *') self.tester.scapy_append(packet) self.dut.send_expect("start", "testpmd>") self.tester.scapy_execute() time.sleep(.5) out = self.dut.send_expect("stop", "testpmd>") if condition: self.verify("PKT_RX_FDIR" in out, "FDIR hash not displayed when required") else: self.verify("PKT_RX_FDIR" not in out, "FDIR hash displayed when not required") def test_fdir_space(self): """ Setting memory reserved for FDir filters. """ dutPorts = self.dut.get_ports() self.pmdout.start_testpmd( "all", "--rxq=2 --txq=2 --disable-rss --pkt-filter-mode=perfect --pkt-filter-size=64K" ) out = self.dut.send_expect("show port fdir %s" % dutPorts[0], "testpmd>") self.dut.send_expect("quit", "# ", 30) self.verify("free: 2048" in out, "Free space doesn't match the expected value") self.pmdout.start_testpmd( "all", "--rxq=2 --txq=2 --disable-rss --pkt-filter-mode=perfect --pkt-filter-size=128K" ) out = self.dut.send_expect("show port fdir %s" % dutPorts[0], "testpmd>") self.dut.send_expect("quit", "# ", 30) self.verify("free: 4096" in out, "Free space doesn't match the expected value") self.pmdout.start_testpmd( "all", "--rxq=2 --txq=2 --disable-rss --pkt-filter-mode=perfect --pkt-filter-size=256K" ) out = self.dut.send_expect("show port fdir %s" % dutPorts[0], "testpmd>") self.dut.send_expect("quit", "# ", 30) self.verify("free: 8192" in out, "Free space doesn't match the expected value") def test_fdir_signatures(self): """ FDir signature matching mode. There are three different reporting modes, that can be set in testpmd using the ``--pkt-filter-report-hash`` command line argument: --pkt-filter-report-hash=none --pkt-filter-report-hash=match --pkt-filter-report-hash=always The test for each mode is following the steps below. - Start the ``testpmd`` application by using paramter of each mode. - Send the ``p_udp`` packet with Scapy on the traffic generator and check that FDir information is printed """ dutPorts = self.dut.get_ports() localPort = self.tester.get_local_port(dutPorts[0]) itf = self.tester.get_interface(localPort) self.dut.kill_all() self.pmdout.start_testpmd( "all", "--portmask=%s --rxq=2 --txq=2 --disable-rss --pkt-filter-mode=perfect --pkt-filter-report-hash=none" % dts.create_mask([dutPorts[0]])) self.dut.send_expect("set verbose 1", "testpmd>") self.dut.send_expect("set fwd rxonly", "testpmd>") self.dut.send_expect("set nbcore 3", "testpmd>") self.send_and_verify( False, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect( "add_perfect_filter %s udp src 192.168.0.1 1024 dst 192.168.0.2 1024 flexbytes 0x800 vlan 0 queue 1 soft 0x14" % dutPorts[0], "testpmd>") self.send_and_verify( False, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect("quit", "# ", 30) self.pmdout.start_testpmd( "all", "--portmask=%s --rxq=2 --txq=2 --disable-rss --pkt-filter-mode=perfect --pkt-filter-report-hash=match" % dts.create_mask([dutPorts[0]])) self.dut.send_expect("set verbose 1", "testpmd>") self.dut.send_expect("set fwd rxonly", "testpmd>") self.dut.send_expect("set nbcore 3", "testpmd>") self.send_and_verify( False, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect( "add_perfect_filter %s udp src 192.168.0.1 1024 dst 192.168.0.2 1024 flexbytes 0x800 vlan 0 queue 1 soft 0x14" % dutPorts[0], "testpmd>") self.send_and_verify( True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect( "upd_perfect_filter %s udp src 192.168.1.1 0 dst 192.168.1.2 0 flexbytes 0x800 vlan 0 queue 1 soft 0x14" % dutPorts[0], "testpmd>") self.send_and_verify( True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.send_and_verify( True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.1.1", dst="192.168.1.2")/UDP(sport=0,dport=0)], iface="%s")' % (itf, itf)) self.dut.send_expect( "rm_perfect_filter %s udp src 192.168.1.1 0 dst 192.168.1.2 0 flexbytes 0x800 vlan 0 soft 0x14" % dutPorts[0], "testpmd>") self.send_and_verify( False, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.1.1", dst="192.168.1.2")/UDP(sport=0,dport=0)], iface="%s")' % (itf, itf)) self.dut.send_expect("quit", "# ", 30) self.pmdout.start_testpmd( "all", "--portmask=%s --rxq=2 --txq=2 --disable-rss --pkt-filter-mode=perfect --pkt-filter-report-hash=always" % dts.create_mask([dutPorts[0]])) self.dut.send_expect("set verbose 1", "testpmd>") self.dut.send_expect("set fwd rxonly", "testpmd>") self.dut.send_expect("set nbcore 3", "testpmd>") self.send_and_verify( True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect( "add_perfect_filter %s udp src 192.168.0.1 1024 dst 192.168.0.2 1024 flexbytes 0x800 vlan 0 queue 1 soft 0x14" % dutPorts[0], "testpmd>") self.send_and_verify( True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect("quit", "# ", 30) def test_fdir_matching(self): """ FDir matching mode This test adds signature filters to the hardware, and then checks whether sent packets match those filters. The test for each mode is following the steps below. - Start the ``testpmd`` application - Add filter with upd, tcp sctp, IP4 or IP6 - Send the packet and validate the filter function. """ dutPorts = self.dut.get_ports() localPort = self.tester.get_local_port(dutPorts[0]) itf = self.tester.get_interface(localPort) self.dut.kill_all() self.pmdout.start_testpmd( "all", "--portmask=%s --rxq=2 --txq=2 --disable-rss --pkt-filter-mode=signature --pkt-filter-report-hash=match" % dts.create_mask([dutPorts[0]])) self.dut.send_expect("set verbose 1", "testpmd>") self.dut.send_expect("set fwd rxonly", "testpmd>") self.dut.send_expect("set nbcore 3", "testpmd>") self.send_and_verify( False, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect( "add_signature_filter %s udp src 192.168.0.1 1024 dst 192.168.0.2 1024 flexbytes 0x800 vlan 0 queue 1" % dutPorts[0], "testpmd>") self.send_and_verify( True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.send_and_verify( False, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/TCP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect( "upd_signature_filter %s udp src 192.168.1.1 0 dst 192.168.1.2 0 flexbytes 0x800 vlan 0 queue 1" % dutPorts[0], "testpmd>") self.send_and_verify( True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.send_and_verify( True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.1.1", dst="192.168.1.2")/UDP(sport=0,dport=0)], iface="%s")' % (itf, itf)) self.dut.send_expect( "rm_signature_filter %s udp src 192.168.1.1 0 dst 192.168.1.2 0 flexbytes 0x800 vlan 0" % dutPorts[0], "testpmd>") self.send_and_verify( False, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.1.1", dst="192.168.1.2")/UDP(sport=0,dport=0)], iface="%s")' % (itf, itf)) self.dut.send_expect( "add_signature_filter %s tcp src 192.168.0.1 1024 dst 192.168.0.2 1024 flexbytes 0x800 vlan 0 queue 1" % dutPorts[0], "testpmd>") self.send_and_verify( True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/TCP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.send_and_verify( False, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/SCTP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect( "add_signature_filter %s sctp src 192.168.0.1 0 dst 192.168.0.2 0 flexbytes 0x800 vlan 0 queue 1" % dutPorts[0], "testpmd>") self.send_and_verify( True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/SCTP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.send_and_verify( False, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")], iface="%s")' % (itf, itf)) self.dut.send_expect( "add_signature_filter %s ip src 192.168.0.1 0 dst 192.168.0.2 0 flexbytes 0x800 vlan 0 queue 1" % dutPorts[0], "testpmd>") self.send_and_verify( True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")], iface="%s")' % (itf, itf)) self.send_and_verify( False, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IPv6(src="2001:0db8:85a3:0000:0000:8a2e:0370:7000", dst="2001:0db8:85a3:0000:0000:8a2e:0370:7338")/UDP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect( "add_signature_filter %s udp src 2001:0db8:85a3:0000:0000:8a2e:0370:7000 1024 dst 2001:0db8:85a3:0000:0000:8a2e:0370:7338 1024 flexbytes 0x86dd vlan 0 queue 1" % dutPorts[0], "testpmd>") self.send_and_verify( True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IPv6(src="2001:0db8:85a3:0000:0000:8a2e:0370:7000", dst="2001:0db8:85a3:0000:0000:8a2e:0370:7338")/UDP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect("quit", "# ", 30) def test_fdir_perfect_matching(self): """ FDir perfect matching mode. This test adds perfect-match filters to the hardware, and then checks whether sent packets match those filters. The test for each mode is following the steps below. - Start the ``testpmd`` application with perfect match; - Add filter with upd, tcp sctp, IP4; - Send the packet and validate the perfect filter function. """ dutPorts = self.dut.get_ports() localPort = self.tester.get_local_port(dutPorts[0]) itf = self.tester.get_interface(localPort) self.dut.kill_all() self.pmdout.start_testpmd( "all", "--portmask=%s --rxq=2 --txq=2 --disable-rss --pkt-filter-mode=perfect --pkt-filter-report-hash=match" % dts.create_mask([dutPorts[0]])) self.dut.send_expect("set verbose 1", "testpmd>") self.dut.send_expect("set fwd rxonly", "testpmd>") self.dut.send_expect("set nbcore 3", "testpmd>") self.dut.send_expect( "add_perfect_filter %s udp src 192.168.0.1 1024 dst 192.168.0.2 1024 flexbytes 0x800 vlan 0 queue 1 soft 0x14" % dutPorts[0], "testpmd>") self.send_and_verify( True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect( "add_perfect_filter %s tcp src 192.168.0.1 1024 dst 192.168.0.2 1024 flexbytes 0x800 vlan 0 queue 1 soft 0x15" % dutPorts[0], "testpmd>") self.send_and_verify( True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/TCP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect( "add_perfect_filter %s sctp src 192.168.0.1 0 dst 192.168.0.2 0 flexbytes 0x800 vlan 0 queue 1 soft 0x16" % dutPorts[0], "testpmd>") self.send_and_verify( True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/SCTP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect( "add_perfect_filter %s ip src 192.168.0.1 0 dst 192.168.0.2 0 flexbytes 0x800 vlan 0 queue 1 soft 0x17" % dutPorts[0], "testpmd>") self.send_and_verify( True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")], iface="%s")' % (itf, itf)) self.dut.send_expect("quit", "# ", 30) def test_fdir_filter_masks(self): """ FDir filter masks. This tests the functionality of the setting FDir masks to to affect which fields, or parts of fields are used in the matching process. """ dutPorts = self.dut.get_ports() localPort = self.tester.get_local_port(dutPorts[0]) itf = self.tester.get_interface(localPort) self.dut.kill_all() self.pmdout.start_testpmd( "all", "--portmask=%s --rxq=2 --txq=2 --disable-rss --pkt-filter-mode=perfect --pkt-filter-size=64K --pkt-filter-report-hash=match" % dts.create_mask([dutPorts[0]])) self.dut.send_expect("set verbose 1", "testpmd>") self.dut.send_expect("set fwd rxonly", "testpmd>") self.dut.send_expect("set nbcore 3", "testpmd>") self.dut.send_expect( "set_masks_filter %s only_ip_flow 0 src_mask 0xffffff00 0xffff dst_mask 0xffffff00 0xffff flexbytes 1 vlan_id 1 vlan_prio 1" % dutPorts[0], "testpmd>") self.dut.send_expect( "add_perfect_filter %s udp src 192.168.0.0 1024 dst 192.168.0.0 1024 flexbytes 0x800 vlan 0 queue 1 soft 0x17" % dutPorts[0], "testpmd>") self.send_and_verify( True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.send_and_verify( True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.15", dst="192.168.0.15")/UDP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.send_and_verify( False, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.1.1")/UDP(sport=1024,dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect( "set_masks_filter %s only_ip_flow 0 src_mask 0xffffffff 0xff00 dst_mask 0xffffffff 0xff00 flexbytes 1 vlan_id 1 vlan_prio 1" % dutPorts[0], "testpmd>") self.dut.send_expect( "add_perfect_filter %s udp src 10.11.12.1 0x4400 dst 10.11.12.2 0x4500 flexbytes 0x800 vlan 0 queue 1 soft 0x4" % dutPorts[0], "testpmd>") self.send_and_verify( True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="10.11.12.1", dst="10.11.12.2")/UDP(sport=0x4400,dport=0x4500)], iface="%s")' % (itf, itf)) self.send_and_verify( True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="10.11.12.1", dst="10.11.12.2")/UDP(sport=0x4411,dport=0x4517)], iface="%s")' % (itf, itf)) self.send_and_verify( False, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="10.11.12.1", dst="10.11.12.2")/UDP(sport=0x4500,dport=0x5500)], iface="%s")' % (itf, itf)) self.dut.send_expect( "set_masks_filter %s only_ip_flow 1 src_mask 0xffffffff 0x0 dst_mask 0xffffffff 0x0 flexbytes 1 vlan_id 1 vlan_prio 1" % dutPorts[0], "testpmd>") self.dut.send_expect( "add_perfect_filter %s ip src 192.168.0.1 0 dst 192.168.0.2 0 flexbytes 0x800 vlan 0 queue 1 soft 0x42" % dutPorts[0], "testpmd>") self.send_and_verify( True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=1024, dport=1024)], iface="%s")' % (itf, itf)) self.send_and_verify( True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/TCP(sport=1024, dport=1024)], iface="%s")' % (itf, itf)) self.send_and_verify( True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/SCTP(sport=1024, dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect("quit", "# ", 30) def test_fdir_flexbytes_filtering(self): """ FDir flexbytes filtering The FDir feature supports setting up filters that can match on any two byte field within the first 64 bytes of a packet. Which byte offset to use is set by passing command line arguments to ``testpmd``. In this test a value of ``18`` corresponds to the bytes at offset 36 and 37, as the offset is in 2-byte units """ dutPorts = self.dut.get_ports() localPort = self.tester.get_local_port(dutPorts[0]) itf = self.tester.get_interface(localPort) self.dut.kill_all() self.pmdout.start_testpmd( "all", "--portmask=%s --rxq=2 --txq=2 --disable-rss --pkt-filter-mode=perfect --pkt-filter-size=64K --pkt-filter-report-hash=match --pkt-filter-flexbytes-offset=18" % dts.create_mask([dutPorts[0]])) self.dut.send_expect("set verbose 1", "testpmd>") self.dut.send_expect("set fwd rxonly", "testpmd>") self.dut.send_expect("set nbcore 3", "testpmd>") self.dut.send_expect( "add_perfect_filter %s ip src 192.168.0.1 0 dst 192.168.0.2 0 flexbytes 0x1 vlan 0 queue 1 soft 0x1" % dutPorts[0], "testpmd>") self.send_and_verify( True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/GRE(proto=0x1)/IP()/UDP()], iface="%s")' % (itf, itf)) self.dut.send_expect( "add_perfect_filter %s ip src 192.168.0.1 0 dst 192.168.0.2 0 flexbytes 0xff vlan 0 queue 1 soft 0xff" % dutPorts[0], "testpmd>") self.send_and_verify( True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/GRE(proto=0xff)/IP()/UDP()], iface="%s")' % (itf, itf)) self.dut.send_expect( "set_masks_filter %s only_ip_flow 0 src_mask 0xffffffff 0xffff dst_mask 0xffffffff 0xffff flexbytes 0 vlan_id 1 vlan_prio 1" % dutPorts[0], "testpmd>") self.dut.send_expect( "add_perfect_filter %s ip src 192.168.0.1 0 dst 192.168.0.2 0 flexbytes 0x0 vlan 0 queue 1 soft 0x42" % dutPorts[0], "testpmd>") self.send_and_verify( True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/GRE(proto=0x1)/IP()/UDP()], iface="%s")' % (itf, itf)) self.send_and_verify( True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/IP(src="192.168.0.1", dst="192.168.0.2")/GRE(proto=0xFF)/IP()/UDP()], iface="%s")' % (itf, itf)) self.dut.send_expect("quit", "# ", 30) def test_fdir_vlanfiltering(self): """ FDir VLAN field filtering """ dutPorts = self.dut.get_ports() localPort = self.tester.get_local_port(dutPorts[0]) itf = self.tester.get_interface(localPort) self.dut.kill_all() self.pmdout.start_testpmd( "all", "--portmask=%s --nb-cores=2 --rxq=2 --txq=2 --disable-rss --pkt-filter-mode=perfect" % dts.create_mask([dutPorts[0]])) self.dut.send_expect("set verbose 1", "testpmd>") self.dut.send_expect("set fwd rxonly", "testpmd>") # "rx_vlan add all" has been removed from testpmd self.dut.send_expect("rx_vlan add 0xFFF %s" % dutPorts[0], "testpmd>") self.dut.send_expect("rx_vlan add 0x001 %s" % dutPorts[0], "testpmd>") self.dut.send_expect("rx_vlan add 0x017 %s" % dutPorts[0], "testpmd>") self.send_and_verify( False, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/Dot1Q(vlan=0x0FFF)/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=1024, dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect( "add_perfect_filter %s udp src 192.168.0.1 1024 dst 192.168.0.2 1024 flexbytes 0x8100 vlan 0xfff queue 1 soft 0x47" % dutPorts[0], "testpmd>") self.send_and_verify( True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/Dot1Q(vlan=0x0FFF)/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=1024, dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect( "set_masks_filter %s only_ip_flow 0 src_mask 0xffffffff 0xffff dst_mask 0xffffffff 0xffff flexbytes 1 vlan_id 0 vlan_prio 0" % dutPorts[0], "testpmd>") self.dut.send_expect( "add_perfect_filter %s udp src 192.168.0.1 1024 dst 192.168.0.2 1024 flexbytes 0x8100 vlan 0 queue 1 soft 0x47" % dutPorts[0], "testpmd>") self.send_and_verify( True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/Dot1Q(vlan=0x001)/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=1024, dport=1024)], iface="%s")' % (itf, itf)) self.send_and_verify( True, 'sendp([Ether(src=get_if_hwaddr("%s"), dst="00:1B:21:8E:B2:30")/Dot1Q(vlan=0x0017)/IP(src="192.168.0.1", dst="192.168.0.2")/UDP(sport=1024, dport=1024)], iface="%s")' % (itf, itf)) self.dut.send_expect("quit", "# ", 30) def tear_down(self): """ Run after each test case. """ pass def tear_down_all(self): """ Run after each test suite. """ pass
class TestVF2VFBridge(TestCase): supported_vf_driver = ['pci-stub', 'vfio-pci'] def set_up_all(self): self.dut_ports = self.dut.get_ports(self.nic) self.verify(len(self.dut_ports) >= 1, "Insufficient ports") self.vm0 = None self.vm1 = None # set vf assign method and vf driver self.vf_driver = self.get_suite_cfg()['vf_driver'] if self.vf_driver is None: self.vf_driver = 'pci-stub' self.verify(self.vf_driver in self.supported_vf_driver, "Unspported vf driver") if self.vf_driver == 'pci-stub': self.vf_assign_method = 'pci-assign' else: self.vf_assign_method = 'vfio-pci' self.dut.send_expect('modprobe vfio-pci', '#') def set_up(self): self.set_up_vf_to_vf_env() def set_up_vf_to_vf_env(self, driver='default'): self.pf_port_for_vfs = self.dut_ports[0] self.dut.restore_interfaces() self.dut.generate_sriov_vfs_by_port( self.pf_port_for_vfs, VF_NUMS_ON_ONE_PF, driver=driver) self.sriov_vfs_ports = self.dut.ports_info[ self.pf_port_for_vfs]['vfs_port'] self.host_port_intf = self.dut.ports_info[self.pf_port_for_vfs]['intf'] for i in range(VF_NUMS_ON_ONE_PF): self.dut.send_expect('ip link set dev %s vf %d mac %s' % (self.host_port_intf, i, VF_TEMP_MAC % i), '#', 10) try: for port in self.sriov_vfs_ports: port.bind_driver(self.vf_driver) time.sleep(1) except Exception as e: raise Exception(e) vf0_prop = {'opt_host': self.sriov_vfs_ports[0].pci} vf1_prop = {'opt_host': self.sriov_vfs_ports[1].pci} time.sleep(1) self.vm0 = VM(self.dut, 'vm0', 'vf_to_vf_bridge') self.vm0.set_vm_device(driver=self.vf_assign_method, **vf0_prop) try: self.vm0_dut = self.vm0.start() if self.vm0_dut is None: raise Exception('Set up VM0 failed') except Exception as e: print utils.RED(str(e)) self.vm1 = VM(self.dut, 'vm1', 'vf_to_vf_bridge') self.vm1.set_vm_device(driver=self.vf_assign_method, **vf1_prop) try: self.vm1_dut = self.vm1.start() if self.vm1_dut is None: raise Exception('Set up VM1 failed') except Exception as e: print utils.RED(str(e)) def clear_vf_to_vf_env(self): if self.vm0 is not None: self.vm0.stop() self.vm0 = None if self.vm1 is not None: self.vm1.stop() self.vm1 = None self.dut.virt_exit() if self.pf_port_for_vfs is not None: self.dut.destroy_sriov_vfs_by_port(self.pf_port_for_vfs) port = self.dut.ports_info[self.pf_port_for_vfs]['port'] port.bind_driver() self.pf_port_for_vfs = 0 def generate_pcap_pkt(self, dst, src, load, pktname='flow.pcap'): """ dst: server: dst server object ether: dst mac ip: dst ip udp: dst udp protocol tcp: dst tcp protocal src: server: src server object ether: src mac ip: src ip udp: src udp protocol tcp: src tcp protocal load: content: pay load length: content length """ context = '[Ether(dst="%s", src="%s")/IP()/Raw(load=%s)]' % \ (str(dst['ether']), str(src['ether']), load['content']) src['server'].send_expect('scapy', '>>> ', 10) src['server'].send_expect( 'wrpcap("%s", %s)' % (pktname, context), '>>> ', 10) src['server'].send_expect('quit()', '#', 10) def prepare_pktgen(self, vm): vm.session.copy_file_to('./dep/tgen.tgz') vm.send_expect("cd /root", "#", 10) vm.send_expect("tar xvf tgen.tgz", '#', 20) def send_stream_pktgen(self, vm, pktname='flow.pcap'): vm.send_expect( "echo 2048 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages", "#", 10) vm.send_expect(" mount -t hugetlbfs nodedev /mnt/huge/", "#", 10) vm.send_expect( "./pktgen -c 0xf -n 2 --proc-type auto -- -P -T -m '1.0' -s 0:%s" % pktname, "", 100) time.sleep(60) vm.send_expect("set 0 rate 50", "", 20) time.sleep(5) vm.send_expect("set 0 count %d" % SEND_PACKET, "", 20) time.sleep(5) vm.send_expect("start all", "", 20) time.sleep(20) def stop_stream_pktgen(self, vm): vm.send_expect("stop all", "", 20) time.sleep(5) vm.send_expect("quit", "#", 20) def test_2vf_d2d_pktgen_stream(self): self.vm0_ports = self.vm0_dut.get_ports('any') self.vm0_pmd = PmdOutput(self.vm0_dut) self.vm0_pmd.start_testpmd('all') self.vm0_pmd.execute_cmd('set fwd rxonly') self.vm0_pmd.execute_cmd("set promisc all off") self.vm0_pmd.execute_cmd('start') self.vm1_ports = self.vm1_dut.get_ports('any') self.prepare_pktgen(self.vm1_dut) dst = {} dst['server'] = self.vm0_dut dst['ether'] = self.vm0_dut.ports_info[self.vm0_ports[0]]['mac'] src = {} src['server'] = self.vm1_dut src['ether'] = self.vm1_dut.ports_info[self.vm1_ports[0]]['mac'] load = {} load['content'] = "'X'*46" self.generate_pcap_pkt(dst, src, load) self.vm0_pmd.execute_cmd('clear port stats all') self.send_stream_pktgen(self.vm1_dut) recv_num = self.vm0_pmd.get_pmd_stats(0)['RX-packets'] time.sleep(1) self.stop_stream_pktgen(self.vm1_dut) self.vm0_pmd.execute_cmd('stop') self.vm0_pmd.execute_cmd('quit', '# ') self.verify(recv_num is SEND_PACKET, 'Rx port recv error: %d' % recv_num) def test_2vf_d2k_pktgen_stream(self): self.vm0_dut.restore_interfaces() self.vm0_ports = self.vm0_dut.get_ports('any') vf0_intf = self.vm0_dut.ports_info[self.vm0_ports[0]]['intf'] self.vm1_ports = self.vm1_dut.get_ports('any') self.prepare_pktgen(self.vm1_dut) dst = {} dst['server'] = self.vm0_dut dst['ether'] = self.vm0_dut.ports_info[self.vm0_ports[0]]['mac'] src = {} src['server'] = self.vm1_dut src['ether'] = self.vm1_dut.ports_info[self.vm1_ports[0]]['mac'] load = {} load['content'] = "'X'*46" self.generate_pcap_pkt(dst, src, load) self.vm0_dut.send_expect( 'tcpdump -i %s -s 1000 "ether src %s and ether dst %s"' % (vf0_intf, src['ether'], dst['ether']), 'tcpdump', 30) self.send_stream_pktgen(self.vm1_dut) self.stop_stream_pktgen(self.vm1_dut) recv_tcpdump = self.vm0_dut.send_expect('^C', '#', 30) time.sleep(5) recv_pattern = re.compile("(\d+) packets captured") recv_info = recv_pattern.search(recv_tcpdump) recv_str = recv_info.group(0).split(' ')[0] recv_number = int(recv_str, 10) self.vm0_dut.bind_interfaces_linux(self.drivername) self.verify(recv_number is SEND_PACKET, 'Rx port recv error: %d' % recv_number) def test_2vf_k2d_scapy_stream(self): self.vm0_ports = self.vm0_dut.get_ports('any') self.vm0_pmd = PmdOutput(self.vm0_dut) self.vm0_pmd.start_testpmd('all') self.vm1_ports = self.vm1_dut.get_ports('any') self.vm1_dut.restore_interfaces() vf1_intf = self.vm1_dut.ports_info[self.vm1_ports[0]]['intf'] dst_mac = self.vm0_dut.ports_info[self.vm0_ports[0]]['mac'] src_mac = self.vm1_dut.ports_info[self.vm1_ports[0]]['mac'] pkt_content = 'Ether(dst="%s", src="%s")/IP()/Raw(load="X"*46)' % \ (dst_mac, src_mac) self.vm1_dut.send_expect('scapy', '>>> ', 10) self.vm0_pmd.execute_cmd('set promisc all off') self.vm0_pmd.execute_cmd('set fwd rxonly') self.vm0_pmd.execute_cmd('set verbose 1') self.vm0_pmd.execute_cmd('start') self.vm1_dut.send_expect('sendp([%s], iface="%s", count=%d)' % (pkt_content, vf1_intf, SEND_PACKET), '>>> ', 30) out = self.vm0_dut.get_session_output(timeout=60) rx_packets = re.findall("src=%s - dst=%s" % (src_mac, dst_mac), out) recv_num = len(rx_packets) self.vm1_dut.send_expect('quit()', '# ', 10) self.vm1_dut.bind_interfaces_linux(self.drivername) self.vm0_pmd.execute_cmd('stop') self.vm0_pmd.execute_cmd('quit', '# ') self.verify(recv_num is SEND_PACKET, 'Rx port recv error: %d' % recv_num) def tear_down(self): self.clear_vf_to_vf_env() def tear_down_all(self): pass
class TestJumboframes(TestCase): def jumboframes_get_stat(self, portid, rx_tx): """ Get packets number from port statistic """ stats = self.pmdout.get_pmd_stats(portid) if rx_tx == "rx": return [stats['RX-packets'], stats['RX-errors'], stats['RX-bytes']] elif rx_tx == "tx": return [stats['TX-packets'], stats['TX-errors'], stats['TX-bytes']] else: return None def jumboframes_send_packet(self, pktsize, received=True): """ Send 1 packet to portid """ tx_pkts_ori, _, tx_bytes_ori = [ int(_) for _ in self.jumboframes_get_stat(self.rx_port, "tx") ] rx_pkts_ori, rx_err_ori, rx_bytes_ori = [ int(_) for _ in self.jumboframes_get_stat(self.tx_port, "rx") ] itf = self.tester.get_interface( self.tester.get_local_port(self.tx_port)) mac = self.dut.get_mac_address(self.tx_port) # The packet total size include ethernet header, ip header, and payload. # ethernet header length is 18 bytes, ip standard header length is 20 bytes. pktlen = pktsize - ETHER_HEADER_LEN padding = pktlen - IP_HEADER_LEN self.tester.scapy_foreground() self.tester.scapy_append('nutmac="%s"' % mac) self.tester.scapy_append( 'sendp([Ether(dst=nutmac, src="52:00:00:00:00:00")/IP(len=%s)/Raw(load="\x50"*%s)], iface="%s")' % (pktlen, padding, itf)) out = self.tester.scapy_execute() sleep(5) tx_pkts, _, tx_bytes = [ int(_) for _ in self.jumboframes_get_stat(self.rx_port, "tx") ] # p0tx_pkts, p0tx_err, p0tx_bytes rx_pkts, rx_err, rx_bytes = [ int(_) for _ in self.jumboframes_get_stat(self.tx_port, "rx") ] tx_pkts -= tx_pkts_ori tx_bytes -= tx_bytes_ori rx_pkts -= rx_pkts_ori rx_bytes -= rx_bytes_ori rx_err -= rx_err_ori if received: self.verify( self.pmdout.check_tx_bytes(tx_pkts, rx_pkts) and (self.pmdout.check_tx_bytes(tx_bytes + 4, pktsize)) and ((rx_bytes + 4) == pktsize), "packet pass assert error") else: #self.verify(p0tx_pkts == p1rx_pkts and (p1rx_err == 1 or p1rx_pkts == 0), self.verify(rx_err == 1 or tx_pkts == 0, "packet drop assert error") return out # # # # Test cases. # def set_up_all(self): """ Prerequisite steps for each test suit. """ self.dut_ports = self.dut.get_ports() self.verify(len(self.dut_ports) >= 1, "Insufficient ports") self.rx_port = self.dut_ports[0] self.tx_port = self.dut_ports[0] cores = self.dut.get_core_list("1S/2C/1T") self.coremask = utils.create_mask(cores) self.port_mask = utils.create_mask([self.rx_port, self.tx_port]) if self.kdriver == "fm10k": netobj = self.dut.ports_info[self.tx_port]['port'] netobj.enable_jumbo(framesize=ETHER_JUMBO_FRAME_MTU) netobj = self.dut.ports_info[self.rx_port]['port'] netobj.enable_jumbo(framesize=ETHER_JUMBO_FRAME_MTU) self.tester.send_expect( "ifconfig %s mtu %s" % (self.tester.get_interface(self.tester.get_local_port( self.rx_port)), ETHER_JUMBO_FRAME_MTU + 200), "# ") # self.tester.send_expect("ifconfig %s mtu %s" % (self.tester.get_interface(self.tester.get_local_port(self.tx_port)), ETHER_JUMBO_FRAME_MTU + 200), "# ") self.pmdout = PmdOutput(self.dut) def set_up(self): """ This is to clear up environment before the case run. """ self.dut.kill_all() def test_jumboframes_normal_nojumbo(self): """ This case aims to test transmitting normal size packet without jumbo f=rame on testpmd app. """ self.pmdout.start_testpmd( "Default", "--max-pkt-len=%d --port-topology=loop" % (ETHER_STANDARD_MTU)) self.dut.send_expect("set fwd mac", "testpmd> ") self.dut.send_expect("start", "testpmd> ") self.jumboframes_send_packet(ETHER_STANDARD_MTU - 1) self.jumboframes_send_packet(ETHER_STANDARD_MTU) self.dut.send_expect("stop", "testpmd> ") self.dut.send_expect("quit", "# ", 30) def test_jumboframes_jumbo_nojumbo(self): """ This case aims to test transmitting jumbo frame packet on testpmd without jumbo frame support. """ # RRC has no ability to set the max pkt len to hardware if self.kdriver == "fm10k": print utils.RED("fm10k not support this case\n") return self.pmdout.start_testpmd( "Default", "--max-pkt-len=%d --port-topology=loop" % (ETHER_STANDARD_MTU)) self.dut.send_expect("set fwd mac", "testpmd> ") self.dut.send_expect("start", "testpmd> ") self.jumboframes_send_packet(ETHER_STANDARD_MTU + 1, False) self.dut.send_expect("stop", "testpmd> ") self.dut.send_expect("quit", "# ", 30) def test_jumboframes_normal_jumbo(self): """ When jumbo frame supported, this case is to verify that the normal size packet forwrding should be support correct. """ self.pmdout.start_testpmd( "Default", "--max-pkt-len=%s --port-topology=loop" % (ETHER_JUMBO_FRAME_MTU)) self.dut.send_expect("set fwd mac", "testpmd> ") self.dut.send_expect("start", "testpmd> ") self.jumboframes_send_packet(1517) self.jumboframes_send_packet(1518) self.dut.send_expect("stop", "testpmd> ") self.dut.send_expect("quit", "# ", 30) def test_jumboframes_jumbo_jumbo(self): """ When jumbo frame supported, this case is to verify that jumbo frame packet can be forwarded correct. """ self.pmdout.start_testpmd( "Default", "--max-pkt-len=%s --port-topology=loop" % (ETHER_JUMBO_FRAME_MTU)) self.dut.send_expect("set fwd mac", "testpmd> ") self.dut.send_expect("start", "testpmd> ") self.jumboframes_send_packet(ETHER_STANDARD_MTU + 1) self.jumboframes_send_packet(ETHER_JUMBO_FRAME_MTU - 1) self.jumboframes_send_packet(ETHER_JUMBO_FRAME_MTU) self.dut.send_expect("stop", "testpmd> ") self.dut.send_expect("quit", "# ", 30) def test_jumboframes_bigger_jumbo(self): """ When the jubmo frame MTU set as 9000, this case is to verify that the packet which the length bigger than MTU can not be forwarded. """ self.pmdout.start_testpmd( "Default", "--max-pkt-len=%s --port-topology=loop" % (ETHER_JUMBO_FRAME_MTU)) self.dut.send_expect("set fwd mac", "testpmd> ") self.dut.send_expect("start", "testpmd> ") """ On 1G NICs, when the jubmo frame MTU set as 9000, the software adjust it to 9004. """ if self.nic in ["powerville", "springville", "kawela_4"]: self.jumboframes_send_packet(ETHER_JUMBO_FRAME_MTU + 4 + 1, False) else: self.jumboframes_send_packet(ETHER_JUMBO_FRAME_MTU + 1, False) self.dut.send_expect("quit", "# ", 30) def tear_down(self): """ Run after each test case. """ pass def tear_down_all(self): """ When the case of this test suite finished, the enviroment should clear up. """ self.tester.send_expect( "ifconfig %s mtu %s" % (self.tester.get_interface( self.tester.get_local_port(self.rx_port)), ETHER_STANDARD_MTU), "# ") self.tester.send_expect( "ifconfig %s mtu %s" % (self.tester.get_interface( self.tester.get_local_port(self.tx_port)), ETHER_STANDARD_MTU), "# ")
class TestEtag(TestCase): supported_vf_driver = ['pci-stub', 'vfio-pci'] def set_up_all(self): self.dut_ports = self.dut.get_ports(self.nic) self.verify(self.nic in ['sagepond', 'sageville'], '802.1BR only support by sagepond and sageville') self.verify(len(self.dut_ports) >= 1, 'Insufficient ports') self.src_intf = self.tester.get_interface( self.tester.get_local_port(0)) self.src_mac = self.tester.get_mac(self.tester.get_local_port(0)) self.dst_mac = self.dut.get_mac_address(0) self.vm0 = None self.printFlag = self._enable_debug self.dut.send_expect('ls', '#') self.setup_vm_env_flag = 0 self.preset_host_cmds = list() def set_up(self): pass def setup_vm_env(self, driver='default'): ''' setup qemu virtual environment ''' if self.setup_vm_env_flag == 1: return self.used_dut_port_0 = self.dut_ports[0] self.dut.generate_sriov_vfs_by_port(self.used_dut_port_0, 2, driver=driver) self.sriov_vfs_port_0 = self.dut.ports_info[ self.used_dut_port_0]['vfs_port'] # set vf assign method and vf driver self.vf_driver = self.get_suite_cfg()['vf_driver'] if self.vf_driver is None: self.vf_driver = 'pci-stub' self.verify(self.vf_driver in self.supported_vf_driver, "Unspported vf driver") if self.vf_driver == 'pci-stub': self.vf_assign_method = 'pci-assign' else: self.vf_assign_method = 'vfio-pci' self.dut.send_expect('modprobe vfio-pci', '#') try: for port in self.sriov_vfs_port_0: port.bind_driver(self.vf_driver) time.sleep(1) vf0_prop = {'opt_host': self.sriov_vfs_port_0[0].pci} vf1_prop = {'opt_host': self.sriov_vfs_port_0[1].pci} # 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_0[1].pci } self.preset_host_testpmd(VM_CORES_MASK, eal_param) # set up VM0 ENV self.vm0 = QEMUKvm(self.dut, 'vm0', 'vf_etag') self.vm0.set_vm_device(driver=self.vf_assign_method, **vf0_prop) self.vm0.set_vm_device(driver=self.vf_assign_method, **vf1_prop) self.vm_dut_0 = self.vm0.start() if self.vm_dut_0 is None: raise Exception('Set up VM0 ENV failed!') except Exception as e: print e self.destroy_vm_env() raise Exception(e) def destroy_vm_env(self): #destroy testpmd in vm0 if getattr(self, 'vm0_testpmd', None) and self.vm0_testpmd: self.vm0_testpmd.execute_cmd('stop') self.vm0_testpmd.execute_cmd('quit', '# ') self.vm0_testpmd = None #destroy vm0 if getattr(self, 'vm0', None) and self.vm0: self.vm0_dut_ports = None self.vm0.stop() self.vm0 = None #destroy host testpmd if getattr(self, 'host_testpmd', None): self.host_testpmd.execute_cmd('quit', '# ') self.host_testpmd = None # reset used port's sriov if getattr(self, 'used_dut_port_0', None): self.dut.destroy_sriov_vfs_by_port(self.used_dut_port_0) port = self.dut.ports_info[self.used_dut_port_0]['port'] port.bind_driver() self.used_dut_port_0 = None # bind used ports with default driver for port_id in self.dut_ports: port = self.dut.ports_info[port_id]['port'] port.bind_driver() self.setup_vm_env_flag = 0 def check_packet_transmission(self, pkt_types): time.sleep(1) for pkt_type in pkt_types.keys(): intf = self.src_intf pkt = Packet(pkt_type=pkt_type) # set packet every layer's input parameters if 'layer_configs' in pkt_types[pkt_type].keys(): pkt_configs = pkt_types[pkt_type]['layer_configs'] if pkt_configs: for layer in pkt_configs.keys(): pkt.config_layer(layer, pkt_configs[layer]) pkt.send_pkt(tx_port=self.src_intf) # check vm testpmd packet received information if 'vm' in pkt_types[pkt_type].keys(): out = self.vm0_testpmd.get_output(timeout=2) if self.printFlag: # debug output print out for pkt_attribute in pkt_types[pkt_type]['vm']: if self.printFlag: # debug output print pkt_attribute if pkt_attribute not in out: print utils.RED('Fail to detect %s' % pkt_attribute) if not self.printFlag: # print out all info in debug mode raise VerifyFailure('Failed to detect %s' % pkt_attribute) print utils.GREEN('VM detected %s successfully' % pkt_type) # check dut testpmd packet received information if 'dut' in pkt_types[pkt_type].keys(): out = self.host_testpmd.get_output(timeout=2) if self.printFlag: # debug output print out for pkt_attribute in pkt_types[pkt_type]['dut']: if self.printFlag: # debug output print pkt_attribute if pkt_attribute not in out: print utils.RED('Fail to detect %s' % pkt_attribute) if not self.printFlag: # print out all info in debug mode raise VerifyFailure('Failed to detect %s' % pkt_attribute) print utils.GREEN('DUT detected %s successfully' % pkt_type) time.sleep(1) def preset_host_testpmd(self, core_mask, eal_param): if self.setup_vm_env_flag == 0: self.host_testpmd.start_testpmd(core_mask, param='--port-topology=loop', eal_param=eal_param) self.execute_host_testpmd_cmd(self.preset_host_cmds) self.preset_host_cmds = list() time.sleep(2) def execute_host_testpmd_cmd(self, cmds): if len(cmds) == 0: return for item in cmds: if len(item) == 2: self.host_testpmd.execute_cmd(item[0], int(item[1])) else: self.host_testpmd.execute_cmd(item[0]) time.sleep(2) def preset_guest_testpmd(self): if self.setup_vm_env_flag == 0: self.vm0_testpmd = PmdOutput(self.vm_dut_0) self.vm0_testpmd.start_testpmd(VM_CORES_MASK, param='--port-topology=loop') time.sleep(1) elif self.vm0_testpmd: self.vm0_testpmd.quit() self.vm0_testpmd.start_testpmd(VM_CORES_MASK, param='--port-topology=loop') time.sleep(1) def execute_guest_testpmd_cmd(self, cmds): if len(cmds) == 0: return for item in cmds: if len(item) == 2: self.vm0_testpmd.execute_cmd(item[0], int(item[1])) else: self.vm0_testpmd.execute_cmd(item[0]) def preset_test_enviroment(self): self.setup_vm_env(driver='igb_uio') self.preset_guest_testpmd() self.setup_vm_env_flag = 1 time.sleep(2) def test_l2_tunnel_filter(self): ''' Enable E-tag l2 tunnel support means enabling ability of parsing E-tag packet. This ability should be enabled before we enable filtering, forwarding, offloading for this specific type of tunnel. ''' host_cmds = [['port config 0 l2-tunnel E-tag enable'], ['set fwd rxonly'], ['set verbose 1'], ['start']] guest_cmds = [['set fwd rxonly'], ['set verbose 1'], ['start']] config_layers = { 'ether': { 'src': self.src_mac }, 'etag': { 'ECIDbase': 1000 } } pkt_types = { 'ETAG_UDP': { 'dut': ['type=0x893f'], 'vm': ['type=0x893f'], 'layer_configs': config_layers } } self.preset_test_enviroment() self.execute_host_testpmd_cmd(host_cmds) self.execute_guest_testpmd_cmd(guest_cmds) self.check_packet_transmission(pkt_types) def test_etag_filter(self): ''' when E-tag packet forwarding and add E-tag on VF0 ''' test_types = ['etag_pf', 'etag_remove', 'etag_vf_0', 'etag_vf_1'] host_cmds = [['port config 0 l2-tunnel E-tag enable'], ['E-tag set forwarding on port 0']] self.preset_test_enviroment() self.execute_host_testpmd_cmd(host_cmds) for test_type in test_types: host_cmds = list() guest_cmds = [['set fwd rxonly'], ['set verbose 1'], ['start']] if test_type == 'etag_pf': # Same E-tag forwarding to PF0, Send 802.1BR packet with broadcast mac and # check packet only received on PF host_cmds = [[ 'E-tag set filter add e-tag-id 1000 dst-pool 2 port 0' ], ['set fwd mac'], ['set verbose 1'], ['start']] # set packet type and its expecting result config_layers = { 'ether': { 'src': self.src_mac, 'dst': self.dst_mac }, 'etag': { 'ECIDbase': 1000 } } pkt_types = { 'ETAG_UDP': { 'dut': ['type=0x893f'], 'layer_configs': config_layers } } elif test_type == 'etag_remove': # Remove E-tag, Send 802.1BR packet with broadcast mac and check packet not # received host_cmds = [['E-tag set filter del e-tag-id 1000 port 0'], ['set fwd rxonly'], ['set verbose 1'], ['start']] config_layers = { 'ether': { 'src': self.src_mac }, 'etag': { 'ECIDbase': 1000 } } pkt_types = { 'ETAG_UDP': { 'vm': [''], 'dut': [''], 'layer_configs': config_layers } } else: # Same E-tag forwarding to VF0, Send 802.1BR packet with broadcast mac and # check packet only received on VF0 or VF1 host_cmds = [[ 'E-tag set filter add e-tag-id 1000 dst-pool %d port 0' % int(test_type[-1:]) ], ['set fwd rxonly'], ['set verbose 1'], ['start']] config_layers = { 'ether': { 'src': self.src_mac }, 'etag': { 'ECIDbase': 1000 } } pkt_types = { 'ETAG_UDP': { 'vm': ['type=0x893f'], 'layer_configs': config_layers } } self.execute_host_testpmd_cmd(host_cmds) self.execute_guest_testpmd_cmd(guest_cmds) self.check_packet_transmission(pkt_types) self.host_testpmd.execute_cmd('E-tag set forwarding off port 0') def test_etag_insertion(self): ''' When E-tag insertion enable in VF0 ''' host_cmds = [['port config 0 l2-tunnel E-tag enable'], ['E-tag set insertion on port-tag-id 1000 port 0 vf 0'], ['set fwd mac'], ['set verbose 1'], ['start']] guest_cmds = [['set fwd mac'], ['set verbose 1'], ['start']] self.preset_test_enviroment() self.execute_host_testpmd_cmd(host_cmds) self.execute_guest_testpmd_cmd(guest_cmds) self.vm0_dut_ports = self.vm_dut_0.get_ports('any') config_layers = {'ether': {'src': self.src_mac}} pkt_types = {'IP_RAW': {'layer_configs': config_layers}} intf = self.src_intf inst = self.tester.tcpdump_sniff_packets(intf) self.check_packet_transmission(pkt_types) time.sleep(1) pkts = self.tester.load_tcpdump_sniff_packets(inst) self.host_testpmd.execute_cmd( 'E-tag set insertion off port-tag-id 1000 port 0 vf 0') # load sniff pcap file, check received packet's content packetContentFile = "/tmp/packetContent.log" pcap_file = "/tmp/sniff_%s.pcap" % intf fp = open(packetContentFile, 'w') backup_out = sys.stdout sys.stdout = fp pkts = rdpcap(pcap_file) pkts.show() fp.close() sys.stdout = backup_out fp = open(packetContentFile, 'r') out = fp.read() fp.close() if self.printFlag: # debug output print out self.verify("Dot1BR" in out, "tester %s hasn't receiver etag packet" % intf) def test_etag_strip(self): ''' When E-tag strip enable on PF ''' host_cmds = [['port config 0 l2-tunnel E-tag enable'], ['set fwd rxonly'], ['set verbose 1'], ['start']] guest_cmds = [['set fwd rxonly'], ['set verbose 1'], ['start']] config_layers = { 'ether': { 'src': self.src_mac }, 'etag': { 'ECIDbase': 1000 } } pkt_types_on = { 'ETAG_UDP': { 'vm': ['type=0x0800', 'type=0x893f'], 'layer_configs': config_layers } } pkt_types_off = { 'ETAG_UDP': { 'vm': ['type=0x893f', 'type=0x893f'], 'layer_configs': config_layers } } self.preset_test_enviroment() self.execute_host_testpmd_cmd(host_cmds) self.execute_guest_testpmd_cmd(guest_cmds) # Enable E-tag strip on PF, Send 802.1BR packet to VF and check forwarded packet without E-tag self.host_testpmd.execute_cmd('E-tag set stripping on port 0') self.check_packet_transmission(pkt_types_on) # Disable E-tag strip on PF, Send 802.1BR packet and check forwarded packet with E-tag self.host_testpmd.execute_cmd('E-tag set stripping off port 0') self.check_packet_transmission(pkt_types_off) def tear_down(self): pass def tear_down_all(self): if self.setup_vm_env_flag == 1: self.destroy_vm_env() if getattr(self, 'vm0', None): self.vm0.stop() for port_id in self.dut_ports: self.dut.destroy_sriov_vfs_by_port(port_id) self.tester.send_expect( "kill -9 $(ps aux | grep -i qemu | grep -v grep | awk {'print $2'})", '# ', 5)
class TestDualVlan(TestCase): def set_up_all(self): """ Run at the start of each test suite. Vlan Prerequistites """ global dutRxPortId global dutTxPortId # Based on h/w type, choose how many ports to use ports = self.dut.get_ports(self.nic) self.verify(len(ports) >= 2, "Insufficient ports") self.ports_socket = self.dut.get_numa_id(ports[0]) cores = self.dut.get_core_list('1S/2C/2T') coreMask = utils.create_mask(cores) ports = self.dut.get_ports(self.nic) valports = [_ for _ in ports if self.tester.get_local_port(_) != -1] portMask = utils.create_mask(valports[:2]) dutRxPortId = valports[0] dutTxPortId = valports[1] self.pmdout = PmdOutput(self.dut) self.pmdout.start_testpmd("Default", "--portmask=%s" % portMask, socket=self.ports_socket) if self.nic in ["fortville_eagle", "fortville_spirit", "fortville_spirit_single", "fortville_25g", "fortpark_TLV"]: self.dut.send_expect("vlan set filter on all", "testpmd> ") self.dut.send_expect("set promisc all off", "testpmd> ") out = self.dut.send_expect("set fwd mac", "testpmd> ") self.verify('Set mac packet forwarding mode' in out, "set fwd mac error") out = self.dut.send_expect("start", "testpmd> ", 120) def start_tcpdump(self, rxItf): self.tester.send_expect("rm -rf ./getPackageByTcpdump.cap", "#") self.tester.send_expect("tcpdump -i %s -w ./getPackageByTcpdump.cap 2> /dev/null& " % rxItf, "#") def get_tcpdump_package(self): self.tester.send_expect("killall tcpdump", "#") return self.tester.send_expect("tcpdump -nn -e -v -r ./getPackageByTcpdump.cap", "#") def vlan_send_packet(self, *vid): """ Send packet to portid """ txPort = self.tester.get_local_port(dutRxPortId) rxPort = self.tester.get_local_port(dutTxPortId) txItf = self.tester.get_interface(txPort) rxItf = self.tester.get_interface(rxPort) mac = self.dut.get_mac_address(dutRxPortId) self.start_tcpdump(rxItf) vlanString = 'sendp([Ether(dst="%s")/' % mac for i in range(len(vid)): vlanString += "Dot1Q(id=0x8100,vlan=%s)/" % vid[i] vlanString += 'IP(len=46)],iface="%s")' % txItf self.tester.scapy_append(vlanString) self.tester.scapy_execute() def mode_config(self, **modeName): """ Set up the VLAN mode. """ for mode in modeName: if self.nic in ["fortville_eagle", "fortville_spirit", "fortville_spirit_single", "fortville_25g", "fortpark_TLV"]: # fortville NIC vlan filter can't close, if want close need remove rx_vlan if mode == "filter": if modeName[mode] == "off": self.dut.send_expect("rx_vlan add %s %s" % (outvlan, dutRxPortId), "testpmd> ") continue else: self.dut.send_expect("rx_vlan rm %s %s" % (outvlan, dutRxPortId), "testpmd> ") continue if mode == "stripq": self.dut.send_expect("vlan set %s %s %s,0" % (mode, modeName[mode], dutRxPortId), "testpmd> ") else: self.dut.send_expect("vlan set %s %s %s" % (mode, modeName[mode], dutRxPortId), "testpmd> ") out = self.dut.send_expect("show port info %s" % dutRxPortId, "testpmd> ") for mode in modeName: if self.nic in ["fortville_eagle", "fortville_spirit", "fortville_spirit_single", "fortville_25g","fortpark_TLV"]: # fortville NIC vlan filter can't close, if want close need remove rx_vlan if mode == "filter": if modeName[mode] == "off": self.dut.send_expect("rx_vlan add %s %s" % (outvlan, dutRxPortId), "testpmd> ") continue else: self.dut.send_expect("rx_vlan rm %s %s" % (outvlan, dutRxPortId), "testpmd> ") continue if mode == "qinq": self.verify("qinq(extend) %s" % modeName[mode] in out, "%s setting error" % mode) continue elif mode == "stripq": continue else: self.verify("%s %s" % (mode, modeName[mode]) in out, "%s setting error" % mode) def multimode_test(self, caseIndex): """ Setup Strip/Filter/Extend/Insert enable/disable for synthetic test. """ caseDef = vlanCaseDef[caseIndex] temp = [] temp.append("on") if (caseDef & stripCase) != 0 else temp.append("off") temp.append("on") if (caseDef & filterCase) != 0 else temp.append("off") temp.append("on") if (caseDef & qinqCase) != 0 else temp.append("off") self.mode_config(strip=temp[0], filter=temp[1], qinq=temp[2]) if (caseDef & txCase) != 0: self.dut.send_expect('tx_vlan set %s %s' % (dutTxPortId, txvlan), "testpmd> ") configMode = "Strip %s, filter %s 0x1, extend %s, insert %s" % (temp[0], temp[1], temp[2], "on" if (caseDef & txCase) != 0 else "off") if (caseDef & filterCase) != 0: self.dut.send_expect('rx_vlan add %s %s' % (outvlan, dutRxPortId), "testpmd> ") self.vlan_send_packet(outvlan, invlan) self.check_result(vlanCase[caseIndex][0], configMode + " result Error") self.dut.send_expect('rx_vlan rm %s %s' % (outvlan, dutRxPortId), "testpmd> ") self.dut.send_expect('rx_vlan add %s %s' % (invlan, dutRxPortId), "testpmd> ") self.vlan_send_packet(outvlan, invlan) self.check_result(vlanCase[caseIndex][1], configMode + " result Error") self.dut.send_expect('rx_vlan rm %s %s' % (invlan, dutRxPortId), "testpmd> ") if (caseDef & txCase) != 0: self.dut.send_expect('tx_vlan reset %s' % dutTxPortId, "testpmd> ") else: self.dut.send_expect('rx_vlan add %s %s' % (invlan, dutRxPortId), "testpmd> ") self.dut.send_expect('rx_vlan add %s %s' % (outvlan, dutRxPortId), "testpmd> ") self.vlan_send_packet(outvlan, invlan) self.check_result(vlanCase[caseIndex], configMode + " result Error") if (caseDef & txCase) != 0: self.dut.send_expect('tx_vlan reset %s' % dutTxPortId, "testpmd> ") self.dut.send_expect('rx_vlan rm %s %s' % (invlan, dutRxPortId), "testpmd> ") self.dut.send_expect('rx_vlan rm %s %s' % (outvlan, dutRxPortId), "testpmd> ") def check_result(self, resultKey, errorString): """ Check results of synthetic test. """ print "vlan flage config:%s" % errorString out = self.get_tcpdump_package() if allResult[resultKey][0] == "No": self.verify("vlan" not in out, errorString) else: resultList = [] for i in range(len(allResult[resultKey]) - 1): resultList.append("vlan %s" % allResult[resultKey][i]) resultList.append("vlan %s" % allResult[resultKey][len(allResult[resultKey]) - 1]) for line in resultList: self.verify(line in out, "reviceive package is wrong:%s" % out) def set_up(self): """ Run before each test case. """ pass def test_vlan_filter_config(self): """ Enable/Disable VLAN packets filtering """ self.mode_config(filter="on") self.mode_config(strip="off") self.mode_config(qinq="off") self.vlan_send_packet(outvlan) out = self.get_tcpdump_package() print out self.verify(out is not None and "vlan %s" % outvlan not in out, "Vlan filter enable error: " + out) if self.nic not in ["fortville_eagle", "fortville_spirit", "fortville_spirit_single", "fortville_25g", "fortpark_TLV"]: self.mode_config(filter="off") self.vlan_send_packet(outvlan) out = self.get_tcpdump_package() self.verify("vlan %s" % outvlan in out, "Vlan filter disable error: " + out) else: self.dut.send_expect('rx_vlan add %s %s' % (outvlan, dutRxPortId), "testpmd> ") self.vlan_send_packet(outvlan) out = self.get_tcpdump_package() self.verify("vlan %s" % outvlan in out, "Vlan filter disable error: " + out) self.dut.send_expect('rx_vlan rm %s %s' % (outvlan, dutRxPortId), "testpmd> ") def test_vlan_filter_table(self): """ Add/Remove VLAN Tag Identifier pass VLAN filtering """ self.mode_config(filter="on") self.mode_config(strip="off") self.mode_config(qinq="off") self.dut.send_expect("rx_vlan add %s %s" % (outvlan, dutRxPortId), "testpmd> ") self.vlan_send_packet(outvlan) out = self.get_tcpdump_package() self.verify("vlan %s" % outvlan in out, "vlan filter table enable error: " + out) self.dut.send_expect("rx_vlan rm %s %s" % (outvlan, dutRxPortId), "testpmd> ") self.vlan_send_packet(outvlan) out = self.get_tcpdump_package() self.verify(out is not None and "vlan %s" % outvlan not in out, "vlan filter table disable error: " + out) def test_vlan_strip_config(self): """ Enable/Disable VLAN packets striping """ self.mode_config(filter="off") self.mode_config(qinq="off") self.mode_config(strip="on") if self.nic in ["fortville_eagle", "fortville_spirit", "fortville_spirit_single", "fortville_25g", "fortpark_TLV"]: self.dut.send_expect('rx_vlan add %s %s' % (outvlan, dutRxPortId), "testpmd> ") self.vlan_send_packet(outvlan) out = self.get_tcpdump_package() self.verify("vlan %s" % outvlan not in out, "Vlan strip enable error: " + out) self.mode_config(strip="off") self.vlan_send_packet(outvlan) out = self.get_tcpdump_package() self.verify("vlan %s" % outvlan in out, "Vlan strip disable error: " + out) if self.nic in ["fortville_eagle", "fortville_spirit", "fortville_spirit_single", "fortville_25g", "fortpark_TLV"]: self.dut.send_expect('rx_vlan rm %s %s' % (outvlan, dutRxPortId), "testpmd> ") def test_vlan_stripq_config(self): """ Enable/Disable VLAN packets strip on queue """ self.verify(self.nic not in ["fortville_eagle", "fortville_spirit", "fortville_spirit_single", "fortville_25g", "fortpark_TLV"], "%s NIC not support queue vlan strip " % self.nic) self.mode_config(filter="off") self.mode_config(qinq="off") self.mode_config(strip="off") self.mode_config(stripq="off") if self.nic in ["fortville_eagle", "fortville_spirit", "fortville_spirit_single", "fortville_25g", "fortpark_TLV"]: self.dut.send_expect('rx_vlan add %s %s' % (outvlan, dutRxPortId), "testpmd> ") self.vlan_send_packet(outvlan) out = self.get_tcpdump_package() self.verify("vlan %s" % outvlan in out, "vlan strip queue disable error : " + out) # if self.nic in ["fortville_eagle", "fortville_spirit", "fortville_spirit_single"]: self.mode_config(strip="on") self.mode_config(stripq="on") self.vlan_send_packet(outvlan) out = self.get_tcpdump_package() self.verify("vlan %s" % outvlan not in out, "vlan strip enable error: " + out) self.mode_config(stripq="off") self.vlan_send_packet(outvlan) out = self.get_tcpdump_package() self.verify("vlan %s" % outvlan in out, "vlan strip queue disable error: " + out) if self.nic in ["fortville_eagle", "fortville_spirit", "fortville_spirit_single", "fortville_25g", "fortpark_TLV"]: self.dut.send_expect('rx_vlan rm %s %s' % (outvlan, dutRxPortId), "testpmd> ") def test_vlan_insert_config(self): """ Enable/Disable VLAN packets inserting """ self.mode_config(filter="off") self.mode_config(qinq="off") # hartwell need to set CTRL.VME for vlan insert if(self.nic == "hartwell"): self.dut.send_expect("vlan set strip on %s" % dutTxPortId, "testpmd> ") self.dut.send_expect("tx_vlan set %s %s" % (dutTxPortId, txvlan), "testpmd> ") self.vlan_send_packet() out = self.get_tcpdump_package() self.verify("vlan %s" % txvlan in out, "vlan inset enalber error: " + out) self.dut.send_expect("tx_vlan reset %s" % dutTxPortId, "testpmd> ") self.vlan_send_packet() out = self.get_tcpdump_package() self.verify("vlan %s" % txvlan not in out, "vlan inset disable error: " + out) def test_vlan_tpid_config(self): """ Configure receive port out vlan TPID """ self.verify(self.nic not in ["fortville_eagle", "fortville_spirit", "fortville_spirit_single", "fortville_25g", "fortpark_TLV", "hartwell"], "%s NIC not support tcpid " % self.nic) self.mode_config(filter="on", strip="on", qinq="on") # nic only support inner model, except fortville nic self.dut.send_expect("vlan set inner tpid 1234 %s" % dutRxPortId, "testpmd> ") self.vlan_send_packet(outvlan, invlan) out = self.get_tcpdump_package() self.verify("vlan %s" % outvlan in out, "vlan tpid disable error: " + out) self.verify("vlan %s" % invlan in out, "vlan tpid disable error: " + out) self.dut.send_expect("vlan set inner tpid 0x8100 %s" % dutRxPortId, "testpmd> ") self.vlan_send_packet(outvlan, invlan) out = self.get_tcpdump_package() self.verify(out is not None and "vlan" not in out, "vlane tpid enable error: " + out) def test_vlan_synthetic_test(self): """ VLAN synthetic test. """ self.verify(self.nic != "hartwell", "sorry, dual vlan cannot support this self.nic") for i in range(len(vlanCase)): self.multimode_test(i) def test_vlan_random_test(self): """ VLAN random test. """ self.verify(self.nic != "hartwell", "sorry, dual vlan cannot support this self.nic") for _ in range(30): rand = random.randint(0, 15) self.multimode_test(rand) def tear_down(self): """ Run after each test case. """ pass def tear_down_all(self): """ Run after each test suite. """ self.dut.kill_all() pass
class TestIeee1588(TestCase): def set_up_all(self): """ Run at the start of each test suite. IEEE1588 Prerequisites """ dutPorts = self.dut.get_ports() self.verify(len(dutPorts) > 0, "No ports found for " + self.nic) # Change the config file to support IEEE1588 and recompile the package. if "bsdapp" in self.target: self.dut.send_expect( "sed -i -e 's/IEEE1588=n$/IEEE1588=y/' config/common_bsdapp", "# ", 30) else: self.dut.send_expect( "sed -i -e 's/IEEE1588=n$/IEEE1588=y/' config/common_linuxapp", "# ", 30) self.dut.skip_setup = False self.dut.build_install_dpdk(self.target) self.pmdout = PmdOutput(self.dut) self.pmdout.start_testpmd("all") def set_up(self): """ Run before each test case. """ pass def test_ieee1588_enable(self): """ IEEE1588 Enable test case. """ self.dut.send_expect("set fwd ieee1588", "testpmd> ") self.dut.send_expect( "start", ">", 5 ) # Waiting for 'testpmd> ' Fails due to log messages, "Received non PTP packet", in the output time.sleep( 1 ) # Allow the output from the "start" command to finish before looking for a regexp in expect # use the first port on that self.nic dutPorts = self.dut.get_ports() port = self.tester.get_local_port(dutPorts[0]) itf = self.tester.get_interface(port) self.tester.scapy_background() self.tester.scapy_append('p = sniff(iface="%s", count=2)' % itf) self.tester.scapy_append('RESULT = p[1].summary()') # this is the output of sniff # [<Ether dst=01:1b:19:00:00:00 src=00:00:00:00:00:00 type=0x88f7 |<Raw load='\x00\x02' |>>] self.tester.scapy_foreground() self.tester.scapy_append('nutmac="01:1b:19:00:00:00"') self.tester.scapy_append( 'sendp([Ether(dst=nutmac,type=0x88f7)/"\\x00\\x02"], iface="%s")' % itf) self.tester.scapy_append('time.sleep(1)') self.tester.scapy_execute() out = self.tester.scapy_get_result() self.verify("0x88f7" in out, "Ether type is not PTP") # self.verify("\\x00\\x02" in out, "Payload wrong in PTP") time.sleep(1) out = self.dut.send_expect("stop", "testpmd> ") text = dts.regexp(out, "(.*) by hardware") self.verify("IEEE1588 PTP V2 SYNC" in text, "Not filtered " + text) rx_time = dts.regexp(out, "RX timestamp value (0x[0-9a-fA-F]+)") tx_time = dts.regexp(out, "TX timestamp value (0x[0-9a-fA-F]+)") self.verify(rx_time is not None, "RX timestamp error ") self.verify(tx_time is not None, "TX timestamp error ") self.verify(int(tx_time, 16) > int(rx_time, 16), "Timestamp mismatch") def test_ieee1588_disable(self): """ IEEE1588 Disable test case. """ self.dut.send_expect("stop", "testpmd> ") time.sleep(3) # use the first port on that self.nic dutPorts = self.dut.get_ports() port = self.tester.get_local_port(dutPorts[0]) itf = self.tester.get_interface(port) self.tester.scapy_background() self.tester.scapy_append('p = sniff(iface="%s", count=2, timeout=1)' % itf) self.tester.scapy_append('RESULT = p[1].summary()') self.tester.scapy_foreground() self.tester.scapy_append('nutmac="01:1b:19:00:00:00"') self.tester.scapy_append( 'sendp([Ether(dst=nutmac,type=0x88f7)/"\\x00\\x02"], iface="%s")' % itf) self.tester.scapy_execute() time.sleep(2) out = self.tester.scapy_get_result() self.verify("Ether" not in out, "Ether type is not PTP") def tear_down(self): """ Run after each test case. """ pass def tear_down_all(self): """ Run after each test suite. """ self.dut.send_expect("quit", "# ", 30) # Restore the config file and recompile the package. if "bsdapp" in self.target: self.dut.send_expect( "sed -i -e 's/IEEE1588=y$/IEEE1588=n/' config/common_bsdapp", "# ", 30) else: self.dut.send_expect( "sed -i -e 's/IEEE1588=y$/IEEE1588=n/' config/common_linuxapp", "# ", 30) self.dut.build_install_dpdk(self.target)
class TestVfOffload(TestCase): supported_vf_driver = ['pci-stub', 'vfio-pci'] def set_up_all(self): self.dut_ports = self.dut.get_ports(self.nic) self.verify(len(self.dut_ports) > 1, "Insufficient ports") self.vm0 = None # set vf assign method and vf driver self.vf_driver = self.get_suite_cfg()['vf_driver'] if self.vf_driver is None: self.vf_driver = 'pci-stub' self.verify(self.vf_driver in self.supported_vf_driver, "Unsupported vf driver") if self.vf_driver == 'pci-stub': self.vf_assign_method = 'pci-assign' else: self.vf_assign_method = 'vfio-pci' self.dut.send_expect('modprobe vfio-pci', '#') self.setup_2pf_2vf_1vm_env_flag = 0 self.setup_2pf_2vf_1vm_env(driver='') self.vm0_dut_ports = self.vm_dut_0.get_ports('any') self.portMask = utils.create_mask([self.vm0_dut_ports[0]]) self.vm0_testpmd = PmdOutput(self.vm_dut_0) def set_up(self): pass def setup_2pf_2vf_1vm_env(self, driver='default'): self.used_dut_port_0 = self.dut_ports[0] self.dut.generate_sriov_vfs_by_port(self.used_dut_port_0, 1, driver=driver) self.sriov_vfs_port_0 = self.dut.ports_info[self.used_dut_port_0]['vfs_port'] self.used_dut_port_1 = self.dut_ports[1] self.dut.generate_sriov_vfs_by_port(self.used_dut_port_1, 1, driver=driver) self.sriov_vfs_port_1 = self.dut.ports_info[self.used_dut_port_1]['vfs_port'] try: for port in self.sriov_vfs_port_0: port.bind_driver(self.vf_driver) for port in self.sriov_vfs_port_1: port.bind_driver(self.vf_driver) time.sleep(1) vf0_prop = {'opt_host': self.sriov_vfs_port_0[0].pci} vf1_prop = {'opt_host': self.sriov_vfs_port_1[0].pci} 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) # set up VM0 ENV self.vm0 = VM(self.dut, 'vm0', 'vf_offload') self.vm0.set_vm_device(driver=self.vf_assign_method, **vf0_prop) self.vm0.set_vm_device(driver=self.vf_assign_method, **vf1_prop) self.vm_dut_0 = self.vm0.start() if self.vm_dut_0 is None: raise Exception("Set up VM0 ENV failed!") self.setup_2pf_2vf_1vm_env_flag = 1 except Exception as e: self.destroy_2pf_2vf_1vm_env() raise Exception(e) def destroy_2pf_2vf_1vm_env(self): if getattr(self, 'vm0', None): #destroy testpmd in vm0 self.vm0_testpmd = None self.vm0_dut_ports = None #destroy vm0 self.vm0.stop() self.dut.virt_exit() self.vm0 = None if getattr(self, 'host_testpmd', None): self.host_testpmd.execute_cmd('quit', '# ') self.host_testpmd = None if getattr(self, 'used_dut_port_0', None) != None: self.dut.destroy_sriov_vfs_by_port(self.used_dut_port_0) port = self.dut.ports_info[self.used_dut_port_0]['port'] port.bind_driver() self.used_dut_port_0 = None if getattr(self, 'used_dut_port_1', None) != None: self.dut.destroy_sriov_vfs_by_port(self.used_dut_port_1) port = self.dut.ports_info[self.used_dut_port_1]['port'] port.bind_driver() self.used_dut_port_1 = None for port_id in self.dut_ports: port = self.dut.ports_info[port_id]['port'] port.bind_driver() self.setup_2pf_2vf_1vm_env_flag = 0 def checksum_enablehw(self, port, dut): dut.send_expect("port stop all", "testpmd>") dut.send_expect("csum set ip hw %d" % port, "testpmd>") dut.send_expect("csum set udp hw %d" % port, "testpmd>") dut.send_expect("csum set tcp hw %d" % port, "testpmd>") dut.send_expect("csum set sctp hw %d" % port, "testpmd>") dut.send_expect("port start all", "testpmd>") def checksum_enablesw(self, port, dut): dut.send_expect("port stop all", "testpmd>") dut.send_expect("csum set ip sw %d" % port, "testpmd>") dut.send_expect("csum set udp sw %d" % port, "testpmd>") dut.send_expect("csum set tcp sw %d" % port, "testpmd>") dut.send_expect("csum set sctp sw %d" % port, "testpmd>") dut.send_expect("port start all", "testpmd>") def checksum_validate(self, packets_sent, packets_expected): """ Validate the checksum. """ tx_interface = self.tester.get_interface(self.tester.get_local_port(self.dut_ports[0])) rx_interface = self.tester.get_interface(self.tester.get_local_port(self.dut_ports[0])) sniff_src = self.vm0_testpmd.get_port_mac(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 print packet_type, ": ", chksums self.tester.send_expect("exit()", "#") self.tester.scapy_background() self.tester.scapy_append('p = sniff(filter="ether src %s", iface="%s", count=%d)' % (sniff_src, rx_interface, len(packets_sent))) self.tester.scapy_append('nr_packets=len(p)') self.tester.scapy_append('reslist = [p[i].sprintf("%IP.chksum%;%TCP.chksum%;%UDP.chksum%;%SCTP.chksum%") for i in range(nr_packets)]') self.tester.scapy_append('import string') self.tester.scapy_append('RESULT = string.join(reslist, ",")') # Send packet. self.tester.scapy_foreground() for packet_type in packets_sent.keys(): self.tester.scapy_append('sendp([%s], iface="%s")' % (packets_sent[packet_type], tx_interface)) self.tester.scapy_execute() out = self.tester.scapy_get_result() packets_received = out.split(',') self.verify(len(packets_sent) == len(packets_received), "Unexpected Packets Drop") for packet_received in packets_received: ip_checksum, tcp_checksum, udp_checksup, sctp_checksum = packet_received.split(';') print "ip_checksum: ", ip_checksum, "tcp_checksum:, ", tcp_checksum, "udp_checksup: ", udp_checksup, "sctp_checksum: ", sctp_checksum packet_type = '' l4_checksum = '' if tcp_checksum != '??': packet_type = 'TCP' l4_checksum = tcp_checksum elif udp_checksup != '??': packet_type = 'UDP' l4_checksum = udp_checksup elif sctp_checksum != '??': packet_type = 'SCTP' l4_checksum = sctp_checksum if ip_checksum != '??': packet_type = 'IP/' + packet_type if chksum[packet_type] != [ip_checksum, l4_checksum]: result[packet_type] = packet_type + " checksum error" else: packet_type = 'IPv6/' + packet_type if chksum[packet_type] != [l4_checksum]: result[packet_type] = packet_type + " checksum error" return result def test_checksum_offload_enable(self): """ Enable HW checksum offload. Send packet with incorrect checksum, can rx it and report the checksum error, verify forwarded packets have correct checksum. """ self.vm0_testpmd.start_testpmd(VM_CORES_MASK, "--portmask=%s " % (self.portMask) + "--enable-rx-cksum " + "" + "--port-topology=loop") self.vm0_testpmd.execute_cmd('set fwd csum') time.sleep(2) port_id_0 = 0 mac = self.vm0_testpmd.get_port_mac(0) sndIP = '10.0.0.1' sndIPv6 = '::1' pkts = {'IP/UDP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IP(src="%s", chksum=0xf)/UDP(chksum=0xf)/("X"*46)' % (mac, sndIP), 'IP/TCP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IP(src="%s", chksum=0xf)/TCP(chksum=0xf)/("X"*46)' % (mac, sndIP), 'IP/SCTP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IP(src="%s", chksum=0xf)/SCTP(chksum=0xf)/("X"*48)' % (mac, sndIP), 'IPv6/UDP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IPv6(src="%s")/UDP(chksum=0xf)/("X"*46)' % (mac, sndIPv6), 'IPv6/TCP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IPv6(src="%s")/TCP(chksum=0xf)/("X"*46)' % (mac, sndIPv6)} expIP = sndIP expIPv6 = sndIPv6 pkts_ref = {'IP/UDP': 'Ether(dst="02:00:00:00:00:00", src="%s")/IP(src="%s")/UDP()/("X"*46)' % (mac, expIP), 'IP/TCP': 'Ether(dst="02:00:00:00:00:00", src="%s")/IP(src="%s")/TCP()/("X"*46)' % (mac, expIP), 'IP/SCTP': 'Ether(dst="02:00:00:00:00:00", src="%s")/IP(src="%s")/SCTP()/("X"*48)' % (mac, expIP), 'IPv6/UDP': 'Ether(dst="02:00:00:00:00:00", src="%s")/IPv6(src="%s")/UDP()/("X"*46)' % (mac, expIPv6), 'IPv6/TCP': 'Ether(dst="02:00:00:00:00:00", src="%s")/IPv6(src="%s")/TCP()/("X"*46)' % (mac, expIPv6)} if self.nic in ['redrockcanyou', 'atwood']: del pkts['IP/SCTP'] del pkts_ref['IP/SCTP'] self.checksum_enablehw(0,self.vm_dut_0) self.vm0_testpmd.execute_cmd('start') result = self.checksum_validate(pkts, pkts_ref) # Validate checksum on the receive packet out = self.vm0_testpmd.execute_cmd('stop') bad_ipcsum = self.vm0_testpmd.get_pmd_value("Bad-ipcsum:", out) bad_l4csum = self.vm0_testpmd.get_pmd_value("Bad-l4csum:", out) self.verify(bad_ipcsum == 3, "Bad-ipcsum check error") self.verify(bad_l4csum == 5, "Bad-l4csum check error") self.verify(len(result) == 0, string.join(result.values(), ",")) def test_checksum_offload_disable(self): """ Enable SW checksum offload. Send same packet with incorrect checksum and verify checksum is valid. """ self.vm0_testpmd.start_testpmd(VM_CORES_MASK, "--portmask=%s " % (self.portMask) + "--enable-rx-cksum " + "--port-topology=loop") self.vm0_testpmd.execute_cmd('set fwd csum') time.sleep(2) mac = self.vm0_testpmd.get_port_mac(0) sndIP = '10.0.0.1' sndIPv6 = '::1' sndPkts = {'IP/UDP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IP(src="%s",chksum=0xf)/UDP(chksum=0xf)/("X"*46)' % (mac, sndIP), 'IP/TCP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IP(src="%s",chksum=0xf)/TCP(chksum=0xf)/("X"*46)' % (mac, sndIP), 'IPv6/UDP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IPv6(src="%s")/UDP(chksum=0xf)/("X"*46)' % (mac, sndIPv6), 'IPv6/TCP': 'Ether(dst="%s", src="52:00:00:00:00:00")/IPv6(src="%s")/TCP(chksum=0xf)/("X"*46)' % (mac, sndIPv6)} expIP = sndIP expIPv6 = sndIPv6 expPkts = {'IP/UDP': 'Ether(dst="02:00:00:00:00:00", src="%s")/IP(src="%s")/UDP()/("X"*46)' % (mac, expIP), 'IP/TCP': 'Ether(dst="02:00:00:00:00:00", src="%s")/IP(src="%s")/TCP()/("X"*46)' % (mac, expIP), 'IPv6/UDP': 'Ether(dst="02:00:00:00:00:00", src="%s")/IPv6(src="%s")/UDP()/("X"*46)' % (mac, expIPv6), 'IPv6/TCP': 'Ether(dst="02:00:00:00:00:00", src="%s")/IPv6(src="%s")/TCP()/("X"*46)' % (mac, expIPv6)} self.checksum_enablesw(0, self.vm_dut_0) self.vm0_testpmd.execute_cmd('start') result = self.checksum_validate(sndPkts, expPkts) # Validate checksum on the receive packet out = self.vm0_testpmd.execute_cmd('stop') bad_ipcsum = self.vm0_testpmd.get_pmd_value("Bad-ipcsum:", out) bad_l4csum = self.vm0_testpmd.get_pmd_value("Bad-l4csum:", out) self.verify(bad_ipcsum == 2, "Bad-ipcsum check error") self.verify(bad_l4csum == 4, "Bad-l4csum check error") self.verify(len(result) == 0, string.join(result.values(), ",")) def tcpdump_start_sniffing(self, ifaces=[]): """ Start tcpdump in the background to sniff the tester interface where the packets are transmitted to and from the self.dut. All the captured packets are going to be stored in a file for a post-analysis. """ for iface in ifaces: command = ('tcpdump -w tcpdump_{0}.pcap -i {0} 2>tcpdump_{0}.out &').format(iface) self.tester.send_expect('rm -f tcpdump_{0}.pcap', '#').format(iface) self.tester.send_expect(command, '#') def tcpdump_stop_sniff(self): """ Stop the tcpdump process running in the background. """ self.tester.send_expect('killall tcpdump', '#') time.sleep(1) self.tester.send_expect('echo "Cleaning buffer"', '#') time.sleep(1) def tcpdump_command(self, command): """ Send a tcpdump related command and return an integer from the output. """ result = self.tester.send_expect(command, '#') print result return int(result.strip()) def number_of_packets(self, iface): """ By reading the file generated by tcpdump it counts how many packets are forwarded by the sample app and received in the self.tester. The sample app will add a known MAC address for the test to look for. """ command = ('tcpdump -A -nn -e -v -r tcpdump_{iface}.pcap 2>/dev/null | ' + 'grep -c "seq"') return self.tcpdump_command(command.format(**locals())) def test_tso(self): """ TSO IPv4 TCP, IPv6 TCP testing. """ tx_interface = self.tester.get_interface(self.tester.get_local_port(self.dut_ports[0])) rx_interface = self.tester.get_interface(self.tester.get_local_port(self.dut_ports[1])) self.frame_sizes = [128, 1458] self.headers_size = HEADER_SIZE['eth'] + HEADER_SIZE['ip'] + HEADER_SIZE['tcp'] padding = self.frame_sizes[0] - self.headers_size self.tester.send_expect("ethtool -K %s rx off tx off tso off gso off gro off lro off" % tx_interface, "# ") self.tester.send_expect("ip l set %s up" % tx_interface, "# ") self.portMask = utils.create_mask([self.vm0_dut_ports[0]]) self.vm0_testpmd.start_testpmd(VM_CORES_MASK, "--portmask=%s " % (self.portMask) + "--enable-rx-cksum " + "" + "--port-topology=loop") mac = self.vm0_testpmd.get_port_mac(0) self.checksum_enablehw(0,self.vm_dut_0) self.vm0_testpmd.execute_cmd("tso set 800 %d" % self.vm0_dut_ports[1]) self.vm0_testpmd.execute_cmd("set fwd csum") self.vm0_testpmd.execute_cmd("start") self.tester.scapy_foreground() time.sleep(5) # IPv4 tcp test self.tcpdump_start_sniffing([tx_interface, rx_interface]) self.tester.scapy_append('sendp([Ether(dst="%s",src="52:00:00:00:00:00")/IP(src="192.168.1.1",dst="192.168.1.2")/TCP(sport=1021,dport=1021)/("X"*%s)], iface="%s")' % (mac, padding, tx_interface)) out = self.tester.scapy_execute() out = self.vm0_testpmd.execute_cmd("show port stats all") print out self.tcpdump_stop_sniff() rx_stats = self.number_of_packets(rx_interface) if (rx_stats == 2): self.verify(1, "Pass") # IPv6 tcp test self.tcpdump_start_sniffing([tx_interface, rx_interface]) self.tester.scapy_append('sendp([Ether(dst="%s", src="52:00:00:00:00:00")/IPv6(src="FE80:0:0:0:200:1FF:FE00:200", dst="3555:5555:6666:6666:7777:7777:8888:8888")/TCP(sport=1021,dport=1021)/("X"*%s)], iface="%s")' % (mac, padding, tx_interface)) out = self.tester.scapy_execute() out = self.vm0_testpmd.execute_cmd("show port stats all") print out self.tcpdump_stop_sniff() rx_stats = self.number_of_packets(rx_interface) if (rx_stats == 2): self.verify(1, "Pass") def tear_down(self): self.vm0_testpmd.execute_cmd('quit', '# ') pass def tear_down_all(self): print "tear_down_all" if self.setup_2pf_2vf_1vm_env_flag == 1: self.destroy_2pf_2vf_1vm_env()
class TestTX_preparation(TestCase): # # Test cases. # def set_up_all(self): """ Run at the start of each test suite. """ self.ports = self.dut.get_ports(self.nic) self.verify(len(self.ports) >= 1, "Insufficient number of ports.") self.used_dut_port = self.ports[0] tester_port = self.tester.get_local_port(self.used_dut_port) self.tester_intf = self.tester.get_interface(tester_port) out = self.tester.send_expect( "ethtool -K %s rx off tx off tso off gso\ off gro off lro off" % self.tester_intf, "#") if "Cannot change large-receive-offload" in out: self.tester.send_expect( "ethtool -K %s rx off tx off tso off gso\ off gro off" % self.tester_intf, "#") self.tester.send_expect( "ifconfig %s mtu %s" % (self.tester_intf, Max_mtu), "#") def set_up(self): """ Run before each test case. """ self.dut_testpmd = PmdOutput(self.dut) # use one port test the case self.dut_testpmd.start_testpmd( "Default", " --portmask=1 --port-topology=chained --max-pkt-len=%s --tx-offloads=0x8000" % Max_mtu) self.dmac = self.dut_testpmd.get_port_mac(0) self.dut_testpmd.execute_cmd('set fwd csum') self.dut_testpmd.execute_cmd('set verbose 1') #enable ip/udp/tcp hardware checksum self.dut_testpmd.execute_cmd('port stop all') self.dut_testpmd.execute_cmd('csum set ip hw 0') self.dut_testpmd.execute_cmd('csum set tcp hw 0') self.dut_testpmd.execute_cmd('csum set udp hw 0') def start_tcpdump(self, rxItf): # only sniff form dut packet and filter lldp packet param = "ether[12:2]!=0x88cc and ether src %s" % self.dmac self.tester.send_expect("rm -rf ./getPackageByTcpdump.cap", "#") self.tester.send_expect( "tcpdump %s -i %s -n -e -vv -w\ ./getPackageByTcpdump.cap 2> /dev/null& " % (param, rxItf), "#") def get_tcpdump_package(self): self.tester.send_expect("killall tcpdump", "#") return self.tester.send_expect( "tcpdump -nn -e -v -r ./getPackageByTcpdump.cap", "#") def send_packet_verify(self, tsoflag=0): """ Send packet to portid and output """ LrgLength = random.randint(Normal_mtu, Max_mtu - 100) pkts = { 'IPv4/cksum TCP': 'Ether(dst="%s")/IP()/TCP(flags=0x10)\ /Raw(RandString(50))' % self.dmac, 'IPv4/bad IP cksum': 'Ether(dst="%s")/IP(chksum=0x1234)\ /TCP(flags=0x10)/Raw(RandString(50))' % self.dmac, 'IPv4/bad TCP cksum': 'Ether(dst="%s")/IP()/TCP(flags=0x10,\ chksum=0x1234)/Raw(RandString(50))' % self.dmac, 'IPv4/large pkt': 'Ether(dst="%s")/IP()/TCP(flags=0x10)\ /Raw(RandString(%s))' % (self.dmac, LrgLength), 'IPv4/bad cksum/large pkt': 'Ether(dst="%s")/IP(chksum=0x1234)\ /TCP(flags=0x10,chksum=0x1234)/Raw(RandString(%s))' % (self.dmac, LrgLength), 'IPv6/cksum TCP': 'Ether(dst="%s")/IPv6()/TCP(flags=0x10)\ /Raw(RandString(50))' % self.dmac, 'IPv6/cksum UDP': 'Ether(dst="%s")/IPv6()/UDP()\ /Raw(RandString(50))' % self.dmac, 'IPv6/bad TCP cksum': 'Ether(dst="%s")/IPv6()/TCP(flags=0x10,\ chksum=0x1234)/Raw(RandString(50))' % self.dmac, 'IPv6/large pkt': 'Ether(dst="%s")/IPv6()/TCP(flags=0x10)\ /Raw(RandString(%s))' % (self.dmac, LrgLength) } for packet_type in pkts.keys(): self.start_tcpdump(self.tester_intf) self.tester.scapy_append('sendp([%s], iface="%s")' % (pkts[packet_type], self.tester_intf)) self.tester.scapy_execute() out = self.get_tcpdump_package() if packet_type == 'IPv6/cksum UDP': self.verify("udp sum ok" in out, "Failed to check UDP checksum correctness!!!") else: self.verify("cksum" in out, "Failed to check IP/TCP checksum!!!") self.verify( "correct" in out and "incorrect" not in out, "Failed to check IP/TCP/UDP checksum correctness!!!") if tsoflag == 1: if packet_type in\ ['IPv4/large pkt', 'IPv6/large pkt', 'IPv4/bad cksum/large pkt']: segnum = LrgLength / TSO_value LastLength = LrgLength % TSO_value num = out.count('length %s' % TSO_value) self.verify( "length %s" % TSO_value in out and num == segnum, "Failed to verify TSO correctness for large packets!!!" ) if LastLength != 0: num = out.count('length %s' % LastLength) self.verify( "length %s" % LastLength in out and num == 1, "Failed to verify TSO correctness for large packets!!!" ) def test_tx_preparation_NonTSO(self): """ ftag functional test """ self.dut_testpmd.execute_cmd('tso set 0 0') self.dut_testpmd.execute_cmd('port start all') self.dut_testpmd.execute_cmd('start') self.send_packet_verify() self.dut_testpmd.execute_cmd('stop') self.dut_testpmd.quit() def test_tx_preparation_TSO(self): """ ftag functional test """ self.dut_testpmd.execute_cmd('tso set %s 0' % TSO_value) self.dut_testpmd.execute_cmd('port start all') self.dut_testpmd.execute_cmd('start') self.send_packet_verify(1) self.dut_testpmd.execute_cmd('stop') self.dut_testpmd.quit() def tear_down(self): """ Run after each test case. """ pass def tear_down_all(self): """ Run after each test suite. """ self.tester.send_expect( "ifconfig %s mtu %s" % (self.tester_intf, Normal_mtu), "#") self.dut.kill_all()
class TestVfPortStartStop(TestCase): supported_vf_driver = ['pci-stub', 'vfio-pci'] def set_up_all(self): self.dut_ports = self.dut.get_ports(self.nic) self.verify(len(self.dut_ports) >= 1, "Insufficient ports") self.vm0 = None self.filename = "/tmp/vf.pcap" # set vf assign method and vf driver self.vf_driver = self.get_suite_cfg()['vf_driver'] if self.vf_driver is None: self.vf_driver = 'pci-stub' self.verify(self.vf_driver in self.supported_vf_driver, "Unspported vf driver") if self.vf_driver == 'pci-stub': self.vf_assign_method = 'pci-assign' else: self.vf_assign_method = 'vfio-pci' self.dut.send_expect('modprobe vfio-pci', '#') def set_up(self): self.setup_1pf_2vf_1vm_env_flag = 0 def pktgen_prerequisites(self): """ igb_uio.ko should be put in ~ before you using pktgen """ out = self.tester.send_expect("ls", "#") self.verify("igb_uio.ko" in out, "No file igb_uio.ko, please add it in ~") self.tester.send_expect("modprobe uio", "#", 70) out = self.tester.send_expect("lsmod | grep igb_uio", "#") if "igb_uio" in out: self.tester.send_expect("rmmod -f igb_uio", "#", 70) self.tester.send_expect("insmod ~/igb_uio.ko", "#", 60) out = self.tester.send_expect("lsmod | grep igb_uio", "#") assert ("igb_uio" in out), "Failed to insmod igb_uio" total_huge_pages = self.tester.get_total_huge_pages() if total_huge_pages == 0: self.tester.mount_huge_pages() self.tester.set_huge_pages(2048) def pktgen_kill(self): """ Kill all pktgen on tester. """ pids = [] pid_reg = r'p(\d+)' out = self.tester.alt_session.send_expect("lsof -Fp /var/run/.pg_config", "#", 20) if len(out): lines = out.split('\r\n') for line in lines: m = re.match(pid_reg, line) if m: pids.append(m.group(1)) for pid in pids: self.tester.alt_session.send_expect('kill -9 %s' % pid, '# ', 20) 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 --bind=igb_uio %s" % self.tester_tx_pci, "#") 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>") time.sleep(1) self.check_port_start_stop(testpmd) # quit pktgen self.tester.send_expect("stop all", "Pktgen>") self.tester.send_expect("quit", "# ") def create_pcap_file(self, filename, dst_mac, src_mac): """ Generates a valid PCAP file with the given configuration. """ def_pkts = {'IP/UDP': Ether(dst="%s" % dst_mac, src="%s" % src_mac)/IP(src="127.0.0.2")/UDP()/("X"*46), 'IP/TCP': Ether(dst="%s" % dst_mac, src="%s" % src_mac)/IP(src="127.0.0.2")/TCP()/("X"*46), 'IP/SCTP': Ether(dst="%s" % dst_mac, src="%s" % src_mac)/IP(src="127.0.0.2")/SCTP()/("X"*48), 'IPv6/UDP': Ether(dst="%s" % dst_mac, src="%s" % src_mac)/IPv6(src="::2")/UDP()/("X"*46), 'IPv6/TCP': Ether(dst="%s" % dst_mac, src="%s" % src_mac)/IPv6(src="::2")/TCP()/("X"*46),} pkts = [] for key in def_pkts.keys(): pkts.append(def_pkts[key]) wrpcap(filename, pkts) def testpmd_reset_status(self, testpmd): """ Reset testpmd :stop forword & stop port """ testpmd.execute_cmd('stop') testpmd.execute_cmd('port stop all') testpmd.execute_cmd('clear port stats all') def check_port_start_stop(self, testpmd, times=10): """ VF port start/stop several times , check if it work well. """ for i in range(times): out = testpmd.execute_cmd('port start all') self.verify("Checking link statuses" in out, "ERROR: port start all") testpmd.execute_cmd('start') time.sleep(.5) testpmd.execute_cmd('stop') out = testpmd.execute_cmd('port stop all') self.verify("Checking link statuses" in out, "ERROR: port stop all") port_id_0 = 0 port_id_1 = 1 vf0_stats = self.vm0_testpmd.get_pmd_stats(port_id_0) vf1_stats = self.vm0_testpmd.get_pmd_stats(port_id_1) vf0_rx_cnt = vf0_stats['RX-packets'] self.verify(vf0_rx_cnt != 0, "no packet was received by vm0_VF0") vf0_rx_err = vf0_stats['RX-errors'] self.verify(vf0_rx_err == 0, "vm0_VF0 rx-errors") vf1_tx_cnt = vf1_stats['TX-packets'] self.verify(vf1_tx_cnt != 0, "no packet was transmitted by vm0_VF1") vf1_tx_err = vf1_stats['TX-errors'] self.verify(vf1_tx_err == 0, "vm0_VF0 tx-errors") def setup_1pf_2vf_1vm_env(self, driver='default'): self.used_dut_port = self.dut_ports[0] self.dut.generate_sriov_vfs_by_port(self.used_dut_port, 2, driver=driver) self.sriov_vfs_port = self.dut.ports_info[self.used_dut_port]['vfs_port'] try: for port in self.sriov_vfs_port: port.bind_driver(self.vf_driver) time.sleep(1) vf0_prop = {'opt_host': self.sriov_vfs_port[0].pci} vf1_prop = {'opt_host': self.sriov_vfs_port[1].pci} 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) # set up VM0 ENV self.vm0 = QEMUKvm(self.dut, 'vm0', 'vf_port_start_stop') self.vm0.set_vm_device(driver=self.vf_assign_method, **vf0_prop) self.vm0.set_vm_device(driver=self.vf_assign_method, **vf1_prop) self.vm_dut_0 = self.vm0.start() if self.vm_dut_0 is None: raise Exception("Set up VM0 ENV failed!") self.setup_1pf_2vf_1vm_env_flag = 1 except Exception as e: self.destroy_1pf_2vf_1vm_env() raise Exception(e) def destroy_1pf_2vf_1vm_env(self): if getattr(self, 'vm0', None): #destroy testpmd in vm0 if getattr(self, 'vm0_testpmd', None): self.vm0_testpmd.execute_cmd('stop') self.vm0_testpmd.execute_cmd('quit', '# ') self.vm0_testpmd = None self.vm0_dut_ports = None #destroy vm0 self.vm0.stop() self.vm0 = None if getattr(self, 'host_testpmd', None): self.host_testpmd.execute_cmd('quit', '# ') self.host_testpmd = None if getattr(self, 'used_dut_port', None) != None: self.dut.destroy_sriov_vfs_by_port(self.used_dut_port) port = self.dut.ports_info[self.used_dut_port]['port'] port.bind_driver() self.used_dut_port = None for port_id in self.dut_ports: port = self.dut.ports_info[port_id]['port'] port.bind_driver() self.setup_1pf_2vf_1vm_env_flag = 0 def test_start_stop_with_kernel_1pf_2vf_1vm(self): self.setup_1pf_2vf_1vm_env(driver='') self.vm0_dut_ports = self.vm_dut_0.get_ports('any') self.vm0_testpmd = PmdOutput(self.vm_dut_0) self.vm0_testpmd.start_testpmd(VM_CORES_MASK) self.vm0_testpmd.execute_cmd('set fwd mac') time.sleep(2) dst_mac = self.vm0_testpmd.get_port_mac(self.vm0_dut_ports[0]) self.send_and_verify(dst_mac, self.vm0_testpmd) def tear_down(self): if self.setup_1pf_2vf_1vm_env_flag == 1: self.destroy_1pf_2vf_1vm_env() 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_nic_bind.py --bind=%s %s" \ %(self.tester_port_driver, self.tester_tx_pci), "#") if getattr(self, 'vm0', None): self.vm0.stop() self.dut.virt_exit() for port_id in self.dut_ports: self.dut.destroy_sriov_vfs_by_port(port_id)
class TestIeee1588(TestCase): def set_up_all(self): """ Run at the start of each test suite. IEEE1588 Prerequisites """ dutPorts = self.dut.get_ports() self.verify(len(dutPorts) > 0, "No ports found for " + self.nic) # Change the config file to support IEEE1588 and recompile the package. if "bsdapp" in self.target: self.dut.send_expect("sed -i -e 's/IEEE1588=n$/IEEE1588=y/' config/common_bsdapp", "# ", 30) else: self.dut.send_expect("sed -i -e 's/IEEE1588=n$/IEEE1588=y/' config/common_linuxapp", "# ", 30) self.dut.skip_setup = False self.dut.build_install_dpdk(self.target) self.pmdout = PmdOutput(self.dut) self.pmdout.start_testpmd("all") def set_up(self): """ Run before each test case. """ pass def test_ieee1588_enable(self): """ IEEE1588 Enable test case. """ self.dut.send_expect("set fwd ieee1588", "testpmd> ") self.dut.send_expect("start", ">", 5) # Waiting for 'testpmd> ' Fails due to log messages, "Received non PTP packet", in the output time.sleep(1) # Allow the output from the "start" command to finish before looking for a regexp in expect # use the first port on that self.nic dutPorts = self.dut.get_ports() port = self.tester.get_local_port(dutPorts[0]) itf = self.tester.get_interface(port) self.tester.scapy_background() self.tester.scapy_append('p = sniff(iface="%s", count=2)' % itf) self.tester.scapy_append('RESULT = p[1].summary()') # this is the output of sniff # [<Ether dst=01:1b:19:00:00:00 src=00:00:00:00:00:00 type=0x88f7 |<Raw load='\x00\x02' |>>] self.tester.scapy_foreground() self.tester.scapy_append('nutmac="01:1b:19:00:00:00"') self.tester.scapy_append('sendp([Ether(dst=nutmac,type=0x88f7)/"\\x00\\x02"], iface="%s")' % itf) self.tester.scapy_append('time.sleep(1)') self.tester.scapy_execute() out = self.tester.scapy_get_result() self.verify("0x88f7" in out, "Ether type is not PTP") # self.verify("\\x00\\x02" in out, "Payload wrong in PTP") time.sleep(1) out = self.dut.send_expect("stop", "testpmd> ") text = dts.regexp(out, "(.*) by hardware") self.verify("IEEE1588 PTP V2 SYNC" in text, "Not filtered " + text) rx_time = dts.regexp(out, "RX timestamp value (0x[0-9a-fA-F]+)") tx_time = dts.regexp(out, "TX timestamp value (0x[0-9a-fA-F]+)") self.verify(rx_time is not None, "RX timestamp error ") self.verify(tx_time is not None, "TX timestamp error ") self.verify(int(tx_time, 16) > int(rx_time, 16), "Timestamp mismatch") def test_ieee1588_disable(self): """ IEEE1588 Disable test case. """ self.dut.send_expect("stop", "testpmd> ") time.sleep(3) # use the first port on that self.nic dutPorts = self.dut.get_ports() port = self.tester.get_local_port(dutPorts[0]) itf = self.tester.get_interface(port) self.tester.scapy_background() self.tester.scapy_append('p = sniff(iface="%s", count=2, timeout=1)' % itf) self.tester.scapy_append('RESULT = p[1].summary()') self.tester.scapy_foreground() self.tester.scapy_append('nutmac="01:1b:19:00:00:00"') self.tester.scapy_append('sendp([Ether(dst=nutmac,type=0x88f7)/"\\x00\\x02"], iface="%s")' % itf) self.tester.scapy_execute() time.sleep(2) out = self.tester.scapy_get_result() self.verify("Ether" not in out, "Ether type is not PTP") def tear_down(self): """ Run after each test case. """ pass def tear_down_all(self): """ Run after each test suite. """ self.dut.send_expect("quit", "# ", 30) # Restore the config file and recompile the package. if "bsdapp" in self.target: self.dut.send_expect("sed -i -e 's/IEEE1588=y$/IEEE1588=n/' config/common_bsdapp", "# ", 30) else: self.dut.send_expect("sed -i -e 's/IEEE1588=y$/IEEE1588=n/' config/common_linuxapp", "# ", 30) self.dut.build_install_dpdk(self.target)