summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorlijia <[email protected]>2019-05-27 18:14:11 +0800
committerlijia <[email protected]>2019-05-27 18:14:11 +0800
commitab2ca4f32203cf5d00d6810a220316fd74ce1007 (patch)
tree228c2870261b18b96858ff93d217a232ab295a35 /test
parentc708b41686b6026ec0cc4096bd5ef5f3eb5cff3e (diff)
测试串联模式收发包、回注功能, 修复一些问题.
Diffstat (limited to 'test')
-rw-r--r--test/Makefile5
-rw-r--r--test/g_device_plug.c197
-rw-r--r--test/wangyan_gdev_measurement.c43
3 files changed, 21 insertions, 224 deletions
diff --git a/test/Makefile b/test/Makefile
index b788026..d65f471 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -8,6 +8,7 @@ MODULES =
BIN_PATH = ../bin/
TARGET = test_app_sapp.so
+TARGET += wangyan_gdev_measurement.so
#TARGET += test_anti_flood_hijack
INCS =
@@ -46,6 +47,10 @@ test_http.so:test_http.o
test_anti_flood_hijack:test_anti_flood_hijack.c ../lib/libavltree.a
g++ -o $@ $(CFLAGS) $^ -I../inner_plug -I../support/avl_tree -lpcap -lpthread -lanti_flood_hijack -lMESA_htable -lMESA_handle_logger
+wangyan_gdev_measurement.so:wangyan_gdev_measurement.c
+ $(CC) -o $@ -shared -fPIC $(INCS) $(CFLAGS) $^ $(MODULES)
+ cp $@ ../bin/plug/business/wangyan_gdev_measurement/$@
+
.c.o:
$(CC) -c -o $@ $(CFLAGS) -I. $(INCS) $<
clean:
diff --git a/test/g_device_plug.c b/test/g_device_plug.c
deleted file mode 100644
index f6ac1db..0000000
--- a/test/g_device_plug.c
+++ /dev/null
@@ -1,197 +0,0 @@
-#ifdef __cplusplus
-extern "C" {
-#endif
-/*
- ��GDEV-KEEPALIVE���ܴ�ƽ̨�а���,
- ���ص�UDP�������ԭ�й���.
-
- ��icmp��arp���Э��ž�ȷʶ��, ��ʱ������ƽ̨�ڲ�.
-*/
-
-#include <pthread.h>
-#ifndef __FAVOR_BSD
-#define __FAVOR_BSD 1
-#endif
-
-#include <arpa/inet.h>
-#include <netinet/udp.h>
-#include "stream_internal.h"
-#include "stream_manage.h"
-#include "packet_io.h"
-#include "g_device.h"
-#include "mesa_net.h"
-#include "packet_io_internal.h"
-#include "sendpacket.h"
-#include "deal_ipv4.h"
-#include "MESA_prof_load.h"
-
-static int sendto_gdev_card_ip; /* ��Gdev����������IP��ַ, ������ */
-
-
-/* �����豸�������ICMPЭ�� */
-static int gdev_keepalive_bfd(const raw_pkt_t *raw_pkt, int thread_id, unsigned char dir, unsigned char *send_buf)
-{
- char payload_buf[1472];
- struct mesa_ethernet_hdr *eth_hdr = (struct mesa_ethernet_hdr *)raw_pkt->raw_pkt_data;
- struct mesa_ip4_hdr *ip_hdr = (struct mesa_ip4_hdr *)((char *)eth_hdr+ SENDPACKET_ETH_H);
- struct mesa_udp_hdr *udp_hdr = (struct mesa_udp_hdr *)((char *)eth_hdr + SENDPACKET_ETH_H + ip_hdr->ip_hl*4);
- bfd_header_t *bfd_net_hdr = (bfd_header_t *)((char *)eth_hdr + SENDPACKET_ETH_H + ip_hdr->ip_hl*4 + SENDPACKET_UDP_H);
- bfd_header_t *bfd_send_hdr = (bfd_header_t *)payload_buf;
- char bfd_buf[4];
- int payload_len = ntohs(udp_hdr->uh_ulen) - SENDPACKET_UDP_H;
-
- /* һЩ�������� */
- if(ntohs(eth_hdr->ether_type) != ETHERTYPE_IP){
- return -1;
- }
-
- if(ip_hdr->ip_p != IPPROTO_UDP){
- return -1;
- }
-
- if(ntohs(udp_hdr->uh_dport) != BFD_DEFAULT_PORT){
- return -1;
- }
-
- if(memcmp(&ip_hdr->ip_dst.s_addr, &sendto_gdev_card_ip, sizeof(int)) != 0){
- return -1;
- }
-
- if(payload_len != (int)sizeof(bfd_header_t)){
- return -1;
- }
-
- memcpy(payload_buf, bfd_net_hdr, payload_len);
-
- memcpy(bfd_buf, bfd_send_hdr->my_discriminator, 4);
- memcpy(bfd_send_hdr->my_discriminator, bfd_send_hdr->your_discriminator, 4);
- memcpy(bfd_send_hdr->your_discriminator, bfd_buf, 4);
-
- sendpacket_build_udp_dual_stack(ntohs(udp_hdr->uh_sport), /* BFDЭ�鲻����Դ��Ŀ�Ķ˿� */
- ntohs(udp_hdr->uh_dport),
- (char *)bfd_send_hdr,
- payload_len,
- payload_len,
- send_buf + SENDPACKET_ETH_H + SENDPACKET_IP_H);
-
- sendpacket_build_ipv4(SENDPACKET_UDP_H + payload_len,
- 0,
- ntohs(ip_hdr->ip_id),
- ntohs(ip_hdr->ip_off),
- ip_hdr->ip_ttl,
- IPPROTO_UDP,
- ip_hdr->ip_dst.s_addr,
- ip_hdr->ip_src.s_addr, /* ����Դ��Ŀ��IP��ַ */
- NULL, 0,
- send_buf + SENDPACKET_ETH_H);
-
- sendpacket_do_checksum(send_buf + SENDPACKET_ETH_H,
- IPPROTO_IP,
- SENDPACKET_IP_H);
-
- sendpacket_do_checksum(send_buf + SENDPACKET_ETH_H,
- IPPROTO_UDP,
- payload_len + SENDPACKET_UDP_H);
-
- return SENDPACKET_IP_H + SENDPACKET_UDP_H+sizeof(bfd_header_t);
-}
-
-static int gdev_keepalive_udp_plug(const raw_pkt_t *raw_pkt, int thread_id, unsigned char dir)
-{
- int ret = -1;
- MESA_send_handle *snd_handle = NULL;
- int low_layer_type;
-
- snd_handle = packet_io_get_send_handle(thread_id);
- if(NULL == snd_handle){
- return -1;
- }
- snd_handle->send_buf = packet_io_get_sendbuf(SEND_TYPE_LINK_INJECT, thread_id);
- if(NULL == snd_handle->send_buf){
- return 0;
- }
-
- ret = gdev_keepalive_bfd(raw_pkt, thread_id, dir, snd_handle->send_buf);
- if(ret < 0){
- goto err;
- }
- low_layer_type = __ADDR_TYPE_IP_PAIR_V4;
-
- /* 2015-01-04 lijia add, MESA_killϵ�к�������ʱ������ethͷ����, �˴�Ҫһ�� */
- if(ADDR_TYPE_MAC == raw_pkt->low_layer_type){
- ret += sizeof(struct mesa_ethernet_hdr);
- }
- /* gdev keepalive�Ļظ�����dirʹ��"ͬ��", �ײ�ֻ��򵥽�MAC��ַ��src��dst�ߵ����� */
- ret = packet_io_send(snd_handle,ret, SEND_TYPE_LINK_INJECT,
- low_layer_type, dir, thread_id,
- (char *)KILL_TCP_PHONY_POINTER, (int *)KILL_TCP_PHONY_POINTER);
-
- packet_io_free_sendbuf(SEND_TYPE_LINK_INJECT, thread_id);
- return ret;
-
-err:
- packet_io_free_sendbuf(SEND_TYPE_LINK_INJECT, thread_id);
- return -1;
-}
-
-/* �ڴ���UDP����, ����ʶ����Щ������BFD����� */
-static inline int gdev_bfd_pkt_identify(const struct streaminfo *a_udp)
-{
- if(g_topology_mode != NET_CONN_SERIAL_GDEV){ /* ��G����ģʽ */
- return 0;
- }
-
- if(ADDR_TYPE_IPV4 != a_udp->addr.addrtype){
- return 0;
- }
-
- if(BFD_DEFAULT_PORT != ntohs(a_udp->addr.tuple4_v4->dest)){
- return 0;
- }
-
- return 1;
-}
-
-
-char gdev_keepalive_udp_entry(const struct streaminfo *a_udp, void **pme, int thread_seq, const void *ip_hdr)
-{
- int ret;
- const struct streaminfo_private *a_udp_pr;
-
- if(0 == gdev_bfd_pkt_identify(a_udp)){
- return APP_STATE_DROPME;
- }
-
- a_udp_pr = (const struct streaminfo_private *)a_udp;
- ret = gdev_keepalive_udp_plug(a_udp_pr->raw_pkt, a_udp->threadnum, a_udp->routedir);
- if(ret < 0){
- return APP_STATE_DROPME;
- }
-
- return APP_STATE_GIVEME;
-}
-
-int gdev_keepalive_plug_init(void)
-{
- char tmp_ip_buf[16];
-
- if(g_topology_mode != NET_CONN_SERIAL_GDEV){ /* ��G����ģʽ */
- sapp_runtime_log(30, "In non-gdev mode, no need to load g_device_plug.so\n");
- return -1;
- }
-
- memset(tmp_ip_buf, 0, 16);
- MESA_load_profile_string_nodef((char *)"conf/gdev.conf", (char *)"Module", (char *)"sendto_gdev_ip", tmp_ip_buf, 16);
- if(tmp_ip_buf[0] == '\0'){
- sapp_runtime_log(30, "can't get 'sendto_gdev_ip' \n");
- return -1;
- }
-
- inet_pton(AF_INET, tmp_ip_buf, &sendto_gdev_card_ip);
-
- return 0;
-}
-
-#ifdef __cplusplus
-}
-#endif
diff --git a/test/wangyan_gdev_measurement.c b/test/wangyan_gdev_measurement.c
index 96f6435..2a0b5b7 100644
--- a/test/wangyan_gdev_measurement.c
+++ b/test/wangyan_gdev_measurement.c
@@ -1,38 +1,17 @@
-#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"
-
+#include "sapp_api.h"
+#include "sapp_private_api.h"
#ifdef __cplusplus
extern "C" {
#endif
+int wangyan_gdev_measure_version_20190527;
#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 */
@@ -83,7 +62,6 @@ 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 {
@@ -134,6 +112,17 @@ static send_pkt_conf_parse_t g_send_pkt_conf_engine[] =
*/
#endif
+static inline time_t get_tmie_from_sapp(void)
+{
+ time_t cur_time;
+ int optlen = sizeof(time_t);
+
+ sapp_get_platform_opt(SPO_CURTIME_TIMET, &cur_time, &optlen);
+
+ return cur_time;
+}
+
+
/* ��ȡ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])
{
@@ -816,12 +805,12 @@ static void *test_gdev_get_opt(void *arg)
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->last_send_time == get_tmie_from_sapp()){
if(instance->send_pkt_num >= instance->send_pkt_para.send_pps){
return;
}
}else{
- instance->last_send_time = g_CurrentTime;
+ instance->last_send_time = get_tmie_from_sapp();
instance->send_pkt_num = 0;
}