diff options
| author | lijie <[email protected]> | 2018-11-13 19:41:13 +0800 |
|---|---|---|
| committer | lijie <[email protected]> | 2018-11-13 19:41:13 +0800 |
| commit | 5d2fa16a8ae712cf8d57b9d31a5980553b87167a (patch) | |
| tree | 7dc0f0e284b56478520de17c9b86107a88376d8f | |
| parent | 845ec90149a3099ebf4888a747dff572a46f82f0 (diff) | |
测试完成写candidate表功能
| -rw-r--r-- | bin/conf/mrl.conf | 16 | ||||
| -rw-r--r-- | bin/conf/table_info.conf | 19 | ||||
| -rw-r--r-- | include/mrl_main.h | 2 | ||||
| -rw-r--r-- | include/mrl_packet.h | 4 | ||||
| -rw-r--r-- | include/mrl_redis.h | 33 | ||||
| -rw-r--r-- | include/mrl_utils.h (renamed from include/mrl_base.h) | 5 | ||||
| -rw-r--r-- | src/Makefile | 2 | ||||
| -rw-r--r-- | src/mrl_main.c | 32 | ||||
| -rw-r--r-- | src/mrl_packet.c | 69 | ||||
| -rw-r--r-- | src/mrl_redis.c | 109 | ||||
| -rw-r--r-- | src/mrl_utils.c (renamed from src/mrl_base.c) | 14 |
11 files changed, 218 insertions, 87 deletions
diff --git a/bin/conf/mrl.conf b/bin/conf/mrl.conf index 19afbea..624e519 100644 --- a/bin/conf/mrl.conf +++ b/bin/conf/mrl.conf @@ -1,20 +1,20 @@ [LOG_INFO]
log_level=20
-log_path=./log/mrl1.log
+log_path=./log/mrl.log
[SOCK_INFO]
mrl_port=8000
mgw_port=8001
mgw_ip=127.0.0.1
[MAAT_INFO]
-Maat_table_path=./conf/Maat_table_info1.conf
+Maat_table_path=./conf/table_info.conf
Maat_max_threads=2
-Maat_redis_ip=127.1.1.1
-Maat_redis_port=8002
-Maat_stat_path=./log/Maat_stat1.log
+Maat_redis_ip=192.168.10.180
+Maat_redis_port=26379
+Maat_stat_path=./log/Maat_stat.log
[HTABLE_INFO]
-ht_slots=1000
-ht_max_element_num=1
-ht_mutex_num=2
+ht_slots=100000
+ht_max_element_num=1000
+ht_mutex_num=5
[VXLAN_INFO]
vxlan_gdev_num=3
vxlan_gdev_mac=00:00:00:00:00:00,11:11:11:11:11:11,22:22:22:22:22:22
diff --git a/bin/conf/table_info.conf b/bin/conf/table_info.conf new file mode 100644 index 0000000..12fe05e --- /dev/null +++ b/bin/conf/table_info.conf @@ -0,0 +1,19 @@ +#each collumn seperate with '\t'
+#id (0~65535)
+#name string
+#type one of ip,expr,expr_plus,digest,intval,compile or plugin
+#src_charset one of GBK,BIG5,UNICODE,UTF8
+#dst_charset combined by GBK,BIG5,UNICODE,UTF8,seperate with '/'
+#do_merege [yes/no]
+#cross cache [number]
+#quick mode [quickon/quickoff], default [quickoff]
+#For ip/intval/digest/compile/group
+#id name type
+#
+#For plugin table
+#id name type valid_column
+#
+#For expr/expr_plus Table
+#id name type src_charset dst_charset do_merge cross_cache quick_mode
+0 IR_NOMINEE_IP plugin 4 --
+1 IR_CANDIDATE_IP plugin 4 --
\ No newline at end of file diff --git a/include/mrl_main.h b/include/mrl_main.h index d6f029a..5f47ad2 100644 --- a/include/mrl_main.h +++ b/include/mrl_main.h @@ -15,7 +15,7 @@ #define MRL_STR_PORT_LEN 6
#define MRL_STR_IP_LEN 16
-#define DATE_LEN 50
+#define MRL_DATE_LEN 50
#define MRL_MAX_PATH 50
diff --git a/include/mrl_packet.h b/include/mrl_packet.h index 4378c80..da14d50 100644 --- a/include/mrl_packet.h +++ b/include/mrl_packet.h @@ -9,6 +9,10 @@ void mrl_send_to_gdev(int thread_seq, struct mrl_vxlan_info * vxlan_info, const 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 detect_ip_addr(const char *ip_addr);
+
+
#endif
diff --git a/include/mrl_redis.h b/include/mrl_redis.h index bdf35f9..84578f3 100644 --- a/include/mrl_redis.h +++ b/include/mrl_redis.h @@ -4,25 +4,16 @@ #include "mrl_main.h"
#define IR_NOMINEE_IP_TABLE_NAME "IR_NOMINEE_IP"
-#define IR_CANDIDATE_IP_TABLE_NAME "IR_CANDINATE_IP"
-#define REDIS_CANDIATE_KEY_NAME "IR_CANDIDATE_ID"
+#define IR_CANDIDATE_IP_TABLE_NAME "IR_CANDIDATE_IP"
+//#define REDIS_CANDIATE_KEY_NAME "IR_CANDIDATE_ID"
struct mrl_nominee_item{
- int region_id;
+ int config_id;
int group_id;
int addr_type;
- char src_ip[MRL_STR_IP_LEN];
- char mask_src_ip[MRL_STR_IP_LEN];
- char dport[MRL_STR_PORT_LEN];
- char mask_dport[MRL_STR_PORT_LEN];
- int protocol;
- int direction;
+ char ip_addr[MRL_STR_IP_LEN];
int is_vaild;
- int action;
- int service;
- char date[DATE_LEN];
- int type;
- int strategy_group_id;
+ char op_time[MRL_DATE_LEN];
};
struct mrl_vxlan_info{
@@ -39,23 +30,23 @@ struct mrl_vxlan_info{ char vxlan_inner_dmac[MRL_STR_MAC_LEN];
};
struct mrl_candidate_item{
- int candidate_id;
+ int config_id;
+ int group_id;
int addr_type;
- char client_ip[MRL_STR_IP_LEN];//�ͻ���IP
- int type;
+ char ip_addr[MRL_STR_IP_LEN];//�ͻ���IP
int location;
- int group_id;
char mrl_ip[MRL_STR_IP_LEN];
struct mrl_vxlan_info vxlan_info;
+ int is_vaild;
+ char op_time[MRL_DATE_LEN];
};
MESA_htable_handle mrl_htable_init(void * fn_data_free_cb);
+
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);
diff --git a/include/mrl_base.h b/include/mrl_utils.h index ab34663..63a489b 100644 --- a/include/mrl_base.h +++ b/include/mrl_utils.h @@ -1,8 +1,9 @@ -#ifndef __MRL_BASE_H_
-#define __MRL_BASE_H_
+#ifndef __MRL_UTILS_H_
+#define __MRL_UTILS_H_
unsigned int mrl_split_str(char *str, const char *delim, char **dest);
int mrl_mac_pton(const char *str, int delim, char *mac);
+void get_cur_time(char *time);
#endif
diff --git a/src/Makefile b/src/Makefile index ac5d78f..173523b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -18,7 +18,7 @@ LIBS += -lMESA_prof_load -lMESA_handle_logger -lpthread -lmaatframe -lMESA_htabl TARGET = mrl
-OBJS = mrl_main.o mrl_base.o mrl_packet.o mrl_redis.o
+OBJS = mrl_main.o mrl_utils.o mrl_packet.o mrl_redis.o
.PHONY: all clean install
diff --git a/src/mrl_main.c b/src/mrl_main.c index 6c16982..9662cb3 100644 --- a/src/mrl_main.c +++ b/src/mrl_main.c @@ -5,7 +5,7 @@ #include <assert.h>
#include "mrl_main.h"
-#include "mrl_base.h"
+#include "mrl_utils.h"
#include "mrl_redis.h"
#include "mrl_packet.h"
@@ -53,7 +53,7 @@ void mrl_cfg_init(const char *profile) /********** load maat info **********/
- MESA_load_profile_string_def(profile, "MAAT_INFO", "Maat_table_path", mrl_instance.mrl_cfg.Maat_table_path, MRL_MAX_PATH, "./conf/Maat_table_info.conf");
+ 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);
@@ -167,7 +167,6 @@ void mrl_cfg_init(const char *profile) free(temp_link_dir_str);
}
-
extern "C" int mrl_init(void)
{
@@ -178,7 +177,6 @@ extern "C" int mrl_init(void) {
assert(0);
}
- return 1;
mrl_instance.ht_nominee = mrl_htable_init((void *)ht_nominee_free_cb);
mrl_instance.ht_candidate = mrl_htable_init((void *)ht_candidate_free_cb);
@@ -190,7 +188,7 @@ extern "C" int mrl_init(void) mrl_socket_init();
//TODO:read from nominee table and candidate table ifno and construct the packet
//send to the speficied destination
-
+ mrl_detect_init();
//���������߳̽��ղ�����mwg���͵����ݰ�
pthread_t pid;
if(pthread_create(&pid,NULL,mrl_recv_mgw_action,NULL) <0)
@@ -199,20 +197,34 @@ extern "C" int mrl_init(void) assert(0);
}
pthread_detach(pid);
+ return 1;
}
int main()
{
mrl_init();
int index = 0;
- struct mrl_candidate_item candidate_item;
char src_ip[]="192.168.11.23";
+ /*
+ struct mrl_nominee_item nominee_item;
+ memset(&nominee_item,0,sizeof(nominee_item));
+ nominee_item.config_id = 0;
+ nominee_item.group_id =1;
+ nominee_item.addr_type =4;
+ memcpy(nominee_item.ip_addr,src_ip,strlen(src_ip));
+ nominee_item.is_vaild = 1;
+ get_cur_time(nominee_item.op_time);
+ Maat_set_nominee_cmd_line(mrl_instance.nominee_feather, &nominee_item);
+*/
+ struct mrl_candidate_item candidate_item;
+ memset(&candidate_item, 0, sizeof(candidate_item));
+ candidate_item.config_id = 0;
+ candidate_item.group_id = 1;
candidate_item.addr_type = 4 ;
- memcpy(candidate_item.client_ip,src_ip,strlen(src_ip));
- candidate_item.type = 0;
- //to do how to get ip location
+ memcpy(candidate_item.ip_addr,src_ip,strlen(src_ip));
candidate_item.location = 0;
- candidate_item.group_id = 1;
+ candidate_item.is_vaild= 1;
+ get_cur_time(candidate_item.op_time);
memcpy(candidate_item.mrl_ip, mrl_instance.mrl_cfg.vxlan_outer_local_ip,strlen(mrl_instance.mrl_cfg.vxlan_outer_local_ip));
memcpy(candidate_item.vxlan_info.vxlan_inner_smac, mrl_instance.mrl_cfg.vxlan_inner_smac[index],strlen(mrl_instance.mrl_cfg.vxlan_inner_smac[index]));
memcpy(candidate_item.vxlan_info.vxlan_inner_dmac, mrl_instance.mrl_cfg.vxlan_inner_dmac[index], strlen(mrl_instance.mrl_cfg.vxlan_inner_dmac[index]));
diff --git a/src/mrl_packet.c b/src/mrl_packet.c index ac8cc7b..8871f91 100644 --- a/src/mrl_packet.c +++ b/src/mrl_packet.c @@ -8,7 +8,7 @@ #include "mrl_packet.h"
#include "mrl_main.h"
-#include "mrl_base.h"
+#include "mrl_utils.h"
#define MRL_MAC_LEN 6
#define MRL_BUFF_LEN 3000
@@ -66,7 +66,26 @@ void mrl_socket_close() ssize_t mrl_sock_send(int fd, const char *pkt, ssize_t pkt_len, struct sockaddr_in *dest)
{
ssize_t send_len = 0;
- send_len = sendto(fd, pkt,pkt_len,0,(struct sockaddr *)dest,sizeof(struct sockaddr_in));
+ while(1)
+ {
+ send_len = sendto(fd, pkt,pkt_len,0,(struct sockaddr *)dest,sizeof(struct sockaddr_in));
+ if(send_len < 0)
+ {
+ if(errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)
+ {
+ continue;
+ }
+ else
+ {
+ assert(0);
+ }
+
+ }
+ else
+ {
+ break;
+ }
+ }
return send_len;
}
@@ -75,7 +94,26 @@ ssize_t mrl_sock_recv(int fd, char *recv_buff, size_t buff_len) struct sockaddr_in from;
socklen_t from_len = sizeof(from);
ssize_t recv_len = 0;
- recv_len = recvfrom(fd, recv_buff, buff_len, 0, (struct sockaddr *) &from, & from_len);
+ while(1)
+ {
+ recv_len = recvfrom(fd, recv_buff, buff_len, 0, (struct sockaddr *) &from, & from_len);
+ if(recv_len < 0)
+ {
+ if(errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)
+ {
+ continue;
+ }
+ else
+ {
+ assert(0);
+ }
+
+ }
+ else
+ {
+ break;
+ }
+ }
return recv_len ;
}
@@ -213,7 +251,7 @@ void mrl_send_to_mgw(void *raw_pkt, int thread_seq) ssize_t pkt_len = strlen(pkt);
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);
+ if(send_len);
}
void *mrl_recv_mgw_action(void *arg)
@@ -237,3 +275,26 @@ void *mrl_recv_mgw_action(void *arg) }
+void detect_ip_addr(const char *ip_addr)
+{
+
+}
+
+void ht_nominee_iterate_cb(const uchar *key, uint size, void *data, void *user)
+{
+ if(data != NULL)
+ {
+ if(MESA_htable_search_cb(mrl_instance.ht_candidate, key, size, NULL,NULL, NULL) == NULL)
+ {
+ detect_ip_addr((const char *)key);
+ }
+ }
+
+}
+void mrl_detect_init()
+{
+ MESA_htable_iterate(mrl_instance.ht_nominee, ht_nominee_iterate_cb, NULL);
+
+}
+
+
diff --git a/src/mrl_redis.c b/src/mrl_redis.c index c1e8d8f..fbab059 100644 --- a/src/mrl_redis.c +++ b/src/mrl_redis.c @@ -2,6 +2,8 @@ #include<stdio.h>
#include "mrl_redis.h"
+#include "mrl_utils.h"
+#include "mrl_packet.h"
#define MRL_IPV4_TYPE 4
@@ -130,40 +132,40 @@ Maat_feather_t mrl_Maat_feather_init(const char * instance_name,const char *tabl void mrl_create_candidate_item(struct mrl_candidate_item *candidate_item, struct mrl_nominee_item *nominee_item)
{
- candidate_item->candidate_id = (int)Maat_cmd_incrby(mrl_instance.candidate_feather,REDIS_CANDIATE_KEY_NAME, 1);;
+ candidate_item->config_id = nominee_item->config_id;
+ candidate_item->group_id = nominee_item->group_id;
candidate_item->addr_type = MRL_IPV4_TYPE ;
- memcpy(candidate_item->client_ip,nominee_item->src_ip,strlen(nominee_item->src_ip));
- candidate_item->type = nominee_item->type;
+ memcpy(candidate_item->ip_addr,nominee_item->ip_addr,strlen(nominee_item->ip_addr));
//to do how to get ip location
candidate_item->location = 0;
- candidate_item->group_id = nominee_item->group_id;
memcpy(candidate_item->mrl_ip, mrl_instance.mrl_cfg.vxlan_outer_local_ip,strlen(mrl_instance.mrl_cfg.vxlan_outer_local_ip));
+ candidate_item->is_vaild = 1;
+ get_cur_time(candidate_item->op_time);
}
void nominee_update_cb(int table_id,const char* table_line,void* u_para)
{
int ret = 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%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%s\t%d\t%d",
- &(nominee_item->region_id), &(nominee_item->group_id), &(nominee_item->addr_type),
- nominee_item->src_ip, nominee_item->mask_src_ip, nominee_item->dport,
- nominee_item->mask_dport, &(nominee_item->protocol), &(nominee_item->direction),
- &(nominee_item->is_vaild), &(nominee_item->action), &(nominee_item->service),
- nominee_item->date, &(nominee_item->type), &(nominee_item->strategy_group_id));
+ 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);
switch(nominee_item->is_vaild)
{
case 0:
-
ret = MESA_htable_del(mrl_instance.ht_nominee, (const unsigned char *)nominee_item->src_ip, sizeof(nominee_item->src_ip), NULL);
+
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->src_ip), sizeof(nominee_item->src_ip),NULL,NULL,NULL) != NULL)
+ 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)
{
- ret = MESA_htable_del(mrl_instance.ht_candidate, (const unsigned char *)nominee_item->src_ip, sizeof(nominee_item->src_ip), NULL);
+ ret = MESA_htable_del(mrl_instance.ht_candidate, (const unsigned char *)nominee_item->ip_addr, sizeof(nominee_item->ip_addr), NULL);
assert(ret >= 0);
}
break;
case 1:
- ret = MESA_htable_add(mrl_instance.ht_nominee, (const unsigned char *)nominee_item->src_ip, sizeof(nominee_item->src_ip), nominee_item);
+ ret = MESA_htable_add(mrl_instance.ht_nominee, (const unsigned char *)nominee_item->ip_addr, sizeof(nominee_item->ip_addr), nominee_item);
assert(ret >= 0);
+ //todo active detect
+ detect_ip_addr(nominee_item->ip_addr);
break;
default:
assert(0);
@@ -175,17 +177,18 @@ 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;
struct mrl_candidate_item *candidate_item = (struct mrl_candidate_item *)calloc(1, sizeof(struct mrl_candidate_item));
- sscanf(table_line,"%d\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%d\t%d\t%d\t%s\t%s",
- &(candidate_item->candidate_id), &(candidate_item->addr_type), candidate_item->client_ip,
- &(candidate_item->type), &(candidate_item->location), &(candidate_item->group_id),
- candidate_item->mrl_ip,candidate_item->vxlan_info.vxlan_outer_local_mac,
- candidate_item->vxlan_info.vxlan_outer_gdev_mac,candidate_item->vxlan_info.vxlan_outer_local_ip,
- candidate_item->vxlan_info.vxlan_outer_gdev_ip,candidate_item->vxlan_info.vxlan_outer_local_port,
- candidate_item->vxlan_info.vxlan_outer_gdev_port,&(candidate_item->vxlan_info.vxlan_encap_type),
- &(candidate_item->vxlan_info.vxlan_link_id),&(candidate_item->vxlan_info.vxlan_link_dir),
- candidate_item->vxlan_info.vxlan_inner_smac,candidate_item->vxlan_info.vxlan_inner_dmac);
- int ret = MESA_htable_add(mrl_instance.ht_candidate, (const unsigned char *)(candidate_item->client_ip), sizeof(candidate_item->client_ip), candidate_item);
+ sscanf(table_line,"%d\t%d\t%d\t%s\t%d\t%s\t%d\t%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%s",
+ &(candidate_item->config_id), &(candidate_item->group_id),&(candidate_item->addr_type),
+ candidate_item->ip_addr,&(candidate_item->location),candidate_item->mrl_ip,
+ &(candidate_item->vxlan_info.vxlan_link_id), &(candidate_item->vxlan_info.vxlan_encap_type),
+ &(candidate_item->vxlan_info.vxlan_link_dir),candidate_item->vxlan_info.vxlan_outer_local_port,
+ candidate_item->vxlan_info.vxlan_outer_gdev_port,candidate_item->vxlan_info.vxlan_outer_local_ip,
+ candidate_item->vxlan_info.vxlan_outer_gdev_ip,candidate_item->vxlan_info.vxlan_outer_local_mac,
+ candidate_item->vxlan_info.vxlan_outer_gdev_mac,candidate_item->vxlan_info.vxlan_inner_smac,
+ candidate_item->vxlan_info.vxlan_inner_dmac,&(candidate_item->is_vaild), candidate_item->op_time);
+ ret = MESA_htable_add(mrl_instance.ht_candidate, (const unsigned char *)(candidate_item->ip_addr), sizeof(candidate_item->ip_addr), candidate_item);
assert(ret >= 0);
}
@@ -243,25 +246,30 @@ void Maat_set_cmd_line(Maat_feather_t feather, struct mrl_candidate_item *candid const struct Maat_line_t *p_line;
struct Maat_line_t line_rule;
char table_line[128];
- int ret=0,i=0;
+ int ret=0;
memset(&line_rule,0,sizeof(line_rule));
line_rule.label_id=0;
- line_rule.rule_id=(int)Maat_cmd_incrby(feather,"TEST_PLUG_SEQ", 1);
+ line_rule.rule_id=candidate_item->config_id;
line_rule.table_name=IR_CANDIDATE_IP_TABLE_NAME;
- snprintf(table_line,sizeof(table_line[i]),"%d\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%d\t%d\t%d\t%s\t%s",
- candidate_item->candidate_id, candidate_item->addr_type, candidate_item->client_ip,
- candidate_item->type, candidate_item->location, candidate_item->group_id,
- candidate_item->mrl_ip,candidate_item->vxlan_info.vxlan_outer_local_mac,
- candidate_item->vxlan_info.vxlan_outer_gdev_mac,candidate_item->vxlan_info.vxlan_outer_local_ip,
- candidate_item->vxlan_info.vxlan_outer_gdev_ip,candidate_item->vxlan_info.vxlan_outer_local_port,
- candidate_item->vxlan_info.vxlan_outer_gdev_port,candidate_item->vxlan_info.vxlan_encap_type,
- candidate_item->vxlan_info.vxlan_link_id,candidate_item->vxlan_info.vxlan_link_dir,
- candidate_item->vxlan_info.vxlan_inner_smac,candidate_item->vxlan_info.vxlan_inner_dmac);
+ 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",
+ 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);
line_rule.table_line=table_line;
line_rule.expire_after=0;
p_line = &line_rule;
ret=Maat_cmd_set_lines(feather, &p_line, 1, MAAT_OP_ADD);
- assert(ret>0);
+ 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(ret>0);
+ }
+
return;
}
@@ -276,11 +284,34 @@ void mrl_identify_nominee(struct streaminfo *mystream) {
mrl_get_candidate_vxlan_info(mystream,&(candidate_item.vxlan_info));
MESA_handle_runtime_log(mrl_instance.mrl_log_handle, RLOG_LV_DEBUG,"mrl_identify_nominee","get candidate item:"
- "candidate_id:%d,addr_type:%d,client_ip:%s,type:%d, location:%d,group_id:%d,mrl_ip:%s",
- candidate_item.candidate_id, candidate_item.addr_type, candidate_item.client_ip,
- candidate_item.type,candidate_item.location, candidate_item.group_id, candidate_item.mrl_ip);
+ "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);
Maat_set_cmd_line(mrl_instance.candidate_feather,&candidate_item);
}
}
+
+
+void Maat_set_nominee_cmd_line(Maat_feather_t feather, struct mrl_nominee_item *nominee_item)
+{
+ const struct Maat_line_t *p_line;
+ struct Maat_line_t line_rule;
+ char table_line[128];
+ int ret=0,i=0;
+ memset(&line_rule,0,sizeof(line_rule));
+ line_rule.label_id=0;
+ line_rule.rule_id=nominee_item->config_id;
+ line_rule.table_name=IR_NOMINEE_IP_TABLE_NAME;
+ snprintf(table_line,sizeof(table_line[i]),"%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);
+ line_rule.table_line=table_line;
+ line_rule.expire_after=0;
+ p_line = &line_rule;
+ ret=Maat_cmd_set_lines(feather, &p_line, 1, MAAT_OP_ADD);
+ assert(ret>0);
+ return;
+}
+
diff --git a/src/mrl_base.c b/src/mrl_utils.c index c7a29a4..46d135a 100644 --- a/src/mrl_base.c +++ b/src/mrl_utils.c @@ -2,7 +2,10 @@ #include<stdio.h>
#include<assert.h>
#include <ctype.h>
-#include "mrl_base.h"
+#include<time.h>
+
+#include "mrl_utils.h"
+#include "mrl_main.h"
/* ascii�ַ�ת16���� */
char mrl_ascii_to_hex(char ascii)
{
@@ -138,3 +141,12 @@ unsigned int mrl_split_str(char *str, const char *delim, char **dest) return i;
}
+void get_cur_time(char *date)
+{
+ time_t t;
+ struct tm *lt;
+ time(&t);
+ lt = localtime(&t);
+ snprintf(date, MRL_DATE_LEN,"%d/%d/%d %d:%d:%d",lt->tm_year+1900, lt->tm_mon, lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec);
+}
+
|
