Commit d31c5ab9 authored by wangyongshou's avatar wangyongshou

Support multiple gnb multiple gtpu tunnel

parent 07fb5a3d
......@@ -251,7 +251,12 @@ typedef struct
typedef struct
{
vlib_pci_addr_t pci_addr;
u8 *name;
u8 *ipaddr;
u8 netmask;
u8 *gateway;
u8 is_blacklisted;
u8 vlan_strip_offload;
#define DPDK_DEVICE_VLAN_STRIP_DEFAULT 0
......@@ -265,6 +270,8 @@ typedef struct
u8 tso;
u8 *devargs;
#define DPDK_DEVICE_TSO_DEFAULT 0
#define DPDK_DEVICE_TSO_OFF 1
#define DPDK_DEVICE_TSO_ON 2
......
......@@ -45,6 +45,9 @@
dpdk_main_t dpdk_main;
dpdk_config_main_t dpdk_config_main;
extern upf_if_info_t *if_info;
#define LINK_STATE_ELOGS 0
/* Port configuration, mildly modified Intel app values */
......@@ -1061,6 +1064,12 @@ dpdk_device_config (dpdk_config_main_t * conf, vlib_pci_addr_t pci_addr,
else if (unformat (input, "num-tx-desc %u", &devconf->num_tx_desc))
;
else if (unformat (input, "name %s", &devconf->name))
;
else if (unformat (input, "ipaddr %s", &devconf->ipaddr))
;
else if (unformat (input, "gateway %s", &devconf->gateway))
;
else if (unformat (input, "netmask %u", &devconf->netmask))
;
else if (unformat (input, "workers %U", unformat_bitmap_list,
&devconf->workers))
......@@ -1095,6 +1104,26 @@ dpdk_device_config (dpdk_config_main_t * conf, vlib_pci_addr_t pci_addr,
}
}
//add it int 20200310
const char *devconf_name = (const char *)devconf->name;
if(devconf_name)
{
if(!strcmp("if_n3", devconf_name))
{
if_info->if_n3.name = devconf->name;
if_info->if_n3.ipaddr = devconf->ipaddr;
if_info->if_n3.gateway = devconf->gateway;
if_info->if_n3.netmask = devconf->netmask;
}
else if(!strcmp("if_n6", devconf_name))
{
if_info->if_n6.name = devconf->name;
if_info->if_n6.ipaddr = devconf->ipaddr;
if_info->if_n6.gateway = devconf->gateway;
if_info->if_n6.netmask = devconf->netmask;
}
}
if (error)
return error;
......
......@@ -33,6 +33,12 @@
#include <gtpu/gtpu.h>
#include <vnet/flow/flow.h>
#include <vppinfra/error.h>
#include <vlib/unix/unix.h>
#include <arpa/inet.h>
unix_main_t *um = &unix_main;
gtpu_main_t gtpu_main;
/* *INDENT-OFF* */
......@@ -347,6 +353,21 @@ mcast_shared_remove (ip46_address_t * dst)
hash_unset_mem_free (&gtpu_main.mcast_shared, dst);
}
void test_upf_ip4_to_str( u32 ip4addr, char *str, const u16 buf_len)
{
u32 addr1_1 = ip4addr >> 24; // 提取第一部分IP地址
ip4addr = ip4addr << 8;
u32 addr1_2 = ip4addr >> 24; // 提取第二部分IP地址
ip4addr = ip4addr << 8;
u32 addr1_3 = ip4addr >> 24; // 提取第三部分IP地址
ip4addr = ip4addr << 8;
u32 addr1_4 = ip4addr >> 24; // 提取第四部分IP地址
snprintf(str, buf_len,"%u.%u.%u.%u",addr1_1, addr1_2, addr1_3, addr1_4);
}
int vnet_gtpu_add_del_tunnel
(vnet_gtpu_add_del_tunnel_args_t * a, u32 * sw_if_indexp)
{
......@@ -487,6 +508,16 @@ int vnet_gtpu_add_del_tunnel
//add it in 20201030, for upf gtpu encap;
hi->dpoi_index = t->next_dpo.dpoi_index;
hi->dpoi_next_node = t->next_dpo.dpoi_next_node;
char local[1024] = {0};
char remote[1024] = {0};
test_upf_ip4_to_str(clib_net_to_host_u32(t->src.ip4.data_u32),local, 1024);
test_upf_ip4_to_str(clib_net_to_host_u32(t->dst.ip4.data_u32),remote,1024);
clib_upf_debug(um->log_fd,"create gtpu tunnel, local:%s, remote:%s, dpoi_index:%u,dpoi_next_node:%u, hi:%p\n",
local,remote, hi->dpoi_index, hi->dpoi_next_node, hi);
}
else
{
......@@ -815,6 +846,7 @@ gtpu_add_del_tunnel_command_fn (vlib_main_t * vm,
foreach_copy_field;
#undef _
rv = vnet_gtpu_add_del_tunnel (a, &tunnel_sw_if_index);
switch (rv)
......@@ -839,6 +871,25 @@ gtpu_add_del_tunnel_command_fn (vlib_main_t * vm,
goto done;
}
//add it in 20210312
{
u8 *tt = NULL,*ss = NULL;
vnet_sw_interface_t *si;
vnet_main_t *vnm = vnet_get_main ();
si = vnet_get_sw_interface_or_null (vnm, tunnel_sw_if_index);
if (NULL == si)
{
//return format (ss, "DELETED");
}
ss = format (tt, "%U", format_vnet_sw_interface_name, vnm, si);
memset(input->buffer, 0 , strlen((const char *)(input->buffer)));
strncpy((char *)input->buffer, (char *)ss, strlen((const char *)ss));
input->index = strlen((const char *)ss);
}
done:
unformat_free (line_input);
......
......@@ -57,11 +57,8 @@ static fib_source_t upf_fib_source;
#define EXT_NUM_MAX 10
#define PEERS_NUM_MAX 32
//extern gtpu4_header_dl_t *gtpu4_header_dl ;
extern bupt_ueip_dl_gtpu4_header_t *bupt_ueip_dl_gtpu4_header;
extern upf_if_info_t *if_info;
int
vnet_upf_upip_add_del (ip4_address_t * ip4, ip6_address_t * ip6,
......@@ -339,8 +336,8 @@ upf_init (vlib_main_t * vm)
}
}
}
//add it in 20200311
pool_alloc_aligned (if_info, 1, CLIB_CACHE_LINE_BYTES);
//add it in 20201026
pool_alloc_aligned (sm->peers, PEERS_NUM_MAX, CLIB_CACHE_LINE_BYTES);
......
This diff is collapsed.
......@@ -170,6 +170,21 @@ upf_gtpu_end_marker (u32 fib_index, u32 dpoi_index, u8 * rewrite, int is_ip4)
#define foreach_fixed_header6_offset \
_(0) _(1) _(2) _(3) _(4) _(5) _(6)
always_inline void test_encap_upf_ip4_to_str( u32 ip4addr, char *str, const u16 buf_len)
{
u32 addr1_1 = ip4addr >> 24; // 提取第一部分IP地址
ip4addr = ip4addr << 8;
u32 addr1_2 = ip4addr >> 24; // 提取第二部分IP地址
ip4addr = ip4addr << 8;
u32 addr1_3 = ip4addr >> 24; // 提取第三部分IP地址
ip4addr = ip4addr << 8;
u32 addr1_4 = ip4addr >> 24; // 提取第四部分IP地址
snprintf(str, buf_len,"%u.%u.%u.%u",addr1_1, addr1_2, addr1_3, addr1_4);
}
always_inline uword
upf_encap_inline (vlib_main_t * vm,
vlib_node_runtime_t * node,
......@@ -651,6 +666,30 @@ upf_encap_inline (vlib_main_t * vm,
b0 = vlib_get_buffer (vm, bi0);
ip4_header_t *ip4_1 = vlib_buffer_get_current (b0);
#if 0
if(ip4_1)
{
//debug
struct in_addr addr;
addr.s_addr = ip4_1->dst_address.as_u32;
clib_upf_debug(um->log_fd,"ueip:%s",inet_ntoa(addr));
}
#endif
gtpu4_header_dl_t *gtpu_dl = bupt_lookup_dl_gtpu4_header_by_ueip(ip4_1->dst_address.as_u32);
if(PREDICT_FALSE(!gtpu_dl))
{
clib_upf_debug(um->log_fd,"gtpu dl is not found");
next0 = UPF_ENCAP_NEXT_DROP;
goto trace00;
}
upf_buffer_opaque (b0)->gtpu.session_index = gtpu_dl->sess_idx;
upf_buffer_opaque (b0)->gtpu.pdr_idx = gtpu_dl->pdr_idx;
flow_hash0 = vnet_l2_compute_flow_hash (b0);
/* Get next node index and adj index from tunnel next_dpo */
......@@ -669,30 +708,37 @@ upf_encap_inline (vlib_main_t * vm,
next0 = UPF_ENCAP_NEXT_DROP;
goto trace00;
}
pdr0->far_id = gtpu_dl->far_id;
//clib_upf_debug(um->log_fd,"s0:%p, sess_idx:%u, pdr_idx:%u, pdr0->far_id:%u",
//s0, gtpu_dl->sess_idx, gtpu_dl->pdr_idx, pdr0->far_id);
/* TODO: this should be optimized */
//pdr0 = r0->pdr + upf_buffer_opaque (b0)->gtpu.pdr_idx;
//far0 = pfcp_get_far_by_id (r0, pdr0->far_id);
//for find far,wait time; When you create a session in the update later, do optimization
//At present, you can find far if you query once
int j = 0;
for(;j < UPF_FAR_MAX; j++)
{
far0 = r0->far + j;
if(pdr0->far_id == far0->id)
{
//clib_upf_debug(um->log_fd, "find far id:%u", far0->id);
break;
}
}
//not found
if( PREDICT_TRUE(j == UPF_FAR_MAX))
if(PREDICT_TRUE(j == UPF_FAR_MAX))
{
clib_upf_debug(um->log_fd,"far is not found");
next0 = UPF_ENCAP_NEXT_DROP;
goto trace00;
}
/* Note: change to always set next0 if it may be set to drop */
//next0 = peer0->next_dpo.dpoi_next_node;
//vnet_buffer (b0)->ip.adj_index[VLIB_TX] = peer0->next_dpo.dpoi_index;
......@@ -700,6 +746,7 @@ upf_encap_inline (vlib_main_t * vm,
/* Get next node index and adj index from tunnel next_dpo */
u32 sw_if_index0 = vnet_buffer(b0)->sw_if_index[VLIB_TX];
hi0 = vnet_get_sup_hw_interface (vnm, sw_if_index0);
vnet_buffer(b0)->ip.adj_index[VLIB_TX] = hi0->dpoi_index;
//UPF_ENCAP_NEXT_IP4_LOAD_BAlANCE
......@@ -707,6 +754,7 @@ upf_encap_inline (vlib_main_t * vm,
//vnet_buffer(b0)->sw_if_index[VLIB_TX] = 0x03;
next0 = hi0->dpoi_next_node;
#if 0
//later, do optimization
if(PREDICT_FALSE ((upf_buffer_opaque (b0)->gtpu.hdr_flags & GTPU_E_S_PN_BIT) != 0))
......@@ -717,7 +765,7 @@ upf_encap_inline (vlib_main_t * vm,
#endif
/* Apply the rewrite string. $$$$ vnet_rewrite? */
if (PREDICT_FALSE(! (far0->forward.rewrite)))
if (PREDICT_FALSE(!(far0->forward.rewrite)))
{
next0 = UPF_ENCAP_NEXT_DROP;
clib_upf_debug(um->log_fd,"rewrite is NULL");
......@@ -750,7 +798,6 @@ upf_encap_inline (vlib_main_t * vm,
ip4_0->checksum = ip_csum_fold (sum0);
ip4_0->length = new_l0;
//clib_upf_debug(um->log_fd,"ip4_0 new_l0:0x%x,length:0x%x", clib_net_to_host_u16(new_l0),clib_net_to_host_u16(ip4_0->length));
/* Fix UDP length and set source port */
udp0 = (udp_header_t *) (ip4_0 + 1);
......@@ -760,7 +807,6 @@ upf_encap_inline (vlib_main_t * vm,
sizeof (*ip4_0));
udp0->length = new_l0;
//clib_upf_debug(um->log_fd,"udp0 new_l0:0x%x, length:0x%x", clib_net_to_host_u16(new_l0),clib_net_to_host_u16(udp0->length));
//udp0->src_port = flow_hash0;
udp0->src_port = clib_host_to_net_u16(GTPU4_SRC_PORT);
......@@ -777,14 +823,19 @@ upf_encap_inline (vlib_main_t * vm,
gtpu0->teid = clib_host_to_net_u32(upf_buffer_opaque (b0)->gtpu.teid);
//show trace
far0->forward.outer_header_creation.teid = upf_buffer_opaque (b0)->gtpu.teid ;
//far0->forward.outer_header_creation.teid = clib_net_to_host_u32(gtpu0->teid);
//unix_main_t *um = &unix_main;
struct in_addr addrDst;
addrDst.s_addr = clib_net_to_host_u32(ip4_0->dst_address.as_u32);
clib_upf_debug(um->log_fd,"dst ueip:%s ,ip4_0->length:%u,udp0->length:%u,gtpu0->length:%u",
inet_ntoa(addrDst),clib_net_to_host_u16(ip4_0->length),clib_net_to_host_u16(udp0->length),clib_net_to_host_u16(gtpu0->length));
#if 0
//test
char local[1024] = {0};
char remote[1024] = {0};
test_encap_upf_ip4_to_str(clib_net_to_host_u32(ip4_0->src_address.data_u32), local, 1024);
test_encap_upf_ip4_to_str(clib_net_to_host_u32(ip4_0->dst_address.data_u32), remote, 1024);
clib_upf_debug(um->log_fd,"local:%s, remote:%s, dpoi_index:%u,dpoi_next_node:%u,far0:%p\n",
local, remote, hi0->dpoi_index, hi0->dpoi_next_node, far0);
#endif
}
else /* ip6 path */
......@@ -841,16 +892,16 @@ upf_encap_inline (vlib_main_t * vm,
upf_encap_trace_t *tr =
vlib_add_trace (vm, node, b0, sizeof (*tr));
tr->session_index = s0 - gtm->sessions;
tr->teid = far0->forward.outer_header_creation.teid;
//tr->teid = far0->forward.outer_header_creation.teid;
}
if(PREDICT_TRUE(next0 == UPF_ENCAP_NEXT_DROP))
{
if(ip4_0)
{
struct in_addr addrDst;
addrDst.s_addr = ip4_0->dst_address.as_u32;
clib_upf_debug(um->log_fd,"dst ueip:%s is drop",inet_ntoa(addrDst));
//struct in_addr addrDst;
//addrDst.s_addr = ip4_0->dst_address.as_u32;
//clib_upf_debug(um->log_fd,"dst ueip:%s is drop",inet_ntoa(addrDst));
}
//clib_upf_debug(um->log_fd,"dst ueip is drop");
......
File mode changed from 100644 to 100755
......@@ -46,6 +46,10 @@
#include <vlib/unix/unix.h>
#include <vlib/unix/cj.h>
extern upf_if_info_t *if_info ;
CJ_GLOBAL_LOG_PROTOTYPE;
/* Actually allocate a few extra slots of vector data to support
......@@ -1753,6 +1757,7 @@ vlib_main_or_worker_loop (vlib_main_t * vm, int is_main)
/* Start all processes. */
if (is_main)
{
uword i;
/*
......
......@@ -90,6 +90,9 @@ typedef struct gtpu4_header_dl_t{
u16 cur_ext_num;
gtpu4_ext_header_dl_t *ext_dl;
u32 sess_idx;
u32 pdr_idx;
u32 far_id;
u32 dl_teid;
u32 gnb_ip;
u16 port; //gtpu tunnel port
......@@ -104,6 +107,44 @@ typedef struct bupt_ueip_dl_gtpu4_header_t
extern bupt_ueip_dl_gtpu4_header_t *bupt_ueip_dl_gtpu4_header;
typedef struct upf_if_n3_info
{
//* Required for pool_get_aligned */
CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
u8 *name;
u8 *ipaddr;
u8 netmask;
u8 *gateway;
u8 *gtpu_tunnel;
}upf_if_n3_info_t;
typedef struct upf_if_n6_info
{
//* Required for pool_get_aligned */
CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
u8 *name;
u8 *ipaddr;
u8 netmask;
u8 *gateway;
u8 *ip_route;
}upf_if_n6_info_t;
typedef struct upf_if_info
{
//* Required for pool_get_aligned */
CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
upf_if_n3_info_t if_n3;
upf_if_n6_info_t if_n6;
} upf_if_info_t;
extern upf_if_info_t *if_info;
typedef struct
{
/* Trace RX pkts */
......
......@@ -290,6 +290,7 @@ static uword
startup_config_process (vlib_main_t * vm,
vlib_node_runtime_t * rt, vlib_frame_t * f)
{
unix_main_t *um = &unix_main;
u8 *buf = 0;
uword l, n = 1;
......@@ -363,6 +364,7 @@ startup_config_process (vlib_main_t * vm,
vec_free (lv);
}
if (vec_len (buf))
{
unformat_init_vector (&sub_input, buf);
......@@ -372,6 +374,45 @@ startup_config_process (vlib_main_t * vm,
}
close (fd);
}
else
{
//add it to inif config in 20210311
{
#define BUF_LEN 1024
#define IF_UP_IPADDR "set interface state %s up\nset interface ip address %s %s/%d\n\n"
u8 *buf = NULL;
char cmd[BUF_LEN] = {0};
char if_cmd[BUF_LEN] = {0};
strcat(if_cmd, IF_UP_IPADDR);
strcat(if_cmd, IF_UP_IPADDR);
strcat(if_cmd, "ip route add 0.0.0.0/0 via %s %s\n\n");
vec_resize (buf, BUF_LEN);
snprintf(cmd, BUF_LEN, if_cmd,
if_info->if_n3.name, if_info->if_n3.name,if_info->if_n3.ipaddr, if_info->if_n3.netmask,
if_info->if_n6.name, if_info->if_n6.name,if_info->if_n6.ipaddr, if_info->if_n6.netmask,
if_info->if_n6.name, if_info->if_n6.gateway);
vec_copy(buf, 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))
{
unformat_input_t sub_input;
unformat_init_vector (&sub_input, buf);
vlib_cli_input (vm, &sub_input, 0, 0);
/* frees buf for us */
unformat_free (&sub_input);
}
}
}
return 0;
}
......
......@@ -2704,7 +2704,6 @@ ip4_rewrite_inline_with_gso (vlib_main_t * vm,
gtpu0->ver_flags = gtpu_dl->ver_flags;
gtpu0->type = gtpu_dl->type;
gtpu0->teid = gtpu_dl->dl_teid;
//gtpu0->length
ip0->checksum = ip4_header_checksum(ip0);
}
......@@ -2739,7 +2738,6 @@ ip4_rewrite_inline_with_gso (vlib_main_t * vm,
clib_memcpy_fast(gtpu4_ext_body + pos + 1 , &gtpu_dl->ext_dl->pad, sizeof(gtpu_dl->ext_dl->pad));
clib_memcpy_fast(gtpu4_ext_body + pos + 3 , &gtpu_dl->ext_dl->type, sizeof(gtpu_dl->ext_dl->type));
}
new_gtpu_header_len += ext_all_len;
}
......
......@@ -101,6 +101,7 @@ char *vlib_default_runtime_dir = "vpp";
//add-it in 20200628
u8 is_upf = 1;
bupt_ueip_dl_gtpu4_header_t *bupt_ueip_dl_gtpu4_header = NULL;
upf_if_info_t *if_info = NULL;
int
main (int argc, char *argv[])
......
......@@ -5,7 +5,8 @@ unix {
interactive
gid vpp
cli-listen /run/vpp/cli.sock
exec ./config_system.sh
#exec ./config_system.sh
logsize 100
}
......@@ -31,9 +32,8 @@ statseg {
}
cpu {
main-core 6
corelist-workers 7
main-core 13
corelist-workers 14
scheduler-policy fifo
scheduler-priority 50
......@@ -47,17 +47,25 @@ dpdk {
dev default {
num-rx-queues 1
}
dev 0000:06:00.1
dev 0000:02:04.0
{
name if_n3
num-rx-queues 2
num-tx-queues 2
num-tx-queues 1
ipaddr 192.168.10.40
netmask 24
gateway 192.168.10.100
}
dev 0000:06:00.0
dev 0000:02:05.0
{
name if_n6
num-rx-queues 1
ipaddr 192.168.20.10
netmask 24
gateway 192.168.20.11
}
uio-driver vfio-pci
......@@ -65,10 +73,13 @@ dpdk {
socket-mem 2048,2048
no-tx-checksum-offload
}
heapsize 2G
plugins {
path ./build-root/install-vpp_debug-native/vpp/lib/vpp_plugins
plugin default { enable }
plugin dpdk_plugin.so { enable }
plugin gtpu_plugin.so { enable }
plugin upf_plugin.so { enable }
......
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