From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 242F2A0C45; Mon, 25 Oct 2021 09:59:41 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 920C8407FF; Mon, 25 Oct 2021 09:59:40 +0200 (CEST) Received: from m12-16.163.com (m12-16.163.com [220.181.12.16]) by mails.dpdk.org (Postfix) with ESMTP id 5CAB24003E for ; Mon, 25 Oct 2021 09:59:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=sLLEn226Oermf0Koog yXiUvlhAfxb0lnifdLJdOagjQ=; b=gCggdgZfuOgErA6ATM3ZRdo0+Zf1h6vRwB b7z5jppBl4cezWTvS+cX+t8dZ+6sl4ad/y/RAkn8pvcUghHsYhqdzH/E8QInlqHn Njlkn/gN7MbwEBCivvn0vgBQs2VXfRWEPoYA+jCmKvYaAHYUoj2sp7aTvnur4V5b 6fPRkJ2O8= Received: from bogon.localdomain (unknown [36.112.33.106]) by smtp12 (Coremail) with SMTP id EMCowABH8JLPY3ZhBcucFQ--.34S2; Mon, 25 Oct 2021 15:59:36 +0800 (CST) From: huichao cai To: dev@dpdk.org Cc: konstantin.ananyev@intel.com Date: Mon, 25 Oct 2021 15:58:59 +0800 Message-Id: <1635148739-61415-1-git-send-email-chcchc88@163.com> X-Mailer: git-send-email 1.8.3.1 X-CM-TRANSID: EMCowABH8JLPY3ZhBcucFQ--.34S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxCF45ZF1rCFW8ZFW8JryfXrb_yoW7Gry7p3 sxt3s0kws3XFnrX3Z3Xrn09r4rGws7KrnFg3sxCr1Fyay2vr48tayDKFyIgr15Kry8A34f ZasYvayagwnFkw7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j-VysUUUUU= X-Originating-IP: [36.112.33.106] X-CM-SenderInfo: pfkfuxrfyyqiywtou0bp/1tbitxA3F1aELjcD8wAAs8 Subject: [dpdk-dev] [PATCH] test/ipfrag: add test content to the test unit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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" Add the test content of the fragment_offset(offset and MF) to the test_ip_frag function. Add test data for a fragment that is not the last fragment. Signed-off-by: huichao cai --- app/test/test_ipfrag.c | 95 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 79 insertions(+), 16 deletions(-) diff --git a/app/test/test_ipfrag.c b/app/test/test_ipfrag.c index da8c212..1ced25a 100644 --- a/app/test/test_ipfrag.c +++ b/app/test/test_ipfrag.c @@ -89,12 +89,14 @@ static void ut_teardown(void) } static void -v4_allocate_packet_of(struct rte_mbuf *b, int fill, size_t s, int df, +v4_allocate_packet_of(struct rte_mbuf *b, int fill, + size_t s, int df, uint8_t mf, uint16_t off, 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 *); + rte_be16_t fragment_offset = 0; /**< fragmentation offset */ memset(data, fill, sizeof(struct rte_ipv4_hdr) + s); @@ -106,9 +108,17 @@ static void ut_teardown(void) 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); + fragment_offset |= 0x4000; + + if (mf) + fragment_offset |= 0x2000; + + if (off) + fragment_offset |= off; + + hdr->fragment_offset = rte_cpu_to_be_16(fragment_offset); if (!ttl) ttl = 64; /* default to 64 */ @@ -155,38 +165,73 @@ static void ut_teardown(void) rte_pktmbuf_free(mb[i]); } +static inline void +test_get_offset(struct rte_mbuf **mb, int32_t len, + uint16_t *offset, int ipv) +{ + int32_t i; + + for (i = 0; i < len; i++) { + if (ipv == 4) { + struct rte_ipv4_hdr *iph = + rte_pktmbuf_mtod(mb[i], struct rte_ipv4_hdr *); + offset[i] = iph->fragment_offset; + } else if (ipv == 6) { + struct ipv6_extension_fragment *fh = + rte_pktmbuf_mtod_offset( + mb[i], + struct ipv6_extension_fragment *, + sizeof(struct rte_ipv6_hdr)); + offset[i] = fh->frag_data; + } + } +} + static int test_ip_frag(void) { static const uint16_t RND_ID = UINT16_MAX; int result = TEST_SUCCESS; - size_t i; + size_t i, j; struct test_ip_frags { int ipv; size_t mtu_size; size_t pkt_size; int set_df; + uint8_t set_mf; + uint16_t set_of; uint8_t ttl; uint8_t proto; uint16_t pkt_id; int expected_frags; + uint16_t expected_fragment_offset[BURST]; } 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}, + {4, 1280, 1400, 0, 0, 0, 64, IPPROTO_ICMP, RND_ID, 2, + {0x2000, 0x009D}}, + {4, 1280, 1400, 0, 0, 0, 64, IPPROTO_ICMP, 0, 2, + {0x2000, 0x009D}}, + {4, 600, 1400, 0, 0, 0, 64, IPPROTO_ICMP, RND_ID, 3, + {0x2000, 0x2048, 0x0090}}, + {4, 4, 1400, 0, 0, 0, 64, IPPROTO_ICMP, RND_ID, -EINVAL}, + {4, 600, 1400, 1, 0, 0, 64, IPPROTO_ICMP, RND_ID, -ENOTSUP}, + {4, 600, 1400, 0, 0, 0, 0, IPPROTO_ICMP, RND_ID, 3, + {0x2000, 0x2048, 0x0090}}, + {4, 68, 104, 0, 1, 13, 0, IPPROTO_ICMP, RND_ID, 3, + {0x200D, 0x2013, 0x2019}}, + + {6, 1280, 1400, 0, 0, 0, 64, IPPROTO_ICMP, RND_ID, 2, + {0x0001, 0x04D0}}, + {6, 1300, 1400, 0, 0, 0, 64, IPPROTO_ICMP, RND_ID, 2, + {0x0001, 0x04E0}}, + {6, 4, 1400, 0, 0, 0, 64, IPPROTO_ICMP, RND_ID, -EINVAL}, + {6, 1300, 1400, 0, 0, 0, 0, IPPROTO_ICMP, RND_ID, 2, + {0x0001, 0x04E0}}, }; for (i = 0; i < RTE_DIM(tests); i++) { int32_t len = 0; + uint16_t fragment_offset[BURST]; uint16_t pktid = tests[i].pkt_id; struct rte_mbuf *pkts_out[BURST]; struct rte_mbuf *b = rte_pktmbuf_alloc(pkt_pool); @@ -201,6 +246,8 @@ static void ut_teardown(void) v4_allocate_packet_of(b, 0x41414141, tests[i].pkt_size, tests[i].set_df, + tests[i].set_mf, + tests[i].set_of, tests[i].ttl, tests[i].proto, pktid); @@ -225,14 +272,30 @@ static void ut_teardown(void) rte_pktmbuf_free(b); - if (len > 0) + if (len > 0) { + test_get_offset(pkts_out, len, + fragment_offset, tests[i].ipv); 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); + if (len > 0) { + for (j = 0; j < (size_t)len; j++) { + printf("%zd-%zd: checking %d with %d\n", + i, j, fragment_offset[j], + rte_cpu_to_be_16( + tests[i].expected_fragment_offset[j])); + RTE_TEST_ASSERT_EQUAL(fragment_offset[j], + rte_cpu_to_be_16( + tests[i].expected_fragment_offset[j]), + "Failed case %zd.\n", i); + } + } + } return result; -- 1.8.3.1