Skip to content

Commit fa6f231

Browse files
committed
Implement RHHH Algorithm.
1 parent 5ececb9 commit fa6f231

File tree

3 files changed

+1152
-1
lines changed

3 files changed

+1152
-1
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ SRCS-y += sol/main.c
4444
# Libraries.
4545
SRCS-y += lib/mailbox.c lib/net.c lib/flow.c lib/ipip.c \
4646
lib/luajit-ffi-cdata.c lib/launch.c lib/lpm.c lib/acl.c lib/varip.c \
47-
lib/l2.c lib/space_saving.c
47+
lib/l2.c lib/space_saving.c lib/gatekeeper_rhhh.c
4848

4949
LDLIBS += $(LDIR) -Bstatic -lluajit-5.1 -Bdynamic -lm -lmnl
5050
CFLAGS += $(WERROR_FLAGS) -I${GATEKEEPER}/include -I/usr/local/include/luajit-2.0/

include/gatekeeper_rhhh.h

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Gatekeeper - DoS protection system.
3+
* Copyright (C) 2016 Digirati LTDA.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#ifndef _GATEKEEPER_RHHH_H_
20+
#define _GATEKEEPER_RHHH_H_
21+
22+
#include "space_saving.h"
23+
24+
#ifndef DIMENSION
25+
#define DIMENSION 1
26+
#endif
27+
28+
#ifndef NUM_V4_COUNTERS
29+
#define NUM_V4_COUNTERS 5
30+
#endif
31+
32+
#ifndef NUM_V6_COUNTERS
33+
#define NUM_V6_COUNTERS 17
34+
#endif
35+
36+
extern struct rte_hash *counter_ip4[NUM_V4_COUNTERS];
37+
extern struct rte_hash *counter_ip6[NUM_V6_COUNTERS];
38+
39+
typedef struct heavyhitter {
40+
struct ip_key key;
41+
42+
union {
43+
/* Mask for IPv4 packets */
44+
struct {
45+
uint32_t src_mask;
46+
uint32_t dst_mask;
47+
} v4;
48+
49+
/* Mask for IPv6 packets */
50+
struct {
51+
uint8_t src_mask[16];
52+
uint8_t dst_mask[16];
53+
} v6;
54+
} msk;
55+
56+
uint32_t upr_bnd;
57+
uint32_t lwr_bnd;
58+
} HeavyHitter;
59+
60+
typedef struct descendant {
61+
struct ip_key key;
62+
union {
63+
/* Mask for IPv4 packet. */
64+
struct {
65+
uint32_t src_mask;
66+
uint32_t dst_mask;
67+
} v4;
68+
69+
/* Mask for IPv6 packet. */
70+
struct {
71+
uint8_t src_mask[16];
72+
uint8_t dst_mask[16];
73+
} v6;
74+
} msk;
75+
} Descendant;
76+
77+
double dblmax(double a, double b);
78+
79+
double two_to_the_k(int k);
80+
81+
extern int
82+
rhhh_init(unsigned int socket_id, uint16_t proto, double prob);
83+
84+
void
85+
rhhh_deinit(uint16_t proto);
86+
87+
extern int
88+
rhhh_update(unsigned int socket_id, struct ip_key *key);
89+
90+
static
91+
struct rte_hash *
92+
create_dblcounter(unsigned int socket_id, uint16_t proto, int dblcounter_id,
93+
int dblcounter_size);
94+
95+
extern int
96+
rhhh1D_v4_output(double threshold, unsigned int socket_id);
97+
98+
extern int
99+
calcPred2D_v4(struct ip_key *key, uint32_t src_mask, uint32_t dst_mask);
100+
101+
extern int
102+
rhhh2D_v4_output(double threshold, unsigned int socket_id);
103+
104+
extern int
105+
rhhh1D_v6_output(double threshold, unsigned int socket_id);
106+
107+
#endif /* _GATEKEEPER_RHHH_H_ */

0 commit comments

Comments
 (0)