diff options
author | Bogdan Pricope <bogdan.pricope@linaro.org> | 2018-01-09 11:50:19 +0200 |
---|---|---|
committer | Maxim Uvarov <maxim.uvarov@linaro.org> | 2018-01-14 18:29:51 +0300 |
commit | b1749baf2590f402ba3cbd23385b9056c99f3839 (patch) | |
tree | 962e6ff16a43bd3149721549ecd6252164fc366e /example/generator/odp_generator.c | |
parent | a37fda78cb7c7d4804c0d9ae1c67801977ce1de5 (diff) |
example: generator: replace L3/L4 packet parsing with a simple one
Platform packet parsing is providing information not needed by
this application while consuming cycles. Replacing platform packet
parsing with a limited parsing may increase performance on RX side.
Signed-off-by: Bogdan Pricope <bogdan.pricope@linaro.org>
Reviewed-by: Bill Fischofer <bill.fischofer@linaro.org>
Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
Diffstat (limited to 'example/generator/odp_generator.c')
-rw-r--r-- | example/generator/odp_generator.c | 49 |
1 files changed, 33 insertions, 16 deletions
diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c index 586c3ede4..f8c787e44 100644 --- a/example/generator/odp_generator.c +++ b/example/generator/odp_generator.c @@ -572,6 +572,12 @@ static int create_pktio(const char *dev, odp_pool_t pool, itf->config.pktout.bit.udp_chksum = 0; } + itf->config.parser.layer = ODP_PROTO_LAYER_L2; + if (itf->config.pktin.bit.udp_chksum) + itf->config.parser.layer = ODP_PROTO_LAYER_L4; + else if (itf->config.pktin.bit.ipv4_chksum) + itf->config.parser.layer = ODP_PROTO_LAYER_L3; + if (odp_pktio_config(itf->pktio, &itf->config)) { EXAMPLE_ERR("Error: Failed to set interface configuration %s\n", dev); @@ -781,11 +787,12 @@ static int gen_send_thread(void *arg) */ static void process_icmp_pkt(int thr, thread_args_t *thr_args, - odph_icmphdr_t *icmp) + uint8_t *_icmp) { uint64_t trecv; uint64_t tsend; uint64_t rtt_ms, rtt_us; + odph_icmphdr_t *icmp = (odph_icmphdr_t *)_icmp; if (icmp->type == ICMP_ECHOREPLY) { thr_args->counters.ctr_icmp_reply_rcv++; @@ -818,18 +825,12 @@ static void process_pkts(int thr, thread_args_t *thr_args, { odp_packet_t pkt; odp_packet_chksum_status_t csum_status; - char *buf; + uint32_t left, offset, i; odph_ipv4hdr_t *ip; - odph_icmphdr_t *icmp; - unsigned i; for (i = 0; i < len; ++i) { pkt = pkt_tbl[i]; - /* only ip pkts */ - if (!odp_packet_has_ipv4(pkt)) - continue; - csum_status = odp_packet_l3_chksum_status(pkt); if (csum_status == ODP_PACKET_CHKSUM_BAD) printf("L3 checksum error detected.\n"); @@ -842,20 +843,36 @@ static void process_pkts(int thr, thread_args_t *thr_args, if (odp_unlikely(odp_packet_has_error(pkt))) continue; + offset = odp_packet_l3_offset(pkt); + left = odp_packet_len(pkt) - offset; + + if (left < sizeof(odph_ipv4hdr_t)) + continue; + + ip = (odph_ipv4hdr_t *)((uint8_t *)odp_packet_data(pkt) + + offset); + + /* only ip pkts */ + if (ODPH_IPV4HDR_VER(ip->ver_ihl) != ODPH_IPV4) + continue; + thr_args->counters.ctr_pkt_rcv++; - buf = odp_packet_data(pkt); - ip = (odph_ipv4hdr_t *)(buf + odp_packet_l3_offset(pkt)); /* udp */ - if (ip->proto == ODPH_IPPROTO_UDP) + if (ip->proto == ODPH_IPPROTO_UDP) { thr_args->counters.ctr_udp_rcv++; + } else if (ip->proto == ODPH_IPPROTO_ICMPV4) { + uint32_t l3_size = ODPH_IPV4HDR_IHL(ip->ver_ihl) * 4; + + offset += l3_size; + left -= l3_size; - /* icmp */ - if (ip->proto == ODPH_IPPROTO_ICMPV4) { - icmp = (odph_icmphdr_t *)(buf + - odp_packet_l4_offset(pkt)); + if (left < sizeof(odph_icmphdr_t)) + continue; - process_icmp_pkt(thr, thr_args, icmp); + process_icmp_pkt(thr, thr_args, + (uint8_t *)odp_packet_data(pkt) + + offset); } } } |