예제 #1
0
    def create_gre_tunnel_interface(node, source_ip, destination_ip):
        """Create GRE tunnel interface on node.

        :param node: VPP node to add tunnel interface.
        :param source_ip: Source of the GRE tunnel.
        :param destination_ip: Destination of the GRE tunnel.
        :type node: dict
        :type source_ip: str
        :type destination_ip: str
        :returns: Name and index of created GRE tunnel interface.
        :rtype: tuple
        :raises RuntimeError: If unable to create GRE tunnel interface.
        """
        output = VatExecutor.cmd_from_template(node, "create_gre.vat",
                                               src=source_ip,
                                               dst=destination_ip)
        output = output[0]

        if output["retval"] == 0:
            sw_if_idx = output["sw_if_index"]

            vat_executor = VatExecutor()
            vat_executor.execute_script_json_out("dump_interfaces.vat", node)
            interface_dump_json = vat_executor.get_script_stdout()
            name = VatJsonUtil.get_interface_name_from_json(
                interface_dump_json, sw_if_idx)

            if_key = Topology.add_new_port(node, "gre_tunnel")
            Topology.update_interface_sw_if_index(node, if_key, sw_if_idx)
            Topology.update_interface_name(node, if_key, name)

            return name, sw_if_idx
        else:
            raise RuntimeError('Unable to create GRE tunnel on node {}.'
                               .format(node))
예제 #2
0
    def vpp_ipsec_add_sad_entries(node,
                                  n_entries,
                                  sad_id,
                                  spi,
                                  crypto_alg,
                                  crypto_key,
                                  integ_alg,
                                  integ_key,
                                  tunnel_src=None,
                                  tunnel_dst=None):
        """Create multiple Security Association Database entries on VPP node.

        :param node: VPP node to add SAD entry on.
        :param n_entries: Number of SAD entries to be created.
        :param sad_id: First SAD entry ID. All subsequent SAD entries will have
            id incremented by 1.
        :param spi: Security Parameter Index of first SAD entry. All subsequent
            SAD entries will have spi incremented by 1.
        :param crypto_alg: The encryption algorithm name.
        :param crypto_key: The encryption key string.
        :param integ_alg: The integrity algorithm name.
        :param integ_key: The integrity key string.
        :param tunnel_src: Tunnel header source IPv4 or IPv6 address. If not
            specified ESP transport mode is used.
        :param tunnel_dst: Tunnel header destination IPv4 or IPv6 address. If
            not specified ESP transport mode is used.
        :type node: dict
        :type n_entries: int
        :type sad_id: int
        :type spi: int
        :type crypto_alg: CryptoAlg
        :type crypto_key: str
        :type integ_alg: IntegAlg
        :type integ_key: str
        :type tunnel_src: str
        :type tunnel_dst: str
        """
        tmp_filename = '/tmp/ipsec_sad_{0}_add_del_entry.script'.format(sad_id)
        ckey = crypto_key.encode('hex')
        ikey = integ_key.encode('hex')
        tunnel = 'tunnel_src {0} tunnel_dst {1}'.format(tunnel_src, tunnel_dst)\
            if tunnel_src is not None and tunnel_dst is not None else ''

        integ = 'integ_alg {0} integ_key {1}'.format(integ_alg.alg_name, ikey)\
            if crypto_alg.alg_name != 'aes-gcm-128' else ''

        with open(tmp_filename, 'w') as tmp_file:
            for i in range(0, n_entries):
                buf_str = 'ipsec_sad_add_del_entry esp sad_id {0} spi {1} ' \
                          'crypto_alg {2} crypto_key {3} {4} {5}\n'.format(
                              sad_id+i, spi+i, crypto_alg.alg_name, ckey, integ,
                              tunnel)
                tmp_file.write(buf_str)
        vat = VatExecutor()
        vat.execute_script(tmp_filename,
                           node,
                           timeout=300,
                           json_out=False,
                           copy_on_execute=True)
        os.remove(tmp_filename)
