Example #1
0
    def vpp_create_vhost_user_interface(node, socket):
        """Create Vhost-user interface on VPP node.

        :param node: Node to create Vhost-user interface on.
        :param socket: Vhost-user interface socket path.
        :type node: dict
        :type socket: str
        :returns: SW interface index.
        :rtype: int
        :raises RuntimeError: If Vhost-user interface creation failed.
        """
        out = VatExecutor.cmd_from_template(node,
                                            'create_vhost_user_if.vat',
                                            sock=socket)
        if out[0].get('retval') == 0:
            sw_if_idx = int(out[0].get('sw_if_index'))
            if_key = Topology.add_new_port(node, 'vhost')
            Topology.update_interface_sw_if_index(node, if_key, sw_if_idx)
            ifc_name = InterfaceUtil.vpp_get_interface_name(node, sw_if_idx)
            Topology.update_interface_name(node, if_key, ifc_name)
            ifc_mac = InterfaceUtil.vpp_get_interface_mac(node, sw_if_idx)
            Topology.update_interface_mac_address(node, if_key, ifc_mac)
            Topology.update_interface_vhost_socket(node, if_key, socket)
            return sw_if_idx
        else:
            raise RuntimeError('Create Vhost-user interface failed on node '
                               '"{}"'.format(node['host']))
Example #2
0
    def vpp_create_vhost_user_interface(node, socket):
        """Create Vhost-user interface on VPP node.

        :param node: Node to create Vhost-user interface on.
        :param socket: Vhost-user interface socket path.
        :type node: dict
        :type socket: str
        :returns: SW interface index.
        :rtype: int
        """
        cmd = 'create_vhost_user_if'
        err_msg = 'Failed to create Vhost-user interface on host {host}'.format(
            host=node['host'])
        args = dict(sock_filename=str(socket))
        with PapiExecutor(node) as papi_exec:
            sw_if_index = papi_exec.add(cmd, **args).get_sw_if_index(err_msg)

        # Update the Topology:
        if_key = Topology.add_new_port(node, 'vhost')
        Topology.update_interface_sw_if_index(node, if_key, sw_if_index)

        ifc_name = InterfaceUtil.vpp_get_interface_name(node, sw_if_index)
        Topology.update_interface_name(node, if_key, ifc_name)

        ifc_mac = InterfaceUtil.vpp_get_interface_mac(node, sw_if_index)
        Topology.update_interface_mac_address(node, if_key, ifc_mac)

        Topology.update_interface_vhost_socket(node, if_key, socket)

        return sw_if_index
Example #3
0
    def vpp_create_vhost_user_interface(node,
                                        socket,
                                        is_server=False,
                                        virtio_feature_mask=None):
        """Create Vhost-user interface on VPP node.

        :param node: Node to create Vhost-user interface on.
        :param socket: Vhost-user interface socket path.
        :param is_server: Server side of connection. Default: False
        :param virtio_feature_mask: Mask of virtio features to be enabled.
        :type node: dict
        :type socket: str
        :type is_server: bool
        :type virtio_feature_mask: int
        :returns: SW interface index.
        :rtype: int
        """
        cmd = u"create_vhost_user_if"
        err_msg = f"Failed to create Vhost-user interface " \
            f"on host {node[u'host']}"
        if virtio_feature_mask is None:
            enable_gso = False
        else:
            enable_gso = VirtioFeatureMask.is_feature_enabled(
                virtio_feature_mask, VirtioFeaturesFlags.VIRTIO_NET_F_API_GSO)
        args = dict(is_server=bool(is_server),
                    sock_filename=str(socket),
                    enable_gso=bool(enable_gso))

        with PapiSocketExecutor(node) as papi_exec:
            sw_if_index = papi_exec.add(cmd, **args).get_sw_if_index(err_msg)

        # Update the Topology:
        if_key = Topology.add_new_port(node, u"vhost")
        Topology.update_interface_sw_if_index(node, if_key, sw_if_index)

        ifc_name = InterfaceUtil.vpp_get_interface_name(node, sw_if_index)
        Topology.update_interface_name(node, if_key, ifc_name)

        ifc_mac = InterfaceUtil.vpp_get_interface_mac(node, sw_if_index)
        Topology.update_interface_mac_address(node, if_key, ifc_mac)

        Topology.update_interface_vhost_socket(node, if_key, socket)

        return sw_if_index
Example #4
0
    def vpp_create_vhost_user_interface(
            node, socket, is_server=False, enable_gso=False):
        """Create Vhost-user interface on VPP node.

        :param node: Node to create Vhost-user interface on.
        :param socket: Vhost-user interface socket path.
        :param is_server: Server side of connection. Default: False
        :param enable_gso: Generic segmentation offloading. Default: False
        :type node: dict
        :type socket: str
        :type is_server: bool
        :type enable_gso: bool
        :returns: SW interface index.
        :rtype: int
        """
        cmd = u"create_vhost_user_if"
        err_msg = f"Failed to create Vhost-user interface " \
            f"on host {node[u'host']}"
        args = dict(
            is_server=bool(is_server),
            sock_filename=str(socket),
            enable_gso=bool(enable_gso)
        )

        with PapiSocketExecutor(node) as papi_exec:
            sw_if_index = papi_exec.add(cmd, **args).get_sw_if_index(err_msg)

        # Update the Topology:
        if_key = Topology.add_new_port(node, u"vhost")
        Topology.update_interface_sw_if_index(node, if_key, sw_if_index)

        ifc_name = InterfaceUtil.vpp_get_interface_name(node, sw_if_index)
        Topology.update_interface_name(node, if_key, ifc_name)

        ifc_mac = InterfaceUtil.vpp_get_interface_mac(node, sw_if_index)
        Topology.update_interface_mac_address(node, if_key, ifc_mac)

        Topology.update_interface_vhost_socket(node, if_key, socket)

        return sw_if_index