summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author杨威 <[email protected]>2019-05-24 11:12:52 +0800
committer杨威 <[email protected]>2019-05-24 11:12:52 +0800
commit17c7dc78b6ed3ab53b46896c4db88a7256e0a74f (patch)
treecce58709671e3ce32a714c110fa6d64a3380b5a1
parentb4301a61c53e1f84c858a42eac08926159a1fa89 (diff)
1.Layer-2 BFD keepalive;
2.static library link.
-rw-r--r--Makefile22
-rw-r--r--dealpkt/deal_ethernet.c10
-rw-r--r--dealpkt/deal_ipv4.c1
-rw-r--r--dealpkt/deal_tcp.c36
-rw-r--r--dealpkt/deal_vlan.c8
-rw-r--r--dealpkt/plug_support.c33
-rw-r--r--entry/Makefile13
-rw-r--r--entry/sapp_init.c9
-rw-r--r--include/stream_inc/stream_rawpkt.h5
-rw-r--r--include/stream_internal.h1
-rw-r--r--inner_plug/Makefile16
-rw-r--r--inner_plug/sapp_assistant.cpp18
-rw-r--r--packet_io/Makefile14
-rw-r--r--packet_io/cycle_pkt_dump_through_write_offset.c8
-rw-r--r--packet_io/packet_io_device.c5
-rw-r--r--packet_io/packet_io_lib_load.c108
-rw-r--r--packet_io/packet_io_marsio.c3
-rw-r--r--run/conf/gdev.conf1
-rw-r--r--run/conf/wangyan_gdev_measure/wangyan_dev_measure1.conf31
-rw-r--r--run/plug/business/wangyan_gdev_measurement/wangyan_gdev_measurement.inf9
-rw-r--r--test_so/Makefile9
-rw-r--r--test_so/test_app_sapp.c52
-rw-r--r--test_so/test_ct_plug.c69
-rw-r--r--test_so/test_wangyan.c779
-rw-r--r--test_so/wangyan_gdev_measurement.c952
25 files changed, 1310 insertions, 902 deletions
diff --git a/Makefile b/Makefile
index cb526c0..2c48c7d 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
##################### MESA Makefile Common Definition Start #################
-MESA_MAKE_VERSION=20170517
+MESA_MAKE_VERSION=20190410
#CC=gcc
CC=g++
@@ -183,6 +183,22 @@ else
endif
endif
+
+__LINK_MODE_DYNAMIC=dynamic
+__LINK_MODE_STATIC=static
+link_mode=dynamic
+
+ifeq ($(link_mode), $(__LINK_MODE_STATIC))
+ CFLAGS += -DLINK_MODE_STATIC=1
+else
+ ifeq ($(link_mode), $(__LINK_MODE_DYNAMIC))
+ CFLAGS += -DLINK_MODE_DYNAMIC=1
+ else
+ $(error link_mode args error, please use make help)
+ exit
+ endif
+endif
+
.PHONY:help clean target
export CC
@@ -210,6 +226,9 @@ export _MODE_PAG_MARSIO
export target_mode
export __TARGET_MODE_ELF
export __TARGET_MODE_SO
+export link_mode
+export __LINK_MODE_STATIC
+export __LINK_MODE_DYNAMIC
target:all
@@ -224,6 +243,7 @@ help:
@echo -e "\t\t\033[31;49;1m opt={0,1,2,3,high_perf}, optimize level, default is 0.\033[0m"
@echo -e "\t\t\033[31;49;1m iomode={pcap,ppf,pag,prfing,dpdk,tilera,topsec,ipfile,marsio,smith,dpdk_vxlan,pag_marsio}, default is pcap.\033[0m"
@echo -e "\t\t\033[31;49;1m target_mode={elf, so}, default is elf.\033[0m"
+ @echo -e "\t\t\033[31;49;1m link_mode={dynamic, static}, default is dynamic.\033[0m"
##################### MESA Makefile Common Definition End ####################
diff --git a/dealpkt/deal_ethernet.c b/dealpkt/deal_ethernet.c
index c5d632f..03da217 100644
--- a/dealpkt/deal_ethernet.c
+++ b/dealpkt/deal_ethernet.c
@@ -55,6 +55,7 @@ int eth_entry(struct streaminfo_private *fstream_pr, const void *this_layer_hdr,
if(NET_CONN_SERIAL_GDEV == g_topology_mode){
if(unlikely(sapp_identify_broad_multicast_pkt(this_layer_hdr, raw_pkt) != 0)){
+ g_SysInputInfo[thread_num][COUNTER_DROP_PKT]++;
return DROP;
}
}
@@ -147,8 +148,13 @@ int eth_entry(struct streaminfo_private *fstream_pr, const void *this_layer_hdr,
g_SysInputInfo[thread_num][PKT_UNKNOWN]++;
g_SysInputInfo[thread_num][PKT_UNKNOWN_LEN] += raw_pkt->raw_pkt_len;
if(NET_CONN_SERIAL_GDEV == g_topology_mode){
- /* GDEVģʽ��, ʲôʱ�򶼲�Ӧ�ðѲ���ʶ�İ���ת����ȥ, ���߷��ְ�SPT������Э����ע��ȥ, ����������� */
- ret = DROP;
+ if(sapp_identify_tunnel_inner_pkt(raw_pkt) != 0){
+ ret = PASS;
+ }else{
+ /* GDEVģʽ��, ʲôʱ�򶼲�Ӧ�ðѷ������ڲ���ʶ�İ���ת����ȥ, ���߷��ְ�SPT������Э����ע��ȥ, ����������� */
+ g_SysInputInfo[thread_num][COUNTER_DROP_PKT]++;
+ ret = DROP;
+ }
}else{
ret = PASS;
}
diff --git a/dealpkt/deal_ipv4.c b/dealpkt/deal_ipv4.c
index 92d696d..2ed66be 100644
--- a/dealpkt/deal_ipv4.c
+++ b/dealpkt/deal_ipv4.c
@@ -630,6 +630,7 @@ int ipv4_entry(struct streaminfo_private *pfstream_pr, const void *this_layer_da
}
*/
if(is_multicast_addr_v4(ntohl(a_packet->ip_dst.s_addr))){
+ g_SysInputInfo[thread_num][COUNTER_DROP_PKT]++;
return DROP;
}
}
diff --git a/dealpkt/deal_tcp.c b/dealpkt/deal_tcp.c
index c141d43..9a9aef3 100644
--- a/dealpkt/deal_tcp.c
+++ b/dealpkt/deal_tcp.c
@@ -1277,7 +1277,12 @@ int tcp_free_stream(struct streamindex *pindex, const void *this_ip_hdr, const v
return pkt_ret;
}
-static void tcp_reset_stream(struct streamindex *pindex,const void *this_iphdr,
+/*
+ return value:
+ 1: reset and create new stream;
+ 0: reset but free current stream;
+*/
+static int tcp_reset_stream(struct streamindex *pindex,const void *this_iphdr,
struct mesa_tcp_hdr *this_tcphdr,int datalen,const raw_pkt_t *raw_pkt)
{
struct stream_list *plist=NULL;
@@ -1287,6 +1292,7 @@ static void tcp_reset_stream(struct streamindex *pindex,const void *this_iphdr,
struct tcpdetail *pdetail = &pdetail_pr->tcpdetail_public;
UCHAR threadnum = pstream->threadnum;
UCHAR saved_curdir;
+ int ret = 0;
//add by lqy 20150107 回退计数
if(pstream->curdir==DIR_S2C)
@@ -1386,11 +1392,32 @@ static void tcp_reset_stream(struct streamindex *pindex,const void *this_iphdr,
if(this_tcphdr->th_flags & TH_SYN){
tcp_add_new_stream_bysyn(pindex,this_iphdr,this_tcphdr,datalen,REUSE_OLD_LINK,raw_pkt);
+ ret = 1;
}else{
- tcp_add_new_stream_bydata(pindex,this_tcphdr,datalen,REUSE_OLD_LINK);
+ if(TCP_CTEAT_LINK_BYDATA & tcp_creatlink_model){
+ tcp_add_new_stream_bydata(pindex,this_tcphdr,datalen,REUSE_OLD_LINK);
+ ret = 1;
+ }else{
+ /* 20190506 lijia add, reset之后如果不建新流, 直接free掉 */
+ hash_del_stream(pindex);
+ if(pstream->pdetail != NULL)
+ {
+ dictator_free(threadnum,pstream->pdetail);
+ pstream->pdetail=NULL;
+ }
+ if(pstream_pr->timeout > link_default_nopkt_time){ /* 链接独有超时时间, 减少计数 */
+ sapp_global_mthread[threadnum].tcp_stream_special_timeout_num--;
+ }
+ free_heap_stream_info(pstream, 0);
+ free_streamindex(threadnum,pindex);
+ ret = 0;
+ }
+
}
g_SysInputInfo[threadnum][SYS_TCP_LINK_RESET]++;
+
+ return ret;
}
@@ -2541,7 +2568,10 @@ static int deal_tcp_stream(struct streamindex *pindex, const void *this_iphdr, s
/* note: reset会重置计数, 放在clientbytes+=, clientpktnum++代码之后 */
if(1 == lrustream(pindex_tcp)){
- tcp_reset_stream(pindex_tcp, this_iphdr,this_tcphdr, tcplen,raw_pkt);
+ ret = tcp_reset_stream(pindex_tcp, this_iphdr,this_tcphdr, tcplen,raw_pkt);
+ if(0 == ret){
+ return PASS;
+ }
}
pdetail->lastmtime=g_CurrentTime;
diff --git a/dealpkt/deal_vlan.c b/dealpkt/deal_vlan.c
index a7cc602..3d90c59 100644
--- a/dealpkt/deal_vlan.c
+++ b/dealpkt/deal_vlan.c
@@ -93,8 +93,12 @@ int vlan_8021q_entry(struct streaminfo_private *pfstream_pr,const void *this_lay
default:
if(NET_CONN_SERIAL_GDEV == g_topology_mode){
- /* GDEVģʽ��, ʲôʱ�򶼲�Ӧ�ðѲ���ʶ�İ���ת����ȥ, ���߷��ְ�SPT������Э����ע��ȥ, ����������� */
- ret = DROP;
+ if(sapp_identify_tunnel_inner_pkt(raw_pkt) != 0){
+ ret = PASS;
+ }else{
+ /* GDEVģʽ��, ʲôʱ�򶼲�Ӧ�ðѲ���ʶ�İ���ת����ȥ, ���߷��ְ�SPT������Э����ע��ȥ, ����������� */
+ ret = DROP;
+ }
}else{
ret = PASS;
}
diff --git a/dealpkt/plug_support.c b/dealpkt/plug_support.c
index 7fa9428..2b8a95c 100644
--- a/dealpkt/plug_support.c
+++ b/dealpkt/plug_support.c
@@ -95,7 +95,7 @@ int get_opt_from_rawpkt(const void *voidpkt, int type, void *void_value)
case RAW_PKT_GET_GDEV_IP:
{
const struct mr_tunnat_ctrlzone *mr_ctrlzone = (const struct mr_tunnat_ctrlzone *)marsio_buff_ctrlzone((marsio_buff_t *)rawpkt->io_lib_pkt_reference, 0); /* index */
- if(mr_ctrlzone->__encap_len <= 0){/* ��vxlan��, �϶�û����Щѡ�� */
+ if(0 == (mr_ctrlzone->action & TUNNAT_CZ_ACTION_FORWARD)){/* ��vxlan��, �϶�û����Щѡ�� */
ret = -1;
break;
}
@@ -108,22 +108,31 @@ int get_opt_from_rawpkt(const void *voidpkt, int type, void *void_value)
case RAW_PKT_GET_VXLAN_ID:
{
const struct mr_tunnat_ctrlzone *mr_ctrlzone = (const struct mr_tunnat_ctrlzone *)marsio_buff_ctrlzone((marsio_buff_t *)rawpkt->io_lib_pkt_reference, 0); /* index */
- if(mr_ctrlzone->__encap_len <= 0){/* ��vxlan��, �϶�û����Щѡ�� */
+ if(0 == (mr_ctrlzone->action & TUNNAT_CZ_ACTION_FORWARD)){/* ��vxlan��, �϶�û����Щѡ�� */
ret = -1;
break;
}
int *out_value = (int *)void_value;
-//modify by liuy 20181205
-// *out_value = ntohl(mr_ctrlzone->g_device_vpn_id);
*out_value = ntohl(mr_ctrlzone->g_device_linkpair);
-//end
+ }
+ break;
+
+ case RAW_PKT_GET_VXLAN_VPNID:
+ {
+ const struct mr_tunnat_ctrlzone *mr_ctrlzone = (const struct mr_tunnat_ctrlzone *)marsio_buff_ctrlzone((marsio_buff_t *)rawpkt->io_lib_pkt_reference, 0); /* index */
+ if(0 == (mr_ctrlzone->action & TUNNAT_CZ_ACTION_FORWARD)){/* ��vxlan��, �϶�û����Щѡ�� */
+ ret = -1;
+ break;
+ }
+ int *out_value = (int *)void_value;
+ *out_value = ntohl(mr_ctrlzone->g_device_vpn_id);
}
break;
case RAW_PKT_GET_VXLAN_SPORT:
{
const struct mr_tunnat_ctrlzone *mr_ctrlzone = (const struct mr_tunnat_ctrlzone *)marsio_buff_ctrlzone((marsio_buff_t *)rawpkt->io_lib_pkt_reference, 0); /* index */
- if(mr_ctrlzone->__encap_len <= 0){/* ��vxlan��, �϶�û����Щѡ�� */
+ if(0 == (mr_ctrlzone->action & TUNNAT_CZ_ACTION_FORWARD)){/* ��vxlan��, �϶�û����Щѡ�� */
ret = -1;
break;
}
@@ -135,7 +144,7 @@ int get_opt_from_rawpkt(const void *voidpkt, int type, void *void_value)
case RAW_PKT_GET_VXLAN_ENCAP_TYPE:
{
const struct mr_tunnat_ctrlzone *mr_ctrlzone = (const struct mr_tunnat_ctrlzone *)marsio_buff_ctrlzone((marsio_buff_t *)rawpkt->io_lib_pkt_reference, 0); /* index */
- if(mr_ctrlzone->__encap_len <= 0){/* ��vxlan��, �϶�û����Щѡ�� */
+ if(0 == (mr_ctrlzone->action & TUNNAT_CZ_ACTION_FORWARD)){/* ��vxlan��, �϶�û����Щѡ�� */
ret = -1;
break;
}
@@ -147,7 +156,7 @@ int get_opt_from_rawpkt(const void *voidpkt, int type, void *void_value)
case RAW_PKT_GET_VXLAN_LINK_DIR:
{
const struct mr_tunnat_ctrlzone *mr_ctrlzone = (const struct mr_tunnat_ctrlzone *)marsio_buff_ctrlzone((marsio_buff_t *)rawpkt->io_lib_pkt_reference, 0); /* index */
- if(mr_ctrlzone->__encap_len <= 0){/* ��vxlan��, �϶�û����Щѡ�� */
+ if(0 == (mr_ctrlzone->action & TUNNAT_CZ_ACTION_FORWARD)){/* ��vxlan��, �϶�û����Щѡ�� */
ret = -1;
break;
}
@@ -159,7 +168,7 @@ int get_opt_from_rawpkt(const void *voidpkt, int type, void *void_value)
case RAW_PKT_GET_VXLAN_OUTER_GDEV_MAC:
{
const struct mr_tunnat_ctrlzone *mr_ctrlzone = (const struct mr_tunnat_ctrlzone *)marsio_buff_ctrlzone((marsio_buff_t *)rawpkt->io_lib_pkt_reference, 0); /* index */
- if(mr_ctrlzone->__encap_len <= 0){/* ��vxlan��, �϶�û����Щѡ�� */
+ if(0 == (mr_ctrlzone->action & TUNNAT_CZ_ACTION_FORWARD)){/* ��vxlan��, �϶�û����Щѡ�� */
ret = -1;
break;
}
@@ -170,7 +179,7 @@ int get_opt_from_rawpkt(const void *voidpkt, int type, void *void_value)
case RAW_PKT_GET_VXLAN_OUTER_LOCAL_MAC:
{
const struct mr_tunnat_ctrlzone *mr_ctrlzone = (const struct mr_tunnat_ctrlzone *)marsio_buff_ctrlzone((marsio_buff_t *)rawpkt->io_lib_pkt_reference, 0); /* index */
- if(mr_ctrlzone->__encap_len <= 0){/* ��vxlan��, �϶�û����Щѡ�� */
+ if(0 == (mr_ctrlzone->action & TUNNAT_CZ_ACTION_FORWARD)){/* ��vxlan��, �϶�û����Щѡ�� */
ret = -1;
break;
}
@@ -181,7 +190,7 @@ int get_opt_from_rawpkt(const void *voidpkt, int type, void *void_value)
case RAW_PKT_GET_VIRTUAL_LINK_ID:
{
const struct mr_tunnat_ctrlzone *mr_ctrlzone = (const struct mr_tunnat_ctrlzone *)marsio_buff_ctrlzone((marsio_buff_t *)rawpkt->io_lib_pkt_reference, 0); /* index */
- if(mr_ctrlzone->virtual_link_id <= 0){/* ��vxlan��, �϶�û����Щѡ�� */
+ if(0 == (mr_ctrlzone->action & TUNNAT_CZ_ACTION_FORWARD)){/* ��vxlan��, �϶�û����Щѡ�� */
ret = -1;
break;
}
@@ -192,7 +201,7 @@ int get_opt_from_rawpkt(const void *voidpkt, int type, void *void_value)
case RAW_PKT_GET_REHASH_INDEX:
{
const struct mr_tunnat_ctrlzone *mr_ctrlzone = (const struct mr_tunnat_ctrlzone *)marsio_buff_ctrlzone((marsio_buff_t *)rawpkt->io_lib_pkt_reference, 0); /* index */
- if(mr_ctrlzone->rehash_index <= 0){/* ��vxlan��, �϶�û����Щѡ�� */
+ if(0 == (mr_ctrlzone->action & TUNNAT_CZ_ACTION_FORWARD)){/* ��vxlan��, �϶�û����Щѡ�� */
ret = -1;
break;
}
diff --git a/entry/Makefile b/entry/Makefile
index 88c0cd1..241faf5 100644
--- a/entry/Makefile
+++ b/entry/Makefile
@@ -6,7 +6,8 @@ endif
all: $(TARGET)
-LIB_PATH=-L../lib
+LIB=
+LIB_PATH=-L../lib -L/opt/mrzcpd/lib
CFLAGS += -fPIC -D_BSD_SOURCE -D_BSD_SOURCE -D__BSD_SOURCE -D__FAVOR_BSD
CFLAGS += -DPLATFORM_NSDPF_PAPP=1
@@ -31,10 +32,14 @@ WHOLE_ARCH=../lib/libdealpkt.a ../lib/libproject.a ../lib/libMESA_sleep.a ../lib
WHOLE_ARCH+=../lib/libpacket_io.a
endif
+ifeq ($(link_mode), $(__LINK_MODE_STATIC))
+ WHOLE_ARCH += ../lib/libinner_plug.a
+else
+ LIB += -lsapp_assistant
+endif
+
LDFLAGS =
LDFLAGS += $(LD_DICTATOR)
-
-LIB=
LIB+=../lib/plugctrl.a
LIB+=../lib/libmd5.a
LIB+=../lib/librbtree.a
@@ -68,7 +73,7 @@ INC+=-I/opt/MESA/include/MESA/stream_inc
LIB += -L/opt/MESA/lib -lpthread -ldl -lrt
LIB += -lMESA_htable -lMESA_handle_logger -lMESA_prof_load
#LIB += -lsesame_door
-LIB += -lsapp_assistant
+LIB += -lMESA_field_stat2
ifeq ($(iomode), $(_MODE_MARSIO))
LIB += -lmarsio
diff --git a/entry/sapp_init.c b/entry/sapp_init.c
index 0e017eb..c3773c4 100644
--- a/entry/sapp_init.c
+++ b/entry/sapp_init.c
@@ -321,9 +321,13 @@ int MESA_platform_init(int argc, char *argv[])
timestamp_record_init();
#endif
+ ///20190411 lijia modify, call packet_io before plug!!!
+ if(packet_io_init(argc, argv) < 0){
+ return -1;
+ }
MESA_load_profile_int_def("conf/main.conf","Module", "load_plug_switch", &load_plug_sw, 1);
if(load_plug_sw){
- plugctrl_proc();
+ plugctrl_proc(); ///20190411 lijia modify, call plugctrl_proc after packet_io_init!!!
}
/* 2017-02-24 lijia modify,
@@ -333,9 +337,6 @@ int MESA_platform_init(int argc, char *argv[])
��ô������pthread_create���߳�Ĭ�ϼ̳������Ϊ,
����, �ȳ�ʼ���߳��ٳ�ʼ��packet_io.
*/
- if(packet_io_init(argc, argv) < 0){
- return -1;
- }
#if CYCLE_PKT_DUMP
diff --git a/include/stream_inc/stream_rawpkt.h b/include/stream_inc/stream_rawpkt.h
index 9be7002..38591ac 100644
--- a/include/stream_inc/stream_rawpkt.h
+++ b/include/stream_inc/stream_rawpkt.h
@@ -1,7 +1,7 @@
#ifndef _APP_STREAM_RAWPKT_H_
#define _APP_STREAM_RAWPKT_H_
-#define STREAM_RAWPKT_H_VERSION (20181029)
+#define STREAM_RAWPKT_H_VERSION (20190430)
#include "stream_base.h"
@@ -21,7 +21,8 @@ enum{
RAW_PKT_GET_VXLAN_OUTER_GDEV_MAC, //value type is char[6],
RAW_PKT_GET_VXLAN_OUTER_LOCAL_MAC, //value type is char[6],
RAW_PKT_GET_VIRTUAL_LINK_ID, //value type is uint64 *, out_value should be uint64 *
- RAW_PKT_GET_REHASH_INDEX // value type is uint64 *, out_value should be uint64 *
+ RAW_PKT_GET_REHASH_INDEX, // value type is uint64 *, out_value should be uint64 *
+ RAW_PKT_GET_VXLAN_VPNID, // network-order, VPN_ID, value type is int, out_value should be int *
};
#ifdef __cplusplus
diff --git a/include/stream_internal.h b/include/stream_internal.h
index 4654be1..6da2923 100644
--- a/include/stream_internal.h
+++ b/include/stream_internal.h
@@ -314,6 +314,7 @@ char biz_retval_to_platform(char biz_ret);
char plat_state_to_biz(char plat_state);
void idle_polling_call(int thread_seq);
int sapp_identify_broad_multicast_pkt(const void *this_layer_data, const raw_pkt_t *raw_pkt);
+int sapp_identify_tunnel_inner_pkt(const raw_pkt_t *raw_pkt);
int sapp_assistant_init(void);
static inline long long sapp_get_cpu_cycle(void)
diff --git a/inner_plug/Makefile b/inner_plug/Makefile
index ba1bd10..380fda3 100644
--- a/inner_plug/Makefile
+++ b/inner_plug/Makefile
@@ -24,13 +24,22 @@ H_DIR += -I/opt/MESA/include
H_DIR += -I/opt/MESA/include/MESA
H_DIR += -I/opt/mrzcpd/include
-LIB=-L/opt/MESA/lib
+LIB=-L/opt/MESA/lib -L/opt/mrzcpd/lib
TARGET = isakmp_protocol_plug.so ipsec_biz_sample.so l2tp_protocol_plug.so l2tp_biz_sample.so
TARGET += pptp_protocol_plug.so pptp_biz_sample.so
TARGET += g_device_plug.so
TARGET += wangyan_keepalive_plug.so
-TARGET += libsapp_assistant.so
+
+OBJS=
+
+ifeq ($(link_mode), $(__LINK_MODE_STATIC))
+ OBJS += sapp_assistant.o
+ TARGET += libinner_plug.a
+else
+ TARGET += libsapp_assistant.so
+endif
+
ifeq ($(iomode), $(_MODE_PCAP))
CFLAGS += -DIOMODE_PCAP=1
@@ -77,6 +86,9 @@ all: $(TARGET)
.cpp.o:
$(CCC) -c $(CFLAGS) -I. $(H_DIR) $<
+libinner_plug.a:$(OBJS)
+ rm -f $@ ;ar -r $@ $^;
+ cp $@ ../lib/
#isakmp_protocol_plug.so:isakmp_protocol_plug.o
isakmp_protocol_plug.so:isakmp_protocol_plug_add_nat.o
diff --git a/inner_plug/sapp_assistant.cpp b/inner_plug/sapp_assistant.cpp
index ffa65f4..0e2d687 100644
--- a/inner_plug/sapp_assistant.cpp
+++ b/inner_plug/sapp_assistant.cpp
@@ -65,6 +65,7 @@ static int sapp_identify_broad_multicast_init(void)
void *io_lib_handle;
if(CAP_MODEL_MARSIOV4 == g_packet_io_cap_mode){
+#if LINK_MODE_DYNAMIC
io_lib_handle = dlopen("./platform_lib/packet_io_marsio.so", RTLD_NOW | RTLD_GLOBAL);
if(NULL == io_lib_handle){
printf("\033[1;31;40m[Error]dlopen %s error, %s!\033[0m\n", "./platform_lib/packet_io_marsio.so", dlerror());
@@ -77,26 +78,31 @@ static int sapp_identify_broad_multicast_init(void)
}
/* �˴���Ҫ��dlclose(), ��Ϊ������Ҫ��dlopen��packet_io_marsio.so, */
+#else
+ dl_marsio_buff_ctrlzone = (void * (*)(void *m, uint8_t id))marsio_buff_ctrlzone;
+#endif
}
#endif
+
return 0;
}
-static int sapp_identify_datalink_mode_is_eth(const raw_pkt_t *raw_pkt)
+/* ʶ���Ƿ������ڲ����ݰ� , �����ڵİ�Ӧ��������ת��/��ע */
+int sapp_identify_tunnel_inner_pkt(const raw_pkt_t *raw_pkt)
{
#if IOMODE_MARSIO
if(CAP_MODEL_MARSIOV4 == g_packet_io_cap_mode){
const struct mr_tunnat_ctrlzone *mr_ctzone;
if(dl_marsio_buff_ctrlzone){
mr_ctzone = (const struct mr_tunnat_ctrlzone *)((*dl_marsio_buff_ctrlzone)((void *)raw_pkt->io_lib_pkt_reference, 0));
- if(mr_ctzone->__encap_len > 0){
- return 0;
+ if(mr_ctzone->action & TUNNAT_CZ_ACTION_FORWARD){
+ return 1;
}
}
}
#endif
- return 1;
+ return 0;
}
int sapp_identify_broad_multicast_pkt(const void *this_layer_data, const raw_pkt_t *raw_pkt)
@@ -104,7 +110,7 @@ int sapp_identify_broad_multicast_pkt(const void *this_layer_data, const raw_pkt
const struct mesa_ethernet_hdr *p_eth_hdr = (const struct mesa_ethernet_hdr *)this_layer_data;
unsigned short eth_type = p_eth_hdr->ether_type; /* ʹ��������ֱ���ж�, ����ÿ�ζ�����ntohs() */
- if(sapp_identify_datalink_mode_is_eth(raw_pkt) == 0){
+ if(sapp_identify_tunnel_inner_pkt(raw_pkt) != 0){
return 0;
}
@@ -114,7 +120,7 @@ int sapp_identify_broad_multicast_pkt(const void *this_layer_data, const raw_pkt
return 1;
}
}else{
- /* 2017-10-10 lijia add, �鲥MAC��ַ, ͨ��Ϊ�������ڿ��������ݰ�, ��LLMNR, SPT��Э��, һ�����账�� */
+ /* 2017-10-10 lijia add, �鲥MAC��ַ, ͨ��Ϊ�������ڿ��������ݰ�, ��LLMNR, STP��Э��, һ�����账�� */
if((p_eth_hdr->ether_dhost[0] & 0x01) == 0x01){
return 1;
}
diff --git a/packet_io/Makefile b/packet_io/Makefile
index 8441798..76fce37 100644
--- a/packet_io/Makefile
+++ b/packet_io/Makefile
@@ -3,6 +3,10 @@
#CC = g++
#CCC = g++
+
+TARGET = libpacket_io.a
+OBJS=sendpacket.o sendpacket_wrap.o packet_io.o packet_io_log.o
+
CFLAGS += -Wall
CFLAGS += -fPIC -shared -D_BSD_SOURCE -D_BSD_SOURCE -D__BSD_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H
CFLAGS += $(OPTFLAGS)
@@ -14,7 +18,7 @@ CFLAGS += -DUSE_PAG_GET_FRAME=1
endif
RELEASE_PATH=../run/platform_lib/
-LIBPATH = -L../lib
+LIBPATH = -L../lib -L/opt/mrzcpd/lib
DEP = ../support/libnet_common.so
H_DIR += $(INC)
@@ -65,8 +69,11 @@ DLL_LIB += packet_io_ipfile.so
endif
ifeq ($(iomode), $(_MODE_MARSIO))
-DLL_LIB += packet_io_marsio.so
CFLAGS += -DIOMODE_MARSIO=1
+DLL_LIB += packet_io_marsio.so
+ ifeq ($(link_mode), $(__LINK_MODE_STATIC))
+ OBJS += packet_io_marsio.o
+ endif
endif
ifeq ($(iomode), $(_MODE_SMITH))
@@ -89,9 +96,6 @@ DLL_LIB += packet_io_pag_marsio.so
endif
-TARGET = libpacket_io.a
-
-OBJS=sendpacket.o sendpacket_wrap.o packet_io.o packet_io_log.o
OBJS+=packet_io_lib_load.o
OBJS+=packet_io_status.o
OBJS+=packet_io_status_new.o
diff --git a/packet_io/cycle_pkt_dump_through_write_offset.c b/packet_io/cycle_pkt_dump_through_write_offset.c
index 1d2845b..d315c07 100644
--- a/packet_io/cycle_pkt_dump_through_write_offset.c
+++ b/packet_io/cycle_pkt_dump_through_write_offset.c
@@ -467,6 +467,8 @@ static void __do_cycle_pkt_dump_udp_socket(int thread_seq, const raw_pkt_t *p_ra
}else{
pktdata = (const unsigned char *)p_raw_pkt->raw_pkt_data + pkt_dump_data_offset;
pktlen = p_raw_pkt->raw_pkt_len - pkt_dump_data_offset;
+ for_bpf_filter_len = pktlen;
+ for_bpf_filter_data = pktdata;
}
/* �������ȷ�Ĺ�������, ���������, ��֤��������ȫ, ���ϵ�������ͼ;
@@ -1181,6 +1183,8 @@ static void * cycle_pkt_dump_udp_socket_daemon_thread(void *arg)
pthread_setname_np(pthread_self(), "sapp_pkt_dump");
#endif
#endif
+ printf("\033[32m[Notice]'%s'is ready, port %d.\033[0m\n", "tcpdump_mesa",
+ pkt_dump_tcp_bind_port);
while(1){
cliaddr_len = sizeof(cliaddr);
@@ -1297,13 +1301,13 @@ int cycle_pkt_dump_init(int argc, char *argv[])
}
MESA_load_profile_int_def((char *)"conf/main.conf", (char *)"pkt_dump", (char *)"pkt_dump_total_size", &total_files_size, 1000);
- if(total_files_size < 1 || (unsigned int)total_files_size >= 1024*100 /* 100GB */){
+ if(total_files_size < 1 || (unsigned int)total_files_size >= 1024*1000 /* 1000GB */){
printf("pkt_dump_total_size invalid!\n");
return -1;
}
MESA_load_profile_int_def((char *)"conf/main.conf", (char *)"pkt_dump", (char *)"pkt_dump_file_max_size", &int_tmp, 100);
- if(int_tmp < 2 || (unsigned int)int_tmp >= 1024*100 /* 100GB */){
+ if(int_tmp < 2 || (unsigned int)int_tmp >= 1024*1000 /* 1000GB */){
printf("pkt_dump_file_max_size invalid!\n");
return -1;
}
diff --git a/packet_io/packet_io_device.c b/packet_io/packet_io_device.c
index 3195bd6..d19b394 100644
--- a/packet_io/packet_io_device.c
+++ b/packet_io/packet_io_device.c
@@ -35,9 +35,11 @@ static void * (*dl_io_device_alias_fun)(unsigned target_id, char *device_args);
extern void del_last_rn(char *data, int max_len);
extern struct dl_io_lib_name g_dl_io_lib_info[];
+extern void * dl_io_device_alias(unsigned int target_id, char *device_args);
static int get_dl_io_device_alias_fun_symbol(void)
{
+#if LINK_MODE_DYNAMIC
void *dl_handle;
char lib_path[256];
@@ -54,6 +56,9 @@ static int get_dl_io_device_alias_fun_symbol(void)
printf("\033[41m[Error]dlsym %s from %s error!\033[0m\n", "dl_io_device_alias", lib_path);
return -1;
}
+#else
+ dl_io_device_alias_fun = (void *(*)(unsigned int, char *))dl_io_device_alias;
+#endif
return 0;
}
diff --git a/packet_io/packet_io_lib_load.c b/packet_io/packet_io_lib_load.c
index 32f08cf..2643d87 100644
--- a/packet_io/packet_io_lib_load.c
+++ b/packet_io/packet_io_lib_load.c
@@ -50,23 +50,10 @@ static inline void __print_critical_msg(void *fun_ptr, const char *libname, cons
}
}
-/*
- (0:pag,1:pcap,2:dumpfile,3:pfring,4:DPDK,5:ppf,6:NPacket,7:qnf,8:N95,9:pcap-dumpfile-list,10:topsec,
- (11:ipfile, 12:marsio4, 13:agent_smith, 14:dpdk_vxlan, 15:marsio_vxlan.
-*/
-int packet_io_lib_load(int cap_mode)
+#if LINK_MODE_DYNAMIC
+static int packet_io_lib_load_by_mode(int cap_mode, const char *full_lib_path)
{
void *io_lib_handle;
- char *lib_name;
- char full_lib_path[PATH_MAX];
- int dl_io_lib_ver;
-
- if(cap_mode < 0 || cap_mode > __CAP_MODEL_MAX){
- printf("\033[1;31;40m[Error]Unknown capture_mode:%d\033[0m\n", cap_mode);
- return -1;
- }
- lib_name = g_dl_io_lib_info[cap_mode].lib_name;
- snprintf(full_lib_path, PATH_MAX, "%s/%s", DL_IO_LIB_PATH, lib_name);
io_lib_handle = dlopen(full_lib_path, RTLD_LAZY | RTLD_GLOBAL);
if(NULL == io_lib_handle){
@@ -96,6 +83,88 @@ int packet_io_lib_load(int cap_mode)
dl_io_fun_list.dl_io_get_version = (int (*)(void))dlsym(io_lib_handle, "dl_io_get_version");
dl_io_fun_list.dl_io_device_alias = (void * (*)(unsigned int , char *))dlsym(io_lib_handle, "dl_io_device_alias");
+}
+#else
+
+extern int dl_io_set_cap_level(int cap_level);
+extern int dl_io_set_cap_mode(int cap_mode);
+extern int dl_io_set_topology_mode(int topology_mode);
+extern int dl_io_set_capdev_parallel(const char *cap_dev);
+extern int dl_io_set_capdev_serial(const char *up_dev, const char *down_dev);
+extern int dl_io_set_capture_filter(const char *filter_rule);
+extern int dl_io_set_cap_buf_queue(int queue_num_max);
+extern int dl_io_set_work_thread_num(int thread_num_max);
+extern long dl_io_get_app_drop_num(int thread_num);
+extern long dl_io_get_lib_drop_num(void);
+extern unsigned char * dl_io_get_sendbuf(void *, int );
+extern void dl_io_free_sendbuf(void *, int thread_num);
+extern void * dl_io_get_send_handle(int thread_num);
+extern int dl_io_low_level_send(void *phandle, unsigned char *data,int datalen,
+ int eth_carry_layer_addr_type, int dir,int thread_num); /* ����ethernet�� */
+extern int dl_io_raw_pkt_send(void *phandle, unsigned char *data,int datalen, void *arg, int thread_num); /* ȫ��ԭʼ�� */
+extern int dl_io_init(int argc, char *argv[]);
+extern void dl_io_run(void);
+extern int dl_io_register_cb(PACKET_IO_CB_T fun);
+extern int dl_io_register_exit_cb(PACKET_IO_EXIT_CB_T exit_fun);
+extern int dl_io_get_version(void);
+extern void * dl_io_device_alias(unsigned int target_id, char *device_args);
+
+
+static int packet_io_lib_load_by_mode(int no_use, const char *full_lib_path)
+{
+ dl_io_fun_list.dl_io_set_cap_level = (int (*)(int cap_level))dl_io_set_cap_level;
+ dl_io_fun_list.dl_io_set_cap_mode = (int (*)(int cap_mode))dl_io_set_cap_mode;
+ dl_io_fun_list.dl_io_set_topology_mode = (int (*)(int topology_mode))dl_io_set_topology_mode;
+ dl_io_fun_list.dl_io_set_capdev_parallel = (int (*)(const char *cap_dev))dl_io_set_capdev_parallel;
+ dl_io_fun_list.dl_io_set_capdev_serial = (int (*)(const char *up_dev, const char *down_dev))dl_io_set_capdev_serial;
+ dl_io_fun_list.dl_io_set_capture_filter = (int (*)(const char *filter_rule))dl_io_set_capture_filter;
+ dl_io_fun_list.dl_io_set_cap_buf_queue = (int (*)(int queue_num_max))dl_io_set_cap_buf_queue;
+ dl_io_fun_list.dl_io_set_work_thread_num = (int (*)(int thread_num_max))dl_io_set_work_thread_num;
+ dl_io_fun_list.dl_io_get_app_drop_num = (long (*)(int thread_num))dl_io_get_app_drop_num;
+ dl_io_fun_list.dl_io_get_lib_drop_num = (long (*)(void))dl_io_get_lib_drop_num;
+ dl_io_fun_list.dl_io_get_sendbuf = (unsigned char * (*)(void *, int thread_num))dl_io_get_sendbuf;
+ dl_io_fun_list.dl_io_free_sendbuf = (void (*)(void *, int thread_num))dl_io_free_sendbuf;
+ dl_io_fun_list.dl_io_get_send_handle = (void * (*)(int thread_num))dl_io_get_send_handle;
+ dl_io_fun_list.dl_io_low_level_send = (int (*)(void *, unsigned char *,int ,int , int ,int ))dl_io_low_level_send;
+ dl_io_fun_list.dl_io_raw_pkt_send = (int (*)(void *, unsigned char *,int , void *,int ))dl_io_raw_pkt_send;
+ dl_io_fun_list.dl_io_init = (int (*)(int argc, char *argv[]))dl_io_init;
+ dl_io_fun_list.dl_io_run = (void (*)(void))dl_io_run;
+ dl_io_fun_list.dl_io_register_cb = (int (*)(PACKET_IO_CB_T fun))dl_io_register_cb;
+ //dl_io_fun_list.dl_io_register_exit_cb = (int (*)(PACKET_IO_EXIT_CB_T exit_fun))dl_io_register_exit_cb;
+ dl_io_fun_list.dl_io_get_version = (int (*)(void))dl_io_get_version;
+ dl_io_fun_list.dl_io_device_alias = (void * (*)(unsigned int , char *))dl_io_device_alias;
+
+ return 0;
+}
+#endif
+
+
+/*
+ (0:pag,1:pcap,2:dumpfile,3:pfring,4:DPDK,5:ppf,6:NPacket,7:qnf,8:N95,9:pcap-dumpfile-list,10:topsec,
+ (11:ipfile, 12:marsio4, 13:agent_smith, 14:dpdk_vxlan, 15:marsio_vxlan.
+*/
+int packet_io_lib_load(int cap_mode)
+{
+#if LINK_MODE_DYNAMIC
+ int dl_io_lib_ver;
+#endif
+
+ char *lib_name;
+ char full_lib_path[PATH_MAX];
+
+ if(cap_mode < 0 || cap_mode > __CAP_MODEL_MAX){
+ printf("\033[1;31;40m[Error]Unknown capture_mode:%d\033[0m\n", cap_mode);
+ return -1;
+ }
+
+ lib_name = g_dl_io_lib_info[cap_mode].lib_name;
+ snprintf(full_lib_path, PATH_MAX, "%s/%s", DL_IO_LIB_PATH, lib_name);
+
+
+ if(packet_io_lib_load_by_mode(cap_mode, full_lib_path) < 0){
+ return -1;
+ }
+
__print_err_msg((void *)dl_io_fun_list.dl_io_set_cap_level, full_lib_path, "dl_io_set_cap_level");
__print_err_msg((void *)dl_io_fun_list.dl_io_set_cap_mode, full_lib_path, "dl_io_set_cap_mode");
__print_err_msg((void *)dl_io_fun_list.dl_io_set_topology_mode, full_lib_path, "dl_io_set_topology_mode");
@@ -117,15 +186,12 @@ int packet_io_lib_load(int cap_mode)
__print_err_msg((void *)dl_io_fun_list.dl_io_get_version, full_lib_path, "dl_io_get_version");
__print_err_msg((void *)dl_io_fun_list.dl_io_device_alias, full_lib_path, "dl_io_device_alias");
+#if LINK_MODE_DYNAMIC
if(dl_io_fun_list.dl_io_get_version != NULL){
dl_io_lib_ver = dl_io_fun_list.dl_io_get_version();
if(dl_io_lib_ver != sapp_packet_io_v){
printf("\033[33m[Warning]packet_io lib: '%s' version is different with platform!!\033[0m\n", full_lib_path);
printf("\033[33mPlease copy newest packet_io library to './platform_lib/'\033[0m\n");
-#if 0
- printf("\033[41mProgram exit!\033[0m\n");
- exit(1); /* 2014-12-26 lijia add, �汾��һ��ǿ���˳� */
-#else
/* ����ijЩ�������Ҫ�¾ɼ����汾�ԱȲ���, Ӧ��������һ���İ汾����, ��Ҫ��ӡ������ʾ */
usleep(1000*100);
printf("\033[33m[Warning]Run anyway, are you sure? \033[0m\n");
@@ -135,10 +201,10 @@ int packet_io_lib_load(int cap_mode)
printf("\033[33m[Warning]Run anyway, are you sure????? \033[0m\n");
usleep(1000*2000);
printf("\033[33m[Warning]Run anyway, platform action is unpredictable!\033[0m\n");
-#endif
}
}
-
+#endif
+
g_packet_io_cap_mode = cap_mode;
return 0;
diff --git a/packet_io/packet_io_marsio.c b/packet_io/packet_io_marsio.c
index 4271020..794d8db 100644
--- a/packet_io/packet_io_marsio.c
+++ b/packet_io/packet_io_marsio.c
@@ -444,7 +444,8 @@ static int marsio4_pkt_forward(int tid, marsio_buff_t * mbufs)
/* ������ȡ, ���������������, vxlan��������װģʽ����ʹ��, Ҫ��ÿ��mbuf�жϵײ��װģʽ */
- if(ctrl_zone->__encap_len > 0){ /* 2018-06-01, marsio vxlan mode, ��vxlan��װ�İ����ܻ�ע */
+ //if(ctrl_zone->__encap_len > 0){ /* 2018-06-01, marsio vxlan mode, ��vxlan��װ�İ����ܻ�ע */
+ if(ctrl_zone->action & TUNNAT_CZ_ACTION_FORWARD){ /* 20190409 lijia modify, tunnel mode, ��������װ�İ����ܻ�ע */
/* vxlan��װ�ڲ�����ת���������κβ���, ֱ�ӵ���marsio_send_burst, ��marsio�������� */
ctrl_zone->action = TUNNAT_CZ_ACTION_FORWARD;
marsio_buff_ctrlzone_set(mbufs, 0, ctrl_zone, sizeof(struct mr_tunnat_ctrlzone));
diff --git a/run/conf/gdev.conf b/run/conf/gdev.conf
index 9c160b6..2e06e54 100644
--- a/run/conf/gdev.conf
+++ b/run/conf/gdev.conf
@@ -3,3 +3,4 @@ pcapdevice=eno1
sendto_gdev_card=eno1
sendto_gdev_ip=10.0.6.203
gdev_status_switch=1
+default_keepalive_action=1
diff --git a/run/conf/wangyan_gdev_measure/wangyan_dev_measure1.conf b/run/conf/wangyan_gdev_measure/wangyan_dev_measure1.conf
new file mode 100644
index 0000000..6c9f5f0
--- /dev/null
+++ b/run/conf/wangyan_gdev_measure/wangyan_dev_measure1.conf
@@ -0,0 +1,31 @@
+#NingSi config
+SRC_OUT_MAC:e8-61-1f-18-ed-b1
+DST_OUT_MAC: 00:1e:73:6c:fa:43
+115_IP:192.168.1.10
+G_IP:10.1.1.1
+LINK_ID_VALUE:1
+LINK_TYPE:0
+C_DIR:1
+CorI:C
+SRC_IN_MAC:6c:b3:11:32:1e:c3
+DST_IN_MAC: 00:23:24:90:95:6f
+
+
+#wangyan dev measure plug config
+#send packet transport type only support tcp or udp
+[plug]
+transport_type=tcp
+send_pps=100
+#only C or I
+send_CorI=I
+
+vxlan_sport=50704
+vxlan_dport=4789
+vxlan_vlan_num=112
+inner_sip=8.8.8.8
+inner_dip=192.168.11.140
+inner_sport=53
+inner_dport=8888
+
+payload=1111111112222222222333333333333
+
diff --git a/run/plug/business/wangyan_gdev_measurement/wangyan_gdev_measurement.inf b/run/plug/business/wangyan_gdev_measurement/wangyan_gdev_measurement.inf
new file mode 100644
index 0000000..aaf77d2
--- /dev/null
+++ b/run/plug/business/wangyan_gdev_measurement/wangyan_gdev_measurement.inf
@@ -0,0 +1,9 @@
+[PLUGINFO]
+PLUGNAME=wangyan_gdev_measurement
+SO_PATH=./plug/business/wangyan_gdev_measurement/wangyan_gdev_measurement.so
+INIT_FUNC=wangyan_gdev_measure_init
+
+
+[POLLING]
+FUNC_FLAG=ALL
+FUNC_NAME=wangyan_gdev_measure_polling_cb
diff --git a/test_so/Makefile b/test_so/Makefile
index 60c98f2..ec0af07 100644
--- a/test_so/Makefile
+++ b/test_so/Makefile
@@ -5,9 +5,10 @@ CFLAGS += $(OPTFLAGS)
OBJECTS = test_app_sapp.o trace_delay.o terminal_tag.o g_device_plug.o
MODULES =
-TARGET = test_app_sapp.so trace_delay.so terminal_tag.so test_http.so test_wangyan.so
-TARGET += test_ct_plug.so
+TARGET = test_app_sapp.so trace_delay.so test_wangyan.so
+#TARGET += test_ct_plug.so
TARGET += wangyan_demo.so
+TARGET += wangyan_gdev_measurement.so
INCS = -I ../include
INCS += -I ../inner_plug/
@@ -58,6 +59,10 @@ test_sapp_so:test_sapp_so.c
# $(CC) -o $@ -shared -fPIC $(CFLAGS) $(INCS) $^ $(MODULES)
# cp $@ ../run/plug/business/test_ct_plug/
+wangyan_gdev_measurement.so:wangyan_gdev_measurement.c
+ $(CC) -o $@ -shared -fPIC $(INCS) $(CFLAGS) $^ $(MODULES)
+ cp $@ ../run/plug/business/wangyan_gdev_measurement/
+
.c.o:
$(CC) -c -o $@ $(CFLAGS) -I. $(INCS) $<
clean:
diff --git a/test_so/test_app_sapp.c b/test_so/test_app_sapp.c
index 04f4401..6e60374 100644
--- a/test_so/test_app_sapp.c
+++ b/test_so/test_app_sapp.c
@@ -785,7 +785,7 @@ char test_layer_addr_prefix_ntop(const struct streaminfo *stream,void **pme, int
{
char addr_ntop_str_r[4096];
char *addr_ntop_str;
- char *addr_type_ntop_str;
+ const char *addr_type_ntop_str;
const struct streaminfo *tmp = stream;
if(OP_STATE_PENDING == stream->opstate){
@@ -801,6 +801,56 @@ char test_layer_addr_prefix_ntop(const struct streaminfo *stream,void **pme, int
}
+char test_get_rawpkt_options(struct streaminfo *stream,void **pme, int thread_seq,const void *raw_pkt)
+{
+ int ret;
+ int gdev_ip;
+ int vxlan_id;
+ int vpn_id;
+ unsigned short vxlan_sport;
+ unsigned char service_id;
+
+ ret = get_rawpkt_opt_from_streaminfo(stream, RAW_PKT_GET_GDEV_IP, &gdev_ip);
+ if(ret >= 0){
+ char tmp_ip_str[32];
+ inet_ntop(AF_INET, &gdev_ip, tmp_ip_str, 32);
+ printf("[debug], test_get_rawpkt_options get gdev-ip:%s\n", tmp_ip_str);
+ }else{
+ printf("[error], test_get_rawpkt_options GDEV_IP error\n");
+ }
+
+ ret = get_rawpkt_opt_from_streaminfo(stream, RAW_PKT_GET_VXLAN_ID, &vxlan_id);
+ if(ret >= 0){
+ printf("[debug], test_get_rawpkt_options get vlan-id:%d\n", vxlan_id);
+ }else{
+ printf("[error], test_get_rawpkt_options VXLAN_ID error\n");
+ }
+
+ ret = get_rawpkt_opt_from_streaminfo(stream, RAW_PKT_GET_VXLAN_VPNID, &vpn_id);
+ if(ret >= 0){
+ printf("[debug], test_get_rawpkt_options get VPNID:%d\n", ntohl(vpn_id)); /* to host order */
+ }else{
+ printf("[error], test_get_rawpkt_options VPNID error\n");
+ }
+
+ service_id = vxlan_id_map_to_service_id(ntohl(vxlan_id));
+ printf("service id from vxlan_id: %u\n", service_id);
+
+ ret = get_rawpkt_opt_from_streaminfo(stream, RAW_PKT_GET_VXLAN_SPORT, &vxlan_sport);
+ if(ret >= 0){
+ printf("[debug], test_get_rawpkt_options get sport:%u\n", ntohs(vxlan_sport));
+ }else{
+ printf("[error], test_get_rawpkt_options VXLAN_SPORT error\n");
+ }
+
+ service_id = vxlan_sport_map_to_service_id(ntohs(vxlan_sport));
+ printf("service id from sport: %u\n", service_id);
+
+ return APP_STATE_GIVEME;
+}
+
+
+
char test_inet_addr_list_addr(const struct streaminfo *stream,void **pme, int thread_seq,const void *raw_pkt)
{
int ret;
diff --git a/test_so/test_ct_plug.c b/test_so/test_ct_plug.c
deleted file mode 100644
index e224181..0000000
--- a/test_so/test_ct_plug.c
+++ /dev/null
@@ -1,69 +0,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-#include <netinet/ip.h>
-#include <netinet/tcp.h>
-#include <netinet/udp.h>
-#include <assert.h>
-#include <time.h>
-#include <arpa/inet.h>
-#include "stream.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define TEST_PLUG_ID (1)
-
-
-
-char test_get_rawpkt_options(struct streaminfo *stream,void **pme, int thread_seq,const void *raw_pkt)
-{
- int ret;
- int gdev_ip;
- int vxlan_id;
- unsigned short vxlan_sport;
- unsigned char service_id;
-
- ret = get_rawpkt_opt_from_streaminfo(stream, RAW_PKT_GET_GDEV_IP, &gdev_ip);
- if(ret >= 0){
- char tmp_ip_str[32];
- inet_ntop(AF_INET, &gdev_ip, tmp_ip_str, 32);
- printf("[debug], test_get_rawpkt_options get gdev-ip:%s\n", tmp_ip_str);
- }else{
- printf("[error], test_get_rawpkt_options error\n");
- }
-
- ret = get_rawpkt_opt_from_streaminfo(stream, RAW_PKT_GET_VXLAN_ID, &vxlan_id);
- if(ret >= 0){
- printf("[debug], test_get_rawpkt_options get vlan-id:%d\n", vxlan_id);
- }else{
- printf("[error], test_get_rawpkt_options error\n");
- }
-
- service_id = vxlan_id_map_to_service_id(ntohl(vxlan_id));
- printf("service id from vxlan_id: %u\n", service_id);
-
- ret = get_rawpkt_opt_from_streaminfo(stream, RAW_PKT_GET_VXLAN_SPORT, &vxlan_sport);
- if(ret >= 0){
- printf("[debug], test_get_rawpkt_options get sport:%u\n", ntohs(vxlan_sport));
- }else{
- printf("[error], test_get_rawpkt_options error\n");
- }
-
- service_id = vxlan_sport_map_to_service_id(ntohs(vxlan_sport));
- printf("service id from sport: %u\n", service_id);
-
- return APP_STATE_GIVEME;
-}
-
-
-int test_ct_init(void)
-{
- printf("test ct plug init SUCC!\n");
- return 1;
-}
-
-#ifdef __cplusplus
-}
-#endif
-
diff --git a/test_so/test_wangyan.c b/test_so/test_wangyan.c
index 3d7c5da..699d870 100644
--- a/test_so/test_wangyan.c
+++ b/test_so/test_wangyan.c
@@ -330,759 +330,6 @@ char test_wangyan_send_ipv6_udp_pkt(struct streaminfo *stream,void **pme, int th
return APP_STATE_GIVEME;
}
-
-typedef struct {
- unsigned char vxlan_smac[6]; /* �����mac */
- unsigned char vxlan_dmac[6]; /* �����mac */
- unsigned int vxlan_sip_net_order;
- unsigned int vxlan_dip_net_order;
- unsigned short vxlan_sport_net_order;
- unsigned short vxlan_dport_net_order;
- int vxlan_link_id;
- int vxlan_vlan_num;
- int sample_pkt_dir; /* ��׼���ݰ�����ʱ�Ĵ��䷽��, C:in-to-out, vxlan dir is 0; I:out-to-int, vxlan dir is 1; */
- int send_pkt_CorI; /* ����ķ�������, �����sample_pkt_dirһ��, �ڲ�macͬ��, ����෴, ��Ҫ���ڲ�MAC���� */
- int inner_layer2_type; /* �ڲ��װ����, Ethernet, PPP, HDLC */
-
- unsigned short inner_sport_net_order;
- unsigned short inner_dport_net_order;
- unsigned int inner_sip_net_order;
- unsigned int inner_dip_net_order;
- unsigned char inner_smac[6];
- unsigned char inner_dmac[6];
- unsigned char payload[1400];
- int payload_len;
- int send_pps; /* ��ֹ��������, �����������ָ��ÿ�뷢������ */
-}send_pkt_para_t;
-
-static send_pkt_para_t g_wangyan_send_fake_pkt_para;
-
-typedef struct{
- int last_record_time;
- unsigned int realtime_pkt_num;
- char __pad[58];
-}send_pkt_realtime_t;
-
-static send_pkt_realtime_t g_wangyan_send_fake_pkt_rt_stat[MAX_THREAD_NUM];
-
-typedef struct {
- int use_which_config; /* 'M', 'N' */
- char para_name[32];
- char para_delime; /* �����ļ��ָ��� */
- char MESA_para_name[32];
- char ONLINE_para_name[32];
- char user_arg[32];
- int (*config_convert)(const char *conf_str, send_pkt_para_t *send_para_bin);
-}send_pkt_conf_parse_t;
-
-#if 0
-static send_pkt_conf_parse_t g_send_pkt_conf_engine[] =
-{
- {'M',"conf_file_name", '=', "./conf/wangyan_send_fake_pkt.conf", "/home/ningsi/new_machine.conf", ""},
- {'N', "vxlan_smac ", ':', "vxlan_smac", "SRC_OUT_MAC", "-"},
- {'N', "vxlan_dmac ", ':', "vxlan_dmac", "DST_OUT_MAC", ":"},
- {'N', "vxlan_sip ", ':', "vxlan_sip", "115_IP", ""},
- {'N', "vxlan_dip ", ':', "vxlan_dip", "GIP", ""},
- {'M',"vxlan_sport ", '=', "vxlan_sport", "", ""},
- {'M',"vxlan_dport ", '=', "vxlan_dport", "", ""},
- {'N', "vxlan_link_id ", ':', "vxlan_link_id", "LINK_ID_VALUE", ""},
- {'N', "vxlan_vlxn_num", ':', "vxlan_vlxn_num", "no", ""},
- {'N', "vxlan_inner_layer2_type" ,':', "vxlan_inner_layer2_type", "LINK_TYPE", ""},
- {'M',"vxlan_trans_dir", '=', "vxlan_trans_dir", "C_DIR", "CorI"},
- {'N', "vxlan_inner_smac", ':', "vxlan_inner_smac", "SRC_IN_MAC", ":"},
- {'N', "vxlan_inner_dmac", ':', "vxlan_inner_dmac", "DST_IN_MAC", ":"}
-}
-
-/*
- #use_which PARA_NAME DELIM MESA_NAME ONLINE_NAME USER_ARG
- #ʹ����Դ
- M conf_file_name = ./conf/wangyan_send_pkt.conf /home/ningsi/new_machine.conf
- N vxlan_smac : vxlan_smac SRC_OUT_MAC -
- N vxlan_dmac : vxlan_dmac DST_OUT_MAC :
- N vxlan_sip : vxlan_sip 115_IP
- N vxlan_dip : vxlan_dip GIP
- M vxlan_sport = vxlan_sport --no
- M vxlan_dport = vxlan_dport --no
- N vxlan_link_id : vxlan_link_id LINK_ID_VALUE
- N vxlan_vlxn_num : vxlan_vlxn_num no
- N vxlan_inner_layer2_type : vxlan_inner_layer2_type LINK_TYPE
- M vxlan_trans_dir = vxlan_trans_dir C_DIR CorI
- N vxlan_inner_smac : vxlan_inner_smac SRC_IN_MAC :
- N vxlan_inner_dmac : vxlan_inner_dmac DST_IN_MAC :
-
-*/
-#endif
-
-/* ��ȡningsi�������ļ�, û��[main], [module]��section, �Լ�ģ��mesa_prof_loadʵ��һ�� */
-static int __load_profile_string_no_section(const char *filename, const char *key, int delim, char out_value[256])
-{
- FILE *fp;
- char tmp_line[1024];
- char *start_ptr;
- int index;
-
- fp = fopen(filename, "r");
- if(NULL == fp){
- printf("open file %s error, %s\n", filename, strerror(errno));
- return -1;
- }
-
- memset(tmp_line, 0, 1024);
-
- while(fgets(tmp_line, 1024, fp) != NULL){
- index = 0;
- del_last_rn(tmp_line, 1024);
-
- if('#' == tmp_line[0]){
- continue;
- }
-
- if(strncasecmp(key, tmp_line, strlen(key)) == 0){
- start_ptr = memchr(tmp_line, delim, 1024);
- if(start_ptr == NULL){ /* �޷ָ��� */
- continue;
- }
- start_ptr++;
- while((start_ptr[index] == ' ' ) || (start_ptr[index] == '\t')){
- index++;
- }
-
- strncpy(out_value, start_ptr+index, strlen(start_ptr+index)+1);
-
- fclose(fp);
- return 0;
- }
-
- memset(tmp_line, 0, 1024);
- }
-
- fclose(fp);
-
- printf("config key %s not found!\n", key);
-
- return -1;
-}
-
-static int wangyan_send_fake_pkt_init(void)
-{
- char config_file[1024];
- char tmp_str[256];
- int tmp_int;
- unsigned short tmp_short;
- int ret;
-
- MESA_load_profile_string_def("./conf/wangyan_send_fake_pkt.conf", "main", "config_file_name", config_file, 1024, "/home/ningsi/new_machine.conf");
-
- MESA_load_profile_int_def("./conf/wangyan_send_fake_pkt.conf", "main", "send_pps", &g_wangyan_send_fake_pkt_para.send_pps, 1);
-
- MESA_load_profile_string_def("./conf/wangyan_send_fake_pkt.conf", "main", "send_CorI", tmp_str, 256, "I");
- if(tmp_str[0] == 'C'){
- g_wangyan_send_fake_pkt_para.send_pkt_CorI = 0;
- }else if(tmp_str[0] == 'I'){
- g_wangyan_send_fake_pkt_para.send_pkt_CorI = 1;
- }else{
- printf("get config %s error, onlye support C or I!\n", "send_CorI");
- return -1;
- }
-
- /********** SRC_OUT_MAC **********/
- ret = __load_profile_string_no_section(config_file, "SRC_OUT_MAC", ':', tmp_str);
- if(ret < 0){
- printf("get config %s error!\n", "SRC_OUT_MAC");
- return -1;
- }
- ret = MESA_mac_pton(tmp_str, '-', (char *)g_wangyan_send_fake_pkt_para.vxlan_smac);
- if(ret < 0){
- ret = MESA_mac_pton(tmp_str, ':', (char *)g_wangyan_send_fake_pkt_para.vxlan_smac);
- if(ret < 0){
- printf("parse config %s error!\n", "SRC_OUT_MAC");
- return -1;
- }
- }
-
- /********** DST_OUT_MAC **********/
- ret = __load_profile_string_no_section(config_file, "DST_OUT_MAC", ':', tmp_str);
- if(ret < 0){
- printf("get config %s error!\n", "DST_OUT_MAC");
- return -1;
- }
- ret = MESA_mac_pton(tmp_str, '-', (char *)g_wangyan_send_fake_pkt_para.vxlan_dmac);
- if(ret < 0){
- ret = MESA_mac_pton(tmp_str, ':', (char *)g_wangyan_send_fake_pkt_para.vxlan_dmac);
- if(ret < 0){
- printf("parse config %s error!\n", "DST_OUT_MAC");
- return -1;
- }
- }
-
- /********** 115_IP **********/
- ret = __load_profile_string_no_section(config_file, "115_IP", ':', tmp_str);
- if(ret < 0){
- printf("get config %s error!\n", "115_IP");
- return -1;
- }
- ret = inet_pton(AF_INET, tmp_str, &g_wangyan_send_fake_pkt_para.vxlan_sip_net_order);
- if(ret <= 0){
- printf("parse config %s error!\n", "115_IP");
- return -1;
- }
-
- /********** GIP **********/
- ret = __load_profile_string_no_section(config_file, "GIP", ':', tmp_str);
- if(ret < 0){
- ret = __load_profile_string_no_section(config_file, "G_IP", ':', tmp_str); /* ��Щ�����ļ���һ��, GIP, G_IP���� */
- if(ret < 0){
- printf("get config %s error!\n", "G_IP");
- return -1;
- }
- }
- ret = inet_pton(AF_INET, tmp_str, &g_wangyan_send_fake_pkt_para.vxlan_dip_net_order);
- if(ret <= 0){
- printf("parse config %s error!\n", "G_IP");
- return -1;
- }
-
- /********** vxlan_sport **********/
- MESA_load_profile_int_def("./conf/wangyan_send_fake_pkt.conf", "ningsi_no_config", "vxlan_sport", &tmp_int, 50704);
- if(tmp_int <= 0 || tmp_int > 65535){
- printf("parse config %s error!\n", "vxlan_sport");
- return -1;
- }
- tmp_short = tmp_int;
- g_wangyan_send_fake_pkt_para.vxlan_sport_net_order = ntohs(tmp_short);
-
-
- /********** vxlan_dport **********/
- MESA_load_profile_int_def("./conf/wangyan_send_fake_pkt.conf", "ningsi_no_config", "vxlan_dport", &tmp_int, 4789);
- if(tmp_int <= 0 || tmp_int > 65535){
- printf("parse config %s error!\n", "vxlan_dport");
- return -1;
- }
- tmp_short = tmp_int;
- g_wangyan_send_fake_pkt_para.vxlan_dport_net_order = ntohs(tmp_short);
-
-
- /********** LINK_ID_VALUE **********/
- ret = __load_profile_string_no_section(config_file, "LINK_ID_VALUE", ':', tmp_str);
- if(ret < 0){
- printf("get config %s error!\n", "LINK_ID_VALUE");
- return -1;
- }
- tmp_int = atoi(tmp_str);
- if(tmp_int< 0 || tmp_int > 64){ /* link id �ܳ�6bit, ��ֵ��Χ[0,63] */
- printf("parse config %s error!\n", "LINK_ID_VALUE");
- return -1;
- }
- g_wangyan_send_fake_pkt_para.vxlan_link_id = tmp_int;
-
-
-
- /********** vxlan_vlxn_num **********/
- MESA_load_profile_int_def("./conf/wangyan_send_fake_pkt.conf", "ningsi_no_config", "vxlan_vlan_num", &tmp_int, 115);
- if(tmp_int <= 0 || tmp_int > 4096){
- printf("parse config %s error!\n", "vxlan_vlxn_num");
- return -1;
- }
- if(tmp_int < 0 || tmp_int > 4096){
- printf("parse config %s error!\n", "vxlan_vlxn_num");
- return -1;
- }
- g_wangyan_send_fake_pkt_para.vxlan_vlan_num = tmp_int;
-
-
- /********** LINK_TYPE **********/
- ret = __load_profile_string_no_section(config_file, "LINK_TYPE", ':', tmp_str);
- if(ret < 0){
- printf("get config %s error!\n", "LINK_TYPE");
- return -1;
- }
- tmp_int = atoi(tmp_str);
-
- if(tmp_int == 0){
- g_wangyan_send_fake_pkt_para.inner_layer2_type = TUNNAT_TUNNEL_TYPE_ETHER;
- }else if(tmp_int = 0x80){
- g_wangyan_send_fake_pkt_para.inner_layer2_type = TUNNAT_TUNNEL_TYPE_PPP;
- }else if(tmp_int = 0xC0){
- g_wangyan_send_fake_pkt_para.inner_layer2_type = TUNNAT_TUNNEL_TYPE_HDLC;
- }else{
- printf("parse config %s error!\n", "LINK_TYPE");
- return -1;
- }
- g_wangyan_send_fake_pkt_para.inner_layer2_type = tmp_int;
-
-
- /********** CorI **********/
- ret = __load_profile_string_no_section(config_file, "CorI", ':', tmp_str);
- if(ret < 0){
- printf("get config %s error!\n", "CorI");
- return -1;
- }
- if(tmp_str[0] == 'C'){
- g_wangyan_send_fake_pkt_para.sample_pkt_dir = 0;
- }else if(tmp_str[0] == 'I'){
- g_wangyan_send_fake_pkt_para.sample_pkt_dir = 1;
- }else{
- printf("parse config %s error!\n", "CorI");
- return -1;
- }
-
- /********** inner sport **********/
- MESA_load_profile_int_def("./conf/wangyan_send_fake_pkt.conf", "ningsi_no_config", "inner_sport", &tmp_int, 8888);
- if(tmp_int <= 0 || tmp_int > 65535){
- printf("parse config %s error!\n", "inner_sport");
- return -1;
- }
- tmp_short = tmp_int;
- g_wangyan_send_fake_pkt_para.inner_sport_net_order = ntohs(tmp_short);
-
- /********** inner dport **********/
- MESA_load_profile_int_def("./conf/wangyan_send_fake_pkt.conf", "ningsi_no_config", "inner_dport", &tmp_int, 8888);
- if(tmp_int <= 0 || tmp_int > 65535){
- printf("parse config %s error!\n", "inner_dport");
- return -1;
- }
- tmp_short = tmp_int;
- g_wangyan_send_fake_pkt_para.inner_dport_net_order = ntohs(tmp_short);
-
-
- /********** inner_sip **********/
- memset(tmp_str, 0, sizeof(tmp_str));
- MESA_load_profile_string_nodef("./conf/wangyan_send_fake_pkt.conf", "ningsi_no_config", "inner_sip", tmp_str, sizeof(tmp_str));
-
- ret = inet_pton(AF_INET, tmp_str, &g_wangyan_send_fake_pkt_para.inner_sip_net_order);
- if(ret <= 0){
- printf("parse config %s error, %s!\n", "inner_sip", strerror(errno));
- return -1;
- }
-
- /********** inner_dip **********/
- memset(tmp_str, 0, sizeof(tmp_str));
- MESA_load_profile_string_nodef("./conf/wangyan_send_fake_pkt.conf", "ningsi_no_config", "inner_dip", tmp_str, sizeof(tmp_str));
-
- ret = inet_pton(AF_INET, tmp_str, &g_wangyan_send_fake_pkt_para.inner_dip_net_order);
- if(ret <= 0){
- printf("parse config %s error, %s!\n", "inner_dip", strerror(errno));
- return -1;
- }
-
- /********** SRC_IN_MAC **********/
- ret = __load_profile_string_no_section(config_file, "SRC_IN_MAC", ':', tmp_str);
- if(ret < 0){
- printf("get config %s error!\n", "SRC_IN_MAC");
- return -1;
- }
- ret = MESA_mac_pton(tmp_str, ':', (char *)g_wangyan_send_fake_pkt_para.inner_smac);
- if(ret < 0){
- ret = MESA_mac_pton(tmp_str, '-', (char *)g_wangyan_send_fake_pkt_para.inner_smac);
- if(ret < 0){
- printf("parse config %s error!\n", "SRC_IN_MAC");
- return -1;
- }
- }
-
- /********** DST_IN_MAC **********/
- ret = __load_profile_string_no_section(config_file, "DST_IN_MAC", ':', tmp_str);
- if(ret < 0){
- printf("get config %s error!\n", "DST_IN_MAC");
- return -1;
- }
- ret = MESA_mac_pton(tmp_str, ':', (char *)g_wangyan_send_fake_pkt_para.inner_dmac);
- if(ret < 0){
- ret = MESA_mac_pton(tmp_str, '-', (char *)g_wangyan_send_fake_pkt_para.inner_dmac);
- if(ret < 0){
- printf("parse config %s error!\n", "DST_IN_MAC");
- return -1;
- }
- }
-
- /********** payload **********/
-
- MESA_load_profile_string_def("./conf/wangyan_send_fake_pkt.conf", "ningsi_no_config", "payload", g_wangyan_send_fake_pkt_para.payload, sizeof(g_wangyan_send_fake_pkt_para.payload), "test send fake packet");
- g_wangyan_send_fake_pkt_para.payload_len = strlen(g_wangyan_send_fake_pkt_para.payload);
-
-
- return 0;
-}
-
-
-static int wangyan_polling_cb_send_control(int tid)
-{
- if(g_wangyan_send_fake_pkt_rt_stat[tid].realtime_pkt_num > g_wangyan_send_fake_pkt_para.send_pps){
- /* �������������, ��ʱ����һ��ͳ��������(1����) */
- if(g_wangyan_send_fake_pkt_rt_stat[tid].last_record_time >= g_CurrentTime){
- return 0;
- }else{
- g_wangyan_send_fake_pkt_rt_stat[tid].last_record_time = g_CurrentTime;
- g_wangyan_send_fake_pkt_rt_stat[tid].realtime_pkt_num = 0;
- return 1;
- }
- }
-
- return 1;
-}
-
-/*
- inside outside
-
- >------------->C(vxlan dir = 0)------------------->
-
- <--------------I(vxlan dir = 1)-------------------<
-
-
- if ningsi.conf->CorI is C, means sample packet from inside to outside, vxlan dir flag is 0;
- if ningsi.conf->CorI is I, means sample packet from outside to inside, vxlan dir flag is 1;
-*/
-
-char wangyan_polling_cb_send_fake_pkt_udp(struct streaminfo *__stream,void **__pme, int thread_seq,const void *__raw_pkt)
-{
-
- struct streaminfo phony_stream;
- SAPP_TLV_T option[32];
- int option_num = 0;
- int vxlan_link_id = 1;
-
- if(0 == wangyan_polling_cb_send_control(thread_seq)){
- return APP_STATE_GIVEME;
- }
-
- phony_stream.threadnum = thread_seq; /* ������ṹ��, MESA_fakepacket_send_udp_options()������Ҫ�߳�id, �˴���ֵ���� */
-
- option[option_num].type = SAPP_SEND_OPT_GDEV_SMAC;
- option[option_num].length = 6;
- memcpy(option[option_num].array_value, g_wangyan_send_fake_pkt_para.vxlan_smac, 6);
- option_num++;////////
- option[option_num].type = SAPP_SEND_OPT_GDEV_DMAC;
- option[option_num].length = 6;
- memcpy(option[option_num].array_value, g_wangyan_send_fake_pkt_para.vxlan_dmac, 6);
- option_num++;///////
- option[option_num].type = SAPP_SEND_OPT_GDEV_SIP;
- option[option_num].length = 4;
- option[option_num].int_value = g_wangyan_send_fake_pkt_para.vxlan_sip_net_order;
- option_num++;///////
- option[option_num].type = SAPP_SEND_OPT_GDEV_DIP;
- option[option_num].length = 4;
- option[option_num].int_value = g_wangyan_send_fake_pkt_para.vxlan_dip_net_order;;
- option_num++;///////
- option[option_num].type = SAPP_SEND_OPT_GDEV_UDP_SPORT;
- option[option_num].length = 2;
-// option[option_num].short_value = ntohs(g_wangyan_send_fake_pkt_para.vxlan_sport_net_order);
- option[option_num].short_value = g_wangyan_send_fake_pkt_para.vxlan_sport_net_order;
- option_num++;///////
- option[option_num].type = SAPP_SEND_OPT_GDEV_UDP_DPORT;
- option[option_num].length = 2;
- option[option_num].short_value = ntohs(g_wangyan_send_fake_pkt_para.vxlan_dport_net_order);
- option_num++;///////
-
- option[option_num].type = SAPP_SEND_OPT_VXLAN_VPN_ID;
- option[option_num].length = 4;
-// option[option_num].int_value = htonl(g_wangyan_send_fake_pkt_para.vxlan_vlan_num);
- option[option_num].int_value = g_wangyan_send_fake_pkt_para.vxlan_vlan_num;
- option_num++;///////
-
- option[option_num].type = SAPP_SEND_OPT_VXLAN_LINK_ID;
- option[option_num].length = 4;
- option[option_num].int_value = g_wangyan_send_fake_pkt_para.vxlan_link_id;
- option_num++;///////
-
- option[option_num].type = SAPP_SEND_OPT_VXLAN_LINK_ENCAP_TYPE;
- option[option_num].length = 1;
- option[option_num].char_value = TUNNAT_TUNNEL_TYPE_ETHER;
- option_num++;///////
- option[option_num].type = SAPP_SEND_OPT_VXLAN_LINK_DIR;
- option[option_num].length = 1;
- option[option_num].char_value = g_wangyan_send_fake_pkt_para.send_pkt_CorI;
- option_num++;///////
- option[option_num].type = SAPP_SEND_OPT_INNER_LINK_ENCAP_TYPE;
- option[option_num].length = 1;
- option[option_num].char_value = TUNNAT_TUNNEL_TYPE_ETHER;
- option_num++;///////
-
- /* ��������ͬ, ���轻���ڲ�MAC����, IP�Ͷ˿��������ļ���д, �ϸ����û�����, �����޸� */
- option[option_num].type = SAPP_SEND_OPT_INNER_SMAC;
- option[option_num].length = 6;
- if(g_wangyan_send_fake_pkt_para.sample_pkt_dir == g_wangyan_send_fake_pkt_para.send_pkt_CorI){
- memcpy(option[option_num].array_value, g_wangyan_send_fake_pkt_para.inner_smac, 6);
- }else{
- memcpy(option[option_num].array_value, g_wangyan_send_fake_pkt_para.inner_dmac, 6);
- }
- option_num++;///////
-
- option[option_num].type = SAPP_SEND_OPT_INNER_DMAC;
- option[option_num].length = 6;
- if(g_wangyan_send_fake_pkt_para.sample_pkt_dir == g_wangyan_send_fake_pkt_para.send_pkt_CorI){
- memcpy(option[option_num].array_value, g_wangyan_send_fake_pkt_para.inner_dmac, 6);
- }else{
- memcpy(option[option_num].array_value, g_wangyan_send_fake_pkt_para.inner_smac, 6);
- }
- option_num++;///////
-
- MESA_fakepacket_send_udp_options(&phony_stream,
- ntohl(g_wangyan_send_fake_pkt_para.inner_sip_net_order),
- ntohl(g_wangyan_send_fake_pkt_para.inner_dip_net_order),
- ntohs(g_wangyan_send_fake_pkt_para.inner_sport_net_order),
- ntohs(g_wangyan_send_fake_pkt_para.inner_dport_net_order),
- g_wangyan_send_fake_pkt_para.payload,
- g_wangyan_send_fake_pkt_para.payload_len,
- g_wangyan_send_fake_pkt_para.send_pkt_CorI,
- option,
- option_num);
-
- g_wangyan_send_fake_pkt_rt_stat[thread_seq].realtime_pkt_num++;
-
- return APP_STATE_GIVEME;
-}
-
-char wangyan_polling_cb_send_fake_pkt_tcp(struct streaminfo *__stream,void **__pme, int thread_seq,const void *__raw_pkt)
-{
- struct streaminfo phony_stream;
- SAPP_TLV_T option[32];
- int option_num = 0;
- int vxlan_link_id = 1;
-
- if(0 == wangyan_polling_cb_send_control(thread_seq)){
- return APP_STATE_GIVEME;
- }
-
- phony_stream.threadnum = thread_seq; /* ������ṹ��, MESA_fakepacket_send_udp_options()������Ҫ�߳�id, �˴���ֵ���� */
-
- option[option_num].type = SAPP_SEND_OPT_GDEV_SMAC;
- option[option_num].length = 6;
- memcpy(option[option_num].array_value, g_wangyan_send_fake_pkt_para.vxlan_smac, 6);
- option_num++;////////
- option[option_num].type = SAPP_SEND_OPT_GDEV_DMAC;
- option[option_num].length = 6;
- memcpy(option[option_num].array_value, g_wangyan_send_fake_pkt_para.vxlan_dmac, 6);
- option_num++;///////
- option[option_num].type = SAPP_SEND_OPT_GDEV_SIP;
- option[option_num].length = 4;
- option[option_num].int_value = g_wangyan_send_fake_pkt_para.vxlan_sip_net_order;
- option_num++;///////
- option[option_num].type = SAPP_SEND_OPT_GDEV_DIP;
- option[option_num].length = 4;
- option[option_num].int_value = g_wangyan_send_fake_pkt_para.vxlan_dip_net_order;;
- option_num++;///////
- option[option_num].type = SAPP_SEND_OPT_GDEV_UDP_SPORT;
- option[option_num].length = 2;
-// option[option_num].short_value = ntohs(g_wangyan_send_fake_pkt_para.vxlan_sport_net_order);
- option[option_num].short_value = g_wangyan_send_fake_pkt_para.vxlan_sport_net_order;
- option_num++;///////
- option[option_num].type = SAPP_SEND_OPT_GDEV_UDP_DPORT;
- option[option_num].length = 2;
- option[option_num].short_value = ntohs(g_wangyan_send_fake_pkt_para.vxlan_dport_net_order);
- option_num++;///////
-
-
- option[option_num].type = SAPP_SEND_OPT_VXLAN_VPN_ID;
- option[option_num].length = 4;
-// option[option_num].int_value = htonl(g_wangyan_send_fake_pkt_para.vxlan_vlan_num);
- option[option_num].int_value = g_wangyan_send_fake_pkt_para.vxlan_vlan_num;
- option_num++;///////
-
- option[option_num].type = SAPP_SEND_OPT_VXLAN_LINK_ID;
- option[option_num].length = 4;
- option[option_num].int_value = g_wangyan_send_fake_pkt_para.vxlan_link_id;
- option_num++;///////
-
- option[option_num].type = SAPP_SEND_OPT_VXLAN_LINK_ENCAP_TYPE;
- option[option_num].length = 1;
- option[option_num].char_value = TUNNAT_TUNNEL_TYPE_ETHER;
- option_num++;///////
- option[option_num].type = SAPP_SEND_OPT_VXLAN_LINK_DIR;
- option[option_num].length = 1;
- option[option_num].char_value = g_wangyan_send_fake_pkt_para.send_pkt_CorI;
- option_num++;///////
- option[option_num].type = SAPP_SEND_OPT_INNER_LINK_ENCAP_TYPE;
- option[option_num].length = 1;
- option[option_num].char_value = TUNNAT_TUNNEL_TYPE_ETHER;
- option_num++;///////
-
- /* ��������ͬ, ���轻���ڲ�MAC����, IP�Ͷ˿��������ļ���д, �ϸ����û�����, �����޸� */
- option[option_num].type = SAPP_SEND_OPT_INNER_SMAC;
- option[option_num].length = 6;
- if(g_wangyan_send_fake_pkt_para.sample_pkt_dir == g_wangyan_send_fake_pkt_para.send_pkt_CorI){
- memcpy(option[option_num].array_value, g_wangyan_send_fake_pkt_para.inner_smac, 6);
- }else{
- memcpy(option[option_num].array_value, g_wangyan_send_fake_pkt_para.inner_dmac, 6);
- }
- option_num++;///////
-
- option[option_num].type = SAPP_SEND_OPT_INNER_DMAC;
- option[option_num].length = 6;
- if(g_wangyan_send_fake_pkt_para.sample_pkt_dir == g_wangyan_send_fake_pkt_para.send_pkt_CorI){
- memcpy(option[option_num].array_value, g_wangyan_send_fake_pkt_para.inner_dmac, 6);
- }else{
- memcpy(option[option_num].array_value, g_wangyan_send_fake_pkt_para.inner_smac, 6);
- }
- option_num++;///////
-
- MESA_fakepacket_send_tcp_options(&phony_stream,
- ntohl(g_wangyan_send_fake_pkt_para.inner_sip_net_order),
- ntohl(g_wangyan_send_fake_pkt_para.inner_dip_net_order),
- ntohs(g_wangyan_send_fake_pkt_para.inner_sport_net_order),
- ntohs(g_wangyan_send_fake_pkt_para.inner_dport_net_order),
- 0x12345678,
- 0x87654321,
- 0x2,
- g_wangyan_send_fake_pkt_para.payload,
- g_wangyan_send_fake_pkt_para.payload_len,
- g_wangyan_send_fake_pkt_para.send_pkt_CorI,
- option,
- option_num);
-
- g_wangyan_send_fake_pkt_rt_stat[thread_seq].realtime_pkt_num++;
-
- return APP_STATE_GIVEME;
-}
-
-
-char wangyan_polling_cb_send_fake_pkt_iplayer(struct streaminfo *__stream, void **__pme, int thread_seq,const void *__raw_pkt)
-{
- char snd_pkt_payload[] =
- {
- /* ICMP request, from 8.8.8.8 to 192.168.11.129 */
- 0x45,0x00,0x00,0x54,0x00,0x00,0x40,0x00,
- 0x40,0x01,0x19,0xF9,
- 0x8,0x8,0x8,0x8,
- 0xC0,0xA8,0x0B,0x81,
- 0x08,0x00,0xC2,0x6A,0x18,0x8B,0x00,0x07,
- 0xE5,0xB8,0xA8,0x54,0x00,0x00,0x00,0x00,
- 0x22,0x5C,0x06,
- 0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0xAA,0xBB,0xCC,0xDD,0xEE,0xFF
- };
-
- if(0 == wangyan_polling_cb_send_control(thread_seq)){
- return APP_STATE_GIVEME;
- }
-
- SAPP_TLV_T option[32];
- int option_num = 0;
- int vxlan_link_id = 1;
-
- option[option_num].type = SAPP_SEND_OPT_GDEV_SMAC;
- option[option_num].length = 6;
- memcpy(option[option_num].array_value, g_wangyan_send_fake_pkt_para.vxlan_smac, 6);
- option_num++;////////
- option[option_num].type = SAPP_SEND_OPT_GDEV_DMAC;
- option[option_num].length = 6;
- memcpy(option[option_num].array_value, g_wangyan_send_fake_pkt_para.vxlan_dmac, 6);
- option_num++;///////
- option[option_num].type = SAPP_SEND_OPT_GDEV_SIP;
- option[option_num].length = 4;
- option[option_num].int_value = g_wangyan_send_fake_pkt_para.vxlan_sip_net_order;
- option_num++;///////
- option[option_num].type = SAPP_SEND_OPT_GDEV_DIP;
- option[option_num].length = 4;
- option[option_num].int_value = g_wangyan_send_fake_pkt_para.vxlan_dip_net_order;;
- option_num++;///////
- option[option_num].type = SAPP_SEND_OPT_GDEV_UDP_SPORT;
- option[option_num].length = 2;
-// option[option_num].short_value = ntohs(g_wangyan_send_fake_pkt_para.vxlan_sport_net_order);
- option[option_num].short_value = g_wangyan_send_fake_pkt_para.vxlan_sport_net_order;
- option_num++;///////
- option[option_num].type = SAPP_SEND_OPT_GDEV_UDP_DPORT;
- option[option_num].length = 2;
- option[option_num].short_value = ntohs(g_wangyan_send_fake_pkt_para.vxlan_dport_net_order);
- option_num++;///////
-
-
- option[option_num].type = SAPP_SEND_OPT_VXLAN_VPN_ID;
- option[option_num].length = 4;
-// option[option_num].int_value = htonl(g_wangyan_send_fake_pkt_para.vxlan_vlan_num);
- option[option_num].int_value = g_wangyan_send_fake_pkt_para.vxlan_vlan_num;
- option_num++;///////
-
- option[option_num].type = SAPP_SEND_OPT_VXLAN_LINK_ID;
- option[option_num].length = 4;
- option[option_num].int_value = g_wangyan_send_fake_pkt_para.vxlan_link_id;
- option_num++;///////
-
- option[option_num].type = SAPP_SEND_OPT_VXLAN_LINK_ENCAP_TYPE;
- option[option_num].length = 1;
- option[option_num].char_value = TUNNAT_TUNNEL_TYPE_ETHER;
- option_num++;///////
- option[option_num].type = SAPP_SEND_OPT_VXLAN_LINK_DIR;
- option[option_num].length = 1;
- option[option_num].char_value = g_wangyan_send_fake_pkt_para.send_pkt_CorI;
- option_num++;///////
- option[option_num].type = SAPP_SEND_OPT_INNER_LINK_ENCAP_TYPE;
- option[option_num].length = 1;
- option[option_num].char_value = TUNNAT_TUNNEL_TYPE_ETHER;
- option_num++;///////
-
- /* ��������ͬ, ���轻���ڲ�MAC����, IP�Ͷ˿��������ļ���д, �ϸ����û�����, �����޸� */
- option[option_num].type = SAPP_SEND_OPT_INNER_SMAC;
- option[option_num].length = 6;
- if(g_wangyan_send_fake_pkt_para.sample_pkt_dir == g_wangyan_send_fake_pkt_para.send_pkt_CorI){
- memcpy(option[option_num].array_value, g_wangyan_send_fake_pkt_para.inner_smac, 6);
- }else{
- memcpy(option[option_num].array_value, g_wangyan_send_fake_pkt_para.inner_dmac, 6);
- }
- option_num++;///////
-
- option[option_num].type = SAPP_SEND_OPT_INNER_DMAC;
- option[option_num].length = 6;
- if(g_wangyan_send_fake_pkt_para.sample_pkt_dir == g_wangyan_send_fake_pkt_para.send_pkt_CorI){
- memcpy(option[option_num].array_value, g_wangyan_send_fake_pkt_para.inner_dmac, 6);
- }else{
- memcpy(option[option_num].array_value, g_wangyan_send_fake_pkt_para.inner_smac, 6);
- }
- option_num++;///////
-
- MESA_sendpacket_iplayer_options(thread_seq,
- snd_pkt_payload,
- sizeof(snd_pkt_payload),
- g_wangyan_send_fake_pkt_para.send_pkt_CorI,
- option,
- option_num);
-
- g_wangyan_send_fake_pkt_rt_stat[thread_seq].realtime_pkt_num++;
-
- return APP_STATE_GIVEME;
-}
-#if 0
-static void *test_gdev_get_opt(void *arg)
-{
- SAPP_TLV_T sapp_tlv;
-
- sapp_tlv.type = GDEV_KEEPALIVE_OPT_RCV_PKT_PPS;
- sapp_tlv.length = sizeof(long);
-
- while(1){
- sapp_tlv.type = GDEV_KEEPALIVE_OPT_RCV_PKT_PPS;
- gdev_keepalive_get_opt(&sapp_tlv);
- printf("GDEV_KEEPALIVE rcv pps:%ld\n", sapp_tlv.long_value);
-
- sapp_tlv.type = GDEV_KEEPALIVE_OPT_SND_PKT_PPS;
- gdev_keepalive_get_opt(&sapp_tlv);
- printf("GDEV_KEEPALIVE snd pps:%ld\n", sapp_tlv.long_value);
-
- sleep(1);
- }
-
- return NULL;
-}
-#endif
-
-
-char test_pkt_action(int net_conn_mode, char plug_action)
-{
- char ret = 1;
-
- if(plug_action == 1){
- ret = 0;
- }
-
- printf("test_pkt_action_cb return DROP!\n");
-
- return ret;
-}
-
-
static void *plug_thread_send(void *arg)
{
int send_tid;
@@ -1138,24 +385,30 @@ static void *plug_thread_send(void *arg)
return NULL;
}
-int test_wangyan_init(void)
+char test_pkt_action(int net_conn_mode, char plug_action)
{
- int ret;
- pthread_t tid;
+ char ret = 1;
+
+ if(plug_action == 1){
+ ret = 0;
+ }
- pthread_create(&tid, NULL, plug_thread_send, NULL);
+ printf("test_pkt_action_cb return DROP!\n");
- //platform_register_action_judge(test_pkt_action);
-
- //pthread_create(&tid, NULL, test_shengkou_thread, NULL);
+ return ret;
+}
- //pthread_create(&tid, NULL, wangyan_send_fake_pkt_thread, NULL);
- ret = wangyan_send_fake_pkt_init();
+int test_wangyan_init(void)
+{
+ pthread_t tid;
+
+ pthread_create(&tid, NULL, plug_thread_send, NULL);
- return ret;
+ return 0;
}
+
#ifdef __cplusplus
}
#endif
diff --git a/test_so/wangyan_gdev_measurement.c b/test_so/wangyan_gdev_measurement.c
new file mode 100644
index 0000000..96f6435
--- /dev/null
+++ b/test_so/wangyan_gdev_measurement.c
@@ -0,0 +1,952 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <netinet/ip.h>
+#include <netinet/tcp.h>
+#include <netinet/udp.h>
+#include <assert.h>
+#include <time.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <arpa/inet.h>
+#include <dirent.h>
+#include "stream.h"
+#include "stream_control.h"
+#include "mesa_net.h"
+#include "gserial_sendpacket.h"
+#include "gdev_keepalive.h"
+#include "mrtunnat.h"
+#include "sysinfo.h"
+#include "MESA_handle_logger.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#define GDEV_MEASURE_CONF_DIR "conf/wangyan_gdev_measure/"
+#define GDEV_MEASURE_MAX_NUM (32) /* ���ͬʱ֧�ֶ��ٸ�����ʵ�� */
+#define GDEV_MEASURE_SEND_MSS (1400)
+
+
+
+
+typedef struct {
+ /****** NingSi config ******/
+ unsigned char vxlan_smac[6]; /* �����mac */
+ unsigned char vxlan_dmac[6]; /* �����mac */
+ unsigned int vxlan_sip_net_order;
+ unsigned int vxlan_dip_net_order;
+ unsigned short vxlan_sport_net_order;
+ unsigned short vxlan_dport_net_order;
+ char vxlan_link_dir; /* ԭʼ��׼����vxlan->link_dirֵ */
+ int vxlan_link_id;
+ int vxlan_vlan_num;
+ int sample_pkt_dir; /* ��׼���ݰ�����ʱ�Ĵ��䷽��, C:in-to-out, vxlan dir is 0; I:out-to-in, vxlan dir is 1; */
+ int send_pkt_CorI; /* ����ķ�������, �����sample_pkt_dirһ��, �ڲ�macͬ��, ����෴, ��Ҫ���ڲ�MAC���� */
+ int inner_layer2_type; /* �ڲ��װ����, Ethernet, PPP, HDLC */
+
+ /****** Gdev Measure plug config ******/
+ unsigned short inner_sport_net_order;
+ unsigned short inner_dport_net_order;
+ unsigned int inner_sip_net_order;
+ unsigned int inner_dip_net_order;
+ unsigned char inner_smac[6];
+ unsigned char inner_dmac[6];
+ unsigned char payload[GDEV_MEASURE_SEND_MSS];
+ unsigned char transport_layer_type; /* tcp or udp */
+ unsigned char transport_tcp_flags; /* SYN, FIN, RST, etc. */
+ int payload_len;
+ int send_pps; /* ��ֹ��������, �����������ָ��ÿ�뷢������ */
+}send_pkt_para_t;
+
+typedef struct{
+ send_pkt_para_t send_pkt_para;
+ int send_pkt_num;
+ time_t last_send_time;
+}wangyan_gdev_measure_instance_t;
+
+
+static wangyan_gdev_measure_instance_t wangyan_gdev_measure_instance_set[GDEV_MEASURE_MAX_NUM];
+static int wangyan_gdev_measure_instance_num = 0;
+
+typedef struct{
+ int last_record_time;
+ unsigned int realtime_pkt_num;
+ char __pad[58];
+}send_pkt_realtime_t;
+
+static send_pkt_realtime_t g_wangyan_send_fake_pkt_rt_stat[MAX_THREAD_NUM];
+
+static void *gdev_measure_logh;
+
+extern int get_thread_count(void);
+extern time_t g_CurrentTime;
+#if 0
+
+typedef struct {
+ int use_which_config; /* 'M', 'N' */
+ char para_name[32];
+ char para_delime; /* �����ļ��ָ��� */
+ char MESA_para_name[32];
+ char ONLINE_para_name[32];
+ char user_arg[32];
+ int (*config_convert)(const char *conf_str, send_pkt_para_t *send_para_bin);
+}send_pkt_conf_parse_t;
+
+
+static send_pkt_conf_parse_t g_send_pkt_conf_engine[] =
+{
+ {'M',"conf_file_name", '=', "./conf/wangyan_send_fake_pkt.conf", "/home/ningsi/new_machine.conf", ""},
+ {'N', "vxlan_smac ", ':', "vxlan_smac", "SRC_OUT_MAC", "-"},
+ {'N', "vxlan_dmac ", ':', "vxlan_dmac", "DST_OUT_MAC", ":"},
+ {'N', "vxlan_sip ", ':', "vxlan_sip", "115_IP", ""},
+ {'N', "vxlan_dip ", ':', "vxlan_dip", "GIP", ""},
+ {'M',"vxlan_sport ", '=', "vxlan_sport", "", ""},
+ {'M',"vxlan_dport ", '=', "vxlan_dport", "", ""},
+ {'N', "vxlan_link_id ", ':', "vxlan_link_id", "LINK_ID_VALUE", ""},
+ {'N', "vxlan_vlxn_num", ':', "vxlan_vlxn_num", "no", ""},
+ {'N', "vxlan_inner_layer2_type" ,':', "vxlan_inner_layer2_type", "LINK_TYPE", ""},
+ {'M',"vxlan_trans_dir", '=', "vxlan_trans_dir", "C_DIR", "CorI"},
+ {'N', "vxlan_inner_smac", ':', "vxlan_inner_smac", "SRC_IN_MAC", ":"},
+ {'N', "vxlan_inner_dmac", ':', "vxlan_inner_dmac", "DST_IN_MAC", ":"}
+}
+
+/*
+ #use_which PARA_NAME DELIM MESA_NAME ONLINE_NAME USER_ARG
+ #ʹ����Դ
+ M conf_file_name = ./conf/wangyan_send_pkt.conf /home/ningsi/new_machine.conf
+ N vxlan_smac : vxlan_smac SRC_OUT_MAC -
+ N vxlan_dmac : vxlan_dmac DST_OUT_MAC :
+ N vxlan_sip : vxlan_sip 115_IP
+ N vxlan_dip : vxlan_dip GIP
+ M vxlan_sport = vxlan_sport --no
+ M vxlan_dport = vxlan_dport --no
+ N vxlan_link_id : vxlan_link_id LINK_ID_VALUE
+ N vxlan_vlxn_num : vxlan_vlxn_num no
+ N vxlan_inner_layer2_type : vxlan_inner_layer2_type LINK_TYPE
+ M vxlan_trans_dir = vxlan_trans_dir C_DIR CorI
+ N vxlan_inner_smac : vxlan_inner_smac SRC_IN_MAC :
+ N vxlan_inner_dmac : vxlan_inner_dmac DST_IN_MAC :
+
+*/
+#endif
+
+/* ��ȡNingSi�������ļ�, û��[main], [module]��section, �޷�ֱ��ʹ��prof_load�ӿ�, �Լ�ģ��mesa_prof_loadʵ��һ�� */
+static int __load_profile_string_no_section(const char *filename, const char *key, int delim, char out_value[256])
+{
+ FILE *fp;
+ char tmp_line[1024];
+ char *start_ptr;
+ int index;
+
+ fp = fopen(filename, "r");
+ if(NULL == fp){
+ printf("open file %s error, %s\n", filename, strerror(errno));
+ return -1;
+ }
+
+ memset(tmp_line, 0, 1024);
+
+ while(fgets(tmp_line, 1024, fp) != NULL){
+ index = 0;
+ del_last_rn(tmp_line, 1024);
+
+ if('#' == tmp_line[0]){
+ continue;
+ }
+
+ if(strncasecmp(key, tmp_line, strlen(key)) == 0){
+ start_ptr = memchr(tmp_line, delim, 1024);
+ if(start_ptr == NULL){ /* �޷ָ��� */
+ continue;
+ }
+ start_ptr++;
+ while((start_ptr[index] == ' ' ) || (start_ptr[index] == '\t')){
+ index++;
+ }
+
+ strncpy(out_value, start_ptr+index, strlen(start_ptr+index)+1);
+
+ fclose(fp);
+ return 0;
+ }
+
+ memset(tmp_line, 0, 1024);
+ }
+
+ fclose(fp);
+
+ printf("config key %s not found!\n", key);
+
+ return -1;
+}
+
+static int wangyan_gdev_measure_parse_config(const char *config_file, wangyan_gdev_measure_instance_t *tmp_ins)
+{
+ char tmp_str[256];
+ int tmp_int;
+ unsigned short tmp_short;
+ int ret;
+
+
+ /********** SRC_OUT_MAC **********/
+ ret = __load_profile_string_no_section(config_file, "SRC_OUT_MAC", ':', tmp_str);
+ if(ret < 0){
+ printf("get config %s error!\n", "SRC_OUT_MAC");
+ return -1;
+ }
+ ret = MESA_mac_pton(tmp_str, '-', (char *)tmp_ins->send_pkt_para.vxlan_smac);
+ if(ret < 0){
+ ret = MESA_mac_pton(tmp_str, ':', (char *)tmp_ins->send_pkt_para.vxlan_smac);
+ if(ret < 0){
+ printf("parse config %s error, '%s'!\n", "SRC_OUT_MAC", tmp_str);
+ return -1;
+ }
+ }
+
+ /********** DST_OUT_MAC **********/
+ ret = __load_profile_string_no_section(config_file, "DST_OUT_MAC", ':', tmp_str);
+ if(ret < 0){
+ printf("get config %s error!\n", "DST_OUT_MAC");
+ return -1;
+ }
+ ret = MESA_mac_pton(tmp_str, '-', (char *)tmp_ins->send_pkt_para.vxlan_dmac);
+ if(ret < 0){
+ ret = MESA_mac_pton(tmp_str, ':', (char *)tmp_ins->send_pkt_para.vxlan_dmac);
+ if(ret < 0){
+ printf("parse config %s error, %s!\n", "DST_OUT_MAC", tmp_str);
+ return -1;
+ }
+ }
+
+ /********** 115_IP, NingSi��115_IP, Ҳ����ǰ�˻���IP **********/
+ ret = __load_profile_string_no_section(config_file, "115_IP", ':', tmp_str);
+ if(ret < 0){
+ printf("get config %s error!\n", "115_IP");
+ return -1;
+ }
+ ret = inet_pton(AF_INET, tmp_str, &tmp_ins->send_pkt_para.vxlan_sip_net_order);
+ if(ret <= 0){
+ printf("parse config %s error, %s!\n", "115_IP", tmp_str);
+ return -1;
+ }
+
+ /********** GIP **********/
+ ret = __load_profile_string_no_section(config_file, "GIP", ':', tmp_str);
+ if(ret < 0){
+ /* NingSi��Щ�����ļ���һ��, GIP, G_IP����, ���������Զ�һ������ */
+ ret = __load_profile_string_no_section(config_file, "G_IP", ':', tmp_str);
+ if(ret < 0){
+ printf("get config %s error!\n", "G_IP");
+ return -1;
+ }
+ }
+ ret = inet_pton(AF_INET, tmp_str, &tmp_ins->send_pkt_para.vxlan_dip_net_order);
+ if(ret <= 0){
+ printf("parse config %s error, %s!\n", "G_IP", tmp_str);
+ return -1;
+ }
+
+ /********** LINK_ID_VALUE **********/
+ ret = __load_profile_string_no_section(config_file, "LINK_ID_VALUE", ':', tmp_str);
+ if(ret < 0){
+ printf("get config %s error!\n", "LINK_ID_VALUE");
+ return -1;
+ }
+ tmp_int = atoi(tmp_str);
+ if(tmp_int< 0 || tmp_int > 64){ /* link id �ܳ�6bit, ��ֵ��Χ[0,63] */
+ printf("parse config %s error!\n", "LINK_ID_VALUE");
+ return -1;
+ }
+ tmp_ins->send_pkt_para.vxlan_link_id = tmp_int;
+
+ /********** LINK_TYPE **********/
+ ret = __load_profile_string_no_section(config_file, "LINK_TYPE", ':', tmp_str);
+ if(ret < 0){
+ printf("get config %s error!\n", "LINK_TYPE");
+ return -1;
+ }
+ tmp_int = atoi(tmp_str);
+
+ if(tmp_int == 0){
+ tmp_ins->send_pkt_para.inner_layer2_type = TUNNAT_TUNNEL_TYPE_ETHER;
+ }else if(tmp_int = 0x80){
+ tmp_ins->send_pkt_para.inner_layer2_type = TUNNAT_TUNNEL_TYPE_PPP;
+ }else if(tmp_int = 0xC0){
+ tmp_ins->send_pkt_para.inner_layer2_type = TUNNAT_TUNNEL_TYPE_HDLC;
+ }else{
+ printf("parse config %s error!\n", "LINK_TYPE");
+ return -1;
+ }
+
+ /************** C_DIR ***************/
+ ret = __load_profile_string_no_section(config_file, "C_DIR", ':', tmp_str);
+ if(ret < 0){
+ printf("get config %s error!\n", "C_DIR");
+ return -1;
+ }
+ tmp_int = atoi(tmp_str);
+ if(tmp_int != 0 && tmp_int != 1){
+ printf("Invalid config %s:%s!\n", "C_DIR", tmp_str);
+ return -1;
+ }
+ tmp_ins->send_pkt_para.vxlan_link_dir = (char)tmp_int;
+
+ /********** CorI **********/
+ ret = __load_profile_string_no_section(config_file, "CorI", ':', tmp_str);
+ if(ret < 0){
+ printf("get config %s error!\n", "CorI");
+ return -1;
+ }
+ if(tmp_str[0] == 'C'){
+ tmp_ins->send_pkt_para.sample_pkt_dir = 0;
+ }else if(tmp_str[0] == 'I'){
+ tmp_ins->send_pkt_para.sample_pkt_dir = 1;
+ }else{
+ printf("parse config %s error!\n", "CorI");
+ return -1;
+ }
+
+ /********** SRC_IN_MAC **********/
+ ret = __load_profile_string_no_section(config_file, "SRC_IN_MAC", ':', tmp_str);
+ if(ret < 0){
+ printf("get config %s error!\n", "SRC_IN_MAC");
+ return -1;
+ }
+ ret = MESA_mac_pton(tmp_str, ':', (char *)tmp_ins->send_pkt_para.inner_smac);
+ if(ret < 0){
+ ret = MESA_mac_pton(tmp_str, '-', (char *)tmp_ins->send_pkt_para.inner_smac);
+ if(ret < 0){
+ printf("parse config %s error!\n", "SRC_IN_MAC");
+ return -1;
+ }
+ }
+
+ /********** DST_IN_MAC **********/
+ ret = __load_profile_string_no_section(config_file, "DST_IN_MAC", ':', tmp_str);
+ if(ret < 0){
+ printf("get config %s error!\n", "DST_IN_MAC");
+ return -1;
+ }
+ ret = MESA_mac_pton(tmp_str, ':', (char *)tmp_ins->send_pkt_para.inner_dmac);
+ if(ret < 0){
+ ret = MESA_mac_pton(tmp_str, '-', (char *)tmp_ins->send_pkt_para.inner_dmac);
+ if(ret < 0){
+ printf("parse config %s error!\n", "DST_IN_MAC");
+ return -1;
+ }
+ }
+
+ /***************** wangyan dev measure plug config **********************/
+
+ /********** transport type ************************/
+ MESA_load_profile_string_def(config_file, "plug", "transport_type", tmp_str, 256, "tcp");
+ if(strncasecmp(tmp_str, "tcp", 3) == 0){
+ tmp_ins->send_pkt_para.transport_layer_type = IPPROTO_TCP;
+ }else if(strncasecmp(tmp_str, "udp", 3) == 0){
+ tmp_ins->send_pkt_para.transport_layer_type = IPPROTO_UDP;
+ }else{
+ printf("parse config %s error, only uspport tcp or udp!\n", "transport_type");
+ return -1;
+ }
+
+ /********** transport type ************************/
+ MESA_load_profile_string_def(config_file, "plug", "transport_tcp_flags", tmp_str, 256, "0x2");
+ if(strncasecmp(tmp_str, "0x", 2) == 0){
+ tmp_ins->send_pkt_para.transport_tcp_flags = (unsigned char)strtoul(tmp_str, NULL, 16);
+ }else{
+ tmp_ins->send_pkt_para.transport_tcp_flags = (unsigned char)strtoul(tmp_str, NULL, 10);
+ }
+
+ /********** send pps **********/
+ MESA_load_profile_int_def(config_file, "plug", "send_pps", &tmp_int, 1);
+ if(tmp_int < 1 || tmp_int > 1000){
+ printf("parse config %s error, pps valid range=[1,1000]!\n", "send_pps");
+ return -1;
+ }
+ tmp_ins->send_pkt_para.send_pps = tmp_int;
+
+ /***************** send_CorI ************************/
+ MESA_load_profile_string_def(config_file, "plug", "send_CorI", tmp_str, 256, "#");
+ if(tmp_str[0] == 'C'){
+ tmp_ins->send_pkt_para.send_pkt_CorI = 0;
+ }else if(tmp_str[0] == 'I'){
+ tmp_ins->send_pkt_para.send_pkt_CorI = 1;
+ }else{
+ printf("parse config %s error!\n", "send_CorI");
+ return -1;
+ }
+
+ /********** vxlan_sport **********/
+ MESA_load_profile_int_def(config_file, "plug", "vxlan_sport", &tmp_int, 50704);
+ if(tmp_int <= 0 || tmp_int > 65535){
+ printf("parse config %s error!\n", "vxlan_sport");
+ return -1;
+ }
+ tmp_short = tmp_int;
+ tmp_ins->send_pkt_para.vxlan_sport_net_order = ntohs(tmp_short);
+
+
+ /********** vxlan_dport **********/
+ MESA_load_profile_int_def(config_file, "plug", "vxlan_dport", &tmp_int, 4789);
+ if(tmp_int <= 0 || tmp_int > 65535){
+ printf("parse config %s error!\n", "vxlan_dport");
+ return -1;
+ }
+ tmp_short = tmp_int;
+ tmp_ins->send_pkt_para.vxlan_dport_net_order = ntohs(tmp_short);
+
+
+ /********** vxlan_vlxn_num **********/
+ MESA_load_profile_int_def(config_file, "plug", "vxlan_vlan_num", &tmp_int, 115);
+ if(tmp_int <= 0 || tmp_int > 4096){
+ printf("parse config %s error!\n", "vxlan_vlxn_num");
+ return -1;
+ }
+ if(tmp_int < 0 || tmp_int > 4096){
+ printf("parse config %s error!\n", "vxlan_vlxn_num");
+ return -1;
+ }
+ tmp_ins->send_pkt_para.vxlan_vlan_num = tmp_int;
+
+
+ /********** inner sport **********/
+ MESA_load_profile_int_def(config_file, "plug", "inner_sport", &tmp_int, 8888);
+ if(tmp_int <= 0 || tmp_int > 65535){
+ printf("parse config %s error!\n", "inner_sport");
+ return -1;
+ }
+ tmp_short = tmp_int;
+ tmp_ins->send_pkt_para.inner_sport_net_order = ntohs(tmp_short);
+
+ /********** inner dport **********/
+ MESA_load_profile_int_def(config_file, "plug", "inner_dport", &tmp_int, 8888);
+ if(tmp_int <= 0 || tmp_int > 65535){
+ printf("parse config %s error!\n", "inner_dport");
+ return -1;
+ }
+ tmp_short = tmp_int;
+ tmp_ins->send_pkt_para.inner_dport_net_order = ntohs(tmp_short);
+
+
+ /********** inner_sip **********/
+ memset(tmp_str, 0, sizeof(tmp_str));
+ MESA_load_profile_string_nodef(config_file, "plug", "inner_sip", tmp_str, sizeof(tmp_str));
+
+ ret = inet_pton(AF_INET, tmp_str, &tmp_ins->send_pkt_para.inner_sip_net_order);
+ if(ret <= 0){
+ printf("parse config %s error, %s!\n", "inner_sip", strerror(errno));
+ return -1;
+ }
+
+ /********** inner_dip **********/
+ memset(tmp_str, 0, sizeof(tmp_str));
+ MESA_load_profile_string_nodef(config_file, "plug", "inner_dip", tmp_str, sizeof(tmp_str));
+
+ ret = inet_pton(AF_INET, tmp_str, &tmp_ins->send_pkt_para.inner_dip_net_order);
+ if(ret <= 0){
+ printf("parse config %s error, %s!\n", "inner_dip", strerror(errno));
+ return -1;
+ }
+
+ /********** payload **********/
+
+ MESA_load_profile_string_def(config_file, "plug", "payload", tmp_ins->send_pkt_para.payload, sizeof(tmp_ins->send_pkt_para.payload), "test send fake packet");
+ tmp_ins->send_pkt_para.payload_len = strlen(tmp_ins->send_pkt_para.payload);
+
+ return 0;
+}
+
+
+/*
+ inside outside
+
+ >------------->C(vxlan dir = 0)------------------->
+
+ <--------------I(vxlan dir = 1)-------------------<
+
+
+ if ningsi.conf->CorI is C, means sample packet from inside to outside, vxlan dir flag is 0;
+ if ningsi.conf->CorI is I, means sample packet from outside to inside, vxlan dir flag is 1;
+*/
+
+char wangyan_polling_cb_send_fake_pkt_udp(int thread_seq, wangyan_gdev_measure_instance_t *instance)
+{
+
+ struct streaminfo phony_stream;
+ SAPP_TLV_T option[32];
+ int option_num = 0;
+
+ phony_stream.threadnum = thread_seq; /* ������ṹ��, MESA_fakepacket_send_udp_options()������Ҫ�߳�id, �˴���ֵ���� */
+
+ option[option_num].type = SAPP_SEND_OPT_GDEV_SMAC;
+ option[option_num].length = 6;
+ memcpy(option[option_num].array_value, instance->send_pkt_para.vxlan_smac, 6);
+ option_num++;////////
+ option[option_num].type = SAPP_SEND_OPT_GDEV_DMAC;
+ option[option_num].length = 6;
+ memcpy(option[option_num].array_value, instance->send_pkt_para.vxlan_dmac, 6);
+ option_num++;///////
+ option[option_num].type = SAPP_SEND_OPT_GDEV_SIP;
+ option[option_num].length = 4;
+ option[option_num].int_value = instance->send_pkt_para.vxlan_sip_net_order;
+ option_num++;///////
+ option[option_num].type = SAPP_SEND_OPT_GDEV_DIP;
+ option[option_num].length = 4;
+ option[option_num].int_value = instance->send_pkt_para.vxlan_dip_net_order;;
+ option_num++;///////
+ option[option_num].type = SAPP_SEND_OPT_GDEV_UDP_SPORT;
+ option[option_num].length = 2;
+// option[option_num].short_value = ntohs(instance->send_pkt_para.vxlan_sport_net_order);
+ option[option_num].short_value = instance->send_pkt_para.vxlan_sport_net_order;
+ option_num++;///////
+ option[option_num].type = SAPP_SEND_OPT_GDEV_UDP_DPORT;
+ option[option_num].length = 2;
+ option[option_num].short_value = ntohs(instance->send_pkt_para.vxlan_dport_net_order);
+ option_num++;///////
+
+ option[option_num].type = SAPP_SEND_OPT_VXLAN_VPN_ID;
+ option[option_num].length = 4;
+// option[option_num].int_value = htonl(instance->send_pkt_para.vxlan_vlan_num);
+ option[option_num].int_value = instance->send_pkt_para.vxlan_vlan_num;
+ option_num++;///////
+
+ option[option_num].type = SAPP_SEND_OPT_VXLAN_LINK_ID;
+ option[option_num].length = 4;
+ option[option_num].int_value = instance->send_pkt_para.vxlan_link_id;
+ option_num++;///////
+
+ option[option_num].type = SAPP_SEND_OPT_VXLAN_LINK_ENCAP_TYPE;
+ option[option_num].length = 1;
+ option[option_num].char_value = TUNNAT_TUNNEL_TYPE_ETHER;
+ option_num++;///////
+
+ option[option_num].type = SAPP_SEND_OPT_VXLAN_LINK_DIR;
+ option[option_num].length = 1;
+ if(instance->send_pkt_para.sample_pkt_dir == instance->send_pkt_para.send_pkt_CorI){
+ option[option_num].char_value = instance->send_pkt_para.vxlan_link_dir;
+ }else{
+ option[option_num].char_value = instance->send_pkt_para.vxlan_link_dir ^ 1;
+ }
+ option_num++;///////
+
+ option[option_num].type = SAPP_SEND_OPT_INNER_LINK_ENCAP_TYPE;
+ option[option_num].length = 1;
+ option[option_num].char_value = TUNNAT_TUNNEL_TYPE_ETHER;
+ option_num++;///////
+
+ /* ��������ͬ, ���轻���ڲ�MAC����, IP�Ͷ˿��������ļ���д, �ϸ����û�����, �����޸� */
+ option[option_num].type = SAPP_SEND_OPT_INNER_SMAC;
+ option[option_num].length = 6;
+ if(instance->send_pkt_para.sample_pkt_dir == instance->send_pkt_para.send_pkt_CorI){
+ memcpy(option[option_num].array_value, instance->send_pkt_para.inner_smac, 6);
+ }else{
+ memcpy(option[option_num].array_value, instance->send_pkt_para.inner_dmac, 6);
+ }
+ option_num++;///////
+
+ option[option_num].type = SAPP_SEND_OPT_INNER_DMAC;
+ option[option_num].length = 6;
+ if(instance->send_pkt_para.sample_pkt_dir == instance->send_pkt_para.send_pkt_CorI){
+ memcpy(option[option_num].array_value, instance->send_pkt_para.inner_dmac, 6);
+ }else{
+ memcpy(option[option_num].array_value, instance->send_pkt_para.inner_smac, 6);
+ }
+ option_num++;///////
+
+ MESA_fakepacket_send_udp_options(&phony_stream,
+ ntohl(instance->send_pkt_para.inner_sip_net_order),
+ ntohl(instance->send_pkt_para.inner_dip_net_order),
+ ntohs(instance->send_pkt_para.inner_sport_net_order),
+ ntohs(instance->send_pkt_para.inner_dport_net_order),
+ instance->send_pkt_para.payload,
+ instance->send_pkt_para.payload_len,
+ instance->send_pkt_para.send_pkt_CorI,
+ option,
+ option_num);
+
+ g_wangyan_send_fake_pkt_rt_stat[thread_seq].realtime_pkt_num++;
+
+ return APP_STATE_GIVEME;
+}
+
+char wangyan_polling_cb_send_fake_pkt_tcp(int thread_seq, wangyan_gdev_measure_instance_t *instance)
+{
+ struct streaminfo phony_stream;
+ SAPP_TLV_T option[32];
+ int option_num = 0;
+
+ phony_stream.threadnum = thread_seq; /* ������ṹ��, MESA_fakepacket_send_udp_options()������Ҫ�߳�id, �˴���ֵ���� */
+
+ option[option_num].type = SAPP_SEND_OPT_GDEV_SMAC;
+ option[option_num].length = 6;
+ memcpy(option[option_num].array_value, instance->send_pkt_para.vxlan_smac, 6);
+ option_num++;////////
+ option[option_num].type = SAPP_SEND_OPT_GDEV_DMAC;
+ option[option_num].length = 6;
+ memcpy(option[option_num].array_value, instance->send_pkt_para.vxlan_dmac, 6);
+ option_num++;///////
+ option[option_num].type = SAPP_SEND_OPT_GDEV_SIP;
+ option[option_num].length = 4;
+ option[option_num].int_value = instance->send_pkt_para.vxlan_sip_net_order;
+ option_num++;///////
+ option[option_num].type = SAPP_SEND_OPT_GDEV_DIP;
+ option[option_num].length = 4;
+ option[option_num].int_value = instance->send_pkt_para.vxlan_dip_net_order;;
+ option_num++;///////
+ option[option_num].type = SAPP_SEND_OPT_GDEV_UDP_SPORT;
+ option[option_num].length = 2;
+// option[option_num].short_value = ntohs(instance->send_pkt_para.vxlan_sport_net_order);
+ option[option_num].short_value = instance->send_pkt_para.vxlan_sport_net_order;
+ option_num++;///////
+ option[option_num].type = SAPP_SEND_OPT_GDEV_UDP_DPORT;
+ option[option_num].length = 2;
+ option[option_num].short_value = ntohs(instance->send_pkt_para.vxlan_dport_net_order);
+ option_num++;///////
+
+
+ option[option_num].type = SAPP_SEND_OPT_VXLAN_VPN_ID;
+ option[option_num].length = 4;
+// option[option_num].int_value = htonl(instance->send_pkt_para.vxlan_vlan_num);
+ option[option_num].int_value = instance->send_pkt_para.vxlan_vlan_num;
+ option_num++;///////
+
+ option[option_num].type = SAPP_SEND_OPT_VXLAN_LINK_ID;
+ option[option_num].length = 4;
+ option[option_num].int_value = instance->send_pkt_para.vxlan_link_id;
+ option_num++;///////
+
+ option[option_num].type = SAPP_SEND_OPT_VXLAN_LINK_ENCAP_TYPE;
+ option[option_num].length = 1;
+ option[option_num].char_value = TUNNAT_TUNNEL_TYPE_ETHER;
+ option_num++;///////
+
+
+ option[option_num].type = SAPP_SEND_OPT_VXLAN_LINK_DIR;
+ option[option_num].length = 1;
+ if(instance->send_pkt_para.sample_pkt_dir == instance->send_pkt_para.send_pkt_CorI){
+ option[option_num].char_value = instance->send_pkt_para.vxlan_link_dir;
+ }else{
+ option[option_num].char_value = instance->send_pkt_para.vxlan_link_dir ^ 1;
+ }
+ option_num++;///////
+
+
+ option[option_num].type = SAPP_SEND_OPT_INNER_LINK_ENCAP_TYPE;
+ option[option_num].length = 1;
+ option[option_num].char_value = TUNNAT_TUNNEL_TYPE_ETHER;
+ option_num++;///////
+
+ /* ��������ͬ, ���轻���ڲ�MAC����, IP�Ͷ˿��������ļ���д, �ϸ����û�����, �����޸� */
+ option[option_num].type = SAPP_SEND_OPT_INNER_SMAC;
+ option[option_num].length = 6;
+ if(instance->send_pkt_para.sample_pkt_dir == instance->send_pkt_para.send_pkt_CorI){
+ memcpy(option[option_num].array_value, instance->send_pkt_para.inner_smac, 6);
+ }else{
+ memcpy(option[option_num].array_value, instance->send_pkt_para.inner_dmac, 6);
+ }
+ option_num++;///////
+
+ option[option_num].type = SAPP_SEND_OPT_INNER_DMAC;
+ option[option_num].length = 6;
+ if(instance->send_pkt_para.sample_pkt_dir == instance->send_pkt_para.send_pkt_CorI){
+ memcpy(option[option_num].array_value, instance->send_pkt_para.inner_dmac, 6);
+ }else{
+ memcpy(option[option_num].array_value, instance->send_pkt_para.inner_smac, 6);
+ }
+ option_num++;///////
+
+ MESA_fakepacket_send_tcp_options(&phony_stream,
+ ntohl(instance->send_pkt_para.inner_sip_net_order),
+ ntohl(instance->send_pkt_para.inner_dip_net_order),
+ ntohs(instance->send_pkt_para.inner_sport_net_order),
+ ntohs(instance->send_pkt_para.inner_dport_net_order),
+ 0x12345678,
+ 0x87654321,
+ instance->send_pkt_para.transport_tcp_flags,
+ instance->send_pkt_para.payload,
+ instance->send_pkt_para.payload_len,
+ instance->send_pkt_para.send_pkt_CorI,
+ option,
+ option_num);
+
+ g_wangyan_send_fake_pkt_rt_stat[thread_seq].realtime_pkt_num++;
+
+ return APP_STATE_GIVEME;
+}
+
+#if 0
+char wangyan_polling_cb_send_fake_pkt_iplayer(struct streaminfo *__stream, void **__pme, int thread_seq,const void *__raw_pkt)
+{
+ char snd_pkt_payload[] =
+ {
+ /* ICMP request, from 8.8.8.8 to 192.168.11.129 */
+ 0x45,0x00,0x00,0x54,0x00,0x00,0x40,0x00,
+ 0x40,0x01,0x19,0xF9,
+ 0x8,0x8,0x8,0x8,
+ 0xC0,0xA8,0x0B,0x81,
+ 0x08,0x00,0xC2,0x6A,0x18,0x8B,0x00,0x07,
+ 0xE5,0xB8,0xA8,0x54,0x00,0x00,0x00,0x00,
+ 0x22,0x5C,0x06,
+ 0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0xAA,0xBB,0xCC,0xDD,0xEE,0xFF
+ };
+
+ if(0 == wangyan_polling_cb_send_control(thread_seq)){
+ return APP_STATE_GIVEME;
+ }
+
+ SAPP_TLV_T option[32];
+ int option_num = 0;
+ int vxlan_link_id = 1;
+
+ option[option_num].type = SAPP_SEND_OPT_GDEV_SMAC;
+ option[option_num].length = 6;
+ memcpy(option[option_num].array_value, instance->send_pkt_para.vxlan_smac, 6);
+ option_num++;////////
+ option[option_num].type = SAPP_SEND_OPT_GDEV_DMAC;
+ option[option_num].length = 6;
+ memcpy(option[option_num].array_value, instance->send_pkt_para.vxlan_dmac, 6);
+ option_num++;///////
+ option[option_num].type = SAPP_SEND_OPT_GDEV_SIP;
+ option[option_num].length = 4;
+ option[option_num].int_value = instance->send_pkt_para.vxlan_sip_net_order;
+ option_num++;///////
+ option[option_num].type = SAPP_SEND_OPT_GDEV_DIP;
+ option[option_num].length = 4;
+ option[option_num].int_value = instance->send_pkt_para.vxlan_dip_net_order;;
+ option_num++;///////
+ option[option_num].type = SAPP_SEND_OPT_GDEV_UDP_SPORT;
+ option[option_num].length = 2;
+// option[option_num].short_value = ntohs(instance->send_pkt_para.vxlan_sport_net_order);
+ option[option_num].short_value = instance->send_pkt_para.vxlan_sport_net_order;
+ option_num++;///////
+ option[option_num].type = SAPP_SEND_OPT_GDEV_UDP_DPORT;
+ option[option_num].length = 2;
+ option[option_num].short_value = ntohs(instance->send_pkt_para.vxlan_dport_net_order);
+ option_num++;///////
+
+
+ option[option_num].type = SAPP_SEND_OPT_VXLAN_VPN_ID;
+ option[option_num].length = 4;
+// option[option_num].int_value = htonl(instance->send_pkt_para.vxlan_vlan_num);
+ option[option_num].int_value = instance->send_pkt_para.vxlan_vlan_num;
+ option_num++;///////
+
+ option[option_num].type = SAPP_SEND_OPT_VXLAN_LINK_ID;
+ option[option_num].length = 4;
+ option[option_num].int_value = instance->send_pkt_para.vxlan_link_id;
+ option_num++;///////
+
+ option[option_num].type = SAPP_SEND_OPT_VXLAN_LINK_ENCAP_TYPE;
+ option[option_num].length = 1;
+ option[option_num].char_value = TUNNAT_TUNNEL_TYPE_ETHER;
+ option_num++;///////
+ option[option_num].type = SAPP_SEND_OPT_VXLAN_LINK_DIR;
+ option[option_num].length = 1;
+ option[option_num].char_value = instance->send_pkt_para.send_pkt_CorI;
+ option_num++;///////
+ option[option_num].type = SAPP_SEND_OPT_INNER_LINK_ENCAP_TYPE;
+ option[option_num].length = 1;
+ option[option_num].char_value = TUNNAT_TUNNEL_TYPE_ETHER;
+ option_num++;///////
+
+ /* ��������ͬ, ���轻���ڲ�MAC����, IP�Ͷ˿��������ļ���д, �ϸ����û�����, �����޸� */
+ option[option_num].type = SAPP_SEND_OPT_INNER_SMAC;
+ option[option_num].length = 6;
+ if(instance->send_pkt_para.sample_pkt_dir == instance->send_pkt_para.send_pkt_CorI){
+ memcpy(option[option_num].array_value, instance->send_pkt_para.inner_smac, 6);
+ }else{
+ memcpy(option[option_num].array_value, instance->send_pkt_para.inner_dmac, 6);
+ }
+ option_num++;///////
+
+ option[option_num].type = SAPP_SEND_OPT_INNER_DMAC;
+ option[option_num].length = 6;
+ if(instance->send_pkt_para.sample_pkt_dir == instance->send_pkt_para.send_pkt_CorI){
+ memcpy(option[option_num].array_value, instance->send_pkt_para.inner_dmac, 6);
+ }else{
+ memcpy(option[option_num].array_value, instance->send_pkt_para.inner_smac, 6);
+ }
+ option_num++;///////
+
+ MESA_sendpacket_iplayer_options(thread_seq,
+ snd_pkt_payload,
+ sizeof(snd_pkt_payload),
+ instance->send_pkt_para.send_pkt_CorI,
+ option,
+ option_num);
+
+ g_wangyan_send_fake_pkt_rt_stat[thread_seq].realtime_pkt_num++;
+
+ return APP_STATE_GIVEME;
+}
+#endif
+#if 0
+static void *test_gdev_get_opt(void *arg)
+{
+ SAPP_TLV_T sapp_tlv;
+
+ sapp_tlv.type = GDEV_KEEPALIVE_OPT_RCV_PKT_PPS;
+ sapp_tlv.length = sizeof(long);
+
+ while(1){
+ sapp_tlv.type = GDEV_KEEPALIVE_OPT_RCV_PKT_PPS;
+ gdev_keepalive_get_opt(&sapp_tlv);
+ printf("GDEV_KEEPALIVE rcv pps:%ld\n", sapp_tlv.long_value);
+
+ sapp_tlv.type = GDEV_KEEPALIVE_OPT_SND_PKT_PPS;
+ gdev_keepalive_get_opt(&sapp_tlv);
+ printf("GDEV_KEEPALIVE snd pps:%ld\n", sapp_tlv.long_value);
+
+ sleep(1);
+ }
+
+ return NULL;
+}
+#endif
+
+
+static void wangyan_gdev_measure_send_pkt(int thread_seq, wangyan_gdev_measure_instance_t *instance)
+{
+ if(instance->last_send_time == g_CurrentTime){
+ if(instance->send_pkt_num >= instance->send_pkt_para.send_pps){
+ return;
+ }
+ }else{
+ instance->last_send_time = g_CurrentTime;
+ instance->send_pkt_num = 0;
+ }
+
+ if(IPPROTO_TCP == instance->send_pkt_para.transport_layer_type){
+ wangyan_polling_cb_send_fake_pkt_tcp(thread_seq, instance);
+ }else{
+ wangyan_polling_cb_send_fake_pkt_udp(thread_seq, instance);
+ }
+
+ instance->send_pkt_num++;
+}
+
+
+char wangyan_gdev_measure_polling_cb(struct streaminfo *__stream, void **__pme, int thread_seq, const void *__raw_pkt)
+{
+ int i;
+
+ if(0 != thread_seq){
+ /* ��ʱ��֧��һ���̷߳���, ʹ��0���߳� */
+ return APP_STATE_GIVEME;
+ }
+
+ for(i = 0; i < wangyan_gdev_measure_instance_num; i++){
+ wangyan_gdev_measure_send_pkt(thread_seq, &wangyan_gdev_measure_instance_set[i]);
+ }
+
+ return APP_STATE_GIVEME;
+}
+
+
+static int wangyan_gdev_measure_add_new_instance(wangyan_gdev_measure_instance_t *tmp_ins)
+{
+ if(wangyan_gdev_measure_instance_num >= GDEV_MEASURE_MAX_NUM){
+ printf("\033[1;31;40m[Error]instance number is over limit %d![0m\n", GDEV_MEASURE_MAX_NUM);
+ MESA_handle_runtime_log(gdev_measure_logh, 30, "gdev", "instance number is over limit %d!", GDEV_MEASURE_MAX_NUM);
+ return -1;
+ }
+
+ memcpy(&wangyan_gdev_measure_instance_set[wangyan_gdev_measure_instance_num], tmp_ins, sizeof(wangyan_gdev_measure_instance_t));
+ wangyan_gdev_measure_instance_num++;
+
+ return 0;
+}
+
+
+static int iterate_readdir(const char *conf_dir)
+{
+ struct stat fstat;
+ char tmp_file_name[PATH_MAX];
+ DIR *dir_h;
+ struct dirent *file_h;
+ int ret;
+ wangyan_gdev_measure_instance_t tmp_ins;
+
+ stat(conf_dir, &fstat);
+
+ if(!S_ISDIR( fstat.st_mode)){
+ printf("\033[1;31;40m[Error]%s is not dir!\033[0m\n", conf_dir);
+ MESA_handle_runtime_log(gdev_measure_logh, 30, "gdev", "%s is not dir!", conf_dir);
+ return -1;
+ }
+
+ dir_h = opendir(conf_dir);
+ if(NULL == dir_h){
+ printf("\033[1;31;40m[Error]opendir %s error!\033[0m\n", conf_dir);
+ MESA_handle_runtime_log(gdev_measure_logh, 30, "gdev", "opendir %s error!", conf_dir);
+ return -1;
+ }
+
+ while((file_h = readdir(dir_h)) != NULL){
+ if(strncmp(file_h->d_name, ".", 1) == 0){ /* ��ǰĿ¼���� */
+ continue;
+ }
+ if(strncmp(file_h->d_name, "..", 2) == 0){ /* ��һ��Ŀ¼���� */
+ continue;
+ }
+
+ snprintf(tmp_file_name, PATH_MAX, "%s/%s", conf_dir, file_h->d_name);
+
+ stat(tmp_file_name, &fstat); /* XFS�ļ�ϵͳ, d_type��ȡ��׼ */
+
+ if(!S_ISREG(fstat.st_mode)){
+ continue; /* ����ͨ�ļ� */
+ }else{
+ memset(&tmp_ins, 0, sizeof(tmp_ins));
+ ret = wangyan_gdev_measure_parse_config(tmp_file_name, &tmp_ins);
+ if(ret >= 0){
+ wangyan_gdev_measure_add_new_instance(&tmp_ins);
+ }
+ }
+ }
+
+ closedir(dir_h);
+
+ MESA_handle_runtime_log(gdev_measure_logh, 10, "gdev", "parse conf succ, total valid config num:%d\n", wangyan_gdev_measure_instance_num);
+
+ return 0;
+}
+
+
+
+int wangyan_gdev_measure_init(void)
+{
+ int ret;
+
+ gdev_measure_logh = MESA_create_runtime_log_handle("./log/gdev_measure.log", 10);
+
+ if(get_thread_count() != 1){
+ printf("\033[1;31;40m[Error]wangyan_gdev_measure plug not support multithread!\033[0m\n");
+ }
+
+ iterate_readdir(GDEV_MEASURE_CONF_DIR);
+
+ if(wangyan_gdev_measure_instance_num <= 0){
+ printf("\033[1;31;40m[Error]No valid config in %s!\033[0m\n", GDEV_MEASURE_CONF_DIR);
+ MESA_handle_runtime_log(gdev_measure_logh, 30, "gdev", "No valid config in %s!", GDEV_MEASURE_CONF_DIR);
+ return -1;
+ }
+
+ return 0;
+}
+
+
+#ifdef __cplusplus
+}
+#endif
+
+