예제 #3
0
    def add_bond_eth_interface(node, ifc_name=None, sw_if_idx=None):
        """Add BondEthernet interface to current topology.

        :param node: DUT node from topology.
        :param ifc_name: Name of the BondEthernet interface.
        :param sw_if_idx: SW interface index.
        :type node: dict
        :type ifc_name: str
        :type sw_if_idx: int
        """
        if_key = Topology.add_new_port(node, 'eth_bond')

        vat_executor = VatExecutor()
        vat_executor.execute_script_json_out("dump_interfaces.vat", node)
        interface_dump_json = vat_executor.get_script_stdout()

        if ifc_name and sw_if_idx is None:
            sw_if_idx = VatJsonUtil.get_interface_sw_index_from_json(
                interface_dump_json, ifc_name)
        Topology.update_interface_sw_if_index(node, if_key, sw_if_idx)
        if sw_if_idx and ifc_name is None:
            ifc_name = InterfaceUtil.vpp_get_interface_name(node, sw_if_idx)
        Topology.update_interface_name(node, if_key, ifc_name)
        ifc_mac = VatJsonUtil.get_interface_mac_from_json(
            interface_dump_json, sw_if_idx)
        Topology.update_interface_mac_address(node, if_key, ifc_mac)
예제 #4
0
    def vpp_clear_runtime(node):
        """Run "clear runtime" CLI command.

        :param node: Node to run command on.
        :type node: dict
        """
        vat = VatExecutor()
        vat.execute_script("clear_runtime.vat", node, json_out=False)
예제 #5
0
    def vpp_show_errors(node):
        """Run "show errors" debug CLI command.

        :param node: Node to run command on.
        :type node: dict
        """
        vat = VatExecutor()
        vat.execute_script("show_errors.vat", node, json_out=False)
예제 #6
0
    def show_event_logger_on_dut(node):
        """Show event logger on the DUT node.

        :param node: DUT node to show traces on.
        :type node: dict
        """
        vat = VatExecutor()
        vat.execute_script("show_event_logger.vat", node, json_out=False)
예제 #7
0
    def vpp_show_version_verbose(node):
        """Run "show version verbose" CLI command.

        :param node: Node to run command on.
        :type node: dict
        """
        vat = VatExecutor()
        vat.execute_script("show_version_verbose.vat", node, json_out=False)
예제 #8
0
    def vpp_api_trace_dump(node):
        """Run "api trace custom-dump" CLI command.

        :param node: Node to run command on.
        :type node: dict
        """
        vat = VatExecutor()
        vat.execute_script("api_trace_dump.vat", node, json_out=False)
예제 #9
0
파일: Memif.py 프로젝트: ondrej-fabry/csit
    def dump_memif(node):
        """Dump Memif data for the given node.

        :param node: Given node to show Memif data on.
        :type node: dict
        """
        vat = VatExecutor()
        vat.execute_script("memif_dump.vat", node, json_out=False)
예제 #10
0
    def vpp_ipsec_show(node):
        """Run "show ipsec" debug CLI command.

        :param node: Node to run command on.
        :type node: dict
        """
        VatExecutor().execute_script("ipsec/ipsec_show.vat", node,
                                     json_out=False)
예제 #11
0
    def vpp_show_hardware_detail(node):
        """Run "show hardware-interfaces detail" debug CLI command.

        :param node: Node to run command on.
        :type node: dict
        """
        vat = VatExecutor()
        vat.execute_script("show_hardware_detail.vat", node, json_out=False)
예제 #12
0
파일: VppCounters.py 프로젝트: marekgr/csit
    def vpp_show_runtime_verbose(node):
        """Run "show runtime verbose" CLI command.

        :param node: Node to run command on.
        :type node: dict
        """
        vat = VatExecutor()
        vat.execute_script("show_runtime_verbose.vat", node, json_out=False)
        vat.script_should_have_passed()
