diff options
author | Mohsin Kazmi <sykazmi@cisco.com> | 2021-06-30 18:26:25 +0000 |
---|---|---|
committer | Damjan Marion <dmarion@me.com> | 2021-09-20 11:11:02 +0000 |
commit | 41b23bc9554a134aee37b430ebf5553cc3260624 (patch) | |
tree | 9094c812a8833a37292244e9c2023d466d99a606 /src/vnet/hash/hash.h | |
parent | e3cf4d0cf3b83f912474220ff52dfedc5a432084 (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.h')
-rw-r--r-- | src/vnet/hash/hash.h | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/vnet/hash/hash.h b/src/vnet/hash/hash.h new file mode 100644 index 00000000000..c1eb9475e28 --- /dev/null +++ b/src/vnet/hash/hash.h @@ -0,0 +1,59 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * Copyright(c) 2021 Cisco Systems, Inc. + */ + +#ifndef __VNET_HASH_H__ +#define __VNET_HASH_H__ + +#include <vlib/vlib.h> + +#define foreach_vnet_hash_fn_types \ + _ (ETHERNET, 0, "hash-fn-ethernet") \ + _ (IP, 1, "hash-fn-ip") + +typedef enum +{ +#define _(f, n, s) VNET_HASH_FN_TYPE_##f, + foreach_vnet_hash_fn_types +#undef _ + VNET_HASH_FN_TYPE_N, +} vnet_hash_fn_type_t; + +typedef void (*vnet_hash_fn_t) (void **p, u32 *h, u32 n_packets); + +typedef struct vnet_hash_function_registration +{ + const char *name; + const char *description; + int priority; + vnet_hash_fn_t function[VNET_HASH_FN_TYPE_N]; + + struct vnet_hash_function_registration *next; +} vnet_hash_function_registration_t; + +typedef struct +{ + vnet_hash_function_registration_t *hash_registrations; +} vnet_hash_main_t; + +extern vnet_hash_main_t vnet_hash_main; + +#define VNET_REGISTER_HASH_FUNCTION(x, ...) \ + __VA_ARGS__ vnet_hash_function_registration_t __vnet_hash_function_##x; \ + static void __clib_constructor __vnet_hash_function_registration_##x (void) \ + { \ + vnet_hash_main_t *hm = &vnet_hash_main; \ + __vnet_hash_function_##x.next = hm->hash_registrations; \ + hm->hash_registrations = &__vnet_hash_function_##x; \ + } \ + __VA_ARGS__ vnet_hash_function_registration_t __vnet_hash_function_##x + +vnet_hash_fn_t vnet_hash_default_function (vnet_hash_fn_type_t ftype); +vnet_hash_fn_t vnet_hash_function_from_name (const char *name, + vnet_hash_fn_type_t ftype); +vnet_hash_function_registration_t * +vnet_hash_function_from_func (vnet_hash_fn_t fn, vnet_hash_fn_type_t ftype); +format_function_t format_vnet_hash; + +#endif |