Ejemplo n.º 1
0
def main():
    args = parse_args()

    # Container image name such as 'sppc/dpdk-ubuntu:18.04'
    if args.container_image is not None:
        container_image = args.container_image
    else:
        container_image = common.container_img_name(
            common.IMG_BASE_NAMES['dpdk'], args.dist_name, args.dist_ver)

    # Setup devices with given device UIDs.
    dev_uids = None
    sock_files = None
    if args.dev_uids is not None:
        if app_helper.is_valid_dev_uids(args.dev_uids) is False:
            print('Invalid option: {}'.format(args.dev_uids))
            exit()

        dev_uids_list = args.dev_uids.split(',')
        sock_files = app_helper.sock_files(dev_uids_list)

    # Setup docker command.
    docker_cmd = ['sudo', 'docker', 'run', '\\']
    docker_opts = app_helper.setup_docker_opts(args, sock_files)

    # Setup helloworld run on container.
    cmd_path = '{0:s}/examples/{2:s}/{1:s}/{2:s}'.format(
        env.RTE_SDK, env.RTE_TARGET, APP_NAME)

    hello_cmd = [cmd_path, '\\']

    eal_opts = app_helper.setup_eal_opts(args, APP_NAME)

    # No application specific options for helloworld
    hello_opts = []

    cmds = docker_cmd + docker_opts + [container_image] + hello_cmd + \
        eal_opts + hello_opts
    if cmds[-1] == '\\':
        cmds.pop()
    common.print_pretty_commands(cmds)

    if args.dry_run is True:
        exit()

    # Remove delimiters for print_pretty_commands().
    while '\\' in cmds:
        cmds.remove('\\')
    subprocess.call(cmds)
Ejemplo n.º 2
0
def main():
    args = parse_args()

    # Container image name such as 'sppc/suricata-ubuntu:18.04'
    if args.container_image is not None:
        container_image = args.container_image
    else:
        container_image = common.container_img_name(
            common.IMG_BASE_NAMES['suricata'], args.dist_name, args.dist_ver)

    # Setup devices with given device UIDs.
    dev_uids = None
    sock_files = None
    if args.dev_uids is not None:
        if app_helper.is_valid_dev_uids(args.dev_uids) is False:
            print('Invalid option: {}'.format(args.dev_uids))
            exit()

        dev_uids_list = args.dev_uids.split(',')
        sock_files = app_helper.sock_files(dev_uids_list)

    # Setup docker command.
    docker_cmd = ['sudo', 'docker', 'run', '\\']
    docker_opts = app_helper.setup_docker_opts(args, sock_files)

    cmd_path = '/bin/bash'

    cmd = [cmd_path, '\\']

    cmds = docker_cmd + docker_opts + [container_image, '\\'] + cmd
    if cmds[-1] == '\\':
        cmds.pop()
    common.print_pretty_commands(cmds)

    if args.dry_run is True:
        exit()

    # Remove delimiters for print_pretty_commands().
    while '\\' in cmds:
        cmds.remove('\\')
    subprocess.call(cmds)
Ejemplo n.º 3
0
def main():
    args = parse_args()

    # Container image name such as 'sppc/dpdk-ubuntu:18.04'
    if args.container_image is not None:
        container_image = args.container_image
    else:
        container_image = common.container_img_name(
            common.IMG_BASE_NAMES['dpdk'],
            args.dist_name, args.dist_ver)

    c_dpdk_ver = app_helper.get_dpdk_ver_in_container(
            env.RTE_SDK, container_image)
    expected = '19.08-rc1'
    if app_helper.compare_version(expected, c_dpdk_ver) > 0:
        print("Load-balancer example was removed after DPDK 'v{}'.".
              format(expected))
        print("You cannot run it because DPDK in the container is 'v{}'.".
              format(c_dpdk_ver))
        exit()

    # Setup devices with given device UIDs.
    dev_uids = None
    sock_files = None
    if args.dev_uids is not None:
        if app_helper.is_valid_dev_uids(args.dev_uids) is False:
            print('Invalid option: {}'.format(args.dev_uids))
            exit()

        dev_uids_list = args.dev_uids.split(',')
        sock_files = app_helper.sock_files(dev_uids_list)

    # Setup docker command.
    docker_cmd = ['sudo', 'docker', 'run', '\\']
    docker_opts = app_helper.setup_docker_opts(args, sock_files)

    cmd_path = '{0:s}/examples/{2:s}/{1:s}/{2:s}'.format(
        env.RTE_SDK, env.RTE_TARGET, APP_NAME)

    # Setup testpmd command.
    lb_cmd = [cmd_path, '\\']

    # Setup EAL options.
    eal_opts = app_helper.setup_eal_opts(args, APP_NAME)

    lb_opts = []

    # Check for other mandatory opitons.
    if args.rx_ports is None:
        common.error_exit('--rx-ports')
    else:
        lb_opts += ['--rx', '"{:s}"'.format(args.rx_ports), '\\']

    if args.tx_ports is None:
        common.error_exit('--tx-ports')
    else:
        lb_opts += ['--tx', '"{:s}"'.format(args.tx_ports), '\\']

    if args.worker_lcores is None:
        common.error_exit('--worker-lcores')
    else:
        lb_opts += ['--w', '{:s}'.format(args.worker_lcores), '\\']

    if args.lpm is None:
        common.error_exit('--lpm')
    else:
        lb_opts += ['--lpm', '"{:s}"'.format(args.lpm), '\\']

    # Check optional opitons.
    if args.ring_sizes is not None:
        lb_opts += ['--ring-sizes', args.ring_sizes, '\\']
    if args.burst_sizes is not None:
        lb_opts += ['--burst-sizes', args.burst_sizes, '\\']
    if args.pos_lb is not None:
        lb_opts += ['--pos-lb', str(args.pos_lb)]

    cmds = docker_cmd + docker_opts + [container_image, '\\'] + \
        lb_cmd + eal_opts + lb_opts
    if cmds[-1] == '\\':
        cmds.pop()
    common.print_pretty_commands(cmds)

    if args.dry_run is True:
        exit()

    # Remove delimiters for print_pretty_commands().
    while '\\' in cmds:
        cmds.remove('\\')
    # Call with shell=True because parsing '--w' option is failed
    # without it.
    subprocess.call(' '.join(cmds), shell=True)