예제 #13
0
    def vpp_show_vhost(node):
        """Get vhost-user data for the given node.

        :param node: VPP node to get interface data from.
        :type node: dict
        :returns: nothing
        """
        vat = VatExecutor()
        vat.execute_script("show_vhost.vat", node, json_out=False)
예제 #14
0
    def vpp_clear_hardware_counters(node):
        """Clear interface hardware counters on VPP node.

        :param node: Node to clear hardware counters on.
        :type node: dict
        """
        vat = VatExecutor()
        vat.execute_script('clear_hardware.vat', node)
        vat.script_should_have_passed()
예제 #15
0
    def vpp_clear_errors_counters(node):
        """Clear errors counters on VPP node.

        :param node: Node to clear errors counters on.
        :type node: dict
        """
        vat = VatExecutor()
        vat.execute_script('clear_errors.vat', node)
        vat.script_should_have_passed()
예제 #16
0
    def vpp_enable_barrier_traces_on_dut(node):
        """Enable vpp barrier traces on the DUT node.

        :param node: DUT node to set up.
        :type node: dict
        """
        vat = VatExecutor()
        vat.execute_script("test_threads_barrier_elog.vat",
                           node,
                           json_out=False)
예제 #17
0
    def clear_packet_trace_on_all_duts(nodes):
        """Clear VPP packet trace.

        :param nodes: Nodes where the packet trace will be cleared.
        :type nodes: list
        """
        for node in nodes.values():
            if node['type'] == NodeType.DUT:
                vat = VatExecutor()
                vat.execute_script("clear_trace.vat", node, json_out=False)
예제 #18
0
    def show_packet_trace_on_all_duts(nodes):
        """Show VPP packet trace.

        :param nodes: Nodes from which the packet trace will be displayed.
        :type nodes: list
        """
        for node in nodes.values():
            if node['type'] == NodeType.DUT:
                vat = VatExecutor()
                vat.execute_script("show_trace.vat", node, json_out=False)
예제 #19
0
    def vpp_show_crypto_device_mapping(node):
        """Run "show crypto device mapping" CLI command.

        :param node: Node to run command on.
        :type node: dict
        """
        vat = VatExecutor()
        vat.execute_script("show_crypto_device_mapping.vat",
                           node,
                           json_out=False)
예제 #20
0
    def vpp_show_lisp_rloc_config(node):
        """Get LISP RLOC configuration from VPP node.

        :param node: VPP node.
        :type node: dict
        :returns: LISP RLOC configuration as python list.
        :rtype: list
        """

        vat = VatExecutor()
        vat.execute_script_json_out('lisp/show_lisp_rloc_config.vat', node)
        return JsonParser().parse_data(vat.get_script_stdout())
예제 #21
0
    def vpp_show_lisp_map_register(node):
        """Get LISP Map Register from VPP node.

        :param node: VPP node.
        :type node: dict
        :returns: LISP Map Register as python list.
        :rtype: list
        """

        vat = VatExecutor()
        vat.execute_script_json_out('lisp/show_lisp_map_register.vat', node)
        return JsonParser().parse_data(vat.get_script_stdout())
예제 #22
0
    def vpp_show_lisp_pitr(node):
        """Get Lisp PITR feature config from VPP node.

        :param node: VPP node.
        :type node: dict
        :returns: Lisp PITR config data.
        :rtype: dict
        """

        vat = VatExecutor()
        vat.execute_script_json_out('lisp/show_lisp_pitr.vat', node)
        return JsonParser().parse_data(vat.get_script_stdout())
예제 #23
0
    def vpp_show_lisp_state(node):
        """Get lisp state from VPP node.

        :param node: VPP node.
        :type node: dict
        :returns: Lisp gpe state.
        :rtype: list
        """

        vat = VatExecutor()
        vat.execute_script_json_out('lisp/show_lisp_status.vat', node)
        return JsonParser().parse_data(vat.get_script_stdout())
예제 #24
0
    def vpp_enable_traces_on_dut(node):
        """Enable vpp packet traces on the DUT node.

        :param node: DUT node to set up.
        :type node: dict
        """
        vat = VatExecutor()
        vat.execute_script("enable_dpdk_traces.vat", node, json_out=False)
        vat.execute_script("enable_vhost_user_traces.vat",
                           node,
                           json_out=False)
        vat.execute_script("enable_memif_traces.vat", node, json_out=False)
예제 #25
0
    def vpp_show_lisp_eid_table(node):
        """Get lisp eid table from VPP node.

        :param node: VPP node.
        :type node: dict
        :returns: Lisp eid table as python list.
        :rtype: list
        """

        vat = VatExecutor()
        vat.execute_script_json_out('lisp/show_lisp_eid_table.vat', node)
        return JsonParser().parse_data(vat.get_script_stdout())
예제 #26
0
파일: IPsecUtil.py 프로젝트: preym17/csit
    def vpp_ipsec_spd_add_entries(node, n_entries, spd_id, priority, inbound,
                                  sa_id, raddr_ip):
        """Create multiple Security Policy Database entries on the VPP node.

        :param node: VPP node to add SPD entries on.
        :param n_entries: Number of SPD entries to be added.
        :param spd_id: SPD ID to add entries on.
        :param priority: SPD entries priority, higher number = higher priority.
        :param inbound: If True policy is for inbound traffic, otherwise
            outbound.
        :param sa_id: SAD entry ID for first entry. Each subsequent entry will
            SAD entry ID incremented by 1.
        :param raddr_ip: Policy selector remote IPv4 start address for the first
            entry. Remote IPv4 end address will be calculated depending on
            raddr_range parameter. Each subsequent entry will have start address
            next after IPv4 end address of previous entry.
        :type node: dict
        :type n_entries: int
        :type spd_id: int
        :type priority: int
        :type inbound: bool
        :type sa_id: int
        :type raddr_ip: string
        """
        tmp_filename = '/tmp/ipsec_spd_{0}_add_del_entry.script'.format(sa_id)

        with open(tmp_filename, 'w') as tmp_file:
            for i in range(0, n_entries):
                raddr_s = ip_address(unicode(raddr_ip)) + i
                raddr_e = ip_address(unicode(raddr_ip)) + (i + 1) - 1
                tunnel = (
                    'exec ipsec policy add spd {spd_id} priority {priority} '
                    '{direction} action protect sa {sa_id} '
                    'remote-ip-range {raddr_s} - {raddr_e} '
                    'local-ip-range 0.0.0.0 - 255.255.255.255\n'.format(
                        spd_id=spd_id,
                        priority=priority,
                        direction='inbound' if inbound else 'outbound',
                        sa_id=sa_id + i,
                        raddr_s=raddr_s,
                        raddr_e=raddr_e))
                tmp_file.write(tunnel)
        vat = VatExecutor()
        vat.execute_script(tmp_filename,
                           node,
                           timeout=300,
                           json_out=False,
                           copy_on_execute=True)
        os.remove(tmp_filename)
예제 #27
0
파일: NAT.py 프로젝트: krickwix/csit-mirror
    def vpp_get_nat_static_mappings(node):
        """Get NAT static mappings from VPP node.

        :param node: VPP node.
        :type node: dict
        :returns: List of static mappings.
        :rtype: list
        :raises RuntimeError: If the output is not as expected.
        """

        vat = VatExecutor()
        # JSON output not supported for this command
        vat.execute_script('snat/snat_mapping_dump.vat', node, json_out=False)

        stdout = vat.get_script_stdout()
        lines = stdout.split("\n")

        data = []
        # lines[0,1] are table and column headers
        for line in lines[2::]:
            # Ignore extra data after NAT table
            if "snat_static_mapping_dump error: Misc" in line or "vat#" in line:
                continue
            items = line.split(" ")
            while "" in items:
                items.remove("")
            if len(items) == 0:
                continue
            elif len(items) == 4:
                # no ports were returned
                data.append({
                    "local_address": items[0],
                    "remote_address": items[1],
                    "vrf": items[2],
                    "protocol": items[3]
                })
            elif len(items) == 6:
                data.append({
                    "local_address": items[0],
                    "local_port": items[1],
                    "remote_address": items[2],
                    "remote_port": items[3],
                    "vrf": items[4],
                    "protocol": items[5]
                })
            else:
                raise RuntimeError("Unexpected output from snat_mapping_dump.")

        return data
