From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id C9A8DA046B for ; Mon, 24 Jun 2019 12:45:45 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id C283A2C2B; Mon, 24 Jun 2019 12:45:45 +0200 (CEST) Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by dpdk.org (Postfix) with ESMTP id 712082C2B for ; Mon, 24 Jun 2019 12:45:44 +0200 (CEST) Received: by mail-pl1-f169.google.com with SMTP id t7so6645088plr.11 for ; Mon, 24 Jun 2019 03:45:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=rvakY1MHAlV8G5tTzF4SqrqzFDmqDDDZewTD8nGWMak=; b=Zhq2ModVEQYoyjb5rWjJ+ET1LZtFmn/U4Z9p7h1nc6nH1WmZGnt+/Ekv9i8nN8Nq16 cTE3m5g6lK8xXPA0puPK330KCLqGwx7i0yKkJoRYlEtKyiGepPrM/VdS/gJ+75B3Od+G ckQ7wAMosM7flFaWk3cznvB93k/ZsgtM09z3AkLyAMLymKEJQIje1d9PfohKv+bP7KWV rNKZRzNQMNvewG8Mm368WVtr4fJHvgPNQgZ7eAV/MsmjihGb5JonDBGrUPARYzBbwvpV 71fNlZliJeF3w0aG6u1ljnpgEIRtnDE44jd+tdGpgzCaWIzun6GyPFYjA7Ml1DKvrsmL vkLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=rvakY1MHAlV8G5tTzF4SqrqzFDmqDDDZewTD8nGWMak=; b=L6lu/umtbXNFIsESuUr/azVoTKNnm7AwD11v81O6ltv/OPdxXCTwgVFhOzxwKFX8nE ScfN1Y8I9lA7/1AnFLXlRI2ZHGS/ZQSnV0UsJvYLO3KXC7sdHn3rFZXRyr33gAzSOavg fr2sNiXyTDjBHWZdY5625yFCZj2NOaGDD8XxqDM3B3UODAi42v5TQ2KVobY3FwmH6bPM gJtlf+nLJshUzL/Z6SgF4Zk9YqdR3vcU3hKHis+B//I7FkbRuVRZ90BAGfXG/rFa2OcI 1PHM6+5jvMdTk4rRVjwvfwo16LvHuCgDZmelpeBhgquoBaIC8LfoFI/O250gPtcTlHaI TnKQ== X-Gm-Message-State: APjAAAX4RhL5yvUwJyY0Kc6G2/zSRq11Lfh7eWNQMFr0Byz3+Q+h9j6J uI6DIsM4oCq0nv9iAAMIIJHddHUu X-Google-Smtp-Source: APXvYqw0rsM0HvMSqxZzTM2eWl+E/oFf6zjnjhgdCWF4e+f0D7pViyLOs4gt+z3Nc7xdvAXw7OPZcg== X-Received: by 2002:a17:902:28:: with SMTP id 37mr78328606pla.188.1561373143375; Mon, 24 Jun 2019 03:45:43 -0700 (PDT) Received: from localhost.localdomain ([192.47.164.146]) by smtp.gmail.com with ESMTPSA id e6sm12150092pfn.71.2019.06.24.03.45.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Jun 2019 03:45:42 -0700 (PDT) From: yasufum.o@gmail.com To: spp@dpdk.org, ferruh.yigit@intel.com, yasufum.o@gmail.com Date: Mon, 24 Jun 2019 19:45:39 +0900 Message-Id: <20190624104539.25196-1-yasufum.o@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [spp] [PATCH] controller: move completion of pri launch 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: , Errors-To: spp-bounces@dpdk.org Sender: "spp" From: Yasufumi Ogawa This update is to move completion of `pri; launch` command defined in complete() method to out side and add new method _setup_launch_opts() because it is getting long. Signed-off-by: Yasufumi Ogawa --- src/controller/commands/pri.py | 152 +++++++++++++++++---------------- 1 file changed, 78 insertions(+), 74 deletions(-) diff --git a/src/controller/commands/pri.py b/src/controller/commands/pri.py index 6089137..97f8780 100644 --- a/src/controller/commands/pri.py +++ b/src/controller/commands/pri.py @@ -155,6 +155,83 @@ class SppPrimary(object): rid=rports['id'], rx=rports['rx'], tx=rports['tx'], rx_drop=rports['rx_drop'], tx_drop=rports['tx_drop'])) + def _setup_launch_opts(self, tokens, cli_config): + """Make options for launch cmd from config params.""" + + if 'max_secondary' in cli_config.keys(): + max_secondary = int(cli_config['max_secondary']['val']) + + if (tokens[2] in spp_common.SEC_TYPES) and \ + (int(tokens[3])-1 in range(max_secondary)): + ptype = tokens[2] + sid = tokens[3] + + if ptype == 'nfv': + opt_sid = '-n' + else: + opt_sid = '--client-id' + + # Need to replace port from `7777` of spp-ctl to `6666` + # of secondary process. + server_addr = common.current_server_addr() + server_addr = server_addr.replace('7777', '6666') + + # Lcore ID of worker lcore starts from sec ID in + # default. + lcore_base = int(sid) + + # Define rest of worker lcores from config dynamically. + if ptype == 'nfv': # one worker lcore is enough + if 'sec_nfv_nof_lcores' in cli_config.keys(): + tmpkey = 'sec_nfv_nof_lcores' + nof_workers = int( + cli_config[tmpkey]['val']) + + elif ptype == 'vf': + if 'sec_vf_nof_lcores' in cli_config.keys(): + nof_workers = int( + cli_config['sec_vf_nof_lcores']['val']) + + elif ptype == 'mirror': # two worker cores + if 'sec_mirror_nof_lcores' in cli_config.keys(): + tmpkey = 'sec_mirror_nof_lcores' + nof_workers = int( + cli_config[tmpkey]['val']) + + elif ptype == 'pcap': # at least two worker cores + if 'sec_pcap_nof_lcores' in cli_config.keys(): + tmpkey = 'sec_pcap_nof_lcores' + nof_workers = int( + cli_config[tmpkey]['val']) + + if 'sec_pcap_port' in cli_config.keys(): + temp = '-c {}'.format( + cli_config['sec_pcap_port']['val']) + + self.launch_template = '{} {}'.format( + self.launch_template, temp) + + last_core = lcore_base + nof_workers - 1 + + # Decide lcore option based on configured number of + # lcores. + if last_core == lcore_base: + rest_core = '{}'.format(last_core) + else: + rest_core = '{}-{}'.format(lcore_base, last_core) + + temp = self._setup_launch_template( + cli_config, self.launch_template) + candidates = [temp.format( + wlcores=rest_core, opt_sid=opt_sid, sid=sid, + sec_addr=server_addr)] + else: + logger.error( + 'Error: max_secondary is not defined in config') + candidates = [] + + return candidates + # TODO(yasufum) add checking for cli_config has keys def complete(self, text, line, begidx, endidx, cli_config): """Completion for primary process commands. @@ -191,80 +268,7 @@ class SppPrimary(object): candidates = [] elif len(tokens) == 5 and tokens[1] == 'launch': - # TODO(yasufum) move this long completion to method. - - if 'max_secondary' in cli_config.keys(): - max_secondary = int(cli_config['max_secondary']['val']) - - if (tokens[2] in spp_common.SEC_TYPES) and \ - (int(tokens[3])-1 in range(max_secondary)): - ptype = tokens[2] - sid = tokens[3] - - if ptype == 'nfv': - opt_sid = '-n' - else: - opt_sid = '--client-id' - - # Need to replace port from `7777` of spp-ctl to `6666` - # of secondary process. - server_addr = common.current_server_addr() - server_addr = server_addr.replace('7777', '6666') - - # Lcore ID of worker lcore starts from sec ID in - # default. - lcore_base = int(sid) - - # Define rest of worker lcores from config dynamically. - if ptype == 'nfv': # one worker lcore is enough - if 'sec_nfv_nof_lcores' in cli_config.keys(): - tmpkey = 'sec_nfv_nof_lcores' - nof_workers = int( - cli_config[tmpkey]['val']) - - elif ptype == 'vf': - if 'sec_vf_nof_lcores' in cli_config.keys(): - nof_workers = int( - cli_config['sec_vf_nof_lcores']['val']) - - elif ptype == 'mirror': # two worker cores - if 'sec_mirror_nof_lcores' in cli_config.keys(): - tmpkey = 'sec_mirror_nof_lcores' - nof_workers = int( - cli_config[tmpkey]['val']) - - elif ptype == 'pcap': # at least two worker cores - if 'sec_pcap_nof_lcores' in cli_config.keys(): - tmpkey = 'sec_pcap_nof_lcores' - nof_workers = int( - cli_config[tmpkey]['val']) - - if 'sec_pcap_port' in cli_config.keys(): - temp = '-c {}'.format( - cli_config['sec_pcap_port']['val']) - - self.launch_template = '{} {}'.format( - self.launch_template, temp) - - last_core = lcore_base + nof_workers - 1 - - # Decide lcore option based on configured number of - # lcores. - if last_core == lcore_base: - rest_core = '{}'.format(last_core) - else: - rest_core = '{}-{}'.format(lcore_base, last_core) - - temp = self._setup_launch_template( - cli_config, self.launch_template) - candidates = [temp.format( - wlcores=rest_core, opt_sid=opt_sid, sid=sid, - sec_addr=server_addr)] - - else: - logger.error( - 'Error: max_secondary is not defined in config') - candidates = [] + candidates = self._setup_launch_opts(tokens, cli_config) if not text: completions = candidates -- 2.17.1