diff options
| author | songyanchao <[email protected]> | 2022-04-20 04:17:54 -0400 |
|---|---|---|
| committer | songyanchao <[email protected]> | 2022-04-20 04:18:51 -0400 |
| commit | 6ffddf81cf32bf823cd2d45bb44a30865c34f237 (patch) | |
| tree | 1d8b35b160ae06701580eb3be4f24f2786f2ef64 /tools | |
| parent | 6d2c7ea1423c8f10bf303969c91391e79fbdde4b (diff) | |
🎈 perf(TSG-10188): 优化request result 函数v4.5.2-20220420
优化request result 函数,设置日志级别
TSG-10188
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/mrctl/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | tools/mrctl/mrctl.c | 248 |
2 files changed, 137 insertions, 114 deletions
diff --git a/tools/mrctl/CMakeLists.txt b/tools/mrctl/CMakeLists.txt index 6b989f5..2d05a04 100644 --- a/tools/mrctl/CMakeLists.txt +++ b/tools/mrctl/CMakeLists.txt @@ -5,4 +5,5 @@ include_directories(${CMAKE_SOURCE_DIR}/service/include) include_directories(${DPDK_INCLUDE_DIR}) add_executable(mrctl mrctl.c) -target_link_libraries(mrctl MESA_prof_load_static infra m MESA_htable_static ${SYSTEMD_LIBRARIES})
\ No newline at end of file +target_link_libraries(mrctl MESA_prof_load_static infra m MESA_htable_static ${SYSTEMD_LIBRARIES}) +install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/mrctl DESTINATION bin COMPONENT Program)
\ No newline at end of file diff --git a/tools/mrctl/mrctl.c b/tools/mrctl/mrctl.c index 4d07df0..25c2878 100644 --- a/tools/mrctl/mrctl.c +++ b/tools/mrctl/mrctl.c @@ -19,9 +19,6 @@ #define MR_CLI_RESPONSE_ENABLE 1 #define MR_CLI_CLOSE_DELAY 100 - -struct mrctl_flow_rule * rule_global; - /* Cli Arg List */ enum mr_cli_arg { @@ -93,8 +90,9 @@ struct mrctl_instance struct mrctl_instance * mrctl_instance = NULL; unsigned int g_logger_to_stdout = 1; unsigned int g_logger_level = LOG_DEBUG; +struct mrctl_flow_rule * rule_global; -/* Command Line Prompt */ +/* Command Line Options */ static struct option cli_options[] = { {"help", no_argument,NULL, 'h'}, @@ -153,6 +151,115 @@ static struct option cli_options[] = {"dmac_arg", required_argument,NULL, MR_CLI_ACTION_SET_DST_MAC_ARG}, }; +/* Help Info */ +int help() +{ + printf("Usage: mrctl {Attr} {Items} {Actions}\n"); + /* Attr */ + printf("Attr:\n"); + printf(" Must Choose:\n"); + printf(" RuleType : -c,--create eg: -c\n"); + printf(" -d,--delete eg: -c\n"); + printf(" -s,--search eg: -c\n"); + printf(" --get_count eg: --get_count\n"); + printf(" Create Must Choose:\n"); + printf(" Direction : -i,--ingress eg: -i\n"); + printf(" -e,--egress eg: -e\n"); + printf(" Portname : -p,--portname eg: -p ens18f1\n"); + printf(" Optional:\n"); + printf(" Group : -g,--group eg: -g 1 \n"); + printf(" Priority : --priority eg: --priority 1\n"); + printf("\n"); + + /* Delete */ + printf("Delete Arg:\n"); + printf(" Must Choose:\n"); + printf(" RuleId : --rule_id eg: --rule_id 0\n"); + printf(" --all eg: --all\n"); + + /* Get Rule Count */ + printf("Get Rule Count:\n"); + printf(" Must Choose:\n"); + printf(" CountRuleId : --count_rule_id eg: --count_rule_id 0\n"); + printf(" --count_all eg: --count_all\n"); + + /* Items */ + printf("Items: Must Choose One Item\n"); + printf(" Ether : --ether eg: --ether\n"); + printf(" Arg : Must Choose One Arg\n"); + printf(" SrcMac : --smac eg: --smac C8:3A:35:09:EF:A1 \n"); + printf(" DstMac : --dmac eg: --dmac 08:C0:EB:97:D2:37\n"); + printf(" SrcMacMask : --smac_mask eg: --smac_mask FF:FF:FF:FF:FF:FF\n"); + printf(" DstMacMask : --dmac_mask eg: --dmac_mask FF:FF:FF:FF:FF:FF\n"); + printf(" EtherType : --ethertype eg: --ethertype ipv4 (OnlySupport ipv4 ipv6 vlan)\n"); + printf(" HasVlan : --hasvlan eg: --hasvlan\n"); + + printf(" IPv4 : --ipv4 eg: --ipv4\n"); + printf(" Arg : Must Choose One Arg\n"); + printf(" Tos : --tos eg: --tos 0 \n"); + printf(" FragmentOffset: --fragment_offset eg: --fragment_offset 0 \n"); + printf(" Ttl : --ttl eg: --ttl 64 \n"); + printf(" Proto : --proto eg: --proto udp (Only Support 'tcp' 'udp') \n"); + printf(" Src : --src eg: --src 123.101.255.252 \n"); + printf(" SrcMask : --src_mask eg: --src_mask 255.255.255.255 \n"); + printf(" Dst : --dst eg: --dst 123.101.255.253 \n"); + printf(" DstMask : --dst_mask eg: --dst_mask 255.255.255.255 \n"); + + printf(" Udp : --udp eg: --udp\n"); + printf(" Arg : Must Choose One Arg\n"); + printf(" SrcPort : --udp_sport eg: --udp_sport 4789 \n"); + printf(" SrcPortMask : --udp_sport_mask eg: --udp_sport_mask 65535 \n"); + printf(" DstPort : --udp_dport eg: --udp_dport 4789 \n"); + printf(" DstPortMask : --udp_dport_mask eg: --udp_dport_mask 65535 \n"); + + printf(" Tcp : --tcp eg: --tcp\n"); + printf(" Arg : Must Choose One Arg\n"); + printf(" SrcPort : --tcp_sport eg: --tcp_sport 60000 \n"); + printf(" SrcPortMask : --tcp_sport_mask eg: --tcp_sport_mask 65535 \n"); + printf(" DstPort : --tcp_dport eg: --tcp_dport 80 \n"); + printf(" DstPortMask : --tcp_dport_mask eg: --tcp_dport_mask 65535 \n"); + printf(" Flags : --tcp_flags eg: --tcp_flags 11 \n"); + + printf(" Vxlan : --vxlan eg: --vxlan\n"); + printf(" Arg : Must Choose One Arg\n"); + printf(" Vni : --vni eg: --vni 123456789 \n"); + printf(" VniMask : --vni_mask eg: --vni_mask 16777215 \n"); + printf("\n"); + + /* Actions */ + printf("Actions: Must Choose One Action\n"); + printf(" Count : --count eg: --count\n"); + printf(" Arg : Must Choose One Arg\n"); + printf(" Shared : --shared eg: --shared \n"); + printf(" Countid : --countid eg: --countid 11 \n"); + + printf(" Drop : --drop eg: --drop\n"); + + printf(" Queue : --queue eg: --queue\n"); + printf(" Arg : Must Choose One Arg\n"); + printf(" Index : --index eg: --index 7 \n"); + + printf(" SetSmac : --set_smac eg: --set_smac\n"); + printf(" Arg : Must Choose One Arg\n"); + printf(" SmacArg : --smac_arg eg: --smac_arg 08:c0:eb:97:d2:37 \n"); + + printf(" SetDmac : --set_dmac eg: --set_dmac\n"); + printf(" Arg : Must Choose One Arg\n"); + printf(" DmacArg : --dmac_arg eg: --dmac_arg c8:3a:35:09:ef:a1 \n"); + /* Eg */ + printf("Create Eg:\n"); + printf("mrctl -c -p eth_pf_100G_1 -g 1 --priority 1 -i --ether --smac c8:3a:35:09:ef:a1 --dmac 08:c0:eb:97:d2:37 --ethertype ipv4 --dmac_mask ff:ff:ff:ff:ff:ff --smac_mask ff:ff:ff:ff:ff:ff --ipv4 --tos 0 --ttl 64 --proto udp --src 123.101.255.252 --src_mask 255.255.255.255 --dst 123.101.255.253 --udp --udp_sport 4789 --udp_sport_mask 65535 --udp_dport 4789 --udp_dport_mask 65535 --dst_mask 255.255.255.255 --vxlan --vni 0 --vni_mask 16777215 --queue --index 7 --set_smac --smac_arg 08:c0:eb:97:d2:37 --set_dmac --dmac_arg c8:3a:35:09:ef:a1\n"); + printf("Search Eg:\n"); + printf("mrctl -s\n"); + printf("Delete Eg:\n"); + printf("mrctl -d --rule_id 1\n"); + printf("mrctl -d --all\n"); + printf("Get Count Eg:\n"); + printf("mrctl --get_count --count_rule_id 1\n"); + printf("mrctl --get_count --count_all\n"); + return RT_SUCCESS; +} + /* rte_ether_addr to str */ void ether_format_addr(char *buf, uint16_t size, const struct rte_ether_addr *eth_addr) @@ -326,10 +433,13 @@ static int mrctl_ctrlmsg_init(struct mrctl_instance * instance) { char str_ctrlmsg_addr[MR_STRING_MAX] = { 0 }; unsigned int ctrlmsg_port = 0; + unsigned int loglevel = g_logger_level + 1; /* Get Ip & Port */ MESA_load_profile_string_def(GLOBAL_CONF_FILE_PATH, "ctrlmsg", "listen_addr", str_ctrlmsg_addr, sizeof(str_ctrlmsg_addr), CTRLMSG_DEFAULT_ADDR); MESA_load_profile_uint_def(GLOBAL_CONF_FILE_PATH, "ctrlmsg", "listen_port", &ctrlmsg_port, CTRLMSG_DEFAULT_PORT); + MESA_load_profile_uint_def(GLOBAL_CONF_FILE_PATH, "eal", "loglevel", &loglevel, loglevel); + g_logger_level = loglevel - 1; /* Change Ip Addr */ struct sockaddr_in sockaddr_in; @@ -398,9 +508,27 @@ static int __flow_search_response_handler(struct ctrlmsg_handler * ct_hand, stru if (rep_msg->msg_err.errcode == RT_SUCCESS) { cjson_search_response = cJSON_Parse((char *)rep_msg->msg_err.strerr); - cJSON * cjson_flow_rule_num = cJSON_GetObjectItem(cjson_search_response,MR_CJSON_KEY_RULE_NUM); - cJSON * cjson_flow_rule_info = cJSON_GetObjectItem(cjson_search_response,MR_CJSON_KEY_RULE_INFO); - cJSON * cjson_flow_rule_end = cJSON_GetObjectItem(cjson_search_response,MR_CJSON_KEY_RULE_END); + + /* Parsing Success Info Str */ + cJSON * cjson_search_success = cJSON_GetObjectItem(cjson_search_response,MR_CJSON_KEY_SUCCESS_INFO); + if (cjson_search_success == NULL) + { + printf("Cant Get The Search Success Info.\n"); + return RT_ERR; + } + + /* Parsing Success Info */ + cJSON * cjson_search_success_info = cJSON_Parse((char *)cjson_search_success->valuestring); + if (cjson_search_success_info == NULL) + { + printf("Cant Parsing The Search Success Info.\n"); + return RT_ERR; + } + + cJSON * cjson_flow_rule_num = cJSON_GetObjectItem(cjson_search_success_info,MR_CJSON_KEY_RULE_NUM); + cJSON * cjson_flow_rule_info = cJSON_GetObjectItem(cjson_search_success_info,MR_CJSON_KEY_RULE_INFO); + cJSON * cjson_flow_rule_end = cJSON_GetObjectItem(cjson_search_success_info,MR_CJSON_KEY_RULE_END); + if (cjson_flow_rule_num != NULL) { printf("The Flow Rule Num : %u\n",(uint32_t)cjson_flow_rule_num->valuedouble); @@ -1333,112 +1461,6 @@ int send_get_count_request_msg(struct mrctl_instance * instance, struct mrctl_fl return RT_SUCCESS; } -/* Help Info */ -int help() -{ - printf("Usage: ./mrctl {Attr} {Items} {Actions}\n"); - /* Attr */ - printf("Attr:\n"); - printf(" Must Choose:\n"); - printf(" RuleType : -c,--create eg: -c\n"); - printf(" -d,--delete eg: -c\n"); - printf(" -s,--search eg: -c\n"); - printf(" --get_count eg: --get_count\n"); - printf(" Create Must Choose:\n"); - printf(" Direction : -i,--ingress eg: -i\n"); - printf(" -e,--egress eg: -e\n"); - printf(" Portname : -p,--portname eg: -p ens18f1\n"); - printf(" Optional:\n"); - printf(" Group : -g,--group eg: -g 1 \n"); - printf(" Priority : --priority eg: --priority 1\n"); - printf("\n"); - - /* Delete */ - printf("Delete Arg:\n"); - printf(" Must Choose:\n"); - printf(" RuleId : --rule_id eg: --rule_id 0\n"); - printf(" --all eg: --all\n"); - - /* Get Rule Count */ - printf("Get Rule Count:\n"); - printf(" Must Choose:\n"); - printf(" CountRuleId : --count_rule_id eg: --count_rule_id 0\n"); - printf(" --count_all eg: --count_all 0\n"); - - /* Items */ - printf("Items: Must Choose One Item\n"); - printf(" Ether : --ether eg: --ether\n"); - printf(" Arg : Must Choose One Arg\n"); - printf(" SrcMac : --smac eg: --smac C8:3A:35:09:EF:A1 \n"); - printf(" DstMac : --dmac eg: --dmac 08:C0:EB:97:D2:37\n"); - printf(" SrcMacMask : --smac_mask eg: --smac_mask FF:FF:FF:FF:FF:FF\n"); - printf(" DstMacMask : --dmac_mask eg: --dmac_mask FF:FF:FF:FF:FF:FF\n"); - printf(" EtherType : --ethertype eg: --ethertype ipv4 (OnlySupport ipv4 ipv6 vlan)\n"); - printf(" HasVlan : --hasvlan eg: --hasvlan\n"); - - printf(" IPv4 : --ipv4 eg: --ipv4\n"); - printf(" Arg : Must Choose One Arg\n"); - printf(" Tos : --tos eg: --tos 0 \n"); - printf(" FragmentOffset: --fragment_offset eg: --fragment_offset 0 \n"); - printf(" Ttl : --ttl eg: --ttl 64 \n"); - printf(" Proto : --proto eg: --proto udp (Only Support 'tcp' 'udp') \n"); - printf(" Src : --src eg: --src 123.101.255.252 \n"); - printf(" SrcMask : --src_mask eg: --src_mask 255.255.255.255 \n"); - printf(" Dst : --dst eg: --dst 123.101.255.253 \n"); - printf(" DstMask : --dst_mask eg: --dst_mask 255.255.255.255 \n"); - - printf(" Udp : --udp eg: --udp\n"); - printf(" Arg : Must Choose One Arg\n"); - printf(" SrcPort : --udp_sport eg: --udp_sport 4789 \n"); - printf(" SrcPortMask : --udp_sport_mask eg: --udp_sport_mask 65535 \n"); - printf(" DstPort : --udp_dport eg: --udp_dport 4789 \n"); - printf(" DstPortMask : --udp_dport_mask eg: --udp_dport_mask 65535 \n"); - - printf(" Tcp : --tcp eg: --tcp\n"); - printf(" Arg : Must Choose One Arg\n"); - printf(" SrcPort : --tcp_sport eg: --tcp_sport 60000 \n"); - printf(" SrcPortMask : --tcp_sport_mask eg: --tcp_sport_mask 65535 \n"); - printf(" DstPort : --tcp_dport eg: --tcp_dport 80 \n"); - printf(" DstPortMask : --tcp_dport_mask eg: --tcp_dport_mask 65535 \n"); - printf(" Flags : --tcp_flags eg: --tcp_flags 11 \n"); - - printf(" Vxlan : --vxlan eg: --vxlan\n"); - printf(" Arg : Must Choose One Arg\n"); - printf(" Vni : --vni eg: --vni 123456789 \n"); - printf(" VniMask : --vni_mask eg: --vni_mask 16777215 \n"); - printf("\n"); - - /* Actions */ - printf("Actions: Must Choose One Action\n"); - printf(" Count : --count eg: --count\n"); - printf(" Arg : Must Choose One Arg\n"); - printf(" Shared : --shared eg: --shared \n"); - printf(" Countid : --countid eg: --countid 11 \n"); - - printf(" Drop : --drop eg: --drop\n"); - - printf(" Queue : --queue eg: --queue\n"); - printf(" Arg : Must Choose One Arg\n"); - printf(" Index : --index eg: --index 7 \n"); - - printf(" SetSmac : --set_smac eg: --set_smac\n"); - printf(" Arg : Must Choose One Arg\n"); - printf(" SmacArg : --smac_arg eg: --smac_arg 08:c0:eb:97:d2:37 \n"); - - printf(" SetDmac : --set_dmac eg: --set_dmac\n"); - printf(" Arg : Must Choose One Arg\n"); - printf(" DmacArg : --dmac_arg eg: --dmac_arg c8:3a:35:09:ef:a1 \n"); - /* Eg */ - printf("Create Eg:\n"); - printf("./mrctl -c -p eth_pf_100G_1 -g 1 --priority 1 -i --ether --smac c8:3a:35:09:ef:a1 --dmac 08:c0:eb:97:d2:37 --ethertype ipv4 --dmac_mask ff:ff:ff:ff:ff:ff --smac_mask ff:ff:ff:ff:ff:ff --ipv4 --tos 0 --ttl 64 --proto udp --src 123.101.255.252 --src_mask 255.255.255.255 --dst 123.101.255.253 --udp --udp_sport 4789 --udp_sport_mask 65535 --udp_dport 4789 --udp_dport_mask 65535 --dst_mask 255.255.255.255 --vxlan --vni 0 --vni_mask 16777215 --queue --index 7 --set_smac --smac_arg 08:c0:eb:97:d2:37 --set_dmac --dmac_arg c8:3a:35:09:ef:a1\n"); - printf("Search Eg:\n"); - printf("./mrctl -s\n"); - printf("Delete Eg:\n"); - printf("./mrctl -d --rule_id 1\n"); - printf("./mrctl -d --all\n"); - return RT_SUCCESS; -} - int main(int argc, char * argv[]) { int opt = 0,close_delay = 0; |
