Soft Patch Panel
 help / color / mirror / Atom feed
* [spp] [PATCH v2 0/4] Change format of sec status to JSON
       [not found] <20181004055918.5922-1-ogawa.yasufumi@lab.ntt.co.j>
@ 2018-10-05  5:06 ` ogawa.yasufumi
  2018-10-05  5:06   ` [spp] [PATCH v2 1/4] shared: change sec status to JSON format ogawa.yasufumi
                     ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: ogawa.yasufumi @ 2018-10-05  5:06 UTC (permalink / raw)
  To: ferruh.yigit, spp, ogawa.yasufumi

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

Update the output format of the status to be more understandable.

  spp > sec 1;status
  - status: idling
  - ports:
    - phy:0 -> ring:0
    - phy:1

Yasufumi Ogawa (4):
  shared: change sec status to JSON format
  spp_nfv: update retrieving status
  spp_vm: update retrieving status
  controller: update for parsing JSON status

 src/controller/shell.py | 61 +++++++++++++++--------------------
 src/nfv/nfv.c           | 10 +++---
 src/shared/common.c     | 84 +++++++++++++++++++++++++++++--------------------
 src/shared/common.h     |  2 +-
 src/vm/main.c           | 10 +++---
 5 files changed, 87 insertions(+), 80 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [spp] [PATCH v2 1/4] shared: change sec status to JSON format
  2018-10-05  5:06 ` [spp] [PATCH v2 0/4] Change format of sec status to JSON ogawa.yasufumi
@ 2018-10-05  5:06   ` ogawa.yasufumi
  2018-10-05  5:06   ` [spp] [PATCH v2 2/4] spp_nfv: update retrieving status ogawa.yasufumi
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: ogawa.yasufumi @ 2018-10-05  5:06 UTC (permalink / raw)
  To: ferruh.yigit, spp, ogawa.yasufumi

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

Spp_nfv or spp_vm returns its status as a YAML-like format for
simplicity and requires clients to parse the response. It is better the
format to parse if it is standardized format.

This update is to change the response to JSON format.

  {
    "status": "running",
    "ports": [
      {"src":"phy:0","dst": "ring:0"},
      {"src":"ring:0","dst": "null"}
    ]
  }

Function retrieving the status is changed from print_active_port() to
get_sec_status_json() to return not only ports info but also running
status.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/shared/common.c | 84 +++++++++++++++++++++++++++++++----------------------
 src/shared/common.h |  2 +-
 2 files changed, 51 insertions(+), 35 deletions(-)

diff --git a/src/shared/common.c b/src/shared/common.c
index fa33fcc..56f89df 100644
--- a/src/shared/common.c
+++ b/src/shared/common.c
@@ -233,21 +233,33 @@ spp_atoi(const char *str, int *val)
 }
 
 /*
- * Print port status in forward array
+ * Get status of spp_nfv or spp_vm as JSON format. It consists of running
+ * status and patch info of ports.
  *
- * Each of port status is formatted as
- * "port_id:[PORT_ID],[IN_PORT_STAT],[TYPE],output:[OUTPORT_STAT]"
+ * Here is an example of well-formatted JSON status to better understand.
+ * Actual status has no spaces and new lines inserted as
+ * '{"status":"running","ports":[{"src":"phy:0","dst":"ring:0"},...]}'
+ *
+ *   {
+ *     "status": "running",
+ *     "ports": [
+ *       {"src":"phy:0","dst": "ring:0"},
+ *       {"src":"ring:0","dst": "null"}
+ *     ]
+ *   }
  */
 void
-print_active_ports(char *str,
+get_sec_stats_json(char *str, const char *running_stat,
 		struct port *ports_fwd_array,
 		struct port_map *port_map)
 {
 	unsigned int i;
-	const char *port_prefix = "ports: '";
+	unsigned int has_ports = 0;  // for checking having port at last
+
+	sprintf(str, "%s",  "{\"status\":");
+	sprintf(str + strlen(str), "\"%s\",", running_stat);
+	sprintf(str + strlen(str), "\"ports\":[");
 
-	/* Every elements value */
-	sprintf(str, "%s",  port_prefix);
 	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
 		if (ports_fwd_array[i].in_port_id == PORT_RESET)
 			continue;
@@ -256,80 +268,79 @@ print_active_ports(char *str,
 		RTE_LOG(INFO, APP, "Status %d\n",
 			ports_fwd_array[i].in_port_id);
 
-		/* in_port_id is same value as port_id */
-		/**
-		 * NOTE(yasuufm)
-		 * in_port_id cannot be PORT_RESET currently and it is
-		 * meaningless, but not remove for future possible change
-		 */
-		// if (ports_fwd_array[i].in_port_id != PORT_RESET)
-		// 	sprintf(str + strlen(str), "on,");
-		// else
-		// 	sprintf(str + strlen(str), "off,");
+		sprintf(str + strlen(str), "{\"src\":");
 
 		switch (port_map[i].port_type) {
 		case PHY:
+			has_ports = 1;
 			RTE_LOG(INFO, APP, "Type: PHY\n");
-			sprintf(str + strlen(str), "phy:%u-",
+			sprintf(str + strlen(str), "\"phy:%u\",",
 					port_map[i].id);
 			break;
 		case RING:
+			has_ports = 1;
 			RTE_LOG(INFO, APP, "Type: RING\n");
-			sprintf(str + strlen(str), "ring:%u-",
+			sprintf(str + strlen(str), "\"ring:%u\",",
 				port_map[i].id);
 			break;
 		case VHOST:
+			has_ports = 1;
 			RTE_LOG(INFO, APP, "Type: VHOST\n");
-			sprintf(str + strlen(str), "vhost:%u-",
+			sprintf(str + strlen(str), "{\"vhost:%u\",",
 				port_map[i].id);
 			break;
 		case PCAP:
+			has_ports = 1;
 			RTE_LOG(INFO, APP, "Type: PCAP\n");
-			sprintf(str + strlen(str), "pcap:%u-",
+			sprintf(str + strlen(str), "\"pcap:%u\",",
 					port_map[i].id);
 			break;
 		case NULLPMD:
+			has_ports = 1;
 			RTE_LOG(INFO, APP, "Type: NULLPMD\n");
-			sprintf(str + strlen(str), "nullpmd:%u-",
+			sprintf(str + strlen(str), "\"nullpmd:%u\",",
 					port_map[i].id);
 			break;
 		case UNDEF:
+			has_ports = 1;
 			RTE_LOG(INFO, APP, "Type: UDF\n");
 			/* TODO(yasufum) Need to remove print for undefined ? */
-			sprintf(str + strlen(str), "udf-");
+			sprintf(str + strlen(str), "\"udf\",");
 			break;
 		}
 
+		sprintf(str + strlen(str), "\"dst\":");
+
 		RTE_LOG(INFO, APP, "Out Port ID %d\n",
 				ports_fwd_array[i].out_port_id);
 		if (ports_fwd_array[i].out_port_id == PORT_RESET) {
-			sprintf(str + strlen(str), "%s", "null,");
+			sprintf(str + strlen(str), "%s", "\"null\"");
 		} else {
 			unsigned int j = ports_fwd_array[i].out_port_id;
 			switch (port_map[j].port_type) {
 			case PHY:
 				RTE_LOG(INFO, APP, "Type: PHY\n");
-				sprintf(str + strlen(str), "phy:%u,",
+				sprintf(str + strlen(str), "\"phy:%u\"",
 						port_map[j].id);
 				break;
 			case RING:
 				RTE_LOG(INFO, APP, "Type: RING\n");
-				sprintf(str + strlen(str), "ring:%u,",
+				sprintf(str + strlen(str), "\"ring:%u\"",
 					port_map[j].id);
 				break;
 			case VHOST:
 				RTE_LOG(INFO, APP, "Type: VHOST\n");
-				sprintf(str + strlen(str), "vhost:%u,",
+				sprintf(str + strlen(str), "\"vhost:%u\"",
 						port_map[j].id);
 				break;
 			case PCAP:
 				RTE_LOG(INFO, APP, "Type: PCAP\n");
-				sprintf(str + strlen(str), "pcap:%u,",
+				sprintf(str + strlen(str), "\"pcap:%u\"",
 						port_map[j].id);
 				break;
 			case NULLPMD:
 				RTE_LOG(INFO, APP, "Type: NULLPMD\n");
-				sprintf(str + strlen(str), "nullpmd:%u,",
+				sprintf(str + strlen(str), "\"nullpmd:%u\"",
 						port_map[j].id);
 				break;
 			case UNDEF:
@@ -338,18 +349,23 @@ print_active_ports(char *str,
 				 * TODO(yasufum) Need to remove print for
 				 * undefined ?
 				 */
-				sprintf(str + strlen(str), "udf,");
+				sprintf(str + strlen(str), "\"udf\"");
 				break;
 			}
 		}
+
+		sprintf(str + strlen(str), "},");
 	}
 
-	// If there are no ports, it's formatted as "ports: ''"
-	if (strcmp(str, port_prefix) == 0) {
-		sprintf(str + strlen(str), "'");
+	// Check the number of ports to remove "," if it has one or more ports.
+	if (has_ports == 0) {
+		sprintf(str + strlen(str), "]");
 	} else {  // Remove last ','
-		sprintf(str + strlen(str) - 1, "'");
+		sprintf(str + strlen(str) - 1, "]");
 	}
+
+	sprintf(str + strlen(str), "}");
+
 	// make sure to be terminated with null character
 	sprintf(str + strlen(str), "%c", '\0');
 }
diff --git a/src/shared/common.h b/src/shared/common.h
index f030ecd..52a9a65 100644
--- a/src/shared/common.h
+++ b/src/shared/common.h
@@ -192,7 +192,7 @@ int parse_portmask(struct port_info *ports, uint16_t max_ports,
 int parse_num_clients(uint16_t *num_clients, const char *clients);
 int parse_server(char **server_ip, int *server_port, char *server_addr);
 
-void print_active_ports(char *str,
+void get_sec_stats_json(char *str, const char *running_stat,
 		struct port *ports_fwd_array,
 		struct port_map *port_map);
 
-- 
2.7.4

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [spp] [PATCH v2 2/4] spp_nfv: update retrieving status
  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   ` ogawa.yasufumi
  2018-10-05  5:06   ` [spp] [PATCH v2 3/4] spp_vm: " ogawa.yasufumi
  2018-10-05  5:06   ` [spp] [PATCH v2 4/4] controller: update for parsing JSON status ogawa.yasufumi
  3 siblings, 0 replies; 5+ messages in thread
