[dpdk-dev] [RFC][PATCH V2 2/3] examples/vhost: Add vswitch command line options

2016-09-15 Thread Pankaj Chauhan
On 9/13/2016 5:44 PM, Yuanhan Liu wrote:
> On Mon, Sep 05, 2016 at 04:24:30PM +0530, Pankaj Chauhan wrote:
>> Add command line options for selecting switch implementation
>> and maximum ports for the vswitch.following are two new command
>> line options:
>>
>> --switch  [char string, Selects the switch imlementation]
>> --max-ports [int, selects maximum number of ports to support]
>>
>> For example:
>>
>> $ ./vhost-switch -c 3 -n 2 --socket-mem 1024 --huge-dir /hugetlbfs -- -p
>> 0x1 --dev-basename sock1
>
> That means you were basing on the master branch. You should base on
> next-virtio instead: http://dpdk.org/browse/next/dpdk-next-virtio/

Yes i were basing it on master, i will base the next version on 
dpdk-next-virtio. Sorry for this, i am bit new to dpdk upstream 
development .
>
>> --switch "vmdq" --max-ports 3
>
> Normally, we should keep the old behaviour first. Say, making the vmdq
> as the default switch mode.

Yes if we don't give the '--switch' option then default is vmdq.
>
> However, actually, I don't quite like to make the vhost-switch to bind
> to a hardare feature that tightly, that you may want to make a standalone
> patch as the last one in this patchset to make the "switch" mode be the
> default one.

Sure i will split the patch to take care of this.
>
>>
>> Signed-off-by: Pankaj Chauhan 
>> ---
>>  examples/vhost/main.c | 43 +++
>>  1 file changed, 43 insertions(+)
>>
>> diff --git a/examples/vhost/main.c b/examples/vhost/main.c
>> index c949df4..a4e51ae 100644
>> --- a/examples/vhost/main.c
>> +++ b/examples/vhost/main.c
>> @@ -142,6 +142,10 @@ static uint32_t burst_rx_retry_num = BURST_RX_RETRIES;
>>  /* Character device basename. Can be set by user. */
>>  static char dev_basename[MAX_BASENAME_SZ] = "vhost-net";
>>
>> +/* vswitch device name and maximum number of ports */
>> +static char switch_dev[MAX_BASENAME_SZ] = "vmdq";
>
> First of all, limiting it with MAX_BASENAME_SZ makes no sense here.
>

I will fix it, define a different constant for switch_dev name.

> Secondly, you don't have to represent the switch mode with string,
> you could simply use some numeric macros, or enum.
>

I used the string because the registration function (vs_register_switch) 
uses the switch name as string to register the switches and find the 
matching switch_dev given in command line. If we use macro or enum then 
we will have to add the MACRO for the switch id in common code every 
time a new switch implementation is added. Keeping a string as name, 
saves us from touching the common code for adding a new switch 
implementation.

> Besides, I just had a quick glimplse of your patches (still couldn't
> make a detailed look so far), and I'd ask you to do few more things
> for v3:
>
> - I'm hoping you could split this patchset further, say **maybe**
>   one patch to introduce vswitch_port, one to introduce vswitch_ops
>   and another one to introduce vswitch_dev. This helps review.
>

Do you want me to split the vswitch_ops, vswitch_dev and vswitch_port 
introduction (mainly vswitch_common.h) in three patches with the patch 
body explaining them in bit detail, correct ?

Their usage i.e vswitch_common.c can be kept in separate patch (4th 
one), is this fine? otherwise it fill be tricky to make vswitch_common.c 
to compilable without complete definition of vswitch_port, vswitch_dev 
and vswitch_ops

> - make sure each commit is buldable.
>
I will take care of this in v3
>
> And few more generic comments to the whole set:
>
> - use "__rte_unused" but not "__attribute__((unused))"
>   And we normally use it after but not before the key word.

I will take care of this in v3
>
> - follow the DPDK prefered way to define a function, the return type
>   and function name takes two lines.
I will take care of this in v3

>
> - run scripts/{checkpatches.sh,check-git-log.sh} and fix real warnings
>   if any before sending them out.
>
>   This would at least help you catch "line over 80 chars" issue.

Sure, will take care of this in v3 and onwards.

Thanks,
Pankaj
>
> Thanks.
>   --yliu
>




[dpdk-dev] [RFC][PATCH V2 1/3] examples/vhost: Add vswitch (generic switch) framework

2016-09-15 Thread Pankaj Chauhan
On 9/13/2016 12:21 PM, Tan, Jianfeng wrote:
Hi Jianfeng,

