[BUGFIX]fix group_exclude miss hit groups

This commit is contained in:
刘文坛
2023-05-15 07:24:36 +00:00
parent 1a7ec28c4f
commit 6830966084
29 changed files with 422 additions and 197 deletions

View File

@@ -4,7 +4,7 @@
* Description:
* Authors: Zheng Chao <zhengchao@geedgenetworks.com>
* Date: 2022-10-31
* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved.
* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved.
***********************************************************************************************
*/

View File

@@ -4,7 +4,7 @@
* Description: alignment statistics
* Authors: Zheng Chao <zhengchao@geedgenetworks.com>
* Date: 2022-10-31
* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved.
* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved.
***********************************************************************************************
*/

View File

@@ -4,7 +4,7 @@
* Description:
* Authors: Liu WenTan <liuwentan@geedgenetworks.com>
* Date: 2022-10-31
* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved.
* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved.
***********************************************************************************************
*/

View File

@@ -4,7 +4,7 @@
* Description: maat config monitor api
* Authors: Liu WenTan <liuwentan@geedgenetworks.com>
* Date: 2022-10-31
* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved.
* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved.
***********************************************************************************************
*/

View File

@@ -4,7 +4,7 @@
* Description:
* Authors: Liu WenTan <liuwentan@geedgenetworks.com>
* Date: 2022-10-31
* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved.
* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved.
***********************************************************************************************
*/

View File

@@ -4,7 +4,7 @@
* Description:
* Authors: Liu WenTan <liuwentan@geedgenetworks.com>
* Date: 2022-10-31
* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved.
* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved.
***********************************************************************************************
*/

View File

@@ -4,7 +4,7 @@
* Description:
* Authors: Liu WenTan <liuwentan@geedgenetworks.com>
* Date: 2022-10-31
* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved.
* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved.
***********************************************************************************************
*/

View File

@@ -4,7 +4,7 @@
* Description:
* Authors: Liu WenTan <liuwentan@geedgenetworks.com>
* Date: 2022-10-31
* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved.
* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved.
***********************************************************************************************
*/

View File

@@ -4,7 +4,7 @@
* Description: maat rule entry
* Authors: Liu WenTan <liuwentan@geedgenetworks.com>
* Date: 2022-10-31
* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved.
* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved.
***********************************************************************************************
*/

View File

@@ -4,7 +4,7 @@
* Description: maat statistics
* Authors: Liu WenTan <liuwentan@geedgenetworks.com>
* Date: 2022-10-31
* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved.
* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved.
***********************************************************************************************
*/

View File

@@ -4,7 +4,7 @@
* Description: maat table schema and runtime
* Authors: Liu WenTan <liuwentan@geedgenetworks.com>
* Date: 2022-10-31
* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved.
* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved.
***********************************************************************************************
*/

View File

@@ -4,7 +4,7 @@
* Description: rule for transform json2iris
* Authors: Zheng Chao <zhengchao@geedgenetworks.com>
* Date: 2022-10-31
* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved.
* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved.
***********************************************************************************************
*/

View File

@@ -1,10 +1,10 @@
/*
**********************************************************************************************
* File: maat_api.cpp
* File: maat_api.c
* Description: maat api entry
* Authors: Liu WenTan <liuwentan@geedgenetworks.com>
* Date: 2022-10-31
* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved.
* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved.
***********************************************************************************************
*/

View File

@@ -1,10 +1,10 @@
/*
**********************************************************************************************
* File: maat_bool_plugin.cpp
* File: maat_bool_plugin.c
* Description:
* Authors: Liu wentan <liuwentan@geedgenetworks.com>
* Date: 2022-10-31
* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved.
* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved.
***********************************************************************************************
*/

View File

@@ -1,10 +1,10 @@
/*
**********************************************************************************************
* File: maat_config_monitor.h
* File: maat_config_monitor.c
* Description: maat config monitor api
* Authors: Liu WenTan <liuwentan@geedgenetworks.com>
* Date: 2022-10-31
* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved.
* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved.
***********************************************************************************************
*/

View File

@@ -1,10 +1,10 @@
/*
**********************************************************************************************
* File: maat_ex_data.cpp
* File: maat_ex_data.c
* Description: ex data
* Authors: Liu WenTan <liuwentan@geedgenetworks.com>
* Date: 2022-10-31
* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved.
* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved.
***********************************************************************************************
*/

