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
bc22817a
Commit
bc22817a
authored
Apr 13, 2021
by
Leonardo Lai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pktgen: add option to log to file
parent
1bee1fb2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
8 deletions
+38
-8
apps/pktgen/README
apps/pktgen/README
+3
-3
apps/pktgen/main.c
apps/pktgen/main.c
+35
-5
No files found.
apps/pktgen/README
View file @
bc22817a
Sender:
sudo ./pktgen -c ../../config.ini -f send -
l 100 -r 10000
sudo ./pktgen -c ../../config.ini -f send -
s 100 -r 10000 -l pktgen-send.log
Receiver:
sudo ./pktgen -c ../../config.ini -f recv
sudo ./pktgen -c ../../config.ini -f recv
-l pktgen-recv.log
Note: '-
l
' is the UDP payload length, excluding the MAC, IPv4 and UDP headers
Note: '-
s
' is the UDP payload length, excluding the MAC, IPv4 and UDP headers
If you want to include them in the stats, add the '-h' option.
apps/pktgen/main.c
View file @
bc22817a
...
...
@@ -52,6 +52,9 @@ static bool dump = false;
static
uint64_t
tx_rate
=
0
;
static
struct
timespec
tx_period
;
static
volatile
bool
app_alive
=
true
;
static
int
log_enabled
=
0
;
static
char
*
log_file
;
static
FILE
*
log
;
static
const
char
*
progname
;
static
void
signal_handler
(
int
signum
)
...
...
@@ -208,7 +211,8 @@ static void usage(void)
" -c CONFIG: .ini configuration file"
" -f FUNCTION: 'send' or 'recv'
\n
"
" -r RATE: desired transmission rate in bytes"
" -l LEN: payload length
\n
"
" -s SIZE: payload size (length)
\n
"
" -l LOGFILE: path to the logfile
\n
"
" -h consider also the MAC, IPv4 and UDP headers bytes for tx_rate and stats
\n
"
" -d dump the payload (ASCII)
\n
"
,
progname
);
...
...
@@ -221,7 +225,7 @@ static int parse_app_args(int argc, char *argv[])
progname
=
argv
[
0
];
while
((
c
=
getopt
(
argc
,
argv
,
"c:f:r:l:hd"
))
!=
-
1
)
{
while
((
c
=
getopt
(
argc
,
argv
,
"c:f:r:
s:
l:hd"
))
!=
-
1
)
{
switch
(
c
)
{
case
'c'
:
// this is for the .ini cfg file needed by DPDK, not by the app
...
...
@@ -239,9 +243,17 @@ static int parse_app_args(int argc, char *argv[])
case
'r'
:
tx_rate
=
atoi
(
optarg
);
break
;
case
'
l
'
:
case
'
s
'
:
pktlen
=
atoi
(
optarg
);
break
;
case
'l'
:
log_enabled
=
1
;
log_file
=
strdup
(
optarg
);
log
=
fopen
(
log_file
,
"w"
);
if
(
log
==
NULL
)
{
printf
(
"Error opening log file: %s
\n
"
,
log_file
);
}
break
;
case
'h'
:
hdr_stats
=
true
;
break
;
...
...
@@ -275,8 +287,13 @@ static void *stats_routine(void *arg)
while
(
1
)
{
tx_bps
=
stats
->
bytes_sent
-
stats
->
bytes_sent_prev
;
rx_bps
=
stats
->
bytes_recv
-
stats
->
bytes_recv_prev
;
printf
(
"Sent: %ld bytes %ld bps | Recv: %ld bytes %ld bps
\n
"
,
stats
->
bytes_sent
,
tx_bps
,
stats
->
bytes_recv
,
rx_bps
);
if
(
log_enabled
)
{
fprintf
(
log
,
"%ld %ld %ld %ld
\n
"
,
stats
->
bytes_sent
,
tx_bps
,
stats
->
bytes_recv
,
rx_bps
);
}
else
{
printf
(
"Sent: %ld bytes %ld bps | Recv: %ld bytes %ld bps
\n
"
,
stats
->
bytes_sent
,
tx_bps
,
stats
->
bytes_recv
,
rx_bps
);
}
stats
->
bytes_sent_prev
=
stats
->
bytes_sent
;
stats
->
bytes_recv_prev
=
stats
->
bytes_recv
;
sleep
(
1
);
...
...
@@ -310,6 +327,14 @@ int main(int argc, char *argv[])
return
-
1
;
}
// Open log file
if
(
log_enabled
)
{
log
=
fopen
(
log_file
,
"w"
);
if
(
log
==
NULL
)
{
printf
(
"Error opening log file: %s
\n
"
,
log_file
);
}
}
// Start the thread to visualize statistics in real time
reset_stats
(
&
stats
);
if
(
pthread_create
(
&
stats_thr
,
NULL
,
stats_routine
,
&
stats
))
{
...
...
@@ -327,6 +352,11 @@ pktgen_end:
// Halt the stats thread
pthread_cancel
(
stats_thr
);
pthread_join
(
stats_thr
,
NULL
);
// Close the log
if
(
log_enabled
)
{
printf
(
"Closing log...
\n
"
);
fclose
(
log
);
}
// Cleanup
udpdk_interrupt
(
0
);
udpdk_cleanup
();
...
...
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