summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/src/raw_packet.cpp17
-rw-r--r--shaping/include/shaper.h3
-rw-r--r--shaping/include/shaper_maat.h2
-rw-r--r--shaping/src/main.cpp2
-rw-r--r--shaping/src/shaper.cpp23
-rw-r--r--shaping/src/shaper_maat.cpp26
6 files changed, 52 insertions, 21 deletions
diff --git a/common/src/raw_packet.cpp b/common/src/raw_packet.cpp
index 3b6dad3..c8fec3b 100644
--- a/common/src/raw_packet.cpp
+++ b/common/src/raw_packet.cpp
@@ -817,17 +817,16 @@ static const void *parse_udp(struct raw_pkt_parser *handler, const void *data, s
size_t data_next_length = length - hdr_len;
//LOG_DEBUG("%s: pkt_trace_id: %lu, this_layer: %s, payload_len: [%lu/%lu]", LOG_TAG_RAWPKT, handler->pkt_trace_id, layer_type2str(this_type), data_next_length, length);
- switch (ntohs(hdr->uh_dport))
- {
- // VXLAN_DPORT
- case 4789:
- // TESTED
+ if (ntohs(hdr->uh_dport) == 4789)
+ {// VXLAN_DPORT
return parse_vxlan(handler, data_next_layer, data_next_length, LAYER_TYPE_G_VXLAN);
- // GTP1U_PORT
- case 2152:
- // TESTED
+ }
+ else if (ntohs(hdr->uh_dport) == 2152 || ntohs(hdr->uh_sport) == 2152)
+ {// GTP1U_PORT
return parse_gtpv1_u(handler, data_next_layer, data_next_length, LAYER_TYPE_GTPV1_U);
- default:
+ }
+ else
+ {
return data_next_layer;
}
}
diff --git a/shaping/include/shaper.h b/shaping/include/shaper.h
index 9276c98..4756dc9 100644
--- a/shaping/include/shaper.h
+++ b/shaping/include/shaper.h
@@ -125,6 +125,7 @@ struct shaping_profile_hash_node {
long long priority_blocked_time_ms[SHAPING_PRIORITY_NUM_MAX];
int hmget_ref_cnt;
int tconsume_ref_cnt;
+ time_t last_refresh_time_s;
struct shaper_token_multiple token_multiple;
struct shaper_aqm_blue_para aqm_blue_para;
struct shaper_aqm_codel_para aqm_codel_para;
@@ -242,7 +243,7 @@ struct shaping_packet_wrapper* shaper_first_pkt_get(struct shaping_flow *sf);
void shaper_queue_clear(struct shaping_flow *sf, struct shaping_thread_ctx *ctx);
int shaper_flow_in_order_get(struct shaper *sp, struct shaper_flow_instance sf_ins[], int priority, int max_sf_num);
-void shaper_profile_hash_node_update(struct shaping_thread_ctx *ctx, struct shaping_profile_info *profile);
+void shaper_profile_hash_node_set(struct shaping_thread_ctx *ctx, struct shaping_profile_info *profile);
int shaper_global_conf_init(struct shaping_system_conf *conf);
diff --git a/shaping/include/shaper_maat.h b/shaping/include/shaper_maat.h
index dc170e5..3ec3259 100644
--- a/shaping/include/shaper_maat.h
+++ b/shaping/include/shaper_maat.h
@@ -37,6 +37,8 @@ void shaper_profile_ex_free(int table_id, void **ad, long argl, void *argp);
int shaper_rule_is_enabled(struct shaping_thread_ctx *ctx, long long rule_id);
+struct shaping_profile *shaper_maat_profile_get(struct shaping_thread_ctx *ctx, int profile_id);
+
void shaper_rules_update(struct shaping_thread_ctx *ctx, struct shaping_flow *sf, long long *rule_compile_ids, int rule_num);
struct shaping_maat_info* shaper_maat_init(const char *instance_name);
void shaper_maat_destroy(struct shaping_maat_info *maat_info); \ No newline at end of file
diff --git a/shaping/src/main.cpp b/shaping/src/main.cpp
index 63b7a49..597230b 100644
--- a/shaping/src/main.cpp
+++ b/shaping/src/main.cpp
@@ -41,7 +41,7 @@ static void *shaper_thread_loop(void *data)
session_table_reset_with_callback(ctx->session_table, shaper_session_data_free_cb, ctx);
__atomic_fetch_and(&ctx->session_need_reset, 0, __ATOMIC_SEQ_CST);
}
- marsio_poll_wait(ctx->marsio_info->instance, &ctx->marsio_info->mr_dev, 1, ctx->thread_index, output_interval_s * 1000);
+ marsio_poll_wait(ctx->marsio_info->instance, &ctx->marsio_info->mr_dev, 1, ctx->thread_index, output_interval_s);
}
shaper_thread_resource_clear();
diff --git a/shaping/src/shaper.cpp b/shaping/src/shaper.cpp
index 2ff490d..91117f5 100644
--- a/shaping/src/shaper.cpp
+++ b/shaping/src/shaper.cpp
@@ -30,6 +30,8 @@ extern "C" {
#define HMGET_REQUEST_INTERVAL_MS 10
#define PRIORITY_BLOCK_MIN_TIME_MS 500
+#define PROFILE_HASH_NODE_REFRESH_SEC 5
+
#define SWARMKV_QUEUE_LEN_GET_CMD "HMGET tsg-shaping-%d priority-0 priority-1 priority-2 priority-3 priority-4 priority-5 priority-6 priority-7 priority-8 priority-9"
struct shaper {//trees in one thread
@@ -563,6 +565,23 @@ static int shaper_deposit_token_get(struct shaping_profile_info *profile, int re
return -1;
}
+static void shaper_profile_hash_node_refresh(struct shaping_thread_ctx *ctx, struct shaping_profile_hash_node *pf_hash_node)
+{
+ time_t curr_time_s = time(NULL);
+ if (curr_time_s - pf_hash_node->last_refresh_time_s < PROFILE_HASH_NODE_REFRESH_SEC) {
+ return;
+ }
+
+ struct shaping_profile *profile = shaper_maat_profile_get(ctx, pf_hash_node->id);
+ if (profile) {
+ pf_hash_node->limit_direction = profile->limit_direction;
+ pf_hash_node->aqm_type = profile->aqm_type;
+ }
+ pf_hash_node->last_refresh_time_s = curr_time_s;
+
+ return;
+}
+
static void shaper_token_get_from_profile(struct shaping_thread_ctx *ctx, struct shaping_flow *sf, struct shaping_profile_info *pf_info, int profile_type, int req_token_bits, unsigned char direction, struct timespec *curr_timespec)
{
struct shaping_tconsume_cb_arg *arg = NULL;
@@ -572,6 +591,8 @@ static void shaper_token_get_from_profile(struct shaping_thread_ctx *ctx, struct
if (pf_hash_node->tconsume_ref_cnt > 0) {
return;
}
+
+ shaper_profile_hash_node_refresh(ctx, pf_hash_node);
if (pf_hash_node->limit_direction == PROFILE_LIMIT_DIRECTION_BIDIRECTION) {
snprintf(key, sizeof(key), "tsg-shaping-%d-bidirectional", pf_info->id);
@@ -708,7 +729,7 @@ END:
}
}
-void shaper_profile_hash_node_update(struct shaping_thread_ctx *ctx, struct shaping_profile_info *profile)
+void shaper_profile_hash_node_set(struct shaping_thread_ctx *ctx, struct shaping_profile_info *profile)
{
if (profile->hash_node == NULL) {
struct shaping_profile_hash_node *hash_node = NULL;
diff --git a/shaping/src/shaper_maat.cpp b/shaping/src/shaper_maat.cpp
index e7de972..9def069 100644
--- a/shaping/src/shaper_maat.cpp
+++ b/shaping/src/shaper_maat.cpp
@@ -352,18 +352,31 @@ void shaper_profile_update(struct shaping_thread_ctx *ctx, struct shaping_profil
{
s_pf_info->id = s_pf_ex->id;
s_pf_info->type = s_pf_ex->type;
- shaper_profile_hash_node_update(ctx, s_pf_info);
+ shaper_profile_hash_node_set(ctx, s_pf_info);
s_pf_info->hash_node->aqm_type = s_pf_ex->aqm_type;
s_pf_info->hash_node->limit_direction = s_pf_ex->limit_direction;
return;
}
+struct shaping_profile *shaper_maat_profile_get(struct shaping_thread_ctx *ctx, int profile_id)
+{
+ struct shaping_profile *s_pf = NULL;
+ char pf_id_key[8] = {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));
+ if (!s_pf) {
+ LOG_ERROR("%s maat_plugin_table_get_ex_data get profile failed for key %s", LOG_TAG_MAAT, pf_id_key);
+ }
+
+ 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)
{
struct shaping_rule *s_rule = NULL;
struct shaping_profile *s_pf = NULL;
- char pf_id_key[8] = {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));
if (!s_rule) {
@@ -376,10 +389,8 @@ static int shaper_rule_update(struct shaping_thread_ctx *ctx, struct shaping_flo
s_rule_info->is_enabled = 1;
- snprintf(pf_id_key, sizeof(pf_id_key), "%d", s_rule->primary_pf_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));
+ s_pf = shaper_maat_profile_get(ctx, s_rule->primary_pf_id);
if (!s_pf) {
- LOG_ERROR("%s maat_plugin_table_get_ex_data get profile failed for key %s", LOG_TAG_MAAT, pf_id_key);
return -1;
}
shaper_profile_update(ctx, &s_rule_info->primary, s_pf);
@@ -403,11 +414,8 @@ static int shaper_rule_update(struct shaping_thread_ctx *ctx, struct shaping_flo
}
for (int i = 0; i < s_rule->borrow_pf_num; i++) {
- memset(pf_id_key, 0, sizeof(pf_id_key));
- snprintf(pf_id_key, sizeof(pf_id_key), "%d", s_rule->borrow_pf_id_array[i]);
- 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));
+ s_pf = shaper_maat_profile_get(ctx, s_rule->borrow_pf_id_array[i]);
if (!s_pf) {
- LOG_ERROR("%s maat_plugin_table_get_ex_data get profile failed for key %s", LOG_TAG_MAAT, pf_id_key);
return -1;
}