From: Jianfeng Tan <jianfeng.tan@intel.com>
To: dev@dpdk.org
Cc: Jianfeng Tan <jianfeng.tan@intel.com>
Subject: [dpdk-dev] [RFC] testpmd: handle UFO packets
Date: Sat, 24 Feb 2018 09:35:07 +0000 [thread overview]
Message-ID: <1519464907-133452-1-git-send-email-jianfeng.tan@intel.com> (raw)
Mostly likely, we will make UFO as a kind of GSO engine.
For short term, we can just call APIs in librte_ip_frag to fragment.
To test:
1. start testpmd with two vhost port.
$ set fwd csum
$ start
2. start vm0 connected to vhost0;
$ ifconfig xxx 1.1.1.1/24 up
$ ethtool -K xxx ufo on
3. start vm1 connected to vhost1;
$ ifconfig xxx 1.1.1.2/24 up
$ ethtool -K xxx ufo on
$ (Fill a large file named 1.txt)
$ cat 1.txt | socat - udp-sendto:1.1.1.1:5000
Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
---
app/test-pmd/csumonly.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 98 insertions(+)
diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c
index 5f5ab64..3e4c414 100644
--- a/app/test-pmd/csumonly.c
+++ b/app/test-pmd/csumonly.c
@@ -41,6 +41,7 @@
#include <rte_flow.h>
#include <rte_gro.h>
#include <rte_gso.h>
+#include <rte_ip_frag.h>
#include "testpmd.h"
@@ -574,6 +575,75 @@ pkt_copy_split(const struct rte_mbuf *pkt)
return md[0];
}
+static inline void
+frag_v4_fixup(const struct rte_mbuf *ms, struct rte_mbuf *mf)
+{
+ struct ipv4_hdr *l3h;
+
+ mf->ol_flags = ms->ol_flags;
+ mf->tx_offload = ms->tx_offload;
+
+ if ((ms->ol_flags & PKT_TX_IP_CKSUM) == 0) {
+ l3h = rte_pktmbuf_mtod(mf, struct ipv4_hdr *);
+ l3h->hdr_checksum = rte_ipv4_cksum(l3h);
+ }
+}
+
+/*
+ * Returns negative for failure to fragment or actual number of fragments.
+ */
+static inline int
+fragment(struct rte_mbuf *m, struct rte_mbuf *frag[], uint32_t num)
+{
+ void *l2;
+ int l2_len;
+ int32_t frag_num, i;
+ uint16_t ether_type;
+ struct ether_hdr *eth_hdr;
+
+ eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
+ ether_type = eth_hdr->ether_type;
+ m->l2_len = sizeof(*eth_hdr);
+ if (ether_type == ETHER_TYPE_VLAN) {
+ struct vlan_hdr *vlan_hdr = (struct vlan_hdr *)(eth_hdr + 1);
+ ether_type = rte_be_to_cpu_16(vlan_hdr->eth_proto);
+ m->l2_len += sizeof(struct vlan_hdr);
+ }
+ l2_len = m->l2_len;
+
+ /* store the l2 header */
+ uint8_t l2_hdr[l2_len];
+ rte_memcpy(l2_hdr, eth_hdr, l2_len);
+
+ /* Remove the l2 header from the input packet */
+ rte_pktmbuf_adj(m, l2_len);
+
+ if (ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv4))
+ frag_num = rte_ipv4_fragment_packet(m, frag, num,
+ m->tso_segsz, current_fwd_lcore()->mbp,
+ current_fwd_lcore()->mbp);
+ else
+ frag_num = rte_ipv6_fragment_packet(m, frag, num,
+ m->tso_segsz, current_fwd_lcore()->mbp,
+ current_fwd_lcore()->mbp);
+
+ if (frag_num > 0) {
+ for (i = 0; i != frag_num; i++) {
+
+ if (ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv4))
+ frag_v4_fixup(m, frag[i]);
+
+ /* Move data_off to include l2 header first */
+ l2 = rte_pktmbuf_prepend(frag[i], l2_len);
+
+ /* copy l2 header into fragmented packet */
+ rte_memcpy(l2, l2_hdr, l2_len);
+ }
+ }
+
+ return frag_num;
+}
+
/*
* Receive a burst of packets, and for each packet:
* - parse packet, and try to recognize a supported packet type (1)
@@ -603,6 +673,7 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
{
struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
struct rte_mbuf *gso_segments[GSO_MAX_PKT_BURST];
+ struct rte_mbuf *ufo_segments[GSO_MAX_PKT_BURST];
struct rte_gso_ctx *gso_ctx;
struct rte_mbuf **tx_pkts_burst;
struct rte_port *txp;
@@ -656,6 +727,32 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
if (gso_ports[fs->tx_port].enable)
info.gso_enable = 1;
+ nb_segments = 0;
+ for (i = 0; i < nb_rx; ++i) {
+ m = pkts_burst[i];
+ if (!(m->ol_flags & PKT_TX_UDP_SEG)) {
+ ufo_segments[nb_segments++] = m;
+ continue;
+ }
+
+ ret = fragment(m, &ufo_segments[nb_segments],
+ RTE_DIM(ufo_segments) - nb_segments);
+ if (ret <= 0) {
+ printf("ip frag failed %s\n", strerror(-ret));
+ rte_pktmbuf_free(m);
+ continue;
+ }
+ nb_segments += ret;
+ /* free the original packet */
+ rte_pktmbuf_free(m);
+ }
+
+ nb_rx = RTE_MIN(nb_segments, MAX_PKT_BURST);
+ for (i = 0; i < nb_rx; i++)
+ pkts_burst[i] = ufo_segments[i];
+ for (i = nb_rx; i < nb_segments; ++i)
+ rte_pktmbuf_free(ufo_segments[i]);
+
for (i = 0; i < nb_rx; i++) {
if (likely(i < nb_rx - 1))
rte_prefetch0(rte_pktmbuf_mtod(pkts_burst[i + 1],
@@ -832,6 +929,7 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
}
}
+ nb_segments = 0;
if (unlikely(gro_enable)) {
if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
nb_rx = rte_gro_reassemble_burst(pkts_burst, nb_rx,
--
2.7.4
next reply other threads:[~2018-02-24 9:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-24 9:35 Jianfeng Tan [this message]
2018-02-28 14:10 ` Jason Wang
2018-02-28 14:53 ` Tan, Jianfeng
2018-03-01 8:36 ` Jason Wang
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=1519464907-133452-1-git-send-email-jianfeng.tan@intel.com \
--to=jianfeng.tan@intel.com \
--cc=dev@dpdk.org \
/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).