Soft Patch Panel
 help / color / mirror / Atom feed
From: ogawa.yasufumi@lab.ntt.co.jp
To: ferruh.yigit@intel.com, spp@dpdk.org
Cc: "ogawa.yasufumi@lab.ntt.co.jp" <ogawa.yasufumi@lab.ntt.co.jp>
Subject: [spp] [PATCH 2/3] spp: add validation for patch command
Date: Fri,  9 Feb 2018 00:17:51 +0900	[thread overview]
Message-ID: <1518103072-4559-2-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> (raw)
In-Reply-To: <1518103072-4559-1-git-send-email-ogawa.yasufumi@lab.ntt.co.jp>

From: "ogawa.yasufumi@lab.ntt.co.jp" <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 20eb59f..3796670 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', 'pcap', 'nullpmd']
@@ -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

  reply	other threads:[~2018-02-08 15:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-08 15:17 [spp] [PATCH 1/3] spp_nfv: enable to patch ports with resource ID ogawa.yasufumi
2018-02-08 15:17 ` ogawa.yasufumi [this message]
2018-02-08 15:17 ` [spp] [PATCH 3/3] spp_vm: " ogawa.yasufumi
2018-02-22 10:52 ` [spp] [PATCH 1/3] spp_nfv: " Ferruh Yigit
  -- strict thread matches above, loose matches on Subject: below --
2018-01-29 12:44 ogawa.yasufumi
2018-01-29 12:46 ` [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=1518103072-4559-2-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).