Ejemplo n.º 4
0
def main():
    args = parse_args()

    # Container image name such as 'sppc/dpdk-ubuntu:18.04'
    if args.container_image is not None:
        container_image = args.container_image
    else:
        container_image = common.container_img_name(
            common.IMG_BASE_NAMES['dpdk'], args.dist_name, args.dist_ver)

    # Check for other mandatory opitons.
    if args.port_mask is None:
        common.error_exit('--port-mask')

    # Setup devices with given device UIDs.
    dev_uids = None
    sock_files = None
    if args.dev_uids is not None:
        if app_helper.is_valid_dev_uids(args.dev_uids) is False:
            print('Invalid option: {}'.format(args.dev_uids))
            exit()

        dev_uids_list = args.dev_uids.split(',')
        sock_files = app_helper.sock_files(dev_uids_list)

    # Setup docker command.
    docker_cmd = ['sudo', 'docker', 'run', '\\']
    docker_opts = app_helper.setup_docker_opts(args, sock_files)

    # Check given number of ports is enough for portmask.
    if (args.port_mask is None) or (args.dev_uids is None):
        pass
    elif app_helper.is_sufficient_ports(args) is not True:
        print("Error: Not enough ports, {0:d} devs for '{1:s}(=0b{2:s})'.".
              format(len(args.dev_uids.split(',')), args.port_mask,
                     format(int(args.port_mask, 16), 'b')))
        exit()

    # Setup l3fwd-acl command runs on container.
    cmd_path = '{0:s}/examples/{2:s}/{1:s}/{2:s}'.format(
        env.RTE_SDK, env.RTE_TARGET, APP_NAME)

    l3fwd_cmd = [cmd_path, '\\']

    # Setup EAL options.
    eal_opts = app_helper.setup_eal_opts(args, APP_NAME)

    # Setup l3fwd-acl options.
    l3fwd_opts = ['-p', args.port_mask, '\\']

    if args.config is None:
        common.error_exit('--config')
    elif check_config_format(args.config, args.nof_queues) is not True:
        print('Invalid config: {}'.format(args.config))
        exit()
    else:
        l3fwd_opts += ['--config', '"{:s}"'.format(args.config), '\\']

    jumbo_opt_valid = False
    if args.enable_jumbo is True:
        jumbo_opt_valid = check_jumbo_opt(args.enable_jumbo, args.max_pkt_len)
        if jumbo_opt_valid is False:
            print('Error: invalid jumbo frame option(s)')
            exit()

    if args.rule_ipv4 is not None:
        if os.path.exists(args.rule_ipv4):
            l3fwd_opts += [
                '--rule_ipv4', '"{:s}"'.format(args.rule_ipv4), '\\'
            ]
        elif args.dry_run is not True:
            print('Error: "{}" does not exist'.format(args.rule_ipv4))
            exit()
    if args.rule_ipv6 is not None:
        if os.path.exists(args.rule_ipv6):
            l3fwd_opts += [
                '--rule_ipv6', '"{:s}"'.format(args.rule_ipv6), '\\'
            ]
        elif args.dry_run is not True:
            print('Error: "{}" does not exist'.format(args.rule_ipv6))
            exit()

    if args.promiscous is True:
        l3fwd_opts += ['-P', '\\']
    if args.scalar is True:
        l3fwd_opts += ['--scalar', '\\']
    if (args.enable_jumbo is not None) and (jumbo_opt_valid is True):
        l3fwd_opts += ['--enable-jumbo', '\\']
        if args.max_pkt_len is not None:
            l3fwd_opts += ['--max-pkt-len {:d}'.format(args.max_pkt_len), '\\']
    if args.no_numa is True:
        l3fwd_opts += ['--no-numa', '\\']

    cmds = docker_cmd + docker_opts + [container_image, '\\'] + \
        l3fwd_cmd + eal_opts + l3fwd_opts
    if cmds[-1] == '\\':
        cmds.pop()
    common.print_pretty_commands(cmds)

    if args.dry_run is True:
        exit()

    # Remove delimiters for print_pretty_commands().
    while '\\' in cmds:
        cmds.remove('\\')
    subprocess.call(' '.join(cmds), shell=True)
