* [spp] [PATCH 0/6] Refactor common libs
@ 2019-01-15 3:27 ogawa.yasufumi
2019-01-15 3:27 ` [spp] [PATCH 1/6] spp_primary: refactor common for primary ogawa.yasufumi
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: ogawa.yasufumi @ 2019-01-15 3:27 UTC (permalink / raw)
To: ferruh.yigit, spp, ogawa.yasufumi
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
SPP's common libraries under `src/shared` are not organized well. For
example, functions used only by spp_primary is included in
`shared/common.c`, but it should be moved under `primary/`.
This series of patches is to refactor file structure of SPP.
* Move functions for spp_primary to `src/primary`.
* Move functions for spp_nfv to `src/nfv`.
* Add common libs for secondary processes in `src/shared/secondary/`.
Yasufumi Ogawa (6):
spp_primary: refactor common for primary
shared: refactor common for SPP secondaries
spp_nfv: refactor common for spp_nfv
shared: refactor common functions
shared: refactor libs of SPP secondary
spp_nfv: refactor file structure
src/Makefile | 2 +-
src/nfv/Makefile | 5 +-
src/nfv/commands.h | 72 +--
src/nfv/init.h | 44 ++
src/nfv/main.c | 31 +-
src/nfv/nfv.h | 13 -
src/nfv/nfv_status.c | 249 +++++++++
src/nfv/nfv_status.h | 24 +
src/nfv/nfv_utils.h | 118 ++++
src/nfv/params.h | 9 +-
src/primary/args.c | 48 +-
src/primary/args.h | 10 +-
src/primary/init.c | 137 ++++-
src/primary/init.h | 16 +-
src/primary/main.c | 52 +-
src/primary/primary.h | 10 +
src/shared/common.c | 526 +-----------------
src/shared/common.h | 141 +----
.../secondary/add_port.h} | 194 ++-----
src/shared/secondary/utils.c | 119 ++++
src/shared/secondary/utils.h | 39 ++
21 files changed, 961 insertions(+), 898 deletions(-)
create mode 100644 src/nfv/init.h
delete mode 100644 src/nfv/nfv.h
create mode 100644 src/nfv/nfv_status.c
create mode 100644 src/nfv/nfv_status.h
create mode 100644 src/nfv/nfv_utils.h
create mode 100644 src/primary/primary.h
rename src/{nfv/command_utils.h => shared/secondary/add_port.h} (61%)
create mode 100644 src/shared/secondary/utils.c
create mode 100644 src/shared/secondary/utils.h
--
2.17.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [spp] [PATCH 1/6] spp_primary: refactor common for primary
2019-01-15 3:27 [spp] [PATCH 0/6] Refactor common libs ogawa.yasufumi
@ 2019-01-15 3:27 ` ogawa.yasufumi
2019-01-15 3:27 ` [spp] [PATCH 2/6] shared: refactor common for SPP secondaries ogawa.yasufumi
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: ogawa.yasufumi @ 2019-01-15 3:27 UTC (permalink / raw)
To: ferruh.yigit, spp, ogawa.yasufumi
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
Move specific variables and functions for spp_primary from
`shared/common.*` to `primary/*`.
Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
src/primary/args.c | 48 ++++++++++++++-
src/primary/args.h | 10 ++-
src/primary/init.c | 137 +++++++++++++++++++++++++++++++++++++++++-
src/primary/init.h | 16 ++++-
src/primary/main.c | 52 ++++++++--------
src/primary/primary.h | 10 +++
6 files changed, 239 insertions(+), 34 deletions(-)
create mode 100644 src/primary/primary.h
diff --git a/src/primary/args.c b/src/primary/args.c
index a601f85..f882ace 100644
--- a/src/primary/args.c
+++ b/src/primary/args.c
@@ -1,14 +1,16 @@
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2015-2016 Intel Corporation
+ * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
*/
#include <getopt.h>
#include <rte_memory.h>
-#include "args.h"
#include "common.h"
+#include "args.h"
#include "init.h"
+#include "primary.h"
/* global var for number of clients - extern in header */
uint16_t num_clients;
@@ -23,13 +25,52 @@ static const char *progname;
static void
usage(void)
{
- RTE_LOG(INFO, APP,
+ RTE_LOG(INFO, PRIMARY,
"%s [EAL options] -- -p PORTMASK -n NUM_CLIENTS [-s NUM_SOCKETS]\n"
" -p PORTMASK: hexadecimal bitmask of ports to use\n"
" -n NUM_CLIENTS: number of client processes to use\n"
, progname);
}
+/**
+ * The ports to be used by the application are passed in
+ * the form of a bitmask. This function parses the bitmask
+ * and places the port numbers to be used into the port[]
+ * array variable
+ */
+int
+parse_portmask(struct port_info *ports, uint16_t max_ports,
+ const char *portmask)
+{
+ char *end = NULL;
+ unsigned long pm;
+ uint16_t count = 0;
+
+ if (portmask == NULL || *portmask == '\0')
+ return -1;
+
+ /* convert parameter to a number and verify */
+ pm = strtoul(portmask, &end, 16);
+ if (end == NULL || *end != '\0' || pm == 0)
+ return -1;
+
+ /* loop through bits of the mask and mark ports */
+ while (pm != 0) {
+ if (pm & 0x01) { /* bit is set in mask, use port */
+ if (count >= max_ports)
+ RTE_LOG(WARNING, PRIMARY,
+ "port %u not present - ignoring\n",
+ count);
+ else
+ ports->id[ports->num_ports++] = count;
+ }
+ pm = (pm >> 1);
+ count++;
+ }
+
+ return 0;
+}
+
/**
* The application specific arguments follow the DPDK-specific
* arguments which are stripped by the DPDK init. This function
@@ -69,7 +110,8 @@ parse_app_args(uint16_t max_ports, int argc, char *argv[])
}
break;
default:
- RTE_LOG(ERR, APP, "ERROR: Unknown option '%c'\n", opt);
+ RTE_LOG(ERR,
+ PRIMARY, "ERROR: Unknown option '%c'\n", opt);
usage();
return -1;
}
diff --git a/src/primary/args.h b/src/primary/args.h
index 972d0ef..bbaf993 100644
--- a/src/primary/args.h
+++ b/src/primary/args.h
@@ -1,16 +1,20 @@
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2015-2016 Intel Corporation
+ * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
*/
-#ifndef _ARGS_H_
-#define _ARGS_H_
+#ifndef _PRIMARY_ARGS_H_
+#define _PRIMARY_ARGS_H_
#include <stdint.h>
+#include "common.h"
extern uint16_t num_clients;
extern char *server_ip;
extern int server_port;
+int parse_portmask(struct port_info *ports, uint16_t max_ports,
+ const char *portmask);
int parse_app_args(uint16_t max_ports, int argc, char *argv[]);
-#endif /* ifndef _ARGS_H_ */
+#endif /* _PRIMARY_ARGS_H_ */
diff --git a/src/primary/init.c b/src/primary/init.c
index 43941dd..2e33df9 100644
--- a/src/primary/init.c
+++ b/src/primary/init.c
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2015-2016 Intel Corporation
+ * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
*/
#include <limits.h>
@@ -11,9 +12,14 @@
#include "args.h"
#include "common.h"
#include "init.h"
+#include "primary.h"
#define CLIENT_QUEUE_RINGSIZE 128
+#define MBUFS_PER_CLIENT 1536
+#define MBUFS_PER_PORT 1536
+#define MBUF_CACHE_SIZE 512
+
/* array of info/queues for clients */
struct client *clients;
@@ -37,7 +43,7 @@ init_mbuf_pools(void)
* don't pass single-producer/single-consumer flags to mbuf create as
* it seems faster to use a cache instead
*/
- RTE_LOG(DEBUG, APP, "Creating mbuf pool '%s' [%u mbufs] ...\n",
+ RTE_LOG(DEBUG, PRIMARY, "Creating mbuf pool '%s' [%u mbufs] ...\n",
PKTMBUF_POOL_NAME, num_mbufs);
if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
@@ -161,3 +167,132 @@ init(int argc, char *argv[])
return 0;
}
+
+/* Check the link status of all ports in up to 9s, and print them finally */
+void
+check_all_ports_link_status(struct port_info *ports, uint16_t port_num,
+ uint32_t port_mask)
+{
+#define CHECK_INTERVAL 100 /* 100ms */
+#define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */
+ uint8_t count, all_ports_up;
+ uint16_t portid;
+ struct rte_eth_link link;
+
+ RTE_LOG(INFO, PRIMARY, "\nChecking link status");
+ fflush(stdout);
+ for (count = 0; count <= MAX_CHECK_TIME; count++) {
+ all_ports_up = 1;
+ for (portid = 0; portid < port_num; portid++) {
+ if ((port_mask & (1 << ports->id[portid])) == 0)
+ continue;
+
+ memset(&link, 0, sizeof(link));
+ rte_eth_link_get_nowait(ports->id[portid], &link);
+
+ /* clear all_ports_up flag if any link down */
+ if (link.link_status == 0) {
+ all_ports_up = 0;
+ break;
+ }
+ }
+
+ if (all_ports_up == 0) {
+ printf(".");
+ fflush(stdout);
+ rte_delay_ms(CHECK_INTERVAL);
+ } else {
+ printf("done\n");
+ break;
+ }
+ }
+
+ /* all ports up or timed out */
+ for (portid = 0; portid < port_num; portid++) {
+ if ((port_mask & (1 << ports->id[portid])) == 0)
+ continue;
+
+ memset(&link, 0, sizeof(link));
+ rte_eth_link_get_nowait(ports->id[portid], &link);
+
+ /* print link status */
+ if (link.link_status)
+ RTE_LOG(INFO, PRIMARY,
+ "Port %d Link Up - speed %u Mbps - %s\n",
+ ports->id[portid], link.link_speed,
+ (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
+ "full-duplex\n" : "half-duplex\n");
+ else
+ RTE_LOG(INFO, PRIMARY,
+ "Port %d Link Down\n", ports->id[portid]);
+ }
+}
+
+/**
+ * Initialise an individual port:
+ * - configure number of rx and tx rings
+ * - set up each rx ring, to pull from the main mbuf pool
+ * - set up each tx ring
+ * - start the port and report its status to stdout
+ */
+int
+init_port(uint16_t port_num, struct rte_mempool *pktmbuf_pool)
+{
+ /* for port configuration all features are off by default */
+ const struct rte_eth_conf port_conf = {
+ .rxmode = {
+ .mq_mode = ETH_MQ_RX_RSS,
+ },
+ };
+ const uint16_t rx_rings = 1, tx_rings = 1;
+ const uint16_t rx_ring_size = RTE_MP_RX_DESC_DEFAULT;
+ const uint16_t tx_ring_size = RTE_MP_TX_DESC_DEFAULT;
+ uint16_t q;
+ int retval;
+ struct rte_eth_dev_info dev_info;
+ struct rte_eth_conf local_port_conf = port_conf;
+ struct rte_eth_txconf txq_conf;
+
+ RTE_LOG(INFO, PRIMARY, "Port %u init ... ", port_num);
+ fflush(stdout);
+
+ rte_eth_dev_info_get(port_num, &dev_info);
+ if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
+ local_port_conf.txmode.offloads |=
+ DEV_TX_OFFLOAD_MBUF_FAST_FREE;
+ txq_conf = dev_info.default_txconf;
+ txq_conf.offloads = local_port_conf.txmode.offloads;
+
+ /*
+ * Standard DPDK port initialisation - config port, then set up
+ * rx and tx rings
+ */
+ retval = rte_eth_dev_configure(port_num, rx_rings, tx_rings,
+ &port_conf);
+ if (retval != 0)
+ return retval;
+
+ for (q = 0; q < rx_rings; q++) {
+ retval = rte_eth_rx_queue_setup(port_num, q, rx_ring_size,
+ rte_eth_dev_socket_id(port_num), NULL, pktmbuf_pool);
+ if (retval < 0)
+ return retval;
+ }
+
+ for (q = 0; q < tx_rings; q++) {
+ retval = rte_eth_tx_queue_setup(port_num, q, tx_ring_size,
+ rte_eth_dev_socket_id(port_num), &txq_conf);
+ if (retval < 0)
+ return retval;
+ }
+
+ rte_eth_promiscuous_enable(port_num);
+
+ retval = rte_eth_dev_start(port_num);
+ if (retval < 0)
+ return retval;
+
+ RTE_LOG(INFO, PRIMARY, "Port %d Init done\n", port_num);
+
+ return 0;
+}
diff --git a/src/primary/init.h b/src/primary/init.h
index 638a4e9..286bdb5 100644
--- a/src/primary/init.h
+++ b/src/primary/init.h
@@ -1,12 +1,17 @@
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2015-2016 Intel Corporation
+ * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
*/
-#ifndef _INIT_H_
-#define _INIT_H_
+#ifndef _PRIMARY_INIT_H_
+#define _PRIMARY_INIT_H_
#include <stdint.h>
+#define MBUF_OVERHEAD (sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM)
+#define RX_MBUF_DATA_SIZE 2048
+#define MBUF_SIZE (RX_MBUF_DATA_SIZE + MBUF_OVERHEAD)
+
/*
* Define a client structure with all needed info, including
* stats from the clients.
@@ -33,4 +38,9 @@ extern struct port_info *ports;
int init(int argc, char *argv[]);
-#endif /* ifndef _INIT_H_ */
+void check_all_ports_link_status(struct port_info *ports, uint16_t port_num,
+ uint32_t port_mask);
+
+int init_port(uint16_t port_num, struct rte_mempool *pktmbuf_pool);
+
+#endif /* ifndef _PRIMARY_INIT_H_ */
diff --git a/src/primary/main.c b/src/primary/main.c
index e010bc6..12b86e5 100644
--- a/src/primary/main.c
+++ b/src/primary/main.c
@@ -1,7 +1,9 @@
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2015-2016 Intel Corporation
+ * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
*/
+#include <signal.h>
#include <arpa/inet.h>
#include <inttypes.h>
#include <poll.h>
@@ -12,6 +14,7 @@
#include "args.h"
#include "common.h"
#include "init.h"
+#include "primary.h"
/* Buffer sizes of status message of primary. Total must be equal to MSG_SIZE */
#define PRI_BUF_SIZE_PHY 512
@@ -27,7 +30,7 @@ static void
turn_off(int sig)
{
on = 0;
- RTE_LOG(INFO, APP, "terminated %d\n", sig);
+ RTE_LOG(INFO, PRIMARY, "terminated %d\n", sig);
}
static const char *
@@ -114,7 +117,7 @@ sleep_lcore(void *dummy __rte_unused)
if (rte_atomic32_test_and_set(&display_stats)) {
const unsigned int sleeptime = 1;
- RTE_LOG(INFO, APP, "Core %u displaying statistics\n",
+ RTE_LOG(INFO, PRIMARY, "Core %u displaying statistics\n",
rte_lcore_id());
/* Longer initial pause so above log is seen */
@@ -146,12 +149,12 @@ do_send(int *connected, int *sock, char *str)
ret = send(*sock, str, MSG_SIZE, 0);
if (ret == -1) {
- RTE_LOG(ERR, APP, "send failed");
+ RTE_LOG(ERR, PRIMARY, "send failed");
*connected = 0;
return -1;
}
- RTE_LOG(INFO, APP, "To Server: %s\n", str);
+ RTE_LOG(INFO, PRIMARY, "To Server: %s\n", str);
return 0;
}
@@ -199,7 +202,7 @@ get_status_json(char *str)
char phy_port[buf_size];
for (i = 0; i < ports->num_ports; i++) {
- RTE_LOG(DEBUG, APP, "Size of phy_ports str: %d\n",
+ RTE_LOG(DEBUG, PRIMARY, "Size of phy_ports str: %d\n",
(int)strlen(phy_ports));
memset(phy_port, '\0', buf_size);
@@ -216,7 +219,7 @@ get_status_json(char *str)
int cur_buf_size = (int)strlen(phy_ports) +
(int)strlen(phy_port);
if (cur_buf_size > phyp_buf_size - 1) {
- RTE_LOG(ERR, APP,
+ RTE_LOG(ERR, PRIMARY,
"Cannot send all of phy_port stats (%d/%d)\n",
i, ports->num_ports);
sprintf(phy_ports + strlen(phy_ports) - 1, "%s", "");
@@ -232,7 +235,7 @@ get_status_json(char *str)
char ring_port[buf_size];
for (i = 0; i < num_clients; i++) {
- RTE_LOG(DEBUG, APP, "Size of ring_ports str: %d\n",
+ RTE_LOG(DEBUG, PRIMARY, "Size of ring_ports str: %d\n",
(int)strlen(ring_ports));
memset(ring_port, '\0', buf_size);
@@ -249,7 +252,7 @@ get_status_json(char *str)
int cur_buf_size = (int)strlen(ring_ports) +
(int)strlen(ring_port);
if (cur_buf_size > ringp_buf_size - 1) {
- RTE_LOG(ERR, APP,
+ RTE_LOG(ERR, PRIMARY,
"Cannot send all of ring_port stats (%d/%d)\n",
i, num_clients);
sprintf(ring_ports + strlen(ring_ports) - 1, "%s", "");
@@ -262,7 +265,7 @@ get_status_json(char *str)
sprintf(ring_ports, "%s,", ring_ports);
}
- RTE_LOG(DEBUG, APP, "{\"phy_ports\": [%s], \"ring_ports\": [%s]}",
+ RTE_LOG(DEBUG, PRIMARY, "{\"phy_ports\": [%s], \"ring_ports\": [%s]}",
phy_ports, ring_ports);
sprintf(str, "{\"phy_ports\": [%s], \"ring_ports\": [%s]}",
@@ -281,20 +284,20 @@ parse_command(char *str)
/* tokenize the user commands from controller */
token_list[i] = strtok(str, " ");
while (token_list[i] != NULL) {
- RTE_LOG(DEBUG, APP, "token %d = %s\n", i, token_list[i]);
+ RTE_LOG(DEBUG, PRIMARY, "token %d = %s\n", i, token_list[i]);
i++;
token_list[i] = strtok(NULL, " ");
}
if (!strcmp(token_list[0], "status")) {
- RTE_LOG(DEBUG, APP, "status\n");
+ RTE_LOG(DEBUG, PRIMARY, "status\n");
memset(str, '\0', MSG_SIZE);
ret = get_status_json(str);
} else if (!strcmp(token_list[0], "exit")) {
- RTE_LOG(DEBUG, APP, "exit\n");
- RTE_LOG(DEBUG, APP, "stop\n");
+ RTE_LOG(DEBUG, PRIMARY, "exit\n");
+ RTE_LOG(DEBUG, PRIMARY, "stop\n");
cmd = STOP;
ret = -1;
@@ -326,14 +329,14 @@ do_receive(int *connected, int *sock, char *str)
ret = recv(*sock, str, MSG_SIZE, 0);
if (ret <= 0) {
- RTE_LOG(DEBUG, APP, "Receive count: %d\n", ret);
+ RTE_LOG(DEBUG, PRIMARY, "Receive count: %d\n", ret);
if (ret < 0)
- RTE_LOG(ERR, APP, "Receive Fail");
+ RTE_LOG(ERR, PRIMARY, "Receive Fail");
else
- RTE_LOG(INFO, APP, "Receive 0\n");
+ RTE_LOG(INFO, PRIMARY, "Receive 0\n");
- RTE_LOG(INFO, APP, "Assume Server closed connection\n");
+ RTE_LOG(INFO, PRIMARY, "Assume Server closed connection\n");
close(*sock);
*sock = SOCK_RESET;
*connected = 0;
@@ -351,7 +354,7 @@ do_connection(int *connected, int *sock)
if (*connected == 0) {
if (*sock < 0) {
- RTE_LOG(INFO, APP, "Creating socket...\n");
+ RTE_LOG(INFO, PRIMARY, "Creating socket...\n");
*sock = socket(AF_INET, SOCK_STREAM, 0);
if (*sock < 0)
rte_exit(EXIT_FAILURE, "socket error\n");
@@ -366,15 +369,16 @@ do_connection(int *connected, int *sock)
pfd.events = POLLIN;
}
- RTE_LOG(INFO, APP, "Trying to connect ... socket %d\n", *sock);
+ RTE_LOG(INFO,
+ PRIMARY, "Trying to connect ... socket %d\n", *sock);
ret = connect(*sock, (struct sockaddr *) &servaddr,
sizeof(servaddr));
if (ret < 0) {
- RTE_LOG(ERR, APP, "Connection Error");
+ RTE_LOG(ERR, PRIMARY, "Connection Error");
return ret;
}
- RTE_LOG(INFO, APP, "Connected\n");
+ RTE_LOG(INFO, PRIMARY, "Connected\n");
*connected = 1;
}
@@ -399,7 +403,7 @@ main(int argc, char *argv[])
set_user_log_debug(1);
- RTE_LOG(INFO, APP, "Finished Process Init.\n");
+ RTE_LOG(INFO, PRIMARY, "Finished Process Init.\n");
/* clear statistics */
clear_stats();
@@ -418,7 +422,7 @@ main(int argc, char *argv[])
if (ret < 0)
continue;
- RTE_LOG(DEBUG, APP, "Received string: %s\n", str);
+ RTE_LOG(DEBUG, PRIMARY, "Received string: %s\n", str);
flg_exit = parse_command(str);
@@ -434,6 +438,6 @@ main(int argc, char *argv[])
/* exit */
close(sock);
sock = SOCK_RESET;
- RTE_LOG(INFO, APP, "spp_primary exit.\n");
+ RTE_LOG(INFO, PRIMARY, "spp_primary exit.\n");
return 0;
}
diff --git a/src/primary/primary.h b/src/primary/primary.h
new file mode 100644
index 0000000..b0d0d64
--- /dev/null
+++ b/src/primary/primary.h
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
+ */
+
+#ifndef _PRIMARY_PRIMARY_H_
+#define _PRIMARY_PRIMARY_H_
+
+#define RTE_LOGTYPE_PRIMARY RTE_LOGTYPE_USER1
+
+#endif
--
2.17.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [spp] [PATCH 2/6] shared: refactor common for SPP secondaries
2019-01-15 3:27 [spp] [PATCH 0/6] Refactor common libs ogawa.yasufumi
2019-01-15 3:27 ` [spp] [PATCH 1/6] spp_primary: refactor common for primary ogawa.yasufumi
@ 2019-01-15 3:27 ` ogawa.yasufumi
2019-01-15 3:27 ` [spp] [PATCH 3/6] spp_nfv: refactor common for spp_nfv ogawa.yasufumi
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: ogawa.yasufumi @ 2019-01-15 3:27 UTC (permalink / raw)
To: ferruh.yigit, spp, ogawa.yasufumi
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
Move specific variables and functions for SPP secondary processes from
`shared/common.*` to `shared/secondary.*`.
Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
src/shared/secondary.c | 359 +++++++++++++++++++++++++++++++++++++++++
src/shared/secondary.h | 102 ++++++++++++
2 files changed, 461 insertions(+)
create mode 100644 src/shared/secondary.c
create mode 100644 src/shared/secondary.h
diff --git a/src/shared/secondary.c b/src/shared/secondary.c
new file mode 100644
index 0000000..2e986d9
--- /dev/null
+++ b/src/shared/secondary.c
@@ -0,0 +1,359 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
+ */
+
+#include <stdint.h>
+#include "common.h"
+#include "secondary.h"
+
+#define RTE_LOGTYPE_SHARED RTE_LOGTYPE_USER1
+
+/*
+ * Get status of spp_nfv or spp_vm as JSON format. It consists of running
+ * status and patch info of ports.
+ *
+ * Here is an example of well-formatted JSON status to better understand.
+ * Actual status has no spaces and new lines inserted as
+ * '{"status":"running","ports":[{"src":"phy:0","dst":"ring:0"},...]}'
+ *
+ * {
+ * "status": "running",
+ * "ports": ["phy:0", "phy:1", "ring:0", "vhost:0"],
+ * "patches": [
+ * {"src":"phy:0","dst": "ring:0"},
+ * {"src":"ring:0","dst": "vhost:0"}
+ * ]
+ * }
+ */
+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)
+{
+ sprintf(str, "{\"client-id\":%d,", client_id);
+
+ 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;
+
+ RTE_LOG(INFO, SHARED, "Port ID %d\n", i);
+ RTE_LOG(INFO, SHARED, "Status %d\n",
+ ports_fwd_array[i].in_port_id);
+
+ memset(patch_str, '\0', sizeof(patch_str));
+
+ sprintf(patch_str, "{\"src\":");
+
+ switch (port_map[i].port_type) {
+ case PHY:
+ RTE_LOG(INFO, SHARED, "Type: PHY\n");
+ sprintf(patch_str + strlen(patch_str),
+ "\"phy:%u\",",
+ port_map[i].id);
+ break;
+ case RING:
+ RTE_LOG(INFO, SHARED, "Type: RING\n");
+ sprintf(patch_str + strlen(patch_str),
+ "\"ring:%u\",",
+ port_map[i].id);
+ break;
+ case VHOST:
+ RTE_LOG(INFO, SHARED, "Type: VHOST\n");
+ sprintf(patch_str + strlen(patch_str),
+ "\"vhost:%u\",",
+ port_map[i].id);
+ break;
+ case PCAP:
+ RTE_LOG(INFO, SHARED, "Type: PCAP\n");
+ sprintf(patch_str + strlen(patch_str),
+ "\"pcap:%u\",",
+ port_map[i].id);
+ break;
+ case NULLPMD:
+ RTE_LOG(INFO, SHARED, "Type: NULLPMD\n");
+ sprintf(patch_str + strlen(patch_str),
+ "\"nullpmd:%u\",",
+ port_map[i].id);
+ break;
+ case UNDEF:
+ RTE_LOG(INFO, SHARED, "Type: UDF\n");
+ /* TODO(yasufum) Need to remove print for undefined ? */
+ sprintf(patch_str + strlen(patch_str),
+ "\"udf\",");
+ break;
+ }
+
+ sprintf(patch_str + strlen(patch_str), "\"dst\":");
+
+ RTE_LOG(INFO, SHARED, "Out Port ID %d\n",
+ ports_fwd_array[i].out_port_id);
+
+ if (ports_fwd_array[i].out_port_id == PORT_RESET) {
+ //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, SHARED, "Type: PHY\n");
+ sprintf(patch_str + strlen(patch_str),
+ "\"phy:%u\"",
+ port_map[j].id);
+ break;
+ case RING:
+ RTE_LOG(INFO, SHARED, "Type: RING\n");
+ sprintf(patch_str + strlen(patch_str),
+ "\"ring:%u\"",
+ port_map[j].id);
+ break;
+ case VHOST:
+ RTE_LOG(INFO, SHARED, "Type: VHOST\n");
+ sprintf(patch_str + strlen(patch_str),
+ "\"vhost:%u\"",
+ port_map[j].id);
+ break;
+ case PCAP:
+ RTE_LOG(INFO, SHARED, "Type: PCAP\n");
+ sprintf(patch_str + strlen(patch_str),
+ "\"pcap:%u\"",
+ port_map[j].id);
+ break;
+ case NULLPMD:
+ RTE_LOG(INFO, SHARED, "Type: NULLPMD\n");
+ sprintf(patch_str + strlen(patch_str),
+ "\"nullpmd:%u\"",
+ port_map[j].id);
+ break;
+ case UNDEF:
+ RTE_LOG(INFO, SHARED, "Type: UDF\n");
+ /*
+ * TODO(yasufum) Need to remove print for
+ * undefined ?
+ */
+ sprintf(patch_str + strlen(patch_str),
+ "\"udf\"");
+ break;
+ }
+ }
+
+ sprintf(patch_str + strlen(patch_str), "},");
+
+ if (has_patch != 0)
+ sprintf(str + strlen(str), "%s", patch_str);
+ }
+
+
+ // 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, "]");
+ }
+
+ return 0;
+}
+
+/**
+ * Retieve port type and ID from resource UID. For example, resource UID
+ * 'ring:0' is parsed to retrieve port tyep 'ring' and ID '0'.
+ */
+int
+parse_resource_uid(char *str, char **port_type, int *port_id)
+{
+ char *token;
+ char delim[] = ":";
+ char *endp;
+
+ RTE_LOG(DEBUG, SHARED, "Parsing resource UID: '%s\n'", str);
+ if (strstr(str, delim) == NULL) {
+ RTE_LOG(ERR, SHARED, "Invalid resource UID: '%s'\n", str);
+ return -1;
+ }
+ RTE_LOG(DEBUG, SHARED, "Delimiter %s is included\n", delim);
+
+ *port_type = strtok(str, delim);
+
+ token = strtok(NULL, delim);
+ *port_id = strtol(token, &endp, 10);
+
+ if (*endp) {
+ RTE_LOG(ERR, SHARED, "Bad integer value: %s\n", str);
+ return -1;
+ }
+
+ return 0;
+}
+
+int
+spp_atoi(const char *str, int *val)
+{
+ char *end;
+
+ *val = strtol(str, &end, 10);
+
+ if (*end) {
+ RTE_LOG(ERR, SHARED, "Bad integer value: %s\n", str);
+ return -1;
+ }
+
+ return 0;
+}
+
+/* attach the new device, then store port_id of the device */
+int
+dev_attach_by_devargs(const char *devargs, uint16_t *port_id)
+{
+ int ret = -1;
+ struct rte_devargs da;
+
+ memset(&da, 0, sizeof(da));
+
+ /* parse devargs */
+ if (rte_devargs_parse(&da, devargs))
+ return -1;
+
+ ret = rte_eal_hotplug_add(da.bus->name, da.name, da.args);
+ if (ret < 0) {
+ free(da.args);
+ return ret;
+ }
+
+ ret = rte_eth_dev_get_port_by_name(da.name, port_id);
+
+ free(da.args);
+
+ return ret;
+}
+
+/* detach the device, then store the name of the device */
+int
+dev_detach_by_port_id(uint16_t port_id)
+{
+ struct rte_device *dev;
+ struct rte_bus *bus;
+ uint32_t dev_flags;
+ int ret = -1;
+
+ if (rte_eth_devices[port_id].data == NULL) {
+ RTE_LOG(INFO, SHARED,
+ "rte_eth_devices[%"PRIu16"].data is NULL\n", port_id);
+ return 0;
+ }
+ dev_flags = rte_eth_devices[port_id].data->dev_flags;
+ if (dev_flags & RTE_ETH_DEV_BONDED_SLAVE) {
+ RTE_LOG(ERR, SHARED,
+ "Port %"PRIu16" is bonded, cannot detach\n", port_id);
+ return -ENOTSUP;
+ }
+
+ dev = rte_eth_devices[port_id].device;
+ if (dev == NULL)
+ return -EINVAL;
+
+ bus = rte_bus_find_by_device(dev);
+ if (bus == NULL)
+ return -ENOENT;
+
+ ret = rte_eal_hotplug_remove(bus->name, dev->name);
+ if (ret < 0)
+ return ret;
+
+ rte_eth_dev_release_port(&rte_eth_devices[port_id]);
+
+ return 0;
+}
diff --git a/src/shared/secondary.h b/src/shared/secondary.h
new file mode 100644
index 0000000..c6a1fde
--- /dev/null
+++ b/src/shared/secondary.h
@@ -0,0 +1,102 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
+ */
+
+#ifndef SHARED_SECONDARY_H
+#define SHARED_SECONDARY_H
+
+#define VHOST_IFACE_NAME "/tmp/sock%u"
+#define VHOST_BACKEND_NAME "eth_vhost%u"
+
+#define PCAP_PMD_DEV_NAME "eth_pcap%u"
+#define NULL_PMD_DEV_NAME "eth_null%u"
+
+static inline const char *
+get_vhost_backend_name(unsigned int id)
+{
+ /*
+ * buffer for return value. Size calculated by %u being replaced
+ * by maximum 3 digits (plus an extra byte for safety)
+ */
+ static char buffer[sizeof(VHOST_BACKEND_NAME) + 2];
+
+ snprintf(buffer, sizeof(buffer) - 1, VHOST_BACKEND_NAME, id);
+ return buffer;
+}
+
+static inline char *
+get_vhost_iface_name(unsigned int id)
+{
+ /*
+ * buffer for return value. Size calculated by %u being replaced
+ * by maximum 3 digits (plus an extra byte for safety)
+ */
+ static char buffer[sizeof(VHOST_IFACE_NAME) + 2];
+
+ snprintf(buffer, sizeof(buffer) - 1, VHOST_IFACE_NAME, id);
+ return buffer;
+}
+
+static inline const char *
+get_pcap_pmd_name(int id)
+{
+ static char buffer[sizeof(PCAP_PMD_DEV_NAME) + 2];
+ snprintf(buffer, sizeof(buffer) - 1, PCAP_PMD_DEV_NAME, id);
+ return buffer;
+}
+
+static inline const char *
+get_null_pmd_name(int id)
+{
+ static char buffer[sizeof(NULL_PMD_DEV_NAME) + 2];
+ snprintf(buffer, sizeof(buffer) - 1, NULL_PMD_DEV_NAME, id);
+ return buffer;
+}
+
+/* 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);
+
+int parse_resource_uid(char *str, char **port_type, int *port_id);
+int spp_atoi(const char *str, int *val);
+
+/**
+ * Attach a new Ethernet device specified by arguments.
+ *
+ * @param devargs
+ * A pointer to a strings array describing the new device
+ * to be attached. The strings should be a pci address like
+ * '0000:01:00.0' or virtual device name like 'net_pcap0'.
+ * @param port_id
+ * A pointer to a port identifier actually attached.
+ * @return
+ * 0 on success and port_id is filled, negative on error
+ */
+int
+dev_attach_by_devargs(const char *devargs, uint16_t *port_id);
+
+/**
+ * Detach a Ethernet device specified by port identifier.
+ * This function must be called when the device is in the
+ * closed state.
+ *
+ * @param port_id
+ * The port identifier of the device to detach.
+ * @return
+ * 0 on success and devname is filled, negative on error
+ */
+int dev_detach_by_port_id(uint16_t port_id);
+
+#endif
--
2.17.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [spp] [PATCH 3/6] spp_nfv: refactor common for spp_nfv
2019-01-15 3:27 [spp] [PATCH 0/6] Refactor common libs ogawa.yasufumi
2019-01-15 3:27 ` [spp] [PATCH 1/6] spp_primary: refactor common for primary ogawa.yasufumi
2019-01-15 3:27 ` [spp] [PATCH 2/6] shared: refactor common for SPP secondaries ogawa.yasufumi
@ 2019-01-15 3:27 ` ogawa.yasufumi
2019-01-15 3:27 ` [spp] [PATCH 4/6] shared: refactor common functions ogawa.yasufumi
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: ogawa.yasufumi @ 2019-01-15 3:27 UTC (permalink / raw)
To: ferruh.yigit, spp, ogawa.yasufumi
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
Move specific variables and functions for spp_nfv from
`shared/common.*` to `nfv/*`.
Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
src/nfv/Makefile | 3 +-
src/nfv/command_utils.h | 46 ++++++++++++++++------------
src/nfv/commands.h | 68 ++++++++++++++++++++++-------------------
src/nfv/main.c | 22 +++++++------
src/nfv/nfv.h | 8 ++---
src/nfv/params.h | 9 +++---
6 files changed, 86 insertions(+), 70 deletions(-)
diff --git a/src/nfv/Makefile b/src/nfv/Makefile
index d6884c5..cee1236 100644
--- a/src/nfv/Makefile
+++ b/src/nfv/Makefile
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2015-2016 Intel Corporation
+# Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
ifeq ($(RTE_SDK),)
$(error "Please define RTE_SDK environment variable")
@@ -12,7 +13,7 @@ include $(RTE_SDK)/mk/rte.vars.mk
APP = spp_nfv
# all source are stored in SRCS-y
-SRCS-y := main.c ../shared/common.c
+SRCS-y := main.c ../shared/common.c ../shared/secondary.c
CFLAGS += -DALLOW_EXPERIMENTAL_API
CFLAGS += $(WERROR_FLAGS) -O3 -MMD
diff --git a/src/nfv/command_utils.h b/src/nfv/command_utils.h
index e3c7db1..f026732 100644
--- a/src/nfv/command_utils.h
+++ b/src/nfv/command_utils.h
@@ -1,16 +1,22 @@
/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright(c) 2018 Nippon Telegraph and Telephone Corporation.
+ * Copyright(c) 2015-2016 Intel Corporation
+ * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
*/
-#ifndef NFV_COMMAND_UTILS_H
-#define NFV_COMMAND_UTILS_H
+#ifndef _NFV_COMMAND_UTILS_H_
+#define _NFV_COMMAND_UTILS_H_
#include "common.h"
-#include "nfv.h"
+#include "secondary.h"
+
+#define RTE_LOGTYPE_SPP_NFV RTE_LOGTYPE_USER1
// The number of receive descriptors to allocate for the receive ring.
#define NR_DESCS 128
+#define PCAP_IFACE_RX "/tmp/spp-rx%d.pcap"
+#define PCAP_IFACE_TX "/tmp/spp-tx%d.pcap"
+
static void
forward_array_init_one(unsigned int i)
{
@@ -105,11 +111,11 @@ add_patch(uint16_t in_port, uint16_t out_port)
ports_fwd_array[out_port].rx_func = &rte_eth_rx_burst;
ports_fwd_array[out_port].tx_func = &rte_eth_tx_burst;
- RTE_LOG(DEBUG, APP, "STATUS: in port %d in_port_id %d\n", in_port,
+ RTE_LOG(DEBUG, SPP_NFV, "STATUS: in port %d in_port_id %d\n", in_port,
ports_fwd_array[in_port].in_port_id);
- RTE_LOG(DEBUG, APP, "STATUS: in port %d patch out port id %d\n",
+ RTE_LOG(DEBUG, SPP_NFV, "STATUS: in port %d patch out port id %d\n",
in_port, ports_fwd_array[in_port].out_port_id);
- RTE_LOG(DEBUG, APP, "STATUS: outport %d in_port_id %d\n", out_port,
+ RTE_LOG(DEBUG, SPP_NFV, "STATUS: outport %d in_port_id %d\n", out_port,
ports_fwd_array[out_port].in_port_id);
return 0;
@@ -135,7 +141,7 @@ create_pcap_rx(char *rx_fpath)
if (tmp_fp == NULL) {
(tmp_fp = fopen(template, "w"));
if (tmp_fp == NULL) {
- RTE_LOG(ERR, APP, "Failed to open %s\n", template);
+ RTE_LOG(ERR, SPP_NFV, "Failed to open %s\n", template);
return -1;
}
}
@@ -143,12 +149,12 @@ create_pcap_rx(char *rx_fpath)
sprintf(cmd_str, "text2pcap %s %s", template, rx_fpath);
res = system(cmd_str);
if (res != 0) {
- RTE_LOG(ERR, APP,
+ RTE_LOG(ERR, SPP_NFV,
"Failed to create pcap device %s\n",
rx_fpath);
return -1;
}
- RTE_LOG(INFO, APP, "PCAP device created\n");
+ RTE_LOG(INFO, SPP_NFV, "PCAP device created\n");
fclose(tmp_fp);
return 0;
}
@@ -169,21 +175,21 @@ add_ring_pmd(int ring_id)
/* Look up ring with provided ring_id */
ring = rte_ring_lookup(rx_queue_name);
if (ring == NULL) {
- RTE_LOG(ERR, APP,
+ RTE_LOG(ERR, SPP_NFV,
"Failed to get RX ring %s - is primary running?\n",
rx_queue_name);
return -1;
}
- RTE_LOG(INFO, APP, "Looked up ring '%s'\n", rx_queue_name);
+ RTE_LOG(INFO, SPP_NFV, "Looked up ring '%s'\n", rx_queue_name);
/* create ring pmd*/
res = rte_eth_from_ring(ring);
if (res < 0) {
- RTE_LOG(ERR, APP,
+ RTE_LOG(ERR, SPP_NFV,
"Cannot create eth dev with rte_eth_from_ring()\n");
return -1;
}
- RTE_LOG(INFO, APP, "Created ring PMD: %d\n", res);
+ RTE_LOG(INFO, SPP_NFV, "Created ring PMD: %d\n", res);
return res;
}
@@ -242,7 +248,7 @@ add_vhost_pmd(int index)
if (ret < 0)
return ret;
- RTE_LOG(DEBUG, APP, "vhost port id %d\n", vhost_port_id);
+ RTE_LOG(DEBUG, SPP_NFV, "vhost port id %d\n", vhost_port_id);
return vhost_port_id;
}
@@ -329,7 +335,7 @@ add_pcap_pmd(int index)
if (ret < 0)
return ret;
- RTE_LOG(DEBUG, APP, "pcap port id %d\n", pcap_pmd_port_id);
+ RTE_LOG(DEBUG, SPP_NFV, "pcap port id %d\n", pcap_pmd_port_id);
return pcap_pmd_port_id;
}
@@ -391,7 +397,7 @@ add_null_pmd(int index)
if (ret < 0)
return ret;
- RTE_LOG(DEBUG, APP, "null port id %d\n", null_pmd_port_id);
+ RTE_LOG(DEBUG, SPP_NFV, "null port id %d\n", null_pmd_port_id);
return null_pmd_port_id;
}
@@ -416,8 +422,8 @@ forward_array_reset(void)
for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
if (ports_fwd_array[i].in_port_id != PORT_RESET) {
ports_fwd_array[i].out_port_id = PORT_RESET;
- RTE_LOG(INFO, APP, "Port ID %d\n", i);
- RTE_LOG(INFO, APP, "out_port_id %d\n",
+ RTE_LOG(INFO, SPP_NFV, "Port ID %d\n", i);
+ RTE_LOG(INFO, SPP_NFV, "out_port_id %d\n",
ports_fwd_array[i].out_port_id);
}
}
@@ -434,4 +440,4 @@ static enum port_type get_port_type(char *portname)
return UNDEF;
}
-#endif
+#endif // _NFV_COMMAND_UTILS_H_
diff --git a/src/nfv/commands.h b/src/nfv/commands.h
index b33625f..35340f9 100644
--- a/src/nfv/commands.h
+++ b/src/nfv/commands.h
@@ -1,14 +1,17 @@
/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright(c) 2018 Nippon Telegraph and Telephone Corporation.
+ * Copyright(c) 2015-2016 Intel Corporation
+ * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
*/
-#ifndef NFV_COMMANDS_H
-#define NFV_COMMANDS_H
+#ifndef _NFV_COMMANDS_H_
+#define _NFV_COMMANDS_H_
#include "common.h"
#include "nfv.h"
#include "command_utils.h"
+#define RTE_LOGTYPE_SPP_NFV RTE_LOGTYPE_USER1
+
static int
do_del(char *res_uid)
{
@@ -19,7 +22,7 @@ do_del(char *res_uid)
res = parse_resource_uid(res_uid, &p_type, &p_id);
if (res < 0) {
- RTE_LOG(ERR, APP,
+ RTE_LOG(ERR, SPP_NFV,
"Failed to parse resource UID\n");
return -1;
}
@@ -30,7 +33,7 @@ do_del(char *res_uid)
return -1;
} else if (!strcmp(p_type, "ring")) {
- RTE_LOG(DEBUG, APP, "Del ring id %d\n", p_id);
+ RTE_LOG(DEBUG, SPP_NFV, "Del ring id %d\n", p_id);
port_id = find_port_id(p_id, RING);
if (port_id == PORT_RESET)
return -1;
@@ -115,7 +118,7 @@ do_connection(int *connected, int *sock)
if (*connected == 0) {
if (*sock < 0) {
- RTE_LOG(INFO, APP, "Creating socket...\n");
+ RTE_LOG(INFO, SPP_NFV, "Creating socket...\n");
*sock = socket(AF_INET, SOCK_STREAM, 0);
if (*sock < 0)
rte_exit(EXIT_FAILURE, "socket error\n");
@@ -127,15 +130,16 @@ do_connection(int *connected, int *sock)
servaddr.sin_port = htons(server_port);
}
- RTE_LOG(INFO, APP, "Trying to connect ... socket %d\n", *sock);
+ RTE_LOG(INFO,
+ SPP_NFV, "Trying to connect ... socket %d\n", *sock);
ret = connect(*sock, (struct sockaddr *) &servaddr,
sizeof(servaddr));
if (ret < 0) {
- RTE_LOG(ERR, APP, "Connection Error");
+ RTE_LOG(ERR, SPP_NFV, "Connection Error");
return ret;
}
- RTE_LOG(INFO, APP, "Connected\n");
+ RTE_LOG(INFO, SPP_NFV, "Connected\n");
*connected = 1;
}
@@ -156,7 +160,7 @@ parse_command(char *str)
/* tokenize user command from controller */
token_list[max_token] = strtok(str, " ");
while (token_list[max_token] != NULL) {
- RTE_LOG(DEBUG, APP, "token %d = %s\n", max_token,
+ RTE_LOG(DEBUG, SPP_NFV, "token %d = %s\n", max_token,
token_list[max_token]);
max_token++;
token_list[max_token] = strtok(NULL, " ");
@@ -166,7 +170,7 @@ parse_command(char *str)
return 0;
if (!strcmp(token_list[0], "status")) {
- RTE_LOG(DEBUG, APP, "status\n");
+ RTE_LOG(DEBUG, SPP_NFV, "status\n");
memset(str, '\0', MSG_SIZE);
if (cmd == FORWARD)
get_sec_stats_json(str, client_id, "running",
@@ -186,26 +190,26 @@ parse_command(char *str)
client_id = id;
} else if (!strcmp(token_list[0], "exit")) {
- RTE_LOG(DEBUG, APP, "exit\n");
- RTE_LOG(DEBUG, APP, "stop\n");
+ RTE_LOG(DEBUG, SPP_NFV, "exit\n");
+ RTE_LOG(DEBUG, SPP_NFV, "stop\n");
cmd = STOP;
ret = -1;
} else if (!strcmp(token_list[0], "stop")) {
- RTE_LOG(DEBUG, APP, "stop\n");
+ RTE_LOG(DEBUG, SPP_NFV, "stop\n");
cmd = STOP;
} else if (!strcmp(token_list[0], "forward")) {
- RTE_LOG(DEBUG, APP, "forward\n");
+ RTE_LOG(DEBUG, SPP_NFV, "forward\n");
cmd = FORWARD;
} else if (!strcmp(token_list[0], "add")) {
- RTE_LOG(DEBUG, APP, "Received add command\n");
+ RTE_LOG(DEBUG, SPP_NFV, "Received add command\n");
if (do_add(token_list[1]) < 0)
- RTE_LOG(ERR, APP, "Failed to do_add()\n");
+ RTE_LOG(ERR, SPP_NFV, "Failed to do_add()\n");
} else if (!strcmp(token_list[0], "patch")) {
- RTE_LOG(DEBUG, APP, "patch\n");
+ RTE_LOG(DEBUG, SPP_NFV, "patch\n");
if (max_token <= 1)
return 0;
@@ -241,41 +245,41 @@ parse_command(char *str)
"Patch not found, both of",
in_p_type, in_p_id,
out_p_type, out_p_id);
- RTE_LOG(ERR, APP, "%s\n", err_msg);
+ RTE_LOG(ERR, SPP_NFV, "%s\n", err_msg);
} else if (in_port == PORT_RESET) {
char err_msg[128];
memset(err_msg, '\0', sizeof(err_msg));
sprintf(err_msg, "%s '%s:%d'",
"Patch not found, in_port",
in_p_type, in_p_id);
- RTE_LOG(ERR, APP, "%s\n", err_msg);
+ RTE_LOG(ERR, SPP_NFV, "%s\n", err_msg);
} else if (out_port == PORT_RESET) {
char err_msg[128];
memset(err_msg, '\0', sizeof(err_msg));
sprintf(err_msg, "%s '%s:%d'",
"Patch not found, out_port",
out_p_type, out_p_id);
- RTE_LOG(ERR, APP, "%s\n", err_msg);
+ RTE_LOG(ERR, SPP_NFV, "%s\n", err_msg);
}
if (add_patch(in_port, out_port) == 0)
- RTE_LOG(INFO, APP,
+ RTE_LOG(INFO, SPP_NFV,
"Patched '%s:%d' and '%s:%d'\n",
in_p_type, in_p_id,
out_p_type, out_p_id);
else
- RTE_LOG(ERR, APP, "Failed to patch\n");
+ RTE_LOG(ERR, SPP_NFV, "Failed to patch\n");
ret = 0;
}
} else if (!strcmp(token_list[0], "del")) {
- RTE_LOG(DEBUG, APP, "Received del command\n");
+ RTE_LOG(DEBUG, SPP_NFV, "Received del command\n");
cmd = STOP;
if (do_del(token_list[1]) < 0)
- RTE_LOG(ERR, APP, "Failed to do_del()\n");
+ RTE_LOG(ERR, SPP_NFV, "Failed to do_del()\n");
}
return ret;
@@ -290,13 +294,13 @@ do_receive(int *connected, int *sock, char *str)
ret = recv(*sock, str, MSG_SIZE, 0);
if (ret <= 0) {
- RTE_LOG(DEBUG, APP, "Receive count: %d\n", ret);
+ RTE_LOG(DEBUG, SPP_NFV, "Receive count: %d\n", ret);
if (ret < 0)
- RTE_LOG(ERR, APP, "Receive Fail");
+ RTE_LOG(ERR, SPP_NFV, "Receive Fail");
else
- RTE_LOG(INFO, APP, "Receive 0\n");
+ RTE_LOG(INFO, SPP_NFV, "Receive 0\n");
- RTE_LOG(INFO, APP, "Assume Server closed connection\n");
+ RTE_LOG(INFO, SPP_NFV, "Assume Server closed connection\n");
close(*sock);
*sock = SOCK_RESET;
*connected = 0;
@@ -313,14 +317,14 @@ do_send(int *connected, int *sock, char *str)
ret = send(*sock, str, MSG_SIZE, 0);
if (ret == -1) {
- RTE_LOG(ERR, APP, "send failed");
+ RTE_LOG(ERR, SPP_NFV, "send failed");
*connected = 0;
return -1;
}
- RTE_LOG(INFO, APP, "To Server: %s\n", str);
+ RTE_LOG(INFO, SPP_NFV, "To Server: %s\n", str);
return 0;
}
-#endif
+#endif // _NFV_COMMANDS_H_
diff --git a/src/nfv/main.c b/src/nfv/main.c
index f1555af..6e9e844 100644
--- a/src/nfv/main.c
+++ b/src/nfv/main.c
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright(c) 2018 Nippon Telegraph and Telephone Corporation.
+ * Copyright(c) 2015-2016 Intel Corporation
+ * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
*/
#include <arpa/inet.h>
@@ -8,9 +9,12 @@
#include <rte_eth_ring.h>
#include <rte_eth_vhost.h>
#include <rte_memzone.h>
+#include <rte_log.h>
#include "nfv.h"
+#define RTE_LOGTYPE_SPP_NFV RTE_LOGTYPE_USER1
+
static sig_atomic_t on = 1;
/*
@@ -19,7 +23,7 @@ static sig_atomic_t on = 1;
static void
usage(const char *progname)
{
- RTE_LOG(INFO, APP,
+ RTE_LOG(INFO, SPP_NFV,
"Usage: %s [EAL args] -- -n <client_id>\n\n", progname);
}
@@ -114,12 +118,12 @@ nfv_loop(void)
{
unsigned int lcore_id = rte_lcore_id();
- RTE_LOG(INFO, APP, "entering main loop on lcore %u\n", lcore_id);
+ RTE_LOG(INFO, SPP_NFV, "entering main loop on lcore %u\n", lcore_id);
while (1) {
if (unlikely(cmd == STOP)) {
sleep(1);
- /*RTE_LOG(INFO, APP, "Idling\n");*/
+ /*RTE_LOG(INFO, SPP_NFV, "Idling\n");*/
continue;
} else if (cmd == FORWARD) {
forward();
@@ -190,7 +194,7 @@ main(int argc, char *argv[])
set_user_log_debug(1);
- RTE_LOG(INFO, APP, "Number of Ports: %d\n", nb_ports);
+ RTE_LOG(INFO, SPP_NFV, "Number of Ports: %d\n", nb_ports);
cmd = STOP;
@@ -211,8 +215,8 @@ main(int argc, char *argv[])
rte_eal_remote_launch(main_loop, NULL, lcore_id);
}
- RTE_LOG(INFO, APP, "My ID %d start handling message\n", client_id);
- RTE_LOG(INFO, APP, "[Press Ctrl-C to quit ...]\n");
+ RTE_LOG(INFO, SPP_NFV, "My ID %d start handling message\n", client_id);
+ RTE_LOG(INFO, SPP_NFV, "[Press Ctrl-C to quit ...]\n");
/* send and receive msg loop */
while (on) {
@@ -226,7 +230,7 @@ main(int argc, char *argv[])
if (ret < 0)
continue;
- RTE_LOG(DEBUG, APP, "Received string: %s\n", str);
+ RTE_LOG(DEBUG, SPP_NFV, "Received string: %s\n", str);
flg_exit = parse_command(str);
@@ -242,6 +246,6 @@ main(int argc, char *argv[])
/* exit */
close(sock);
sock = SOCK_RESET;
- RTE_LOG(INFO, APP, "spp_nfv exit.\n");
+ RTE_LOG(INFO, SPP_NFV, "spp_nfv exit.\n");
return 0;
}
diff --git a/src/nfv/nfv.h b/src/nfv/nfv.h
index a8e037d..d9e5adf 100644
--- a/src/nfv/nfv.h
+++ b/src/nfv/nfv.h
@@ -1,13 +1,13 @@
/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright(c) 2018 Nippon Telegraph and Telephone Corporation.
+ * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
*/
-#ifndef NFV_H
-#define NFV_H
+#ifndef _NFV_H_
+#define _NFV_H_
#include "common.h"
#include "params.h"
#include "command_utils.h"
#include "commands.h"
-#endif
+#endif // _NFV_H_
diff --git a/src/nfv/params.h b/src/nfv/params.h
index f7525ae..aa9c720 100644
--- a/src/nfv/params.h
+++ b/src/nfv/params.h
@@ -1,9 +1,10 @@
/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright(c) 2018 Nippon Telegraph and Telephone Corporation.
+ * Copyright(c) 2015-2016 Intel Corporation
+ * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
*/
-#ifndef NFV_PARAMS_H
-#define NFV_PARAMS_H
+#ifndef _NFV_PARAMS_H_
+#define _NFV_PARAMS_H_
/* It is used to convert port name from string type to enum */
struct porttype_map {
@@ -38,4 +39,4 @@ static enum cmd_type cmd;
static struct port_map port_map[RTE_MAX_ETHPORTS];
-#endif
+#endif // _NFV_PARAMS_H_
--
2.17.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [spp] [PATCH 4/6] shared: refactor common functions
2019-01-15 3:27 [spp] [PATCH 0/6] Refactor common libs ogawa.yasufumi
` (2 preceding siblings ...)
2019-01-15 3:27 ` [spp] [PATCH 3/6] spp_nfv: refactor common for spp_nfv ogawa.yasufumi
@ 2019-01-15 3:27 ` ogawa.yasufumi
2019-01-15 3:28 ` [spp] [PATCH 5/6] shared: refactor libs of SPP secondary ogawa.yasufumi
2019-01-15 3:28 ` [spp] [PATCH 6/6] spp_nfv: refactor file structure ogawa.yasufumi
5 siblings, 0 replies; 7+ messages in thread
From: ogawa.yasufumi @ 2019-01-15 3:27 UTC (permalink / raw)
To: ferruh.yigit, spp, ogawa.yasufumi
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
Move specific variables and functions of each of SPP processes from
`shared`.
Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
src/shared/common.c | 526 +-------------------------------------------
src/shared/common.h | 141 +-----------
2 files changed, 9 insertions(+), 658 deletions(-)
diff --git a/src/shared/common.c b/src/shared/common.c
index 8837ff9..f7d522a 100644
--- a/src/shared/common.c
+++ b/src/shared/common.c
@@ -1,69 +1,12 @@
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2015-2016 Intel Corporation
+ * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
*/
#include <rte_cycles.h>
#include "common.h"
-/* Check the link status of all ports in up to 9s, and print them finally */
-void
-check_all_ports_link_status(struct port_info *ports, uint16_t port_num,
- uint32_t port_mask)
-{
-#define CHECK_INTERVAL 100 /* 100ms */
-#define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */
- uint8_t count, all_ports_up;
- uint16_t portid;
- struct rte_eth_link link;
-
- RTE_LOG(INFO, APP, "\nChecking link status");
- fflush(stdout);
- for (count = 0; count <= MAX_CHECK_TIME; count++) {
- all_ports_up = 1;
- for (portid = 0; portid < port_num; portid++) {
- if ((port_mask & (1 << ports->id[portid])) == 0)
- continue;
-
- memset(&link, 0, sizeof(link));
- rte_eth_link_get_nowait(ports->id[portid], &link);
-
- /* clear all_ports_up flag if any link down */
- if (link.link_status == 0) {
- all_ports_up = 0;
- break;
- }
- }
-
- if (all_ports_up == 0) {
- printf(".");
- fflush(stdout);
- rte_delay_ms(CHECK_INTERVAL);
- } else {
- printf("done\n");
- break;
- }
- }
-
- /* all ports up or timed out */
- for (portid = 0; portid < port_num; portid++) {
- if ((port_mask & (1 << ports->id[portid])) == 0)
- continue;
-
- memset(&link, 0, sizeof(link));
- rte_eth_link_get_nowait(ports->id[portid], &link);
-
- /* print link status */
- if (link.link_status)
- RTE_LOG(INFO, APP,
- "Port %d Link Up - speed %u Mbps - %s\n",
- ports->id[portid], link.link_speed,
- (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
- "full-duplex\n" : "half-duplex\n");
- else
- RTE_LOG(INFO, APP,
- "Port %d Link Down\n", ports->id[portid]);
- }
-}
+#define RTE_LOGTYPE_SHARED RTE_LOGTYPE_USER1
/**
* Set log level of type RTE_LOGTYPE_USER* to given level, for instance,
@@ -75,7 +18,7 @@ check_all_ports_link_status(struct port_info *ports, uint16_t port_num,
* ...
* set_user_log_level(1, RTE_LOG_DEBUG);
* ...
- * RTE_LOG(APP, DEBUG, "Your debug log...");
+ * RTE_LOG(DEBUG, APP, "Your debug log...");
*/
int
set_user_log_level(int num_user_log, uint32_t log_level)
@@ -100,114 +43,6 @@ set_user_log_debug(int num_user_log)
return 0;
}
-/**
- * Initialise an individual port:
- * - configure number of rx and tx rings
- * - set up each rx ring, to pull from the main mbuf pool
- * - set up each tx ring
- * - start the port and report its status to stdout
- */
-int
-init_port(uint16_t port_num, struct rte_mempool *pktmbuf_pool)
-{
- /* for port configuration all features are off by default */
- const struct rte_eth_conf port_conf = {
- .rxmode = {
- .mq_mode = ETH_MQ_RX_RSS,
- },
- };
- const uint16_t rx_rings = 1, tx_rings = 1;
- const uint16_t rx_ring_size = RTE_MP_RX_DESC_DEFAULT;
- const uint16_t tx_ring_size = RTE_MP_TX_DESC_DEFAULT;
- uint16_t q;
- int retval;
- struct rte_eth_dev_info dev_info;
- struct rte_eth_conf local_port_conf = port_conf;
- struct rte_eth_txconf txq_conf;
-
- RTE_LOG(INFO, APP, "Port %u init ... ", port_num);
- fflush(stdout);
-
- rte_eth_dev_info_get(port_num, &dev_info);
- if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
- local_port_conf.txmode.offloads |=
- DEV_TX_OFFLOAD_MBUF_FAST_FREE;
- txq_conf = dev_info.default_txconf;
- txq_conf.offloads = local_port_conf.txmode.offloads;
-
- /*
- * Standard DPDK port initialisation - config port, then set up
- * rx and tx rings
- */
- retval = rte_eth_dev_configure(port_num, rx_rings, tx_rings,
- &port_conf);
- if (retval != 0)
- return retval;
-
- for (q = 0; q < rx_rings; q++) {
- retval = rte_eth_rx_queue_setup(port_num, q, rx_ring_size,
- rte_eth_dev_socket_id(port_num), NULL, pktmbuf_pool);
- if (retval < 0)
- return retval;
- }
-
- for (q = 0; q < tx_rings; q++) {
- retval = rte_eth_tx_queue_setup(port_num, q, tx_ring_size,
- rte_eth_dev_socket_id(port_num), &txq_conf);
- if (retval < 0)
- return retval;
- }
-
- rte_eth_promiscuous_enable(port_num);
-
- retval = rte_eth_dev_start(port_num);
- if (retval < 0)
- return retval;
-
- RTE_LOG(INFO, APP, "Port %d Init done\n", port_num);
-
- return 0;
-}
-
-/**
- * The ports to be used by the application are passed in
- * the form of a bitmask. This function parses the bitmask
- * and places the port numbers to be used into the port[]
- * array variable
- */
-int
-parse_portmask(struct port_info *ports, uint16_t max_ports,
- const char *portmask)
-{
- char *end = NULL;
- unsigned long pm;
- uint16_t count = 0;
-
- if (portmask == NULL || *portmask == '\0')
- return -1;
-
- /* convert parameter to a number and verify */
- pm = strtoul(portmask, &end, 16);
- if (end == NULL || *end != '\0' || pm == 0)
- return -1;
-
- /* loop through bits of the mask and mark ports */
- while (pm != 0) {
- if (pm & 0x01) { /* bit is set in mask, use port */
- if (count >= max_ports)
- RTE_LOG(WARNING, APP,
- "port %u not present - ignoring\n",
- count);
- else
- ports->id[ports->num_ports++] = count;
- }
- pm = (pm >> 1);
- count++;
- }
-
- return 0;
-}
-
/**
* Take the number of clients parameter passed to the app
* and convert to a number to store in the num_clients variable
@@ -239,363 +74,14 @@ parse_server(char **server_ip, int *server_port, char *server_addr)
return -1;
*server_ip = strtok(server_addr, delim);
- RTE_LOG(DEBUG, APP, "server ip %s\n", *server_ip);
+ RTE_LOG(DEBUG, SHARED, "server ip %s\n", *server_ip);
token = strtok(NULL, delim);
- RTE_LOG(DEBUG, APP, "token %s\n", token);
+ RTE_LOG(DEBUG, SHARED, "token %s\n", token);
if (token == NULL || *token == '\0')
return -1;
- RTE_LOG(DEBUG, APP, "token %s\n", token);
+ RTE_LOG(DEBUG, SHARED, "token %s\n", token);
*server_port = atoi(token);
return 0;
}
-
-/**
- * Retieve port type and ID from resource UID. For example, resource UID
- * 'ring:0' is parsed to retrieve port tyep 'ring' and ID '0'.
- */
-int
-parse_resource_uid(char *str, char **port_type, int *port_id)
-{
- char *token;
- char delim[] = ":";
- char *endp;
-
- RTE_LOG(DEBUG, APP, "Parsing resource UID: '%s\n'", str);
- if (strstr(str, delim) == NULL) {
- RTE_LOG(ERR, APP, "Invalid resource UID: '%s'\n", str);
- return -1;
- }
- RTE_LOG(DEBUG, APP, "Delimiter %s is included\n", delim);
-
- *port_type = strtok(str, delim);
-
- token = strtok(NULL, delim);
- *port_id = strtol(token, &endp, 10);
-
- if (*endp) {
- RTE_LOG(ERR, APP, "Bad integer value: %s\n", str);
- return -1;
- }
-
- return 0;
-}
-
-int
-spp_atoi(const char *str, int *val)
-{
- char *end;
-
- *val = strtol(str, &end, 10);
-
- if (*end) {
- RTE_LOG(ERR, APP, "Bad integer value: %s\n", str);
- return -1;
- }
-
- return 0;
-}
-
-/*
- * Get status of spp_nfv or spp_vm as JSON format. It consists of running
- * status and patch info of ports.
- *
- * Here is an example of well-formatted JSON status to better understand.
- * Actual status has no spaces and new lines inserted as
- * '{"status":"running","ports":[{"src":"phy:0","dst":"ring:0"},...]}'
- *
- * {
- * "status": "running",
- * "ports": ["phy:0", "phy:1", "ring:0", "vhost:0"],
- * "patches": [
- * {"src":"phy:0","dst": "ring:0"},
- * {"src":"ring:0","dst": "vhost:0"}
- * ]
- * }
- */
-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)
-{
- sprintf(str, "{\"client-id\":%d,", client_id);
-
- 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;
-
- RTE_LOG(INFO, APP, "Port ID %d\n", i);
- RTE_LOG(INFO, APP, "Status %d\n",
- ports_fwd_array[i].in_port_id);
-
- memset(patch_str, '\0', sizeof(patch_str));
-
- sprintf(patch_str, "{\"src\":");
-
- switch (port_map[i].port_type) {
- case PHY:
- RTE_LOG(INFO, APP, "Type: PHY\n");
- sprintf(patch_str + strlen(patch_str),
- "\"phy:%u\",",
- port_map[i].id);
- break;
- case RING:
- RTE_LOG(INFO, APP, "Type: RING\n");
- sprintf(patch_str + strlen(patch_str),
- "\"ring:%u\",",
- port_map[i].id);
- break;
- case VHOST:
- RTE_LOG(INFO, APP, "Type: VHOST\n");
- sprintf(patch_str + strlen(patch_str),
- "\"vhost:%u\",",
- port_map[i].id);
- break;
- case PCAP:
- RTE_LOG(INFO, APP, "Type: PCAP\n");
- sprintf(patch_str + strlen(patch_str),
- "\"pcap:%u\",",
- port_map[i].id);
- break;
- case NULLPMD:
- RTE_LOG(INFO, APP, "Type: NULLPMD\n");
- sprintf(patch_str + strlen(patch_str),
- "\"nullpmd:%u\",",
- port_map[i].id);
- break;
- case UNDEF:
- RTE_LOG(INFO, APP, "Type: UDF\n");
- /* TODO(yasufum) Need to remove print for undefined ? */
- sprintf(patch_str + strlen(patch_str),
- "\"udf\",");
- break;
- }
-
- 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(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(patch_str + strlen(patch_str),
- "\"phy:%u\"",
- port_map[j].id);
- break;
- case RING:
- RTE_LOG(INFO, APP, "Type: RING\n");
- sprintf(patch_str + strlen(patch_str),
- "\"ring:%u\"",
- port_map[j].id);
- break;
- case VHOST:
- RTE_LOG(INFO, APP, "Type: VHOST\n");
- sprintf(patch_str + strlen(patch_str),
- "\"vhost:%u\"",
- port_map[j].id);
- break;
- case PCAP:
- RTE_LOG(INFO, APP, "Type: PCAP\n");
- sprintf(patch_str + strlen(patch_str),
- "\"pcap:%u\"",
- port_map[j].id);
- break;
- case NULLPMD:
- RTE_LOG(INFO, APP, "Type: NULLPMD\n");
- 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(patch_str + strlen(patch_str),
- "\"udf\"");
- break;
- }
- }
-
- sprintf(patch_str + strlen(patch_str), "},");
-
- if (has_patch != 0)
- sprintf(str + strlen(str), "%s", patch_str);
- }
-
-
- // 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, "]");
- }
-
- return 0;
-}
-
-/* attach the new device, then store port_id of the device */
-int
-dev_attach_by_devargs(const char *devargs, uint16_t *port_id)
-{
- int ret = -1;
- struct rte_devargs da;
-
- memset(&da, 0, sizeof(da));
-
- /* parse devargs */
- if (rte_devargs_parse(&da, devargs))
- return -1;
-
- ret = rte_eal_hotplug_add(da.bus->name, da.name, da.args);
- if (ret < 0) {
- free(da.args);
- return ret;
- }
-
- ret = rte_eth_dev_get_port_by_name(da.name, port_id);
-
- free(da.args);
-
- return ret;
-}
-
-/* detach the device, then store the name of the device */
-int
-dev_detach_by_port_id(uint16_t port_id)
-{
- struct rte_device *dev;
- struct rte_bus *bus;
- uint32_t dev_flags;
- int ret = -1;
-
- if (rte_eth_devices[port_id].data == NULL) {
- RTE_LOG(INFO, APP,
- "rte_eth_devices[%"PRIu16"].data is NULL\n", port_id);
- return 0;
- }
- dev_flags = rte_eth_devices[port_id].data->dev_flags;
- if (dev_flags & RTE_ETH_DEV_BONDED_SLAVE) {
- RTE_LOG(ERR, APP,
- "Port %"PRIu16" is bonded, cannot detach\n", port_id);
- return -ENOTSUP;
- }
-
- dev = rte_eth_devices[port_id].device;
- if (dev == NULL)
- return -EINVAL;
-
- bus = rte_bus_find_by_device(dev);
- if (bus == NULL)
- return -ENOENT;
-
- ret = rte_eal_hotplug_remove(bus->name, dev->name);
- if (ret < 0)
- return ret;
-
- rte_eth_dev_release_port(&rte_eth_devices[port_id]);
-
- return 0;
-}
diff --git a/src/shared/common.h b/src/shared/common.h
index 3607f4b..cde013e 100644
--- a/src/shared/common.h
+++ b/src/shared/common.h
@@ -1,32 +1,14 @@
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2015-2016 Intel Corporation
+ * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
*/
-#ifndef _COMMON_H_
-#define _COMMON_H_
+#ifndef _SHARED_COMMON_H_
+#define _SHARED_COMMON_H_
#include <signal.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/socket.h>
#include <unistd.h>
-#include <limits.h>
-
-#include <rte_branch_prediction.h>
-#include <rte_common.h>
-#include <rte_config.h>
-#include <rte_eal.h>
-#include <rte_devargs.h>
-#include <rte_ethdev.h>
#include <rte_ethdev_driver.h>
-#include <rte_launch.h>
-#include <rte_lcore.h>
-#include <rte_log.h>
-#include <rte_mbuf.h>
-#include <rte_mempool.h>
-#include <rte_ring.h>
#define MSG_SIZE 2048 /* socket buffer len */
@@ -53,15 +35,6 @@
*/
#define MAX_PKT_BURST 32
-// TODO(yasufum) move it from common.h used only for primary and spp_vm.
-#define MBUFS_PER_CLIENT 1536
-#define MBUFS_PER_PORT 1536
-#define MBUF_CACHE_SIZE 512
-
-#define MBUF_OVERHEAD (sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM)
-#define RX_MBUF_DATA_SIZE 2048
-#define MBUF_SIZE (RX_MBUF_DATA_SIZE + MBUF_OVERHEAD)
-
#define RTE_MP_RX_DESC_DEFAULT 512
#define RTE_MP_TX_DESC_DEFAULT 512
@@ -124,19 +97,8 @@ struct port {
/* define common names for structures shared between server and client */
#define MP_CLIENT_RXQ_NAME "eth_ring%u"
#define PKTMBUF_POOL_NAME "MProc_pktmbuf_pool"
-#define VM_PKTMBUF_POOL_NAME "VM_Proc_pktmbuf_pool"
-#define VM_MZ_PORT_INFO "VM_Proc_port_info"
#define MZ_PORT_INFO "MProc_port_info"
-#define VHOST_BACKEND_NAME "eth_vhost%u"
-#define VHOST_IFACE_NAME "/tmp/sock%u"
-
-#define PCAP_PMD_DEV_NAME "eth_pcap%u"
-#define PCAP_IFACE_RX "/tmp/spp-rx%d.pcap"
-#define PCAP_IFACE_TX "/tmp/spp-tx%d.pcap"
-
-#define NULL_PMD_DEV_NAME "eth_null%u"
-
/*
* Given the rx queue name template above, get the queue name
*/
@@ -153,110 +115,13 @@ get_rx_queue_name(unsigned int id)
return buffer;
}
-static inline const char *
-get_vhost_backend_name(unsigned int id)
-{
- /*
- * buffer for return value. Size calculated by %u being replaced
- * by maximum 3 digits (plus an extra byte for safety)
- */
- static char buffer[sizeof(VHOST_BACKEND_NAME) + 2];
-
- snprintf(buffer, sizeof(buffer) - 1, VHOST_BACKEND_NAME, id);
- return buffer;
-}
-
-static inline char *
-get_vhost_iface_name(unsigned int id)
-{
- /*
- * buffer for return value. Size calculated by %u being replaced
- * by maximum 3 digits (plus an extra byte for safety)
- */
- static char buffer[sizeof(VHOST_IFACE_NAME) + 2];
-
- snprintf(buffer, sizeof(buffer) - 1, VHOST_IFACE_NAME, id);
- return buffer;
-}
-
-static inline const char *
-get_pcap_pmd_name(int id)
-{
- static char buffer[sizeof(PCAP_PMD_DEV_NAME) + 2];
- snprintf(buffer, sizeof(buffer) - 1, PCAP_PMD_DEV_NAME, id);
- return buffer;
-}
-
-static inline const char *
-get_null_pmd_name(int id)
-{
- static char buffer[sizeof(NULL_PMD_DEV_NAME) + 2];
- snprintf(buffer, sizeof(buffer) - 1, NULL_PMD_DEV_NAME, id);
- return buffer;
-}
-
/* Set log level of type RTE_LOGTYPE_USER* to given level. */
int set_user_log_level(int num_user_log, uint32_t log_level);
/* Set log level of type RTE_LOGTYPE_USER* to RTE_LOG_DEBUG. */
int set_user_log_debug(int num_user_log);
-void check_all_ports_link_status(struct port_info *ports, uint16_t port_num,
- uint32_t port_mask);
-
-int init_port(uint16_t port_num, struct rte_mempool *pktmbuf_pool);
-
-int parse_portmask(struct port_info *ports, uint16_t max_ports,
- const char *portmask);
int parse_num_clients(uint16_t *num_clients, const char *clients);
int parse_server(char **server_ip, int *server_port, char *server_addr);
-/* 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);
-
-int parse_resource_uid(char *str, char **port_type, int *port_id);
-int spp_atoi(const char *str, int *val);
-
-#define RTE_LOGTYPE_APP RTE_LOGTYPE_USER1
-
-/**
- * Attach a new Ethernet device specified by arguments.
- *
- * @param devargs
- * A pointer to a strings array describing the new device
- * to be attached. The strings should be a pci address like
- * '0000:01:00.0' or virtual device name like 'net_pcap0'.
- * @param port_id
- * A pointer to a port identifier actually attached.
- * @return
- * 0 on success and port_id is filled, negative on error
- */
-int
-dev_attach_by_devargs(const char *devargs, uint16_t *port_id);
-
-/**
- * Detach a Ethernet device specified by port identifier.
- * This function must be called when the device is in the
- * closed state.
- *
- * @param port_id
- * The port identifier of the device to detach.
- * @return
- * 0 on success and devname is filled, negative on error
- */
-int dev_detach_by_port_id(uint16_t port_id);
-
#endif
--
2.17.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [spp] [PATCH 5/6] shared: refactor libs of SPP secondary
2019-01-15 3:27 [spp] [PATCH 0/6] Refactor common libs ogawa.yasufumi
` (3 preceding siblings ...)
2019-01-15 3:27 ` [spp] [PATCH 4/6] shared: refactor common functions ogawa.yasufumi
@ 2019-01-15 3:28 ` ogawa.yasufumi
2019-01-15 3:28 ` [spp] [PATCH 6/6] spp_nfv: refactor file structure ogawa.yasufumi
5 siblings, 0 replies; 7+ messages in thread
From: ogawa.yasufumi @ 2019-01-15 3:28 UTC (permalink / raw)
To: ferruh.yigit, spp, ogawa.yasufumi
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
This update is to redefine common functions of SPP secondary process.
Move functions for adding port and other util functions are moved to
`shared/secondary/`.
Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
src/nfv/nfv.h | 13 -
src/nfv/nfv_utils.h | 118 ++++++
src/shared/secondary.c | 359 ------------------
src/shared/secondary.h | 102 -----
.../secondary/add_port.h} | 198 +++-------
src/shared/secondary/utils.c | 119 ++++++
src/shared/secondary/utils.h | 39 ++
7 files changed, 328 insertions(+), 620 deletions(-)
delete mode 100644 src/nfv/nfv.h
create mode 100644 src/nfv/nfv_utils.h
delete mode 100644 src/shared/secondary.c
delete mode 100644 src/shared/secondary.h
rename src/{nfv/command_utils.h => shared/secondary/add_port.h} (61%)
create mode 100644 src/shared/secondary/utils.c
create mode 100644 src/shared/secondary/utils.h
diff --git a/src/nfv/nfv.h b/src/nfv/nfv.h
deleted file mode 100644
index d9e5adf..0000000
--- a/src/nfv/nfv.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
- */
-
-#ifndef _NFV_H_
-#define _NFV_H_
-
-#include "common.h"
-#include "params.h"
-#include "command_utils.h"
-#include "commands.h"
-
-#endif // _NFV_H_
diff --git a/src/nfv/nfv_utils.h b/src/nfv/nfv_utils.h
new file mode 100644
index 0000000..aca5f13
--- /dev/null
+++ b/src/nfv/nfv_utils.h
@@ -0,0 +1,118 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2015-2016 Intel Corporation
+ * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
+ */
+
+#ifndef _NFV_NFV_UTILS_H_
+#define _NFV_NFV_UTILS_H_
+
+#define RTE_LOGTYPE_SPP_NFV RTE_LOGTYPE_USER1
+
+static void
+forward_array_remove(int port_id)
+{
+ unsigned int i;
+
+ /* Update ports_fwd_array */
+ forward_array_init_one(port_id);
+
+ for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
+ if (ports_fwd_array[i].in_port_id == PORT_RESET)
+ continue;
+
+ if (ports_fwd_array[i].out_port_id == port_id) {
+ ports_fwd_array[i].out_port_id = PORT_RESET;
+ break;
+ }
+ }
+}
+
+/* Return 0 if invalid */
+static int
+is_valid_port(uint16_t port_id)
+{
+ if (port_id > RTE_MAX_ETHPORTS)
+ return 0;
+
+ return port_map[port_id].id != PORT_RESET;
+}
+
+/*
+ * Return actual port ID which is assigned by system internally, or PORT_RESET
+ * if port is not found.
+ */
+static uint16_t
+find_port_id(int id, enum port_type type)
+{
+ uint16_t port_id = PORT_RESET;
+ uint16_t i;
+
+ for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
+ if (port_map[i].port_type != type)
+ continue;
+
+ if (port_map[i].id == id) {
+ port_id = i;
+ break;
+ }
+ }
+
+ return port_id;
+}
+
+/* Return -1 as an error if given patch is invalid */
+static int
+add_patch(uint16_t in_port, uint16_t out_port)
+{
+ if (!is_valid_port(in_port) || !is_valid_port(out_port))
+ return -1;
+
+ /* Populate in port data */
+ ports_fwd_array[in_port].in_port_id = in_port;
+ ports_fwd_array[in_port].rx_func = &rte_eth_rx_burst;
+ ports_fwd_array[in_port].tx_func = &rte_eth_tx_burst;
+ ports_fwd_array[in_port].out_port_id = out_port;
+
+ /* Populate out port data */
+ ports_fwd_array[out_port].in_port_id = out_port;
+ ports_fwd_array[out_port].rx_func = &rte_eth_rx_burst;
+ ports_fwd_array[out_port].tx_func = &rte_eth_tx_burst;
+
+ RTE_LOG(DEBUG, SPP_NFV, "STATUS: in port %d in_port_id %d\n", in_port,
+ ports_fwd_array[in_port].in_port_id);
+ RTE_LOG(DEBUG, SPP_NFV, "STATUS: in port %d patch out port id %d\n",
+ in_port, ports_fwd_array[in_port].out_port_id);
+ RTE_LOG(DEBUG, SPP_NFV, "STATUS: outport %d in_port_id %d\n", out_port,
+ ports_fwd_array[out_port].in_port_id);
+
+ return 0;
+}
+
+static void
+forward_array_reset(void)
+{
+ unsigned int i;
+
+ /* initialize port forward array*/
+ for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
+ if (ports_fwd_array[i].in_port_id != PORT_RESET) {
+ ports_fwd_array[i].out_port_id = PORT_RESET;
+ RTE_LOG(INFO, SPP_NFV, "Port ID %d\n", i);
+ RTE_LOG(INFO, SPP_NFV, "out_port_id %d\n",
+ ports_fwd_array[i].out_port_id);
+ }
+ }
+}
+
+/* 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;
+}
+
+#endif // _NFV_COMMAND_UTILS_H_
diff --git a/src/shared/secondary.c b/src/shared/secondary.c
deleted file mode 100644
index 2e986d9..0000000
--- a/src/shared/secondary.c
+++ /dev/null
@@ -1,359 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
- */
-
-#include <stdint.h>
-#include "common.h"
-#include "secondary.h"
-
-#define RTE_LOGTYPE_SHARED RTE_LOGTYPE_USER1
-
-/*
- * Get status of spp_nfv or spp_vm as JSON format. It consists of running
- * status and patch info of ports.
- *
- * Here is an example of well-formatted JSON status to better understand.
- * Actual status has no spaces and new lines inserted as
- * '{"status":"running","ports":[{"src":"phy:0","dst":"ring:0"},...]}'
- *
- * {
- * "status": "running",
- * "ports": ["phy:0", "phy:1", "ring:0", "vhost:0"],
- * "patches": [
- * {"src":"phy:0","dst": "ring:0"},
- * {"src":"ring:0","dst": "vhost:0"}
- * ]
- * }
- */
-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)
-{
- sprintf(str, "{\"client-id\":%d,", client_id);
-
- 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;
-
- RTE_LOG(INFO, SHARED, "Port ID %d\n", i);
- RTE_LOG(INFO, SHARED, "Status %d\n",
- ports_fwd_array[i].in_port_id);
-
- memset(patch_str, '\0', sizeof(patch_str));
-
- sprintf(patch_str, "{\"src\":");
-
- switch (port_map[i].port_type) {
- case PHY:
- RTE_LOG(INFO, SHARED, "Type: PHY\n");
- sprintf(patch_str + strlen(patch_str),
- "\"phy:%u\",",
- port_map[i].id);
- break;
- case RING:
- RTE_LOG(INFO, SHARED, "Type: RING\n");
- sprintf(patch_str + strlen(patch_str),
- "\"ring:%u\",",
- port_map[i].id);
- break;
- case VHOST:
- RTE_LOG(INFO, SHARED, "Type: VHOST\n");
- sprintf(patch_str + strlen(patch_str),
- "\"vhost:%u\",",
- port_map[i].id);
- break;
- case PCAP:
- RTE_LOG(INFO, SHARED, "Type: PCAP\n");
- sprintf(patch_str + strlen(patch_str),
- "\"pcap:%u\",",
- port_map[i].id);
- break;
- case NULLPMD:
- RTE_LOG(INFO, SHARED, "Type: NULLPMD\n");
- sprintf(patch_str + strlen(patch_str),
- "\"nullpmd:%u\",",
- port_map[i].id);
- break;
- case UNDEF:
- RTE_LOG(INFO, SHARED, "Type: UDF\n");
- /* TODO(yasufum) Need to remove print for undefined ? */
- sprintf(patch_str + strlen(patch_str),
- "\"udf\",");
- break;
- }
-
- sprintf(patch_str + strlen(patch_str), "\"dst\":");
-
- RTE_LOG(INFO, SHARED, "Out Port ID %d\n",
- ports_fwd_array[i].out_port_id);
-
- if (ports_fwd_array[i].out_port_id == PORT_RESET) {
- //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, SHARED, "Type: PHY\n");
- sprintf(patch_str + strlen(patch_str),
- "\"phy:%u\"",
- port_map[j].id);
- break;
- case RING:
- RTE_LOG(INFO, SHARED, "Type: RING\n");
- sprintf(patch_str + strlen(patch_str),
- "\"ring:%u\"",
- port_map[j].id);
- break;
- case VHOST:
- RTE_LOG(INFO, SHARED, "Type: VHOST\n");
- sprintf(patch_str + strlen(patch_str),
- "\"vhost:%u\"",
- port_map[j].id);
- break;
- case PCAP:
- RTE_LOG(INFO, SHARED, "Type: PCAP\n");
- sprintf(patch_str + strlen(patch_str),
- "\"pcap:%u\"",
- port_map[j].id);
- break;
- case NULLPMD:
- RTE_LOG(INFO, SHARED, "Type: NULLPMD\n");
- sprintf(patch_str + strlen(patch_str),
- "\"nullpmd:%u\"",
- port_map[j].id);
- break;
- case UNDEF:
- RTE_LOG(INFO, SHARED, "Type: UDF\n");
- /*
- * TODO(yasufum) Need to remove print for
- * undefined ?
- */
- sprintf(patch_str + strlen(patch_str),
- "\"udf\"");
- break;
- }
- }
-
- sprintf(patch_str + strlen(patch_str), "},");
-
- if (has_patch != 0)
- sprintf(str + strlen(str), "%s", patch_str);
- }
-
-
- // 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, "]");
- }
-
- return 0;
-}
-
-/**
- * Retieve port type and ID from resource UID. For example, resource UID
- * 'ring:0' is parsed to retrieve port tyep 'ring' and ID '0'.
- */
-int
-parse_resource_uid(char *str, char **port_type, int *port_id)
-{
- char *token;
- char delim[] = ":";
- char *endp;
-
- RTE_LOG(DEBUG, SHARED, "Parsing resource UID: '%s\n'", str);
- if (strstr(str, delim) == NULL) {
- RTE_LOG(ERR, SHARED, "Invalid resource UID: '%s'\n", str);
- return -1;
- }
- RTE_LOG(DEBUG, SHARED, "Delimiter %s is included\n", delim);
-
- *port_type = strtok(str, delim);
-
- token = strtok(NULL, delim);
- *port_id = strtol(token, &endp, 10);
-
- if (*endp) {
- RTE_LOG(ERR, SHARED, "Bad integer value: %s\n", str);
- return -1;
- }
-
- return 0;
-}
-
-int
-spp_atoi(const char *str, int *val)
-{
- char *end;
-
- *val = strtol(str, &end, 10);
-
- if (*end) {
- RTE_LOG(ERR, SHARED, "Bad integer value: %s\n", str);
- return -1;
- }
-
- return 0;
-}
-
-/* attach the new device, then store port_id of the device */
-int
-dev_attach_by_devargs(const char *devargs, uint16_t *port_id)
-{
- int ret = -1;
- struct rte_devargs da;
-
- memset(&da, 0, sizeof(da));
-
- /* parse devargs */
- if (rte_devargs_parse(&da, devargs))
- return -1;
-
- ret = rte_eal_hotplug_add(da.bus->name, da.name, da.args);
- if (ret < 0) {
- free(da.args);
- return ret;
- }
-
- ret = rte_eth_dev_get_port_by_name(da.name, port_id);
-
- free(da.args);
-
- return ret;
-}
-
-/* detach the device, then store the name of the device */
-int
-dev_detach_by_port_id(uint16_t port_id)
-{
- struct rte_device *dev;
- struct rte_bus *bus;
- uint32_t dev_flags;
- int ret = -1;
-
- if (rte_eth_devices[port_id].data == NULL) {
- RTE_LOG(INFO, SHARED,
- "rte_eth_devices[%"PRIu16"].data is NULL\n", port_id);
- return 0;
- }
- dev_flags = rte_eth_devices[port_id].data->dev_flags;
- if (dev_flags & RTE_ETH_DEV_BONDED_SLAVE) {
- RTE_LOG(ERR, SHARED,
- "Port %"PRIu16" is bonded, cannot detach\n", port_id);
- return -ENOTSUP;
- }
-
- dev = rte_eth_devices[port_id].device;
- if (dev == NULL)
- return -EINVAL;
-
- bus = rte_bus_find_by_device(dev);
- if (bus == NULL)
- return -ENOENT;
-
- ret = rte_eal_hotplug_remove(bus->name, dev->name);
- if (ret < 0)
- return ret;
-
- rte_eth_dev_release_port(&rte_eth_devices[port_id]);
-
- return 0;
-}
diff --git a/src/shared/secondary.h b/src/shared/secondary.h
deleted file mode 100644
index c6a1fde..0000000
--- a/src/shared/secondary.h
+++ /dev/null
@@ -1,102 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
- */
-
-#ifndef SHARED_SECONDARY_H
-#define SHARED_SECONDARY_H
-
-#define VHOST_IFACE_NAME "/tmp/sock%u"
-#define VHOST_BACKEND_NAME "eth_vhost%u"
-
-#define PCAP_PMD_DEV_NAME "eth_pcap%u"
-#define NULL_PMD_DEV_NAME "eth_null%u"
-
-static inline const char *
-get_vhost_backend_name(unsigned int id)
-{
- /*
- * buffer for return value. Size calculated by %u being replaced
- * by maximum 3 digits (plus an extra byte for safety)
- */
- static char buffer[sizeof(VHOST_BACKEND_NAME) + 2];
-
- snprintf(buffer, sizeof(buffer) - 1, VHOST_BACKEND_NAME, id);
- return buffer;
-}
-
-static inline char *
-get_vhost_iface_name(unsigned int id)
-{
- /*
- * buffer for return value. Size calculated by %u being replaced
- * by maximum 3 digits (plus an extra byte for safety)
- */
- static char buffer[sizeof(VHOST_IFACE_NAME) + 2];
-
- snprintf(buffer, sizeof(buffer) - 1, VHOST_IFACE_NAME, id);
- return buffer;
-}
-
-static inline const char *
-get_pcap_pmd_name(int id)
-{
- static char buffer[sizeof(PCAP_PMD_DEV_NAME) + 2];
- snprintf(buffer, sizeof(buffer) - 1, PCAP_PMD_DEV_NAME, id);
- return buffer;
-}
-
-static inline const char *
-get_null_pmd_name(int id)
-{
- static char buffer[sizeof(NULL_PMD_DEV_NAME) + 2];
- snprintf(buffer, sizeof(buffer) - 1, NULL_PMD_DEV_NAME, id);
- return buffer;
-}
-
-/* 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);
-
-int parse_resource_uid(char *str, char **port_type, int *port_id);
-int spp_atoi(const char *str, int *val);
-
-/**
- * Attach a new Ethernet device specified by arguments.
- *
- * @param devargs
- * A pointer to a strings array describing the new device
- * to be attached. The strings should be a pci address like
- * '0000:01:00.0' or virtual device name like 'net_pcap0'.
- * @param port_id
- * A pointer to a port identifier actually attached.
- * @return
- * 0 on success and port_id is filled, negative on error
- */
-int
-dev_attach_by_devargs(const char *devargs, uint16_t *port_id);
-
-/**
- * Detach a Ethernet device specified by port identifier.
- * This function must be called when the device is in the
- * closed state.
- *
- * @param port_id
- * The port identifier of the device to detach.
- * @return
- * 0 on success and devname is filled, negative on error
- */
-int dev_detach_by_port_id(uint16_t port_id);
-
-#endif
diff --git a/src/nfv/command_utils.h b/src/shared/secondary/add_port.h
similarity index 61%
rename from src/nfv/command_utils.h
rename to src/shared/secondary/add_port.h
index f026732..83f2514 100644
--- a/src/nfv/command_utils.h
+++ b/src/shared/secondary/add_port.h
@@ -3,122 +3,66 @@
* Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
*/
-#ifndef _NFV_COMMAND_UTILS_H_
-#define _NFV_COMMAND_UTILS_H_
+#ifndef _SHARED_SECONDARY_ADD_PORT_H_
+#define _SHARED_SECONDARY_ADD_PORT_H_
-#include "common.h"
-#include "secondary.h"
-
-#define RTE_LOGTYPE_SPP_NFV RTE_LOGTYPE_USER1
+#include <arpa/inet.h>
+#include "utils.h"
// The number of receive descriptors to allocate for the receive ring.
#define NR_DESCS 128
-#define PCAP_IFACE_RX "/tmp/spp-rx%d.pcap"
-#define PCAP_IFACE_TX "/tmp/spp-tx%d.pcap"
-
-static void
-forward_array_init_one(unsigned int i)
-{
- ports_fwd_array[i].in_port_id = PORT_RESET;
- ports_fwd_array[i].out_port_id = PORT_RESET;
-}
-
-static void
-forward_array_remove(int port_id)
-{
- unsigned int i;
-
- /* Update ports_fwd_array */
- forward_array_init_one(port_id);
+#define VHOST_IFACE_NAME "/tmp/sock%u"
+#define VHOST_BACKEND_NAME "eth_vhost%u"
- for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
- if (ports_fwd_array[i].in_port_id == PORT_RESET)
- continue;
+#define PCAP_PMD_DEV_NAME "eth_pcap%u"
+#define NULL_PMD_DEV_NAME "eth_null%u"
- if (ports_fwd_array[i].out_port_id == port_id) {
- ports_fwd_array[i].out_port_id = PORT_RESET;
- break;
- }
- }
-}
+#define PCAP_IFACE_RX "/tmp/spp-rx%d.pcap"
+#define PCAP_IFACE_TX "/tmp/spp-tx%d.pcap"
-static void
-port_map_init_one(unsigned int i)
-{
- port_map[i].id = PORT_RESET;
- port_map[i].port_type = UNDEF;
- port_map[i].stats = &port_map[i].default_stats;
-}
+#define RTE_LOGTYPE_SHARED RTE_LOGTYPE_USER1
-static void
-port_map_init(void)
+static inline const char *
+get_vhost_backend_name(unsigned int id)
{
- unsigned int i;
-
- for (i = 0; i < RTE_MAX_ETHPORTS; i++)
- port_map_init_one(i);
+ /*
+ * buffer for return value. Size calculated by %u being replaced
+ * by maximum 3 digits (plus an extra byte for safety)
+ */
+ static char buffer[sizeof(VHOST_BACKEND_NAME) + 2];
+
+ snprintf(buffer, sizeof(buffer) - 1, VHOST_BACKEND_NAME, id);
+ return buffer;
}
-/* Return 0 if invalid */
-static int
-is_valid_port(uint16_t port_id)
+static inline char *
+get_vhost_iface_name(unsigned int id)
{
- if (port_id > RTE_MAX_ETHPORTS)
- return 0;
-
- return port_map[port_id].id != PORT_RESET;
+ /*
+ * buffer for return value. Size calculated by %u being replaced
+ * by maximum 3 digits (plus an extra byte for safety)
+ */
+ static char buffer[sizeof(VHOST_IFACE_NAME) + 2];
+
+ snprintf(buffer, sizeof(buffer) - 1, VHOST_IFACE_NAME, id);
+ return buffer;
}
-/*
- * Return actual port ID which is assigned by system internally, or PORT_RESET
- * if port is not found.
- */
-static uint16_t
-find_port_id(int id, enum port_type type)
+static inline const char *
+get_pcap_pmd_name(int id)
{
- uint16_t port_id = PORT_RESET;
- uint16_t i;
-
- for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
- if (port_map[i].port_type != type)
- continue;
-
- if (port_map[i].id == id) {
- port_id = i;
- break;
- }
- }
-
- return port_id;
+ static char buffer[sizeof(PCAP_PMD_DEV_NAME) + 2];
+ snprintf(buffer, sizeof(buffer) - 1, PCAP_PMD_DEV_NAME, id);
+ return buffer;
}
-/* Return -1 as an error if given patch is invalid */
-static int
-add_patch(uint16_t in_port, uint16_t out_port)
+static inline const char *
+get_null_pmd_name(int id)
{
- if (!is_valid_port(in_port) || !is_valid_port(out_port))
- return -1;
-
- /* Populate in port data */
- ports_fwd_array[in_port].in_port_id = in_port;
- ports_fwd_array[in_port].rx_func = &rte_eth_rx_burst;
- ports_fwd_array[in_port].tx_func = &rte_eth_tx_burst;
- ports_fwd_array[in_port].out_port_id = out_port;
-
- /* Populate out port data */
- ports_fwd_array[out_port].in_port_id = out_port;
- ports_fwd_array[out_port].rx_func = &rte_eth_rx_burst;
- ports_fwd_array[out_port].tx_func = &rte_eth_tx_burst;
-
- RTE_LOG(DEBUG, SPP_NFV, "STATUS: in port %d in_port_id %d\n", in_port,
- ports_fwd_array[in_port].in_port_id);
- RTE_LOG(DEBUG, SPP_NFV, "STATUS: in port %d patch out port id %d\n",
- in_port, ports_fwd_array[in_port].out_port_id);
- RTE_LOG(DEBUG, SPP_NFV, "STATUS: outport %d in_port_id %d\n", out_port,
- ports_fwd_array[out_port].in_port_id);
-
- return 0;
+ static char buffer[sizeof(NULL_PMD_DEV_NAME) + 2];
+ snprintf(buffer, sizeof(buffer) - 1, NULL_PMD_DEV_NAME, id);
+ return buffer;
}
/*
@@ -141,7 +85,7 @@ create_pcap_rx(char *rx_fpath)
if (tmp_fp == NULL) {
(tmp_fp = fopen(template, "w"));
if (tmp_fp == NULL) {
- RTE_LOG(ERR, SPP_NFV, "Failed to open %s\n", template);
+ RTE_LOG(ERR, SHARED, "Failed to open %s\n", template);
return -1;
}
}
@@ -149,12 +93,12 @@ create_pcap_rx(char *rx_fpath)
sprintf(cmd_str, "text2pcap %s %s", template, rx_fpath);
res = system(cmd_str);
if (res != 0) {
- RTE_LOG(ERR, SPP_NFV,
+ RTE_LOG(ERR, SHARED,
"Failed to create pcap device %s\n",
rx_fpath);
return -1;
}
- RTE_LOG(INFO, SPP_NFV, "PCAP device created\n");
+ RTE_LOG(INFO, SHARED, "PCAP device created\n");
fclose(tmp_fp);
return 0;
}
@@ -175,21 +119,21 @@ add_ring_pmd(int ring_id)
/* Look up ring with provided ring_id */
ring = rte_ring_lookup(rx_queue_name);
if (ring == NULL) {
- RTE_LOG(ERR, SPP_NFV,
+ RTE_LOG(ERR, SHARED,
"Failed to get RX ring %s - is primary running?\n",
rx_queue_name);
return -1;
}
- RTE_LOG(INFO, SPP_NFV, "Looked up ring '%s'\n", rx_queue_name);
+ RTE_LOG(INFO, SHARED, "Looked up ring '%s'\n", rx_queue_name);
/* create ring pmd*/
res = rte_eth_from_ring(ring);
if (res < 0) {
- RTE_LOG(ERR, SPP_NFV,
+ RTE_LOG(ERR, SHARED,
"Cannot create eth dev with rte_eth_from_ring()\n");
return -1;
}
- RTE_LOG(INFO, SPP_NFV, "Created ring PMD: %d\n", res);
+ RTE_LOG(INFO, SHARED, "Created ring PMD: %d\n", res);
return res;
}
@@ -248,7 +192,7 @@ add_vhost_pmd(int index)
if (ret < 0)
return ret;
- RTE_LOG(DEBUG, SPP_NFV, "vhost port id %d\n", vhost_port_id);
+ RTE_LOG(DEBUG, SHARED, "vhost port id %d\n", vhost_port_id);
return vhost_port_id;
}
@@ -335,7 +279,7 @@ add_pcap_pmd(int index)
if (ret < 0)
return ret;
- RTE_LOG(DEBUG, SPP_NFV, "pcap port id %d\n", pcap_pmd_port_id);
+ RTE_LOG(DEBUG, SHARED, "pcap port id %d\n", pcap_pmd_port_id);
return pcap_pmd_port_id;
}
@@ -397,47 +341,9 @@ add_null_pmd(int index)
if (ret < 0)
return ret;
- RTE_LOG(DEBUG, SPP_NFV, "null port id %d\n", null_pmd_port_id);
+ RTE_LOG(DEBUG, SHARED, "null port id %d\n", null_pmd_port_id);
return null_pmd_port_id;
}
-/* initialize forward array with default value*/
-static void
-forward_array_init(void)
-{
- unsigned int i;
-
- /* initialize port forward array*/
- for (i = 0; i < RTE_MAX_ETHPORTS; i++)
- forward_array_init_one(i);
-}
-
-static void
-forward_array_reset(void)
-{
- unsigned int i;
-
- /* initialize port forward array*/
- for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
- if (ports_fwd_array[i].in_port_id != PORT_RESET) {
- ports_fwd_array[i].out_port_id = PORT_RESET;
- RTE_LOG(INFO, SPP_NFV, "Port ID %d\n", i);
- RTE_LOG(INFO, SPP_NFV, "out_port_id %d\n",
- ports_fwd_array[i].out_port_id);
- }
- }
-}
-
-/* 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;
-}
-
-#endif // _NFV_COMMAND_UTILS_H_
+#endif
diff --git a/src/shared/secondary/utils.c b/src/shared/secondary/utils.c
new file mode 100644
index 0000000..8f2e830
--- /dev/null
+++ b/src/shared/secondary/utils.c
@@ -0,0 +1,119 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
+ */
+
+#include <stdint.h>
+#include "shared/common.h"
+#include "shared/secondary/utils.h"
+
+#define RTE_LOGTYPE_SHARED RTE_LOGTYPE_USER1
+
+/**
+ * Retieve port type and ID from resource UID. For example, resource UID
+ * 'ring:0' is parsed to retrieve port tyep 'ring' and ID '0'.
+ */
+int
+parse_resource_uid(char *str, char **port_type, int *port_id)
+{
+ char *token;
+ char delim[] = ":";
+ char *endp;
+
+ RTE_LOG(DEBUG, SHARED, "Parsing resource UID: '%s\n'", str);
+ if (strstr(str, delim) == NULL) {
+ RTE_LOG(ERR, SHARED, "Invalid resource UID: '%s'\n", str);
+ return -1;
+ }
+ RTE_LOG(DEBUG, SHARED, "Delimiter %s is included\n", delim);
+
+ *port_type = strtok(str, delim);
+
+ token = strtok(NULL, delim);
+ *port_id = strtol(token, &endp, 10);
+
+ if (*endp) {
+ RTE_LOG(ERR, SHARED, "Bad integer value: %s\n", str);
+ return -1;
+ }
+
+ return 0;
+}
+
+int
+spp_atoi(const char *str, int *val)
+{
+ char *end;
+
+ *val = strtol(str, &end, 10);
+
+ if (*end) {
+ RTE_LOG(ERR, SHARED, "Bad integer value: %s\n", str);
+ return -1;
+ }
+
+ return 0;
+}
+
+/* attach the new device, then store port_id of the device */
+int
+dev_attach_by_devargs(const char *devargs, uint16_t *port_id)
+{
+ int ret = -1;
+ struct rte_devargs da;
+
+ memset(&da, 0, sizeof(da));
+
+ /* parse devargs */
+ if (rte_devargs_parse(&da, devargs))
+ return -1;
+
+ ret = rte_eal_hotplug_add(da.bus->name, da.name, da.args);
+ if (ret < 0) {
+ free(da.args);
+ return ret;
+ }
+
+ ret = rte_eth_dev_get_port_by_name(da.name, port_id);
+
+ free(da.args);
+
+ return ret;
+}
+
+/* detach the device, then store the name of the device */
+int
+dev_detach_by_port_id(uint16_t port_id)
+{
+ struct rte_device *dev;
+ struct rte_bus *bus;
+ uint32_t dev_flags;
+ int ret = -1;
+
+ if (rte_eth_devices[port_id].data == NULL) {
+ RTE_LOG(INFO, SHARED,
+ "rte_eth_devices[%"PRIu16"].data is NULL\n", port_id);
+ return 0;
+ }
+ dev_flags = rte_eth_devices[port_id].data->dev_flags;
+ if (dev_flags & RTE_ETH_DEV_BONDED_SLAVE) {
+ RTE_LOG(ERR, SHARED,
+ "Port %"PRIu16" is bonded, cannot detach\n", port_id);
+ return -ENOTSUP;
+ }
+
+ dev = rte_eth_devices[port_id].device;
+ if (dev == NULL)
+ return -EINVAL;
+
+ bus = rte_bus_find_by_device(dev);
+ if (bus == NULL)
+ return -ENOENT;
+
+ ret = rte_eal_hotplug_remove(bus->name, dev->name);
+ if (ret < 0)
+ return ret;
+
+ rte_eth_dev_release_port(&rte_eth_devices[port_id]);
+
+ return 0;
+}
diff --git a/src/shared/secondary/utils.h b/src/shared/secondary/utils.h
new file mode 100644
index 0000000..c905b12
--- /dev/null
+++ b/src/shared/secondary/utils.h
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
+ */
+
+#ifndef _SHARED_SECONDARY_UTILS_H_
+#define _SHARED_SECONDARY_UTILS_H_
+
+int parse_resource_uid(char *str, char **port_type, int *port_id);
+
+int spp_atoi(const char *str, int *val);
+
+/**
+ * Attach a new Ethernet device specified by arguments.
+ *
+ * @param devargs
+ * A pointer to a strings array describing the new device
+ * to be attached. The strings should be a pci address like
+ * '0000:01:00.0' or virtual device name like 'net_pcap0'.
+ * @param port_id
+ * A pointer to a port identifier actually attached.
+ * @return
+ * 0 on success and port_id is filled, negative on error
+ */
+int
+dev_attach_by_devargs(const char *devargs, uint16_t *port_id);
+
+/**
+ * Detach a Ethernet device specified by port identifier.
+ * This function must be called when the device is in the
+ * closed state.
+ *
+ * @param port_id
+ * The port identifier of the device to detach.
+ * @return
+ * 0 on success and devname is filled, negative on error
+ */
+int dev_detach_by_port_id(uint16_t port_id);
+
+#endif
--
2.17.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [spp] [PATCH 6/6] spp_nfv: refactor file structure
2019-01-15 3:27 [spp] [PATCH 0/6] Refactor common libs ogawa.yasufumi
` (4 preceding siblings ...)
2019-01-15 3:28 ` [spp] [PATCH 5/6] shared: refactor libs of SPP secondary ogawa.yasufumi
@ 2019-01-15 3:28 ` ogawa.yasufumi
5 siblings, 0 replies; 7+ messages in thread
From: ogawa.yasufumi @ 2019-01-15 3:28 UTC (permalink / raw)
To: ferruh.yigit, spp, ogawa.yasufumi
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
* Move init functions to `init.h`.
* Move functions for getting status to `nfv_status.c` and
`nfv_status.h`.
* Change include path to explicitly include shared functions, for
instance, from `common.h` to `shared/common.h`.<Paste>
Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
src/Makefile | 2 +-
src/nfv/Makefile | 4 +-
src/nfv/commands.h | 4 +-
src/nfv/init.h | 44 ++++++++
src/nfv/main.c | 9 +-
src/nfv/nfv_status.c | 249 +++++++++++++++++++++++++++++++++++++++++++
src/nfv/nfv_status.h | 24 +++++
7 files changed, 329 insertions(+), 7 deletions(-)
create mode 100644 src/nfv/init.h
create mode 100644 src/nfv/nfv_status.c
create mode 100644 src/nfv/nfv_status.h
diff --git a/src/Makefile b/src/Makefile
index 8e2bffa..4cf7ef4 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -38,8 +38,8 @@ RTE_TARGET ?= x86_64-native-linuxapp-gcc
include $(RTE_SDK)/mk/rte.vars.mk
-DIRS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += nfv
DIRS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += primary
+DIRS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += nfv
DIRS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += vf
DIRS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += mirror
diff --git a/src/nfv/Makefile b/src/nfv/Makefile
index cee1236..e921010 100644
--- a/src/nfv/Makefile
+++ b/src/nfv/Makefile
@@ -13,11 +13,11 @@ include $(RTE_SDK)/mk/rte.vars.mk
APP = spp_nfv
# all source are stored in SRCS-y
-SRCS-y := main.c ../shared/common.c ../shared/secondary.c
+SRCS-y := main.c nfv_status.c ../shared/common.c ../shared/secondary/utils.c
CFLAGS += -DALLOW_EXPERIMENTAL_API
CFLAGS += $(WERROR_FLAGS) -O3 -MMD
-CFLAGS += -I$(SRCDIR)/../shared
+CFLAGS += -I$(SRCDIR)/../
ifeq ($(CONFIG_RTE_BUILD_SHARED_LIB),y)
LDLIBS += -lrte_pmd_ring
diff --git a/src/nfv/commands.h b/src/nfv/commands.h
index 35340f9..3280d69 100644
--- a/src/nfv/commands.h
+++ b/src/nfv/commands.h
@@ -6,9 +6,7 @@
#ifndef _NFV_COMMANDS_H_
#define _NFV_COMMANDS_H_
-#include "common.h"
-#include "nfv.h"
-#include "command_utils.h"
+#include "shared/secondary/add_port.h"
#define RTE_LOGTYPE_SPP_NFV RTE_LOGTYPE_USER1
diff --git a/src/nfv/init.h b/src/nfv/init.h
new file mode 100644
index 0000000..0702082
--- /dev/null
+++ b/src/nfv/init.h
@@ -0,0 +1,44 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2015-2016 Intel Corporation
+ * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
+ */
+
+#ifndef _NFV_INIT_H_
+#define _NFV_INIT_H_
+
+static void
+forward_array_init_one(unsigned int i)
+{
+ ports_fwd_array[i].in_port_id = PORT_RESET;
+ ports_fwd_array[i].out_port_id = PORT_RESET;
+}
+
+/* initialize forward array with default value*/
+static void
+forward_array_init(void)
+{
+ unsigned int i;
+
+ /* initialize port forward array*/
+ for (i = 0; i < RTE_MAX_ETHPORTS; i++)
+ forward_array_init_one(i);
+}
+
+static void
+port_map_init_one(unsigned int i)
+{
+ port_map[i].id = PORT_RESET;
+ port_map[i].port_type = UNDEF;
+ port_map[i].stats = &port_map[i].default_stats;
+}
+
+static void
+port_map_init(void)
+{
+ unsigned int i;
+
+ for (i = 0; i < RTE_MAX_ETHPORTS; i++)
+ port_map_init_one(i);
+}
+
+#endif
diff --git a/src/nfv/main.c b/src/nfv/main.c
index 6e9e844..ce7e07d 100644
--- a/src/nfv/main.c
+++ b/src/nfv/main.c
@@ -11,7 +11,14 @@
#include <rte_memzone.h>
#include <rte_log.h>
-#include "nfv.h"
+#include "shared/common.h"
+#include "shared/secondary/add_port.h"
+
+#include "params.h"
+#include "init.h"
+#include "nfv_status.h"
+#include "nfv_utils.h"
+#include "commands.h"
#define RTE_LOGTYPE_SPP_NFV RTE_LOGTYPE_USER1
diff --git a/src/nfv/nfv_status.c b/src/nfv/nfv_status.c
new file mode 100644
index 0000000..8f66d1f
--- /dev/null
+++ b/src/nfv/nfv_status.c
@@ -0,0 +1,249 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
+ */
+
+#define RTE_LOGTYPE_SHARED RTE_LOGTYPE_USER1
+
+#include <arpa/inet.h>
+#include "shared/common.h"
+#include "nfv_status.h"
+
+/*
+ * Get status of spp_nfv or spp_vm as JSON format. It consists of running
+ * status and patch info of ports.
+ *
+ * Here is an example of well-formatted JSON status to better understand.
+ * Actual status has no spaces and new lines inserted as
+ * '{"status":"running","ports":[{"src":"phy:0","dst":"ring:0"},...]}'
+ *
+ * {
+ * "status": "running",
+ * "ports": ["phy:0", "phy:1", "ring:0", "vhost:0"],
+ * "patches": [
+ * {"src":"phy:0","dst": "ring:0"},
+ * {"src":"ring:0","dst": "vhost:0"}
+ * ]
+ * }
+ */
+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)
+{
+ sprintf(str, "{\"client-id\":%d,", client_id);
+
+ 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;
+
+ RTE_LOG(INFO, SHARED, "Port ID %d\n", i);
+ RTE_LOG(INFO, SHARED, "Status %d\n",
+ ports_fwd_array[i].in_port_id);
+
+ memset(patch_str, '\0', sizeof(patch_str));
+
+ sprintf(patch_str, "{\"src\":");
+
+ switch (port_map[i].port_type) {
+ case PHY:
+ RTE_LOG(INFO, SHARED, "Type: PHY\n");
+ sprintf(patch_str + strlen(patch_str),
+ "\"phy:%u\",",
+ port_map[i].id);
+ break;
+ case RING:
+ RTE_LOG(INFO, SHARED, "Type: RING\n");
+ sprintf(patch_str + strlen(patch_str),
+ "\"ring:%u\",",
+ port_map[i].id);
+ break;
+ case VHOST:
+ RTE_LOG(INFO, SHARED, "Type: VHOST\n");
+ sprintf(patch_str + strlen(patch_str),
+ "\"vhost:%u\",",
+ port_map[i].id);
+ break;
+ case PCAP:
+ RTE_LOG(INFO, SHARED, "Type: PCAP\n");
+ sprintf(patch_str + strlen(patch_str),
+ "\"pcap:%u\",",
+ port_map[i].id);
+ break;
+ case NULLPMD:
+ RTE_LOG(INFO, SHARED, "Type: NULLPMD\n");
+ sprintf(patch_str + strlen(patch_str),
+ "\"nullpmd:%u\",",
+ port_map[i].id);
+ break;
+ case UNDEF:
+ RTE_LOG(INFO, SHARED, "Type: UDF\n");
+ /* TODO(yasufum) Need to remove print for undefined ? */
+ sprintf(patch_str + strlen(patch_str),
+ "\"udf\",");
+ break;
+ }
+
+ sprintf(patch_str + strlen(patch_str), "\"dst\":");
+
+ RTE_LOG(INFO, SHARED, "Out Port ID %d\n",
+ ports_fwd_array[i].out_port_id);
+
+ if (ports_fwd_array[i].out_port_id == PORT_RESET) {
+ //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, SHARED, "Type: PHY\n");
+ sprintf(patch_str + strlen(patch_str),
+ "\"phy:%u\"",
+ port_map[j].id);
+ break;
+ case RING:
+ RTE_LOG(INFO, SHARED, "Type: RING\n");
+ sprintf(patch_str + strlen(patch_str),
+ "\"ring:%u\"",
+ port_map[j].id);
+ break;
+ case VHOST:
+ RTE_LOG(INFO, SHARED, "Type: VHOST\n");
+ sprintf(patch_str + strlen(patch_str),
+ "\"vhost:%u\"",
+ port_map[j].id);
+ break;
+ case PCAP:
+ RTE_LOG(INFO, SHARED, "Type: PCAP\n");
+ sprintf(patch_str + strlen(patch_str),
+ "\"pcap:%u\"",
+ port_map[j].id);
+ break;
+ case NULLPMD:
+ RTE_LOG(INFO, SHARED, "Type: NULLPMD\n");
+ sprintf(patch_str + strlen(patch_str),
+ "\"nullpmd:%u\"",
+ port_map[j].id);
+ break;
+ case UNDEF:
+ RTE_LOG(INFO, SHARED, "Type: UDF\n");
+ /*
+ * TODO(yasufum) Need to remove print for
+ * undefined ?
+ */
+ sprintf(patch_str + strlen(patch_str),
+ "\"udf\"");
+ break;
+ }
+ }
+
+ sprintf(patch_str + strlen(patch_str), "},");
+
+ if (has_patch != 0)
+ sprintf(str + strlen(str), "%s", patch_str);
+ }
+
+
+ // 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, "]");
+ }
+
+ return 0;
+}
diff --git a/src/nfv/nfv_status.h b/src/nfv/nfv_status.h
new file mode 100644
index 0000000..c7aee4f
--- /dev/null
+++ b/src/nfv/nfv_status.h
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
+ */
+
+#ifndef _NFV_STATUS_H_
+#define _NFV_STATUS_H_
+
+/* 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);
+
+#endif
--
2.17.1
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2019-01-15 3:30 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-15 3:27 [spp] [PATCH 0/6] Refactor common libs ogawa.yasufumi
2019-01-15 3:27 ` [spp] [PATCH 1/6] spp_primary: refactor common for primary ogawa.yasufumi
2019-01-15 3:27 ` [spp] [PATCH 2/6] shared: refactor common for SPP secondaries ogawa.yasufumi
2019-01-15 3:27 ` [spp] [PATCH 3/6] spp_nfv: refactor common for spp_nfv ogawa.yasufumi
2019-01-15 3:27 ` [spp] [PATCH 4/6] shared: refactor common functions ogawa.yasufumi
2019-01-15 3:28 ` [spp] [PATCH 5/6] shared: refactor libs of SPP secondary ogawa.yasufumi
2019-01-15 3:28 ` [spp] [PATCH 6/6] spp_nfv: refactor file structure 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).