Soft Patch Panel
 help / color / mirror / Atom feed
From: ogawa.yasufumi@lab.ntt.co.jp
To: spp@dpdk.org, ferruh.yigit@intel.com, ogawa.yasufumi@lab.ntt.co.jp
Subject: [spp] [PATCH 2/5] controller: refactor pri launch command
Date: Mon,  4 Feb 2019 12:11:58 +0900	[thread overview]
Message-ID: <1549249921-31638-3-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> (raw)
In-Reply-To: <1549249921-31638-1-git-send-email-ogawa.yasufumi@lab.ntt.co.jp>

From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>

This patch is to move variables related to launch command from Shell
class to SppPrimary because these vars are used only in SppPrimary
actually.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/controller/commands/pri.py | 58 ++++++++++++++++++++++++++++++++++--------
 src/controller/shell.py        | 17 ++++---------
 2 files changed, 53 insertions(+), 22 deletions(-)

diff --git a/src/controller/commands/pri.py b/src/controller/commands/pri.py
index b03524b..aa78cef 100644
--- a/src/controller/commands/pri.py
+++ b/src/controller/commands/pri.py
@@ -6,7 +6,6 @@ from __future__ import absolute_import
 from .. import spp_common
 from ..shell_lib import common
 from ..spp_common import logger
-#from .. import spp_common
 
 
 class SppPrimary(object):
@@ -25,6 +24,22 @@ class SppPrimary(object):
     def __init__(self, spp_ctl_cli):
         self.spp_ctl_cli = spp_ctl_cli
 
+        # Default args for `pri; launch`, used if given cli_config is invalid
+        self.launch_default = {
+                'mem': '-m 512',
+                'base_lcore': '1',
+                'vhost_cli': ''
+                }
+
+        # Setup template of args for `pri; launch`
+        temp = "-l __BASE_LCORE__,{} "
+        temp = temp + "__MEM__ "
+        temp = temp + "-- "
+        temp = temp + "{} {} "  # '-n 1' or '--client-id 1'
+        temp = temp + "-s {} "  # '-s 192.168.1.100:6666'
+        temp = temp + "__VHOST_CLI__"
+        self.launch_template = temp
+
     def run(self, cmd):
         """Called from do_pri() to Send command to primary process."""
 
@@ -141,7 +156,7 @@ class SppPrimary(object):
                     rports['id'], rports['rx'],  rports['tx'],
                     rports['rx_drop'], rports['tx_drop']))
 
