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 A81FBA0563; Wed, 15 Apr 2020 19:26:21 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6AD0A1D984; Wed, 15 Apr 2020 19:26:10 +0200 (CEST) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by dpdk.org (Postfix) with ESMTP id 8082B1D929 for ; Wed, 15 Apr 2020 19:26:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586971561; 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=VTxoRDBsvWXXCVvFndVpWFN4oHYiGDq4a7bKgkFO3O4=; b=X69JExszP3Y1++GCvHT9dB5NzvZ2uFNCYGoIpH1LkJj/JsYJ096OlbqpeRXoZSl43ASGiz neTduqMn4INzLWNnkIJ70db/aTqwCgEMwyXchrX6E2xqZ7td0oTa45L9G8EveUMwCnqj4L 6OtB3erQaPAs68wY/cxcMsm/fTxY4p4= 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-61--MQj-_NxNiK4cKK94IIpQA-1; Wed, 15 Apr 2020 13:25:57 -0400 X-MC-Unique: -MQj-_NxNiK4cKK94IIpQA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 008131005509; Wed, 15 Apr 2020 17:25:56 +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 0670410027B6; Wed, 15 Apr 2020 17:25:54 +0000 (UTC) From: Aaron Conole To: dev@dpdk.org Cc: Konstantin Ananyev , Pavan Nikhilesh , Bruce Richardson , David Marchand , Ferruh Yigit , Anatoly Burakov Date: Wed, 15 Apr 2020 13:25:47 -0400 Message-Id: <20200415172547.1421587-4-aconole@redhat.com> In-Reply-To: <20200415172547.1421587-1-aconole@redhat.com> References: <20200401183917.3620845-1-aconole@redhat.com> <20200415172547.1421587-1-aconole@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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 v4 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 | 276 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 279 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..6a13e334d5 --- /dev/null +++ b/app/test/test_ipfrag.c @@ -0,0 +1,276 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2020 Red Hat, Inc. + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "test.h" + +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +#endif + +static struct rte_mempool *pkt_pool, +=09=09=09 *direct_pool, +=09=09=09 *indirect_pool; + +static int +setup_buf_pool(void) +{ +#define NUM_MBUFS (128) +#define BURST 32 + +=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 0; + +bad_setup: +=09if (pkt_pool) +=09=09rte_mempool_free(pkt_pool); + +=09if (direct_pool) +=09=09rte_mempool_free(direct_pool); + +=09return TEST_FAILED; +} + +static int testsuite_setup(void) +{ +=09if (setup_buf_pool()) +=09=09return TEST_FAILED; +=09return TEST_SUCCESS; +} + +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; +} + +static int ut_setup(void) +{ +=09return TEST_SUCCESS; +} + +static void ut_teardown(void) +{ +} + +static int +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_32(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); + +=09return 0; +} + +static int +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)); + +=09return 0; +} + +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) +{ +=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=09int ttl; +=09=09uint8_t proto; +=09=09int pkt_id; +=09=09int expected_frags; +=09} tests[] =3D { +=09=09 {4, 1280, 1400, 0, 64, IPPROTO_ICMP, -1, 2}, +=09=09 {4, 1280, 1400, 0, 64, IPPROTO_ICMP, 0, 2}, +=09=09 {4, 600, 1400, 0, 64, IPPROTO_ICMP, -1, 3}, +=09=09 {4, 4, 1400, 0, 64, IPPROTO_ICMP, -1, -EINVAL}, +=09=09 {4, 600, 1400, 1, 64, IPPROTO_ICMP, -1, -ENOTSUP}, +=09=09 {4, 600, 1400, 0, 0, IPPROTO_ICMP, -1, 3}, + +=09=09 {6, 1280, 1400, 0, 64, IPPROTO_ICMP, -1, 2}, +=09=09 {6, 1300, 1400, 0, 64, IPPROTO_ICMP, -1, 2}, +=09=09 {6, 4, 1400, 0, 64, IPPROTO_ICMP, -1, -EINVAL}, +=09=09 {6, 1300, 1400, 0, 0, IPPROTO_ICMP, -1, 2}, +=09}; + +=09for (i =3D 0; i < ARRAY_SIZE(tests); i++) { +=09=09int32_t len; +=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=09if (!b) +=09=09=09return TEST_FAILED; /* Serious error.. abort here */ + +=09=09if (tests[i].pkt_id =3D=3D -1) +=09=09=09pktid =3D rte_rand_max(UINT16_MAX); + +=09=09if (tests[i].ipv =3D=3D 4) { +=09=09=09if (v4_allocate_packet_of(b, 0x41414141, +=09=09=09=09=09=09 tests[i].pkt_size, +=09=09=09=09=09=09 tests[i].set_df, +=09=09=09=09=09=09 tests[i].ttl, +=09=09=09=09=09=09 tests[i].proto, +=09=09=09=09=09=09 pktid)) +=09=09=09=09result =3D TEST_FAILED; +=09=09} else if (tests[i].ipv =3D=3D 6) { +=09=09=09if (v6_allocate_packet_of(b, 0x41414141, +=09=09=09=09=09=09 tests[i].pkt_size, +=09=09=09=09=09=09 tests[i].ttl, +=09=09=09=09=09=09 tests[i].proto, +=09=09=09=09=09=09 pktid)) +=09=09=09=09result =3D TEST_FAILED; +=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 +=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("%d: checking %d with %d\n", (int)i, len, +=09=09 (int)tests[i].expected_frags); +=09=09RTE_TEST_ASSERT_EQUAL(len, tests[i].expected_frags, +=09=09=09=09 "Failed case %u\n", (unsigned int)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) +{ +=09return unit_test_suite_runner(&ipfrag_testsuite); +} + +REGISTER_TEST_COMMAND(ipfrag_autotest, test_ipfrag); --=20 2.25.1