Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
U
udpdk
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
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
ywj
udpdk
Commits
6a0e67f3
Commit
6a0e67f3
authored
Oct 07, 2020
by
Leonardo Lai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support INADDR_ANY and binding to specific IP
parent
ceba7d84
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
24 additions
and
11 deletions
+24
-11
apps/pingpong/README
apps/pingpong/README
+2
-2
config.ini
config.ini
+1
-0
udpdk/udpdk_args.c
udpdk/udpdk_args.c
+9
-4
udpdk/udpdk_syscall.c
udpdk/udpdk_syscall.c
+9
-5
udpdk/udpdk_types.h
udpdk/udpdk_types.h
+3
-0
No files found.
apps/pingpong/README
View file @
6a0e67f3
Ping host:
Ping host:
sudo ./pingpong -
-
-f ping
sudo ./pingpong -
c ../../config.ini
-f ping
Pong host:
Pong host:
sudo ./pingpong -
-
-f pong
sudo ./pingpong -
c ../../config.ini
-f pong
config.ini
View file @
6a0e67f3
...
@@ -8,6 +8,7 @@ n_mem_channels=2
...
@@ -8,6 +8,7 @@ n_mem_channels=2
[port0]
[port0]
mac_addr
=
68:05:ca:95:f8:ec
mac_addr
=
68:05:ca:95:f8:ec
ip_addr
=
172.31.100.2
[port0_dst]
[port0_dst]
mac_addr
=
68:05:ca:95:fa:64
mac_addr
=
68:05:ca:95:fa:64
udpdk/udpdk_args.c
View file @
6a0e67f3
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
// Created by leoll2 on 10/6/20.
// Created by leoll2 on 10/6/20.
// Copyright (c) 2020 Leonardo Lai. All rights reserved.
// Copyright (c) 2020 Leonardo Lai. All rights reserved.
//
//
#include <arpa/inet.h> // for inet_addr
#include <rte_ether.h>
#include <rte_ether.h>
...
@@ -17,15 +18,19 @@ extern char *primary_argv[MAX_ARGC];
...
@@ -17,15 +18,19 @@ extern char *primary_argv[MAX_ARGC];
extern
char
*
secondary_argv
[
MAX_ARGC
];
extern
char
*
secondary_argv
[
MAX_ARGC
];
static
char
*
progname
;
static
char
*
progname
;
static
int
parse_handler
(
void
*
configuration
,
const
char
*
section
,
const
char
*
name
,
const
char
*
value
)
static
int
parse_handler
(
void
*
configuration
,
const
char
*
section
,
const
char
*
name
,
const
char
*
value
)
{
{
#define MATCH(s, n) strcmp(section, s) == 0 && strcmp(name, n) == 0
#define MATCH(s, n) strcmp(section, s) == 0 && strcmp(name, n) == 0
if
(
MATCH
(
"port0"
,
"mac_addr"
))
{
if
(
MATCH
(
"port0"
,
"mac_addr"
))
{
if
(
rte_ether_unformat_addr
(
value
,
&
config
.
src_mac_addr
)
<
0
)
{
if
(
rte_ether_unformat_addr
(
value
,
&
config
.
src_mac_addr
)
<
0
)
{
fprintf
(
stderr
,
"Can't parse MAC address: %s
\n
"
,
value
);
fprintf
(
stderr
,
"Can't parse MAC address: %s
\n
"
,
value
);
return
0
;
return
0
;
}
}
}
else
if
(
MATCH
(
"port0_dst"
,
"mac_addr"
))
{
}
else
if
(
MATCH
(
"port0"
,
"ip_addr"
))
{
config
.
src_ip_addr
.
s_addr
=
inet_addr
(
value
);
if
(
config
.
src_ip_addr
.
s_addr
==
(
in_addr_t
)(
-
1
))
{
fprintf
(
stderr
,
"Can't parse IPv4 address: %s
\n
"
,
value
);
}
}
else
if
(
MATCH
(
"port0_dst"
,
"mac_addr"
))
{
if
(
rte_ether_unformat_addr
(
value
,
&
config
.
dst_mac_addr
)
<
0
)
{
if
(
rte_ether_unformat_addr
(
value
,
&
config
.
dst_mac_addr
)
<
0
)
{
fprintf
(
stderr
,
"Can't parse MAC address: %s
\n
"
,
value
);
fprintf
(
stderr
,
"Can't parse MAC address: %s
\n
"
,
value
);
return
0
;
return
0
;
...
...
udpdk/udpdk_syscall.c
View file @
6a0e67f3
...
@@ -125,15 +125,21 @@ int udpdk_bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
...
@@ -125,15 +125,21 @@ int udpdk_bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
return
-
1
;
return
-
1
;
}
}
// Mark the slot as bound
// Mark the slot as bound
, and store the corresponding IP and port
exch_zone_desc
->
slots
[
sockfd
].
bound
=
1
;
exch_zone_desc
->
slots
[
sockfd
].
bound
=
1
;
exch_zone_desc
->
slots
[
sockfd
].
udp_port
=
(
int
)
port
;
exch_zone_desc
->
slots
[
sockfd
].
udp_port
=
(
int
)
port
;
if
(
addr_in
->
sin_addr
.
s_addr
==
INADDR_ANY
)
{
// If INADDR_ANY, use the address from the configuration file
exch_zone_desc
->
slots
[
sockfd
].
ip_addr
=
config
.
src_ip_addr
;
}
else
{
// If the address is explicitly set, bind to that
exch_zone_desc
->
slots
[
sockfd
].
ip_addr
=
addr_in
->
sin_addr
;
}
// Insert in the hashtable (port, sock_id)
// Insert in the hashtable (port, sock_id)
htable_insert
(
udp_port_table
,
(
int
)
port
,
sockfd
);
htable_insert
(
udp_port_table
,
(
int
)
port
,
sockfd
);
RTE_LOG
(
INFO
,
SYSCALL
,
"Binding port %d to sock_id %d
\n
"
,
port
,
sockfd
);
RTE_LOG
(
INFO
,
SYSCALL
,
"Binding port %d to sock_id %d
\n
"
,
port
,
sockfd
);
// TODO must bind the IP address too (if INADDR_ANY, pick one)
return
0
;
return
0
;
}
}
...
@@ -195,8 +201,6 @@ ssize_t udpdk_sendto(int sockfd, const void *buf, size_t len, int flags,
...
@@ -195,8 +201,6 @@ ssize_t udpdk_sendto(int sockfd, const void *buf, size_t len, int flags,
void
*
udp_data
;
void
*
udp_data
;
const
struct
sockaddr_in
*
dest_addr_in
=
(
struct
sockaddr_in
*
)
dest_addr
;
const
struct
sockaddr_in
*
dest_addr_in
=
(
struct
sockaddr_in
*
)
dest_addr
;
static
uint32_t
src_ip_addr
=
RTE_IPV4
(
2
,
100
,
31
,
172
);
// TODO from bind (reversed for endianness)
// Validate the arguments
// Validate the arguments
if
(
sendto_validate_args
(
sockfd
,
buf
,
len
,
flags
,
dest_addr
,
addrlen
)
<
0
)
{
if
(
sendto_validate_args
(
sockfd
,
buf
,
len
,
flags
,
dest_addr
,
addrlen
)
<
0
)
{
return
-
1
;
return
-
1
;
...
@@ -238,7 +242,7 @@ ssize_t udpdk_sendto(int sockfd, const void *buf, size_t len, int flags,
...
@@ -238,7 +242,7 @@ ssize_t udpdk_sendto(int sockfd, const void *buf, size_t len, int flags,
ip_hdr
->
time_to_live
=
IP_DEFTTL
;
ip_hdr
->
time_to_live
=
IP_DEFTTL
;
ip_hdr
->
next_proto_id
=
IPPROTO_UDP
;
ip_hdr
->
next_proto_id
=
IPPROTO_UDP
;
ip_hdr
->
packet_id
=
0
;
ip_hdr
->
packet_id
=
0
;
ip_hdr
->
src_addr
=
src_ip_addr
;
// TODO this should be determined by bind()
ip_hdr
->
src_addr
=
exch_zone_desc
->
slots
[
sockfd
].
ip_addr
.
s_addr
;
ip_hdr
->
dst_addr
=
dest_addr_in
->
sin_addr
.
s_addr
;
ip_hdr
->
dst_addr
=
dest_addr_in
->
sin_addr
.
s_addr
;
ip_hdr
->
total_length
=
rte_cpu_to_be_16
(
len
+
sizeof
(
*
ip_hdr
)
+
sizeof
(
*
udp_hdr
));
ip_hdr
->
total_length
=
rte_cpu_to_be_16
(
len
+
sizeof
(
*
ip_hdr
)
+
sizeof
(
*
udp_hdr
));
ip_hdr
->
hdr_checksum
=
rte_ipv4_cksum
(
ip_hdr
);
ip_hdr
->
hdr_checksum
=
rte_ipv4_cksum
(
ip_hdr
);
...
...
udpdk/udpdk_types.h
View file @
6a0e67f3
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
#include <rte_memory.h>
#include <rte_memory.h>
#include <rte_memzone.h>
#include <rte_memzone.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/types.h>
#include <unistd.h>
#include <unistd.h>
...
@@ -29,6 +30,7 @@ struct exch_slot_info {
...
@@ -29,6 +30,7 @@ struct exch_slot_info {
int
bound
;
// used by a socket that did 'bind'
int
bound
;
// used by a socket that did 'bind'
int
sockfd
;
// TODO redundant because it matches the slot index in this implementation
int
sockfd
;
// TODO redundant because it matches the slot index in this implementation
int
udp_port
;
// UDP port associated to the socket (only if bound)
int
udp_port
;
// UDP port associated to the socket (only if bound)
struct
in_addr
ip_addr
;
// IPv4 address associated to the socket (only if bound)
}
__rte_cache_aligned
;
}
__rte_cache_aligned
;
struct
exch_zone_info
{
struct
exch_zone_info
{
...
@@ -46,6 +48,7 @@ struct exch_slot {
...
@@ -46,6 +48,7 @@ struct exch_slot {
typedef
struct
{
typedef
struct
{
struct
rte_ether_addr
src_mac_addr
;
struct
rte_ether_addr
src_mac_addr
;
struct
rte_ether_addr
dst_mac_addr
;
struct
rte_ether_addr
dst_mac_addr
;
struct
in_addr
src_ip_addr
;
char
lcores_primary
[
MAX_ARG_LEN
];
char
lcores_primary
[
MAX_ARG_LEN
];
char
lcores_secondary
[
MAX_ARG_LEN
];
char
lcores_secondary
[
MAX_ARG_LEN
];
int
n_mem_channels
;
int
n_mem_channels
;
...
...
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