View File

@@ -1,10 +1,10 @@
/*
**********************************************************************************************
* File: maat_flag.cpp
* File: maat_flag.c
* Description:
* Authors: Liu WenTan <liuwentan@geedgenetworks.com>
* Date: 2022-10-31
* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved.
* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved.
***********************************************************************************************
*/

View File

@@ -1,10 +1,10 @@
/*
**********************************************************************************************
* File: maat_fqdn_plugin.cpp
* File: maat_fqdn_plugin.c
* Description:
* Authors: Liu wentan <liuwentan@geedgenetworks.com>
* Date: 2022-10-31
* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved.
* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved.
***********************************************************************************************
*/

View File

@@ -1,10 +1,10 @@
/*
**********************************************************************************************
* File: maat_garbage_collection.h
* File: maat_garbage_collection.c
* Description:
* Authors: Zhengchao <zhengchao@geedgenetworks.com>
* Date: 2022-10-31
* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved.
* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved.
***********************************************************************************************
*/

View File

@@ -1,10 +1,10 @@
/*
**********************************************************************************************
* File: maat_group.cpp
* File: maat_group.c
* Description:
* Authors: Liu wentan <liuwentan@geedgenetworks.com>
* Date: 2022-10-31
* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved.
* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved.
***********************************************************************************************
*/
@@ -315,7 +315,8 @@ group2group_item_new(const char *line, struct group2group_schema *g2g_schema,
size_t column_len = 0;
struct group2group_item *g2g_item = ALLOC(struct group2group_item, 1);
int ret = get_column_pos(line, g2g_schema->group_id_column, &column_offset, &column_len);
int ret = get_column_pos(line, g2g_schema->group_id_column,
&column_offset, &column_len);
if (ret < 0) {
log_error(logger, MODULE_GROUP,
"[%s:%d] group2group table:%s line:%s has no group_id",
@@ -360,7 +361,8 @@ size_t print_igraph_vector(igraph_vector_t *v, char *buff, size_t sz) {
int printed = 0;
for (i = 0; i < igraph_vector_size(v); i++) {
printed += snprintf(buff + printed, sz - printed, " %li", (long int) VECTOR(*v)[i]);
printed += snprintf(buff + printed, sz - printed, " %li",
(long int) VECTOR(*v)[i]);
}
return printed;
@@ -382,8 +384,10 @@ struct maat_group *group_topology_add_group(struct maat_group_topology *group_to
assert(igraph_vcount(&group_topo->group_graph)==group->vertex_id);
igraph_add_vertices(&group_topo->group_graph, 1, NULL); //Add 1 vertice.
HASH_ADD(hh_group_id, group_topo->hash_by_group_id, group_id, sizeof(group->group_id), group);
HASH_ADD(hh_vertex_id, group_topo->hash_by_vertex_id, vertex_id, sizeof(group->vertex_id), group);
HASH_ADD(hh_group_id, group_topo->hash_by_group_id, group_id,
sizeof(group->group_id), group);
HASH_ADD(hh_vertex_id, group_topo->hash_by_vertex_id, vertex_id,
sizeof(group->vertex_id), group);
return group;
}
@@ -494,7 +498,6 @@ void maat_group_dereference_super_group(struct maat_group *group, long long supe
if (tmp_id != NULL) {
remove_idx = utarray_eltidx(group->incl_super_group_ids, tmp_id);
utarray_erase(group->incl_super_group_ids, remove_idx, 1);
utarray_sort(group->incl_super_group_ids, compare_group_id);
}
} else {
//exclude superior group
@@ -502,7 +505,6 @@ void maat_group_dereference_super_group(struct maat_group *group, long long supe
if (tmp_id != NULL) {
remove_idx = utarray_eltidx(group->excl_super_group_ids, tmp_id);
utarray_erase(group->excl_super_group_ids, remove_idx, 1);
utarray_sort(group->excl_super_group_ids, compare_group_id);
}
}
}
@@ -522,7 +524,6 @@ void maat_group_dereference_sub_group(struct maat_group *group, long long sub_gr
if (tmp_id != NULL) {
remove_idx = utarray_eltidx(group->incl_sub_group_ids, tmp_id);
utarray_erase(group->incl_sub_group_ids, remove_idx, 1);
utarray_sort(group->incl_sub_group_ids, compare_group_id);
}
} else {
//exclude superior group
@@ -530,7 +531,6 @@ void maat_group_dereference_sub_group(struct maat_group *group, long long sub_gr
if (tmp_id != NULL) {
remove_idx = utarray_eltidx(group->excl_sub_group_ids, tmp_id);
utarray_erase(group->excl_sub_group_ids, remove_idx, 1);
utarray_sort(group->excl_sub_group_ids, compare_group_id);
}
}
}
@@ -695,8 +695,10 @@ int group2group_runtime_update(void *g2g_runtime, void *g2g_schema,
if (0 == is_valid) {
//delete
ret = group_topology_del_group_from_group(g2g_rt->updating_group_topo, g2g_item->group_id,
g2g_item->super_group_id, g2g_item->is_exclude);
ret = group_topology_del_group_from_group(g2g_rt->updating_group_topo,
g2g_item->group_id,
g2g_item->super_group_id,
g2g_item->is_exclude);
if (0 == ret) {
g2g_rt->rule_num--;
} else {
@@ -704,8 +706,10 @@ int group2group_runtime_update(void *g2g_runtime, void *g2g_schema,
}
} else {
//add
ret = group_topology_add_group_to_group(g2g_rt->updating_group_topo, g2g_item->group_id,
g2g_item->super_group_id, g2g_item->is_exclude);
ret = group_topology_add_group_to_group(g2g_rt->updating_group_topo,
g2g_item->group_id,
g2g_item->super_group_id,
g2g_item->is_exclude);
if (0 == ret) {
g2g_rt->rule_num++;
} else {
@@ -723,7 +727,8 @@ void garbage_maat_group_topology_free(void *data, void *arg)
maat_group_topology_free(group_topo);
}
int group2group_runtime_commit(void *g2g_runtime, const char *table_name, long long maat_rt_version)
int group2group_runtime_commit(void *g2g_runtime, const char *table_name,
long long maat_rt_version)
{
if (NULL == g2g_runtime) {
return -1;
@@ -759,19 +764,11 @@ int group2group_runtime_commit(void *g2g_runtime, const char *table_name, long l
}
#define MAX_RECURSION_DEPTH 5
void get_candidate_super_group_ids(struct maat_group_topology *group_topo, UT_array *hit_group_ids,
UT_array *candidate_group_ids, size_t depth)
void get_candidate_super_group_ids(struct maat_group_topology *group_topo,
UT_array *hit_group_ids,
UT_array *super_group_ids)
{
long long *p = NULL;
UT_array *one_round_hit_group_ids;
if (depth >= MAX_RECURSION_DEPTH) {
log_error(group_topo->logger, MODULE_GROUP, "[%s:%d] recursive depth:%zu exceed maxium:%d",
__FUNCTION__, __LINE__, depth, MAX_RECURSION_DEPTH);
return;
}
utarray_new(one_round_hit_group_ids, &ut_group_id_icd);
//Find super candidates
for (p = (long long *)utarray_front(hit_group_ids); p != NULL;
@@ -782,135 +779,149 @@ void get_candidate_super_group_ids(struct maat_group_topology *group_topo, UT_ar
continue;
}
if ((0 == utarray_len(group->incl_sub_group_ids)) &&
(0 == utarray_len(group->excl_sub_group_ids))) {
if (!utarray_find(candidate_group_ids, p, compare_group_id)) {
utarray_push_back(candidate_group_ids, p);
utarray_sort(candidate_group_ids, compare_group_id);
}
}
long long *tmp = NULL;
for (tmp = (long long *)utarray_front(group->incl_super_group_ids); tmp != NULL;
tmp = (long long *)utarray_next(group->incl_super_group_ids, tmp)) {
if (utarray_find(candidate_group_ids, tmp, compare_group_id)) {
if (utarray_find(super_group_ids, tmp, compare_group_id)) {
continue;
}
utarray_push_back(candidate_group_ids, tmp);
utarray_sort(candidate_group_ids, compare_group_id);
utarray_push_back(one_round_hit_group_ids, tmp);
utarray_push_back(super_group_ids, tmp);
utarray_sort(super_group_ids, compare_group_id);
}
}
if (utarray_len(one_round_hit_group_ids) == 0) {
goto next;
}
depth++;
get_candidate_super_group_ids(group_topo, one_round_hit_group_ids, candidate_group_ids, depth);
next:
utarray_free(one_round_hit_group_ids);
}
void verify_candidate_super_group_ids(struct maat_group_topology *group_topo, UT_array *candidate_group_ids,
UT_array *all_hit_group_ids, size_t depth)
void verify_candidate_super_group_ids(struct maat_group_topology *group_topo,
UT_array *candidate_super_group_ids,
UT_array *all_hit_group_ids,
UT_array *kept_super_group_ids)
{
long long *p = NULL;
UT_array *kept_group_ids;
UT_array *candidate_group_ids;
if (depth >= MAX_RECURSION_DEPTH) {
log_error(group_topo->logger, MODULE_GROUP, "[%s:%d] recursive depth:%zu exceed maxium:%d",
__FUNCTION__, __LINE__, depth, MAX_RECURSION_DEPTH);
return;
utarray_new(candidate_group_ids, &ut_group_id_icd);
for (p = (long long *)utarray_front(candidate_super_group_ids); p != NULL;
p = (long long *)utarray_next(candidate_super_group_ids, p)) {
utarray_push_back(candidate_group_ids, p);
}
utarray_new(kept_group_ids, &ut_group_id_icd);
for (p = (long long *)utarray_front(all_hit_group_ids); p != NULL;
p = (long long *)utarray_next(all_hit_group_ids, p)) {
utarray_push_back(candidate_group_ids, p);
}
utarray_sort(candidate_group_ids, compare_group_id);
for (p = (long long *)utarray_front(candidate_group_ids); p != NULL;
p = (long long *)utarray_next(candidate_group_ids, p)) {
/**
* verify sub exclude for candidate_super_group_ids
*/
for (p = (long long *)utarray_front(candidate_super_group_ids); p != NULL;
p = (long long *)utarray_next(candidate_super_group_ids, p)) {
struct maat_group *group = group_topology_find_group(group_topo, *p);
assert(group != NULL);
if ((0 == utarray_len(group->incl_sub_group_ids)) &&
(0 == utarray_len(group->excl_sub_group_ids))) {
if (!utarray_find(kept_group_ids, p, compare_group_id)) {
utarray_push_back(kept_group_ids, p);
//if group's sub excl in candidate_group_ids
int sub_excl_flag = 0;
long long *tmp_id = NULL;
for (tmp_id = (long long *)utarray_front(group->excl_sub_group_ids); tmp_id != NULL;
tmp_id = (long long *)utarray_next(group->excl_sub_group_ids, tmp_id)) {
if (utarray_find(candidate_group_ids, tmp_id, compare_group_id)) {
sub_excl_flag = 1;
break;
}
}
//delete group_id from kept_group_ids
if (1 == sub_excl_flag) {
continue;
}
utarray_push_back(kept_super_group_ids, p);
utarray_sort(kept_super_group_ids, compare_group_id);
long long *tmp = NULL;
int kept_flag = 1;
// group's sub_exclude in candidates, it should not be kept
for (tmp = (long long *)utarray_front(group->excl_sub_group_ids); tmp != NULL;
tmp = (long long *)utarray_next(group->excl_sub_group_ids, tmp)) {
if (utarray_find(candidate_group_ids, tmp, compare_group_id)) {
//if group's sub exclude in candidate, it should not be kept
kept_flag = 0;
break;
}
}
// group's all sub_include not in candidates, it should not be kept
for (tmp = (long long *)utarray_front(group->incl_sub_group_ids); tmp != NULL;
tmp = (long long *)utarray_next(group->incl_sub_group_ids, tmp)) {
if (!utarray_find(candidate_group_ids, tmp, compare_group_id)) {
kept_flag = 0;
break;
}
}
if (1 == kept_flag) {
utarray_push_back(kept_group_ids, p);
}
}
if (utarray_len(kept_group_ids) == utarray_len(candidate_group_ids)) {
for (p = (long long *)utarray_front(candidate_group_ids); p != NULL;
p = (long long *)utarray_next(candidate_group_ids, p)) {
if (!utarray_find(all_hit_group_ids, p, compare_group_id)) {
utarray_push_back(all_hit_group_ids, p);
utarray_sort(all_hit_group_ids, compare_group_id);
}
goto next;
}
depth++;
verify_candidate_super_group_ids(group_topo, kept_group_ids, all_hit_group_ids, depth);
next:
utarray_free(kept_group_ids);
}
size_t group_topology_get_super_groups(struct maat_group_topology *group_topo,
long long *group_ids, size_t n_group_ids,
long long *super_group_ids,
size_t super_group_ids_size)
{
size_t i = 0, idx = 0, depth = 0;
UT_array *one_round_hit_group_ids;
UT_array *candidate_group_ids;
UT_array *all_hit_group_ids;
utarray_new(one_round_hit_group_ids, &ut_group_id_icd);
utarray_new(candidate_group_ids, &ut_group_id_icd);
utarray_new(all_hit_group_ids, &ut_group_id_icd);
for (i = 0; i < n_group_ids; i++) {
utarray_push_back(one_round_hit_group_ids, &(group_ids[i]));
}
/**
candidates means all hit groups' super include group, no need to consider super exclude groups
* candidate_group_ids clone all_hit_group_ids
*/
utarray_clear(candidate_group_ids);
for (p = (long long *)utarray_front(all_hit_group_ids); p != NULL;
p = (long long *)utarray_next(all_hit_group_ids, p)) {
utarray_push_back(candidate_group_ids, p);
}
/**
* delete groups whose all incl sub is non-exist in all_hit_group_ids
*/
for (p = (long long *)utarray_front(candidate_group_ids); p != NULL;
p = (long long *)utarray_next(candidate_group_ids, p)) {
struct maat_group *group = group_topology_find_group(group_topo, *p);
if (NULL == group) {
continue;
}
if (0 == utarray_len(group->incl_sub_group_ids)) {
continue;
}
int sub_incl_flag = 0;
long long *tmp_id = NULL;
for (tmp_id = (long long *)utarray_front(group->incl_sub_group_ids); tmp_id != NULL;
tmp_id = (long long *)utarray_next(group->incl_sub_group_ids, tmp_id)) {
if (utarray_find(candidate_group_ids, tmp_id, compare_group_id)) {
sub_incl_flag = 1;
break;
}
}
if (0 == sub_incl_flag) {
tmp_id = utarray_find(all_hit_group_ids, p, compare_group_id);
assert(tmp_id != NULL);
size_t remove_idx = utarray_eltidx(all_hit_group_ids, tmp_id);
utarray_erase(all_hit_group_ids, remove_idx, 1);
tmp_id = utarray_find(kept_super_group_ids, p, compare_group_id);
if (tmp_id != NULL) {
remove_idx = utarray_eltidx(kept_super_group_ids, tmp_id);
utarray_erase(kept_super_group_ids, remove_idx, 1);
}
}
}
utarray_free(candidate_group_ids);
}
#define MAX_RECURSION_DEPTH 5
void get_super_group_ids(struct maat_group_topology *group_topo, UT_array *hit_group_ids,
UT_array *all_hit_group_ids, size_t depth)
{
UT_array *candidate_super_group_ids;
UT_array *kept_super_group_ids;
if (depth >= MAX_RECURSION_DEPTH) {
return;
}
utarray_new(kept_super_group_ids, &ut_group_id_icd);
utarray_new(candidate_super_group_ids, &ut_group_id_icd);
/**
candidate super groups means all hit groups' super include group,
no need to consider super exclude groups
for example:
hit_groups = {g4, g11}
g4's super include groups = {g7, g8}
g11's super include groups = {g12}
candidates = {g7, g8, g12}
candidate super groups = {g7, g8, g12}
*/
get_candidate_super_group_ids(group_topo, one_round_hit_group_ids, candidate_group_ids, depth);
if (0 == utarray_len(candidate_group_ids)) {
get_candidate_super_group_ids(group_topo, hit_group_ids, candidate_super_group_ids);
if (0 == utarray_len(candidate_super_group_ids)) {
goto next;
}
@@ -932,17 +943,43 @@ size_t group_topology_get_super_groups(struct maat_group_topology *group_topo,
g3 g4 g5 g11
candidates = {g4, g11, g7, g8, g12}
g12's sub_exclude g8 in candidates, so g12 should be dropped
after verify candidates, all hit super groups = {g7, g8}, all hit groups = {g4, g11, g7, g8}
after verify candidates, all hit super groups = {g7, g8},
all hit groups = {g4, g11, g7, g8}
*/
verify_candidate_super_group_ids(group_topo, candidate_group_ids, all_hit_group_ids, depth);
if (0 == utarray_len(all_hit_group_ids)) {
goto next;
}
verify_candidate_super_group_ids(group_topo, candidate_super_group_ids, all_hit_group_ids,
kept_super_group_ids);
depth++;
get_super_group_ids(group_topo, kept_super_group_ids, all_hit_group_ids, depth);
next:
utarray_free(candidate_super_group_ids);
utarray_free(kept_super_group_ids);
}
size_t group_topology_get_super_groups(struct maat_group_topology *group_topo,
long long *group_ids, size_t n_group_ids,
long long *super_group_ids,
size_t super_group_ids_size)
{
size_t i = 0, idx = 0;
UT_array *all_hit_group_ids;
UT_array *candidate_group_ids;
utarray_new(all_hit_group_ids, &ut_group_id_icd);
utarray_new(candidate_group_ids, &ut_group_id_icd);
// delete group_ids from all_hit_group_ids, just keep all hit super groups
for (i = 0; i < n_group_ids; i++) {
long long *tmp_id = NULL;
tmp_id = utarray_find(all_hit_group_ids, &group_ids[i], compare_group_id);
utarray_push_back(candidate_group_ids, &(group_ids[i]));
utarray_push_back(all_hit_group_ids, &(group_ids[i]));
}
utarray_sort(candidate_group_ids, compare_group_id);
utarray_sort(all_hit_group_ids, compare_group_id);
get_super_group_ids(group_topo, candidate_group_ids, all_hit_group_ids, 0);
for (i = 0; i < n_group_ids; i++) {
long long *tmp_id = utarray_find(all_hit_group_ids, &(group_ids[i]),
compare_group_id);
if (tmp_id != NULL) {
size_t remove_idx = utarray_eltidx(all_hit_group_ids, tmp_id);
utarray_erase(all_hit_group_ids, remove_idx, 1);
@@ -952,17 +989,11 @@ size_t group_topology_get_super_groups(struct maat_group_topology *group_topo,
long long *p = NULL;
for (p = (long long *)utarray_front(all_hit_group_ids); p != NULL;
p = (long long *)utarray_next(all_hit_group_ids, p)) {
if (idx >= super_group_ids_size) {
break;
}
super_group_ids[idx++] = *p;
}
next:
utarray_free(one_round_hit_group_ids);
utarray_free(candidate_group_ids);
utarray_free(all_hit_group_ids);
utarray_free(candidate_group_ids);
return idx;
}

View File

@@ -1,10 +1,10 @@
/*
**********************************************************************************************
* File: maat_ip_plugin.cpp
* File: maat_ip_plugin.c
* Description:
* Authors: Liu wentan <liuwentan@geedgenetworks.com>
* Date: 2022-10-31
* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved.
* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved.
***********************************************************************************************
*/

View File

@@ -1,10 +1,10 @@
/*
**********************************************************************************************
* File: maat_kv_map.cpp
* File: maat_kv.c
* Description:
* Authors: Zheng chao <zhengchao@geedgenetworks.com>
* Date: 2022-10-31
* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved.
* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved.
***********************************************************************************************
*/

View File

@@ -6,9 +6,6 @@ include_directories(${PROJECT_SOURCE_DIR}/scanner)
include_directories(${PROJECT_SOURCE_DIR}/scanner/adapter_hs)
include_directories(${PROJECT_SOURCE_DIR}/scanner/ip_matcher)
add_executable(maat_api_gtest maat_api_gtest.cpp)
target_link_libraries(maat_api_gtest maat_frame_shared gtest_static)
add_executable(rcu_hash_gtest rcu_hash_gtest.cpp)
target_link_libraries(rcu_hash_gtest maat_frame_static gtest_static)
@@ -27,6 +24,8 @@ target_link_libraries(adapter_hs_gtest maat_frame_static gtest_static)
add_executable(maat_ex_data_gtest maat_ex_data_gtest.cpp)
target_link_libraries(maat_ex_data_gtest maat_frame_static gtest_static)
add_subdirectory(group_exclude)
file(COPY table_info.conf DESTINATION ./)
file(COPY file_test_tableinfo.conf DESTINATION ./)
file(COPY literal_expr.conf DESTINATION ./)
@@ -37,6 +36,7 @@ file(COPY ntcrule DESTINATION ./)
file(COPY testdata DESTINATION ./)
file(COPY test_streamfiles DESTINATION ./)
file(COPY json_update DESTINATION ./)
file(COPY group_exclude DESTINATION ./)
include(GoogleTest)
gtest_discover_tests(maat_framework_gtest)

View File

@@ -0,0 +1,4 @@
include_directories(${PROJECT_SOURCE_DIR}/src/inc_internal)
add_executable(group_exclude_gtest group_exclude_gtest.cpp)
target_link_libraries(group_exclude_gtest maat_frame_static gtest_static)

View File

@@ -79,19 +79,9 @@
"group_id": 11,
"super_group_id": 13,
"is_exclude": 1
},
{
"group_id": 8,
"super_group_id": 7,
"is_exclude": 1
}
],
"del_items": [
{
"group_id": 8,
"super_group_id": 7,
"is_exclude": 1
},
{
"group_id": 11,
"super_group_id": 13,

View File

@@ -0,0 +1,202 @@
#include "maat.h"
#include "log/log.h"
#include "cJSON/cJSON.h"
#include "maat_rule.h"
#include "maat_utils.h"
#include "maat_command.h"
#include "maat_group.h"
#include <gtest/gtest.h>
#define MODULE_GROUP_EXCLUDE_GTEST module_name_str("maat.group_exclude_gtest")
#define MAX_ITEM_NUM 64
#define WAIT_FOR_EFFECTIVE_S 2
const char *table_info_path = "./table_info.conf";
struct group_item {
long long group_id;
long long super_group_id;
int is_exclude;
};
struct group2group_rule {
size_t n_add_item;
size_t n_del_item;
struct group_item add_items[MAX_ITEM_NUM];
struct group_item del_items[MAX_ITEM_NUM];
};
static int parse_config_file(const char *filename, struct group2group_rule *rules)
{
unsigned char *json_buff = NULL;
size_t json_buff_size = 0;
int ret = load_file_to_memory(filename, &json_buff, &json_buff_size);
if (ret < 0) {
printf("load file:%s to memory failed.\n", filename);
return -1;
}
size_t rule_cnt = 0;
cJSON *items_array = NULL;
cJSON *root = cJSON_Parse((const char *)json_buff);
if (NULL == root) {
printf("Error before: %-200.200s\n", cJSON_GetErrorPtr());
ret = -1;
goto next;
}
items_array = cJSON_GetObjectItem(root, "add_items");
if (NULL == items_array) {
printf("Error before: %-200.200s\n", cJSON_GetErrorPtr());
ret = -1;
goto next;
}
rule_cnt = cJSON_GetArraySize(items_array);
for (size_t i = 0; i < rule_cnt; i++) {
cJSON *item_obj = cJSON_GetArrayItem(items_array, i);
cJSON *tmp_item = cJSON_GetObjectItem(item_obj, "group_id");
if (tmp_item != NULL && tmp_item->type == cJSON_Number) {
rules->add_items[i].group_id = tmp_item->valueint;
}
tmp_item = cJSON_GetObjectItem(item_obj, "super_group_id");
if (tmp_item != NULL && tmp_item->type == cJSON_Number) {
rules->add_items[i].super_group_id = tmp_item->valueint;
}
tmp_item = cJSON_GetObjectItem(item_obj, "is_exclude");
if (tmp_item != NULL && tmp_item->type == cJSON_Number) {
rules->add_items[i].is_exclude = tmp_item->valueint;
}
}
rules->n_add_item = rule_cnt;
items_array = cJSON_GetObjectItem(root, "del_items");
if (NULL == items_array) {
printf("Error before: %-200.200s\n", cJSON_GetErrorPtr());
ret = -1;
goto next;
}
rule_cnt = cJSON_GetArraySize(items_array);
for (size_t i = 0; i < rule_cnt; i++) {
cJSON *item_obj = cJSON_GetArrayItem(items_array, i);
cJSON *tmp_item = cJSON_GetObjectItem(item_obj, "group_id");
if (tmp_item != NULL && tmp_item->type == cJSON_Number) {
rules->del_items[i].group_id = tmp_item->valueint;
}
tmp_item = cJSON_GetObjectItem(item_obj, "super_group_id");
if (tmp_item != NULL && tmp_item->type == cJSON_Number) {
rules->del_items[i].super_group_id = tmp_item->valueint;
}
tmp_item = cJSON_GetObjectItem(item_obj, "is_exclude");
if (tmp_item != NULL && tmp_item->type == cJSON_Number) {
rules->del_items[i].is_exclude = tmp_item->valueint;
}
}
rules->n_del_item = rule_cnt;
next:
cJSON_Delete(root);
FREE(json_buff);
return ret;
}
class MaatGroupExclude : public testing::Test
{
protected:
static void SetUpTestCase() {
unsigned char *json_buff = NULL;
size_t json_buff_size = 0;
logger = log_handle_create("./group_exclude_gtest.log", 0);
garbage_bin = maat_garbage_bin_new(60);
int ret = load_file_to_memory("./group_exclude_table_info.conf",
&json_buff, &json_buff_size);
if (ret < 0) {
log_error(logger, MODULE_GROUP_EXCLUDE_GTEST, "load_file_to_memory failed.");
assert(0);
}
cJSON *root = cJSON_Parse((const char *)json_buff);
if (!root) {
log_error(logger, MODULE_GROUP_EXCLUDE_GTEST, "cJSON_Parse failed.");
assert(0);
}
g2g_schema = group2group_schema_new(root, NULL, "EXCLUDE_GROUP2GROUP", logger);
FREE(json_buff);
cJSON_Delete(root);
if (NULL == g2g_schema) {
log_error(logger, MODULE_GROUP_EXCLUDE_GTEST, "group2group_schema_new failed.");
assert(0);
}
g2g_runtime = group2group_runtime_new(g2g_schema, 1, garbage_bin, logger);
if (NULL == g2g_runtime) {
log_error(logger, MODULE_GROUP_EXCLUDE_GTEST, "group2group_runtime_new failed.");
assert(0);
}
}
static void TearDownTestCase() {
log_handle_destroy(logger);
maat_garbage_bin_free(garbage_bin);
group2group_runtime_free(g2g_runtime);
group2group_schema_free(g2g_schema);
}
static void *g2g_schema;
static void *g2g_runtime;
static struct log_handle *logger;
static struct maat_garbage_bin *garbage_bin;
};
void *MaatGroupExclude::g2g_schema;
void *MaatGroupExclude::g2g_runtime;
struct log_handle *MaatGroupExclude::logger;
struct maat_garbage_bin *MaatGroupExclude::garbage_bin;
TEST_F(MaatGroupExclude, level_3_basic) {
char table_line[1024];
struct group2group_rule rules;
const char *table_name = "EXCLUDE_GROUP2GROUP";
//struct log_handle *logger = MaatGroupExclude::logger;
int ret = parse_config_file("group_exclude_L3.conf", &rules);
EXPECT_EQ(ret, 0);
for (size_t i = 0; i < rules.n_add_item; i++) {
memset(table_line, 0, sizeof(table_line));
sprintf(table_line, "%lld\t%lld\t%d\t%d", rules.add_items[i].group_id,
rules.add_items[i].super_group_id, rules.add_items[i].is_exclude, 1);
group2group_runtime_update(g2g_runtime, g2g_schema, table_name, table_line, 4);
}
group2group_runtime_commit(g2g_runtime, table_name, 1);
long long hit_group_ids[2] = {11, 4};
long long super_group_ids[MAX_ITEM_NUM];
size_t super_group_cnt = group2group_runtime_get_super_groups(g2g_runtime, hit_group_ids, 2,
super_group_ids, MAX_ITEM_NUM);
for (size_t i = 0; i < super_group_cnt; i++) {
printf("super_group_ids[%zu]:%lld\n", i, super_group_ids[i]);
}
}
int main(int argc, char ** argv)
{
int ret=0;
::testing::InitGoogleTest(&argc, argv);
ret=RUN_ALL_TESTS();
return ret;
}

View File

@@ -0,0 +1,11 @@
{
"table_id":1,
"table_name":"EXCLUDE_GROUP2GROUP",
"table_type":"group2group",
"valid_column":4,
"custom": {
"group_id":1,
"super_group_id":2,
"is_exclude":3
}
}

View File

@@ -1,12 +0,0 @@
#include "maat.h"
#include "maat_rule.h"
#include <gtest/gtest.h>
int main(int argc, char ** argv)
{
int ret=0;
::testing::InitGoogleTest(&argc, argv);
ret=RUN_ALL_TESTS();
return ret;
}

View File

@@ -775,7 +775,7 @@ TEST_F(MaatFlagScan, FlagPlus) {
maat_state_free(state);
state = NULL;
}
#if 1
class MaatStringScan : public testing::Test
{
protected:
@@ -6160,7 +6160,6 @@ TEST_F(MaatRollbackTest, FullConfigRollback) {
maat_state_free(state);
state = NULL;
}
#endif
int main(int argc, char ** argv)
{