summaryrefslogtreecommitdiffstats
path: root/src/vnet/hash/hash.c
diff options
context:
space:
mode:
authorMohsin Kazmi <sykazmi@cisco.com>2021-06-30 18:26:25 +0000
committerDamjan Marion <dmarion@me.com>2021-09-20 11:11:02 +0000
commit41b23bc9554a134aee37b430ebf5553cc3260624 (patch)
tree9094c812a8833a37292244e9c2023d466d99a606 /src/vnet/hash/hash.c
parente3cf4d0cf3b83f912474220ff52dfedc5a432084 (diff)
hash: add support for hashing infra
Type: feature Signed-off-by: Mohsin Kazmi <sykazmi@cisco.com> Change-Id: I3652ae275385d9b1eb1b11f418e3a7e5fef2f556
Diffstat (limited to 'src/vnet/hash/hash.c')
-rw-r--r--src/vnet/hash/hash.c76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/vnet/hash/hash.c b/src/vnet/hash/hash.c
new file mode 100644
index 00000000000..31693c9889b
--- /dev/null
+++ b/src/vnet/hash/hash.c
@@ -0,0 +1,76 @@
+/*
+ * SPDX-License-Identifier: Apache-2.0
+ * Copyright(c) 2021 Cisco Systems, Inc.
+ */
+
+#include <vlib/vlib.h>
+#include <vnet/vnet.h>
+#include <vnet/interface.h>
+#include <vnet/hash/hash.h>
+
+vnet_hash_main_t vnet_hash_main;
+
+u8 *
+format_vnet_hash (u8 *s, va_list *args)
+{
+ vnet_hash_function_registration_t *hash =
+ va_arg (*args, vnet_hash_function_registration_t *);
+
+ s = format (s, "[name: %s ", hash->name);
+ s = format (s, "priority: %u ", hash->priority);
+ s = format (s, "description: %s]", hash->description);
+ return s;
+}
+
+/**
+ * select hash func with highest priority
+ */
+vnet_hash_fn_t
+vnet_hash_default_function (vnet_hash_fn_type_t ftype)
+{
+ vnet_hash_function_registration_t *hash = vnet_hash_main.hash_registrations;
+ vnet_hash_function_registration_t *tmp_hash = hash;
+ while (hash)
+ {
+ if (hash->priority > tmp_hash->priority)
+ tmp_hash = hash;
+ hash = hash->next;
+ }
+ return tmp_hash->function[ftype];
+}
+
+vnet_hash_fn_t
+vnet_hash_function_from_name (const char *name, vnet_hash_fn_type_t ftype)
+{
+ vnet_hash_function_registration_t *hash = vnet_hash_main.hash_registrations;
+ while (hash)
+ {
+ if (strcmp (hash->name, name) == 0)
+ break;
+ hash = hash->next;
+ }
+ if (!hash)
+ return (0);
+ return hash->function[ftype];
+}
+
+vnet_hash_function_registration_t *
+vnet_hash_function_from_func (vnet_hash_fn_t fn, vnet_hash_fn_type_t ftype)
+{
+ vnet_hash_function_registration_t *hash = vnet_hash_main.hash_registrations;
+ while (hash)
+ {
+ if (hash->function[ftype] == fn)
+ break;
+ hash = hash->next;
+ }
+ return hash;
+}
+
+static clib_error_t *
+vnet_hash_init (vlib_main_t *vm)
+{
+ return (0);
+}
+
+VLIB_INIT_FUNCTION (vnet_hash_init);