From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mogw0224.ocn.ad.jp (mogw0224.ocn.ad.jp [114.147.58.30]) by dpdk.org (Postfix) with ESMTP id 16E2F1D8D9 for ; Fri, 15 Jun 2018 10:38:11 +0200 (CEST) Received: from mf-smf-ucb024c3 (mf-smf-ucb024c3.ocn.ad.jp [153.153.66.162]) by mogw0224.ocn.ad.jp (Postfix) with ESMTP id 1E8DA1A42B3; Fri, 15 Jun 2018 17:38:10 +0900 (JST) Received: from ntt.pod01.mv-mta-ucb029 ([153.149.230.163]) by mf-smf-ucb024c3 with ESMTP id TkFFfztj6Jf6oTkFGfnBJC; Fri, 15 Jun 2018 17:38:10 +0900 Received: from smtp.ocn.ne.jp ([153.149.227.166]) by ntt.pod01.mv-mta-ucb029 with id yweA1x0013c2f7501weA5M; Fri, 15 Jun 2018 08:38:10 +0000 Received: from localhost.localdomain (p5164-ipngn8501marunouchi.tokyo.ocn.ne.jp [153.214.228.164]) by smtp.ocn.ne.jp (Postfix) with ESMTPA; Fri, 15 Jun 2018 17:38:09 +0900 (JST) From: ogawa.yasufumi@lab.ntt.co.jp To: ferruh.yigit@intel.com, spp@dpdk.org Cc: Yasufumi Ogawa Date: Fri, 15 Jun 2018 17:37:50 +0900 Message-Id: <20180615083754.20220-12-ogawa.yasufumi@lab.ntt.co.jp> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180615083754.20220-1-ogawa.yasufumi@lab.ntt.co.jp> References: <20180615083754.20220-1-ogawa.yasufumi@lab.ntt.co.jp> Subject: [spp] [PATCH 11/15] tools/sppc: add pktgen app continer X-BeenThere: spp@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Soft Patch Panel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Jun 2018 08:38:12 -0000 From: Yasufumi Ogawa Signed-off-by: Yasufumi Ogawa --- tools/sppc/app/pktgen.py | 182 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100755 tools/sppc/app/pktgen.py diff --git a/tools/sppc/app/pktgen.py b/tools/sppc/app/pktgen.py new file mode 100755 index 0000000..0b79bd3 --- /dev/null +++ b/tools/sppc/app/pktgen.py @@ -0,0 +1,182 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2018 Nippon Telegraph and Telephone Corporation + +import argparse +import os +import subprocess +import sys + +work_dir = os.path.dirname(__file__) +sys.path.append(work_dir + '/..') +from conf import env +from lib import app_helper +from lib import common + +target_name = 'pktgen' + + +def parse_args(): + parser = argparse.ArgumentParser( + description="Launcher for pktgen-dpdk application container") + + parser = app_helper.add_eal_args(parser) + parser = app_helper.add_appc_args(parser) + + parser.add_argument( + '-s', '--pcap-file', + type=str, + help="PCAP packet flow file of port, defined as 'N:filename'") + parser.add_argument( + '-f', '--script-file', + type=str, + help="Pktgen script (.pkt) to or a Lua script (.lua)") + parser.add_argument( + '-lf', '--log-file', + type=str, + help="Filename to write a log, as '-l' of pktgen") + parser.add_argument( + '-P', '--promiscuous', + action='store_true', + help="Enable PROMISCUOUS mode on all ports") + parser.add_argument( + '-G', '--sock-default', + action='store_true', + help="Enable socket support using default server values of " + + "localhost:0x5606") + parser.add_argument( + '-g', '--sock-address', + type=str, + help="Same as -G but with an optional IP address and port number") + parser.add_argument( + '-T', '--term-color', + action='store_true', + help="Enable color terminal output in VT100") + parser.add_argument( + '-N', '--numa', + action='store_true', + help="Enable NUMA support") + parser.add_argument( + '--matrix', + type=str, + help="Matrix of cores and port as '-m' of pktgen, " + + "such as [1:2].0 or 1.0") + + parser = app_helper.add_sppc_args(parser) + return parser.parse_args() + + +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, + '%s/../pktgen-dpdk' % env.RTE_SDK) + + cmd_path = '%s/../pktgen-dpdk/app/%s/pktgen' % ( + env.RTE_SDK, env.RTE_TARGET) + + # Setup pktgen command + pktgen_cmd = [cmd_path, '\\'] + + 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) + + +if __name__ == '__main__': + main() -- 2.17.1