[dpdk-dev] [PATCH 0/4] virtio support for container

Tan, Jianfeng jianfeng.tan at intel.com
Tue Jan 12 17:18:34 CET 2016


Hello,

On 1/12/2016 11:11 PM, Amit Tomer wrote:
> Hello,
>
>> In vhost-switch, it judges if a virtio device is ready for processing after
>> receiving
>> a pkt from virtio device. So you'd better construct a pkt, and send it out
>> firstly
>> in l2fwd.
> I tried to ping the socket interface from host for the same purpose
> but it didn't work.
>
> Could you please suggest some other approach for achieving same(how
> pkt can be sent out to l2fwd)?
>
> Also, before trying this, I have verified that vhost-switch is working
> ok with testpmd .
>
> Thanks,
> Amit.

You can use below patch for l2fwd to send out an arp packet when it gets 
started.

diff --git a/examples/l2fwd/main.c b/examples/l2fwd/main.c
index 720fd5a..572b1ac 100644
--- a/examples/l2fwd/main.c
+++ b/examples/l2fwd/main.c
@@ -69,6 +69,8 @@
  #include <rte_mempool.h>
  #include <rte_mbuf.h>

+#define SEND_ARP
+
  #define RTE_LOGTYPE_L2FWD RTE_LOGTYPE_USER1

  #define NB_MBUF   8192
@@ -185,6 +187,53 @@ print_stats(void)
printf("\n====================================================\n");
  }

+#ifdef SEND_ARP
+static void
+dpdk_send_arp(int portid, struct rte_mempool *mp)
+{
+    /*
+     * len = 14 + 46
+     * ARP, Request who-has 10.0.0.1 tell 10.0.0.2, length 46
+     */
+    static const uint8_t arp_request[] = {
+        /*0x0000:*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xec, 0xa8, 
0x6b, 0xfd, 0x02, 0x29, 0x08, 0x06, 0x00, 0x01,
+        /*0x0010:*/ 0x08, 0x00, 0x06, 0x04, 0x00, 0x01, 0xec, 0xa8, 
0x6b, 0xfd, 0x02, 0x29, 0x0a, 0x00, 0x00, 0x01,
+        /*0x0020:*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 
0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+        /*0x0030:*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00
+    };
+    int ret;
+    struct rte_mbuf *m;
+    struct ether_addr mac_addr;
+    int pkt_len = sizeof(arp_request) - 1;
+
+    m = rte_pktmbuf_alloc(mp);
+
+    memcpy((void *)((uint64_t)m->buf_addr + m->data_off), arp_request, 
pkt_len);
+    rte_pktmbuf_pkt_len(m) = pkt_len;
+    rte_pktmbuf_data_len(m) = pkt_len;
+
+    rte_eth_macaddr_get(portid, &mac_addr);
+    memcpy((void *)((uint64_t)m->buf_addr + m->data_off + 6), 
&mac_addr, 6);
+
+    ret = rte_eth_tx_burst(portid, 0, &m, 1);
+    if (ret == 1) {
+        printf("arp sent: ok\n");
+        printf("%02x:%02x:%02x:%02x:%02x:%02x\n",
+                mac_addr.addr_bytes[0],
+                mac_addr.addr_bytes[1],
+                mac_addr.addr_bytes[2],
+                mac_addr.addr_bytes[3],
+                mac_addr.addr_bytes[4],
+                mac_addr.addr_bytes[5]);
+    } else {
+        printf("arp sent: fail\n");
+    }
+
+    rte_pktmbuf_free(m);
+}
+#endif
+
+
  /* Send the burst of packets on an output interface */
  static int
  l2fwd_send_burst(struct lcore_queue_conf *qconf, unsigned n, uint8_t port)
@@ -281,6 +330,9 @@ l2fwd_main_loop(void)
          portid = qconf->rx_port_list[i];
          RTE_LOG(INFO, L2FWD, " -- lcoreid=%u portid=%u\n", lcore_id,
              portid);
+#ifdef SEND_ARP
+        dpdk_send_arp(portid, l2fwd_pktmbuf_pool);
+#endif
      }

      while (1) {



More information about the dev mailing list