Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG-UPF
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenXG
OpenXG-UPF
Commits
061832ae
Commit
061832ae
authored
Mar 18, 2021
by
wangyongshou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize multiple GNB multiple GTPU TUNNEL codes
parent
0f7e1add
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
81 deletions
+77
-81
src/vppe/src/plugins/upf/upf_api.c
src/vppe/src/plugins/upf/upf_api.c
+75
-79
src/vppe/src/vlib/unix/main.c
src/vppe/src/vlib/unix/main.c
+2
-2
No files found.
src/vppe/src/plugins/upf/upf_api.c
View file @
061832ae
...
@@ -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
;
...
...
src/vppe/src/vlib/unix/main.c
View file @
061832ae
...
@@ -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
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment