Soft Patch Panel
 help / color / mirror / Atom feed
* [spp] [PATCH 0/4] Update response of status of spp_nfv and spp_vm
@ 2018-10-09 10:50 ogawa.yasufumi
  2018-10-09 10:50 ` [spp] [PATCH 1/4] shared: update status format of spp_nfv ogawa.yasufumi
                   ` (4 more replies)
  0 siblings, 5 replies; 12+ messages in thread
From: ogawa.yasufumi @ 2018-10-09 10:50 UTC (permalink / raw)
  To: spp, ferruh.yigit, ogawa.yasufumi

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

Spp-ctl provides a set of REST APIs for managing all of SPP processes in
a unified way. If the REST API is called, spp-ctl sets up a request for
SPP process by parsing user's request and replies to the user.

This update is to update spp_nfv and spp_vm to return responses as JSON
as similar to spp_vf for better maintaince of spp-ctl.

Yasufumi Ogawa (4):
  shared: update status format of spp_nfv
  controller: update parsing status message
  spp-ctl: update syntax of add and del command
  spp-ctl: update parsing status

 src/controller/shell.py   |  21 +++---
 src/nfv/nfv.c             |  10 +--
 src/shared/common.c       | 179 ++++++++++++++++++++++++++++++++++++----------
 src/shared/common.h       |  14 +++-
 src/spp-ctl/spp_proc.py   |   4 +-
 src/spp-ctl/spp_webapi.py |  34 +++------
 src/vm/init.c             |   2 +-
 src/vm/main.c             |   8 +--
 8 files changed, 185 insertions(+), 87 deletions(-)

-- 
2.7.4

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

* [spp] [PATCH 1/4] shared: update status format of spp_nfv
  2018-10-09 10:50 [spp] [PATCH 0/4] Update response of status of spp_nfv and spp_vm ogawa.yasufumi
@ 2018-10-09 10:50 ` ogawa.yasufumi
  2018-10-09 10:50 ` [spp] [PATCH 2/4] controller: update parsing status message ogawa.yasufumi
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 12+ messages in thread
From: ogawa.yasufumi @ 2018-10-09 10:50 UTC (permalink / raw)
  To: spp, ferruh.yigit, ogawa.yasufumi

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

Update message format of get_sec_status_json() for considering spp-ctl's
API. The message should be the same as the response params of spp-ctl
for maintainance. 'client_id' is added to the args for including it to
the message.

This update also changes spp_nfv and spp_vm for adding 'client_id'.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/nfv/nfv.c       |  10 +--
 src/shared/common.c | 179 ++++++++++++++++++++++++++++++++++++++++------------
 src/shared/common.h |  14 +++-
 src/vm/init.c       |   2 +-
 src/vm/main.c       |   8 +--
 5 files changed, 163 insertions(+), 50 deletions(-)

diff --git a/src/nfv/nfv.c b/src/nfv/nfv.c
index 0ccabac..931269d 100644
--- a/src/nfv/nfv.c
+++ b/src/nfv/nfv.c
@@ -709,11 +709,11 @@ parse_command(char *str)
 		RTE_LOG(DEBUG, APP, "status\n");
 		memset(str, '\0', MSG_SIZE);
 		if (cmd == FORWARD)
-			get_sec_stats_json(str, "running", ports_fwd_array,
-					port_map);
+			get_sec_stats_json(str, client_id, "running",
+					ports_fwd_array, port_map);
 		else
-			get_sec_stats_json(str, "idling", ports_fwd_array,
-					port_map);
+			get_sec_stats_json(str, client_id, "idling",
+					ports_fwd_array, port_map);
 
 	} else if (!strcmp(token_list[0], "_get_client_id")) {
 		memset(str, '\0', MSG_SIZE);
@@ -891,7 +891,7 @@ main(int argc, char *argv[])
 			rte_socket_id(), NO_FLAGS);
 		if (mz == NULL)
 			rte_exit(EXIT_FAILURE,
-				"Cannot reserve memory zone for port information\n");
+				"Cannot reserve memzone for port info\n");
 		memset(mz->addr, 0, sizeof(*ports));
 		ports = mz->addr;
 	}