>>>
>>> On 9/5/2016 6:54 PM, Pankaj Chauhan wrote:
>>>> Introduce support for a generic framework for handling of switching
>>>> between
>>>> physical and vhost devices. The vswitch framework introduces the
>>>> following
>>>> concept:
>>>>
>>>> 1. vswitch_dev: Vswitch device is a logical switch which can have
>>>> physical and
>>>> virtio devices. The devices are operated/used using standard rte_eth
>>>> API for
>>>> physical devices and lib_vhost API for vhost devices, PMD API is not
>>>> used
>>>> for vhost devices.
>>>>
>>>> 2. vswitch_port: Any physical or virtio device that is added to
>>>> vswitch. The
>>>> port can have its own tx/rx functions for doing data transfer, which
>>>> are exposed
>>>> to the framework using generic function pointers
>>>> (vs_port->do_tx/do_rx). This way
>>>> the generic code can do tx/rx without understanding the type of device
>>>> (Physical or
>>>> virtio). Similarly each port has its own functions to select tx/rx
>>>> queues. The framework
>>>> provides default tx/rx queue selection functions to the port when port
>>>> is added
>>>> (for both physical and vhost devices). But the framework allows the
>>>> switch implementation
>>>> to override the queue selection functions (vs_port->get_txq/rxq) if
>>>> required.
>>>>
>>>> 3. vswitch_ops: The ops is set of function pointers which are used to
>>>> do operations
>>>> like learning, unlearning, add/delete port, lookup_and_forward. The
>>>> user of vswitch
>>>> framework (vhost/main.[c,h])uses these function pointers to perform
>>>> above mentioned
>>>> operations, thus it remains agnostic of the underlying implementation.
>>>>
>>>> Different switching logics can implement their vswitch_device and
>>>> vswitch_ops, and
>>>> register with the framework. This framework makes vhost-switch
>>>> application scalable
>>>> in terms of:
>>>>
>>>> 1. Different switching logics (one of them is vmdq, vhost/vmdq.[c,h]
>>>> 2. Number of ports.
>>>> 3. Policies of selecting ports for rx and tx.
>>>>
>>>> Signed-off-by: Pankaj Chauhan 
>>>
>>> After this patch set, how's mapping relationship between cores and
>>> vswitch_dev? Old vhost example does not have the concept of switch, so
>>> each core is binded with some VDEVs. Now, we still keep original logic?
>>>
>>> (a) If yes, provided that phys device could has no direct relationship
>>> with vdevs in other switching logics, we may need to bind those physical
>>> devices to cores too? In that case, switch_worker() will receiving pkts
>>> from all devices (phys or virtual) and dispatch, which looks like:
>>>
>>> switch_worker() {
>>> FOR each port binding to this core {
>>>  rx(port, pkts[], count);
>>>  vs_lookup_n_fwd( information_needed );
>>> }
>>> }
>>
>> Since we support only one switch device running at one time. We bind
>> the ports of the switchdev to the core. But The switch might have it's
>> own logic to bind the port to the core. For example
>> VMDQ only supports one Physical port, other switch can support more
>> than one Physical port. In order to take care of that i have added two
>> ops in swithdev_ops:
>>
>> 1. vs_sched_rx_port:
>>
>> struct vswitch_port *vs_sched_rx_port(struct vswitch_dev *vs_dev, enum
>>   vswitch_port_type ptype,
>> uint16_t core_id)
>>
>> 2. vs_sched_tx_port:
>>
>> struct vswitch_port *vs_sched_tx_port(struct vswitch_dev *vs_dev, enum
>>   vswitch_port_type ptype, uint16_t
>> core_id)
>>
>> The idea of providing these functions is that vhost/main requests the
>> underlying switch implementation to schedule a port for rx or Tx, the
>> current running core_id is also passed as parameter. So the switch can
>> take a decision which port to do rx or tx based on core id, and may be
>> some other custom policy.
>>
>> For example VMDQ always returns the one single Physical port in
>> response to these functions called from any core. The other switch
>> can return the por

[dpdk-dev] [RFC][PATCH V2 1/3] examples/vhost: Add vswitch (generic switch) framework

2016-09-12 Thread Pankaj Chauhan
On 9/11/2016 5:51 PM, Yuanhan Liu wrote:
> On Mon, Sep 05, 2016 at 04:24:29PM +0530, Pankaj Chauhan wrote:
>> Introduce support for a generic framework for handling of switching between
>> physical and vhost devices. The vswitch framework introduces the following
>> concept:
>>
>> 1. vswitch_dev: Vswitch device is a logical switch which can have physical 
>> and
>> virtio devices. The devices are operated/used using standard rte_eth API for
>> physical devices and lib_vhost API for vhost devices, PMD API is not used
>> for vhost devices.
>>
>> 2. vswitch_port: Any physical or virtio device that is added to vswitch. The
>> port can have its own tx/rx functions for doing data transfer, which are 
>> exposed
>> to the framework using generic function pointers (vs_port->do_tx/do_rx). 
>> This way
>> the generic code can do tx/rx without understanding the type of device 
>> (Physical or
>> virtio). Similarly each port has its own functions to select tx/rx queues. 
>> The framework
>> provides default tx/rx queue selection functions to the port when port is 
>> added
>> (for both physical and vhost devices). But the framework allows the switch 
>> implementation
>> to override the queue selection functions (vs_port->get_txq/rxq) if required.
>>
>> 3. vswitch_ops: The ops is set of function pointers which are used to do 
>> operations
>> like learning, unlearning, add/delete port, lookup_and_forward. The user of 
>> vswitch
>> framework (vhost/main.[c,h])uses these function pointers to perform above 
>> mentioned
>> operations, thus it remains agnostic of the underlying implementation.
>>
>> Different switching logics can implement their vswitch_device and 
>> vswitch_ops, and
>> register with the framework. This framework makes vhost-switch application 
>> scalable
>> in terms of:
>>
>> 1. Different switching logics (one of them is vmdq, vhost/vmdq.[c,h]
>> 2. Number of ports.
>> 3. Policies of selecting ports for rx and tx.
>>
>> Signed-off-by: Pankaj Chauhan 
>
> Hi,
>
> FYI, my testrobot caught some errors when this patch is applied.
> (And sorry for the late review; hopefully I can make it next week).
>
> --yliu

Hi YLiu,

Thanks for the review. I am sorry it was my mistake in this patchset, 
the header defining few structures and macros used in patch 0001 are 
defined in patch 0003. Because of this 0001 was not individually 
compilable but all three are compliable as set, it was mistake on my 
part , will fix it and will take care of it in further patchsets.

Do you want me to send another version for review, or i can fix it
in the next version i send after review of v2 is complete?

Thanks,
Pankaj
>




[dpdk-dev] [RFC][PATCH V2 1/3] examples/vhost: Add vswitch (generic switch) framework

2016-09-12 Thread Pankaj Chauhan
On 9/9/2016 2:26 PM, Tan, Jianfeng wrote:
> Hi Pankaj,
>
> Thanks for the massive and great work.

Hi Jianfeng,

Thanks for the review.
>
> On 9/5/2016 6:54 PM, Pankaj Chauhan wrote:
>> Introduce support for a generic framework for handling of switching
>> between
>> physical and vhost devices. The vswitch framework introduces the
>> following
>> concept:
>>
>> 1. vswitch_dev: Vswitch device is a logical switch which can have
>> physical and
>> virtio devices. The devices are operated/used using standard rte_eth
>> API for
>> physical devices and lib_vhost API for vhost devices, PMD API is not used
>> for vhost devices.
>>
>> 2. vswitch_port: Any physical or virtio device that is added to
>> vswitch. The
>> port can have its own tx/rx functions for doing data transfer, which
>> are exposed
>> to the framework using generic function pointers
>> (vs_port->do_tx/do_rx). This way
>> the generic code can do tx/rx without understanding the type of device
>> (Physical or
>> virtio). Similarly each port has its own functions to select tx/rx
>> queues. The framework
>> provides default tx/rx queue selection functions to the port when port
>> is added
>> (for both physical and vhost devices). But the framework allows the
>> switch implementation
>> to override the queue selection functions (vs_port->get_txq/rxq) if
>> required.
>>
>> 3. vswitch_ops: The ops is set of function pointers which are used to
>> do operations
>> like learning, unlearning, add/delete port, lookup_and_forward. The
>> user of vswitch
>> framework (vhost/main.[c,h])uses these function pointers to perform
>> above mentioned
>> operations, thus it remains agnostic of the underlying implementation.
>>
>> Different switching logics can implement their vswitch_device and
>> vswitch_ops, and
>> register with the framework. This framework makes vhost-switch
>> application scalable
>> in terms of:
>>
>> 1. Different switching logics (one of them is vmdq, vhost/vmdq.[c,h]
>> 2. Number of ports.
>> 3. Policies of selecting ports for rx and tx.
>>
>> Signed-off-by: Pankaj Chauhan 
>
> After this patch set, how's mapping relationship between cores and
> vswitch_dev? Old vhost example does not have the concept of switch, so
> each core is binded with some VDEVs. Now, we still keep original logic?
>
> (a) If yes, provided that phys device could has no direct relationship
> with vdevs in other switching logics, we may need to bind those physical
> devices to cores too? In that case, switch_worker() will receiving pkts
> from all devices (phys or virtual) and dispatch, which looks like:
>
> switch_worker() {
> FOR each port binding to this core {
>  rx(port, pkts[], count);
>  vs_lookup_n_fwd( information_needed );
> }
> }

Since we support only one switch device running at one time. We bind the 
ports of the switchdev to the core. But The switch might have it's own 
logic to bind the port to the core. For example
VMDQ only supports one Physical port, other switch can support more than 
one Physical port. In order to take care of that i have added two ops in 
swithdev_ops:

1. vs_sched_rx_port:

struct vswitch_port *vs_sched_rx_port(struct vswitch_dev *vs_dev, enum
   vswitch_port_type ptype, uint16_t 
core_id)

2. vs_sched_tx_port:

struct vswitch_port *vs_sched_tx_port(struct vswitch_dev *vs_dev, enum
   vswitch_port_type ptype, uint16_t
core_id)

The idea of providing these functions is that vhost/main requests the 
underlying switch implementation to schedule a port for rx or Tx, the 
current running core_id is also passed as parameter. So the switch can
take a decision which port to do rx or tx based on core id, and may be 
some other custom policy.

For example VMDQ always returns the one single Physical port in response 
to these functions called from any core. The other switch
can return the ports bound to the cores.

Similarly there are two port operations (vs_port->get_rxq and 
vs_port->get_txq), here also we pass core_id as parameter so that
the underlying switch implementation can schedule the rx or tx queue 
based on the core_id.

The above mentioned ops are used in drain_eth_rx() and 
do_drain_mbuf_table() (main.c) currently, and they leave binding of 
physical port and the queues to the underlying implementation. This
way we can accommodate VMDQ which uses only one physical port and 
rxqueues based on VMDQ, OR any other switch which uses multiple physical 
port and rx/tx queue scheduling based on some other logic.

Please suggest if this way of scheduling ports and tx/rx qu

[dpdk-dev] [RFC][PATCH V2 3/3] examples/vhost: Add VMDQ vswitch device

2016-09-05 Thread Pankaj Chauhan
Add support for VMDQ vswitch device. This patch takes
out all VMDQ specefic code from vhost/main.[c,h] and
move it to vmdq.[c,h]. Moreover vmdq.[c,h] files plug
the VMDQ vswitch device implmentation to the vhost-switch
using vswitch framework.

The main vhost/main.[c,h] code is now generic and can support
any switch implementation that conforms with vswitch framework.

Please note that the core VMDQ logic remains as it is, as it
was in vhost/main.c, this patch just moves it to different
file and fits into ops provided by framework.

Signed-off-by: Pankaj Chauhan 
---
 examples/vhost/main.c | 486 +---
 examples/vhost/main.h |  10 +
 examples/vhost/vmdq.c | 669 ++
 examples/vhost/vmdq.h |  57 +
 4 files changed, 794 insertions(+), 428 deletions(-)
 create mode 100644 examples/vhost/vmdq.c
 create mode 100644 examples/vhost/vmdq.h

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index a4e51ae..096339b 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -54,6 +54,7 @@
 #include 

 #include "main.h"
+#include "vswitch_common.h"

 #ifndef MAX_QUEUES
 #define MAX_QUEUES 128
@@ -65,7 +66,6 @@
 #define MBUF_CACHE_SIZE128
 #define MBUF_DATA_SIZE RTE_MBUF_DEFAULT_BUF_SIZE

-#define MAX_PKT_BURST 32   /* Max burst size for RX/TX */
 #define BURST_TX_DRAIN_US 100  /* TX drain every ~100us */

 #define BURST_RX_WAIT_US 15/* Defines how long we wait between retries on 
RX */
@@ -103,7 +103,6 @@ static uint32_t enabled_port_mask = 0;
 static uint32_t promiscuous;

 /* number of devices/queues to support*/
-static uint32_t num_queues = 0;
 static uint32_t num_devices;

 static struct rte_mempool *mbuf_pool;
@@ -112,6 +111,8 @@ static int mergeable;
 /* Do vlan strip on host, enabled on default */
 static uint32_t vlan_strip = 1;

+static uint32_t jumbo_frame_en = 0;
+
 /* Enable VM2VM communications. If this is disabled then the MAC address 
compare is skipped. */
 typedef enum {
VM2VM_DISABLED = 0,
@@ -146,74 +147,16 @@ static char dev_basename[MAX_BASENAME_SZ] = "vhost-net";
 static char switch_dev[MAX_BASENAME_SZ] = "vmdq";
 static uint32_t switch_max_ports = MAX_DEVICES;

-/* empty vmdq configuration structure. Filled in programatically */
-static struct rte_eth_conf vmdq_conf_default = {
-   .rxmode = {
-   .mq_mode= ETH_MQ_RX_VMDQ_ONLY,
-   .split_hdr_size = 0,
-   .header_split   = 0, /**< Header Split disabled */
-   .hw_ip_checksum = 0, /**< IP checksum offload disabled */
-   .hw_vlan_filter = 0, /**< VLAN filtering disabled */
-   /*
-* It is necessary for 1G NIC such as I350,
-* this fixes bug of ipv4 forwarding in guest can't
-* forward pakets from one virtio dev to another virtio dev.
-*/
-   .hw_vlan_strip  = 1, /**< VLAN strip enabled. */
-   .jumbo_frame= 0, /**< Jumbo Frame Support disabled */
-   .hw_strip_crc   = 0, /**< CRC stripped by hardware */
-   },
-
-   .txmode = {
-   .mq_mode = ETH_MQ_TX_NONE,
-   },
-   .rx_adv_conf = {
-   /*
-* should be overridden separately in code with
-* appropriate values
-*/
-   .vmdq_rx_conf = {
-   .nb_queue_pools = ETH_8_POOLS,
-   .enable_default_pool = 0,
-   .default_pool = 0,
-   .nb_pool_maps = 0,
-   .pool_map = {{0, 0},},
-   },
-   },
-};
-
+struct vswitch_dev *vswitch_dev_g;
 static unsigned lcore_ids[RTE_MAX_LCORE];
 static uint8_t ports[RTE_MAX_ETHPORTS];
 static unsigned num_ports = 0; /**< The number of ports specified in command 
line */
-static uint16_t num_pf_queues, num_vmdq_queues;
-static uint16_t vmdq_pool_base, vmdq_queue_base;
-static uint16_t queues_per_pool;
-
-const uint16_t vlan_tags[] = {
-   1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007,
-   1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015,
-   1016, 1017, 1018, 1019, 1020, 1021, 1022, 1023,
-   1024, 1025, 1026, 1027, 1028, 1029, 1030, 1031,
-   1032, 1033, 1034, 1035, 1036, 1037, 1038, 1039,
-   1040, 1041, 1042, 1043, 1044, 1045, 1046, 1047,
-   1048, 1049, 1050, 1051, 1052, 1053, 1054, 1055,
-   1056, 1057, 1058, 1059, 1060, 1061, 1062, 1063,
-};
-
-/* ethernet addresses of ports */
-static struct ether_addr vmdq_ports_eth_addr[RTE_MAX_ETHPORTS];

 static struct vhost_dev_tailq_list vhost_dev_list =
TAILQ_HEAD_INITIALIZER(vhost_dev_list);

 static struct lcore_info lcore_info[RTE_MAX_LCORE];

-/* Used for queueing bursts of TX packets. */
-struct mbuf_table {
-   unsigned len;
-   unsigned txq_id;
-   struct rte_mbuf *m_table[MAX

[dpdk-dev] [RFC][PATCH V2 2/3] examples/vhost: Add vswitch command line options

2016-09-05 Thread Pankaj Chauhan
Add command line options for selecting switch implementation
and maximum ports for the vswitch.following are two new command
line options:

--switch  [char string, Selects the switch imlementation]
--max-ports [int, selects maximum number of ports to support]

For example:

$ ./vhost-switch -c 3 -n 2 --socket-mem 1024 --huge-dir /hugetlbfs -- -p
0x1 --dev-basename sock1 --switch "vmdq" --max-ports 3

Signed-off-by: Pankaj Chauhan 
---
 examples/vhost/main.c | 43 +++
 1 file changed, 43 insertions(+)

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index c949df4..a4e51ae 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -142,6 +142,10 @@ static uint32_t burst_rx_retry_num = BURST_RX_RETRIES;
 /* Character device basename. Can be set by user. */
 static char dev_basename[MAX_BASENAME_SZ] = "vhost-net";

+/* vswitch device name and maximum number of ports */
+static char switch_dev[MAX_BASENAME_SZ] = "vmdq";
+static uint32_t switch_max_ports = MAX_DEVICES;
+
 /* empty vmdq configuration structure. Filled in programatically */
 static struct rte_eth_conf vmdq_conf_default = {
.rxmode = {
@@ -408,6 +412,22 @@ us_vhost_parse_basename(const char *q_arg)
 }

 /*
+ * Set switch device name.
+ */
+static int
+us_vhost_parse_switch_name(const char *q_arg)
+{
+   /* parse number string */
+
+   if (strnlen(q_arg, MAX_BASENAME_SZ) > MAX_BASENAME_SZ)
+   return -1;
+
+   snprintf(_dev[0], MAX_BASENAME_SZ, "%s", q_arg);
+
+   return 0;
+}
+
+/*
  * Parse the portmask provided at run time.
  */
 static int
@@ -501,6 +521,8 @@ us_vhost_parse_args(int argc, char **argv)
{"tx-csum", required_argument, NULL, 0},
{"tso", required_argument, NULL, 0},
{"client", no_argument, _mode, 1},
+   {"switch", required_argument, NULL, 0},
+   {"max-ports", required_argument, NULL, 0},
{NULL, 0, 0, 0},
};

@@ -655,6 +677,27 @@ us_vhost_parse_args(int argc, char **argv)
}
}

+   /* Set vswitch_driver name */
+   if (!strncmp(long_option[option_index].name, "switch", 
MAX_LONG_OPT_SZ)) {
+   if (us_vhost_parse_switch_name(optarg) == -1) {
+   RTE_LOG(INFO, VHOST_CONFIG,
+   "Invalid argument for switch 
(Max len %d )\n", MAX_BASENAME_SZ);
+   us_vhost_usage(prgname);
+   return -EINVAL;
+   }
+   }
+
+   /* Specify Max ports in vswitch. */
+   if (!strncmp(long_option[option_index].name, 
"max-ports", MAX_LONG_OPT_SZ)) {
+   ret = parse_num_opt(optarg, INT32_MAX);
+   if (ret == -1) {
+   RTE_LOG(INFO, VHOST_CONFIG, "Invalid 
argument for switch max ports [0-N]\n");
+   us_vhost_usage(prgname);
+   return -1;
+   }
+   switch_max_ports = ret;
+   }
+
break;

/* Invalid option - print options. */
-- 
1.9.1



[dpdk-dev] [RFC][PATCH V2 1/3] examples/vhost: Add vswitch (generic switch) framework

2016-09-05 Thread Pankaj Chauhan
Introduce support for a generic framework for handling of switching between
physical and vhost devices. The vswitch framework introduces the following
concept:

1. vswitch_dev: Vswitch device is a logical switch which can have physical and
virtio devices. The devices are operated/used using standard rte_eth API for
physical devices and lib_vhost API for vhost devices, PMD API is not used
for vhost devices.

2. vswitch_port: Any physical or virtio device that is added to vswitch. The
port can have its own tx/rx functions for doing data transfer, which are exposed
to the framework using generic function pointers (vs_port->do_tx/do_rx). This 
way
the generic code can do tx/rx without understanding the type of device 
(Physical or
virtio). Similarly each port has its own functions to select tx/rx queues. The 
framework
provides default tx/rx queue selection functions to the port when port is added
(for both physical and vhost devices). But the framework allows the switch 
implementation
to override the queue selection functions (vs_port->get_txq/rxq) if required.

3. vswitch_ops: The ops is set of function pointers which are used to do 
operations
like learning, unlearning, add/delete port, lookup_and_forward. The user of 
vswitch
framework (vhost/main.[c,h])uses these function pointers to perform above 
mentioned
operations, thus it remains agnostic of the underlying implementation.

Different switching logics can implement their vswitch_device and vswitch_ops, 
and
register with the framework. This framework makes vhost-switch application 
scalable
in terms of:

1. Different switching logics (one of them is vmdq, vhost/vmdq.[c,h]
2. Number of ports.
3. Policies of selecting ports for rx and tx.

Signed-off-by: Pankaj Chauhan 
---
 examples/vhost/Makefile |   2 +-
 examples/vhost/main.c   | 128 +--
 examples/vhost/vswitch_common.c | 499 
 examples/vhost/vswitch_common.h | 186 +++
 examples/vhost/vswitch_txrx.c   |  97 
 examples/vhost/vswitch_txrx.h   |  71 ++
 6 files changed, 966 insertions(+), 17 deletions(-)
 create mode 100644 examples/vhost/vswitch_common.c
 create mode 100644 examples/vhost/vswitch_common.h
 create mode 100644 examples/vhost/vswitch_txrx.c
 create mode 100644 examples/vhost/vswitch_txrx.h

diff --git a/examples/vhost/Makefile b/examples/vhost/Makefile
index e95c68a..1b58308 100644
--- a/examples/vhost/Makefile
+++ b/examples/vhost/Makefile
@@ -48,7 +48,7 @@ else
 APP = vhost-switch

 # all source are stored in SRCS-y
-SRCS-y := main.c
+SRCS-y := main.c vswitch_common.c vswitch_txrx.c vmdq.c

 CFLAGS += -O2 -D_FILE_OFFSET_BITS=64
 CFLAGS += $(WERROR_FLAGS)
diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 92a9823..c949df4 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -811,9 +811,16 @@ static inline void __attribute__((always_inline))
 virtio_xmit(struct vhost_dev *dst_vdev, struct vhost_dev *src_vdev,
struct rte_mbuf *m)
 {
-   uint16_t ret;
+   uint16_t ret, txq;
+   struct vswitch_port *vs_port = dst_vdev->vs_port;

-   ret = rte_vhost_enqueue_burst(dst_vdev->vid, VIRTIO_RXQ, , 1);
+   /* The switch implmentation decides the txq for each port itself.
+* this gives switch implmentations to choose thier own queue management
+* for each port
+*/
+
+   txq = vs_port->get_txq(vs_port, rte_lcore_id());
+   ret = rte_vhost_enqueue_burst(dst_vdev->vid, txq, , 1);
if (enable_stats) {
rte_atomic64_inc(_vdev->stats.rx_total_atomic);
rte_atomic64_add(_vdev->stats.rx_atomic, ret);
@@ -832,7 +839,7 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)
struct ether_hdr *pkt_hdr;
struct vhost_dev *dst_vdev;

-   pkt_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
+   pkt_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);

dst_vdev = find_vhost_dev(_hdr->d_addr);
if (!dst_vdev)
@@ -934,11 +941,26 @@ static inline void __attribute__((always_inline))
 do_drain_mbuf_table(struct mbuf_table *tx_q)
 {
uint16_t count;
+   struct vswitch_port *tx_port;
+
+   /* Let switch implmentation decide which physical port to do tx to.
+* Every switch implmentation may have it's own strategy, for example
+* VMDQ does tx to only one Physical port. Having a scheduler function
+* which is switch specefic give flexibility to have another strategy
+* for a switch
+*/
+   tx_port = vs_sched_tx_port(vswitch_dev_g, VSWITCH_PTYPE_PHYS,
+rte_lcore_id());
+   if (unlikely(!tx_port))
+   goto out;

-   count = rte_eth_tx_burst(ports[0], tx_q->txq_id,
-tx_q->m_table, tx_q->len);
-   if (unlikely(count < tx_q->len))
-   free_pkts(_q->m_table[coun

[dpdk-dev] [RFC][PATCH V2 0/3] example/vhost: Introduce Vswitch Framework

2016-09-05 Thread Pankaj Chauhan
Introduce generic vswitch framework in vhost-switch application. Following
are the goals/aim of the framework:

1. Make vhost-switch application generic so that it can support devices 
which don't support VMDQ.

2. Provide a framework so that any switching logic (generic in software or
vendor specefic like VMDQ) can work with vhost-switch. Thus making vhost-switch
applicable for multiple platforms of different vendors.

3. Make vhost-switch and switching logic scalable in terms of ports or policies
of doing rx/tx across the ports added to switch.

The patchset includes three patches:
1. "Add vswitch(generic switch) framework": This adds the generic framework, it 
provides
the APIs/accessor functions which the vhos-switch application uses without 
knowing
anything about underlying switching logic. The framework introduces the concept 
of
vswitch_device, vswitch_port, and vswitch_ops. The idea is that vhost-switch 
will
sit over the framework and different switching logics will plug into the 
framework
underneath it. Please refer the patch description for more details of devices, 
ports
and ops.

2. "Add vswitch command line options": Adds two new command line options for 
vswitch.
3. "Add VMDQ vswitch device": This patch basically delinks existing 
vhost/main.[c,h]
from VMDQ and adds VMDQ as a vswitch device implmentation which plugs into the 
vswitch
framework. Any other vendor logic for switching can also be plugged in same way.

Thanks to Tan Jianfeng, Yuanhan Liu, Maxime coquelin for early discussions and 
inputs
on this concept.

TODO list:
1. Addd constructor based logic for registration of Vswitch implmentations like 
VMDQ.
we will use similar mechanism as registration of PMD drivers (base on 
constructor function)
to register all the switch implmentations in vhost-switch and then select the 
required
implementation using command line option 'switch'.

2. Test VM2VM hardware mode: I tried following command it didn't work:

vhost-switch -c f -n 4 --socket-mem 1024 --huge-dir /mnt/huge  -- -p 0x1  
--vm2vm 2 
--vlan-strip 1 --dev-basename usvhost
I tried same command on upstream master also but it didn't work, that means i 
am doing something
wrong, please help me with correct method to test it. Or now the patches are 
working, so
if possible please give a try to hardware VM2VM mode.

3. Changes for Maxime's comment on freeing of buffers in vs_looup_n_fwd(). I 
wasn't clear about
what is the right way to handle, we'll fix it after getting feedback from 
Maxime.

Change Log
==

v1->v2
--
1. Tested following:
- Ping and iperf from VM to external machine connected to Phys port.
- Ping and iperf betweeen 2 VMs in software vm2vm mode

- My testsetup is:
-  vhost & VM machine: xeonD1521 with Network card: 
X552/X557-AT 10GBASE-T
- Peer connected to VM machine: OptiPlex-790 with 82574L 
Gigabit card
2. Incorporated changes for all the comments from Maxime Coquelin. One comment 
is not yet
   taken care off, and it is listed in TODO list.

Pankaj Chauhan (3):
  examples/vhost: Add vswitch (generic switch) framework
  examples/vhost: Add vswitch command line options
  examples/vhost: Add VMDQ vswitch device

 examples/vhost/Makefile |   2 +-
 examples/vhost/main.c   | 651 +-
 examples/vhost/main.h   |  10 +
 examples/vhost/vmdq.c   | 669 
 examples/vhost/vmdq.h   |  57 
 examples/vhost/vswitch_common.c | 499 ++
 examples/vhost/vswitch_common.h | 186 +++
 examples/vhost/vswitch_txrx.c   |  97 ++
 examples/vhost/vswitch_txrx.h   |  71 +
 9 files changed, 1800 insertions(+), 442 deletions(-)
 create mode 100644 examples/vhost/vmdq.c
 create mode 100644 examples/vhost/vmdq.h
 create mode 100644 examples/vhost/vswitch_common.c
 create mode 100644 examples/vhost/vswitch_common.h
 create mode 100644 examples/vhost/vswitch_txrx.c
 create mode 100644 examples/vhost/vswitch_txrx.h

-- 
1.9.1



[dpdk-dev] [RFC][PATCH 2/3] examples/vhost: Add vswitch command line options

2016-09-03 Thread Pankaj Chauhan
On 9/2/2016 8:14 PM, Maxime Coquelin wrote:
>
>
> On 08/27/2016 06:26 PM, Pankaj Chauhan wrote:
>> Add command line options for selecting switch implementation
>> and maximum ports for the vswitch.following are two new command
>> line options:
>>
>> --switch  [char string, Selects the switch imlementation]
>> --max-ports [int, selects maximum number of ports to support]
>>
>> For example:
>>
>> $ ./vhost-switch -c 3 -n 2 --socket-mem 1024 --huge-dir /hugetlbfs -- -p
>> 0x1 --dev-basename sock1 --switch "vmdq" --max-ports 3
>>
>> Signed-off-by: Pankaj Chauhan 
>> ---
>>  examples/vhost/main.c | 43 +++
>>  1 file changed, 43 insertions(+)
>>
>> diff --git a/examples/vhost/main.c b/examples/vhost/main.c
>> index 92a9823..59cddb8 100644
>> --- a/examples/vhost/main.c
>> +++ b/examples/vhost/main.c
>> @@ -142,6 +142,10 @@ static uint32_t burst_rx_retry_num =
>> BURST_RX_RETRIES;
>>  /* Character device basename. Can be set by user. */
>>  static char dev_basename[MAX_BASENAME_SZ] = "vhost-net";
>>
>> +/* vswitch device name and maximum number of ports */
>> +static char switch_dev[MAX_BASENAME_SZ] = "vmdq";
>> +static uint32_t switch_max_ports = MAX_DEVICES;
>> +
>>  /* empty vmdq configuration structure. Filled in programatically */
>>  static struct rte_eth_conf vmdq_conf_default = {
>>  .rxmode = {
>> @@ -408,6 +412,22 @@ us_vhost_parse_basename(const char *q_arg)
>>  }
>>
>>  /*
>> + * Set switch device name.
>> + */
>> +static int
>> +us_vhost_parse_switch_name(const char *q_arg)
>> +{
>> +/* parse number string */
>> +
>> +if (strnlen(q_arg, MAX_BASENAME_SZ) > MAX_BASENAME_SZ)
>> +return -1;
>> +else
>> +snprintf((char*)_dev, MAX_BASENAME_SZ, "%s", q_arg);
> why casting?

yes not required, will remove it.
>> +
>> +return 0;
>> +}
>> +
>> +/*
>>   * Parse the portmask provided at run time.
>>   */
>>  static int
>> @@ -501,6 +521,8 @@ us_vhost_parse_args(int argc, char **argv)
>>  {"tx-csum", required_argument, NULL, 0},
>>  {"tso", required_argument, NULL, 0},
>>  {"client", no_argument, _mode, 1},
>> +{"switch", required_argument, NULL, 0},
>> +{"max-ports", required_argument, NULL, 0},
>>  {NULL, 0, 0, 0},
>>  };
>>
>> @@ -655,6 +677,27 @@ us_vhost_parse_args(int argc, char **argv)
>>  }
>>  }
>>
>> +/* Set vswitch_driver name */
>> +if (!strncmp(long_option[option_index].name, "switch",
>> MAX_LONG_OPT_SZ)) {
>> +if (us_vhost_parse_switch_name(optarg) == -1) {
>> +RTE_LOG(INFO, VHOST_CONFIG, "Invalid argument for
>> character switch dev (Max %d characters)\n", MAX_BASENAME_SZ);
> ERR may be morez appropriate.

I didn't get the comment, can you please help me understand.
> And the message may be a little too long.

I will shorten it, thanks.
>
>> +us_vhost_usage(prgname);
>> +return -1;
>> +}
>> +}
>> +
>> +/* Specify Max ports in vswitch. */
>> +if (!strncmp(long_option[option_index].name, "max-ports",
>> MAX_LONG_OPT_SZ)) {
>> +ret = parse_num_opt(optarg, INT32_MAX);
>> +if (ret == -1) {
>> +RTE_LOG(INFO, VHOST_CONFIG, "Invalid argument for
>> switch max ports [0-N]\n");
>> +us_vhost_usage(prgname);
>> +return -1;
>> +} else {
>> +switch_max_ports = ret;
>> +}
> The else is not needed as the 'if' returns.

Agreed, will fix it.
>> +}
>> +
>>  break;
>>
>>  /* Invalid option - print options. */
>>
>




[dpdk-dev] [RFC][PATCH 1/3] examples/vhost: Add vswitch (generic switch) framework

2016-09-03 Thread Pankaj Chauhan
On 9/2/2016 7:47 PM, Maxime Coquelin wrote:
>
> Hi Pankaj,
>
>   Sorry for the late review.

Hi Maxime,

No problem :) Thanks for the review, and it came just in time. I am 
almost done with testing the patchset for intel (with vmdq) and i was 
about to send the next version tomorrow.

Now that i've your review and views, i will incorporte them and send the 
tested patchset soon.

Thanks again for your time and effort for review.

>
> On 08/27/2016 06:26 PM, Pankaj Chauhan wrote:
>> Indroduce support for a generic framework for handling of switching
>> between
> s/Indroduce/Introduce/
>> physical and virtio devices. The vswitch framework introduces the
>> following
>> concept:
> Shouldn't you use vhost term instead of virtio?

Agreed, i will use vhost in next version
>>
>> 1. vswitch_dev: Vswitch device is a logical switch which can have
>> Phsyical and
> s/Phsyical/physical/
>> virtio devices. The devices are operated/used using standard DPDK API for
>> devices.
> Maybe mention that today, we don't use PMD API for vhost devices but
> use directly the vhost library API?

Agreed, will do it.
>>
>> 2. vswitch_port: Any physical or virtio device that is added to
>> vswitch. The
>> port can have it's own tx/rx functions for doing data transfer, which
>> are exposed
> s/it's/its/

sorry for typo, will fix it.
>> to the framework using generic function pointers
>> (vs_port->do_tx/do_rx). This way
>> the generic code can do tx/rx without understanding the type of device
>> (Physical or
>> virtio).
> Very good.
>>
>> 3. vswitch_ops: The ops is set of function pointers which are used to
>> do operations
>> like learning, unlearning, add/delete port, lookup_and_forward. The
>> user of vswitch
>> framework (vhost/main.[c,h])uses these function pointers to perform
>> above mentioned
>> operations, thus it remains agnostic of the underlying implmentation.
> s/implmentation/implementation/

Typo again my bad!, will fix it
>
>
>>
>> Different switching logics can implement their vswitch_device and
>> vswitch_ops, and
>> register with the framework. This framework makes vhost-switch
>> application scalable
>> in terms of:
>>
>> 1. Different switching logics (one of them is vmdq, vhost/vmdq.[c,h]
>> 2. Number of ports.
>> 3. Policies of selecting ports for rx and tx.
>>
>> Signed-off-by: Pankaj Chauhan 
>> ---
>>  examples/vhost/Makefile |   2 +-
>>  examples/vhost/vswitch_common.c | 467
>> 
>>  examples/vhost/vswitch_common.h | 175 +++
>>  3 files changed, 643 insertions(+), 1 deletion(-)
>>  create mode 100644 examples/vhost/vswitch_common.c
>>  create mode 100644 examples/vhost/vswitch_common.h
>>
>> diff --git a/examples/vhost/Makefile b/examples/vhost/Makefile
>> index e95c68a..458d166 100644
>> --- a/examples/vhost/Makefile
>> +++ b/examples/vhost/Makefile
>> @@ -48,7 +48,7 @@ else
>>  APP = vhost-switch
>>
>>  # all source are stored in SRCS-y
>> -SRCS-y := main.c
>> +SRCS-y := main.c vswitch_common.c
>>
>>  CFLAGS += -O2 -D_FILE_OFFSET_BITS=64
>>  CFLAGS += $(WERROR_FLAGS)
>> diff --git a/examples/vhost/vswitch_common.c
>> b/examples/vhost/vswitch_common.c
>> new file mode 100644
>> index 000..f0e07f2
>> --- /dev/null
>> +++ b/examples/vhost/vswitch_common.c
>> @@ -0,0 +1,467 @@
>> +/*-
>> + *   BSD LICENSE
>> + *
>> + *   Copyright(c) 2016 Freescale Semiconductor. All rights reserved.
>> + *   All rights reserved.
>> + *
>> + *   Redistribution and use in source and binary forms, with or without
>> + *   modification, are permitted provided that the following conditions
>> + *   are met:
>> + *
>> + * * Redistributions of source code must retain the above copyright
>> + *   notice, this list of conditions and the following disclaimer.
>> + * * Redistributions in binary form must reproduce the above
>> copyright
>> + *   notice, this list of conditions and the following disclaimer in
>> + *   the documentation and/or other materials provided with the
>> + *   distribution.
>> + * * Neither the name of Freescale Semiconductor nor the names of
>> its
>> + *   contributors may be used to endorse or promote products derived
>> + *   from this software without specific prior written permission.
>> + *
>> + *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
>> + *   "AS IS" AND ANY EXPRESS OR

[dpdk-dev] [RFC][PATCH 3/3] examples/vhost: Add VMDQ vswitch device

2016-08-27 Thread Pankaj Chauhan
Add support for VMDQ vswitch device. This patch takes
out all VMDQ specefic code from vhost/main.[c,h] and
move it to vmdq.[c,h]. Moreover vmdq.[c,h] files plug
the VMDQ vswitch device implmentation to the vhost-switch
using vswitch framework.

The main vhost/main.[c,h] code is now generic and can support
any switch implementation that conforms with vswitch framework.

Please note that the core VMDQ logic remains as it is, as it
was in vhost/main.c, this patch just moves it to different
file and fits into ops provided by framework.

Signed-off-by: Pankaj Chauhan 
---
 examples/vhost/Makefile |   2 +-
 examples/vhost/main.c   | 562 ++---
 examples/vhost/main.h   |  10 +
 examples/vhost/vmdq.c   | 649 
 examples/vhost/vmdq.h   |  59 +
 5 files changed, 844 insertions(+), 438 deletions(-)
 create mode 100644 examples/vhost/vmdq.c
 create mode 100644 examples/vhost/vmdq.h

diff --git a/examples/vhost/Makefile b/examples/vhost/Makefile
index 458d166..f1f96fe 100644
--- a/examples/vhost/Makefile
+++ b/examples/vhost/Makefile
@@ -48,7 +48,7 @@ else
 APP = vhost-switch

 # all source are stored in SRCS-y
-SRCS-y := main.c vswitch_common.c
+SRCS-y := main.c vswitch_common.c vmdq.c

 CFLAGS += -O2 -D_FILE_OFFSET_BITS=64
 CFLAGS += $(WERROR_FLAGS)
diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 59cddb8..74d5031 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -54,6 +54,7 @@
 #include 

 #include "main.h"
+#include "vswitch_common.h"

 #ifndef MAX_QUEUES
 #define MAX_QUEUES 128
@@ -65,7 +66,6 @@
 #define MBUF_CACHE_SIZE128
 #define MBUF_DATA_SIZE RTE_MBUF_DEFAULT_BUF_SIZE

-#define MAX_PKT_BURST 32   /* Max burst size for RX/TX */
 #define BURST_TX_DRAIN_US 100  /* TX drain every ~100us */

 #define BURST_RX_WAIT_US 15/* Defines how long we wait between retries on 
RX */
@@ -103,7 +103,6 @@ static uint32_t enabled_port_mask = 0;
 static uint32_t promiscuous;

 /* number of devices/queues to support*/
-static uint32_t num_queues = 0;
 static uint32_t num_devices;

 static struct rte_mempool *mbuf_pool;
@@ -112,6 +111,8 @@ static int mergeable;
 /* Do vlan strip on host, enabled on default */
 static uint32_t vlan_strip = 1;

+static uint32_t jumbo_frame_en = 0;
+
 /* Enable VM2VM communications. If this is disabled then the MAC address 
compare is skipped. */
 typedef enum {
VM2VM_DISABLED = 0,
@@ -146,74 +147,16 @@ static char dev_basename[MAX_BASENAME_SZ] = "vhost-net";
 static char switch_dev[MAX_BASENAME_SZ] = "vmdq";
 static uint32_t switch_max_ports = MAX_DEVICES;

-/* empty vmdq configuration structure. Filled in programatically */
-static struct rte_eth_conf vmdq_conf_default = {
-   .rxmode = {
-   .mq_mode= ETH_MQ_RX_VMDQ_ONLY,
-   .split_hdr_size = 0,
-   .header_split   = 0, /**< Header Split disabled */
-   .hw_ip_checksum = 0, /**< IP checksum offload disabled */
-   .hw_vlan_filter = 0, /**< VLAN filtering disabled */
-   /*
-* It is necessary for 1G NIC such as I350,
-* this fixes bug of ipv4 forwarding in guest can't
-* forward pakets from one virtio dev to another virtio dev.
-*/
-   .hw_vlan_strip  = 1, /**< VLAN strip enabled. */
-   .jumbo_frame= 0, /**< Jumbo Frame Support disabled */
-   .hw_strip_crc   = 0, /**< CRC stripped by hardware */
-   },
-
-   .txmode = {
-   .mq_mode = ETH_MQ_TX_NONE,
-   },
-   .rx_adv_conf = {
-   /*
-* should be overridden separately in code with
-* appropriate values
-*/
-   .vmdq_rx_conf = {
-   .nb_queue_pools = ETH_8_POOLS,
-   .enable_default_pool = 0,
-   .default_pool = 0,
-   .nb_pool_maps = 0,
-   .pool_map = {{0, 0},},
-   },
-   },
-};
-
+struct vswitch_dev *vswitch_dev_g;
 static unsigned lcore_ids[RTE_MAX_LCORE];
 static uint8_t ports[RTE_MAX_ETHPORTS];
 static unsigned num_ports = 0; /**< The number of ports specified in command 
line */
-static uint16_t num_pf_queues, num_vmdq_queues;
-static uint16_t vmdq_pool_base, vmdq_queue_base;
-static uint16_t queues_per_pool;
-
-const uint16_t vlan_tags[] = {
-   1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007,
-   1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015,
-   1016, 1017, 1018, 1019, 1020, 1021, 1022, 1023,
-   1024, 1025, 1026, 1027, 1028, 1029, 1030, 1031,
-   1032, 1033, 1034, 1035, 1036, 1037, 1038, 1039,
-   1040, 1041, 1042, 1043, 1044, 1045, 1046, 1047,
-   1048, 1049, 1050, 1051, 1052, 1053, 1054, 1055,
-   1056, 1057, 1058, 1059, 1060, 1061, 1062, 

[dpdk-dev] [RFC][PATCH 2/3] examples/vhost: Add vswitch command line options

2016-08-27 Thread Pankaj Chauhan
Add command line options for selecting switch implementation
and maximum ports for the vswitch.following are two new command
line options:

--switch  [char string, Selects the switch imlementation]
--max-ports [int, selects maximum number of ports to support]

For example:

$ ./vhost-switch -c 3 -n 2 --socket-mem 1024 --huge-dir /hugetlbfs -- -p
0x1 --dev-basename sock1 --switch "vmdq" --max-ports 3

Signed-off-by: Pankaj Chauhan 
---
 examples/vhost/main.c | 43 +++
 1 file changed, 43 insertions(+)

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 92a9823..59cddb8 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -142,6 +142,10 @@ static uint32_t burst_rx_retry_num = BURST_RX_RETRIES;
 /* Character device basename. Can be set by user. */
 static char dev_basename[MAX_BASENAME_SZ] = "vhost-net";

+/* vswitch device name and maximum number of ports */
+static char switch_dev[MAX_BASENAME_SZ] = "vmdq";
+static uint32_t switch_max_ports = MAX_DEVICES;
+
 /* empty vmdq configuration structure. Filled in programatically */
 static struct rte_eth_conf vmdq_conf_default = {
.rxmode = {
@@ -408,6 +412,22 @@ us_vhost_parse_basename(const char *q_arg)
 }

 /*
+ * Set switch device name.
+ */
+static int
+us_vhost_parse_switch_name(const char *q_arg)
+{
+   /* parse number string */
+
+   if (strnlen(q_arg, MAX_BASENAME_SZ) > MAX_BASENAME_SZ)
+   return -1;
+   else
+   snprintf((char*)_dev, MAX_BASENAME_SZ, "%s", q_arg);
+
+   return 0;
+}
+
+/*
  * Parse the portmask provided at run time.
  */
 static int
@@ -501,6 +521,8 @@ us_vhost_parse_args(int argc, char **argv)
{"tx-csum", required_argument, NULL, 0},
{"tso", required_argument, NULL, 0},
{"client", no_argument, _mode, 1},
+   {"switch", required_argument, NULL, 0},
+   {"max-ports", required_argument, NULL, 0},
{NULL, 0, 0, 0},
};

@@ -655,6 +677,27 @@ us_vhost_parse_args(int argc, char **argv)
}
}

+   /* Set vswitch_driver name */
+   if (!strncmp(long_option[option_index].name, "switch", 
MAX_LONG_OPT_SZ)) {
+   if (us_vhost_parse_switch_name(optarg) == -1) {
+   RTE_LOG(INFO, VHOST_CONFIG, "Invalid 
argument for character switch dev (Max %d characters)\n", MAX_BASENAME_SZ);
+   us_vhost_usage(prgname);
+   return -1;
+   }
+   }
+
+   /* Specify Max ports in vswitch. */
+   if (!strncmp(long_option[option_index].name, 
"max-ports", MAX_LONG_OPT_SZ)) {
+   ret = parse_num_opt(optarg, INT32_MAX);
+   if (ret == -1) {
+   RTE_LOG(INFO, VHOST_CONFIG, "Invalid 
argument for switch max ports [0-N]\n");
+   us_vhost_usage(prgname);
+   return -1;
+   } else {
+   switch_max_ports = ret;
+   }
+   }
+
break;

/* Invalid option - print options. */
-- 
1.9.1



[dpdk-dev] [RFC][PATCH 1/3] examples/vhost: Add vswitch (generic switch) framework

2016-08-27 Thread Pankaj Chauhan
Indroduce support for a generic framework for handling of switching between
physical and virtio devices. The vswitch framework introduces the following
concept:

1. vswitch_dev: Vswitch device is a logical switch which can have Phsyical and
virtio devices. The devices are operated/used using standard DPDK API for
devices.

2. vswitch_port: Any physical or virtio device that is added to vswitch. The
port can have it's own tx/rx functions for doing data transfer, which are 
exposed
to the framework using generic function pointers (vs_port->do_tx/do_rx). This 
way
the generic code can do tx/rx without understanding the type of device 
(Physical or
virtio).

3. vswitch_ops: The ops is set of function pointers which are used to do 
operations
like learning, unlearning, add/delete port, lookup_and_forward. The user of 
vswitch
framework (vhost/main.[c,h])uses these function pointers to perform above 
mentioned
operations, thus it remains agnostic of the underlying implmentation.

Different switching logics can implement their vswitch_device and vswitch_ops, 
and
register with the framework. This framework makes vhost-switch application 
scalable
in terms of:

1. Different switching logics (one of them is vmdq, vhost/vmdq.[c,h]
2. Number of ports.
3. Policies of selecting ports for rx and tx.

Signed-off-by: Pankaj Chauhan 
---
 examples/vhost/Makefile |   2 +-
 examples/vhost/vswitch_common.c | 467 
 examples/vhost/vswitch_common.h | 175 +++
 3 files changed, 643 insertions(+), 1 deletion(-)
 create mode 100644 examples/vhost/vswitch_common.c
 create mode 100644 examples/vhost/vswitch_common.h

diff --git a/examples/vhost/Makefile b/examples/vhost/Makefile
index e95c68a..458d166 100644
--- a/examples/vhost/Makefile
+++ b/examples/vhost/Makefile
@@ -48,7 +48,7 @@ else
 APP = vhost-switch

 # all source are stored in SRCS-y
-SRCS-y := main.c
+SRCS-y := main.c vswitch_common.c

 CFLAGS += -O2 -D_FILE_OFFSET_BITS=64
 CFLAGS += $(WERROR_FLAGS)
diff --git a/examples/vhost/vswitch_common.c b/examples/vhost/vswitch_common.c
new file mode 100644
index 000..f0e07f2
--- /dev/null
+++ b/examples/vhost/vswitch_common.c
@@ -0,0 +1,467 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2016 Freescale Semiconductor. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Freescale Semiconductor nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#include "vswitch_common.h"
+
+/* Meta data for vswitch. Since this is going to be used in this file only it
+ * is defined here instead of in a header file.
+ */
+struct vs_mdata {
+   rte_spinlock_t lock;
+   int vswitch_dev_count;
+   LIST_HEAD(, vswitch_dev) vswitch_head;
+};
+
+static struct vs_mdata *vs_mdata_g;
+
+static uint16_t vs_do_tx_phys_port(struct vswitch_port *port, uint16_t tx_q,
+   __attribute__((unused))struct rte_mempool *mbuf_pool,
+  struct rte_mbuf **pkts, uint16_t pkt_count)
+{
+   return rte_eth_tx_burst(port->port_id, tx_q, pkts, pkt_count);
+}
+
+
+static uint16_t vs_do_tx_virtio_port(struct vswitch_port *port, uint16_t tx_q,
+   __attribute__((unused)) struct rte_mempool *mbuf_pool,
+   struct rte_mbuf 

[dpdk-dev] [RFC][PATCH 0/3] example/vhost: Introduce Vswitch Framework

2016-08-27 Thread Pankaj Chauhan
Introduce generic vswitch framework in vhost-switch application. Following
are the goals/aim of the framework:

1. Make vhost-switch application generic so that it can support devices 
which don't support VMDQ.

2. Provide a framework so that any switching logic (generic in software or
vendor specefic like VMDQ) can work with vhost-switch. Thus making vhost-switch
applicable for multiple platforms of different vendors.

3. Make vhost-switch and switching logic scalable in terms of ports or policies
of doing rx/tx across the ports added to switch.

The patchset includes three patches:
1. "Add vswitch(generic switch) framework": This adds the generic framework, it 
provides
the APIs/accessor functions which the vhos-switch application uses without 
knowing
anything about underlying switching logic. The framework introduces the concept 
of
vswitch_device, vswitch_port, and vswitch_ops. The idea is that vhost-switch 
will
sit over the framework and different switching logics will plug into the 
framework
underneath it. Please refer the patch description for more details of devices, 
ports
and ops.

2. "Add vswitch command line options": Adds two new command line options for 
vswitch.
3. "Add VMDQ vswitch device": This patch basically delinks existing 
vhost/main.[c,h]
from VMDQ and adds VMDQ as a vswitch device implmentation which plugs into the 
vswitch
framework. Any other vendor logic for switching can also be plugged in same way.

Thanks to Tan Jianfeng, Yuanhan Liu, Maxime coquelin for early discussions and 
inputs
on this concept.

** Caution and disclaimer **
1. The patch set is not tested, it just compiles fine: I just finished the 
coding and
sending the RFC patch so that it can be reviewed early. In parallel i will 
start testing it
and therefore please forgive if you find some code which you think will crash 
shamelessly
(i know it will crash :), it is not tested). So please review the concept, 
meanwhile
i will test and  send the next version soon.

2. This patchset is first step towards using vhost-switch on platforms other 
than
intel and making it generic. It is no way complete, so i expect that we 
discuss/develop
toghether towards the goals i mentioned in this cover letter.

TODO list:
1. Test obviously : i will do it in comming week, once basic things are working 
i will
send another version which you can use for your testing. Till then don't spend 
your
time in test because i am sure it will waste your time for my silly mistakes.

2. Addd constructor based logic for registration of Vswitch implmentations like 
VMDQ.
we will use similar mechanism as registration of PMD drivers (base on 
constructor function)
to register all the switch implmentations in vhost-switch and then select the 
required
implementation using command line option 'switch'.

Pankaj Chauhan (3):
  examples/vhost: Add vswitch (generic switch) framework
  examples/vhost: Add vwitch command line options
  examples/vhost: Add VMDQ vswitch device

 examples/vhost/Makefile |   2 +-
 examples/vhost/main.c   | 603 +++--
 examples/vhost/main.h   |  10 +
 examples/vhost/vmdq.c   | 649 
 examples/vhost/vmdq.h   |  59 
 examples/vhost/vswitch_common.c | 467 +
 examples/vhost/vswitch_common.h | 175 +++
 7 files changed, 1528 insertions(+), 437 deletions(-)
 create mode 100644 examples/vhost/vmdq.c
 create mode 100644 examples/vhost/vmdq.h
 create mode 100644 examples/vhost/vswitch_common.c
 create mode 100644 examples/vhost/vswitch_common.h

-- 
1.9.1



[dpdk-dev] vhost [query] : support for multiple ports and non VMDQ devices in vhost switch

2016-08-26 Thread Pankaj Chauhan
On 8/24/2016 12:58 PM, Maxime Coquelin wrote:
>
>
> On 08/18/2016 04:35 AM, Tan, Jianfeng wrote:
>> Hi Maxime,
>>
>> On 8/17/2016 7:18 PM, Maxime Coquelin wrote:
>>> Hi Jianfeng,
>>>
>>> On 08/17/2016 04:33 AM, Tan, Jianfeng wrote:
 Hi,

 Please review below proposal of Pankaj and myself after an offline
 discussion. (Pankaj, please correct me if I'm going somewhere wrong).

 a. Remove HW dependent option, --strip-vlan, because different kinds of
 NICs behave differently. It's a bug fix.
 b. Abstract switching logic into a framework, so that we can develop
 different kinds of switching logics. In this phase, we will have two
 switching logics: (1) a simple software-based mac learning switching;
 (2) VMDQ based switching. Any other advanced switching logics can be
 proposed based on this framework.
 c. Merge tep_termination example vxlan as a switching logic of the
 framework.
>>>
>>> I was also thinking of making physical port optional and add MAC
>>> learning,
>>> so this is all good for me.
>>
>> To make it clear, we are not proposing to eliminate physical port,
>> instead, we just eliminate the binding of VMDQ and virtio ports,
>> superseding it with a MAC learning switching.
>>
>>>
>>> Let me know if I can help in implementation, I'll be happy to
>>> contribute.
>>
>> Thank you for participating. Currently, I'm working on item a (will be a
>> quick and simple fix). Pankaj is working on item b (which would be a
>> huge change). Item c is depending on item b. So let's wait RFC patch
>> from Pankaj and see what we can help.
>
> Pankaj, so I organize myself , do you have an idea of when the RFC
> patch will be available?

I am almost finishing the first version of RFC patch set, hoping to send 
it today itself.

Thanks,
Pankaj
>
> Thanks,
> Maxime
>




[dpdk-dev] vhost [query] : support for multiple ports and non VMDQ devices in vhost switch

2016-08-17 Thread Pankaj Chauhan
On 8/16/2016 8:26 AM, Yuanhan Liu wrote:
> On Tue, Aug 09, 2016 at 04:42:33PM +0530, Pankaj Chauhan wrote:
>>
>> Hi,
>>
>> I am working on an NXP platform where we intend to use user space vhost
>> switch (examples/vhost) as backend for VIRTIO devices. But there are two
>> limitations in current vhost-switch (examples/vhost)that are restricting my
>> use case:
>>
>> 1. The vhost-switch application is tightly integrated with Intel VMDQ. Since
>> my device doesn't have VMDQ i can not use this application directly.
>
> Sorry being late (I was on biz trip last week).
>
> Yes, a vhost example should not do that. We have an internal TODO to
> remove it. Actually, to make it optional, and Jianfeng was working on
> that. Well, seems that you two have already had some discussions.

Yes I had a discussion with Jianfeng and he has sent the work items on 
the list.
>
>> 2. The vhost-switch application supports only one external or physical port
>> (non virtio devices), but my requirement is to have multiple physical ports
>> and multiple virtio devices.
>
> What are you going to achieve? BTW, have you tried testpmd (with vhost-pmd)?
> I'm with impression that it might be a better option to you.
>
>   --yliu
My use case is that my machine/board which is not sitting as end node of 
network but somewhere in between like an router. So the traffic looks 
something like this:

Physical port 1 -> Enter VM(s) through virtio -> exit from physical port 2

For above use case i need a vhost-back-end which supports multiple 
physical ports.

Thanks for the suggestion of vhost-pmd ( i was not aware of that), i'll 
explore possibility of using it for my use case of multiple physical ports.

thanks,
Pankaj

>




[dpdk-dev] Running DPDK in a VM

2016-08-10 Thread Pankaj Chauhan
On 8/4/2016 3:51 PM, Vaibhav Sood wrote:
Hi,

> Hi!
>
> I am looking at running DPDK in a VM, I would like to know if there are any 
> limitations when doing this in terms of any DPDK features that do not work in 
> a VM
>

We do run DPDK in VM, and we have not come across any major limitations. 
There are multiple ways to run DPDK in virtual machine, if you are using 
virtio devices:

1. vhost-switch : please refer following link:

http://dpdk.readthedocs.io/en/v16.04/sample_app_ug/vhost.html

2. you can use OVS also as backend instead of vhost-switch.

we've used both methods on our platforms and they work fine.

> The only post I came across for running DPDK in a VM is this: 
> http://dpdk.org/ml/archives/dev/2013-September/000441.html
>
> As an example, I tried to run the DPDK test suite (DTS, 
> http://dpdk.org/doc/dts/gsg/ ) and see some tests fail saying virtio nics are 
> not supported (Specifically, the ethertype_filter and five_tuple_filter tests 
> give an error: FAILED ''virtio nic not support syn filter''). I would like to 
> know if there are any limitations along these lines when running DPDK in VMs 
> as compared to physical machines/NICS
>
> Thanks!
> Vaibhav
>

Thanks,
Pankaj




[dpdk-dev] vhost [query] : support for multiple ports and non VMDQ devices in vhost switch

2016-08-09 Thread Pankaj Chauhan

Hi,

I am working on an NXP platform where we intend to use user space vhost 
switch (examples/vhost) as backend for VIRTIO devices. But there are two 
limitations in current vhost-switch (examples/vhost)that are restricting 
my use case:

1. The vhost-switch application is tightly integrated with Intel VMDQ. 
Since my device doesn't have VMDQ i can not use this application directly.

2. The vhost-switch application supports only one external or physical 
port (non virtio devices), but my requirement is to have multiple 
physical ports and multiple virtio devices.

In summary my requirement is to do whatever vhost-switch is doing, in 
addition to that add support for following:

1. support devices that don't have VMDQ.
2. Support multiple physical ports.

I need suggestions on the approach i should take: whether to add support 
of above mentioned in existing vhost-switch (examples/vhost) or write 
another application (based on librte_vhost only) to support my requirements.

I'll work on it after the suggestion i get from the list, and send the 
RFC patch.

Thanks,
Pankaj