summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorsongyanchao <[email protected]>2022-09-21 08:47:04 +0000
committersongyanchao <[email protected]>2022-09-23 06:42:49 -0400
commitb634feff6aecc57780e1a3be8c8baebe4b2c2074 (patch)
tree5311e6074950450a3b4ea960efe2c6b60f68cf6a /tools
parent2c5bed5be461d981b8cd60e69c06ae9ea6953322 (diff)
🎈 perf(TSG-12030): Classifier 动态规则处理流程,删除单条规则添加/删除操作
Classifier 动态规则处理流程,删除单条规则添加/删除操作
Diffstat (limited to 'tools')
-rw-r--r--tools/classifier_rule_test/classifier_rule_test.c357
1 files changed, 70 insertions, 287 deletions
diff --git a/tools/classifier_rule_test/classifier_rule_test.c b/tools/classifier_rule_test/classifier_rule_test.c
index 9fdd415..fdabd78 100644
--- a/tools/classifier_rule_test/classifier_rule_test.c
+++ b/tools/classifier_rule_test/classifier_rule_test.c
@@ -27,13 +27,7 @@
enum mr_cli_arg
{
- MR_CLI_ADD = 1000,
- MR_CLI_DEL,
- MR_CLI_DELETE_ALL,
- MR_CLI_ADD_FOR_ID,
- MR_CLI_DEL_FOR_ID,
- MR_CLI_LOOP,
- MR_CLI_REPEATED,
+ MR_CLI_REPEATED = 1000,
MR_CLI_IP_VERSION_ANY,
MR_CLI_FULL_UPDATE,
};
@@ -50,14 +44,8 @@ struct rpc_instance * rpc_instance = NULL;
/* Command Line Options */
static struct option cli_options[] = {
{"help", no_argument, NULL, 'h'},
- {"add", required_argument, NULL, MR_CLI_ADD},
- {"delete", required_argument, NULL, MR_CLI_DEL},
- {"delete_all", no_argument, NULL, MR_CLI_DELETE_ALL},
- {"add_id", required_argument, NULL, MR_CLI_ADD_FOR_ID},
- {"delete_id", required_argument, NULL, MR_CLI_DEL_FOR_ID},
- {"loop", no_argument, NULL, MR_CLI_LOOP},
{"repeated", no_argument, NULL, MR_CLI_REPEATED},
- {"ip_version_any", no_argument, NULL, MR_CLI_IP_VERSION_ANY},
+ {"ip_version_any", required_argument, NULL, MR_CLI_IP_VERSION_ANY},
{"full_update", required_argument, NULL, MR_CLI_FULL_UPDATE},
};
@@ -82,14 +70,9 @@ struct rpc_instance * rpc_create()
void help()
{
- printf("--add + (rule num) eg: --a 1024}\n");
- printf("--delete_all eg: --delete_all}\n");
- printf("--add_id + (rule id) eg: --add_id 33 }\n");
- printf("--delete_id + (rule id) eg: --add_id 33 }\n");
- printf("--loop eg: --loop }\n");
- printf("--repeated eg: --repeated }\n");
- printf("--ip_version_any eg: --ip_version_any }\n");
- printf("--full_update + (rule num) eg: --ip_version_any }\n");
+ printf("--repeated eg: --repeated }\n");
+ printf("--ip_version_any + (rule num) eg: --ip_version_any 10 }\n");
+ printf("--full_update + (rule num) eg: --full_update 1024 }\n");
}
/* Rpc Init */
@@ -123,26 +106,43 @@ static int rpc_init(struct rpc_instance * instance)
return RT_SUCCESS;
}
-void rule_add_for_ip_version_any(struct rpc_instance * instance, int rule_id)
+void send_classifier_rule_msg_repate(struct rpc_instance * instance)
{
+ char str_src_addr[MR_STRING_MAX] = {0};
+ char str_dst_addr[MR_STRING_MAX] = {0};
+ cJSON * cjson_rule_array = cJSON_CreateArray();
+ cJSON * cjson_rule = cJSON_CreateObject();
- cJSON * cjson_rule = NULL;
-
- cjson_rule = cJSON_CreateObject();
- cJSON_AddNumberToObject(cjson_rule, "RuleId", rule_id);
- cJSON_AddNumberToObject(cjson_rule, "SrcPortLow", 0);
- cJSON_AddNumberToObject(cjson_rule, "SrcPortHigh", 65530);
- cJSON_AddNumberToObject(cjson_rule, "DstPortLow", 0);
- cJSON_AddNumberToObject(cjson_rule, "DstPortHigh", 64511 + rule_id);
- cJSON_AddNumberToObject(cjson_rule, "Proto", IPPROTO_TCP);
- cJSON_AddNumberToObject(cjson_rule, "Priority", 1);
- cJSON_AddNumberToObject(cjson_rule, "SiId", rule_id % 2);
- cJSON_AddNumberToObject(cjson_rule, "Action", 1);
- cJSON_AddNumberToObject(cjson_rule, "NextGroup", rule_id % 2);
-
- if (rpc_client_send_request_async(instance->handler, MR_CLASSIFIER_TOPIC_SINGLE_RULE_ADD, cjson_rule) != 0)
+ for (int rule_id = 1; rule_id <= 2; rule_id++)
{
- printf("Send Add Request Failed !!!\n");
+ sprintf(str_src_addr, "%s", "172.2.60.2");
+ sprintf(str_dst_addr, "%s", "172.2.60.2");
+ cJSON * cjson_rule_item = cJSON_CreateObject();
+ cJSON_AddNumberToObject(cjson_rule_item, "RuleId", 1);
+ cJSON_AddStringToObject(cjson_rule_item, "SrcIpV4", str_src_addr);
+ cJSON_AddNumberToObject(cjson_rule_item, "SrcIpMaskV4", 24);
+ cJSON_AddStringToObject(cjson_rule_item, "DstIpV4", str_dst_addr);
+ cJSON_AddNumberToObject(cjson_rule_item, "DstIpMaskV4", 24);
+ cJSON_AddNumberToObject(cjson_rule_item, "SrcPortLow", 0);
+ cJSON_AddNumberToObject(cjson_rule_item, "SrcPortHigh", 65535);
+ cJSON_AddNumberToObject(cjson_rule_item, "DstPortLow", 0);
+ cJSON_AddNumberToObject(cjson_rule_item, "DstPortHigh", 65535);
+ cJSON_AddNumberToObject(cjson_rule_item, "Proto", IPPROTO_TCP);
+ cJSON_AddNumberToObject(cjson_rule_item, "Priority", 1);
+ cJSON_AddNumberToObject(cjson_rule_item, "SiId", 0);
+ cJSON_AddNumberToObject(cjson_rule_item, "Action", 1);
+ cJSON_AddNumberToObject(cjson_rule_item, "NextGroup", 0);
+ cJSON_AddItemToArray(cjson_rule_array, cjson_rule_item);
+ }
+ cJSON_AddItemToObject(cjson_rule, "RuleArray", cjson_rule_array);
+
+ char * cjson_str = cJSON_Print(cjson_rule);
+ printf("cjson_rule: \n%s\n", cjson_str);
+ free(cjson_str);
+
+ if (rpc_client_send_request_async(instance->handler, MR_CLASSIFIER_TOPIC_FULL_UPDATE, cjson_rule) != 0)
+ {
+ printf("Send Repate Rule Request Failed !!!\n");
}
else
{
@@ -152,43 +152,35 @@ void rule_add_for_ip_version_any(struct rpc_instance * instance, int rule_id)
cJSON_Delete(cjson_rule);
}
-void send_classifier_rule_add_msg(struct rpc_instance * instance, int rule_id)
+void send_classifier_rule_msg_ip_version_any(struct rpc_instance * instance, int rule_num)
{
+ cJSON * cjson_rule_array = cJSON_CreateArray();
+ cJSON * cjson_rule = cJSON_CreateObject();
- cJSON * cjson_rule = NULL;
- char str_src_addr[MR_STRING_MAX] = {0};
- char str_dst_addr[MR_STRING_MAX] = {0};
-
- if (rule_id < 2048)
- {
- sprintf(str_src_addr, "%s", "172.2.60.2");
- sprintf(str_dst_addr, "%s", "172.2.60.2");
- }
- else
+ for (int rule_id = 1; rule_id <= rule_num; rule_id++)
{
- sprintf(str_src_addr, "%s", "192.168.102.1");
- sprintf(str_dst_addr, "%s", "192.168.102.1");
+ cJSON * cjson_rule_item = cJSON_CreateObject();
+ cJSON_AddNumberToObject(cjson_rule_item, "RuleId", rule_id);
+ cJSON_AddNumberToObject(cjson_rule_item, "SrcPortLow", 0);
+ cJSON_AddNumberToObject(cjson_rule_item, "SrcPortHigh", 65530);
+ cJSON_AddNumberToObject(cjson_rule_item, "DstPortLow", 0);
+ cJSON_AddNumberToObject(cjson_rule_item, "DstPortHigh", 64511 + rule_id);
+ cJSON_AddNumberToObject(cjson_rule_item, "Proto", IPPROTO_TCP);
+ cJSON_AddNumberToObject(cjson_rule_item, "Priority", 1);
+ cJSON_AddNumberToObject(cjson_rule_item, "SiId", rule_id % 2);
+ cJSON_AddNumberToObject(cjson_rule_item, "Action", 1);
+ cJSON_AddNumberToObject(cjson_rule_item, "NextGroup", rule_id % 2);
+ cJSON_AddItemToArray(cjson_rule_array, cjson_rule_item);
}
+ cJSON_AddItemToObject(cjson_rule, "RuleArray", cjson_rule_array);
+
+ char * cjson_str = cJSON_Print(cjson_rule);
+ printf("cjson_rule: \n%s\n", cjson_str);
+ free(cjson_str);
- cjson_rule = cJSON_CreateObject();
- cJSON_AddNumberToObject(cjson_rule, "RuleId", rule_id);
- cJSON_AddStringToObject(cjson_rule, "SrcIpV4", str_src_addr);
- cJSON_AddNumberToObject(cjson_rule, "SrcIpMaskV4", 24);
- cJSON_AddStringToObject(cjson_rule, "DstIpV4", str_dst_addr);
- cJSON_AddNumberToObject(cjson_rule, "DstIpMaskV4", 24);
- cJSON_AddNumberToObject(cjson_rule, "SrcPortLow", 0);
- cJSON_AddNumberToObject(cjson_rule, "SrcPortHigh", 65530);
- cJSON_AddNumberToObject(cjson_rule, "DstPortLow", 0);
- cJSON_AddNumberToObject(cjson_rule, "DstPortHigh", 64511 + rule_id);
- cJSON_AddNumberToObject(cjson_rule, "Proto", IPPROTO_TCP);
- cJSON_AddNumberToObject(cjson_rule, "Priority", 1);
- cJSON_AddNumberToObject(cjson_rule, "SiId", rule_id % 2);
- cJSON_AddNumberToObject(cjson_rule, "Action", 1);
- cJSON_AddNumberToObject(cjson_rule, "NextGroup", rule_id % 2);
-
- if (rpc_client_send_request_async(instance->handler, MR_CLASSIFIER_TOPIC_SINGLE_RULE_ADD, cjson_rule) != 0)
+ if (rpc_client_send_request_async(instance->handler, MR_CLASSIFIER_TOPIC_FULL_UPDATE, cjson_rule) != 0)
{
- printf("Send Add Request Failed !!!\n");
+ printf("Send Ip Version Any Request Failed !!!\n");
}
else
{
@@ -253,68 +245,6 @@ void send_classifier_rule_full_update_msg(struct rpc_instance * instance, int ru
cJSON_Delete(cjson_rule);
}
-void send_classifier_rule_del_msg(struct rpc_instance * instance, int rule_id)
-{
- cJSON * cjson_rule = NULL;
-
- cjson_rule = cJSON_CreateObject();
-
- cJSON_AddNumberToObject(cjson_rule, "RuleId", rule_id);
- cJSON_AddStringToObject(cjson_rule, "SrcIpV4", "172.16.1.10");
- cJSON_AddNumberToObject(cjson_rule, "SrcIpMaskV4", 24);
- cJSON_AddStringToObject(cjson_rule, "DstIpV4", "172.16.1.100");
- cJSON_AddNumberToObject(cjson_rule, "DstIpMaskV4", 24);
- cJSON_AddNumberToObject(cjson_rule, "SrcPortLow", 10);
- cJSON_AddNumberToObject(cjson_rule, "SrcPortHigh", 60000);
- cJSON_AddNumberToObject(cjson_rule, "DstPortLow", 20);
- cJSON_AddNumberToObject(cjson_rule, "DstPortHigh", 60000);
- cJSON_AddNumberToObject(cjson_rule, "Proto", IPPROTO_TCP);
- cJSON_AddNumberToObject(cjson_rule, "Priority", 1);
- cJSON_AddNumberToObject(cjson_rule, "SiId", rule_id);
- cJSON_AddStringToObject(cjson_rule, "Action", "nf_steering");
- cJSON_AddNumberToObject(cjson_rule, "NextGroup", rule_id % 2);
-
- if (rpc_client_send_request_async(instance->handler, MR_CLASSIFIER_TOPIC_SINGLE_RULE_DEL, cjson_rule) != 0)
- {
- printf("Send Del Request Failed !!!\n");
- }
- else
- {
- /* Set Creat Response Disable */
- __atomic_exchange_n(&instance->response_flag, MR_CLI_RESPONSE_DISABLE, __ATOMIC_SEQ_CST);
- }
- cJSON_Delete(cjson_rule);
-}
-
-/* Rule Add Response */
-static int __rule_add_response_handler(cJSON * rsp, void * arg)
-{
- cJSON * j_result = NULL;
- struct rpc_instance * rpc_instance = (struct rpc_instance *)arg;
-
- j_result = cJSON_GetObjectItem(rsp, MR_CLASSIFIER_RPC_RESULT);
-
- if (j_result == NULL)
- {
- printf("The Result Is Null !\n");
- }
- else
- {
- if ((u_int32_t)j_result->valuedouble == RT_SUCCESS)
- {
- printf("The One Classifier Rule Add Success.\n");
- }
- else
- {
- printf("One Classifier Rule Add Error. Error Code:%u\n", (u_int32_t)j_result->valuedouble);
- }
- }
-
- /* Set Creat Response Enable */
- __atomic_exchange_n(&rpc_instance->response_flag, MR_CLI_RESPONSE_ENABLE, __ATOMIC_SEQ_CST);
- return RT_SUCCESS;
-}
-
/* Rule Full Update Response */
static int __rule_full_update_response_handler(cJSON * rsp, void * arg)
{
@@ -348,35 +278,6 @@ static int __rule_full_update_response_handler(cJSON * rsp, void * arg)
return RT_SUCCESS;
}
-/* Rule Delete Response */
-static int __rule_del_response_handler(cJSON * rsp, void * arg)
-{
- cJSON * j_result = NULL;
- struct rpc_instance * rpc_instance = (struct rpc_instance *)arg;
-
- j_result = cJSON_GetObjectItem(rsp, MR_CLASSIFIER_RPC_RESULT);
-
- if (j_result == NULL)
- {
- printf("The Result Is Null !\n");
- }
- else
- {
- if ((u_int32_t)j_result->valuedouble == RT_SUCCESS)
- {
- printf("The One Classifier Rule Del Success.\n");
- }
- else
- {
- printf("One Classifier Rule Del Error. Error Code:%d\n", (u_int32_t)j_result->valuedouble);
- }
- }
-
- /* Set Creat Response Enable */
- __atomic_exchange_n(&rpc_instance->response_flag, MR_CLI_RESPONSE_ENABLE, __ATOMIC_SEQ_CST);
- return RT_SUCCESS;
-}
-
int main(int argc, char * argv[])
{
int opt = 0, type = 0;
@@ -387,41 +288,13 @@ int main(int argc, char * argv[])
{
switch (opt)
{
- case MR_CLI_ADD: {
- type = MR_CLI_ADD;
- deal_num = (uint32_t)strtoull(optarg, &endptr, 0);
- break;
- }
- case MR_CLI_DEL: {
- type = MR_CLI_DEL;
- deal_num = (uint32_t)strtoull(optarg, &endptr, 0);
- break;
- }
- case MR_CLI_DELETE_ALL: {
- type = MR_CLI_DELETE_ALL;
- deal_num = 1024;
- break;
- }
- case MR_CLI_ADD_FOR_ID: {
- type = MR_CLI_ADD_FOR_ID;
- deal_num = (uint32_t)strtoull(optarg, &endptr, 0);
- break;
- }
- case MR_CLI_DEL_FOR_ID: {
- type = MR_CLI_DEL_FOR_ID;
- deal_num = (uint32_t)strtoull(optarg, &endptr, 0);
- break;
- }
- case MR_CLI_LOOP: {
- type = MR_CLI_LOOP;
- break;
- }
case MR_CLI_REPEATED: {
type = MR_CLI_REPEATED;
break;
}
case MR_CLI_IP_VERSION_ANY: {
type = MR_CLI_IP_VERSION_ANY;
+ deal_num = (uint32_t)strtoull(optarg, &endptr, 0);
break;
}
case MR_CLI_FULL_UPDATE: {
@@ -445,20 +318,6 @@ int main(int argc, char * argv[])
return 0;
}
- if (rpc_client_recv_response_register(rpc_instance->handler, MR_CLASSIFIER_TOPIC_SINGLE_RULE_ADD,
- __rule_add_response_handler, rpc_instance) != 0)
- {
- printf("Register Add Response Callback Failed !!!\n");
- return 0;
- }
-
- if (rpc_client_recv_response_register(rpc_instance->handler, MR_CLASSIFIER_TOPIC_SINGLE_RULE_DEL,
- __rule_del_response_handler, rpc_instance) != 0)
- {
- printf("Register Del Response Callback Failed !!!\n");
- return 0;
- }
-
if (rpc_client_recv_response_register(rpc_instance->handler, MR_CLASSIFIER_TOPIC_FULL_UPDATE,
__rule_full_update_response_handler, rpc_instance) != 0)
{
@@ -479,99 +338,23 @@ int main(int argc, char * argv[])
}
/* Send Delete Requeset Msg */
- if (type == MR_CLI_ADD)
- {
- /* Send Create Requeset Msg */
- for (int i = 1; i <= deal_num; i++)
- {
- send_classifier_rule_add_msg(rpc_instance, i);
- printf("Send Add:%d\n", i);
- while (__atomic_load_n(&rpc_instance->response_flag, __ATOMIC_RELAXED) == MR_CLI_RESPONSE_DISABLE)
- {
- usleep(1);
- }
- }
- }
- else if ((type == MR_CLI_DEL) || (type == MR_CLI_DELETE_ALL))
+ if (type == MR_CLI_REPEATED)
{
- for (int i = deal_num; i > 0; i--)
- {
- send_classifier_rule_del_msg(rpc_instance, i);
- printf("Send Delete:%d\n", i);
- while (__atomic_load_n(&rpc_instance->response_flag, __ATOMIC_RELAXED) == MR_CLI_RESPONSE_DISABLE)
- {
- usleep(1);
- }
- }
- }
- else if (type == MR_CLI_ADD_FOR_ID)
- {
- send_classifier_rule_add_msg(rpc_instance, deal_num);
- printf("Send Add:%d\n", deal_num);
- while (__atomic_load_n(&rpc_instance->response_flag, __ATOMIC_RELAXED) == MR_CLI_RESPONSE_DISABLE)
- {
- usleep(1);
- }
- }
- else if (type == MR_CLI_DEL_FOR_ID)
- {
- send_classifier_rule_del_msg(rpc_instance, deal_num);
- printf("Send Delete:%d\n", deal_num);
+ send_classifier_rule_msg_repate(rpc_instance);
+ printf("Send Repate Rule.\n");
while (__atomic_load_n(&rpc_instance->response_flag, __ATOMIC_RELAXED) == MR_CLI_RESPONSE_DISABLE)
{
usleep(1);
}
}
- else if (type == MR_CLI_LOOP)
- {
- while (1)
- {
- /* Send Create Requeset Msg */
- for (int i = 1; i <= 1024; i++)
- {
- send_classifier_rule_add_msg(rpc_instance, i);
- printf("Send Add:%d\n", i);
- while (__atomic_load_n(&rpc_instance->response_flag, __ATOMIC_RELAXED) == MR_CLI_RESPONSE_DISABLE)
- {
- usleep(1);
- }
- }
-
- for (int i = 1024; i > 0; i--)
- {
- send_classifier_rule_del_msg(rpc_instance, i);
- printf("Send Delete:%d\n", i);
- while (__atomic_load_n(&rpc_instance->response_flag, __ATOMIC_RELAXED) == MR_CLI_RESPONSE_DISABLE)
- {
- usleep(1);
- }
- }
- }
- }
- else if (type == MR_CLI_REPEATED)
- {
- /* Send Create Requeset Msg */
- for (int i = 1; i <= 2; i++)
- {
- send_classifier_rule_add_msg(rpc_instance, 1);
- printf("Send Add:%d\n", i);
- while (__atomic_load_n(&rpc_instance->response_flag, __ATOMIC_RELAXED) == MR_CLI_RESPONSE_DISABLE)
- {
- usleep(1);
- }
- }
- }
else if (type == MR_CLI_IP_VERSION_ANY)
{
- for (int i = 1; i <= 1024; i++)
+ send_classifier_rule_msg_ip_version_any(rpc_instance, deal_num);
+ printf("Send Ip Version Any.\n");
+ while (__atomic_load_n(&rpc_instance->response_flag, __ATOMIC_RELAXED) == MR_CLI_RESPONSE_DISABLE)
{
- rule_add_for_ip_version_any(rpc_instance, i);
- printf("Send Add:%d\n", i);
- while (__atomic_load_n(&rpc_instance->response_flag, __ATOMIC_RELAXED) == MR_CLI_RESPONSE_DISABLE)
- {
- usleep(1);
- }
+ usleep(1);
}
}
else if (type == MR_CLI_FULL_UPDATE)