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
b94ded12
Commit
b94ded12
authored
Jun 09, 2020
by
Joanne Hugé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow server to receive and print the packet's data
parent
cbd2afa6
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
48 additions
and
48 deletions
+48
-48
packet-exchange/src/client.c
packet-exchange/src/client.c
+5
-5
packet-exchange/src/recv_packet.c
packet-exchange/src/recv_packet.c
+16
-17
packet-exchange/src/recv_packet.h
packet-exchange/src/recv_packet.h
+1
-1
packet-exchange/src/send_packet.c
packet-exchange/src/send_packet.c
+13
-13
packet-exchange/src/send_packet.h
packet-exchange/src/send_packet.h
+1
-1
packet-exchange/src/server.c
packet-exchange/src/server.c
+8
-9
packet-exchange/src/utilities.h
packet-exchange/src/utilities.h
+4
-2
No files found.
packet-exchange/src/client.c
View file @
b94ded12
...
...
@@ -27,7 +27,7 @@
typedef
struct
thread_stat
{
int
nb_cycles
;
uint64_t
rtt
;
packet_
timestamps_t
packet_ts
;
packet_
info_t
packet_info
;
}
thread_stat_t
;
typedef
struct
thread_param
{
...
...
@@ -215,13 +215,13 @@ int main(int argc, char *argv[]) {
printf
(
"(%d) Enter send_udp_packet timestamp: %"
PRIu64
"
\n
"
,
stats
->
nb_cycles
,
stats
->
packet_
ts
.
userspace_enter_ts
);
stats
->
packet_
info
.
userspace_enter_ts
);
printf
(
"(%d) Call sendmsg timestamp : %"
PRIu64
"
\n
"
,
stats
->
nb_cycles
,
stats
->
packet_
ts
.
userspace_exit_ts
);
stats
->
packet_
info
.
userspace_exit_ts
);
printf
(
"(%d) Leave kernel timestamp : %"
PRIu64
"
\n
"
,
stats
->
nb_cycles
,
stats
->
packet_
ts
.
kernelspace_ts
);
stats
->
packet_
info
.
kernelspace_ts
);
}
}
...
...
@@ -244,7 +244,7 @@ static void do_tsn_task(struct thread_param *param, uint64_t next_txtime) {
// One way packet sending
if
(
tsn_task
==
SEND_PACKET_TASK
)
{
param
->
stats
.
packet_
ts
=
send_udp_packet
(
param
->
stats
.
packet_
info
=
send_udp_packet
(
enable_etf
,
enable_timestamps
,
next_txtime
,
network_config
.
ip_address
,
histograms
);
...
...
packet-exchange/src/recv_packet.c
View file @
b94ded12
...
...
@@ -29,12 +29,9 @@
#include "send_packet.h"
#include "utilities.h"
static
void
fill_histograms
(
packet_info_t
*
packet_info
,
int64_t
histograms
[
NB_HISTOGRAMS
][
MAX_HIST_VAL
]);
#define BUFFER_SIZE 1024
static
void
fill_histograms
(
packet_timestamps_t
*
packet_ts
,
int64_t
histograms
[
NB_HISTOGRAMS
][
MAX_HIST_VAL
]);
static
char
rx_buffer
[
BUFFER_SIZE
];
static
char
rx_buffer
[
MAX_BUFFER_SIZE
];
static
int
sock_fd
;
static
int
so_timestamping_flags
=
...
...
@@ -106,7 +103,7 @@ int init_udp_recv(int use_timestamps, char *network_if) {
/*
* Receives udp packets
*/
packet_
timestamps
_t
recv_udp_packet
(
int
use_timestamps
,
int
use_histograms
,
int64_t
histograms
[
NB_HISTOGRAMS
][
MAX_HIST_VAL
])
{
packet_
info
_t
recv_udp_packet
(
int
use_timestamps
,
int
use_histograms
,
int64_t
histograms
[
NB_HISTOGRAMS
][
MAX_HIST_VAL
])
{
struct
cmsghdr
*
cmsg
;
struct
msghdr
msg
;
// Message hardware, sent to the socket
...
...
@@ -119,11 +116,11 @@ packet_timestamps_t recv_udp_packet(int use_timestamps, int use_histograms, int6
int
recvmsgerr
;
packet_
timestamps_t
packet_ts
;
packet_
info_t
packet_info
;
struct
timespec
ts
;
iov
.
iov_base
=
&
rx_buffer
;
iov
.
iov_len
=
BUFFER_SIZE
-
1
;
iov
.
iov_len
=
MAX_
BUFFER_SIZE
-
1
;
memset
(
&
msg
,
0
,
sizeof
(
msg
));
msg
.
msg_name
=
&
sin
;
...
...
@@ -135,7 +132,7 @@ packet_timestamps_t recv_udp_packet(int use_timestamps, int use_histograms, int6
if
(
use_timestamps
)
{
clock_gettime
(
CLOCK_REALTIME
,
&
ts
);
packet_
ts
.
userspace_exit_ts
=
ts_to_uint
(
ts
);
packet_
info
.
userspace_exit_ts
=
ts_to_uint
(
ts
);
}
recvmsgerr
=
recvmsg
(
sock_fd
,
&
msg
,
0
);
...
...
@@ -144,7 +141,7 @@ packet_timestamps_t recv_udp_packet(int use_timestamps, int use_histograms, int6
if
(
use_timestamps
)
{
clock_gettime
(
CLOCK_REALTIME
,
&
ts
);
packet_
ts
.
userspace_enter_ts
=
ts_to_uint
(
ts
);
packet_
info
.
userspace_enter_ts
=
ts_to_uint
(
ts
);
}
if
(
use_timestamps
)
{
...
...
@@ -152,24 +149,26 @@ packet_timestamps_t recv_udp_packet(int use_timestamps, int use_histograms, int6
if
(
cmsg
->
cmsg_level
==
SOL_SOCKET
&&
cmsg
->
cmsg_type
==
SO_TIMESTAMPING
)
{
struct
timespec
*
stamp
=
(
struct
timespec
*
)
CMSG_DATA
(
cmsg
);
packet_
ts
.
kernelspace_ts
=
ts_to_uint
(
*
stamp
);
packet_
info
.
kernelspace_ts
=
ts_to_uint
(
*
stamp
);
clock_gettime
(
CLOCK_REALTIME
,
&
ts
);
packet_
ts
.
userspace_exit_ts
=
ts_to_uint
(
ts
);
packet_
info
.
userspace_exit_ts
=
ts_to_uint
(
ts
);
if
(
use_histograms
)
fill_histograms
(
&
packet_
ts
,
histograms
);
fill_histograms
(
&
packet_
info
,
histograms
);
}
}
}
return
packet_ts
;
strcpy
(
packet_info
.
data
,
rx_buffer
);
return
packet_info
;
}
static
void
fill_histograms
(
packet_
timestamps_t
*
packet_ts
,
int64_t
histograms
[
NB_HISTOGRAMS
][
MAX_HIST_VAL
])
{
static
void
fill_histograms
(
packet_
info_t
*
packet_info
,
int64_t
histograms
[
NB_HISTOGRAMS
][
MAX_HIST_VAL
])
{
uint64_t
user_space_time
=
packet_
ts
->
userspace_exit_ts
-
packet_ts
->
userspace_enter_ts
;
uint64_t
kernel_space_time
=
packet_
ts
->
userspace_enter_ts
-
packet_ts
->
kernelspace_ts
;
uint64_t
user_space_time
=
packet_
info
->
userspace_exit_ts
-
packet_info
->
userspace_enter_ts
;
uint64_t
kernel_space_time
=
packet_
info
->
userspace_enter_ts
-
packet_info
->
kernelspace_ts
;
user_space_time
/=
1000u
;
kernel_space_time
/=
1000u
;
...
...
packet-exchange/src/recv_packet.h
View file @
b94ded12
...
...
@@ -4,6 +4,6 @@
#include "utilities.h"
int
init_udp_recv
(
int
use_timestamps
,
char
*
network_if
);
packet_
timestamps
_t
recv_udp_packet
(
int
use_timestamps
,
int
use_histograms
,
int64_t
histograms
[
NB_HISTOGRAMS
][
MAX_HIST_VAL
]);
packet_
info
_t
recv_udp_packet
(
int
use_timestamps
,
int
use_histograms
,
int64_t
histograms
[
NB_HISTOGRAMS
][
MAX_HIST_VAL
]);
#endif
packet-exchange/src/send_packet.c
View file @
b94ded12
...
...
@@ -39,7 +39,7 @@
#define MESSAGE ((uint32_t)0x00FACADE)
static
void
process_timestamps
(
packet_
timestamps_t
*
packet_ts
,
int64_t
histograms
[
NB_HISTOGRAMS
][
MAX_HIST_VAL
]);
static
void
process_timestamps
(
packet_
info_t
*
packet_info
,
int64_t
histograms
[
NB_HISTOGRAMS
][
MAX_HIST_VAL
]);
static
void
init_tx_buffer
(
size_t
_tx_buffer_len
);
static
int
so_priority
=
3
;
...
...
@@ -146,7 +146,7 @@ uint64_t get_txtime() {
/*
* Sends udp packets
*/
packet_
timestamps
_t
send_udp_packet
(
int
use_etf
,
int
use_timestamps
,
packet_
info
_t
send_udp_packet
(
int
use_etf
,
int
use_timestamps
,
uint64_t
txtime
,
const
char
*
server_ip
,
int64_t
histograms
[
NB_HISTOGRAMS
][
MAX_HIST_VAL
])
{
...
...
@@ -160,12 +160,12 @@ packet_timestamps_t send_udp_packet(int use_etf, int use_timestamps,
// Server address
struct
sockaddr_in
sin
;
packet_
timestamps_t
packet_ts
;
packet_
info_t
packet_info
;
struct
timespec
ts
;
if
(
use_timestamps
)
{
clock_gettime
(
CLOCK_REALTIME
,
&
ts
);
packet_
ts
.
userspace_enter_ts
=
ts_to_uint
(
ts
);
packet_
info
.
userspace_enter_ts
=
ts_to_uint
(
ts
);
}
memset
(
&
sin
,
0
,
sizeof
(
sin
));
...
...
@@ -197,7 +197,7 @@ packet_timestamps_t send_udp_packet(int use_etf, int use_timestamps,
if
(
use_timestamps
)
{
clock_gettime
(
CLOCK_REALTIME
,
&
ts
);
packet_
ts
.
userspace_exit_ts
=
ts_to_uint
(
ts
);
packet_
info
.
userspace_exit_ts
=
ts_to_uint
(
ts
);
}
sendmsgerr
=
sendmsg
(
sock_fd
,
&
msg
,
0
);
...
...
@@ -207,18 +207,18 @@ packet_timestamps_t send_udp_packet(int use_etf, int use_timestamps,
if
(
use_timestamps
)
{
pollerr
=
poll
(
&
poll_fd
,
1
,
0
);
if
(
pollerr
>
0
)
process_timestamps
(
&
packet_
ts
,
histograms
);
process_timestamps
(
&
packet_
info
,
histograms
);
else
fprintf
(
stderr
,
"select failed
\n
"
);
}
return
packet_
ts
;
return
packet_
info
;
}
static
void
fill_histograms
(
packet_
timestamps_t
*
packet_ts
,
int64_t
histograms
[
NB_HISTOGRAMS
][
MAX_HIST_VAL
])
{
static
void
fill_histograms
(
packet_
info_t
*
packet_info
,
int64_t
histograms
[
NB_HISTOGRAMS
][
MAX_HIST_VAL
])
{
uint64_t
user_space_time
=
packet_
ts
->
userspace_exit_ts
-
packet_ts
->
userspace_enter_ts
;
uint64_t
kernel_space_time
=
packet_
ts
->
kernelspace_ts
-
packet_ts
->
userspace_exit_ts
;
uint64_t
user_space_time
=
packet_
info
->
userspace_exit_ts
-
packet_info
->
userspace_enter_ts
;
uint64_t
kernel_space_time
=
packet_
info
->
kernelspace_ts
-
packet_info
->
userspace_exit_ts
;
user_space_time
/=
1000u
;
kernel_space_time
/=
1000u
;
...
...
@@ -236,7 +236,7 @@ static void fill_histograms(packet_timestamps_t *packet_ts, int64_t histograms[N
histograms
[
1
][
kernel_space_time
]
++
;
}
static
void
process_timestamps
(
packet_
timestamps_t
*
packet_ts
,
int64_t
histograms
[
NB_HISTOGRAMS
][
MAX_HIST_VAL
])
{
static
void
process_timestamps
(
packet_
info_t
*
packet_info
,
int64_t
histograms
[
NB_HISTOGRAMS
][
MAX_HIST_VAL
])
{
char
data
[
256
];
struct
msghdr
msg
;
struct
iovec
entry
;
...
...
@@ -266,8 +266,8 @@ static void process_timestamps(packet_timestamps_t *packet_ts, int64_t histogram
if
(
cmsg
->
cmsg_level
==
SOL_SOCKET
&&
cmsg
->
cmsg_type
==
SO_TIMESTAMPING
)
{
struct
timespec
*
stamp
=
(
struct
timespec
*
)
CMSG_DATA
(
cmsg
);
packet_
ts
->
kernelspace_ts
=
ts_to_uint
(
*
stamp
);
fill_histograms
(
packet_
ts
,
histograms
);
packet_
info
->
kernelspace_ts
=
ts_to_uint
(
*
stamp
);
fill_histograms
(
packet_
info
,
histograms
);
}
else
{
...
...
packet-exchange/src/send_packet.h
View file @
b94ded12
...
...
@@ -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_
timestamps
_t
send_udp_packet
(
int
use_etf
,
int
use_timestamps
,
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
,
uint64_t
txtime
,
const
char
*
server_ip
,
int64_t
histograms
[
NB_HISTOGRAMS
][
MAX_HIST_VAL
]);
#endif
packet-exchange/src/server.c
View file @
b94ded12
...
...
@@ -28,15 +28,13 @@
#include "send_packet.h"
#include "utilities.h"
#define BUFFER_SIZE 1024
// Structs
typedef
struct
thread_stat
{
uint64_t
min_interval
;
uint64_t
max_interval
;
int
packets_received
;
packet_
timestamps_t
packet_ts
;
packet_
info_t
packet_info
;
}
thread_stat_t
;
typedef
struct
thread_param
{
...
...
@@ -136,7 +134,7 @@ static void *packet_receiving_thread(void *p) {
}
else
if
(
tsn_task
==
RECV_PACKET_TASK
)
{
param
->
stats
.
packet_
ts
=
recv_udp_packet
(
enable_timestamps
,
enable_histograms
,
histograms
);
param
->
stats
.
packet_
info
=
recv_udp_packet
(
enable_timestamps
,
enable_histograms
,
histograms
);
clock_gettime
(
CLOCK_MONOTONIC
,
&
current
);
...
...
@@ -219,20 +217,21 @@ int main(int argc, char *argv[]) {
if
(
tsn_task
==
RECV_PACKET_TASK
)
{
diff
=
((
int64_t
)
stats
->
max_interval
)
-
stats
->
min_interval
;
printf
(
"(%d) Jitter : %"
PRIi64
"
\n
"
,
printf
(
"(%d) Jitter : %"
PRIi64
"
[Packet data: %s]
\n
"
,
stats
->
packets_received
,
diff
);
diff
,
stats
->
packet_info
.
data
);
if
(
enable_timestamps
)
{
printf
(
"(%d) Enter send_udp_packet timestamp: %"
PRIu64
"
\n
"
,
stats
->
packets_received
,
stats
->
packet_
ts
.
userspace_enter_ts
);
stats
->
packet_
info
.
userspace_enter_ts
);
printf
(
"(%d) Call sendmsg timestamp : %"
PRIu64
"
\n
"
,
stats
->
packets_received
,
stats
->
packet_
ts
.
userspace_exit_ts
);
stats
->
packet_
info
.
userspace_exit_ts
);
printf
(
"(%d) Leave kernel timestamp : %"
PRIu64
"
\n
"
,
stats
->
packets_received
,
stats
->
packet_
ts
.
kernelspace_ts
);
stats
->
packet_
info
.
kernelspace_ts
);
}
}
}
...
...
packet-exchange/src/utilities.h
View file @
b94ded12
...
...
@@ -12,12 +12,14 @@
#define SERVER_PORT_INT 50000
#define MAX_HIST_VAL 2000
#define NB_HISTOGRAMS 3
#define MAX_BUFFER_SIZE 1024
typedef
struct
packet_
timestamps
{
typedef
struct
packet_
info
{
uint64_t
userspace_enter_ts
;
uint64_t
userspace_exit_ts
;
uint64_t
kernelspace_ts
;
}
packet_timestamps_t
;
char
data
[
MAX_BUFFER_SIZE
];
}
packet_info_t
;
uint64_t
ts_to_uint
(
struct
timespec
t
);
void
add_ns
(
struct
timespec
*
t
,
uint64_t
ns
);
...
...
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