Soft Patch Panel
 help / color / Atom feed
* [spp] [PATCH 0/4] Remove global vars of IP and port of spp-ctl
@ 2019-06-24 10:44 yasufum.o
  2019-06-24 10:44 ` [spp] [PATCH 1/4] spp_nfv: remove global vars of spp-ctl IP and port yasufum.o
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: yasufum.o @ 2019-06-24 10:44 UTC (permalink / raw)
  To: spp, ferruh.yigit, yasufum.o

From: Yasufumi Ogawa <yasufum.o@gmail.com>

In secondary processes, IP address and port given as command args are
defined as global variables, but no need to be global. This update is to
change them to be retrieved from functions and remove global
variables.

Yasufumi Ogawa (4):
  spp_nfv: remove global vars of spp-ctl IP and port
  spp_vf: remove global vars of spp-ctl IP and port
  spp_mirror: remove global vars spp-ctl IP and port
  spp_pcap: remove global vars spp-ctl IP and port

 src/mirror/spp_mirror.c | 60 ++++++++++++-------------------
 src/nfv/commands.h      |  6 ++--
 src/nfv/main.c          |  6 +++-
 src/nfv/params.h        |  7 ----
 src/pcap/spp_pcap.c     | 78 +++++++++++++++++------------------------
 src/shared/common.c     | 48 +++++++++++++++++++++++++
 src/shared/common.h     | 42 +++++++++++++++++++++-
 src/vf/spp_vf.c         | 60 ++++++++++++-------------------
 8 files changed, 175 insertions(+), 132 deletions(-)

-- 
2.17.1


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

* [spp] [PATCH 1/4] spp_nfv: remove global vars of spp-ctl IP and port
  2019-06-24 10:44 [spp] [PATCH 0/4] Remove global vars of IP and port of spp-ctl yasufum.o
@ 2019-06-24 10:44 ` yasufum.o
  2019-06-24 10:44 ` [spp] [PATCH 2/4] spp_vf: " yasufum.o
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: yasufum.o @ 2019-06-24 10:44 UTC (permalink / raw)
  To: spp, ferruh.yigit, yasufum.o

From: Yasufumi Ogawa <yasufum.o@gmail.com>

This update is to remove global variable of IP address and port number
of spp-ctl, and functions for gettting and setting them instead.

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 src/nfv/commands.h  |  6 ++++--
 src/nfv/main.c      |  6 +++++-
 src/nfv/params.h    |  7 -------
 src/shared/common.c | 48 +++++++++++++++++++++++++++++++++++++++++++++
 src/shared/common.h | 42 ++++++++++++++++++++++++++++++++++++++-
 5 files changed, 98 insertions(+), 11 deletions(-)

diff --git a/src/nfv/commands.h b/src/nfv/commands.h
index 708d084..11e434a 100644
--- a/src/nfv/commands.h
+++ b/src/nfv/commands.h
@@ -116,6 +116,7 @@ do_connection(int *connected, int *sock)
 {
 	static struct sockaddr_in servaddr;
 	int ret = 0;
+	char ctl_ip[IPADDR_LEN] = { 0 };  /* spp_ctl's IP addr. */
 
 	if (*connected == 0) {
 		if (*sock < 0) {
@@ -127,8 +128,9 @@ do_connection(int *connected, int *sock)
 			/*Create of the tcp socket*/
 			memset(&servaddr, 0, sizeof(servaddr));
 			servaddr.sin_family = AF_INET;
-			servaddr.sin_addr.s_addr = inet_addr(server_ip);
-			servaddr.sin_port = htons(server_port);
+			get_spp_ctl_ip(ctl_ip);
+			servaddr.sin_addr.s_addr = inet_addr(ctl_ip);
+			servaddr.sin_port = htons(get_spp_ctl_port());
 		}
 
 		RTE_LOG(INFO,
diff --git a/src/nfv/main.c b/src/nfv/main.c
index ae4168c..9cfe49a 100644
--- a/src/nfv/main.c
+++ b/src/nfv/main.c
@@ -65,6 +65,8 @@ parse_app_args(int argc, char *argv[])
 	int cli_id;
 	char **argvopt = argv;
 	const char *progname = argv[0];
+	char *ctl_ip;  /* IP address of spp_ctl. */
+	int ctl_port;  /* Port num to connect spp_ctl. */
 	int ret;
 
 	while ((opt = getopt_long(argc, argvopt, "n:s:", lgopts,
@@ -81,7 +83,9 @@ parse_app_args(int argc, char *argv[])
 			set_client_id(cli_id);
 			break;
 		case 's':
-			ret = parse_server(&server_ip, &server_port, optarg);
+			ret = parse_server(&ctl_ip, &ctl_port, optarg);
+			set_spp_ctl_ip(ctl_ip);
+			set_spp_ctl_port(ctl_port);
 			if (ret != 0) {
 				usage(progname);
 				return -1;
diff --git a/src/nfv/params.h b/src/nfv/params.h
index 9ddf79d..06e6f1f 100644
--- a/src/nfv/params.h
+++ b/src/nfv/params.h
@@ -26,13 +26,6 @@ static struct port ports_fwd_array[RTE_MAX_ETHPORTS];
 /* the port details */
 struct port_info *ports;
 
-/*
- * our client id number - tells us which rx queue to read, and NIC TX
- * queue to write to.
- */
-static char *server_ip;
-static int server_port;
-
 static enum cmd_type cmd;
 
 static struct port_map port_map[RTE_MAX_ETHPORTS];
diff --git a/src/shared/common.c b/src/shared/common.c
index 9c244e5..a195929 100644
--- a/src/shared/common.c
+++ b/src/shared/common.c
@@ -8,6 +8,9 @@
 
 #define RTE_LOGTYPE_SHARED RTE_LOGTYPE_USER1
 
+char spp_ctl_ip[IPADDR_LEN];  /* IP address of spp_ctl. */
+int spp_ctl_port;  /* Port num to connect spp_ctl. */
+
 /**
  * Set log level of type RTE_LOGTYPE_USER* to given level, for instance,
  * RTE_LOG_INFO or RTE_LOG_DEBUG.
@@ -115,3 +118,48 @@ int get_sec_dir(char *proc_name, char *dir_name)
 	}
 	return 0;
 }
+
+/* Get IP address of spp_ctl as string. */
+int get_spp_ctl_ip(char *s_ip)
+{
+	sprintf(s_ip, "%s", spp_ctl_ip);
+	if (spp_ctl_ip == NULL) {
+		RTE_LOG(ERR, SHARED, "Failed to get IP of spp_ctl.\n");
+		return -1;
+	}
+	return 0;
+}
+
+/* Set IP address of spp_ctl. */
+int set_spp_ctl_ip(const char *s_ip)
+{
+	memset(spp_ctl_ip, 0x00, sizeof(spp_ctl_ip));
+	sprintf(spp_ctl_ip, "%s", s_ip);
+	if (spp_ctl_ip == NULL) {
+		RTE_LOG(ERR, SHARED, "Failed to set IP of spp_ctl.\n");
+		return -1;
+	}
+	return 0;
+}
+
+/* Get port number for connecting to spp_ctl as string. */
+int get_spp_ctl_port(void)
+{
+	if (spp_ctl_port < 0) {
+		RTE_LOG(ERR, SHARED, "Server port is not initialized.\n");
+		return -1;
+	}
+	return spp_ctl_port;
+}
+
+/* Set port number for connecting to spp_ctl. */
+int set_spp_ctl_port(int s_port)
+{
+	if (s_port < 0) {
+		RTE_LOG(ERR, SHARED, "Given invalid port number '%d'.\n",
+				s_port);
+		return -1;
+	}
+	spp_ctl_port = s_port;
+	return 0;
+}
diff --git a/src/shared/common.h b/src/shared/common.h
index 9b8d897..78d2520 100644
--- a/src/shared/common.h
+++ b/src/shared/common.h
@@ -10,6 +10,8 @@
 #include <unistd.h>
 #include <rte_ethdev_driver.h>
 
+#define IPADDR_LEN 16  /* Length of IP address in string. */
+
 #define MSG_SIZE 2048  /* socket buffer len */
 
 #define SOCK_RESET  -1
@@ -125,11 +127,49 @@ int set_user_log_level(int num_user_log, uint32_t log_level);
 int set_user_log_debug(int num_user_log);
 
 int parse_num_clients(uint16_t *num_clients, const char *clients);
+
 int parse_server(char **server_ip, int *server_port, char *server_addr);
 
-/* Get directory name of given proc_name */
+/**
+ * Get directory name of given proc_name.
+ *
+ * @param[in] proc_name Name of sec process such as spp_nfv.
+ * @param[out] dir_name Directory name.
+ * @return 0
+ */
 int get_sec_dir(char *proc_name, char *dir_name);
 
 extern uint8_t lcore_id_used[RTE_MAX_LCORE];
 
+/**
+ * Get IP address of spp_ctl as string.
+ *
+ * @param[in,out] s_ip IP address of spp_ctl.
+ * @return 0 if succeeded, or -1 if failed.
+ */
+int get_spp_ctl_ip(char *s_ip);
+
+/**
+ * Set IP address of spp_ctl.
+ *
+ * @param[in] s_ip IP address of spp_ctl.
+ * @return 0 if succeeded, or -1 if failed.
+ */
+int set_spp_ctl_ip(const char *s_ip);
+
+/**
+ * Get port number for connecting to spp_ctl as string.
+ *
+ * @return Port number, or -1 if failed.
+ */
+int get_spp_ctl_port(void);
+
+/**
+ * Set port number for connecting to spp_ctl.
+ *
+ * @param[in] s_port Port number for spp_ctl.
+ * @return 0 if succeeded, or -1 if failed.
+ */
+int set_spp_ctl_port(int s_port);
+
 #endif
-- 
2.17.1


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

* [spp] [PATCH 2/4] spp_vf: remove global vars of spp-ctl IP and port
  2019-06-24 10:44 [spp] [PATCH 0/4] Remove global vars of IP and port of spp-ctl yasufum.o
  2019-06-24 10:44 ` [spp] [PATCH 1/4] spp_nfv: remove global vars of spp-ctl IP and port yasufum.o
