DPDK patches and discussions
 help / color / mirror / Atom feed
From: Vladimir Medvedkin <medvedkinv@gmail.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH v4] Add unit test for thash library
Date: Tue, 30 Jun 2015 19:41:13 -0400	[thread overview]
Message-ID: <1435707673-17423-1-git-send-email-medvedkinv@gmail.com> (raw)
In-Reply-To: <1434735125-27452-1-git-send-email-medvedkinv@gmail.com>

Add unit test for thash library

v4 changes
- Reflect rte_thash.h changes

v3 changes
- Fix checkpatch errors

v2 changes
- fix typo
- remove unnecessary comments

Signed-off-by: Vladimir Medvedkin <medvedkinv@gmail.com>
---
 app/test/Makefile     |   1 +
 app/test/test_thash.c | 176 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 177 insertions(+)
 create mode 100644 app/test/test_thash.c

diff --git a/app/test/Makefile b/app/test/Makefile
index 2e2758c..caa359c 100644
--- a/app/test/Makefile
+++ b/app/test/Makefile
@@ -82,6 +82,7 @@ SRCS-y += test_memcpy.c
 SRCS-y += test_memcpy_perf.c
 
 SRCS-$(CONFIG_RTE_LIBRTE_HASH) += test_hash.c
+SRCS-$(CONFIG_RTE_LIBRTE_HASH) += test_thash.c
 SRCS-$(CONFIG_RTE_LIBRTE_HASH) += test_hash_perf.c
 SRCS-$(CONFIG_RTE_LIBRTE_HASH) += test_hash_functions.c
 SRCS-$(CONFIG_RTE_LIBRTE_HASH) += test_hash_scaling.c
