Пример #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']))
Пример #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
Пример #3
0
    def add_geneve_tunnel(node,
                          local_address,
                          remote_address,
                          vni,
                          multicast_if=None,
                          encap_vrf=0,
                          l3_mode=False,
                          next_index=None):
        """Add GENEVE tunnel on the specified VPP node.

        :param node: Topology node.
        :param local_address: Local IP address.
        :param remote_address: Remote IP address.
        :param vni: Virtual network ID.
        :param multicast_if: Interface key of multicast interface; used only if
            remote is multicast. (Default value = None)
        :param encap_vrf: The FIB ID for sending unicast GENEVE encap packets or
            receiving multicast packets. (Default value = 0)
        :param l3_mode: Use geneve tunnel in L3 mode (ip routing) if Tue else in
            L2 mode (L2 switching). (Default value = False)
        :param next_index: The index of the next node.
        :type node: dict
        :type local_address: str
        :type remote_address: str
        :type vni: int
        :type multicast_if: str
        :type encap_vrf: int
        :type l3_mode: bool
        :type next_index: int
        :returns: SW interface index of created geneve tunnel.
        :rtype: int
        """
        cmd = u"geneve_add_del_tunnel2"
        args = dict(is_add=True,
                    local_address=IPAddress.create_ip_address_object(
                        ip_address(local_address)),
                    remote_address=IPAddress.create_ip_address_object(
                        ip_address(remote_address)),
                    mcast_sw_if_index=Topology.get_interface_sw_index(
                        node, multicast_if)
                    if multicast_if else Constants.BITWISE_NON_ZERO,
                    encap_vrf_id=int(encap_vrf),
                    decap_next_index=next_index
                    if l3_mode else Constants.BITWISE_NON_ZERO,
                    vni=int(vni),
                    l3_mode=l3_mode)
        err_msg = f"Failed to configure GENEVE tunnel on host {node[u'host']}!"
        with PapiSocketExecutor(node) as papi_exec:
            sw_if_index = papi_exec.add(cmd, **args).get_sw_if_index(err_msg)

        if_key = Topology.add_new_port(node, u"geneve_tunnel")
        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)

        return sw_if_index
Пример #4
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
Пример #5
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
Пример #6
0
    def vpp_route_add(node, network, prefix_len, strict=True, **kwargs):
        """Add route to the VPP node. Prefer multipath behavior.

        :param node: VPP node.
        :param network: Route destination network address.
        :param prefix_len: Route destination network prefix length.
        :param strict: If true, fail if address has host bits set.
        :param kwargs: Optional key-value arguments:

            gateway: Route gateway address. (str)
            interface: Route interface. (str)
            vrf: VRF table ID. (int)
            count: number of IP addresses to add starting from network IP (int)
            local: The route is local with same prefix (increment is 1 network)
            If None, then is not used. (bool)
            lookup_vrf: VRF table ID for lookup. (int)
            multipath: Enable multipath routing. (bool) Default: True.
            weight: Weight value for unequal cost multipath routing. (int)

        :type node: dict
        :type network: str
        :type prefix_len: int
        :type strict: bool
        :type kwargs: dict
        :raises RuntimeError: If the argument combination is not supported.
        """
        count = kwargs.get(u"count", 1)

        if count > 100:
            if not kwargs.get(u"multipath", True):
                raise RuntimeError(
                    u"VAT exec supports only multipath behavior")
            gateway = kwargs.get(u"gateway", u"")
            interface = kwargs.get(u"interface", u"")
            local = kwargs.get(u"local", u"")
            if interface:
                interface = InterfaceUtil.vpp_get_interface_name(
                    node, InterfaceUtil.get_interface_index(node, interface))
            vrf = kwargs.get(u"vrf", None)
            trailers = list()
            if vrf:
                trailers.append(f"table {vrf}")
            if gateway:
                trailers.append(f"via {gateway}")
                if interface:
                    trailers.append(interface)
            elif interface:
                trailers.append(f"via {interface}")
            if local:
                if gateway or interface:
                    raise RuntimeError(u"Unsupported combination with local.")
                trailers.append(u"local")
            trailer = u" ".join(trailers)
            command_parts = [u"exec ip route add", u"network goes here"]
            if trailer:
                command_parts.append(trailer)
            netiter = NetworkIncrement(ip_network(f"{network}/{prefix_len}",
                                                  strict=strict),
                                       format=u"slash")
            tmp_filename = u"/tmp/routes.config"
            with open(tmp_filename, u"w") as tmp_file:
                for _ in range(count):
                    command_parts[1] = netiter.inc_fmt()
                    print(u" ".join(command_parts), file=tmp_file)
            VatExecutor().execute_script(tmp_filename,
                                         node,
                                         timeout=1800,
                                         json_out=False,
                                         copy_on_execute=True,
                                         history=False)
            os.remove(tmp_filename)
            return

        cmd = u"ip_route_add_del"
        args = dict(is_add=True,
                    is_multipath=kwargs.get(u"multipath", True),
                    route=None)
        err_msg = f"Failed to add route(s) on host {node[u'host']}"

        netiter = NetworkIncrement(ip_network(f"{network}/{prefix_len}",
                                              strict=strict),
                                   format=u"addr")
        with PapiSocketExecutor(node) as papi_exec:
            for i in range(count):
                args[u"route"] = IPUtil.compose_vpp_route_structure(
                    node, netiter.inc_fmt(), prefix_len, **kwargs)
                history = bool(not 0 < i < count - 1)
                papi_exec.add(cmd, history=history, **args)
            papi_exec.get_replies(err_msg)