Exemplo n.º 1
0
    def build_qemu(node, force_install=False, apply_patch=False):
        """Build QEMU from sources.

        :param node: Node to build QEMU on.
        :param force_install: If True, then remove previous build.
        :param apply_patch: If True, then apply patches from qemu_patches dir.
        :type node: dict
        :type force_install: bool
        :type apply_patch: bool
        :raises RuntimeError: If building QEMU failed.
        """
        ssh = SSH()
        ssh.connect(node)

        directory = ' --directory={0}'.format(Constants.QEMU_INSTALL_DIR)
        if apply_patch:
            directory += '-patch'
        else:
            directory += '-base'
        version = ' --version={0}'.format(Constants.QEMU_INSTALL_VERSION)
        force = ' --force' if force_install else ''
        patch = ' --patch' if apply_patch else ''
        arch = Topology.get_node_arch(node)
        target_list = ' --target-list={0}-softmmu'.format(arch)

        (ret_code, stdout, stderr) = \
            ssh.exec_command(
                "sudo -E sh -c '{0}/{1}/qemu_build.sh{2}{3}{4}{5}{6}'"\
                .format(Constants.REMOTE_FW_DIR, Constants.RESOURCES_LIB_SH,
                        version, directory, force, patch, target_list), 1000)

        if int(ret_code) != 0:
            logger.debug('QEMU build failed {0}'.format(stdout + stderr))
            raise RuntimeError('QEMU build failed on {0}'.format(node['host']))
Exemplo n.º 2
0
    def crypto_device_init(node, numvfs):
        """Init Crypto QAT device virtual functions on DUT.

        :param node: DUT node.
        :param numvfs: Number of VFs to initialize, 0 - disable the VFs.
        :type node: dict
        :type numvfs: int
        :returns: nothing
        :raises RuntimeError: If QAT failed to initialize.
        """

        ssh = SSH()
        ssh.connect(node)

        cryptodev = Topology.get_cryptodev(node)

        # QAT device must be bind to kernel driver before initialization
        DUTSetup.pci_driver_unbind(node, cryptodev)
        DUTSetup.pci_driver_bind(node, cryptodev, "dh895xcc")

        # Initialize QAT VFs
        ret_code, _, _ = ssh.exec_command(
            "sudo sh -c 'echo {} | tee /sys/bus/pci/devices/{}/sriov_numvfs'".
            format(numvfs, cryptodev.replace(':', r'\:')))

        if int(ret_code) != 0:
            raise RuntimeError('Failed to initialize {} VFs on QAT device on '
                               'host: {}'.format(numvfs, node['host']))
Exemplo n.º 3
0
    def set_acl_list_for_interface(node, interface, acl_type, acl_idx=None):
        """Set the list of input or output ACLs applied to the interface. It
        unapplies any previously applied ACLs.

        :param node: VPP node to set ACL on.
        :param interface: Interface name or sw_if_index.
        :param acl_type: Type of ACL(s) - input or output.
        :param acl_idx: Index(ies) of ACLs to be applied on the interface.
        :type node: dict
        :type interface: str or int
        :type acl_type: str
        :type acl_idx: list
        :raises RuntimeError: If unable to set ACL list for the interface.
        """
        if isinstance(interface, basestring):
            sw_if_index = Topology.get_interface_sw_index(node, interface)
        else:
            sw_if_index = interface

        acl_list = acl_type + ' ' + ' '.join(str(idx) for idx in acl_idx) \
            if acl_idx else acl_type

        try:
            with VatTerminal(node, json_param=False) as vat:
                vat.vat_terminal_exec_cmd_from_template(
                    "acl_plugin/acl_interface_set_acl_list.vat",
                    interface=sw_if_index,
                    acl_list=acl_list)
        except RuntimeError:
            raise RuntimeError("Setting of ACL list for interface {0} failed "
                               "on node {1}".format(interface, node['host']))