@ 2019-06-24 10:44 ` " yasufum.o
  2019-06-24 10:44 ` [spp] [PATCH 3/4] spp_mirror: remove global vars " yasufum.o
  2019-06-24 10:44 ` [spp] [PATCH 4/4] spp_pcap: " yasufum.o
  3 siblings, 0 replies; 5+ messages in thread
From: yasufum.o @ 2019-06-24 10:44 UTC (permalink / raw)
  To: spp, ferruh.yigit, yasufum.o

From: Yasufumi Ogawa <yasufum.o@gmail.com>

This update is to remove global `startup_params` from spp_vf, and change
to use getter and setter for IP addr and port of spp-ctl.

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 src/shared/common.c |  4 +--
 src/vf/spp_vf.c     | 60 +++++++++++++++++----------------------------
 2 files changed, 24 insertions(+), 40 deletions(-)

diff --git a/src/shared/common.c b/src/shared/common.c
index a195929..b261fb0 100644
--- a/src/shared/common.c
+++ b/src/shared/common.c
@@ -122,11 +122,11 @@ int get_sec_dir(char *proc_name, char *dir_name)
 /* Get IP address of spp_ctl as string. */
 int get_spp_ctl_ip(char *s_ip)
 {
-	sprintf(s_ip, "%s", spp_ctl_ip);
 	if (spp_ctl_ip == NULL) {
-		RTE_LOG(ERR, SHARED, "Failed to get IP of spp_ctl.\n");
+		RTE_LOG(ERR, SHARED, "IP addr of spp_ctl not initialized.\n");
 		return -1;
 	}
+	sprintf(s_ip, "%s", spp_ctl_ip);
 	return 0;
 }
 
diff --git a/src/vf/spp_vf.c b/src/vf/spp_vf.c
index f4bafb4..d8098f2 100644
--- a/src/vf/spp_vf.c
+++ b/src/vf/spp_vf.c
@@ -57,44 +57,24 @@ usage(const char *progname)
 			, progname);
 }
 
-/* Parse options for server IP and port */
-static int
-parse_app_server(const char *server_str, char *server_ip, int *server_port)
-{
-	const char delim[2] = ":";
-	unsigned int pos = 0;
-	int port = 0;
-	char *endptr = NULL;
-
-	pos = strcspn(server_str, delim);
-	if (pos >= strlen(server_str))
-		return SPP_RET_NG;
-
-	port = strtol(&server_str[pos+1], &endptr, 0);
-	if (unlikely(&server_str[pos+1] == endptr) ||
-				unlikely(*endptr != '\0'))
-		return SPP_RET_NG;
-
-	memcpy(server_ip, server_str, pos);
-	server_ip[pos] = '\0';
-	*server_port = port;
-	RTE_LOG(DEBUG, APP, "Set server IP   = %s\n", server_ip);
-	RTE_LOG(DEBUG, APP, "Set server port = %d\n", *server_port);
-	return SPP_RET_OK;
-}
-
 /* Parse options for client app */
 static int
 parse_app_args(int argc, char *argv[])
 {
+	int cli_id;  /* Client ID. */
+	char *ctl_ip;  /* IP address of spp_ctl. */
+	int ctl_port;  /* Port num to connect spp_ctl. */
+	int ret;
 	int cnt;
-	int cli_id;
+	int option_index, opt;
+
 	int proc_flg = 0;
 	int server_flg = 0;
-	int option_index, opt;
+
 	const int argcopt = argc;
 	char *argvopt[argcopt];
 	const char *progname = argv[0];
+
 	static struct option lgopts[] = {
 			{ "client-id", required_argument, NULL,
 					SPP_LONGOPT_RETVAL_CLIENT_ID },
@@ -132,9 +112,10 @@ parse_app_args(int argc, char *argv[])
 			g_enable_vhost_cli = 1;
 			break;
 		case 's':
-			if (parse_app_server(optarg, g_startup_param.server_ip,
-					&g_startup_param.server_port) !=
-								SPP_RET_OK) {
+			ret = parse_server(&ctl_ip, &ctl_port, optarg);
+			set_spp_ctl_ip(ctl_ip);
+			set_spp_ctl_port(ctl_port);
+			if (ret != SPP_RET_OK) {
 				usage(progname);
 				return SPP_RET_NG;
 			}
@@ -154,8 +135,7 @@ parse_app_args(int argc, char *argv[])
 	RTE_LOG(INFO, APP,
 			"Parsed app args (client_id=%d,server=%s:%d,"
 			"vhost_client=%d)\n",
-			cli_id, g_startup_param.server_ip,
-			g_startup_param.server_port, g_enable_vhost_cli);
+			cli_id, ctl_ip, ctl_port, g_enable_vhost_cli);
 	return SPP_RET_OK;
 }
 
@@ -222,6 +202,11 @@ int
 main(int argc, char *argv[])
 {
 	int ret = SPP_RET_NG;
+	char ctl_ip[IPADDR_LEN] = { 0 };
+	int ctl_port;
+	int ret_cmd_init;
+	unsigned int lcore_id = 0;
+
 #ifdef SPP_DEMONIZE
 	/* Daemonize process */
 	int ret_daemon = daemon(0, 0);
@@ -274,10 +259,10 @@ main(int argc, char *argv[])
 		spp_port_ability_init();
 
 		/* Setup connection for accepting commands from controller */
-		int ret_command_init = sppwk_cmd_runner_conn(
-				g_startup_param.server_ip,
-				g_startup_param.server_port);
-		if (unlikely(ret_command_init != SPP_RET_OK))
+		get_spp_ctl_ip(ctl_ip);
+		ctl_port = get_spp_ctl_port();
+		ret_cmd_init = sppwk_cmd_runner_conn(ctl_ip, ctl_port);
+		if (unlikely(ret_cmd_init != SPP_RET_OK))
 			break;
 
 #ifdef SPP_RINGLATENCYSTATS_ENABLE
@@ -289,7 +274,6 @@ main(int argc, char *argv[])
 #endif /* SPP_RINGLATENCYSTATS_ENABLE */
 
 		/* Start worker threads of classifier and forwarder */
-		unsigned int lcore_id = 0;
 		RTE_LCORE_FOREACH_SLAVE(lcore_id) {
 			rte_eal_remote_launch(slave_main, NULL, lcore_id);
 		}
-- 
2.17.1


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

* [spp] [PATCH 3/4] spp_mirror: remove global vars spp-ctl IP and port
  2019-06-24 10:44 [spp] [PATCH 0/4] Remove global vars of IP and port of spp-ctl yasufum.o
  2019-06-24 10:44 ` [spp] [PATCH 1/4] spp_nfv: remove global vars of spp-ctl IP and port yasufum.o
  2019-06-24 10:44 ` [spp] [PATCH 2/4] spp_vf: " yasufum.o
@ 2019-06-24 10:44 ` " yasufum.o
  2019-06-24 10:44 ` [spp] [PATCH 4/4] spp_pcap: " yasufum.o
  3 siblings, 0 replies; 5+ messages in thread
From: yasufum.o @ 2019-06-24 10:44 UTC (permalink / raw)
  To: spp, ferruh.yigit, yasufum.o

From: Yasufumi Ogawa <yasufum.o@gmail.com>

This update is to remove global `startup_params` from spp_mirror, and
change to use getter and setter for IP addr and port of spp-ctl.

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 src/mirror/spp_mirror.c | 60 ++++++++++++++++-------------------------
 src/shared/common.c     |  4 +--
 2 files changed, 25 insertions(+), 39 deletions(-)

diff --git a/src/mirror/spp_mirror.c b/src/mirror/spp_mirror.c
index 9d9b4a8..305e977 100644
--- a/src/mirror/spp_mirror.c
+++ b/src/mirror/spp_mirror.c
@@ -101,43 +101,24 @@ usage(const char *progname)
 			, progname);
 }
 
-/* Parse options for server IP and port */
-static int
-parse_app_server(const char *server_str, char *server_ip, int *server_port)
-{
-	const char delim[2] = ":";
-	unsigned int pos = 0;
-	int port = 0;
-	char *endptr = NULL;
-
-	pos = strcspn(server_str, delim);
-	if (pos >= strlen(server_str))
-		return SPP_RET_NG;
-
-	port = strtol(&server_str[pos+1], &endptr, 0);
-	if (unlikely(&server_str[pos+1] == endptr) || unlikely(*endptr != '\0'))
-		return SPP_RET_NG;
-
-	memcpy(server_ip, server_str, pos);
-	server_ip[pos] = '\0';
-	*server_port = port;
-	RTE_LOG(DEBUG, MIRROR, "Set server IP   = %s\n", server_ip);
-	RTE_LOG(DEBUG, MIRROR, "Set server port = %d\n", *server_port);
-	return SPP_RET_OK;
-}
-
 /* Parse options for client app */
 static int
 parse_app_args(int argc, char *argv[])
 {
+	int cli_id;  /* Client ID. */
+	char *ctl_ip;  /* IP address of spp_ctl. */
+	int ctl_port;  /* Port num to connect spp_ctl. */
+	int ret;
 	int cnt;
-	int cli_id;
+	int option_index, opt;
+
 	int proc_flg = 0;
 	int server_flg = 0;
-	int option_index, opt;
+
 	const int argcopt = argc;
 	char *argvopt[argcopt];
 	const char *progname = argv[0];
+
 	static struct option lgopts[] = {
 			{ "client-id", required_argument, NULL,
 					SPP_LONGOPT_RETVAL_CLIENT_ID },
@@ -175,12 +156,13 @@ parse_app_args(int argc, char *argv[])
 			g_enable_vhost_cli = 1;
 			break;
 		case 's':
-			if (parse_app_server(optarg, g_startup_param.server_ip,
-					     &g_startup_param.server_port) !=
-					     SPP_RET_OK) {
+			ret = parse_server(&ctl_ip, &ctl_port, optarg);
+			if (ret != SPP_RET_OK) {
 				usage(progname);
 				return SPP_RET_NG;
 			}
+			set_spp_ctl_ip(ctl_ip);
+			set_spp_ctl_port(ctl_port);
 			server_flg = 1;
 			break;
 		default:
@@ -197,8 +179,7 @@ parse_app_args(int argc, char *argv[])
 	RTE_LOG(INFO, MIRROR,
 			"Parsed app args (client_id=%d, server=%s:%d, "
 			"vhost_client=%d,)\n",
-			cli_id, g_startup_param.server_ip,
-			g_startup_param.server_port, g_enable_vhost_cli);
+			cli_id, ctl_ip, ctl_port, g_enable_vhost_cli);
 	return SPP_RET_OK;
 }
 
@@ -488,6 +469,11 @@ int
 main(int argc, char *argv[])
 {
 	int ret = SPP_RET_NG;
+	char ctl_ip[IPADDR_LEN] = { 0 };
+	int ctl_port;
+	int ret_cmd_init;
+	unsigned int lcore_id;
+
 #ifdef SPP_DEMONIZE
 	/* Daemonize process */
 	int ret_daemon = daemon(0, 0);
@@ -543,10 +529,10 @@ main(int argc, char *argv[])
 		spp_port_ability_init();
 
 		/* Setup connection for accepting commands from controller */
-		int ret_command_init = sppwk_cmd_runner_conn(
-				g_startup_param.server_ip,
-				g_startup_param.server_port);
-		if (unlikely(ret_command_init != SPP_RET_OK))
+		get_spp_ctl_ip(ctl_ip);
+		ctl_port = get_spp_ctl_port();
+		ret_cmd_init = sppwk_cmd_runner_conn(ctl_ip, ctl_port);
+		if (unlikely(ret_cmd_init != SPP_RET_OK))
 			break;
 
 #ifdef SPP_RINGLATENCYSTATS_ENABLE
@@ -558,7 +544,7 @@ main(int argc, char *argv[])
 #endif /* SPP_RINGLATENCYSTATS_ENABLE */
 
 		/* Start worker threads of classifier and forwarder */
-		unsigned int lcore_id = 0;
+		lcore_id = 0;
 		RTE_LCORE_FOREACH_SLAVE(lcore_id) {
 			rte_eal_remote_launch(slave_main, NULL, lcore_id);
 		}
diff --git a/src/shared/common.c b/src/shared/common.c
index b261fb0..55c53c0 100644
--- a/src/shared/common.c
+++ b/src/shared/common.c
@@ -8,8 +8,8 @@
 
 #define RTE_LOGTYPE_SHARED RTE_LOGTYPE_USER1
 
-char spp_ctl_ip[IPADDR_LEN];  /* IP address of spp_ctl. */
-int spp_ctl_port;  /* Port num to connect spp_ctl. */
+char spp_ctl_ip[IPADDR_LEN] = { 0 };  /* IP address of spp_ctl. */
+int spp_ctl_port = -1;  /* Port num to connect spp_ctl. */
 
 /**
  * Set log level of type RTE_LOGTYPE_USER* to given level, for instance,
-- 
2.17.1


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

* [spp] [PATCH 4/4] spp_pcap: remove global vars spp-ctl IP and port
  2019-06-24 10:44 [spp] [PATCH 0/4] Remove global vars of IP and port of spp-ctl yasufum.o
                   ` (2 preceding siblings ...)
  2019-06-24 10:44 ` [spp] [PATCH 3/4] spp_mirror: remove global vars " yasufum.o
@ 2019-06-24 10:44 ` " yasufum.o
  3 siblings, 0 replies; 5+ messages in thread
