DPDK patches and discussions
 help / color / mirror / Atom feed
From: Yuanhan Liu <yuanhan.liu@linux.intel.com>
To: dev@dpdk.org
Cc: huawei.xie@intel.com, Yuanhan Liu <yuanhan.liu@linux.intel.com>
Subject: [dpdk-dev] [PATCH v2 5/8] examples/vhost: handle broadcast packet
Date: Mon,  2 May 2016 14:23:47 -0700	[thread overview]
Message-ID: <1462224230-19460-6-git-send-email-yuanhan.liu@linux.intel.com> (raw)
In-Reply-To: <1462224230-19460-1-git-send-email-yuanhan.liu@linux.intel.com>

Every time I do a VM2VM iperf test with vhost example, I have to set
the arp table manually, as vhost-switch just ignores the broadcast
packet, leaving the ARP request not served.

Here we do a transmit a broadcast packet (such as ARP request) to
every vhost device, as well as the physical port, to fix above
arp table issue.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 examples/vhost/main.c | 39 +++++++++++++++++++++++++++++----------
 1 file changed, 29 insertions(+), 10 deletions(-)

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index bfcabf3..7448e4f 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -807,6 +807,21 @@ unlink_vmdq(struct vhost_dev *vdev)
 	}
 }
 
+static inline void __attribute__((always_inline))
+virtio_xmit(struct virtio_net *dst_dev, struct virtio_net *src_dev,
+	    struct rte_mbuf *m)
+{
+	uint16_t ret;
+
+	ret = rte_vhost_enqueue_burst(dst_dev, VIRTIO_RXQ, &m, 1);
+	if (enable_stats) {
+		rte_atomic64_inc(&dev_statistics[dst_dev->device_fh].rx_total_atomic);
+		rte_atomic64_add(&dev_statistics[dst_dev->device_fh].rx_atomic, ret);
+		dev_statistics[src_dev->device_fh].tx_total++;
+		dev_statistics[src_dev->device_fh].tx += ret;
+	}
+}
+
 /*
  * Check if the packet destination MAC address is for a local device. If so then put
  * the packet on that devices RX queue. If not then return.
@@ -815,7 +830,6 @@ static inline int __attribute__((always_inline))
 virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)
 {
 	struct ether_hdr *pkt_hdr;
-	uint64_t ret = 0;
 	struct vhost_dev *dst_vdev;
 	uint64_t fh;
 
@@ -842,15 +856,7 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)
 		return 0;
 	}
 
-	/* send the packet to the local virtio device */
-	ret = rte_vhost_enqueue_burst(dst_vdev->dev, VIRTIO_RXQ, &m, 1);
-	if (enable_stats) {
-		rte_atomic64_inc(&dev_statistics[fh].rx_total_atomic);
-		rte_atomic64_add(&dev_statistics[fh].rx_atomic, ret);
-		dev_statistics[vdev->dev->device_fh].tx_total++;
-		dev_statistics[vdev->dev->device_fh].tx += ret;
-	}
-
+	virtio_xmit(dst_vdev->dev, vdev->dev, m);
 	return 0;
 }
 
@@ -934,6 +940,17 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
 	struct virtio_net *dev = vdev->dev;
 	struct ether_hdr *nh;
 
+
+	nh = rte_pktmbuf_mtod(m, struct ether_hdr *);
+	if (unlikely(is_broadcast_ether_addr(&nh->d_addr))) {
+		struct vhost_dev *vdev2;
+
+		TAILQ_FOREACH(vdev2, &vhost_dev_list, next) {
+			virtio_xmit(vdev2->dev, vdev->dev, m);
+		}
+		goto queue2nic;
+	}
+
 	/*check if destination is local VM*/
 	if ((vm2vm_mode == VM2VM_SOFTWARE) && (virtio_tx_local(vdev, m) == 0)) {
 		rte_pktmbuf_free(m);
@@ -950,6 +967,8 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
 	RTE_LOG(DEBUG, VHOST_DATA, "(%" PRIu64 ") TX: "
 		"MAC address is external\n", dev->device_fh);
 
+queue2nic:
+
 	/*Add packet to the port tx queue*/
 	tx_q = &lcore_tx_queue[lcore_id];
 	len = tx_q->len;
-- 
1.9.3

  parent reply	other threads:[~2016-05-02 21:20 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-26  4:45 [dpdk-dev] [PATCH 0/7] vhost/example cleanup/fix Yuanhan Liu
2016-04-26  4:45 ` [dpdk-dev] [PATCH 1/7] examples/vhost: remove the non-working zero copy code Yuanhan Liu
2016-04-26  4:45 ` [dpdk-dev] [PATCH 2/7] examples/vhost: remove unused macro and struct Yuanhan Liu
2016-04-26  4:45 ` [dpdk-dev] [PATCH 3/7] examples/vhost: use tailq to link vhost devices Yuanhan Liu
2016-04-26  4:45 ` [dpdk-dev] [PATCH 4/7] examples/vhost: use mac compare helper function directly Yuanhan Liu
2016-04-26  4:45 ` [dpdk-dev] [PATCH 5/7] examples/vhost: handle broadcast packet Yuanhan Liu
2016-04-26  4:45 ` [dpdk-dev] [PATCH 6/7] examples/vhost: fix mbuf allocation failures Yuanhan Liu
2016-04-26  4:45 ` [dpdk-dev] [PATCH 7/7] examples/vhost: switch_worker cleanup Yuanhan Liu
2016-04-28  5:45 ` [dpdk-dev] [PATCH 0/7] vhost/example cleanup/fix Wang, Zhihong
2016-04-28  6:09   ` Yuanhan Liu
     [not found] ` <1462224230-19460-1-git-send-email-yuanhan.liu@linux.intel.com>
2016-05-02 21:23   ` [dpdk-dev] [PATCH v2 1/8] examples/vhost: remove the non-working zero copy code Yuanhan Liu
2016-05-02 21:23   ` [dpdk-dev] [PATCH v2 2/8] examples/vhost: remove unused macro and struct Yuanhan Liu
2016-05-02 21:23   ` [dpdk-dev] [PATCH v2 3/8] examples/vhost: use tailq to link vhost devices Yuanhan Liu
2016-05-02 21:23   ` [dpdk-dev] [PATCH v2 4/8] examples/vhost: use mac compare helper function directly Yuanhan Liu
2016-05-02 21:23   ` Yuanhan Liu [this message]
2016-05-02 21:23   ` [dpdk-dev] [PATCH v2 6/8] examples/vhost: fix mbuf allocation failure Yuanhan Liu
2016-05-02 21:23   ` [dpdk-dev] [PATCH v2 7/8] examples/vhost: switch_worker cleanup Yuanhan Liu
2016-05-02 21:23   ` [dpdk-dev] [PATCH v2 8/8] examples/vhost: embed statistics into vhost_dev struct Yuanhan Liu
2016-05-09 18:06   ` [dpdk-dev] [PATCH v2 0/8] vhost/example cleanup/fix Yuanhan Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1462224230-19460-6-git-send-email-yuanhan.liu@linux.intel.com \
    --to=yuanhan.liu@linux.intel.com \
    --cc=dev@dpdk.org \
    --cc=huawei.xie@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).