Soft Patch Panel
 help / color / mirror / Atom feed
* [spp] [PATCH 1/3] spp_nfv: enable to patch ports with resource ID
@ 2018-02-08 15:17 ogawa.yasufumi
  2018-02-08 15:17 ` [spp] [PATCH 2/3] spp: add validation for patch command ogawa.yasufumi
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: ogawa.yasufumi @ 2018-02-08 15:17 UTC (permalink / raw)
  To: ferruh.yigit, spp; +Cc: ogawa.yasufumi

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

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

In spp, port ID is assigned as a number incrementally and the number of
ID can be different from each sec processes. It depends on the order of
adding ports.

It is confusing to users for patching because each of sec processes has
different port IDs but they refer the same resource. It might cause a
mistake.

This update enables users to patch ports with a combination of port type
and number to identify resources as following.
  spp> sec 1;patch phy:0 ring:0

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

diff --git a/src/nfv/nfv.c b/src/nfv/nfv.c
index 9c92bee..1dc996a 100644
--- a/src/nfv/nfv.c
+++ b/src/nfv/nfv.c
@@ -59,6 +59,48 @@ struct port_info *ports;
 
 static struct port ports_fwd_array[RTE_MAX_ETHPORTS];
 
+/* It is used to convert port name from string type to enum */
+struct porttype_map {
+	const char     *port_name;
+	enum port_type port_type;
+};
+
+struct porttype_map portmap[] = {
+	{ .port_name = "phy",   .port_type = PHY, },
+	{ .port_name = "ring",  .port_type = RING, },
+	{ .port_name = "vhost", .port_type = VHOST, },
+	{ .port_name = NULL,    .port_type = UNDEF, },
+};
+
+/* Return a type of port as a enum member of porttype_map structure. */
+static enum port_type get_port_type(char *portname)
+{
+	for (int i = 0; portmap[i].port_name != NULL; i++) {
+		const char *port_name = portmap[i].port_name;
+		if (strncmp(portname, port_name, strlen(port_name)) == 0)
+			return portmap[i].port_type;
+	}
+	return UNDEF;
+}
+
+/*
+ * Split a token into words  with given separator and return the number of
+ * splitted words.
+ */
+static int spp_split(char *splitted_words[], char *token, const char *sep)
+{
+	int cnt = 0;
+	splitted_words[cnt] = strtok(token, sep);
+	while (splitted_words[cnt] != NULL) {
+		RTE_LOG(DEBUG, APP, "token %d = %s\n",
+				cnt, splitted_words[cnt]);
+		cnt++;
+		splitted_words[cnt] = strtok(NULL, sep);
+	}
+	return cnt;
+}
+
+
 /*
  * print a usage message
  */
@@ -720,10 +762,43 @@ parse_command(char *str)
 			if (max_token <= 2)
 				return 0;
 
-			if (spp_atoi(token_list[1], &in_port) < 0)
-				return 0;
+			if (spp_atoi(token_list[1], &in_port) < 0) {
+				char *param_list[MAX_PARAMETER] = { 0 };
+				int param_count = spp_split(
+						param_list, token_list[1], ":");
+				if (param_count == 2) {
+					int in_port_id;
+					if (spp_atoi(
+						param_list[1], &in_port_id) < 0)
+						return 0;
+					in_port = find_port_id(
+						in_port_id,
+						get_port_type(param_list[0]));
+				} else {
+					return 0;
+				}
+			}
+
+			if (spp_atoi(token_list[2], &out_port) < 0) {
+				char *param_list[MAX_PARAMETER] = { 0 };
+				int param_count = spp_split(
+						param_list,
+						token_list[2], ":");
+				if (param_count == 2) {
+					int out_port_id;
+					if (spp_atoi(
+						param_list[1],
+						&out_port_id) < 0)
+						return 0;
+					out_port = find_port_id(
+						out_port_id,
+						get_port_type(param_list[0]));
+				} else {
+					return 0;
+				}
+			}
 
-			if (spp_atoi(token_list[2], &out_port) < 0)
+			if (in_port < 0 || out_port < 0)
 				return 0;
 
 			add_patch(in_port, out_port);
-- 
2.7.4

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

* [spp] [PATCH 2/3] spp: add validation for patch command
  2018-02-08 15:17 [spp] [PATCH 1/3] spp_nfv: enable to patch ports with resource ID ogawa.yasufumi
@ 2018-02-08 15:17 ` ogawa.yasufumi
  2018-02-08 15:17 ` [spp] [PATCH 3/3] spp_vm: enable to patch ports with resource ID ogawa.yasufumi
  2018-02-22 10:52 ` [spp] [PATCH 1/3] spp_nfv: " Ferruh Yigit
  2 siblings, 0 replies; 5+ messages in thread
