Esempio n. 1
0
File: IPUtil.py Progetto: gvnn3/csit
    def vpp_get_ip_table(node):
        """Get IPv4 FIB table on a VPP node.

        :param node: VPP node.
        :type node: dict
        """
        PapiSocketExecutor.run_cli_cmd(node, u"show ip fib")
Esempio n. 2
0
    def set_hoststack_quic_crypto_engine(node, quic_crypto_engine,
                                         fail_on_error=False):
        """Set the Hoststack QUIC crypto engine on node

        :param node: Node to enable/disable HostStack.
        :param quic_crypto_engine: type of crypto engine
        :type node: dict
        :type quic_crypto_engine: str
        """
        vpp_crypto_engines = {u"openssl", u"native", u"ipsecmb"}
        if quic_crypto_engine == u"nocrypto":
            logger.trace(u"No QUIC crypto engine.")
            return

        if quic_crypto_engine in vpp_crypto_engines:
            cmds = [u"quic set crypto api vpp",
                    f"set crypto handler aes-128-gcm {quic_crypto_engine}",
                    f"set crypto handler aes-256-gcm {quic_crypto_engine}"]
        elif quic_crypto_engine == u"picotls":
            cmds = [u"quic set crypto api picotls"]
        else:
            raise ValueError(f"Unknown QUIC crypto_engine {quic_crypto_engine}")

        for cmd in cmds:
            try:
                PapiSocketExecutor.run_cli_cmd(node, cmd)
            except AssertionError:
                if fail_on_error:
                    raise
Esempio n. 3
0
    def show_log(node):
        """Show logging on the specified topology node.

        :param node: Topology node.
        :type node: dict
        """
        PapiSocketExecutor.run_cli_cmd(node, u"show logging")
Esempio n. 4
0
    def set_hoststack_quic_fifo_size(node, fifo_size):
        """Set the QUIC protocol fifo size.

        :param node: Node to set the QUIC fifo size on.
        :param fifo_size: fifo size, passed to the quic set fifo-size command.
        :type node: dict
        :type fifo_size: str
        """
        cmd = f"quic set fifo-size {fifo_size}"
        PapiSocketExecutor.run_cli_cmd(node, cmd)
Esempio n. 5
0
    def start_vpp_http_server_params(cls, node, http_static_plugin,
                                     prealloc_fifos, fifo_size,
                                     private_segment_size):
        """Start the test HTTP server internal application or
           the HTTP static server plugin internal applicatoin on the given node.

        http static server www-root <www-root-dir> prealloc-fifos <N>
        fifo-size <size in kB>
        private-segment-size <seg_size expressed as number + unit, e.g. 100m>
                                -- or --
        test http server static prealloc-fifos <N> fifo-size <size in kB>
        private-segment-size <seg_size expressed as number + unit, e.g. 100m>


        Where N is the max number of connections you expect to handle at one
        time and <size> should be small if you test for CPS and exchange few
        bytes, say 4, if each connection just exchanges few packets. Or it
        should be much larger, up to 1024/4096 (i.e. 1-4MB) if you have only
        one connection and exchange a lot of packets, i.e., when you test for
        RPS. If you need to allocate lots of FIFOs, so you test for CPS, make
        private-segment-size something like 4g.

        Example:

        For CPS
        http static server www-root <www-root-dir> prealloc-fifos 10000
        fifo-size 64 private-segment-size 4000m

        For RPS
        test http server static prealloc-fifos 500000 fifo-size 4
        private-segment-size 4000m

        :param node: Node to start HTTP server on.
        :param http_static_plugin: Run HTTP static server plugin
        :param prealloc_fifos: Max number of connections you expect to handle at
            one time.
        :param fifo_size: FIFO size in kB.
        :param private_segment_size: Private segment size. Number + unit.
        :type node: dict
        :type http_static_plugin: boolean
        :type prealloc_fifos: str
        :type fifo_size: str
        :type private_segment_size: str
        """
        cmd = f"http static server www-root {cls.www_root_dir} " \
            f"prealloc-fifos {prealloc_fifos} fifo-size {fifo_size} " \
            f"private-segment-size {private_segment_size}" \
            if http_static_plugin \
            else f"test http server static prealloc-fifos {prealloc_fifos} " \
            f"fifo-size {fifo_size} private-segment-size {private_segment_size}"

        PapiSocketExecutor.run_cli_cmd(node, cmd)
Esempio n. 6
0
    def vpp_get_ip_tables_prefix(node, address):
        """Get dump of all IP FIB tables on a VPP node.

        :param node: VPP node.
        :param address: IP address.
        :type node: dict
        :type address: str
        """
        addr = ip_address(address)
        ip_ver = u"ip6" if addr.version == 6 else u"ip"

        PapiSocketExecutor.run_cli_cmd(
            node, f"show {ip_ver} fib {addr}/{addr.max_prefixlen}")
Esempio n. 7
0
    def log_vpp_hoststack_data(node):
        """Retrieve and log VPP HostStack data.

        :param node: DUT node.
        :type node: dict
        :raises RuntimeError: If node subtype is not a DUT or startup failed.
        """

        if node[u"type"] != u"DUT":
            raise RuntimeError(u"Node type is not a DUT!")

        PapiSocketExecutor.run_cli_cmd(node, u"show error")
        PapiSocketExecutor.run_cli_cmd(node, u"show interface")
Esempio n. 8
0
    def vpp_get_ip_tables(node):
        """Get dump of all IP FIB tables on a VPP node.

        :param node: VPP node.
        :type node: dict
        """
        PapiSocketExecutor.run_cli_cmd(node, u"show ip fib")
        PapiSocketExecutor.run_cli_cmd(node, u"show ip fib summary")
        PapiSocketExecutor.run_cli_cmd(node, u"show ip6 fib")
        PapiSocketExecutor.run_cli_cmd(node, u"show ip6 fib summary")
Esempio n. 9
0
    def show_nat44_summary(node):
        """Show NAT44 summary on the specified topology node.

        :param node: Topology node.
        :type node: dict
        :returns: NAT44 summary data.
        :rtype: str
        """
        return PapiSocketExecutor.run_cli_cmd(node, u"show nat44 summary")
Esempio n. 10
0
    def show_classify_tables_verbose(node):
        """Show classify tables verbose.

        :param node: Topology node.
        :type node: dict
        :returns: Classify tables verbose data.
        :rtype: str
        """
        return PapiSocketExecutor.run_cli_cmd(node,
                                              u"show classify tables verbose")
Esempio n. 11
0
    def configure_sr_localsid(node,
                              local_sid,
                              behavior,
                              interface=None,
                              next_hop=None,
                              fib_table=None,
                              out_if=None,
                              in_if=None,
                              src_addr=None,
                              sid_list=None):
        """Create SRv6 LocalSID and binds it to a particular behaviour on
        the given node.

        :param node: Given node to create localSID on.
        :param local_sid: LocalSID IPv6 address.
        :param behavior: SRv6 LocalSID function.
        :param interface: Interface name (Optional, required for
            L2/L3 xconnects).
        :param next_hop: Next hop IPv4/IPv6 address (Optional, required for L3
            xconnects).
        :param fib_table: FIB table for IPv4/IPv6 lookup (Optional, required for
            L3 routing).
        :param out_if: Interface name of local interface for sending traffic
            towards the Service Function (Optional, required for SRv6 endpoint
            to SR-unaware appliance).
        :param in_if: Interface name of local interface receiving the traffic
            coming back from the Service Function (Optional, required for SRv6
            endpoint to SR-unaware appliance).
        :param src_addr: Source address on the packets coming back on in_if
            interface (Optional, required for SRv6 endpoint to SR-unaware
            appliance via static proxy).
        :param sid_list: SID list (Optional, required for SRv6 endpoint to
            SR-unaware appliance via static proxy).
        :type node: dict
        :type local_sid: str
        :type behavior: str
        :type interface: str
        :type next_hop: str
        :type fib_table: str
        :type out_if: str
        :type in_if: str
        :type src_addr: str
        :type sid_list: list
        :raises ValueError: If required parameter is missing.
        """
        beh = behavior.replace(u".", u"_").upper()
        # There is no SRv6Behaviour enum defined for functions from SRv6 plugins
        # so we need to use CLI command to configure it.
        if beh in (getattr(SRv6Behavior, u"END_AD").name,
                   getattr(SRv6Behavior,
                           u"END_AS").name, getattr(SRv6Behavior,
                                                    u"END_AM").name):
            if beh == getattr(SRv6Behavior, u"END_AS").name:
                if next_hop is None or out_if is None or in_if is None or \
                        src_addr is None or sid_list is None:
                    raise ValueError(f"Required parameter(s) missing.\n"
                                     f"next_hop:{next_hop}\n "
                                     f"out_if:{out_if}\n"
                                     f"in_if:{in_if}\n"
                                     f"src_addr:{src_addr}\n"
                                     f"sid_list:{sid_list}")
                sid_conf = f"next {u' next '.join(sid_list)}"
                params = f"nh {next_hop} oif {out_if} iif {in_if} " \
                    f"src {src_addr} {sid_conf}"
            else:
                if next_hop is None or out_if is None or in_if is None:
                    raise ValueError(f"Required parameter(s) missing.\n"
                                     f"next_hop:{next_hop}\n"
                                     f"out_if:{out_if}\n"
                                     f"in_if:{in_if}")
                params = f"nh {next_hop} oif {out_if} iif {in_if}"

            cli_cmd = f"sr localsid address {local_sid} behavior {behavior} " \
                f"{params}"

            PapiSocketExecutor.run_cli_cmd(node, cli_cmd)
            return

        cmd = u"sr_localsid_add_del"
        args = dict(is_del=False,
                    localsid=IPv6Address(local_sid).packed,
                    end_psp=False,
                    behavior=getattr(SRv6Behavior, beh).value,
                    sw_if_index=Constants.BITWISE_NON_ZERO,
                    vlan_index=0,
                    fib_table=0,
                    nh_addr=0)
        err_msg = f"Failed to add SR localSID {local_sid} " \
            f"host {node[u'host']}"
        if beh in (getattr(SRv6Behavior, u"END_X").name,
                   getattr(SRv6Behavior,
                           u"END_DX4").name, getattr(SRv6Behavior,
                                                     u"END_DX6").name):
            if interface is None or next_hop is None:
                raise ValueError(f"Required parameter(s) missing.\n"
                                 f"interface:{interface}\n"
                                 f"next_hop:{next_hop}")
            args[u"sw_if_index"] = InterfaceUtil.get_interface_index(
                node, interface)
            args[u"nh_addr"] = IPAddress.create_ip_address_object(
                ip_address(next_hop))
        elif beh == getattr(SRv6Behavior, u"END_DX2").name:
            if interface is None:
                raise ValueError(
                    f"Required parameter missing.\ninterface: {interface}")
            args[u"sw_if_index"] = InterfaceUtil.get_interface_index(
                node, interface)
        elif beh in (getattr(SRv6Behavior,
                             u"END_DT4").name, getattr(SRv6Behavior,
                                                       u"END_DT6").name):
            if fib_table is None:
                raise ValueError(f"Required parameter missing.\n"
                                 f"fib_table: {fib_table}")
            args[u"fib_table"] = fib_table

        with PapiSocketExecutor(node) as papi_exec:
            papi_exec.add(cmd, **args).get_reply(err_msg)