def main():
    args = parse_args()

    # Setup for vhost devices with given device IDs.
    dev_ids_list = app_helper.dev_ids_to_list(args.dev_ids)
    sock_files = app_helper.sock_files(dev_ids_list)

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

    cmd_path = '/bin/bash'

    cmd = [cmd_path, '\\']

    cmds = docker_cmd + docker_opts + 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)
def main():
    args = parse_args()

    app_name = 'spp_nfv'

    # Setup docker command.
    docker_cmd = ['sudo', 'docker', 'run', '\\']

    # Container image name such as 'sppc/spp-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['spp'], args.dist_name, args.dist_ver)

    app_opts = ['-v', '/var/run/:/var/run/', '\\', '-v', '/tmp/:/tmp/', '\\']

    docker_opts = app_helper.setup_docker_opts(args, None, app_opts)

    # Setup spp_nfv command.
    spp_cmd = [app_name, '\\']

    eal_opts = app_helper.setup_eal_opts(args,
                                         app_name=None,
                                         proc_type='secondary')

    spp_opts = []
    # Check for other mandatory opitons.
    if args.sec_id is None:
        common.error_exit('--sec-id')
    else:
        spp_opts += ['-n', str(args.sec_id), '\\']

    # IP address of spp-ctl.
    ctl_ip = os.getenv('SPP_CTL_IP', args.ctl_ip)
    if ctl_ip is None:
        print('Env variable "SPP_CTL_IP" is not defined!')
        exit()
    else:
        spp_opts += ['-s', '{}:{}'.format(ctl_ip, args.ctl_port), '\\']

    cmds = docker_cmd + docker_opts + [container_image, '\\'] + \
        spp_cmd + eal_opts + spp_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)
def main():
    args = parse_args()

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

    # Setup for vhost devices with given device IDs.
    dev_ids_list = app_helper.dev_ids_to_list(args.dev_ids)
    sock_files = app_helper.sock_files(dev_ids_list)

    # Setup docker command.
    docker_cmd = ['sudo', 'docker', 'run', '\\']
    docker_opts = app_helper.setup_docker_opts(args, target_name, 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 = '%s/examples/l2fwd/%s/l2fwd' % (env.RTE_SDK, env.RTE_TARGET)

    l2fwd_cmd = [cmd_path, '\\']

    file_prefix = 'spp-l2fwd-container%d' % dev_ids_list[0]
    eal_opts = app_helper.setup_eal_opts(args, file_prefix)

    l2fwd_opts = ['-p', args.port_mask, '\\']

    # Parse vhost device IDs and Check the number of devices is
    # sufficient for port mask.
    if app_helper.is_sufficient_dev_ids(args.dev_ids,
                                        args.port_mask) is not True:
        print("Error: Cannot reserve ports '%s (= 0b%s)' on '%s'." %
              (args.port_mask, format(int(args.port_mask, 16),
                                      'b'), args.dev_ids))
        exit()

    cmds = docker_cmd + docker_opts + 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)
Exemple #4
0
def main():
    args = parse_args()

    # Check for other mandatory opitons.
    if args.sec_id is None:
        common.error_exit('--sec-id')

    if args.dev_ids is None:
        common.error_exit('--dev-ids')

    if args.port_mask is None:
        common.error_exit('--port-mask')

    # Setup for vhost devices with given device IDs.
    dev_ids_list = app_helper.dev_ids_to_list(args.dev_ids)
    sock_files = app_helper.sock_files(dev_ids_list)

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

    # IP address of SPP controller.
    ctrl_ip = os.getenv('SPP_CTRL_IP', args.ctrl_ip)
    if ctrl_ip is None:
        common.error_exit('SPP_CTRL_IP')

    # Setup spp_vm command.
    spp_cmd = ['spp_vm', '\\']

    file_prefix = 'spp-l2fwd-container%d' % dev_ids_list[0]
    eal_opts = app_helper.setup_eal_opts(args, file_prefix)

    spp_opts = [
        '-n', str(args.sec_id), '\\',
        '-p', args.port_mask, '\\',
        '-s', '%s:%d' % (ctrl_ip, args.ctrl_port)
    ]

    cmds = docker_cmd + docker_opts + spp_cmd + eal_opts + spp_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)
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)
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)
Exemple #7
0
def main():
    args = parse_args()

    # Check for other mandatory opitons.
    if args.dev_ids is None:
        common.error_exit('--dev-ids')

    # Setup for vhost devices with given device IDs.
    dev_ids_list = app_helper.dev_ids_to_list(args.dev_ids)
    sock_files = app_helper.sock_files(dev_ids_list)

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

    # Setup helloworld run on container.
    cmd_path = '%s/examples/helloworld/%s/helloworld' % (env.RTE_SDK,
                                                         env.RTE_TARGET)

    hello_cmd = [cmd_path, '\\']

    file_prefix = 'spp-hello-container%d' % dev_ids_list[0]
    eal_opts = app_helper.setup_eal_opts(args, file_prefix)

    # No application specific options for helloworld
    hello_opts = []

    cmds = docker_cmd + docker_opts + 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)
