Example #1
0
 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
Example #2
0
    def setup_vm_env(self):
        """
        Start One VM with one virtio device
        """
        self.dut_testpmd = PmdOutput(self.dut)
        self.dut_testpmd.start_testpmd(
            "Default", "--rxq=4 --txq=4 --port-topology=chained")
        self.dut_testpmd.execute_cmd("start")

        vf0_prop_1 = {'opt_host': self.sriov_vfs_port_0[0].pci}
        vf0_prop_2 = {'opt_host': self.sriov_vfs_port_1[0].pci}
        self.vm0 = QEMUKvm(self.dut, 'vm0', 'vf_interrupt_pmd')
        self.vm0.set_vm_device(driver='pci-assign', **vf0_prop_1)
        self.vm0.set_vm_device(driver='pci-assign', **vf0_prop_2)
        try:
            self.vm0_dut = self.vm0.start()
            if self.vm0_dut is None:
                raise Exception("Set up VM ENV failed")
            else:
                self.verify(self.vm0_dut.ports_info[0]['intf'] != 'N/A',
                            "Not interface")
        except Exception as e:
            self.destroy_vm_env()
            self.logger.error("Failure for %s" % str(e))

        self.vm0_vf0_mac = self.vm0_dut.get_mac_address(0)
        self.vm0_vf1_mac = self.vm0_dut.get_mac_address(1)
        self.vm0_dut.send_expect("systemctl stop NetworkManager", "# ", 60)
Example #3
0
    def prepare_vxlan_sample_env(self, tep_cmd, vm_num=1):
        # remove unexpected socke
        self.dut.send_expect("rm -rf vhost-net", "# ")

        # start tep_termination first
        self.dut.send_expect(tep_cmd, "VHOST_CONFIG: bind to vhost-net")

        # start one vm
        self.vm = QEMUKvm(self.dut, 'vm0', 'vxlan_sample')

        # add two virtio user netdevices
        vm_params = {}
        vm_params['driver'] = 'vhost-user'
        vm_params['opt_path'] = './vhost-net'
        vm_params['opt_mac'] = self.def_mac
        self.vm.set_vm_device(**vm_params)
        vm_params['opt_mac'] = self.mac_address_add(1)
        self.vm.set_vm_device(**vm_params)

        try:
            self.vm_dut = self.vm.start()
            if self.vm_dut is None:
                raise Exception("Set up VM ENV failed!")
        except Exception as e:
            print utils.RED("Failure for %s" % str(e))

        # create another vm
        if vm_num == 2:
            print "not implemented now"

        return True
Example #4
0
    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)
Example #5
0
    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)
        self.dut_testpmd.start_testpmd(
            "Default", "--rxq=4 --txq=4 --port-topology=chained")
        self.dut_testpmd.execute_cmd("start")
        time.sleep(5)

        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
        self.dut_testpmd.quit()
Example #6
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']
        pf_intf0 = self.dut.ports_info[0]['port'].get_interface_name()

        if self.iplinkset:
            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('pci-stub')

            for port in self.sriov_vfs_port_1:
                port.bind_driver('pci-stub')

            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 = QEMUKvm(self.dut, 'vm0', 'vf_macfilter')
            self.vm0.set_vm_device(driver='pci-assign', **vf0_prop)
            self.vm0.set_vm_device(driver='pci-assign', **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)
Example #7
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)
Example #8
0
    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)
Example #9
0
    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)
Example #10
0
    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
Example #11
0
    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))
Example #12
0
    def start_onevm(self):
        """
        Start One VM with one virtio device
        """
        self.vm_dut = None
        self.vm = QEMUKvm(self.dut, 'vm0', 'vhost_pmd_xstats')
        vm_params = {}
        vm_params['driver'] = 'vhost-user'
        vm_params['opt_path'] = './vhost-net'
        vm_params['opt_mac'] = self.virtio1_mac
        self.vm.set_vm_device(**vm_params)

        try:
            self.vm_dut = self.vm.start()
            if self.vm_dut is None:
                raise Exception("Set up VM ENV failed")
        except Exception as e:
            self.logger.error("Failure for %s" % str(e))
        return True