Exemplo n.º 4
0
    def vpp_ip_probe(node, interface, addr, if_type="key"):
        """Run ip probe on VPP node.

        :param node: VPP node.
        :param interface: Interface key or name.
        :param addr: IPv4/IPv6 address.
        :param if_type: Interface type
        :type node: dict
        :type interface: str
        :type addr: str
        :type if_type: str
        :raises ValueError: If the if_type is unknown.
        :raises Exception: If vpp probe fails.
        """
        ssh = SSH()
        ssh.connect(node)

        if if_type == "key":
            iface_name = Topology.get_interface_name(node, interface)
        elif if_type == "name":
            iface_name = interface
        else:
            raise ValueError("if_type unknown: {0}".format(if_type))

        cmd = "{c}".format(c=Constants.VAT_BIN_NAME)
        cmd_input = 'exec ip probe {dev} {ip}'.format(dev=iface_name, ip=addr)
        (ret_code, _, _) = ssh.exec_command_sudo(cmd, cmd_input)
        if int(ret_code) != 0:
            raise Exception('VPP ip probe {dev} {ip} failed on {h}'.format(
                dev=iface_name, ip=addr, h=node['host']))
Exemplo n.º 5
0
    def crypto_device_init(node, numvfs):
        """Init Crypto QAT device virtual functions on DUT.

        :param node: DUT node.
        :param numvfs: Number of VFs to initialize, 0 - disable the VFs.
        :type node: dict
        :type numvfs: int
        :returns: nothing
        :raises RuntimeError: If failed to stop VPP or QAT failed to initialize.
        """
        pci_addr = Topology.get_cryptodev(node)

        # QAT device must be re-bound to kernel driver before initialization.
        DUTSetup.verify_kernel_module(node, 'qat_dh895xcc', force_load=True)

        # Stop VPP to prevent deadlock.
        DUTSetup.stop_service(node, Constants.VPP_UNIT)

        current_driver = DUTSetup.get_pci_dev_driver(
            node, pci_addr.replace(':', r'\:'))
        if current_driver is not None:
            DUTSetup.pci_driver_unbind(node, pci_addr)

        # Bind to kernel driver.
        DUTSetup.pci_driver_bind(node, pci_addr, 'dh895xcc')

        # Initialize QAT VFs.
        if numvfs > 0:
            DUTSetup.set_sriov_numvfs(node, pci_addr, numvfs)
Exemplo n.º 6
0
    def create_kernelvm_config_testpmd_mac(self, **kwargs):
        """Create QEMU testpmd-mac command line.

        :param kwargs: Key-value pairs to construct command line parameters.
        :type kwargs: dict
        """
        testpmd_path = ('{path}/{arch}-native-linuxapp-gcc/app'.
                        format(path=Constants.QEMU_VM_DPDK,
                               arch=Topology.get_node_arch(self._node)))
        testpmd_cmd = DpdkUtil.get_testpmd_cmdline(
            eal_corelist='0-{smp}'.format(smp=self._opt.get('smp') - 1),
            eal_driver=False,
            eal_in_memory=True,
            pmd_num_mbufs=16384,
            pmd_fwd_mode='mac',
            pmd_eth_peer_0='0,{mac}'.format(mac=kwargs['vif1_mac']),
            pmd_eth_peer_1='1,{mac}'.format(mac=kwargs['vif2_mac']),
            pmd_rxq=kwargs['queues'],
            pmd_txq=kwargs['queues'],
            pmd_tx_offloads=False,
            pmd_disable_hw_vlan=False,
            pmd_max_pkt_len=9200 if kwargs['jumbo_frames'] else None,
            pmd_nb_cores=str(self._opt.get('smp') - 1))

        self._opt['vnf_bin'] = ('{testpmd_path}/{testpmd_cmd}'.
                                format(testpmd_path=testpmd_path,
                                       testpmd_cmd=testpmd_cmd))
Exemplo n.º 7
0
def install_sfc_test(node):
    """Prepare the NSH SFC test envrionment.

    :param node: Dictionary created from topology
    :type node: dict
    :returns: nothing
    """
    logger.console('Install the NSH SFC on {0}'.format(node['host']))

    if_name_list = Topology.get_node_interfaces(node)

    ssh = SSH()
    ssh.connect(node)

    (ret_code, _, stderr) = ssh.exec_command(
        'cd {0}/tests/nsh_sfc/sfc_scripts/ && ./install_sfc.sh {1} {2}'
        .format(con.REMOTE_FW_DIR, if_name_list[0], if_name_list[1]), \
        timeout=600)

    if ret_code != 0:
        logger.error('Install the NSH SFC error: {0}'.format(stderr))
        raise RuntimeError('Install the NSH SFC failed')
    else:
        logger.console('Install the NSH SFC on {0} success!'.
                       format(node['host']))