Exemple #8
0
def main():
    args = parse_args()

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

    # Setup for vhost devices with given device IDs.
    dev_ids_list = app_helper.dev_ids_to_list(args.dev_ids)
    sock_files = app_helper.sock_files(dev_ids_list)

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

    # Parse vhost device IDs and Check the number of devices is
    # sufficient for port mask.
    if app_helper.is_sufficient_dev_ids(args.dev_ids,
                                        args.port_mask) is not True:
        print("Error: Cannot reserve ports '{} (= 0b{})' on '{}'.".format(
            args.port_mask, format(int(args.port_mask, 16), 'b'),
            args.dev_ids))
        exit()

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

    l3fwd_cmd = [cmd_path, '\\']

    # Setup EAL options.
    file_prefix = 'spp-l3fwd-acl-container{}'.format(dev_ids_list[0])
    eal_opts = app_helper.setup_eal_opts(args, file_prefix)

    # 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', '"{}"'.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', '"{}"'.format(args.rule_ipv4), '\\']
        else:
            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', '"{}"'.format(args.rule_ipv6), '\\']
        else:
            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 {}'.format(args.max_pkt_len), '\\']
    if args.no_numa is True:
        l3fwd_opts += ['--no-numa', '\\']

    cmds = docker_cmd + docker_opts + 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)
