From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from tama50.ecl.ntt.co.jp (tama50.ecl.ntt.co.jp [129.60.39.147]) by dpdk.org (Postfix) with ESMTP id 797581B429 for ; Tue, 25 Dec 2018 08:37:49 +0100 (CET) Received: from vc1.ecl.ntt.co.jp (vc1.ecl.ntt.co.jp [129.60.86.153]) by tama50.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id wBP7blKd029302; Tue, 25 Dec 2018 16:37:47 +0900 Received: from vc1.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id CE227EA7D4A; Tue, 25 Dec 2018 16:37:47 +0900 (JST) Received: from localhost.localdomain (lobster.nslab.ecl.ntt.co.jp [129.60.13.95]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id BED80EA7B29; Tue, 25 Dec 2018 16:37:47 +0900 (JST) From: ogawa.yasufumi@lab.ntt.co.jp To: ferruh.yigit@intel.com, spp@dpdk.org, ogawa.yasufumi@lab.ntt.co.jp Date: Tue, 25 Dec 2018 16:35:35 +0900 Message-Id: <1545723335-3547-5-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1545723335-3547-1-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> References: <1545723335-3547-1-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> X-TM-AS-MML: disable Subject: [spp] [PATCH 4/4] spp_nfv: move defines and util functions X-BeenThere: spp@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Soft Patch Panel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Dec 2018 07:37:50 -0000 From: Yasufumi Ogawa Move all of utility functions from `commands.h` to `command_utils.h`. This update also moves defines in shared and primary. Signed-off-by: Yasufumi Ogawa --- src/nfv/command_utils.h | 297 ++++++++++++++++++++++++++++++++++++++++++++++++ src/nfv/commands.h | 295 ----------------------------------------------- src/primary/main.c | 4 + src/shared/common.h | 25 ++-- 4 files changed, 317 insertions(+), 304 deletions(-) diff --git a/src/nfv/command_utils.h b/src/nfv/command_utils.h index e84eaa7..e3c7db1 100644 --- a/src/nfv/command_utils.h +++ b/src/nfv/command_utils.h @@ -8,6 +8,9 @@ #include "common.h" #include "nfv.h" +// The number of receive descriptors to allocate for the receive ring. +#define NR_DESCS 128 + static void forward_array_init_one(unsigned int i) { @@ -62,6 +65,57 @@ is_valid_port(uint16_t port_id) } /* + * 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, APP, "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", + in_port, ports_fwd_array[in_port].out_port_id); + RTE_LOG(DEBUG, APP, "STATUS: outport %d in_port_id %d\n", out_port, + ports_fwd_array[out_port].in_port_id); + + return 0; +} + +/* * Create an empty rx pcap file to given path if it does not exit * Return 0 for succeeded, or -1 for failed. */ @@ -99,6 +153,249 @@ create_pcap_rx(char *rx_fpath) return 0; } +/* + * Create ring PMD with given ring_id. + */ +static int +add_ring_pmd(int ring_id) +{ + struct rte_ring *ring; + int res; + char rx_queue_name[32]; /* Prefix and number like as 'eth_ring_0' */ + + memset(rx_queue_name, '\0', sizeof(rx_queue_name)); + sprintf(rx_queue_name, "%s", get_rx_queue_name(ring_id)); + + /* Look up ring with provided ring_id */ + ring = rte_ring_lookup(rx_queue_name); + if (ring == NULL) { + RTE_LOG(ERR, APP, + "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); + + /* create ring pmd*/ + res = rte_eth_from_ring(ring); + if (res < 0) { + RTE_LOG(ERR, APP, + "Cannot create eth dev with rte_eth_from_ring()\n"); + return -1; + } + RTE_LOG(INFO, APP, "Created ring PMD: %d\n", res); + + return res; +} + +static int +add_vhost_pmd(int index) +{ + struct rte_eth_conf port_conf = { + .rxmode = { .max_rx_pkt_len = ETHER_MAX_LEN } + }; + struct rte_mempool *mp; + uint16_t vhost_port_id; + int nr_queues = 1; + const char *name; + char devargs[64]; + char *iface; + uint16_t q; + int ret; + + mp = rte_mempool_lookup(PKTMBUF_POOL_NAME); + if (mp == NULL) + rte_exit(EXIT_FAILURE, "Cannot get mempool for mbufs\n"); + + /* eth_vhost0 index 0 iface /tmp/sock0 on numa 0 */ + name = get_vhost_backend_name(index); + iface = get_vhost_iface_name(index); + + sprintf(devargs, "%s,iface=%s,queues=%d", name, iface, nr_queues); + ret = dev_attach_by_devargs(devargs, &vhost_port_id); + if (ret < 0) + return ret; + + ret = rte_eth_dev_configure(vhost_port_id, nr_queues, nr_queues, + &port_conf); + if (ret < 0) + return ret; + + /* Allocate and set up 1 RX queue per Ethernet port. */ + for (q = 0; q < nr_queues; q++) { + ret = rte_eth_rx_queue_setup(vhost_port_id, q, NR_DESCS, + rte_eth_dev_socket_id(vhost_port_id), NULL, mp); + if (ret < 0) + return ret; + } + + /* Allocate and set up 1 TX queue per Ethernet port. */ + for (q = 0; q < nr_queues; q++) { + ret = rte_eth_tx_queue_setup(vhost_port_id, q, NR_DESCS, + rte_eth_dev_socket_id(vhost_port_id), NULL); + if (ret < 0) + return ret; + } + + /* Start the Ethernet port. */ + ret = rte_eth_dev_start(vhost_port_id); + if (ret < 0) + return ret; + + RTE_LOG(DEBUG, APP, "vhost port id %d\n", vhost_port_id); + + return vhost_port_id; +} + +/* + * Open pcap files with given index for rx and tx. + * Index is given as a argument of 'patch' command. + * This function returns a port ID if it is succeeded, + * or negative int if failed. + */ +static int +add_pcap_pmd(int index) +{ + struct rte_eth_conf port_conf = { + .rxmode = { .max_rx_pkt_len = ETHER_MAX_LEN } + }; + + struct rte_mempool *mp; + const char *name; + char devargs[256]; + uint16_t pcap_pmd_port_id; + uint16_t nr_queues = 1; + int ret; + + // PCAP file path + char rx_fpath[128]; + char tx_fpath[128]; + + FILE *rx_fp; + + sprintf(rx_fpath, PCAP_IFACE_RX, index); + sprintf(tx_fpath, PCAP_IFACE_TX, index); + + // create rx pcap file if it does not exist + rx_fp = fopen(rx_fpath, "r"); + if (rx_fp == NULL) { + ret = create_pcap_rx(rx_fpath); + if (ret < 0) + return ret; + } + + mp = rte_mempool_lookup(PKTMBUF_POOL_NAME); + if (mp == NULL) + rte_exit(EXIT_FAILURE, "Cannon get mempool for mbuf\n"); + + name = get_pcap_pmd_name(index); + sprintf(devargs, + "%s,rx_pcap=%s,tx_pcap=%s", + name, rx_fpath, tx_fpath); + ret = dev_attach_by_devargs(devargs, &pcap_pmd_port_id); + + if (ret < 0) + return ret; + + ret = rte_eth_dev_configure( + pcap_pmd_port_id, nr_queues, nr_queues, &port_conf); + + if (ret < 0) + return ret; + + /* Allocate and set up 1 RX queue per Ethernet port. */ + uint16_t q; + for (q = 0; q < nr_queues; q++) { + ret = rte_eth_rx_queue_setup( + pcap_pmd_port_id, q, NR_DESCS, + rte_eth_dev_socket_id(pcap_pmd_port_id), + NULL, mp); + if (ret < 0) + return ret; + } + + /* Allocate and set up 1 TX queue per Ethernet port. */ + for (q = 0; q < nr_queues; q++) { + ret = rte_eth_tx_queue_setup( + pcap_pmd_port_id, q, NR_DESCS, + rte_eth_dev_socket_id(pcap_pmd_port_id), + NULL); + if (ret < 0) + return ret; + } + + ret = rte_eth_dev_start(pcap_pmd_port_id); + + if (ret < 0) + return ret; + + RTE_LOG(DEBUG, APP, "pcap port id %d\n", pcap_pmd_port_id); + + return pcap_pmd_port_id; +} + +static int +add_null_pmd(int index) +{ + struct rte_eth_conf port_conf = { + .rxmode = { .max_rx_pkt_len = ETHER_MAX_LEN } + }; + + struct rte_mempool *mp; + const char *name; + char devargs[64]; + uint16_t null_pmd_port_id; + uint16_t nr_queues = 1; + + int ret; + + mp = rte_mempool_lookup(PKTMBUF_POOL_NAME); + if (mp == NULL) + rte_exit(EXIT_FAILURE, "Cannon get mempool for mbuf\n"); + + name = get_null_pmd_name(index); + sprintf(devargs, "%s", name); + ret = dev_attach_by_devargs(devargs, &null_pmd_port_id); + if (ret < 0) + return ret; + + ret = rte_eth_dev_configure( + null_pmd_port_id, nr_queues, nr_queues, + &port_conf); + if (ret < 0) + return ret; + + /* Allocate and set up 1 RX queue per Ethernet port. */ + uint16_t q; + for (q = 0; q < nr_queues; q++) { + ret = rte_eth_rx_queue_setup( + null_pmd_port_id, q, NR_DESCS, + rte_eth_dev_socket_id( + null_pmd_port_id), NULL, mp); + if (ret < 0) + return ret; + } + + /* Allocate and set up 1 TX queue per Ethernet port. */ + for (q = 0; q < nr_queues; q++) { + ret = rte_eth_tx_queue_setup( + null_pmd_port_id, q, NR_DESCS, + rte_eth_dev_socket_id( + null_pmd_port_id), + NULL); + if (ret < 0) + return ret; + } + + ret = rte_eth_dev_start(null_pmd_port_id); + if (ret < 0) + return ret; + + RTE_LOG(DEBUG, APP, "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) diff --git a/src/nfv/commands.h b/src/nfv/commands.h index 89dfd31..b33625f 100644 --- a/src/nfv/commands.h +++ b/src/nfv/commands.h @@ -9,29 +9,6 @@ #include "nfv.h" #include "command_utils.h" -/* - * 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; -} - static int do_del(char *res_uid) { @@ -82,278 +59,6 @@ do_del(char *res_uid) return 0; } -/* 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, APP, "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", - in_port, ports_fwd_array[in_port].out_port_id); - RTE_LOG(DEBUG, APP, "STATUS: outport %d in_port_id %d\n", out_port, - ports_fwd_array[out_port].in_port_id); - - return 0; -} - -/* - * Create ring PMD with given ring_id. - */ -static int -add_ring_pmd(int ring_id) -{ - struct rte_ring *ring; - int res; - char rx_queue_name[32]; /* Prefix and number like as 'eth_ring_0' */ - - memset(rx_queue_name, '\0', sizeof(rx_queue_name)); - sprintf(rx_queue_name, "%s", get_rx_queue_name(ring_id)); - - /* Look up ring with provided ring_id */ - ring = rte_ring_lookup(rx_queue_name); - if (ring == NULL) { - RTE_LOG(ERR, APP, - "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); - - /* create ring pmd*/ - res = rte_eth_from_ring(ring); - if (res < 0) { - RTE_LOG(ERR, APP, - "Cannot create eth dev with rte_eth_from_ring()\n"); - return -1; - } - RTE_LOG(INFO, APP, "Created ring PMD: %d\n", res); - - return res; -} - -static int -add_vhost_pmd(int index) -{ - struct rte_eth_conf port_conf = { - .rxmode = { .max_rx_pkt_len = ETHER_MAX_LEN } - }; - struct rte_mempool *mp; - uint16_t vhost_port_id; - int nr_queues = 1; - const char *name; - char devargs[64]; - char *iface; - uint16_t q; - int ret; -#define NR_DESCS 128 - - mp = rte_mempool_lookup(PKTMBUF_POOL_NAME); - if (mp == NULL) - rte_exit(EXIT_FAILURE, "Cannot get mempool for mbufs\n"); - - /* eth_vhost0 index 0 iface /tmp/sock0 on numa 0 */ - name = get_vhost_backend_name(index); - iface = get_vhost_iface_name(index); - - sprintf(devargs, "%s,iface=%s,queues=%d", name, iface, nr_queues); - ret = dev_attach_by_devargs(devargs, &vhost_port_id); - if (ret < 0) - return ret; - - ret = rte_eth_dev_configure(vhost_port_id, nr_queues, nr_queues, - &port_conf); - if (ret < 0) - return ret; - - /* Allocate and set up 1 RX queue per Ethernet port. */ - for (q = 0; q < nr_queues; q++) { - ret = rte_eth_rx_queue_setup(vhost_port_id, q, NR_DESCS, - rte_eth_dev_socket_id(vhost_port_id), NULL, mp); - if (ret < 0) - return ret; - } - - /* Allocate and set up 1 TX queue per Ethernet port. */ - for (q = 0; q < nr_queues; q++) { - ret = rte_eth_tx_queue_setup(vhost_port_id, q, NR_DESCS, - rte_eth_dev_socket_id(vhost_port_id), NULL); - if (ret < 0) - return ret; - } - - /* Start the Ethernet port. */ - ret = rte_eth_dev_start(vhost_port_id); - if (ret < 0) - return ret; - - RTE_LOG(DEBUG, APP, "vhost port id %d\n", vhost_port_id); - - return vhost_port_id; -} - -/* - * Open pcap files with given index for rx and tx. - * Index is given as a argument of 'patch' command. - * This function returns a port ID if it is succeeded, - * or negative int if failed. - */ -static int -add_pcap_pmd(int index) -{ - struct rte_eth_conf port_conf = { - .rxmode = { .max_rx_pkt_len = ETHER_MAX_LEN } - }; - - struct rte_mempool *mp; - const char *name; - char devargs[256]; - uint16_t pcap_pmd_port_id; - uint16_t nr_queues = 1; - int ret; - - // PCAP file path - char rx_fpath[128]; - char tx_fpath[128]; - - FILE *rx_fp; - - sprintf(rx_fpath, PCAP_IFACE_RX, index); - sprintf(tx_fpath, PCAP_IFACE_TX, index); - - // create rx pcap file if it does not exist - rx_fp = fopen(rx_fpath, "r"); - if (rx_fp == NULL) { - ret = create_pcap_rx(rx_fpath); - if (ret < 0) - return ret; - } - - mp = rte_mempool_lookup(PKTMBUF_POOL_NAME); - if (mp == NULL) - rte_exit(EXIT_FAILURE, "Cannon get mempool for mbuf\n"); - - name = get_pcap_pmd_name(index); - sprintf(devargs, - "%s,rx_pcap=%s,tx_pcap=%s", - name, rx_fpath, tx_fpath); - ret = dev_attach_by_devargs(devargs, &pcap_pmd_port_id); - - if (ret < 0) - return ret; - - ret = rte_eth_dev_configure( - pcap_pmd_port_id, nr_queues, nr_queues, &port_conf); - - if (ret < 0) - return ret; - - /* Allocate and set up 1 RX queue per Ethernet port. */ - uint16_t q; - for (q = 0; q < nr_queues; q++) { - ret = rte_eth_rx_queue_setup( - pcap_pmd_port_id, q, NR_DESCS, - rte_eth_dev_socket_id(pcap_pmd_port_id), - NULL, mp); - if (ret < 0) - return ret; - } - - /* Allocate and set up 1 TX queue per Ethernet port. */ - for (q = 0; q < nr_queues; q++) { - ret = rte_eth_tx_queue_setup( - pcap_pmd_port_id, q, NR_DESCS, - rte_eth_dev_socket_id(pcap_pmd_port_id), - NULL); - if (ret < 0) - return ret; - } - - ret = rte_eth_dev_start(pcap_pmd_port_id); - - if (ret < 0) - return ret; - - RTE_LOG(DEBUG, APP, "pcap port id %d\n", pcap_pmd_port_id); - - return pcap_pmd_port_id; -} - -static int -add_null_pmd(int index) -{ - struct rte_eth_conf port_conf = { - .rxmode = { .max_rx_pkt_len = ETHER_MAX_LEN } - }; - - struct rte_mempool *mp; - const char *name; - char devargs[64]; - uint16_t null_pmd_port_id; - uint16_t nr_queues = 1; - - int ret; - - mp = rte_mempool_lookup(PKTMBUF_POOL_NAME); - if (mp == NULL) - rte_exit(EXIT_FAILURE, "Cannon get mempool for mbuf\n"); - - name = get_null_pmd_name(index); - sprintf(devargs, "%s", name); - ret = dev_attach_by_devargs(devargs, &null_pmd_port_id); - if (ret < 0) - return ret; - - ret = rte_eth_dev_configure( - null_pmd_port_id, nr_queues, nr_queues, - &port_conf); - if (ret < 0) - return ret; - - /* Allocate and set up 1 RX queue per Ethernet port. */ - uint16_t q; - for (q = 0; q < nr_queues; q++) { - ret = rte_eth_rx_queue_setup( - null_pmd_port_id, q, NR_DESCS, - rte_eth_dev_socket_id( - null_pmd_port_id), NULL, mp); - if (ret < 0) - return ret; - } - - /* Allocate and set up 1 TX queue per Ethernet port. */ - for (q = 0; q < nr_queues; q++) { - ret = rte_eth_tx_queue_setup( - null_pmd_port_id, q, NR_DESCS, - rte_eth_dev_socket_id( - null_pmd_port_id), - NULL); - if (ret < 0) - return ret; - } - - ret = rte_eth_dev_start(null_pmd_port_id); - if (ret < 0) - return ret; - - RTE_LOG(DEBUG, APP, "null port id %d\n", null_pmd_port_id); - - return null_pmd_port_id; -} - /** * Add a port to this process. Port is described with resource UID which is a * combination of port type and ID like as 'ring:0'. diff --git a/src/primary/main.c b/src/primary/main.c index 825a8bf..e010bc6 100644 --- a/src/primary/main.c +++ b/src/primary/main.c @@ -13,6 +13,10 @@ #include "common.h" #include "init.h" +/* Buffer sizes of status message of primary. Total must be equal to MSG_SIZE */ +#define PRI_BUF_SIZE_PHY 512 +#define PRI_BUF_SIZE_RING 1512 + static sig_atomic_t on = 1; static enum cmd_type cmd = STOP; diff --git a/src/shared/common.h b/src/shared/common.h index 326343e..3607f4b 100644 --- a/src/shared/common.h +++ b/src/shared/common.h @@ -28,27 +28,36 @@ #include #include -#define MAX_CLIENT 99 #define MSG_SIZE 2048 /* socket buffer len */ + #define SOCK_RESET -1 #define PORT_RESET UINT16_MAX -/* Buffer sizes of status message of primary. Total must be equal to MSG_SIZE */ -#define PRI_BUF_SIZE_PHY 512 -#define PRI_BUF_SIZE_RING 1512 +// Maximum number of rings. +#define MAX_CLIENT 99 + +// The number of tokens in a command line. +#define MAX_PARAMETER 10 + +#define NO_FLAGS 0 /* * When doing reads from the NIC or the client queues, * use this batch size */ -#define PACKET_READ_SIZE 32 -#define MAX_PKT_BURST 32 +//#define PACKET_READ_SIZE 32 -#define MAX_PARAMETER 10 +/* + * TODO(yasufum) move it from common.h used only for spp_nfv, spp_vf and + * spp_mirror. + */ +#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) @@ -56,8 +65,6 @@ #define RTE_MP_RX_DESC_DEFAULT 512 #define RTE_MP_TX_DESC_DEFAULT 512 -#define NO_FLAGS 0 - /* Command. */ enum cmd_type { STOP, -- 2.7.4