Example #13
0
    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']

        try:
            for port in self.sriov_vfs_port_0:
                port.bind_driver('pci-stub')

            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('1S/2C/2T', eal_param)

            # set up VM0 ENV
            self.vm0 = QEMUKvm(self.dut, 'vm0', 'vf_etag')
            self.vm0.set_vm_device(driver='pci-assign', **vf0_prop)
            self.vm0.set_vm_device(driver='pci-assign', **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)
Example #14
0
    def reboot_vm1(self):
        """
        reboot vm1.
        """
        self.vm1.stop()
        vf1_prop_5 = {'opt_host': self.sriov_vfs_port[4].pci}
        vf1_prop_6 = {'opt_host': self.sriov_vfs_port[5].pci}
        self.vm1 = QEMUKvm(self.dut, 'vm1', 'vf_kernel')
        self.vm1.set_vm_device(driver='pci-assign', **vf1_prop_5)
        self.vm1.set_vm_device(driver='pci-assign', **vf1_prop_6)

        try:
            self.vm1_dut = self.vm1.start()
            if self.vm1_dut is None:
                raise Exception("Set up VM1 ENV failed!")
            else:
                self.verify(self.vm1_dut.ports_info[0]['intf'] != 'N/A',
                            "Not interface")
        except Exception as e:
            self.destroy_vm_env()
            raise Exception(e)
    def launch_virtio_dut(self, vm_name):
        # start vm
        vm = QEMUKvm(self.dut, vm_name, 'virtio_perf_cryptodev_func')

        try:
            vm_dut = vm.start(set_target=False)
            if vm_dut is None:
                print('{} start failed'.format(vm_name))
        except Exception as err:
            raise err

        vm_dut.restore_interfaces()

        if not self.dut.skip_setup:
            self.build_user_dpdk(vm_dut)
            self.build_user_app(vm_dut)

        vm_dut.setup_modules(self.target, "igb_uio", None)
        vm_dut.bind_interfaces_linux('igb_uio')
        self.set_virtio_pci(vm_dut)

        return vm, vm_dut
Example #16
0
    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('pci-stub')
            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 = QEMUKvm(self.dut, 'vm0', 'vf_to_vf_bridge')
        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 failed')
        except Exception as e:
            print utils.RED(str(e))

        self.vm1 = QEMUKvm(self.dut, 'vm1', 'vf_to_vf_bridge')
        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 failed')
        except Exception as e:
            print utils.RED(str(e))
    def start_onevm(self):
        #
        # Start One VM with 2 virtio devices
        #

        self.vm = QEMUKvm(self.dut, 'vm0', 'vhost_sample')
        if "user" in self.running_case:
            vm_params = {}
            vm_params['driver'] = 'vhost-user'
            vm_params['opt_path'] = './vhost-net'
            vm_params['opt_mac'] = self.virtio1_mac
            self.vm.set_vm_device(**vm_params)
            vm_params['opt_mac'] = self.virtio2_mac
            self.vm.set_vm_device(**vm_params)

        try:
            self.vm_dut = self.vm.start()
            if self.vm_dut is None:
                raise Exception("Set up VM ENV failed")
        except Exception as e:
            print utils.RED("Failure for %s" % str(e))

        return True
Example #18
0
    def start_onevm(self, path="", modem=0):
        #
        # Start One VM with one virtio device
        #

        self.vm = QEMUKvm(self.dut, 'vm0', 'vhost_sample')
        if (path != ""):
            self.vm.set_qemu_emulator(path)
        vm_params = {}
        vm_params['driver'] = 'vhost-user'
        vm_params['opt_path'] = './vhost-net'
        vm_params['opt_mac'] = self.virtio1_mac
        if (modem == 1):
            vm_params['opt_settings'] = 'disable-modern=false'
        self.vm.set_vm_device(**vm_params)

        try:
            self.vm_dut = self.vm.start()
            if self.vm_dut is None:
                raise Exception("Set up VM ENV failed")
        except Exception as e:
            self.logger.error("ERROR: Failure for %s" % str(e))

        return True
