From: ogawa.yasufumi@lab.ntt.co.jp
To: ferruh.yigit@intel.com, spp@dpdk.org, ogawa.yasufumi@lab.ntt.co.jp
Subject: [spp] [PATCH v2 4/4] controller: update for parsing JSON status
Date: Fri, 5 Oct 2018 14:06:30 +0900 [thread overview]
Message-ID: <20181005050630.10661-5-ogawa.yasufumi@lab.ntt.co.jp> (raw)
In-Reply-To: <20181005050630.10661-1-ogawa.yasufumi@lab.ntt.co.jp>
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
Because the response of status of spp_nfv and spp_vm is changed to
JSON format, update for parsing the JSON format.
Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
src/controller/shell.py | 61 +++++++++++++++++++++----------------------------
1 file changed, 26 insertions(+), 35 deletions(-)
diff --git a/src/controller/shell.py b/src/controller/shell.py
index fb30d5d..5da48c6 100644
--- a/src/controller/shell.py
+++ b/src/controller/shell.py
@@ -152,47 +152,38 @@ class Shell(cmd.Cmd, object):
rports['rx_drop'], rports['tx_drop']))
def print_sec_status(self, msg):
- """Parse and print message from SPP secondary
+ """Parse and print message from SPP secondary.
- The format of sent message is expected as YAML like format as
+ Print status received from secondary.
- status: idling\nports: 'phy:0-phy:1,phy:1-null'\x00\x00..
+ spp > sec 1;status
+ - status: idling
+ - ports:
+ - phy:0 -> ring:0
+ - phy:1
- '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
+ The format of the received message is JSON and ended with
+ series of null character "\x00". The value of "ports" attribute
+ is a set of combinations of patches. If a port is not patched,
+ the "dst" is set to "null".
- status = sec_attr[0]
- ports = sec_attr[1]
+ {"status":"idling","ports":[{"src":"phy:0", "dst": ...,]}'\x00\x00..
+ """
- # Printed result to which port info is appended.
- res = status
+ msg = msg.replace("\x00", "") # clean sec's msg
- 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)
-
- print(res)
+ try:
+ sec_attr = json.loads(msg)
+ print('- status: %s' % sec_attr['status'])
+ print('- ports:')
+ for port in sec_attr['ports']:
+ if port['dst'] == 'null':
+ print(' - %s' % port['src'])
+ else:
+ print(' - %s -> %s' % (port['src'], port['dst']))
+ except ValueError as err:
+ print('Invalid format: {0}.'.format(err))
+ print(" '%s'" % msg)
def command_primary(self, command):
"""Send command to primary process"""
--
2.7.4
prev parent reply other threads:[~2018-10-05 5:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20181004055918.5922-1-ogawa.yasufumi@lab.ntt.co.j>
2018-10-05 5:06 ` [spp] [PATCH v2 0/4] Change format of sec status to JSON ogawa.yasufumi
2018-10-05 5:06 ` [spp] [PATCH v2 1/4] shared: change sec status to JSON format ogawa.yasufumi
2018-10-05 5:06 ` [spp] [PATCH v2 2/4] spp_nfv: update retrieving status ogawa.yasufumi
2018-10-05 5:06 ` [spp] [PATCH v2 3/4] spp_vm: " ogawa.yasufumi
2018-10-05 5:06 ` 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=20181005050630.10661-5-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).