Exemplo n.º 8
0
    def start_the_l2fwd_test(dut_node, cpu_cores, nb_cores, queue_nums,
                             jumbo_frames):
        """
        Execute the l2fwd on the dut_node.

        :param dut_node: Will execute the l2fwd on this node.
        :param cpu_cores: The DPDK run cores.
        :param nb_cores: The cores number for the forwarding.
        :param queue_nums: The queues number for the NIC.
        :param jumbo_frames: Are jumbo frames used or not.
        :type dut_node: dict
        :type cpu_cores: str
        :type nb_cores: str
        :type queue_nums: str
        :type jumbo_frames: str
        :raises RuntimeError: If the script "run_l2fwd.sh" fails.
        """
        if dut_node['type'] == NodeType.DUT:
            ssh = SSH()
            ssh.connect(dut_node)

            arch = Topology.get_node_arch(dut_node)
            cmd = '{fwdir}/tests/dpdk/dpdk_scripts/run_l2fwd.sh {cpu_cores} ' \
                  '{nb_cores} {queues} {jumbo} {arch}'.\
                  format(fwdir=Constants.REMOTE_FW_DIR, cpu_cores=cpu_cores,
                         nb_cores=nb_cores, queues=queue_nums,
                         jumbo=jumbo_frames, arch=arch)

            ret_code, _, _ = ssh.exec_command_sudo(cmd, timeout=600)
            if ret_code != 0:
                raise RuntimeError('Failed to execute l2fwd test at node '
                                   '{name}'.format(name=dut_node['host']))
Exemplo n.º 9
0
    def vpp_add_ip_neighbor(node, iface_key, ip_addr, mac_address):
        """Add IP neighbor on DUT node.

        :param node: VPP node.
        :param iface_key: Interface key.
        :param ip_addr: IP address of the interface.
        :param mac_address: MAC address of the interface.
        :type node: dict
        :type iface_key: str
        :type ip_addr: str
        :type mac_address: str
        """
        dst_ip = ip_address(ip_addr)

        neighbor = dict(sw_if_index=Topology.get_interface_sw_index(
            node, iface_key),
                        flags=0,
                        mac_address=str(mac_address),
                        ip_address=str(dst_ip))
        cmd = u"ip_neighbor_add_del"
        args = dict(is_add=True, neighbor=neighbor)
        err_msg = f"Failed to add IP neighbor on interface {iface_key}"

        with PapiSocketExecutor(node) as papi_exec:
            papi_exec.add(cmd, **args).get_reply(err_msg)
Exemplo n.º 10
0
    def add_pci_device(self, node, *pci_devices):
        """Add PCI device configuration for node.

        :param node: DUT node.
        :param pci_devices: PCI devices (format 0000:00:00.0 or 00:00.0)
        :type node: dict
        :type pci_devices: tuple
        :returns: nothing
        """
        if node['type'] != NodeType.DUT:
            raise ValueError('Node type is not a DUT')

        # Specific device was given.
        hostname = Topology.get_node_hostname(node)

        pattern = re.compile("^[0-9A-Fa-f]{4}:[0-9A-Fa-f]{2}:"
                             "[0-9A-Fa-f]{2}\\.[0-9A-Fa-f]$")
        for pci_device in pci_devices:
            if not pattern.match(pci_device):
                raise ValueError('PCI address {} to be added to host {} '
                                 'is not in valid format xxxx:xx:xx.x'.
                                 format(pci_device, hostname))

            if hostname not in self._nodeconfig:
                self._nodeconfig[hostname] = {}
            if 'pci_addrs' not in self._nodeconfig[hostname]:
                self._nodeconfig[hostname]['pci_addrs'] = []
            self._nodeconfig[hostname]['pci_addrs'].append(pci_device)
            logger.debug('Adding PCI device {1} to {0}'.format(hostname,
                                                               pci_device))