From: ogawa.yasufumi @ 2018-10-05  5:06 UTC (permalink / raw)
  To: ferruh.yigit, spp, ogawa.yasufumi

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

Change from print_active_ports() to get_sec_status_json() to create a
response for status command.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/nfv/nfv.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/nfv/nfv.c b/src/nfv/nfv.c
index 16b0cf6..f036f62 100644
--- a/src/nfv/nfv.c
+++ b/src/nfv/nfv.c
@@ -725,7 +725,6 @@ parse_command(char *str)
 	char *token_list[MAX_PARAMETER] = {NULL};
 	int max_token = 0;
 	int ret = 0;
-	int i;
 
 	if (!str)
 		return 0;
@@ -746,14 +745,15 @@ parse_command(char *str)
 		RTE_LOG(DEBUG, APP, "status\n");
 		memset(str, '\0', MSG_SIZE);
 		if (cmd == FORWARD)
-			i = sprintf(str, "status: running\n");
+			get_sec_stats_json(str, "running", ports_fwd_array,
+					port_map);
 		else
-			i = sprintf(str, "status: idling\n");
-		print_active_ports(str + i, ports_fwd_array, port_map);
+			get_sec_stats_json(str, "idling", ports_fwd_array,
+					port_map);
 
 	} else if (!strcmp(token_list[0], "_get_client_id")) {
 		memset(str, '\0', MSG_SIZE);
-		i = sprintf(str, "%d", client_id);
+		sprintf(str, "%d", client_id);
 
 	} else if (!strcmp(token_list[0], "_set_client_id")) {
 		int id;
-- 
2.7.4

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [spp] [PATCH v2 3/4] spp_vm: update retrieving status
  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   ` ogawa.yasufumi
  2018-10-05  5:06   ` [spp] [PATCH v2 4/4] controller: update for parsing JSON status ogawa.yasufumi
  3 siblings, 0 replies; 5+ messages in thread
From: ogawa.yasufumi @ 2018-10-05  5:06 UTC (permalink / raw)
  To: ferruh.yigit, spp, ogawa.yasufumi

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

Change from print_active_ports() to get_sec_status_json() to create a
response for status command.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/vm/main.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/vm/main.c b/src/vm/main.c
index 16b4c6b..4f3511b 100644
--- a/src/vm/main.c
+++ b/src/vm/main.c
@@ -397,7 +397,6 @@ parse_command(char *str)
 	char *token_list[MAX_PARAMETER] = {NULL};
 	int max_token = 0;
 	int ret = 0;
-	int i;
 
 	if (!str)
 		return 0;
@@ -418,14 +417,15 @@ parse_command(char *str)
 		RTE_LOG(DEBUG, APP, "status\n");
 		memset(str, '\0', MSG_SIZE);
 		if (cmd == FORWARD)
-			i = sprintf(str, "status: running\n");
+			get_sec_stats_json(str, "running", ports_fwd_array,
+					port_map);
 		else
-			i = sprintf(str, "status: idling\n");
-		print_active_ports(str + i, ports_fwd_array, port_map);
+			get_sec_stats_json(str, "idling", ports_fwd_array,
+					port_map);
 
 	} else if (!strcmp(token_list[0], "_get_client_id")) {
 		memset(str, '\0', MSG_SIZE);
-		i = sprintf(str, "%d", client_id);
+		sprintf(str, "%d", client_id);
 
 	} else if (!strcmp(token_list[0], "_set_client_id")) {
 		int id;
-- 
2.7.4

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [spp] [PATCH v2 4/4] controller: update for parsing JSON status
  2018-10-05  5:06 ` [spp] [PATCH v2 0/4] Change format of sec status to JSON ogawa.yasufumi
                     ` (2 preceding siblings ...)
  2018-10-05  5:06   ` [spp] [PATCH v2 3/4] spp_vm: " ogawa.yasufumi
@ 2018-10-05  5:06   ` ogawa.yasufumi
  3 siblings, 0 replies; 5+ messages in thread
From: ogawa.yasufumi @ 2018-10-05  5:06 UTC (permalink / raw)
  To: ferruh.yigit, spp, ogawa.yasufumi

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-10-05  5:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [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   ` [spp] [PATCH v2 4/4] controller: update for parsing JSON status ogawa.yasufumi

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).