From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from tama500.ecl.ntt.co.jp (tama500.ecl.ntt.co.jp [129.60.39.148]) by dpdk.org (Postfix) with ESMTP id 3412C5F12 for ; Fri, 5 Oct 2018 07:06:41 +0200 (CEST) Received: from vc1.ecl.ntt.co.jp (vc1.ecl.ntt.co.jp [129.60.86.153]) by tama500.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id w9556fZO017219; Fri, 5 Oct 2018 14:06:41 +0900 Received: from vc1.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id 03C9BEA880F; Fri, 5 Oct 2018 14:06:41 +0900 (JST) Received: from localhost.localdomain (unknown [129.60.13.51]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id DAC71EA880D; Fri, 5 Oct 2018 14:06:40 +0900 (JST) From: ogawa.yasufumi@lab.ntt.co.jp To: ferruh.yigit@intel.com, spp@dpdk.org, ogawa.yasufumi@lab.ntt.co.jp Date: Fri, 5 Oct 2018 14:06:30 +0900 Message-Id: <20181005050630.10661-5-ogawa.yasufumi@lab.ntt.co.jp> X-Mailer: git-send-email 2.13.1 In-Reply-To: <20181005050630.10661-1-ogawa.yasufumi@lab.ntt.co.jp> References: <20181004055918.5922-1-ogawa.yasufumi@lab.ntt.co.j> <20181005050630.10661-1-ogawa.yasufumi@lab.ntt.co.jp> X-TM-AS-MML: disable Subject: [spp] [PATCH v2 4/4] controller: update for parsing JSON status X-BeenThere: spp@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Soft Patch Panel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Oct 2018 05:06:42 -0000 From: Yasufumi Ogawa 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 --- 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