Exemplo n.º 11
0
    def get_affinity_vhost(node, pf_key, skip_cnt=0, cpu_cnt=1):
        """Get affinity for vhost. Result will be used to pin vhost threads.

        :param node: Topology node.
        :param pf_key: Topology interface.
        :param skip_cnt: Amount of CPU cores to skip.
        :param cpu_cnt: CPU threads count.
        :type node: dict
        :type pf_key: str
        :type skip_cnt: int
        :type cpu_cnt: int
        :returns: List of CPUs allocated to vhost process.
        :rtype: str
        """
        if pf_key:
            cpu_node = Topology.get_interface_numa_node(node, pf_key)
        else:
            cpu_node = 0

        smt_used = CpuUtils.is_smt_enabled(node[u"cpuinfo"])
        if smt_used:
            cpu_cnt = cpu_cnt // CpuUtils.NR_OF_THREADS

        return CpuUtils.cpu_slice_of_list_per_node(node,
                                                   cpu_node=cpu_node,
                                                   skip_cnt=skip_cnt,
                                                   cpu_cnt=cpu_cnt,
                                                   smt_used=smt_used)
Exemplo n.º 12
0
    def acquire(self, force=True):
        """Pull an image or a repository from a registry.

        :param force: Destroy a container if exists.
        :type force: bool
        :raises RuntimeError: If pulling a container failed.
        """
        if self.is_container_present():
            if force:
                self.destroy()
            else:
                return

        if not self.container.image:
            img = Constants.DOCKER_SUT_IMAGE_UBUNTU_ARM \
                if Topology.get_node_arch(self.container.node) == u"aarch64" \
                else Constants.DOCKER_SUT_IMAGE_UBUNTU
            setattr(self.container, u"image", img)

        cmd = f"docker pull {self.container.image}"

        ret, _, _ = self.container.ssh.exec_command_sudo(cmd, timeout=1800)
        if int(ret) != 0:
            raise RuntimeError(
                f"Failed to create container {self.container.name}."
            )

        if self.container.cpuset_cpus:
            self._configure_cgroup(u"docker")
Exemplo n.º 13
0
    def acquire(self, force=True):
        """Acquire a privileged system object where configuration is stored.

        :param force: If a container exists, destroy it and create a new
            container.
        :type force: bool
        :raises RuntimeError: If creating the container or writing the container
            config fails.
        """
        if self.is_container_present():
            if force:
                self.destroy()
            else:
                return

        target_arch = u"arm64" \
            if Topology.get_node_arch(self.container.node) == u"aarch64" \
            else u"amd64"

        image = self.container.image if self.container.image \
            else f"-d ubuntu -r bionic -a {target_arch}"

        cmd = f"lxc-create -t download --name {self.container.name} " \
            f"-- {image} --no-validate"

        ret, _, _ = self.container.ssh.exec_command_sudo(cmd, timeout=1800)
        if int(ret) != 0:
            raise RuntimeError(u"Failed to create container.")

        self._configure_cgroup(u"lxc")
Exemplo n.º 14
0
    def vpp_add_ip_neighbor(node, iface_key, ip_addr, mac_address):
        """Add IP neighbor on DUT node.

        :param node: VPP node.
        :param iface_key: Interface key.
        :param ip_addr: IP address of the interface.
        :param mac_address: MAC address of the interface.
        :type node: dict
        :type iface_key: str
        :type ip_addr: str
        :type mac_address: str
        """
        dst_ip = ip_address(unicode(ip_addr))

        neighbor = dict(
            sw_if_index=Topology.get_interface_sw_index(node, iface_key),
            flags=0,
            mac_address=str(mac_address),
            ip_address=str(dst_ip))
        cmd = 'ip_neighbor_add_del'
        args = dict(
            is_add=1,
            neighbor=neighbor)
        err_msg = 'Failed to add IP neighbor on interface {ifc}'.format(
            ifc=iface_key)
        with PapiExecutor(node) as papi_exec:
            papi_exec.add(cmd, **args).get_replies(err_msg). \
                verify_reply(err_msg=err_msg)
