Skip to content

Commit

Permalink
fix the issue #14. Support multiple dpdk ports.
Browse files Browse the repository at this point in the history
Interface name of viftype DPDK on nuse.conf must be "dpdk%d".
This %d indicates dpdk port number.
  • Loading branch information
upa committed Nov 19, 2014
1 parent ea80570 commit eb0e038
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 47 deletions.
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Additional DPDK configuration is needed, hugepage setup, make an interface DPDK

## Run

At 1st, please write a configuration file for nuse **nuse.conf**.
At first, please write a configuration file for nuse **nuse.conf**.
Example of nuse.conf is shown below.

```
Expand Down Expand Up @@ -89,6 +89,42 @@ should just work fine !

since the LD_PRELOAD with sudo technique requires additional copy and permission changes to the library, the script will automatically conduct such an operation.


### Run with DPDK

If you want to use nuse with dpdk, interface names of dpdk on nuse.conf must
follow the **dpdk%d** format. The digit X of _dpdkX_ indicates the
dpdk port number. An example is shown below.

```
nuse1:net-next-nuse % cat nuse-dpdk.conf
interface dpdk0
address 172.16.0.1
netmask 255.255.255.0
macaddr 00:01:01:01:01:01
viftype DPDK
interface dpdk1
address 172.16.1.1
netmask 255.255.255.0
macaddr 00:01:01:01:01:02
viftype DPDK
nuse1:net-next-nuse % ./dpdk/tools/dpdk_nic_bind.py --status
Network devices using DPDK-compatible driver
============================================
0000:0a:00.0 'Ethernet 10G 2P X520 Adapter' drv=igb_uio unused=
0000:0a:00.1 'Ethernet 10G 2P X520 Adapter' drv=igb_uio unused=
~ snip ~
```

This set up means
"use PCI 0000:0a:00.0 as dpdk0 and PCI 0000:0a:00.1 as dpdk1".


## Tested platform
- Fedora 19 64bits
- Ubuntu 13.04 64bits
Expand Down
96 changes: 50 additions & 46 deletions arch/sim/nuse-vif-dpdk.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ typedef int (*initcall_t)(void);
__FUNCTION__, __LINE__, ##__VA_ARGS__); \


static int dpdk_init = 0;

static const char *ealargs[] = {
"nuse_vif_dpdk",
"-c 1",
Expand Down Expand Up @@ -80,12 +82,16 @@ static const struct rte_eth_txconf txconf = {

#define NUMDESC 256
#define NUMQUEUE 1
#define PORTID 0 /* XXX: how to specify a port... */
#define PORTID (dpdk->portid)


struct nuse_vif_dpdk {

int portid;
struct rte_mempool * rxpool, * txpool; /* rin buffer pool */

char txpoolname[16], rxpoolname[16];

/* burst receive context by rump dpdk code */
struct rte_mbuf * rms[MAX_PKT_BURST];
int npkts;
Expand Down Expand Up @@ -174,79 +180,74 @@ dpdk_if_init (struct nuse_vif_dpdk * dpdk)
struct rte_eth_conf portconf;
struct rte_eth_link link;

ret = rte_eal_init (sizeof (ealargs) / sizeof (ealargs[0]),
(void *) (uintptr_t) ealargs);
if (ret < 0)
{
PE ("failed to initialize eal");
}
if (!dpdk_init) {
ret = rte_eal_init (sizeof (ealargs) / sizeof (ealargs[0]),
(void *) (uintptr_t) ealargs);
if (ret < 0) {
PE ("failed to initialize eal");
}

ret = -EINVAL;
ret = -EINVAL;

dpdk->txpool =
rte_mempool_create ("txpool", MBUF_NUM, MBUF_SIZ,
MEMPOOL_CACHE_SZ,
sizeof (struct rte_pktmbuf_pool_private),
rte_pktmbuf_pool_init, NULL,
rte_pktmbuf_init, NULL, 0, 0);
ret = rte_eal_pci_probe ();
if (ret < 0) {
PE ("eal pci probe failed");
}

dpdk_init = 1;
}

if (dpdk->txpool == NULL)
{
dpdk->txpool =
rte_mempool_create (dpdk->txpoolname,
MBUF_NUM, MBUF_SIZ, MEMPOOL_CACHE_SZ,
sizeof (struct rte_pktmbuf_pool_private),
rte_pktmbuf_pool_init, NULL,
rte_pktmbuf_init, NULL, 0, 0);

if (dpdk->txpool == NULL) {
PE ("failed to allocate tx pool");
}
}


dpdk->rxpool =
rte_mempool_create ("rxpool", MBUF_NUM, MBUF_SIZ,
0,
dpdk->rxpool =
rte_mempool_create (dpdk->rxpoolname, MBUF_NUM, MBUF_SIZ, 0,
sizeof (struct rte_pktmbuf_pool_private),
rte_pktmbuf_pool_init, NULL,
rte_pktmbuf_init, NULL, 0, 0);

if (dpdk->rxpool == NULL)
{
PE ("failed to allocate rx pool");
}

if (dpdk->rxpool == NULL) {
PE ("failed to allocate rx pool");
}

ret = rte_eal_pci_probe ();
if (ret < 0)
{
PE ("eal pci probe failed");
}

memset (&portconf, 0, sizeof (portconf));
ret = rte_eth_dev_configure (PORTID, NUMQUEUE, NUMQUEUE, &portconf);
if (ret < 0)
{
if (ret < 0) {
PE ("failed to configure port");
}
}


ret = rte_eth_rx_queue_setup (PORTID, 0, NUMDESC, 0, &rxconf,
dpdk->rxpool);
if (ret < 0)
{

if (ret < 0) {
PE ("failed to setup rx queue");
}
}

ret = rte_eth_tx_queue_setup (PORTID, 0, NUMDESC, 0, &txconf);
if (ret < 0)
{
if (ret < 0) {
PE ("failed to setup tx queue");
}
}

ret = rte_eth_dev_start (PORTID);
if (ret < 0)
{
if (ret < 0) {
PE ("failed to start device");
}
}

rte_eth_link_get (PORTID, &link);
if (!link.link_status)
{
if (!link.link_status) {
PO ("interface state is down");
}
}

/* should be promisc ? */
rte_eth_promiscuous_enable (PORTID);
Expand All @@ -262,7 +263,10 @@ nuse_vif_dpdk_create (const char * ifname)
struct nuse_vif_dpdk * dpdk;

dpdk = sim_malloc (sizeof (struct nuse_vif_dpdk));

sscanf (ifname, "dpdk%d", &dpdk->portid);
snprintf (dpdk->txpoolname, 16, "%s%s", "tx", ifname);
snprintf (dpdk->rxpoolname, 16, "%s%s", "rx", ifname);

if (dpdk_if_init (dpdk) < 0) {
sim_free (dpdk);
PO ("failed to init dpdk interface");
Expand Down

0 comments on commit eb0e038

Please sign in to comment.