fieldstat增加health check功能的计数
This commit is contained in:
@@ -49,6 +49,11 @@ struct global_metrics
|
||||
uint64_t control_packet_resetall_num; // 累计值
|
||||
uint64_t control_packet_error_num; // 累计值
|
||||
|
||||
uint64_t sf_active_times; // 累计值
|
||||
uint64_t sf_inactive_times; // 累计值
|
||||
uint64_t sf_mac_exist_times; // 累计值
|
||||
uint64_t sf_mac_noexist_times; // 累计值
|
||||
|
||||
uint64_t session_nums; // 瞬时值
|
||||
|
||||
struct global_metrics_config config;
|
||||
|
||||
@@ -39,6 +39,7 @@ enum session_action_reason
|
||||
ACTION_BYPASS_DUE_UNAVAILABLE_ACTION = 0x13,
|
||||
ACTION_BYPASS_DUE_FAILURE_ACTION = 0x14,
|
||||
ACTION_BYPASS_DUE_INVALID_POLICY = 0x15,
|
||||
ACTION_BYPASS_DUE_INVALID_SF_MAC = 0x16,
|
||||
|
||||
ACTION_BLOCK_DUE_UNAVAILABLE_ACTION = 0x21,
|
||||
ACTION_BLOCK_DUE_FAILURE_ACTION = 0x22,
|
||||
@@ -126,7 +127,7 @@ void selected_chaining_dump(struct selected_chaining *chaining);
|
||||
void selected_chaining_bref(struct selected_chaining *chaining);
|
||||
|
||||
const char *session_action_reason_to_string(enum session_action_reason session_action_reason);
|
||||
void policy_enforce_select_chaining(struct selected_chaining *chaining, struct policy_enforcer *enforcer, struct raw_pkt_parser *parser, int policy_id, int dir_is_internal);
|
||||
void policy_enforce_select_chaining(struct selected_chaining *chaining, struct policy_enforcer *enforcer, struct raw_pkt_parser *parser, int policy_id, int dir_is_internal, struct session_ctx *s_ctx);
|
||||
|
||||
#ifdef __cpluscplus
|
||||
}
|
||||
|
||||
@@ -56,6 +56,8 @@ struct session_ctx
|
||||
// depending on first control packet
|
||||
struct packet_info first_ctrl_pkt;
|
||||
struct selected_chaining *chaining;
|
||||
|
||||
struct thread_ctx *ref_thread_ctx;
|
||||
};
|
||||
|
||||
struct session_ctx *session_ctx_new();
|
||||
|
||||
@@ -65,6 +65,12 @@ enum SCE_STAT_FIELD
|
||||
STAT_KEEPALIVE_RX_PKT,
|
||||
STAT_KEEPALIVE_RX_B,
|
||||
|
||||
// health check
|
||||
STAT_SF_ACTIVE_TIMES,
|
||||
STAT_SF_INACTIVE_TIMES,
|
||||
STAT_SF_MAC_EXIST_TIMES,
|
||||
STAT_SF_MAC_NOEXIST_TIMES,
|
||||
|
||||
// max
|
||||
STAT_MAX,
|
||||
};
|
||||
@@ -128,6 +134,12 @@ static const char *stat_map[] =
|
||||
[STAT_KEEPALIVE_RX_PKT] = "kepalive_rx_pkt",
|
||||
[STAT_KEEPALIVE_RX_B] = "kepalive_rx_B",
|
||||
|
||||
// health check
|
||||
[STAT_SF_ACTIVE_TIMES] = "sf_active_num",
|
||||
[STAT_SF_INACTIVE_TIMES] = "sf_inactive_num",
|
||||
[STAT_SF_MAC_EXIST_TIMES] = "sf_mac_succ_num",
|
||||
[STAT_SF_MAC_NOEXIST_TIMES] = "sf_mac_err_num",
|
||||
|
||||
[STAT_MAX] = NULL};
|
||||
|
||||
static void global_metrics_parse_config(const char *profile, struct global_metrics_config *config)
|
||||
@@ -265,5 +277,11 @@ void global_metrics_dump(struct global_metrics *metrics)
|
||||
// current session number
|
||||
FS_operate(metrics->fs_handle, metrics->fs_id[STAT_CURRENT_SESSION_NUMS], 0, FS_OP_SET, __atomic_fetch_add(&(metrics->session_nums), 0, __ATOMIC_RELAXED));
|
||||
|
||||
// health check
|
||||
FS_operate(metrics->fs_handle, metrics->fs_id[STAT_SF_ACTIVE_TIMES], 0, FS_OP_SET, __atomic_fetch_add(&(metrics->sf_active_times), 0, __ATOMIC_RELAXED));
|
||||
FS_operate(metrics->fs_handle, metrics->fs_id[STAT_SF_INACTIVE_TIMES], 0, FS_OP_SET, __atomic_fetch_add(&(metrics->sf_inactive_times), 0, __ATOMIC_RELAXED));
|
||||
FS_operate(metrics->fs_handle, metrics->fs_id[STAT_SF_MAC_EXIST_TIMES], 0, FS_OP_SET, __atomic_fetch_add(&(metrics->sf_mac_exist_times), 0, __ATOMIC_RELAXED));
|
||||
FS_operate(metrics->fs_handle, metrics->fs_id[STAT_SF_MAC_NOEXIST_TIMES], 0, FS_OP_SET, __atomic_fetch_add(&(metrics->sf_mac_noexist_times), 0, __ATOMIC_RELAXED));
|
||||
|
||||
FS_passive_output(metrics->fs_handle);
|
||||
}
|
||||
|
||||
@@ -1076,6 +1076,7 @@ static int forward_all_nf_packet_to_sf(struct packet_io *handle, marsio_buff_t *
|
||||
}
|
||||
|
||||
s_ctx = session_ctx_new();
|
||||
s_ctx->ref_thread_ctx = thread;
|
||||
s_ctx->session_id = meta.session_id;
|
||||
s_ctx->first_ctrl_pkt.dir_is_e2i = meta.dir_is_e2i;
|
||||
raw_packet_parser_get_most_inner_tuple4(&raw_parser, &inner_tuple4);
|
||||
@@ -1218,6 +1219,7 @@ static int handle_session_opening(struct metadata *meta, struct ctrl_pkt_parser
|
||||
}
|
||||
|
||||
struct session_ctx *s_ctx = session_ctx_new();
|
||||
s_ctx->ref_thread_ctx = thread;
|
||||
fixed_num_array_init(&s_ctx->policy_ids);
|
||||
s_ctx->session_id = meta->session_id;
|
||||
s_ctx->first_ctrl_pkt.dir_is_e2i = meta->dir_is_e2i;
|
||||
@@ -1238,7 +1240,7 @@ static int handle_session_opening(struct metadata *meta, struct ctrl_pkt_parser
|
||||
}
|
||||
else
|
||||
{
|
||||
policy_enforce_select_chaining(s_ctx->chaining, thread->ref_enforcer, &raw_parser, new_policy_id, meta->dir_is_e2i);
|
||||
policy_enforce_select_chaining(s_ctx->chaining, thread->ref_enforcer, &raw_parser, new_policy_id, meta->dir_is_e2i, s_ctx);
|
||||
selected_chaining_bref(s_ctx->chaining);
|
||||
fixed_num_array_add_elem(&s_ctx->policy_ids, new_policy_id);
|
||||
}
|
||||
@@ -1303,7 +1305,7 @@ static int handle_session_active(struct metadata *meta, struct ctrl_pkt_parser *
|
||||
}
|
||||
else
|
||||
{
|
||||
policy_enforce_select_chaining(s_ctx->chaining, thread->ref_enforcer, &raw_parser, new_policy_id, meta->dir_is_e2i);
|
||||
policy_enforce_select_chaining(s_ctx->chaining, thread->ref_enforcer, &raw_parser, new_policy_id, meta->dir_is_e2i, s_ctx);
|
||||
selected_chaining_bref(s_ctx->chaining);
|
||||
fixed_num_array_add_elem(&s_ctx->policy_ids, new_policy_id);
|
||||
}
|
||||
|
||||
@@ -5,11 +5,13 @@
|
||||
#include <MESA/Maat_rule.h>
|
||||
#include <MESA/MESA_prof_load.h>
|
||||
|
||||
#include "global_metrics.h"
|
||||
#include "health_check.h"
|
||||
#include "raw_packet.h"
|
||||
#include "policy.h"
|
||||
#include "utils.h"
|
||||
#include "log.h"
|
||||
#include "sce.h"
|
||||
|
||||
/******************************************************************************
|
||||
* Struct policy_enforcer
|
||||
@@ -206,6 +208,8 @@ const char *session_action_reason_to_string(enum session_action_reason session_a
|
||||
return "bypass_due_failure_action";
|
||||
case ACTION_BYPASS_DUE_INVALID_POLICY:
|
||||
return "bypass_due_invalid_policy";
|
||||
case ACTION_BYPASS_DUE_INVALID_SF_MAC:
|
||||
return "bypass_due_invalid_sf_mac";
|
||||
case ACTION_BLOCK_DUE_UNAVAILABLE_ACTION:
|
||||
return "block_due_unavailable_action";
|
||||
case ACTION_BLOCK_DUE_FAILURE_ACTION:
|
||||
@@ -1037,8 +1041,11 @@ static void select_sf_by_nearby_and_active(struct policy_enforcer *enforcer, str
|
||||
// return : SESSION_ACTION_BYPASS, not care selected_sf_profile_id
|
||||
// return : SESSION_ACTION_BLOCK, not care selected_sf_profile_id
|
||||
// return : SESSION_ACTION_FORWARD, care selected_sf_profile_id
|
||||
static enum session_action select_sf_by_ldbc(uint64_t hash, struct sff_param *sff_param, struct fixed_num_array *array, int *selected_sf_profile_id, enum session_action_reason *sf_action_reason)
|
||||
static enum session_action select_sf_by_ldbc(uint64_t hash, struct sff_param *sff_param, struct fixed_num_array *array, int *selected_sf_profile_id, enum session_action_reason *sf_action_reason, struct session_ctx *s_ctx)
|
||||
{
|
||||
struct thread_ctx *thread = (struct thread_ctx *)s_ctx->ref_thread_ctx;
|
||||
struct global_metrics *g_metrics = thread->ref_metrics;
|
||||
|
||||
*selected_sf_profile_id = -1;
|
||||
int sf_is_active = 0;
|
||||
int sf_profile_id = 0;
|
||||
@@ -1055,12 +1062,16 @@ static enum session_action select_sf_by_ldbc(uint64_t hash, struct sff_param *sf
|
||||
|
||||
if (sf_is_active)
|
||||
{
|
||||
__atomic_fetch_add(&g_metrics->sf_active_times, 1, __ATOMIC_RELAXED);
|
||||
|
||||
*selected_sf_profile_id = sf_profile_id;
|
||||
*sf_action_reason = ACTION_FORWAED_DUE_SELECTED_AVAILABLE_SF;
|
||||
return SESSION_ACTION_FORWARD;
|
||||
}
|
||||
else
|
||||
{
|
||||
__atomic_fetch_add(&g_metrics->sf_inactive_times, 1, __ATOMIC_RELAXED);
|
||||
|
||||
if (sff_param->sff_exception.fail_action == FAILURE_ACTION_RE_DISPATCH)
|
||||
{
|
||||
fixed_num_array_del_elem(array, sf_profile_id);
|
||||
@@ -1403,8 +1414,11 @@ void selected_chaining_bref(struct selected_chaining *chaining)
|
||||
LOG_DEBUG("%s: selected_chaining_bref: %s}", LOG_TAG_POLICY, buff);
|
||||
}
|
||||
|
||||
void policy_enforce_select_chaining(struct selected_chaining *chaining, struct policy_enforcer *enforcer, struct raw_pkt_parser *parser, int policy_id, int dir_is_internal)
|
||||
void policy_enforce_select_chaining(struct selected_chaining *chaining, struct policy_enforcer *enforcer, struct raw_pkt_parser *parser, int policy_id, int dir_is_internal, struct session_ctx *s_ctx)
|
||||
{
|
||||
struct thread_ctx *thread = (struct thread_ctx *)s_ctx->ref_thread_ctx;
|
||||
struct global_metrics *g_metrics = thread->ref_metrics;
|
||||
|
||||
uint64_t hash_value = 0;
|
||||
char buffer[16] = {0};
|
||||
struct sf_param *sf_param = NULL;
|
||||
@@ -1460,7 +1474,7 @@ void policy_enforce_select_chaining(struct selected_chaining *chaining, struct p
|
||||
}
|
||||
|
||||
hash_value = raw_packet_parser_get_hash_value(parser, sff_param->sff_ldbc.method, dir_is_internal);
|
||||
item->sf_action = select_sf_by_ldbc(hash_value, sff_param, &array, &(item->sf_profile_id), &(item->sf_action_reason));
|
||||
item->sf_action = select_sf_by_ldbc(hash_value, sff_param, &array, &(item->sf_profile_id), &(item->sf_action_reason), s_ctx);
|
||||
LOG_DEBUG("%s: chaining policy %d -> sff_profile %d sf_profile_ids_num %d (after filter ldbc)", LOG_TAG_POLICY, policy_id, item->sff_profile_id, fixed_num_array_count_elem(&array));
|
||||
if (item->sf_action != SESSION_ACTION_FORWARD)
|
||||
{
|
||||
@@ -1495,7 +1509,22 @@ void policy_enforce_select_chaining(struct selected_chaining *chaining, struct p
|
||||
}
|
||||
else
|
||||
{
|
||||
health_check_session_get_mac(item->sf_profile_id, item->sf_dst_mac);
|
||||
if (health_check_session_get_mac(item->sf_profile_id, item->sf_dst_mac) == 0)
|
||||
{
|
||||
__atomic_fetch_add(&g_metrics->sf_mac_exist_times, 1, __ATOMIC_RELAXED);
|
||||
}
|
||||
else
|
||||
{
|
||||
__atomic_fetch_add(&g_metrics->sf_mac_noexist_times, 1, __ATOMIC_RELAXED);
|
||||
|
||||
LOG_ERROR("%s: failed to get sf mac address of selected profile %d, bypass current sff !!!", LOG_TAG_POLICY, item->sf_profile_id);
|
||||
item->sf_action = SESSION_ACTION_BYPASS;
|
||||
item->sf_action_reason = ACTION_BYPASS_DUE_INVALID_SF_MAC;
|
||||
chaining->chaining_used++;
|
||||
sff_param_free(sff_param);
|
||||
sf_param_free(sf_param);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
chaining->chaining_used++;
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "sce.h"
|
||||
#include "policy.h"
|
||||
#include "raw_packet.h"
|
||||
#include "global_metrics.h"
|
||||
|
||||
unsigned char data1[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0xa4, 0xc6, 0x4f, 0x3b, 0xb3, 0x9a, 0x81, 0x00, 0x66, 0x58, 0x81, 0x00, 0x61, 0xf9, 0x08, 0x00, 0x45, 0xb8, 0x00, 0x94,
|
||||
@@ -24,6 +26,13 @@ TEST(POLICY, SELECTED_CHAINING_LIFE_CYCLE)
|
||||
|
||||
TEST(POLICY, POLICY_ENFORCER_LIFE_CYCLE)
|
||||
{
|
||||
struct global_metrics g_metrics;
|
||||
struct thread_ctx t_ctx;
|
||||
struct session_ctx s_ctx;
|
||||
|
||||
t_ctx.ref_metrics = &g_metrics;
|
||||
s_ctx.ref_thread_ctx = &t_ctx;
|
||||
|
||||
struct raw_pkt_parser handler;
|
||||
raw_packet_parser_init(&handler, 0, LAYER_TYPE_ALL, 8);
|
||||
|
||||
@@ -39,10 +48,10 @@ TEST(POLICY, POLICY_ENFORCER_LIFE_CYCLE)
|
||||
int dir_is_internal = 1;
|
||||
struct selected_chaining *chaining = selected_chaining_create(64);
|
||||
EXPECT_TRUE(chaining != nullptr);
|
||||
policy_enforce_select_chaining(chaining, enforcer, &handler, 1, dir_is_internal);
|
||||
policy_enforce_select_chaining(chaining, enforcer, &handler, 2, dir_is_internal);
|
||||
policy_enforce_select_chaining(chaining, enforcer, &handler, 11, dir_is_internal);
|
||||
policy_enforce_select_chaining(chaining, enforcer, &handler, 12, dir_is_internal);
|
||||
policy_enforce_select_chaining(chaining, enforcer, &handler, 1, dir_is_internal, &s_ctx);
|
||||
policy_enforce_select_chaining(chaining, enforcer, &handler, 2, dir_is_internal, &s_ctx);
|
||||
policy_enforce_select_chaining(chaining, enforcer, &handler, 11, dir_is_internal, &s_ctx);
|
||||
policy_enforce_select_chaining(chaining, enforcer, &handler, 12, dir_is_internal, &s_ctx);
|
||||
selected_chaining_dump(chaining);
|
||||
selected_chaining_bref(chaining);
|
||||
selected_chaining_destory(chaining);
|
||||
|
||||
Reference in New Issue
Block a user