Ejemplo n.º 5
0
def main():
    args = parse_args()

    # Container image name such as 'sppc/dpdk-ubuntu:18.04'
    if args.container_image is not None:
        container_image = args.container_image
    else:
        container_image = common.container_img_name(
            common.IMG_BASE_NAMES['dpdk'], args.dist_name, args.dist_ver)

    # Check for other mandatory opitons.
    if args.port_mask is None:
        common.error_exit('--port-mask')

    # Setup devices with given device UIDs.
    dev_uids = None
    sock_files = None
    if args.dev_uids is not None:
        if app_helper.is_valid_dev_uids(args.dev_uids) is False:
            print('Invalid option: {}'.format(args.dev_uids))
            exit()

        dev_uids_list = args.dev_uids.split(',')
        sock_files = app_helper.sock_files(dev_uids_list)

    # Setup docker command.
    docker_cmd = ['sudo', 'docker', 'run', '\\']
    docker_opts = app_helper.setup_docker_opts(args, sock_files)

    # Check if the number of ports is even for l2fwd.
    nof_ports = app_helper.count_ports(args.port_mask)
    if (nof_ports % 2) != 0:
        print("Error: Number of ports must be an even number!")
        exit()

    # Setup l2fwd command run on container.
    cmd_path = '{0:s}/examples/{2:s}/{1:s}/{2:s}'.format(
        env.RTE_SDK, env.RTE_TARGET, APP_NAME)

    l2fwd_cmd = [cmd_path, '\\']

    # Setup EAL options.
    eal_opts = app_helper.setup_eal_opts(args, APP_NAME)

    # Setup l2fwd options.
    l2fwd_opts = ['-p', args.port_mask, '\\']

    # Check given number of ports is enough for portmask.
    if (args.port_mask is None) or (args.dev_uids is None):
        pass
    elif app_helper.is_sufficient_ports(args) is not True:
        print("Error: Not enough ports, {0:d} devs for '{1:s}(=0b{2:s})'.".
              format(len(args.dev_uids.split(',')), args.port_mask,
                     format(int(args.port_mask, 16), 'b')))
        exit()

    cmds = docker_cmd + docker_opts + [container_image, '\\'] + \
        l2fwd_cmd + eal_opts + l2fwd_opts
    if cmds[-1] == '\\':
        cmds.pop()
    common.print_pretty_commands(cmds)

    if args.dry_run is True:
        exit()

    # Remove delimiters for print_pretty_commands().
    while '\\' in cmds:
        cmds.remove('\\')
    subprocess.call(cmds)
