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
cedd81a0
Commit
cedd81a0
authored
Feb 24, 2021
by
Leonardo Lai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add option to specify logfile
parent
9a713ebc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
4 deletions
+34
-4
apps/pingpong/README
apps/pingpong/README
+1
-1
apps/pingpong/main.c
apps/pingpong/main.c
+33
-3
No files found.
apps/pingpong/README
View file @
cedd81a0
Ping host:
sudo ./pingpong -c ../../config.ini -f ping
sudo ./pingpong -c ../../config.ini -f ping
-d 10000 -l pingpong.log
Pong host:
sudo ./pingpong -c ../../config.ini -f pong
apps/pingpong/main.c
View file @
cedd81a0
...
...
@@ -27,6 +27,10 @@ typedef enum {PING, PONG} app_mode;
static
app_mode
mode
=
PING
;
static
volatile
int
app_alive
=
1
;
static
int
log_enabled
=
0
;
static
char
*
log_file
;
static
FILE
*
log
;
static
unsigned
delay
=
1000000
;
static
const
char
*
progname
;
static
void
signal_handler
(
int
signum
)
...
...
@@ -44,6 +48,14 @@ static void ping_body(void)
printf
(
"PING mode
\n
"
);
// Open log file
if
(
log_enabled
)
{
log
=
fopen
(
log_file
,
"w"
);
if
(
log
==
NULL
)
{
printf
(
"Error opening log file: %s
\n
"
,
log_file
);
}
}
// Create a socket
int
sock
;
if
((
sock
=
udpdk_socket
(
AF_INET
,
SOCK_DGRAM
,
0
))
<
0
)
{
...
...
@@ -83,9 +95,12 @@ static void ping_body(void)
ts
.
tv_sec
--
;
}
printf
(
"Received pong; delta = %d.%09d seconds
\n
"
,
(
int
)
ts
.
tv_sec
,
(
int
)
ts
.
tv_nsec
);
if
(
log_file
)
{
fprintf
(
log
,
" %d%09d
\n
"
,
(
int
)
ts
.
tv_sec
,
(
int
)
ts
.
tv_nsec
);
}
}
sleep
(
1
);
usleep
(
delay
);
}
}
...
...
@@ -126,8 +141,9 @@ static void pong_body(void)
static
void
usage
(
void
)
{
printf
(
"%s -c CONFIG -f FUNCTION
\n
"
" -c CONFIG: .ini configuration file"
" -c CONFIG: .ini configuration file
\n
"
" -f FUNCTION: 'ping' or 'pong'
\n
"
" -d DELAY: delay (microseconds) between two ping invocations
\n
"
,
progname
);
}
...
...
@@ -138,7 +154,7 @@ static int parse_app_args(int argc, char *argv[])
progname
=
argv
[
0
];
while
((
c
=
getopt
(
argc
,
argv
,
"c:f:"
))
!=
-
1
)
{
while
((
c
=
getopt
(
argc
,
argv
,
"c:f:
d:l:
"
))
!=
-
1
)
{
switch
(
c
)
{
case
'c'
:
// this is for the .ini cfg file needed by DPDK, not by the app
...
...
@@ -153,6 +169,17 @@ static int parse_app_args(int argc, char *argv[])
return
-
1
;
}
break
;
case
'd'
:
delay
=
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
;
default:
fprintf
(
stderr
,
"Unknown option `-%c'.
\n
"
,
optopt
);
usage
();
...
...
@@ -194,6 +221,9 @@ int main(int argc, char *argv[])
}
pingpong_end:
if
(
log_enabled
)
{
fclose
(
log
);
}
udpdk_interrupt
(
0
);
udpdk_cleanup
();
return
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