예제 #28
0
    def vpp_show_interfaces(node):
        """Run "show interface" CLI command.

        :param node: Node to run command on.
        :type node: dict
        """
        vat = VatExecutor()
        vat.execute_script("show_interface.vat", node, json_out=False)

        try:
            vat.script_should_have_passed()
        except AssertionError:
            raise RuntimeError(
                'Failed to get VPP interfaces on host: {name}'.format(
                    name=node['host']))
예제 #29
0
    def vpp_ipsec_spd_add_entries(node, n_entries, spd_id, priority, inbound,
                                  sa_id, raddr_ip, raddr_range):
        """Create multiple Security Policy Database entries on the VPP node.

        :param node: VPP node to add SPD entries on.
        :param n_entries: Number of SPD entries to be added.
        :param spd_id: SPD ID to add entries on.
        :param priority: SPD entries priority, higher number = higher priority.
        :param inbound: If True policy is for inbound traffic, otherwise
            outbound.
        :param sa_id: SAD entry ID for first entry. Each subsequent entry will
            SAD entry ID incremented by 1.
        :param raddr_ip: Policy selector remote IPv4 start address for the first
            entry. Remote IPv4 end address will be calculated depending on
            raddr_range parameter. Each subsequent entry will have start address
            next after IPv4 end address of previous entry.
        :param raddr_range: Mask specifying range of Policy selector Remote IPv4
            addresses. Valid values are from 1 to 32.
        :type node: dict
        :type n_entries: int
        :type spd_id: int
        :type priority: int
        :type inbound: bool
        :type sa_id: int
        :type raddr_ip: string
        :type raddr_range: int
        """
        tmp_filename = '/tmp/ipsec_spd_{0}_add_del_entry.script'.format(sa_id)

        direction = 'inbound' if inbound else 'outbound'
        addr_incr = 1 << (32 - raddr_range)
        addr_ip = int(ip_address(unicode(raddr_ip)))
        start_str = 'ipsec_spd_add_del_entry spd_id {0} priority {1} {2} ' \
                    'action protect sa_id'.format(spd_id, priority, direction)
        with open(tmp_filename, 'w') as tmp_file:
            for i in range(0, n_entries):
                r_ip_s = ip_address(addr_ip + addr_incr * i)
                r_ip_e = ip_address(addr_ip + addr_incr * (i + 1) - 1)
                buf_str = '{0} {1} raddr_start {2} raddr_stop {3}\n'.format(
                    start_str, sa_id + i, r_ip_s, r_ip_e)
                tmp_file.write(buf_str)
        vat = VatExecutor()
        vat.execute_script(tmp_filename,
                           node,
                           timeout=300,
                           json_out=False,
                           copy_on_execute=True)
        os.remove(tmp_filename)
예제 #30
0
    def update_vpp_interface_data_on_node(node):
        """Update vpp generated interface data for a given node in DICT__nodes.

        Updates interface names, software if index numbers and any other details
        generated specifically by vpp that are unknown before testcase run.
        It does this by dumping interface list to JSON output from all
        devices using vpp_api_test, and pairing known information from topology
        (mac address/pci address of interface) to state from VPP.

        :param node: Node selected from DICT__nodes.
        :type node: dict
        """
        vat_executor = VatExecutor()
        vat_executor.execute_script_json_out("dump_interfaces.vat", node)
        interface_dump_json = vat_executor.get_script_stdout()
        VatJsonUtil.update_vpp_interface_data_from_json(node,
                                                        interface_dump_json)