summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlijie <[email protected]>2018-11-28 16:26:43 +0800
committerlijie <[email protected]>2018-11-28 16:26:43 +0800
commit8abbfe5a10fdcca9e6b33beb1d3fad0bfc53c24c (patch)
tree8570068ed4d72860f3b4f039e65a9753f14341ba
parentde9b2d4ff40d5874de7d8fc7fe3a8e46b99f99d9 (diff)
添加统计功能,统计分配和释放的内存数以及接收和发送的数据包数目
-rw-r--r--src/Makefile4
-rw-r--r--src/mrl_main.c165
-rw-r--r--src/mrl_packet.c37
-rw-r--r--src/mrl_redis.c52
-rw-r--r--src/mrl_stat.c82
5 files changed, 245 insertions, 95 deletions
diff --git a/src/Makefile b/src/Makefile
index b9cb678..5637f24 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -18,11 +18,11 @@ LIBS = -L /opt/MESA/lib
#LIBS = -L ../support/lib
-LIBS += -lMESA_prof_load -lMESA_handle_logger -lpthread -lmaatframe -lMESA_htable -lmaxminddb
+LIBS += -lMESA_prof_load -lMESA_handle_logger -lpthread -lmaatframe -lMESA_htable -lMESA_field_stat2 -lmaxminddb
TARGET = mrl.so
-OBJS = mrl_main.o mrl_utils.o mrl_packet.o mrl_redis.o
+OBJS = mrl_main.o mrl_utils.o mrl_packet.o mrl_redis.o mrl_stat.o
.PHONY: all clean install
diff --git a/src/mrl_main.c b/src/mrl_main.c
index 99f8001..9296ee0 100644
--- a/src/mrl_main.c
+++ b/src/mrl_main.c
@@ -7,10 +7,10 @@
#include "mrl_main.h"
#include "mrl_redis.h"
#include "mrl_packet.h"
-
+#include "mrl_stat.h"
struct mrl_global_instance mrl_instance;
-
+extern struct global_stat_t global_stat;
void mrl_cfg_init(const char *profile)
{
char *temp_mac_str;
@@ -74,45 +74,71 @@ void mrl_cfg_init(const char *profile)
MESA_load_profile_uint_def(profile, "VXLAN_INFO", "vxlan_gdev_num", &(mrl_instance.mrl_cfg.vxlan_gdev_num), 1);
temp_mac_str = (char *)calloc(mrl_instance.mrl_cfg.vxlan_gdev_num * MRL_STR_MAC_LEN,sizeof(char));
+ global_stat.malloc_memory += mrl_instance.mrl_cfg.vxlan_gdev_num * MRL_STR_MAC_LEN;
+
temp_ip_str = (char *)calloc(mrl_instance.mrl_cfg.vxlan_gdev_num * MRL_STR_IP_LEN,sizeof(char));
+ global_stat.malloc_memory += mrl_instance.mrl_cfg.vxlan_gdev_num * MRL_STR_IP_LEN;
+
temp_port_str = (char *)calloc(mrl_instance.mrl_cfg.vxlan_gdev_num * MRL_STR_PORT_LEN, sizeof(char));
+ global_stat.malloc_memory += mrl_instance.mrl_cfg.vxlan_gdev_num * MRL_STR_PORT_LEN;
+
temp_encap_type_str = (char *)calloc(mrl_instance.mrl_cfg.vxlan_gdev_num * MRL_STR_ENCAP_TYPE_LEN,sizeof(char));
+ global_stat.malloc_memory += mrl_instance.mrl_cfg.vxlan_gdev_num * MRL_STR_ENCAP_TYPE_LEN;
+
temp_vpn_id_str = (char *)calloc(mrl_instance.mrl_cfg.vxlan_gdev_num * MRL_STR_VPN_ID_LEN,sizeof(char));
+ global_stat.malloc_memory += mrl_instance.mrl_cfg.vxlan_gdev_num * MRL_STR_VPN_ID_LEN;
+
temp_link_id_str = (char *)calloc(mrl_instance.mrl_cfg.vxlan_gdev_num * MRL_STR_LINK_ID_LEN,sizeof(char));
+ global_stat.malloc_memory += mrl_instance.mrl_cfg.vxlan_gdev_num * MRL_STR_LINK_ID_LEN;
+
temp_link_dir_str = (char *)calloc(mrl_instance.mrl_cfg.vxlan_gdev_num * MRL_STR_LINK_DIR_LEN, sizeof(char));
+ global_stat.malloc_memory += mrl_instance.mrl_cfg.vxlan_gdev_num * MRL_STR_LINK_DIR_LEN;
MESA_load_profile_string_def(profile, "VXLAN_INFO", "vxlan_gdev_mac",temp_mac_str, mrl_instance.mrl_cfg.vxlan_gdev_num*MRL_STR_MAC_LEN, "00:00:00:00:00:00");
mrl_instance.mrl_cfg.vxlan_outer_gdev_mac = (char **)malloc(sizeof(char *)*mrl_instance.mrl_cfg.vxlan_gdev_num);
+ global_stat.malloc_memory += mrl_instance.mrl_cfg.vxlan_gdev_num * sizeof(char *);
+
for(i=0;i<mrl_instance.mrl_cfg.vxlan_gdev_num;i++)
{
mrl_instance.mrl_cfg.vxlan_outer_gdev_mac[i] = (char *)malloc(sizeof(char)*MRL_STR_MAC_LEN);
+ global_stat.malloc_memory += sizeof(char)*MRL_STR_MAC_LEN;
+
}
split_num = mrl_split_str(temp_mac_str,",",mrl_instance.mrl_cfg.vxlan_outer_gdev_mac);
assert(split_num == mrl_instance.mrl_cfg.vxlan_gdev_num);
MESA_load_profile_string_def(profile, "VXLAN_INFO", "vxlan_gdev_ip",temp_ip_str, mrl_instance.mrl_cfg.vxlan_gdev_num*MRL_STR_IP_LEN, "0.0.0.0");
mrl_instance.mrl_cfg.vxlan_outer_gdev_ip = (char **)malloc(sizeof(char *)*mrl_instance.mrl_cfg.vxlan_gdev_num);
+ global_stat.malloc_memory +=mrl_instance.mrl_cfg.vxlan_gdev_num * sizeof(char *);
+
for(i=0;i<mrl_instance.mrl_cfg.vxlan_gdev_num;i++)
{
mrl_instance.mrl_cfg.vxlan_outer_gdev_ip[i] = (char *)malloc(sizeof(char)*MRL_STR_IP_LEN);
+ global_stat.malloc_memory += sizeof(char)*MRL_STR_IP_LEN;
}
split_num = mrl_split_str(temp_ip_str,",",mrl_instance.mrl_cfg.vxlan_outer_gdev_ip);
assert(split_num == mrl_instance.mrl_cfg.vxlan_gdev_num);
MESA_load_profile_string_def(profile, "VXLAN_INFO", "vxlan_gdev_port",temp_port_str, mrl_instance.mrl_cfg.vxlan_gdev_num*MRL_STR_PORT_LEN, "8888");
mrl_instance.mrl_cfg.vxlan_outer_gdev_port = (char **)malloc(sizeof(char *)*mrl_instance.mrl_cfg.vxlan_gdev_num);
+ global_stat.malloc_memory +=mrl_instance.mrl_cfg.vxlan_gdev_num * sizeof(char *);
+
for(i=0;i<mrl_instance.mrl_cfg.vxlan_gdev_num;i++)
{
mrl_instance.mrl_cfg.vxlan_outer_gdev_port[i] = (char *)malloc(sizeof(char)*MRL_STR_PORT_LEN);
+ global_stat.malloc_memory += sizeof(char)*MRL_STR_PORT_LEN;
}
split_num = mrl_split_str(temp_port_str,",",mrl_instance.mrl_cfg.vxlan_outer_gdev_port);
assert(split_num == mrl_instance.mrl_cfg.vxlan_gdev_num);
MESA_load_profile_string_def(profile, "VXLAN_INFO", "vxlan_encap_type",temp_encap_type_str, mrl_instance.mrl_cfg.vxlan_gdev_num*MRL_STR_ENCAP_TYPE_LEN, "0000");
mrl_instance.mrl_cfg.vxlan_encap_type = (char **)malloc(sizeof(char *)*mrl_instance.mrl_cfg.vxlan_gdev_num);
+ global_stat.malloc_memory +=mrl_instance.mrl_cfg.vxlan_gdev_num * sizeof(char *);
+
for(i=0;i<mrl_instance.mrl_cfg.vxlan_gdev_num;i++)
{
mrl_instance.mrl_cfg.vxlan_encap_type[i] = (char *)malloc(sizeof(char)*MRL_STR_ENCAP_TYPE_LEN);
+ global_stat.malloc_memory += sizeof(char)*MRL_STR_ENCAP_TYPE_LEN;
}
split_num = mrl_split_str(temp_encap_type_str,",",mrl_instance.mrl_cfg.vxlan_encap_type);
assert(split_num == mrl_instance.mrl_cfg.vxlan_gdev_num);
@@ -120,9 +146,12 @@ void mrl_cfg_init(const char *profile)
MESA_load_profile_string_def(profile, "VXLAN_INFO", "vxlan_vpn_id",temp_vpn_id_str, mrl_instance.mrl_cfg.vxlan_gdev_num*MRL_STR_VPN_ID_LEN, "0000");
mrl_instance.mrl_cfg.vxlan_vpn_id = (char **)malloc(sizeof(char *)*mrl_instance.mrl_cfg.vxlan_gdev_num);
+ global_stat.malloc_memory +=mrl_instance.mrl_cfg.vxlan_gdev_num * sizeof(char *);
+
for(i=0;i<mrl_instance.mrl_cfg.vxlan_gdev_num;i++)
{
mrl_instance.mrl_cfg.vxlan_vpn_id[i] = (char *)malloc(sizeof(char)*MRL_STR_VPN_ID_LEN);
+ global_stat.malloc_memory += sizeof(char)*MRL_STR_VPN_ID_LEN;
}
split_num = mrl_split_str(temp_vpn_id_str,",",mrl_instance.mrl_cfg.vxlan_vpn_id);
assert(split_num == mrl_instance.mrl_cfg.vxlan_gdev_num);
@@ -130,36 +159,48 @@ void mrl_cfg_init(const char *profile)
MESA_load_profile_string_def(profile, "VXLAN_INFO", "vxlan_link_id",temp_link_id_str, mrl_instance.mrl_cfg.vxlan_gdev_num*MRL_STR_LINK_ID_LEN, "0");
mrl_instance.mrl_cfg.vxlan_link_id= (char **)malloc(sizeof(char *)*mrl_instance.mrl_cfg.vxlan_gdev_num);
+ global_stat.malloc_memory += mrl_instance.mrl_cfg.vxlan_gdev_num * sizeof(char *);
+
for(i=0;i<mrl_instance.mrl_cfg.vxlan_gdev_num;i++)
{
mrl_instance.mrl_cfg.vxlan_link_id[i] = (char *)malloc(sizeof(char)*MRL_STR_LINK_ID_LEN);
+ global_stat.malloc_memory += sizeof(char)*MRL_STR_LINK_ID_LEN;
}
split_num = mrl_split_str(temp_link_id_str,",",mrl_instance.mrl_cfg.vxlan_link_id);
assert(split_num == mrl_instance.mrl_cfg.vxlan_gdev_num);
MESA_load_profile_string_def(profile, "VXLAN_INFO", "vxlan_link_dir",temp_link_dir_str, mrl_instance.mrl_cfg.vxlan_gdev_num*MRL_STR_LINK_DIR_LEN, "0");
mrl_instance.mrl_cfg.vxlan_link_dir= (char **)malloc(sizeof(char *)*mrl_instance.mrl_cfg.vxlan_gdev_num);
+ global_stat.malloc_memory += mrl_instance.mrl_cfg.vxlan_gdev_num * sizeof(char *);
+
for(i=0;i<mrl_instance.mrl_cfg.vxlan_gdev_num;i++)
{
mrl_instance.mrl_cfg.vxlan_link_dir[i] = (char *)malloc(sizeof(char)*MRL_STR_LINK_DIR_LEN);
+ global_stat.malloc_memory += sizeof(char)*MRL_STR_LINK_DIR_LEN;
}
split_num = mrl_split_str(temp_link_dir_str,",",mrl_instance.mrl_cfg.vxlan_link_dir);
assert(split_num == mrl_instance.mrl_cfg.vxlan_gdev_num);
MESA_load_profile_string_def(profile, "VXLAN_INFO", "vxlan_inner_smac",temp_mac_str, mrl_instance.mrl_cfg.vxlan_gdev_num*MRL_STR_MAC_LEN, "00:00:00:00:00:00");
mrl_instance.mrl_cfg.vxlan_inner_smac = (char **)malloc(sizeof(char *)*mrl_instance.mrl_cfg.vxlan_gdev_num);
+ global_stat.malloc_memory +=mrl_instance.mrl_cfg.vxlan_gdev_num * sizeof(char *);
+
for(i=0;i<mrl_instance.mrl_cfg.vxlan_gdev_num;i++)
{
mrl_instance.mrl_cfg.vxlan_inner_smac[i] = (char *)malloc(sizeof(char)*MRL_STR_MAC_LEN);
+ global_stat.malloc_memory += sizeof(char)*MRL_STR_MAC_LEN;
}
split_num = mrl_split_str(temp_mac_str,",",mrl_instance.mrl_cfg.vxlan_inner_smac);
assert(split_num == mrl_instance.mrl_cfg.vxlan_gdev_num);
MESA_load_profile_string_def(profile, "VXLAN_INFO", "vxlan_inner_dmac",temp_mac_str, mrl_instance.mrl_cfg.vxlan_gdev_num*MRL_STR_MAC_LEN, "00:00:00:00:00:00");
mrl_instance.mrl_cfg.vxlan_inner_dmac = (char **)malloc(sizeof(char *)*mrl_instance.mrl_cfg.vxlan_gdev_num);
+ global_stat.malloc_memory +=mrl_instance.mrl_cfg.vxlan_gdev_num * sizeof(char *);
+
for(i=0;i<mrl_instance.mrl_cfg.vxlan_gdev_num;i++)
{
mrl_instance.mrl_cfg.vxlan_inner_dmac[i] = (char *)malloc(sizeof(char)*MRL_STR_MAC_LEN);
+ global_stat.malloc_memory += sizeof(char)*MRL_STR_MAC_LEN;
}
split_num = mrl_split_str(temp_mac_str,",",mrl_instance.mrl_cfg.vxlan_inner_dmac);
assert(split_num == mrl_instance.mrl_cfg.vxlan_gdev_num);
@@ -167,41 +208,37 @@ void mrl_cfg_init(const char *profile)
MESA_load_profile_string_def(profile, "VXLAN_INFO", "vxlan_local_mac", mrl_instance.mrl_cfg.vxlan_outer_local_mac, MRL_STR_MAC_LEN, "00:00:00:00:00:00");
MESA_load_profile_string_def(profile, "VXLAN_INFO", "vxlan_local_ip", mrl_instance.mrl_cfg.vxlan_outer_local_ip, MRL_STR_IP_LEN, "0.0.0.0");
MESA_load_profile_string_def(profile, "VXLAN_INFO", "vxlan_local_port", mrl_instance.mrl_cfg.xvlan_outer_local_port,MRL_STR_PORT_LEN, "8888");
-/*
- MESA_load_profile_string_def(profile, "VXLAN_INFO", "vxlan_inner_ip",mrl_instance.mrl_cfg.vxlan_inner_dip, MRL_STR_IP_LEN, "0.0.0.0");
- MESA_load_profile_string_def(profile, "VXLAN_INFO", "vxlan_inner_sport", mrl_instance.mrl_cfg.vxlan_inner_sport,MRL_STR_PORT_LEN, "8888");
- MESA_load_profile_string_def(profile, "VXLAN_INFO", "vxlan_inner_dport", mrl_instance.mrl_cfg.vxlan_inner_dport,MRL_STR_PORT_LEN, "8888");
-*/
+
free(temp_mac_str);
+ global_stat.free_memory += mrl_instance.mrl_cfg.vxlan_gdev_num * MRL_STR_MAC_LEN;
+
free(temp_ip_str);
+ global_stat.free_memory += mrl_instance.mrl_cfg.vxlan_gdev_num * MRL_STR_IP_LEN;
+
free(temp_port_str);
+ global_stat.free_memory += mrl_instance.mrl_cfg.vxlan_gdev_num * MRL_STR_PORT_LEN;
+
free(temp_encap_type_str);
+ global_stat.free_memory += mrl_instance.mrl_cfg.vxlan_gdev_num * MRL_STR_ENCAP_TYPE_LEN;
+
free(temp_link_id_str);
+ global_stat.free_memory += mrl_instance.mrl_cfg.vxlan_gdev_num * MRL_STR_LINK_ID_LEN;
+
free(temp_link_dir_str);
+ global_stat.free_memory += mrl_instance.mrl_cfg.vxlan_gdev_num * MRL_STR_LINK_DIR_LEN;
}
-/*
-void mrl_nominee_test_init()
-{
- printf("mrl moninee_test init\n");
- char src_ip[]="192.168.11.60";
- const char date[]="2018/11/15/11:01:11";
- struct mrl_nominee_item nominee_item;
- memset(&nominee_item,0,sizeof(nominee_item));
- nominee_item.config_id =(int)Maat_cmd_incrby(mrl_instance.nominee_feather,"TEST_PLUG_SEQ", 1);
- nominee_item.group_id =1;
- nominee_item.addr_type =4;
- memcpy(nominee_item.ip_addr,src_ip,strlen(src_ip));
- nominee_item.is_vaild = 1;
- memcpy(nominee_item.op_time,date,strlen(date));
- Maat_set_nominee_cmd_line(mrl_instance.nominee_feather, &nominee_item);
-}*/
+
void candidate_update_cb(int table_id,const char* table_line,void* u_para)
{
}
extern "C" int mrl_init(void)
{
+ int ret = 0;
mrl_instance.stop_flag = 0;
+
+ mrl_stat_init();
+
mrl_cfg_init("./mrl_conf/mrl.conf");
mrl_instance.mrl_log_handle = MESA_create_runtime_log_handle(mrl_instance.mrl_cfg.mrl_log_path, mrl_instance.mrl_cfg.mrl_log_level);
@@ -232,20 +269,30 @@ extern "C" int mrl_init(void)
//mrl_nominee_test_init();
//���������߳̽��ղ�����mwg���͵����ݰ�
- pthread_t recv_pid, detect_pid;
- if(pthread_create(&recv_pid,NULL,mrl_recv_mgw_action,NULL) <0)
+ pthread_t recv_pid, detect_pid, stat_pid;
+ ret = pthread_create(&recv_pid,NULL,mrl_recv_mgw_action,NULL);
+ if( ret < 0)
{
- MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_FATAL,"mrl_init","pthread_create func error!");
+ MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_FATAL,"mrl_init","recv pthread create error,error is %d",ret);
assert(0);
}
pthread_detach(recv_pid);
- if(pthread_create(&detect_pid,NULL,mrl_detect_ip_action,NULL) <0)
+ ret = pthread_create(&detect_pid,NULL,mrl_detect_ip_action,NULL);
+ if( ret < 0)
{
- MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_FATAL,"mrl_init","pthread_create func error!");
+ MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_FATAL,"mrl_init","detect pthread create error,error is %d",ret);
assert(0);
}
pthread_detach(detect_pid);
+
+ ret = pthread_create(&stat_pid,NULL,mrl_stat_action,NULL);
+ if( ret < 0)
+ {
+ MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_FATAL,"mrl_init","stat pthread create error,error is %d",ret);
+ assert(0);
+ }
+ pthread_detach(stat_pid);
return 1;
}
@@ -255,28 +302,59 @@ void mrl_destroy_cfg()
for(i = 0; i<mrl_instance.mrl_cfg.vxlan_gdev_num;i++)
{
free(mrl_instance.mrl_cfg.vxlan_outer_gdev_mac[i]);
+ global_stat.free_memory += sizeof(char)*MRL_STR_MAC_LEN;
+
free(mrl_instance.mrl_cfg.vxlan_outer_gdev_ip[i]);
+ global_stat.free_memory += sizeof(char)*MRL_STR_IP_LEN;
+
free(mrl_instance.mrl_cfg.vxlan_outer_gdev_port[i]);
+ global_stat.free_memory += sizeof(char)*MRL_STR_PORT_LEN;
+
free(mrl_instance.mrl_cfg.vxlan_encap_type[i]);
+ global_stat.free_memory += sizeof(char)*MRL_STR_ENCAP_TYPE_LEN;
+
free(mrl_instance.mrl_cfg.vxlan_link_id[i]);
+ global_stat.free_memory += sizeof(char)*MRL_STR_LINK_ID_LEN;
+
free(mrl_instance.mrl_cfg.vxlan_link_dir[i]);
+ global_stat.free_memory += sizeof(char)*MRL_STR_LINK_DIR_LEN;
+
free(mrl_instance.mrl_cfg.vxlan_inner_smac[i]);
+ global_stat.free_memory += sizeof(char)*MRL_STR_MAC_LEN;
+
free(mrl_instance.mrl_cfg.vxlan_inner_dmac[i]);
+ global_stat.free_memory += sizeof(char)*MRL_STR_MAC_LEN;
}
+
free(mrl_instance.mrl_cfg.vxlan_outer_gdev_mac);
+ global_stat.free_memory += mrl_instance.mrl_cfg.vxlan_gdev_num * sizeof(char *);
+
free(mrl_instance.mrl_cfg.vxlan_outer_gdev_ip);
+ global_stat.free_memory += mrl_instance.mrl_cfg.vxlan_gdev_num * sizeof(char *);
+
free(mrl_instance.mrl_cfg.vxlan_outer_gdev_port);
+ global_stat.free_memory += mrl_instance.mrl_cfg.vxlan_gdev_num * sizeof(char *);
+
free(mrl_instance.mrl_cfg.vxlan_encap_type);
+ global_stat.free_memory += mrl_instance.mrl_cfg.vxlan_gdev_num * sizeof(char *);
+
free(mrl_instance.mrl_cfg.vxlan_link_id);
+ global_stat.free_memory += mrl_instance.mrl_cfg.vxlan_gdev_num * sizeof(char *);
+
free(mrl_instance.mrl_cfg.vxlan_link_dir);
+ global_stat.free_memory += mrl_instance.mrl_cfg.vxlan_gdev_num * sizeof(char *);
+
free(mrl_instance.mrl_cfg.vxlan_inner_smac);
+ global_stat.free_memory += mrl_instance.mrl_cfg.vxlan_gdev_num * sizeof(char *);
+
free(mrl_instance.mrl_cfg.vxlan_inner_dmac);
+ global_stat.free_memory += mrl_instance.mrl_cfg.vxlan_gdev_num * sizeof(char *);
}
extern "C" void mrl_destroy(void)
{
-
+ MESA_htable_destroy(mrl_instance.ht_nominee,ht_nominee_free_cb);
MESA_lqueue_destroy(mrl_instance.mrl_queue,NULL,NULL);
Maat_burn_feather(mrl_instance.candidate_feather);
Maat_burn_feather(mrl_instance.nominee_feather);
@@ -288,13 +366,16 @@ extern "C" void mrl_destroy(void)
extern "C" char mrl_tcpall_entry(struct streaminfo *a_tcp,void **pme, int thread_seq, void *raw_packet)
{
+ global_stat.recv_gdev_total_pkts ++;
+ global_stat.recv_gdev_tcp_pkts ++;
char ret = APP_STATE_GIVEME;
switch(a_tcp->pktstate){
case OP_STATE_PENDING:
if(mrl_pkt_signature_identify(a_tcp))
{
- mrl_send_to_mgw(raw_packet, thread_seq);
- ret = APP_STATE_GIVEME;//��ָ��faw��drop���ȡ�ĸ�������
+ global_stat.recv_ir_pkts ++;
+ mrl_send_to_mgw(raw_packet, thread_seq);
+ ret = APP_STATE_GIVEME;//��ָ��faw��drop���ȡ�ĸ�������
}
else
{
@@ -304,12 +385,17 @@ extern "C" char mrl_tcpall_entry(struct streaminfo *a_tcp,void **pme, int thread
break;
case OP_STATE_DATA:
+ global_stat.recv_ir_pkts ++;
mrl_send_to_mgw(raw_packet, thread_seq);
ret = APP_STATE_GIVEME;
break;
case OP_STATE_CLOSE:
- mrl_send_to_mgw(raw_packet, thread_seq);
+ if(raw_packet != NULL)
+ {
+ global_stat.recv_ir_pkts ++;
+ mrl_send_to_mgw(raw_packet, thread_seq);
+ }
ret = APP_STATE_DROPME;
break;
@@ -323,27 +409,36 @@ extern "C" char mrl_tcpall_entry(struct streaminfo *a_tcp,void **pme, int thread
extern "C" char mrl_udp_entry(struct streaminfo *a_udp, void **pme, int thread_seq, void *raw_packet)
{
- char ret = APP_STATE_GIVEME;
+ global_stat.recv_gdev_total_pkts ++;
+ global_stat.recv_gdev_udp_pkts ++;
+
+ char ret = APP_STATE_GIVEME;
switch(a_udp->pktstate){
case OP_STATE_PENDING:
if(mrl_pkt_signature_identify(a_udp))
{
+ global_stat.recv_ir_pkts ++;
mrl_send_to_mgw(raw_packet, thread_seq);
ret = APP_STATE_GIVEME;
}
else
{
mrl_identify_nominee(a_udp);
- ret =APP_STATE_DROPME;
+ ret =APP_STATE_DROPME|APP_STATE_FAWPKT;
}
break;
case OP_STATE_DATA:
+ global_stat.recv_ir_pkts ++;
mrl_send_to_mgw(raw_packet, thread_seq);
ret = APP_STATE_GIVEME;
break;
case OP_STATE_CLOSE:
- mrl_send_to_mgw(raw_packet, thread_seq);
+ if(raw_packet != NULL)
+ {
+ global_stat.recv_ir_pkts ++;
+ mrl_send_to_mgw(raw_packet, thread_seq);
+ }
ret = APP_STATE_DROPME;
break;
diff --git a/src/mrl_packet.c b/src/mrl_packet.c
index 575ebb5..e4b3b26 100644
--- a/src/mrl_packet.c
+++ b/src/mrl_packet.c
@@ -12,7 +12,9 @@
#include "mrl_main.h"
#include "mrl_utils.h"
#include "mrl_redis.h"
+#include "mrl_stat.h"
+extern struct global_stat_t global_stat;
extern struct mrl_global_instance mrl_instance;
extern void mrl_get_vxlan_info(struct mrl_vxlan_info *vxlan, unsigned int index);
@@ -26,6 +28,8 @@ void mrl_socket_init()
sapp_get_platform_opt(SPO_THREAD_COUNT,(void *) &thread_num, &len);
printf("sapp thread num is %d\n",thread_num);
mrl_instance.mrl_snd_fd = (int *) malloc (sizeof(int)*thread_num);
+ global_stat.malloc_memory += sizeof(int)*thread_num;
+
for(i = 0; i< thread_num;i++)
{
mrl_instance.mrl_snd_fd[i] = socket(AF_INET, SOCK_DGRAM, 0);
@@ -56,8 +60,11 @@ void mrl_socket_close()
printf("sapp thread num is %d\n",thread_num);
for(i = 0; i< thread_num;i++)
{
- close(mrl_instance.mrl_snd_fd[i]);
+ close(mrl_instance.mrl_snd_fd[i]);
}
+
+ free(mrl_instance.mrl_snd_fd);
+ global_stat.free_memory += sizeof(int)*thread_num;
close(mrl_instance.mrl_rcv_fd);
}
@@ -239,7 +246,6 @@ void mrl_send_to_gdev(int thread_seq, struct mrl_vxlan_info * vxlan_info, const
//�ж��Ƿ���IP���ð�
bool mrl_pkt_signature_identify(struct streaminfo *mystream)
{
- //printf("start to signature identify\n");
char temp_sip[MRL_STR_IP_LEN];
char temp_dip[MRL_STR_IP_LEN];
memset(temp_sip,0,MRL_STR_IP_LEN);
@@ -254,16 +260,17 @@ bool mrl_pkt_signature_identify(struct streaminfo *mystream)
dip = ntohl(mystream->addr.tuple4_v4->daddr);
inet_ntop(AF_INET,&(mystream->addr.tuple4_v4->saddr),temp_sip,MRL_STR_IP_LEN);
inet_ntop(AF_INET,&(mystream->addr.tuple4_v4->daddr),temp_dip,MRL_STR_IP_LEN);
- /*if(memcmp(temp_sip,"61.135.169.121",strlen(temp_sip)) == 0)
+ /*
+ if(memcmp(temp_sip,"61.135.169.121",strlen(temp_sip)) == 0)
{
- printf("cur sip is baidu\n");
+ printf("cur stream sip is baidu\n");
return true;
}
else
{
- if(memcmp(temp_dip,"61.135.169.121",strlen(temp_sip)) == 0)
+ if(memcmp(temp_dip,"61.135.169.121",strlen(temp_dip)) == 0)
{
- printf("cur dip is baidu\n");
+ printf("cur stream dip is baidu\n");
return true;
}
else
@@ -315,11 +322,12 @@ void mrl_send_to_mgw(void *raw_pkt, int thread_seq)
const char *pkt = (const char *)raw_pkt;
struct iphdr *ip_hdr = (struct iphdr *)pkt;
ssize_t pkt_len = ntohs(ip_hdr->tot_len);
- MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_send_to_mgw","send to mgw len is %d",pkt_len);
ssize_t send_len = 0;
send_len = mrl_sock_send(mrl_instance.mrl_snd_fd[thread_seq],pkt,pkt_len,&(mrl_instance.mgw_addr));
+ global_stat.send_to_mgw_pkts += 1;
+ MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_send_to_mgw","pkt len is %d and send to mgw len is %d",pkt_len,send_len);
assert(send_len == pkt_len);
- printf("send socket len is %ld\n",send_len);
+
}
@@ -338,7 +346,8 @@ void *mrl_recv_mgw_action(void *arg)
}
memset(rcv_buff,0,MRL_BUFF_LEN);
recv_len = mrl_sock_recv(mrl_instance.mrl_rcv_fd,rcv_buff, MRL_BUFF_LEN);
- printf("recv from mgw len is %ld\n",recv_len);
+ global_stat.recv_from_mgw_pkts ++;
+ MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_recv_mgw_action","recv from mgw len is %ld",recv_len);
struct mrl_vxlan_info *vxlan_info = (struct mrl_vxlan_info *)rcv_buff;
MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_recv_mgw_action","recv mgw vxlan info:"
"link_id:%d,encap_type:%d,link_dir:%d,vpn_id:%d,local_port:%s,gdev_port:%s, local_ip:%s,gdev_ip:%s,"
@@ -348,11 +357,10 @@ void *mrl_recv_mgw_action(void *arg)
vxlan_info->vxlan_outer_local_ip,vxlan_info->vxlan_outer_gdev_ip,vxlan_info->vxlan_outer_local_mac,
vxlan_info->vxlan_outer_gdev_mac,vxlan_info->vxlan_inner_smac, vxlan_info->vxlan_inner_dmac);
size_t vxlan_len = sizeof(struct mrl_vxlan_info);
-
temp_len = sizeof(thread_seq);
sapp_get_platform_opt(SPO_INDEPENDENT_THREAD_ID, &thread_seq, &temp_len);
- //printf("send to gdev thread seq is %d\n",thread_seq);
mrl_send_to_gdev(thread_seq,vxlan_info,rcv_buff + vxlan_len, recv_len - vxlan_len);
+ global_stat.send_gdev_total_pkts ++;
}
return NULL;
}
@@ -396,7 +404,7 @@ size_t mrl_build_udp_payload(char *payload)
}
void mrl_detect_action(uint32_t src_ip)
{
- MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_FATAL,"mrl_detect_action","detect ip is %u",src_ip);
+ MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_detect_action","detect ip is %u",src_ip);
unsigned int i = 0;
int thread_seq = 0;
int temp_len = 0;
@@ -417,12 +425,14 @@ void mrl_detect_action(uint32_t src_ip)
memset(&vxlan_info,0,sizeof(vxlan_info));
mrl_get_vxlan_info(&vxlan_info,i);
mrl_send_to_gdev(thread_seq,&vxlan_info,ip_pkt,ip_len);
+ global_stat.send_detect_pkts ++;
+ global_stat.send_gdev_total_pkts ++;
}
}
void *mrl_detect_ip_action(void *arg)
{
- sleep(10);
+ sleep(20);
int ret = 0;
uint32_t detect_ip = 0;
long int ip_len = sizeof(detect_ip);
@@ -433,7 +443,6 @@ void *mrl_detect_ip_action(void *arg)
break;
}
ret = MESA_lqueue_get_head(mrl_instance.mrl_queue,&detect_ip,&ip_len);
- MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_FATAL,"mrl_detect_ip_action","get ip from lqueue is %u",detect_ip);
if(ret != 0)
{
MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_FATAL,"mrl_detect_ip_action","MESA_lqueue_get_head func error! ret is %d",ret);
diff --git a/src/mrl_redis.c b/src/mrl_redis.c
index 86287db..113ba68 100644
--- a/src/mrl_redis.c
+++ b/src/mrl_redis.c
@@ -3,8 +3,10 @@
#include "mrl_packet.h"
#include "mrl_redis.h"
+#include "mrl_stat.h"
extern struct mrl_global_instance mrl_instance;
+extern struct global_stat_t global_stat;
extern void mrl_detect_action(const char *ip_addr);
void wrapped_Maat_set_feather_opt(Maat_feather_t feather, enum MAAT_INIT_OPT type, const void* value, int size)
@@ -24,22 +26,12 @@ void ht_nominee_free_cb(void * data)
{
free(nominee_item);
nominee_item = NULL;
+ global_stat.free_memory += sizeof(struct mrl_nominee_item);
}
}
-/*
-void ht_candidate_free_cb(void * data)
-{
- struct mrl_candidate_item *candidate_item = (struct mrl_candidate_item *)data;
- if(candidate_item != NULL)
- {
- free(candidate_item);
- candidate_item = NULL;
- }
-}
-*/
+
MESA_htable_handle mrl_htable_init(void * fn_data_free_cb)
{
- printf("mrl htable init\n");
unsigned int opt_int;
MESA_htable_handle htable = MESA_htable_born();
assert(htable != NULL);
@@ -159,6 +151,7 @@ void nominee_update_cb(int table_id,const char* table_line,void* u_para)
int ret = 0;
uint32_t client_ip = 0;
struct mrl_nominee_item *nominee_item = (struct mrl_nominee_item *)calloc(1, sizeof(struct mrl_nominee_item));
+ global_stat.malloc_memory += sizeof(struct mrl_nominee_item);
sscanf(table_line,"%d\t%d\t%d\t%s\t%d\t%s",
&(nominee_item->config_id), &(nominee_item->group_id), &(nominee_item->addr_type),
nominee_item->ip_addr, &(nominee_item->is_vaild), nominee_item->op_time);
@@ -169,7 +162,7 @@ void nominee_update_cb(int table_id,const char* table_line,void* u_para)
switch(nominee_item->is_vaild)
{
case 0:
- if(MESA_htable_search_cb(mrl_instance.ht_nominee, (const unsigned char *)nominee_item->ip_addr, MRL_STR_IP_LEN,NULL,NULL,NULL) == NULL)
+ if(MESA_htable_search_cb(mrl_instance.ht_nominee, (const unsigned char *)nominee_item->ip_addr, MRL_STR_IP_LEN,NULL,NULL,NULL) != NULL)
{
ret = MESA_htable_del(mrl_instance.ht_nominee, (const unsigned char *)nominee_item->ip_addr, MRL_STR_IP_LEN, NULL);
if(ret < 0)
@@ -213,37 +206,7 @@ void nominee_update_cb(int table_id,const char* table_line,void* u_para)
}
-/*
-void candidate_update_cb(int table_id,const char* table_line,void* u_para)
-{
- int ret = 0;
- printf("this is candidate update cb\n");
- struct mrl_candidate_item *candidate_item = (struct mrl_candidate_item *)calloc(1, sizeof(struct mrl_candidate_item));
- sscanf(table_line,"%d\t%d\t%d\t%s\t%d\t%s\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%s",
- &(candidate_item->config_id), &(candidate_item->group_id),&(candidate_item->addr_type),
- candidate_item->ip_addr,&(candidate_item->location),candidate_item->mrl_ip,
- &(candidate_item->vxlan_info.vxlan_link_id), &(candidate_item->vxlan_info.vxlan_encap_type),
- &(candidate_item->vxlan_info.vxlan_link_dir),candidate_item->vxlan_info.vxlan_outer_local_port,
- candidate_item->vxlan_info.vxlan_outer_gdev_port,candidate_item->vxlan_info.vxlan_outer_local_ip,
- candidate_item->vxlan_info.vxlan_outer_gdev_ip,candidate_item->vxlan_info.vxlan_outer_local_mac,
- candidate_item->vxlan_info.vxlan_outer_gdev_mac,candidate_item->vxlan_info.vxlan_inner_smac,
- candidate_item->vxlan_info.vxlan_inner_dmac,&(candidate_item->is_vaild), candidate_item->op_time);
- if(MESA_htable_search_cb(mrl_instance.ht_candidate, (const unsigned char *)candidate_item->ip_addr, sizeof(candidate_item->ip_addr),NULL,NULL,NULL) == NULL)
- {
- ret = MESA_htable_add(mrl_instance.ht_candidate, (const unsigned char *)(candidate_item->ip_addr), sizeof(candidate_item->ip_addr), candidate_item);
- if(ret < 0)
- {
- MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_FATAL,"candidate_update_cb","MESA_htable_add func error! ret is %d",ret);
- assert(0);
- }
- }
- else
- {
- MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_FATAL,"candidate_update_cb","the candidate item is duplicated in candidate htable.");
- }
-
-}
-*/
+
long ht_search_cb(void *data, const uchar *key, uint size, void *user_arg)
{
struct mrl_nominee_item *nominee_item = (struct mrl_nominee_item *)data;
@@ -348,6 +311,7 @@ void mrl_identify_nominee(struct streaminfo *mystream)
MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_identify_nominee","cur identify nominee stream ip is %s\n",ip_addr);
if(MESA_htable_search_cb(mrl_instance.ht_nominee, (const unsigned char *)ip_addr, MRL_STR_IP_LEN,ht_search_cb,(void *)&candidate_item,&ret) != NULL)
{
+ global_stat.recv_detect_pkts ++;
get_rawpkt_opt_from_streaminfo(mystream, RAW_PKT_GET_GDEV_IP, &(gdev_ip));
//printf("cur gdev ip is %d\n",gdev_ip);
index = get_gdev_ip_index(gdev_ip);
diff --git a/src/mrl_stat.c b/src/mrl_stat.c
new file mode 100644
index 0000000..a2ead74
--- /dev/null
+++ b/src/mrl_stat.c
@@ -0,0 +1,82 @@
+#include"mrl_stat.h"
+#include<stdio.h>
+#include<stdlib.h>
+#include<string.h>
+#include<unistd.h>
+
+struct global_stat_t global_stat;
+struct fs_stat_t global_fs_stat;
+void mrl_stat_init()
+{
+ int value = 0;
+ char stat_file[] = "log/mrl_stat.log";
+ memset(&global_stat,0,sizeof(struct global_stat_t));
+
+ global_fs_stat.handle = FS_create_handle();
+
+ FS_set_para(global_fs_stat.handle, OUTPUT_DEVICE, stat_file, strlen(stat_file)+1);
+
+ value = 1;
+ FS_set_para(global_fs_stat.handle, PRINT_MODE, &value, sizeof(value));
+
+ value = 0;
+ FS_set_para(global_fs_stat.handle, CREATE_THREAD, &value, sizeof(value));
+
+ /* field */
+ global_fs_stat.fs_field_id[FIELD_RECV_MGW_PKTS] = FS_register(global_fs_stat.handle, FS_STYLE_FIELD, FS_CALC_SPEED,"RECV_MGW_PKTS");
+ global_fs_stat.fs_field_id[FIELD_SEND_MGW_PKTS] = FS_register(global_fs_stat.handle, FS_STYLE_FIELD, FS_CALC_SPEED,"SEND_MGW_PKTS");
+
+ global_fs_stat.fs_field_id[FIELD_RECV_GDEV_PKTS] = FS_register(global_fs_stat.handle, FS_STYLE_FIELD, FS_CALC_SPEED,"RECV_GDEV_PKTS");
+ global_fs_stat.fs_field_id[FIELD_SEND_GDEV_PKTS] = FS_register(global_fs_stat.handle, FS_STYLE_FIELD, FS_CALC_SPEED,"SEND_GDEV_PKTS");
+
+ global_fs_stat.fs_field_id[FIELD_RECV_IR_PKTS] = FS_register(global_fs_stat.handle, FS_STYLE_FIELD, FS_CALC_SPEED,"rec_ir_pkts");
+
+ global_fs_stat.fs_field_id[FIELD_RECV_GDEV_TCP_PKTS] = FS_register(global_fs_stat.handle, FS_STYLE_FIELD, FS_CALC_SPEED,"recv_gdev_tcp_pkts");
+ global_fs_stat.fs_field_id[FIELD_RECV_GDEV_UDP_PKTS] = FS_register(global_fs_stat.handle, FS_STYLE_FIELD, FS_CALC_SPEED,"recv_gdev_udp_pkts");
+
+ global_fs_stat.fs_field_id[FIELD_SEND_DETECT_PKTS] = FS_register(global_fs_stat.handle, FS_STYLE_FIELD, FS_CALC_SPEED,"send_detect_pkts");
+ global_fs_stat.fs_field_id[FIELD_RECV_DETECT_PKTS] = FS_register(global_fs_stat.handle, FS_STYLE_FIELD, FS_CALC_SPEED,"recv_detect_pkts");
+
+ /*status*/
+ global_fs_stat.fs_status_id[STATUS_MALLOC_MEMORY] = FS_register(global_fs_stat.handle, FS_STYLE_STATUS, FS_CALC_CURRENT, "malloc_memory(Byte)");
+ global_fs_stat.fs_status_id[STATUS_FREE_MEMORY] = FS_register(global_fs_stat.handle, FS_STYLE_STATUS, FS_CALC_CURRENT, "free_memory(Byte)");
+
+ FS_start(global_fs_stat.handle);
+}
+
+void mrl_stat_output()
+{
+ /*field*/
+
+ FS_operate(global_fs_stat.handle, global_fs_stat.fs_field_id[FIELD_SEND_MGW_PKTS], 0, FS_OP_SET, global_stat.send_to_mgw_pkts);
+ FS_operate(global_fs_stat.handle, global_fs_stat.fs_field_id[FIELD_RECV_MGW_PKTS], 0, FS_OP_SET, global_stat.recv_from_mgw_pkts);
+
+ FS_operate(global_fs_stat.handle, global_fs_stat.fs_field_id[FIELD_SEND_GDEV_PKTS], 0, FS_OP_SET, global_stat.send_gdev_total_pkts);
+ FS_operate(global_fs_stat.handle, global_fs_stat.fs_field_id[FIELD_RECV_GDEV_PKTS], 0, FS_OP_SET, global_stat.recv_gdev_total_pkts);
+ FS_operate(global_fs_stat.handle, global_fs_stat.fs_field_id[FIELD_RECV_GDEV_TCP_PKTS], 0, FS_OP_SET, global_stat.recv_gdev_tcp_pkts);
+ FS_operate(global_fs_stat.handle, global_fs_stat.fs_field_id[FIELD_RECV_GDEV_UDP_PKTS], 0, FS_OP_SET, global_stat.recv_gdev_udp_pkts);
+
+ FS_operate(global_fs_stat.handle, global_fs_stat.fs_field_id[FIELD_RECV_IR_PKTS], 0, FS_OP_SET, global_stat.recv_ir_pkts);
+
+ FS_operate(global_fs_stat.handle, global_fs_stat.fs_field_id[FIELD_SEND_DETECT_PKTS], 0, FS_OP_SET, global_stat.send_detect_pkts);
+ FS_operate(global_fs_stat.handle, global_fs_stat.fs_field_id[FIELD_RECV_DETECT_PKTS], 0, FS_OP_SET, global_stat.recv_detect_pkts);
+
+ /*status*/
+ FS_operate(global_fs_stat.handle, global_fs_stat.fs_status_id[STATUS_MALLOC_MEMORY], 0, FS_OP_SET, global_stat.malloc_memory);
+ FS_operate(global_fs_stat.handle, global_fs_stat.fs_status_id[STATUS_FREE_MEMORY], 0, FS_OP_SET, global_stat.free_memory);
+ FS_passive_output(global_fs_stat.handle);
+}
+
+
+void *mrl_stat_action(void *arg)
+{
+ printf("start stat thread\n");
+ for(;;)
+ {
+ mrl_stat_output();
+ sleep(1);
+ }
+ return NULL;
+}
+
+