From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mogw0536.ocn.ad.jp (mogw0536.ocn.ad.jp [118.23.178.178]) by dpdk.org (Postfix) with ESMTP id B992C1B6A7 for ; Tue, 15 May 2018 03:21:54 +0200 (CEST) Received: from mf-smf-ucb031c1 (mf-smf-ucb031c1.ocn.ad.jp [153.153.66.200]) by mogw0536.ocn.ad.jp (Postfix) with ESMTP id 1CAE4104239; Tue, 15 May 2018 10:21:53 +0900 (JST) Received: from ntt.pod01.mv-mta-ucb019 ([153.149.142.82]) by mf-smf-ucb031c1 with ESMTP id IOelfaVqcxhxrIOf3fOp6D; Tue, 15 May 2018 10:21:53 +0900 Received: from smtp.ocn.ne.jp ([153.149.227.167]) by ntt.pod01.mv-mta-ucb019 with id mRMs1x00B3dLKTM01RMsim; Tue, 15 May 2018 01:21:53 +0000 Received: from localhost.localdomain (p5164-ipngn8501marunouchi.tokyo.ocn.ne.jp [153.214.228.164]) by smtp.ocn.ne.jp (Postfix) with ESMTPA; Tue, 15 May 2018 10:21:52 +0900 (JST) From: ogawa.yasufumi@lab.ntt.co.jp To: ferruh.yigit@intel.com, spp@dpdk.org Cc: Yasufumi Ogawa Date: Tue, 15 May 2018 10:21:42 +0900 Message-Id: <20180515012146.8899-3-ogawa.yasufumi@lab.ntt.co.jp> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180515012146.8899-1-ogawa.yasufumi@lab.ntt.co.jp> References: <20180515012146.8899-1-ogawa.yasufumi@lab.ntt.co.jp> Subject: [spp] [PATCH 2/6] spp_nfv: update for creating rx pcap device 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, 15 May 2018 01:21:55 -0000 From: Yasufumi Ogawa Libpcap-based PMD of DPDK requires two different streams for rx and tx of pcap files[1]. 'tx_pcap' is created by DPDK but not for 'rx_pcap'. In SPP, rx pcap file should be prepared like as '/tmp/spp-rx1.pcap' before 'add pcap', or failed to setup pcap PMD. This update is for creating the rx pcap with 'text2pcap'[2] if it does not exist. This update is also including definition of format of pcap files in src/shared/common.h as following. #define PCAP_IFACE_RX "/tmp/spp-rx%d.pcap" #define PCAP_IFACE_TX "/tmp/spp-tx%d.pcap" [1] https://dpdk.org/doc/guides/nics/pcap_ring.html [2] https://www.wireshark.org/docs/man-pages/text2pcap.html Signed-off-by: Yasufumi Ogawa --- src/nfv/nfv.c | 66 ++++++++++++++++++++++++++++++++++++++++++--- src/shared/common.h | 5 ++++ 2 files changed, 68 insertions(+), 3 deletions(-) diff --git a/src/nfv/nfv.c b/src/nfv/nfv.c index d90b40b..6de6ffa 100644 --- a/src/nfv/nfv.c +++ b/src/nfv/nfv.c @@ -481,6 +481,50 @@ add_vhost_pmd(int index) return vhost_port_id; } +/* + * Create an empty rx pcap file to given path if it does not exit + * Return 0 for succeeded, or -1 for failed. + */ +static int +create_pcap_rx(char *rx_fpath) +{ + int res; + FILE *tmp_fp; + char cmd_str[256]; + + // empty file is required for 'text2pcap' command for + // creating a pcap file. + char template[] = "/tmp/spp-emptyfile.txt"; + + // create empty file if it is not exist + tmp_fp = fopen(template, "r"); + if (tmp_fp == NULL) { + (tmp_fp = fopen(template, "w")); + if (tmp_fp == NULL) { + RTE_LOG(ERR, APP, "Failed to open %s\n", template); + return -1; + } + } + + sprintf(cmd_str, "text2pcap %s %s", template, rx_fpath); + res = system(cmd_str); + if (res != 0) { + RTE_LOG(ERR, APP, + "Failed to create pcap device %s\n", + rx_fpath); + return -1; + } + RTE_LOG(INFO, APP, "PCAP device created\n"); + fclose(tmp_fp); + return 0; +} + +/* + * 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) { @@ -493,17 +537,33 @@ add_pcap_pmd(int index) 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=/tmp/rx_%d.pcap,tx_pcap=/tmp/tx_%d.pcap", - name, index, index); + "%s,rx_pcap=%s,tx_pcap=%s", + name, rx_fpath, tx_fpath); ret = rte_eth_dev_attach(devargs, &pcap_pmd_port_id); if (ret < 0) diff --git a/src/shared/common.h b/src/shared/common.h index cad88fe..4978037 100644 --- a/src/shared/common.h +++ b/src/shared/common.h @@ -115,9 +115,14 @@ struct port { #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" /* -- 2.17.0