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 7CAA5A058A; Fri, 17 Apr 2020 16:14:10 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 3F3041E8D0; Fri, 17 Apr 2020 16:14:10 +0200 (CEST) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id AE7F91DC69 for ; Fri, 17 Apr 2020 16:14:08 +0200 (CEST) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200417141407euoutp0252765c98665c08f592ae3a3aa223d753~GoOp1MnPR1815418154euoutp02i for ; Fri, 17 Apr 2020 14:14:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200417141407euoutp0252765c98665c08f592ae3a3aa223d753~GoOp1MnPR1815418154euoutp02i DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1587132847; bh=L/c547q4rrzLpIlmcObde7OiheJwm+oXXxb8xMEAjzg=; h=Subject:To:Cc:From:Date:In-Reply-To:References:From; b=g9TbVu8v6oOz3YrKRylej8MIAPdxHqlobFf85W52wP7MAk3Q/6m/9QT7ibzqsS21h REM62kSBVCmWJR9H+mJqRo01FKmfwXPANA/NIy/aF8WC6+coYRFWzF3NRL7w2ytWsq GRyUXK3ErMSOfpqDlrbZ/crW9lRlc6lZQ/s3sz2I= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200417141407eucas1p292d71dbaae8c4693e905482954f71e39~GoOpo7uIc0733707337eucas1p2B; Fri, 17 Apr 2020 14:14:07 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 04.0D.61286.FA9B99E5; Fri, 17 Apr 2020 15:14:07 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200417141406eucas1p28f11bdfd3a790ab9ab228c6c58ba41ef~GoOpUtNim0734007340eucas1p2A; Fri, 17 Apr 2020 14:14:06 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200417141406eusmtrp2d8ea92922df4dd59752d33d11268fa75~GoOpT-_x80423804238eusmtrp2n; Fri, 17 Apr 2020 14:14:06 +0000 (GMT) X-AuditID: cbfec7f2-f0bff7000001ef66-26-5e99b9afc5e3 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 7E.73.08375.EA9B99E5; Fri, 17 Apr 2020 15:14:06 +0100 (BST) Received: from [106.210.88.70] (unknown [106.210.88.70]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20200417141406eusmtip2a15533ab8e21f5a96ce83231a68d311a~GoOogLCew0111701117eusmtip2M; Fri, 17 Apr 2020 14:14:06 +0000 (GMT) To: Aaron Conole , dev@dpdk.org Cc: Konstantin Ananyev , Pavan Nikhilesh , Bruce Richardson , David Marchand , Ferruh Yigit , Anatoly Burakov From: Lukasz Wojciechowski Message-ID: <288587c3-11db-ef39-a599-a35c371ae2ce@partner.samsung.com> Date: Fri, 17 Apr 2020 16:14:04 +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: <20200417131410.1343135-4-aconole@redhat.com> Content-Transfer-Encoding: 8bit Content-Language: pl X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrFKsWRmVeSWpSXmKPExsWy7djPc7rrd86MM3jcwG/x680DdotH9xYz W9xYZW+xfUUXm8W7T9uZLO7sPc1u8f7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l7G 9SkLGAueelW8frqEqYHxg0UXIyeHhICJxJvpi5m7GLk4hASWMkrc+fkRyOEASshIfLgkAFEj LPHnWhcbiC0k8JpRYstpGRBbWMBMYkL7TWYQW0TAWGLHh/NMIHOYBWYxSWx8+RNq6FtGiXsH JzKCVLEJ2EocmfmVFcTmFXCTaPy2gB1kGYuAqsTrH/4gpqhArETLRU2ICkGJkzOfsIDYnAJW Egu/zwG7gRlo77zND5khbHmJ5q2zoWwRiRuPWhgnMArNQtI+C0nLLCQts5C0LGBkWcUoklpa nJueW2yoV5yYW1yal66XnJ+7iREYcduO/dy8g/HSxuBDjAIcjEo8vAY9M+OEWBPLiitzDzFK cDArifAedAMK8aYkVlalFuXHF5XmpBYfYjQFem0is5Rocj4wGeSVxBuaGppbWBqaG5sbm1ko ifN2CByMERJITyxJzU5NLUgtgulj4uCUamAsUru7e2s/a6P9/WA9IxauqqRWafGaWxPCQmyf KDzXCAh+k2Vtf63Y/rQh8/6P/Be2/b5zcpndWSuplt5fTxTsllkdZHy3I/DarsRC68MFL0sK pljFT1c0qOZ6f0HuxBfex0fXFLu+bHky5cR6hVtuP8O+zPhd7SUuXqC6RjTg8az59cIzglYr sRRnJBpqMRcVJwIAsz0ZEM4CAAA= X-CMS-MailID: 20200417141406eucas1p28f11bdfd3a790ab9ab228c6c58ba41ef X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20200417131431eucas1p16f920a14abfb3a5ad851e39258600214 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200417131431eucas1p16f920a14abfb3a5ad851e39258600214 References: <20200415172547.1421587-1-aconole@redhat.com> <20200417131410.1343135-1-aconole@redhat.com> <20200417131410.1343135-4-aconole@redhat.com> Subject: Re: [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" W dniu 17.04.2020 o 15:14, 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 | 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 = 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..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, > + *direct_pool, > + *indirect_pool; > + > +static int > +setup_buf_pool(void) > +{ > + if (!pkt_pool) > + 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; > + } > + > + if (!direct_pool) > + 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) { > + printf("%s: Error creating direct mempool\n", __func__); > + goto bad_setup; > + } > + > + if (!indirect_pool) > + indirect_pool = rte_pktmbuf_pool_create("FRAG_I_MBUF_POOL", > + NUM_MBUFS, BURST, 0, > + 0, SOCKET_ID_ANY); > + if (!indirect_pool) { > + printf("%s: Error creating indirect mempool\n", __func__); > + goto bad_setup; > + } > + > + return TEST_SUCCESS; > + > +bad_setup: > + if (pkt_pool) > + rte_mempool_free(pkt_pool); > + pkt_pool = NULL; > + > + if (direct_pool) > + 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) > +{ > + if (pkt_pool) > + rte_mempool_free(pkt_pool); > + > + if (direct_pool) > + rte_mempool_free(direct_pool); > + > + if (indirect_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); Perfect! Reviewed-by: Lukasz Wojciechowski Tested-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