Exemple #9
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)
Exemple #10
0
def main():
    args = parse_args()

    # Check for other mandatory opitons.
    if args.dev_ids is None:
        common.error_exit('--dev-ids')

    # Setup for vhost devices with given device IDs.
    dev_ids_list = app_helper.dev_ids_to_list(args.dev_ids)
    sock_files = app_helper.sock_files(dev_ids_list)

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

    cmd_path = 'testpmd'

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

    # Setup EAL options
    file_prefix = 'spp-testpmd-container%d' % dev_ids_list[0]
    eal_opts = app_helper.setup_eal_opts(args, file_prefix)

    # 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: '%s' cannot be used in interactive mode" %
                  ('--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' % args.nb_cores, '\\']

    if args.coremask is not None:
        testpmd_opts += ['--coremask=%s' % args.coremask, '\\']

    if args.portmask is not None:
        testpmd_opts += ['--portmask=%s' % 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={}'.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={}'.format(args.ring_numa_config), '\\'
            ]

    if args.socket_num is not None:
        testpmd_opts += ['%s=%d' % ('--socket-num', args.socket_num), '\\']

    if args.mbuf_size is not None:
        mbuf_limit = 65536
        if args.mbuf_size > mbuf_limit:
            print("Error: '%s' should be less than %d" %
                  ('--mbuf-size', mbuf_limit))
            exit()
        else:
            testpmd_opts += ['%s=%d' % ('--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: '%s' should be more than %d" %
                  ('--total-num-mbufs', nof_mbuf_limit))
            exit()
        else:
            testpmd_opts += [
                '%s=%d' % ('--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: '%s' should be equal or more than %d" %
                  ('--max-pkt-len', pkt_len_limit))
            exit()
        else:
            testpmd_opts += [
                '%s=%d' % ('--max-pkt-len', args.max_pkt_len), '\\'
            ]

    if args.eth_peers_configfile is not None:
        testpmd_opts += [
            '%s=%s' % ('--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 += ['%s=%s' % ('--eth-peer', args.eth_peer), '\\']
        else:
            error_exit('--eth-peer')

    if args.pkt_filter_mode is not None:
        if check_pkt_filter_mode(args.pkt_filter_mode) is True:
            testpmd_opts += [
                '%s=%s' % ('--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 += [
                '%s=%s' %
                ('--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 += [
                '%s=%s' % ('--pkt-filter-size', args.pkt_filter_size), '\\'
            ]
        else:
            print("Error: '--pkt-filter-size' should be " +
                  "'64K', '128K' or '256K'")
            exit()

    # TODO(yasufum) Confirm this option is supported in dpdk 18.02
    if args.pkt_filter_flexbytes_offset is not None:
        not_supported_exit('--pkt-filter-flexbytes-offset')

    # 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: '%s' should be %d-%d" % (
    #             '--pkt-filter-flexbytes-offset',
    #             f_offset_min, f_offset_max))
    #         exit()
    #     else:
    #         testpmd_opts += ['%s=%d' % (
    #             '--pkt-filter-flexbytes-offset', f_offset), '\\']

    if args.pkt_filter_drop_queue is not None:
        testpmd_opts += [
            '%s=%d' % ('--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={}'.format(args.port_topology), '\\'
            ]
        else:
            error_exit('--port-topology')

    if args.forward_mode is not None:
        if check_forward_mode(args.forward_mode) is True:
            testpmd_opts += [
                '--forward-mode={}'.format(args.forward_mode), '\\'
            ]
        else:
            error_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: '%s' should be %d-%d" %
                  ('--rxq', nof_q_min, nof_q_max))
            exit()
        else:
            testpmd_opts += ['%s=%d' % ('--rxq', args.rxq), '\\']

    if args.rxd is not None:
        nof_d_min = 1
        if (args.rxd < nof_d_min):
            print("Error: '%s' should be equal or more than %d" %
                  ('--rxd', nof_d_min))
            exit()
        else:
            testpmd_opts += ['%s=%d' % ('--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: '%s' should be %d-%d" %
                  ('--txq', nof_q_min, nof_q_max))
            exit()
        else:
            testpmd_opts += ['%s=%d' % ('--txq', args.txq), '\\']

    if args.txd is not None:
        nof_d_min = 1
        if (args.txd < nof_d_min):
            print("Error: '%s' should be equal or more than %d" %
                  ('--txd', nof_d_min))
            exit()
        else:
            testpmd_opts += ['%s=%d' % ('--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: '%s' should be %d-%d" % ('--burst', b_min, b_max))
            exit()
        else:
            testpmd_opts += ['%s=%d' % ('--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: '%s' should be %d-%d" %
                  ('--mbcache', mb_min, mb_max))
            exit()
        else:
            testpmd_opts += ['%s=%d' % ('--mbcache', args.mbcache), '\\']

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

    if args.rxht is not None:
        nof_h_min = 0
        if (args.rxht < nof_h_min):
            print("Error: '%s' should be equal or more than %d" %
                  ('--rxht', nof_h_min))
            exit()
        else:
            testpmd_opts += ['%s=%d' % ('--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: '%s' should be %d-%d" %
                  ('--rxfreet', nof_f_min, nof_f_max))
            exit()
        else:
            testpmd_opts += ['%s=%d' % ('--rxfreet', args.rxfreet), '\\']

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

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

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

    if args.txwt is not None:
        nof_w_min = 0
        if (args.txwt < nof_w_min):
            print("Error: '%s' should be equal or more than %d" %
                  ('--txwt', nof_w_min))
            exit()
        else:
            testpmd_opts += ['%s=%d' % ('--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: '%s' should be %d-%d" %
                  ('--txfreet', nof_f_min, nof_f_max))
            exit()
        else:
            testpmd_opts += ['%s=%d' % ('--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: '%s' should be %d-%d" %
                  ('--txrst', nof_r_min, nof_r_max))
            exit()
        else:
            testpmd_opts += ['%s=%d' % ('--txrst', args.txrst), '\\']

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

    if args.tx_queue_stats_mapping is not None:
        testpmd_opts += [
            '--tx-queue-stats-mapping={}'.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 += ['%s=%s' % ('--txpkts', args.txpkts), '\\']
        else:
            error_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 += ['%s=%d' % ('--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 += [
                '%s=%s' % ('--print-event', args.print_event), '\\'
            ]
        else:
            error_exit('--print-event')

    if args.mask_event is not None:
        if check_event(args.mask_event) is True:
            testpmd_opts += ['%s=%s' % ('--mask-event', args.mask_event), '\\']
        else:
            error_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 += [
                '%s=%s' % ('--tx-offloads', args.tx_offloads), '\\'
            ]
        else:
            error_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: '%s' should be <= %d" %
                  ('--vxlan-gpe-port', nof_p_min))
            exit()
        else:
            testpmd_opts += [
                '%s=%d' % ('--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 + 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)
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)
Exemple #12
0
def main():
    args = parse_args()

    app_name = 'spp_primary'

    # Setup docker command.
    docker_cmd = ['sudo', 'docker', 'run', '\\']

    # Container image name such as 'sppc/spp-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['spp'], args.dist_name, args.dist_ver)

    app_opts = ['-v', '/var/run/:/var/run/', '\\', '-v', '/tmp:/tmp', '\\']

    # Use host network if attaching TAP device to show them on the host.
    for dev_uid in args.dev_uids.split(','):
        if 'tap' in dev_uid:
            app_opts += ['--net', 'host', '\\']

    docker_opts = app_helper.setup_docker_opts(args, None, app_opts)

    # Setup spp primary command.
    spp_cmd = [app_name, '\\']

    eal_opts = app_helper.setup_eal_opts(args,
                                         app_name=None,
                                         proc_type='primary',
                                         is_spp_pri=True)

    spp_opts = []
    # Check for other mandatory opitons.
    if args.port_mask is None:
        common.error_exit('port_mask')
    else:
        spp_opts += ['-p', args.port_mask, '\\']

    spp_opts += ['-n', str(args.nof_ring), '\\']

    # IP address of spp-ctl.
    ctl_ip = os.getenv('SPP_CTL_IP', args.ctl_ip)
    if ctl_ip is None:
        print('Env variable "SPP_CTL_IP" is not defined!')
        exit()
    else:
        spp_opts += ['-s', '{}:{}'.format(ctl_ip, args.ctl_port), '\\']

    cmds = docker_cmd + docker_opts + [container_image, '\\'] + \
        spp_cmd + eal_opts + spp_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)
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)
Exemple #14
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)
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)
Exemple #16
0
def main():
    args = parse_args()

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

    # Setup for vhost devices with given device IDs.
    dev_ids_list = app_helper.dev_ids_to_list(args.dev_ids)
    sock_files = app_helper.sock_files(dev_ids_list)

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

    # Parse vhost device IDs and Check the number of devices is
    # sufficient for port mask.
    if app_helper.is_sufficient_dev_ids(args.dev_ids,
                                        args.port_mask) is not True:
        print("Error: Cannot reserve ports '%s (= 0b%s)' on '%s'." %
              (args.port_mask, format(int(args.port_mask, 16),
                                      'b'), args.dev_ids))
        exit()

    # Setup l3fwd command runs on container.
    cmd_path = '%s/examples/l3fwd/%s/l3fwd' % (env.RTE_SDK, env.RTE_TARGET)

    l3fwd_cmd = [cmd_path, '\\']

    # Setup EAL options.
    file_prefix = 'spp-l3fwd-container%d' % dev_ids_list[0]
    eal_opts = app_helper.setup_eal_opts(args, file_prefix)

    # 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: %s' % args.config)
        exit()
    else:
        l3fwd_opts += ['--config', '"%s"' % 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 %s' % 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' % 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' % 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 + 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)
Exemple #17
0
def main():
    args = parse_args()

    # Setup for vhost devices with given device IDs.
    dev_ids_list = app_helper.dev_ids_to_list(args.dev_ids)
    sock_files = app_helper.sock_files(dev_ids_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, target_name, sock_files,
                                               wd)

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

    file_prefix = 'spp-pktgen-container%d' % dev_ids_list[0]
    eal_opts = app_helper.setup_eal_opts(args, file_prefix)

    # 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_ids_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("%d cores required for %d port(s)" %
                  ((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('%d.%d' % (slave_core_list[i], i))
        elif nof_cores_each_port == 2:
            for i in range(0, nof_ports):
                matrix_list.append(
                    '[%d:%d].%d' %
                    (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(
                    '[%d-%d:%d].%d' %
                    (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(
                    '[%d-%d:%d-%d].%d' %
                    (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 + 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)
Exemple #18
0
def main():
    args = parse_args()

    # Check for other mandatory opitons.
    if args.dev_ids is None:
        common.error_exit('--dev-ids')

    # Setup for vhost devices with given device IDs.
    dev_ids_list = app_helper.dev_ids_to_list(args.dev_ids)
    sock_files = app_helper.sock_files(dev_ids_list)

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

    app_name = 'load_balancer'
    cmd_path = '%s/examples/%s/%s/%s' % (env.RTE_SDK, app_name, env.RTE_TARGET,
                                         app_name)

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

    file_prefix = 'spp-lb-container%d' % dev_ids_list[0]
    eal_opts = app_helper.setup_eal_opts(args, file_prefix)

    lb_opts = []

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

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

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

    if args.lpm is None:
        common.error_exit('--lpm')
    else:
        lpm = '"%s"' % args.lpm
        lb_opts += ['--lpm', 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 + 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)