Example #19
0
def VM(dut, vm_name, suite_name):
    conf = VirtConf(CONFIG_ROOT_PATH + os.sep + suite_name + '.cfg')
    conf.load_virt_config(vm_name)
    local_conf = conf.get_virt_config()
    # Default virt_type is 'KVM'
    virt_type = 'KVM'
    for param in local_conf:
        if 'virt_type' in param.keys():
            virt_type = param['virt_type'][0]['virt_type']

    if virt_type == 'KVM':
        return QEMUKvm(dut, vm_name, suite_name)
    elif virt_type == 'LIBVIRT':
        return LibvirtKvm(dut, vm_name, suite_name)
    else:
        raise Exception("Virt type %s is not supported!" % virt_type)
Example #20
0
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()
Example #21
0
class TestVhostCuseOneCopyOneVm(TestCase, IxiaPacketGenerator):
    def set_up_all(self):
        # To Extend IXIA packet generator method, call the tester's method.
        self.tester.extend_external_packet_generator(TestVhostCuseOneCopyOneVm,
                                                     self)

        # Change config file to enable vhost-cuse compiled.
        self.dut.send_expect(
            "sed -i -e 's/CONFIG_RTE_LIBRTE_VHOST_USER=.*$/CONFIG_RTE_LIBRTE"
            "_VHOST_USER=n/' ./config/common_base", "# ", 30)
        self.dut.build_install_dpdk(self.target)
        self.dut.send_expect("cd ./lib/librte_vhost", "#", 30)
        print self.dut.send_expect("make", "#", 30)
        self.dut.send_expect("cd ./eventfd_link", "#", 30)
        print self.dut.send_expect("make", "#", 30)
        self.dut.send_expect("cd ~/dpdk", "#", 30)

        # build the vhost sample in vhost-cuse mode.
        if self.nic in ['niantic']:
            self.dut.send_expect(
                "sed -i -e 's/#define MAX_QUEUES.*$/#define MAX_QUEUES 128/' "
                "./examples/vhost/main.c", "#")
        else:
            self.dut.send_expect(
                "sed -i -e 's/#define MAX_QUEUES.*$/#define MAX_QUEUES 512/' "
                "./examples/vhost/main.c", "#")
        out = self.dut.send_expect("make -C examples/vhost", "#")
        self.verify("Error" not in out, "compilation error")
        self.verify("No such file" not in out, "Not found file error")

        # Build target with modified config file
        self.dut.build_install_dpdk(self.target)

        # Get and verify the ports
        self.dut_ports = self.dut.get_ports()
        self.verify(len(self.dut_ports) >= 1, "Insufficient ports for testing")

        # Get the port's socket
        self.pf = self.dut_ports[0]
        netdev = self.dut.ports_info[self.pf]['port']
        self.socket = netdev.get_nic_socket()
        self.cores = self.dut.get_core_list("1S/3C/1T", socket=self.socket)

        # Set the params of vhost-cuse sample
        self.vhost_app = "./examples/vhost/build/vhost-switch"
        self.zero_copy = 0
        self.vm2vm = 0
        self.jumbo = 0
        self.vhost_test = self.vhost_app + \
            " -c %s -n %d --socket-mem 1024,1024 -- -p 0x1 --mergeable %d" + \
            " --zero-copy %d --vm2vm %d 2 > ./vhost.out &"

        # Define the virtio/VM variables
        self.virtio1 = "eth1"
        self.virtio2 = "eth2"
        self.virtio1_mac = "52:54:00:00:00:01"
        self.virtio2_mac = "52:54:00:00:00:02"
        self.src1 = "192.168.4.1"
        self.src2 = "192.168.3.1"
        self.dst1 = "192.168.3.1"
        self.dst2 = "192.168.4.1"
        self.vm_dut = None
        self.virtio_cmd_params = \
        'csum=off,gso=off,guest_csum=off,guest_tso4=off,guest_tso6=off,guest_ecn=off'
        # Define the table columns
        self.header_row = [
            "FrameSize(B)", "Injection(Mpps)", "Throughput(Mpps)",
            "LineRate(%)"
        ]
        self.memory_channel = 4

    def set_up(self):
        #
        # Run before each test case.
        #
        # Launch vhost sample using default params

        if "jumbo" in self.running_case:
            self.jumbo = 1
            self.frame_sizes = [
                64, 128, 256, 512, 1024, 1280, 1518, 2048, 5000, 9000
            ]
            self.vm_testpmd = "./x86_64-native-linuxapp-gcc/app/testpmd -c 0x3 -n 3" \
                + " -- -i --txqflags=0xf00 " \
                + "--disable-hw-vlan-filter --max-pkt-len 9600"
        else:
            self.jumbo = 0
            self.frame_sizes = [64, 128, 256, 512, 1024, 1280, 1518]
            self.vm_testpmd = "./x86_64-native-linuxapp-gcc/app/testpmd -c 0x3 -n 3" \
                + " -- -i --txqflags=0xf00 --disable-hw-vlan-filter"
        self.dut.send_expect("rm -rf ./vhost.out", "#")

        self.launch_vhost_sample()

        # start VM with 2virtio
        self.start_onevm()

    def launch_vhost_sample(self):
        #
        # Launch the vhost sample with different parameters
        #
        self.coremask = utils.create_mask(self.cores)
        self.vhostapp_testcmd = self.vhost_test % (
            self.coremask, self.memory_channel, self.jumbo, self.zero_copy,
            self.vm2vm)
        # Clean and prepare the vhost cuse modules
        self.dut.send_expect("rm -rf /dev/vhost-net", "#", 20)
        self.dut.send_expect("modprobe fuse", "#", 20)
        self.dut.send_expect("modprobe cuse", "#", 20)
        self.dut.send_expect("rmmod eventfd_link", "#", 20)
        self.dut.send_expect(
            "insmod lib/librte_vhost/eventfd_link/eventfd_link.ko", "#", 20)
        self.dut.send_expect(self.vhostapp_testcmd, "# ", 40)
        time.sleep(30)
        try:
            print "Launch vhost sample:"
            self.dut.session.copy_file_from("/root/dpdk/vhost.out")
            fp = open('./vhost.out', 'r')
            out = fp.read()
            fp.close()
            if "Error" in out:
                raise Exception("Launch vhost sample failed")
            else:
                print "Launch vhost sample finished"
        except Exception as e:
            print utils.RED("Failed to launch vhost sample: %s" % str(e))

    def start_onevm(self):
        #
        # Start One VM with 2 virtio devices
        #

        self.vm = QEMUKvm(self.dut, 'vm0', 'vhost_cuse_sample')
        if "cuse" in self.running_case:
            vm_params = {}
            vm_params['driver'] = 'vhost-cuse'
            vm_params['opt_mac'] = self.virtio1_mac
            vm_params['opt_settings'] = self.virtio_cmd_params
            self.vm.set_vm_device(**vm_params)

            vm_params['opt_mac'] = self.virtio2_mac
            vm_params['opt_settings'] = self.virtio_cmd_params
            self.vm.set_vm_device(**vm_params)
        try:
            self.vm_dut = self.vm.start()
            if self.vm_dut is None:
                raise Exception("Set up VM ENV failed")
        except Exception as e:
            print utils.RED("Failure for %s" % str(e))

        return True

    def vm_testpmd_start(self):
        #
        # Start testpmd in vm
        #
        if self.vm_dut is not None:
            # Start testpmd with user
            self.vm_dut.send_expect(self.vm_testpmd, "testpmd>", 20)
            # Start tx_first
            self.vm_dut.send_expect("start tx_first", "testpmd>")

    def clear_vhost_env(self):
        #
        # Kill all vhost sample, shutdown VM
        #
        if self.vm_dut:
            self.vm_dut.kill_all()
            time.sleep(1)
        if self.vm:
            self.vm.stop()
            self.vm = None

    def set_legacy_disablefw(self):
        #
        # Disable firewall and ip tables in legacy case
        #
        if self.vm_dut is not None:
            self.vm_dut.send_expect("systemctl stop firewalld.service", "#")
            self.vm_dut.send_expect("systemctl disable firewalld.service", "#")
            self.vm_dut.send_expect("systemctl stop ip6tables.service", "#")
            self.vm_dut.send_expect("systemctl disable ip6tables.service", "#")
            self.vm_dut.send_expect("systemctl stop iptables.service", "#")
            self.vm_dut.send_expect("systemctl disable iptables.service", "#")
            self.vm_dut.send_expect("systemctl stop NetworkManager.service",
                                    "#")
            self.vm_dut.send_expect("systemctl disable NetworkManager.service",
                                    "#")
            self.vm_dut.send_expect("echo 1 >/proc/sys/net/ipv4/ip_forward",
                                    "#")

    def set_onevm_legacy_fwd(self):
        if self.vm_dut is not None:
            ifcfg = self.vm_dut.send_expect("ifconfig -a", "#", 10)
            intfs = re.compile('eth\d').findall(ifcfg)
            # Get the virito1/virtio2's interface names
            for intf in intfs:
                out_mac = self.vm_dut.send_expect("ifconfig %s" % intf, "#",
                                                  10)
                if self.virtio1_mac in out_mac:
                    self.virtio1 = intf
                if self.virtio2_mac in out_mac:
                    self.virtio2 = intf
            print "Virtio1's intf is %s" % self.virtio1
            print "Virtio2's intf is %s" % self.virtio2
            # Set the MTU for jumboframe enabled case
            if self.jumbo == 1:
                self.vm_dut.send_expect("ifconfig %s mtu 9000" % self.virtio1,
                                        "#")
                self.vm_dut.send_expect("ifconfig %s mtu 9000" % self.virtio2,
                                        "#")
            # Set the ipv4 fwd rules
            self.vm_dut.send_expect(
                "ip addr add 192.168.4.2/24 dev %s" % self.virtio1, "#")
            self.vm_dut.send_expect(
                "ip addr add 192.168.3.2/24 dev %s" % self.virtio2, "#")
            self.vm_dut.send_expect("ip link set dev %s up" % self.virtio1,
                                    "#")
            self.vm_dut.send_expect("ip link set dev %s up" % self.virtio2,
                                    "#")
            self.vm_dut.send_expect(
                "ip neigh add 192.168.4.1 lladdr 52:00:00:00:00:01 dev %s" %
                self.virtio1, "#")
            self.vm_dut.send_expect(
                "ip neigh add 192.168.3.1 lladdr 52:00:00:00:00:02 dev %s" %
                self.virtio2, "#")
            self.vm_dut.send_expect("ip route show", "#")
            print self.vm_dut.send_expect("arp -a", "#")

    def get_transmission_results(self, rx_port_list, tx_port_list, delay=5):
        time.sleep(delay)
        recvbpsRate = 0
        recvRate = 0
        txbpsRate = 0
        txRate = 0
        for port in tx_port_list:
            self.stat_get_rate_stat_all_stats(port)
            out = self.send_expect('stat cget -framesSent', '%', 10)
            txRate += int(out.strip())
            self.logger.info("Port %s: TX %f Mpps" %
                             (port, (txRate * 1.0 / 1000000)))
            out = self.send_expect('stat cget -bitsSent', '%', 10)
            txbpsRate += int(out.strip())
            self.logger.info("Port %s: TX %f Mbps" %
                             (port, (txbpsRate * 1.0 / 1000000)))
        for port in rx_port_list:
            self.stat_get_rate_stat_all_stats(port)
            out = self.send_expect('stat cget -framesReceived', '%', 10)
            recvRate += int(out.strip())
            out = self.send_expect('stat cget -oversize', '%', 10)
            recvRate += int(out.strip())
            self.logger.info("Port %s: RX %f Mpps" %
                             (port, (recvRate * 1.0 / 1000000)))
            out = self.send_expect('stat cget -bitsReceived', '%', 10)
            recvbpsRate += int(out.strip())
            self.logger.info("Port %s: RX %f Mbps" %
                             (port, (recvbpsRate * 1.0 / 1000000)))

        self.hook_transmissoin_func()
        self.send_expect("ixStopTransmit portList", "%", 30)

        return (txRate, recvRate)

    def send_verify(self, case, frame_sizes, vlan_id1=0, vlan_id2=0):
