From: yasufum.o@gmail.com
To: spp@dpdk.org, ferruh.yigit@intel.com, yasufum.o@gmail.com
Subject: [spp] [PATCH] controller: avoid launch with duplicated IDs
Date: Thu, 25 Jul 2019 20:26:12 +0900 [thread overview]
Message-ID: <20190725112612.27492-1-yasufum.o@gmail.com> (raw)
From: Yasufumi Ogawa <yasufum.o@gmail.com>
If secondary processes are launched with the same ID, it should be
uncontrollable. To avoid such a situation, this patch adds checking
secondary ID for `pri; launch` command.
Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
src/controller/commands/pri.py | 23 ++++++++++++++++++++---
src/controller/spp_common.py | 6 +++++-
2 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/src/controller/commands/pri.py b/src/controller/commands/pri.py
index eaf3d09..5ad0539 100644
--- a/src/controller/commands/pri.py
+++ b/src/controller/commands/pri.py
@@ -347,18 +347,27 @@ class SppPrimary(object):
elif len(tokens) == 4 and tokens[1] == 'launch':
if 'max_secondary' in cli_config.keys():
- max_secondary = int(cli_config['max_secondary']['val'])
+ max_secondary = int(
+ cli_config['max_secondary']['val'])
if tokens[2] in spp_common.SEC_TYPES:
+ used_ids = spp_common.used_sec_ids
candidates = [
- str(i+1) for i in range(max_secondary)]
+ str(i+1) for i in range(max_secondary)
+ if str(i+1) not in used_ids]
else:
logger.error(
'Error: max_secondary is not defined in config')
candidates = []
elif len(tokens) == 5 and tokens[1] == 'launch':
- candidates = self._setup_launch_opts(tokens, cli_config)
+ # Do not show candidate if given sec ID is already used.
+ # Sec ID is contained as the third entry in tokens. Here is an
+ # example of tokens.
+ # ['pri;', 'launch', 'nfv', '1', '']
+ if tokens[3] not in spp_common.used_sec_ids:
+ candidates = self._setup_launch_opts(
+ tokens, cli_config)
if not text:
completions = candidates
@@ -517,6 +526,12 @@ class SppPrimary(object):
else:
opts['app']['--client-id'] = sec_id
+ # Check if sec ID is already used.
+ if sec_id in spp_common.used_sec_ids:
+ print('Secondary ID {sid} is already used!'.format(
+ sid=sec_id))
+ return None
+
logger.debug('launch, {}'.format(opts))
# Send request for launch secondary.
@@ -529,6 +544,8 @@ class SppPrimary(object):
print('Send request to launch {ptype}:{sid}.'.format(
ptype=proc_type, sid=sec_id))
+ # Add used ID to avoid to launch with duplicated ID.
+ spp_common.used_sec_ids.append(sec_id)
elif res.status_code in error_codes:
pass
else:
diff --git a/src/controller/spp_common.py b/src/controller/spp_common.py
index 6bf8b1f..5ddca46 100644
--- a/src/controller/spp_common.py
+++ b/src/controller/spp_common.py
@@ -5,14 +5,18 @@
import logging
import os
+# Type definitions.
PORT_TYPES = ['phy', 'ring', 'vhost', 'pcap', 'nullpmd']
-
SEC_TYPES = ['nfv', 'vf', 'mirror', 'pcap']
LOGFILE = 'spp_cli.log' # name of logfile under `/src/controller/log/`
+# Current server under management of SPP CLI.
cur_server_addr = None
+# Entry of used secondary IDs to avoid to launch duplicated ID.
+used_sec_ids = []
+
# Setup logger object
logger = logging.getLogger(__name__)
# handler = logging.StreamHandler()
--
2.17.1
reply other threads:[~2019-07-25 11:26 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20190725112612.27492-1-yasufum.o@gmail.com \
--to=yasufum.o@gmail.com \
--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).