diff --git a/app/test/test_thash.c b/app/test/test_thash.c
new file mode 100644
index 0000000..8e9dca0
--- /dev/null
+++ b/app/test/test_thash.c
@@ -0,0 +1,176 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2015 Vladimir Medvedkin <medvedkinv@gmail.com>
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <rte_common.h>
+#include <rte_eal.h>
+#include <rte_ip.h>
+
+#include "test.h"
+
+#include <rte_thash.h>
+
+struct test_thash_v4 {
+	uint32_t	dst_ip;
+	uint32_t	src_ip;
+	uint16_t	dst_port;
+	uint16_t	src_port;
+	uint32_t	hash_l3;
+	uint32_t	hash_l3l4;
+};
+
+struct test_thash_v6 {
+	uint8_t		dst_ip[16];
+	uint8_t		src_ip[16];
+	uint16_t	dst_port;
+	uint16_t	src_port;
+	uint32_t	hash_l3;
+	uint32_t	hash_l3l4;
+};
+
+/*From 82599 Datasheet 7.1.2.8.3 RSS Verification Suite*/
+struct test_thash_v4 v4_tbl[] = {
+{IPv4(161, 142, 100, 80), IPv4(66, 9, 149, 187),
+	1766, 2794, 0x323e8fc2, 0x51ccc178},
+{IPv4(65, 69, 140, 83), IPv4(199, 92, 111, 2),
+	4739, 14230, 0xd718262a, 0xc626b0ea},
+{IPv4(12, 22, 207, 184), IPv4(24, 19, 198, 95),
+	38024, 12898, 0xd2d0a5de, 0x5c2b394a},
+{IPv4(209, 142, 163, 6), IPv4(38, 27, 205, 30),
+	2217, 48228, 0x82989176, 0xafc7327f},
+{IPv4(202, 188, 127, 2), IPv4(153, 39, 163, 191),
+	1303, 44251, 0x5d1809c5, 0x10e828a2},
+};
+
+struct test_thash_v6 v6_tbl[] = {
+/*3ffe:2501:200:3::1*/
+{{0x3f, 0xfe, 0x25, 0x01, 0x02, 0x00, 0x00, 0x03,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,},
+/*3ffe:2501:200:1fff::7*/
+{0x3f, 0xfe, 0x25, 0x01, 0x02, 0x00, 0x1f, 0xff,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07,},
+1766, 2794, 0x2cc18cd5, 0x40207d3d},
+/*ff02::1*/
+{{0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,},
+/*3ffe:501:8::260:97ff:fe40:efab*/
+{0x3f, 0xfe, 0x05, 0x01, 0x00, 0x08, 0x00, 0x00,
+0x02, 0x60, 0x97, 0xff, 0xfe, 0x40, 0xef, 0xab,},
+4739, 14230, 0x0f0c461c, 0xdde51bbf},
+/*fe80::200:f8ff:fe21:67cf*/
+{{0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x02, 0x00, 0xf8, 0xff, 0xfe, 0x21, 0x67, 0xcf,},
+/*3ffe:1900:4545:3:200:f8ff:fe21:67cf*/
+{0x3f, 0xfe, 0x19, 0x00, 0x45, 0x45, 0x00, 0x03,
+0x02, 0x00, 0xf8, 0xff, 0xfe, 0x21, 0x67, 0xcf,},
+38024, 44251, 0x4b61e985, 0x02d1feef},
+};
+
+uint8_t default_rss_key[] = {
+0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2,
+0x41, 0x67, 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0,
+0xd0, 0xca, 0x2b, 0xcb, 0xae, 0x7b, 0x30, 0xb4,
+0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30, 0xf2, 0x0c,
+0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa,
+};
+
+static int
+test_thash(void)
+{
+	uint32_t i, j;
+	union rte_thash_tuple tuple;
+	uint32_t rss_l3, rss_l3l4;
+	uint8_t rss_key_be[RTE_DIM(default_rss_key)];
+	struct ipv6_hdr ipv6_hdr;
+
+	/* Convert RSS key*/
+	rte_convert_rss_key((uint32_t *)&default_rss_key,
+		(uint32_t *)rss_key_be, RTE_DIM(default_rss_key));
+
+
+	for (i = 0; i < RTE_DIM(v4_tbl); i++) {
+		tuple.v4.src_addr = v4_tbl[i].src_ip;
+		tuple.v4.dst_addr = v4_tbl[i].dst_ip;
+		tuple.v4.sport = v4_tbl[i].src_port;
+		tuple.v4.dport = v4_tbl[i].dst_port;
+		/*Calculate hash with original key*/
+		rss_l3 = rte_softrss((uint32_t *)&tuple,
+				RTE_THASH_V4_L3_LEN, default_rss_key);
+		rss_l3l4 = rte_softrss((uint32_t *)&tuple,
+				RTE_THASH_V4_L4_LEN, default_rss_key);
+		if ((rss_l3 != v4_tbl[i].hash_l3) ||
+				(rss_l3l4 != v4_tbl[i].hash_l3l4))
+			return -1;
+		/*Calculate hash with converted key*/
+		rss_l3 = rte_softrss_be((uint32_t *)&tuple,
+				RTE_THASH_V4_L3_LEN, rss_key_be);
+		rss_l3l4 = rte_softrss_be((uint32_t *)&tuple,
+				RTE_THASH_V4_L4_LEN, rss_key_be);
+		if ((rss_l3 != v4_tbl[i].hash_l3) ||
+				(rss_l3l4 != v4_tbl[i].hash_l3l4))
+			return -1;
+	}
+	for (i = 0; i < RTE_DIM(v6_tbl); i++) {
+		/*Fill ipv6 hdr*/
+		for (j = 0; j < RTE_DIM(ipv6_hdr.src_addr); j++)
+			ipv6_hdr.src_addr[j] = v6_tbl[i].src_ip[j];
+		for (j = 0; j < RTE_DIM(ipv6_hdr.dst_addr); j++)
+			ipv6_hdr.dst_addr[j] = v6_tbl[i].dst_ip[j];
+		/*Load and convert ipv6 address into tuple*/
+		rte_thash_load_v6_addrs(&ipv6_hdr, &tuple);
+		tuple.v6.sport = v6_tbl[i].src_port;
+		tuple.v6.dport = v6_tbl[i].dst_port;
+		/*Calculate hash with original key*/
+		rss_l3 = rte_softrss((uint32_t *)&tuple,
+				RTE_THASH_V6_L3_LEN, default_rss_key);
+		rss_l3l4 = rte_softrss((uint32_t *)&tuple,
+				RTE_THASH_V6_L4_LEN, default_rss_key);
+		if ((rss_l3 != v6_tbl[i].hash_l3) ||
+				(rss_l3l4 != v6_tbl[i].hash_l3l4))
+			return -1;
+		/*Calculate hash with converted key*/
+		rss_l3 = rte_softrss_be((uint32_t *)&tuple,
+				RTE_THASH_V6_L3_LEN, rss_key_be);
+		rss_l3l4 = rte_softrss_be((uint32_t *)&tuple,
+				RTE_THASH_V6_L4_LEN, rss_key_be);
+		if ((rss_l3 != v6_tbl[i].hash_l3) ||
+				(rss_l3l4 != v6_tbl[i].hash_l3l4))
+			return -1;
+	}
+	return 0;
+}
+
+static struct test_command thash_cmd = {
+	.command = "thash_autotest",
+	.callback = test_thash,
+};
+REGISTER_TEST_COMMAND(thash_cmd);
-- 
1.8.3.2

  parent reply	other threads:[~2015-06-30 23:43 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-08 19:06 [dpdk-dev] [PATCH] Add toeplitz hash algorithm Vladimir Medvedkin
2015-04-08 22:24 ` Stephen Hemminger
2015-04-09 12:50   ` Vladimir Medvedkin
2015-04-09  6:37 ` Gleb Natapov
2015-04-09 12:57   ` Vladimir Medvedkin
2015-05-05 13:20 ` [dpdk-dev] [PATCH v2] Add toeplitz hash algorithm used by RSS Vladimir Medvedkin
2015-05-05 16:03   ` Chilikin, Andrey
2015-05-07 10:28     ` Vladimir Medvedkin
2015-05-07 11:38       ` Chilikin, Andrey
2015-05-08 14:58         ` Vladimir Medvedkin
2015-05-08 14:58   ` Vladimir Medvedkin
2015-06-03 14:07     ` Thomas Monjalon
2015-06-16  9:07       ` Thomas Monjalon
2015-06-16 10:36         ` Bruce Richardson
2015-06-16 12:29     ` Bruce Richardson
2015-06-16 19:26       ` Vladimir Medvedkin
2015-06-19 14:55     ` [dpdk-dev] [PATCH v4] " Vladimir Medvedkin
2015-06-19 15:59       ` Richardson, Bruce
2015-06-19 16:14         ` Vladimir Medvedkin
2015-06-29 12:18           ` Bruce Richardson
2015-06-19 16:33         ` Mcnamara, John
2015-06-19 17:31       ` [dpdk-dev] [PATCH v5] " Vladimir Medvedkin
2015-06-29 12:40         ` Bruce Richardson
2015-06-30 12:14           ` Vladimir Medvedkin
2015-06-30 12:48             ` Bruce Richardson
2015-06-30 23:40         ` [dpdk-dev] [PATCH v6] " Vladimir Medvedkin
2015-07-01 15:29           ` Bruce Richardson
2015-07-01 21:23             ` Thomas Monjalon
2015-07-22  7:55           ` Tony Lu
2015-07-27 11:57             ` Vladimir Medvedkin
2015-07-29  5:01               ` Qiu, Michael
2015-07-29 14:00                 ` Vladimir Medvedkin
2015-06-19 17:32       ` [dpdk-dev] [PATCH v3] Add unit test for thash library Vladimir Medvedkin
2015-06-29 12:42         ` Bruce Richardson
2015-06-30 23:41         ` Vladimir Medvedkin [this message]
2015-07-01 15:30           ` [dpdk-dev] [PATCH v4] " Bruce Richardson
2015-07-01 21:28             ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1435707673-17423-1-git-send-email-medvedkinv@gmail.com \
    --to=medvedkinv@gmail.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).