From: ogawa.yasufumi @ 2018-02-08 15:17 UTC (permalink / raw)
  To: ferruh.yigit, spp; +Cc: ogawa.yasufumi

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

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

To support patch command with port ID and resource ID, add validation
for format of ID. 'is_patched_ids_valid' method is for checking given
IDs are valid or not.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/spp.py | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/src/spp.py b/src/spp.py
index 20eb59f..3796670 100755
--- a/src/spp.py
+++ b/src/spp.py
@@ -358,6 +358,8 @@ class Shell(cmd.Cmd):
     CMD_NOTREADY = "NOTREADY"
     CMD_ERROR = "ERROR"
 
+    PORT_TYPES = ['phy', 'ring', 'vhost']
+
     PRI_CMDS = ['status', 'exit', 'clear']
     SEC_CMDS = ['status', 'exit', 'forward', 'stop', 'add', 'patch', 'del']
     SEC_SUBCMDS = ['vhost', 'ring', 'pcap', 'nullpmd']
@@ -427,6 +429,25 @@ class Shell(cmd.Cmd):
             print(message)
             return self.CMD_NOTREADY, message
 
+    def is_patched_ids_valid(self, id1, id2, delim=':'):
+        """Check if port IDs are valid
+
+        Supported format is port ID of integer or resource ID such as
+        'phy:0' or 'ring:1'. Default delimiter ':' can be overwritten
+        by giving 'delim' option.
+        """
+
+        if str.isdigit(id1) and str.isdigit(id2):
+            return True
+        else:
+            ptn = r"\w+\%s\d+" % delim  # Match "phy:0" or "ring:1" or so
+            if re.match(ptn, id1) and re.match(ptn, id2):
+                pt1 = id1.split(delim)[0]
+                pt2 = id2.split(delim)[0]
+                if (pt1 in self.PORT_TYPES) and (pt2 in self.PORT_TYPES):
+                    return True
+        return False
+
     def check_sec_cmds(self, cmds):
         """Validate secondary commands before sending"""
 
@@ -452,7 +473,7 @@ class Shell(cmd.Cmd):
                         if str.isdigit(cmdlist[2]):
                             valid = 1
                 elif cmdlist[0] == 'patch':
-                    if str.isdigit(cmdlist[1]) and str.isdigit(cmdlist[2]):
+                    if self.is_patched_ids_valid(cmdlist[1], cmdlist[2]):
                         valid = 1
 
         return valid
-- 
2.7.4

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