Exemplo n.º 15
0
    def vxlan_dump(node, interface=None):
        """Get VxLAN data for the given interface.

        :param node: VPP node to get interface data from.
        :param interface: Numeric index or name string of a specific interface.
            If None, information about all VxLAN interfaces is returned.
        :type node: dict
        :type interface: int or str
        :returns: Dictionary containing data for the given VxLAN interface or if
            interface=None, the list of dictionaries with all VxLAN interfaces.
        :rtype: dict or list
        :raises TypeError: if the data type of interface is neither basestring
            nor int.
        """
        param = "sw_if_index"
        if interface is None:
            param = ''
            sw_if_index = ''
        elif isinstance(interface, basestring):
            sw_if_index = Topology.get_interface_sw_index(node, interface)
        elif isinstance(interface, int):
            sw_if_index = interface
        else:
            raise TypeError("Wrong interface format {0}".format(interface))

        with VatTerminal(node) as vat:
            response = vat.vat_terminal_exec_cmd_from_template(
                "vxlan_dump.vat", param=param, sw_if_index=sw_if_index)

        if sw_if_index:
            for vxlan in response[0]:
                if vxlan["sw_if_index"] == sw_if_index:
                    return vxlan
            return {}
        return response[0]
Exemplo n.º 16
0
    def vpp_set_if_ipv6_addr(node, iface_key, addr, prefix):
        """Set IPv6 address on VPP.

        :param node: VPP node.
        :param iface_key: Node interface key.
        :param addr: IPv6 address.
        :param prefix: IPv6 address prefix.
        :type node: dict
        :type iface_key: str
        :type addr: str
        :type prefix: str
        """
        sw_if_index = Topology.get_interface_sw_index(node, iface_key)
        with VatTerminal(node) as vat:
            vat.vat_terminal_exec_cmd_from_template('add_ip_address.vat',
                                                    sw_if_index=sw_if_index,
                                                    address=addr,
                                                    prefix_length=prefix)
            vat.vat_terminal_exec_cmd_from_template('set_if_state.vat',
                                                    sw_if_index=sw_if_index,
                                                    state='admin-up')

        ssh = SSH()
        ssh.connect(node)
        cmd_input = 'exec show int'
        (ret_code, stdout,
         stderr) = ssh.exec_command_sudo(Constants.VAT_BIN_NAME, cmd_input)
        logger.debug('ret: {0}'.format(ret_code))
        logger.debug('stdout: {0}'.format(stdout))
        logger.debug('stderr: {0}'.format(stderr))
Exemplo n.º 17
0
    def set_interface_ethernet_mtu(node, iface_key, mtu):
        """Set Ethernet MTU for specified interface.

        Function can be used only for TGs.

        :param node: Node where the interface is.
        :param iface_key: Interface key from topology file.
        :param mtu: MTU to set.
        :type node: dict
        :type iface_key: str
        :type mtu: int
        :returns: Nothing.
        :raises ValueError: If the node type is "DUT".
        :raises ValueError: If the node has an unknown node type.
        """
        if node['type'] == NodeType.DUT:
            raise ValueError(
                'Node {}: Setting Ethernet MTU for interface '
                'on DUT nodes not supported', node['host'])
        elif node['type'] == NodeType.TG:
            iface_name = Topology.get_interface_name(node, iface_key)
            cmd = 'ip link set {} mtu {}'.format(iface_name, mtu)
            exec_cmd_no_error(node, cmd, sudo=True)
        else:
            raise ValueError('Node {} has unknown NodeType: "{}"'.format(
                node['host'], node['type']))
Exemplo n.º 18
0
    def get_ip_addr(node, iface_key, nodes_addr):
        """Return IPv4 address of the node port.

        :param node: Node in the topology.
        :param iface_key: Interface key of the node.
        :param nodes_addr: Nodes IPv4 addresses.
        :type node: dict
        :type iface_key: str
        :type nodes_addr: dict
        :returns: IPv4 address.
        :rtype: str
        """
        interface = Topology.get_interface_name(node, iface_key)
        for net in nodes_addr.values():
            for port in net['ports'].values():
                host = port.get('node')
                dev = port.get('if')
                if host == node['host'] and dev == interface:
                    ip_addr = port.get('addr')
                    if ip_addr is not None:
                        return ip_addr
                    else:
                        raise Exception(
                            'Node {n} port {p} IPv4 address is not set'.format(
                                n=node['host'], p=interface))

        raise Exception('Node {n} port {p} IPv4 address not found.'.format(
            n=node['host'], p=interface))
