From: ogawa.yasufumi@lab.ntt.co.jp
To: spp@dpdk.org, ferruh.yigit@intel.com, geminoa@juno.ocn.ne.jp
Cc: ogawa.yasufumi@lab.ntt.co.jp
Subject: [spp] [PATCH 2/3] spp: add validation for patch command
Date: Mon, 29 Jan 2018 21:46:50 +0900 [thread overview]
Message-ID: <20180129122506.75403-2-ogawa.yasufumi@lab.ntt.co.jp> (raw)
In-Reply-To: <20180129122506.75403-1-ogawa.yasufumi@lab.ntt.co.jp>
From: ogawa.yasufumi@lab.ntt.co.jp
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
To support patch command with port ID and resource ID, add validation
for format of ID. 'is_patched_ids_valid' method is for checking given
IDs are valid or not.
Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
src/spp.py | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/src/spp.py b/src/spp.py
index dda1452..e7ad43b 100755
--- a/src/spp.py
+++ b/src/spp.py
@@ -358,6 +358,8 @@ class Shell(cmd.Cmd):
CMD_NOTREADY = "NOTREADY"
CMD_ERROR = "ERROR"
+ PORT_TYPES = ['phy', 'ring', 'vhost']
+
PRI_CMDS = ['status', 'exit', 'clear']
SEC_CMDS = ['status', 'exit', 'forward', 'stop', 'add', 'patch', 'del']
SEC_SUBCMDS = ['vhost', 'ring']
@@ -427,6 +429,25 @@ class Shell(cmd.Cmd):
print(message)
return self.CMD_NOTREADY, message
+ def is_patched_ids_valid(self, id1, id2, delim=':'):
+ """Check if port IDs are valid
+
+ Supported format is port ID of integer or resource ID such as
+ 'phy:0' or 'ring:1'. Default delimiter ':' can be overwritten
+ by giving 'delim' option.
+ """
+
+ if str.isdigit(id1) and str.isdigit(id2):
+ return True
+ else:
+ ptn = r"\w+\%s\d+" % delim # Match "phy:0" or "ring:1" or so
+ if re.match(ptn, id1) and re.match(ptn, id2):
+ pt1 = id1.split(delim)[0]
+ pt2 = id2.split(delim)[0]
+ if (pt1 in self.PORT_TYPES) and (pt2 in self.PORT_TYPES):
+ return True
+ return False
+
def check_sec_cmds(self, cmds):
"""Validate secondary commands before sending"""
@@ -452,7 +473,7 @@ class Shell(cmd.Cmd):
if str.isdigit(cmdlist[2]):
valid = 1
elif cmdlist[0] == 'patch':
- if str.isdigit(cmdlist[1]) and str.isdigit(cmdlist[2]):
+ if self.is_patched_ids_valid(cmdlist[1], cmdlist[2]):
valid = 1
return valid
--
2.7.4
next prev parent reply other threads:[~2018-01-29 12:46 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-29 12:44 [spp] [PATCH 1/3] spp_nfv: enable to patch ports with resource ID ogawa.yasufumi
2018-01-29 12:46 ` ogawa.yasufumi [this message]
2018-01-29 12:47 ` [spp] [PATCH 3/3] spp_vm: " ogawa.yasufumi
2018-02-08 15:17 [spp] [PATCH 1/3] spp_nfv: " ogawa.yasufumi
2018-02-08 15:17 ` [spp] [PATCH 2/3] spp: add validation for patch command 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=20180129122506.75403-2-ogawa.yasufumi@lab.ntt.co.jp \
--to=ogawa.yasufumi@lab.ntt.co.jp \
--cc=ferruh.yigit@intel.com \
--cc=geminoa@juno.ocn.ne.jp \
--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).