* [spp] [PATCH 3/3] spp_vm: enable to patch ports with resource ID
  2018-02-08 15:17 [spp] [PATCH 1/3] spp_nfv: enable to patch ports with resource ID ogawa.yasufumi
  2018-02-08 15:17 ` [spp] [PATCH 2/3] spp: add validation for patch command ogawa.yasufumi
@ 2018-02-08 15:17 ` ogawa.yasufumi
  2018-02-22 10:52 ` [spp] [PATCH 1/3] spp_nfv: " Ferruh Yigit
  2 siblings, 0 replies; 5+ messages in thread
From: ogawa.yasufumi @ 2018-02-08 15:17 UTC (permalink / raw)
  To: ferruh.yigit, spp; +Cc: ogawa.yasufumi

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

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

This patch is same as commit e338799
for spp_nfv. It enables users to patch ports with a combination of
port type and number to identify resources as following.
  spp> sec 1;patch phy:0 ring:0

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

diff --git a/src/vm/main.c b/src/vm/main.c
index c9f1571..52f381f 100644
--- a/src/vm/main.c
+++ b/src/vm/main.c
@@ -49,6 +49,47 @@ static struct port_map port_map[RTE_MAX_ETHPORTS];
 
 static struct port ports_fwd_array[RTE_MAX_ETHPORTS];
 
+/* It is used to convert port name from string type to enum */
+struct porttype_map {
+	const char     *port_name;
+	enum port_type port_type;
+};
+
+struct porttype_map portmap[] = {
+	{ .port_name = "phy",   .port_type = PHY, },
+	{ .port_name = "ring",  .port_type = RING, },
+	{ .port_name = "vhost", .port_type = VHOST, },
+	{ .port_name = NULL,    .port_type = UNDEF, },
+};
+
+/* Return a type of port as a enum member of porttype_map structure. */
+static enum port_type get_port_type(char *portname)
+{
+	for (int i = 0; portmap[i].port_name != NULL; i++) {
+		const char *port_name = portmap[i].port_name;
+		if (strncmp(portname, port_name, strlen(port_name)) == 0)
+			return portmap[i].port_type;
+	}
+	return UNDEF;
+}
+
+/*
+ * Split a token into words  with given separator and return the number of
+ * splitted words.
+ */
+static int spp_split(char *splitted_words[], char *token, const char *sep)
+{
+	int cnt = 0;
+	splitted_words[cnt] = strtok(token, sep);
+	while (splitted_words[cnt] != NULL) {
+		RTE_LOG(DEBUG, APP, "token %d = %s\n",
+				cnt, splitted_words[cnt]);
+		cnt++;
+		splitted_words[cnt] = strtok(NULL, sep);
+	}
+	return cnt;
+}
+
 static void
 forward(void)
 {
@@ -406,7 +447,8 @@ parse_command(char *str)
 			i = sprintf(str, "Client ID %d Running\n", client_id);
 		else
 			i = sprintf(str, "Client ID %d Idling\n", client_id);
-		print_active_ports(str + i, client_id, ports_fwd_array, port_map);
+		print_active_ports(
+				str+i, client_id, ports_fwd_array, port_map);
 
 	} else if (!strcmp(token_list[0], "_get_client_id")) {
 		memset(str, '\0', MSG_SIZE);
@@ -452,10 +494,43 @@ parse_command(char *str)
 			if (max_token <= 2)
 				return 0;
 
-			if (spp_atoi(token_list[1], &in_port) < 0)
-				return 0;
-
-			if (spp_atoi(token_list[2], &out_port) < 0)
+			if (spp_atoi(token_list[1], &in_port) < 0) {
+				char *param_list[MAX_PARAMETER] = { 0 };
+				int param_count = spp_split(
+						param_list, token_list[1], ":");
+				if (param_count == 2) {
+					int in_port_id;
+					if (spp_atoi(
+						param_list[1], &in_port_id) < 0)
+						return 0;
+					in_port = find_port_id(
+						in_port_id,
+						get_port_type(param_list[0]));
+				} else {
+					return 0;
+				}
+			}
+
+			if (spp_atoi(token_list[2], &out_port) < 0) {
+				char *param_list[MAX_PARAMETER] = { 0 };
+				int param_count = spp_split(
+						param_list,
+						token_list[2], ":");
+				if (param_count == 2) {
+					int out_port_id;
+					if (spp_atoi(
+						param_list[1],
+						&out_port_id) < 0)
+						return 0;
+					out_port = find_port_id(
+						out_port_id,
+						get_port_type(param_list[0]));
+				} else {
+					return 0;
+				}
+			}
+
+			if (in_port < 0 || out_port < 0)
 				return 0;
 
 			add_patch(in_port, out_port);
-- 
2.7.4

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

* Re: [spp] [PATCH 1/3] spp_nfv: enable to patch ports with resource ID
  2018-02-08 15:17 [spp] [PATCH 1/3] spp_nfv: enable to patch ports with resource ID ogawa.yasufumi
  2018-02-08 15:17 ` [spp] [PATCH 2/3] spp: add validation for patch command ogawa.yasufumi
  2018-02-08 15:17 ` [spp] [PATCH 3/3] spp_vm: enable to patch ports with resource ID ogawa.yasufumi
@ 2018-02-22 10:52 ` Ferruh Yigit
  2 siblings, 0 replies; 5+ messages in thread
From: Ferruh Yigit @ 2018-02-22 10:52 UTC (permalink / raw)
  To: Yasufumi Ogawa; +Cc: spp

On 2/8/2018 3:17 PM, ogawa.yasufumi at lab.ntt.co.jp
(ogawa.yasufumi@lab.ntt.co.jp) wrote:
> From: "ogawa.yasufumi@lab.ntt.co.jp" <ogawa.yasufumi@lab.ntt.co.jp>
> 
> From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
> 
> In spp, port ID is assigned as a number incrementally and the number of
> ID can be different from each sec processes. It depends on the order of
> adding ports.
> 
> It is confusing to users for patching because each of sec processes has
> different port IDs but they refer the same resource. It might cause a
> mistake.
> 
> This update enables users to patch ports with a combination of port type
> and number to identify resources as following.
>   spp> sec 1;patch phy:0 ring:0
> 
> Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>

Series applied to dpdk-next-net/master, thanks.

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

* [spp] [PATCH 3/3] spp_vm: enable to patch ports with resource ID
  2018-01-29 12:44 ogawa.yasufumi