From: yasufum.o @ 2019-06-24 10:44 UTC (permalink / raw)
  To: spp, ferruh.yigit, yasufum.o

From: Yasufumi Ogawa <yasufum.o@gmail.com>

This update is to remove global `startup_params` from spp_pcap, and
change to use getter and setter for IP addr and port of spp-ctl.

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 src/pcap/spp_pcap.c | 78 +++++++++++++++++++--------------------------
 1 file changed, 32 insertions(+), 46 deletions(-)

diff --git a/src/pcap/spp_pcap.c b/src/pcap/spp_pcap.c
index d4896eb..57cc0bb 100644
--- a/src/pcap/spp_pcap.c
+++ b/src/pcap/spp_pcap.c
@@ -17,6 +17,7 @@
 #include "spp_pcap.h"
 #include "cmd_runner.h"
 #include "cmd_parser.h"
+#include "shared/secondary/utils.h"
 #include "shared/secondary/spp_worker_th/spp_port.h"
 
 /* Declare global variables */
@@ -198,32 +199,6 @@ client_id_toi(const char *client_id_str, int *client_id)
 	return SPPWK_RET_OK;
 }
 
-/* Parse options for server IP and port */
-static int
-parse_server_ip(const char *server_str, char *server_ip, int *server_port)
-{
-	const char delim[2] = ":";
-	unsigned int pos = 0;
-	int port = 0;
-	char *endptr = NULL;
-
-	pos = strcspn(server_str, delim);
-	if (pos >= strlen(server_str))
-		return SPPWK_RET_NG;
-
-	port = strtol(&server_str[pos+1], &endptr, 0);
-	if (unlikely(&server_str[pos+1] == endptr) || unlikely(*endptr != '\0'))
-		return SPPWK_RET_NG;
-
-	memcpy(server_ip, server_str, pos);
-	server_ip[pos] = '\0';
-	*server_port = port;
-	RTE_LOG(DEBUG, SPP_PCAP, "Set server IP   = %s\n", server_ip);
-	RTE_LOG(DEBUG, SPP_PCAP, "Set server port = %d\n", *server_port);
-	return SPPWK_RET_OK;
-}
-
-
 /* Parse `--fsize` option and get the value */
 static int
 parse_fsize(const char *fsize_str, uint64_t *fsize)
