Commit 061832ae authored by wangyongshou's avatar wangyongshou

Optimize multiple GNB multiple GTPU TUNNEL codes

parent 0f7e1add
...@@ -54,9 +54,9 @@ unix_main_t *um = &unix_main; ...@@ -54,9 +54,9 @@ unix_main_t *um = &unix_main;
extern vlib_main_t vlib_global_main; extern vlib_main_t vlib_global_main;
extern bupt_ueip_dl_gtpu4_header_t *bupt_ueip_dl_gtpu4_header; extern bupt_ueip_dl_gtpu4_header_t *bupt_ueip_dl_gtpu4_header;
//Gtpu N3 interface index 1 ;
#define UPF_BUF 1024
const u32 gtpu_n3_dst_sw_if_index = 1; const u32 gtpu_n3_dst_sw_if_index = 1;
#define GTPU_TUNNEL "create gtpu tunnel src %s dst %s teid %u encap-vrf-id 0 decap-next node ip4-lookup\n" #define GTPU_TUNNEL "create gtpu tunnel src %s dst %s teid %u encap-vrf-id 0 decap-next node ip4-lookup\n"
...@@ -65,84 +65,80 @@ const u32 gtpu_n3_dst_sw_if_index = 1; ...@@ -65,84 +65,80 @@ const u32 gtpu_n3_dst_sw_if_index = 1;
void upf_ip4_to_str( u32 ip4addr, char *str, const u16 buf_len) void upf_ip4_to_str( u32 ip4addr, char *str, const u16 buf_len)
{ {
u32 addr1_1 = ip4addr >> 24; // 提取第一部分IP地址 u32 addr1_1 = ip4addr >> 24;
ip4addr = ip4addr << 8; ip4addr = ip4addr << 8;
u32 addr1_2 = ip4addr >> 24; // 提取第二部分IP地址 u32 addr1_2 = ip4addr >> 24;
ip4addr = ip4addr << 8; ip4addr = ip4addr << 8;
u32 addr1_3 = ip4addr >> 24; // 提取第三部分IP地址 u32 addr1_3 = ip4addr >> 24;
ip4addr = ip4addr << 8; ip4addr = ip4addr << 8;
u32 addr1_4 = ip4addr >> 24; // 提取第四部分IP地址 u32 addr1_4 = ip4addr >> 24;
snprintf(str, buf_len,"%u.%u.%u.%u",addr1_1, addr1_2, addr1_3, addr1_4); snprintf(str, buf_len,"%u.%u.%u.%u",addr1_1, addr1_2, addr1_3, addr1_4);
} }
void upf_create_gtpu_tunnel(const u32 n3_local_ip, const u32 n3_remote_ip, const u32 teid, char *gtpu_name) void upf_create_gtpu_tunnel(const u32 n3_local_ip, const u32 n3_remote_ip, const u32 teid, char *gtpu_name)
{ {
#define BUF_LEN 1024
u8 *buf = NULL;
vlib_main_t * vm = &vlib_global_main; char n3_local[UPF_BUF] = {0};
u8 *buf = NULL; char n3_remote[UPF_BUF] = {0};
vlib_main_t * vm = &vlib_global_main;
char n3_local[1024] = {0};
char n3_remote[1024] = {0}; upf_ip4_to_str(n3_local_ip, n3_local, UPF_BUF);
upf_ip4_to_str(n3_remote_ip, n3_remote, UPF_BUF);
upf_ip4_to_str(n3_local_ip, n3_local, 1024);
upf_ip4_to_str(n3_remote_ip, n3_remote, 1024); char cmd[BUF_LEN] = {0} ;
snprintf(cmd, UPF_BUF, GTPU_TUNNEL, n3_local, n3_remote, teid);
char cmd[BUF_LEN] = {0} ;
snprintf(cmd, BUF_LEN, GTPU_TUNNEL, n3_local, n3_remote, teid); unformat_input_t sub_input;
vec_resize (buf, UPF_BUF);
unformat_input_t sub_input;
vec_resize (buf, BUF_LEN); //vec_copy(buf, cmd);
//vec_copy(buf, cmd); strncpy((char *)buf, cmd, strlen(cmd));
clib_upf_debug(um->log_fd, "\n\n***** Startup Config *****\n\n%s\n***** End Startup Config *****\n\n",cmd);
strncpy((char *)buf, cmd, strlen(cmd));
clib_upf_debug(um->log_fd, "\n\n***** Startup Config *****\n\n%s\n***** End Startup Config *****\n\n",cmd); if(vec_len (buf))
{
if(vec_len (buf)) unformat_init_vector (&sub_input, buf);
{ vlib_cli_input (vm, &sub_input, 0, 0);
unformat_init_vector (&sub_input, buf);
vlib_cli_input (vm, &sub_input, 0, 0); //clib_upf_debug(um->log_fd, "len:%d,name:%s", sub_input.index, sub_input.buffer);
clib_upf_debug(um->log_fd, "len:%d,name:%s", sub_input.index, sub_input.buffer); strncpy(gtpu_name, (char *)sub_input.buffer, sub_input.index);
strncpy(gtpu_name, (char *)sub_input.buffer, sub_input.index); /* frees buf for us */
unformat_free (&sub_input);
/* frees buf for us */ }
unformat_free (&sub_input);
}
} }
void upf_create_ip_route(const u32 ue_ip, const char *gtpu_name) void upf_create_ip_route(const u32 ue_ip, const char *gtpu_name)
{ {
#define BUF_LEN 1024
u8 *buf = NULL;
vlib_main_t * vm = &vlib_global_main; char cmd[UPF_BUF] = {0};
u8 *buf = NULL; char ueaddr[UPF_BUF]= {0};
char cmd[BUF_LEN] = {0};
char ueaddr[BUF_LEN]= {0}; vlib_main_t * vm = &vlib_global_main;
upf_ip4_to_str(ue_ip, ueaddr, UPF_BUF);
upf_ip4_to_str(ue_ip, ueaddr, BUF_LEN); snprintf(cmd, UPF_BUF, IP_ROUTE, ueaddr, gtpu_name);
snprintf(cmd, BUF_LEN, IP_ROUTE, ueaddr, gtpu_name); unformat_input_t sub_input;
vec_resize (buf, UPF_BUF);
unformat_input_t sub_input;
vec_resize (buf, BUF_LEN); strncpy((char *)buf, cmd, strlen(cmd));
clib_upf_debug(um->log_fd, "\n\n***** Startup Config *****\n\n%s\n***** End Startup Config *****\n\n",cmd);
strncpy((char *)buf, cmd, strlen(cmd));
clib_upf_debug(um->log_fd, "\n\n***** Startup Config *****\n\n%s\n***** End Startup Config *****\n\n",cmd); if(vec_len (buf))
{
if(vec_len (buf)) unformat_init_vector (&sub_input, buf);
{ vlib_cli_input (vm, &sub_input, 0, 0);
unformat_init_vector (&sub_input, buf);
vlib_cli_input (vm, &sub_input, 0, 0); /* frees buf for us */
unformat_free (&sub_input);
/* frees buf for us */ }
unformat_free (&sub_input);
}
} }
static void static void
upf_ip_udp_gtpu_rewrite (/*upf_far_forward_t * ff */upf_far_t *ff, u32 fib_index, int is_ip4) upf_ip_udp_gtpu_rewrite (/*upf_far_forward_t * ff */upf_far_t *ff, u32 fib_index, int is_ip4)
{ {
union union
...@@ -157,8 +153,8 @@ upf_ip_udp_gtpu_rewrite (/*upf_far_forward_t * ff */upf_far_t *ff, u32 fib_index ...@@ -157,8 +153,8 @@ upf_ip_udp_gtpu_rewrite (/*upf_far_forward_t * ff */upf_far_t *ff, u32 fib_index
vec_validate_aligned (r.rw, len - 1, CLIB_CACHE_LINE_BYTES); vec_validate_aligned (r.rw, len - 1, CLIB_CACHE_LINE_BYTES);
char n3_local[1024] = {0}; //char n3_local[1024] = {0};
char n3_remote[1024] = {0}; //char n3_remote[1024] = {0};
udp_header_t *udp = NULL; udp_header_t *udp = NULL;
gtpu_header_t *gtpu = NULL; gtpu_header_t *gtpu = NULL;
...@@ -182,11 +178,11 @@ upf_ip_udp_gtpu_rewrite (/*upf_far_forward_t * ff */upf_far_t *ff, u32 fib_index ...@@ -182,11 +178,11 @@ upf_ip_udp_gtpu_rewrite (/*upf_far_forward_t * ff */upf_far_t *ff, u32 fib_index
ip4_address_t src_address = *(ip4_address_t *)ip_interface_get_first_ip (gtpu_n3_dst_sw_if_index, is_ip4); ip4_address_t src_address = *(ip4_address_t *)ip_interface_get_first_ip (gtpu_n3_dst_sw_if_index, is_ip4);
ip->src_address.data_u32 = src_address.data_u32; ip->src_address.data_u32 = src_address.data_u32;
ip->dst_address = ff->forward.outer_header_creation.ip.ip4; ip->dst_address = ff->forward.outer_header_creation.ip.ip4;
upf_ip4_to_str(clib_net_to_host_u32(ip->src_address.data_u32), n3_local, 1024); //upf_ip4_to_str(clib_net_to_host_u32(ip->src_address.data_u32), n3_local, 1024);
upf_ip4_to_str(clib_net_to_host_u32(ip->dst_address.data_u32), n3_remote, 1024); //upf_ip4_to_str(clib_net_to_host_u32(ip->dst_address.data_u32), n3_remote, 1024);
/* we fix up the ip4 header length and checksum after-the-fact */ /* we fix up the ip4 header length and checksum after-the-fact */
ip->checksum = ip4_header_checksum (ip); ip->checksum = ip4_header_checksum (ip);
...@@ -200,12 +196,12 @@ upf_ip_udp_gtpu_rewrite (/*upf_far_forward_t * ff */upf_far_t *ff, u32 fib_index ...@@ -200,12 +196,12 @@ upf_ip_udp_gtpu_rewrite (/*upf_far_forward_t * ff */upf_far_t *ff, u32 fib_index
clib_host_to_net_u32 (6 << 28); clib_host_to_net_u32 (6 << 28);
ip->hop_limit = 255; ip->hop_limit = 255;
ip->protocol = IP_PROTOCOL_UDP; ip->protocol = IP_PROTOCOL_UDP;
ip->dst_address = ff->forward.outer_header_creation.ip.ip6; ip->dst_address = ff->forward.outer_header_creation.ip.ip6;
} }
/* UDP header, randomize src port on something, maybe? */ /* UDP header, randomize src port on something, maybe? */
udp->src_port = clib_host_to_net_u16 (UDP_DST_PORT_GTPU); udp->src_port = clib_host_to_net_u16 (UDP_DST_PORT_GTPU);
udp->dst_port = clib_host_to_net_u16(ff->forward.outer_header_creation.port); udp->dst_port = clib_host_to_net_u16(ff->forward.outer_header_creation.port);
...@@ -214,8 +210,8 @@ upf_ip_udp_gtpu_rewrite (/*upf_far_forward_t * ff */upf_far_t *ff, u32 fib_index ...@@ -214,8 +210,8 @@ upf_ip_udp_gtpu_rewrite (/*upf_far_forward_t * ff */upf_far_t *ff, u32 fib_index
gtpu->type = GTPU_TYPE_GTPU; gtpu->type = GTPU_TYPE_GTPU;
gtpu->teid = clib_host_to_net_u32 (ff->forward.outer_header_creation.teid); gtpu->teid = clib_host_to_net_u32 (ff->forward.outer_header_creation.teid);
clib_upf_debug(um->log_fd,"src_ip:%s, dst_ip:%s, ff:%p", n3_local, n3_remote, ff); //clib_upf_debug(um->log_fd,"src_ip:%s, dst_ip:%s, ff:%p", n3_local, n3_remote, ff);
ff->forward.rewrite = r.rw; ff->forward.rewrite = r.rw;
......
...@@ -379,10 +379,10 @@ startup_config_process (vlib_main_t * vm, ...@@ -379,10 +379,10 @@ startup_config_process (vlib_main_t * vm,
{ {
//add it to inif config in 20210311 //add it to inif config in 20210311
{ {
#define BUF_LEN 1024 #define BUF_LEN 1024
#define IF_UP_IPADDR "set interface state %s up\nset interface ip address %s %s/%d\n\n" #define IF_UP_IPADDR "set interface state %s up\nset interface ip address %s %s/%d\n\n"
u8 *buf = NULL; u8 *buf = NULL;
char cmd[BUF_LEN] = {0}; char cmd[BUF_LEN] = {0};
char if_cmd[BUF_LEN] = {0}; char if_cmd[BUF_LEN] = {0};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment