-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathduplicate_filter.h
99 lines (84 loc) · 3.04 KB
/
duplicate_filter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright (c) 2021 ETH Zurich
*/
#ifndef LF_DUPLICATE_FILTER_H
#define LF_DUPLICATE_FILTER_H
#include <inttypes.h>
#include "lf.h"
/**
* This module provides the (MAC) duplicate filtering functionalities.
*/
/**
* The worker's duplicate filter struct, containing the worker's rotating bloom
* filters.
*/
struct lf_duplicate_filter_worker {
uint64_t last_rotation; /* nanoseconds */
uint64_t bf_period; /* nanoseconds */
/* Bloom Filter Variables */
unsigned int bf_hashes;
unsigned int bf_size;
unsigned int secret;
unsigned int current_bf;
unsigned int nb_bf;
/*
* It is required that bf_size*8 is a power of 2.
* This enables an efficient modulo computation simply using a mask:
* x % (bf_size*8) == x & modulo_mask
*/
uint32_t modulo_mask;
/* all bloom filters. */
uint8_t *bf_arrays[]; /* dynamically sized */
};
struct lf_duplicate_filter {
struct lf_duplicate_filter_worker *workers[LF_MAX_WORKER];
uint16_t nb_workers;
};
/**
* Applies duplicate detection.
* @return 0 if no duplication has been identified.
* Otherwise, a duplicate is suspected.
*/
int
lf_duplicate_filter_apply(struct lf_duplicate_filter_worker *df,
const uint8_t key[16], uint64_t ns_now);
/**
* Create new duplicate filter worker context and initialize it.
* See lf_duplicate_filter_init for the description of the parameters.
* @return new duplicate filter worker context
*/
struct lf_duplicate_filter_worker *
lf_duplicate_filter_worker_new(uint16_t socket, unsigned int nb_bf,
unsigned int bf_period, unsigned int bf_hashes, unsigned int bf_size,
unsigned int hash_secret);
void
lf_duplicate_filter_worker_free(struct lf_duplicate_filter_worker *df);
/**
* Initializes the duplicate filter struct. This also includes the allocation
* and initialization of the worker contexts.
* @param df: Duplicate filter struct to be initialized.
* @param worker_lcores: The lcore assignment for the workers, which determines
* the socket for which memory is allocated.
* @param nb_workers: Number of worker contexts to be created.
* @param nb_bf: Number of Bloom filters to use.
* @param bf_period: Period between Bloom filter rotation in nanoseconds.
* @param bf_hashes: Number of hash values used for the Bloom filters.
* @param bf_size: Size of each Bloom filter bit array in bytes.
* The size in bits (8*bf_size) must be a power of 2, at least 8,
* and fit into a 32 bit unsigned integer.
* @param hash_secret: Random secret used to make the hash unpredictable.
* @returns 0 if successful.
*/
int
lf_duplicate_filter_init(struct lf_duplicate_filter *df,
uint16_t worker_lcores[LF_MAX_WORKER], uint16_t nb_workers,
unsigned int nb_bf, unsigned int bf_period, unsigned int bf_hashes,
unsigned int bf_size, unsigned int hash_secret);
/**
* De-initialize the duplicate filter struct and free all memory allocated for
* it, i.e., the worker contexts.
* @param df: Duplicate filter struct to be de-initialized.
*/
void
lf_duplicate_filter_close(struct lf_duplicate_filter *df);
#endif /* LF_DUPLICATE_FILTER_H */