-    def complete(self, text, line, begidx, endidx, cli_config, template):
+    def complete(self, text, line, begidx, endidx, cli_config):
         """Completion for primary process commands.
 
         Called from complete_pri() to complete primary command.
@@ -150,13 +165,7 @@ class SppPrimary(object):
         candidates = []
         tokens = line.split(' ')
 
-        template = template.replace('__MEM__', cli_config['sec_mem']['val'])
-        template = template.replace('__BASE_LCORE__', cli_config['sec_base_lcore']['val'])
-        if cli_config['sec_vhost_cli']['val']:
-            template = template.replace('__VHOST_CLI__', '--vhost-client')
-        else:
-            template = template.replace('__VHOST_CLI__', '')
-
+        # Parse command line
         if tokens[0].endswith(';'):
 
             # Show sub commands
@@ -199,7 +208,10 @@ class SppPrimary(object):
                     elif ptype == 'pcap':  # at least two cores
                         rest_core = '{}-{}'.format(int(sid), int(sid)+1)
 
-                    candidates = [template.format(
+                    temp = self._setup_launch_template(
+                            cli_config, self.launch_template,
+                            self.launch_default)
+                    candidates = [temp.format(
                         rest_core, opt_sid, sid, server_addr)]
 
         if not text:
@@ -211,6 +223,32 @@ class SppPrimary(object):
 
         return completions
 
+    def _setup_launch_template(self, cli_config, template, defaults):
+        """Check given `cli_config` for params of launch."""
+
+        if 'sec_mem' in cli_config.keys():
+            sec_mem = cli_config['sec_mem']['val']
+        else:
+            sec_mem = defaults['mem']
+        template = template.replace('__MEM__', sec_mem)
+
+        if 'sec_base_lcore' in cli_config.keys():
+            sec_base_lcore = cli_config['sec_base_lcore']['val']
+        else:
+            sec_base_lcore = defaults['base_lcore']
+        template = template.replace('__BASE_LCORE__', sec_base_lcore)
+
+        if 'sec_vhost_cli' in cli_config.keys():
+            if cli_config['sec_vhost_cli']['val']:
+                vhost_client = '--vhost-client'
+            else:
+                vhost_client = ''
+        else:
+            vhost_client = defaults['vhost_cli']
+        template = template.replace('__VHOST_CLI__', vhost_client)
+
+        return template
+
     def _get_sec_ids(self):
         sec_ids = []
         res = self.spp_ctl_cli.get('processes')
diff --git a/src/controller/shell.py b/src/controller/shell.py
index 8cf10e6..78795f7 100644
--- a/src/controller/shell.py
+++ b/src/controller/shell.py
@@ -30,7 +30,7 @@ class Shell(cmd.Cmd, object):
             'topo_size': {
                 'val': '60%', 'desc': 'Percentage or ratio of topo'},
             'sec_mem': {
-                'val':'-m 512', 'desc': 'Mem size'},
+                'val': '-m 512', 'desc': 'Mem size'},
             'sec_base_lcore': {
                 'val': '1', 'desc': 'Shared lcore among secondaryes'},
             'sec_vf_nof_lcores': {
@@ -39,14 +39,6 @@ class Shell(cmd.Cmd, object):
                 'val': '', 'desc': 'Vhost client mode'},
             }
 
-    # Setup template of `pri; launch`
-    template = "-l __BASE_LCORE__,{} "
-    template = template + "__MEM__ "
-    template = template + "-- "
-    template = template + "{} {} "  # '-n 1' or '--client-id 1'
-    template = template + "-s {} "  # '-s 192.168.1.100:6666'
-    template = template + "__VHOST_CLI__"
-
     hist_file = os.path.expanduser('~/.spp_history')
     PLUGIN_DIR = 'plugins'
 
@@ -358,8 +350,9 @@ class Shell(cmd.Cmd, object):
         """Completion for primary process commands."""
 
         line = re.sub(r'\s+', " ", line)
-        return self.primary.complete(text, line, begidx, endidx,
-                self.cli_config, self.template)
+        return self.primary.complete(
+                text, line, begidx, endidx,
+                self.cli_config)
 
     def do_nfv(self, cmd):
         """Send a command to spp_nfv specified with ID.
@@ -660,7 +653,7 @@ class Shell(cmd.Cmd, object):
         if len(tokens) == 1:
             key = tokens[0]
             if key == '':
-                for k,v in self.cli_config.items():
+                for k, v in self.cli_config.items():
                     print('- {}: "{}"\t# {}'.format(k, v['val'], v['desc']))
             elif key in self.cli_config.keys():
                 print('- {}: "{}"\t# {}'.format(
-- 
2.7.4

  parent reply	other threads:[~2019-02-04  3:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-04  3:11 [spp] [PATCH 0/5] Add config command ogawa.yasufumi
2019-02-04  3:11 ` [spp] [PATCH 1/5] controller: add " ogawa.yasufumi
2019-02-04  3:11 ` ogawa.yasufumi [this message]
2019-02-04  3:11 ` [spp] [PATCH 3/5] controller: remove nouse check_sec_cmds ogawa.yasufumi
2019-02-04  3:12 ` [spp] [PATCH 4/5] controller: add max_secondary to config ogawa.yasufumi
2019-02-04  3:12 ` [spp] [PATCH 5/5] controller: change nof worker lcores configurable ogawa.yasufumi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1549249921-31638-3-git-send-email-ogawa.yasufumi@lab.ntt.co.jp \
    --to=ogawa.yasufumi@lab.ntt.co.jp \
    --cc=ferruh.yigit@intel.com \
    --cc=spp@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).