Soft Patch Panel
 help / color / mirror / Atom feed
From: oda@valinux.co.jp
To: spp@dpdk.org, ferruh.yigit@intel.com, ogawa.yasufumi@lab.ntt.co.jp
Subject: [spp] [PATCH v4 10/14] spp-ctl: update parsing spp_nfv status
Date: Fri,  5 Oct 2018 12:57:53 +0900	[thread overview]
Message-ID: <20181005035757.23122-11-oda@valinux.co.jp> (raw)
In-Reply-To: <20181005035757.23122-1-oda@valinux.co.jp>

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

Update for parsing the result of status of spp_nfv.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
Signed-off-by: Itsuro Oda <oda@valinux.co.jp>
---
 src/spp-ctl/spp_webapi.py | 66 +++++++++++++++++----------------------
 1 file changed, 28 insertions(+), 38 deletions(-)

diff --git a/src/spp-ctl/spp_webapi.py b/src/spp-ctl/spp_webapi.py
index 435c4b7..ee47f2f 100644
--- a/src/spp-ctl/spp_webapi.py
+++ b/src/spp-ctl/spp_webapi.py
@@ -318,50 +318,40 @@ class V1NFVHandler(BaseHandler):
         self.route('/<sec_id:int>/patches', 'DELETE',
                    callback=self.nfv_patch_del)
 
-    def convert_nfv_info(self, data):
+    def convert_nfv_info(self, sec_id, data):
         nfv = {}
-        lines = data.splitlines()
-        if len(lines) < 3:
+
+        # spp_nfv returns status info in two lines. First line is
+        # status of running or idling, and second is patch info.
+        # 'null' means that it has no dst port.
+        #   "status: idling\nports: 'phy:0-phy:1,phy:1-null'\x00\x00.."
+        entries = data.split('\n')
+        if len(entries) != 2:
             return {}
-        p = re.compile("Client ID (\d+) (\w+)")
-        m = p.match(lines[0])
-        if m:
-            nfv['client_id'] = int(m.group(1))
-            nfv['status'] = m.group(2)
-
-        ports = {}
-        outs = []
-        for line in lines[2:]:
-            if not line.startswith("port_id"):
-                break
-            arg1, _, arg2, arg3 = line.split(",")
-            _, port_id = arg1.split(":")
-            if arg2 == "PHY":
-                port = "phy:" + port_id
-            else:
-                if_type, rest = arg2.split("(")
-                if_num = rest.rstrip(")")
-                if if_type == "RING":
-                    port = "ring:" + if_num
-                elif if_type == "VHOST":
-                    port = "vhost:" + if_num
-                else:
-                    port = if_type + ":" + if_num
-            ports[port_id] = port
-            _, out_id = arg3.split(":")
-            if out_id != "none":
-                outs.append((port_id, out_id))
-        nfv['ports'] = list(ports.values())
-        patches = []
-        if outs:
-            for src_id, dst_id in outs:
-                patches.append({"src": ports[src_id], "dst": ports[dst_id]})
-        nfv['patches'] = patches
+
+        nfv['client_id'] = int(sec_id)
+        nfv['status'] = entries[0].split()[1]
+
+        patch_list = entries[1].split()[1].replace("'", '')
+
+        ports = []
+        nfv['patches'] = []
+
+        for port_cmb in patch_list.split(','):
+            p_src, p_dst = port_cmb.split('-')
+            if p_src != 'null' and p_dst != 'null':
+                nfv['patches'].append({'src': p_src, 'dst': p_dst})
+
+            for port in [p_src, p_dst]:
+                if port != 'null':
+                    ports.append(port)
+
+        nfv['ports'] = list(set(ports))
 
         return nfv
 
     def nfv_get(self, proc):
-        return self.convert_nfv_info(proc.get_status())
+        return self.convert_nfv_info(proc.id, proc.get_status())
 
     def _validate_nfv_forward(self, body):
         if 'action' not in body:
-- 
2.17.1

  parent reply	other threads:[~2018-10-05  3:58 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-12 23:25 [spp] [PATCH] spp-ctl: SPP controller with Web API Itsuro ODA
2018-09-18 10:00 ` Yasufumi Ogawa
2018-09-18 21:40   ` Itsuro ODA
2018-10-05  1:37 ` [spp] [PATCH v3 00/13] " oda
2018-10-05  1:37   ` [spp] [PATCH v3 01/13] docs: add overview of spp-ctl oda
2018-10-05  1:37   ` [spp] [PATCH v3 02/13] docs: add API reference " oda
2018-10-05  1:37   ` [spp] [PATCH v3 03/13] docs: add index " oda
2018-10-05  1:37   ` [spp] [PATCH v3 04/13] project: add requirements.txt for spp-ctl oda
2018-10-05  1:37   ` [spp] [PATCH v3 05/13] docs: add spp-ctl to index of doc root oda
2018-10-05  1:37   ` [spp] [PATCH v3 06/13] spp-ctl: add entry point oda
2018-10-05  1:37   ` [spp] [PATCH v3 07/13] spp-ctl: add Controller class oda
2018-10-05  1:37   ` [spp] [PATCH v3 08/13] spp-ctl: add web API handler oda
2018-10-05  1:37   ` [spp] [PATCH v3 09/13] spp-ctl: add spp command interfaces oda
2018-10-05  1:37   ` [spp] [PATCH v3 10/13] spp-ctl: update parsing spp_nfv status oda
2018-10-05  1:37   ` [spp] [PATCH v3 11/13] docs: add request examples of spp-ctl oda
2018-10-05  1:37   ` [spp] [PATCH v3 12/13] docs: correct directives " oda
2018-10-05  1:37   ` [spp] [PATCH v3 13/13] docs: add labels and captions for tables oda
2018-10-05  3:57 ` [spp] [PATCH v4 00/14] spp-ctl: SPP controller with Web API oda
2018-10-05  3:57   ` [spp] [PATCH v4 01/14] docs: add overview of spp-ctl oda
2018-10-05  3:57   ` [spp] [PATCH v4 02/14] docs: add API reference " oda
2018-10-05  3:57   ` [spp] [PATCH v4 03/14] docs: add index " oda
2018-10-05  3:57   ` [spp] [PATCH v4 04/14] project: add requirements.txt for spp-ctl oda
2018-10-05  3:57   ` [spp] [PATCH v4 05/14] docs: add spp-ctl to index of doc root oda
2018-10-05  3:57   ` [spp] [PATCH v4 06/14] spp-ctl: add entry point oda
2018-10-05  3:57   ` [spp] [PATCH v4 07/14] spp-ctl: add Controller class oda
2018-10-05  3:57   ` [spp] [PATCH v4 08/14] spp-ctl: add web API handler oda
2018-10-05  3:57   ` [spp] [PATCH v4 09/14] spp-ctl: add spp command interfaces oda
2018-10-05  3:57   ` oda [this message]
2018-10-05  3:57   ` [spp] [PATCH v4 11/14] docs: add request examples of spp-ctl oda
2018-10-05  3:57   ` [spp] [PATCH v4 12/14] docs: correct directives " oda
2018-10-05  3:57   ` [spp] [PATCH v4 13/14] docs: add labels and captions for tables oda
2018-10-05  3:57   ` [spp] [PATCH v4 14/14] spp-ctl: fix incorrect URL oda
2018-10-09  2:01   ` [spp] [PATCH v4 00/14] spp-ctl: SPP controller with Web API Yasufumi Ogawa

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=20181005035757.23122-11-oda@valinux.co.jp \
    --to=oda@valinux.co.jp \
    --cc=ferruh.yigit@intel.com \
    --cc=ogawa.yasufumi@lab.ntt.co.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).