Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
tsn-measures
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
nexedi
tsn-measures
Commits
3bbec828
Commit
3bbec828
authored
Jun 10, 2020
by
Joanne Hugé
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'packet-exchange'
parents
147e41be
4c33499c
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
140 additions
and
97 deletions
+140
-97
packet-exchange/src/client.c
packet-exchange/src/client.c
+34
-34
packet-exchange/src/recv_packet.c
packet-exchange/src/recv_packet.c
+5
-5
packet-exchange/src/send_packet.c
packet-exchange/src/send_packet.c
+8
-9
packet-exchange/src/send_packet.h
packet-exchange/src/send_packet.h
+1
-1
packet-exchange/src/server.c
packet-exchange/src/server.c
+52
-48
packet-exchange/src/utilities.c
packet-exchange/src/utilities.c
+35
-0
packet-exchange/src/utilities.h
packet-exchange/src/utilities.h
+5
-0
No files found.
packet-exchange/src/client.c
View file @
3bbec828
...
...
@@ -54,9 +54,9 @@ typedef struct network_config {
// Static functions
static
void
process_options
(
int
argc
,
char
*
argv
[]);
static
void
do_tsn_task
(
struct
thread_param
*
param
,
char
*
data
,
uint64_t
next_txtime
);
static
void
do_tsn_task
(
struct
thread_param
*
param
,
char
*
data
,
uint64_t
next_txtime
);
static
void
print_histograms
();
static
void
sig
int_handler
(
int
sig_num
);
static
void
sig
hand
(
int
sig_num
);
// Static variables
...
...
@@ -122,13 +122,12 @@ static void *packet_sending_thread(void *p) {
if
(
sched_setscheduler
(
0
,
SCHED_FIFO
,
&
priority
))
error
(
EXIT_FAILURE
,
errno
,
"Couldn't set priority"
);
if
(
enable_etf
)
{
if
(
enable_etf
)
{
// Measure from CLOCK_TAI to generate timestamp
clock_gettime
(
CLOCK_TAI
,
&
next
);
next_txtime
=
next
.
tv_sec
*
NSEC_PER_SEC
+
next
.
tv_nsec
;
next_txtime
+=
param
->
etf_offset
;
}
else
{
}
else
{
next_txtime
=
0
;
}
...
...
@@ -145,7 +144,7 @@ static void *packet_sending_thread(void *p) {
add_ns
(
&
next
,
param
->
interval
);
if
(
enable_etf
)
if
(
enable_etf
)
next_txtime
+=
param
->
interval
;
clock_nanosleep
(
CLOCK_MONOTONIC
,
TIMER_ABSTIME
,
&
next
,
NULL
);
...
...
@@ -160,9 +159,6 @@ int main(int argc, char *argv[]) {
pthread_t
thread
;
thread_stat_t
*
stats
;
// Catch breaks with sigint_handler
signal
(
SIGINT
,
sigint_handler
);
param
=
malloc
(
sizeof
(
thread_param_t
));
stats
=
&
param
->
stats
;
...
...
@@ -191,6 +187,9 @@ int main(int argc, char *argv[]) {
memset
((
int64_t
*
)
histograms
,
0
,
NB_HISTOGRAMS
*
MAX_HIST_VAL
);
}
// Catch breaks with sighand to print the histograms
init_signals
(
sighand
,
enable_histograms
);
// Initialize the UDP packet sending socket
init_udp_send
(
enable_etf
,
enable_timestamps
,
network_config
.
packet_priority
,
...
...
@@ -240,7 +239,7 @@ int main(int argc, char *argv[]) {
}
// Critical TSN task
static
void
do_tsn_task
(
struct
thread_param
*
param
,
char
*
data
,
uint64_t
next_txtime
)
{
static
void
do_tsn_task
(
struct
thread_param
*
param
,
char
*
data
,
uint64_t
next_txtime
)
{
struct
timespec
t1
,
t2
;
int
rtt_us
;
...
...
@@ -262,9 +261,9 @@ static void do_tsn_task(struct thread_param *param, char * data, uint64_t next_t
param
->
stats
.
rtt
=
calcdiff_ns
(
t2
,
t1
);
if
(
enable_histograms
)
{
if
(
enable_histograms
)
{
rtt_us
=
param
->
stats
.
rtt
/
1000
;
if
(
rtt_us
>
MAX_HIST_VAL
)
{
if
(
rtt_us
>
MAX_HIST_VAL
)
{
fprintf
(
stderr
,
"RTT value higher than MAX_HIST_VAL : %d ( > %d)
\n
"
,
rtt_us
,
MAX_HIST_VAL
);
exit
(
EXIT_FAILURE
);
}
...
...
@@ -288,26 +287,28 @@ static void print_histograms() {
interval
=
param
->
interval
/
1000
;
if
(
tsn_task
==
SEND_PACKET_TASK
)
{
if
(
tsn_task
==
SEND_PACKET_TASK
)
{
printf
(
"{
\"
measure_sets
\"
: [{"
"
\"
measure_type
\"
:
\"
packet_send_timestamps
\"
,"
"
\"
props_names
\"
: [
\"
user_space
\"
,
\"
kernel_space
\"
],"
"
\"
units
\"
: [
\"
us
\"
,
\"
us
\"
],"
"
\"
props_type
\"
:
\"
histogram
\"
,"
"
\"
metadata
\"
: {"
"
\"
i
\"
:
\"
%dus
\"
,
\"
duration
\"
:
\"
%dh%d
\"
"
"
\"
i
\"
:
\"
%dus
\"
,
\"
duration
\"
:
\"
%dh%d
\"
,
\"
etf_offset
\"
:
\"
%dus
\"
,
"
"},"
"
\"
props
\"
: ["
,
interval
,
duration_hour
,
duration_minutes
);
}
else
if
(
tsn_task
==
RTT_TASK
)
{
"
\"
props
\"
: ["
,
interval
,
duration_hour
,
duration_minutes
,
param
->
etf_offset
);
}
else
if
(
tsn_task
==
RTT_TASK
)
{
printf
(
"{
\"
measure_sets
\"
: [{"
"
\"
measure_type
\"
:
\"
packet_rtt
\"
,"
"
\"
props_names
\"
: [
\"
rtt
\"
],"
"
\"
units
\"
: [
\"
us
\"
],"
"
\"
props_type
\"
:
\"
histogram
\"
,"
"
\"
metadata
\"
: {"
"
\"
i
\"
:
\"
%dus
\"
,
\"
duration
\"
:
\"
%dh%d
\"
"
"
\"
i
\"
:
\"
%dus
\"
,
\"
duration
\"
:
\"
%dh%d
\"
,
\"
etf_offset
\"
:
\"
%dus
\"
,
"
"},"
"
\"
props
\"
: ["
,
interval
,
duration_hour
,
duration_minutes
);
"
\"
props
\"
: ["
,
interval
,
duration_hour
,
duration_minutes
,
param
->
etf_offset
);
}
nb_hists
=
tsn_task
==
SEND_PACKET_TASK
?
2
:
1
;
...
...
@@ -325,12 +326,11 @@ static void print_histograms() {
printf
(
"%s"
,
(
i
+
1
<
nb_hists
?
"], "
:
"]"
));
}
printf
(
"]}]}
\n
"
);
printf
(
"]}]}
\n
"
);
}
static
void
sig
int_handler
(
int
sig_num
)
{
static
void
sig
hand
(
int
sig_num
)
{
(
void
)
sig_num
;
if
(
enable_histograms
)
print_histograms
();
exit
(
EXIT_SUCCESS
);
}
...
...
packet-exchange/src/recv_packet.c
View file @
3bbec828
...
...
@@ -144,7 +144,7 @@ packet_info_t recv_udp_packet(int use_timestamps, int use_histograms, int64_t hi
packet_info
.
userspace_enter_ts
=
ts_to_uint
(
ts
);
}
if
(
use_timestamps
)
{
if
(
use_timestamps
)
{
for
(
cmsg
=
CMSG_FIRSTHDR
(
&
msg
);
cmsg
;
cmsg
=
CMSG_NXTHDR
(
&
msg
,
cmsg
))
{
if
(
cmsg
->
cmsg_level
==
SOL_SOCKET
&&
cmsg
->
cmsg_type
==
SO_TIMESTAMPING
)
{
...
...
@@ -154,7 +154,7 @@ packet_info_t recv_udp_packet(int use_timestamps, int use_histograms, int64_t hi
clock_gettime
(
CLOCK_REALTIME
,
&
ts
);
packet_info
.
userspace_exit_ts
=
ts_to_uint
(
ts
);
if
(
use_histograms
)
if
(
use_histograms
)
fill_histograms
(
&
packet_info
,
histograms
);
}
}
...
...
packet-exchange/src/send_packet.c
View file @
3bbec828
...
...
@@ -42,7 +42,7 @@ static void init_tx_buffer(size_t _tx_buffer_len);
static
int
so_priority
=
3
;
static
struct
sock_txtime
sk_txtime
;
static
unsigned
char
*
tx_buffer
;
static
char
*
tx_buffer
;
static
size_t
tx_buffer_len
;
static
int
sock_fd
;
...
...
@@ -128,7 +128,7 @@ void init_udp_send(int use_etf, int use_timestamps, int packet_priority,
* Sends udp packets
*/
packet_info_t
send_udp_packet
(
int
use_etf
,
int
use_timestamps
,
char
*
data
,
char
*
data
,
uint64_t
txtime
,
const
char
*
server_ip
,
int64_t
histograms
[
NB_HISTOGRAMS
][
MAX_HIST_VAL
])
{
...
...
@@ -260,7 +260,6 @@ static void process_timestamps(packet_info_t *packet_info, int64_t histograms[NB
fprintf
(
stderr
,
"process_timestamps: level %d type %d"
,
cmsg
->
cmsg_level
,
cmsg
->
cmsg_type
);
#endif
}
}
}
...
...
packet-exchange/src/send_packet.h
View file @
3bbec828
...
...
@@ -4,6 +4,6 @@
#include "utilities.h"
void
init_udp_send
(
int
use_etf
,
int
use_timestamps
,
int
so_priority
,
char
*
network_if
,
size_t
tx_buffer_len
);
packet_info_t
send_udp_packet
(
int
use_etf
,
int
use_timestamps
,
char
*
data
,
uint64_t
txtime
,
const
char
*
server_ip
,
int64_t
histograms
[
NB_HISTOGRAMS
][
MAX_HIST_VAL
]);
packet_info_t
send_udp_packet
(
int
use_etf
,
int
use_timestamps
,
char
*
data
,
uint64_t
txtime
,
const
char
*
server_ip
,
int64_t
histograms
[
NB_HISTOGRAMS
][
MAX_HIST_VAL
]);
#endif
packet-exchange/src/server.c
View file @
3bbec828
...
...
@@ -60,7 +60,7 @@ typedef struct main_param {
static
void
process_options
(
int
argc
,
char
*
argv
[]);
static
void
print_histograms
();
static
void
sig
int_handler
(
int
sig_num
);
static
void
sig
hand
(
int
sig_num
);
// Static variables
...
...
@@ -154,14 +154,13 @@ static void *packet_receiving_thread(void *p) {
// Check if packets were lost
param
->
stats
.
lost_packets
+=
(
current_packet_id
-
prev_packet_id
-
1
)
%
1000
;
if
(
enable_histograms
)
{
if
(
enable_histograms
)
{
dist_to_interval
=
(((
int64_t
)
diff
)
-
param
->
interval
)
/
1000
;
dist_to_interval
+=
MAX_HIST_VAL
/
2
;
if
(
dist_to_interval
>
((
int
)
MAX_HIST_VAL
)
||
dist_to_interval
<
0
)
{
if
(
dist_to_interval
>
((
int
)
MAX_HIST_VAL
)
||
dist_to_interval
<
0
)
{
fprintf
(
stderr
,
"jitter higher than MAX_HIST_VAL: %"
PRIi64
"
\n
"
,
dist_to_interval
);
exit
(
EXIT_FAILURE
);
}
else
{
}
else
{
histograms
[
2
][
dist_to_interval
]
++
;
}
}
...
...
@@ -182,9 +181,6 @@ int main(int argc, char *argv[]) {
thread_stat_t
*
stats
;
int64_t
diff
;
// Catch breaks with sigint_handler
signal
(
SIGINT
,
sigint_handler
);
param
=
malloc
(
sizeof
(
thread_param_t
));
stats
=
&
param
->
stats
;
...
...
@@ -210,6 +206,9 @@ int main(int argc, char *argv[]) {
memset
((
int64_t
*
)
histograms
,
0
,
NB_HISTOGRAMS
*
MAX_HIST_VAL
);
}
// Catch breaks with sighand to print the histograms
init_signals
(
sighand
,
enable_histograms
);
// Initialize the UDP packet receiving socket
init_udp_recv
(
enable_timestamps
,
network_config
.
network_if
);
...
...
@@ -225,17 +224,17 @@ int main(int argc, char *argv[]) {
for
(;;)
{
usleep
(
main_param
.
refresh_rate
);
if
(
main_param
.
verbose
)
{
if
(
main_param
.
verbose
)
{
if
(
tsn_task
==
RECV_PACKET_TASK
)
{
if
(
tsn_task
==
RECV_PACKET_TASK
)
{
diff
=
((
int64_t
)
stats
->
max_interval
)
-
stats
->
min_interval
;
printf
(
"(%d) Jitter : %"
PRIi64
" [Packet data: %s] [Lost packets: %d]
\n
"
,
printf
(
"(%d) Jitter : %"
PRIi64
" [Packet data: %s] [Lost packets: %d]
\n
"
,
stats
->
packets_received
,
diff
,
stats
->
packet_info
.
data
,
stats
->
lost_packets
);
if
(
enable_timestamps
)
{
if
(
enable_timestamps
)
{
printf
(
"(%d) Enter send_udp_packet timestamp: %"
PRIu64
"
\n
"
,
stats
->
packets_received
,
stats
->
packet_info
.
userspace_enter_ts
);
...
...
@@ -266,7 +265,7 @@ static void print_histograms() {
interval
=
param
->
interval
/
1000
;
if
(
enable_timestamps
)
{
if
(
enable_timestamps
)
{
printf
(
"{
\"
measure_sets
\"
: [{"
"
\"
measure_type
\"
:
\"
packet_recv_timestamps
\"
,"
"
\"
props_names
\"
: [
\"
user_space
\"
,
\"
kernel_space
\"
],"
...
...
@@ -275,7 +274,8 @@ static void print_histograms() {
"
\"
metadata
\"
: {"
"
\"
i
\"
:
\"
%dus
\"
,
\"
duration
\"
:
\"
%dh%d
\"
"
"},"
"
\"
props
\"
: ["
,
interval
,
duration_hour
,
duration_minutes
);
"
\"
props
\"
: ["
,
interval
,
duration_hour
,
duration_minutes
);
max_hist_val
=
0
;
for
(
int
i
=
0
;
i
<
2
;
i
++
)
...
...
@@ -293,19 +293,19 @@ static void print_histograms() {
max_hist_val
=
0
;
for
(
int
j
=
0
;
j
<
MAX_HIST_VAL
;
j
++
)
if
(
histograms
[
2
][
j
])
if
(
histograms
[
2
][
j
])
max_hist_val
=
j
;
min_hist_val
=
MAX_HIST_VAL
-
1
;
for
(
int
j
=
MAX_HIST_VAL
-
1
;
j
>=
0
;
j
--
)
if
(
histograms
[
2
][
j
])
if
(
histograms
[
2
][
j
])
min_hist_val
=
j
;
if
(
!
enable_timestamps
)
if
(
!
enable_timestamps
)
printf
(
"{
\"
measure_sets
\"
: [{"
);
else
printf
(
"]}, {"
);
printf
(
"]}, {"
);
printf
(
"
\"
measure_type
\"
:
\"
packet_jitter
\"
,"
printf
(
"
\"
measure_type
\"
:
\"
packet_jitter
\"
,"
"
\"
props_names
\"
: [
\"
jitter
\"
],"
"
\"
units
\"
: [
\"
us
\"
],"
"
\"
props_type
\"
:
\"
histogram
\"
,"
...
...
@@ -313,7 +313,8 @@ static void print_histograms() {
"
\"
metadata
\"
: {"
"
\"
i
\"
:
\"
%dus
\"
,
\"
duration
\"
:
\"
%dh%d
\"
"
"},"
"
\"
props
\"
: [["
,
MAX_HIST_VAL
/
2
-
min_hist_val
,
"
\"
props
\"
: [["
,
MAX_HIST_VAL
/
2
-
min_hist_val
,
interval
,
duration_hour
,
duration_minutes
);
...
...
@@ -321,14 +322,17 @@ static void print_histograms() {
for
(
int
j
=
min_hist_val
;
j
<
max_hist_val
;
j
++
)
printf
(
"%"
PRIi64
"%s"
,
histograms
[
2
][
j
],
(
j
+
1
<
max_hist_val
?
", "
:
""
));
printf
(
"]]}]}
\n
"
);
printf
(
"]]}]}
\n
"
);
}
static
void
sigint_handler
(
int
sig_num
)
{
static
void
sighand
(
int
sig_num
)
{
(
void
)
sig_num
;
if
(
enable_histograms
)
print_histograms
();
if
(
param
->
stats
.
lost_packets
)
fprintf
(
stderr
,
"%d packets were lost
\n
"
,
param
->
stats
.
lost_packets
);
exit
(
EXIT_SUCCESS
);
}
...
...
packet-exchange/src/utilities.c
View file @
3bbec828
#define _GNU_SOURCE
#include <inttypes.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "utilities.h"
void
(
*
previous_handlers
[
NSIG
])(
int
);
static
void
(
*
sighand
)(
int
);
uint64_t
ts_to_uint
(
struct
timespec
t
)
{
return
t
.
tv_sec
*
NSEC_PER_SEC
+
t
.
tv_nsec
;
}
...
...
@@ -28,3 +34,32 @@ uint64_t calcdiff_ns(struct timespec t1, struct timespec t2) {
uint64_t
max
(
uint64_t
a
,
uint64_t
b
)
{
return
a
>
b
?
a
:
b
;
}
uint64_t
min
(
uint64_t
a
,
uint64_t
b
)
{
return
a
<
b
?
a
:
b
;
}
static
void
sighand_wrapper
(
int
sig
)
{
// If we get un unexpected signal, report it, if not print the histogram
if
(
sig
==
SIGINT
||
sig
==
SIGTERM
)
(
*
sighand
)(
sig
);
// Will print the histogram
else
printf
(
"Uknown signal interrupt: %s (%d)
\n
"
,
strsignal
(
sig
),
sig
);
// Execute the default handler
if
(
previous_handlers
[
sig
]
==
SIG_DFL
)
{
signal
(
sig
,
SIG_DFL
);
raise
(
sig
);
}
else
if
(
previous_handlers
[
sig
]
==
SIG_IGN
)
{
return
;
}
else
{
(
*
previous_handlers
[
sig
])(
sig
);
}
}
void
init_signals
(
void
(
*
_sighand
)(
int
),
int
enable_histograms
)
{
sighand
=
_sighand
;
if
(
enable_histograms
)
for
(
int
i
=
0
;
i
<
NSIG
;
i
++
)
signal
(
i
,
sighand_wrapper
);
}
packet-exchange/src/utilities.h
View file @
3bbec828
...
...
@@ -3,6 +3,7 @@
#define _GNU_SOURCE
#include <inttypes.h>
#include <signal.h>
#include <stdint.h>
#include <time.h>
#include <unistd.h>
...
...
@@ -27,4 +28,8 @@ uint64_t calcdiff_ns(struct timespec t1, struct timespec t2);
uint64_t
max
(
uint64_t
a
,
uint64_t
b
);
uint64_t
min
(
uint64_t
a
,
uint64_t
b
);
void
init_signals
(
void
(
*
_sighand
)(
int
),
int
enable_histograms
);
extern
void
(
*
previous_handlers
[
NSIG
])(
int
);
#endif
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