@ 2018-01-29 12:47 ` ogawa.yasufumi
  0 siblings, 0 replies; 5+ messages in thread
From: ogawa.yasufumi @ 2018-01-29 12:47 UTC (permalink / raw)
  To: spp, ferruh.yigit, geminoa; +Cc: ogawa.yasufumi

From: ogawa.yasufumi@lab.ntt.co.jp

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

This patch is same as commit e338799
for spp_nfv. It enables users to patch ports with a combination of
port type and number to identify resources as following.
  spp> sec 1;patch phy:0 ring:0

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

diff --git a/src/vm/main.c b/src/vm/main.c
index c9f1571..52f381f 100644
--- a/src/vm/main.c
+++ b/src/vm/main.c
@@ -49,6 +49,47 @@ static struct port_map port_map[RTE_MAX_ETHPORTS];
 
 static struct port ports_fwd_array[RTE_MAX_ETHPORTS];
 
+/* It is used to convert port name from string type to enum */
+struct porttype_map {
+	const char     *port_name;
+	enum port_type port_type;
+};
+
+struct porttype_map portmap[] = {
+	{ .port_name = "phy",   .port_type = PHY, },
+	{ .port_name = "ring",  .port_type = RING, },
+	{ .port_name = "vhost", .port_type = VHOST, },
+	{ .port_name = NULL,    .port_type = UNDEF, },
+};
+
+/* Return a type of port as a enum member of porttype_map structure. */
+static enum port_type get_port_type(char *portname)
+{
+	for (int i = 0; portmap[i].port_name != NULL; i++) {
+		const char *port_name = portmap[i].port_name;
+		if (strncmp(portname, port_name, strlen(port_name)) == 0)
+			return portmap[i].port_type;
+	}
+	return UNDEF;
+}
+
+/*
+ * Split a token into words  with given separator and return the number of
+ * splitted words.
+ */
+static int spp_split(char *splitted_words[], char *token, const char *sep)
+{
+	int cnt = 0;
+	splitted_words[cnt] = strtok(token, sep);
+	while (splitted_words[cnt] != NULL) {
+		RTE_LOG(DEBUG, APP, "token %d = %s\n",
+				cnt, splitted_words[cnt]);
+		cnt++;
+		splitted_words[cnt] = strtok(NULL, sep);
+	}
+	return cnt;
+}
+
 static void
 forward(void)
 {
@@ -406,7 +447,8 @@ parse_command(char *str)
 			i = sprintf(str, "Client ID %d Running\n", client_id);
 		else
 			i = sprintf(str, "Client ID %d Idling\n", client_id);
-		print_active_ports(str + i, client_id, ports_fwd_array, port_map);
+		print_active_ports(
+				str+i, client_id, ports_fwd_array, port_map);
 
 	} else if (!strcmp(token_list[0], "_get_client_id")) {
 		memset(str, '\0', MSG_SIZE);
@@ -452,10 +494,43 @@ parse_command(char *str)
 			if (max_token <= 2)
 				return 0;
 
-			if (spp_atoi(token_list[1], &in_port) < 0)
-				return 0;
-
-			if (spp_atoi(token_list[2], &out_port) < 0)
+			if (spp_atoi(token_list[1], &in_port) < 0) {
+				char *param_list[MAX_PARAMETER] = { 0 };
+				int param_count = spp_split(
+						param_list, token_list[1], ":");
+				if (param_count == 2) {
+					int in_port_id;
+					if (spp_atoi(
+						param_list[1], &in_port_id) < 0)
+						return 0;
+					in_port = find_port_id(
+						in_port_id,
+						get_port_type(param_list[0]));
+				} else {
+					return 0;
+				}
+			}
+
+			if (spp_atoi(token_list[2], &out_port) < 0) {
+				char *param_list[MAX_PARAMETER] = { 0 };
+				int param_count = spp_split(
+						param_list,
+						token_list[2], ":");
+				if (param_count == 2) {
+					int out_port_id;
+					if (spp_atoi(
+						param_list[1],
+						&out_port_id) < 0)
+						return 0;
+					out_port = find_port_id(
+						out_port_id,
+						get_port_type(param_list[0]));
+				} else {
+					return 0;
+				}
+			}
+
+			if (in_port < 0 || out_port < 0)
 				return 0;
 
 			add_patch(in_port, out_port);
-- 
2.7.4

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

end of thread, other threads:[~2018-02-22 10:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-08 15:17 [spp] [PATCH 1/3] spp_nfv: enable to patch ports with resource ID ogawa.yasufumi
2018-02-08 15:17 ` [spp] [PATCH 2/3] spp: add validation for patch command ogawa.yasufumi
2018-02-08 15:17 ` [spp] [PATCH 3/3] spp_vm: enable to patch ports with resource ID ogawa.yasufumi
2018-02-22 10:52 ` [spp] [PATCH 1/3] spp_nfv: " Ferruh Yigit
  -- strict thread matches above, loose matches on Subject: below --
2018-01-29 12:44 ogawa.yasufumi
2018-01-29 12:47 ` [spp] [PATCH 3/3] spp_vm: " 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).