diff options
| author | 杨威 <[email protected]> | 2023-06-20 15:32:46 +0800 |
|---|---|---|
| committer | 杨威 <[email protected]> | 2023-06-26 20:18:26 +0800 |
| commit | acc0ee76193f032c64dca379acad9c7256d6e13f (patch) | |
| tree | f0f7128a993710dbeca21f4fc97184fb85345e19 /src/inner_plug/sapp_assistant.cpp | |
| parent | 7510b7b17e9494550076d3da6116526282140b44 (diff) | |
🌈 style(inner_plug): 目录更名为extensions
Diffstat (limited to 'src/inner_plug/sapp_assistant.cpp')
| -rw-r--r-- | src/inner_plug/sapp_assistant.cpp | 1309 |
1 files changed, 0 insertions, 1309 deletions
diff --git a/src/inner_plug/sapp_assistant.cpp b/src/inner_plug/sapp_assistant.cpp deleted file mode 100644 index 666605e..0000000 --- a/src/inner_plug/sapp_assistant.cpp +++ /dev/null @@ -1,1309 +0,0 @@ -/* - ���ļ���ƽ̨���Ĺ��ܺͺ���(Ip��Ƭ, ����ԭ, ��������, ���������), - ���ṩ������ҵ�����Ľӿ�, ��sapp_get_platform_opt��, ��Ϊһ��.so�ļ����ص�ƽ̨, - ���ڸ��²���. -*/ -#include "sapp_api.h" -#include "sapp_private_api.h" -#include "sapp_declaration.h" -#include "field_stat2.h" -#include "fieldstat.h" - -#include "marsio.h" - -static int sapp_fs2_init(sapp_global_t *global_parameters); -static int sapp_fs3_init(sapp_global_t *global_parameters); - -//extern time_t g_CurrentTime;//add by lqy 20070606 -//extern int g_packet_io_thread_num; -extern char g_app_instance_name[64]; -//extern int g_timestamp_record_sw; - -static pthread_mutex_t g_plug_Independent_thread_mutex; -static pthread_t *g_plug_Independent_thread_pid; - - -static const unsigned char G_BROADCAST_ADDR[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; - -int sapp_assistant_version_VERSION_20181024; -extern "C" int MESA_get_dev_ipv4(const char *device, int *ip_add); -extern "C" int MESA_get_dev_mac(const char *device, unsigned char mac[6]); - -void * (*dl_marsio_buff_ctrlzone)(void *m, uint8_t id); -extern void * (*ptr_marsio_buff_ctrlzone)(marsio_buff_t *m, uint8_t id); - - -/* ʶ���Ƿ������ڲ����ݰ� , �����ڵİ�Ӧ��������ת��/��ע */ -int sapp_identify_tunnel_inner_pkt(const raw_pkt_t *raw_pkt) -{ - int ret = 0; -#if IOMODE_MARSIO - if (CAP_MODEL_MARSIOV4 == g_packet_io_cap_mode) - { - /* û��mrtunnatʱ, �������l2_l3_tunnel_support, Ҫ�ж�overlay����, �Ƿ��Ǹ�������, �Ƿ��Ǿ���overlayԭʼ��·��İ� */ - if (raw_pkt->is_overlay_pkt) - { - ret = 1; - } - } -#endif - - return ret; -} -int sapp_identify_broad_multicast_pkt(const void *this_layer_data, const raw_pkt_t *raw_pkt) -{ - const struct mesa_ethernet_hdr *p_eth_hdr = (const struct mesa_ethernet_hdr *)this_layer_data; - unsigned short eth_type = ntohs(p_eth_hdr->ether_type); - - if(sapp_identify_tunnel_inner_pkt(raw_pkt) != 0){ - return 0; - } - - if(memcmp(G_BROADCAST_ADDR, p_eth_hdr->ether_dhost, ETH_ALEN) == 0){ - /* G����ģʽ�£���ARPЭ��Ĺ㲥����ֱ�Ӷ���! ��ֹ�ٻ�ע��������, ��ɹ㲥�籩���������� */ - if(eth_type != ETH_P_ARP){ - return 1; - } - }else{ - /* 2017-10-10 lijia add, �鲥MAC��ַ, ͨ��Ϊ�������ڿ��������ݰ�, ��LLMNR, STP��Э��, һ�����账�� - �ο�:https://en.wikipedia.org/wiki/Multicast_address - */ - if((p_eth_hdr->ether_dhost[0] == 0x01) - &&(p_eth_hdr->ether_dhost[1] == 0x00) - &&(p_eth_hdr->ether_dhost[2] == 0x0C) - &&(p_eth_hdr->ether_dhost[3] == 0xCC)){ - return 1; - }else if((p_eth_hdr->ether_dhost[0] == 0x01) - &&(p_eth_hdr->ether_dhost[1] == 0x80) - &&(p_eth_hdr->ether_dhost[2] == 0xC2) - &&(p_eth_hdr->ether_dhost[3] == 0x00)){ - return 1; - }else if((p_eth_hdr->ether_dhost[0] == 0x01) - &&(p_eth_hdr->ether_dhost[1] == 0x00) - &&(p_eth_hdr->ether_dhost[2] == 0x5E)){ - return 1; - }else if((p_eth_hdr->ether_dhost[0] == 0x33) - &&(p_eth_hdr->ether_dhost[1] == 0x33)){ - return 1; - }else if((p_eth_hdr->ether_dhost[0] == 0x01) - &&(p_eth_hdr->ether_dhost[1] == 0x0C) - &&(p_eth_hdr->ether_dhost[2] == 0xCD)){ - return 1; - } - } - - return 0; -} - -/* - ctype: - 'c':count; - 'l':length; -*/ -static inline unsigned long long __get_platform_opt_traffic(int ctype, sapp_sys_stat_type_t index) -{ - int i; - unsigned long long tmp_long = 0; - - for(i = 0; i < g_packet_io_thread_num; i++){ - if('c' == ctype){ - tmp_long += sapp_global_val->mthread_volatile[i]->sys_stat.count[index]; - }else{ - tmp_long += sapp_global_val->mthread_volatile[i]->sys_stat.length[index]; - } - } - - return tmp_long; -} - -/* 2017-09-04 lijia add, for ��������, �����ȡƽ̨�ڲ����� */ -extern "C" int sapp_get_platform_opt(enum sapp_platform_opt opt, void *opt_val, int *opt_val_len) -{ - int ret = 0; - - if((NULL == opt_val) || (NULL == opt_val_len) || (*opt_val_len <= 0)){ - return -1; - } - - switch((int)opt){ - case SPO_TOTAL_RCV_PKT: - { - if(*opt_val_len != sizeof(long long)){ - ret = -1; - sapp_runtime_log(RLOG_LV_INFO, "sapp_get_platform_opt() SPO_TOTAL_RCV_PKT error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - unsigned long long *tot_pkt = (unsigned long long *)opt_val; - *tot_pkt = __get_platform_opt_traffic('c', SAPP_STAT_RCV_ETHERNET); - } - break; - - case SPO_TOTAL_RCV_BYTE: - { - if(*opt_val_len != sizeof(long long)){ - ret = -1; - sapp_runtime_log(RLOG_LV_INFO, "sapp_get_platform_opt() SPO_TOTAL_RCV_BYTE error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - unsigned long long *tot_byte = (unsigned long long *)opt_val; - *tot_byte = __get_platform_opt_traffic('l', SAPP_STAT_RCV_ETHERNET);; - } - break; - - case SPO_TOTAL_INBOUND_PKT: - { - if(*opt_val_len != sizeof(long long)){ - ret = -1; - sapp_runtime_log(RLOG_LV_INFO, "sapp_get_platform_opt() SPO_TOTAL_INBOUND_PKT error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - unsigned long long *inbound_pkt = (unsigned long long *)opt_val; - *inbound_pkt = __get_platform_opt_traffic('c', SAPP_STAT_RAW_INBOUND); - } - break; - - case SPO_TOTAL_INBOUND_BYTE: - { - if(*opt_val_len != sizeof(long long)){ - ret = -1; - sapp_runtime_log(RLOG_LV_INFO, "sapp_get_platform_opt() SPO_TOTAL_INBOUND_BYTE error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - unsigned long long *inbound_byte = (unsigned long long *)opt_val; - *inbound_byte = __get_platform_opt_traffic('l', SAPP_STAT_RAW_INBOUND); - - } - break; - - case SPO_TOTAL_OUTBOUND_PKT: - { - if(*opt_val_len != sizeof(long long)){ - ret = -1; - sapp_runtime_log(RLOG_LV_INFO, "sapp_get_platform_opt() SPO_TOTAL_OUTBOUND_PKT error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - unsigned long long *outbound_pkt = (unsigned long long *)opt_val; - *outbound_pkt = __get_platform_opt_traffic('c', SAPP_STAT_RAW_OUTBOUND); - } - break; - - case SPO_TOTAL_OUTBOUND_BYTE: - { - if(*opt_val_len != sizeof(long long)){ - ret = -1; - sapp_runtime_log(RLOG_LV_INFO, "sapp_get_platform_opt() SPO_TOTAL_OUTBOUND_BYTE error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - unsigned long long *outbound_byte = (unsigned long long *)opt_val; - *outbound_byte = __get_platform_opt_traffic('l', SAPP_STAT_RAW_OUTBOUND); - - } - break; - - case SPO_TCP_STREAM_NEW: - { - if(*opt_val_len != sizeof(long long)){ - ret = -1; - sapp_runtime_log(RLOG_LV_INFO, "sapp_get_platform_opt() SPO_TCP_STREAM_NEW error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - unsigned long long *tot_num = (unsigned long long *)opt_val; - *tot_num = __get_platform_opt_traffic('c', SAPP_STAT_TCP_STREAM_NEW); - } - break; - - case SPO_TCP_STREAM_ESTAB: - { - if(*opt_val_len != sizeof(long long)){ - ret = -1; - sapp_runtime_log(RLOG_LV_INFO, "sapp_get_platform_opt() SPO_TCP_STREAM_ESTAB error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - unsigned long long *tot_num = (unsigned long long *)opt_val; - *tot_num = __get_platform_opt_traffic('c', SAPP_STAT_TCP_STREAM_DATA); - } - break; - - case SPO_TCP_STREAM_CLOSE: - { - if(*opt_val_len != sizeof(long long)){ - ret = -1; - sapp_runtime_log(RLOG_LV_INFO, "sapp_get_platform_opt() SPO_TCP_STREAM_CLOSE error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - unsigned long long *tot_num = (unsigned long long *)opt_val; - *tot_num = __get_platform_opt_traffic('c', SAPP_STAT_TCP_STREAM_DEL); - } - break; - - case SPO_UDP_STREAM_NEW: - { - if(*opt_val_len != sizeof(long long)){ - ret = -1; - sapp_runtime_log(RLOG_LV_INFO, "sapp_get_platform_opt() SPO_UDP_STREAM_NEW error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - unsigned long long *tot_num = (unsigned long long *)opt_val; - *tot_num = __get_platform_opt_traffic('c', SAPP_STAT_UDP_STREAM_NEW); - } - break; - - case SPO_UDP_STREAM_CONCURRENT: - { - if(*opt_val_len != sizeof(long long)){ - ret = -1; - sapp_runtime_log(RLOG_LV_INFO, "sapp_get_platform_opt() SPO_UDP_STREAM_CONCURRENT error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - unsigned long long *tot_num = (unsigned long long *)opt_val; - *tot_num = __get_platform_opt_traffic('c', SAPP_STAT_UDP_STREAM_TWO); - } - break; - - - case SPO_UDP_STREAM_CLOSE: - { - if(*opt_val_len != sizeof(long long)){ - ret = -1; - sapp_runtime_log(RLOG_LV_INFO, "sapp_get_platform_opt() SPO_UDP_STREAM_CLOSE error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - unsigned long long *tot_num = (unsigned long long *)opt_val; - *tot_num = __get_platform_opt_traffic('c', SAPP_STAT_UDP_STREAM_DEL); - } - break; - - case SPO_TOTAL_RCV_INBOUND_IPV4_PKT: - { - if (*opt_val_len != sizeof(long long)) - { - ret = -1; - sapp_runtime_log(RLOG_LV_DEBUG, "sapp_get_platform_opt() error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - unsigned long long *tot_pkt = (unsigned long long *)opt_val; - *tot_pkt = __get_platform_opt_traffic('c', SAPP_STAT_IPV4_INBOUND); - } - break; - case SPO_TOTAL_RCV_INBOUND_IPV4_BYTE: - { - if (*opt_val_len != sizeof(long long)) - { - ret = -1; - sapp_runtime_log(RLOG_LV_DEBUG, "sapp_get_platform_opt() error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - unsigned long long *tot_pkt = (unsigned long long *)opt_val; - *tot_pkt = __get_platform_opt_traffic('l', SAPP_STAT_IPV4_INBOUND); - } - break; - case SPO_TOTAL_RCV_OUTBOUND_IPV4_PKT: - { - if (*opt_val_len != sizeof(long long)) - { - ret = -1; - sapp_runtime_log(RLOG_LV_DEBUG, "sapp_get_platform_opt() error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - unsigned long long *tot_byte = (unsigned long long *)opt_val; - *tot_byte = __get_platform_opt_traffic('c', SAPP_STAT_IPV4_OUTBOUND); - ; - } - break; - case SPO_TOTAL_RCV_OUTBOUND_IPV4_BYTE: - { - if (*opt_val_len != sizeof(long long)) - { - ret = -1; - sapp_runtime_log(RLOG_LV_DEBUG, "sapp_get_platform_opt() error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - unsigned long long *tot_byte = (unsigned long long *)opt_val; - *tot_byte = __get_platform_opt_traffic('l', SAPP_STAT_IPV4_OUTBOUND); - ; - } - break; - - case SPO_TOTAL_RCV_INBOUND_IPV6_PKT: - { - if (*opt_val_len != sizeof(long long)) - { - ret = -1; - sapp_runtime_log(RLOG_LV_DEBUG, "sapp_get_platform_opt() error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - unsigned long long *tot_pkt = (unsigned long long *)opt_val; - *tot_pkt = __get_platform_opt_traffic('c', SAPP_STAT_IPV6_INBOUND); - } - break; - case SPO_TOTAL_RCV_INBOUND_IPV6_BYTE: - { - if (*opt_val_len != sizeof(long long)) - { - ret = -1; - sapp_runtime_log(RLOG_LV_DEBUG, "sapp_get_platform_opt() error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - unsigned long long *tot_pkt = (unsigned long long *)opt_val; - *tot_pkt = __get_platform_opt_traffic('l', SAPP_STAT_IPV6_INBOUND); - } - break; - case SPO_TOTAL_RCV_OUTBOUND_IPV6_PKT: - { - if (*opt_val_len != sizeof(long long)) - { - ret = -1; - sapp_runtime_log(RLOG_LV_DEBUG, "sapp_get_platform_opt() error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - unsigned long long *tot_byte = (unsigned long long *)opt_val; - *tot_byte = __get_platform_opt_traffic('c', SAPP_STAT_IPV6_OUTBOUND); - ; - } - break; - case SPO_TOTAL_RCV_OUTBOUND_IPV6_BYTE: - { - if (*opt_val_len != sizeof(long long)) - { - ret = -1; - sapp_runtime_log(RLOG_LV_DEBUG, "sapp_get_platform_opt() error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - unsigned long long *tot_byte = (unsigned long long *)opt_val; - *tot_byte = __get_platform_opt_traffic('l', SAPP_STAT_IPV6_OUTBOUND); - ; - } - break; - - case SPO_TOTAL_RCV_INBOUND_TCP_PKT: - { - if (*opt_val_len != sizeof(long long)) - { - ret = -1; - sapp_runtime_log(RLOG_LV_DEBUG, "sapp_get_platform_opt() error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - unsigned long long *tot_pkt = (unsigned long long *)opt_val; - *tot_pkt = __get_platform_opt_traffic('c', SAPP_STAT_TCP_INBOUND); - } - break; - case SPO_TOTAL_RCV_INBOUND_TCP_BYTE: - { - if (*opt_val_len != sizeof(long long)) - { - ret = -1; - sapp_runtime_log(RLOG_LV_DEBUG, "sapp_get_platform_opt() error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - unsigned long long *tot_pkt = (unsigned long long *)opt_val; - *tot_pkt = __get_platform_opt_traffic('l', SAPP_STAT_TCP_INBOUND); - } - break; - case SPO_TOTAL_RCV_OUTBOUND_TCP_PKT: - { - if (*opt_val_len != sizeof(long long)) - { - ret = -1; - sapp_runtime_log(RLOG_LV_DEBUG, "sapp_get_platform_opt() error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - unsigned long long *tot_byte = (unsigned long long *)opt_val; - *tot_byte = __get_platform_opt_traffic('c', SAPP_STAT_TCP_OUTBOUND); - ; - } - break; - case SPO_TOTAL_RCV_OUTBOUND_TCP_BYTE: - { - if (*opt_val_len != sizeof(long long)) - { - ret = -1; - sapp_runtime_log(RLOG_LV_DEBUG, "sapp_get_platform_opt() error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - unsigned long long *tot_byte = (unsigned long long *)opt_val; - *tot_byte = __get_platform_opt_traffic('l', SAPP_STAT_TCP_OUTBOUND); - ; - } - break; - - case SPO_TOTAL_RCV_INBOUND_UDP_PKT: - { - if (*opt_val_len != sizeof(long long)) - { - ret = -1; - sapp_runtime_log(RLOG_LV_DEBUG, "sapp_get_platform_opt() error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - unsigned long long *tot_pkt = (unsigned long long *)opt_val; - *tot_pkt = __get_platform_opt_traffic('c', SAPP_STAT_UDP_INBOUND); - } - break; - - case SPO_TOTAL_RCV_INBOUND_UDP_BYTE: - { - if (*opt_val_len != sizeof(long long)) - { - ret = -1; - sapp_runtime_log(RLOG_LV_DEBUG, "sapp_get_platform_opt() error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - unsigned long long *tot_pkt = (unsigned long long *)opt_val; - *tot_pkt = __get_platform_opt_traffic('l', SAPP_STAT_UDP_INBOUND); - } - break; - - case SPO_TOTAL_RCV_OUTBOUND_UDP_PKT: - { - if (*opt_val_len != sizeof(long long)) - { - ret = -1; - sapp_runtime_log(RLOG_LV_DEBUG, "sapp_get_platform_opt() error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - unsigned long long *tot_byte = (unsigned long long *)opt_val; - *tot_byte = __get_platform_opt_traffic('c', SAPP_STAT_UDP_OUTBOUND); - ; - } - break; - - case SPO_TOTAL_RCV_OUTBOUND_UDP_BYTE: - { - if (*opt_val_len != sizeof(long long)) - { - ret = -1; - sapp_runtime_log(RLOG_LV_DEBUG, "sapp_get_platform_opt() error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - unsigned long long *tot_byte = (unsigned long long *)opt_val; - *tot_byte = __get_platform_opt_traffic('l', SAPP_STAT_UDP_OUTBOUND); - ; - } - break; - - case SPO_THREAD_COUNT: - { - if(*opt_val_len != sizeof(int)){ - ret = -1; - sapp_runtime_log(RLOG_LV_INFO, "sapp_get_platform_opt() SPO_THREAD_COUNT error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - - int *tcnt = (int *)opt_val; - *tcnt = g_packet_io_thread_num; - } - break; - - case SPO_CURTIME_TIMET: - { - if(*opt_val_len != sizeof(time_t)){ - ret = -1; - sapp_runtime_log(RLOG_LV_INFO, "sapp_get_platform_opt() SPO_CURTIME_TIMET error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - time_t *curtime = (time_t *)opt_val; - *curtime = g_CurrentTime; - } - break; - - case SPO_CURTIME_TIMET_MS: - { - if(*opt_val_len != sizeof(long long)){ - ret = -1; - sapp_runtime_log(RLOG_LV_INFO, "sapp_get_platform_opt() SPO_CURTIME_TIMET_MS error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - long long *curtime_ms = (long long *)opt_val; - *curtime_ms = sapp_global_val->individual_volatile->current_time_ms; - - } - break; - - case SPO_CURTIME_STRING: - { - if(*opt_val_len <= (int)strlen("1970-01-01 11:11:11")){ - - ret = -1; - - sapp_runtime_log(RLOG_LV_INFO, "sapp_get_platform_opt() SPO_CURTIME_STRING error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - time_t cur_time = g_CurrentTime; - struct tm date_loc; - - localtime_r(&cur_time, &date_loc); - ret = snprintf((char *)opt_val, *opt_val_len, "%04d-%02d-%02d %02d:%02d:%02d", - date_loc.tm_year+1900, date_loc.tm_mon+1,date_loc.tm_mday, - date_loc.tm_hour, date_loc.tm_min, date_loc.tm_sec); - *opt_val_len = ret; - } - break; - - case SPO_START_TIME: - { - if(*opt_val_len != sizeof(time_t)){ - ret = -1; - - sapp_runtime_log(RLOG_LV_INFO, "sapp_get_platform_opt() SPO_START_TIME error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - time_t *stime = (time_t *)opt_val; - *stime = ABBR_SAPP_START_TIME; - } - break; - - case SPO_RUN_TIME: - { - if(*opt_val_len != sizeof(time_t)){ - ret = -1; - - sapp_runtime_log(RLOG_LV_INFO, "sapp_get_platform_opt() SPO_RUN_TIME error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - time_t *runtime = (time_t *)opt_val; - *runtime = ABBR_CURRENT_TIME - ABBR_SAPP_START_TIME; - } - break; - - /* �ⲿ���Ƶ������rand�Ⱥ����Ƚ�����CPU, ʹ��CPU��ǰ��ʱ��������, �͵�ǰƽ̨�����İ���ƴ��һ������� */ - case SPO_RAND_NUMBER: - { - if(*opt_val_len != sizeof(long long)){ - ret = -1; - - sapp_runtime_log(RLOG_LV_INFO, "sapp_get_platform_opt() SPO_RAND_NUMBER error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - - long long *rnum = (long long *)opt_val; - - *rnum = ((sapp_get_cpu_cycle() & 0xFFFF) << 48) - | ((sapp_global_val->mthread_volatile[0]->sys_stat.count[SAPP_STAT_RCV_ETHERNET] & 0xFFFF) << 32) - | ((sapp_global_val->mthread_volatile[0]->sys_stat.length[SAPP_STAT_RCV_ETHERNET] & 0xFFFF) << 16) - | ((sapp_global_val->mthread_volatile[0]->sys_stat.count[SAPP_STAT_RCV_IPV4] & 0xFFFF)); - } - break; - - case SPO_FIELD_STAT_HANDLE: - { - ret = -1; - sapp_runtime_log(RLOG_LV_INFO, "sapp_get_platform_opt() SPO_FIELD_STAT_HANDLE error: obsolete option"); - break; - } - break; - - case SPO_INDEPENDENT_THREAD_ID: - { - int id_index = -1; - int *opt_int = (int *)opt_val; - int i; - pthread_t this_pid = pthread_self(); /* ��ȡ��ǰ�߳�id */ - - pthread_mutex_lock(&g_plug_Independent_thread_mutex); - - /* Ϊ����һ���̶߳�ε��ô˽ӿ�, �Ȳ���֮ǰ�Ƿ�� */ - for(i = 0; i < sapp_global_val->config.cpu.send_only_threads_max_num; i++){ - if(g_plug_Independent_thread_pid[i] == this_pid){ - id_index = i; - break; - } - } - - if(-1 == id_index){ /* ��ǰ�̵߳�һ�δ���, û�ҵ� */ - for(i = 0; i < sapp_global_val->config.cpu.send_only_threads_max_num; i++){ - if(0 == g_plug_Independent_thread_pid[i]){ - g_plug_Independent_thread_pid[i] = this_pid; - break; - } - } - if(i >= sapp_global_val->config.cpu.send_only_threads_max_num ){ /* ���������߳�������� */ - sapp_runtime_log(RLOG_LV_FATAL, "Independent_thread num more than CPU->send_only_threads_max:%d!\n", - sapp_global_val->config.cpu.send_only_threads_max_num); - *opt_int = -1; - ret = -1; - }else{ - *opt_int = g_packet_io_thread_num + i; - } - }else{ - *opt_int = g_packet_io_thread_num + id_index; - } - - pthread_mutex_unlock(&g_plug_Independent_thread_mutex); - } - break; - - case SPO_DEPLOYMENT_MODE_STR: - { - if(*opt_val_len <= (int)strlen(sapp_global_val->config.packet_io.depolyment_mode_str)){ - ret = -1; - - sapp_runtime_log(RLOG_LV_INFO, "sapp_get_platform_opt() SPO_DEPLOYMENT_MODE_STR error:opt_val_len:%d is not enough!\n", *opt_val_len); - break; - } - strncpy((char *)opt_val, sapp_global_val->config.packet_io.depolyment_mode_str, *opt_val_len); - } - break; - - case SPO_DEPLOYMENT_MODE: - { - if(*opt_val_len != sizeof(enum sapp_deploment_mode_t)){ - ret = -1; - sapp_runtime_log(RLOG_LV_INFO, "sapp_get_platform_opt() SPO_DEPLOYMENT_MODE error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - enum sapp_deploment_mode_t *dep_mode = (enum sapp_deploment_mode_t *)opt_val; - *dep_mode = (enum sapp_deploment_mode_t)sapp_global_val->config.packet_io.depolyment_mode_bin; - } - break; - - case SPO_CURRENT_STATE: - { - if(*opt_val_len != sizeof(enum sapp_state_t)){ - ret = -1; - sapp_runtime_log(RLOG_LV_INFO, "sapp_get_platform_opt() SPO_CURRENT_STATE error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - enum sapp_state_t *cur_stage = (enum sapp_state_t *)opt_val; - *cur_stage = (enum sapp_state_t)sapp_global_val->individual_volatile->current_state; - } - - case SPO_CONFIG_ROOT_DIR: - { - if(NULL == sapp_global_val->config.cfg_file_path.cfg_files_root_dir){ - sapp_runtime_log(RLOG_LV_INFO, "sapp_get_platform_opt() SPO_CONFIG_ROOT_DIR error: no config root dir cmd args!\n"); - ret = -1; - break; - } - if(*opt_val_len <= (int)strlen(sapp_global_val->config.cfg_file_path.cfg_files_root_dir)+1){ - sapp_runtime_log(RLOG_LV_INFO, "sapp_get_platform_opt() SPO_CONFIG_ROOT_DIR error:opt_val_len:%d is smaller than root dir string len!\n", *opt_val_len); - ret = -1; - } - strncpy((char *)opt_val, sapp_global_val->config.cfg_file_path.cfg_files_root_dir, *opt_val_len); - } - break; - - case SPO_DATA_ROOT_DIR: - { - if(NULL == sapp_global_val->config.data_file_path.data_files_root_dir){ - sapp_runtime_log(RLOG_LV_INFO, "sapp_get_platform_opt() SPO_CONFIG_ROOT_DIR error: no data root dir cmd args!\n"); - ret = -1; - break; - } - if(*opt_val_len <= (int)strlen(sapp_global_val->config.data_file_path.data_files_root_dir)+1){ - sapp_runtime_log(RLOG_LV_INFO, "sapp_get_platform_opt() SPO_DATA_ROOT_DIR error:opt_val_len:%d is smaller than root dir string len!\n", *opt_val_len); - ret = -1; - } - strncpy((char *)opt_val, sapp_global_val->config.data_file_path.data_files_root_dir, *opt_val_len); - } - break; - - case SPO_TCP_STREAM_C2S: - { - if(*opt_val_len != sizeof(long long)){ - ret = -1; - sapp_runtime_log(RLOG_LV_INFO, "sapp_get_platform_opt() SPO_TCP_STREAM_C2S error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - unsigned long long *tot_num = (unsigned long long *)opt_val; - *tot_num = __get_platform_opt_traffic('c', SAPP_STAT_TCP_STREAM_TOTAL_C2S); - } - break; - - case SPO_TCP_STREAM_S2C: - { - if(*opt_val_len != sizeof(long long)){ - ret = -1; - sapp_runtime_log(RLOG_LV_INFO, "sapp_get_platform_opt() SPO_TCP_STREAM_S2C error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - unsigned long long *tot_num = (unsigned long long *)opt_val; - *tot_num = __get_platform_opt_traffic('c', SAPP_STAT_TCP_STREAM_TOTAL_S2C); - } - break; - - case SPO_TCP_STREAM_DOUBLE: - { - if(*opt_val_len != sizeof(long long)){ - ret = -1; - sapp_runtime_log(RLOG_LV_INFO, "sapp_get_platform_opt() SPO_TCP_STREAM_DOUBLE error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - unsigned long long *tot_num = (unsigned long long *)opt_val; - *tot_num = __get_platform_opt_traffic('c', SAPP_STAT_TCP_STREAM_TOTAL_DOUBLE); - } - break; - - case SPO_UDP_STREAM_C2S: - { - if(*opt_val_len != sizeof(long long)){ - ret = -1; - sapp_runtime_log(RLOG_LV_INFO, "sapp_get_platform_opt() SPO_UDP_STREAM_C2S error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - unsigned long long *tot_num = (unsigned long long *)opt_val; - *tot_num = __get_platform_opt_traffic('c', SAPP_STAT_UDP_STREAM_TOTAL_C2S); - } - break; - - case SPO_UDP_STREAM_S2C: - { - if(*opt_val_len != sizeof(long long)){ - ret = -1; - sapp_runtime_log(RLOG_LV_INFO, "sapp_get_platform_opt() SPO_UDP_STREAM_S2C error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - unsigned long long *tot_num = (unsigned long long *)opt_val; - *tot_num = __get_platform_opt_traffic('c', SAPP_STAT_UDP_STREAM_TOTAL_S2C); - } - break; - - case SPO_UDP_STREAM_DOUBLE: - { - if(*opt_val_len != sizeof(long long)){ - ret = -1; - sapp_runtime_log(RLOG_LV_INFO, "sapp_get_platform_opt() SPO_UDP_STREAM_DOUBLE error:opt_val_len:%d is invalid!\n", *opt_val_len); - break; - } - unsigned long long *tot_num = (unsigned long long *)opt_val; - *tot_num = __get_platform_opt_traffic('c', SAPP_STAT_UDP_STREAM_TOTAL_DOUBLE); - } - break; - - default: - - sapp_runtime_log(RLOG_LV_FATAL, "sapp_get_platform_opt() error:opt_type:%d not support!\n", (int)opt); - ret = -1; - } - - return ret; -} - -static int __sdo_get_dev_mtu(const char *device, int *mtu) -{ - struct ifreq ifr; - int fd; - - fd = socket(AF_INET, SOCK_DGRAM, 0); - if(fd < 0) - { - return -1; - } - - memset(ifr.ifr_ifrn.ifrn_name, 0, sizeof(ifr.ifr_ifrn.ifrn_name)); - strncpy(ifr.ifr_ifrn.ifrn_name, device, sizeof(ifr.ifr_ifrn.ifrn_name)); - if(ioctl(fd, SIOCGIFMTU, &ifr) == -1) - { - fprintf(stderr, "__sdo_get_dev_mtu(%s), ioctl SIOCGIFMTU: %s\n", device, strerror(errno)); - goto err_exit; - } - - *mtu = ifr.ifr_ifru.ifru_mtu; - - close(fd); - - return 0; - -err_exit: - close(fd); - return -1; -} - -extern "C" int sapp_get_device_opt(const char *device, enum sapp_device_opt opt_type, void *opt_val, int *opt_val_len) -{ - int ret; - unsigned char uchar_tmp_buf[8]; - //char *char_out_value; - int int_out_value; - - if((NULL == opt_val) || (NULL == opt_val_len) || (*opt_val_len <= 0)){ - return -1; - } - - switch((int)opt_type){ - case SDO_MAC_ADDR: - { - ret = MESA_get_dev_mac(device, uchar_tmp_buf); - if(ret < 0){ - return ret; - } - if(*opt_val_len < ETH_ALEN){ - return -1; - } - memcpy(opt_val, uchar_tmp_buf, ETH_ALEN); - *opt_val_len = ETH_ALEN; - ret = 0; - } - break; - - case SDO_IPV4_ADDR: - { - ret = MESA_get_dev_ipv4(device, &int_out_value); - if(ret < 0){ - return ret; - } - if(*opt_val_len < (int)sizeof(int)){ - return -1; - } - memcpy(opt_val, &int_out_value, sizeof(int)); - *opt_val_len = (int)sizeof(int); - ret = 0; - } - break; - - case SDO_MTU: - { - ret = __sdo_get_dev_mtu(device, &int_out_value); - if(ret < 0){ - return ret; - } - if(*opt_val_len < (int)sizeof(int)){ - return -1; - } - memcpy(opt_val, &int_out_value, sizeof(int)); - *opt_val_len = (int)sizeof(int); - ret = 0; - } - break; - - default: - sapp_runtime_log(RLOG_LV_FATAL, "sapp_get_device_opt() error: opt_type:%d is invalid!\n", opt_type); - return -1; - } - - return ret; -} - -void sapp_fs2_update_count(int field_index, unsigned long long value) -{ - if(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle != NULL){ - FS_operate(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle, - sapp_global_val->individual_fixed.fs2_runtime.fs_id_count_array[field_index], - 0, FS_OP_SET, (long long)value); - } -} - -void sapp_fs2_update_length(int field_index, unsigned long long value) -{ - if(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle != NULL){ - FS_operate(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle, - sapp_global_val->individual_fixed.fs2_runtime.fs_id_length_array[field_index], - 0, FS_OP_SET, (long long)value); - } -} - - -void sapp_fs2_set_latency(int thead_seq, long long time_cost) -{ - if(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle != NULL){ - FS_operate(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle, - sapp_global_val->individual_fixed.fs2_runtime.fs_latency_id_array[thead_seq], - 0, FS_OP_SET, time_cost); - } -} - - -void sapp_fs2_set_plug_entry_latency(int entry_id, long long time_cost) -{ - if(unlikely(entry_id < 0 || entry_id >= SAPP_MAX_PLUG_ENTRY_NUM)){ - return; - } - if(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle != NULL){ - FS_operate(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle, - sapp_global_val->individual_fixed.fs2_runtime.fs_latency_plug_entrg_id_array[entry_id], - 0, FS_OP_SET, time_cost); - } -} - -/* - ģ�������������ʱ, ����ÿ����������һ��FS_operate(), - ��sapp timer�߳�ÿ��һ��ʱ�����sapp_fuzzy_latency_update(), ����filed_stat2����. -*/ -extern "C" void sapp_fs2_fuzzy_latency_update_per_thread(int thead_seq, long long time_cost) -{ - sapp_fuzzy_latency_stat_t *this_thread_stat = &sapp_global_val->mthread_volatile[thead_seq]->fuzzy_pkt_latency_stat_per_thread; - - if(time_cost < this_thread_stat->min_time_cost){ - this_thread_stat->min_time_cost = time_cost; - } - - if(time_cost > this_thread_stat->max_time_cost){ - this_thread_stat->max_time_cost = time_cost; - } - - this_thread_stat->time_cost_sum += time_cost; - this_thread_stat->stat_count++; -} - -extern "C" void sapp_fs2_fuzzy_latency_update_per_entry(int thead_seq, int entry_id, long long time_cost) -{ - sapp_fuzzy_latency_stat_t *this_thread_stat; - if(unlikely(entry_id < 0 || entry_id >= SAPP_MAX_PLUG_ENTRY_NUM)){ - return; - } - - this_thread_stat = &sapp_global_val->mthread_volatile[thead_seq]->fuzzy_pkt_latency_stat_per_entry_per_thread[entry_id]; - - if(time_cost < this_thread_stat->min_time_cost){ - this_thread_stat->min_time_cost = time_cost; - } - - if(time_cost > this_thread_stat->max_time_cost){ - this_thread_stat->max_time_cost = time_cost; - } - - this_thread_stat->time_cost_sum += time_cost; - this_thread_stat->stat_count++; - -} - - -/* - ��sapp timer�����̵߳���, ÿ��һ��ʱ��, �����۵İ�������ʱ����ˢ�¸�field_stat2. -*/ -void sapp_fuzzy_latency_update(void) -{ - int tid, entry_id, this_stat_count; - long long min_latency, max_latency; - double avg_latency; - sapp_fuzzy_latency_stat_t *this_thread_stat, *this_entry_stat; - - for(tid = 0; tid < g_packet_io_thread_num; tid++){ - this_thread_stat = &sapp_global_val->mthread_volatile[tid]->fuzzy_pkt_latency_stat_per_thread; - avg_latency = (double)this_thread_stat->time_cost_sum/(double)this_thread_stat->stat_count; - min_latency = this_thread_stat->min_time_cost; - max_latency = this_thread_stat->max_time_cost; - this_stat_count = this_thread_stat->stat_count; - - if(this_stat_count > 0){ - memset(this_thread_stat, 0, sizeof(sapp_fuzzy_latency_stat_t)); - this_thread_stat->min_time_cost = 999999999; /* Ҫ��¼��Сֵ, ��ʼ��Ҫ������ֵ */ - - /* ÿ�θ�������ֵ, ���,��С��ƽ��ֵ */ - sapp_fs2_set_latency(tid, min_latency); - sapp_fs2_set_latency(tid, max_latency); - sapp_fs2_set_latency(tid, (long long)avg_latency); - } - - for(entry_id = 1; entry_id < g_plug_global_entry_index; entry_id++){ - this_entry_stat = &sapp_global_val->mthread_volatile[tid]->fuzzy_pkt_latency_stat_per_entry_per_thread[entry_id]; - avg_latency = (double)this_entry_stat->time_cost_sum/(double)this_entry_stat->stat_count; - min_latency = this_entry_stat->min_time_cost; - max_latency = this_entry_stat->max_time_cost; - this_stat_count = this_entry_stat->stat_count; - if(this_stat_count > 0){ - memset(this_entry_stat, 0, sizeof(sapp_fuzzy_latency_stat_t)); - this_entry_stat->min_time_cost = 999999999; /* Ҫ��¼��Сֵ, ��ʼ��Ҫ������ֵ */ - - sapp_fs2_set_latency(tid, min_latency); - sapp_fs2_set_latency(tid, max_latency); - sapp_fs2_set_plug_entry_latency(entry_id, (long long)avg_latency); - } - } - } -} - - -int sapp_independent_thread_init(void) -{ - pthread_mutex_init(&g_plug_Independent_thread_mutex, NULL); - - if(sapp_global_val->config.cpu.send_only_threads_max_num > 0){ - g_plug_Independent_thread_pid = (pthread_t *)calloc(g_packet_io_thread_num + sapp_global_val->config.cpu.send_only_threads_max_num, sizeof(pthread_t)); - } - - return 0; -} - -int sapp_metric_init(void) -{ - int ret = 0; - if( sapp_global_val->config.profiling.fs2.enabled == 1) - { - sapp_fs2_init(sapp_global_val); - } - if( sapp_global_val->config.profiling.fs3.enabled == 1) - { - sapp_fs3_init(sapp_global_val); - } - - return ret; -} - - -static int fs2_plug_entry_historgram_init(sapp_gval_individual_fixed_fs_t *fs_rt) -{ - int i; - /* 0������sapp���ò��, index��1��ʼ */ - for(i = 1; i < g_plug_global_entry_index; i++){ - fs_rt->fs_latency_plug_entrg_id_array[i] = FS_register_histogram(fs_rt->fs_metric_handle, //Field Stat��� - FS_CALC_SPEED, //����ۼ�ֵ��˲ʱֵ - g_plug_global_entry[i].plug_entry_name, //ͳ�������ƣ��ַ��� - 1, //���ٵ���Сֵ - 1000000, //���ٵ����ֵ - 2); //���ȣ���С�����λ����Χ1~4 - if(fs_rt->fs_latency_plug_entrg_id_array[i] < 0){ - sapp_runtime_log(RLOG_LV_FATAL, "FS_register_histogram() error, plug name:%s", g_plug_global_entry[i].plug_entry_name); - return -1; - } - } - - return 0; -} - -void sapp_fs2_set_tcp_unorder_historgram(int thead_seq, long long unorder_num) -{ - if(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle != NULL){ - FS_operate(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle, - sapp_global_val->individual_fixed.fs2_runtime.fs_tcp_unorder_id_array[thead_seq], - 0, FS_OP_SET, unorder_num); - } -} - -static int fs2_tcp_unorder_historgram_init(sapp_gval_individual_fixed_fs_t *fs_rt) -{ - int i; - char histogram_name[16]; - /* 0������sapp���ò��, index��1��ʼ */ - for (i = 1; i < g_packet_io_thread_num; i++) - { - sprintf(histogram_name, "OoO_num(tid_%d)", i); - fs_rt->fs_tcp_unorder_id_array[i] = - FS_register_histogram(fs_rt->fs_metric_handle, // Field Stat��� - FS_CALC_SPEED, //����ۼ�ֵ��˲ʱֵ - histogram_name, //ͳ�������ƣ��ַ��� - 1, //���ٵ���Сֵ - 65536, //���ٵ����ֵ - 2); //���ȣ���С�����λ����Χ1~4 - if (fs_rt->fs_tcp_unorder_id_array[i] < 0) - { - sapp_runtime_log(RLOG_LV_FATAL, "FS_fs2_tcp_unorder_historgram_init() error, name:%s", - histogram_name); - return -1; - } - } - - return 0; -} - -/************************ C++ compiler **************************************/ -static int sapp_fs2_init(sapp_global_t *global_paramters) -{ - void *fs2_handle=NULL; - int fs2_opt; - sapp_gval_individual_fixed_fs_t *p_fs2_rt = &global_paramters->individual_fixed.fs2_runtime; - sapp_config_profiling_metric_t *p_fs2_para = &global_paramters->config.profiling.fs2; - int fs2_local_enabled = 0; - int fs2_prometheus_enabled = 0; - - if(strlen(p_fs2_para->local_file) > 0) - { - fs2_local_enabled = 1; - } - if(strlen(p_fs2_para->prometheus_service_uri) > 0 && p_fs2_para->prometheus_service_port > 0) - { - fs2_prometheus_enabled = 1; - } - - p_fs2_rt->fs_metric_handle = FS_create_handle(); - if(NULL == p_fs2_rt->fs_metric_handle){ - sapp_log(RLOG_LV_FATAL, 30, 30, "FS_create_handle() error: %s!\n", strerror(errno)); - return -1; - } - fs2_handle = p_fs2_rt->fs_metric_handle; - if(fs2_prometheus_enabled){ - FS_library_set_prometheus_port((unsigned short)p_fs2_para->prometheus_service_port); - FS_library_set_prometheus_url_path(p_fs2_para->prometheus_service_uri); - if(FS_library_init() < 0){ - sapp_log(RLOG_LV_FATAL, 30, 30, "FS_library_init() error, port:%d, url:%s\n", - p_fs2_para->prometheus_service_port, - p_fs2_para->prometheus_service_uri); - return -1; - } - fs2_opt = 1; - FS_set_para(fs2_handle, OUTPUT_PROMETHEUS, &fs2_opt, sizeof(int)); - } - - FS_set_para(fs2_handle, STAT_CYCLE, &p_fs2_para->refresh_interval_s, sizeof(int)); - - fs2_opt = 1; /* 1:Rewrite ,2: Append. */ - FS_set_para(fs2_handle, PRINT_MODE, &fs2_opt, sizeof(int)); - - fs2_opt = 1; - FS_set_para(fs2_handle, PRINT_TRIGGER, &fs2_opt, sizeof(int)); - - fs2_opt = 1; - FS_set_para(fs2_handle, NOT_SEND_METRIC_TO_SERVER, &fs2_opt, sizeof(int)); - - if(fs2_local_enabled){ - FS_set_para(fs2_handle, OUTPUT_DEVICE, ABBR_FS2_LOG_DATA_FILE, strlen(ABBR_FS2_LOG_DATA_FILE)+1); - }else{ - sapp_log(RLOG_LV_INFO, 10, 10, "profiling.log.local.enabled is 0, not save local stat log file.\n"); - FS_set_para(fs2_handle, OUTPUT_DEVICE, "/dev/null", strlen("/dev/null") + 1); - } - FS_set_para(fs2_handle, APP_NAME, sapp_global_val->config.system.instance_name, strlen(sapp_global_val->config.system.instance_name)+1); - - - p_fs2_rt->fs_id_count_array[SAPP_STAT_RCV_LINE] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Line_Pkt"); - p_fs2_rt->fs_id_length_array[SAPP_STAT_RCV_LINE] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Line_Bit"); - - p_fs2_rt->fs_id_count_array[SAPP_STAT_RCV_ETHERNET] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Eth_Pkt"); - p_fs2_rt->fs_id_length_array[SAPP_STAT_RCV_ETHERNET] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Eth_Bit"); - - if((DEPOLYMENT_MODE_INLINE == sapp_global_val->config.packet_io.depolyment_mode_bin) - || (DEPOLYMENT_MODE_TRANSPARENT == sapp_global_val->config.packet_io.depolyment_mode_bin)){ - p_fs2_rt->fs_id_count_array[SAPP_STAT_ETH_INBOUND] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Pkt_Inbound"); - p_fs2_rt->fs_id_length_array[SAPP_STAT_ETH_INBOUND] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Bit_Inbound"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_ETH_OUTBOUND] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Pkt_Outbound"); - p_fs2_rt->fs_id_length_array[SAPP_STAT_ETH_OUTBOUND] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Bit_Outbound"); - } - - p_fs2_rt->fs_id_count_array[SAPP_STAT_RCV_UNKNOWN] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Unknown_Pkt"); - p_fs2_rt->fs_id_length_array[SAPP_STAT_RCV_UNKNOWN] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Unknown_Bit"); - - p_fs2_rt->fs_id_count_array[SAPP_STAT_SND_ERROR] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Snd_Err_Pkt"); - //pfs_para->fs_id_length_array[SAPP_STAT_SND_ERROR] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Snd_Err_Bit"); - - p_fs2_rt->fs_id_count_array[SAPP_STAT_RCV_IPV4] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Ipv4_Pkt"); - p_fs2_rt->fs_id_length_array[SAPP_STAT_RCV_IPV4] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Ipv4_Bit"); - - p_fs2_rt->fs_id_count_array[SAPP_STAT_RCV_IPV6] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Ipv6_Pkt"); - p_fs2_rt->fs_id_length_array[SAPP_STAT_RCV_IPV6] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Ipv6_Bit"); - - p_fs2_rt->fs_id_count_array[SAPP_STAT_RCV_TCP] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Pkt"); - p_fs2_rt->fs_id_length_array[SAPP_STAT_RCV_TCP] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Bit"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_RCV_DUP_TCP] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Dup_Tcp_Pkt"); - p_fs2_rt->fs_id_length_array[SAPP_STAT_RCV_DUP_TCP] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Dup_Tcp_Bit"); - p_fs2_rt->fs_id_length_array[SAPP_STAT_TCP_LOST_PKT] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Lost_Bit"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_LOST_PKT_STREAM_NUM] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Lost_STM"); - - p_fs2_rt->fs_id_count_array[SAPP_STAT_DUP_IDENTIFY_ERR] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Dup_Key_Err"); /* dup�ظ���ʶ������key������� */ - - p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_CLOSE_BY_TIMEOUT] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Close_byT"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_CLOSE_BY_KICKOUT] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Close_byK"); - - p_fs2_rt->fs_id_count_array[SAPP_STAT_RCV_UDP] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Pkt"); - p_fs2_rt->fs_id_length_array[SAPP_STAT_RCV_UDP] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Bit"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_RCV_DUP_UDP] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Dup_Udp_Pkt"); - p_fs2_rt->fs_id_length_array[SAPP_STAT_RCV_DUP_UDP] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Dup_Udp_Bit"); - - p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_CLOSE_BY_TIMEOUT] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Close_byT"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_CLOSE_BY_KICKOUT] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Close_byK"); - - p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_STREAM_NEW] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Link_New"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_STREAM_DEL] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Link_Del"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_STREAM_DATA] = FS_register(fs2_handle, FS_STYLE_STATUS, FS_CALC_CURRENT, "Tcp_Concurrent"); - - p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_STREAM_NEW] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Link_New"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_STREAM_DEL] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Link_Del"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_STREAM_MORE] = FS_register(fs2_handle, FS_STYLE_STATUS, FS_CALC_CURRENT, "Udp_Concurrent"); - - - p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_STREAM_DOUBLE] = FS_register(fs2_handle, FS_STYLE_STATUS,FS_CALC_CURRENT, "Tcp_Link_Double"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_STREAM_C2S] = FS_register(fs2_handle,FS_STYLE_STATUS, FS_CALC_CURRENT, "Tcp_Link_C2S"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_STREAM_S2C] = FS_register(fs2_handle,FS_STYLE_STATUS, FS_CALC_CURRENT, "Tcp_Link_S2C"); - - p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_STREAM_TOTAL_DOUBLE] = FS_register(fs2_handle, FS_STYLE_STATUS,FS_CALC_CURRENT, "Tcp_Link_Double_ALL"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_STREAM_TOTAL_C2S] = FS_register(fs2_handle,FS_STYLE_STATUS, FS_CALC_CURRENT, "Tcp_Link_C2S_ALL"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_STREAM_TOTAL_S2C] = FS_register(fs2_handle,FS_STYLE_STATUS, FS_CALC_CURRENT, "Tcp_Link_S2C_ALL"); - - - p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_STREAM_DOUBLE] = FS_register(fs2_handle, FS_STYLE_STATUS,FS_CALC_CURRENT, "Udp_Link_Double"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_STREAM_C2S] = FS_register(fs2_handle,FS_STYLE_STATUS, FS_CALC_CURRENT, "Udp_Link_C2S"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_STREAM_S2C] = FS_register(fs2_handle,FS_STYLE_STATUS, FS_CALC_CURRENT, "Udp_Link_S2C"); - - p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_STREAM_TOTAL_DOUBLE] = FS_register(fs2_handle, FS_STYLE_STATUS,FS_CALC_CURRENT, "Udp_Link_Double_ALL"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_STREAM_TOTAL_C2S] = FS_register(fs2_handle,FS_STYLE_STATUS, FS_CALC_CURRENT, "Udp_Link_C2S_ALL"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_STREAM_TOTAL_S2C] = FS_register(fs2_handle,FS_STYLE_STATUS, FS_CALC_CURRENT, "Udp_Link_S2C_ALL"); - - - p_fs2_rt->fs_id_count_array[SAPP_STAT_SND_TCP_RST] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Send_Tcp_Rst"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_SND_TCP_SYNACK] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Send_Tcp_S/A"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_SND_UDP] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Send_Udp"); - - p_fs2_rt->fs_id_count_array[SAPP_STAT_GLOBAL_BYPASS] = FS_register(fs2_handle,FS_STYLE_STATUS, FS_CALC_CURRENT, "DDOS_Bypass"); - - p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_BYPASS_STREAM] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Bypass_STM"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_BYPASS_PKTS] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Bypass_Pkt"); - p_fs2_rt->fs_id_length_array[SAPP_STAT_TCP_BYPASS_BYTES] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Bypass_Bit"); - - p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_BYPASS_STREAM] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Bypass_STM"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_BYPASS_PKTS] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Bypass_Pkt"); - p_fs2_rt->fs_id_length_array[SAPP_STAT_UDP_BYPASS_BYTES] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Bypass_Bit"); - - p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_OFFLOAD_STREAM] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Offload_STM"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_OFFLOAD_PKTS] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Offload_Pkt"); - p_fs2_rt->fs_id_length_array[SAPP_STAT_TCP_OFFLOAD_BYTES] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Offload_Bit"); - - p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_OFFLOAD_STREAM] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Offload_STM"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_OFFLOAD_PKTS] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Offload_Pkt"); - p_fs2_rt->fs_id_length_array[SAPP_STAT_UDP_OFFLOAD_BYTES] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Offload_Bit"); - - if (unlikely(g_timestamp_record_sw)) - { - if (fs2_tcp_unorder_historgram_init(p_fs2_rt) < 0) - { - return -1; - } - for (int i = 0; i < g_packet_io_thread_num; i++) - { - char histogram_name[16]; - sprintf(histogram_name, "TD_ns(tid_%d)", i); - p_fs2_rt->fs_latency_id_array[i] = FS_register_histogram(fs2_handle, // Field Stat��� - FS_CALC_SPEED, //����ۼ�ֵ��˲ʱֵ - histogram_name, //ͳ�������ƣ��ַ��� - 1, //���ٵ���Сֵ - 1000000, //���ٵ����ֵ - 2); //���ȣ���С�����λ����Χ1~4 - FS_set_para(fs2_handle, NOT_SEND_METRIC_TO_SERVER, &p_fs2_rt->fs_latency_id_array[i], sizeof(int)); - } - - if (fs2_plug_entry_historgram_init(p_fs2_rt) < 0) - { - return -1; - } - } - FS_start(fs2_handle); - - return 0; -} - -static void sapp_fs2_destroy(sapp_global_t *global_paramters) -{ - sapp_config_profiling_metric_t *p_fs2_para = &global_paramters->config.profiling.fs2; - sapp_gval_individual_fixed_fs_t *p_fs2_rt = &global_paramters->individual_fixed.fs2_runtime; - if (strlen(p_fs2_para->prometheus_service_uri) > 0 && p_fs2_para->prometheus_service_port > 0) - { - FS_library_destroy(); - } - - if (p_fs2_rt->fs_metric_handle) - { - FS_stop(&p_fs2_rt->fs_metric_handle); - } -} - -static int sapp_fs3_init(sapp_global_t *global_paramters) -{ - sapp_config_profiling_metric_t *p_fs3_para = &global_paramters->config.profiling.fs3; - sapp_gval_individual_fixed_fs_t *p_fs3_rt = &global_paramters->individual_fixed.fs3_runtime; - return 0; -} - -static void sapp_fs3_destroy(sapp_global_t *global_paramters) -{ - return; -} - -void sapp_metric_destroy(void) -{ - - if( sapp_global_val->config.profiling.fs2.enabled == 1) - { - sapp_fs2_destroy(sapp_global_val); - } - if( sapp_global_val->config.profiling.fs3.enabled == 1) - { - sapp_fs3_destroy(sapp_global_val); - } -} - - |
