Soft Patch Panel
 help / color / mirror / Atom feed
From: ogawa.yasufumi@lab.ntt.co.jp
To: spp@dpdk.org, ferruh.yigit@intel.com, geminoa@juno.ocn.ne.jp
Cc: ogawa.yasufumi@lab.ntt.co.jp
Subject: [spp] [PATCH 1/3] spp_nfv: enable to patch ports with resource ID
Date: Mon, 29 Jan 2018 21:44:01 +0900	[thread overview]
Message-ID: <20180129122506.75403-1-ogawa.yasufumi@lab.ntt.co.jp> (raw)

From: 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<Paste>

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 5972657..d62626c 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
  */
@@ -555,10 +597,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

             reply	other threads:[~2018-01-29 12:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-29 12:44 ogawa.yasufumi [this message]
2018-01-29 12:46 ` [spp] [PATCH 2/3] spp: add validation for patch command ogawa.yasufumi
2018-01-29 12:47 ` [spp] [PATCH 3/3] spp_vm: enable to patch ports with resource ID ogawa.yasufumi
2018-02-08 15:17 [spp] [PATCH 1/3] spp_nfv: " ogawa.yasufumi
2018-02-22 10:52 ` Ferruh Yigit

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=20180129122506.75403-1-ogawa.yasufumi@lab.ntt.co.jp \
    --to=ogawa.yasufumi@lab.ntt.co.jp \
    --cc=ferruh.yigit@intel.com \
    --cc=geminoa@juno.ocn.ne.jp \
    --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).