diff options
| author | yangwei <[email protected]> | 2024-11-12 13:24:11 +0800 |
|---|---|---|
| committer | yangwei <[email protected]> | 2024-11-12 14:22:04 +0800 |
| commit | 421d4ed459f6656f7f67c301530891e332b49959 (patch) | |
| tree | 8f59efe9755f458d9570f6900883d0cf4027378a /benchmark | |
| parent | bff48cc28a94e72540c1cdb65b3fc55e892b0201 (diff) | |
🔧 build(integrate tcpdump_mesa): in toolsFeature-merge-jump-layer
Diffstat (limited to 'benchmark')
| -rw-r--r-- | benchmark/include/sapp_bchmk_inner.h | 33 | ||||
| -rw-r--r-- | benchmark/include/sapp_benchmark.h | 8 | ||||
| -rw-r--r-- | benchmark/src/sapp_benchmark.cpp | 14 | ||||
| -rw-r--r-- | benchmark/src/sapp_benchmark_utils.cpp | 64 |
4 files changed, 54 insertions, 65 deletions
diff --git a/benchmark/include/sapp_bchmk_inner.h b/benchmark/include/sapp_bchmk_inner.h index 935bde3..76a7f5b 100644 --- a/benchmark/include/sapp_bchmk_inner.h +++ b/benchmark/include/sapp_bchmk_inner.h @@ -1,29 +1,20 @@ #ifndef _SAPP_BCHMK_INNER_H_ #define _SAPP_BCHMK_INNER_H_ 1 -#include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <netinet/ip.h> #include <netinet/tcp.h> #include <netinet/udp.h> -#include <assert.h> -#include <time.h> #include <arpa/inet.h> #include <sys/types.h> /* See NOTES */ #include <sys/socket.h> #include <sys/un.h> #include <linux/limits.h> -#include <errno.h> -#include "stream.h" -#include <signal.h> #include <sys/types.h> #include <sys/wait.h> #include <pthread.h> #include <pcap/pcap.h> #include "wrap_cJSON.h" -#include "MESA_jump_layer.h" -#include "MESA_handle_logger.h" -#include "MESA_prof_load.h" #ifdef __cplusplus extern "C" { #endif @@ -58,10 +49,11 @@ extern "C" { #define SAPP_BCHMK_DEFAULT_CFG_FILE_DIR "sapp_default_config" +#include "MESA_handle_logger.h" extern void * __g_sapp_benchmark_log_handle; #define sapp_bchmk_log(h, log_level, format, args...) do{if(((benchmark_engine_t *)h)->plug_opt.MESA_log_handle) {MESA_handle_runtime_log(((benchmark_engine_t *)h)->plug_opt.MESA_log_handle, log_level, "sapp_benchmark", format, ##args);} }while(0) -/* �ڴ����index��0��ʼ, ����Ϊ�˷����wireshark�Աȷ���, ���������ļ���index����1��ʼ, ��Ҫ��һ��ת�� */ +/* �ڴ����index��0��ʼ, ����Ϊ�˷����wireshark�Աȷ���, ���������ļ���index����1��ʼ, ��Ҫ��һ��ת�� */ #define ADJUST_ARRAY_INDEX_to_WIRESHARK(n) do{ n = n + 1;}while(0) #define ADJUST_WIRESHARK_INDEX_to_ARRAY(n) do{ n = n + 1;}while(0) @@ -88,23 +80,24 @@ typedef struct{ typedef struct{ - int pkt_len; /* pcapÿ��eth���ij��� */ - const struct ethhdr *pkt_data; /* �洢pcap�����ݵ�ָ������ */ - //char md5sum_with_timestamp[MD5_STRING_MAX_LEN]; /* ��Ϊ�ظ������ش���md5������ȫ��һ����, Ҫ����ʱ��� */ + int pkt_len; /* pcapÿ��eth���ij��� */ + const struct ethhdr *pkt_data; /* �洢pcap�����ݵ�ָ������ */ + //char md5sum_with_timestamp[MD5_STRING_MAX_LEN]; /* ��Ϊ�ظ������ش���md5������ȫ��һ����, Ҫ����ʱ��� */ }pcap_pkt_detail_t; typedef struct{ - int pkt_num; /* ���pcap����һ�����ٸ����ݰ� */ + int pkt_num; /* ���pcap����һ�����ٸ����ݰ� */ pcap_pkt_detail_t *pkt_array; }pcap_pkt_image_t; +#include "stream.h" typedef struct{ enum sapp_deploment_mode_t sapp_deploy_mode; int tap_internal_fd; int tap_external_fd; - int last_replay_fd; /* ��¼�Ǵ��ĸ���������ȥ��, ֻ��˫��ģʽ������, inline��mirror�϶�����tap_up */ + int last_replay_fd; /* ��¼�Ǵ��ĸ���������ȥ��, ֻ��˫��ģʽ������, inline��mirror�϶�����tap_up */ }pkt_process_engine_t; @@ -118,8 +111,8 @@ typedef struct{ }plug_opt_t; -/* ����debug, ԭʼ��ע���, �ִ������յ������ݰ�, (������Э��ջ�Զ������Ĺ㲥���鲥��), - ������forward��, �����Dz����ע���, Ҳ����һ����û��, ����DROP��! +/* ����debug, ԭʼ��ע���, �ִ������յ������ݰ�, (������Э��ջ�Զ������Ĺ㲥���鲥��), + ������forward��, �����Dz����ע���, Ҳ����һ����û��, ����DROP��! */ typedef struct{ int pkt_index; @@ -168,9 +161,9 @@ int sapp_bchmk_create_process_engine(benchmark_engine_t *bch_engine); int sapp_bchmk_md5_checksum(const char *filename, const char *expect_md5sum); /* - ע��: - �˺���ʵ�ʷ��ص���TRUE��FALSE, - 0��ʾ��һ��, 1��ʾһ��!! + ע��: + �˺���ʵ�ʷ��ص���TRUE��FALSE, + 0��ʾ��һ��, 1��ʾһ��!! */ cJSON_bool sapp_bchmk_json_file_compare(benchmark_engine_t *, const char *json_file1, const char *json_file2, cJSON_Compare_Opt_t opt); diff --git a/benchmark/include/sapp_benchmark.h b/benchmark/include/sapp_benchmark.h index 0067149..401078f 100644 --- a/benchmark/include/sapp_benchmark.h +++ b/benchmark/include/sapp_benchmark.h @@ -1,23 +1,17 @@ #ifndef _SAPP_BENCHMARK_H_ #define _SAPP_BENCHMARK_H_ 1 -#include <stdlib.h> -#include <stdio.h> #include <unistd.h> #include <netinet/ip.h> +#include <netinet/ip6.h> #include <netinet/tcp.h> #include <netinet/udp.h> -#include <assert.h> -#include <time.h> #include <arpa/inet.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/un.h> -#include <errno.h> -#include <signal.h> #include <sys/types.h> #include <sys/wait.h> -#include "stream.h" #ifdef __cplusplus diff --git a/benchmark/src/sapp_benchmark.cpp b/benchmark/src/sapp_benchmark.cpp index d122591..554cdbc 100644 --- a/benchmark/src/sapp_benchmark.cpp +++ b/benchmark/src/sapp_benchmark.cpp @@ -1,16 +1,18 @@ -#include "wrap_cJSON.h" +#ifdef __cplusplus +extern "C" { +#endif +#include "wrap_cJSON.h" #include "sapp_benchmark.h" #include "sapp_bchmk_inner.h" -#include "stream.h" #include "stream_entry.h" #include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <netinet/ip.h> +#include <netinet/ip6.h> #include <netinet/tcp.h> #include <netinet/udp.h> -#include <assert.h> #include <time.h> #include <arpa/inet.h> #include <sys/types.h> /* See NOTES */ @@ -21,10 +23,9 @@ #include <sys/types.h> #include <sys/wait.h> +#include "MESA_prof_load.h" + -#ifdef __cplusplus -extern "C" { -#endif /* 因为sapp插件获取不到 benchmark_engine_t 句柄, 只能暂时靠全局变量传递一下, TODO: 有什么更好的方式? @@ -470,7 +471,6 @@ static int sapp_bchmk_env_prepare(benchmark_engine_t *bch_engine) return 0; } - /* 根据内层ip确定一个传输方向, 用于双臂串联模式从哪个网卡发出. */ diff --git a/benchmark/src/sapp_benchmark_utils.cpp b/benchmark/src/sapp_benchmark_utils.cpp index 40aec01..6c80c7e 100644 --- a/benchmark/src/sapp_benchmark_utils.cpp +++ b/benchmark/src/sapp_benchmark_utils.cpp @@ -1,8 +1,13 @@ +#ifdef __cplusplus +extern "C" { +#endif + #include "sapp_benchmark.h" #include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <netinet/ip.h> +#include <netinet/ip6.h> #include <netinet/tcp.h> #include <netinet/udp.h> #include <assert.h> @@ -12,8 +17,6 @@ #include <sys/socket.h> #include <sys/un.h> #include <errno.h> -#include "stream.h" -#include <signal.h> #include <sys/types.h> #include <sys/wait.h> #include <sys/time.h> @@ -26,9 +29,8 @@ #include "wrap_cJSON.h" #include "sapp_bchmk_inner.h" -#ifdef __cplusplus -extern "C" { -#endif +#include "MESA_prof_load.h" + @@ -102,9 +104,9 @@ static int ifconfig_device_up(const char *interface_name) printf("Create Socket Failed.\n"); return -2; } - //ָ������������up + //ָ������������up sprintf(ifr.ifr_name, "%s", interface_name); - /* ��ýӿڵı�־ */ + /* ��ýӿڵı�־ */ if ((err = ioctl(socket_fd, SIOCGIFFLAGS, (void *)&ifr)) < 0) { fprintf(stderr, "ifconfig_device_up(%s), ioctl SIOCGIFFLAGS: %s\n", interface_name, strerror(errno)); close(socket_fd); @@ -143,7 +145,7 @@ int ifconfig_device_mtu(const char *interface_name, int mtu_val) return -2; } sprintf(ifr.ifr_name, "%s", interface_name); - /* ��ýӿڵı�־ */ + /* ��ýӿڵı�־ */ if ((err = ioctl(socket_fd, SIOCGIFMTU, (void *)&ifr)) < 0) { fprintf(stderr, "ifconfig_device_mtu(%s), ioctl SIOCGIFMTU: %s\n", interface_name, strerror(errno)); close(socket_fd); @@ -191,14 +193,14 @@ static int tuntap_dev_create(char *dev, int flags) ifconfig_device_up(dev); - ifconfig_device_mtu(dev, 2000); /* ijЩpcap�����ܿ�����offload, ����vlan, vxlan��, ����MTU */ + ifconfig_device_mtu(dev, 2000); /* ijЩpcap�����ܿ�����offload, ����vlan, vxlan��, ����MTU */ return fd; } /* - �������, ���mirror, inlineģʽ�Ǵ���һ��TAP, transparent�Ǵ�������TAP, - ֱ�Ӷ�ȡ����sapp.toml�ļ�. + �������, ���mirror, inlineģʽ�Ǵ���һ��TAP, transparent�Ǵ�������TAP, + ֱ�Ӷ�ȡ����sapp.toml�ļ�. */ int sapp_bchmk_create_process_engine(benchmark_engine_t *bch_engine) { @@ -289,9 +291,9 @@ int sapp_bchmk_md5_checksum(const char *filename, const char *expect_md5sum) } /* - ע��: - �˺���ʵ�ʷ��ص���TRUE��FALSE, - 0��ʾ��һ��, 1��ʾһ��!! + ע��: + �˺���ʵ�ʷ��ص���TRUE��FALSE, + 0��ʾ��һ��, 1��ʾһ��!! */ cJSON_bool sapp_bchmk_json_file_compare(benchmark_engine_t *bchmk_engine, const char *json_file1, const char *json_file2, cJSON_Compare_Opt_t opt) { @@ -429,7 +431,7 @@ int sapp_bchmk_gen_pcap_file(benchmark_engine_t *bchmk_engine, const pcap_pkt_de /* - ���ڴ��е�һ��ԭʼ����, ������pcap�ļ�, �ٵ���tshark -T ����һ��json�ļ�. + ���ڴ��е�һ��ԭʼ����, ������pcap�ļ�, �ٵ���tshark -T ����һ��json�ļ�. */ int sapp_bchmk_gen_tshark_json(benchmark_engine_t *bchmk_engine, const pcap_pkt_detail_t *pkt_detail, int pkt_num, const char *tshark_json_filename) { @@ -478,7 +480,7 @@ int sapp_bchmk_need_drop_cur_pkt(benchmark_engine_t *bchmk_engine, int pkt_index array_size = cJSON_GetArraySize(sub_pkt_index_item); - /* ��C�����±�ת��Ϊwireshark�����ݰ����, ��ʵ���Ǽ�1 */ + /* ��C�����±�ת��Ϊwireshark�����ݰ����, ��ʵ���Ǽ�1 */ ADJUST_ARRAY_INDEX_to_WIRESHARK(pkt_index); for(i = 0; i < array_size; i++){ @@ -492,9 +494,9 @@ int sapp_bchmk_need_drop_cur_pkt(benchmark_engine_t *bchmk_engine, int pkt_index } /* - ����ֵ: Ҫ���˰����������json file name. + ����ֵ: Ҫ���˰����������json file name. - �����NULL, ��Ҫ�����ж�һ��errno, �Ƿ�����Ϊjson��ʽ����, û��дpacket_detail_json_file. + �����NULL, ��Ҫ�����ж�һ��errno, �Ƿ�����Ϊjson��ʽ����, û��дpacket_detail_json_file. */ const char *sapp_bchmk_need_check_forward_pkt(benchmark_engine_t *bchmk_engine, int pkt_index) { @@ -520,7 +522,7 @@ const char *sapp_bchmk_need_check_forward_pkt(benchmark_engine_t *bchmk_engine, array_size = cJSON_GetArraySize(sub_pkt_detail_item); - /* ע��: Ϊ�˷����wireshark�Ա�, pkt index��1��ʼ����, �����±��0��ʼ */ + /* ע��: Ϊ�˷����wireshark�Ա�, pkt index��1��ʼ����, �����±��0��ʼ */ ADJUST_ARRAY_INDEX_to_WIRESHARK(pkt_index); for(i = 0; i < array_size; i++){ @@ -546,7 +548,7 @@ const char *sapp_bchmk_need_check_forward_pkt(benchmark_engine_t *bchmk_engine, } /* - ����ֵ: ָ��inject���cjson�ṹ��ָ��. + ����ֵ: ָ��inject���cjson�ṹ��ָ��. */ const cJSON *sapp_bchmk_need_check_inject_pkt(benchmark_engine_t *bchmk_engine, int carray_pkt_index) { @@ -566,9 +568,9 @@ const cJSON *sapp_bchmk_need_check_inject_pkt(benchmark_engine_t *bchmk_engine, return NULL; } - /* ע��: Ϊ�˷����wireshark�Ա�, pkt index��1��ʼ����, �˴������0��ʼ */ + /* ע��: Ϊ�˷����wireshark�Ա�, pkt index��1��ʼ����, �˴������0��ʼ */ if(sub_array_pkt_index_item->valueint != (carray_pkt_index+1)){ - /* ��ǰ�����ᴥ��inject����, do nothing */ + /* ��ǰ�����ᴥ��inject����, do nothing */ sapp_bchmk_log(bchmk_engine,RLOG_LV_DEBUG, "pkt index:%d, don't need check inject json, ignore it", carray_pkt_index+1); errno = 0; return NULL; @@ -578,7 +580,7 @@ const cJSON *sapp_bchmk_need_check_inject_pkt(benchmark_engine_t *bchmk_engine, } /* - ����ֵ: ָ��control���cjson�ṹ��ָ��. + ����ֵ: ָ��control���cjson�ṹ��ָ��. */ const cJSON *sapp_bchmk_need_process_control(benchmark_engine_t *bchmk_engine, int carray_pkt_index) { @@ -604,13 +606,13 @@ const cJSON *sapp_bchmk_need_process_control(benchmark_engine_t *bchmk_engine, i /* - ÿ�β���ǰ, ����sapp��Ĭ�����ø������л���, - ��Ҫ�ĵ����ò���, ÿ��ҲҪ�ֳ���, - ������Ĭ�ϲ��������²��Բ�ͨ��. + ÿ�β���ǰ, ����sapp��Ĭ�����ø������л���, + ��Ҫ�ĵ����ò���, ÿ��ҲҪ�ֳ���, + ������Ĭ�ϲ��������²��Բ�ͨ��. - ��sapp�������ļ�ֱ�ӷ������.c����, ����cmake install, ��rpm -iʱ�Ͳ���װһ���ļ���, - ���������װʱʹ��--prefix����, ������Ҳ�����Щ�ļ���. - ֱ�Ӵӳ�����copy����. + ��sapp�������ļ�ֱ�ӷ������.c����, ����cmake install, ��rpm -iʱ�Ͳ���װһ���ļ���, + ���������װʱʹ��--prefix����, ������Ҳ�����Щ�ļ���. + ֱ�Ӵӳ�����copy����. */ static void sapp_bchmk_write_to_file(const char *config_name, const void *content, int content_len) @@ -657,7 +659,7 @@ void sapp_bchmk_set_default_config(void) sapp_bchmk_write_to_file("etc/send_raw_pkt.conf", templete_send_raw_pkt, templete_send_raw_pkt_len); sapp_bchmk_write_to_file("etc/send_log.conf", templete_sapp_log, templete_sapp_log_len); - /* ������plug.inf����, ֻ���������ͷ���ֶ� */ + /* ������plug.inf����, ֻ���������ͷ���ֶ� */ system("mkdir -p ./plug/business/gtest_sapp"); system("echo \"[PLUGINFO]\" > ./plug/business/gtest_sapp/gtest_sapp.inf"); system("echo \"PLUGNAME=xxxx\" >> ./plug/business/gtest_sapp/gtest_sapp.inf"); @@ -734,7 +736,7 @@ const char *sapp_bchmk_rawpkt_ntop_v6(const struct ip6_hdr *ip6hdr, char *res_bu dport = inner_uhdr->dest; snprintf(res_buf, buf_len, "%s.%u --> %s.%u, %s", ip_src_str, ntohs(sport), ip_dst_str, ntohs(dport), "UDP"); - }else if(IPPROTO_ICMPV6 == inner_ip_proto){ /* ע��: ipv6��icmpͷ���ֶ���ipv4��һ��!! */ + }else if(IPPROTO_ICMPV6 == inner_ip_proto){ /* ע��: ipv6��icmpͷ���ֶ���ipv4��һ��!! */ snprintf(res_buf, buf_len, "%s --> %s,ICMP", ip_src_str, ip_dst_str); }else{ snprintf(res_buf, buf_len, "%s --> %s, unknown protocol:%u", ip_src_str, ip_dst_str, inner_ip_proto); |
