summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorliuchang <[email protected]>2023-03-30 13:41:47 +0000
committerliuchang <[email protected]>2023-03-30 13:41:47 +0000
commit2a08bca02ebf7b53c68a05571bf7a7629a03c204 (patch)
tree87914bdd1229821955789a88967e56053771c6c1
parent7f71a2b1736911e49a3287b8ab7fd7ccf880b8c8 (diff)
adapt maat4 new interfacev1.1.2
-rw-r--r--shaping/include/shaper_maat.h4
-rw-r--r--shaping/src/shaper_maat.cpp30
-rw-r--r--shaping/src/shaper_stat.cpp3
-rw-r--r--shaping/test/gtest_shaper_maat.cpp4
-rw-r--r--shaping/test/stub.cpp2
5 files changed, 28 insertions, 15 deletions
diff --git a/shaping/include/shaper_maat.h b/shaping/include/shaper_maat.h
index 87d5389..e14f25d 100644
--- a/shaping/include/shaper_maat.h
+++ b/shaping/include/shaper_maat.h
@@ -25,10 +25,10 @@ struct shaping_profile {
int ref_cnt;
};
-void shaper_rule_ex_new(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, int table_id, const char *key, const char *table_line, void **ad, long argl, void *argp);
void shaper_rule_ex_dup(int table_id, void **to, void **from, long argl, void *argp);
void shaper_rule_ex_free(int table_id, void **ad, long argl, void *argp);
-void shaper_profile_ex_new(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, int table_id, const char *key, const char *table_line, void **ad, long argl, void *argp);
void shaper_profile_ex_dup(int table_id, void **to, void **from, long argl, void *argp);
void shaper_profile_ex_free(int table_id, void **ad, long argl, void *argp);
diff --git a/shaping/src/shaper_maat.cpp b/shaping/src/shaper_maat.cpp
index b253075..7ce72c0 100644
--- a/shaping/src/shaper_maat.cpp
+++ b/shaping/src/shaper_maat.cpp
@@ -12,6 +12,8 @@
#include "utils.h"
#define SHAPING_STREAM_TIMEOUT 3600
+#define SHAPING_RULE_TABLE_NAME "TRAFFIC_SHAPING_COMPILE"
+#define SHAPING_PROFILE_TABLE_NAME "TRAFFIC_SHAPING_PROFILE"
enum input_mode
{
@@ -32,7 +34,7 @@ struct shaper_maat_config {
struct maat *g_maat_instance = NULL;
-void shaper_rule_ex_new(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, int table_id, const char *key, const char *table_line, void **ad, long argl, void *argp)
{
struct shaping_rule *s_rule;
cJSON *json=NULL;
@@ -42,6 +44,10 @@ void shaper_rule_ex_new(int table_id, const char *key, const char *table_line, v
int array_size;
int i;
+ if (strncmp(table_name, SHAPING_RULE_TABLE_NAME, strlen(table_name)) != 0) {
+ return;
+ }
+
s_rule = (struct shaping_rule*)calloc(1, sizeof(struct shaping_rule));
s_rule->ref_cnt = 1;
@@ -141,7 +147,7 @@ void shaper_rule_ex_free(int table_id, void **ad, long argl, void *argp)
return;
}
-void shaper_profile_ex_new(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, int table_id, const char *key, const char *table_line, void **ad, long argl, void *argp)
{
struct shaping_profile *s_pf;
cJSON *json=NULL;
@@ -156,6 +162,10 @@ void shaper_profile_ex_new(int table_id, const char *key, const char *table_line
int array_size, i;
int ret;
+ if (strncmp(table_name, SHAPING_PROFILE_TABLE_NAME, strlen(table_name)) != 0) {
+ return;
+ }
+
s_pf = (struct shaping_profile*)calloc(1, sizeof(struct shaping_profile));
s_pf->ref_cnt = 1;
@@ -376,26 +386,26 @@ 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, "TRAFFIC_SHAPING_COMPILE");
+ 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 TRAFFIC_SHAPING_COMPILE failed", LOG_TAG_MAAT);
+ 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, "TRAFFIC_SHAPING_PROFILE");
+ 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 TRAFFIC_SHAPING_PROFILE failed", LOG_TAG_MAAT);
+ 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, maat_info->rule_table_id, shaper_rule_ex_new, shaper_rule_ex_free, shaper_rule_ex_dup, 0, NULL);
+ 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 TRAFFIC_SHAPING_COMPILE failed", LOG_TAG_MAAT);
+ LOG_ERROR("%s: shaping maat register callback funcs for table %s failed", LOG_TAG_MAAT, SHAPING_RULE_TABLE_NAME);
goto ERROR;
}
- ret = maat_plugin_table_ex_schema_register(g_maat_instance, maat_info->profile_table_id, shaper_profile_ex_new, shaper_profile_ex_free, shaper_profile_ex_dup, 0, NULL);
+ ret = maat_plugin_table_ex_schema_register(g_maat_instance, SHAPING_PROFILE_TABLE_NAME, shaper_profile_ex_new, shaper_profile_ex_free, shaper_profile_ex_dup, 0, NULL);
if (ret < 0) {
- LOG_ERROR("%s: shaping maat register callback funcs for table TRAFFIC_SHAPING_PROFILE failed", LOG_TAG_MAAT);
+ LOG_ERROR("%s: shaping maat register callback funcs for table %s failed", LOG_TAG_MAAT, SHAPING_PROFILE_TABLE_NAME);
goto ERROR;
}
diff --git a/shaping/src/shaper_stat.cpp b/shaping/src/shaper_stat.cpp
index 6c9644b..b340995 100644
--- a/shaping/src/shaper_stat.cpp
+++ b/shaping/src/shaper_stat.cpp
@@ -74,6 +74,9 @@ struct shaping_stat* shaper_stat_init(int thread_num)
goto ERROR;
}
+ fieldstat_global_enable_prometheus_endpoint(9007, NULL);
+ //fieldstat_enable_prometheus_output();
+
fieldstat_dynamic_set_output_interval(stat->instance, conf.output_interval_ms);
fieldstat_dynamic_set_line_protocol_server(stat->instance, conf.telegraf_ip, conf.telegraf_port);
if (conf.enable_backgroud_thread == 0) {
diff --git a/shaping/test/gtest_shaper_maat.cpp b/shaping/test/gtest_shaper_maat.cpp
index 07699df..972d550 100644
--- a/shaping/test/gtest_shaper_maat.cpp
+++ b/shaping/test/gtest_shaper_maat.cpp
@@ -19,7 +19,7 @@ TEST(shaping_rule, parse)
struct shaping_rule *s_rule = NULL;
struct shaping_rule *s_rule_dup = NULL;
- shaper_rule_ex_new(0, NULL, data, (void**)&s_rule, 0, NULL);
+ shaper_rule_ex_new("TRAFFIC_SHAPING_COMPILE", 0, NULL, data, (void**)&s_rule, 0, NULL);
EXPECT_EQ(s_rule->id, 182);
EXPECT_EQ(s_rule->primary_pf_id, 1);
EXPECT_EQ(s_rule->borrow_pf_num, 2);
@@ -48,7 +48,7 @@ TEST(shaping_profile, parse)
struct shaping_profile *s_pf = NULL;
struct shaping_profile *s_pf_dup = NULL;
- shaper_profile_ex_new(0, NULL, data, (void**)&s_pf, 0, NULL);
+ shaper_profile_ex_new("TRAFFIC_SHAPING_PROFILE", 0, NULL, data, (void**)&s_pf, 0, NULL);
EXPECT_EQ(s_pf->id, 1);
EXPECT_EQ(s_pf->in_limit_bandwidth, 1024);
EXPECT_EQ(s_pf->out_limit_bandwidth, 2048);
diff --git a/shaping/test/stub.cpp b/shaping/test/stub.cpp
index b49bafd..ec7ce6b 100644
--- a/shaping/test/stub.cpp
+++ b/shaping/test/stub.cpp
@@ -383,7 +383,7 @@ int maat_get_table_id(struct maat *instance, const char *table_name)
}
}
-int maat_plugin_table_ex_schema_register(struct maat *instance, int table_id,
+int maat_plugin_table_ex_schema_register(struct maat *instance, const char *table_name,
maat_ex_new_func_t *new_func,
maat_ex_free_func_t *free_func,
maat_ex_dup_func_t *dup_func,