summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlijie <[email protected]>2018-11-21 20:47:01 +0800
committerlijie <[email protected]>2018-11-21 20:47:01 +0800
commitde9b2d4ff40d5874de7d8fc7fe3a8e46b99f99d9 (patch)
tree35c6a856170017775381954bd4f02218e949dad8
parentb61723f018870507100d28c7671e3b6b7baa1e18 (diff)
初步和接入网关联调成功
-rw-r--r--bin/conf/mrl.conf15
-rw-r--r--bin/conf/mrl.inf4
-rw-r--r--bin/conf/table_info.conf2
-rw-r--r--bin/mrl.sobin89144 -> 0 bytes
-rw-r--r--include/mrl_main.h17
-rw-r--r--include/mrl_packet.h6
-rw-r--r--include/mrl_redis.h20
-rw-r--r--include/mrl_utils.h2
-rw-r--r--src/Makefile2
-rw-r--r--src/mrl.sobin88928 -> 0 bytes
-rw-r--r--src/mrl_main.c70
-rw-r--r--src/mrl_main.obin47664 -> 0 bytes
-rw-r--r--src/mrl_packet.c179
-rw-r--r--src/mrl_packet.obin36104 -> 0 bytes
-rw-r--r--src/mrl_redis.c126
-rw-r--r--src/mrl_redis.obin45856 -> 0 bytes
-rw-r--r--src/mrl_utils.obin22040 -> 0 bytes
17 files changed, 280 insertions, 163 deletions
diff --git a/bin/conf/mrl.conf b/bin/conf/mrl.conf
index 58ee390..92c58f0 100644
--- a/bin/conf/mrl.conf
+++ b/bin/conf/mrl.conf
@@ -1,6 +1,10 @@
[LOG_INFO]
-log_level=20
+log_level=10
log_path=./log/mrl.log
+[DETECT_INFO]
+dest_ip=123.57.35.217
+dest_port=20181
+local_port=20182
[SOCK_INFO]
mrl_port=23456
mgw_port=33456
@@ -18,14 +22,15 @@ ht_max_element_num=40000
ht_mutex_num=5
[VXLAN_INFO]
vxlan_gdev_num=1
-vxlan_local_mac=e4:95:6e:20:0d:0as
+vxlan_local_mac=e4:95:6e:20:0d:0a
vxlan_gdev_mac=00:1e:73:6c:fa:43
vxlan_local_ip=192.168.1.10
vxlan_gdev_ip=10.1.1.1
-vxlan_local_port=4789
-vxlan_gdev_port=50710
+vxlan_local_port=50710
+vxlan_gdev_port=4789
vxlan_encap_type=0
vxlan_link_id=1
vxlan_link_dir=1
-vxlan_inner_smac=60:67:20:2a:6a:b0
+vxlan_vpn_id=112
+vxlan_inner_smac=7c:2a:31:a3:44:9a
vxlan_inner_dmac=e8:61:1f:13:70:7a \ No newline at end of file
diff --git a/bin/conf/mrl.inf b/bin/conf/mrl.inf
index 66e03a1..203ec1c 100644
--- a/bin/conf/mrl.inf
+++ b/bin/conf/mrl.inf
@@ -4,9 +4,9 @@ SO_PATH=./plug/business/mrl/mrl.so
INIT_FUNC=mrl_init
DESTROY_FUNC=mrl_destroy
-[TCPALL]
+[TCP_ALL]
FUNC_FLAG=ALL
-FUNC_NAME=mrl_tcp_entry
+FUNC_NAME=mrl_tcpall_entry
[UDP]
FUNC_FLAG=ALL
diff --git a/bin/conf/table_info.conf b/bin/conf/table_info.conf
index 42d2ead..d860d44 100644
--- a/bin/conf/table_info.conf
+++ b/bin/conf/table_info.conf
@@ -16,4 +16,4 @@
#For expr/expr_plus Table
#id name type src_charset dst_charset do_merge cross_cache quick_mode
0 IR_NOMINEE_IP plugin 5 --
-1 IR_CANDIDATE_IP plugin 18 -- \ No newline at end of file
+1 IR_CANDIDATE_IP plugin 19 -- \ No newline at end of file
diff --git a/bin/mrl.so b/bin/mrl.so
deleted file mode 100644
index f269249..0000000
--- a/bin/mrl.so
+++ /dev/null
Binary files differ
diff --git a/include/mrl_main.h b/include/mrl_main.h
index d3ab72c..a9bd8d5 100644
--- a/include/mrl_main.h
+++ b/include/mrl_main.h
@@ -8,6 +8,7 @@
#include "MESA_prof_load.h"
#include "MESA_handle_logger.h"
#include "MESA_htable.h"
+#include "MESA_list_queue.h"
#include "Maat_rule.h"
#include "Maat_command.h"
@@ -20,8 +21,8 @@ struct mrl_global_cfg
int mrl_log_level;
//detect info
- char detect_ip[MRL_STR_IP_LEN];
- uint16_t detect_port;
+ char dest_ip[MRL_STR_IP_LEN];
+ uint16_t dest_port;
uint16_t local_port;
//socket info
@@ -41,7 +42,7 @@ struct mrl_global_cfg
unsigned int ht_slots;
unsigned int ht_max_element_num;
unsigned int ht_mutex_num;
-
+
/*vxlan info*/
unsigned int vxlan_gdev_num;
char **vxlan_outer_gdev_mac;
@@ -51,13 +52,11 @@ struct mrl_global_cfg
char **vxlan_outer_gdev_port;
char xvlan_outer_local_port[MRL_STR_PORT_LEN];
char **vxlan_encap_type;
+ char **vxlan_vpn_id;
char **vxlan_link_id;
char **vxlan_link_dir;
char **vxlan_inner_smac;
char **vxlan_inner_dmac;
- //char vxlan_inner_dip[MRL_STR_IP_LEN];
- //char vxlan_inner_dport[MRL_STR_PORT_LEN];
- //char vxlan_inner_sport[MRL_STR_PORT_LEN];
};
struct mrl_global_instance
@@ -69,9 +68,13 @@ struct mrl_global_instance
Maat_feather_t candidate_feather;
MESA_htable_handle ht_nominee;
- MESA_htable_handle ht_candidate;
+
+ //MESA_htable_handle ht_candidate;
+ MESA_lqueue_head mrl_queue;
MMDB_s mrl_mmdb;
+
+ int stop_flag;
int *mrl_snd_fd;
int mrl_rcv_fd;
diff --git a/include/mrl_packet.h b/include/mrl_packet.h
index 06069ae..aec886f 100644
--- a/include/mrl_packet.h
+++ b/include/mrl_packet.h
@@ -8,14 +8,12 @@ void mrl_socket_close();
void mrl_send_to_gdev(int thread_seq, struct mrl_vxlan_info * vxlan_info, const char *payload, size_t payload_len);
bool mrl_pkt_signature_identify(struct streaminfo *mystream);
-void *mrl_recv_mgw_action(void *arg);
void mrl_send_to_mgw(void *raw_pkt, int thread_seq);
void mrl_detect_init();
void mrl_detect_action(const char *ip_addr);
-
bool mrl_pkt_signature_identify(struct streaminfo *mystream);
-
-
+void *mrl_recv_mgw_action(void *arg);
+void *mrl_detect_ip_action(void *arg);
#endif
diff --git a/include/mrl_redis.h b/include/mrl_redis.h
index de6cdcb..b840a8e 100644
--- a/include/mrl_redis.h
+++ b/include/mrl_redis.h
@@ -16,16 +16,17 @@ struct mrl_nominee_item{
char op_time[MRL_DATE_LEN];
};
-struct mrl_vxlan_info{
- char vxlan_outer_local_mac[MRL_STR_MAC_LEN];//���յ������ݰ��ı����豸MAC��ַ
- char vxlan_outer_gdev_mac[MRL_STR_MAC_LEN];//���յ������ݰ��Ĵ����豸MAC��ַ
- char vxlan_outer_local_ip[MRL_STR_IP_LEN];
- char vxlan_outer_gdev_ip[MRL_STR_IP_LEN];//�����豸IP
- char vxlan_outer_gdev_port[MRL_STR_PORT_LEN];
- char vxlan_outer_local_port[MRL_STR_PORT_LEN];
- int vxlan_encap_type;
+struct mrl_vxlan_info{
int vxlan_link_id;
+ int vxlan_encap_type;
int vxlan_link_dir;
+ int vxlan_vpn_id;
+ char vxlan_outer_local_port[MRL_STR_PORT_LEN];
+ char vxlan_outer_gdev_port[MRL_STR_PORT_LEN];
+ char vxlan_outer_local_ip[MRL_STR_IP_LEN];
+ char vxlan_outer_gdev_ip[MRL_STR_IP_LEN];//�����豸IP
+ char vxlan_outer_local_mac[MRL_STR_MAC_LEN];//���յ������ݰ��ı����豸MAC��ַ
+ char vxlan_outer_gdev_mac[MRL_STR_MAC_LEN];//���յ������ݰ��Ĵ����豸MAC��ַ
char vxlan_inner_smac[MRL_STR_MAC_LEN];
char vxlan_inner_dmac[MRL_STR_MAC_LEN];
};
@@ -43,14 +44,13 @@ struct mrl_candidate_item{
MESA_htable_handle mrl_htable_init(void * fn_data_free_cb);
-void ht_candidate_free_cb(void * data);
+//void ht_candidate_free_cb(void * data);
void ht_nominee_free_cb(void * data);
void Maat_set_cmd_line(Maat_feather_t feather, struct mrl_candidate_item *candidate_item);
void Maat_set_nominee_cmd_line(Maat_feather_t feather, struct mrl_nominee_item *nominee_item);
Maat_feather_t mrl_Maat_feather_init(const char * instance_name,const char *table_name, Maat_start_callback_t *start,Maat_update_callback_t *update,Maat_finish_callback_t *finish,void *u_para);
void nominee_update_cb(int table_id,const char* table_line,void* u_para);
-void candidate_update_cb(int table_id,const char* table_line,void* u_para);
void mrl_identify_nominee(struct streaminfo *mystream);
#endif
diff --git a/include/mrl_utils.h b/include/mrl_utils.h
index 2bf05d8..ca148a6 100644
--- a/include/mrl_utils.h
+++ b/include/mrl_utils.h
@@ -8,7 +8,7 @@
#define MRL_STR_ENCAP_TYPE_LEN 5
#define MRL_STR_LINK_ID_LEN 5
#define MRL_STR_LINK_DIR_LEN 2
-
+#define MRL_STR_VPN_ID_LEN 5
#define MRL_DATE_LEN 50
diff --git a/src/Makefile b/src/Makefile
index f1e4639..b9cb678 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -8,7 +8,7 @@ CXXFLAGS = -Wall -g -fPIC
INCLUDES = -I ../include
-#INCLUDES += -I ../support/include
+INCLUDES += -I /opt/mrzcpd/include
INCLUDES += -I /opt/MESA/include
diff --git a/src/mrl.so b/src/mrl.so
deleted file mode 100644
index 445ab26..0000000
--- a/src/mrl.so
+++ /dev/null
Binary files differ
diff --git a/src/mrl_main.c b/src/mrl_main.c
index 12153b2..99f8001 100644
--- a/src/mrl_main.c
+++ b/src/mrl_main.c
@@ -17,11 +17,12 @@ void mrl_cfg_init(const char *profile)
char *temp_port_str;
char *temp_ip_str;
char *temp_encap_type_str;
+ char *temp_vpn_id_str;
char *temp_link_id_str;
char *temp_link_dir_str;
unsigned int split_num = 0;
- short temp_port = 0;
+ int temp_port = 0;
unsigned int i=0;
/********** load log info **********/
@@ -29,22 +30,23 @@ void mrl_cfg_init(const char *profile)
MESA_load_profile_string_def(profile, "LOG_INFO", "log_path", mrl_instance.mrl_cfg.mrl_log_path, MRL_MAX_PATH, "./log/mrl.log");
/********** load detect info **********/
- MESA_load_profile_string_def(profile, "DETECT_INFO", "detect_ip", mrl_instance.mrl_cfg.detect_ip, MRL_STR_IP_LEN, "0.0.0.0");
+ MESA_load_profile_string_def(profile, "DETECT_INFO", "dest_ip", mrl_instance.mrl_cfg.dest_ip, MRL_STR_IP_LEN, "0.0.0.0");
- MESA_load_profile_short_def(profile, "SOCK_INFO", "mrl_port",&(temp_port),8888);
+ MESA_load_profile_int_def(profile, "DETECT_INFO", "dest_port",&(temp_port),8888);
assert(temp_port > 0 && temp_port <= 65535);
- mrl_instance.mrl_cfg.detect_port = temp_port;
+ mrl_instance.mrl_cfg.dest_port = temp_port;
- MESA_load_profile_short_def(profile, "SOCK_INFO", "mrl_port",&(temp_port),8888);
+ MESA_load_profile_int_def(profile, "DETECT_INFO", "local_port",&(temp_port),8888);
assert(temp_port > 0 && temp_port <= 65535);
mrl_instance.mrl_cfg.local_port = temp_port;
/********** load sock info **********/
- MESA_load_profile_short_def(profile, "SOCK_INFO", "mrl_port",&(temp_port),8888);
+ MESA_load_profile_int_def(profile, "SOCK_INFO", "mrl_port",&(temp_port),8888);
assert(temp_port > 0 && temp_port <= 65535);
mrl_instance.mrl_cfg.mrl_port = temp_port;
+
- MESA_load_profile_short_def(profile, "SOCK_INFO", "mgw_port",&(temp_port),8888);
+ MESA_load_profile_int_def(profile, "SOCK_INFO", "mgw_port",&(temp_port),8888);
assert(temp_port > 0 && temp_port <= 65535);
mrl_instance.mrl_cfg.mgw_port = temp_port;
@@ -56,9 +58,9 @@ void mrl_cfg_init(const char *profile)
MESA_load_profile_string_def(profile, "MAAT_INFO", "Maat_table_path", mrl_instance.mrl_cfg.Maat_table_path, MRL_MAX_PATH, "./conf/table_info.conf");
MESA_load_profile_uint_def(profile, "MAAT_INFO", "Maat_max_threads", &(mrl_instance.mrl_cfg.Maat_max_threads), 1);
MESA_load_profile_string_def(profile, "MAAT_INFO", "Maat_redis_ip", mrl_instance.mrl_cfg.Maat_redis_ip, MRL_STR_IP_LEN, "127.0.0.1");
- MESA_load_profile_short_def(profile, "MAAT_INFO", "Maat_redis_port", &(temp_port), 6379);
+ MESA_load_profile_int_def(profile, "MAAT_INFO", "Maat_redis_port", &(temp_port), 6379);
assert(temp_port > 0 && temp_port <= 65535);
- mrl_instance.mrl_cfg.Maat_redis_port = (unsigned short)temp_port;
+ mrl_instance.mrl_cfg.Maat_redis_port = temp_port;
MESA_load_profile_string_def(profile, "MAAT_INFO", "Maat_stat_path", mrl_instance.mrl_cfg.Maat_stat_path,MRL_MAX_PATH, "./log/Maat_stat.log");
@@ -75,6 +77,7 @@ void mrl_cfg_init(const char *profile)
temp_ip_str = (char *)calloc(mrl_instance.mrl_cfg.vxlan_gdev_num * MRL_STR_IP_LEN,sizeof(char));
temp_port_str = (char *)calloc(mrl_instance.mrl_cfg.vxlan_gdev_num * MRL_STR_PORT_LEN, sizeof(char));
temp_encap_type_str = (char *)calloc(mrl_instance.mrl_cfg.vxlan_gdev_num * MRL_STR_ENCAP_TYPE_LEN,sizeof(char));
+ temp_vpn_id_str = (char *)calloc(mrl_instance.mrl_cfg.vxlan_gdev_num * MRL_STR_VPN_ID_LEN,sizeof(char));
temp_link_id_str = (char *)calloc(mrl_instance.mrl_cfg.vxlan_gdev_num * MRL_STR_LINK_ID_LEN,sizeof(char));
temp_link_dir_str = (char *)calloc(mrl_instance.mrl_cfg.vxlan_gdev_num * MRL_STR_LINK_DIR_LEN, sizeof(char));
@@ -114,6 +117,17 @@ void mrl_cfg_init(const char *profile)
split_num = mrl_split_str(temp_encap_type_str,",",mrl_instance.mrl_cfg.vxlan_encap_type);
assert(split_num == mrl_instance.mrl_cfg.vxlan_gdev_num);
+
+ MESA_load_profile_string_def(profile, "VXLAN_INFO", "vxlan_vpn_id",temp_vpn_id_str, mrl_instance.mrl_cfg.vxlan_gdev_num*MRL_STR_VPN_ID_LEN, "0000");
+ mrl_instance.mrl_cfg.vxlan_vpn_id = (char **)malloc(sizeof(char *)*mrl_instance.mrl_cfg.vxlan_gdev_num);
+ for(i=0;i<mrl_instance.mrl_cfg.vxlan_gdev_num;i++)
+ {
+ mrl_instance.mrl_cfg.vxlan_vpn_id[i] = (char *)malloc(sizeof(char)*MRL_STR_VPN_ID_LEN);
+ }
+ split_num = mrl_split_str(temp_vpn_id_str,",",mrl_instance.mrl_cfg.vxlan_vpn_id);
+ assert(split_num == mrl_instance.mrl_cfg.vxlan_gdev_num);
+
+
MESA_load_profile_string_def(profile, "VXLAN_INFO", "vxlan_link_id",temp_link_id_str, mrl_instance.mrl_cfg.vxlan_gdev_num*MRL_STR_LINK_ID_LEN, "0");
mrl_instance.mrl_cfg.vxlan_link_id= (char **)malloc(sizeof(char *)*mrl_instance.mrl_cfg.vxlan_gdev_num);
for(i=0;i<mrl_instance.mrl_cfg.vxlan_gdev_num;i++)
@@ -165,6 +179,7 @@ void mrl_cfg_init(const char *profile)
free(temp_link_id_str);
free(temp_link_dir_str);
}
+/*
void mrl_nominee_test_init()
{
printf("mrl moninee_test init\n");
@@ -179,11 +194,14 @@ void mrl_nominee_test_init()
nominee_item.is_vaild = 1;
memcpy(nominee_item.op_time,date,strlen(date));
Maat_set_nominee_cmd_line(mrl_instance.nominee_feather, &nominee_item);
+}*/
+void candidate_update_cb(int table_id,const char* table_line,void* u_para)
+{
}
extern "C" int mrl_init(void)
{
-
+ mrl_instance.stop_flag = 0;
mrl_cfg_init("./mrl_conf/mrl.conf");
mrl_instance.mrl_log_handle = MESA_create_runtime_log_handle(mrl_instance.mrl_cfg.mrl_log_path, mrl_instance.mrl_cfg.mrl_log_level);
@@ -192,29 +210,42 @@ extern "C" int mrl_init(void)
assert(0);
}
+ int thread_safe = 1;
+ long max_item_num = 0;
+ mrl_instance.mrl_queue = MESA_lqueue_create(thread_safe,max_item_num);
+ if(mrl_instance.mrl_queue== NULL)
+ {
+ MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_FATAL,"mrl_init","MESA_lqueue_create func error!");
+ assert(0);
+ }
+
mrl_instance.ht_nominee = mrl_htable_init((void *)ht_nominee_free_cb);
- mrl_instance.ht_candidate = mrl_htable_init((void *)ht_candidate_free_cb);
-
mrl_instance.nominee_feather = mrl_Maat_feather_init("mrl_nominee",IR_NOMINEE_IP_TABLE_NAME,NULL,nominee_update_cb,NULL,NULL);
mrl_instance.candidate_feather = mrl_Maat_feather_init("mrl_candidate",IR_CANDIDATE_IP_TABLE_NAME,NULL,candidate_update_cb,NULL,NULL);
mrl_socket_init();
//TODO:read from nominee table and candidate table ifno and construct the packet
//send to the speficied destination
- mrl_detect_init();
mrl_mmdb_init("./mrl_conf/all_ip_only_coun_v4.mmdb");
- mrl_nominee_test_init();
+ //mrl_nominee_test_init();
//���������߳̽��ղ�����mwg���͵����ݰ�
- pthread_t pid;
- if(pthread_create(&pid,NULL,mrl_recv_mgw_action,NULL) <0)
+ pthread_t recv_pid, detect_pid;
+ if(pthread_create(&recv_pid,NULL,mrl_recv_mgw_action,NULL) <0)
{
MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_FATAL,"mrl_init","pthread_create func error!");
assert(0);
}
- pthread_detach(pid);
+ pthread_detach(recv_pid);
+
+ if(pthread_create(&detect_pid,NULL,mrl_detect_ip_action,NULL) <0)
+ {
+ MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_FATAL,"mrl_init","pthread_create func error!");
+ assert(0);
+ }
+ pthread_detach(detect_pid);
return 1;
}
@@ -245,11 +276,14 @@ void mrl_destroy_cfg()
extern "C" void mrl_destroy(void)
{
- MESA_destroy_runtime_log_handle(mrl_instance.mrl_log_handle);
+
+ MESA_lqueue_destroy(mrl_instance.mrl_queue,NULL,NULL);
Maat_burn_feather(mrl_instance.candidate_feather);
Maat_burn_feather(mrl_instance.nominee_feather);
mrl_destroy_cfg();
mrl_socket_close();
+ mrl_instance.stop_flag = 1;
+ MESA_destroy_runtime_log_handle(mrl_instance.mrl_log_handle);
}
extern "C" char mrl_tcpall_entry(struct streaminfo *a_tcp,void **pme, int thread_seq, void *raw_packet)
diff --git a/src/mrl_main.o b/src/mrl_main.o
deleted file mode 100644
index 653c64f..0000000
--- a/src/mrl_main.o
+++ /dev/null
Binary files differ
diff --git a/src/mrl_packet.c b/src/mrl_packet.c
index fd00be2..575ebb5 100644
--- a/src/mrl_packet.c
+++ b/src/mrl_packet.c
@@ -6,6 +6,7 @@
#include "stream.h"
#include "stream_inc/stream_control.h"
+#include "mrtunnat.h"
#include "mrl_packet.h"
#include "mrl_main.h"
@@ -124,9 +125,10 @@ void mrl_send_to_gdev(int thread_seq, struct mrl_vxlan_info * vxlan_info, const
uint8_t temp_mac[MRL_MAC_LEN];
uint32_t temp_ip;
uint16_t temp_port;
-
+ //printf("the vxlan info is: \n");
memset(temp_mac, 0, MRL_MAC_LEN);
mrl_mac_pton(vxlan_info->vxlan_outer_local_mac, ':', temp_mac);
+ //printf("SAPP_SEND_OPT_GDEV_SMAC is:%02x-%02x-%02x-%02x-%02x-%02x\n",temp_mac[0],temp_mac[1],temp_mac[2],temp_mac[3],temp_mac[4],temp_mac[5]);
option[option_num].type = SAPP_SEND_OPT_GDEV_SMAC;
option[option_num].length = MRL_MAC_LEN;
memcpy(option[option_num].array_value, temp_mac, MRL_MAC_LEN);
@@ -134,12 +136,14 @@ void mrl_send_to_gdev(int thread_seq, struct mrl_vxlan_info * vxlan_info, const
memset(temp_mac, 0, MRL_MAC_LEN);
mrl_mac_pton(vxlan_info->vxlan_outer_gdev_mac, ':', temp_mac);
+ //printf("SAPP_SEND_OPT_GDEV_DMAC is:%02x-%02x-%02x-%02x-%02x-%02x\n",temp_mac[0],temp_mac[1],temp_mac[2],temp_mac[3],temp_mac[4],temp_mac[5]);
option[option_num].type = SAPP_SEND_OPT_GDEV_DMAC;
option[option_num].length = MRL_MAC_LEN;
memcpy(option[option_num].array_value, temp_mac, MRL_MAC_LEN);
option_num++;///////
- inet_pton(AF_INET, vxlan_info->vxlan_outer_local_ip, &temp_ip);
+ inet_pton(AF_INET, vxlan_info->vxlan_outer_local_ip, &temp_ip);
+ //printf("SAPP_SEND_OPT_GDEV_SIP is:%u\n",temp_ip);
option[option_num].type = SAPP_SEND_OPT_GDEV_SIP;
option[option_num].length = 4;
option[option_num].int_value = temp_ip;
@@ -147,6 +151,7 @@ void mrl_send_to_gdev(int thread_seq, struct mrl_vxlan_info * vxlan_info, const
inet_pton(AF_INET, vxlan_info->vxlan_outer_gdev_ip, &temp_ip);
+ //printf("SAPP_SEND_OPT_GDEV_DIP is:%u\n",temp_ip);
option[option_num].type = SAPP_SEND_OPT_GDEV_DIP;
option[option_num].length = 4;
option[option_num].int_value = temp_ip;
@@ -155,52 +160,57 @@ void mrl_send_to_gdev(int thread_seq, struct mrl_vxlan_info * vxlan_info, const
temp_port = atoi(vxlan_info->vxlan_outer_local_port);
assert(temp_port >0 && temp_port <= 65535);
+ //printf("SAPP_SEND_OPT_GDEV_UDP_SPORT is:%hu\n",temp_port);
option[option_num].type = SAPP_SEND_OPT_GDEV_UDP_SPORT;
option[option_num].length = 2;
- option[option_num].short_value = temp_port;
+ option[option_num].short_value = htons(temp_port);
option_num++;///////
temp_port = atoi(vxlan_info->vxlan_outer_gdev_port);
assert(temp_port >0 && temp_port <= 65535);
+ //printf("SAPP_SEND_OPT_GDEV_UDP_DPORT is:%hu\n",temp_port);
option[option_num].type = SAPP_SEND_OPT_GDEV_UDP_DPORT;
option[option_num].length = 2;
- option[option_num].short_value = temp_port;
+ option[option_num].short_value = htons(temp_port);
+ //printf("cur option gdev_udp_dport value is %hu\n",ntohs(option[option_num].short_value));
option_num++;///////
option[option_num].type = SAPP_SEND_OPT_VXLAN_VPN_ID;
+ //printf("SAPP_SEND_OPT_VXLAN_VPN_ID is %d\n",vxlan_info->vxlan_vpn_id);
option[option_num].length = 4;
- option[option_num].int_value = 0;
+ option[option_num].int_value = vxlan_info->vxlan_vpn_id;
option_num++;///////
-
+ //printf("SAPP_SEND_OPT_VXLAN_LINK_ID is:%d\n",vxlan_info->vxlan_link_id);
option[option_num].type = SAPP_SEND_OPT_VXLAN_LINK_ID;
option[option_num].length = 4;
option[option_num].int_value = vxlan_info->vxlan_link_id;
option_num++;///////
-
+ //printf("SAPP_SEND_OPT_VXLAN_LINK_ENCAP_TYPE is:%d\n",vxlan_info->vxlan_encap_type);
option[option_num].type = SAPP_SEND_OPT_VXLAN_LINK_ENCAP_TYPE;
option[option_num].length = 1;
- option[option_num].char_value = vxlan_info->vxlan_encap_type;
+ option[option_num].char_value = TUNNAT_TUNNEL_TYPE_ETHER;
option_num++;///////
-
+ //printf("SAPP_SEND_OPT_VXLAN_LINK_DIR is:%d\n",vxlan_info->vxlan_link_dir);
option[option_num].type = SAPP_SEND_OPT_VXLAN_LINK_DIR;
option[option_num].length = 1;
option[option_num].char_value = vxlan_info->vxlan_link_dir;
option_num++;///////
-
+ //printf("SAPP_SEND_OPT_INNER_LINK_ENCAP_TYPE is:%d\n",vxlan_info->vxlan_encap_type);
option[option_num].type = SAPP_SEND_OPT_INNER_LINK_ENCAP_TYPE;
option[option_num].length = 1;
- option[option_num].char_value = vxlan_info->vxlan_encap_type;
+ option[option_num].char_value = TUNNAT_TUNNEL_TYPE_ETHER;
option_num++;///////
memset(temp_mac, 0, MRL_MAC_LEN);
mrl_mac_pton(vxlan_info->vxlan_inner_smac, ':', temp_mac);
+ //printf("SAPP_SEND_OPT_INNER_SMAC is:%02x-%02x-%02x-%02x-%02x-%02x\n",temp_mac[0],temp_mac[1],temp_mac[2],temp_mac[3],temp_mac[4],temp_mac[5]);
option[option_num].type = SAPP_SEND_OPT_INNER_SMAC;
option[option_num].length = MRL_MAC_LEN;
memcpy(option[option_num].array_value, temp_mac, MRL_MAC_LEN);
@@ -209,32 +219,58 @@ void mrl_send_to_gdev(int thread_seq, struct mrl_vxlan_info * vxlan_info, const
memset(temp_mac, 0, MRL_MAC_LEN);
mrl_mac_pton(vxlan_info->vxlan_inner_dmac, ':', temp_mac);
+ //printf("SAPP_SEND_OPT_INNER_DMAC is:%02x-%02x-%02x-%02x-%02x-%02x\n",temp_mac[0],temp_mac[1],temp_mac[2],temp_mac[3],temp_mac[4],temp_mac[5]);
option[option_num].type = SAPP_SEND_OPT_INNER_DMAC;
option[option_num].length = MRL_MAC_LEN;
memcpy(option[option_num].array_value, temp_mac, MRL_MAC_LEN);
option_num++;///////
-
- printf("send to gdev\n");
- MESA_sendpacket_iplayer_options(thread_seq,
+ int ret = 0;
+ ret = MESA_sendpacket_iplayer_options(thread_seq,
payload,
payload_len,
vxlan_info->vxlan_link_dir,
option,
option_num);
+ assert(ret >=0);
+ //printf("send to gdev ret is %d\n",ret);
}
//�ж��Ƿ���IP���ð�
bool mrl_pkt_signature_identify(struct streaminfo *mystream)
{
- printf("start to signature identify\n");
+ //printf("start to signature identify\n");
+ char temp_sip[MRL_STR_IP_LEN];
+ char temp_dip[MRL_STR_IP_LEN];
+ memset(temp_sip,0,MRL_STR_IP_LEN);
+ memset(temp_dip,0,MRL_STR_IP_LEN);
uint8_t type = 0;
- uint16_t sport = 0,dport = 0;
- uint32_t sip = 0,dip = 0;
- sport = mystream->addr.tuple4_v4->source;
- dport = mystream->addr.tuple4_v4->dest;
- sip = mystream->addr.tuple4_v4->saddr;
- dip = mystream->addr.tuple4_v4->daddr;
+ uint16_t sport = 0, dport = 0, temp_port = 0;
+ uint32_t hash_sport = 0, hash_dport =0;
+ uint32_t sip = 0, dip = 0;
+ sport = ntohs(mystream->addr.tuple4_v4->source);
+ dport = ntohs(mystream->addr.tuple4_v4->dest);
+ sip = ntohl(mystream->addr.tuple4_v4->saddr);
+ dip = ntohl(mystream->addr.tuple4_v4->daddr);
+ inet_ntop(AF_INET,&(mystream->addr.tuple4_v4->saddr),temp_sip,MRL_STR_IP_LEN);
+ inet_ntop(AF_INET,&(mystream->addr.tuple4_v4->daddr),temp_dip,MRL_STR_IP_LEN);
+ /*if(memcmp(temp_sip,"61.135.169.121",strlen(temp_sip)) == 0)
+ {
+ printf("cur sip is baidu\n");
+ return true;
+ }
+ else
+ {
+ if(memcmp(temp_dip,"61.135.169.121",strlen(temp_sip)) == 0)
+ {
+ printf("cur dip is baidu\n");
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }*/
switch(mystream->type)
{
case STREAM_TYPE_TCP:
@@ -247,23 +283,27 @@ bool mrl_pkt_signature_identify(struct streaminfo *mystream)
assert(0);
break;
}
- printf("cur stream sport is %u and dport is %u and sip is %d and dip is %d and protocol is %d\n",sport,dport,sip,dip,type);
- unsigned int hash_sport = sport ^ sip ^ dip ^type;
- hash_sport = hash_sport & 0xff;
- if(hash_sport == dport)
+ hash_dport = sport ^ sip ^ dip ^type;
+ hash_dport = hash_dport & 0xff;
+ temp_port = dport & 0xff;
+ MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_pkt_signature_identify","sapp recv stream info:"
+ "sport is %hu, dport is %hu, hash_dport is %hu, temp_port is %u,sip is %s,dip is %s, protocol is %d",
+ sport,dport,hash_dport,temp_port,temp_sip,temp_dip,type);
+ if(hash_dport == temp_port)
{
return true;
}
else
{
- if(type == MRL_UDP_TYPE)
+ hash_sport = dport ^ sip ^ dip ^type;
+ hash_sport = hash_sport & 0xff;
+ temp_port = sport & 0xff;
+ MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_pkt_signature_identify","sapp recv stream info:"
+ "sport is %hu, dport is %hu, hash_sport is %hu, temp_port is %u,sip is %s,dip is %s, protocol is %d",
+ sport,dport,hash_sport,temp_port,temp_sip,temp_dip,type);
+ if(hash_sport == temp_port)
{
- unsigned int hash_dport = dport ^ sip ^ dip ^type;
- hash_dport = hash_dport & 0xff;
- if(hash_dport == sport)
- {
- return true;
- }
+ return true;
}
return false;
}
@@ -273,9 +313,12 @@ bool mrl_pkt_signature_identify(struct streaminfo *mystream)
void mrl_send_to_mgw(void *raw_pkt, int thread_seq)
{
const char *pkt = (const char *)raw_pkt;
- ssize_t pkt_len = strlen(pkt);
+ struct iphdr *ip_hdr = (struct iphdr *)pkt;
+ ssize_t pkt_len = ntohs(ip_hdr->tot_len);
+ MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_send_to_mgw","send to mgw len is %d",pkt_len);
ssize_t send_len = 0;
send_len = mrl_sock_send(mrl_instance.mrl_snd_fd[thread_seq],pkt,pkt_len,&(mrl_instance.mgw_addr));
+ assert(send_len == pkt_len);
printf("send socket len is %ld\n",send_len);
}
@@ -289,35 +332,48 @@ void *mrl_recv_mgw_action(void *arg)
int temp_len = 0;
while(1)
{
+ if(mrl_instance.stop_flag == 1)
+ {
+ break;
+ }
+ memset(rcv_buff,0,MRL_BUFF_LEN);
recv_len = mrl_sock_recv(mrl_instance.mrl_rcv_fd,rcv_buff, MRL_BUFF_LEN);
printf("recv from mgw len is %ld\n",recv_len);
struct mrl_vxlan_info *vxlan_info = (struct mrl_vxlan_info *)rcv_buff;
+ MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_recv_mgw_action","recv mgw vxlan info:"
+ "link_id:%d,encap_type:%d,link_dir:%d,vpn_id:%d,local_port:%s,gdev_port:%s, local_ip:%s,gdev_ip:%s,"
+ "local_mac:%s, gdev_mac:%s,inner_smac:%s, inner_dmac:%s",
+ vxlan_info->vxlan_link_id,vxlan_info->vxlan_encap_type,vxlan_info->vxlan_link_dir,
+ vxlan_info->vxlan_vpn_id,vxlan_info->vxlan_outer_local_port,vxlan_info->vxlan_outer_gdev_port,
+ vxlan_info->vxlan_outer_local_ip,vxlan_info->vxlan_outer_gdev_ip,vxlan_info->vxlan_outer_local_mac,
+ vxlan_info->vxlan_outer_gdev_mac,vxlan_info->vxlan_inner_smac, vxlan_info->vxlan_inner_dmac);
size_t vxlan_len = sizeof(struct mrl_vxlan_info);
+
temp_len = sizeof(thread_seq);
sapp_get_platform_opt(SPO_INDEPENDENT_THREAD_ID, &thread_seq, &temp_len);
- printf("send to gdev thread seq is %d\n",thread_seq);
+ //printf("send to gdev thread seq is %d\n",thread_seq);
mrl_send_to_gdev(thread_seq,vxlan_info,rcv_buff + vxlan_len, recv_len - vxlan_len);
}
return NULL;
}
-size_t mrl_build_ip_hdr(char *ip_pkt, const char *src_ip, const char *dst_ip, size_t udp_len)
+size_t mrl_build_ip_hdr(char *ip_pkt, uint32_t src_ip, uint32_t dst_ip, size_t udp_len)
{
size_t ip_len = udp_len + MRL_IP_HDR_LEN;
struct iphdr *ip_hdr =(struct iphdr *)ip_pkt;
ip_hdr->ihl = 0x5;
ip_hdr->version=0x4;
ip_hdr->tos = 0x00;
- ip_hdr->tot_len = ip_len;
+ ip_hdr->tot_len = htons(ip_len);
ip_hdr->id = 0x325f;
ip_hdr->frag_off =0x0000;
ip_hdr->ttl = 0x80;
ip_hdr->protocol =0x11;
ip_hdr->check = 0x0000;
- inet_pton(AF_INET,src_ip,&(ip_hdr->saddr));
- inet_pton(AF_INET,dst_ip,&(ip_hdr->daddr));
- ip_hdr->check = htons(mrl_get_checksum((uint16_t *)ip_pkt,MRL_IP_HDR_LEN));
+ ip_hdr->saddr = src_ip;
+ ip_hdr->daddr = dst_ip;
+ ip_hdr->check = mrl_get_checksum((uint16_t *)ip_pkt,MRL_IP_HDR_LEN);
return ip_len;
}
@@ -325,10 +381,9 @@ size_t mrl_build_udp_hdr(char *udp_pkt,size_t payload_len)
{
struct udphdr *udp_hdr = (struct udphdr *)udp_pkt;
udp_hdr->source = htons(mrl_instance.mrl_cfg.local_port);
- udp_hdr->dest = htons(mrl_instance.mrl_cfg.detect_port);
- udp_hdr->len = payload_len + MRL_UDP_HDR_LEN;
+ udp_hdr->dest = htons(mrl_instance.mrl_cfg.dest_port);
+ udp_hdr->len = htons(payload_len + MRL_UDP_HDR_LEN);
udp_hdr->check = 0;
- udp_hdr->check = htons(mrl_get_checksum((uint16_t *)udp_pkt,payload_len + MRL_UDP_HDR_LEN));
return payload_len + MRL_UDP_HDR_LEN;
}
@@ -339,23 +394,24 @@ size_t mrl_build_udp_payload(char *payload)
memcpy(payload,content,payload_len);
return payload_len;
}
-void mrl_detect_action(const char *ip_addr)
+void mrl_detect_action(uint32_t src_ip)
{
- printf("start detect ip %s\n",ip_addr);
+ MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_FATAL,"mrl_detect_action","detect ip is %u",src_ip);
unsigned int i = 0;
int thread_seq = 0;
int temp_len = 0;
size_t udp_payload_len = 0;
size_t udp_len = 0;
size_t ip_len = 0;
+ uint32_t dest_ip = 0;
char ip_pkt[MRL_IP_PKT_LEN];
memset(ip_pkt,0,MRL_IP_PKT_LEN);
struct mrl_vxlan_info vxlan_info;
sapp_get_platform_opt(SPO_INDEPENDENT_THREAD_ID, &thread_seq, &temp_len);
udp_payload_len = mrl_build_udp_payload(ip_pkt +MRL_UDP_HDR_LEN + MRL_IP_HDR_LEN);
udp_len = mrl_build_udp_hdr(ip_pkt + MRL_IP_HDR_LEN, udp_payload_len);
- ip_len = mrl_build_ip_hdr(ip_pkt,ip_addr,mrl_instance.mrl_cfg.detect_ip,udp_len);
- MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_detect_action","detect pkt len is %d",ip_len);
+ inet_pton(AF_INET,mrl_instance.mrl_cfg.dest_ip,&dest_ip);
+ ip_len = mrl_build_ip_hdr(ip_pkt,src_ip,dest_ip,udp_len);
for(i = 0; i< mrl_instance.mrl_cfg.vxlan_gdev_num;i++)
{
memset(&vxlan_info,0,sizeof(vxlan_info));
@@ -364,20 +420,27 @@ void mrl_detect_action(const char *ip_addr)
}
}
-void ht_nominee_iterate_cb(const uchar *key, uint size, void *data, void *user)
+void *mrl_detect_ip_action(void *arg)
{
- if(data != NULL)
+ sleep(10);
+ int ret = 0;
+ uint32_t detect_ip = 0;
+ long int ip_len = sizeof(detect_ip);
+ while(1)
{
- if(MESA_htable_search_cb(mrl_instance.ht_candidate, key, size, NULL,NULL, NULL) == NULL)
+ if(mrl_instance.stop_flag == 1)
+ {
+ break;
+ }
+ ret = MESA_lqueue_get_head(mrl_instance.mrl_queue,&detect_ip,&ip_len);
+ MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_FATAL,"mrl_detect_ip_action","get ip from lqueue is %u",detect_ip);
+ if(ret != 0)
{
- mrl_detect_action((const char *)key);
- }
+ MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_FATAL,"mrl_detect_ip_action","MESA_lqueue_get_head func error! ret is %d",ret);
+ assert(0);
+ }
+ mrl_detect_action(detect_ip);
}
-
-}
-void mrl_detect_init()
-{
- printf("mrl detect init\n");
- MESA_htable_iterate(mrl_instance.ht_nominee, ht_nominee_iterate_cb, NULL);
-
+ return NULL;
}
+
diff --git a/src/mrl_packet.o b/src/mrl_packet.o
deleted file mode 100644
index 64dd8c0..0000000
--- a/src/mrl_packet.o
+++ /dev/null
Binary files differ
diff --git a/src/mrl_redis.c b/src/mrl_redis.c
index 81b343f..86287db 100644
--- a/src/mrl_redis.c
+++ b/src/mrl_redis.c
@@ -26,7 +26,7 @@ void ht_nominee_free_cb(void * data)
nominee_item = NULL;
}
}
-
+/*
void ht_candidate_free_cb(void * data)
{
struct mrl_candidate_item *candidate_item = (struct mrl_candidate_item *)data;
@@ -36,7 +36,7 @@ void ht_candidate_free_cb(void * data)
candidate_item = NULL;
}
}
-
+*/
MESA_htable_handle mrl_htable_init(void * fn_data_free_cb)
{
printf("mrl htable init\n");
@@ -134,6 +134,11 @@ int mrl_get_candidate_location(const char *ip_addr)
const char *mycountry="China";
int location = 0;
location = mrl_search_ip_country(mrl_instance.mrl_mmdb, ip_addr, mycountry);
+ if(location < 0)
+ {
+ MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_FATAL,"mrl_get_candidate_location","cur ip addr %s not exist in mmdb",ip_addr);
+ return 0;
+ }
return location;
}
void mrl_create_candidate_item(struct mrl_candidate_item *candidate_item, struct mrl_nominee_item *nominee_item)
@@ -144,7 +149,6 @@ void mrl_create_candidate_item(struct mrl_candidate_item *candidate_item, struct
memcpy(candidate_item->ip_addr,nominee_item->ip_addr,strlen(nominee_item->ip_addr));
//to do how to get ip location
candidate_item->location = mrl_get_candidate_location(candidate_item->ip_addr);
- assert(candidate_item->location >= 0);
memcpy(candidate_item->mrl_ip, mrl_instance.mrl_cfg.mrl_ip,strlen(mrl_instance.mrl_cfg.mrl_ip));
candidate_item->is_vaild = 1;
get_cur_time(candidate_item->op_time);
@@ -153,39 +157,55 @@ void mrl_create_candidate_item(struct mrl_candidate_item *candidate_item, struct
void nominee_update_cb(int table_id,const char* table_line,void* u_para)
{
int ret = 0;
- printf("this is nominee update cb\n");
+ uint32_t client_ip = 0;
struct mrl_nominee_item *nominee_item = (struct mrl_nominee_item *)calloc(1, sizeof(struct mrl_nominee_item));
sscanf(table_line,"%d\t%d\t%d\t%s\t%d\t%s",
&(nominee_item->config_id), &(nominee_item->group_id), &(nominee_item->addr_type),
nominee_item->ip_addr, &(nominee_item->is_vaild), nominee_item->op_time);
+ MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"nominee_update_cb","get nominee item:"
+ "config_id:%d,group_id:%d,addr_type:%d,ip_addr:%s,is_vaild:%d,op_time:%s",
+ nominee_item->config_id, nominee_item->group_id,nominee_item->addr_type,
+ nominee_item->ip_addr, nominee_item->is_vaild,nominee_item->op_time);
switch(nominee_item->is_vaild)
{
case 0:
- ret = MESA_htable_del(mrl_instance.ht_nominee, (const unsigned char *)nominee_item->ip_addr, sizeof(nominee_item->ip_addr), NULL);
- assert(ret >= 0);
- if(MESA_htable_search_cb(mrl_instance.ht_candidate, (const unsigned char *)nominee_item->ip_addr, sizeof(nominee_item->ip_addr),NULL,NULL,NULL) != NULL)
+ if(MESA_htable_search_cb(mrl_instance.ht_nominee, (const unsigned char *)nominee_item->ip_addr, MRL_STR_IP_LEN,NULL,NULL,NULL) == NULL)
+ {
+ ret = MESA_htable_del(mrl_instance.ht_nominee, (const unsigned char *)nominee_item->ip_addr, MRL_STR_IP_LEN, NULL);
+ if(ret < 0)
+ {
+ MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_FATAL,"nominee_update_cb","MESA_htable_del func error! ret is %d",ret);
+ assert(0);
+ }
+ }
+ else
{
- ret = MESA_htable_del(mrl_instance.ht_candidate, (const unsigned char *)nominee_item->ip_addr, sizeof(nominee_item->ip_addr), NULL);
- assert(ret >= 0);
+ MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"nominee_update_cb","the nominee item %s is not exsit in nominee htable.",nominee_item->ip_addr);
}
break;
case 1:
- if(MESA_htable_search_cb(mrl_instance.ht_candidate, (const unsigned char *)nominee_item->ip_addr, sizeof(nominee_item->ip_addr),NULL,NULL,NULL) == NULL)
+ if(MESA_htable_search_cb(mrl_instance.ht_nominee, (const unsigned char *)nominee_item->ip_addr, MRL_STR_IP_LEN,NULL,NULL,NULL) == NULL)
{
- ret = MESA_htable_add(mrl_instance.ht_nominee, (const unsigned char *)nominee_item->ip_addr, sizeof(nominee_item->ip_addr), nominee_item);
- if(ret < 0)
- {
+ ret = MESA_htable_add(mrl_instance.ht_nominee, (const unsigned char *)nominee_item->ip_addr, MRL_STR_IP_LEN, nominee_item);
+ if(ret < 0)
+ {
MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_FATAL,"nominee_update_cb","MESA_htable_add func error! ret is %d",ret);
assert(0);
- }
+ }
+ inet_pton(AF_INET,nominee_item->ip_addr,&client_ip);
+ ret = MESA_lqueue_join_tail(mrl_instance.mrl_queue,&client_ip,sizeof(client_ip));
+ MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_FATAL,"nominee_update_cb","insert queue ip is %u",client_ip);
+ if(ret != 0)
+ {
+ MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_FATAL,"nominee_update_cb","MESA_lqueue_join_tail func error! ret is %d",ret);
+ assert(0);
+ }
}
else
{
- MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_FATAL,"nominee_update_cb","the nominee item is duplicated in nominee htable.");
+ MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"nominee_update_cb","the nominee item %s is duplicated in nominee htable.",nominee_item->ip_addr);
}
- //todo active detect
- mrl_detect_action(nominee_item->ip_addr);
- break;
+ break;
default:
assert(0);
break;
@@ -193,7 +213,7 @@ void nominee_update_cb(int table_id,const char* table_line,void* u_para)
}
-
+/*
void candidate_update_cb(int table_id,const char* table_line,void* u_para)
{
int ret = 0;
@@ -223,7 +243,7 @@ void candidate_update_cb(int table_id,const char* table_line,void* u_para)
}
}
-
+*/
long ht_search_cb(void *data, const uchar *key, uint size, void *user_arg)
{
struct mrl_nominee_item *nominee_item = (struct mrl_nominee_item *)data;
@@ -242,6 +262,7 @@ void mrl_get_vxlan_info(struct mrl_vxlan_info *vxlan, unsigned int index)
memcpy(vxlan->vxlan_inner_smac, mrl_instance.mrl_cfg.vxlan_inner_smac[index],strlen(mrl_instance.mrl_cfg.vxlan_inner_smac[index]));
memcpy(vxlan->vxlan_inner_dmac, mrl_instance.mrl_cfg.vxlan_inner_dmac[index], strlen(mrl_instance.mrl_cfg.vxlan_inner_dmac[index]));
vxlan->vxlan_encap_type = atoi(mrl_instance.mrl_cfg.vxlan_encap_type[index]);
+ vxlan->vxlan_vpn_id= atoi(mrl_instance.mrl_cfg.vxlan_vpn_id[index]);
vxlan->vxlan_link_id = atoi(mrl_instance.mrl_cfg.vxlan_link_id[index]);
vxlan->vxlan_link_dir = atoi(mrl_instance.mrl_cfg.vxlan_link_dir[index]);
memcpy(vxlan->vxlan_outer_local_port, mrl_instance.mrl_cfg.xvlan_outer_local_port,strlen(mrl_instance.mrl_cfg.xvlan_outer_local_port));
@@ -250,27 +271,11 @@ void mrl_get_vxlan_info(struct mrl_vxlan_info *vxlan, unsigned int index)
memcpy(vxlan->vxlan_outer_gdev_ip, mrl_instance.mrl_cfg.vxlan_outer_gdev_ip[index],strlen(mrl_instance.mrl_cfg.vxlan_outer_gdev_ip[index]));
memcpy(vxlan->vxlan_outer_local_mac, mrl_instance.mrl_cfg.vxlan_outer_local_mac,strlen(mrl_instance.mrl_cfg.vxlan_outer_local_mac));
memcpy(vxlan->vxlan_outer_gdev_mac, mrl_instance.mrl_cfg.vxlan_outer_gdev_mac[index],strlen(mrl_instance.mrl_cfg.vxlan_outer_gdev_mac[index]));
- printf("get vxlan opt from rawpkt:inner_smac:%s, inner_dmac:%s,encap_type:%d,link_id:%d, link_dir:%d,local_port:%s,"
- "gdev_port:%s, local_ip:%s,gdev_ip:%s,local_mac:%s, gdev_mac:%s\n",
- vxlan->vxlan_inner_smac, vxlan->vxlan_inner_dmac, vxlan->vxlan_encap_type,
- vxlan->vxlan_link_id, vxlan->vxlan_link_dir,vxlan->vxlan_outer_local_port,
- vxlan->vxlan_outer_gdev_port,vxlan->vxlan_outer_local_ip,vxlan->vxlan_outer_gdev_ip,
- vxlan->vxlan_outer_local_mac,vxlan->vxlan_outer_gdev_mac);
-
- MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_get_candidate_vxlan_info", "get vxlan opt from rawpkt:"
- "inner_smac:%s, inner_dmac:%s,encap_type:%d,link_id:%d, link_dir:%d,local_port:%s,"
- "gdev_port:%s, local_ip:%s,gdev_ip:%s,local_mac:%s, gdev_mac:%s",
- vxlan->vxlan_inner_smac, vxlan->vxlan_inner_dmac, vxlan->vxlan_encap_type,
- vxlan->vxlan_link_id, vxlan->vxlan_link_dir,vxlan->vxlan_outer_local_port,
- vxlan->vxlan_outer_gdev_port,vxlan->vxlan_outer_local_ip,vxlan->vxlan_outer_gdev_ip,
- vxlan->vxlan_outer_local_mac,vxlan->vxlan_outer_gdev_mac);
-
}
void Maat_set_cmd_line(Maat_feather_t feather, struct mrl_candidate_item *candidate_item)
{
- printf("start to insert candidate table\n");
const struct Maat_line_t *p_line;
struct Maat_line_t line_rule;
char table_line[512];
@@ -280,15 +285,16 @@ void Maat_set_cmd_line(Maat_feather_t feather, struct mrl_candidate_item *candid
line_rule.label_id=0;
line_rule.rule_id=candidate_item->config_id;
line_rule.table_name=IR_CANDIDATE_IP_TABLE_NAME;
- snprintf(table_line,sizeof(table_line),"%d\t%d\t%d\t%s\t%d\t%s\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%s",
+ snprintf(table_line,sizeof(table_line),"%d\t%d\t%d\t%s\t%d\t%s\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%s",
candidate_item->config_id, candidate_item->group_id,candidate_item->addr_type,
candidate_item->ip_addr,candidate_item->location, candidate_item->mrl_ip,
candidate_item->vxlan_info.vxlan_link_id,candidate_item->vxlan_info.vxlan_encap_type,
- candidate_item->vxlan_info.vxlan_link_dir,candidate_item->vxlan_info.vxlan_outer_local_port,
- candidate_item->vxlan_info.vxlan_outer_gdev_port,candidate_item->vxlan_info.vxlan_outer_local_ip,
- candidate_item->vxlan_info.vxlan_outer_gdev_ip,candidate_item->vxlan_info.vxlan_outer_local_mac,
- candidate_item->vxlan_info.vxlan_outer_gdev_mac,candidate_item->vxlan_info.vxlan_inner_smac,
- candidate_item->vxlan_info.vxlan_inner_dmac,candidate_item->is_vaild, candidate_item->op_time);
+ candidate_item->vxlan_info.vxlan_link_dir,candidate_item->vxlan_info.vxlan_vpn_id,
+ candidate_item->vxlan_info.vxlan_outer_local_port,candidate_item->vxlan_info.vxlan_outer_gdev_port,
+ candidate_item->vxlan_info.vxlan_outer_local_ip,candidate_item->vxlan_info.vxlan_outer_gdev_ip,
+ candidate_item->vxlan_info.vxlan_outer_local_mac,candidate_item->vxlan_info.vxlan_outer_gdev_mac,
+ candidate_item->vxlan_info.vxlan_inner_smac,candidate_item->vxlan_info.vxlan_inner_dmac,
+ candidate_item->is_vaild, candidate_item->op_time);
line_rule.table_line=table_line;
line_rule.expire_after=0;
p_line = &line_rule;
@@ -296,9 +302,20 @@ void Maat_set_cmd_line(Maat_feather_t feather, struct mrl_candidate_item *candid
if(ret < 0)
{
MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_FATAL,"Maat_set_cmd_line","Maat_cmd_set_lines func error! ret is %d",ret);
- assert(0);
}
-
+ MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"Maat_set_cmd_line","maat set candidate item:"
+ "config_id:%d,group_id:%d,addr_type:%d,ip_addr:%s,location:%d,mrl_ip:%s,link_id:%d,encap_type:%d,"
+ "link_dir:%d,vpn_id:%d,local_port:%s,gdev_port:%s, local_ip:%s,gdev_ip:%s,local_mac:%s, gdev_mac:%s,"
+ "inner_smac:%s, inner_dmac:%s,is_vaild:%d,op_time:%s",
+ candidate_item->config_id, candidate_item->group_id,candidate_item->addr_type, candidate_item->ip_addr,
+ candidate_item->location, candidate_item->mrl_ip,candidate_item->vxlan_info.vxlan_link_id,
+ candidate_item->vxlan_info.vxlan_encap_type, candidate_item->vxlan_info.vxlan_link_dir,
+ candidate_item->vxlan_info.vxlan_vpn_id,
+ candidate_item->vxlan_info.vxlan_outer_local_port,candidate_item->vxlan_info.vxlan_outer_gdev_port,
+ candidate_item->vxlan_info.vxlan_outer_local_ip,candidate_item->vxlan_info.vxlan_outer_gdev_ip,
+ candidate_item->vxlan_info.vxlan_outer_local_mac,candidate_item->vxlan_info.vxlan_outer_gdev_mac,
+ candidate_item->vxlan_info.vxlan_inner_smac, candidate_item->vxlan_info.vxlan_inner_dmac,
+ candidate_item->is_vaild,candidate_item->op_time);
return;
}
@@ -320,26 +337,23 @@ unsigned int get_gdev_ip_index(UINT32 gdev_ip)
void mrl_identify_nominee(struct streaminfo *mystream)
{
- char dip[MRL_STR_IP_LEN];
- memset(dip,0,MRL_STR_IP_LEN);
-
+ char ip_addr[MRL_STR_IP_LEN];
+ memset(ip_addr,0,MRL_STR_IP_LEN);
uint32_t gdev_ip;
+ long ret = 0;
unsigned int index = 0;
struct mrl_candidate_item candidate_item;
memset(&candidate_item ,0,sizeof(struct mrl_candidate_item));
- inet_ntop(AF_INET, &(mystream->addr.tuple4_v4->daddr), dip, MRL_STR_IP_LEN);
- if(MESA_htable_search_cb(mrl_instance.ht_nominee, (const unsigned char *)dip, MRL_STR_IP_LEN,ht_search_cb,(void *)&candidate_item,NULL) != NULL)
+ inet_ntop(AF_INET, &(mystream->addr.tuple4_v4->saddr), ip_addr, MRL_STR_IP_LEN);
+ MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_identify_nominee","cur identify nominee stream ip is %s\n",ip_addr);
+ if(MESA_htable_search_cb(mrl_instance.ht_nominee, (const unsigned char *)ip_addr, MRL_STR_IP_LEN,ht_search_cb,(void *)&candidate_item,&ret) != NULL)
{
get_rawpkt_opt_from_streaminfo(mystream, RAW_PKT_GET_GDEV_IP, &(gdev_ip));
- printf("cur gdev ip is %d\n",gdev_ip);
+ //printf("cur gdev ip is %d\n",gdev_ip);
index = get_gdev_ip_index(gdev_ip);
- printf("cur gdev info index is %d\n",index);
+ //printf("cur gdev info index is %d\n",index);
assert(index < mrl_instance.mrl_cfg.vxlan_gdev_num);//������ھ�˵�������ݰ���GDEV��������̽���GDEV�У�����
- mrl_get_vxlan_info(&(candidate_item.vxlan_info),index);
- MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_identify_nominee","get candidate item:"
- "config_id:%d,group_id:%d,addr_type:%d,ip_addr:%s,location:%d,mrl_ip:%s,is_vaild:%d,op_time:%s",
- candidate_item.config_id, candidate_item.group_id,candidate_item.addr_type, candidate_item.ip_addr,
- candidate_item.location, candidate_item.mrl_ip,candidate_item.is_vaild,candidate_item.op_time);
+ mrl_get_vxlan_info(&(candidate_item.vxlan_info),index);
Maat_set_cmd_line(mrl_instance.candidate_feather,&candidate_item);
}
}
diff --git a/src/mrl_redis.o b/src/mrl_redis.o
deleted file mode 100644
index a5987ea..0000000
--- a/src/mrl_redis.o
+++ /dev/null
Binary files differ
diff --git a/src/mrl_utils.o b/src/mrl_utils.o
deleted file mode 100644
index 83236e2..0000000
--- a/src/mrl_utils.o
+++ /dev/null
Binary files differ