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 5/5] controller: simply print primary status
Date: Mon,  1 Oct 2018 12:14:13 +0900	[thread overview]
Message-ID: <20181001031413.75652-6-ogawa.yasufumi@lab.ntt.co.jp> (raw)
In-Reply-To: <20181001031413.75652-1-ogawa.yasufumi@lab.ntt.co.jp>

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

Change printing primary status of law JSON format to be more intuitive.
Here is an example.

  Physical Ports:
    ID          rx          tx     tx_drop  mac_addr
     0    78932932    78932931           1  56:48:4f:53:54:00
  Ring Ports:
    ID          rx          tx     rx_drop     rx_drop
     0       89283       89283           0           0
               ...
Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/controller/shell.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 60 insertions(+), 1 deletion(-)

diff --git a/src/controller/shell.py b/src/controller/shell.py
index 3497073..fb30d5d 100644
--- a/src/controller/shell.py
+++ b/src/controller/shell.py
@@ -95,6 +95,62 @@ class Shell(cmd.Cmd, object):
         for i in spp_common.SECONDARY_LIST:
             print("Connected secondary id: %d" % i)
 
+    def print_pri_status(self, json_obj):
+        """Parse SPP primary's status and print.
+
+        Primary returns the status as JSON format, but it is just a little
+        long.
+
+            {
+                "phy_ports": [
+                    {
+                        "eth": "56:48:4f:12:34:00",
+                        "id": 0,
+                        "rx": 78932932,
+                        "tx": 78932931,
+                        "tx_drop": 1,
+                    }
+                    ...
+                ],
+                "ring_ports": [
+                    {
+                        "id": 0,
+                        "rx": 89283,
+                        "rx_drop": 0,
+                        "tx": 89283,
+                        "tx_drop": 0
+                    },
+                    ...
+                ]
+            }
+
+        It is formatted to be simple and more understandable.
+
+            Physical Ports:
+              ID          rx          tx     tx_drop  mac_addr
+               0    78932932    78932931           1  56:48:4f:53:54:00
+            Ring Ports:
+              ID          rx          tx     rx_drop     rx_drop
+               0       89283       89283           0           0
+               ...
+        """
+
+        if json_obj.has_key('phy_ports'):
+            print('Physical Ports:')
+            print('  ID          rx          tx     tx_drop  mac_addr')
+            for pports in json_obj['phy_ports']:
+                print('  %2d  %10d  %10d  %10d  %s' % (
+                    pports['id'], pports['rx'],  pports['tx'],
+                    pports['tx_drop'], pports['eth']))
+
+        if json_obj.has_key('ring_ports'):
+            print('Ring Ports:')
+            print('  ID          rx          tx     rx_drop     rx_drop')
+            for rports in json_obj['ring_ports']:
+                print('  %2d  %10d  %10d  %10d  %10d' % (
+                    rports['id'], rports['rx'],  rports['tx'],
+                    rports['rx_drop'], rports['tx_drop']))
+
     def print_sec_status(self, msg):
         """Parse and print message from SPP secondary
 
@@ -144,7 +200,8 @@ class Shell(cmd.Cmd, object):
         if spp_common.PRIMARY:
             spp_common.MAIN2PRIMARY.put(command.encode('utf-8'))
             recv = spp_common.PRIMARY2MAIN.get(True)
-            print(recv)
+            json_obj = json.loads(recv)
+            self.print_pri_status(json_obj)
             return self.CMD_OK, recv
         else:
             recv = "primary not started"
@@ -508,7 +565,9 @@ class Shell(cmd.Cmd, object):
         if cmds[0] == 'sec':
             self.close_all_secondary()
         elif cmds[0] == 'all':
+            print('Closing secondary ...')
             self.close_all_secondary()
+            print('Closing primary ...')
             self.command_primary('exit')
         elif cmds[0] == '':
             print('Thank you for using Soft Patch Panel')
-- 
2.7.4

      parent reply	other threads:[~2018-10-01  3:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-01  3:14 [spp] [PATCH 0/5] Change primary status command to be detailed ogawa.yasufumi
2018-10-01  3:14 ` [spp] [PATCH 1/5] shared: change socket buffer length ogawa.yasufumi
2018-10-01  3:14 ` [spp] [PATCH 2/5] controller: " ogawa.yasufumi
2018-10-01  3:14 ` [spp] [PATCH 3/5] primary: change status command detailed ogawa.yasufumi
2018-10-01  3:14 ` [spp] [PATCH 4/5] controller: change msg format in ConnectionThread ogawa.yasufumi
2018-10-01  3:14 ` ogawa.yasufumi [this message]

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=20181001031413.75652-6-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).