Exemplo n.º 19
0
    def stop_vpp_service(node, node_key=None):
        """Stop VPP service on the specified topology node.

        Disconnect possibly connected PAPI executor.

        :param node: Topology node.
        :param node_key: Topology node key.
        :type node: dict
        :type node_key: str
        """
        # Containers have a separate lifecycle, but better be safe.
        PapiSocketExecutor.disconnect_all_sockets_by_node(node)
        DUTSetup.stop_service(node, Constants.VPP_UNIT)
        if node_key:
            Topology.del_node_socket_id(node, SocketType.PAPI, node_key)
            Topology.del_node_socket_id(node, SocketType.STATS, node_key)
Exemplo n.º 20
0
def install_dmm_test(node):
    """Prepare the DMM test envrionment.
    Raise errors when failed.

    :param node: Dictionary created from topology.
    :type node: dict
    :returns: nothing.
    :raises RuntimeError: If install dmm failed.
    """

    arch = Topology.get_node_arch(node)
    logger.console('Install the DMM on {0} ({1})'.format(node['host'], arch))

    ssh = SSH()
    ssh.connect(node)
    (ret_code, _, stderr) = ssh.exec_command(
        'cd {0}/{1} && ./install_prereq.sh {2} 2>&1 | tee '
        'log_install_prereq.txt'
        .format(con.REMOTE_FW_DIR, con.DMM_SCRIPTS, arch), timeout=600)

    if ret_code != 0:
        logger.error('Install the DMM error: {0}'.format(stderr))
        raise RuntimeError('Install prereq failed')
    else:
        logger.console('Install prereq on {0} success!'.format(node['host']))
Exemplo n.º 21
0
    def add_del_macip_acl_interface(node, interface, action, acl_idx):
        """Apply/un-apply the MACIP ACL to/from a given interface.

        :param node: VPP node to set MACIP ACL on.
        :param interface: Interface name or sw_if_index.
        :param action: Required action - add or del.
        :param acl_idx: ACL index to be applied on the interface.
        :type node: dict
        :type interface: str or int
        :type action: str
        :type acl_idx: str or int
        :raises RuntimeError: If unable to set MACIP ACL for the interface.
        """
        if isinstance(interface, basestring):
            sw_if_index = Topology.get_interface_sw_index(node, interface)
        else:
            sw_if_index = interface

        is_add = 1 if action == "add" else 0

        cmd = 'macip_acl_interface_add_del'
        err_msg = "Failed to get 'macip_acl_interface' on host {host}".format(
            host=node['host'])
        args = dict(is_add=is_add,
                    sw_if_index=int(sw_if_index),
                    acl_index=int(acl_idx))
        with PapiExecutor(node) as papi_exec:
            papi_exec.add(cmd, **args).get_replies(err_msg).\
                verify_reply(err_msg=err_msg)
Exemplo n.º 22
0
    def start_the_tcpdump_on_the_node(from_node, from_port, filter_ip):
        """
        Start the tcpdump on the frome_node.

        :param from_node: Will execute the tcpdump on this node.
        :param from_port: Will capture the packets on this interface.
        :param filter_ip: filter the dest ip.
        :type from_node: dict
        :type from_port: str
        :type filter_ip: str
        :returns: none
        :raises RuntimeError: If the script "start_tcpdump.sh" fails.
        """

        interface_name = Topology.get_interface_name(from_node, from_port)

        ssh = SSH()
        ssh.connect(from_node)

        cmd = 'cd {0}/nsh_sfc_tests/sfc_scripts/ && sudo ./start_tcpdump.sh ' \
              '{1} {2}'.format(con.REMOTE_FW_DIR, interface_name, filter_ip)

        (ret_code, _, _) = ssh.exec_command(cmd, timeout=600)
        if ret_code != 0:
            raise RuntimeError(
                'Failed to exec start_tcpdump.sh at node {0}'.format(
                    from_node['host']))