Ejemplo n.º 6
0
def main():
    args = parse_args()

    # Container image name such as 'sppc/dpdk-ubuntu:18.04'
    if args.container_image is not None:
        container_image = args.container_image
    else:
        container_image = common.container_img_name(
            common.IMG_BASE_NAMES['dpdk'], args.dist_name, args.dist_ver)

    # Check for other mandatory opitons.
    if args.port_mask is None:
        common.error_exit('--port-mask')

    # Setup devices with given device UIDs.
    dev_uids = None
    sock_files = None
    if args.dev_uids is not None:
        if app_helper.is_valid_dev_uids(args.dev_uids) is False:
            print('Invalid option: {}'.format(args.dev_uids))
            exit()

        dev_uids_list = args.dev_uids.split(',')
        sock_files = app_helper.sock_files(dev_uids_list)

    # Setup docker command.
    docker_cmd = ['sudo', 'docker', 'run', '\\']
    docker_opts = app_helper.setup_docker_opts(args, sock_files)

    # Check given number of ports is enough for portmask.
    if (args.port_mask is None) or (args.dev_uids is None):
        pass
    elif app_helper.is_sufficient_ports(args) is not True:
        print("Error: Not enough ports, {0:d} devs for '{1:s}(=0b{2:s})'.".
              format(len(args.dev_uids.split(',')), args.port_mask,
                     format(int(args.port_mask, 16), 'b')))
        exit()

    # Setup l3fwd command runs on container.
    cmd_path = '{0:s}/examples/{2:s}/{1:s}/{2:s}'.format(
        env.RTE_SDK, env.RTE_TARGET, APP_NAME)

    l3fwd_cmd = [cmd_path, '\\']

    # Setup EAL options.
    eal_opts = app_helper.setup_eal_opts(args, APP_NAME)

    # Setup l3fwd options.
    l3fwd_opts = ['-p', args.port_mask, '\\']

    if args.config is None:
        common.error_exit('--config')
    elif check_config_format(args.config, args.nof_queues) is not True:
        print('Invalid config: {}'.format(args.config))
        exit()
    else:
        l3fwd_opts += ['--config', '"{:s}"'.format(args.config), '\\']

    # '--parse-ptype' is optional on host, but not on container.
    if args.parse_ptype == 'ipv4' or args.parse_ptype == 'ipv6':
        ptype_valid = True
    else:
        ptype_valid = False
    if ptype_valid is False:
        print('Error: invalid --parse-ptype {}'.format(args.parse_ptype))
        exit()
    else:
        l3fwd_opts += ['--parse-ptype', args.parse_ptype, '\\']

    # Check for optional opitons of l3fwd.
    if (args.exact_match is True) and (args.longest_prefix_match) is True:
        print('Error: -L and -E are mutually exclusive, select only one')
        exit()

    jumbo_opt_valid = False
    if args.enable_jumbo is True:
        jumbo_opt_valid = check_jumbo_opt(args.enable_jumbo, args.max_pkt_len)
        if jumbo_opt_valid is False:
            print('Error: invalid jumbo frame option(s)')
            exit()

    eth_dest_opt_valid = False
    if args.eth_dest is not None:
        eth_dest_opt_valid = check_eth_dest(args.eth_dest)
        if eth_dest_opt_valid is False:
            print('Error: invalid --eth-dest option')
            exit()

    if args.promiscous is True:
        l3fwd_opts += ['-P', '\\']
    if args.exact_match is True:
        l3fwd_opts += ['-E', '\\']
    if args.longest_prefix_match is True:
        l3fwd_opts += ['-L', '\\']
    if (args.eth_dest is not None) and (eth_dest_opt_valid is True):
        for eth_dest in args.eth_dest:  # args.eth_dest is a double array
            l3fwd_opts += ['--eth-dest {:s}'.format(eth_dest[0]), '\\']
    if (args.enable_jumbo is not None) and (jumbo_opt_valid is True):
        l3fwd_opts += ['--enable-jumbo', '\\']
        if args.max_pkt_len is not None:
            l3fwd_opts += ['--max-pkt-len {:d}'.format(args.max_pkt_len), '\\']
    if args.no_numa is True:
        l3fwd_opts += ['--no-numa', '\\']
    if args.hash_entry_num is True:
        l3fwd_opts += ['--hash-entry-num', '\\']
    if args.ipv6 is True:
        l3fwd_opts += ['--ipv6', '\\']

    cmds = docker_cmd + docker_opts + [container_image, '\\'] + \
        l3fwd_cmd + eal_opts + l3fwd_opts
    if cmds[-1] == '\\':
        cmds.pop()
    common.print_pretty_commands(cmds)

    if args.dry_run is True:
        exit()

    # Remove delimiters for print_pretty_commands().
    while '\\' in cmds:
        cmds.remove('\\')
    # Call with shell=True because parsing '--eth_dest' option is failed
    # without it.
    subprocess.call(' '.join(cmds), shell=True)