diff --git a/src/shared/common.c b/src/shared/common.c
index 56ef8c5..c78ee7b 100644
--- a/src/shared/common.c
+++ b/src/shared/common.c
@@ -162,7 +162,7 @@ parse_portmask(struct port_info *ports, uint16_t max_ports,
 		if (pm & 0x01) { /* bit is set in mask, use port */
 			if (count >= max_ports)
 				RTE_LOG(WARNING, APP,
-					"requested port %u not present - ignoring\n",
+					"port %u not present - ignoring\n",
 					count);
 			else
 				ports->id[ports->num_ports++] = count;
@@ -266,25 +266,114 @@ spp_atoi(const char *str, int *val)
  *
  *   {
  *     "status": "running",
- *     "ports": [
+ *     "ports": ["phy:0", "phy:1", "ring:0", "vhost:0"],
+ *     "patches": [
  *       {"src":"phy:0","dst": "ring:0"},
- *       {"src":"ring:0","dst": "null"}
+ *       {"src":"ring:0","dst": "vhost:0"}
  *     ]
  *   }
  */
 void
-get_sec_stats_json(char *str, const char *running_stat,
+get_sec_stats_json(char *str, uint16_t client_id,
+		const char *running_stat,
 		struct port *ports_fwd_array,
 		struct port_map *port_map)
 {
-	unsigned int i;
-	unsigned int has_ports = 0;  // for checking having port at last
+	sprintf(str, "{\"client-id\":%d,", client_id);
 
-	sprintf(str, "%s",  "{\"status\":");
+	sprintf(str + strlen(str), "\"status\":");
 	sprintf(str + strlen(str), "\"%s\",", running_stat);
+
+	append_port_info_json(str, ports_fwd_array, port_map);
+	sprintf(str + strlen(str), ",");
+
+	append_patch_info_json(str, ports_fwd_array, port_map);
+	sprintf(str + strlen(str), "}");
+
+	// make sure to be terminated with null character
+	sprintf(str + strlen(str), "%c", '\0');
+}
+
+/*
+ * Append patch info to sec status. It is called from get_sec_stats_json()
+ * to add a JSON formatted patch info to given 'str'. Here is an example.
+ *
+ *     "ports": ["phy:0", "phy:1", "ring:0", "vhost:0"]
+ */
+int
+append_port_info_json(char *str,
+		struct port *ports_fwd_array,
+		struct port_map *port_map)
+{
+	unsigned int i;
+	unsigned int has_port = 0;  // for checking having port at last
+
 	sprintf(str + strlen(str), "\"ports\":[");
+	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
+
+		if (ports_fwd_array[i].in_port_id == PORT_RESET)
+			continue;
+
+		has_port = 1;
+		switch (port_map[i].port_type) {
+		case PHY:
+			sprintf(str + strlen(str), "\"phy:%u\",",
+					port_map[i].id);
+			break;
+		case RING:
+			sprintf(str + strlen(str), "\"ring:%u\",",
+				port_map[i].id);
+			break;
+		case VHOST:
+			sprintf(str + strlen(str), "\"vhost:%u\",",
+				port_map[i].id);
+			break;
+		case PCAP:
+			sprintf(str + strlen(str), "\"pcap:%u\",",
+					port_map[i].id);
+			break;
+		case NULLPMD:
+			sprintf(str + strlen(str), "\"nullpmd:%u\",",
+					port_map[i].id);
+			break;
+		case UNDEF:
+			/* TODO(yasufum) Need to remove print for undefined ? */
+			sprintf(str + strlen(str), "\"udf\",");
+			break;
+		}
+	}
+
+	// Check if it has at least one port to remove ",".
+	if (has_port == 0) {
+		sprintf(str + strlen(str), "]");
+	} else {  // Remove last ','
+		sprintf(str + strlen(str) - 1, "]");
+	}
+
+	return 0;
+}
+
+/*
+ * Append patch info to sec status. It is called from get_sec_stats_json()
+ * to add a JSON formatted patch info to given 'str'. Here is an example.
+ *
+ *     "patches": [
+ *       {"src":"phy:0","dst": "ring:0"},
+ *       {"src":"ring:0","dst": "vhost:0"}
+ *      ]
+ */
+int
+append_patch_info_json(char *str,
+		struct port *ports_fwd_array,
+		struct port_map *port_map)
+{
+	unsigned int i;
+	unsigned int has_patch = 0;  // for checking having patch at last
 
+	char patch_str[128];
+	sprintf(str + strlen(str), "\"patches\":[");
 	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
+
 		if (ports_fwd_array[i].in_port_id == PORT_RESET)
 			continue;
 
@@ -292,104 +381,116 @@ get_sec_stats_json(char *str, const char *running_stat,
 		RTE_LOG(INFO, APP, "Status %d\n",
 			ports_fwd_array[i].in_port_id);
 
-		sprintf(str + strlen(str), "{\"src\":");
+		memset(patch_str, '\0', sizeof(patch_str));
+
+		sprintf(patch_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(patch_str + strlen(patch_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\",",
-				port_map[i].id);
+			sprintf(patch_str + strlen(patch_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\",",
-				port_map[i].id);
+			sprintf(patch_str + strlen(patch_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(patch_str + strlen(patch_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(patch_str + strlen(patch_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(patch_str + strlen(patch_str),
+					"\"udf\",");
 			break;
 		}
 
-		sprintf(str + strlen(str), "\"dst\":");
+		sprintf(patch_str + strlen(patch_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(patch_str + strlen(patch_str), "%s", "\"\"");
+			continue;
 		} else {
+			has_patch = 1;
 			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(patch_str + strlen(patch_str),
+						"\"phy:%u\"",
 						port_map[j].id);
 				break;
 			case RING:
 				RTE_LOG(INFO, APP, "Type: RING\n");
-				sprintf(str + strlen(str), "\"ring:%u\"",
-					port_map[j].id);
+				sprintf(patch_str + strlen(patch_str),
+						"\"ring:%u\"",
+						port_map[j].id);
 				break;
 			case VHOST:
 				RTE_LOG(INFO, APP, "Type: VHOST\n");
-				sprintf(str + strlen(str), "\"vhost:%u\"",
+				sprintf(patch_str + strlen(patch_str),
+						"\"vhost:%u\"",
 						port_map[j].id);
 				break;
 			case PCAP:
 				RTE_LOG(INFO, APP, "Type: PCAP\n");
-				sprintf(str + strlen(str), "\"pcap:%u\"",
+				sprintf(patch_str + strlen(patch_str),
+						"\"pcap:%u\"",
 						port_map[j].id);
 				break;
 			case NULLPMD:
 				RTE_LOG(INFO, APP, "Type: NULLPMD\n");
-				sprintf(str + strlen(str), "\"nullpmd:%u\"",
+				sprintf(patch_str + strlen(patch_str),
+						"\"nullpmd:%u\"",
 						port_map[j].id);
 				break;
 			case UNDEF:
 				RTE_LOG(INFO, APP, "Type: UDF\n");
-				/**
+				/*
 				 * TODO(yasufum) Need to remove print for
 				 * undefined ?
 				 */
-				sprintf(str + strlen(str), "\"udf\"");
+				sprintf(patch_str + strlen(patch_str),
+						"\"udf\"");
 				break;
 			}
 		}
 
-		sprintf(str + strlen(str), "},");
+		sprintf(patch_str + strlen(patch_str), "},");
+
+		if (has_patch != 0)
+			sprintf(str + strlen(str), "%s", patch_str);
 	}
 
-	// Check the number of ports to remove "," if it has one or more ports.
-	if (has_ports == 0) {
+
+	// Check if it has at least one patch to remove ",".
+	if (has_patch == 0) {
 		sprintf(str + strlen(str), "]");
 	} else {  // Remove last ','
 		sprintf(str + strlen(str) - 1, "]");
 	}
 
-	sprintf(str + strlen(str), "}");
-
-	// make sure to be terminated with null character
-	sprintf(str + strlen(str), "%c", '\0');
+	return 0;
 }
diff --git a/src/shared/common.h b/src/shared/common.h
index 1580b08..a30f0da 100644
--- a/src/shared/common.h
+++ b/src/shared/common.h
@@ -192,7 +192,19 @@ 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 get_sec_stats_json(char *str, const char *running_stat,
+/* Get status of spp_nfv or spp_vm as JSON format. */
+void get_sec_stats_json(char *str, uint16_t client_id,
+		const char *running_stat,
+		struct port *ports_fwd_array,
+		struct port_map *port_map);
+
+/* Append port info to sec status, called from get_sec_stats_json(). */
+int append_port_info_json(char *str,
+		struct port *ports_fwd_array,
+		struct port_map *port_map);
+
+/* Append patch info to sec status, called from get_sec_stats_json(). */
+int append_patch_info_json(char *str,
 		struct port *ports_fwd_array,
 		struct port_map *port_map);
 
diff --git a/src/vm/init.c b/src/vm/init.c
index c222ed0..dd4353d 100644
--- a/src/vm/init.c
+++ b/src/vm/init.c
@@ -83,7 +83,7 @@ init(int argc, char *argv[])
 			rte_socket_id(), NO_FLAGS);
 		if (mz == NULL)
 			rte_exit(EXIT_FAILURE,
-				"Cannot reserve memory zone for port information\n");
+				"Cannot reserve memzone for port info\n");
 		memset(mz->addr, 0, sizeof(*ports));
 	}
 	ports = mz->addr;
diff --git a/src/vm/main.c b/src/vm/main.c
index c32faaf..7aec126 100644
--- a/src/vm/main.c
+++ b/src/vm/main.c
@@ -399,11 +399,11 @@ parse_command(char *str)
 		RTE_LOG(DEBUG, APP, "status\n");
 		memset(str, '\0', MSG_SIZE);
 		if (cmd == FORWARD)
-			get_sec_stats_json(str, "running", ports_fwd_array,
-					port_map);
+			get_sec_stats_json(str, client_id, "running",
+					ports_fwd_array, port_map);
 		else
-			get_sec_stats_json(str, "idling", ports_fwd_array,
-					port_map);
+			get_sec_stats_json(str, client_id, "idling",
+					ports_fwd_array, port_map);
 
 	} else if (!strcmp(token_list[0], "_get_client_id")) {
 		memset(str, '\0', MSG_SIZE);
-- 
2.7.4

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

* [spp] [PATCH 2/4] controller: update parsing status message
  2018-10-09 10:50 [spp] [PATCH 0/4] Update response of status of spp_nfv and spp_vm ogawa.yasufumi
  2018-10-09 10:50 ` [spp] [PATCH 1/4] shared: update status format of spp_nfv ogawa.yasufumi
@ 2018-10-09 10:50 ` ogawa.yasufumi
  2018-10-09 10:50 ` [spp] [PATCH 3/4] spp-ctl: update syntax of add and del command ogawa.yasufumi
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 12+ messages in thread
From: ogawa.yasufumi @ 2018-10-09 10:50 UTC (permalink / raw)
  To: spp, ferruh.yigit, ogawa.yasufumi

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

To apply with the update of spp_nfv and spp_vm, update parsing the
message of status.

In the updated message, 'ports' attribute is changed to not include
patch info and it is moved to the new 'patches' attribute. This patch
is to parse 'patches' attribute. Output of status command is not
changed.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/controller/shell.py | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/src/controller/shell.py b/src/controller/shell.py
index 09b9e86..8fb5a1a 100644
--- a/src/controller/shell.py
+++ b/src/controller/shell.py
@@ -194,27 +194,30 @@ class Shell(cmd.Cmd, object):
             - phy:1
 
         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".
+        series of null character "\x00".
 
-          {"status":"idling","ports":[{"src":"phy:0", "dst": ...,]}'\x00\x00..
+          {"client-id":1,...,"patches":[{"src":"phy:0"...},...]}'\x00..
         """
 
-        msg = msg.replace("\x00", "")  # clean sec's msg
+        msg = msg.replace("\x00", "")  # Clean received msg
 
         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'])
+                dst = None
+                for patch in sec_attr['patches']:
+                    if patch['src'] == port:
+                        dst = patch['dst']
+
+                if dst is None:
+                    print('  - %s' % port)
                 else:
-                    print('  - %s -> %s' % (port['src'], port['dst']))
+                    print('  - %s -> %s' % (port, dst))
         except ValueError as err:
             print('Invalid format: {0}.'.format(err))
-            print("  '%s'" % msg)
+            print("'%s'" % msg)
 
     def command_primary(self, command):
         """Send command to primary process"""
-- 
2.7.4

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

* [spp] [PATCH 3/4] spp-ctl: update syntax of add and del command
  2018-10-09 10:50 [spp] [PATCH 0/4] Update response of status of spp_nfv and spp_vm ogawa.yasufumi
  2018-10-09 10:50 ` [spp] [PATCH 1/4] shared: update status format of spp_nfv ogawa.yasufumi
  2018-10-09 10:50 ` [spp] [PATCH 2/4] controller: update parsing status message ogawa.yasufumi
@ 2018-10-09 10:50 ` ogawa.yasufumi
  2018-10-09 21:56   ` Itsuro ODA
  2018-10-09 10:50 ` [spp] [PATCH 4/4] spp-ctl: update parsing status ogawa.yasufumi
  2018-10-11 10:33 ` [spp] [PATCH v2 0/4] Update response of status of spp_nfv and spp_vm ogawa.yasufumi
  4 siblings, 1 reply; 12+ messages in thread
From: ogawa.yasufumi @ 2018-10-09 10:50 UTC (permalink / raw)
  To: spp, ferruh.yigit, ogawa.yasufumi

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

Because add and del command are updated to use resource UID, spp-ctl is
also updated to use resource UID.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/spp-ctl/spp_proc.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/spp-ctl/spp_proc.py b/src/spp-ctl/spp_proc.py
index aa83b76..726de3e 100644
--- a/src/spp-ctl/spp_proc.py
+++ b/src/spp-ctl/spp_proc.py
@@ -146,11 +146,11 @@ class NfvProc(SppProc):
 
     @exec_command
     def port_add(self, if_type, if_num):
-        return "add {if_type} {if_num}".format(**locals())
+        return "add {if_type}:{if_num}".format(**locals())
 
     @exec_command
     def port_del(self, if_type, if_num):
-        return "del {if_type} {if_num}".format(**locals())
+        return "del {if_type}:{if_num}".format(**locals())
 
     @exec_command
     def patch_add(self, src_port, dst_port):
-- 
2.7.4

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

* [spp] [PATCH 4/4] spp-ctl: update parsing status
  2018-10-09 10:50 [spp] [PATCH 0/4] Update response of status of spp_nfv and spp_vm ogawa.yasufumi
                   ` (2 preceding siblings ...)
  2018-10-09 10:50 ` [spp] [PATCH 3/4] spp-ctl: update syntax of add and del command ogawa.yasufumi
@ 2018-10-09 10:50 ` ogawa.yasufumi
  2018-10-11 10:33 ` [spp] [PATCH v2 0/4] Update response of status of spp_nfv and spp_vm ogawa.yasufumi
  4 siblings, 0 replies; 12+ messages in thread
From: ogawa.yasufumi @ 2018-10-09 10:50 UTC (permalink / raw)
  To: spp, ferruh.yigit, ogawa.yasufumi

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

Update parsing the result of status. Spp_nfv and spp_vm are changed to
return the same status message as spp-ctl, so it can be used without
modifying.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/spp-ctl/spp_webapi.py | 34 ++++++++--------------------------
 1 file changed, 8 insertions(+), 26 deletions(-)

diff --git a/src/spp-ctl/spp_webapi.py b/src/spp-ctl/spp_webapi.py
index ddf6513..9c16af6 100644
--- a/src/spp-ctl/spp_webapi.py
+++ b/src/spp-ctl/spp_webapi.py
@@ -321,33 +321,15 @@ class V1NFVHandler(BaseHandler):
     def convert_nfv_info(self, sec_id, data):
         nfv = {}
 
-        # spp_nfv returns status info in two lines. First line is
-        # status of running or idling, and second is patch info.
-        # 'null' means that it has no dst port.
-        #   "status: idling\nports: 'phy:0-phy:1,phy:1-null'\x00\x00.."
-        entries = data.split('\n')
-        if len(entries) != 2:
-            return {}
-
-        nfv['client_id'] = int(sec_id)
-        nfv['status'] = entries[0].split()[1]
-
-        patch_list = entries[1].split()[1].replace("'", '')
-
-        ports = []
-        nfv['patches'] = []
-
-        for port_cmb in patch_list.split(','):
-            p_src, p_dst = port_cmb.split('-')
-            if p_src != 'null' and p_dst != 'null':
-                nfv['patches'].append({'src': p_src, 'dst': p_dst})
-
-            for port in [p_src, p_dst]:
-                if port != 'null':
-                    ports.append(port)
-
-        nfv['ports'] = list(set(ports))
+        # spp_nfv returns status info in JSON format. 'null' means
+        # that it has no dst port.
+        #   {"status":"idling","ports":[{"src":"phy:0","dst":"null"},...
 
+        # TODO(yasufum) modify after nfv and vm is updated for new data definition.
+        try:
+            nfv = json.loads(data)
+        except json.JSONDecodeError as e:
+            print("%s" % e)
         return nfv
 
     def nfv_get(self, proc):
-- 
2.7.4

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

* Re: [spp] [PATCH 3/4] spp-ctl: update syntax of add and del command
  2018-10-09 10:50 ` [spp] [PATCH 3/4] spp-ctl: update syntax of add and del command ogawa.yasufumi
@ 2018-10-09 21:56   ` Itsuro ODA
  2018-10-10  4:41     ` Yasufumi Ogawa
  0 siblings, 1 reply; 12+ messages in thread
From: Itsuro ODA @ 2018-10-09 21:56 UTC (permalink / raw)
  To: ogawa.yasufumi; +Cc: spp, ferruh.yigit

Hi Yasufumi,

I think it seems a bit strange to split port to if_type
and if_num before calling port_add/port_del. How about the
following fix ?

---
diff --git a/src/spp-ctl/spp_proc.py b/src/spp-ctl/spp_proc.py
index aa83b76..3b01e3f 100644
--- a/src/spp-ctl/spp_proc.py
+++ b/src/spp-ctl/spp_proc.py
@@ -145,12 +145,12 @@ class NfvProc(SppProc):
         return "status"
 
     @exec_command
-    def port_add(self, if_type, if_num):
-        return "add {if_type} {if_num}".format(**locals())
+    def port_add(self, port):
+        return "add {port}".format(**locals())
 
     @exec_command
-    def port_del(self, if_type, if_num):
-        return "del {if_type} {if_num}".format(**locals())
+    def port_del(self, port):
+        return "del {port}".format(**locals())
 
     @exec_command
     def patch_add(self, src_port, dst_port):
diff --git a/src/spp-ctl/spp_webapi.py b/src/spp-ctl/spp_webapi.py
index ddf6513..6bfc436 100644
--- a/src/spp-ctl/spp_webapi.py
+++ b/src/spp-ctl/spp_webapi.py
@@ -376,11 +376,10 @@ class V1NFVHandler(BaseHandler):
     def nfv_port(self, proc, body):
         self._validate_nfv_port(body)
 
-        if_type, if_num = body['port'].split(":")
         if body['action'] == "add":
-            proc.port_add(if_type, if_num)
+            proc.port_add(body['port'])
         else:
-            proc.port_del(if_type, if_num)
+            proc.port_del(body['port'])
 
     def _validate_nfv_patch(self, body):
         for key in ['src', 'dst']:
---

On Tue,  9 Oct 2018 19:50:46 +0900
ogawa.yasufumi@lab.ntt.co.jp wrote:

> From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
> 
> Because add and del command are updated to use resource UID, spp-ctl is
> also updated to use resource UID.
> 
> Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
> ---
>  src/spp-ctl/spp_proc.py | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/src/spp-ctl/spp_proc.py b/src/spp-ctl/spp_proc.py
> index aa83b76..726de3e 100644
> --- a/src/spp-ctl/spp_proc.py
> +++ b/src/spp-ctl/spp_proc.py
> @@ -146,11 +146,11 @@ class NfvProc(SppProc):
>  
>      @exec_command
>      def port_add(self, if_type, if_num):
> -        return "add {if_type} {if_num}".format(**locals())
> +        return "add {if_type}:{if_num}".format(**locals())
>  
>      @exec_command
>      def port_del(self, if_type, if_num):
> -        return "del {if_type} {if_num}".format(**locals())
> +        return "del {if_type}:{if_num}".format(**locals())
>  
>      @exec_command
>      def patch_add(self, src_port, dst_port):
> -- 
> 2.7.4

Thanks.
-- 
Itsuro ODA <oda@valinux.co.jp>

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

* Re: [spp] [PATCH 3/4] spp-ctl: update syntax of add and del command
  2018-10-09 21:56   ` Itsuro ODA
@ 2018-10-10  4:41     ` Yasufumi Ogawa
  0 siblings, 0 replies; 12+ messages in thread
From: Yasufumi Ogawa @ 2018-10-10  4:41 UTC (permalink / raw)
  To: Itsuro ODA; +Cc: spp, ferruh.yigit

On 2018/10/10 6:56, Itsuro ODA wrote:
> Hi Yasufumi,
> 
> I think it seems a bit strange to split port to if_type
> and if_num before calling port_add/port_del. How about the
> following fix ?
I understand your point. Although the reason of dividing 'if_type' and 'if_num' was to remove the delimiter explicitly before 
sending the request to spp_nfv, but all of processes are already updated to expect the same delimiter and no need to remove. 
Your proposal is more simple and better for considering code maintenance.

Thanks
> 
> ---
> diff --git a/src/spp-ctl/spp_proc.py b/src/spp-ctl/spp_proc.py
> index aa83b76..3b01e3f 100644
> --- a/src/spp-ctl/spp_proc.py
> +++ b/src/spp-ctl/spp_proc.py
> @@ -145,12 +145,12 @@ class NfvProc(SppProc):
>           return "status"
>   
>       @exec_command
> -    def port_add(self, if_type, if_num):
> -        return "add {if_type} {if_num}".format(**locals())
> +    def port_add(self, port):
> +        return "add {port}".format(**locals())
>   
>       @exec_command
> -    def port_del(self, if_type, if_num):
> -        return "del {if_type} {if_num}".format(**locals())
> +    def port_del(self, port):
> +        return "del {port}".format(**locals())
>   
>       @exec_command
>       def patch_add(self, src_port, dst_port):
> diff --git a/src/spp-ctl/spp_webapi.py b/src/spp-ctl/spp_webapi.py
> index ddf6513..6bfc436 100644
> --- a/src/spp-ctl/spp_webapi.py
> +++ b/src/spp-ctl/spp_webapi.py
> @@ -376,11 +376,10 @@ class V1NFVHandler(BaseHandler):
>       def nfv_port(self, proc, body):
>           self._validate_nfv_port(body)
>   
> -        if_type, if_num = body['port'].split(":")
>           if body['action'] == "add":
> -            proc.port_add(if_type, if_num)
> +            proc.port_add(body['port'])
>           else:
> -            proc.port_del(if_type, if_num)
> +            proc.port_del(body['port'])
>   
>       def _validate_nfv_patch(self, body):
>           for key in ['src', 'dst']:
> ---
> 
> On Tue,  9 Oct 2018 19:50:46 +0900
> ogawa.yasufumi@lab.ntt.co.jp wrote:
> 
>> From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
>>
>> Because add and del command are updated to use resource UID, spp-ctl is
>> also updated to use resource UID.
>>
>> Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
>> ---
>>   src/spp-ctl/spp_proc.py | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/src/spp-ctl/spp_proc.py b/src/spp-ctl/spp_proc.py
>> index aa83b76..726de3e 100644
>> --- a/src/spp-ctl/spp_proc.py
>> +++ b/src/spp-ctl/spp_proc.py
>> @@ -146,11 +146,11 @@ class NfvProc(SppProc):
>>   
>>       @exec_command
>>       def port_add(self, if_type, if_num):
>> -        return "add {if_type} {if_num}".format(**locals())
>> +        return "add {if_type}:{if_num}".format(**locals())
>>   
>>       @exec_command
>>       def port_del(self, if_type, if_num):
>> -        return "del {if_type} {if_num}".format(**locals())
>> +        return "del {if_type}:{if_num}".format(**locals())
>>   
>>       @exec_command
>>       def patch_add(self, src_port, dst_port):
>> -- 
>> 2.7.4
> 
> Thanks.
> 


-- 
Yasufumi Ogawa
NTT Network Service Systems Labs

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

* [spp] [PATCH v2 0/4] Update response of status of spp_nfv and spp_vm
  2018-10-09 10:50 [spp] [PATCH 0/4] Update response of status of spp_nfv and spp_vm ogawa.yasufumi
                   ` (3 preceding siblings ...)
  2018-10-09 10:50 ` [spp] [PATCH 4/4] spp-ctl: update parsing status ogawa.yasufumi
@ 2018-10-11 10:33 ` ogawa.yasufumi
  2018-10-11 10:33   ` [spp] [PATCH v2 1/4] shared: update status format of spp_nfv ogawa.yasufumi
                     ` (3 more replies)
  4 siblings, 4 replies; 12+ messages in thread
From: ogawa.yasufumi @ 2018-10-11 10:33 UTC (permalink / raw)
  To: spp, ferruh.yigit, ogawa.yasufumi

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

Hi,

I updated calling port_add and port_del methods to be simple. Here is
the change of definition of port_add(), and port_del() is also the same.

  -    def port_add(self, if_type, if_num):
  -        return "add {if_type} {if_num}".format(**locals())
  +    def port_add(self, port):
  +        return "add {port}".format(**locals())

Thanks,
Yasufumi

>Spp-ctl provides a set of REST APIs for managing all of SPP processes in
>a unified way. If the REST API is called, spp-ctl sets up a request for
>SPP process by parsing user's request and replies to the user.
>
>This update is to update spp_nfv and spp_vm to return responses as JSON
>as similar to spp_vf for better maintaince of spp-ctl.

Yasufumi Ogawa (4):
  shared: update status format of spp_nfv
  controller: update parsing status message
  spp-ctl: update syntax of add and del command
  spp-ctl: update parsing status

 src/controller/shell.py   |  21 +++---
 src/nfv/nfv.c             |  10 +--
 src/shared/common.c       | 179 ++++++++++++++++++++++++++++++++++++----------
 src/shared/common.h       |  14 +++-
 src/spp-ctl/spp_proc.py   |   8 +--
 src/spp-ctl/spp_webapi.py |  39 +++-------
 src/vm/init.c             |   2 +-
 src/vm/main.c             |   8 +--
 8 files changed, 189 insertions(+), 92 deletions(-)

-- 
2.7.4

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

* [spp] [PATCH v2 1/4] shared: update status format of spp_nfv
  2018-10-11 10:33 ` [spp] [PATCH v2 0/4] Update response of status of spp_nfv and spp_vm ogawa.yasufumi
@ 2018-10-11 10:33   ` ogawa.yasufumi
  2018-10-11 10:33   ` [spp] [PATCH v2 2/4] controller: update parsing status message ogawa.yasufumi
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 12+ messages in thread
From: ogawa.yasufumi @ 2018-10-11 10:33 UTC (permalink / raw)
  To: spp, ferruh.yigit, ogawa.yasufumi

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

Update message format of get_sec_status_json() for considering spp-ctl's
API. The message should be the same as the response params of spp-ctl
for maintainance. 'client_id' is added to the args for including it to
the message.

This update also changes spp_nfv and spp_vm for adding 'client_id'.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/nfv/nfv.c       |  10 +--
 src/shared/common.c | 179 ++++++++++++++++++++++++++++++++++++++++------------
 src/shared/common.h |  14 +++-
 src/vm/init.c       |   2 +-
 src/vm/main.c       |   8 +--
 5 files changed, 163 insertions(+), 50 deletions(-)

diff --git a/src/nfv/nfv.c b/src/nfv/nfv.c
index 0ccabac..931269d 100644
--- a/src/nfv/nfv.c
+++ b/src/nfv/nfv.c
@@ -709,11 +709,11 @@ parse_command(char *str)
 		RTE_LOG(DEBUG, APP, "status\n");
 		memset(str, '\0', MSG_SIZE);
 		if (cmd == FORWARD)
-			get_sec_stats_json(str, "running", ports_fwd_array,
-					port_map);
+			get_sec_stats_json(str, client_id, "running",
+					ports_fwd_array, port_map);
 		else
-			get_sec_stats_json(str, "idling", ports_fwd_array,
-					port_map);
+			get_sec_stats_json(str, client_id, "idling",
+					ports_fwd_array, port_map);
 
 	} else if (!strcmp(token_list[0], "_get_client_id")) {
 		memset(str, '\0', MSG_SIZE);
@@ -891,7 +891,7 @@ main(int argc, char *argv[])
 			rte_socket_id(), NO_FLAGS);
 		if (mz == NULL)
 			rte_exit(EXIT_FAILURE,
-				"Cannot reserve memory zone for port information\n");
+				"Cannot reserve memzone for port info\n");
 		memset(mz->addr, 0, sizeof(*ports));
 		ports = mz->addr;
 	}
diff --git a/src/shared/common.c b/src/shared/common.c
index 56ef8c5..c78ee7b 100644
--- a/src/shared/common.c
+++ b/src/shared/common.c
@@ -162,7 +162,7 @@ parse_portmask(struct port_info *ports, uint16_t max_ports,
 		if (pm & 0x01) { /* bit is set in mask, use port */
 			if (count >= max_ports)
 				RTE_LOG(WARNING, APP,
-					"requested port %u not present - ignoring\n",
+					"port %u not present - ignoring\n",
 					count);
 			else
 				ports->id[ports->num_ports++] = count;
@@ -266,25 +266,114 @@ spp_atoi(const char *str, int *val)
  *
  *   {
  *     "status": "running",
- *     "ports": [
+ *     "ports": ["phy:0", "phy:1", "ring:0", "vhost:0"],
+ *     "patches": [
  *       {"src":"phy:0","dst": "ring:0"},
- *       {"src":"ring:0","dst": "null"}
+ *       {"src":"ring:0","dst": "vhost:0"}
  *     ]
  *   }
  */
 void
-get_sec_stats_json(char *str, const char *running_stat,
+get_sec_stats_json(char *str, uint16_t client_id,
+		const char *running_stat,
 		struct port *ports_fwd_array,
 		struct port_map *port_map)
 {
-	unsigned int i;
-	unsigned int has_ports = 0;  // for checking having port at last
+	sprintf(str, "{\"client-id\":%d,", client_id);
 
-	sprintf(str, "%s",  "{\"status\":");
+	sprintf(str + strlen(str), "\"status\":");
 	sprintf(str + strlen(str), "\"%s\",", running_stat);
+
+	append_port_info_json(str, ports_fwd_array, port_map);
+	sprintf(str + strlen(str), ",");
+
+	append_patch_info_json(str, ports_fwd_array, port_map);
+	sprintf(str + strlen(str), "}");
+
+	// make sure to be terminated with null character
+	sprintf(str + strlen(str), "%c", '\0');
+}
+
+/*
+ * Append patch info to sec status. It is called from get_sec_stats_json()
+ * to add a JSON formatted patch info to given 'str'. Here is an example.
+ *
+ *     "ports": ["phy:0", "phy:1", "ring:0", "vhost:0"]
+ */
+int
+append_port_info_json(char *str,
+		struct port *ports_fwd_array,
+		struct port_map *port_map)
+{
+	unsigned int i;
+	unsigned int has_port = 0;  // for checking having port at last
+
 	sprintf(str + strlen(str), "\"ports\":[");
+	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
+
+		if (ports_fwd_array[i].in_port_id == PORT_RESET)
+			continue;
+
+		has_port = 1;
+		switch (port_map[i].port_type) {
+		case PHY:
+			sprintf(str + strlen(str), "\"phy:%u\",",
+					port_map[i].id);
+			break;
+		case RING:
+			sprintf(str + strlen(str), "\"ring:%u\",",
+				port_map[i].id);
+			break;
+		case VHOST:
+			sprintf(str + strlen(str), "\"vhost:%u\",",
+				port_map[i].id);
+			break;
+		case PCAP:
+			sprintf(str + strlen(str), "\"pcap:%u\",",
+					port_map[i].id);
+			break;
+		case NULLPMD:
+			sprintf(str + strlen(str), "\"nullpmd:%u\",",
+					port_map[i].id);
+			break;
+		case UNDEF:
+			/* TODO(yasufum) Need to remove print for undefined ? */
+			sprintf(str + strlen(str), "\"udf\",");
+			break;
+		}
+	}
+
+	// Check if it has at least one port to remove ",".
+	if (has_port == 0) {
+		sprintf(str + strlen(str), "]");
+	} else {  // Remove last ','
+		sprintf(str + strlen(str) - 1, "]");
+	}
+
+	return 0;
+}
+
+/*
+ * Append patch info to sec status. It is called from get_sec_stats_json()
+ * to add a JSON formatted patch info to given 'str'. Here is an example.
+ *
+ *     "patches": [
+ *       {"src":"phy:0","dst": "ring:0"},
+ *       {"src":"ring:0","dst": "vhost:0"}
+ *      ]
+ */
+int
+append_patch_info_json(char *str,
+		struct port *ports_fwd_array,
+		struct port_map *port_map)
+{
+	unsigned int i;
+	unsigned int has_patch = 0;  // for checking having patch at last
 
+	char patch_str[128];
+	sprintf(str + strlen(str), "\"patches\":[");
 	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
+
 		if (ports_fwd_array[i].in_port_id == PORT_RESET)
 			continue;
 
@@ -292,104 +381,116 @@ get_sec_stats_json(char *str, const char *running_stat,
 		RTE_LOG(INFO, APP, "Status %d\n",
 			ports_fwd_array[i].in_port_id);
 
-		sprintf(str + strlen(str), "{\"src\":");
+		memset(patch_str, '\0', sizeof(patch_str));
+
+		sprintf(patch_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(patch_str + strlen(patch_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\",",
-				port_map[i].id);
+			sprintf(patch_str + strlen(patch_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\",",
-				port_map[i].id);
+			sprintf(patch_str + strlen(patch_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(patch_str + strlen(patch_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(patch_str + strlen(patch_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(patch_str + strlen(patch_str),
+					"\"udf\",");
 			break;
 		}
 
-		sprintf(str + strlen(str), "\"dst\":");
+		sprintf(patch_str + strlen(patch_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(patch_str + strlen(patch_str), "%s", "\"\"");
+			continue;
 		} else {
+			has_patch = 1;
 			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(patch_str + strlen(patch_str),
+						"\"phy:%u\"",
 						port_map[j].id);
 				break;
 			case RING:
 				RTE_LOG(INFO, APP, "Type: RING\n");
-				sprintf(str + strlen(str), "\"ring:%u\"",
-					port_map[j].id);
+				sprintf(patch_str + strlen(patch_str),
+						"\"ring:%u\"",
+						port_map[j].id);
 				break;
 			case VHOST:
 				RTE_LOG(INFO, APP, "Type: VHOST\n");
-				sprintf(str + strlen(str), "\"vhost:%u\"",
+				sprintf(patch_str + strlen(patch_str),
+						"\"vhost:%u\"",
 						port_map[j].id);
 				break;
 			case PCAP:
 				RTE_LOG(INFO, APP, "Type: PCAP\n");
-				sprintf(str + strlen(str), "\"pcap:%u\"",
+				sprintf(patch_str + strlen(patch_str),
+						"\"pcap:%u\"",
 						port_map[j].id);
 				break;
 			case NULLPMD:
 				RTE_LOG(INFO, APP, "Type: NULLPMD\n");
-				sprintf(str + strlen(str), "\"nullpmd:%u\"",
+				sprintf(patch_str + strlen(patch_str),
+						"\"nullpmd:%u\"",
 						port_map[j].id);
 				break;
 			case UNDEF:
 				RTE_LOG(INFO, APP, "Type: UDF\n");
-				/**
+				/*
 				 * TODO(yasufum) Need to remove print for
 				 * undefined ?
 				 */
-				sprintf(str + strlen(str), "\"udf\"");
+				sprintf(patch_str + strlen(patch_str),
+						"\"udf\"");
 				break;
 			}
 		}
 
-		sprintf(str + strlen(str), "},");
+		sprintf(patch_str + strlen(patch_str), "},");
+
+		if (has_patch != 0)
+			sprintf(str + strlen(str), "%s", patch_str);
 	}
 
-	// Check the number of ports to remove "," if it has one or more ports.
-	if (has_ports == 0) {
+
+	// Check if it has at least one patch to remove ",".
+	if (has_patch == 0) {
 		sprintf(str + strlen(str), "]");
 	} else {  // Remove last ','
 		sprintf(str + strlen(str) - 1, "]");
 	}
 
-	sprintf(str + strlen(str), "}");
-
-	// make sure to be terminated with null character
-	sprintf(str + strlen(str), "%c", '\0');
+	return 0;
 }
diff --git a/src/shared/common.h b/src/shared/common.h
index 1580b08..a30f0da 100644
--- a/src/shared/common.h
+++ b/src/shared/common.h
@@ -192,7 +192,19 @@ 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 get_sec_stats_json(char *str, const char *running_stat,
+/* Get status of spp_nfv or spp_vm as JSON format. */
+void get_sec_stats_json(char *str, uint16_t client_id,
+		const char *running_stat,
+		struct port *ports_fwd_array,
+		struct port_map *port_map);
+
+/* Append port info to sec status, called from get_sec_stats_json(). */
+int append_port_info_json(char *str,
+		struct port *ports_fwd_array,
+		struct port_map *port_map);
+
+/* Append patch info to sec status, called from get_sec_stats_json(). */
+int append_patch_info_json(char *str,
 		struct port *ports_fwd_array,
 		struct port_map *port_map);
 
diff --git a/src/vm/init.c b/src/vm/init.c
index c222ed0..dd4353d 100644
--- a/src/vm/init.c
+++ b/src/vm/init.c
@@ -83,7 +83,7 @@ init(int argc, char *argv[])
 			rte_socket_id(), NO_FLAGS);
 		if (mz == NULL)
 			rte_exit(EXIT_FAILURE,
-				"Cannot reserve memory zone for port information\n");
+				"Cannot reserve memzone for port info\n");
 		memset(mz->addr, 0, sizeof(*ports));
 	}
 	ports = mz->addr;
diff --git a/src/vm/main.c b/src/vm/main.c
index c32faaf..7aec126 100644
--- a/src/vm/main.c
+++ b/src/vm/main.c
@@ -399,11 +399,11 @@ parse_command(char *str)
 		RTE_LOG(DEBUG, APP, "status\n");
 		memset(str, '\0', MSG_SIZE);
 		if (cmd == FORWARD)
-			get_sec_stats_json(str, "running", ports_fwd_array,
-					port_map);
+			get_sec_stats_json(str, client_id, "running",
+					ports_fwd_array, port_map);
 		else
-			get_sec_stats_json(str, "idling", ports_fwd_array,
-					port_map);
+			get_sec_stats_json(str, client_id, "idling",
+					ports_fwd_array, port_map);
 
 	} else if (!strcmp(token_list[0], "_get_client_id")) {
 		memset(str, '\0', MSG_SIZE);
-- 
2.7.4

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

* [spp] [PATCH v2 2/4] controller: update parsing status message
  2018-10-11 10:33 ` [spp] [PATCH v2 0/4] Update response of status of spp_nfv and spp_vm ogawa.yasufumi
  2018-10-11 10:33   ` [spp] [PATCH v2 1/4] shared: update status format of spp_nfv ogawa.yasufumi
@ 2018-10-11 10:33   ` ogawa.yasufumi
  2018-10-11 10:33   ` [spp] [PATCH v2 3/4] spp-ctl: update syntax of add and del command ogawa.yasufumi
  2018-10-11 10:33   ` [spp] [PATCH v2 4/4] spp-ctl: update parsing status ogawa.yasufumi
  3 siblings, 0 replies; 12+ messages in thread
From: ogawa.yasufumi @ 2018-10-11 10:33 UTC (permalink / raw)
  To: spp, ferruh.yigit, ogawa.yasufumi

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

To apply with the update of spp_nfv and spp_vm, update parsing the
message of status.

In the updated message, 'ports' attribute is changed to not include
patch info and it is moved to the new 'patches' attribute. This patch
is to parse 'patches' attribute. Output of status command is not
changed.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/controller/shell.py | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/src/controller/shell.py b/src/controller/shell.py
index 09b9e86..8fb5a1a 100644
--- a/src/controller/shell.py
+++ b/src/controller/shell.py
@@ -194,27 +194,30 @@ class Shell(cmd.Cmd, object):
             - phy:1
 
         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".
+        series of null character "\x00".
 
-          {"status":"idling","ports":[{"src":"phy:0", "dst": ...,]}'\x00\x00..
+          {"client-id":1,...,"patches":[{"src":"phy:0"...},...]}'\x00..
         """
 
-        msg = msg.replace("\x00", "")  # clean sec's msg
+        msg = msg.replace("\x00", "")  # Clean received msg
 
         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'])
+                dst = None
+                for patch in sec_attr['patches']:
+                    if patch['src'] == port:
+                        dst = patch['dst']
+
+                if dst is None:
+                    print('  - %s' % port)
                 else:
-                    print('  - %s -> %s' % (port['src'], port['dst']))
+                    print('  - %s -> %s' % (port, dst))
         except ValueError as err:
             print('Invalid format: {0}.'.format(err))
-            print("  '%s'" % msg)
+            print("'%s'" % msg)
 
     def command_primary(self, command):
         """Send command to primary process"""
-- 
2.7.4

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

* [spp] [PATCH v2 3/4] spp-ctl: update syntax of add and del command
  2018-10-11 10:33 ` [spp] [PATCH v2 0/4] Update response of status of spp_nfv and spp_vm ogawa.yasufumi
  2018-10-11 10:33   ` [spp] [PATCH v2 1/4] shared: update status format of spp_nfv ogawa.yasufumi
  2018-10-11 10:33   ` [spp] [PATCH v2 2/4] controller: update parsing status message ogawa.yasufumi
@ 2018-10-11 10:33   ` ogawa.yasufumi
  2018-10-11 10:33   ` [spp] [PATCH v2 4/4] spp-ctl: update parsing status ogawa.yasufumi
  3 siblings, 0 replies; 12+ messages in thread
From: ogawa.yasufumi @ 2018-10-11 10:33 UTC (permalink / raw)
  To: spp, ferruh.yigit, ogawa.yasufumi

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

Because add and del command are updated to use resource UID, spp-ctl is
also updated to use resource UID.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/spp-ctl/spp_proc.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/spp-ctl/spp_proc.py b/src/spp-ctl/spp_proc.py
index aa83b76..3b01e3f 100644
--- a/src/spp-ctl/spp_proc.py
+++ b/src/spp-ctl/spp_proc.py
@@ -145,12 +145,12 @@ class NfvProc(SppProc):
         return "status"
 
     @exec_command
-    def port_add(self, if_type, if_num):
-        return "add {if_type} {if_num}".format(**locals())
+    def port_add(self, port):
+        return "add {port}".format(**locals())
 
     @exec_command
-    def port_del(self, if_type, if_num):
-        return "del {if_type} {if_num}".format(**locals())
+    def port_del(self, port):
+        return "del {port}".format(**locals())
 
     @exec_command
     def patch_add(self, src_port, dst_port):
-- 
2.7.4

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

* [spp] [PATCH v2 4/4] spp-ctl: update parsing status
  2018-10-11 10:33 ` [spp] [PATCH v2 0/4] Update response of status of spp_nfv and spp_vm ogawa.yasufumi
                     ` (2 preceding siblings ...)
  2018-10-11 10:33   ` [spp] [PATCH v2 3/4] spp-ctl: update syntax of add and del command ogawa.yasufumi
@ 2018-10-11 10:33   ` ogawa.yasufumi
  3 siblings, 0 replies; 12+ messages in thread
From: ogawa.yasufumi @ 2018-10-11 10:33 UTC (permalink / raw)
  To: spp, ferruh.yigit, ogawa.yasufumi

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

Update parsing the result of status. Spp_nfv and spp_vm are changed to
return the same status message as spp-ctl, so it can be used without
modifying.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/spp-ctl/spp_webapi.py | 39 ++++++++++-----------------------------
 1 file changed, 10 insertions(+), 29 deletions(-)

diff --git a/src/spp-ctl/spp_webapi.py b/src/spp-ctl/spp_webapi.py
index ddf6513..c81d0b7 100644
--- a/src/spp-ctl/spp_webapi.py
+++ b/src/spp-ctl/spp_webapi.py
@@ -321,33 +321,15 @@ class V1NFVHandler(BaseHandler):
     def convert_nfv_info(self, sec_id, data):
         nfv = {}
 
-        # spp_nfv returns status info in two lines. First line is
-        # status of running or idling, and second is patch info.
-        # 'null' means that it has no dst port.
-        #   "status: idling\nports: 'phy:0-phy:1,phy:1-null'\x00\x00.."
-        entries = data.split('\n')
-        if len(entries) != 2:
-            return {}
-
-        nfv['client_id'] = int(sec_id)
-        nfv['status'] = entries[0].split()[1]
-
-        patch_list = entries[1].split()[1].replace("'", '')
-
-        ports = []
-        nfv['patches'] = []
-
-        for port_cmb in patch_list.split(','):
-            p_src, p_dst = port_cmb.split('-')
-            if p_src != 'null' and p_dst != 'null':
-                nfv['patches'].append({'src': p_src, 'dst': p_dst})
-
-            for port in [p_src, p_dst]:
-                if port != 'null':
-                    ports.append(port)
-
-        nfv['ports'] = list(set(ports))
+        # spp_nfv returns status info in JSON format. 'null' means
+        # that it has no dst port.
+        #   {"status":"idling","ports":[{"src":"phy:0","dst":"null"},...
 
+        # TODO(yasufum) modify after nfv and vm is updated for new data definition.
+        try:
+            nfv = json.loads(data)
+        except json.JSONDecodeError as e:
+            print("%s" % e)
         return nfv
 
     def nfv_get(self, proc):
@@ -376,11 +358,10 @@ class V1NFVHandler(BaseHandler):
     def nfv_port(self, proc, body):
         self._validate_nfv_port(body)
 
-        if_type, if_num = body['port'].split(":")
         if body['action'] == "add":
-            proc.port_add(if_type, if_num)
+            proc.port_add(body['port'])
         else:
-            proc.port_del(if_type, if_num)
+            proc.port_del(body['port'])
 
     def _validate_nfv_patch(self, body):
         for key in ['src', 'dst']:
-- 
2.7.4

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

end of thread, other threads:[~2018-10-11 10:33 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-09 10:50 [spp] [PATCH 0/4] Update response of status of spp_nfv and spp_vm ogawa.yasufumi
2018-10-09 10:50 ` [spp] [PATCH 1/4] shared: update status format of spp_nfv ogawa.yasufumi
2018-10-09 10:50 ` [spp] [PATCH 2/4] controller: update parsing status message ogawa.yasufumi
2018-10-09 10:50 ` [spp] [PATCH 3/4] spp-ctl: update syntax of add and del command ogawa.yasufumi
2018-10-09 21:56   ` Itsuro ODA
2018-10-10  4:41     ` Yasufumi Ogawa
2018-10-09 10:50 ` [spp] [PATCH 4/4] spp-ctl: update parsing status ogawa.yasufumi
2018-10-11 10:33 ` [spp] [PATCH v2 0/4] Update response of status of spp_nfv and spp_vm ogawa.yasufumi
2018-10-11 10:33   ` [spp] [PATCH v2 1/4] shared: update status format of spp_nfv ogawa.yasufumi
2018-10-11 10:33   ` [spp] [PATCH v2 2/4] controller: update parsing status message ogawa.yasufumi
2018-10-11 10:33   ` [spp] [PATCH v2 3/4] spp-ctl: update syntax of add and del command ogawa.yasufumi
2018-10-11 10:33   ` [spp] [PATCH v2 4/4] spp-ctl: update parsing 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).