blob: c1eb9475e28490720b9cc222f13806ad7c9bcc30 [file] [log] [blame]
Mohsin Kazmi41b23bc2021-06-30 18:26:25 +00001/*
2 * SPDX-License-Identifier: Apache-2.0
3 * Copyright(c) 2021 Cisco Systems, Inc.
4 */
5
6#ifndef __VNET_HASH_H__
7#define __VNET_HASH_H__
8
9#include <vlib/vlib.h>
10
11#define foreach_vnet_hash_fn_types \
12 _ (ETHERNET, 0, "hash-fn-ethernet") \
13 _ (IP, 1, "hash-fn-ip")
14
15typedef enum
16{
17#define _(f, n, s) VNET_HASH_FN_TYPE_##f,
18 foreach_vnet_hash_fn_types
19#undef _
20 VNET_HASH_FN_TYPE_N,
21} vnet_hash_fn_type_t;
22
23typedef void (*vnet_hash_fn_t) (void **p, u32 *h, u32 n_packets);
24
25typedef struct vnet_hash_function_registration
26{
27 const char *name;
28 const char *description;
29 int priority;
30 vnet_hash_fn_t function[VNET_HASH_FN_TYPE_N];
31
32 struct vnet_hash_function_registration *next;
33} vnet_hash_function_registration_t;
34
35typedef struct
36{
37 vnet_hash_function_registration_t *hash_registrations;
38} vnet_hash_main_t;
39
40extern vnet_hash_main_t vnet_hash_main;
41
42#define VNET_REGISTER_HASH_FUNCTION(x, ...) \
43 __VA_ARGS__ vnet_hash_function_registration_t __vnet_hash_function_##x; \
44 static void __clib_constructor __vnet_hash_function_registration_##x (void) \
45 { \
46 vnet_hash_main_t *hm = &vnet_hash_main; \
47 __vnet_hash_function_##x.next = hm->hash_registrations; \
48 hm->hash_registrations = &__vnet_hash_function_##x; \
49 } \
50 __VA_ARGS__ vnet_hash_function_registration_t __vnet_hash_function_##x
51
52vnet_hash_fn_t vnet_hash_default_function (vnet_hash_fn_type_t ftype);
53vnet_hash_fn_t vnet_hash_function_from_name (const char *name,
54 vnet_hash_fn_type_t ftype);
55vnet_hash_function_registration_t *
56vnet_hash_function_from_func (vnet_hash_fn_t fn, vnet_hash_fn_type_t ftype);
57format_function_t format_vnet_hash;
58
59#endif