Skip to content

Commit

Permalink
Implement space saving algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
gogapp committed Jun 25, 2018
1 parent 80a665b commit 5b985ee
Show file tree
Hide file tree
Showing 3 changed files with 926 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ SRCS-y += sol/main.c
# Libraries.
SRCS-y += lib/mailbox.c lib/net.c lib/flow.c lib/ipip.c \
lib/luajit-ffi-cdata.c lib/launch.c lib/lpm.c lib/acl.c lib/varip.c \
lib/l2.c
lib/l2.c lib/space_saving.c

LDLIBS += $(LDIR) -Bstatic -lluajit-5.1 -Bdynamic -lm -lmnl
CFLAGS += $(WERROR_FLAGS) -I${GATEKEEPER}/include -I/usr/local/include/luajit-2.0/
Expand Down
130 changes: 130 additions & 0 deletions include/space_saving.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
* Gatekeeper - DoS protection system.
* Copyright (C) 2016 Digirati LTDA.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _SPACE_SAVING_H_
#define _SPACE_SAVING_H_

#include <rte_hash.h>

#include "gatekeeper_gk.h"
#include "gatekeeper_net.h"
#include "gatekeeper_flow.h"

/* Data structure for Counter Table */
struct counter_table {

/* Counter for IPV4 address */
struct rte_hash *ct_ip4;

/* Counter for IPV6 address */
struct rte_hash *ct_ip6;
};

/* Data structure for Counter bucket */
struct counter_bucket {

int proto;

union {
/* Bucket for IPV4 address */
struct rte_hash *bkt_ip4;

/* Bucket for IPV6 address */
struct rte_hash *bkt_ip6;
} bkt;
};

/* Data present in a Counter bucket */
struct bucket_data {

int err;
struct ip_flow flow;
};

/* Data structure of IP data */
struct ip_data {

int bkt_id;
struct bucket_data bkt_data;
};

static int
setup_bucket_params(unsigned int socket_id, int bkt_id, int bkt_size,
int ip_ver, struct rte_hash_parameters *bkt_hash_params);

static int
create_bucket(struct gatekeeper_if *iface, struct gk_config *gk_conf,
int bkt_id);

static int
get_bucket(int bkt_id, int proto, struct counter_bucket *ct_bkt);

static int
get_bucket_entry(struct counter_bucket *ct_bkt, struct ip_flow *flow,
struct bucket_data *bkt_data);

static int
add_bucket_entry(struct counter_bucket *ct_bkt, struct ip_flow *flow,
struct bucket_data *bkt_data);

static int
delete_bucket_entry(struct counter_bucket *ct_bkt, struct ip_flow *flow);

static int
setup_counter_params(unsigned int socket_id, int identifier, int ht_size,
int ip_ver, struct rte_hash_parameters *ct_hash_params);

static int
create_counter_table(struct gatekeeper_if *iface, struct gk_config *gk_conf);

static int
get_bucket_id(struct counter_table *ct_table, struct ip_flow *flow,
int *bkt_id);

static int
add_bucket_id(struct counter_table *ct_table, struct ip_flow *flow,
int *bkt_id);

static int
delete_bucket_id(struct counter_table *ct_table, struct ip_flow *flow);

static int
update_bucket_id(struct counter_table *ct_table, struct ip_flow *flow);

static int
get_ip_data(struct counter_table *ct_table, struct ip_flow *flow,
struct ip_data *data);

static int
add_ip_data(struct counter_table *ct_table, struct ip_flow *flow,
struct ip_data *data);

static int
delete_ip_data(struct counter_table *ct_table, struct ip_flow *flow);

static int
update_ip_data(struct counter_table *ct_table, struct ip_flow *flow,
struct gatekeeper_if *iface, struct gk_config *gk_conf);

static int
space_saving(struct counter_table *ct_table, struct ip_flow *flow,
struct gatekeeper_if *iface, struct gk_config *gk_conf);

int run(struct gatekeeper_if *iface, struct gk_config *gk_conf);
#endif /* _SPACE_SAVING_H */

Loading

0 comments on commit 5b985ee

Please sign in to comment.