summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author郑超 <[email protected]>2024-03-27 11:19:39 +0000
committerliuwentan <[email protected]>2024-03-27 11:19:39 +0000
commit99f98abbcdf6a9ae2da51b99aaa8dbf70568a4ff (patch)
treedd7b00ac76051ca16936a42eaa9e4f61a68ed043
parent35d60d06b5bf18a8adf95cb4cfb00df5ab3c02da (diff)
Feature/scan ip port together support endpoint objectv4.1.32
-rw-r--r--include/maat.h12
-rw-r--r--scanner/CMakeLists.txt2
-rw-r--r--scanner/ipport_matcher/ipport_matcher.c (renamed from scanner/ipport_matcher/ipport_matcher.cpp)0
-rw-r--r--src/CMakeLists.txt4
-rw-r--r--src/inc_internal/maat_ip.h2
-rw-r--r--src/inc_internal/maat_redis_monitor.h1
-rw-r--r--src/inc_internal/maat_rule.h1
-rw-r--r--src/inc_internal/maat_table.h2
-rw-r--r--src/json2iris.c16
-rw-r--r--src/maat_api.c53
-rw-r--r--src/maat_ip.c51
-rw-r--r--src/maat_rule.c156
-rw-r--r--src/maat_stat.c4
-rw-r--r--src/maat_table.c4
-rw-r--r--test/CMakeLists.txt15
-rw-r--r--test/benchmark/benchmark_hs_gtest.cpp125
-rw-r--r--test/benchmark/benchmark_rs_gtest.cpp114
-rw-r--r--test/benchmark/benchmark_table_info.conf20
-rw-r--r--test/file_test_tableinfo.conf4
-rw-r--r--test/group_exclude/group_exclude_gtest.cpp4
-rw-r--r--test/ipport_plugin/ipport_plugin_gtest.cpp6
-rw-r--r--test/maat_ex_data_gtest.cpp14
-rw-r--r--test/maat_framework_gtest.cpp495
-rw-r--r--test/maat_framework_perf_gtest.cpp355
-rw-r--r--test/maat_input_mode_gtest.cpp32
-rw-r--r--test/maat_json.json149
-rw-r--r--test/table_info.conf20
-rw-r--r--test/test_utils.cpp303
-rw-r--r--test/test_utils.h37
-rw-r--r--test/tsg_table_info.conf3
30 files changed, 941 insertions, 1063 deletions
diff --git a/include/maat.h b/include/maat.h
index 8b59faf..2b15321 100644
--- a/include/maat.h
+++ b/include/maat.h
@@ -118,8 +118,6 @@ int maat_options_set_caller_thread_number(struct maat_options *opts, size_t n_th
int maat_options_set_accept_tags(struct maat_options *opts, const char *accept_tags);
-int maat_options_set_rule_effect_interval_ms(struct maat_options *opts, int interval_ms);
-
int maat_options_set_rule_update_checking_interval_ms(struct maat_options *opts, int interval_ms);
int maat_options_set_gc_timeout_ms(struct maat_options *opts, int interval_ms);
@@ -264,8 +262,16 @@ int maat_scan_integer(struct maat *instance, int table_id, long long integer,
struct maat_state *state);
/**
- * @param ip_addr: network ipv4 address
+ * @param ip_addr: ipv4 address in network order
+ * @param port: port in host order. If the port is not specified, use -1. Note that 0 is a valid port.
*/
+int maat_scan_ipv4_port(struct maat *instance, int table_id, uint32_t ip_addr, int port,
+ long long *results, size_t n_result, size_t *n_hit_result,
+ struct maat_state *state);
+
+int maat_scan_ipv6_port(struct maat *instance, int table_id, uint8_t *ip_addr, int port,
+ long long *results, size_t n_result, size_t *n_hit_result,
+ struct maat_state *state);
int maat_scan_ipv4(struct maat *instance, int table_id, uint32_t ip_addr,
long long *results, size_t n_result, size_t *n_hit_result,
struct maat_state *state);
diff --git a/scanner/CMakeLists.txt b/scanner/CMakeLists.txt
index e8c1a7b..827602b 100644
--- a/scanner/CMakeLists.txt
+++ b/scanner/CMakeLists.txt
@@ -11,7 +11,7 @@ set(SCANNER_SRC bool_matcher/bool_matcher.cpp expr_matcher/expr_matcher.cpp
expr_matcher/adapter_hs/adapter_hs.cpp expr_matcher/adapter_rs/adapter_rs.cpp
fqdn_engine/fqdn_engine.cpp ip_matcher/ip_matcher.cpp ip_matcher/ipv4_match.cpp
ip_matcher/ipv6_match.cpp flag_matcher/flag_matcher.cpp interval_matcher/cgranges.c
- interval_matcher/interval_matcher.cpp ipport_matcher/ipport_matcher.cpp)
+ interval_matcher/interval_matcher.cpp ipport_matcher/ipport_matcher.c)
set(LIB_SOURCE_FILES ${PROJECT_SOURCE_DIR}/deps/bloom/bloom.c ${PROJECT_SOURCE_DIR}/deps/bloom/murmurhash2.c)
diff --git a/scanner/ipport_matcher/ipport_matcher.cpp b/scanner/ipport_matcher/ipport_matcher.c
index c4271c3..c4271c3 100644
--- a/scanner/ipport_matcher/ipport_matcher.cpp
+++ b/scanner/ipport_matcher/ipport_matcher.c
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 3246338..b298abd 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,8 +1,8 @@
cmake_minimum_required(VERSION 3.5)
set(MAAT_FRAME_MAJOR_VERSION 4)
-set(MAAT_FRAME_MINOR_VERSION 0)
-set(MAAT_FRAME_PATCH_VERSION 14)
+set(MAAT_FRAME_MINOR_VERSION 1)
+set(MAAT_FRAME_PATCH_VERSION 0)
set(MAAT_FRAME_VERSION ${MAAT_FRAME_MAJOR_VERSION}.${MAAT_FRAME_MINOR_VERSION}.${MAAT_FRAME_PATCH_VERSION})
message(STATUS "Maat Frame, Version: ${MAAT_FRAME_VERSION}")
diff --git a/src/inc_internal/maat_ip.h b/src/inc_internal/maat_ip.h
index bfa3ddc..726c99c 100644
--- a/src/inc_internal/maat_ip.h
+++ b/src/inc_internal/maat_ip.h
@@ -42,7 +42,7 @@ long long ip_runtime_ipv6_rule_count(void *ip_runtime);
/* ip runtime scan API */
int ip_runtime_scan(struct ip_runtime *ip_rt, int thread_id, int ip_type,
- uint8_t *ip_addr, int vtable_id, struct maat_state *state);
+ uint8_t *ip_addr, int port, int vtable_id, struct maat_state *state);
void ip_runtime_perf_stat(struct ip_runtime *ip_rt, struct timespec *start,
struct timespec *end, int thread_id);
diff --git a/src/inc_internal/maat_redis_monitor.h b/src/inc_internal/maat_redis_monitor.h
index a2037b5..dff8933 100644
--- a/src/inc_internal/maat_redis_monitor.h
+++ b/src/inc_internal/maat_redis_monitor.h
@@ -22,6 +22,7 @@ extern "C"
#include "log/log.h"
#include "hiredis/hiredis.h"
#include "maat_command.h"
+#include "maat_limits.h"
#include "uthash/uthash.h"
struct foreign_key {
diff --git a/src/inc_internal/maat_rule.h b/src/inc_internal/maat_rule.h
index 9d69c55..ae84de8 100644
--- a/src/inc_internal/maat_rule.h
+++ b/src/inc_internal/maat_rule.h
@@ -126,7 +126,6 @@ struct maat_options {
int maat_json_is_gzipped;
int gc_timeout_ms;
- int rule_effect_interval_ms;
int rule_update_checking_interval_ms;
enum maat_expr_engine expr_engine;
diff --git a/src/inc_internal/maat_table.h b/src/inc_internal/maat_table.h
index f8a0616..964c744 100644
--- a/src/inc_internal/maat_table.h
+++ b/src/inc_internal/maat_table.h
@@ -29,7 +29,7 @@ enum table_type {
TABLE_TYPE_FLAG_PLUS,
TABLE_TYPE_EXPR,
TABLE_TYPE_EXPR_PLUS,
- TABLE_TYPE_IP_PLUS,
+ TABLE_TYPE_IP,
TABLE_TYPE_INTERVAL,
TABLE_TYPE_INTERVAL_PLUS,
TABLE_TYPE_PLUGIN,
diff --git a/src/json2iris.c b/src/json2iris.c
index 975db56..4c7e533 100644
--- a/src/json2iris.c
+++ b/src/json2iris.c
@@ -150,7 +150,7 @@ static int set_iris_descriptor(const char *json_file, cJSON *json,
maat_kv_register(iris_cfg->str2int_map, "flag", TABLE_TYPE_FLAG);
maat_kv_register(iris_cfg->str2int_map, "flag_plus", TABLE_TYPE_FLAG_PLUS);
- maat_kv_register(iris_cfg->str2int_map, "ip_plus", TABLE_TYPE_IP_PLUS);
+ maat_kv_register(iris_cfg->str2int_map, "ip", TABLE_TYPE_IP);
maat_kv_register(iris_cfg->str2int_map, "string", TABLE_TYPE_EXPR);
maat_kv_register(iris_cfg->str2int_map, "expr", TABLE_TYPE_EXPR);
maat_kv_register(iris_cfg->str2int_map, "expr_plus", TABLE_TYPE_EXPR_PLUS);
@@ -503,7 +503,7 @@ static int write_expr_line(cJSON *region_json, struct iris_description *p_iris,
json_cmd, cmd_cnt, table, logger);
}
-static int write_ip_plus_line(cJSON *region_json, struct iris_description *p_iris,
+static int write_ip_line(cJSON *region_json, struct iris_description *p_iris,
struct iris_table *table, struct log_handle *logger)
{
struct translate_command json_cmd[MAX_COLUMN_NUM];
@@ -541,6 +541,12 @@ static int write_ip_plus_line(cJSON *region_json, struct iris_description *p_iri
json_cmd[cmd_cnt].default_string = "255.255.255.255";
cmd_cnt++;
+ json_cmd[cmd_cnt].json_string = "port";
+ json_cmd[cmd_cnt].json_type = cJSON_String;
+ json_cmd[cmd_cnt].empty_allowed = 1;
+ json_cmd[cmd_cnt].default_string = "0-65535";
+ cmd_cnt++;
+
json_cmd[cmd_cnt].json_string = "is_valid";
json_cmd[cmd_cnt].json_type = cJSON_Number;
cmd_cnt++;
@@ -642,8 +648,8 @@ static int write_region_rule(cJSON *region_json, int compile_id, int group_id,
case TABLE_TYPE_EXPR_PLUS:
ret = write_expr_line(table_content, p_iris, table_info, logger);
break;
- case TABLE_TYPE_IP_PLUS:
- ret = write_ip_plus_line(table_content, p_iris, table_info, logger);
+ case TABLE_TYPE_IP:
+ ret = write_ip_line(table_content, p_iris, table_info, logger);
break;
case TABLE_TYPE_INTERVAL:
case TABLE_TYPE_INTERVAL_PLUS:
@@ -701,7 +707,7 @@ static int write_group2group_line(int group_id, UT_array *incl_sub_group_ids,
UT_array *excl_sub_group_ids,
struct iris_description *p_iris)
{
- char buff[MAX_BUFF_LEN] = {0};
+ char buff[MAX_BUFF_LEN*4] = {0};
struct iris_table *table = p_iris->group2group_table;
if (NULL == table) {
return -1;
diff --git a/src/maat_api.c b/src/maat_api.c
index ba70a5d..677e351 100644
--- a/src/maat_api.c
+++ b/src/maat_api.c
@@ -72,7 +72,6 @@ struct maat_options* maat_options_new(void)
options->nr_worker_thread = 1;
options->deferred_load_on = 0;
- options->rule_effect_interval_ms = 60 * 1000;
options->rule_update_checking_interval_ms = 1 * 1000;
options->gc_timeout_ms = 10 * 1000;
options->input_mode = DATA_SOURCE_NONE;
@@ -111,16 +110,6 @@ int maat_options_set_accept_tags(struct maat_options *opts, const char *accept_t
return 0;
}
-int maat_options_set_rule_effect_interval_ms(struct maat_options *opts, int interval_ms)
-{
- if (NULL == opts || interval_ms < 0) {
- return -1;
- }
-
- opts->rule_effect_interval_ms = interval_ms;
- return 0;
-}
-
int maat_options_set_rule_update_checking_interval_ms(struct maat_options *opts, int interval_ms)
{
if (NULL == opts || interval_ms < 0) {
@@ -387,8 +376,7 @@ struct maat *maat_new(struct maat_options *opts, const char *table_info_path)
maat_inst->maat_version = 0;
maat_inst->last_full_version = 0;
- garbage_gc_timeout_s = (maat_inst->opts.rule_effect_interval_ms / 1000) +
- (maat_inst->opts.gc_timeout_ms / 1000);
+ garbage_gc_timeout_s = MAX(1, (maat_inst->opts.gc_timeout_ms / 1000) );
if (maat_inst->opts.input_mode != DATA_SOURCE_IRIS_FILE &&
maat_inst->opts.input_mode != DATA_SOURCE_JSON_FILE &&
@@ -429,6 +417,7 @@ struct maat *maat_new(struct maat_options *opts, const char *table_info_path)
pthread_create(&(maat_inst->cfg_mon_thread), NULL, rule_monitor_loop, (void *)maat_inst);
return maat_inst;
+
failed:
_maat_free(maat_inst);
return NULL;
@@ -1079,12 +1068,12 @@ static int interval_scan(struct table_manager *tbl_mgr, int thread_id, long long
return group_hit_cnt;
}
-static int ipv4_scan(struct table_manager *tbl_mgr, int thread_id, uint32_t ip_addr,
+static int ipv4_scan(struct table_manager *tbl_mgr, int thread_id, uint32_t ip_addr, int port,
int phy_table_id, int vtable_id, struct maat_state *state)
{
enum table_type table_type = table_manager_get_table_type(tbl_mgr, phy_table_id);
- if (table_type != TABLE_TYPE_IP_PLUS) {
+ if (table_type != TABLE_TYPE_IP) {
return -1;
}
@@ -1094,7 +1083,7 @@ static int ipv4_scan(struct table_manager *tbl_mgr, int thread_id, uint32_t ip_a
}
int group_hit_cnt = ip_runtime_scan((struct ip_runtime *)ip_rt, thread_id, IPv4,
- (uint8_t *)&ip_addr, vtable_id, state);
+ (uint8_t *)&ip_addr, port, vtable_id, state);
if (group_hit_cnt <= 0) {
return group_hit_cnt;
}
@@ -1105,12 +1094,12 @@ static int ipv4_scan(struct table_manager *tbl_mgr, int thread_id, uint32_t ip_a
}
static int ipv6_scan(struct table_manager *tbl_mgr, int thread_id,
- uint8_t *ip_addr, int phy_table_id, int vtable_id,
+ uint8_t *ip_addr, int port, int phy_table_id, int vtable_id,
struct maat_state *state)
{
enum table_type table_type = table_manager_get_table_type(tbl_mgr, phy_table_id);
- if (table_type != TABLE_TYPE_IP_PLUS) {
+ if (table_type != TABLE_TYPE_IP) {
return -1;
}
@@ -1120,7 +1109,7 @@ static int ipv6_scan(struct table_manager *tbl_mgr, int thread_id,
}
int group_hit_cnt = ip_runtime_scan((struct ip_runtime *)ip_rt, thread_id, IPv6,
- ip_addr, vtable_id, state);
+ ip_addr, port, vtable_id, state);
if (group_hit_cnt <= 0) {
return group_hit_cnt;
}
@@ -1349,7 +1338,7 @@ int maat_scan_integer(struct maat *maat_inst, int table_id,
}
}
-int maat_scan_ipv4(struct maat *maat_inst, int table_id, uint32_t ip_addr,
+int maat_scan_ipv4_port(struct maat *maat_inst, int table_id, uint32_t ip_addr, int port,
long long *results, size_t n_result, size_t *n_hit_result,
struct maat_state *state)
{
@@ -1387,13 +1376,13 @@ int maat_scan_ipv4(struct maat *maat_inst, int table_id, uint32_t ip_addr,
}
table_type = table_manager_get_table_type(maat_inst->tbl_mgr, phy_table_id);
- if (table_type != TABLE_TYPE_IP_PLUS) {
+ if (table_type != TABLE_TYPE_IP) {
maat_inst->stat->scan_err_cnt++;
return MAAT_SCAN_ERR;
}
alignment_int64_array_add(maat_inst->stat->thread_call_cnt, state->thread_id, 1);
- int hit_group_cnt = ipv4_scan(maat_inst->tbl_mgr, state->thread_id, ip_addr,
+ int hit_group_cnt = ipv4_scan(maat_inst->tbl_mgr, state->thread_id, ip_addr, port,
phy_table_id, vtable_id, state);
if (hit_group_cnt < 0) {
maat_inst->stat->scan_err_cnt++;
@@ -1434,7 +1423,7 @@ int maat_scan_ipv4(struct maat *maat_inst, int table_id, uint32_t ip_addr,
}
}
-int maat_scan_ipv6(struct maat *maat_inst, int table_id, uint8_t *ip_addr,
+int maat_scan_ipv6_port(struct maat *maat_inst, int table_id, uint8_t *ip_addr, int port,
long long *results, size_t n_result, size_t *n_hit_result,
struct maat_state *state)
{
@@ -1472,13 +1461,13 @@ int maat_scan_ipv6(struct maat *maat_inst, int table_id, uint8_t *ip_addr,
}
table_type = table_manager_get_table_type(maat_inst->tbl_mgr, phy_table_id);
- if (table_type != TABLE_TYPE_IP_PLUS) {
+ if (table_type != TABLE_TYPE_IP) {
maat_inst->stat->scan_err_cnt++;
return MAAT_SCAN_ERR;
}
alignment_int64_array_add(maat_inst->stat->thread_call_cnt, state->thread_id, 1);
- int hit_group_cnt = ipv6_scan(maat_inst->tbl_mgr, state->thread_id, ip_addr,
+ int hit_group_cnt = ipv6_scan(maat_inst->tbl_mgr, state->thread_id, ip_addr, port,
phy_table_id, vtable_id, state);
if (hit_group_cnt < 0) {
maat_inst->stat->scan_err_cnt++;
@@ -1518,7 +1507,19 @@ int maat_scan_ipv6(struct maat *maat_inst, int table_id, uint8_t *ip_addr,
return MAAT_SCAN_OK;
}
}
-
+#define PORT_IGNORED -1
+inline int maat_scan_ipv6(struct maat *instance, int table_id, uint8_t *ip_addr,
+ long long *results, size_t n_result, size_t *n_hit_result,
+ struct maat_state *state)
+{
+ return maat_scan_ipv6_port(instance, table_id, ip_addr, PORT_IGNORED, results, n_result, n_hit_result, state);
+}
+inline int maat_scan_ipv4(struct maat *instance, int table_id, uint32_t ip_addr,
+ long long *results, size_t n_result, size_t *n_hit_result,
+ struct maat_state *state)
+{
+ return maat_scan_ipv4_port(instance, table_id, ip_addr, PORT_IGNORED, results, n_result, n_hit_result, state);
+}
int maat_scan_string(struct maat *maat_inst, int table_id,
const char *data, size_t data_len,
long long *results, size_t n_result,
diff --git a/src/maat_ip.c b/src/maat_ip.c
index 3038270..02616a0 100644
--- a/src/maat_ip.c
+++ b/src/maat_ip.c
@@ -31,6 +31,7 @@ struct ip_schema {
int ip1_column;
int ip2_column;
int table_id;
+ int port_column;
struct table_manager *ref_tbl_mgr;
};
@@ -53,6 +54,8 @@ struct ip_item {
struct ipv6_item_rule ipv6;
};
enum ip_format ip_format;
+ int port_start;
+ int port_end;
};
struct ip_runtime {
@@ -158,6 +161,12 @@ void *ip_schema_new(cJSON *json, struct table_manager *tbl_mgr,
goto error;
}
+ custom_item = cJSON_GetObjectItem(item, "port");
+ if (custom_item != NULL && custom_item->type == cJSON_Number) {
+ ip_schema->port_column = custom_item->valueint;
+ } else {
+ ip_schema->port_column = 0;
+ }
ip_schema->ref_tbl_mgr = tbl_mgr;
return ip_schema;
error:
@@ -275,7 +284,33 @@ ip_item_new(struct ip_schema *ip_schema, const char *table_name,
goto error;
}
}
-
+ if(ip_schema->port_column>0)
+ {
+ ret = get_column_pos(line, ip_schema->port_column, &column_offset,
+ &column_len);
+ if (ret < 0) {
+ log_fatal(logger, MODULE_IP,
+ "[%s:%d] ip table:<%s> has no port in line:%s",
+ __FUNCTION__, __LINE__, table_name, line);
+ goto error;
+ }
+ char port_range[20] = {0};
+ memcpy(port_range, (line + column_offset), column_len);
+
+ //port range is port or port_start-port_end
+ if(strchr(port_range,'-')!=NULL){
+ char *port_start = strtok(port_range,"-");
+ char *port_end = strtok(NULL,"-");
+ ip_item->port_start = atoi(port_start);
+ ip_item->port_end = atoi(port_end);
+ } else {
+ ip_item->port_start = atoi(port_range);
+ ip_item->port_end = atoi(port_range);
+ }
+ } else {
+ ip_item->port_start = 0;
+ ip_item->port_end = 65535;
+ }
return ip_item;
error:
FREE(ip_item);
@@ -306,7 +341,6 @@ void *ip_runtime_new(void *ip_schema, size_t max_thread_num,
}
struct ip_runtime *ip_rt = ALLOC(struct ip_runtime, 1);
-
ip_rt->item_hash = rcu_hash_new(ip_item_free_cb, NULL, 0);
ip_rt->n_worker_thread = max_thread_num;
ip_rt->ref_garbage_bin = garbage_bin;
@@ -561,7 +595,7 @@ long long ip_runtime_ipv6_rule_count(void *ip_runtime)
}
int ip_runtime_scan(struct ip_runtime *ip_rt, int thread_id, int ip_type,
- uint8_t *ip_addr, int vtable_id, struct maat_state *state)
+ uint8_t *ip_addr, int port, int vtable_id, struct maat_state *state)
{
if (0 == ip_rt->rule_num) {
//empty ip table
@@ -608,7 +642,16 @@ int ip_runtime_scan(struct ip_runtime *ip_rt, int thread_id, int ip_type,
// item config has been deleted
continue;
}
-
+ if(port < 0 && ip_item->port_start!=0 && ip_item->port_end!=65535)
+ {
+ //If port is not speicified, an IP should NOT match rules with port range.
+ continue;
+ }
+ if(port >= 0 && (port<ip_item->port_start || port>ip_item->port_end)){
+ //If port is specified, the port should within the port range.
+ continue;
+ }
+
hit_maat_items[real_hit_item_cnt].item_id = ip_results[i].rule_id;
hit_maat_items[real_hit_item_cnt].group_id = ip_item->group_id;
real_hit_item_cnt++;
diff --git a/src/maat_rule.c b/src/maat_rule.c
index 88b3492..60769d2 100644
--- a/src/maat_rule.c
+++ b/src/maat_rule.c
@@ -452,94 +452,82 @@ void *rule_monitor_loop(void *arg)
}
usleep(maat_inst->opts.rule_update_checking_interval_ms * 1000);
-
- if (0 == pthread_mutex_trylock(&(maat_inst->background_update_mutex))) {
- switch (maat_inst->opts.input_mode) {
- case DATA_SOURCE_REDIS:
- redis_monitor_traverse(maat_inst->maat_version,
- &(maat_inst->opts.redis_ctx),
- maat_start_cb, maat_update_cb, maat_finish_cb,
- maat_inst);
- break;
- case DATA_SOURCE_IRIS_FILE:
- config_monitor_traverse(maat_inst->maat_version,
- maat_inst->opts.iris_ctx.inc_idx_dir,
- maat_start_cb, maat_update_cb, maat_finish_cb,
- maat_inst, maat_inst->opts.decrypt_key,
- maat_inst->logger);
- break;
- case DATA_SOURCE_JSON_FILE:
- memset(md5_tmp, 0, sizeof(md5_tmp));
- stat(maat_inst->opts.json_ctx.json_file, &attrib);
- if (memcmp(&attrib.st_ctim, &(maat_inst->opts.json_ctx.last_md5_time),
- sizeof(attrib.st_ctim))) {
- maat_inst->opts.json_ctx.last_md5_time = attrib.st_ctim;
- md5_file(maat_inst->opts.json_ctx.json_file, md5_tmp);
- if (0 != strcmp(md5_tmp, maat_inst->opts.json_ctx.effective_json_md5)) {
- ret = load_maat_json_file(maat_inst, maat_inst->opts.json_ctx.json_file,
- err_str, sizeof(err_str));
- if (ret < 0) {
- log_fatal(maat_inst->logger, MODULE_MAAT_RULE,
- "[%s:%d] Maat re-initiate with JSON file %s (md5=%s)failed: %s\n",
- __FUNCTION__, __LINE__, maat_inst->opts.json_ctx.json_file,
- md5_tmp, err_str);
- } else {
- config_monitor_traverse(0, maat_inst->opts.json_ctx.iris_file,
- maat_start_cb, maat_update_cb, maat_finish_cb,
- maat_inst, maat_inst->opts.decrypt_key,
- maat_inst->logger);
- log_info(maat_inst->logger, MODULE_MAAT_RULE,
- "Maat re-initiate with JSON file %s success, md5: %s\n",
- maat_inst->opts.json_ctx.json_file, md5_tmp);
- }
- }
- }
- break;
- default:
- break;
- }
-
- if (maat_inst->creating_maat_rt != NULL) {
- struct maat_runtime *old_maat_rt = maat_inst->maat_rt;
- maat_inst->maat_rt = maat_inst->creating_maat_rt;
-
- if (old_maat_rt != NULL) {
- if (maat_inst->maat_rt->version > old_maat_rt->version) {
- log_info(maat_inst->logger, MODULE_MAAT_RULE,
- "Maat version updated %lld -> %lld\n",
- old_maat_rt->version, maat_inst->maat_rt->version);
- } else {
- log_info(maat_inst->logger, MODULE_MAAT_RULE,
- "Maat version roll back %lld -> %lld\n",
- old_maat_rt->version, maat_inst->maat_rt->version);
+ pthread_mutex_lock(&(maat_inst->background_update_mutex));
+
+ switch (maat_inst->opts.input_mode) {
+ case DATA_SOURCE_REDIS:
+ redis_monitor_traverse(maat_inst->maat_version,
+ &(maat_inst->opts.redis_ctx),
+ maat_start_cb, maat_update_cb, maat_finish_cb,
+ maat_inst);
+ break;
+ case DATA_SOURCE_IRIS_FILE:
+ config_monitor_traverse(maat_inst->maat_version,
+ maat_inst->opts.iris_ctx.inc_idx_dir,
+ maat_start_cb, maat_update_cb, maat_finish_cb,
+ maat_inst, maat_inst->opts.decrypt_key,
+ maat_inst->logger);
+ break;
+ case DATA_SOURCE_JSON_FILE:
+ memset(md5_tmp, 0, sizeof(md5_tmp));
+ stat(maat_inst->opts.json_ctx.json_file, &attrib);
+ if (memcmp(&attrib.st_ctim, &(maat_inst->opts.json_ctx.last_md5_time),
+ sizeof(attrib.st_ctim))) {
+ maat_inst->opts.json_ctx.last_md5_time = attrib.st_ctim;
+ md5_file(maat_inst->opts.json_ctx.json_file, md5_tmp);
+ if (0 != strcmp(md5_tmp, maat_inst->opts.json_ctx.effective_json_md5)) {
+ ret = load_maat_json_file(maat_inst, maat_inst->opts.json_ctx.json_file,
+ err_str, sizeof(err_str));
+ if (ret < 0) {
+ log_fatal(maat_inst->logger, MODULE_MAAT_RULE,
+ "[%s:%d] Maat re-initiate with JSON file %s (md5=%s)failed: %s\n",
+ __FUNCTION__, __LINE__, maat_inst->opts.json_ctx.json_file,
+ md5_tmp, err_str);
+ } else {
+ config_monitor_traverse(0, maat_inst->opts.json_ctx.iris_file,
+ maat_start_cb, maat_update_cb, maat_finish_cb,
+ maat_inst, maat_inst->opts.decrypt_key,
+ maat_inst->logger);
+ log_info(maat_inst->logger, MODULE_MAAT_RULE,
+ "Maat re-initiate with JSON file %s success, md5: %s\n",
+ maat_inst->opts.json_ctx.json_file, md5_tmp);
+ }
}
+ }
+ break;
+ default:
+ break;
+ }
- maat_inst->stat->zombie_rs_stream +=
- alignment_int64_array_sum(old_maat_rt->ref_cnt,
- maat_inst->opts.nr_worker_thread);
- maat_garbage_bagging(maat_inst->garbage_bin, old_maat_rt, NULL,
- garbage_maat_runtime_destroy);
- }
-
- maat_inst->creating_maat_rt = NULL;
- maat_inst->maat_version = maat_inst->maat_rt->version;
- maat_inst->last_full_version = maat_inst->maat_rt->version;
- }
-
- if (maat_inst->maat_rt != NULL) {
- time_t time_window = time(NULL) - maat_inst->maat_rt->last_update_time;
-
- if (time_window >= maat_inst->opts.rule_effect_interval_ms / 1000) {
- maat_runtime_commit(maat_inst->maat_rt, MAAT_UPDATE_TYPE_INC,
- maat_inst->maat_rt->version, maat_inst->logger);
- log_info(maat_inst->logger, MODULE_MAAT_RULE,
- "Actual update config version %u, %d entries load to maat runtime.",
- maat_inst->maat_rt->version, maat_inst->maat_rt->rule_num);
+ if (maat_inst->creating_maat_rt != NULL) {
+ struct maat_runtime *old_maat_rt = maat_inst->maat_rt;
+ maat_inst->maat_rt = maat_inst->creating_maat_rt;
+
+ if (old_maat_rt != NULL) {
+ if (maat_inst->maat_rt->version > old_maat_rt->version) {
+ log_info(maat_inst->logger, MODULE_MAAT_RULE,
+ "Maat version updated %lld -> %lld\n",
+ old_maat_rt->version, maat_inst->maat_rt->version);
+ } else {
+ log_info(maat_inst->logger, MODULE_MAAT_RULE,
+ "Maat version roll back %lld -> %lld\n",
+ old_maat_rt->version, maat_inst->maat_rt->version);
}
- }
- pthread_mutex_unlock(&(maat_inst->background_update_mutex));
- }
+ maat_inst->stat->zombie_rs_stream +=
+ alignment_int64_array_sum(old_maat_rt->ref_cnt,
+ maat_inst->opts.nr_worker_thread);
+ maat_garbage_bagging(maat_inst->garbage_bin, old_maat_rt, NULL,
+ garbage_maat_runtime_destroy);
+ }
+
+ maat_inst->creating_maat_rt = NULL;
+ maat_inst->maat_version = maat_inst->maat_rt->version;
+ maat_inst->last_full_version = maat_inst->maat_rt->version;
+ }
+
+ pthread_mutex_unlock(&(maat_inst->background_update_mutex));
+
maat_garbage_collect_routine(maat_inst->garbage_bin);
maat_plugin_table_garbage_collect_routine(maat_inst->tbl_mgr);
diff --git a/src/maat_stat.c b/src/maat_stat.c
index 4844001..48db6c6 100644
--- a/src/maat_stat.c
+++ b/src/maat_stat.c
@@ -283,7 +283,7 @@ static void fs_table_row_output(FILE *fp, struct maat_stat *stat, int perf_on)
case TABLE_TYPE_EXPR_PLUS:
regex_rule_num = expr_runtime_regex_rule_count(runtime);
break;
- case TABLE_TYPE_IP_PLUS:
+ case TABLE_TYPE_IP:
ipv6_rule_num = ip_runtime_ipv6_rule_count(runtime);
break;
default:
@@ -350,7 +350,7 @@ static void fs_table_row_output(FILE *fp, struct maat_stat *stat, int perf_on)
total_hit_pattern_num += hit_pattern_num;
}
- if (table_type == TABLE_TYPE_IP_PLUS) {
+ if (table_type == TABLE_TYPE_IP) {
fieldstat_easy_counter_set(stat->fs_handle, 0,
stat->fs_column_id[COLUMN_REGEX_NUM],
&cell_tag, 1, ipv6_rule_num);
diff --git a/src/maat_table.c b/src/maat_table.c
index 690212b..3240a11 100644
--- a/src/maat_table.c
+++ b/src/maat_table.c
@@ -155,7 +155,7 @@ struct table_operations table_ops[TABLE_TYPE_MAX] = {
.update_err_count = expr_runtime_update_err_count
},
{
- .type = TABLE_TYPE_IP_PLUS,
+ .type = TABLE_TYPE_IP,
.new_schema = ip_schema_new,
.free_schema = ip_schema_free,
.new_runtime = ip_runtime_new,
@@ -499,7 +499,7 @@ static void register_reserved_word(struct maat_kv_store *reserved_word_map)
maat_kv_register(reserved_word_map, "expr_plus", TABLE_TYPE_EXPR_PLUS);
maat_kv_register(reserved_word_map, "interval", TABLE_TYPE_INTERVAL);
maat_kv_register(reserved_word_map, "interval_plus", TABLE_TYPE_INTERVAL_PLUS);
- maat_kv_register(reserved_word_map, "ip_plus", TABLE_TYPE_IP_PLUS);
+ maat_kv_register(reserved_word_map, "ip", TABLE_TYPE_IP);
maat_kv_register(reserved_word_map, "plugin", TABLE_TYPE_PLUGIN);
maat_kv_register(reserved_word_map, "ip_plugin", TABLE_TYPE_IP_PLUGIN);
maat_kv_register(reserved_word_map, "ipport_plugin", TABLE_TYPE_IPPORT_PLUGIN);
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 9d31201..7115bc8 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -16,10 +16,10 @@ target_link_libraries(rcu_hash_gtest maat_frame_static gtest_static)
add_executable(maat_input_mode_gtest maat_input_mode_gtest.cpp)
target_link_libraries(maat_input_mode_gtest maat_frame_static gtest_static)
-add_executable(maat_framework_gtest maat_framework_gtest.cpp)
+add_executable(maat_framework_gtest maat_framework_gtest.cpp test_utils.cpp)
target_link_libraries(maat_framework_gtest maat_frame_static gtest_static)
-add_executable(maat_framework_perf_gtest maat_framework_perf_gtest.cpp)
+add_executable(maat_framework_perf_gtest maat_framework_perf_gtest.cpp test_utils.cpp)
target_link_libraries(maat_framework_perf_gtest maat_frame_static gtest_static)
add_executable(expr_matcher_gtest expr_matcher_gtest.cpp)
@@ -41,11 +41,12 @@ add_subdirectory(group_exclude)
add_subdirectory(ipport_plugin)
add_subdirectory(benchmark)
-file(COPY table_info.conf DESTINATION ./)
-file(COPY tsg_table_info.conf DESTINATION ./)
-file(COPY file_test_tableinfo.conf DESTINATION ./)
-file(COPY expr_matcher.conf DESTINATION ./)
-file(COPY maat_json.json DESTINATION ./)
+configure_file(table_info.conf table_info.conf COPYONLY)
+configure_file(tsg_table_info.conf tsg_table_info.conf COPYONLY)
+configure_file(file_test_tableinfo.conf file_test_tableinfo.conf COPYONLY)
+configure_file(expr_matcher.conf expr_matcher.conf COPYONLY)
+configure_file(maat_json.json maat_json.json COPYONLY)
+
file(COPY ntcrule DESTINATION ./)
file(COPY tsgrule DESTINATION ./)
file(COPY testdata DESTINATION ./)
diff --git a/test/benchmark/benchmark_hs_gtest.cpp b/test/benchmark/benchmark_hs_gtest.cpp
index 289af24..87633cd 100644
--- a/test/benchmark/benchmark_hs_gtest.cpp
+++ b/test/benchmark/benchmark_hs_gtest.cpp
@@ -27,7 +27,7 @@
#define PERF_THREAD_NUM 5
#define MAX_SCAN_TIMES 1000000
-const char *table_info_path = "./benchmark_table_info.conf";
+const char *g_table_info_path = "./benchmark_table_info.conf";
struct log_handle *g_logger = NULL;
struct thread_param {
@@ -547,11 +547,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -639,11 +638,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -731,11 +729,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -823,11 +820,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -915,11 +911,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1007,11 +1002,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1099,11 +1093,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1191,11 +1184,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1283,11 +1275,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1375,11 +1366,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1468,11 +1458,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1561,11 +1550,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1654,11 +1642,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1747,11 +1734,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1840,11 +1826,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1933,11 +1918,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2026,11 +2010,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2119,11 +2102,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2212,11 +2194,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2302,11 +2283,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2392,11 +2372,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2482,11 +2461,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2572,11 +2550,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2662,11 +2639,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2752,11 +2728,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2842,11 +2817,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2932,9 +2906,8 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -3023,9 +2996,8 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -3114,9 +3086,8 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -3205,9 +3176,8 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -3296,9 +3266,8 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -3387,9 +3356,8 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -3478,9 +3446,8 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -3569,9 +3536,8 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -3660,9 +3626,8 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -3751,9 +3716,8 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -3842,9 +3806,8 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -3933,9 +3896,8 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -4024,9 +3986,8 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -4115,9 +4076,8 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -4206,9 +4166,8 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
diff --git a/test/benchmark/benchmark_rs_gtest.cpp b/test/benchmark/benchmark_rs_gtest.cpp
index 0432dac..48f2954 100644
--- a/test/benchmark/benchmark_rs_gtest.cpp
+++ b/test/benchmark/benchmark_rs_gtest.cpp
@@ -27,7 +27,7 @@
#define PERF_THREAD_NUM 5
#define MAX_scan_times 1000000
-const char *table_info_path = "./benchmark_table_info.conf";
+const char *g_table_info_path = "./benchmark_table_info.conf";
struct log_handle *g_logger = NULL;
struct thread_param {
@@ -547,11 +547,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -639,11 +638,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -731,11 +729,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -824,11 +821,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -917,11 +913,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1009,12 +1004,11 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
- maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
+ maat_options_set_iris(opts, "./", "./");
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1103,11 +1097,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1196,11 +1189,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1289,11 +1281,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1382,11 +1373,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1475,11 +1465,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1567,12 +1556,11 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
- maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
+ maat_options_set_iris(opts, "./", "./");
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1658,11 +1646,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1748,11 +1735,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1838,11 +1824,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -1928,11 +1913,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2018,11 +2002,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2108,11 +2091,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2198,11 +2180,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2287,12 +2268,11 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
- maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
+ maat_options_set_iris(opts, "./", "./");
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2380,12 +2360,11 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
- maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
+ maat_options_set_iris(opts, "./", "./");
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2474,11 +2453,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2566,12 +2544,11 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
- maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
+ maat_options_set_iris(opts, "./", "./");
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2660,11 +2637,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2753,11 +2729,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2846,11 +2821,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2939,11 +2913,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -3032,10 +3005,9 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -3124,11 +3096,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -3217,11 +3188,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -3310,11 +3280,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -3403,11 +3372,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -3496,11 +3464,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -3589,11 +3556,10 @@ protected:
struct maat_options *opts = maat_options_new();
maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO);
maat_options_set_iris(opts, "./", "./");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
diff --git a/test/benchmark/benchmark_table_info.conf b/test/benchmark/benchmark_table_info.conf
index 89485e7..051dcf7 100644
--- a/test/benchmark/benchmark_table_info.conf
+++ b/test/benchmark/benchmark_table_info.conf
@@ -128,7 +128,7 @@
{
"table_id":10,
"table_name":"IP_1K",
- "table_type":"ip_plus",
+ "table_type":"ip",
"valid_column":11,
"custom": {
"item_id":1,
@@ -146,7 +146,7 @@
{
"table_id":11,
"table_name":"IP_5K",
- "table_type":"ip_plus",
+ "table_type":"ip",
"valid_column":11,
"custom": {
"item_id":1,
@@ -164,7 +164,7 @@
{
"table_id":12,
"table_name":"IP_10K",
- "table_type":"ip_plus",
+ "table_type":"ip",
"valid_column":11,
"custom": {
"item_id":1,
@@ -182,7 +182,7 @@
{
"table_id":13,
"table_name":"IP_50K",
- "table_type":"ip_plus",
+ "table_type":"ip",
"valid_column":11,
"custom": {
"item_id":1,
@@ -200,7 +200,7 @@
{
"table_id":14,
"table_name":"IP_100K",
- "table_type":"ip_plus",
+ "table_type":"ip",
"valid_column":11,
"custom": {
"item_id":1,
@@ -218,7 +218,7 @@
{
"table_id":15,
"table_name":"IP_500K",
- "table_type":"ip_plus",
+ "table_type":"ip",
"valid_column":11,
"custom": {
"item_id":1,
@@ -236,7 +236,7 @@
{
"table_id":16,
"table_name":"IP_1M",
- "table_type":"ip_plus",
+ "table_type":"ip",
"valid_column":11,
"custom": {
"item_id":1,
@@ -254,7 +254,7 @@
{
"table_id":17,
"table_name":"IP_2M",
- "table_type":"ip_plus",
+ "table_type":"ip",
"valid_column":11,
"custom": {
"item_id":1,
@@ -272,7 +272,7 @@
{
"table_id":18,
"table_name":"IP_5M",
- "table_type":"ip_plus",
+ "table_type":"ip",
"valid_column":11,
"custom": {
"item_id":1,
@@ -290,7 +290,7 @@
{
"table_id":19,
"table_name":"IP_10M",
- "table_type":"ip_plus",
+ "table_type":"ip",
"valid_column":11,
"custom": {
"item_id":1,
diff --git a/test/file_test_tableinfo.conf b/test/file_test_tableinfo.conf
index 404de30..c3dff0a 100644
--- a/test/file_test_tableinfo.conf
+++ b/test/file_test_tableinfo.conf
@@ -62,7 +62,7 @@
{
"table_id":5,
"table_name":"NTC_UNIVERSAL_IP",
- "table_type":"ip_plus",
+ "table_type":"ip",
"valid_column":7,
"custom": {
"item_id":1,
@@ -88,7 +88,7 @@
{
"table_id":7,
"table_name":"WHITE_LIST_IP",
- "table_type":"ip_plus",
+ "table_type":"ip",
"valid_column":7,
"custom": {
"item_id":1,
diff --git a/test/group_exclude/group_exclude_gtest.cpp b/test/group_exclude/group_exclude_gtest.cpp
index 21ec5b0..ac69ff2 100644
--- a/test/group_exclude/group_exclude_gtest.cpp
+++ b/test/group_exclude/group_exclude_gtest.cpp
@@ -15,7 +15,7 @@
#define WAIT_FOR_EFFECTIVE_S 2
#define MAX_G2G_SCAN_TIMES (1000 * 1000)
-const char *table_info_path = "./group_exclude_table_info.conf";
+const char *g_table_info_path = "./group_exclude_table_info.conf";
const char *log_file = "./group_exclude_gtest.log";
struct group_item {
@@ -127,7 +127,7 @@ protected:
logger = log_handle_create(log_file, 0);
garbage_bin = maat_garbage_bin_new(60);
- int ret = load_file_to_memory(table_info_path, &json_buff, &json_buff_size);
+ int ret = load_file_to_memory(g_table_info_path, &json_buff, &json_buff_size);
if (ret < 0) {
log_fatal(logger, MODULE_GROUP_EXCLUDE_GTEST, "load_file_to_memory failed.");
assert(0);
diff --git a/test/ipport_plugin/ipport_plugin_gtest.cpp b/test/ipport_plugin/ipport_plugin_gtest.cpp
index 229bf5b..392de72 100644
--- a/test/ipport_plugin/ipport_plugin_gtest.cpp
+++ b/test/ipport_plugin/ipport_plugin_gtest.cpp
@@ -13,7 +13,7 @@
#define ARRAY_SIZE 10
#define PERF_scan_times 1000 * 1000
-const char *table_info_path = "./ipport_plugin_table_info.conf";
+const char *g_table_info_path = "./ipport_plugin_table_info.conf";
const char *log_file = "./ipport_plugin_gtest.log";
const char *g_ip_str = "116.71.169.140";
@@ -376,7 +376,7 @@ TEST_F(IPPortPluginTable, WITHOUT_SAME_IP) {
maat_options_set_stat_file(opts, "./stat.log");
maat_options_set_rule_update_checking_interval_ms(opts, 100);
- struct maat *maat_inst = maat_new(opts, table_info_path);
+ struct maat *maat_inst = maat_new(opts, g_table_info_path);
assert(maat_inst);
maat_options_free(opts);
@@ -445,7 +445,7 @@ TEST_F(IPPortPluginTable, WITH_256SAME_IP) {
maat_options_set_stat_file(opts, "./stat.log");
maat_options_set_rule_update_checking_interval_ms(opts, 100);
- struct maat *maat_inst = maat_new(opts, table_info_path);
+ struct maat *maat_inst = maat_new(opts, g_table_info_path);
assert(maat_inst);
maat_options_free(opts);
diff --git a/test/maat_ex_data_gtest.cpp b/test/maat_ex_data_gtest.cpp
index 0cf2965..93898f0 100644
--- a/test/maat_ex_data_gtest.cpp
+++ b/test/maat_ex_data_gtest.cpp
@@ -9,8 +9,8 @@
#include <gtest/gtest.h>
#include <limits.h>
-const char *table_info_path = "./table_info.conf";
-const char *json_filename = "maat_json.json";
+const char *g_table_info_path = "./table_info.conf";
+const char *g_json_filename = "maat_json.json";
struct log_handle *g_logger = NULL;
struct maat *g_maat_inst = NULL;
@@ -133,7 +133,7 @@ int main(int argc, char ** argv)
char json_iris_path[NAME_MAX] = {0};
char tmp_iris_path[PATH_MAX] = {0};
- snprintf(json_iris_path, sizeof(json_iris_path), "./%s_iris_tmp", json_filename);
+ snprintf(json_iris_path, sizeof(json_iris_path), "./%s_iris_tmp", g_json_filename);
if ((access(json_iris_path, F_OK)) == 0) {
system_cmd_rmdir(json_iris_path);
}
@@ -142,10 +142,10 @@ int main(int argc, char ** argv)
char *json_buff = NULL;
size_t json_buff_sz = 0;
- int ret = load_file_to_memory(json_filename, (unsigned char**)&json_buff, &json_buff_sz);
+ int ret = load_file_to_memory(g_json_filename, (unsigned char**)&json_buff, &json_buff_sz);
EXPECT_NE(ret, -1);
- ret = json2iris(json_buff, json_filename, NULL, tmp_iris_path, sizeof(tmp_iris_path),
+ ret = json2iris(json_buff, g_json_filename, NULL, tmp_iris_path, sizeof(tmp_iris_path),
NULL, NULL, g_logger);
FREE(json_buff);
EXPECT_NE(ret, -1);
@@ -153,10 +153,10 @@ int main(int argc, char ** argv)
struct maat_options *opts = maat_options_new();
char json_path[PATH_MAX] = {0};
- snprintf(json_path, sizeof(json_path), "./%s", json_filename);
+ snprintf(json_path, sizeof(json_path), "./%s", g_json_filename);
maat_options_set_json_file(opts, json_path);
- g_maat_inst = maat_new(opts, table_info_path);
+ g_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
EXPECT_TRUE(g_maat_inst != NULL);
diff --git a/test/maat_framework_gtest.cpp b/test/maat_framework_gtest.cpp
index 56603c4..3c74a01 100644
--- a/test/maat_framework_gtest.cpp
+++ b/test/maat_framework_gtest.cpp
@@ -2,6 +2,7 @@
#include <dirent.h>
#include <openssl/md5.h>
+#include "test_utils.h"
#include "maat.h"
#include "maat_rule.h"
#include "maat_utils.h"
@@ -18,286 +19,12 @@
#define HIT_PATH_SIZE 128
#define WAIT_FOR_EFFECTIVE_S 2
-const char *table_info_path = "./table_info.conf";
-const char *json_path ="./maat_json.json";
-const char *json_filename = "maat_json.json";
+const char *g_table_info_path = "./table_info.conf";
+const char *g_json_filename = "maat_json.json";
size_t g_thread_num = 4;
-int count_line_num_cb(const char *table_name, const char *line, void *u_para)
-{
- (*((unsigned int *)u_para))++;
- return 0;
-}
-
-int line_idx = 0;
-long long absolute_expire_time = 0;
-int make_serial_rule(const char *table_name, const char *line, void *u_para)
-{
- struct serial_rule *s_rule=(struct serial_rule *)u_para;
- redisContext *ctx = s_rule->ref_ctx;
- char *buff = ALLOC(char, strlen(line) + 1);
-
- memcpy(buff, line, strlen(line) + 1);
- while (buff[strlen(line) - 1] == '\n' || buff[strlen(line) - 1] == '\t') {
- buff[strlen(line) - 1] = '\0';
- }
-
- const char *redis_rule_key = "TEST_RULE_KEY";
- redisReply *reply = maat_wrap_redis_command(ctx, NULL, "INCRBY %s %d",
- redis_rule_key, 1);
- if (reply->type == REDIS_REPLY_NIL) {
- printf("incrby redis_rule_key:%s failed.", redis_rule_key);
- return -1;
- } else {
- s_rule->rule_id = maat_read_redis_integer(reply);
- freeReplyObject(reply);
- reply = NULL;
- }
-
- maat_set_serial_rule(s_rule + line_idx, MAAT_OP_ADD, s_rule->rule_id,
- table_name, buff, absolute_expire_time);
- (s_rule + line_idx)->ref_ctx = ctx;
- line_idx++;
-
- FREE(buff);
-
- return 0;
-}
-
-int write_config_to_redis(char *redis_ip, int redis_port, int redis_db,
- struct log_handle *logger)
-{
- char json_iris_path[512] = {0};
-
- snprintf(json_iris_path, sizeof(json_iris_path), "./%s_iris_tmp",
- json_filename);
-
- redisContext *c = maat_connect_redis(redis_ip, redis_port, redis_db, logger);
- if (NULL == c) {
- return -1;
- }
-
- redisReply *reply = maat_wrap_redis_command(c, logger, "flushdb");
- if (NULL == reply) {
- return -1;
- } else {
- freeReplyObject(reply);
- reply = NULL;
- }
-
- if (0 == access(json_iris_path, F_OK)) {
- system_cmd_rmdir(json_iris_path);
- }
-
- if (access(json_iris_path, F_OK) < 0) {
- char tmp_iris_path[128] = {0};
- char *json_buff = NULL;
- size_t json_buff_sz = 0;
-
- int ret = load_file_to_memory(json_filename, (unsigned char **)&json_buff,
- &json_buff_sz);
- if (ret < 0) {
- return -1;
- }
-
- ret = json2iris(json_buff, json_filename, c, tmp_iris_path,
- sizeof(tmp_iris_path), NULL, NULL, logger);
- FREE(json_buff);
- if (ret < 0) {
- return -1;
- }
- }
-
- size_t total_line_cnt = 0;
- char tmp_iris_full_idx_path[PATH_MAX] = {0};
- snprintf(tmp_iris_full_idx_path, sizeof(tmp_iris_full_idx_path), "%s/index",
- json_iris_path);
- config_monitor_traverse(0, tmp_iris_full_idx_path, NULL, count_line_num_cb,
- NULL, &total_line_cnt, NULL, logger);
-
- struct serial_rule *s_rule = ALLOC(struct serial_rule, total_line_cnt);
- s_rule->ref_ctx = c;
- long long server_time = maat_redis_server_time_s(c);
- if (server_time < 0) {
- return -1;
- }
- absolute_expire_time = server_time + 300;
- config_monitor_traverse(0, tmp_iris_full_idx_path, NULL, make_serial_rule,
- NULL, s_rule, NULL, logger);
- s_rule->ref_ctx = NULL;
- line_idx = 0;
- absolute_expire_time = 0;
-
- int success_cnt = 0;
- do {
- success_cnt = maat_cmd_write_rule(c, s_rule, total_line_cnt,
- server_time, logger);
- } while (success_cnt < 0);
-
- EXPECT_EQ(success_cnt, (int)total_line_cnt);
-
- for (size_t i = 0; i < total_line_cnt; i++) {
- maat_clear_rule_cache(s_rule + i);
- }
- FREE(s_rule);
- redisFree(c);
-
- return 0;
-}
-
-int compile_table_set_line(struct maat *maat_inst, const char *table_name,
- enum maat_operation op, long long compile_id,
- const char *user_region, int clause_num,
- int expire_after)
-{
- char table_line[1024 * 16] = {0};
- sprintf(table_line, "%lld\t0\t0\t0\t0\t0\t%s\t%d\t%d\t0.0",
- compile_id, user_region, clause_num, op);
-
- struct maat_cmd_line line_rule;
- line_rule.rule_id = compile_id;
- line_rule.table_line = table_line;
- line_rule.table_name = table_name;
- line_rule.expire_after = expire_after;
-
- return maat_cmd_set_line(maat_inst, &line_rule);
-}
-
-#define TO_GROUP2X_KEY(group_id, parent_id, clause_index) (((unsigned long)group_id<<32|parent_id) + clause_index)
-
-int group2compile_table_set_line(struct maat *maat_inst, const char *table_name,
- enum maat_operation op, long long group_id,
- long long compile_id, int not_flag,
- const char *vtable_name, int clause_index,
- int expire_after)
-{
- char table_line[128] = {0};
- sprintf(table_line, "%lld\t%lld\t%d\t%s\t%d\t%d",
- group_id, compile_id, not_flag, vtable_name, clause_index, op);
-
- struct maat_cmd_line line_rule;
- line_rule.rule_id = TO_GROUP2X_KEY(group_id, compile_id, clause_index);
- line_rule.table_line = table_line;
- line_rule.table_name = table_name;
- line_rule.expire_after = expire_after;
-
- return maat_cmd_set_line(maat_inst, &line_rule);
-}
-
-int group2group_table_set_line(struct maat *maat_inst, const char *table_name,
- enum maat_operation op, long long group_id,
- long long sub_group_id, int expire_after)
-{
- char table_line[128] = {0};
- sprintf(table_line, "%lld\t%lld\t%s\t%d", group_id, sub_group_id,
- "null", op);
-
- struct maat_cmd_line line_rule;
- line_rule.rule_id = TO_GROUP2X_KEY(group_id, sub_group_id, 0);
- line_rule.table_line = table_line;
- line_rule.table_name = table_name;
- line_rule.expire_after = expire_after;
-
- return maat_cmd_set_line(maat_inst, &line_rule);
-}
-
-int expr_table_set_line(struct maat *maat_inst, const char *table_name,
- enum maat_operation op, long long item_id,
- long long group_id, const char *keywords,
- const char *district, int expr_type,
- int match_method, int is_hexbin, int expire_after)
-{
- char table_line[1024] = {0};
- int table_id = maat_get_table_id(maat_inst, table_name);
- if (table_id < 0) {
- return 0;
- }
-
- enum table_type table_type = table_manager_get_table_type(maat_inst->tbl_mgr,
- table_id);
- assert(table_type == TABLE_TYPE_EXPR || table_type == TABLE_TYPE_EXPR_PLUS);
-
- if (table_type == TABLE_TYPE_EXPR_PLUS) {
- sprintf(table_line, "%lld\t%lld\t%s\t%s\t%d\t%d\t%d\t%d",
- item_id, group_id, district, keywords, expr_type,
- match_method, is_hexbin, op);
- } else {
- sprintf(table_line, "%lld\t%lld\t%s\t%d\t%d\t%d\t%d",
- item_id, group_id, keywords, expr_type,
- match_method, is_hexbin, op);
- }
-
- struct maat_cmd_line line_rule;
- line_rule.rule_id = item_id;
- line_rule.table_line = table_line;
- line_rule.table_name = table_name;
- line_rule.expire_after = expire_after;
-
- return maat_cmd_set_line(maat_inst, &line_rule);
-}
-
-int
-interval_table_set_line(struct maat *maat_inst, const char *table_name,
- enum maat_operation op, long long item_id, long long group_id,
- unsigned int low_boundary, unsigned int up_boundary,
- const char *district, int expire_after)
-{
- char table_line[1024] = {0};
- int table_id = maat_get_table_id(maat_inst, table_name);
- if (table_id < 0) {
- return 0;
- }
-
- enum table_type table_type = table_manager_get_table_type(maat_inst->tbl_mgr,
- table_id);
- assert(table_type == TABLE_TYPE_INTERVAL || table_type == TABLE_TYPE_INTERVAL_PLUS);
-
- if (table_type == TABLE_TYPE_INTERVAL_PLUS) {
- sprintf(table_line, "%lld\t%lld\t%s\t%u\t%u\t%d",
- item_id, group_id, district, low_boundary, up_boundary, op);
- } else {
- sprintf(table_line, "%lld\t%lld\t%u\t%u\t%d",
- item_id, group_id, low_boundary, up_boundary, op);
- }
-
- struct maat_cmd_line line_rule;
- line_rule.rule_id = item_id;
- line_rule.table_line = table_line;
- line_rule.table_name = table_name;
- line_rule.expire_after = expire_after;
-
- return maat_cmd_set_line(maat_inst, &line_rule);
-}
-
-int ip_table_set_line(struct maat *maat_inst, const char *table_name,
- enum maat_operation op, long long item_id,
- long long group_id, enum IP_TYPE type, const char *ip1,
- const char *ip2, int expire_after)
-{
- char table_line[1024] = {0};
- int table_id = maat_get_table_id(maat_inst, table_name);
- if (table_id < 0) {
- return 0;
- }
-
- int ip_type = IPV4;
- if (type == IPv6) {
- ip_type = IPV6;
- }
-
- sprintf(table_line, "%lld\t%lld\t%d\t%s\t%s\t%s\t%d",
- item_id, group_id, ip_type, "range", ip1, ip2, op);
- struct maat_cmd_line line_rule;
-
- line_rule.rule_id = item_id;
- line_rule.table_line = table_line;
- line_rule.table_name = table_name;
- line_rule.expire_after = expire_after;
-
- return maat_cmd_set_line(maat_inst, &line_rule);
-}
int test_add_expr_command(struct maat *maat_inst, const char *expr_table,
long long compile_id, int timeout,
@@ -369,7 +96,7 @@ protected:
maat_options_set_json_file_decrypt_key(opts, json_decrypt_key);
maat_options_set_rule_update_checking_interval_ms(opts, scan_interval_ms);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -467,7 +194,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.", __FUNCTION__, __LINE__);
@@ -481,7 +208,7 @@ protected:
maat_options_set_accept_tags(opts, accept_tags);
maat_options_set_hit_path_enabled(opts);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -773,7 +500,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.",
@@ -789,7 +516,7 @@ protected:
maat_options_set_hit_path_enabled(opts);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -1685,7 +1412,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.",
@@ -1701,7 +1428,7 @@ protected:
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
maat_options_set_hit_path_enabled(opts);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -2607,18 +2334,17 @@ protected:
maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
assert(_shared_maat_inst != NULL);
maat_cmd_flushDB(_shared_maat_inst);
maat_free(_shared_maat_inst);
maat_options_set_foreign_cont_dir(opts, "./foreign_files/");
- maat_options_set_rule_effect_interval_ms(opts, 0);
maat_options_set_gc_timeout_ms(opts, 0); // start GC immediately
maat_options_set_stat_file(opts, "./stat.log");
maat_options_set_perf_on(opts);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2721,19 +2447,18 @@ protected:
maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
assert(_shared_maat_inst != NULL);
maat_cmd_flushDB(_shared_maat_inst);
maat_free(_shared_maat_inst);
maat_options_set_foreign_cont_dir(opts, "./foreign_files/");
- maat_options_set_rule_effect_interval_ms(opts, 0);
maat_options_set_gc_timeout_ms(opts, 0); // start GC immediately
maat_options_set_stat_file(opts, "./stat.log");
maat_options_set_perf_on(opts);
maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
}
@@ -2828,7 +2553,7 @@ TEST_F(MaatRsStreamScan, dynamic_config) {
state = NULL;
}
-class MaatIPScan : public testing::Test
+class IPScan : public testing::Test
{
protected:
static void SetUpTestCase() {
@@ -2839,7 +2564,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.",
@@ -2853,11 +2578,11 @@ protected:
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
- "[%s:%d] create maat instance in MaatIPScan failed.",
+ "[%s:%d] create maat instance in IPScan failed.",
__FUNCTION__, __LINE__);
}
}
@@ -2871,12 +2596,12 @@ protected:
static struct maat *_shared_maat_inst;
};
-struct maat *MaatIPScan::_shared_maat_inst;
-struct log_handle *MaatIPScan::logger;
+struct maat *IPScan::_shared_maat_inst;
+struct log_handle *IPScan::logger;
-TEST_F(MaatIPScan, IPv4ScanDataFull_0) {
+TEST_F(IPScan, IPv4Unspecified) {
const char *table_name = "IP_PLUS_CONFIG";
- struct maat *maat_inst = MaatIPScan::_shared_maat_inst;
+ struct maat *maat_inst = IPScan::_shared_maat_inst;
int thread_id = 0;
int table_id = maat_get_table_id(maat_inst, table_name);
@@ -2903,9 +2628,9 @@ TEST_F(MaatIPScan, IPv4ScanDataFull_0) {
state = NULL;
}
-TEST_F(MaatIPScan, IPv4ScanDataFull_1) {
+TEST_F(IPScan, IPv4Broadcast) {
const char *table_name = "IP_PLUS_CONFIG";
- struct maat *maat_inst = MaatIPScan::_shared_maat_inst;
+ struct maat *maat_inst = IPScan::_shared_maat_inst;
int thread_id = 0;
int table_id = maat_get_table_id(maat_inst, table_name);
@@ -2932,9 +2657,9 @@ TEST_F(MaatIPScan, IPv4ScanDataFull_1) {
state = NULL;
}
-TEST_F(MaatIPScan, IPv4RuleFull_0) {
+TEST_F(IPScan, MatchSingleIPv4) {
const char *table_name = "IP_PLUS_CONFIG";
- struct maat *maat_inst = MaatIPScan::_shared_maat_inst;
+ struct maat *maat_inst = IPScan::_shared_maat_inst;
int thread_id = 0;
int table_id = maat_get_table_id(maat_inst, table_name);
@@ -2962,9 +2687,9 @@ TEST_F(MaatIPScan, IPv4RuleFull_0) {
state = NULL;
}
-TEST_F(MaatIPScan, IPv6ScanDataFull_0) {
+TEST_F(IPScan, IPv6Unspecified) {
const char *table_name = "IP_PLUS_CONFIG";
- struct maat *maat_inst = MaatIPScan::_shared_maat_inst;
+ struct maat *maat_inst = IPScan::_shared_maat_inst;
int thread_id = 0;
int table_id = maat_get_table_id(maat_inst, table_name);
@@ -2991,9 +2716,9 @@ TEST_F(MaatIPScan, IPv6ScanDataFull_0) {
maat_state_free(state);
}
-TEST_F(MaatIPScan, IPv6ScanDataFull_1) {
+TEST_F(IPScan, IPv6Broadcast) {
const char *table_name = "IP_PLUS_CONFIG";
- struct maat *maat_inst = MaatIPScan::_shared_maat_inst;
+ struct maat *maat_inst = IPScan::_shared_maat_inst;
int thread_id = 0;
int table_id = maat_get_table_id(maat_inst, table_name);
@@ -3019,9 +2744,9 @@ TEST_F(MaatIPScan, IPv6ScanDataFull_1) {
maat_state_free(state);
}
-TEST_F(MaatIPScan, IPv6RuleFull_0) {
+TEST_F(IPScan, MatchSingleIPv6) {
const char *table_name = "IP_PLUS_CONFIG";
- struct maat *maat_inst = MaatIPScan::_shared_maat_inst;
+ struct maat *maat_inst = IPScan::_shared_maat_inst;
int thread_id = 0;
int table_id = maat_get_table_id(maat_inst, table_name);
@@ -3050,9 +2775,9 @@ TEST_F(MaatIPScan, IPv6RuleFull_0) {
state = NULL;
}
-TEST_F(MaatIPScan, IPv4_IPPort) {
+TEST_F(IPScan, MatchIPv4Range) {
const char *table_name = "IP_PLUS_CONFIG";
- struct maat *maat_inst = MaatIPScan::_shared_maat_inst;
+ struct maat *maat_inst = IPScan::_shared_maat_inst;
int thread_id = 0;
int table_id = maat_get_table_id(maat_inst, table_name);
@@ -3080,10 +2805,39 @@ TEST_F(MaatIPScan, IPv4_IPPort) {
maat_state_free(state);
state = NULL;
}
+TEST_F(IPScan, MatchIPv4Port) {
+ const char *table_name = "IP_PLUS_CONFIG";
+ struct maat *maat_inst = IPScan::_shared_maat_inst;
+ int thread_id = 0;
+
+ int table_id = maat_get_table_id(maat_inst, table_name);
+ ASSERT_GT(table_id, 0);
+
+ char ip_str[32] = "192.168.30.44";
+ uint32_t sip;
+ int ret = inet_pton(AF_INET, ip_str, &sip);
+ EXPECT_EQ(ret, 1);
+
+ long long results[ARRAY_SIZE] = {0};
+ size_t n_hit_result = 0;
+ struct maat_state *state = maat_state_new(maat_inst, thread_id);
+ ret = maat_scan_ipv4_port(maat_inst, table_id, sip, 443, results, ARRAY_SIZE,
+ &n_hit_result, state);
+ EXPECT_EQ(ret, MAAT_SCAN_OK);
+ EXPECT_EQ(n_hit_result, 0);
-TEST_F(MaatIPScan, IPv6_IPPort) {
+ ret = maat_scan_ipv4_port(maat_inst, table_id, sip, 80, results, ARRAY_SIZE,
+ &n_hit_result, state);
+ EXPECT_EQ(ret, MAAT_SCAN_HIT);
+ EXPECT_EQ(n_hit_result, 1);
+ EXPECT_EQ(results[0], 232);
+
+ maat_state_free(state);
+ state = NULL;
+}
+TEST_F(IPScan, MatchIPv6Range) {
const char *table_name = "IP_PLUS_CONFIG";
- struct maat *maat_inst = MaatIPScan::_shared_maat_inst;
+ struct maat *maat_inst = IPScan::_shared_maat_inst;
int thread_id = 0;
int table_id = maat_get_table_id(maat_inst, table_name);
@@ -3109,10 +2863,43 @@ TEST_F(MaatIPScan, IPv6_IPPort) {
maat_state_free(state);
state = NULL;
}
+TEST_F(IPScan, MatchIPv6Port) {
+ const char *table_name = "IP_PLUS_CONFIG";
+ struct maat *maat_inst = IPScan::_shared_maat_inst;
+ int thread_id = 0;
+
+ int table_id = maat_get_table_id(maat_inst, table_name);
+ char ip_str[32] = "2607:5d00:2:2::32:28";
+ int port=443;
+ uint8_t sip[16];
+ int ret = inet_pton(AF_INET6, ip_str, &sip);
+ EXPECT_EQ(ret, 1);
-TEST_F(MaatIPScan, BugReport20210515) {
+ long long results[ARRAY_SIZE] = {0};
+ size_t n_hit_result = 0;
+ struct maat_state *state = maat_state_new(maat_inst, thread_id);
+ ret = maat_scan_ipv6_port(maat_inst, table_id, sip, port, results, ARRAY_SIZE,
+ &n_hit_result, state);
+ EXPECT_EQ(ret, MAAT_SCAN_HIT);
+ EXPECT_EQ(n_hit_result, 2);
+ EXPECT_EQ(results[0], 230);
+ EXPECT_EQ(results[1], 210);
+
+ maat_state_reset(state);
+ //If the port is not present, should not match rules with port range. In this case, only rule 210 "::/0" should match.
+ ret = maat_scan_ipv6(maat_inst, table_id, sip, results, ARRAY_SIZE,
+ &n_hit_result, state);
+ EXPECT_EQ(ret, MAAT_SCAN_HIT);
+ EXPECT_EQ(n_hit_result, 1);
+ EXPECT_EQ(results[0], 210);
+
+ maat_state_free(state);
+ state = NULL;
+}
+
+TEST_F(IPScan, BugReport20210515) {
const char *table_name = "IP_CONFIG";
- struct maat *maat_inst = MaatIPScan::_shared_maat_inst;
+ struct maat *maat_inst = IPScan::_shared_maat_inst;
int thread_id = 0;
int table_id = maat_get_table_id(maat_inst, table_name);
@@ -3136,9 +2923,9 @@ TEST_F(MaatIPScan, BugReport20210515) {
state = NULL;
}
-TEST_F(MaatIPScan, dynamic_config) {
+TEST_F(IPScan, RuleUpdates) {
const char *table_name = "IP_PLUS_CONFIG";
- struct maat *maat_inst = MaatIPScan::_shared_maat_inst;
+ struct maat *maat_inst = IPScan::_shared_maat_inst;
int thread_id = 0;
int table_id = maat_get_table_id(maat_inst, table_name);
@@ -3236,7 +3023,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.", __FUNCTION__, __LINE__);
@@ -3249,7 +3036,7 @@ protected:
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -3372,7 +3159,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.", __FUNCTION__, __LINE__);
@@ -3385,7 +3172,7 @@ protected:
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -3471,7 +3258,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.",
@@ -3485,7 +3272,7 @@ protected:
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -4730,7 +4517,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.",
@@ -4744,7 +4531,7 @@ protected:
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -5117,7 +4904,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.",
@@ -5131,7 +4918,7 @@ protected:
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_DEBUG);
maat_options_set_accept_tags(opts, accept_tags);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -5381,7 +5168,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.",
@@ -5395,7 +5182,7 @@ protected:
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -5521,7 +5308,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.",
@@ -5535,7 +5322,7 @@ protected:
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -5661,7 +5448,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.",
@@ -5675,7 +5462,7 @@ protected:
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -5832,7 +5619,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.",
@@ -5846,7 +5633,7 @@ protected:
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -5919,7 +5706,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.",
@@ -5933,7 +5720,7 @@ protected:
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -5985,7 +5772,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.",
@@ -6000,7 +5787,7 @@ protected:
maat_options_set_accept_tags(opts, accept_tags);
maat_options_set_hit_path_enabled(opts);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -6138,7 +5925,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.",
@@ -6153,7 +5940,7 @@ protected:
maat_options_set_accept_tags(opts, accept_tags);
maat_options_set_hit_path_enabled(opts);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -6320,7 +6107,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.",
@@ -6335,7 +6122,7 @@ protected:
maat_options_set_accept_tags(opts, accept_tags);
maat_options_set_hit_path_enabled(opts);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -6732,7 +6519,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.",
@@ -6746,7 +6533,7 @@ protected:
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -6806,8 +6593,6 @@ protected:
static void SetUpTestCase() {
const char *rule_folder = "./ntcrule/full/index";
const char *table_info = "./file_test_tableinfo.conf";
- int scan_interval_ms = 500;
- int effective_interval_ms = 0;
struct maat_options *opts = maat_options_new();
maat_options_set_caller_thread_number(opts, g_thread_num);
@@ -6815,8 +6600,7 @@ protected:
maat_options_set_stat_file(opts, "./stat.log");
maat_options_set_perf_on(opts);
maat_options_set_iris(opts, rule_folder, rule_folder);
- maat_options_set_rule_update_checking_interval_ms(opts, scan_interval_ms);
- maat_options_set_rule_effect_interval_ms(opts, effective_interval_ms);
+ maat_options_set_rule_update_checking_interval_ms(opts, 500);
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
_shared_maat_inst = maat_new(opts, table_info);
@@ -6909,7 +6693,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.",
@@ -6923,7 +6707,7 @@ protected:
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -7282,15 +7066,14 @@ protected:
maat_options_set_hit_path_enabled(opts);
maat_options_set_hit_group_enabled(opts);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
assert(_shared_maat_inst != NULL);
maat_cmd_flushDB(_shared_maat_inst);
maat_free(_shared_maat_inst);
maat_options_set_foreign_cont_dir(opts, "./foreign_files/");
- maat_options_set_rule_effect_interval_ms(opts, 1000);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
_ex_data_counter = ALLOC(int, 1);
@@ -11207,7 +10990,7 @@ protected:
int redis_db = 0;
logger = log_handle_create("./maat_framework_gtest.log", 0);
- int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.", __FUNCTION__, __LINE__);
@@ -11220,7 +11003,7 @@ protected:
maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO);
maat_options_set_accept_tags(opts, accept_tags);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_GTEST,
@@ -11368,7 +11151,7 @@ TEST_F(MaatRollbackTest, FullConfigRollback) {
ret = clear_config_in_redis(c, logger);
EXPECT_EQ(ret, 0);
- ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
EXPECT_EQ(ret, 0);
ret = rollback_redis_version(c, logger);
@@ -11428,7 +11211,7 @@ TEST_F(MaatRollbackTest, FullConfigRollbackWhenScanUnfinished) {
ret = clear_config_in_redis(c, logger);
EXPECT_EQ(ret, 0);
- ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
+ ret = write_json_to_redis(g_json_filename, redis_ip, redis_port, redis_db, logger);
EXPECT_EQ(ret, 0);
ret = rollback_redis_version(c, logger);
diff --git a/test/maat_framework_perf_gtest.cpp b/test/maat_framework_perf_gtest.cpp
index 8c1fded..d7f3181 100644
--- a/test/maat_framework_perf_gtest.cpp
+++ b/test/maat_framework_perf_gtest.cpp
@@ -1,5 +1,6 @@
#include <gtest/gtest.h>
+#include "test_utils.h"
#include "log/log.h"
#include "maat.h"
#include "maat_rule.h"
@@ -17,8 +18,8 @@
#define PERF_THREAD_NUM 5
#define PERF_SCAN_TIMES 1000 * 1000
-const char *table_info_path = "./table_info.conf";
-const char *json_filename = "maat_json.json";
+const char *g_table_info_path = "./table_info.conf";
+const char *g_json_filename = "maat_json.json";
struct thread_param {
int thread_id;
@@ -40,282 +41,7 @@ void random_keyword_generate(char *keyword_buf, size_t sz)
keyword_buf[i] = '\0';
}
-int count_line_num_cb(const char *table_name, const char *line, void *u_para)
-{
- (*((unsigned int *)u_para))++;
- return 0;
-}
-
-int line_idx = 0;
-long long absolute_expire_time=0;
-int make_serial_rule(const char *table_name, const char *line, void *u_para)
-{
- struct serial_rule *s_rule=(struct serial_rule *)u_para;
- long long rule_id = 0;
- char *buff = ALLOC(char, strlen(line) + 1);
-
- memcpy(buff, line, strlen(line) + 1);
- while (buff[strlen(buff) - 1] == '\n' || buff[strlen(buff) - 1] == '\t') {
- buff[strlen(buff) - 1] = '\0';
- }
-
- int j = 0;
- char *str1 = NULL;
- char *token = NULL;
- char *saveptr1 = NULL;
-
- for (j = 0,str1 = buff; ; j++, str1 = NULL) {
- token = strtok_r(str1, "\t ", &saveptr1);
- if (token == NULL)
- break;
- if (j == 0) {
- sscanf(token,"%lld", &rule_id);
- }
- }
-
- memcpy(buff, line, strlen(line)+1);
- while(buff[strlen(buff)-1]=='\n'||buff[strlen(buff)-1]=='\t') {
- buff[strlen(buff)-1]='\0';
- }
-
- maat_set_serial_rule(s_rule + line_idx, MAAT_OP_ADD, rule_id, table_name,
- buff, absolute_expire_time);
- line_idx++;
-
- FREE(buff);
-
- return 0;
-}
-
-static int
-write_config_to_redis(const char *json_iris_path,
- char *redis_ip, int redis_port,
- int redis_db, struct log_handle *logger)
-{
- redisContext *c =
- maat_connect_redis(redis_ip, redis_port, redis_db, logger);
- if (NULL == c) {
- return -1;
- }
-
- redisReply *reply = maat_wrap_redis_command(c, logger, "flushdb");
- if (NULL == reply) {
- return -1;
- } else {
- freeReplyObject(reply);
- reply = NULL;
- }
-
- if (access(json_iris_path, F_OK) < 0) {
- char tmp_iris_path[128] = {0};
- char *json_buff = NULL;
- size_t json_buff_sz = 0;
-
- int ret = load_file_to_memory(json_filename,
- (unsigned char **)&json_buff,
- &json_buff_sz);
- if (ret < 0) {
- return -1;
- }
-
- ret = json2iris(json_buff, json_filename, c, tmp_iris_path,
- sizeof(tmp_iris_path), NULL, NULL, logger);
- FREE(json_buff);
- if (ret < 0) {
- return -1;
- }
- }
-
- size_t total_line_cnt = 0;
- char tmp_iris_full_idx_path[PATH_MAX] = {0};
- snprintf(tmp_iris_full_idx_path, sizeof(tmp_iris_full_idx_path),
- "%s/index", json_iris_path);
-
- config_monitor_traverse(0, tmp_iris_full_idx_path, NULL,
- count_line_num_cb, NULL, &total_line_cnt,
- NULL, logger);
-
- struct serial_rule *s_rule = ALLOC(struct serial_rule, total_line_cnt);
- long long server_time = maat_redis_server_time_s(c);
- if (server_time < 0) {
- return -1;
- }
-
- //absolute_expire_time = server_time + 300;
- config_monitor_traverse(0, tmp_iris_full_idx_path, NULL,
- make_serial_rule, NULL, s_rule,
- NULL, logger);
- line_idx = 0;
- absolute_expire_time = 0;
-
- int success_cnt = 0;
- do {
- success_cnt = maat_cmd_write_rule(c, s_rule, total_line_cnt,
- server_time, logger);
- } while (success_cnt < 0);
-
- EXPECT_EQ(success_cnt, (int)total_line_cnt);
-
- for (size_t i = 0; i < total_line_cnt; i++) {
- maat_clear_rule_cache(s_rule + i);
- }
- FREE(s_rule);
- redisFree(c);
-
- return 0;
-}
-
-static int
-compile_table_set_line(struct maat *maat_inst, const char *table_name,
- enum maat_operation op, long long compile_id,
- const char *user_region, int clause_num,
- int expire_after)
-{
- char table_line[1024 * 16] = {0};
- sprintf(table_line, "%lld\t0\t0\t0\t0\t0\t%s\t%d\t%d\t0.0",
- compile_id, user_region, clause_num, op);
-
- struct maat_cmd_line line_rule;
- line_rule.rule_id = compile_id;
- line_rule.table_line = table_line;
- line_rule.table_name = table_name;
- line_rule.expire_after = expire_after;
-
- return maat_cmd_set_line(maat_inst, &line_rule);
-}
-static int
-group2compile_table_set_line(struct maat *maat_inst, const char *table_name,
- enum maat_operation op, long long group_id,
- long long compile_id, int not_flag,
- const char *vtable_name, int clause_index,
- int expire_after)
-{
- char table_line[128] = {0};
- sprintf(table_line, "%lld\t%lld\t%d\t%s\t%d\t%d",
- group_id, compile_id, not_flag, vtable_name, clause_index, op);
-
- struct maat_cmd_line line_rule;
- line_rule.rule_id = group_id;
- line_rule.table_line = table_line;
- line_rule.table_name = table_name;
- line_rule.expire_after = expire_after;
-
- return maat_cmd_set_line(maat_inst, &line_rule);
-}
-
-static int
-expr_table_set_line(struct maat *maat_inst, const char *table_name,
- enum maat_operation op, long long item_id,
- long long group_id, const char *keywords,
- const char *district, int expr_type,
- int match_method, int is_hexbin, int expire_after)
-{
- char table_line[1024] = {0};
- int table_id = maat_get_table_id(maat_inst, table_name);
- if (table_id < 0) {
- return 0;
- }
-
- enum table_type table_type =
- table_manager_get_table_type(maat_inst->tbl_mgr, table_id);
- assert(table_type == TABLE_TYPE_EXPR || table_type == TABLE_TYPE_EXPR_PLUS);
-
- if (table_type == TABLE_TYPE_EXPR_PLUS) {
- sprintf(table_line, "%lld\t%lld\t%s\t%s\t%d\t%d\t%d\t%d",
- item_id, group_id, district, keywords, expr_type,
- match_method, is_hexbin, op);
- } else {
- sprintf(table_line, "%lld\t%lld\t%s\t%d\t%d\t%d\t%d",
- item_id, group_id, keywords, expr_type,
- match_method, is_hexbin, op);
- }
-
- struct maat_cmd_line line_rule;
- line_rule.rule_id = item_id;
- line_rule.table_line = table_line;
- line_rule.table_name = table_name;
- line_rule.expire_after = expire_after;
-
- return maat_cmd_set_line(maat_inst, &line_rule);
-}
-
-static int
-ip_table_set_line(struct maat *maat_inst, const char *table_name,
- enum maat_operation op, long long item_id,
- long long group_id, enum IP_TYPE type,
- const char *ip1, const char *ip2, int expire_after)
-{
- char table_line[1024] = {0};
- int table_id = maat_get_table_id(maat_inst, table_name);
- if (table_id < 0) {
- return 0;
- }
-
- int ip_type = IPV4;
- if (type == IPv6) {
- ip_type = IPV6;
- }
-
- sprintf(table_line, "%lld\t%lld\t%d\t%s\t%s\t%s\t%d",
- item_id, group_id, ip_type, "range", ip1, ip2, op);
- struct maat_cmd_line line_rule;
-
- line_rule.rule_id = item_id;
- line_rule.table_line = table_line;
- line_rule.table_name = table_name;
- line_rule.expire_after = expire_after;
-
- return maat_cmd_set_line(maat_inst, &line_rule);
-}
-
-static int
-integer_table_set_line(struct maat *maat_inst, const char *table_name,
- enum maat_operation op, long long item_id,
- long long group_id, int low_boundary,
- int up_boundary, int expire_after)
-{
- char table_line[1024] = {0};
- int table_id = maat_get_table_id(maat_inst, table_name);
- if (table_id < 0) {
- return 0;
- }
-
- sprintf(table_line, "%lld\t%lld\t%d\t%d\t%d",
- item_id, group_id, low_boundary, up_boundary, op);
- struct maat_cmd_line line_rule;
-
- line_rule.rule_id = item_id;
- line_rule.table_line = table_line;
- line_rule.table_name = table_name;
- line_rule.expire_after = expire_after;
-
- return maat_cmd_set_line(maat_inst, &line_rule);
-}
-
-static int
-flag_table_set_line(struct maat *maat_inst, const char *table_name,
- enum maat_operation op, long long item_id,
- long long group_id, long long flag,
- long long flag_mask, int expire_after)
-{
- char table_line[1024] = {0};
- int table_id = maat_get_table_id(maat_inst, table_name);
- if (table_id < 0) {
- return 0;
- }
-
- sprintf(table_line, "%lld\t%lld\t%lld\t%lld\t%d",
- item_id, group_id, flag, flag_mask, op);
- struct maat_cmd_line line_rule;
-
- line_rule.rule_id = item_id;
- line_rule.table_line = table_line;
- line_rule.table_name = table_name;
- line_rule.expire_after = expire_after;
-
- return maat_cmd_set_line(maat_inst, &line_rule);
-}
static void
test_add_expr_command(struct maat *maat_inst, const char *table_name,
@@ -378,8 +104,8 @@ test_add_integer_command(struct maat *maat_inst, const char *table_name,
EXPECT_EQ(ret, 1);
long long item_id = maat_cmd_incrby(maat_inst, "SEQUENCE_REGION", 1);
- ret = integer_table_set_line(maat_inst, table_name, MAAT_OP_ADD, item_id,
- group_id, low_boundary, up_boundary, 0);
+ ret = interval_table_set_line(maat_inst, table_name, MAAT_OP_ADD, item_id,
+ group_id, low_boundary, up_boundary, NULL, 0);
EXPECT_EQ(ret, 1);
}
@@ -415,12 +141,9 @@ protected:
char redis_ip[64] = "127.0.0.1";
int redis_port = 6379;
int redis_db = 0;
- char json_iris_path[512] = {0};
- snprintf(json_iris_path, sizeof(json_iris_path),
- "./%s_iris_tmp", json_filename);
logger = log_handle_create("./maat_framework_perf_gtest.log", 0);
- int ret = write_config_to_redis(json_iris_path, redis_ip, redis_port,
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port,
redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
@@ -437,7 +160,7 @@ protected:
maat_options_set_accept_tags(opts, accept_tags);
maat_options_set_caller_thread_number(opts, 5);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
@@ -573,12 +296,9 @@ protected:
char redis_ip[64] = "127.0.0.1";
int redis_port = 6379;
int redis_db = 0;
- char json_iris_path[512] = {0};
-
- snprintf(json_iris_path, sizeof(json_iris_path),
- "./%s_iris_tmp", json_filename);
+
logger = log_handle_create("./maat_framework_perf_gtest.log", 0);
- int ret = write_config_to_redis(json_iris_path, redis_ip, redis_port,
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port,
redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
@@ -595,7 +315,7 @@ protected:
maat_options_set_accept_tags(opts, accept_tags);
maat_options_set_caller_thread_number(opts, 5);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
@@ -786,12 +506,9 @@ protected:
char redis_ip[64] = "127.0.0.1";
int redis_port = 6379;
int redis_db = 0;
- char json_iris_path[512] = {0};
-
- snprintf(json_iris_path, sizeof(json_iris_path),
- "./%s_iris_tmp", json_filename);
+\
logger = log_handle_create("./maat_framework_perf_gtest.log", 0);
- int ret = write_config_to_redis(json_iris_path, redis_ip, redis_port,
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port,
redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
@@ -808,7 +525,7 @@ protected:
maat_options_set_accept_tags(opts, accept_tags);
maat_options_set_caller_thread_number(opts, 5);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
@@ -924,12 +641,9 @@ protected:
char redis_ip[64] = "127.0.0.1";
int redis_port = 6379;
int redis_db = 0;
- char json_iris_path[512] = {0};
- snprintf(json_iris_path, sizeof(json_iris_path),
- "./%s_iris_tmp", json_filename);
logger = log_handle_create("./maat_framework_perf_gtest.log", 0);
- int ret = write_config_to_redis(json_iris_path, redis_ip, redis_port,
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port,
redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
@@ -946,7 +660,7 @@ protected:
maat_options_set_accept_tags(opts, accept_tags);
maat_options_set_caller_thread_number(opts, 5);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
@@ -1096,12 +810,9 @@ protected:
char redis_ip[64] = "127.0.0.1";
int redis_port = 6379;
int redis_db = 0;
- char json_iris_path[512] = {0};
- snprintf(json_iris_path, sizeof(json_iris_path),
- "./%s_iris_tmp", json_filename);
logger = log_handle_create("./maat_framework_perf_gtest.log", 0);
- int ret = write_config_to_redis(json_iris_path, redis_ip, redis_port,
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port,
redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
@@ -1118,7 +829,7 @@ protected:
maat_options_set_accept_tags(opts, accept_tags);
maat_options_set_caller_thread_number(opts, 5);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
@@ -1198,12 +909,9 @@ protected:
char redis_ip[64] = "127.0.0.1";
int redis_port = 6379;
int redis_db = 0;
- char json_iris_path[512] = {0};
- snprintf(json_iris_path, sizeof(json_iris_path),
- "./%s_iris_tmp", json_filename);
logger = log_handle_create("./maat_framework_perf_gtest.log", 0);
- int ret = write_config_to_redis(json_iris_path, redis_ip, redis_port,
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port,
redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
@@ -1220,7 +928,7 @@ protected:
maat_options_set_accept_tags(opts, accept_tags);
maat_options_set_caller_thread_number(opts, 5);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
@@ -1353,12 +1061,9 @@ protected:
char redis_ip[64] = "127.0.0.1";
int redis_port = 6379;
int redis_db = 0;
- char json_iris_path[512] = {0};
- snprintf(json_iris_path, sizeof(json_iris_path),
- "./%s_iris_tmp", json_filename);
logger = log_handle_create("./maat_framework_perf_gtest.log", 0);
- int ret = write_config_to_redis(json_iris_path, redis_ip, redis_port,
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port,
redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
@@ -1375,7 +1080,7 @@ protected:
maat_options_set_accept_tags(opts, accept_tags);
maat_options_set_caller_thread_number(opts, 5);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
@@ -1591,12 +1296,9 @@ protected:
char redis_ip[64] = "127.0.0.1";
int redis_port = 6379;
int redis_db = 0;
- char json_iris_path[512] = {0};
- snprintf(json_iris_path, sizeof(json_iris_path),
- "./%s_iris_tmp", json_filename);
logger = log_handle_create("./maat_framework_perf_gtest.log", 0);
- int ret = write_config_to_redis(json_iris_path, redis_ip, redis_port,
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port,
redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
@@ -1613,7 +1315,7 @@ protected:
maat_options_set_accept_tags(opts, accept_tags);
maat_options_set_caller_thread_number(opts, 5);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
@@ -1949,12 +1651,10 @@ protected:
char redis_ip[64] = "127.0.0.1";
int redis_port = 6379;
int redis_db = 0;
- char json_iris_path[512] = {0};
const char *tsg_table_info = "./tsg_table_info.conf";
- snprintf(json_iris_path, sizeof(json_iris_path), "./tsgrule");
logger = log_handle_create("./maat_framework_perf_gtest.log", 0);
- int ret = write_config_to_redis(json_iris_path, redis_ip, redis_port,
+ int ret = write_iris_to_redis("./tsgrule", redis_ip, redis_port,
redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
@@ -2026,12 +1726,9 @@ protected:
char redis_ip[64] = "127.0.0.1";
int redis_port = 6379;
int redis_db = 0;
- char json_iris_path[512] = {0};
- snprintf(json_iris_path, sizeof(json_iris_path),
- "./%s_iris_tmp", json_filename);
logger = log_handle_create("./maat_framework_perf_gtest.log", 0);
- int ret = write_config_to_redis(json_iris_path, redis_ip, redis_port,
+ int ret = write_json_to_redis(g_json_filename, redis_ip, redis_port,
redis_db, logger);
if (ret < 0) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
@@ -2048,7 +1745,7 @@ protected:
maat_options_set_accept_tags(opts, accept_tags);
maat_options_set_caller_thread_number(opts, 5);
- _shared_maat_inst = maat_new(opts, table_info_path);
+ _shared_maat_inst = maat_new(opts, g_table_info_path);
maat_options_free(opts);
if (NULL == _shared_maat_inst) {
log_fatal(logger, MODULE_FRAMEWORK_PERF_GTEST,
diff --git a/test/maat_input_mode_gtest.cpp b/test/maat_input_mode_gtest.cpp
index bc56414..ade4371 100644
--- a/test/maat_input_mode_gtest.cpp
+++ b/test/maat_input_mode_gtest.cpp
@@ -10,26 +10,26 @@
#define MODULE_INPUT_MODE_GTEST module_name_str("maat.input_mode_gtest")
-const char *table_info_path = "./table_info.conf";
-const char *json_filename = "maat_json.json";
+const char *g_table_info_path = "./table_info.conf";
+const char *g_json_filename = "maat_json.json";
struct log_handle *g_logger = NULL;
TEST(json_mode, maat_scan_string) {
char tmp_iris_path[PATH_MAX] = {0};
char json_iris_path[PATH_MAX] = {0};
snprintf(json_iris_path, sizeof(json_iris_path),
- "./%s_iris_tmp", json_filename);
+ "./%s_iris_tmp", g_json_filename);
if (access(json_iris_path, F_OK) < 0) {
char *json_buff = NULL;
size_t json_buff_sz = 0;
- int ret = load_file_to_memory(json_filename,
+ int ret = load_file_to_memory(g_json_filename,
(unsigned char**)&json_buff,
&json_buff_sz);
EXPECT_NE(ret, -1);
- ret = json2iris(json_buff, json_filename, NULL, tmp_iris_path,
+ ret = json2iris(json_buff, g_json_filename, NULL, tmp_iris_path,
sizeof(tmp_iris_path), NULL, NULL, g_logger);
FREE(json_buff);
EXPECT_NE(ret, -1);
@@ -37,13 +37,13 @@ TEST(json_mode, maat_scan_string) {
struct maat_options *opts = maat_options_new();
char json_path[PATH_MAX] = {0};
- snprintf(json_path, sizeof(json_path), "./%s", json_filename);
+ snprintf(json_path, sizeof(json_path), "./%s", g_json_filename);
maat_options_set_json_file(opts, json_path);
maat_options_set_stat_on(opts);
maat_options_set_perf_on(opts);
maat_options_set_logger(opts, "./maat_input_mode_gtest.log", LOG_LEVEL_INFO);
- struct maat *maat_inst = maat_new(opts, table_info_path);
+ struct maat *maat_inst = maat_new(opts, g_table_info_path);
EXPECT_TRUE(maat_inst != NULL);
const char *table_name = "KEYWORDS_TABLE";
@@ -70,18 +70,18 @@ TEST(iris_mode, maat_scan_string) {
char tmp_iris_path[512] = {0};
char json_iris_path[512] = {0};
snprintf(json_iris_path, sizeof(json_iris_path),
- "./%s_iris_tmp", json_filename);
+ "./%s_iris_tmp", g_json_filename);
if (access(json_iris_path, F_OK) < 0) {
char *json_buff = NULL;
size_t json_buff_sz = 0;
- int ret = load_file_to_memory(json_filename,
+ int ret = load_file_to_memory(g_json_filename,
(unsigned char**)&json_buff,
&json_buff_sz);
EXPECT_NE(ret, -1);
- ret = json2iris(json_buff, json_filename, NULL, tmp_iris_path,
+ ret = json2iris(json_buff, g_json_filename, NULL, tmp_iris_path,
sizeof(tmp_iris_path), NULL, NULL, g_logger);
FREE(json_buff);
EXPECT_NE(ret, -1);
@@ -100,7 +100,7 @@ TEST(iris_mode, maat_scan_string) {
maat_options_set_iris(opts, tmp_iris_full_idx_path, tmp_iris_inc_idx_path);
maat_options_set_logger(opts, "./maat_input_mode_gtest.log", LOG_LEVEL_INFO);
- struct maat *maat_inst = maat_new(opts, table_info_path);
+ struct maat *maat_inst = maat_new(opts, g_table_info_path);
EXPECT_TRUE(maat_inst != NULL);
const char *table_name = "KEYWORDS_TABLE";
@@ -171,7 +171,7 @@ TEST(redis_mode, maat_scan_string) {
int redis_db = 0;
snprintf(json_iris_path, sizeof(json_iris_path),
- "./%s_iris_tmp", json_filename);
+ "./%s_iris_tmp", g_json_filename);
redisContext *c =
maat_connect_redis(redis_ip, redis_port, redis_db, g_logger);
@@ -187,12 +187,12 @@ TEST(redis_mode, maat_scan_string) {
char *json_buff = NULL;
size_t json_buff_sz = 0;
- int ret = load_file_to_memory(json_filename,
+ int ret = load_file_to_memory(g_json_filename,
(unsigned char **)&json_buff,
&json_buff_sz);
EXPECT_NE(ret, -1);
- ret = json2iris(json_buff, json_filename, c, tmp_iris_path,
+ ret = json2iris(json_buff, g_json_filename, c, tmp_iris_path,
sizeof(tmp_iris_path), NULL, NULL, g_logger);
FREE(json_buff);
EXPECT_NE(ret, -1);
@@ -235,7 +235,7 @@ TEST(redis_mode, maat_scan_string) {
maat_options_set_logger(opts, "./maat_input_mode_gtest.log",
LOG_LEVEL_INFO);
- struct maat *maat_inst = maat_new(opts, table_info_path);
+ struct maat *maat_inst = maat_new(opts, g_table_info_path);
const char *table_name = "KEYWORDS_TABLE";
int table_id = maat_get_table_id(maat_inst, table_name);
char scan_data[128] =
@@ -264,7 +264,7 @@ int main(int argc, char ** argv)
char json_iris_path[NAME_MAX] = {0};
snprintf(json_iris_path, sizeof(json_iris_path),
- "./%s_iris_tmp", json_filename);
+ "./%s_iris_tmp", g_json_filename);
if ((access(json_iris_path, F_OK)) == 0) {
system_cmd_rmdir(json_iris_path);
}
diff --git a/test/maat_json.json b/test/maat_json.json
index 66f6a86..98e4586 100644
--- a/test/maat_json.json
+++ b/test/maat_json.json
@@ -104,7 +104,7 @@
"group_id": 7,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv4",
@@ -151,7 +151,7 @@
"group_id": 10,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv4",
@@ -167,7 +167,7 @@
"group_id": 11,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv4",
@@ -184,7 +184,7 @@
"regions": [
{
"table_name": "IP_CONFIG",
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_content": {
"addr_type": "ipv4",
"addr_format": "mask",
@@ -200,7 +200,7 @@
"regions": [
{
"table_name": "IP_PLUS_CONFIG",
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_content": {
"addr_type": "ipv4",
"addr_format": "mask",
@@ -216,7 +216,7 @@
"regions": [
{
"table_name": "IP_PLUS_CONFIG",
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_content": {
"addr_type": "ipv4",
"addr_format": "mask",
@@ -260,7 +260,7 @@
"regions": [
{
"table_name": "IP_CONFIG",
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_content": {
"addr_type": "ipv4",
"addr_format": "mask",
@@ -270,7 +270,7 @@
},
{
"table_name": "IP_CONFIG",
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_content": {
"addr_type": "ipv6",
"addr_format": "mask",
@@ -1384,7 +1384,7 @@
"not_flag": 0,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv4",
@@ -1413,7 +1413,7 @@
"not_flag": 0,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv6",
@@ -1498,7 +1498,7 @@
"group_id": 149,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv4",
@@ -1526,7 +1526,7 @@
"group_id": 150,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv6",
@@ -1737,7 +1737,7 @@
"not_flag": 0,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv4",
@@ -1856,7 +1856,7 @@
"not_flag" : 0,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv4",
@@ -1885,7 +1885,7 @@
"not_flag": 0,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv4",
@@ -1914,7 +1914,7 @@
"not_flag": 0,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv4",
@@ -2103,7 +2103,7 @@
"regions": [
{
"table_name": "IP_CONFIG",
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_content": {
"addr_type": "ipv6",
"addr_format": "mask",
@@ -2190,7 +2190,7 @@
"not_flag": 0,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv4",
@@ -2237,7 +2237,7 @@
"not_flag": 0,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv4",
@@ -2284,7 +2284,7 @@
"not_flag": 0,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv4",
@@ -2740,7 +2740,7 @@
"is_exclude": 0,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv4",
@@ -2757,7 +2757,7 @@
"is_exclude": 1,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv4",
@@ -2774,7 +2774,7 @@
"is_exclude": 1,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv4",
@@ -2806,7 +2806,7 @@
"regions": [
{
"table_name": "IP_PLUS_CONFIG",
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_content": {
"addr_type": "ipv4",
"addr_format": "range",
@@ -2825,7 +2825,7 @@
"regions": [
{
"table_name": "IP_PLUS_CONFIG",
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_content": {
"addr_type": "ipv4",
"addr_format": "range",
@@ -2896,7 +2896,7 @@
"regions": [
{
"table_name": "IP_PLUS_CONFIG",
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_content": {
"addr_type": "ipv4",
"addr_format": "range",
@@ -2915,7 +2915,7 @@
"regions": [
{
"table_name": "IP_PLUS_CONFIG",
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_content": {
"addr_type": "ipv4",
"addr_format": "range",
@@ -3091,7 +3091,7 @@
"not_flag": 0,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv4",
@@ -3146,7 +3146,7 @@
"group_id": 215,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PLUS_CONFIG",
"table_content": {
"addr_type": "ipv6",
@@ -3175,7 +3175,7 @@
"not_flag": 0,
"regions": [
{
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_name": "IP_PERF_CONFIG",
"table_content": {
"addr_type": "ipv4",
@@ -3958,7 +3958,7 @@
"regions": [
{
"table_name": "IP_CONFIG",
- "table_type": "ip_plus",
+ "table_type":"ip",
"table_content": {
"addr_type": "ipv4",
"addr_format": "mask",
@@ -3997,6 +3997,93 @@
]
}
]
+ },
+ {
+ "compile_id": 230,
+ "service": 0,
+ "action": 0,
+ "do_blacklist": 0,
+ "do_log": 0,
+ "user_region": "ipv6_::",
+ "is_valid": "yes",
+ "groups": [
+ {
+ "virtual_table": "IP_PLUS_CONFIG",
+ "group_name": "230_IP_group",
+ "group_id": 256,
+ "regions": [
+ {
+ "table_type":"ip",
+ "table_name": "IP_PLUS_CONFIG",
+ "table_content": {
+ "addr_type": "ipv6",
+ "addr_format": "CIDR",
+ "ip1": "2607:5d00:2:2::32:28",
+ "ip2": "128",
+ "port":"80-443"
+ }
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "compile_id": 231,
+ "service": 0,
+ "action": 0,
+ "do_blacklist": 0,
+ "do_log": 0,
+ "user_region": "should_not_hit",
+ "is_valid": "yes",
+ "groups": [
+ {
+ "virtual_table": "IP_PLUS_CONFIG",
+ "group_name": "231_IP_group",
+ "group_id": 257,
+ "regions": [
+ {
+ "table_type":"ip",
+ "table_name": "IP_PLUS_CONFIG",
+ "table_content": {
+ "addr_type": "ipv6",
+ "addr_format": "CIDR",
+ "ip1": "2607:5d00:2:2::32:28",
+ "ip2": "128",
+ "port":"80"
+ }
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "compile_id": 232,
+ "service": 0,
+ "action": 0,
+ "do_blacklist": 0,
+ "do_log": 0,
+ "user_region": "should_not_hit",
+ "is_valid": "yes",
+ "groups": [
+ {
+ "virtual_table": "IP_PLUS_CONFIG",
+ "group_name": "232_IP_group",
+ "group_id": 258,
+ "regions": [
+ {
+ "table_type":"ip",
+ "table_name": "IP_PLUS_CONFIG",
+ "table_content": {
+ "addr_type": "ipv4",
+ "addr_format": "CIDR",
+ "ip1": "192.168.30.44",
+ "ip2": "32",
+ "port": "80"
+ }
+ }
+ ]
+ }
+ ]
}
],
"plugin_table": [
diff --git a/test/table_info.conf b/test/table_info.conf
index 1792213..902ae53 100644
--- a/test/table_info.conf
+++ b/test/table_info.conf
@@ -137,7 +137,7 @@
"schema_tag": "{\"http_region\": \"expr\"}",
"custom": {
"item_id":1,
- "group_id":2,
+ "group_id":2,
"keywords":3,
"expr_type":4,
"match_method":5,
@@ -161,8 +161,8 @@
{
"table_id":12,
"table_name":"IP_CONFIG",
- "table_type":"ip_plus",
- "valid_column":7,
+ "table_type":"ip",
+ "valid_column":8,
"custom": {
"item_id":1,
"group_id":2,
@@ -322,15 +322,16 @@
{
"table_id":24,
"table_name":"IP_PLUS_CONFIG",
- "table_type":"ip_plus",
- "valid_column":7,
+ "table_type":"ip",
+ "valid_column":8,
"custom": {
"item_id":1,
"group_id":2,
"addr_type":3,
"addr_format":4,
"ip1":5,
- "ip2":6
+ "ip2":6,
+ "port":7
}
},
{
@@ -565,15 +566,16 @@
{
"table_id":47,
"table_name":"IP_PERF_CONFIG",
- "table_type":"ip_plus",
- "valid_column":7,
+ "table_type":"ip",
+ "valid_column":8,
"custom": {
"item_id":1,
"group_id":2,
"addr_type":3,
"addr_format":4,
"ip1":5,
- "ip2":6
+ "ip2":6,
+ "port":7
}
},
{
diff --git a/test/test_utils.cpp b/test/test_utils.cpp
new file mode 100644
index 0000000..0f5234a
--- /dev/null
+++ b/test/test_utils.cpp
@@ -0,0 +1,303 @@
+#include "test_utils.h"
+#include "maat_redis_monitor.h"
+#include "maat_utils.h"
+#include "maat_table.h"
+#include "maat_rule.h"
+#include "maat_config_monitor.h"
+#include "json2iris.h"
+
+#include <assert.h>
+#include <unistd.h>
+
+int count_line_num_cb(const char *table_name, const char *line, void *u_para)
+{
+ (*((unsigned int *)u_para))++;
+ return 0;
+}
+
+int line_idx = 0;
+long long absolute_expire_time = 0;
+int make_serial_rule(const char *table_name, const char *line, void *u_para)
+{
+ struct serial_rule *s_rule=(struct serial_rule *)u_para;
+ redisContext *ctx = s_rule->ref_ctx;
+ char *buff = ALLOC(char, strlen(line) + 1);
+
+ memcpy(buff, line, strlen(line) + 1);
+ while (buff[strlen(line) - 1] == '\n' || buff[strlen(line) - 1] == '\t') {
+ buff[strlen(line) - 1] = '\0';
+ }
+
+ const char *redis_rule_key = "TEST_RULE_KEY";
+ redisReply *reply = maat_wrap_redis_command(ctx, NULL, "INCRBY %s %d",
+ redis_rule_key, 1);
+ if (reply->type == REDIS_REPLY_NIL) {
+ printf("incrby redis_rule_key:%s failed.", redis_rule_key);
+ return -1;
+ } else {
+ s_rule->rule_id = maat_read_redis_integer(reply);
+ freeReplyObject(reply);
+ reply = NULL;
+ }
+
+ maat_set_serial_rule(s_rule + line_idx, MAAT_OP_ADD, s_rule->rule_id,
+ table_name, buff, absolute_expire_time);
+ (s_rule + line_idx)->ref_ctx = ctx;
+ line_idx++;
+
+ FREE(buff);
+
+ return 0;
+}
+int write_json_to_iris(const char* json_fn, char *iris_path, size_t path_sz, struct log_handle *logger)
+{
+
+ char *json_buff = NULL;
+ size_t json_buff_sz = 0;
+
+ int ret = load_file_to_memory(json_fn, (unsigned char **)&json_buff,
+ &json_buff_sz);
+ if (ret < 0) {
+ return -1;
+ }
+
+ ret = json2iris(json_buff, json_fn, NULL, iris_path,
+ path_sz, NULL, NULL, logger);
+ FREE(json_buff);
+ if (ret < 0) {
+ return -1;
+ }
+
+ return 0;
+}
+int write_iris_to_redis(const char* iris_path, char *redis_ip, int redis_port, int redis_db,
+ struct log_handle *logger)
+{
+ redisContext *c = maat_connect_redis(redis_ip, redis_port, redis_db, logger);
+ if (NULL == c) {
+ return -1;
+ }
+
+ redisReply *reply = maat_wrap_redis_command(c, logger, "flushdb");
+ if (NULL == reply) {
+ return -1;
+ } else {
+ freeReplyObject(reply);
+ reply = NULL;
+ }
+
+ size_t total_line_cnt = 0;
+ config_monitor_traverse(0, iris_path, NULL, count_line_num_cb,
+ NULL, &total_line_cnt, NULL, logger);
+
+ struct serial_rule *s_rule = ALLOC(struct serial_rule, total_line_cnt);
+ s_rule->ref_ctx = c;
+ long long server_time = maat_redis_server_time_s(c);
+ if (server_time < 0) {
+ return -1;
+ }
+
+ absolute_expire_time = server_time + 300;
+ config_monitor_traverse(0, iris_path, NULL, make_serial_rule,
+ NULL, s_rule, NULL, logger);
+ s_rule->ref_ctx = NULL;
+ line_idx = 0;
+ absolute_expire_time = 0;
+
+ int success_cnt = 0;
+ do {
+ success_cnt = maat_cmd_write_rule(c, s_rule, total_line_cnt,
+ server_time, logger);
+ } while (success_cnt < 0);
+
+ assert(success_cnt == (int)total_line_cnt);
+
+ for (size_t i = 0; i < total_line_cnt; i++) {
+ maat_clear_rule_cache(s_rule + i);
+ }
+ FREE(s_rule);
+ redisFree(c);
+ return 0;
+}
+int write_json_to_redis(const char* json_filename, char *redis_ip, int redis_port, int redis_db,
+ struct log_handle *logger)
+{
+ char iris_path[512] = {0};
+ write_json_to_iris(json_filename, iris_path, sizeof(iris_path), logger);
+ write_iris_to_redis(iris_path, redis_ip, redis_port, redis_db, logger);
+
+ return 0;
+}
+
+int compile_table_set_line(struct maat *maat_inst, const char *table_name,
+ enum maat_operation op, long long compile_id,
+ const char *user_region, int clause_num,
+ int expire_after)
+{
+ char table_line[1024 * 16] = {0};
+ sprintf(table_line, "%lld\t0\t0\t0\t0\t0\t%s\t%d\t%d\t0.0",
+ compile_id, user_region, clause_num, op);
+
+ struct maat_cmd_line line_rule;
+ line_rule.rule_id = compile_id;
+ line_rule.table_line = table_line;
+ line_rule.table_name = table_name;
+ line_rule.expire_after = expire_after;
+
+ return maat_cmd_set_line(maat_inst, &line_rule);
+}
+
+#define TO_GROUP2X_KEY(group_id, parent_id, clause_index) (((unsigned long)group_id<<32|parent_id) + clause_index)
+
+int group2compile_table_set_line(struct maat *maat_inst, const char *table_name,
+ enum maat_operation op, long long group_id,
+ long long compile_id, int not_flag,
+ const char *vtable_name, int clause_index,
+ int expire_after)
+{
+ char table_line[128] = {0};
+ sprintf(table_line, "%lld\t%lld\t%d\t%s\t%d\t%d",
+ group_id, compile_id, not_flag, vtable_name, clause_index, op);
+
+ struct maat_cmd_line line_rule;
+ line_rule.rule_id = TO_GROUP2X_KEY(group_id, compile_id, clause_index);
+ line_rule.table_line = table_line;
+ line_rule.table_name = table_name;
+ line_rule.expire_after = expire_after;
+
+ return maat_cmd_set_line(maat_inst, &line_rule);
+}
+
+int group2group_table_set_line(struct maat *maat_inst, const char *table_name,
+ enum maat_operation op, long long group_id,
+ long long sub_group_id, int expire_after)
+{
+ char table_line[128] = {0};
+ sprintf(table_line, "%lld\t%lld\t%s\t%d", group_id, sub_group_id,
+ "null", op);
+
+ struct maat_cmd_line line_rule;
+ line_rule.rule_id = TO_GROUP2X_KEY(group_id, sub_group_id, 0);
+ line_rule.table_line = table_line;
+ line_rule.table_name = table_name;
+ line_rule.expire_after = expire_after;
+
+ return maat_cmd_set_line(maat_inst, &line_rule);
+}
+
+int expr_table_set_line(struct maat *maat_inst, const char *table_name,
+ enum maat_operation op, long long item_id,
+ long long group_id, const char *keywords,
+ const char *district, int expr_type,
+ int match_method, int is_hexbin, int expire_after)
+{
+ char table_line[1024] = {0};
+ int table_id = maat_get_table_id(maat_inst, table_name);
+ if (table_id < 0) {
+ return 0;
+ }
+
+ enum table_type table_type = table_manager_get_table_type(maat_inst->tbl_mgr,
+ table_id);
+ assert(table_type == TABLE_TYPE_EXPR || table_type == TABLE_TYPE_EXPR_PLUS);
+
+ if (table_type == TABLE_TYPE_EXPR_PLUS) {
+ sprintf(table_line, "%lld\t%lld\t%s\t%s\t%d\t%d\t%d\t%d",
+ item_id, group_id, district, keywords, expr_type,
+ match_method, is_hexbin, op);
+ } else {
+ sprintf(table_line, "%lld\t%lld\t%s\t%d\t%d\t%d\t%d",
+ item_id, group_id, keywords, expr_type,
+ match_method, is_hexbin, op);
+ }
+
+ struct maat_cmd_line line_rule;
+ line_rule.rule_id = item_id;
+ line_rule.table_line = table_line;
+ line_rule.table_name = table_name;
+ line_rule.expire_after = expire_after;
+
+ return maat_cmd_set_line(maat_inst, &line_rule);
+}
+
+int interval_table_set_line(struct maat *maat_inst, const char *table_name,
+ enum maat_operation op, long long item_id, long long group_id,
+ unsigned int low_boundary, unsigned int up_boundary,
+ const char *district, int expire_after)
+{
+ char table_line[1024] = {0};
+ int table_id = maat_get_table_id(maat_inst, table_name);
+ if (table_id < 0) {
+ return 0;
+ }
+
+ enum table_type table_type = table_manager_get_table_type(maat_inst->tbl_mgr,
+ table_id);
+ assert(table_type == TABLE_TYPE_INTERVAL || table_type == TABLE_TYPE_INTERVAL_PLUS);
+
+ if (table_type == TABLE_TYPE_INTERVAL_PLUS) {
+ sprintf(table_line, "%lld\t%lld\t%s\t%u\t%u\t%d",
+ item_id, group_id, district, low_boundary, up_boundary, op);
+ } else {
+ sprintf(table_line, "%lld\t%lld\t%u\t%u\t%d",
+ item_id, group_id, low_boundary, up_boundary, op);
+ }
+
+ struct maat_cmd_line line_rule;
+ line_rule.rule_id = item_id;
+ line_rule.table_line = table_line;
+ line_rule.table_name = table_name;
+ line_rule.expire_after = expire_after;
+
+ return maat_cmd_set_line(maat_inst, &line_rule);
+}
+
+int ip_table_set_line(struct maat *maat_inst, const char *table_name,
+ enum maat_operation op, long long item_id,
+ long long group_id, enum IP_TYPE type, const char *ip1,
+ const char *ip2, int expire_after)
+{
+ char table_line[1024] = {0};
+ int table_id = maat_get_table_id(maat_inst, table_name);
+ if (table_id < 0) {
+ return 0;
+ }
+
+ int ip_type = IPV4;
+ if (type == IPv6) {
+ ip_type = IPV6;
+ }
+
+ sprintf(table_line, "%lld\t%lld\t%d\trange\t%s\t%s\t0-65535\t%d",
+ item_id, group_id, ip_type, ip1, ip2, op);
+ struct maat_cmd_line line_rule;
+
+ line_rule.rule_id = item_id;
+ line_rule.table_line = table_line;
+ line_rule.table_name = table_name;
+ line_rule.expire_after = expire_after;
+
+ return maat_cmd_set_line(maat_inst, &line_rule);
+}
+int flag_table_set_line(struct maat *maat_inst, const char *table_name,
+ enum maat_operation op, long long item_id,
+ long long group_id, long long flag,
+ long long flag_mask, int expire_after)
+{
+ char table_line[1024] = {0};
+ int table_id = maat_get_table_id(maat_inst, table_name);
+ if (table_id < 0) {
+ return 0;
+ }
+
+ sprintf(table_line, "%lld\t%lld\t%lld\t%lld\t%d",
+ item_id, group_id, flag, flag_mask, op);
+ struct maat_cmd_line line_rule;
+
+ line_rule.rule_id = item_id;
+ line_rule.table_line = table_line;
+ line_rule.table_name = table_name;
+ line_rule.expire_after = expire_after;
+
+ return maat_cmd_set_line(maat_inst, &line_rule);
+} \ No newline at end of file
diff --git a/test/test_utils.h b/test/test_utils.h
new file mode 100644
index 0000000..6049c91
--- /dev/null
+++ b/test/test_utils.h
@@ -0,0 +1,37 @@
+#pragma once
+#include "maat_utils.h"
+#include "maat_command.h"
+#include "ip_matcher.h"
+int write_json_to_redis(const char* json_filename, char *redis_ip, int redis_port, int redis_db,
+ struct log_handle *logger);
+int write_iris_to_redis(const char* iris_path, char *redis_ip, int redis_port, int redis_db,
+ struct log_handle *logger);
+int compile_table_set_line(struct maat *maat_inst, const char *table_name,
+ enum maat_operation op, long long compile_id,
+ const char *user_region, int clause_num,
+ int expire_after);
+int group2compile_table_set_line(struct maat *maat_inst, const char *table_name,
+ enum maat_operation op, long long group_id,
+ long long compile_id, int not_flag,
+ const char *vtable_name, int clause_index,
+ int expire_after);
+int group2group_table_set_line(struct maat *maat_inst, const char *table_name,
+ enum maat_operation op, long long group_id,
+ long long sub_group_id, int expire_after);
+int expr_table_set_line(struct maat *maat_inst, const char *table_name,
+ enum maat_operation op, long long item_id,
+ long long group_id, const char *keywords,
+ const char *district, int expr_type,
+ int match_method, int is_hexbin, int expire_after);
+int interval_table_set_line(struct maat *maat_inst, const char *table_name,
+ enum maat_operation op, long long item_id, long long group_id,
+ unsigned int low_boundary, unsigned int up_boundary,
+ const char *district, int expire_after);
+int ip_table_set_line(struct maat *maat_inst, const char *table_name,
+ enum maat_operation op, long long item_id,
+ long long group_id, enum IP_TYPE type, const char *ip1,
+ const char *ip2, int expire_after);
+int flag_table_set_line(struct maat *maat_inst, const char *table_name,
+ enum maat_operation op, long long item_id,
+ long long group_id, long long flag,
+ long long flag_mask, int expire_after); \ No newline at end of file
diff --git a/test/tsg_table_info.conf b/test/tsg_table_info.conf
index 53a03c5..0632c13 100644
--- a/test/tsg_table_info.conf
+++ b/test/tsg_table_info.conf
@@ -8,8 +8,7 @@
"item_id":1,
"ip_type":3,
"start_ip":4,
- "end_ip":5,
- "addr_format":7
+ "end_ip":5
}
},
{