summaryrefslogtreecommitdiffstats
path: root/src/vnet/util
diff options
context:
space:
mode:
authorNeale Ranns <nranns@cisco.com>2018-08-31 02:51:45 -0700
committerDamjan Marion <dmarion@me.com>2018-10-29 12:06:11 +0000
commitcd35e53c928f666e50342e27d69e6dd7d60e1283 (patch)
treeab4faf6f9d9e28151627df757b6d0dffba4d006f /src/vnet/util
parentb3a9381ad54ea30bf872cf781023e353a89ebaa6 (diff)
Use throttle_t for ND throttling
Change-Id: I93c6b7bccd1a1ab71625ae29c99c974581186c4d Signed-off-by: Neale Ranns <nranns@cisco.com>
Diffstat (limited to 'src/vnet/util')
-rw-r--r--src/vnet/util/throttle.h12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/vnet/util/throttle.h b/src/vnet/util/throttle.h
index 45d437cf471..38ace280131 100644
--- a/src/vnet/util/throttle.h
+++ b/src/vnet/util/throttle.h
@@ -17,6 +17,7 @@
#define __THROTTLE_H__
#include <vlib/vlib.h>
+#include <vppinfra/xxhash.h>
/**
* @brief A throttle
@@ -28,7 +29,7 @@ typedef struct throttle_t_
{
f64 time;
uword **bitmaps;
- u32 *seeds;
+ u64 *seeds;
f64 *last_seed_change_time;
} throttle_t;
@@ -36,12 +37,12 @@ typedef struct throttle_t_
extern void throttle_init (throttle_t * t, u32 n_threads, f64 time);
-always_inline u32
+always_inline u64
throttle_seed (throttle_t * t, u32 thread_index, f64 time_now)
{
if (time_now - t->last_seed_change_time[thread_index] > t->time)
{
- (void) random_u32 (&t->seeds[thread_index]);
+ (void) random_u64 (&t->seeds[thread_index]);
clib_memset (t->bitmaps[thread_index], 0, THROTTLE_BITS / BITS (u8));
t->last_seed_change_time[thread_index] = time_now;
@@ -50,13 +51,14 @@ throttle_seed (throttle_t * t, u32 thread_index, f64 time_now)
}
always_inline int
-throttle_check (throttle_t * t, u32 thread_index, u32 hash, u32 seed)
+throttle_check (throttle_t * t, u32 thread_index, u64 hash, u64 seed)
{
int drop;
uword m;
u32 w;
- hash ^= seed;
+ hash = clib_xxhash (hash ^ seed);
+
/* Select bit number */
hash &= THROTTLE_BITS - 1;
w = hash / BITS (uword);