Exemplo n.º 23
0
    def crypto_device_verify(node, force_init=False, numvfs=32):
        """Verify if Crypto QAT device virtual functions are initialized on all
        DUTs. If parameter force initialization is set to True, then try to
        initialize or remove VFs on QAT.

        :param node: DUT node.
        :param force_init: If True then try to initialize to specific value.
        :param numvfs: Number of VFs to initialize, 0 - disable the VFs.
        :type node: dict
        :type force_init: bool
        :type numvfs: int
        :returns: nothing
        :raises RuntimeError: If QAT VFs are not created and force init is set
                              to False.
        """
        pci_addr = Topology.get_cryptodev(node)
        sriov_numvfs = DUTSetup.get_sriov_numvfs(node, pci_addr)

        if sriov_numvfs != numvfs:
            if force_init:
                # QAT is not initialized and we want to initialize with numvfs
                DUTSetup.crypto_device_init(node, numvfs)
            else:
                raise RuntimeError(
                    'QAT device failed to create VFs on {host}'.format(
                        host=node['host']))
Exemplo n.º 24
0
    def cop_add_whitelist_entry(
            node, interface, ip_version, fib_id, default_cop=0):
        """Add cop whitelisted entry.

        :param node: Node to add COP whitelist on.
        :param interface: Interface of the node where the COP is added.
        :param ip_version: IP version. 'ip4' and 'ip6' are valid values.
        :param fib_id: Specify the fib table ID.
        :param default_cop: 1 => enable non-ip4, non-ip6 filtration,
            0 => disable it.
        :type node: dict
        :type interface: str
        :type ip_version: str
        :type fib_id: int
        :type default_cop: int
        :raises ValueError: If parameter 'ip_version' has incorrect value.
        """
        if ip_version not in (u"ip4", u"ip6"):
            raise ValueError(u"IP version is not in correct format")

        cmd = u"cop_whitelist_enable_disable"
        err_msg = f"Failed to add COP whitelist on interface {interface} " \
            f"on host {node[u'host']}"
        args = dict(
            sw_if_index=Topology.get_interface_sw_index(node, interface),
            fib_id=int(fib_id),
            ip4=bool(ip_version == u"ip4"),
            ip6=bool(ip_version == u"ip6"),
            default_cop=default_cop
        )

        with PapiSocketExecutor(node) as papi_exec:
            papi_exec.add(cmd, **args).get_reply(err_msg)
Exemplo n.º 25
0
    def vpp_lb_add_del_intf_nat4(node, **kwargs):
        """Enable/disable NAT4 feature on the interface.

        :param node: Node where the interface is.
        :param kwargs: Optional key-value arguments:

            is_add: true if add, false if delete. (bool)
            interface: software index of the interface. (int)

        :type node: dict
        :type kwargs: dict
        :returns: Nothing.
        :raises ValueError: If the node has an unknown node type.
        """
        if node[u"type"] == NodeType.DUT:
            cmd = u"lb_add_del_intf_nat4"
            err_msg = f"Failed to add interface nat4 on host {node[u'host']}"

            is_add = kwargs.pop(u"is_add", True)
            interface = kwargs.pop(u"interface", 0)
            sw_if_index = Topology.get_interface_sw_index(node, interface)
            args = dict(is_add=is_add, sw_if_index=sw_if_index)

            with PapiSocketExecutor(node) as papi_exec:
                papi_exec.add(cmd, **args).get_reply(err_msg)
        else:
            raise ValueError(
                f"Node {node[u'host']} has unknown NodeType: '{node[u'type']}'"
            )
Exemplo n.º 26
0
    def cop_interface_enable_or_disable(node, interface, state):
        """Enable or disable COP on the interface.

        :param node: Node to add COP whitelist on.
        :param interface: Interface of the node where the COP is added.
        :param state: Enable or disable COP on the interface.
        :type node: dict
        :type interface: str
        :type state: str
        :raises ValueError: If parameter 'state' has incorrect value.
        """
        state = state.lower()
        if state in (u"enable", u"disable"):
            enable = bool(state == u"enable")
        else:
            raise ValueError(u"Possible state values are 'enable' or 'disable'")

        cmd = u"cop_interface_enable_disable"
        err_msg = f"Failed to enable/disable COP on interface {interface} " \
            f"on host {node[u'host']}"
        args = dict(
            sw_if_index=Topology.get_interface_sw_index(node, interface),
            enable_disable=enable
        )

        with PapiSocketExecutor(node) as papi_exec:
            papi_exec.add(cmd, **args).get_reply(err_msg)