@@ -286,17 +261,23 @@ parse_captured_port(const char *port_str, enum port_type *iface_type,
 
 /* Parse options for client app */
 static int
-parse_args(int argc, char *argv[])
+parse_app_args(int argc, char *argv[])
 {
+	char *ctl_ip;  /* IP address of spp_ctl. */
+	int ctl_port;  /* Port num to connect spp_ctl. */
+	char cap_port_str[PORT_STR_SIZE];  /* Captured port. */
 	int cnt;
+	int ret;
+	int option_index, opt;
+
 	int proc_flg = 0;
 	int server_flg = 0;
 	int port_flg = 0;
-	int option_index, opt;
+
 	const int argcopt = argc;
 	char *argvopt[argcopt];
 	const char *progname = argv[0];
-	char port_str[PORT_STR_SIZE];
+
 	static struct option lgopts[] = {
 		{ "client-id", required_argument, NULL,
 			SPP_LONGOPT_RETVAL_CLIENT_ID },
@@ -351,7 +332,7 @@ parse_args(int argc, char *argv[])
 			}
 			break;
 		case 'c':  /* captured port */
-			strcpy(port_str, optarg);
+			strcpy(cap_port_str, optarg);
 			if (parse_captured_port(optarg,
 					&g_pcap_option.port_cap.iface_type,
 					&g_pcap_option.port_cap.iface_no) !=
@@ -362,9 +343,10 @@ parse_args(int argc, char *argv[])
 			port_flg = 1;
 			break;
 		case 's':  /* server addr */
-			if (parse_server_ip(optarg, g_startup_param.server_ip,
-					&g_startup_param.server_port) !=
-								SPPWK_RET_OK) {
+			ret = parse_server(&ctl_ip, &ctl_port, optarg);
+			set_spp_ctl_ip(ctl_ip);
+			set_spp_ctl_port(ctl_port);
+			if (ret != SPPWK_RET_OK) {
 				usage(progname);
 				return SPPWK_RET_NG;
 			}
@@ -383,12 +365,10 @@ parse_args(int argc, char *argv[])
 	}
 
 	RTE_LOG(INFO, SPP_PCAP,
-			"App opts: '--client-id %d', '-s %s:%d', "
-			"'-c %s', '--out-dir %s', '--fsize %ld'\n",
-			g_startup_param.client_id,
-			g_startup_param.server_ip,
-			g_startup_param.server_port,
-			port_str,
+			"Parsed app args ('--client-id %d', '-s %s:%d', "
+			"'-c %s', '--out-dir %s', '--fsize %ld')\n",
+			g_startup_param.client_id, ctl_ip, ctl_port,
+			cap_port_str,
 			g_pcap_option.compress_file_path,
 			g_pcap_option.fsize_limit);
 	return SPPWK_RET_OK;
@@ -946,6 +926,12 @@ int
 main(int argc, char *argv[])
 {
 	int ret = SPPWK_RET_NG;
+	char ctl_ip[IPADDR_LEN] = { 0 };
+	int ctl_port;
+	int ret_cmd_init;
+	unsigned int lcore_id;
+	unsigned int thread_no;
+
 #ifdef SPP_DEMONIZE
 	/* Daemonize process */
 	int ret_daemon = daemon(0, 0);
@@ -969,7 +955,7 @@ main(int argc, char *argv[])
 		argv += ret_eal;
 
 		/* Parse spp_pcap specific parameters */
-		int ret_parse = parse_args(argc, argv);
+		int ret_parse = parse_app_args(argc, argv);
 		if (unlikely(ret_parse != 0))
 			break;
 
@@ -995,10 +981,10 @@ main(int argc, char *argv[])
 		spp_port_ability_init();
 
 		/* Setup connection for accepting commands from controller */
-		int ret_command_init = spp_command_proc_init(
-				g_startup_param.server_ip,
-				g_startup_param.server_port);
-		if (unlikely(ret_command_init != SPPWK_RET_OK))
+		get_spp_ctl_ip(ctl_ip);
+		ctl_port = get_spp_ctl_port();
+		ret_cmd_init = spp_command_proc_init(ctl_ip, ctl_port);
+		if (unlikely(ret_cmd_init != SPPWK_RET_OK))
 			break;
 
 		/* capture port setup */
@@ -1060,10 +1046,10 @@ main(int argc, char *argv[])
 				g_pcap_option.cap_ring->flags);
 
 		/* Start worker threads of recive or write */
-		unsigned int lcore_id = 0;
-		unsigned int thread_no = 0;
 		g_pcap_thread_info.thread_cnt = 0;
 		g_pcap_thread_info.start_up_cnt = 0;
+		lcore_id = 0;
+		thread_no = 0;
 		RTE_LCORE_FOREACH_SLAVE(lcore_id) {
 			g_pcap_thread_info.thread_cnt += 1;
 			g_pcap_info[lcore_id].thread_no = thread_no++;
-- 
2.17.1


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

end of thread, back to index

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-24 10:44 [spp] [PATCH 0/4] Remove global vars of IP and port of spp-ctl yasufum.o
2019-06-24 10:44 ` [spp] [PATCH 1/4] spp_nfv: remove global vars of spp-ctl IP and port yasufum.o
2019-06-24 10:44 ` [spp] [PATCH 2/4] spp_vf: " yasufum.o
2019-06-24 10:44 ` [spp] [PATCH 3/4] spp_mirror: remove global vars " yasufum.o
2019-06-24 10:44 ` [spp] [PATCH 4/4] spp_pcap: " yasufum.o

Soft Patch Panel

Archives are clonable:
	git clone --mirror http://inbox.dpdk.org/spp/0 spp/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 spp spp/ http://inbox.dpdk.org/spp \
		spp@dpdk.org
	public-inbox-index spp


Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.spp


AGPL code for this site: git clone https://public-inbox.org/ public-inbox