[spp] [PATCH 2/6] spp_nfv: update for creating rx pcap device
ogawa.yasufumi at lab.ntt.co.jp
ogawa.yasufumi at lab.ntt.co.jp
Tue May 15 03:21:42 CEST 2018
From: Yasufumi Ogawa <ogawa.yasufumi at lab.ntt.co.jp>
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 <ogawa.yasufumi at lab.ntt.co.jp>
---
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
More information about the spp
mailing list