Soft Patch Panel
 help / color / mirror / Atom feed
From: ogawa.yasufumi@lab.ntt.co.jp
To: ferruh.yigit@intel.com, spp@dpdk.org, ogawa.yasufumi@lab.ntt.co.jp
Subject: [spp] [PATCH 2/5] controller: change to exclude used port from del
Date: Wed, 12 Dec 2018 11:03:12 +0900	[thread overview]
Message-ID: <1544580195-9242-3-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> (raw)
In-Reply-To: <1544580195-9242-1-git-send-email-ogawa.yasufumi@lab.ntt.co.jp>

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

In completion of `del`, exclude ports already used.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/controller/commands/nfv.py | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/src/controller/commands/nfv.py b/src/controller/commands/nfv.py
index 9af4449..7a8d073 100644
--- a/src/controller/commands/nfv.py
+++ b/src/controller/commands/nfv.py
@@ -248,19 +248,33 @@ class SppNfv(object):
             return res
 
     def _compl_del(self, sub_tokens):
+        # Del command consists of two tokens max, for instance,
+        # `nfv 1; del ring:1`.
         if len(sub_tokens) < 3:
             res = []
 
             if self.use_cache is False:
                 self.ports = self.get_registered_ports()
+                self.patches = self.get_registered_patches()
 
-            for kw in self.ports:
-                if kw.startswith(sub_tokens[1]):
-                    if ':' in sub_tokens[1]:  # exp, 'ring:' or 'ring:0'
-                        res.append(kw.split(':')[1])
-                    else:
-                        res.append(kw)
+            # Used ports should not be included in the candidate of del.
+            used_ports = []
+            for pt in self.ports:
+                for ppt in self.patches:
+                    if ((pt in ppt['src']) or (pt in ppt['dst'])):
+                            used_ports.append(pt)
+            used_ports = list(set(used_ports))
 
+            # Remove ports already used from candidate.
+            for kw in self.ports:
+                if not (kw in used_ports):
+                    if kw.startswith(sub_tokens[1]):
+                        if ':' in sub_tokens[1]:  # exp, 'ring:' or 'ring:0'
+                            res.append(kw.split(':')[1])
+                        else:
+                            res.append(kw)
+
+            # Physical port cannot be removed.
             for p in res:
                 if p.startswith('phy:'):
                     res.remove(p)
-- 
2.7.4

  parent reply	other threads:[~2018-12-12  2:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-12  2:03 [spp] [PATCH 0/5] update SPP CLI ogawa.yasufumi
2018-12-12  2:03 ` [spp] [PATCH 1/5] controller: change sec command to nfv ogawa.yasufumi
2018-12-12  2:03 ` ogawa.yasufumi [this message]
2018-12-12  2:03 ` [spp] [PATCH 3/5] controller: add checking for add and del cmds ogawa.yasufumi
2018-12-12  2:03 ` [spp] [PATCH 4/5] controller: refactor SppNfv class ogawa.yasufumi
2018-12-12  2:03 ` [spp] [PATCH 5/5] controller: update SppBye class 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=1544580195-9242-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).