diff options
| author | root <[email protected]> | 2024-10-17 10:20:30 +0000 |
|---|---|---|
| committer | root <[email protected]> | 2024-10-17 10:20:30 +0000 |
| commit | d0d37d605abe3413ff8afca150e20e475880e78e (patch) | |
| tree | 296b4cf7b4fb3172a9d493bc8745fb7293b73463 /shaping/src | |
| parent | b0de64f0deb1672f0b183f72b99d615f00a73b3b (diff) | |
TSG-22757: 1.适配新版maat,加载json格式的规则 2.适配规则ID变为UUID
Diffstat (limited to 'shaping/src')
| -rw-r--r-- | shaping/src/shaper.cpp | 44 | ||||
| -rw-r--r-- | shaping/src/shaper_aqm.cpp | 32 | ||||
| -rw-r--r-- | shaping/src/shaper_maat.cpp | 233 | ||||
| -rw-r--r-- | shaping/src/shaper_marsio.cpp | 4 | ||||
| -rw-r--r-- | shaping/src/shaper_session.cpp | 14 | ||||
| -rw-r--r-- | shaping/src/shaper_stat.cpp | 33 |
6 files changed, 181 insertions, 179 deletions
diff --git a/shaping/src/shaper.cpp b/shaping/src/shaper.cpp index 9c2a49f..f7a81fb 100644 --- a/shaping/src/shaper.cpp +++ b/shaping/src/shaper.cpp @@ -35,8 +35,8 @@ extern "C" { #define SWARMKV_CALLER_LOOP_DIVISOR_MIN 1 #define SWARMKV_CALLER_LOOP_DIVISOR_MAX 10 -#define SWARMKV_IN_QUEUE_LEN_GET_CMD "HMGET tsg-shaping-%d priority-0-in priority-1-in priority-2-in priority-3-in priority-4-in priority-5-in priority-6-in priority-7-in priority-8-in priority-9-in" -#define SWARMKV_OUT_QUEUE_LEN_GET_CMD "HMGET tsg-shaping-%d priority-0-out priority-1-out priority-2-out priority-3-out priority-4-out priority-5-out priority-6-out priority-7-out priority-8-out priority-9-out" +#define SWARMKV_IN_QUEUE_LEN_GET_CMD "HMGET tsg-shaping-%s priority-0-in priority-1-in priority-2-in priority-3-in priority-4-in priority-5-in priority-6-in priority-7-in priority-8-in priority-9-in" +#define SWARMKV_OUT_QUEUE_LEN_GET_CMD "HMGET tsg-shaping-%s priority-0-out priority-1-out priority-2-out priority-3-out priority-4-out priority-5-out priority-6-out priority-7-out priority-8-out priority-9-out" struct shaper {//trees in one thread struct avl_tree *priority_trees[SHAPING_PRIORITY_NUM_MAX][SHAPING_DIR_MAX];//represent 10 avl tree corresponding to 10 priority @@ -442,7 +442,7 @@ static void shaper_token_multiple_update(struct shaping_thread_ctx *ctx, struct } END: - LOG_INFO("%s: profile id %d, token_get_multiple %d, has_failed_get_token %d, token_not_enough %d", LOG_TAG_SHAPING, profile->id, token_multiple->token_get_multiple, token_multiple->has_failed_get_token, token_multiple->token_not_enough); + LOG_INFO("%s: profile id %s, token_get_multiple %d, has_failed_get_token %d, token_not_enough %d", LOG_TAG_SHAPING, uuid_print_str(profile->uuid), token_multiple->token_get_multiple, token_multiple->has_failed_get_token, token_multiple->token_not_enough); token_multiple->has_failed_get_token = 0; token_multiple->token_not_enough = 0; @@ -476,7 +476,7 @@ static void shaper_deposit_token_add(struct shaping_thread_ctx *ctx, struct shap } break; default: - LOG_ERROR("%s: invalid profile type %d, profile id %d", LOG_TAG_SHAPING, profile->type, profile->id); + LOG_ERROR("%s: invalid profile type %d, profile id %s", LOG_TAG_SHAPING, profile->type, uuid_print_str(profile->uuid)); return; } @@ -508,7 +508,7 @@ static void shaper_token_get_cb(const struct swarmkv_reply *reply, void * cb_arg shaper_global_stat_async_callback_inc(&ctx->thread_global_stat); shaper_global_stat_tconsume_callback_inc(&ctx->thread_global_stat); - LOG_DEBUG("Swarmkv reply type =%d, profile_id %d, direction =%d, integer =%llu",reply->type, profile->id, arg->direction, reply->integer); + LOG_DEBUG("Swarmkv reply type =%d, profile_id %s, direction =%d, integer =%llu",reply->type, uuid_print_str(profile->uuid), arg->direction, reply->integer); if (reply->type != SWARMKV_REPLY_INTEGER) { shaper_global_stat_async_tconsume_failed_inc(&ctx->thread_global_stat); @@ -599,7 +599,7 @@ static int shaper_deposit_token_get(struct shaping_profile_info *profile, int re token_multiple = TOKEN_MULTIPLE_DEFAULT; break; default: - LOG_ERROR("%s: invalid profile type %d, profile id %d", LOG_TAG_SHAPING, profile->type, profile->id); + LOG_ERROR("%s: invalid profile type %d, profile id %s", LOG_TAG_SHAPING, profile->type, uuid_print_str(profile->uuid)); return 0; } @@ -627,7 +627,7 @@ static void shaper_profile_hash_node_refresh(struct shaping_thread_ctx *ctx, str return; } - struct shaping_profile *profile = shaper_maat_profile_get(ctx, pf_hash_node->id); + struct shaping_profile *profile = shaper_maat_profile_get(ctx, pf_hash_node->uuid); if (profile) { pf_hash_node->limit_direction = profile->limit_direction; pf_hash_node->aqm_type = profile->aqm_type; @@ -641,7 +641,7 @@ static void shaper_token_get_from_profile(struct shaping_thread_ctx *ctx, struct { struct shaping_tconsume_cb_arg *arg = NULL; struct shaping_profile_hash_node *pf_hash_node = pf_info->hash_node; - char key[32] = {0}; + char key[64] = {0}; if (pf_hash_node->tconsume_ref_cnt > 0) { return; @@ -650,9 +650,9 @@ static void shaper_token_get_from_profile(struct shaping_thread_ctx *ctx, struct shaper_profile_hash_node_refresh(ctx, pf_hash_node, curr_timespec); if (pf_hash_node->limit_direction == PROFILE_LIMIT_DIRECTION_BIDIRECTION) { - snprintf(key, sizeof(key), "tsg-shaping-%d-bidirectional", pf_info->id); + snprintf(key, sizeof(key), "tsg-shaping-%s-bidirectional", uuid_print_str(pf_info->uuid)); } else { - snprintf(key, sizeof(key), "tsg-shaping-%d-%s", pf_info->id, dir == SHAPING_DIR_OUT ? "outgoing" : "incoming"); + snprintf(key, sizeof(key), "tsg-shaping-%s-%s", uuid_print_str(pf_info->uuid), dir == SHAPING_DIR_OUT ? "outgoing" : "incoming"); } arg = (struct shaping_tconsume_cb_arg *)calloc(1, sizeof(struct shaping_tconsume_cb_arg)); @@ -769,9 +769,9 @@ static int shaper_profile_is_priority_blocked(struct shaping_thread_ctx *ctx, st shaper_global_stat_async_invoke_inc(&ctx->thread_global_stat); shaper_global_stat_hmget_invoke_inc(&ctx->thread_global_stat); if (direction == SHAPING_DIR_IN) { - swarmkv_async_command(ctx->swarmkv_db, shaper_queue_len_get_cb, arg, SWARMKV_IN_QUEUE_LEN_GET_CMD, profile->id); + swarmkv_async_command(ctx->swarmkv_db, shaper_queue_len_get_cb, arg, SWARMKV_IN_QUEUE_LEN_GET_CMD, uuid_print_str(profile->uuid)); } else { - swarmkv_async_command(ctx->swarmkv_db, shaper_queue_len_get_cb, arg, SWARMKV_OUT_QUEUE_LEN_GET_CMD, profile->id); + swarmkv_async_command(ctx->swarmkv_db, shaper_queue_len_get_cb, arg, SWARMKV_OUT_QUEUE_LEN_GET_CMD, uuid_print_str(profile->uuid)); } for (int i = 0; i < priority; i++) { @@ -794,14 +794,15 @@ void shaper_profile_hash_node_set(struct shaping_thread_ctx *ctx, struct shaping { if (profile->hash_node == NULL) { struct shaping_profile_hash_node *hash_node = NULL; - HASH_FIND_INT(thread_sp_hashtbl, &profile->id, hash_node); + + HASH_FIND(hh, thread_sp_hashtbl, &(profile->uuid), sizeof(uuid_t), hash_node); if (hash_node) { profile->hash_node = hash_node; } else { profile->hash_node = (struct shaping_profile_hash_node*)calloc(1, sizeof(struct shaping_profile_hash_node)); - profile->hash_node->id = profile->id; + uuid_copy(profile->hash_node->uuid, profile->uuid); profile->hash_node->token_multiple.token_get_multiple = TOKEN_MULTIPLE_DEFAULT; - HASH_ADD_INT(thread_sp_hashtbl, id, profile->hash_node); + HASH_ADD(hh, thread_sp_hashtbl, uuid, sizeof(uuid_t), profile->hash_node); timeout_init(&profile->hash_node->timeout_handle, TIMEOUT_ABS); timeouts_add(ctx->expires, &profile->hash_node->timeout_handle, time(NULL) + SHAPING_STAT_REFRESH_INTERVAL_SEC); } @@ -841,7 +842,7 @@ static int shaper_token_consume(struct shaping_thread_ctx *ctx, struct shaping_f time_t curr_time = time(NULL); if (curr_time - sf->check_rule_time >= ctx->conf.check_rule_enable_interval_sec) { sf->check_rule_time = curr_time; - if (shaper_rule_is_enabled(ctx, rule->id) != 1) { + if (shaper_rule_is_enabled(ctx, rule->uuid) != 1) { rule->is_enabled = 0; return SHAPER_TOKEN_GET_PASS;//rule is disabled, don't need to get token and forward packet } else { @@ -1381,7 +1382,8 @@ static void shaper_datapath_telemetry_info_append(struct shaping_marsio_info *ma for (int i= 0; i < sf->rule_num; i++) { rule = &sf->matched_rule_infos[i]; - len += snprintf(datapath_telemetry_str + len, sizeof(datapath_telemetry_str) - len, "rule_id=%d, primary_pf_id=%d", rule->id, rule->primary.id); + len += snprintf(datapath_telemetry_str + len, sizeof(datapath_telemetry_str) - len, "rule_id=%s, ", uuid_print_str(rule->uuid)); + len += snprintf(datapath_telemetry_str + len, sizeof(datapath_telemetry_str) - len, "primary_pf_id=%s", uuid_print_str(rule->primary.uuid)); if (rule->borrowing_num > 0) { len += snprintf(datapath_telemetry_str + len, sizeof(datapath_telemetry_str) - len, ", borrow_pf_ids:["); @@ -1390,7 +1392,7 @@ static void shaper_datapath_telemetry_info_append(struct shaping_marsio_info *ma if (j != 0) { len += snprintf(datapath_telemetry_str + len, sizeof(datapath_telemetry_str) - len, ","); } - len += snprintf(datapath_telemetry_str + len, sizeof(datapath_telemetry_str) - len, "%d", rule->borrowing[j].id); + len += snprintf(datapath_telemetry_str + len, sizeof(datapath_telemetry_str) - len, "%s", rule->borrowing[j].uuid); } if (rule->borrowing_num > 0) { len += snprintf(datapath_telemetry_str + len, sizeof(datapath_telemetry_str) - len, "]"); @@ -1556,7 +1558,7 @@ void shaping_engine_destroy(struct shaping_ctx *ctx) if (ctx) { shaper_swarmkv_destroy(ctx->swarmkv_db); - shaper_maat_destroy(ctx->maat_info); + shaper_maat_destroy(); shaper_marsio_destroy(ctx->marsio_info); shaper_stat_destroy(ctx->stat); shaper_global_stat_destroy(ctx->global_stat); @@ -1598,8 +1600,7 @@ struct shaping_ctx *shaping_engine_init() } /*init maat*/ - ctx->maat_info = shaper_maat_init("SHAPING"); - if (ctx->maat_info == NULL) { + if (shaper_maat_init("SHAPING") < 0) { goto ERROR; } @@ -1627,7 +1628,6 @@ struct shaping_ctx *shaping_engine_init() ctx->thread_ctx[i].stat = ctx->stat; ctx->thread_ctx[i].global_stat = ctx->global_stat; ctx->thread_ctx[i].session_table = session_table_create(); - ctx->thread_ctx[i].maat_info = ctx->maat_info; ctx->thread_ctx[i].marsio_info = ctx->marsio_info; ctx->thread_ctx[i].swarmkv_db = ctx->swarmkv_db; ctx->thread_ctx[i].expires = timeouts_open(0, &error); diff --git a/shaping/src/shaper_aqm.cpp b/shaping/src/shaper_aqm.cpp index 1de33e9..bdfa443 100644 --- a/shaping/src/shaper_aqm.cpp +++ b/shaping/src/shaper_aqm.cpp @@ -5,7 +5,7 @@ #include "shaper_aqm.h" thread_local unsigned int seed = 0; -int shaper_aqm_blue_need_drop(int profile_id, struct shaper_aqm_blue_para *para, int curr_queue_len) +int shaper_aqm_blue_need_drop(uuid_t profile_uuid, struct shaper_aqm_blue_para *para, int curr_queue_len) { time_t curr_time; @@ -17,7 +17,7 @@ int shaper_aqm_blue_need_drop(int profile_id, struct shaper_aqm_blue_para *para, para->probability = (para->probability - BLUE_DECREMENT) >= 0 ? (para->probability - BLUE_DECREMENT) : 0; } - LOG_INFO("%s: profile id: %d blue probability update to %d", LOG_TAG_SHAPING, profile_id, para->probability); + LOG_INFO("%s: profile id: %s blue probability update to %d", LOG_TAG_SHAPING, uuid_print_str(profile_uuid), para->probability); } if (rand_r(&seed) % BLUE_PROBABILITY_MAX < para->probability) { @@ -27,12 +27,12 @@ int shaper_aqm_blue_need_drop(int profile_id, struct shaper_aqm_blue_para *para, return 0; } -int shaper_aqm_codel_need_drop(int profile_id, struct shaper_aqm_codel_para *para, unsigned long long curr_time_ms, unsigned long long latency_ms) +int shaper_aqm_codel_need_drop(uuid_t profile_uuid, struct shaper_aqm_codel_para *para, unsigned long long curr_time_ms, unsigned long long latency_ms) { if (latency_ms < CODEL_MAX_LATENCY) { if (para->state != CODEL_STATE_NORMAL) { para->state = CODEL_STATE_NORMAL; - LOG_INFO("%s: profile id: %d codel enter state CODEL_STATE_NORMAL, last DROPPING_PHASE drop count %d", LOG_TAG_SHAPING, profile_id, para->drop_count); + LOG_INFO("%s: profile id: %s codel enter state CODEL_STATE_NORMAL, last DROPPING_PHASE drop count %d", LOG_TAG_SHAPING, uuid_print_str(profile_uuid), para->drop_count); } return 0; @@ -43,7 +43,7 @@ int shaper_aqm_codel_need_drop(int profile_id, struct shaper_aqm_codel_para *par case CODEL_STATE_NORMAL: para->start_drop_time_ms = curr_time_ms + CODEL_DROP_INTERVAL; para->state = CODEL_STATE_DROPPING_TIMER; - LOG_INFO("%s: profile id: %d codel enter state CODEL_STATE_DROPPING_TIMER", LOG_TAG_SHAPING, profile_id); + LOG_INFO("%s: profile id: %s codel enter state CODEL_STATE_DROPPING_TIMER", LOG_TAG_SHAPING, uuid_print_str(profile_uuid)); break; case CODEL_STATE_DROPPING_TIMER: if (curr_time_ms >= para->start_drop_time_ms) { @@ -51,7 +51,7 @@ int shaper_aqm_codel_need_drop(int profile_id, struct shaper_aqm_codel_para *par para->drop_count = 1; para->next_drop_time_ms = curr_time_ms + CODEL_DROP_INTERVAL / sqrt(para->drop_count); ret = 1; - LOG_INFO("%s: profile id: %d codel enter state CODEL_STATE_DROPPING_PHASE", LOG_TAG_SHAPING, profile_id); + LOG_INFO("%s: profile id: %s codel enter state CODEL_STATE_DROPPING_PHASE", LOG_TAG_SHAPING, uuid_print_str(profile_uuid)); } break; case CODEL_STATE_DROPPING_PHASE: @@ -69,14 +69,14 @@ int shaper_aqm_codel_need_drop(int profile_id, struct shaper_aqm_codel_para *par } -static int shaper_aqm_have_processed(struct shaping_packet_wrapper *pkt_wrapper, int profile_id) +static int shaper_aqm_have_processed(struct shaping_packet_wrapper *pkt_wrapper, uuid_t profile_uuid) { int i = 0; for (i = 0; i < SHAPING_REF_PROFILE_NUM_MAX; i++) { - if (pkt_wrapper->aqm_processed_pf_ids[i] == profile_id) { + if (uuid_compare(profile_uuid, pkt_wrapper->aqm_processed_pf_uuids[i]) == 0) { return 1; - } else if (pkt_wrapper->aqm_processed_pf_ids[i] == 0) { + } else if (uuid_is_null(pkt_wrapper->aqm_processed_pf_uuids[i])) { break; } } @@ -84,13 +84,13 @@ static int shaper_aqm_have_processed(struct shaping_packet_wrapper *pkt_wrapper, return 0; } -static void shaper_aqm_mark_processed(struct shaping_packet_wrapper *pkt_wrapper, int profile_id) +static void shaper_aqm_mark_processed(struct shaping_packet_wrapper *pkt_wrapper, uuid_t profile_uuid) { int i = 0; for (i = 0; i < SHAPING_REF_PROFILE_NUM_MAX; i++) { - if (pkt_wrapper->aqm_processed_pf_ids[i] == 0) { - pkt_wrapper->aqm_processed_pf_ids[i] = profile_id; + if (uuid_is_null(pkt_wrapper->aqm_processed_pf_uuids[i])) { + uuid_copy(pkt_wrapper->aqm_processed_pf_uuids[i], profile_uuid); break; } } @@ -105,23 +105,23 @@ int shaper_aqm_need_drop(struct shaping_profile_info *profile, struct shaping_pa return 0; } - if (shaper_aqm_have_processed(pkt_wrapper, profile->id)) { + if (shaper_aqm_have_processed(pkt_wrapper, profile->uuid)) { return 0; } switch (profile->hash_node->aqm_type) { case AQM_TYPE_BLUE: - ret = shaper_aqm_blue_need_drop(profile->id, &profile->hash_node->aqm_blue_para, profile->hash_node->queue_len[profile->priority][dir]); + ret = shaper_aqm_blue_need_drop(profile->uuid, &profile->hash_node->aqm_blue_para, profile->hash_node->queue_len[profile->priority][dir]); break; case AQM_TYPE_CODEL: curr_time_ms = curr_time->tv_sec * MILLI_SECONDS_PER_SEC + curr_time->tv_nsec / NANO_SECONDS_PER_MILLI_SEC; - ret = shaper_aqm_codel_need_drop(profile->id, &profile->hash_node->aqm_codel_para, curr_time_ms, latency_us / 1000); + ret = shaper_aqm_codel_need_drop(profile->uuid, &profile->hash_node->aqm_codel_para, curr_time_ms, latency_us / 1000); break; default: break; } - shaper_aqm_mark_processed(pkt_wrapper, profile->id); + shaper_aqm_mark_processed(pkt_wrapper, profile->uuid); return ret; }
\ No newline at end of file diff --git a/shaping/src/shaper_maat.cpp b/shaping/src/shaper_maat.cpp index ea91a1d..e74c280 100644 --- a/shaping/src/shaper_maat.cpp +++ b/shaping/src/shaper_maat.cpp @@ -15,7 +15,7 @@ #include "utils.h" #define SHAPING_STREAM_TIMEOUT 3600 -#define SHAPING_RULE_TABLE_NAME "TRAFFIC_SHAPING_COMPILE" +#define SHAPING_RULE_TABLE_NAME "TRAFFIC_SHAPING_RULE" #define SHAPING_PROFILE_TABLE_NAME "TRAFFIC_SHAPING_PROFILE" enum input_mode @@ -78,16 +78,16 @@ static int dscp_value_to_priority[DSCP_VALUE_MAX] = {DSCP_CLASS_DF, DSCP_CLASS_M struct maat *g_maat_instance = NULL; -void shaper_rule_ex_new(const char *table_name, int table_id, const char *key, const char *table_line, void **ad, long argl, void *argp) +void shaper_rule_ex_new(const char *table_name, const char *key, const char *table_line, void **ad, long argl, void *argp) { struct shaping_rule *s_rule; cJSON *json=NULL; cJSON *tmp_obj = NULL; + cJSON *action_para_obj = NULL; cJSON *tmp_array_obj = NULL; cJSON *dscp_obj = NULL; int array_size; - char user_region[1024] = {0}; - int i, ret; + int i; if (strncmp(table_name, SHAPING_RULE_TABLE_NAME, strlen(table_name)) != 0) { return; @@ -95,77 +95,80 @@ void shaper_rule_ex_new(const char *table_name, int table_id, const char *key, c s_rule = (struct shaping_rule*)calloc(1, sizeof(struct shaping_rule)); - ret = sscanf(table_line, "%d\t%*d\t%*d\t%*d\t%*d\t%*s\t%s\t", &s_rule->id, user_region); - if (ret != 2) { - LOG_ERROR("%s: sscanf parse rule failed for table line %s", LOG_TAG_MAAT, table_line); + json = cJSON_Parse(table_line); + if (!json) { + LOG_ERROR("%s: json parse rule failed for table line %s", LOG_TAG_MAAT, table_line); goto END; } - json = cJSON_Parse(user_region); - if (!json) {//required - LOG_ERROR("%s: json parse rule failed for table line %s", LOG_TAG_MAAT, table_line); + tmp_obj = cJSON_GetObjectItem(json, "uuid"); + if (!tmp_obj) { + LOG_ERROR("%s: json parse uuid failed for table line %s", LOG_TAG_MAAT, table_line); + goto END; + } + uuid_parse(tmp_obj->valuestring, s_rule->uuid); + + action_para_obj = cJSON_GetObjectItem(json, "action_parameter"); + if (!action_para_obj) { + LOG_ERROR("%s: json parse action_parameter failed for table line %s", LOG_TAG_MAAT, table_line); goto END; } - tmp_obj = cJSON_GetObjectItem(json, "vsys_id"); + tmp_obj = cJSON_GetObjectItem(action_para_obj, "vsys_id"); if (!tmp_obj) { LOG_ERROR("%s: json parse vsys_id failed for table line %s", LOG_TAG_MAAT, table_line); goto END; } s_rule->vsys_id = tmp_obj->valueint; - tmp_obj = cJSON_GetObjectItem(json, "priority"); + tmp_obj = cJSON_GetObjectItem(action_para_obj, "priority"); if (!tmp_obj) { LOG_ERROR("%s: json parse priority failed for table line %s", LOG_TAG_MAAT, table_line); goto END; } s_rule->priority = tmp_obj->valueint; - tmp_obj = cJSON_GetObjectItem(json, "fair_factor"); + tmp_obj = cJSON_GetObjectItem(action_para_obj, "fair_factor"); if (!tmp_obj) { - LOG_ERROR("%s: json parse fair-factor failed for table line %s", LOG_TAG_MAAT, table_line); + LOG_ERROR("%s: json parse fair_factor failed for table line %s", LOG_TAG_MAAT, table_line); goto END; } s_rule->fair_factor = tmp_obj->valueint; - //dscp_marking - tmp_obj = cJSON_GetObjectItem(json, "dscp_marking"); - if (!tmp_obj) { + dscp_obj = cJSON_GetObjectItem(action_para_obj, "dscp_marking"); + if (!dscp_obj) { LOG_ERROR("%s: json parse dscp_marking failed for table line %s", LOG_TAG_MAAT, table_line); goto END; } - dscp_obj = cJSON_GetObjectItem(tmp_obj, "enabled"); - if (dscp_obj && dscp_obj->valueint == 1) { - dscp_obj = cJSON_GetObjectItem(tmp_obj, "dscp_value"); - if (dscp_obj && dscp_obj->valueint < DSCP_VALUE_MAX && dscp_value_to_priority[dscp_obj->valueint] != DSCP_CLASS_MAX) { - s_rule->dscp_enable = 1; - s_rule->dscp_value = dscp_obj->valueint; + tmp_obj = cJSON_GetObjectItem(dscp_obj, "enabled"); + if (tmp_obj && tmp_obj->valueint == 1) { + s_rule->dscp_enable = 1; + tmp_obj = cJSON_GetObjectItem(dscp_obj, "dscp_value"); + if (tmp_obj && tmp_obj->valueint < DSCP_VALUE_MAX && dscp_value_to_priority[tmp_obj->valueint] != DSCP_CLASS_MAX) { + s_rule->dscp_value = tmp_obj->valueint; } else { LOG_ERROR("%s: json parse dscp_value wrong for table line %s", LOG_TAG_MAAT, table_line); goto END; } } - //profile_chain - tmp_obj = cJSON_GetObjectItem(json, "profile_chain"); - if (!tmp_obj) {//required + tmp_array_obj = cJSON_GetObjectItem(action_para_obj, "profile_chain"); + if (!tmp_array_obj) { LOG_ERROR("%s: json parse profile_chain failed for table line %s", LOG_TAG_MAAT, table_line); goto END; } - - array_size = cJSON_GetArraySize(tmp_obj); + array_size = cJSON_GetArraySize(tmp_array_obj); if (array_size < 1) { LOG_ERROR("%s: json parse profile_chain empty for table line %s", LOG_TAG_MAAT, table_line); goto END; } - - tmp_array_obj = cJSON_GetArrayItem(tmp_obj, 0); - s_rule->primary_pf_id = tmp_array_obj->valueint; + tmp_obj = cJSON_GetArrayItem(tmp_array_obj, 0); + uuid_parse(tmp_obj->valuestring, s_rule->primary_pf_uuid); s_rule->borrow_pf_num = array_size - 1; for (i = 1; i < array_size; i++) { - tmp_array_obj = cJSON_GetArrayItem(tmp_obj, i); - s_rule->borrow_pf_id_array[i - 1] = tmp_array_obj->valueint; + tmp_obj = cJSON_GetArrayItem(tmp_array_obj, i); + uuid_parse(tmp_obj->valuestring, s_rule->borrow_pf_uuid_array[i - 1]); } END: @@ -176,7 +179,7 @@ END: return; } -void shaper_rule_ex_dup(int table_id, void **to, void **from, long argl, void *argp) +void shaper_rule_ex_dup(const char *table_name, void **to, void **from, long argl, void *argp) { if (*from == NULL) { return; @@ -187,7 +190,7 @@ void shaper_rule_ex_dup(int table_id, void **to, void **from, long argl, void *a return; } -void shaper_rule_ex_free(int table_id, void **ad, long argl, void *argp) +void shaper_rule_ex_free(const char *table_name, void **ad, long argl, void *argp) { if (*ad == NULL) { return; @@ -199,20 +202,16 @@ void shaper_rule_ex_free(int table_id, void **ad, long argl, void *argp) return; } -void shaper_profile_ex_new(const char *table_name, int table_id, const char *key, const char *table_line, void **ad, long argl, void *argp) +void shaper_profile_ex_new(const char *table_name, const char *key, const char *table_line, void **ad, long argl, void *argp) { struct shaping_profile *s_pf; cJSON *json=NULL; cJSON *tmp_array_obj = NULL; cJSON *tmp_obj = NULL; - char profile_type[64] = {0}; - char type_arg[64] = {0}; - char limits[128] = {0}; - char aqm_options[64] = {0}; - char volume_based_shaping[64] = {0}; + cJSON *type_arg_obj = NULL; + cJSON *aqm_options_obj = NULL; + cJSON *limits_obj = NULL; int limit_bandwidth; - int array_size, i; - int ret; if (strncmp(table_name, SHAPING_PROFILE_TABLE_NAME, strlen(table_name)) != 0) { return; @@ -220,26 +219,43 @@ void shaper_profile_ex_new(const char *table_name, int table_id, const char *key s_pf = (struct shaping_profile*)calloc(1, sizeof(struct shaping_profile)); - ret = sscanf(table_line, "%d\t%63s\t%63s\t%127s\t%63s\t%63s\t%d", - &s_pf->id, profile_type, type_arg, limits, aqm_options, volume_based_shaping, &s_pf->valid); - if (ret != 7) { - LOG_ERROR("%s: sscanf parse failed for profile line %s", LOG_TAG_MAAT, table_line); + json = cJSON_Parse(table_line); + if (!json) { + LOG_ERROR("%s: json parse profile failed for table line %s", LOG_TAG_MAAT, table_line); goto END; } - if (strcmp(profile_type, "generic") == 0) { + tmp_obj = cJSON_GetObjectItem(json, "uuid"); + if (!tmp_obj) { + LOG_ERROR("%s: json parse uuid failed for table line %s", LOG_TAG_MAAT, table_line); + goto END; + } + uuid_parse(tmp_obj->valuestring, s_pf->uuid); + + //parse profile type + tmp_obj = cJSON_GetObjectItem(json, "type"); + if (!tmp_obj) { + LOG_ERROR("%s: json parse type failed for table line %s", LOG_TAG_MAAT, table_line); + goto END; + } + type_arg_obj = cJSON_GetObjectItem(json, "type_argument"); + if (!type_arg_obj) { + LOG_ERROR("%s: json parse type_argument failed for table line %s", LOG_TAG_MAAT, table_line); + goto END; + } + if (strcmp(tmp_obj->valuestring, "generic") == 0) { s_pf->type = PROFILE_TYPE_GENERIC; - } else if (strcmp(profile_type, "fair_share") == 0) { - if (strcmp(type_arg, "host_fairness") == 0) { + } else if (strcmp(tmp_obj->valuestring, "fair_share") == 0) { + if (strcmp(type_arg_obj->valuestring, "host_fairness") == 0) { s_pf->type = PROFILE_TYPE_HOST_FARINESS; - } else if (strcmp(type_arg, "max_min_host_fairness") == 0) { + } else if (strcmp(type_arg_obj->valuestring, "max_min_host_fairness") == 0) { s_pf->type = PROFILE_TYPE_MAX_MIN_HOST_FAIRNESS; } else { LOG_ERROR("%s: profile type argument wrong for profile line %s", LOG_TAG_MAAT, table_line); goto END; } - } else if (strcmp(profile_type, "split_by") == 0) { - if (strcmp(type_arg, "local_host") == 0) { + } else if (strcmp(tmp_obj->valuestring, "split_by") == 0) { + if (strcmp(type_arg_obj->valuestring, "local_host") == 0) { s_pf->type = PROFILE_TYPE_SPLIT_BY_LOCAL_HOST; } else { LOG_ERROR("%s: profile type argument wrong for profile line %s", LOG_TAG_MAAT, table_line); @@ -251,16 +267,14 @@ void shaper_profile_ex_new(const char *table_name, int table_id, const char *key } //parse aqm options - json = cJSON_Parse(aqm_options); - if (!json) { - LOG_ERROR("%s: json parse profile aqm options failed for profile id %d, line %s", LOG_TAG_MAAT, s_pf->id, table_line); + aqm_options_obj = cJSON_GetObjectItem(json, "aqm_options"); + if (!aqm_options_obj) { + LOG_ERROR("%s: json parse aqm options failed for line %s", LOG_TAG_MAAT, table_line); goto END; } - - - tmp_obj = cJSON_GetObjectItem(json, "algorithm"); + tmp_obj = cJSON_GetObjectItem(aqm_options_obj, "algorithm"); if (!tmp_obj || tmp_obj->type != cJSON_String || !tmp_obj->valuestring) { - LOG_ERROR("%s: json parse algorithm failed for profile id %d, line %s", LOG_TAG_MAAT, s_pf->id, table_line); + LOG_ERROR("%s: json parse aqm algorithm failed for line %s", LOG_TAG_MAAT, table_line); goto END; } if (strncmp(tmp_obj->valuestring, "none", strlen(tmp_obj->valuestring)) == 0) { @@ -270,32 +284,27 @@ void shaper_profile_ex_new(const char *table_name, int table_id, const char *key } else if (strncmp(tmp_obj->valuestring, "codel", strlen(tmp_obj->valuestring)) == 0) { s_pf->aqm_type = AQM_TYPE_CODEL; } else { - LOG_ERROR("%s: json parse aqm type wrong for profile id %d, line %s", LOG_TAG_MAAT, s_pf->id, table_line); + LOG_ERROR("%s: json parse aqm type wrong for line %s", LOG_TAG_MAAT, table_line); goto END; } - - cJSON_Delete(json); //parse limits of profile - json = cJSON_Parse(limits); - if (!json) { - LOG_ERROR("%s: json parse profile limits failed for profile id %d, line %s", LOG_TAG_MAAT, s_pf->id, table_line); + limits_obj = cJSON_GetObjectItem(json, "limits"); + if (!limits_obj) { + LOG_ERROR("%s: json parse limits failed for line %s", LOG_TAG_MAAT, table_line); goto END; } - - array_size = cJSON_GetArraySize(json); - for (i = 0; i < array_size; i++) { - tmp_array_obj = cJSON_GetArrayItem(json, i); + cJSON_ArrayForEach(tmp_array_obj, limits_obj) { tmp_obj = cJSON_GetObjectItem(tmp_array_obj, "bandwidth"); if (!tmp_obj) { - LOG_ERROR("%s: json parse limit bandwidth failed for profile id %d, line %s", LOG_TAG_MAAT, s_pf->id, table_line); + LOG_ERROR("%s: json parse limit bandwidth failed for line %s", LOG_TAG_MAAT, table_line); goto END; } limit_bandwidth = tmp_obj->valueint; tmp_obj = cJSON_GetObjectItem(tmp_array_obj, "direction"); if (!tmp_obj) { - LOG_ERROR("%s: json parse limit direction failed for profile id %d, line %s", LOG_TAG_MAAT, s_pf->id, table_line); + LOG_ERROR("%s: json parse limit direction failed for line %s", LOG_TAG_MAAT, table_line); goto END; } @@ -322,7 +331,7 @@ END: return; } -void shaper_profile_ex_dup(int table_id, void **to, void **from, long argl, void *argp) +void shaper_profile_ex_dup(const char *table_name, void **to, void **from, long argl, void *argp) { if (*from == NULL) { return; @@ -333,7 +342,7 @@ void shaper_profile_ex_dup(int table_id, void **to, void **from, long argl, void return; } -void shaper_profile_ex_free(int table_id, void **ad, long argl, void *argp) +void shaper_profile_ex_free(const char *table_name, void **ad, long argl, void *argp) { if (*ad == NULL) { return; @@ -347,7 +356,7 @@ void shaper_profile_ex_free(int table_id, void **ad, long argl, void *argp) void shaper_profile_update(struct shaping_thread_ctx *ctx, struct shaping_profile_info *s_pf_info, struct shaping_profile *s_pf_ex) { - s_pf_info->id = s_pf_ex->id; + uuid_copy(s_pf_info->uuid, s_pf_ex->uuid); s_pf_info->type = s_pf_ex->type; shaper_profile_hash_node_set(ctx, s_pf_info); s_pf_info->hash_node->aqm_type = s_pf_ex->aqm_type; @@ -356,37 +365,40 @@ void shaper_profile_update(struct shaping_thread_ctx *ctx, struct shaping_profil return; } -struct shaping_profile *shaper_maat_profile_get(struct shaping_thread_ctx *ctx, int profile_id) +struct shaping_profile *shaper_maat_profile_get(struct shaping_thread_ctx *ctx, uuid_t profile_uuid) { struct shaping_profile *s_pf = NULL; - char pf_id_key[8] = {0}; + char uuid_str[UUID_STR_LEN] = {0}; - snprintf(pf_id_key, sizeof(pf_id_key), "%d", profile_id); - s_pf = (struct shaping_profile *)maat_plugin_table_get_ex_data(g_maat_instance, ctx->maat_info->profile_table_id, pf_id_key, strlen(pf_id_key)); + uuid_unparse(profile_uuid, uuid_str); + s_pf = (struct shaping_profile *)maat_plugin_table_get_ex_data(g_maat_instance, SHAPING_PROFILE_TABLE_NAME, uuid_str, strlen(uuid_str)); if (!s_pf) { - LOG_ERROR("%s maat_plugin_table_get_ex_data get profile failed for key %s", LOG_TAG_MAAT, pf_id_key); + LOG_ERROR("%s maat_plugin_table_get_ex_data get profile failed for key %s", LOG_TAG_MAAT, uuid_str); } return s_pf; } -static int shaper_rule_update(struct shaping_thread_ctx *ctx, struct shaping_flow *sf, struct shaping_rule_info *s_rule_info, long long rule_compile_id, int *priority_changed) +static int shaper_rule_update(struct shaping_thread_ctx *ctx, struct shaping_flow *sf, struct shaping_rule_info *s_rule_info, uuid_t rule_uuid, int *priority_changed) { struct shaping_rule *s_rule = NULL; struct shaping_profile *s_pf = NULL; + char uuid_str[UUID_STR_LEN] = {0}; - s_rule = (struct shaping_rule*)maat_plugin_table_get_ex_data(g_maat_instance, ctx->maat_info->rule_table_id, (char *)&rule_compile_id, sizeof(rule_compile_id)); + uuid_unparse(rule_uuid, uuid_str); + s_rule = (struct shaping_rule*)maat_plugin_table_get_ex_data(g_maat_instance, SHAPING_RULE_TABLE_NAME, uuid_str, strlen(uuid_str)); if (!s_rule) { - LOG_ERROR("%s maat_plugin_table_get_ex_data get rule failed for compile id %lld", LOG_TAG_MAAT, rule_compile_id); + LOG_ERROR("%s maat_plugin_table_get_ex_data get rule failed for rule id %s", LOG_TAG_MAAT, uuid_str); return -1; } - s_rule_info->id = s_rule->id; + + uuid_copy(s_rule_info->uuid, s_rule->uuid); s_rule_info->fair_factor = s_rule->fair_factor; s_rule_info->vsys_id = s_rule->vsys_id; s_rule_info->is_enabled = 1; - s_pf = shaper_maat_profile_get(ctx, s_rule->primary_pf_id); + s_pf = shaper_maat_profile_get(ctx, s_rule->primary_pf_uuid); if (!s_pf) { return -1; } @@ -411,7 +423,7 @@ static int shaper_rule_update(struct shaping_thread_ctx *ctx, struct shaping_flo } for (int i = 0; i < s_rule->borrow_pf_num; i++) { - s_pf = shaper_maat_profile_get(ctx, s_rule->borrow_pf_id_array[i]); + s_pf = shaper_maat_profile_get(ctx, s_rule->borrow_pf_uuid_array[i]); if (!s_pf) { return -1; } @@ -436,9 +448,11 @@ static void shaper_profiles_priority_update(struct shaping_flow *sf) return; } -int shaper_rule_is_enabled(struct shaping_thread_ctx *ctx, long long rule_id) +int shaper_rule_is_enabled(struct shaping_thread_ctx *ctx, uuid_t rule_uuid) { - struct shaping_rule *s_rule = (struct shaping_rule*)maat_plugin_table_get_ex_data(g_maat_instance, ctx->maat_info->rule_table_id, (char *)&rule_id, sizeof(rule_id)); + char uuid_str[UUID_STR_LEN] = {0}; + uuid_unparse(rule_uuid, uuid_str); + struct shaping_rule *s_rule = (struct shaping_rule*)maat_plugin_table_get_ex_data(g_maat_instance, SHAPING_RULE_TABLE_NAME, uuid_str, sizeof(uuid_str)); if (s_rule) { return 1; @@ -447,19 +461,19 @@ int shaper_rule_is_enabled(struct shaping_thread_ctx *ctx, long long rule_id) return 0; } -static int shaper_rules_dup_remove(struct shaping_flow *sf, long long *rule_compile_ids, int rule_num, long long *rule_ids_remove_dup) +static int shaper_rules_dup_remove(struct shaping_flow *sf, uuid_t *rule_uuids, int rule_num, uuid_t *rule_uuids_remove_dup) { int i, j; int rule_num_remove_dup = 0; for (i = 0; i < rule_num; i++) { for (j = 0; j < sf->rule_num; j++) { - if (rule_compile_ids[i] == sf->matched_rule_infos[j].id) { + if (uuid_compare(rule_uuids[i], sf->matched_rule_infos[j].uuid) == 0) { break; } } if (j == sf->rule_num) { - rule_ids_remove_dup[rule_num_remove_dup] = rule_compile_ids[i]; + uuid_copy(rule_uuids_remove_dup[rule_num_remove_dup], rule_uuids[i]); rule_num_remove_dup++; } } @@ -467,10 +481,10 @@ static int shaper_rules_dup_remove(struct shaping_flow *sf, long long *rule_comp return rule_num_remove_dup; } -void shaper_rules_update(struct shaping_thread_ctx *ctx, struct shaping_flow *sf, long long *rule_compile_ids, int rule_num) +void shaper_rules_update(struct shaping_thread_ctx *ctx, struct shaping_flow *sf, uuid_t *rule_uuids, int rule_num) { int priority_changed = 0; - long long rule_ids_remove_dup[SHAPING_RULE_NUM_MAX] = {0}; + uuid_t rule_uuids_remove_dup[SHAPING_RULE_NUM_MAX]; int rule_num_remove_dup = 0; int old_rule_num = sf->rule_num; @@ -483,7 +497,7 @@ void shaper_rules_update(struct shaping_thread_ctx *ctx, struct shaping_flow *sf return; } - rule_num_remove_dup = shaper_rules_dup_remove(sf, rule_compile_ids, rule_num, rule_ids_remove_dup); + rule_num_remove_dup = shaper_rules_dup_remove(sf, rule_uuids, rule_num, rule_uuids_remove_dup); if (rule_num_remove_dup == 0) { return; } @@ -498,7 +512,7 @@ void shaper_rules_update(struct shaping_thread_ctx *ctx, struct shaping_flow *sf } for (int i = 0; i < rule_num_remove_dup; i++) { - if (shaper_rule_update(ctx, sf, &sf->matched_rule_infos[sf->rule_num], rule_ids_remove_dup[i], &priority_changed) == 0) { + if (shaper_rule_update(ctx, sf, &sf->matched_rule_infos[sf->rule_num], rule_uuids_remove_dup[i], &priority_changed) == 0) { sf->rule_num++; } } @@ -526,18 +540,15 @@ static int shaper_maat_config_load(struct shaper_maat_config *conf) return 0; } -struct shaping_maat_info* shaper_maat_init(const char *instance_name) +int shaper_maat_init(const char *instance_name) { struct maat_options *opts; - struct shaping_maat_info *maat_info; struct shaper_maat_config conf; int ret; if (shaper_maat_config_load(&conf) < 0) { - return NULL; + return -1; } - - maat_info = (struct shaping_maat_info *)calloc(1, sizeof(struct shaping_maat_info)); opts = maat_options_new(); @@ -578,17 +589,6 @@ struct shaping_maat_info* shaper_maat_init(const char *instance_name) goto ERROR; } - maat_info->rule_table_id = maat_get_table_id(g_maat_instance, SHAPING_RULE_TABLE_NAME); - if (maat_info->rule_table_id < 0) { - LOG_ERROR("%s: shaping maat register table %s failed", LOG_TAG_MAAT, SHAPING_RULE_TABLE_NAME); - goto ERROR; - } - maat_info->profile_table_id = maat_get_table_id(g_maat_instance, SHAPING_PROFILE_TABLE_NAME); - if (maat_info->profile_table_id < 0) { - LOG_ERROR("%s: shaping maat register table %s failed", LOG_TAG_MAAT, SHAPING_PROFILE_TABLE_NAME); - goto ERROR; - } - ret = maat_plugin_table_ex_schema_register(g_maat_instance, SHAPING_RULE_TABLE_NAME, shaper_rule_ex_new, shaper_rule_ex_free, shaper_rule_ex_dup, 0, NULL); if (ret < 0) { LOG_ERROR("%s: shaping maat register callback funcs for table %s failed", LOG_TAG_MAAT, SHAPING_RULE_TABLE_NAME); @@ -603,17 +603,14 @@ struct shaping_maat_info* shaper_maat_init(const char *instance_name) LOG_DEBUG("%s: shaping maat init complete", LOG_TAG_MAAT); - return maat_info; + return 0; ERROR: - shaper_maat_destroy(maat_info); - return NULL; + shaper_maat_destroy(); + return -1; } -void shaper_maat_destroy(struct shaping_maat_info *maat_info) +void shaper_maat_destroy() { - if (maat_info) { - free(maat_info); - } if (g_maat_instance) { maat_free(g_maat_instance); } diff --git a/shaping/src/shaper_marsio.cpp b/shaping/src/shaper_marsio.cpp index 357e818..a2c1097 100644 --- a/shaping/src/shaper_marsio.cpp +++ b/shaping/src/shaper_marsio.cpp @@ -265,11 +265,11 @@ int shaper_marsio_ctrl_pkt_data_parse(struct ctrl_pkt_data *ctrl_data, const cha shaping_rule_id_array_size = mpack_node_array_length(tmp_node); ctrl_data->shaping_rule_num = MIN(shaping_rule_id_array_size, SHAPING_RULE_NUM_MAX); for (int i = 0; i < ctrl_data->shaping_rule_num; i++) { - if (mpack_type_uint != mpack_node_type(mpack_node_array_at(tmp_node, i))) { + if (mpack_type_bin != mpack_node_type(mpack_node_array_at(tmp_node, i))) { LOG_ERROR("%s: shaping marsio msgpack shaping rule id type wrong at index %d, type is %d", LOG_TAG_MARSIO, i, mpack_node_type(mpack_node_array_at(tmp_node, i))); goto ERROR; } - ctrl_data->shaping_rule_ids[i] = mpack_node_i64(mpack_node_array_at(tmp_node, i)); + uuid_copy(ctrl_data->shaping_rule_uuids[i], *(uuid_t*)mpack_node_bin_data(mpack_node_array_at(tmp_node, i))); } SUCCESS: diff --git a/shaping/src/shaper_session.cpp b/shaping/src/shaper_session.cpp index f58d55f..8fbb65d 100644 --- a/shaping/src/shaper_session.cpp +++ b/shaping/src/shaper_session.cpp @@ -85,17 +85,17 @@ void shaper_session_log_prepare(struct shaping_flow *sf, char **mpack_data, size mpack_build_map(&writer); mpack_write_cstr(&writer, "rule_id"); - mpack_write_i64(&writer, rule_info->id); - LOG_DEBUG("%s: rule id %d", LOG_TAG_SHAPING, rule_info->id); + mpack_write_bin(&writer, (char*)rule_info->uuid, sizeof(uuid_t)); + LOG_DEBUG("%s: rule id %s", LOG_TAG_SHAPING, uuid_print_str(rule_info->uuid)); mpack_write_cstr(&writer, "profile_ids"); mpack_build_array(&writer); - mpack_write_i64(&writer, rule_info->primary.id); - LOG_DEBUG("%s: primary_profile id %d", LOG_TAG_SHAPING, rule_info->primary.id); + mpack_write_bin(&writer, (char*)rule_info->primary.uuid, sizeof(uuid_t)); + LOG_DEBUG("%s: primary_profile id %s", LOG_TAG_SHAPING, uuid_print_str(rule_info->primary.uuid)); for (int j = 0; j < rule_info->borrowing_num; j++) { - mpack_write_i64(&writer, rule_info->borrowing[j].id); - LOG_DEBUG("%s: borrow_profile id %d", LOG_TAG_SHAPING, rule_info->borrowing[j].id); + mpack_write_bin(&writer, (char*)rule_info->borrowing[j].uuid, sizeof(uuid_t)); + LOG_DEBUG("%s: borrow_profile id %s", LOG_TAG_SHAPING, uuid_print_str(rule_info->borrowing[j].uuid)); } mpack_complete_array(&writer);//end build array for profile_ids mpack_complete_map(&writer); @@ -221,7 +221,7 @@ struct shaping_flow* shaper_session_active(struct shaping_thread_ctx *ctx, struc sf = (struct shaping_flow *)node->val_data; } - shaper_rules_update(ctx, sf, ctrl_data->shaping_rule_ids, ctrl_data->shaping_rule_num); + shaper_rules_update(ctx, sf, ctrl_data->shaping_rule_uuids, ctrl_data->shaping_rule_num); shaper_session_log_send(ctx, sf);//send log of rules and profiles when receive new matched rules return sf; diff --git a/shaping/src/shaper_stat.cpp b/shaping/src/shaper_stat.cpp index 6275d93..bf88f41 100644 --- a/shaping/src/shaper_stat.cpp +++ b/shaping/src/shaper_stat.cpp @@ -27,8 +27,8 @@ struct shaper_stat_conf { thread_local struct field tags[TAG_IDX_MAX] = { [TAG_VSYS_ID_IDX] = {.key = "vsys_id", .type = FIELD_VALUE_INTEGER}, - [TAG_RULE_ID_IDX] = {.key = "rule_id", .type = FIELD_VALUE_INTEGER}, - [TAG_PROFILE_ID_IDX] = {.key = "profile_id", .type = FIELD_VALUE_INTEGER}, + [TAG_RULE_ID_IDX] = {.key = "rule_uuid", .type = FIELD_VALUE_CSTRING}, + [TAG_PROFILE_ID_IDX] = {.key = "profile_uuid", .type = FIELD_VALUE_CSTRING}, [TAG_PRIORITY_IDX] = {.key = "priority", .type = FIELD_VALUE_INTEGER}, [TAG_PROFILE_TYPE_IDX] = {.key = "profile_type", .type = FIELD_VALUE_CSTRING} }; @@ -223,13 +223,18 @@ ERROR: return NULL; } -static void shaper_stat_tags_build(int vsys_id, int rule_id, int profile_id, int priority, int profile_type) +static void shaper_stat_tags_build(int vsys_id, uuid_t rule_uuid, uuid_t profile_uuid, int priority, int profile_type) { + static thread_local char rule_uuid_str[UUID_STR_LEN] = {0}; + static thread_local char profile_uuid_str[UUID_STR_LEN] = {0}; + tags[TAG_VSYS_ID_IDX].value_longlong = vsys_id; - tags[TAG_RULE_ID_IDX].value_longlong = rule_id; + uuid_unparse(rule_uuid, rule_uuid_str); + tags[TAG_RULE_ID_IDX].value_str = rule_uuid_str; - tags[TAG_PROFILE_ID_IDX].value_longlong = profile_id; + uuid_unparse(profile_uuid, profile_uuid_str); + tags[TAG_PROFILE_ID_IDX].value_str = profile_uuid_str; tags[TAG_PRIORITY_IDX].value_longlong = priority; @@ -261,8 +266,8 @@ static void shaper_stat_swarmkv_hincrby_cb(const struct swarmkv_reply *reply, vo shaper_global_stat_async_hincrby_failed_inc(&ctx->thread_global_stat); if (arg->retry_cnt >= HINCRBY_RETRY_MAX) { - LOG_ERROR("%s: shaping stat hincrby failed after retry %d times for profile id %d priority %d, operate %s queue_len %lld", - LOG_TAG_STAT, arg->retry_cnt, arg->profile_id, arg->priority, arg->dir == SHAPING_DIR_IN ? "in" : "out", arg->queue_len); + LOG_ERROR("%s: shaping stat hincrby failed after retry %d times for profile id %s priority %d, operate %s queue_len %lld", + LOG_TAG_STAT, arg->retry_cnt, uuid_print_str(arg->profile_uuid), arg->priority, arg->dir == SHAPING_DIR_IN ? "in" : "out", arg->queue_len); goto END; } @@ -271,12 +276,12 @@ static void shaper_stat_swarmkv_hincrby_cb(const struct swarmkv_reply *reply, vo shaper_global_stat_async_invoke_inc(&ctx->thread_global_stat);//hincrby failed, retry shaper_global_stat_hincrby_invoke_inc(&ctx->thread_global_stat); - LOG_DEBUG("%s: shaping stat hincrby failed, retry for profile id %d priority %d, operate %s queue_len %lld", LOG_TAG_STAT, arg->profile_id, arg->priority, arg->dir == SHAPING_DIR_IN ? "in" : "out", arg->queue_len); + LOG_DEBUG("%s: shaping stat hincrby failed, retry for profile id %s priority %d, operate %s queue_len %lld", LOG_TAG_STAT, uuid_print_str(arg->profile_uuid), arg->priority, arg->dir == SHAPING_DIR_IN ? "in" : "out", arg->queue_len); if (arg->dir == SHAPING_DIR_IN) { - swarmkv_async_command(ctx->swarmkv_db, shaper_stat_swarmkv_hincrby_cb, arg, "HINCRBY tsg-shaping-%d priority-%d-in %lld", arg->profile_id, arg->priority, arg->queue_len); + swarmkv_async_command(ctx->swarmkv_db, shaper_stat_swarmkv_hincrby_cb, arg, "HINCRBY tsg-shaping-%s priority-%d-in %lld", uuid_print_str(arg->profile_uuid), arg->priority, arg->queue_len); } else { - swarmkv_async_command(ctx->swarmkv_db, shaper_stat_swarmkv_hincrby_cb, arg, "HINCRBY tsg-shaping-%d priority-%d-out %lld", arg->profile_id, arg->priority, arg->queue_len); + swarmkv_async_command(ctx->swarmkv_db, shaper_stat_swarmkv_hincrby_cb, arg, "HINCRBY tsg-shaping-%s priority-%d-out %lld", uuid_print_str(arg->profile_uuid), arg->priority, arg->queue_len); } return; @@ -297,16 +302,16 @@ static void shaper_stat_priority_queue_len_refresh_dir(struct shaping_thread_ctx arg->ctx = ctx; arg->start_time_us = curr_time_us; - arg->profile_id = profile_hash_node->id; + uuid_copy(arg->profile_uuid, profile_hash_node->uuid); arg->priority = priority; arg->dir = direction; arg->queue_len = profile_hash_node->local_queue_len[priority][direction]; shaper_global_stat_async_invoke_inc(&ctx->thread_global_stat); shaper_global_stat_hincrby_invoke_inc(&ctx->thread_global_stat); if (direction == SHAPING_DIR_IN) { - swarmkv_async_command(ctx->swarmkv_db, shaper_stat_swarmkv_hincrby_cb, arg, "HINCRBY tsg-shaping-%d priority-%d-in %lld", arg->profile_id, arg->priority, arg->queue_len); + swarmkv_async_command(ctx->swarmkv_db, shaper_stat_swarmkv_hincrby_cb, arg, "HINCRBY tsg-shaping-%s priority-%d-in %lld", uuid_print_str(arg->profile_uuid), arg->priority, arg->queue_len); } else { - swarmkv_async_command(ctx->swarmkv_db, shaper_stat_swarmkv_hincrby_cb, arg, "HINCRBY tsg-shaping-%d priority-%d-out %lld", arg->profile_id, arg->priority, arg->queue_len); + swarmkv_async_command(ctx->swarmkv_db, shaper_stat_swarmkv_hincrby_cb, arg, "HINCRBY tsg-shaping-%s priority-%d-out %lld", uuid_print_str(arg->profile_uuid), arg->priority, arg->queue_len); } profile_hash_node->local_queue_len[priority][direction] = 0; @@ -362,7 +367,7 @@ static void shaper_stat_profile_metirc_refresh(struct shaping_thread_ctx *ctx, s return; } - shaper_stat_tags_build(rule->vsys_id, rule->id, profile->id, priority, profile_type); + shaper_stat_tags_build(rule->vsys_id, rule->uuid, profile->uuid, priority, profile_type); fieldstat_easy_counter_incrby(stat->counter_instance, thread_id, stat->column_ids[IN_DROP_PKTS_IDX], tags, TAG_IDX_MAX, profile_stat->in.drop_pkts); fieldstat_easy_counter_incrby(stat->counter_instance, thread_id, stat->column_ids[IN_PKTS_IDX], tags, TAG_IDX_MAX, profile_stat->in.pkts); |