Ejemplo n.º 7
0
def main():
    args = parse_args()

    # Container image name such as 'sppc/dpdk-ubuntu:18.04'
    if args.container_image is not None:
        container_image = args.container_image
    else:
        container_image = common.container_img_name(
            common.IMG_BASE_NAMES['dpdk'], args.dist_name, args.dist_ver)

    # Setup devices with given device UIDs.
    dev_uids = None
    sock_files = None
    if args.dev_uids is not None:
        if app_helper.is_valid_dev_uids(args.dev_uids) is False:
            print('Invalid option: {}'.format(args.dev_uids))
            exit()

        dev_uids_list = args.dev_uids.split(',')
        sock_files = app_helper.sock_files(dev_uids_list)

    # Setup docker command.
    docker_cmd = ['sudo', 'docker', 'run', '\\']
    docker_opts = app_helper.setup_docker_opts(args, sock_files)

    cmd_path = APP_NAME  # testpmd is included in $PATH on container

    # Setup testpmd command.
    testpmd_cmd = [cmd_path, '\\']

    # Setup EAL options.
    eal_opts = app_helper.setup_eal_opts(args, APP_NAME)

    # Setup testpmd options
    testpmd_opts = []

    if args.interactive is True:
        testpmd_opts += ['--interactive', '\\']

    if args.auto_start is True:
        testpmd_opts += ['--auto-start', '\\']

    if args.tx_first is True:
        if args.interactive is not True:
            testpmd_opts += ['--tx-first', '\\']
        else:
            print("Error: '{}' cannot be used in interactive mode".format(
                '--tx-first'))
            exit()

    if args.stats_period is not None:
        testpmd_opts += ['--stats-period', str(args.stats_period), '\\']

    if args.nb_cores is not None:
        testpmd_opts += ['--nb-cores={:d}'.format(args.nb_cores), '\\']

    if args.coremask is not None:
        testpmd_opts += ['--coremask={:s}'.format(args.coremask), '\\']

    if args.portmask is not None:
        testpmd_opts += ['--portmask={:s}'.format(args.portmask), '\\']

    if args.no_numa is True:
        testpmd_opts += ['--no-numa', '\\']

    if args.port_numa_config is not None:
        if check_port_numa_config(args.port_numa_config) is True:
            testpmd_opts += [
                '--port-numa-config={:s}'.format(args.port_numa_config), '\\'
            ]

    if args.ring_numa_config is not None:
        if check_ring_numa_config(args.ring_numa_config) is True:
            testpmd_opts += [
                '--ring-numa-config={:s}'.format(args.ring_numa_config), '\\'
            ]

    if args.socket_num is not None:
        testpmd_opts += [
            '{0:s}={1:d}'.format('--socket-num', args.socket_num), '\\'
        ]

    if args.mbuf_size is not None:
        mbuf_limit = 65536
        if args.mbuf_size > mbuf_limit:
            print("Error: '{0:s}' should be less than {1:d}".format(
                '--mbuf-size', mbuf_limit))
            exit()
        else:
            testpmd_opts += [
                '{0:s}={1:d}'.format('--mbuf-size', args.mbuf_size), '\\'
            ]

    if args.total_num_mbufs is not None:
        nof_mbuf_limit = 1024
        if args.total_num_mbufs <= nof_mbuf_limit:
            print("Error: '{}' should be more than {}".format(
                '--total-num-mbufs', nof_mbuf_limit))
            exit()
        else:
            testpmd_opts += [
                '{0:s}={1:d}'.format('--total-num-mbufs',
                                     args.total_num_mbufs), '\\'
            ]

    if args.max_pkt_len is not None:
        pkt_len_limit = 64
        if args.max_pkt_len < pkt_len_limit:
            print("Error: '{0:s}' should be equal or more than {1:d}".format(
                '--max-pkt-len', pkt_len_limit))
            exit()
        else:
            testpmd_opts += [
                '{0:s}={1:d}'.format('--max-pkt-len', args.max_pkt_len), '\\'
            ]

    if args.eth_peers_configfile is not None:
        testpmd_opts += [
            '{0:s}={1:s}'.format('--eth-peers-configfile',
                                 args.eth_peers_configfile), '\\'
        ]

    if args.eth_peer is not None:
        if check_eth_peer(args.eth_peer) is True:
            testpmd_opts += [
                '{0:s}={1:s}'.format('--eth-peer', args.eth_peer), '\\'
            ]
        else:
            invalid_opt_exit('--eth-peer')

    if args.pkt_filter_mode is not None:
        if check_pkt_filter_mode(args.pkt_filter_mode) is True:
            testpmd_opts += [
                '{0:s}={1:s}'.format('--pkt-filter-mode',
                                     args.pkt_filter_mode), '\\'
            ]
        else:
            print("Error: '--pkt-filter-mode' should be " +
                  "'none', 'signature' or 'perfect'")
            exit()

    if args.pkt_filter_report_hash is not None:
        if check_pkt_filter_report_hash(args.pkt_filter_report_hash) is True:
            testpmd_opts += [
                '{0:s}={1:s}'.format('--pkt-filter-report-hash',
                                     args.pkt_filter_report_hash), '\\'
            ]
        else:
            print("Error: '--pkt-filter-report-hash' should be " +
                  "'none', 'match' or 'always'")
            exit()

    if args.pkt_filter_size is not None:
        if check_pkt_filter_size(args.pkt_filter_size) is True:
            testpmd_opts += [
                '{0:s}={1:s}'.format('--pkt-filter-size',
                                     args.pkt_filter_size), '\\'
            ]
        else:
            print("Error: '--pkt-filter-size' should be " +
                  "'64K', '128K' or '256K'")
            exit()

    # It causes 'unrecognized option' error.
    # if args.pkt_filter_flexbytes_offset is not None:
    #     f_offset = args.pkt_filter_flexbytes_offset
    #     f_offset_min = 0
    #     f_offset_max = 32
    #     if (f_offset < f_offset_min) or (f_offset > f_offset_max):
    #         print("Error: '{0:s}' should be {1:d}-{2:d}".format(
    #             '--pkt-filter-flexbytes-offset',
    #             f_offset_min, f_offset_max))
    #         exit()
    #     else:
    #         testpmd_opts += ['{0:s}={1:d}'.format(
    #             '--pkt-filter-flexbytes-offset', f_offset), '\\']

    if args.pkt_filter_drop_queue is not None:
        testpmd_opts += [
            '{0:s}={1:d}'.format('--pkt-filter-drop-queue',
                                 args.pkt_filter_drop_queue), '\\'
        ]

    if args.disable_crc_strip is True:
        testpmd_opts += ['--disable-crc-strip', '\\']

    if args.enable_lro is True:
        testpmd_opts += ['--enable-lro', '\\']

    if args.enable_rx_cksum is True:
        testpmd_opts += ['--enable-rx-cksum', '\\']

    if args.enable_scatter is True:
        testpmd_opts += ['--enable-scatter', '\\']

    if args.enable_hw_vlan is True:
        testpmd_opts += ['--enable-hw-vlan', '\\']

    if args.enable_hw_vlan_filter is True:
        testpmd_opts += ['--enable-hw-vlan-filter', '\\']

    if args.enable_hw_vlan_strip is True:
        testpmd_opts += ['--enable-hw-vlan-strip', '\\']

    if args.enable_hw_vlan_extend is True:
        testpmd_opts += ['--enable-hw-vlan-extend', '\\']

    if args.enable_drop_en is True:
        testpmd_opts += ['--enable-drop-en', '\\']

    if args.disable_rss is True:
        testpmd_opts += ['--disable-rss', '\\']

    if args.port_topology is not None:
        if check_port_topology(args.port_topology) is True:
            testpmd_opts += [
                '--port-topology={:s}'.format(args.port_topology), '\\'
            ]
        else:
            invalid_opt_exit('--port-topology')

    if args.forward_mode is not None:
        if check_forward_mode(args.forward_mode) is True:
            testpmd_opts += [
                '--forward-mode={:s}'.format(args.forward_mode), '\\'
            ]
        else:
            invalid_opt_exit('--forward-mode')

    if args.rss_ip is True:
        testpmd_opts += ['--rss-ip', '\\']

    if args.rss_udp is True:
        testpmd_opts += ['--rss-udp', '\\']

    if args.rxq is not None:
        nof_q_min = 1
        nof_q_max = 65535
        if (args.rxq < nof_q_min) or (nof_q_max < args.rxq):
            print("Error: '{0:s}' should be {1:d}-{2:d}".format(
                '--rxq', nof_q_min, nof_q_max))
            exit()
        else:
            testpmd_opts += ['{0:s}={1:d}'.format('--rxq', args.rxq), '\\']

    if args.rxd is not None:
        nof_d_min = 1
        if (args.rxd < nof_d_min):
            print("Error: '{0:s}' should be equal or more than {1:d}".format(
                '--rxd', nof_d_min))
            exit()
        else:
            testpmd_opts += ['{0:s}={1:d}'.format('--rxd', args.rxd), '\\']

    if args.txq is not None:
        nof_q_min = 1
        nof_q_max = 65535
        if (args.txq < nof_q_min) or (nof_q_max < args.txq):
            print("Error: '{0:s}' should be {1:d}-{2:d}".format(
                '--txq', nof_q_min, nof_q_max))
            exit()
        else:
            testpmd_opts += ['{0:s}={1:d}'.format('--txq', args.txq), '\\']

    if args.txd is not None:
        nof_d_min = 1
        if (args.txd < nof_d_min):
            print("Error: '{0:s}' should be equal or more than {1:d}".format(
                '--txd', nof_d_min))
            exit()
        else:
            testpmd_opts += ['{0:s}={1:d}'.format('--txd', args.txd), '\\']

    if args.burst is not None:
        b_min = 1
        b_max = 512
        if (args.burst < b_min) or (b_max < args.burst):
            print("Error: '{0:s}' should be {1:d}-{2:d}".format(
                '--burst', b_min, b_max))
            exit()
        else:
            testpmd_opts += ['{0:s}={1:d}'.format('--burst', args.burst), '\\']

    if args.mbcache is not None:
        mb_min = 0
        mb_max = 512
        if (args.mbcache < mb_min) or (mb_max < args.mbcache):
            print("Error: '{0:s}' should be {1:d}-{2:d}".format(
                '--mbcache', mb_min, mb_max))
            exit()
        else:
            testpmd_opts += [
                '{0:s}={1:d}'.format('--mbcache', args.mbcache), '\\'
            ]

    if args.rxpt is not None:
        nof_p_min = 0
        if (args.rxpt < nof_p_min):
            print("Error: '{0:s}' should be equal or more than {1:d}".format(
                '--rxpt', nof_p_min))
            exit()
        else:
            testpmd_opts += ['{0:s}={1:d}'.format('--rxpt', args.rxpt), '\\']

    if args.rxht is not None:
        nof_h_min = 0
        if (args.rxht < nof_h_min):
            print("Error: '{0:s}' should be equal or more than {1:d}".format(
                '--rxht', nof_h_min))
            exit()
        else:
            testpmd_opts += ['{0:s}={1:d}'.format('--rxht', args.rxht), '\\']

    if args.rxfreet is not None:
        nof_f_min = 0
        if args.rxd is not None:
            nof_f_max = args.rxd - 1
        else:
            nof_f_max = 128 - 1  # as default of rxd - 1
        if (args.rxfreet < nof_f_min) or (nof_f_max < args.rxfreet):
            print("Error: '{0:s}' should be {1:d}-{2:d}".format(
                '--rxfreet', nof_f_min, nof_f_max))
            exit()
        else:
            testpmd_opts += [
                '{0:s}={1:d}'.format('--rxfreet', args.rxfreet), '\\'
            ]

    if args.rxwt is not None:
        nof_w_min = 0
        if (args.rxwt < nof_w_min):
            print("Error: '{0:s}' should be equal or more than {1:d}".format(
                '--rxwt', nof_w_min))
            exit()
        else:
            testpmd_opts += ['{0:s}={1:d}'.format('--rxwt', args.rxwt), '\\']

    if args.txpt is not None:
        nof_p_min = 0
        if (args.txpt < nof_p_min):
            print("Error: '{0:s}' should be equal or more than {1:d}".format(
                '--txpt', nof_p_min))
            exit()
        else:
            testpmd_opts += ['{0:s}={1:d}'.format('--txpt', args.txpt), '\\']

    if args.txht is not None:
        nof_h_min = 0
        if (args.txht < nof_h_min):
            print("Error: '{0:s}' should be equal or more than {1:d}".format(
                '--txht', nof_h_min))
            exit()
        else:
            testpmd_opts += ['{0:s}={1:d}'.format('--txht', args.txht), '\\']

    if args.txwt is not None:
        nof_w_min = 0
        if (args.txwt < nof_w_min):
            print("Error: '{0:s}' should be equal or more than {1:d}".format(
                '--txwt', nof_w_min))
            exit()
        else:
            testpmd_opts += ['{0:s}={1:d}'.format('--txwt', args.txwt), '\\']

    if args.txfreet is not None:
        nof_f_min = 0
        if args.txd is not None:
            nof_f_max = args.txd
        else:
            nof_f_max = 512  # as default of txd
        if (args.txfreet < nof_f_min) or (nof_f_max < args.txfreet):
            print("Error: '{0:s}' should be {1:d}-{2:d}".format(
                '--txfreet', nof_f_min, nof_f_max))
            exit()
        else:
            testpmd_opts += [
                '{0:s}={1:d}'.format('--txfreet', args.txfreet), '\\'
            ]

    if args.txrst is not None:
        nof_r_min = 0
        if args.txd is not None:
            nof_r_max = args.txd
        else:
            nof_r_max = 512  # as default of txd
        if (args.txrst < nof_r_min) or (nof_r_max < args.txrst):
            print("Error: '{0:s}' should be {1:d}-{2:d}".format(
                '--txrst', nof_r_min, nof_r_max))
            exit()
        else:
            testpmd_opts += ['{0:s}={1:d}'.format('--txrst', args.txrst), '\\']

    if args.rx_queue_stats_mapping is not None:
        testpmd_opts += [
            '--rx-queue-stats-mapping={:s}'.format(
                args.rx_queue_stats_mapping), '\\'
        ]

    if args.tx_queue_stats_mapping is not None:
        testpmd_opts += [
            '--tx-queue-stats-mapping={:s}'.format(
                args.tx_queue_stats_mapping), '\\'
        ]

    if args.no_flush_rx is True:
        testpmd_opts += ['--no-flush-rx', '\\']

    if args.txpkts is not None:
        if check_txpkts(args.txpkts) is True:
            testpmd_opts += [
                '{0:s}={1:s}'.format('--txpkts', args.txpkts), '\\'
            ]
        else:
            invalid_opt_exit('--txpkts')

    if args.disable_link_check is True:
        testpmd_opts += ['--disable-link-check', '\\']

    if args.no_lsc_interrupt is True:
        testpmd_opts += ['--no-lsc-interrupt', '\\']

    if args.no_rmv_interrupt is True:
        testpmd_opts += ['--no-rmv-interrupt', '\\']

    if args.bitrate_stats is not None:
        # --bitrate-stats can be several
        for stat in args.bitrate_stats:
            if stat[0] >= 0:
                testpmd_opts += [
                    '{0:s}={1:d}'.format('--bitrate-stats', stat[0]), '\\'
                ]
            else:
                print("Error: '--bitrate-stats' should be <= 0")
                exit()

    if args.print_event is not None:
        if check_event(args.print_event) is True:
            testpmd_opts += [
                '{0:s}={1:s}'.format('--print-event', args.print_event), '\\'
            ]
        else:
            invalid_opt_exit('--print-event')

    if args.mask_event is not None:
        if check_event(args.mask_event) is True:
            testpmd_opts += [
                '{0:s}={1:s}'.format('--mask-event', args.mask_event), '\\'
            ]
        else:
            invalid_opt_exit('--mask-event')

    if args.flow_isolate_all is True:
        testpmd_opts += ['--flow-isolate-all', '\\']

    if args.tx_offloads is not None:
        ptn = r'^0x[0-9aA-Fa-f]+$'  # should be hexadecimal
        if re.match(ptn, args.tx_offloads) is True:
            testpmd_opts += [
                '{0:s}={1:s}'.format('--tx-offloads', args.tx_offloads), '\\'
            ]
        else:
            invalid_opt_exit('--tx-offloads')

    if args.hot_plug is True:
        testpmd_opts += ['--hot-plug', '\\']

    if args.vxlan_gpe_port is not None:
        nof_p_min = 0
        if (args.vxlan_gpe_port < nof_p_min):
            print("Error: '{0:s}' should be <= {1:d}".format(
                '--vxlan-gpe-port', nof_p_min))
            exit()
        else:
            testpmd_opts += [
                '{0:s}={1:d}'.format('--vxlan-gpe-port', args.vxlan_gpe_port),
                '\\'
            ]

    if args.mlockall is True:
        testpmd_opts += ['--mlockall', '\\']

    if args.no_mlockall is True:
        testpmd_opts += ['--no-mlockall', '\\']

    cmds = docker_cmd + docker_opts + [container_image, '\\'] + \
        testpmd_cmd + eal_opts + testpmd_opts
    if cmds[-1] == '\\':
        cmds.pop()
    common.print_pretty_commands(cmds)

    if args.dry_run is True:
        exit()

    # Remove delimiters for print_pretty_commands().
    while '\\' in cmds:
        cmds.remove('\\')
    subprocess.call(cmds)