Example #22
0
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)
    def setup_vm_env(self, driver='default'):
        """
        Create testing environment on Host and Backup
        """
        if self.env_done:
            return

        # start vhost application on host and backup machines
        self.logger.info("Start vhost on host and backup host")
        for crb in self.duts[:2]:
            self.bind_nic_driver(crb, [crb.get_ports()[0]], driver="igb_uio")
            # start vhost app: testpmd, predict hugepage on both sockets
            base_dir = crb.base_dir.replace('~', '/root')
            crb.send_expect("rm -f %s/vhost-net" % base_dir, "# ")
            crb.send_expect("%s -c f -n 4 --socket-mem 512,512 --vdev 'eth_vhost0,iface=./vhost-net,queues=1' -- -i" % self.vhost, "testpmd> ",60)
            crb.send_expect("start", "testpmd> ")

        try:
            # set up host virtual machine
            self.host_vm = QEMUKvm(self.duts[0], 'host', 'vhost_user_live_migration')
            vhost_params = {}
            vhost_params['driver'] = 'vhost-user'
            # qemu command can't use ~
            base_dir = self.dut.base_dir.replace('~', '/root')
            vhost_params['opt_path'] = base_dir + '/vhost-net'
            vhost_params['opt_mac'] = self.virio_mac
            self.host_vm.set_vm_device(**vhost_params)

            self.logger.info("Start virtual machine on host")
            self.vm_host = self.host_vm.start()

            if self.vm_host is None:
                raise Exception("Set up host VM ENV failed!")

            self.host_serial = self.host_vm.connect_serial_port(name='vhost_user_live_migration')
            if self.host_serial is None:
                raise Exception("Connect host serial port failed!")

            self.logger.info("Start virtual machine on backup host")
            # set up backup virtual machine
            self.backup_vm = QEMUKvm(self.duts[1], 'backup', 'vhost_user_live_migration')
            vhost_params = {}
            vhost_params['driver'] = 'vhost-user'
            # qemu command can't use ~
            base_dir = self.dut.base_dir.replace('~', '/root')
            vhost_params['opt_path'] = base_dir + '/vhost-net'
            vhost_params['opt_mac'] = self.virio_mac
            self.backup_vm.set_vm_device(**vhost_params)

            # start qemu command
            self.backup_vm.start()

        except Exception as ex:
            if ex is VirtDutInitException:
                self.host_vm.stop()
                self.host_vm = None
                # no session created yet, call internal stop function
                self.backup_vm._stop_vm()
                self.backup_vm = None
            else:
                self.destroy_vm_env()
                raise Exception(ex)

        self.env_done = True
Example #24
0
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)
Example #25
0
class TestVF2VFBridge(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

    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('pci-stub')
            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 = QEMUKvm(self.dut, 'vm0', 'vf_to_vf_bridge')
        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 failed')
        except Exception as e:
            print utils.RED(str(e))

        self.vm1 = QEMUKvm(self.dut, 'vm1', 'vf_to_vf_bridge')
        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 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('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.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
Example #26
0
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
Example #27
0
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
Example #28
0
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()
Example #29
0
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)
Example #30
0
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, &eth_hdr->s_addr);/d' " +\
            " app/test-pmd/macswap.c", "# ", 30)
        self.vm0_dut.send_expect("sed -i -e '/ether_addr_copy(&eth_hdr->s_addr, &eth_hdr->d_addr);/a " +\
            "\ether_addr_copy(&fake_mac, &eth_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, &eth_hdr->s_addr);/d' " +\
            "app/test-pmd/macswap.c", "# ", 30)
        self.vm0_dut.send_expect("sed -i '/ether_addr_copy(&eth_hdr->s_addr, &eth_hdr->d_addr);/a " +\
            "\ether_addr_copy(&addr, &eth_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