From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 1D9E5A058A; Fri, 17 Apr 2020 15:14:56 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6986E1E88D; Fri, 17 Apr 2020 15:14:34 +0200 (CEST) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by dpdk.org (Postfix) with ESMTP id 6F1861E86B for ; Fri, 17 Apr 2020 15:14:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587129265; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NZSdG977qTfnuiifruli9FYJF14gnYd06tjHNBjdm0A=; b=BL2FZjzAd1ib1HvE884wHqcbmqwdNI3FcHnyHcdjb/fG96G7MHHrrjI0gEH1zfw1CkXkZ0 eF1PiJFjsvJww8AYD+gH8hEMeXVIwsdojXyT+5tn+D/xNnCUgoEZl6mRC9Cu8ElpUu/0VQ jVo6HWc2Xwh9kNeJqhYWpxFHW/YneEE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-159-z1AN7M46OLGYULNowf4SiQ-1; Fri, 17 Apr 2020 09:14:24 -0400 X-MC-Unique: z1AN7M46OLGYULNowf4SiQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DEB94100DFC9; Fri, 17 Apr 2020 13:14:22 +0000 (UTC) Received: from dhcp-25.97.bos.redhat.com (ovpn-116-136.phx2.redhat.com [10.3.116.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id CB0387E7FF; Fri, 17 Apr 2020 13:14:21 +0000 (UTC) From: Aaron Conole To: dev@dpdk.org Cc: Konstantin Ananyev , Pavan Nikhilesh , Bruce Richardson , David Marchand , Ferruh Yigit , Anatoly Burakov , Lukasz Wojciechowski Date: Fri, 17 Apr 2020 09:14:10 -0400 Message-Id: <20200417131410.1343135-4-aconole@redhat.com> In-Reply-To: <20200417131410.1343135-1-aconole@redhat.com> References: <20200415172547.1421587-1-aconole@redhat.com> <20200417131410.1343135-1-aconole@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Subject: [dpdk-dev] [PATCH v5 3/3] ipfrag: add unit test case X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Initial IP fragmentation unit test. Signed-off-by: Aaron Conole --- MAINTAINERS | 1 + app/test/meson.build | 2 + app/test/test_ipfrag.c | 272 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 275 insertions(+) create mode 100644 app/test/test_ipfrag.c diff --git a/MAINTAINERS b/MAINTAINERS index fe59f0224f..a77c7c17ce 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1228,6 +1228,7 @@ F: app/test/test_crc.c IP fragmentation & reassembly M: Konstantin Ananyev F: lib/librte_ip_frag/ +F: app/test/test_ipfrag.c F: doc/guides/prog_guide/ip_fragment_reassembly_lib.rst F: examples/ip_fragmentation/ F: doc/guides/sample_app_ug/ip_frag.rst diff --git a/app/test/meson.build b/app/test/meson.build index 04b59cffa4..4b3c3852a2 100644 --- a/app/test/meson.build +++ b/app/test/meson.build @@ -58,6 +58,7 @@ test_sources =3D files('commands.c', =09'test_hash_perf.c', =09'test_hash_readwrite_lf_perf.c', =09'test_interrupts.c', + 'test_ipfrag.c', =09'test_ipsec.c', =09'test_ipsec_sad.c', =09'test_kni.c', @@ -187,6 +188,7 @@ fast_tests =3D [ ['flow_classify_autotest', false], ['hash_autotest', true], ['interrupt_autotest', true], + ['ipfrag_autotest', false], ['logs_autotest', true], ['lpm_autotest', true], ['lpm6_autotest', true], diff --git a/app/test/test_ipfrag.c b/app/test/test_ipfrag.c new file mode 100644 index 0000000000..6a80581f0e --- /dev/null +++ b/app/test/test_ipfrag.c @@ -0,0 +1,272 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2020 Red Hat, Inc. + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "test.h" + +#define NUM_MBUFS 128 +#define BURST 32 + +static struct rte_mempool *pkt_pool, +=09=09=09 *direct_pool, +=09=09=09 *indirect_pool; + +static int +setup_buf_pool(void) +{ +=09if (!pkt_pool) +=09=09pkt_pool =3D rte_pktmbuf_pool_create("FRAG_MBUF_POOL", +=09=09=09=09=09=09 NUM_MBUFS, BURST, 0, +=09=09=09=09=09=09 RTE_MBUF_DEFAULT_BUF_SIZE, +=09=09=09=09=09=09 SOCKET_ID_ANY); +=09if (pkt_pool =3D=3D NULL) { +=09=09printf("%s: Error creating pkt mempool\n", __func__); +=09=09goto bad_setup; +=09} + +=09if (!direct_pool) +=09=09direct_pool =3D rte_pktmbuf_pool_create("FRAG_D_MBUF_POOL", +=09=09=09=09=09=09 NUM_MBUFS, BURST, 0, +=09=09=09=09=09=09 RTE_MBUF_DEFAULT_BUF_SIZE, +=09=09=09=09=09=09 SOCKET_ID_ANY); +=09if (!direct_pool) { +=09=09printf("%s: Error creating direct mempool\n", __func__); +=09=09goto bad_setup; +=09} + +=09if (!indirect_pool) +=09=09indirect_pool =3D rte_pktmbuf_pool_create("FRAG_I_MBUF_POOL", +=09=09=09=09=09=09=09NUM_MBUFS, BURST, 0, +=09=09=09=09=09=09=090, SOCKET_ID_ANY); +=09if (!indirect_pool) { +=09=09printf("%s: Error creating indirect mempool\n", __func__); +=09=09goto bad_setup; +=09} + +=09return TEST_SUCCESS; + +bad_setup: +=09if (pkt_pool) +=09=09rte_mempool_free(pkt_pool); +=09pkt_pool =3D NULL; + +=09if (direct_pool) +=09=09rte_mempool_free(direct_pool); +=09direct_pool =3D NULL; + +=09return TEST_FAILED; +} + +static int testsuite_setup(void) +{ +=09return setup_buf_pool(); +} + +static void testsuite_teardown(void) +{ +=09if (pkt_pool) +=09=09rte_mempool_free(pkt_pool); + +=09if (direct_pool) +=09=09rte_mempool_free(direct_pool); + +=09if (indirect_pool) +=09=09rte_mempool_free(indirect_pool); + +=09pkt_pool =3D NULL; +=09direct_pool =3D NULL; +=09indirect_pool =3D NULL; +} + +static int ut_setup(void) +{ +=09return TEST_SUCCESS; +} + +static void ut_teardown(void) +{ +} + +static void +v4_allocate_packet_of(struct rte_mbuf *b, int fill, size_t s, int df, +=09=09 uint8_t ttl, uint8_t proto, uint16_t pktid) +{ +=09/* Create a packet, 2k bytes long */ +=09b->data_off =3D 0; +=09char *data =3D rte_pktmbuf_mtod(b, char *); + +=09memset(data, fill, sizeof(struct rte_ipv4_hdr) + s); + +=09struct rte_ipv4_hdr *hdr =3D (struct rte_ipv4_hdr *)data; + +=09hdr->version_ihl =3D 0x45; /* standard IP header... */ +=09hdr->type_of_service =3D 0; +=09b->pkt_len =3D s + sizeof(struct rte_ipv4_hdr); +=09b->data_len =3D b->pkt_len; +=09hdr->total_length =3D rte_cpu_to_be_16(b->pkt_len); +=09hdr->packet_id =3D rte_cpu_to_be_16(pktid); +=09hdr->fragment_offset =3D 0; +=09if (df) +=09=09hdr->fragment_offset =3D rte_cpu_to_be_16(0x4000); + +=09if (!ttl) +=09=09ttl =3D 64; /* default to 64 */ + +=09if (!proto) +=09=09proto =3D 1; /* icmp */ + +=09hdr->time_to_live =3D ttl; +=09hdr->next_proto_id =3D proto; +=09hdr->hdr_checksum =3D 0; +=09hdr->src_addr =3D rte_cpu_to_be_32(0x8080808); +=09hdr->dst_addr =3D rte_cpu_to_be_32(0x8080404); +} + +static void +v6_allocate_packet_of(struct rte_mbuf *b, int fill, size_t s, uint8_t ttl, +=09=09 uint8_t proto, uint16_t pktid) +{ +=09/* Create a packet, 2k bytes long */ +=09b->data_off =3D 0; +=09char *data =3D rte_pktmbuf_mtod(b, char *); + +=09memset(data, fill, sizeof(struct rte_ipv6_hdr) + s); + +=09struct rte_ipv6_hdr *hdr =3D (struct rte_ipv6_hdr *)data; +=09b->pkt_len =3D s + sizeof(struct rte_ipv6_hdr); +=09b->data_len =3D b->pkt_len; + +=09/* basic v6 header */ +=09hdr->vtc_flow =3D rte_cpu_to_be_32(0x60 << 24 | pktid); +=09hdr->payload_len =3D rte_cpu_to_be_16(b->pkt_len); +=09hdr->proto =3D proto; +=09hdr->hop_limits =3D ttl; + +=09memset(hdr->src_addr, 0x08, sizeof(hdr->src_addr)); +=09memset(hdr->dst_addr, 0x04, sizeof(hdr->src_addr)); +} + +static inline void +test_free_fragments(struct rte_mbuf *mb[], uint32_t num) +{ +=09uint32_t i; +=09for (i =3D 0; i < num; i++) +=09=09rte_pktmbuf_free(mb[i]); +} + +static int +test_ip_frag(void) +{ +=09static const uint16_t RND_ID =3D UINT16_MAX; +=09int result =3D TEST_SUCCESS; +=09size_t i; + +=09struct test_ip_frags { +=09=09int ipv; +=09=09size_t mtu_size; +=09=09size_t pkt_size; +=09=09int set_df; +=09=09uint8_t ttl; +=09=09uint8_t proto; +=09=09uint16_t pkt_id; +=09=09int expected_frags; +=09} tests[] =3D { +=09=09 {4, 1280, 1400, 0, 64, IPPROTO_ICMP, RND_ID, 2}, +=09=09 {4, 1280, 1400, 0, 64, IPPROTO_ICMP, 0, 2}, +=09=09 {4, 600, 1400, 0, 64, IPPROTO_ICMP, RND_ID, 3}, +=09=09 {4, 4, 1400, 0, 64, IPPROTO_ICMP, RND_ID, -EINVAL}, +=09=09 {4, 600, 1400, 1, 64, IPPROTO_ICMP, RND_ID, -ENOTSUP}, +=09=09 {4, 600, 1400, 0, 0, IPPROTO_ICMP, RND_ID, 3}, + +=09=09 {6, 1280, 1400, 0, 64, IPPROTO_ICMP, RND_ID, 2}, +=09=09 {6, 1300, 1400, 0, 64, IPPROTO_ICMP, RND_ID, 2}, +=09=09 {6, 4, 1400, 0, 64, IPPROTO_ICMP, RND_ID, -EINVAL}, +=09=09 {6, 1300, 1400, 0, 0, IPPROTO_ICMP, RND_ID, 2}, +=09}; + +=09for (i =3D 0; i < RTE_DIM(tests); i++) { +=09=09int32_t len =3D 0; +=09=09uint16_t pktid =3D tests[i].pkt_id; +=09=09struct rte_mbuf *pkts_out[BURST]; +=09=09struct rte_mbuf *b =3D rte_pktmbuf_alloc(pkt_pool); + +=09=09RTE_TEST_ASSERT_NOT_EQUAL(b, NULL, +=09=09=09=09=09 "Failed to allocate pkt."); + +=09=09if (tests[i].pkt_id =3D=3D RND_ID) +=09=09=09pktid =3D rte_rand_max(UINT16_MAX); + +=09=09if (tests[i].ipv =3D=3D 4) { +=09=09=09v4_allocate_packet_of(b, 0x41414141, +=09=09=09=09=09 tests[i].pkt_size, +=09=09=09=09=09 tests[i].set_df, +=09=09=09=09=09 tests[i].ttl, +=09=09=09=09=09 tests[i].proto, +=09=09=09=09=09 pktid); +=09=09} else if (tests[i].ipv =3D=3D 6) { +=09=09=09v6_allocate_packet_of(b, 0x41414141, +=09=09=09=09=09 tests[i].pkt_size, +=09=09=09=09=09 tests[i].ttl, +=09=09=09=09=09 tests[i].proto, +=09=09=09=09=09 pktid); +=09=09} + +=09=09if (tests[i].ipv =3D=3D 4) +=09=09=09len =3D rte_ipv4_fragment_packet(b, pkts_out, BURST, +=09=09=09=09=09=09 tests[i].mtu_size, +=09=09=09=09=09=09 direct_pool, +=09=09=09=09=09=09 indirect_pool); +=09=09else if (tests[i].ipv =3D=3D 6) +=09=09=09len =3D rte_ipv6_fragment_packet(b, pkts_out, BURST, +=09=09=09=09=09=09 tests[i].mtu_size, +=09=09=09=09=09=09 direct_pool, +=09=09=09=09=09=09 indirect_pool); + +=09=09rte_pktmbuf_free(b); + +=09=09if (len > 0) +=09=09=09test_free_fragments(pkts_out, len); + +=09=09printf("%zd: checking %d with %d\n", i, len, +=09=09 tests[i].expected_frags); +=09=09RTE_TEST_ASSERT_EQUAL(len, tests[i].expected_frags, +=09=09=09=09 "Failed case %zd.\n", i); + +=09} + +=09return result; +} + +static struct unit_test_suite ipfrag_testsuite =3D { +=09.suite_name =3D "IP Frag Unit Test Suite", +=09.setup =3D testsuite_setup, +=09.teardown =3D testsuite_teardown, +=09.unit_test_cases =3D { +=09=09TEST_CASE_ST(ut_setup, ut_teardown, +=09=09=09 test_ip_frag), + +=09=09TEST_CASES_END() /**< NULL terminate unit test array */ +=09} +}; + +static int +test_ipfrag(void) +{ +=09rte_log_set_global_level(RTE_LOG_DEBUG); +=09rte_log_set_level(RTE_LOGTYPE_EAL, RTE_LOG_DEBUG); + +=09return unit_test_suite_runner(&ipfrag_testsuite); +} + +REGISTER_TEST_COMMAND(ipfrag_autotest, test_ipfrag); --=20 2.25.1