Soft Patch Panel
 help / color / mirror / Atom feed
From: yasufum.o@gmail.com
To: spp@dpdk.org, ferruh.yigit@intel.com, yasufum.o@gmail.com
Subject: [spp] [PATCH] cli: update status message for pri
Date: Thu, 17 Oct 2019 21:58:11 +0900	[thread overview]
Message-ID: <20191017125811.29253-1-yasufum.o@gmail.com> (raw)

From: Yasufumi Ogawa <yasufum.o@gmail.com>

Add status message of slave forwarder in `status` command.

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 src/cli/commands/pri.py | 107 ++++++++++++++++++++++++++++------------
 1 file changed, 75 insertions(+), 32 deletions(-)

diff --git a/src/cli/commands/pri.py b/src/cli/commands/pri.py
index c711c72..021f322 100644
--- a/src/cli/commands/pri.py
+++ b/src/cli/commands/pri.py
@@ -111,7 +111,9 @@ class SppPrimary(object):
         long.
 
             {
-                "lcores": [0, 3],
+                "master-lcore": 0,
+                "lcores": [0,1],
+                "forwarder" {...},   # exists if slave thread is running
                 "phy_ports": [
                     {
                         "eth": "56:48:4f:12:34:00",
@@ -136,39 +138,80 @@ class SppPrimary(object):
 
         It is formatted to be simple and more understandable.
 
-            - lcores:
-                [0, 3]
-            - 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     tx_drop
-                 0       89283       89283           0           0
-                 ...
+            - lcore_ids:
+                - master: 0
+                - slave: 1
+            - forwarder:
+              - status: running
+              - ports:
+                - phy:0 -> phy:1
+                - phy:1
+            - stats
+              - 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     tx_drop
+                   0       89283       89283           0           0
+                   ...
         """
 
-        if 'lcores' in json_obj:
-            print('- lcores:')
-            print('  - {}'.format(json_obj['lcores']))
-
-        if 'phy_ports' in json_obj:
-            print('- physical ports:')
-            print('    ID          rx          tx     tx_drop  mac_addr')
-
-            temp = '    {portid:2}  {rx:10}  {tx:10}  {tx_drop:10}  {eth}'
-            for pports in json_obj['phy_ports']:
-                print(temp.format(
-                    portid=pports['id'], rx=pports['rx'], tx=pports['tx'],
-                    tx_drop=pports['tx_drop'], eth=pports['eth']))
-
-        if 'ring_ports' in json_obj:
-            print('- ring ports:')
-            print('    ID          rx          tx     rx_drop     tx_drop')
-            temp = '    {rid:2}  {rx:10}  {tx:10}  {rx_drop:10}  {tx_drop:10}'
-            for rports in json_obj['ring_ports']:
-                print(temp.format(
-                    rid=rports['id'], rx=rports['rx'], tx=rports['tx'],
-                    rx_drop=rports['rx_drop'], tx_drop=rports['tx_drop']))
+        try:
+            if 'lcores' in json_obj:
+                print('- lcore_ids:')
+                print('  - master: {}'.format(json_obj['lcores'][0]))
+                if len(json_obj['lcores']) > 1:
+                    if len(json_obj['lcores']) == 2:
+                        print('  - slave: {}'.format(json_obj['lcores'][1]))
+                    else:
+                        lcores = ', '.join([str(i)
+                            for i in json_obj['lcores'][1:]])
+                        print('  - slaves: [{}]'.format(lcores))
+
+            sep = ' '
+            if 'forwarder' in json_obj:
+                print('- forwarder:')
+                print('  - status: {}'.format(json_obj['forwarder']['status']))
+
+                print('  - ports:')
+                for port in json_obj['forwarder']['ports']:
+                    dst = None
+                    for patch in json_obj['forwarder']['patches']:
+                        if patch['src'] == port:
+                            dst = patch['dst']
+
+                    if dst is None:
+                        print('    - {}'.format(port))
+                    else:
+                        print('    - {} -> {}'.format(port, dst))
+
+            if ('phy_ports' in json_obj) or ('ring_ports' in json_obj):
+                print('- stats')
+
+            if 'phy_ports' in json_obj:
+                print('  - physical ports:')
+                print('{s6}ID{s10}rx{s10}tx{s4}tx_drop  mac_addr'.format(
+                      s4=sep*4, s6=sep*6, s10=sep*10))
+
+                temp = '{s6}{portid:2}  {rx:10}  {tx:10}  {tx_d:10}  {eth}'
+                for pports in json_obj['phy_ports']:
+                    print(temp.format(s6=sep*6,
+                        portid=pports['id'], rx=pports['rx'], tx=pports['tx'],
+                        tx_d=pports['tx_drop'], eth=pports['eth']))
+
+            if 'ring_ports' in json_obj:
+                print('  - ring ports:')
+                print('{s6}ID{s10}rx{s10}tx{s5}rx_drop{s5}tx_drop'.format(
+                      s6=sep*6, s5=sep*5, s10=sep*10))
+                temp = '{s6}{rid:2}  {rx:10}  {tx:10}  {rx_d:10}  {tx_d:10}'
+                for rports in json_obj['ring_ports']:
+                    print(temp.format(s6=sep*6,
+                        rid=rports['id'], rx=rports['rx'], tx=rports['tx'],
+                        rx_d=rports['rx_drop'], tx_d=rports['tx_drop']))
+
+        except KeyError as e:
+            logger.error('{} is not defined!'.format(e))
 
     # TODO(yasufum) make methods start with '_get' to be shared
     # because it is similar to nfv. _get_ports(self) is changed as
-- 
2.17.1


                 reply	other threads:[~2019-10-17 12:58 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20191017125811.29253-1-yasufum.o@gmail.com \
    --to=yasufum.o@gmail.com \
    --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).