Exemplo n.º 27
0
    def add_interface_to_l2_bd(node, interface, bd_id, shg=0, port_type=0):
        """Add an interface to the L2 bridge domain.

        Get SW IF ID and add it to the bridge domain.

        :param node: Node where we want to execute the command that does this.
        :param interface: Interface name.
        :param bd_id: Bridge domain index.
        :param shg: Split-horizon group index. (Default value = 0)
        :param port_type: Port mode: 0 - normal, 1 - BVI, 2 - UU_FWD.
            (Default value = 0)
        :type node: dict
        :type interface: str
        :type bd_id: int or str
        :type shg: int or str
        :type port_type: int or str
        """

        sw_if_index = Topology.get_interface_sw_index(node, interface)

        cmd = 'sw_interface_set_l2_bridge'
        err_msg = 'Failed to add interface {ifc} to L2 bridge domain on host ' \
                  '{host}'.format(ifc=interface, host=node['host'])
        args = dict(rx_sw_if_index=sw_if_index,
                    bd_id=int(bd_id),
                    shg=int(shg),
                    port_type=int(port_type),
                    enable=1)
        with PapiExecutor(node) as papi_exec:
            papi_exec.add(cmd, **args).get_replies(err_msg).\
                verify_reply(err_msg=err_msg)
Exemplo n.º 28
0
    def assign_interface_to_fib_table(node, interface, table_id, ipv6=False):
        """Assign VPP interface to specific VRF/FIB table.

        :param node: VPP node where the FIB and interface are located.
        :param interface: Interface to be assigned to FIB.
        :param table_id: VRF table ID.
        :param ipv6: Assign to IPv6 table. Default False.
        :type node: dict
        :type interface: str or int
        :type table_id: int
        :type ipv6: bool
        """
        if isinstance(interface, basestring):
            sw_if_index = Topology.get_interface_sw_index(node, interface)
        else:
            sw_if_index = interface

        ipv6 = 'ipv6' if ipv6 else ''

        with VatTerminal(node) as vat:
            ret = vat.vat_terminal_exec_cmd_from_template(
                "set_fib_to_interface.vat",
                sw_index=sw_if_index,
                vrf=table_id,
                ipv6=ipv6)

        if ret[0]["retval"] != 0:
            raise RuntimeError(
                'Unable to assign interface to FIB node {}.'.format(node))
Exemplo n.º 29
0
    def add_del_macip_acl_interface(node, interface, action, acl_idx):
        """Apply/un-apply the MACIP ACL to/from a given interface.

        :param node: VPP node to set MACIP ACL on.
        :param interface: Interface name or sw_if_index.
        :param action: Required action - add or del.
        :param acl_idx: ACL index to be applied on the interface.
        :type node: dict
        :type interface: str or int
        :type action: str
        :type acl_idx: str or int
        :raises RuntimeError: If unable to set MACIP ACL for the interface.
        """
        if isinstance(interface, basestring):
            sw_if_index = Topology.get_interface_sw_index(node, interface)
        else:
            sw_if_index = interface

        try:
            with VatTerminal(node, json_param=False) as vat:
                vat.vat_terminal_exec_cmd_from_template(
                    "acl_plugin/macip_acl_interface_add_del.vat",
                    sw_if_index=sw_if_index,
                    action=action,
                    acl_idx=acl_idx)
        except RuntimeError:
            raise RuntimeError("Setting of MACIP ACL index for interface {0} "
                               "failed on node {1}".format(
                                   interface, node['host']))
Exemplo n.º 30
0
    def add_locator(node, interface, locator_set, priority=1, weight=1):
        """Configure a new LISP locator set.

        :param node: Honeycomb node.
        :param interface: An interface on the node.
        :param locator_set: Name for the new locator set.
        :param priority: Priority parameter for the locator.
        :param weight. Weight parameter for the locator.
        :type node: dict
        :type interface: str
        :type locator_set: str
        :type priority: int
        :type weight: int
        :returns: Content of response.
        :rtype: bytearray
        """

        interface = Topology.convert_interface_reference(
            node, interface, "name")

        path = "/lisp-feature-data/locator-sets/locator-set" \
               "/{0}".format(locator_set)

        data = {
            "locator-set": {
                "name": locator_set,
                "interface": {
                    "interface-ref": interface,
                    "priority": priority,
                    "weight": weight
                }
            }
        }

        return LispKeywords._set_lisp_properties(node, path, data)