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
e9e0d67e
Commit
e9e0d67e
authored
Nov 05, 2020
by
Leonardo Lai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup
parent
89fa8cef
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
92 additions
and
53 deletions
+92
-53
udpdk/Makefile
udpdk/Makefile
+1
-0
udpdk/udpdk_bind_table.c
udpdk/udpdk_bind_table.c
+2
-1
udpdk/udpdk_init.c
udpdk/udpdk_init.c
+5
-51
udpdk/udpdk_monitor.c
udpdk/udpdk_monitor.c
+66
-0
udpdk/udpdk_monitor.h
udpdk/udpdk_monitor.h
+12
-0
udpdk/udpdk_types.h
udpdk/udpdk_types.h
+6
-1
No files found.
udpdk/Makefile
View file @
e9e0d67e
...
...
@@ -43,6 +43,7 @@ UDPDK_CORE_SRCS+= \
udpdk_globals.c
\
udpdk_init.c
\
udpdk_bind_table.c
\
udpdk_monitor.c
\
udpdk_poller.c
\
udpdk_syscall.c
\
...
...
udpdk/udpdk_bind_table.c
View file @
e9e0d67e
...
...
@@ -88,6 +88,7 @@ static inline bool btable_can_bind(struct in_addr ip, int port, int opts)
return
can_bind
;
}
/* Bind a socket to a (IP, port) pair */
int
btable_add_binding
(
int
s
,
struct
in_addr
ip
,
int
port
,
int
opts
)
{
struct
bind_info
*
b
;
...
...
@@ -129,7 +130,7 @@ void btable_del_binding(int s, int port) {
list_node_t
*
node
;
list_iterator_t
*
it
;
// Remove the binding from the l
si
t
// Remove the binding from the l
is
t
it
=
list_iterator_new
(
sock_bind_table
[
port
],
LIST_HEAD
);
while
((
node
=
list_iterator_next
(
it
)))
{
if
(((
struct
bind_info
*
)(
node
->
val
))
->
sockfd
==
s
)
{
...
...
udpdk/udpdk_init.c
View file @
e9e0d67e
...
...
@@ -25,6 +25,7 @@
#include "udpdk_args.h"
#include "udpdk_constants.h"
#include "udpdk_bind_table.h"
#include "udpdk_monitor.h"
#include "udpdk_poller.h"
#include "udpdk_types.h"
...
...
@@ -63,7 +64,7 @@ static inline const char * get_exch_ring_name(unsigned id, enum exch_ring_func f
static
int
init_mbuf_pools
(
void
)
{
const
unsigned
int
num_mbufs_rx
=
NUM_RX_DESC_DEFAULT
;
const
unsigned
int
num_mbufs_tx
=
NUM_TX_DESC_DEFAULT
;
// TODO
why sized like this?
const
unsigned
int
num_mbufs_tx
=
NUM_TX_DESC_DEFAULT
;
// TODO
size properly
const
unsigned
int
num_mbufs_cache
=
2
*
MBUF_CACHE_SIZE
;
const
unsigned
int
num_mbufs
=
num_mbufs_rx
+
num_mbufs_tx
+
num_mbufs_cache
;
const
int
socket
=
rte_socket_id
();
...
...
@@ -76,21 +77,21 @@ static int init_mbuf_pools(void)
}
tx_pktmbuf_pool
=
rte_pktmbuf_pool_create
(
PKTMBUF_POOL_TX_NAME
,
num_mbufs
,
MBUF_CACHE_SIZE
,
0
,
RTE_MBUF_DEFAULT_BUF_SIZE
,
socket
);
// used by the app (sendto) TODO size properly
RTE_MBUF_DEFAULT_BUF_SIZE
,
socket
);
// used by the app (sendto)
//
TODO size properly
if
(
tx_pktmbuf_pool
==
NULL
)
{
RTE_LOG
(
ERR
,
INIT
,
"Failed to allocate TX pool: %s
\n
"
,
rte_strerror
(
rte_errno
));
return
-
1
;
}
tx_pktmbuf_direct_pool
=
rte_pktmbuf_pool_create
(
PKTMBUF_POOL_DIRECT_TX_NAME
,
num_mbufs
,
MBUF_CACHE_SIZE
,
0
,
RTE_MBUF_DEFAULT_BUF_SIZE
,
socket
);
// used by the poller TODO size properly
RTE_MBUF_DEFAULT_BUF_SIZE
,
socket
);
// used by the poller
//
TODO size properly
if
(
tx_pktmbuf_direct_pool
==
NULL
)
{
RTE_LOG
(
ERR
,
INIT
,
"Failed to allocate TX direct pool: %s
\n
"
,
rte_strerror
(
rte_errno
));
return
-
1
;
}
tx_pktmbuf_indirect_pool
=
rte_pktmbuf_pool_create
(
PKTMBUF_POOL_INDIRECT_TX_NAME
,
num_mbufs
,
MBUF_CACHE_SIZE
,
0
,
RTE_MBUF_DEFAULT_BUF_SIZE
,
socket
);
// used by the poller TODO size properly
RTE_MBUF_DEFAULT_BUF_SIZE
,
socket
);
// used by the poller
//
TODO size properly
if
(
tx_pktmbuf_indirect_pool
==
NULL
)
{
RTE_LOG
(
ERR
,
INIT
,
"Failed to allocate TX indirect pool: %s
\n
"
,
rte_strerror
(
rte_errno
));
return
-
1
;
...
...
@@ -175,53 +176,6 @@ static int init_port(uint16_t port_num)
return
0
;
}
static
void
check_port_link_status
(
uint16_t
portid
)
{
#define CHECK_INTERVAL 100 // 100ms
#define MAX_CHECK_TIME 90 // how many times
uint8_t
count
,
all_ports_up
,
print_flag
=
0
;
struct
rte_eth_link
link
;
int
ret
;
RTE_LOG
(
INFO
,
INIT
,
"Checking link status of port %d.
\n
"
,
portid
);
for
(
count
=
0
;
count
<=
MAX_CHECK_TIME
;
count
++
)
{
all_ports_up
=
1
;
memset
(
&
link
,
0
,
sizeof
(
link
));
ret
=
rte_eth_link_get_nowait
(
portid
,
&
link
);
if
(
ret
<
0
)
{
all_ports_up
=
0
;
if
(
print_flag
==
1
)
RTE_LOG
(
WARNING
,
INIT
,
"Port %u link get failed: %s
\n
"
,
portid
,
rte_strerror
(
-
ret
));
continue
;
}
if
(
print_flag
==
1
)
{
if
(
link
.
link_status
)
{
RTE_LOG
(
INFO
,
INIT
,
"Port %d Link Up - speed %u Mbps - %s
\n
"
,
portid
,
(
unsigned
)
link
.
link_speed
,
(
link
.
link_duplex
==
ETH_LINK_FULL_DUPLEX
)
?
(
"full-duplex"
)
:
(
"half-duplex
\n
"
));
break
;
}
else
{
RTE_LOG
(
INFO
,
INIT
,
"Port %d Link Down
\n
"
,
(
uint8_t
)
portid
);
}
continue
;
}
if
(
link
.
link_status
==
ETH_LINK_DOWN
)
{
all_ports_up
=
0
;
break
;
}
if
(
print_flag
==
1
)
return
;
if
(
all_ports_up
==
0
)
{
printf
(
"."
);
fflush
(
stdout
);
rte_delay_ms
(
CHECK_INTERVAL
);
}
if
(
all_ports_up
==
1
||
count
==
(
MAX_CHECK_TIME
-
1
))
{
print_flag
=
1
;
}
}
}
/* Initialize a shared memory region to contain descriptors for the exchange slots */
static
int
init_exch_memzone
(
void
)
{
...
...
udpdk/udpdk_monitor.c
0 → 100644
View file @
e9e0d67e
//
// Created by leoll2 on 11/05/20.
// Copyright (c) 2020 Leonardo Lai. All rights reserved.
//
#include <stdlib.h>
#include <unistd.h>
#include <rte_common.h>
#include <rte_eal.h>
#include <rte_errno.h>
#include <rte_ethdev.h>
#include <rte_log.h>
#include "udpdk_monitor.h"
#define RTE_LOGTYPE_MONITOR RTE_LOGTYPE_USER1
/* Show information about the current state of a DPDK port */
void
check_port_link_status
(
uint16_t
portid
)
{
#define CHECK_INTERVAL 100 // 100ms
#define MAX_CHECK_TIME 90 // how many times
uint8_t
count
,
all_ports_up
,
print_flag
=
0
;
struct
rte_eth_link
link
;
int
ret
;
RTE_LOG
(
INFO
,
MONITOR
,
"Checking link status of port %d.
\n
"
,
portid
);
for
(
count
=
0
;
count
<=
MAX_CHECK_TIME
;
count
++
)
{
all_ports_up
=
1
;
memset
(
&
link
,
0
,
sizeof
(
link
));
ret
=
rte_eth_link_get_nowait
(
portid
,
&
link
);
if
(
ret
<
0
)
{
all_ports_up
=
0
;
if
(
print_flag
==
1
)
RTE_LOG
(
WARNING
,
MONITOR
,
"Port %u link get failed: %s
\n
"
,
portid
,
rte_strerror
(
-
ret
));
continue
;
}
if
(
print_flag
==
1
)
{
if
(
link
.
link_status
)
{
RTE_LOG
(
INFO
,
MONITOR
,
"Port %d Link Up - speed %u Mbps - %s
\n
"
,
portid
,
(
unsigned
)
link
.
link_speed
,
(
link
.
link_duplex
==
ETH_LINK_FULL_DUPLEX
)
?
(
"full-duplex"
)
:
(
"half-duplex
\n
"
));
break
;
}
else
{
RTE_LOG
(
INFO
,
MONITOR
,
"Port %d Link Down
\n
"
,
(
uint8_t
)
portid
);
}
continue
;
}
if
(
link
.
link_status
==
ETH_LINK_DOWN
)
{
all_ports_up
=
0
;
break
;
}
if
(
print_flag
==
1
)
return
;
if
(
all_ports_up
==
0
)
{
printf
(
"."
);
fflush
(
stdout
);
rte_delay_ms
(
CHECK_INTERVAL
);
}
if
(
all_ports_up
==
1
||
count
==
(
MAX_CHECK_TIME
-
1
))
{
print_flag
=
1
;
}
}
}
udpdk/udpdk_monitor.h
0 → 100644
View file @
e9e0d67e
//
// Created by leoll2 on 11/05/20.
// Copyright (c) 2020 Leonardo Lai. All rights reserved.
//
#ifndef UDPDK_MONITOR_H
#define UDPDK_MONITOR_H
void
check_port_link_status
(
uint16_t
portid
);
#endif // UDPDK_MONITOR_H
udpdk/udpdk_types.h
View file @
e9e0d67e
...
...
@@ -27,6 +27,7 @@
enum
exch_ring_func
{
EXCH_RING_RX
,
EXCH_RING_TX
};
/* Descriptor for a binding of a socket to (IP, port) */
struct
bind_info
{
int
sockfd
;
// socket fd of the (addr, port) pair
struct
in_addr
ip_addr
;
// IPv4 address associated to the socket
...
...
@@ -35,20 +36,23 @@ struct bind_info {
bool
closed
;
// mark this binding as closed
};
/* Descriptor of a socket (current state and options) */
struct
exch_slot_info
{
int
used
;
// used by an open socket
int
bound
;
// used by a socket that did 'bind'
int
sockfd
;
//
TODO redundant because it matches the slot index in this implementation
int
sockfd
;
//
NOTE: redundant atm because it matches the slot index in the current impl
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)
int
so_options
;
// socket options
}
__rte_cache_aligned
;
/* Descriptor of the zone in shared memory where packets are exchanged between app and poller */
struct
exch_zone_info
{
uint64_t
n_zones_active
;
struct
exch_slot_info
slots
[
NUM_SOCKETS_MAX
];
};
/* Descriptor of the exchange zone queues and buffers for a socket */
struct
exch_slot
{
struct
rte_ring
*
rx_q
;
// RX queue
struct
rte_ring
*
tx_q
;
// TX queue
...
...
@@ -56,6 +60,7 @@ struct exch_slot {
uint16_t
rx_count
;
// current number of packets in the rx buffer
}
__rte_cache_aligned
;
/* Global configuration (parsed from file) */
typedef
struct
{
struct
rte_ether_addr
src_mac_addr
;
struct
rte_ether_addr
dst_mac_addr
;
...
...
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