Soft Patch Panel
 help / color / mirror / Atom feed
From: ogawa.yasufumi@lab.ntt.co.jp
To: spp@dpdk.org, ferruh.yigit@intel.com
Cc: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
Subject: [spp] [PATCH 8/9] controller: update topo command
Date: Mon, 12 Mar 2018 14:35:23 +0900	[thread overview]
Message-ID: <1520832924-28387-9-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> (raw)
In-Reply-To: <1520832924-28387-1-git-send-email-ogawa.yasufumi@lab.ntt.co.jp>

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

Update topo and topo_subgraph commands for parsing port status which
is changed for 18.02.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/controller/shell.py | 50 +++++++++++++++++++++++++++++++++++++------------
 src/controller/topo.py  |  9 +++++++++
 2 files changed, 47 insertions(+), 12 deletions(-)

diff --git a/src/controller/shell.py b/src/controller/shell.py
index c379c2a..ea5e8a9 100644
--- a/src/controller/shell.py
+++ b/src/controller/shell.py
@@ -89,20 +89,46 @@ class Shell(cmd.Cmd, object):
             print ("Connected secondary id: %d" % i)
 
     def print_sec_status(self, msg):
-        msg = msg.replace("\x00", "")  # remove null chars in msg from sec
-        status, ports = msg.split("\n")
-        res = "%s\nports:\n" % status
+        """Parse and print message from SPP secondary
+
+        The format of sent message is expected as YAML like format as
+
+        status: idling\nports: 'phy:0-phy:1,phy:1-null'\x00\x00..
+
+        'ports' is a set of combinations of patches. The value is
+        encapsulated with "'" and ended series of null character "\x00".
+        If the destination is not defined, null is assigned.
+        """
+
+        msg = msg.replace("\x00", "").replace("'", "")  # clean sec's msg
+        sec_attr = msg.split("\n")
+
+        # Do nothing if returned msg is not valid format.
+        if len(sec_attr) < 2:
+            return None
+
+        status = sec_attr[0]
+        ports = sec_attr[1]
+
+        # Printed result to which port info is appended.
+        res = status
+
         port_list = ports.split(' ')[1].split(',')
+        if port_list[0] == '':  # port_list is [''] if there are no ports
+            res = '%s\nports: "no ports"' % res
+        else:
+            res = "%s\nports:\n" % res
+            tmp_list = []
+            for port_ent in port_list:
+                if '-' in port_ent:
+                    p1, p2 = port_ent.split('-')
+                    if p2 == 'null':
+                        tmp_list.append("  - '%s'" % p1)
+                    else:
+                        tmp_list.append("  - '%s -> %s'" % (p1, p2))
+            tmp_list.sort()
+            res += "\n".join(tmp_list)
 
-        tmp = []
-        for p in port_list:
-            p1, p2 = p.split('-')
-            if p2 == 'null':
-                tmp.append("  - '%s'" % p1)
-            else:
-                tmp.append("  - '%s -> %s'" % (p1, p2))
-        tmp.sort()
-        res += "\n".join(tmp)
         print(res)
 
     def command_primary(self, command):
diff --git a/src/controller/topo.py b/src/controller/topo.py
index 0fc529b..76dd54f 100644
--- a/src/controller/topo.py
+++ b/src/controller/topo.py
@@ -96,6 +96,8 @@ class Topo(object):
 
         # parse status message from sec.
         for sec in sec_list:
+            if sec is None:
+                continue
             for port in sec["ports"]:
                 if port["iface"]["type"] == "phy":
                     phys.append(port)
@@ -313,6 +315,10 @@ class Topo(object):
         }
         """
 
+        # Clean sec stat message
+        stat = stat.replace("\x00", "")
+        stat = stat.replace("'", "")
+
         stat_obj = yaml.load(stat)
         res = {}
         res['sec_id'] = sec_id
@@ -320,6 +326,9 @@ class Topo(object):
 
         port_list = []
         try:
+            if stat_obj['ports'] is None:
+                return None
+
             ports = stat_obj['ports'].split(',')
             for port_info in ports:
                 rid, outport = port_info.split('-')
-- 
2.7.4

  parent reply	other threads:[~2018-03-12  5:35 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-01  9:28 [spp] Port ID incrementation is changed from DPDK18.02 Yasufumi Ogawa
2018-03-12  5:35 ` [spp] [PATCH 0/9] Update port management ogawa.yasufumi
2018-03-12  5:35   ` [spp] [PATCH 1/9] controller: change displaying status ogawa.yasufumi
2018-03-12  5:35   ` [spp] [PATCH 2/9] shared: update print_active_ports ogawa.yasufumi
2018-03-12  5:35   ` [spp] [PATCH 3/9] spp_nfv: change format displaying status ogawa.yasufumi
2018-03-12  5:35   ` [spp] [PATCH 4/9] spp_vm: " ogawa.yasufumi
2018-03-12  5:35   ` [spp] [PATCH 5/9] controller: add delimiter for topo command ogawa.yasufumi
2018-03-12  5:35   ` [spp] [PATCH 6/9] controller: update Shell for topo_subgraph ogawa.yasufumi
2018-03-12  5:35   ` [spp] [PATCH 7/9] controller: update generating graph ogawa.yasufumi
2018-03-12  5:35   ` ogawa.yasufumi [this message]
2018-03-12  5:35   ` [spp] [PATCH 9/9] shared: fix bug for print port status ogawa.yasufumi
2018-03-27 23:51   ` [spp] [PATCH 0/9] Update port management Ferruh Yigit

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=1520832924-28387-9-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).