Soft Patch Panel
 help / color / mirror / Atom feed
From: ogawa.yasufumi@lab.ntt.co.jp
To: spp@dpdk.org, ferruh.yigit@intel.com, ogawa.yasufumi@lab.ntt.co.jp
Subject: [spp] [PATCH 2/4] spp_nfv: change to use parse_resource_uid
Date: Tue,  9 Oct 2018 19:48:45 +0900	[thread overview]
Message-ID: <20181009104847.42502-3-ogawa.yasufumi@lab.ntt.co.jp> (raw)
In-Reply-To: <20181009104847.42502-1-ogawa.yasufumi@lab.ntt.co.jp>

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

To simplify parsing resource UID, replace spp_split() to
parse_resource_uid(). spp_split() is removed because it is not needed
anymore.

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

diff --git a/src/nfv/nfv.c b/src/nfv/nfv.c
index f036f62..0ccabac 100644
--- a/src/nfv/nfv.c
+++ b/src/nfv/nfv.c
@@ -57,24 +57,6 @@ static enum port_type get_port_type(char *portname)
 }
 
 /*
- * 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
  */
 static void
@@ -303,53 +285,42 @@ find_port_id(int id, enum port_type type)
 }
 
 static int
-do_del(char *token_list[], int max_token)
+do_del(char *res_uid)
 {
 	int port_id = PORT_RESET;
-	int id;
+	char *p_type;
+	int p_id;
 
-	if (max_token <= 2)
-		return -1;
-
-	if (!strcmp(token_list[1], "vhost")) {
-		if (spp_atoi(token_list[2], &id) < 0)
-			return 0;
+	parse_resource_uid(res_uid, &p_type, &p_id);
 
-		port_id = find_port_id(id, VHOST);
+	if (!strcmp(p_type, "vhost")) {
+		port_id = find_port_id(p_id, VHOST);
 		if (port_id < 0)
 			return -1;
 
-	} else if (!strcmp(token_list[1], "ring")) {
+	} else if (!strcmp(p_type, "ring")) {
 		char name[RTE_ETH_NAME_MAX_LEN];
 
-		if (spp_atoi(token_list[2], &id) < 0)
-			return 0;
-
-		port_id = find_port_id(id, RING);
+		RTE_LOG(DEBUG, APP, "Del ring id %d\n", p_id);
+		port_id = find_port_id(p_id, RING);
 		if (port_id < 0)
 			return -1;
 
 		rte_eth_dev_detach(port_id, name);
 
-	} else if (!strcmp(token_list[1], "pcap")) {
+	} else if (!strcmp(p_type, "pcap")) {
 		char name[RTE_ETH_NAME_MAX_LEN];
 
-		if (spp_atoi(token_list[2], &id) < 0)
-			return 0;
-
-		port_id = find_port_id(id, PCAP);
+		port_id = find_port_id(p_id, PCAP);
 		if (port_id < 0)
 			return -1;
 
 		rte_eth_dev_detach(port_id, name);
 
-	} else if (!strcmp(token_list[1], "nullpmd")) {
+	} else if (!strcmp(p_type, "nullpmd")) {
 		char name[RTE_ETH_NAME_MAX_LEN];
 
-		if (spp_atoi(token_list[2], &id) < 0)
-			return 0;
-
-		port_id = find_port_id(id, NULLPMD);
+		port_id = find_port_id(p_id, NULLPMD);
 		if (port_id < 0)
 			return -1;
 
@@ -667,51 +638,44 @@ add_null_pmd(int index)
 	return null_pmd_port_id;
 }
 
+/**
+ * Add a port to this process. Port is described with resource UID which is a
+ * combination of port type and ID like as 'ring:0'.
+ */
 static int
-do_add(char *token_list[], int max_token)
+do_add(char *res_uid)
 {
 	enum port_type type = UNDEF;
 	int port_id = PORT_RESET;
-	int id;
 
-	if (max_token <= 2)
-		return -1;
+	char *p_type;
+	int p_id;
 
-	if (!strcmp(token_list[1], "vhost")) {
-		if (spp_atoi(token_list[2], &id) < 0)
-			return 0;
+	parse_resource_uid(res_uid, &p_type, &p_id);
 
+	if (!strcmp(p_type, "vhost")) {
 		type = VHOST;
-		port_id = add_vhost_pmd(id);
-
-	} else if (!strcmp(token_list[1], "ring")) {
-		if (spp_atoi(token_list[2], &id) < 0)
-			return 0;
+		port_id = add_vhost_pmd(p_id);
 
+	} else if (!strcmp(p_type, "ring")) {
 		type = RING;
-		port_id = add_ring_pmd(id);
-
-	} else if (!strcmp(token_list[1], "pcap")) {
-		if (spp_atoi(token_list[2], &id) < 0)
-			return 0;
+		port_id = add_ring_pmd(p_id);
 
+	} else if (!strcmp(p_type, "pcap")) {
 		type = PCAP;
-		port_id = add_pcap_pmd(id);
-
-	} else if (!strcmp(token_list[1], "nullpmd")) {
-		if (spp_atoi(token_list[2], &id) < 0)
-			return 0;
+		port_id = add_pcap_pmd(p_id);
 
+	} else if (!strcmp(p_type, "nullpmd")) {
 		type = NULLPMD;
-		port_id = add_null_pmd(id);
+		port_id = add_null_pmd(p_id);
 	}
 
 	if (port_id < 0)
 		return -1;
 
-	port_map[port_id].id = id;
+	port_map[port_id].id = p_id;
 	port_map[port_id].port_type = type;
-	port_map[port_id].stats = &ports->client_stats[id];
+	port_map[port_id].stats = &ports->client_stats[p_id];
 
 	/* Update ports_fwd_array with port id */
 	ports_fwd_array[port_id].in_port_id = port_id;
@@ -777,7 +741,7 @@ parse_command(char *str)
 
 	} else if (!strcmp(token_list[0], "add")) {
 		RTE_LOG(DEBUG, APP, "add\n");
-		do_add(token_list, max_token);
+		do_add(token_list[1]);
 
 	} else if (!strcmp(token_list[0], "patch")) {
 		RTE_LOG(DEBUG, APP, "patch\n");
@@ -795,41 +759,14 @@ parse_command(char *str)
 			if (max_token <= 2)
 				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;
-				}
-			}
+			char *p_type;
+			int p_id;
 
-			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;
-				}
-			}
+			parse_resource_uid(token_list[1], &p_type, &p_id);
+			in_port = find_port_id(p_id, get_port_type(p_type));
+
+			parse_resource_uid(token_list[2], &p_type, &p_id);
+			out_port = find_port_id(p_id, get_port_type(p_type));
 
 			if (in_port < 0 || out_port < 0)
 				return 0;
@@ -841,7 +778,7 @@ parse_command(char *str)
 		RTE_LOG(DEBUG, APP, "del\n");
 
 		cmd = STOP;
-		do_del(token_list, max_token);
+		do_del(token_list[1]);
 	}
 
 	return ret;
-- 
2.7.4

  parent reply	other threads:[~2018-10-09 10:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-09 10:48 [spp] [PATCH 0/4] Port management with resource UID ogawa.yasufumi
2018-10-09 10:48 ` [spp] [PATCH 1/4] shared: add parsing " ogawa.yasufumi
2018-10-09 10:48 ` ogawa.yasufumi [this message]
2018-10-09 10:48 ` [spp] [PATCH 3/4] spp_vm: change to use parse_resource_uid ogawa.yasufumi
2018-10-09 10:48 ` [spp] [PATCH 4/4] controller: unify accepting resource UID format ogawa.yasufumi

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=20181009104847.42502-3-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).