test/compress: add initial unit tests
[dpdk.git] / test / test-pipeline / pipeline_hash.c
index edc1663..c201472 100644 (file)
@@ -1,34 +1,5 @@
-/*-
- *   BSD LICENSE
- *
- *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
- *   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.
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2010-2016 Intel Corporation
  */
 
 #include <stdio.h>
@@ -44,6 +15,7 @@
 #include <rte_port_ring.h>
 #include <rte_table_hash.h>
 #include <rte_hash.h>
+#include <rte_table_hash_cuckoo.h>
 #include <rte_pipeline.h>
 
 #include "main.h"
@@ -180,6 +152,17 @@ app_main_loop_worker_pipeline_hash(void) {
                .seed = 0,
        };
 
+       struct rte_table_hash_cuckoo_params table_hash_cuckoo_params = {
+               .name = "TABLE",
+               .key_size = key_size,
+               .key_offset = APP_METADATA_OFFSET(32),
+               .key_mask = NULL,
+               .n_keys = 1 << 24,
+               .n_buckets = 1 << 22,
+               .f_hash = test_hash_cuckoo,
+               .seed = 0,
+       };
+
        /* Table configuration */
        switch (app.pipeline_type) {
        case e_APP_PIPELINE_HASH_KEY8_EXT:
@@ -327,7 +310,7 @@ app_main_loop_worker_pipeline_hash(void) {
        {
                struct rte_pipeline_table_params table_params = {
                        .ops = &rte_table_hash_cuckoo_ops,
-                       .arg_create = &table_hash_params,
+                       .arg_create = &table_hash_cuckoo_params,
                        .f_action_hit = NULL,
                        .f_action_miss = NULL,
                        .arg_ah = NULL,
@@ -408,6 +391,18 @@ uint64_t test_hash(
        return signature;
 }
 
+uint32_t test_hash_cuckoo(
+       const void *key,
+       __attribute__((unused)) uint32_t key_size,
+       __attribute__((unused)) uint32_t seed)
+{
+       const uint32_t *k32 = key;
+       uint32_t ip_dst = rte_be_to_cpu_32(k32[0]);
+       uint32_t signature = (ip_dst >> 2) | ((ip_dst & 0x3) << 30);
+
+       return signature;
+}
+
 void
 app_main_loop_rx_metadata(void) {
        uint32_t i, j;