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 BFE1CA0597; Tue, 21 Apr 2020 13:03:32 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id AF0DC1D94B; Tue, 21 Apr 2020 13:03:31 +0200 (CEST) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id 0BEC51D903 for ; Tue, 21 Apr 2020 13:03:29 +0200 (CEST) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200421110329euoutp02145d29fb35dfab17640d03dd7089f3db~H0NWBEEhB0113901139euoutp02a for ; Tue, 21 Apr 2020 11:03:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200421110329euoutp02145d29fb35dfab17640d03dd7089f3db~H0NWBEEhB0113901139euoutp02a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1587467009; bh=wXnm86my1Vru1FSlU+F8h87uTQTI0S37EtSIU5di4lQ=; h=Subject:To:Cc:From:Date:In-Reply-To:References:From; b=dC5jFIc71VJuj2r7oseeCMe5sDGjH9XaK3wEt4nn5yD+jmAhmgBMq/yj7g1cWiB0u Tb174u4pqoZflMIyAxofGytfsN7Cf7zOO6Nt1is9lY8tFPd0Pp/IroHtyhxj0wBWaJ 8cQO6WZDKZaTzeWjtEO2ZzesUPUovbfmsgdUVUpk= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200421110328eucas1p2c8311b39356f2e199c91bb3b79fd4a66~H0NV56kYj3249332493eucas1p2m; Tue, 21 Apr 2020 11:03:28 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id FC.0D.61286.003DE9E5; Tue, 21 Apr 2020 12:03:28 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200421110328eucas1p11bb5646227e4543d7ec3e91b79fcd7da~H0NVmjl9G1782817828eucas1p13; Tue, 21 Apr 2020 11:03:28 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200421110328eusmtrp2a91a19490857df4220257c556f538e6e~H0NVl6zCW0858908589eusmtrp2P; Tue, 21 Apr 2020 11:03:28 +0000 (GMT) X-AuditID: cbfec7f2-f0bff7000001ef66-74-5e9ed300eb94 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id EB.21.08375.003DE9E5; Tue, 21 Apr 2020 12:03:28 +0100 (BST) Received: from [106.210.88.70] (unknown [106.210.88.70]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200421110327eusmtip14dcf919855126271f3bb7c48605f24f0~H0NU6ZLcN0752207522eusmtip1T; Tue, 21 Apr 2020 11:03:27 +0000 (GMT) To: Aaron Conole , dev@dpdk.org Cc: Pavan Nikhilesh , Bruce Richardson , David Marchand , Ferruh Yigit , Anatoly Burakov From: Lukasz Wojciechowski Message-ID: <86d40d5e-80f7-11c1-815d-e1435a175270@partner.samsung.com> Date: Tue, 21 Apr 2020 13:03:26 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20200420192523.2546909-4-aconole@redhat.com> Content-Transfer-Encoding: 8bit Content-Language: pl X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrKKsWRmVeSWpSXmKPExsWy7djPc7oMl+fFGVz4YGrx680DdotH9xYz W9xYZW+xfUUXm8W7T9uZLO7sPc1ucbznI4sDu8ev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BsZmiy5GTg4JAROJd1872LsYuTiEBJYySixYtYWli5EDKCEj8eGSAESNsMSfa11s EDWvGSWePWtnBkkIC5hJHGiZwQZiiwgYS+z4cJ4JpIhZ4CmjROetfawQHW8ZJe5OOw3WwSZg K3Fk5ldWEJtXwE3i/Z3dzCDbWARUJQ4+qQUxRQViJVouakJUCEqcnPmEBcTmFLCSWPrxIZjN DLR33uaHzBC2vETz1tlQtojEjUctjBMYhWYhaZ+FpGUWkpZZSFoWMLKsYhRJLS3OTc8tNtQr TswtLs1L10vOz93ECIyzbcd+bt7BeGlj8CFGAQ5GJR7eG+fnxQmxJpYVV+YeYpTgYFYS4bXQ AgrxpiRWVqUW5ccXleakFh9iNAV6bSKzlGhyPjAF5JXEG5oamltYGpobmxubWSiJ83YIHIwR EkhPLEnNTk0tSC2C6WPi4JRqYJQUvXs4YdqyRW18fetvdDY/TtgvyjefZ5N3a4Fc/my5O3uP RHRFH3jLYLl3f1hczR6TLmGlmnOlvn+3MfYbf5IUq8rP2ddoMSO+T9S+q0LoxKPtQRuV+k99 s55w9r7v7qrz2Tdf3rERShew2h3yod36qxNXnnz05103MiP5v08Q3VZ8xFfslxJLcUaioRZz UXEiAFNmS0PJAgAA X-CMS-MailID: 20200421110328eucas1p11bb5646227e4543d7ec3e91b79fcd7da X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20200420192543eucas1p1103b98467e9349c5c6bea5ba8f2b45d6 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200420192543eucas1p1103b98467e9349c5c6bea5ba8f2b45d6 References: <20200417131410.1343135-1-aconole@redhat.com> <20200420192523.2546909-1-aconole@redhat.com> <20200420192523.2546909-4-aconole@redhat.com> Subject: Re: [dpdk-dev] [PATCH v6 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" W dniu 20.04.2020 o 21:25, Aaron Conole pisze: > Initial IP fragmentation unit test. > > Signed-off-by: Aaron Conole > --- > MAINTAINERS | 1 + > app/test/meson.build | 2 + > app/test/test_ipfrag.c | 262 +++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 265 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 = files('commands.c', > 'test_hash_perf.c', > 'test_hash_readwrite_lf_perf.c', > 'test_interrupts.c', > + 'test_ipfrag.c', > 'test_ipsec.c', > 'test_ipsec_sad.c', > 'test_kni.c', > @@ -187,6 +188,7 @@ fast_tests = [ > ['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..da8c212f92 > --- /dev/null > +++ b/app/test/test_ipfrag.c > @@ -0,0 +1,262 @@ > +/* 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, > + *direct_pool, > + *indirect_pool; > + > +static int > +setup_buf_pool(void) > +{ > + pkt_pool = rte_pktmbuf_pool_create("FRAG_MBUF_POOL", > + NUM_MBUFS, BURST, 0, > + RTE_MBUF_DEFAULT_BUF_SIZE, > + SOCKET_ID_ANY); > + if (pkt_pool == NULL) { > + printf("%s: Error creating pkt mempool\n", __func__); > + goto bad_setup; > + } > + > + direct_pool = rte_pktmbuf_pool_create("FRAG_D_MBUF_POOL", > + NUM_MBUFS, BURST, 0, > + RTE_MBUF_DEFAULT_BUF_SIZE, > + SOCKET_ID_ANY); > + if (direct_pool == NULL) { > + printf("%s: Error creating direct mempool\n", __func__); > + goto bad_setup; > + } > + > + indirect_pool = rte_pktmbuf_pool_create("FRAG_I_MBUF_POOL", > + NUM_MBUFS, BURST, 0, > + 0, SOCKET_ID_ANY); > + if (indirect_pool == NULL) { > + printf("%s: Error creating indirect mempool\n", __func__); > + goto bad_setup; > + } > + > + return TEST_SUCCESS; > + > +bad_setup: > + rte_mempool_free(pkt_pool); > + pkt_pool = NULL; > + > + rte_mempool_free(direct_pool); > + direct_pool = NULL; > + > + return TEST_FAILED; > +} > + > +static int testsuite_setup(void) > +{ > + return setup_buf_pool(); > +} > + > +static void testsuite_teardown(void) > +{ > + rte_mempool_free(pkt_pool); > + rte_mempool_free(direct_pool); > + rte_mempool_free(indirect_pool); > + > + pkt_pool = NULL; > + direct_pool = NULL; > + indirect_pool = NULL; > +} > + > +static int ut_setup(void) > +{ > + return TEST_SUCCESS; > +} > + > +static void ut_teardown(void) > +{ > +} > + > +static void > +v4_allocate_packet_of(struct rte_mbuf *b, int fill, size_t s, int df, > + uint8_t ttl, uint8_t proto, uint16_t pktid) > +{ > + /* Create a packet, 2k bytes long */ > + b->data_off = 0; > + char *data = rte_pktmbuf_mtod(b, char *); > + > + memset(data, fill, sizeof(struct rte_ipv4_hdr) + s); > + > + struct rte_ipv4_hdr *hdr = (struct rte_ipv4_hdr *)data; > + > + hdr->version_ihl = 0x45; /* standard IP header... */ > + hdr->type_of_service = 0; > + b->pkt_len = s + sizeof(struct rte_ipv4_hdr); > + b->data_len = b->pkt_len; > + hdr->total_length = rte_cpu_to_be_16(b->pkt_len); > + hdr->packet_id = rte_cpu_to_be_16(pktid); > + hdr->fragment_offset = 0; > + if (df) > + hdr->fragment_offset = rte_cpu_to_be_16(0x4000); > + > + if (!ttl) > + ttl = 64; /* default to 64 */ > + > + if (!proto) > + proto = 1; /* icmp */ > + > + hdr->time_to_live = ttl; > + hdr->next_proto_id = proto; > + hdr->hdr_checksum = 0; > + hdr->src_addr = rte_cpu_to_be_32(0x8080808); > + hdr->dst_addr = rte_cpu_to_be_32(0x8080404); > +} > + > +static void > +v6_allocate_packet_of(struct rte_mbuf *b, int fill, size_t s, uint8_t ttl, > + uint8_t proto, uint16_t pktid) > +{ > + /* Create a packet, 2k bytes long */ > + b->data_off = 0; > + char *data = rte_pktmbuf_mtod(b, char *); > + > + memset(data, fill, sizeof(struct rte_ipv6_hdr) + s); > + > + struct rte_ipv6_hdr *hdr = (struct rte_ipv6_hdr *)data; > + b->pkt_len = s + sizeof(struct rte_ipv6_hdr); > + b->data_len = b->pkt_len; > + > + /* basic v6 header */ > + hdr->vtc_flow = rte_cpu_to_be_32(0x60 << 24 | pktid); > + hdr->payload_len = rte_cpu_to_be_16(b->pkt_len); > + hdr->proto = proto; > + hdr->hop_limits = ttl; > + > + memset(hdr->src_addr, 0x08, sizeof(hdr->src_addr)); > + memset(hdr->dst_addr, 0x04, sizeof(hdr->src_addr)); > +} > + > +static inline void > +test_free_fragments(struct rte_mbuf *mb[], uint32_t num) > +{ > + uint32_t i; > + for (i = 0; i < num; i++) > + rte_pktmbuf_free(mb[i]); > +} > + > +static int > +test_ip_frag(void) > +{ > + static const uint16_t RND_ID = UINT16_MAX; > + int result = TEST_SUCCESS; > + size_t i; > + > + struct test_ip_frags { > + int ipv; > + size_t mtu_size; > + size_t pkt_size; > + int set_df; > + uint8_t ttl; > + uint8_t proto; > + uint16_t pkt_id; > + int expected_frags; > + } tests[] = { > + {4, 1280, 1400, 0, 64, IPPROTO_ICMP, RND_ID, 2}, > + {4, 1280, 1400, 0, 64, IPPROTO_ICMP, 0, 2}, > + {4, 600, 1400, 0, 64, IPPROTO_ICMP, RND_ID, 3}, > + {4, 4, 1400, 0, 64, IPPROTO_ICMP, RND_ID, -EINVAL}, > + {4, 600, 1400, 1, 64, IPPROTO_ICMP, RND_ID, -ENOTSUP}, > + {4, 600, 1400, 0, 0, IPPROTO_ICMP, RND_ID, 3}, > + > + {6, 1280, 1400, 0, 64, IPPROTO_ICMP, RND_ID, 2}, > + {6, 1300, 1400, 0, 64, IPPROTO_ICMP, RND_ID, 2}, > + {6, 4, 1400, 0, 64, IPPROTO_ICMP, RND_ID, -EINVAL}, > + {6, 1300, 1400, 0, 0, IPPROTO_ICMP, RND_ID, 2}, > + }; > + > + for (i = 0; i < RTE_DIM(tests); i++) { > + int32_t len = 0; > + uint16_t pktid = tests[i].pkt_id; > + struct rte_mbuf *pkts_out[BURST]; > + struct rte_mbuf *b = rte_pktmbuf_alloc(pkt_pool); > + > + RTE_TEST_ASSERT_NOT_EQUAL(b, NULL, > + "Failed to allocate pkt."); > + > + if (tests[i].pkt_id == RND_ID) > + pktid = rte_rand_max(UINT16_MAX); > + > + if (tests[i].ipv == 4) { > + v4_allocate_packet_of(b, 0x41414141, > + tests[i].pkt_size, > + tests[i].set_df, > + tests[i].ttl, > + tests[i].proto, > + pktid); > + } else if (tests[i].ipv == 6) { > + v6_allocate_packet_of(b, 0x41414141, > + tests[i].pkt_size, > + tests[i].ttl, > + tests[i].proto, > + pktid); > + } > + > + if (tests[i].ipv == 4) > + len = rte_ipv4_fragment_packet(b, pkts_out, BURST, > + tests[i].mtu_size, > + direct_pool, > + indirect_pool); > + else if (tests[i].ipv == 6) > + len = rte_ipv6_fragment_packet(b, pkts_out, BURST, > + tests[i].mtu_size, > + direct_pool, > + indirect_pool); > + > + rte_pktmbuf_free(b); > + > + if (len > 0) > + test_free_fragments(pkts_out, len); > + > + printf("%zd: checking %d with %d\n", i, len, > + tests[i].expected_frags); > + RTE_TEST_ASSERT_EQUAL(len, tests[i].expected_frags, > + "Failed case %zd.\n", i); > + > + } > + > + return result; > +} > + > +static struct unit_test_suite ipfrag_testsuite = { > + .suite_name = "IP Frag Unit Test Suite", > + .setup = testsuite_setup, > + .teardown = testsuite_teardown, > + .unit_test_cases = { > + TEST_CASE_ST(ut_setup, ut_teardown, > + test_ip_frag), > + > + TEST_CASES_END() /**< NULL terminate unit test array */ > + } > +}; > + > +static int > +test_ipfrag(void) > +{ > + rte_log_set_global_level(RTE_LOG_DEBUG); > + rte_log_set_level(RTE_LOGTYPE_EAL, RTE_LOG_DEBUG); > + > + return unit_test_suite_runner(&ipfrag_testsuite); > +} > + > +REGISTER_TEST_COMMAND(ipfrag_autotest, test_ipfrag); Stiil works and lloks good to me. Tested-by: Lukasz Wojciechowski Reviewed-by: Lukasz Wojciechowski -- Lukasz Wojciechowski Principal Software Engineer Samsung R&D Institute Poland Samsung Electronics Office +48 22 377 88 25 l.wojciechow@partner.samsung.com