Ejemplo n.º 8
0
def main():
    args = parse_args()

    # Container image name such as 'sppc/dpdk-ubuntu:18.04'
    if args.container_image is not None:
        container_image = args.container_image
    else:
        container_image = common.container_img_name(
            common.IMG_BASE_NAMES['pktgen'], args.dist_name, args.dist_ver)

    # Setup devices with given device UIDs.
    dev_uids = None
    sock_files = None
    if args.dev_uids is not None:
        if app_helper.is_valid_dev_uids(args.dev_uids) is False:
            print('Invalid option: {}'.format(args.dev_uids))
            exit()

        dev_uids_list = args.dev_uids.split(',')
        sock_files = app_helper.sock_files(dev_uids_list)

    # Setup docker command.
    if args.workdir is not None:
        wd = args.workdir
    else:
        wd = '/root/pktgen-dpdk'
    docker_cmd = ['sudo', 'docker', 'run', '\\']
    docker_opts = app_helper.setup_docker_opts(args, sock_files, None, wd)

    # Setup pktgen command
    pktgen_cmd = [APP_NAME, '\\']

    # Setup EAL options.
    eal_opts = app_helper.setup_eal_opts(args, APP_NAME)

    # Setup matrix for assignment of cores and ports.
    if args.matrix is not None:
        matrix = args.matrix
    else:
        # Get core_list such as [0,1,2] from '-c 0x07' or '-l 0-2'
        core_opt = app_helper.get_core_opt(args)
        core_list = app_helper.cores_to_list(core_opt)
        if len(core_list) < 2:
            print("Error: Two or more cores required!")
            exit()

        slave_core_list = core_list[1:]
        nof_slave_cores = len(slave_core_list)
        nof_ports = len(dev_uids_list)
        nof_cores_each_port = nof_slave_cores / nof_ports
        if nof_cores_each_port < 1:
            print('Error: Too few cores for given port(s)!')
            print('{0:d} cores required for {1:d} port(s)'.format(
                (nof_slave_cores + 1), nof_ports))
            exit()

        matrix_list = []
        if nof_cores_each_port == 1:
            for i in range(0, nof_ports):
                matrix_list.append('{0:d}.{1:d}'.format(slave_core_list[i], i))
        elif nof_cores_each_port == 2:
            for i in range(0, nof_ports):
                matrix_list.append('[{0:d}:{1:d}].{2:d}'.format(
                    slave_core_list[2 * i], slave_core_list[2 * i + 1], i))
        elif nof_cores_each_port == 3:  # Two cores for rx, one for tx
            for i in range(0, nof_ports):
                matrix_list.append('[{0:d}-{1:d}:{2:d}].{3:d}'.format(
                    slave_core_list[3 * i], slave_core_list[3 * i + 1],
                    slave_core_list[3 * i + 2], i))
        elif nof_cores_each_port == 4:
            for i in range(0, nof_ports):
                matrix_list.append('[{0:d}-{1:d}:{2:d}-{3:d}].{4:d}'.format(
                    slave_core_list[4 * i], slave_core_list[4 * i + 1],
                    slave_core_list[4 * i + 2], slave_core_list[4 * i + 3], i))
        # Do not support more than five because it is rare case and
        # calculation is complex.
        else:
            print('Error: Too many cores for calculation for ports!')
            print("Consider to use '--matrix' for assigning directly")
            exit()
        matrix = ','.join(matrix_list)

    pktgen_opts = ['-m', matrix, '\\']

    if args.pcap_file is not None:
        pktgen_opts += ['-s', args.pcap_file, '\\']

    if args.script_file is not None:
        pktgen_opts += ['-f', args.script_file, '\\']

    if args.log_file is not None:
        pktgen_opts += ['-l', args.log_file, '\\']

    if args.promiscuous is True:
        pktgen_opts += ['-P', '\\']

    if args.sock_default is True:
        pktgen_opts += ['-G', '\\']

    if args.sock_address is not None:
        pktgen_opts += ['-g', args.sock_address, '\\']

    if args.term_color is True:
        pktgen_opts += ['-T', '\\']

    if args.numa is True:
        pktgen_opts += ['-N', '\\']

    cmds = docker_cmd + docker_opts + [container_image, '\\'] + \
        pktgen_cmd + eal_opts + pktgen_opts
    if cmds[-1] == '\\':
        cmds.pop()
    common.print_pretty_commands(cmds)

    if args.dry_run is True:
        exit()

    # Remove delimiters for print_pretty_commands().
    while '\\' in cmds:
        cmds.remove('\\')
    subprocess.call(cmds)