} \
} while (0)
-/* 5-tuple key type */
+/*
+ * 5-tuple key type.
+ * Should be packed to avoid holes with potentially
+ * undefined content in the middle.
+ */
struct flow_key {
uint32_t ip_src;
uint32_t ip_dst;
uint16_t port_src;
uint16_t port_dst;
- uint8_t proto;
+ uint32_t proto;
} __rte_packed;
/*
/* Parameters used for hash table in unit test functions. Name set later. */
static struct rte_hash_parameters ut_params = {
.entries = 64,
- .key_len = sizeof(struct flow_key), /* 13 */
+ .key_len = sizeof(struct flow_key),
.hash_func = rte_jhash,
.hash_func_init_val = 0,
.socket_id = 0,
struct rte_hash_parameters params_pseudo_hash = {
.name = "test4",
.entries = 64,
- .key_len = sizeof(struct flow_key), /* 13 */
+ .key_len = sizeof(struct flow_key),
.hash_func = pseudo_hash,
.hash_func_init_val = 0,
.socket_id = 0,
struct rte_hash_parameters params_pseudo_hash = {
.name = "test5",
.entries = 64,
- .key_len = sizeof(struct flow_key), /* 13 */
+ .key_len = sizeof(struct flow_key),
.hash_func = pseudo_hash,
.hash_func_init_val = 0,
.socket_id = 0,
.socket_id = 0,
};
+/*
+ * Wrapper function around rte_jhash_32b.
+ * It is required because rte_jhash_32b() accepts the length
+ * as size of 4-byte units.
+ */
+static inline uint32_t
+test_jhash_32b(const void *k, uint32_t length, uint32_t initval)
+{
+ return rte_jhash_32b(k, length >> 2, initval);
+}
+
/*
* add/delete key with jhash2
*/
hash_params_ex.name = "hash_test_jhash2";
hash_params_ex.key_len = 4;
- hash_params_ex.hash_func = (rte_hash_function)rte_jhash_32b;
+ hash_params_ex.hash_func = (rte_hash_function)test_jhash_32b;
handle = rte_hash_create(&hash_params_ex);
if (handle == NULL) {
hash_params_ex.name = "hash_test_2_jhash2";
hash_params_ex.key_len = 8;
- hash_params_ex.hash_func = (rte_hash_function)rte_jhash_32b;
+ hash_params_ex.hash_func = (rte_hash_function)test_jhash_32b;
handle = rte_hash_create(&hash_params_ex);
if (handle == NULL)
struct rte_hash_parameters params_pseudo_hash = {
.name = "test_hash_rcu_qsbr_dq_mode",
.entries = total_entries,
- .key_len = sizeof(struct flow_key), /* 13 */
+ .key_len = sizeof(struct flow_key),
.hash_func = pseudo_hash,
.hash_func_init_val = 0,
.socket_id = 0,
struct rte_hash_parameters params_pseudo_hash = {
.name = "test_hash_rcu_qsbr_sync_mode",
.entries = total_entries,
- .key_len = sizeof(struct flow_key), /* 13 */
+ .key_len = sizeof(struct flow_key),
.hash_func = pseudo_hash,
.hash_func_init_val = 0,
.socket_id = 0,
static int
test_hash(void)
{
+ RTE_BUILD_BUG_ON(sizeof(struct flow_key) % sizeof(uint32_t) != 0);
+
if (test_add_delete() < 0)
return -1;
if (test_hash_add_delete_jhash2() < 0)